2
0

ossysc.inc 23 KB

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