2
0

linux.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. BSD parts (c) 2000 by Marco van de Voort
  5. members of the Free Pascal development team.
  6. New linux unit. Linux only calls only. Will be renamed to linux.pp
  7. when 1.0.x support is killed off.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY;without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. unit Linux;
  15. {$packrecords c}
  16. interface
  17. uses
  18. BaseUnix, unixtype;
  19. type
  20. TSysInfo = record
  21. uptime: clong; //* Seconds since boot */
  22. loads: array[0..2] of culong; //* 1, 5, and 15 minute load averages */
  23. totalram: culong; //* Total usable main memory size */
  24. freeram: culong; //* Available memory size */
  25. sharedram: culong; //* Amount of shared memory */
  26. bufferram: culong; //* Memory used by buffers */
  27. totalswap: culong; //* Total swap space size */
  28. freeswap: culong; //* swap space still available */
  29. procs: cushort; //* Number of current processes */
  30. pad: cushort; //* explicit padding for m68k */
  31. totalhigh: culong; //* Total high memory size */
  32. freehigh: culong; //* Available high memory size */
  33. mem_unit: cuint; //* Memory unit size in bytes */
  34. {$ifndef cpu64}
  35. { the upper bound of the array below is negative for 64 bit cpus }
  36. _f: array[0..19-2*sizeof(clong)-sizeof(cint)] of cChar; //* Padding: libc5 uses this.. */
  37. {$endif cpu64}
  38. end;
  39. PSysInfo = ^TSysInfo;
  40. function Sysinfo(Info: PSysinfo): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'sysinfo'; {$endif}
  41. const
  42. CSIGNAL = $000000ff; // signal mask to be sent at exit
  43. CLONE_VM = $00000100; // set if VM shared between processes
  44. CLONE_FS = $00000200; // set if fs info shared between processes
  45. CLONE_FILES = $00000400; // set if open files shared between processes
  46. CLONE_SIGHAND = $00000800; // set if signal handlers shared
  47. CLONE_PID = $00001000; // set if pid shared
  48. CLONE_PTRACE = $00002000; // Set if tracing continues on the child.
  49. CLONE_VFORK = $00004000; // Set if the parent wants the child to wake it up on mm_release.
  50. CLONE_PARENT = $00008000; // Set if we want to have the same parent as the cloner.
  51. CLONE_THREAD = $00010000; // Set to add to same thread group.
  52. CLONE_NEWNS = $00020000; // Set to create new namespace.
  53. CLONE_SYSVSEM = $00040000; // Set to shared SVID SEM_UNDO semantics.
  54. CLONE_SETTLS = $00080000; // Set TLS info.
  55. CLONE_PARENT_SETTID = $00100000; // Store TID in userlevel buffer before MM copy.
  56. CLONE_CHILD_CLEARTID = $00200000; // Register exit futex and memory location to clear.
  57. CLONE_DETACHED = $00400000; // Create clone detached.
  58. CLONE_UNTRACED = $00800000; // Set if the tracing process can't force CLONE_PTRACE on this clone.
  59. CLONE_CHILD_SETTID = $01000000; // Store TID in userlevel buffer in the child.
  60. CLONE_STOPPED = $02000000; // Start in stopped state.
  61. FUTEX_WAIT = 0;
  62. FUTEX_WAKE = 1;
  63. FUTEX_FD = 2;
  64. FUTEX_REQUEUE = 3;
  65. FUTEX_CMP_REQUEUE = 4;
  66. FUTEX_WAKE_OP = 5;
  67. FUTEX_LOCK_PI = 6;
  68. FUTEX_UNLOCK_PI = 7;
  69. FUTEX_TRYLOCK_PI = 8;
  70. FUTEX_OP_SET = 0; // *(int *)UADDR2 = OPARG;
  71. FUTEX_OP_ADD = 1; // *(int *)UADDR2 += OPARG;
  72. FUTEX_OP_OR = 2; // *(int *)UADDR2 |= OPARG;
  73. FUTEX_OP_ANDN = 3; // *(int *)UADDR2 &= ~OPARG;
  74. FUTEX_OP_XOR = 4; // *(int *)UADDR2 ^= OPARG;
  75. FUTEX_OP_OPARG_SHIFT = 8; // Use (1 << OPARG) instead of OPARG.
  76. FUTEX_OP_CMP_EQ = 0; // if (oldval == CMPARG) wake
  77. FUTEX_OP_CMP_NE = 1; // if (oldval != CMPARG) wake
  78. FUTEX_OP_CMP_LT = 2; // if (oldval < CMPARG) wake
  79. FUTEX_OP_CMP_LE = 3; // if (oldval <= CMPARG) wake
  80. FUTEX_OP_CMP_GT = 4; // if (oldval > CMPARG) wake
  81. FUTEX_OP_CMP_GE = 5; // if (oldval >= CMPARG) wake
  82. { FUTEX_WAKE_OP will perform atomically
  83. int oldval = *(int *)UADDR2;
  84. *(int *)UADDR2 = oldval OP OPARG;
  85. if (oldval CMP CMPARG)
  86. wake UADDR2; }
  87. {$ifndef FPC_USE_LIBC}
  88. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  89. function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  90. function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  91. // general aliases:
  92. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  93. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  94. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  95. {$else}
  96. // futex is currently not exposed by glibc
  97. //function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint; cdecl; external name 'futex';
  98. //function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint; cdecl; external name 'futex';
  99. //function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint; cdecl; external name 'futex';
  100. {$endif}
  101. {$ifndef FPC_USE_LIBC}
  102. function futex_op(op, oparg, cmp, cmparg: cint): cint; {$ifdef SYSTEMINLINE}inline;{$endif}
  103. {$endif}
  104. const
  105. POLLMSG = $0400;
  106. POLLREMOVE = $1000;
  107. POLLRDHUP = $2000;
  108. EPOLLIN = $01; { The associated file is available for read(2) operations. }
  109. EPOLLPRI = $02; { There is urgent data available for read(2) operations. }
  110. EPOLLOUT = $04; { The associated file is available for write(2) operations. }
  111. EPOLLERR = $08; { Error condition happened on the associated file descriptor. }
  112. EPOLLHUP = $10; { Hang up happened on the associated file descriptor. }
  113. EPOLLONESHOT = $40000000; { Sets the One-Shot behaviour for the associated file descriptor. }
  114. EPOLLET = $80000000; { Sets the Edge Triggered behaviour for the associated file descriptor. }
  115. { Valid opcodes ( "op" parameter ) to issue to epoll_ctl }
  116. EPOLL_CTL_ADD = 1;
  117. EPOLL_CTL_DEL = 2;
  118. EPOLL_CTL_MOD = 3;
  119. {Some console iotcl's.}
  120. GIO_FONT = $4B60; {gets font in expanded form}
  121. PIO_FONT = $4B61; {use font in expanded form}
  122. GIO_FONTX = $4B6B; {get font using struct consolefontdesc}
  123. PIO_FONTX = $4B6C; {set font using struct consolefontdesc}
  124. PIO_FONTRESET = $4B6D; {reset to default font}
  125. GIO_CMAP = $4B70; {gets colour palette on VGA+}
  126. PIO_CMAP = $4B71; {sets colour palette on VGA+}
  127. KIOCSOUND = $4B2F; {start sound generation (0 for off)}
  128. KDMKTONE = $4B30; {generate tone}
  129. KDGETLED = $4B31; {return current led state}
  130. KDSETLED = $4B32; {set led state [lights, not flags]}
  131. KDGKBTYPE = $4B33; {get keyboard type}
  132. KDADDIO = $4B34; {add i/o port as valid}
  133. KDDELIO = $4B35; {del i/o port as valid}
  134. KDENABIO = $4B36; {enable i/o to video board}
  135. KDDISABIO = $4B37; {disable i/o to video board}
  136. KDSETMODE = $4B3A; {set text/graphics mode}
  137. KDGETMODE = $4B3B; {get current mode}
  138. KDMAPDISP = $4B3C; {map display into address space}
  139. KDUNMAPDISP = $4B3D; {unmap display from address space}
  140. GIO_SCRNMAP = $4B40; {get screen mapping from kernel}
  141. PIO_SCRNMAP = $4B41; {put screen mapping table in kernel}
  142. GIO_UNISCRNMAP = $4B69; {get full Unicode screen mapping}
  143. PIO_UNISCRNMAP = $4B6A; {set full Unicode screen mapping}
  144. GIO_UNIMAP = $4B66; {get unicode-to-font mapping from kernel}
  145. PIO_UNIMAP = $4B67; {put unicode-to-font mapping in kernel}
  146. PIO_UNIMAPCLR = $4B68; {clear table, possibly advise hash algorithm}
  147. KDGKBDIACR = $4B4A; {read kernel accent table}
  148. KDSKBDIACR = $4B4B; {write kernel accent table}
  149. KDGETKEYCODE = $4B4C; {read kernel keycode table entry}
  150. KDSETKEYCODE = $4B4D; {write kernel keycode table entry}
  151. KDSIGACCEPT = $4B4E; {accept kbd generated signals}
  152. KDFONTOP = $4B72; {font operations}
  153. {Keyboard types (for KDGKBTYPE)}
  154. KB_84 = 1;
  155. KB_101 = 2; {Normal PC keyboard.}
  156. KB_OTHER = 3;
  157. {Keyboard LED constants.}
  158. LED_SCR = 1; {scroll lock led}
  159. LED_NUM = 2; {num lock led}
  160. LED_CAP = 4; {caps lock led}
  161. {Tty modes. (for KDSETMODE)}
  162. KD_TEXT = 0;
  163. KD_GRAPHICS = 1;
  164. KD_TEXT0 = 2; {obsolete}
  165. KD_TEXT1 = 3; {obsolete}
  166. MAP_GROWSDOWN = $100; { stack-like segment }
  167. MAP_DENYWRITE = $800; { ETXTBSY }
  168. MAP_EXECUTABLE = $1000; { mark it as an executable }
  169. MAP_LOCKED = $2000; { pages are locked }
  170. MAP_NORESERVE = $4000; { don't check for reservations }
  171. type
  172. TCloneFunc = function(args:pointer):longint;cdecl;
  173. {$ifdef cpui386}
  174. {$define clone_implemented}
  175. {$endif}
  176. {$ifdef clone_implemented}
  177. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clone'; {$endif}
  178. {$endif}
  179. {$ifndef FPC_USE_LIBC}
  180. {$if defined(cpui386) or defined(cpux86_64)}
  181. const
  182. MODIFY_LDT_CONTENTS_DATA = 0;
  183. MODIFY_LDT_CONTENTS_STACK = 1;
  184. MODIFY_LDT_CONTENTS_CODE = 2;
  185. { Flags for user_desc.flags }
  186. UD_SEG_32BIT = $01;
  187. UD_CONTENTS_DATA = MODIFY_LDT_CONTENTS_DATA shl 1;
  188. UD_CONTENTS_STACK = MODIFY_LDT_CONTENTS_STACK shl 1;
  189. UD_CONTENTS_CODE = MODIFY_LDT_CONTENTS_CODE shl 1;
  190. UD_READ_EXEC_ONLY = $08;
  191. UD_LIMIT_IN_PAGES = $10;
  192. UD_SEG_NOT_PRESENT = $20;
  193. UD_USEABLE = $40;
  194. UD_LM = $80;
  195. type
  196. user_desc = record
  197. entry_number : cuint;
  198. base_addr : cuint;
  199. limit : cuint;
  200. flags : cuint;
  201. end;
  202. TUser_Desc = user_desc;
  203. PUser_Desc = ^user_desc;
  204. function modify_ldt(func:cint;p:pointer;bytecount:culong):cint;
  205. {$endif cpui386 or cpux86_64}
  206. {$endif}
  207. procedure sched_yield; {$ifdef FPC_USE_LIBC} cdecl; external name 'sched_yield'; {$endif}
  208. type
  209. EPoll_Data = record
  210. case integer of
  211. 0: (ptr: pointer);
  212. 1: (fd: cint);
  213. 2: (u32: cuint);
  214. 3: (u64: cuint64);
  215. end;
  216. TEPoll_Data = Epoll_Data;
  217. PEPoll_Data = ^Epoll_Data;
  218. EPoll_Event = {$ifdef cpu64} packed {$endif} record
  219. Events: cuint32;
  220. Data : TEpoll_Data;
  221. end;
  222. TEPoll_Event = Epoll_Event;
  223. PEpoll_Event = ^Epoll_Event;
  224. { open an epoll file descriptor }
  225. function epoll_create(size: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_create'; {$endif}
  226. { control interface for an epoll descriptor }
  227. function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_ctl'; {$endif}
  228. { wait for an I/O event on an epoll file descriptor }
  229. function epoll_wait(epfd: cint; events: pepoll_event; maxevents, timeout: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_wait'; {$endif}
  230. type Puser_cap_header=^user_cap_header;
  231. user_cap_header=record
  232. version: cuint32;
  233. pid:cint;
  234. end;
  235. Puser_cap_data=^user_cap_data;
  236. user_cap_data=record
  237. effective,permitted,inheritable:cuint32;
  238. end;
  239. {Get a capability.}
  240. function capget(header:Puser_cap_header;data:Puser_cap_data):cint;{$ifdef FPC_USE_LIBC} cdecl; external name 'capget'; {$endif}
  241. {Set a capability.}
  242. function capset(header:Puser_cap_header;data:Puser_cap_data):cint;{$ifdef FPC_USE_LIBC} cdecl; external name 'capset'; {$endif}
  243. const CAP_CHOWN = 0;
  244. CAP_DAC_OVERRIDE = 1;
  245. CAP_DAC_READ_SEARCH = 2;
  246. CAP_FOWNER = 3;
  247. CAP_FSETID = 4;
  248. CAP_FS_MASK = $1f;
  249. CAP_KILL = 5;
  250. CAP_SETGID = 6;
  251. CAP_SETUID = 7;
  252. CAP_SETPCAP = 8;
  253. CAP_LINUX_IMMUTABLE = 9;
  254. CAP_NET_BIND_SERVICE = 10;
  255. CAP_NET_BROADCAST = 11;
  256. CAP_NET_ADMIN = 12;
  257. CAP_NET_RAW = 13;
  258. CAP_IPC_LOCK = 14;
  259. CAP_IPC_OWNER = 15;
  260. CAP_SYS_MODULE = 16;
  261. CAP_SYS_RAWIO = 17;
  262. CAP_SYS_CHROOT = 18;
  263. CAP_SYS_PTRACE = 19;
  264. CAP_SYS_PACCT = 20;
  265. CAP_SYS_ADMIN = 21;
  266. CAP_SYS_BOOT = 22;
  267. CAP_SYS_NICE = 23;
  268. CAP_SYS_RESOURCE = 24;
  269. CAP_SYS_TIME = 25;
  270. CAP_SYS_TTY_CONFIG = 26;
  271. CAP_MKNOD = 27;
  272. CAP_LEASE = 28;
  273. CAP_AUDIT_WRITE = 29;
  274. CAP_AUDIT_CONTROL = 30;
  275. LINUX_CAPABILITY_VERSION = $19980330;
  276. //***********************************************SPLICE from kernel 2.6.17+****************************************
  277. const
  278. {* Flags for SPLICE and VMSPLICE. *}
  279. SPLICE_F_MOVE = 1; { Move pages instead of copying. }
  280. SPLICE_F_NONBLOCK = 2; {* Don't block on the pipe splicing
  281. (but we may still block on the fd
  282. we splice from/to). *}
  283. SPLICE_F_MORE = 4; {* Expect more data. *}
  284. SPLICE_F_GIFT = 8; {* Pages passed in are a gift. *}
  285. {$ifdef cpu86}
  286. {* Splice address range into a pipe. *}
  287. function vmsplice (fdout: cInt; iov: PIOVec; count: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'vmsplice'; {$ENDIF}
  288. {* Splice two files together. *}
  289. function splice (fdin: cInt; offin: off64_t; fdout: cInt;
  290. offout: off64_t; len: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'splice'; {$ENDIF}
  291. function tee(fd_in: cInt; fd_out: cInt; len: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'tee'; {$ENDIF}
  292. {$endif} // x86
  293. const
  294. { flags for sync_file_range }
  295. SYNC_FILE_RANGE_WAIT_BEFORE = 1;
  296. SYNC_FILE_RANGE_WRITE = 2;
  297. SYNC_FILE_RANGE_WAIT_AFTER = 4;
  298. function sync_file_range(fd: cInt; offset, nbytes: off64_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'sync_file_range'; {$ENDIF}
  299. function fdatasync (fd: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'sync_file_range'; {$ENDIF}
  300. implementation
  301. {$if not defined(FPC_USE_LIBC) or defined(cpui386) or defined(cpux86_64)}
  302. { needed for modify_ldt on x86 }
  303. Uses Syscall;
  304. {$endif not defined(FPC_USE_LIBC) or defined(cpui386) or defined(cpux86_64)}
  305. {$ifndef FPC_USE_LIBC}
  306. function Sysinfo(Info: PSysinfo): cInt;
  307. begin
  308. Sysinfo := do_SysCall(SysCall_nr_Sysinfo, TSysParam(info));
  309. end;
  310. {$ifdef clone_implemented}
  311. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  312. begin
  313. if (pointer(func)=nil) or (sp=nil) then
  314. exit(-1); // give an error result
  315. {$ifdef cpui386}
  316. {$ASMMODE ATT}
  317. asm
  318. { Insert the argument onto the new stack. }
  319. movl sp,%ecx
  320. subl $8,%ecx
  321. movl args,%eax
  322. movl %eax,4(%ecx)
  323. { Save the function pointer as the zeroth argument.
  324. It will be popped off in the child in the ebx frobbing below. }
  325. movl func,%eax
  326. movl %eax,0(%ecx)
  327. { Do the system call }
  328. pushl %ebx
  329. movl flags,%ebx
  330. movl syscall_nr_clone,%eax
  331. int $0x80
  332. popl %ebx
  333. test %eax,%eax
  334. jnz .Lclone_end
  335. { We're in the new thread }
  336. subl %ebp,%ebp { terminate the stack frame }
  337. call *%ebx
  338. { exit process }
  339. movl %eax,%ebx
  340. movl syscall_nr_exit,%eax
  341. int $0x80
  342. .Lclone_end:
  343. movl %eax,__RESULT
  344. end;
  345. {$endif cpui386}
  346. end;
  347. {$endif}
  348. procedure sched_yield;
  349. begin
  350. do_syscall(syscall_nr_sched_yield);
  351. end;
  352. function epoll_create(size: cint): cint;
  353. begin
  354. epoll_create := do_syscall(syscall_nr_epoll_create,tsysparam(size));
  355. end;
  356. function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint;
  357. begin
  358. epoll_ctl := do_syscall(syscall_nr_epoll_ctl, tsysparam(epfd),
  359. tsysparam(op), tsysparam(fd), tsysparam(event));
  360. end;
  361. function epoll_wait(epfd: cint; events: pepoll_event; maxevents, timeout: cint): cint;
  362. begin
  363. epoll_wait := do_syscall(syscall_nr_epoll_wait, tsysparam(epfd),
  364. tsysparam(events), tsysparam(maxevents), tsysparam(timeout));
  365. end;
  366. function capget(header:Puser_cap_header;data:Puser_cap_data):cint;
  367. begin
  368. capget:=do_syscall(syscall_nr_capget,Tsysparam(header),Tsysparam(data));
  369. end;
  370. function capset(header:Puser_cap_header;data:Puser_cap_data):cint;
  371. begin
  372. capset:=do_syscall(syscall_nr_capset,Tsysparam(header),Tsysparam(data));
  373. end;
  374. // TODO: update also on non x86!
  375. {$ifdef cpu86} // didn't update syscall_nr on others yet
  376. function vmsplice (fdout: cInt; iov: PIOVec; count: size_t; flags: cuInt): cInt;
  377. begin
  378. vmsplice := do_syscall(syscall_nr_vmsplice, TSysParam(fdout), TSysParam(iov),
  379. TSysParam(count), TSysParam(flags));
  380. end;
  381. function splice (fdin: cInt; offin: off64_t; fdout: cInt; offout: off64_t; len: size_t; flags: cuInt): cInt;
  382. begin
  383. splice := do_syscall(syscall_nr_splice, TSysParam(fdin), TSysParam(@offin),
  384. TSysParam(fdout), TSysParam(@offout), TSysParam(len), TSysParam(flags));
  385. end;
  386. function tee(fd_in: cInt; fd_out: cInt; len: size_t; flags: cuInt): cInt;
  387. begin
  388. tee := do_syscall(syscall_nr_tee, TSysParam(fd_in), TSysParam(fd_out),
  389. TSysParam(len), TSysParam(flags));
  390. end;
  391. {$endif} // x86
  392. function sync_file_range(fd: cInt; offset: off64_t; nbytes: off64_t; flags: cuInt): cInt;
  393. begin
  394. {$if defined(cpupowerpc) or defined(cpuarm)}
  395. sync_file_range := do_syscall(syscall_nr_sync_file_range2, TSysParam(fd), TSysParam(flags),
  396. TSysParam(hi(offset)), TSysParam(lo(offset)), TSysParam(hi(nbytes)), TSysParam(lo(nbytes)));
  397. {$else}
  398. {$if defined(cpupowerpc64)}
  399. sync_file_range := do_syscall(syscall_nr_sync_file_range2, TSysParam(fd), TSysParam(flags),
  400. TSysParam(offset), TSysParam(nbytes));
  401. {$else}
  402. {$ifdef cpu64}
  403. sync_file_range := do_syscall(syscall_nr_sync_file_range, TSysParam(fd), TSysParam(offset),
  404. TSysParam(nbytes), TSysParam(flags));
  405. {$else}
  406. sync_file_range := do_syscall(syscall_nr_sync_file_range, TSysParam(fd), TSysParam(lo(offset)),
  407. TSysParam(hi(offset)), TSysParam(lo(nbytes)), TSysParam(hi(nbytes)), TSysParam(flags));
  408. {$endif}
  409. {$endif}
  410. {$endif}
  411. end;
  412. function fdatasync (fd: cint): cint;
  413. begin
  414. fdatasync:=do_SysCall(syscall_nr_fdatasync, fd);
  415. end;
  416. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  417. begin
  418. futex:=do_syscall(syscall_nr_futex,Tsysparam(uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout),
  419. Tsysparam(addr2),Tsysparam(val3));
  420. end;
  421. function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  422. begin
  423. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout),
  424. Tsysparam(@addr2),Tsysparam(val3));
  425. end;
  426. function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  427. begin
  428. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(@timeout),
  429. Tsysparam(@addr2),Tsysparam(val3));
  430. end;
  431. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  432. begin
  433. futex:=do_syscall(syscall_nr_futex,Tsysparam(uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout));
  434. end;
  435. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  436. begin
  437. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout));
  438. end;
  439. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  440. begin
  441. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(@timeout));
  442. end;
  443. {$else}
  444. {Libc case.}
  445. (*
  446. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  447. begin
  448. futex:=futex(uaddr,op,val,nil,nil,0);
  449. end;
  450. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  451. begin
  452. futex:=futex(@uaddr,op,val,nil,nil,0);
  453. end;
  454. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  455. begin
  456. futex:=futex(@uaddr,op,val,@timeout,nil,0);
  457. end;
  458. *)
  459. {$endif} // non-libc
  460. {$ifndef FPC_USE_LIBC}
  461. {$if defined(cpui386) or defined(cpux86_64)}
  462. { does not exist as a wrapper in glibc, and exists only for x86 }
  463. function modify_ldt(func:cint;p:pointer;bytecount:culong):cint;
  464. begin
  465. modify_ldt:=do_syscall(syscall_nr_modify_ldt,Tsysparam(func),
  466. Tsysparam(p),
  467. Tsysparam(bytecount));
  468. end;
  469. {$endif}
  470. {$endif}
  471. { FUTEX_OP is a macro, doesn't exist in libC as function}
  472. function FUTEX_OP(op, oparg, cmp, cmparg: cint): cint; {$ifdef SYSTEMINLINE}inline;{$endif}
  473. begin
  474. FUTEX_OP := ((op and $F) shl 28) or ((cmp and $F) shl 24) or ((oparg and $FFF) shl 12) or (cmparg and $FFF);
  475. end;
  476. end.