ossysc.inc 21 KB

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