ossysc.inc 20 KB

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