ossysc.inc 21 KB

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