ossysc.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. {
  2. Copyright (c) 2002 by Marco van de Voort
  3. The base Linux syscalls required to implement the system unit. These
  4. are aliased for use in other units (to avoid poluting the system units
  5. interface)
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. ****************************************************************************
  12. }
  13. {*****************************************************************************
  14. --- Main:The System Call Self ---
  15. *****************************************************************************}
  16. function Fptime(tloc:pTime_t): Time_t; [public, alias : 'FPC_SYSC_TIME'];
  17. {$ifdef FPC_USEGETTIMEOFDAY}
  18. VAR tv : timeval;
  19. tz : timezone;
  20. retval : longint;
  21. begin
  22. Retval:=do_syscall(syscall_nr_gettimeofday,TSysParam(@tv),TSysParam(@tz));
  23. If retval=-1 then
  24. Fptime:=-1
  25. else
  26. Begin
  27. If Assigned(tloc) Then
  28. TLoc^:=tv.tv_sec;
  29. Fptime:=tv.tv_sec;
  30. End;
  31. End;
  32. {$else FPC_USEGETTIMEOFDAY}
  33. begin
  34. Fptime:=do_syscall(syscall_nr_time,TSysParam(tloc));
  35. end;
  36. {$endif FPC_USEGETTIMEOFDAY}
  37. {*****************************************************************************
  38. --- File:File handling related calls ---
  39. *****************************************************************************}
  40. function Fpopen(path: pchar; flags : cint; mode: mode_t):cint; [public, alias : 'FPC_SYSC_OPEN'];
  41. Begin
  42. Fpopen:=do_syscall(syscall_nr_open,TSysParam(path),TSysParam(flags or O_LARGEFILE),TSysParam(mode));
  43. End;
  44. function Fpclose(fd : cint): cint; [public, alias : 'FPC_SYSC_CLOSE'];
  45. begin
  46. Fpclose:=do_syscall(syscall_nr_close,fd);
  47. end;
  48. function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; [public, alias : 'FPC_SYSC_LSEEK'];
  49. begin
  50. {$if defined(cpu64)}
  51. result:=do_syscall(syscall_nr_lseek,tsysparam(fd),tsysparam(offset),tsysparam(whence));
  52. {$else}
  53. if do_syscall(syscall_nr__llseek,tsysparam(fd),
  54. // {$ifdef FPC_ABI_EABI} 0, { align parameters as required with dummy } {$endif FPC_ABI_EABI}
  55. tsysparam(hi(offset)),tsysparam(lo(offset)),
  56. tsysparam(@result), tsysparam(whence)) = -1 then
  57. result:=off_t(-1);
  58. {$endif}
  59. end;
  60. function Fpread(fd: cint; buf: pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_READ'];
  61. begin
  62. Fpread:=do_syscall(syscall_nr_read,Fd,TSysParam(buf),nbytes);
  63. end;
  64. function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias : 'FPC_SYSC_WRITE'];
  65. begin
  66. Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
  67. end;
  68. {
  69. function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
  70. !! check 64 bit off_t sycall
  71. begin
  72. Fpread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,offset);
  73. end;
  74. function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
  75. !! check 64 bit off_t sycall
  76. begin
  77. Fpwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,offset);
  78. end;
  79. }
  80. function Fpunlink(path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
  81. begin
  82. Fpunlink:=do_syscall(syscall_nr_unlink,TSysParam(path));
  83. end;
  84. function Fprename(old : pchar; newpath: pchar): cint; [public, alias : 'FPC_SYSC_RENAME'];
  85. begin
  86. Fprename:=do_syscall(syscall_nr_rename,TSysParam(old),TSysParam(newpath));
  87. end;
  88. function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
  89. begin
  90. {$if defined(cpu64)}
  91. Fpstat:=do_syscall(syscall_nr_stat,TSysParam(path),TSysParam(@buf));
  92. {$else}
  93. Fpstat:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
  94. {$endif}
  95. end;
  96. {*****************************************************************************
  97. --- Directory:Directory related calls ---
  98. *****************************************************************************}
  99. function Fpchdir(path : pchar): cint; [public, alias : 'FPC_SYSC_CHDIR'];
  100. begin
  101. Fpchdir:=do_syscall(syscall_nr_chdir,TSysParam(path));
  102. end;
  103. function Fpmkdir(path : pchar; mode: mode_t):cint; [public, alias : 'FPC_SYSC_MKDIR'];
  104. begin
  105. Fpmkdir:=do_syscall(syscall_nr_mkdir,TSysParam(path),TSysParam(mode));
  106. end;
  107. function Fprmdir(path : pchar): cint; [public, alias : 'FPC_SYSC_RMDIR'];
  108. begin
  109. Fprmdir:=do_syscall(syscall_nr_rmdir,TSysParam(path));
  110. end;
  111. function Fpopendir(dirname : pchar): pdir; [public, alias : 'FPC_SYSC_OPENDIR'];
  112. var
  113. fd:integer;
  114. st:stat;
  115. ptr:pdir;
  116. begin
  117. Fpopendir:=nil;
  118. if Fpstat(dirname,st)<0 then
  119. exit;
  120. { Is it a dir ? }
  121. if not((st.st_mode and $f000)=$4000)then
  122. begin
  123. errno:=ESysENOTDIR;
  124. exit
  125. end;
  126. { Open it}
  127. fd:=Fpopen(dirname,O_RDONLY,438);
  128. if fd<0 then
  129. exit;
  130. new(ptr);
  131. if ptr=nil then
  132. exit;
  133. new(ptr^.dd_buf);
  134. if ptr^.dd_buf=nil then
  135. exit;
  136. ptr^.dd_fd:=fd;
  137. ptr^.dd_loc:=0;
  138. ptr^.dd_size:=0;
  139. ptr^.dd_nextoff:=0;
  140. ptr^.dd_max:=sizeof(ptr^.dd_buf^);
  141. Fpopendir:=ptr;
  142. end;
  143. function Fpclosedir(dirp : pdir): cint; [public, alias : 'FPC_SYSC_CLOSEDIR'];
  144. begin
  145. repeat
  146. Fpclosedir:=Fpclose(dirp^.dd_fd);
  147. until (Fpclosedir=0) or (errno<>ESysEINTR);
  148. dispose(dirp^.dd_buf);
  149. dispose(dirp);
  150. end;
  151. Function Fpreaddir(dirp : pdir) : pdirent; [public, alias: 'FPC_SYSC_READDIR'];
  152. var bytes : longint;
  153. dp : pdirent;
  154. begin
  155. repeat
  156. if dirp^.dd_nextoff >= dirp^.dd_size then
  157. begin
  158. bytes := do_SysCall(SysCall_nr_getdents64,TSysParam(dirp^.dd_fd),TSysParam(dirp^.dd_buf),TSysParam(dirp^.dd_max));
  159. if bytes <= 0 then
  160. begin
  161. fpreaddir := nil;
  162. exit;
  163. end;
  164. dirp^.dd_size := bytes;
  165. dirp^.dd_nextoff := 0;
  166. end;
  167. dp := Pdirent(ptruint(dirp^.dd_buf)+dirp^.dd_nextoff);
  168. inc(dirp^.dd_nextoff,dp^.d_reclen);
  169. inc(dirp^.dd_loc,dp^.d_reclen);
  170. until dp^.d_fileno <> 0; // Don't show deleted files
  171. Fpreaddir := dp;
  172. end;
  173. {*****************************************************************************
  174. --- Process:Process & program handling - related calls ---
  175. *****************************************************************************}
  176. procedure Fpexit(status : cint); [public, alias : 'FPC_SYSC_EXIT'];
  177. begin
  178. do_syscall(syscall_nr_exit_group,status);
  179. end;
  180. {
  181. Change action of process upon receipt of a signal.
  182. Signum specifies the signal (all except SigKill and SigStop).
  183. If Act is non-nil, it is used to specify the new action.
  184. If OldAct is non-nil the previous action is saved there.
  185. }
  186. {$ifdef cpusparc}
  187. procedure Fprt_sigreturn_stub;assembler;nostackframe;
  188. asm
  189. mov syscall_nr_rt_sigreturn,%g1
  190. ta 0x10
  191. end;
  192. {$endif cpusparc}
  193. {$if defined(cpui386) or defined(cpuarm) or defined(cpux86_64)}
  194. {$define NEED_USER_TRAMPOLINE}
  195. {$endif}
  196. {$if defined(cpui386) or defined(cpuarm)}
  197. {$define NEED_USER_TRAMPOLINE_RT_DIFFERENT}
  198. {$endif}
  199. {$ifdef NEED_USER_TRAMPOLINE}
  200. procedure linux_restore; cdecl; nostackframe; assembler;
  201. {$ifdef cpuarm}
  202. asm
  203. {$ifdef FPC_ABI_EABI}
  204. mov r7, syscall_nr_sigreturn
  205. {$ifdef CPUTHUMB}
  206. // svc #0x0
  207. // GNU 2.22 does not like svc #0x0
  208. .byte 0,0xdf
  209. {$else CPUTHUMB}
  210. swi #0x0
  211. {$endif CPUTHUMB}
  212. {$else}
  213. swi syscall_nr_sigreturn
  214. {$endif}
  215. end;
  216. {$endif}
  217. {$ifdef cpui386}
  218. asm
  219. popl %eax
  220. movl $syscall_nr_sigreturn, %eax
  221. int $0x80
  222. end;
  223. {$endif}
  224. {$ifdef cpux86_64}
  225. asm
  226. movq $syscall_nr_rt_sigreturn, %rax
  227. syscall
  228. end;
  229. {$endif}
  230. {$endif}
  231. {$ifdef NEED_USER_TRAMPOLINE_RT_DIFFERENT}
  232. procedure linux_restore_rt; cdecl; nostackframe; assembler;
  233. {$ifdef cpuarm}
  234. asm
  235. {$ifdef FPC_ABI_EABI}
  236. mov r7, syscall_nr_rt_sigreturn
  237. {$ifdef CPUTHUMB}
  238. // svc #0x0
  239. // GNU 2.22 does not like svc #0x0
  240. .byte 0,0xdf
  241. {$else CPUTHUMB}
  242. swi #0x0
  243. {$endif CPUTHUMB}
  244. {$else}
  245. swi syscall_nr_rt_sigreturn
  246. {$endif}
  247. end;
  248. {$endif}
  249. {$ifdef cpui386}
  250. asm
  251. movl $syscall_nr_rt_sigreturn, %eax
  252. int $0x80
  253. end;
  254. {$endif}
  255. {$endif}
  256. function Fpsigaction(sig: cint; new_action, old_action: psigactionrec): cint; [public, alias : 'FPC_SYSC_SIGACTION'];
  257. {
  258. Change action of process upon receipt of a signal.
  259. Signum specifies the signal (all except SigKill and SigStop).
  260. If Act is non-nil, it is used to specify the new action.
  261. If OldAct is non-nil the previous action is saved there.
  262. }
  263. begin
  264. {$ifdef cpusparc}
  265. { Sparc has an extra stub parameter }
  266. Fpsigaction:=do_syscall(syscall_nr_rt_sigaction,TSysParam(sig),TSysParam(new_action),TSysParam(old_action),TSysParam(ptruint(@Fprt_sigreturn_stub)-8),TSysParam(8));
  267. {$else cpusparc}
  268. {$ifdef NEED_USER_TRAMPOLINE}
  269. if new_action <> nil then
  270. begin
  271. // a different stack (SA_ONSTACK) requires sa_restorer field
  272. if (new_action^.sa_flags and (SA_RESTORER or SA_ONSTACK)) = 0 then
  273. begin
  274. new_action^.sa_flags := new_action^.sa_flags or SA_RESTORER;
  275. {$ifdef NEED_USER_TRAMPOLINE_RT_DIFFERENT}
  276. if (new_action^.sa_flags and SA_SIGINFO) <> 0 then
  277. new_action^.sa_restorer := @linux_restore_rt
  278. else
  279. {$endif}
  280. new_action^.sa_restorer := @linux_restore;
  281. end;
  282. end;
  283. {$endif}
  284. Fpsigaction:=do_syscall(syscall_nr_rt_sigaction,TSysParam(sig),
  285. TSysParam(new_action),TSysParam(old_action),
  286. {$ifdef cpumips}
  287. TSysParam(16{should be wordsinsigset})
  288. {$else not cpumips}
  289. TSysParam(8)
  290. {$endif not cpumips}
  291. );
  292. {$endif cpusparc}
  293. end;
  294. function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
  295. { See notes lseek. This one is completely similar for the parameter (but
  296. doesn't have the returnvalue 64-bit problem)}
  297. begin
  298. {$if defined(cpu64)}
  299. Fpftruncate:=Do_syscall(syscall_nr_ftruncate,TSysParam(fd),TSysParam(flength));
  300. {$else}
  301. Fpftruncate:=Do_syscall(syscall_nr_ftruncate64,TSysParam(fd),
  302. {$ifdef FPC_ABI_EABI} 0, { align parameters as required with dummy } {$endif FPC_ABI_EABI}
  303. {$ifdef FPC_BIG_ENDIAN} tsysparam(hi(flength)),tsysparam(lo(flength)){$endif}
  304. {$ifdef FPC_LITTLE_ENDIAN} tsysparam(lo(flength)),tsysparam(hi(flength)){$endif}
  305. );
  306. {$endif}
  307. end;
  308. function Fpfstat(fd : cint; var sb : stat): cint; [public, alias : 'FPC_SYSC_FSTAT'];
  309. begin
  310. {$if defined(cpu64)}
  311. FpFStat:=do_SysCall(syscall_nr_fstat,TSysParam(fd),TSysParam(@sb));
  312. {$else}
  313. FpFStat:=do_SysCall(syscall_nr_fstat64,TSysParam(fd),TSysParam(@sb));
  314. {$endif}
  315. end;
  316. {$ifndef FPC_SYSTEM_HAS_FPFORK}
  317. function Fpfork : pid_t; [public, alias : 'FPC_SYSC_FORK'];
  318. {
  319. This function issues the 'fork' System call. the program is duplicated in memory
  320. and Execution continues in parent and child process.
  321. In the parent process, fork returns the PID of the child. In the child process,
  322. zero is returned.
  323. A negative value indicates that an error has occurred, the error is returned in
  324. LinuxError.
  325. }
  326. Begin
  327. Fpfork:=Do_syscall(SysCall_nr_fork);
  328. End;
  329. {$endif FPC_SYSTEM_HAS_FPFORK}
  330. // Look at execve variants later, when overloaded is determined.
  331. {
  332. function Fpexecve(path : pathstr; argv : ppchar; envp: ppchar): cint;
  333. }
  334. {
  335. Replaces the current program by the program specified in path,
  336. arguments in args are passed to Execve.
  337. environment specified in ep is passed on.
  338. }
  339. {
  340. Begin
  341. path:=path+#0;
  342. do_syscall(syscall_nr_Execve,TSysParam(@path[1]),TSysParam(Argv),TSysParam(envp));
  343. End;
  344. }
  345. {
  346. function Fpexecve(path : pchar; argv : ppchar; envp: ppchar): cint; [public, alias : 'FPC_SYSC_EXECVE'];
  347. }
  348. {
  349. Replaces the current program by the program specified in path,
  350. arguments in args are passed to Execve.
  351. environment specified in ep is passed on.
  352. }
  353. {
  354. Begin
  355. do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
  356. End;
  357. }
  358. function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
  359. {
  360. Waits until a child with PID Pid exits, or returns if it is exited already.
  361. Any resources used by the child are freed.
  362. The exit status is reported in the adress referred to by Status. It should
  363. be a longint.
  364. }
  365. begin
  366. {$ifdef WAIT4}
  367. FpWaitPID:=do_syscall(syscall_nr_Wait4,PID,TSysParam(Stat_loc),options,0);
  368. {$else WAIT4}
  369. FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options);
  370. {$endif WAIT4}
  371. end;
  372. function Fpaccess(pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
  373. {
  374. Test users access rights on the specified file.
  375. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  376. R,W,X stand for read,write and Execute access, simultaneously.
  377. F_OK checks whether the test would be allowed on the file.
  378. i.e. It checks the search permissions in all directory components
  379. of the path.
  380. The test is done with the real user-ID, instead of the effective.
  381. If access is denied, or an error occurred, false is returned.
  382. If access is granted, true is returned.
  383. Errors other than no access,are reported in unixerror.
  384. }
  385. begin
  386. FpAccess:=do_syscall(syscall_nr_access,TSysParam(pathname),amode);
  387. end;
  388. (* overloaded
  389. function Fpaccess(pathname : pathstr; amode : cint): cint;
  390. {
  391. Test users access rights on the specified file.
  392. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  393. R,W,X stand for read,write and Execute access, simultaneously.
  394. F_OK checks whether the test would be allowed on the file.
  395. i.e. It checks the search permissions in all directory components
  396. of the path.
  397. The test is done with the real user-ID, instead of the effective.
  398. If access is denied, or an error occurred, false is returned.
  399. If access is granted, true is returned.
  400. Errors other than no access,are reported in unixerror.
  401. }
  402. begin
  403. pathname:=pathname+#0;
  404. Access:=do_syscall(syscall_nr_access, TSysParam(@pathname[1]),mode)=0;
  405. end;
  406. *)
  407. Function FpDup(fildes:cint):cint; [public, alias : 'FPC_SYSC_DUP'];
  408. begin
  409. Fpdup:=Do_syscall(syscall_nr_dup,TSysParam(fildes));
  410. end;
  411. Function FpDup2(fildes,fildes2:cint):cint; [public, alias : 'FPC_SYSC_DUP2'];
  412. begin
  413. Fpdup2:=do_syscall(syscall_nr_dup2,TSysParam(fildes),TSysParam(fildes2));
  414. end;
  415. type
  416. tmmapargs = record
  417. address : TSysParam;
  418. size : TSysParam;
  419. prot : TSysParam;
  420. flags : TSysParam;
  421. fd : TSysParam;
  422. offset : TSysParam;
  423. end;
  424. Function Fpmmap(adr:pointer;len:size_t;prot:cint;flags:cint;fd:cint;off:off_t):pointer; [public, alias : 'FPC_SYSC_MMAP'];
  425. // OFF_T procedure, and returns a pointer, NOT cint.
  426. {$ifdef OLDMMAP}
  427. var
  428. mmapargs : tmmapargs;
  429. begin
  430. mmapargs.address:=TSysParam(adr);
  431. mmapargs.size:=TSysParam(len);
  432. mmapargs.prot:=TSysParam(prot);
  433. mmapargs.flags:=TSysParam(flags);
  434. mmapargs.fd:=TSysParam(fd);
  435. mmapargs.offset:=TSysParam(off);
  436. Fpmmap:=pointer(do_syscall(syscall_nr_mmap,TSysParam(@MMapArgs)));
  437. end;
  438. {$else OLDMMAP}
  439. {$ifdef MMAP2}
  440. begin
  441. {$if sizeof(TSysParam)>=sizeof(off_t)}
  442. Fpmmap:= pointer(do_syscall(syscall_nr_mmap2,TSysParam(adr),TSysParam(len),
  443. TSysParam(prot),TSysParam(flags),TSysParam(fd),TSysParam(off)));
  444. {$else off_t is larger than TsysParam }
  445. {$message warning need mmap64 syscall, hi(off) not used}
  446. Fpmmap:= pointer(do_syscall(syscall_nr_mmap2,TSysParam(adr),TSysParam(len),
  447. TSysParam(prot),TSysParam(flags),TSysParam(fd),TSysParam(lo(off))));
  448. {$endif}
  449. end;
  450. {$else MMAP2}
  451. begin
  452. {$if sizeof(TSysParam)>=sizeof(off_t)}
  453. Fpmmap:= pointer(do_syscall(syscall_nr_mmap,TSysParam(adr),TSysParam(len),
  454. TSysParam(prot),TSysParam(flags),TSysParam(fd),TSysParam(off)));
  455. {$else off_t is larger than TsysParam }
  456. {$message warning need mmap64 syscall, hi(off) not used}
  457. Fpmmap:= pointer(do_syscall(syscall_nr_mmap,TSysParam(adr),TSysParam(len),
  458. TSysParam(prot),TSysParam(flags),TSysParam(fd),TSysParam(lo(off))));
  459. {$endif}
  460. end;
  461. {$endif MMAP2}
  462. {$endif OLDMMAP}
  463. Function Fpmunmap(adr:pointer;len:size_t):cint; [public, alias :'FPC_SYSC_MUNMAP'];
  464. begin
  465. Fpmunmap:=do_syscall(syscall_nr_munmap,TSysParam(Adr),TSysParam(Len));
  466. end;
  467. {
  468. Interface to Unix ioctl call.
  469. Performs various operations on the filedescriptor Handle.
  470. Ndx describes the operation to perform.
  471. Data points to data needed for the Ndx function. The structure of this
  472. data is function-dependent.
  473. }
  474. // prototype is cint __P(cint,culong,....)
  475. // actual meaning of return value depends on request.
  476. Function FpIOCtl(fd:cint;request:TIOCtlRequest;Data: Pointer):cint; [public, alias : 'FPC_SYSC_IOCTL'];
  477. // This was missing here, instead hardcoded in Do_IsDevice
  478. begin
  479. FpIOCtl:=do_SysCall(syscall_nr_ioctl,tsysparam(fd),tsysparam(Request),TSysParam(data));
  480. end;
  481. Function FpGetPid:pid_t; [public, alias : 'FPC_SYSC_GETPID'];
  482. {
  483. Get Process ID.
  484. }
  485. begin
  486. FpGetPID:=do_syscall(syscall_nr_getpid);
  487. end;
  488. Function FpReadLink(name,linkname:pchar;maxlen:size_t):cint; [public, alias : 'FPC_SYSC_READLINK'];
  489. begin
  490. Fpreadlink:=do_syscall(syscall_nr_readlink, TSysParam(name),TSysParam(linkname),maxlen);
  491. end;
  492. function FPSigProcMask(how:cint;nset : psigset;oset : psigset):cint; [public, alias : 'FPC_SYSC_SIGPROCMASK'];
  493. {
  494. Change the list of currently blocked signals.
  495. How determines which signals will be blocked :
  496. SigBlock : Add SSet to the current list of blocked signals
  497. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  498. SigSetMask : Set the list of blocked signals to SSet
  499. if OldSSet is non-null, the old set will be saved there.
  500. }
  501. begin
  502. FPsigprocmask:=do_syscall(syscall_nr_rt_sigprocmask,TSysParam(how),
  503. TSysParam(nset),TSysParam(oset),
  504. {$ifdef CPUMIPS}
  505. TSysParam(16)
  506. {$else not CPUMIPS}
  507. TSysParam(8)
  508. {$endif not CPUMIPS}
  509. );
  510. end;
  511. Function FpNanoSleep(req : ptimespec;rem : ptimespec):cint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
  512. begin
  513. FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
  514. end;
  515. function fpgetcwd(path : pchar; siz:tsize):pchar; [public, alias : 'FPC_SYSC_GETCWD'];
  516. begin
  517. fpgetcwd:=pchar(Do_Syscall(Syscall_nr_getcwd,TSysParam(Path),TSysParam(siz)));
  518. end;
  519. function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; [public, alias: 'FPC_SYSC_GETTIMEOFDAY'];
  520. begin
  521. fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp));
  522. end;
  523. function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; [public, alias : 'FPC_SYSC_GETRLIMIT'];
  524. begin
  525. {$ifndef NO_SYSCALL_GETRLIMIT}
  526. FpGetRLimit := do_syscall(syscall_nr_getrlimit,
  527. TSysParam(resource), TSysParam(rlim));
  528. {$else}
  529. FpGetRLimit := do_syscall(syscall_nr_ugetrlimit,
  530. TSysParam(resource), TSysParam(rlim));
  531. {$endif}
  532. end;
  533. {$ifdef HAS_UGETRLIMIT}
  534. function fpugetrlimit(resource : cInt; rlim : PRLimit) : cInt;
  535. begin
  536. FpUGetRLimit := do_syscall(syscall_nr_ugetrlimit,
  537. TSysParam(resource), TSysParam(rlim));
  538. end;
  539. {$endif}
  540. {$if defined(cpupowerpc)}
  541. { fpprctl() call }
  542. function fpprctl(option : cint; const arg : ptruint) : cint;
  543. begin
  544. fpprctl := do_syscall(syscall_nr_prctl, option, arg);
  545. end;
  546. {$endif}
  547. function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
  548. begin
  549. fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
  550. end;