linux.pp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. {$IFNDEF FPC_DOTTEDUNITS}
  15. unit Linux;
  16. {$ENDIF FPC_DOTTEDUNITS}
  17. {$i osdefs.inc}
  18. {$packrecords c}
  19. {$ifdef FPC_USE_LIBC}
  20. {$linklib rt} // for clock* functions
  21. {$endif}
  22. interface
  23. {$IFDEF FPC_DOTTEDUNITS}
  24. uses
  25. UnixApi.Base, UnixApi.Types;
  26. {$ELSE FPC_DOTTEDUNITS}
  27. uses
  28. BaseUnix, unixtype;
  29. {$ENDIF FPC_DOTTEDUNITS}
  30. const
  31. O_CLOEXEC = $80000;
  32. type
  33. { used by newer Linux headers }
  34. __u16 = Word;
  35. __s16 = Smallint;
  36. __u32 = DWord;
  37. __s32 = Longint;
  38. __u64 = QWord;
  39. __s64 = Int64;
  40. type
  41. TSysInfo = record
  42. uptime: clong; //* Seconds since boot */
  43. loads: array[0..2] of culong; //* 1, 5, and 15 minute load averages */
  44. totalram: culong; //* Total usable main memory size */
  45. freeram: culong; //* Available memory size */
  46. sharedram: culong; //* Amount of shared memory */
  47. bufferram: culong; //* Memory used by buffers */
  48. totalswap: culong; //* Total swap space size */
  49. freeswap: culong; //* swap space still available */
  50. procs: cushort; //* Number of current processes */
  51. pad: cushort; //* explicit padding for m68k */
  52. totalhigh: culong; //* Total high memory size */
  53. freehigh: culong; //* Available high memory size */
  54. mem_unit: cuint; //* Memory unit size in bytes */
  55. {$ifndef cpu64}
  56. { the upper bound of the array below is negative for 64 bit cpus }
  57. _f: array[0..19-2*sizeof(clong)-sizeof(cint)] of cChar; //* Padding: libc5 uses this.. */
  58. {$endif cpu64}
  59. end;
  60. PSysInfo = ^TSysInfo;
  61. function Sysinfo(Info: PSysinfo): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'sysinfo'; {$endif}
  62. const
  63. CSIGNAL = $000000ff; // signal mask to be sent at exit
  64. CLONE_VM = $00000100; // set if VM shared between processes
  65. CLONE_FS = $00000200; // set if fs info shared between processes
  66. CLONE_FILES = $00000400; // set if open files shared between processes
  67. CLONE_SIGHAND = $00000800; // set if signal handlers shared
  68. CLONE_PID = $00001000; // set if pid shared
  69. CLONE_PTRACE = $00002000; // Set if tracing continues on the child.
  70. CLONE_VFORK = $00004000; // Set if the parent wants the child to wake it up on mm_release.
  71. CLONE_PARENT = $00008000; // Set if we want to have the same parent as the cloner.
  72. CLONE_THREAD = $00010000; // Set to add to same thread group.
  73. CLONE_NEWNS = $00020000; // Set to create new namespace.
  74. CLONE_SYSVSEM = $00040000; // Set to shared SVID SEM_UNDO semantics.
  75. CLONE_SETTLS = $00080000; // Set TLS info.
  76. CLONE_PARENT_SETTID = $00100000; // Store TID in userlevel buffer before MM copy.
  77. CLONE_CHILD_CLEARTID = $00200000; // Register exit futex and memory location to clear.
  78. CLONE_DETACHED = $00400000; // Create clone detached.
  79. CLONE_UNTRACED = $00800000; // Set if the tracing process can't force CLONE_PTRACE on this clone.
  80. CLONE_CHILD_SETTID = $01000000; // Store TID in userlevel buffer in the child.
  81. CLONE_STOPPED = $02000000; // Start in stopped state.
  82. FUTEX_WAIT = 0;
  83. FUTEX_WAKE = 1;
  84. FUTEX_FD = 2;
  85. FUTEX_REQUEUE = 3;
  86. FUTEX_CMP_REQUEUE = 4;
  87. FUTEX_WAKE_OP = 5;
  88. FUTEX_LOCK_PI = 6;
  89. FUTEX_UNLOCK_PI = 7;
  90. FUTEX_TRYLOCK_PI = 8;
  91. FUTEX_OP_SET = 0; // *(int *)UADDR2 = OPARG;
  92. FUTEX_OP_ADD = 1; // *(int *)UADDR2 += OPARG;
  93. FUTEX_OP_OR = 2; // *(int *)UADDR2 |= OPARG;
  94. FUTEX_OP_ANDN = 3; // *(int *)UADDR2 &= ~OPARG;
  95. FUTEX_OP_XOR = 4; // *(int *)UADDR2 ^= OPARG;
  96. FUTEX_OP_OPARG_SHIFT = 8; // Use (1 << OPARG) instead of OPARG.
  97. FUTEX_OP_CMP_EQ = 0; // if (oldval == CMPARG) wake
  98. FUTEX_OP_CMP_NE = 1; // if (oldval != CMPARG) wake
  99. FUTEX_OP_CMP_LT = 2; // if (oldval < CMPARG) wake
  100. FUTEX_OP_CMP_LE = 3; // if (oldval <= CMPARG) wake
  101. FUTEX_OP_CMP_GT = 4; // if (oldval > CMPARG) wake
  102. FUTEX_OP_CMP_GE = 5; // if (oldval >= CMPARG) wake
  103. { FUTEX_WAKE_OP will perform atomically
  104. int oldval = *(int *)UADDR2;
  105. *(int *)UADDR2 = oldval OP OPARG;
  106. if (oldval CMP CMPARG)
  107. wake UADDR2; }
  108. {$ifndef FPC_USE_LIBC}
  109. {$ifndef android}
  110. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  111. function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  112. function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  113. // general aliases:
  114. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  115. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  116. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  117. {$endif android}
  118. {$else}
  119. // futex is currently not exposed by glibc
  120. //function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint; cdecl; external name 'futex';
  121. //function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint; cdecl; external name 'futex';
  122. //function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint; cdecl; external name 'futex';
  123. {$endif}
  124. {$ifndef FPC_USE_LIBC}
  125. function futex_op(op, oparg, cmp, cmparg: cint): cint; {$ifdef SYSTEMINLINE}inline;{$endif}
  126. {$endif}
  127. const
  128. POLLMSG = $0400;
  129. POLLREMOVE = $1000;
  130. POLLRDHUP = $2000;
  131. EPOLLIN = $01; { The associated file is available for read(2) operations. }
  132. EPOLLPRI = $02; { There is urgent data available for read(2) operations. }
  133. EPOLLOUT = $04; { The associated file is available for write(2) operations. }
  134. EPOLLERR = $08; { Error condition happened on the associated file descriptor. }
  135. EPOLLHUP = $10; { Hang up happened on the associated file descriptor. }
  136. EPOLLONESHOT = $40000000; { Sets the One-Shot behaviour for the associated file descriptor. }
  137. EPOLLET = $80000000; { Sets the Edge Triggered behaviour for the associated file descriptor. }
  138. { Valid opcodes ( "op" parameter ) to issue to epoll_ctl }
  139. EPOLL_CTL_ADD = 1;
  140. EPOLL_CTL_DEL = 2;
  141. EPOLL_CTL_MOD = 3;
  142. {Some console iotcl's.}
  143. GIO_FONT = $4B60; {gets font in expanded form}
  144. PIO_FONT = $4B61; {use font in expanded form}
  145. GIO_FONTX = $4B6B; {get font using struct consolefontdesc}
  146. PIO_FONTX = $4B6C; {set font using struct consolefontdesc}
  147. PIO_FONTRESET = $4B6D; {reset to default font}
  148. GIO_CMAP = $4B70; {gets colour palette on VGA+}
  149. PIO_CMAP = $4B71; {sets colour palette on VGA+}
  150. KIOCSOUND = $4B2F; {start sound generation (0 for off)}
  151. KDMKTONE = $4B30; {generate tone}
  152. KDGETLED = $4B31; {return current led state}
  153. KDSETLED = $4B32; {set led state [lights, not flags]}
  154. KDGKBTYPE = $4B33; {get keyboard type}
  155. KDADDIO = $4B34; {add i/o port as valid}
  156. KDDELIO = $4B35; {del i/o port as valid}
  157. KDENABIO = $4B36; {enable i/o to video board}
  158. KDDISABIO = $4B37; {disable i/o to video board}
  159. KDSETMODE = $4B3A; {set text/graphics mode}
  160. KDGETMODE = $4B3B; {get current mode}
  161. KDMAPDISP = $4B3C; {map display into address space}
  162. KDUNMAPDISP = $4B3D; {unmap display from address space}
  163. GIO_SCRNMAP = $4B40; {get screen mapping from kernel}
  164. PIO_SCRNMAP = $4B41; {put screen mapping table in kernel}
  165. GIO_UNISCRNMAP = $4B69; {get full Unicode screen mapping}
  166. PIO_UNISCRNMAP = $4B6A; {set full Unicode screen mapping}
  167. GIO_UNIMAP = $4B66; {get unicode-to-font mapping from kernel}
  168. PIO_UNIMAP = $4B67; {put unicode-to-font mapping in kernel}
  169. PIO_UNIMAPCLR = $4B68; {clear table, possibly advise hash algorithm}
  170. KDGKBDIACR = $4B4A; {read kernel accent table}
  171. KDSKBDIACR = $4B4B; {write kernel accent table}
  172. KDGETKEYCODE = $4B4C; {read kernel keycode table entry}
  173. KDSETKEYCODE = $4B4D; {write kernel keycode table entry}
  174. KDSIGACCEPT = $4B4E; {accept kbd generated signals}
  175. KDFONTOP = $4B72; {font operations}
  176. {Keyboard types (for KDGKBTYPE)}
  177. KB_84 = 1;
  178. KB_101 = 2; {Normal PC keyboard.}
  179. KB_OTHER = 3;
  180. {Keyboard LED constants.}
  181. LED_SCR = 1; {scroll lock led}
  182. LED_NUM = 2; {num lock led}
  183. LED_CAP = 4; {caps lock led}
  184. {Tty modes. (for KDSETMODE)}
  185. KD_TEXT = 0;
  186. KD_GRAPHICS = 1;
  187. KD_TEXT0 = 2; {obsolete}
  188. KD_TEXT1 = 3; {obsolete}
  189. {$if defined(cpumips) or defined(cpumipsel)}
  190. MAP_GROWSDOWN = $1000; { stack-like segment }
  191. MAP_DENYWRITE = $2000; { ETXTBSY }
  192. MAP_EXECUTABLE = $4000; { mark it as an executable }
  193. MAP_LOCKED = $8000; { pages are locked }
  194. MAP_NORESERVE = $4000; { don't check for reservations; not defined for linux/mips? }
  195. {$else cpumips}
  196. MAP_GROWSDOWN = $100; { stack-like segment }
  197. MAP_DENYWRITE = $800; { ETXTBSY }
  198. MAP_EXECUTABLE = $1000; { mark it as an executable }
  199. MAP_LOCKED = $2000; { pages are locked }
  200. MAP_NORESERVE = $4000; { don't check for reservations }
  201. {$endif cpumips}
  202. type
  203. TCloneFunc = function(args:pointer):longint;cdecl;
  204. {$ifdef cpui386}
  205. {$define clone_implemented}
  206. {$endif}
  207. {$ifdef clone_implemented}
  208. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clone'; {$endif}
  209. {$endif}
  210. {$if not defined(FPC_USE_LIBC) and not defined(android)}
  211. {$if defined(cpui386) or defined(cpux86_64)}
  212. const
  213. MODIFY_LDT_CONTENTS_DATA = 0;
  214. MODIFY_LDT_CONTENTS_STACK = 1;
  215. MODIFY_LDT_CONTENTS_CODE = 2;
  216. { Flags for user_desc.flags }
  217. UD_SEG_32BIT = $01;
  218. UD_CONTENTS_DATA = MODIFY_LDT_CONTENTS_DATA shl 1;
  219. UD_CONTENTS_STACK = MODIFY_LDT_CONTENTS_STACK shl 1;
  220. UD_CONTENTS_CODE = MODIFY_LDT_CONTENTS_CODE shl 1;
  221. UD_READ_EXEC_ONLY = $08;
  222. UD_LIMIT_IN_PAGES = $10;
  223. UD_SEG_NOT_PRESENT = $20;
  224. UD_USEABLE = $40;
  225. UD_LM = $80;
  226. type
  227. user_desc = record
  228. entry_number : cuint;
  229. base_addr : cuint;
  230. limit : cuint;
  231. flags : cuint;
  232. end;
  233. TUser_Desc = user_desc;
  234. PUser_Desc = ^user_desc;
  235. function modify_ldt(func:cint;p:pointer;bytecount:culong):cint;
  236. {$endif cpui386 or cpux86_64}
  237. {$endif}
  238. procedure sched_yield; {$ifdef FPC_USE_LIBC} cdecl; external name 'sched_yield'; {$endif}
  239. type
  240. EPoll_Data = record
  241. case integer of
  242. 0: (ptr: pointer);
  243. 1: (fd: cint);
  244. 2: (u32: cuint);
  245. 3: (u64: cuint64);
  246. end;
  247. TEPoll_Data = Epoll_Data;
  248. PEPoll_Data = ^Epoll_Data;
  249. { x86_64 uses a packed record so it is compatible with i386 }
  250. EPoll_Event = {$ifdef cpux86_64} packed {$endif} record
  251. Events: cuint32;
  252. Data : TEpoll_Data;
  253. end;
  254. TEPoll_Event = Epoll_Event;
  255. PEpoll_Event = ^Epoll_Event;
  256. { open an epoll file descriptor }
  257. function epoll_create(size: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_create'; {$endif}
  258. function epoll_create1(flags: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_create1'; {$endif}
  259. { control interface for an epoll descriptor }
  260. function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_ctl'; {$endif}
  261. { wait for an I/O event on an epoll file descriptor }
  262. function epoll_wait(epfd: cint; events: pepoll_event; maxevents, timeout: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_wait'; {$endif}
  263. function epoll_pwait(epfd: cint; events: pepoll_event; maxevents, timeout: cint; sigmask: PSigSet): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'epoll_pwait'; {$endif}
  264. type Puser_cap_header=^user_cap_header;
  265. user_cap_header=record
  266. version: cuint32;
  267. pid:cint;
  268. end;
  269. Puser_cap_data=^user_cap_data;
  270. user_cap_data=record
  271. effective,permitted,inheritable:cuint32;
  272. end;
  273. {Get a capability.}
  274. function capget(header:Puser_cap_header;data:Puser_cap_data):cint;{$ifdef FPC_USE_LIBC} cdecl; external name 'capget'; {$endif}
  275. {Set a capability.}
  276. function capset(header:Puser_cap_header;data:Puser_cap_data):cint;{$ifdef FPC_USE_LIBC} cdecl; external name 'capset'; {$endif}
  277. const CAP_CHOWN = 0;
  278. CAP_DAC_OVERRIDE = 1;
  279. CAP_DAC_READ_SEARCH = 2;
  280. CAP_FOWNER = 3;
  281. CAP_FSETID = 4;
  282. CAP_FS_MASK = $1f;
  283. CAP_KILL = 5;
  284. CAP_SETGID = 6;
  285. CAP_SETUID = 7;
  286. CAP_SETPCAP = 8;
  287. CAP_LINUX_IMMUTABLE = 9;
  288. CAP_NET_BIND_SERVICE = 10;
  289. CAP_NET_BROADCAST = 11;
  290. CAP_NET_ADMIN = 12;
  291. CAP_NET_RAW = 13;
  292. CAP_IPC_LOCK = 14;
  293. CAP_IPC_OWNER = 15;
  294. CAP_SYS_MODULE = 16;
  295. CAP_SYS_RAWIO = 17;
  296. CAP_SYS_CHROOT = 18;
  297. CAP_SYS_PTRACE = 19;
  298. CAP_SYS_PACCT = 20;
  299. CAP_SYS_ADMIN = 21;
  300. CAP_SYS_BOOT = 22;
  301. CAP_SYS_NICE = 23;
  302. CAP_SYS_RESOURCE = 24;
  303. CAP_SYS_TIME = 25;
  304. CAP_SYS_TTY_CONFIG = 26;
  305. CAP_MKNOD = 27;
  306. CAP_LEASE = 28;
  307. CAP_AUDIT_WRITE = 29;
  308. CAP_AUDIT_CONTROL = 30;
  309. LINUX_CAPABILITY_VERSION = $19980330;
  310. //***********************************************SPLICE from kernel 2.6.17+****************************************
  311. {$ifndef android}
  312. const
  313. {* Flags for SPLICE and VMSPLICE. *}
  314. SPLICE_F_MOVE = 1; { Move pages instead of copying. }
  315. SPLICE_F_NONBLOCK = 2; {* Don't block on the pipe splicing
  316. (but we may still block on the fd
  317. we splice from/to). *}
  318. SPLICE_F_MORE = 4; {* Expect more data. *}
  319. SPLICE_F_GIFT = 8; {* Pages passed in are a gift. *}
  320. {$ifdef cpu86}
  321. {* Splice address range into a pipe. *}
  322. function vmsplice (fdout: cInt; iov: PIOVec; count: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'vmsplice'; {$ENDIF}
  323. {* Splice two files together. *}
  324. function splice (fdin: cInt; offin: off64_t; fdout: cInt;
  325. offout: off64_t; len: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'splice'; {$ENDIF}
  326. function tee(fd_in: cInt; fd_out: cInt; len: size_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'tee'; {$ENDIF}
  327. {$endif} // x86
  328. {$endif android}
  329. {$ifndef android}
  330. const
  331. { flags for sync_file_range }
  332. SYNC_FILE_RANGE_WAIT_BEFORE = 1;
  333. SYNC_FILE_RANGE_WRITE = 2;
  334. SYNC_FILE_RANGE_WAIT_AFTER = 4;
  335. function sync_file_range(fd: cInt; offset, nbytes: off64_t; flags: cuInt): cInt; {$ifdef FPC_USE_LIBC} cdecl; external name 'sync_file_range'; {$ENDIF}
  336. {$endif android}
  337. function fdatasync (fd: cint): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'sync_file_range'; {$ENDIF}
  338. {$PACKRECORDS 1}
  339. { Flags for the parameter of inotify_init1. }
  340. Const
  341. IN_CLOEXEC = &02000000;
  342. IN_NONBLOCK = &00004000;
  343. Type
  344. inotify_event = record
  345. wd : cint;
  346. mask : cuint32;
  347. cookie : cuint32;
  348. len : cuint32;
  349. name : AnsiChar;
  350. end;
  351. Pinotify_event = ^inotify_event;
  352. { Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH. }
  353. const
  354. IN_ACCESS = $00000001; { File was accessed. }
  355. IN_MODIFY = $00000002; { File was modified. }
  356. IN_ATTRIB = $00000004; { Metadata changed. }
  357. IN_CLOSE_WRITE = $00000008; { Writtable file was closed. }
  358. IN_CLOSE_NOWRITE = $00000010; { Unwrittable file closed. }
  359. IN_OPEN = $00000020; { File was opened. }
  360. IN_MOVED_FROM = $00000040; { File was moved from X. }
  361. IN_MOVED_TO = $00000080; { File was moved to Y. }
  362. IN_CLOSE = IN_CLOSE_WRITE or IN_CLOSE_NOWRITE; { Close. }
  363. IN_MOVE = IN_MOVED_FROM or IN_MOVED_TO; { Moves. }
  364. IN_CREATE = $00000100; { Subfile was created. }
  365. IN_DELETE = $00000200; { Subfile was deleted. }
  366. IN_DELETE_SELF = $00000400; { Self was deleted. }
  367. IN_MOVE_SELF = $00000800; { Self was moved. }
  368. { Events sent by the kernel. }
  369. IN_UNMOUNT = $00002000; { Backing fs was unmounted. }
  370. IN_Q_OVERFLOW = $00004000; { Event queued overflowed. }
  371. IN_IGNORED = $00008000; { File was ignored. }
  372. { Special flags. }
  373. IN_ONLYDIR = $01000000; { Only watch the path if it is a directory. }
  374. IN_DONT_FOLLOW = $02000000; { Do not follow a sym link. }
  375. IN_MASK_ADD = $20000000; { Add to the mask of an already existing watch. }
  376. IN_ISDIR = $40000000; { Event occurred against dir. }
  377. IN_ONESHOT = $80000000; { Only send event once. }
  378. { All events which a program can wait on. }
  379. IN_ALL_EVENTS = IN_ACCESS or IN_MODIFY or IN_ATTRIB or IN_CLOSE
  380. or IN_OPEN or IN_MOVE or IN_CREATE or IN_DELETE
  381. or IN_DELETE_SELF or IN_MOVE_SELF;
  382. // these have _THROW in the header.
  383. { Create and initialize inotify instance. }
  384. function inotify_init: cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_init'; {$ENDIF}
  385. { Create and initialize inotify instance. }
  386. function inotify_init1(flags:cint):cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_init1'; {$ENDIF}
  387. { Add watch of object NAME to inotify instance FD.
  388. Notify about events specified by MASK. }
  389. function inotify_add_watch(fd:cint; name:PAnsiChar; mask:cuint32):cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_add_watch'; {$ENDIF}
  390. { Remove the watch specified by WD from the inotify instance FD. }
  391. function inotify_rm_watch(fd:cint; wd: cint):cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'inotify_rm_watch'; {$ENDIF}
  392. { clock_gettime, clock_settime, clock_getres }
  393. Const
  394. // Taken from linux/time.h
  395. // Posix timers
  396. CLOCK_REALTIME = 0;
  397. CLOCK_MONOTONIC = 1;
  398. CLOCK_PROCESS_CPUTIME_ID = 2;
  399. CLOCK_THREAD_CPUTIME_ID = 3;
  400. CLOCK_MONOTONIC_RAW = 4;
  401. CLOCK_REALTIME_COARSE = 5;
  402. CLOCK_MONOTONIC_COARSE = 6;
  403. // Linux specific
  404. CLOCK_SGI_CYCLE = 10;
  405. MAX_CLOCKS = 16;
  406. CLOCKS_MASK = CLOCK_REALTIME or CLOCK_MONOTONIC;
  407. CLOCKS_MONO = CLOCK_MONOTONIC;
  408. Type
  409. clockid_t = cint;
  410. // FPC_USE_LIBC unchecked, just to get it compiling again.
  411. function clock_getres(clk_id : clockid_t; res : ptimespec) : cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_getres'; {$ENDIF}
  412. function clock_gettime(clk_id : clockid_t; tp: ptimespec) : cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_gettime'; {$ENDIF}
  413. function clock_settime(clk_id : clockid_t; tp : ptimespec) : cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'clock_settime'; {$ENDIF}
  414. function setregid(rgid,egid : uid_t): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'setregid'; {$ENDIF}
  415. function setreuid(ruid,euid : uid_t): cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'setreuid'; {$ENDIF}
  416. Const
  417. STATX_TYPE = $00000001;
  418. STATX_MODE = $00000002;
  419. STATX_NLINK = $00000004;
  420. STATX_UID = $00000008;
  421. STATX_GID = $00000010;
  422. STATX_ATIME = $00000020;
  423. STATX_MTIME = $00000040;
  424. STATX_CTIME = $00000080;
  425. STATX_INO = $00000100;
  426. STATX_SIZE = $00000200;
  427. STATX_BLOCKS = $00000400;
  428. STATX_BASIC_STATS = $000007ff;
  429. STATX_BTIME = $00000800;
  430. STATX_ALL = $00000fff;
  431. STATX__RESERVED = $80000000;
  432. STATX_ATTR_COMPRESSED = $00000004;
  433. STATX_ATTR_IMMUTABLE = $00000010;
  434. STATX_ATTR_APPEND = $00000020;
  435. STATX_ATTR_NODUMP = $00000040;
  436. STATX_ATTR_ENCRYPTED = $00000800;
  437. STATX_ATTR_AUTOMOUNT = $00001000;
  438. Type
  439. statx_timestamp = record
  440. tv_sec : __s64;
  441. tv_nsec : __u32;
  442. __reserved : __s32;
  443. end;
  444. pstatx_timestamp = ^statx_timestamp;
  445. tstatx = record
  446. stx_mask : __u32;
  447. stx_blksize : __u32;
  448. stx_attributes : __u64;
  449. stx_nlink : __u32;
  450. stx_uid : __u32;
  451. stx_gid : __u32;
  452. stx_mode : __u16;
  453. __spare0 : array[0..0] of __u16;
  454. stx_ino : __u64;
  455. stx_size : __u64;
  456. stx_blocks : __u64;
  457. stx_attributes_mask : __u64;
  458. stx_atime : statx_timestamp;
  459. stx_btime : statx_timestamp;
  460. stx_ctime : statx_timestamp;
  461. stx_mtime : statx_timestamp;
  462. stx_rdev_major : __u32;
  463. stx_rdev_minor : __u32;
  464. stx_dev_major : __u32;
  465. stx_dev_minor : __u32;
  466. __spare2 : array[0..13] of __u64;
  467. end;
  468. pstatx = ^tstatx;
  469. function statx(dfd: cint; filename: PAnsiChar; flags,mask: cuint; var buf: tstatx):cint; {$ifdef FPC_USE_LIBC} cdecl; weakexternal name 'statx'; {$ENDIF}
  470. Function utimensat(dfd: cint; path:PAnsiChar;const times:TTimespecArr;flags:cint):cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'utimensat'; {$ENDIF}
  471. Function futimens(fd: cint; const times:TTimespecArr):cint; {$ifdef FPC_USE_LIBC} cdecl; external name 'futimens'; {$ENDIF}
  472. {$if defined(cpuriscv)}
  473. type
  474. priscv_hwprobe = ^triscv_hwprobe;
  475. triscv_hwprobe = record
  476. key : __s64;
  477. value : __u64;
  478. end;
  479. const
  480. RISCV_HWPROBE_KEY_MVENDORID = 0;
  481. RISCV_HWPROBE_KEY_MARCHID = 1;
  482. RISCV_HWPROBE_KEY_MIMPID = 2;
  483. RISCV_HWPROBE_KEY_BASE_BEHAVIOR = 3;
  484. RISCV_HWPROBE_BASE_BEHAVIOR_IMA = 1 shl 0;
  485. RISCV_HWPROBE_KEY_IMA_EXT_0 = 4;
  486. RISCV_HWPROBE_IMA_FD = 1 shl 0;
  487. RISCV_HWPROBE_IMA_C = 1 shl 1;
  488. RISCV_HWPROBE_IMA_V = 1 shl 2;
  489. RISCV_HWPROBE_EXT_ZBA = 1 shl 3;
  490. RISCV_HWPROBE_EXT_ZBB = 1 shl 4;
  491. RISCV_HWPROBE_EXT_ZBS = 1 shl 5;
  492. RISCV_HWPROBE_EXT_ZICBOZ = 1 shl 6;
  493. RISCV_HWPROBE_EXT_ZBC = 1 shl 7;
  494. RISCV_HWPROBE_EXT_ZBKB = 1 shl 8;
  495. RISCV_HWPROBE_EXT_ZBKC = 1 shl 9;
  496. RISCV_HWPROBE_EXT_ZBKX = 1 shl 10;
  497. RISCV_HWPROBE_EXT_ZKND = 1 shl 11;
  498. RISCV_HWPROBE_EXT_ZKNE = 1 shl 12;
  499. RISCV_HWPROBE_EXT_ZKNH = 1 shl 13;
  500. RISCV_HWPROBE_EXT_ZKSED = 1 shl 14;
  501. RISCV_HWPROBE_EXT_ZKSH = 1 shl 15;
  502. RISCV_HWPROBE_EXT_ZKT = 1 shl 16;
  503. RISCV_HWPROBE_EXT_ZVBB = 1 shl 17;
  504. RISCV_HWPROBE_EXT_ZVBC = 1 shl 18;
  505. RISCV_HWPROBE_EXT_ZVKB = 1 shl 19;
  506. RISCV_HWPROBE_EXT_ZVKG = 1 shl 20;
  507. RISCV_HWPROBE_EXT_ZVKNED = 1 shl 21;
  508. RISCV_HWPROBE_EXT_ZVKNHA = 1 shl 22;
  509. RISCV_HWPROBE_EXT_ZVKNHB = 1 shl 23;
  510. RISCV_HWPROBE_EXT_ZVKSED = 1 shl 24;
  511. RISCV_HWPROBE_EXT_ZVKSH = 1 shl 25;
  512. RISCV_HWPROBE_EXT_ZVKT = 1 shl 26;
  513. RISCV_HWPROBE_EXT_ZFH = 1 shl 27;
  514. RISCV_HWPROBE_EXT_ZFHMIN = 1 shl 28;
  515. RISCV_HWPROBE_EXT_ZIHINTNTL = 1 shl 29;
  516. RISCV_HWPROBE_EXT_ZVFH = 1 shl 30;
  517. RISCV_HWPROBE_EXT_ZVFHMIN = 1 shl 31;
  518. RISCV_HWPROBE_EXT_ZFA = 1 shl 32;
  519. RISCV_HWPROBE_EXT_ZTSO = 1 shl 33;
  520. RISCV_HWPROBE_EXT_ZACAS = 1 shl 34;
  521. RISCV_HWPROBE_EXT_ZICOND = 1 shl 35;
  522. RISCV_HWPROBE_EXT_ZIHINTPAUSE = 1 shl 36;
  523. RISCV_HWPROBE_EXT_ZVE32X = 1 shl 37;
  524. RISCV_HWPROBE_EXT_ZVE32F = 1 shl 38;
  525. RISCV_HWPROBE_EXT_ZVE64X = 1 shl 39;
  526. RISCV_HWPROBE_EXT_ZVE64F = 1 shl 40;
  527. RISCV_HWPROBE_EXT_ZVE64D = 1 shl 41;
  528. RISCV_HWPROBE_EXT_ZIMOP = 1 shl 42;
  529. RISCV_HWPROBE_EXT_ZCA = 1 shl 43;
  530. RISCV_HWPROBE_EXT_ZCB = 1 shl 44;
  531. RISCV_HWPROBE_EXT_ZCD = 1 shl 45;
  532. RISCV_HWPROBE_EXT_ZCF = 1 shl 46;
  533. RISCV_HWPROBE_EXT_ZCMOP = 1 shl 47;
  534. RISCV_HWPROBE_EXT_ZAWRS = 1 shl 48;
  535. RISCV_HWPROBE_EXT_SUPM = 1 shl 49;
  536. RISCV_HWPROBE_KEY_CPUPERF_0 = 5;
  537. RISCV_HWPROBE_MISALIGNED_UNKNOWN = 0 shl 0;
  538. RISCV_HWPROBE_MISALIGNED_EMULATED = 1 shl 0;
  539. RISCV_HWPROBE_MISALIGNED_SLOW = 2 shl 0;
  540. RISCV_HWPROBE_MISALIGNED_FAST = 3 shl 0;
  541. RISCV_HWPROBE_MISALIGNED_UNSUPPORTED = 4 shl 0;
  542. RISCV_HWPROBE_MISALIGNED_MASK = 7 shl 0;
  543. RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE = 6;
  544. RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS = 7;
  545. RISCV_HWPROBE_KEY_TIME_CSR_FREQ = 8;
  546. RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF = 9;
  547. RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN = 0;
  548. RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED = 1;
  549. RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW = 2;
  550. RISCV_HWPROBE_MISALIGNED_SCALAR_FAST = 3;
  551. RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED = 4;
  552. RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF = 10;
  553. RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN = 0;
  554. RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW = 2;
  555. RISCV_HWPROBE_MISALIGNED_VECTOR_FAST = 3;
  556. RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED = 4;
  557. RISCV_HWPROBE_WHICH_CPUS = 1 shl 0;
  558. function riscv_hwprobe(pairs:priscv_hwprobe; pair_count:size_t; cpusetsize:size_t; cpus:pdword; flags:dword):longint;
  559. {$ifdef FPC_USE_LIBC}
  560. cdecl; external name '__riscv_hwprobe';
  561. {$endif}
  562. {$endif defined(cpuriscv)}
  563. implementation
  564. {$if not defined(FPC_USE_LIBC) or defined(cpui386) or defined(cpux86_64)}
  565. { needed for modify_ldt on x86 }
  566. {$IFDEF FPC_DOTTEDUNITS}
  567. Uses UnixApi.SysCall;
  568. {$ELSE FPC_DOTTEDUNITS}
  569. Uses Syscall;
  570. {$ENDIF FPC_DOTTEDUNITS}
  571. {$endif not defined(FPC_USE_LIBC) or defined(cpui386) or defined(cpux86_64)}
  572. {$ifndef FPC_USE_LIBC}
  573. function Sysinfo(Info: PSysinfo): cInt;
  574. begin
  575. Sysinfo := do_SysCall(SysCall_nr_Sysinfo, TSysParam(info));
  576. end;
  577. {$ifdef clone_implemented}
  578. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  579. begin
  580. if (pointer(func)=nil) or (sp=nil) then
  581. exit(-1); // give an error result
  582. {$ifdef cpui386}
  583. {$ASMMODE ATT}
  584. asm
  585. { Insert the argument onto the new stack. }
  586. movl sp,%ecx
  587. subl $8,%ecx
  588. movl args,%eax
  589. movl %eax,4(%ecx)
  590. { Save the function pointer as the zeroth argument.
  591. It will be popped off in the child in the ebx frobbing below. }
  592. movl func,%eax
  593. movl %eax,0(%ecx)
  594. { Do the system call }
  595. pushl %ebx
  596. movl flags,%ebx
  597. movl syscall_nr_clone,%eax
  598. int $0x80
  599. popl %ebx
  600. test %eax,%eax
  601. jnz .Lclone_end
  602. { We're in the new thread }
  603. subl %ebp,%ebp { terminate the stack frame }
  604. call *%ebx
  605. { exit process }
  606. movl %eax,%ebx
  607. movl syscall_nr_exit,%eax
  608. int $0x80
  609. .Lclone_end:
  610. movl %eax,__RESULT
  611. end;
  612. {$endif cpui386}
  613. end;
  614. {$endif}
  615. procedure sched_yield;
  616. begin
  617. do_syscall(syscall_nr_sched_yield);
  618. end;
  619. function epoll_create(size: cint): cint;
  620. begin
  621. {$if defined(generic_linux_syscalls)}
  622. epoll_create := do_syscall(syscall_nr_epoll_create1,0);
  623. {$else}
  624. epoll_create := do_syscall(syscall_nr_epoll_create,tsysparam(size));
  625. {$endif}
  626. end;
  627. function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint;
  628. begin
  629. epoll_ctl := do_syscall(syscall_nr_epoll_ctl, tsysparam(epfd),
  630. tsysparam(op), tsysparam(fd), tsysparam(event));
  631. end;
  632. function epoll_wait(epfd: cint; events: pepoll_event; maxevents, timeout: cint): cint;
  633. begin
  634. {$if defined(generic_linux_syscalls)}
  635. epoll_wait := do_syscall(syscall_nr_epoll_pwait, tsysparam(epfd),
  636. tsysparam(events), tsysparam(maxevents), tsysparam(timeout),0,sizeof(TSigSet));
  637. {$else}
  638. epoll_wait := do_syscall(syscall_nr_epoll_wait, tsysparam(epfd),
  639. tsysparam(events), tsysparam(maxevents), tsysparam(timeout));
  640. {$endif}
  641. end;
  642. function epoll_create1(flags: cint): cint;
  643. begin
  644. epoll_create1 := do_syscall(syscall_nr_epoll_create1, tsysparam(flags));
  645. end;
  646. function epoll_pwait(epfd: cint; events: pepoll_event; maxevents, timeout: cint; sigmask: PSigSet): cint;
  647. begin
  648. epoll_pwait := do_syscall(syscall_nr_epoll_pwait, tsysparam(epfd),
  649. tsysparam(events), tsysparam(maxevents), tsysparam(timeout), tsysparam(sigmask), sizeof(TSigSet));
  650. end;
  651. function capget(header:Puser_cap_header;data:Puser_cap_data):cint;
  652. begin
  653. capget:=do_syscall(syscall_nr_capget,Tsysparam(header),Tsysparam(data));
  654. end;
  655. function capset(header:Puser_cap_header;data:Puser_cap_data):cint;
  656. begin
  657. capset:=do_syscall(syscall_nr_capset,Tsysparam(header),Tsysparam(data));
  658. end;
  659. {$ifndef android}
  660. // TODO: update also on non x86!
  661. {$ifdef cpu86} // didn't update syscall_nr on others yet
  662. function vmsplice (fdout: cInt; iov: PIOVec; count: size_t; flags: cuInt): cInt;
  663. begin
  664. vmsplice := do_syscall(syscall_nr_vmsplice, TSysParam(fdout), TSysParam(iov),
  665. TSysParam(count), TSysParam(flags));
  666. end;
  667. function splice (fdin: cInt; offin: off64_t; fdout: cInt; offout: off64_t; len: size_t; flags: cuInt): cInt;
  668. begin
  669. splice := do_syscall(syscall_nr_splice, TSysParam(fdin), TSysParam(@offin),
  670. TSysParam(fdout), TSysParam(@offout), TSysParam(len), TSysParam(flags));
  671. end;
  672. function tee(fd_in: cInt; fd_out: cInt; len: size_t; flags: cuInt): cInt;
  673. begin
  674. tee := do_syscall(syscall_nr_tee, TSysParam(fd_in), TSysParam(fd_out),
  675. TSysParam(len), TSysParam(flags));
  676. end;
  677. {$endif} // x86
  678. function sync_file_range(fd: cInt; offset: off64_t; nbytes: off64_t; flags: cuInt): cInt;
  679. begin
  680. {$if defined(cpupowerpc) or defined(cpuarm) or defined(cpuxtensa)}
  681. sync_file_range := do_syscall(syscall_nr_sync_file_range2, TSysParam(fd), TSysParam(flags),
  682. TSysParam(hi(offset)), TSysParam(lo(offset)), TSysParam(hi(nbytes)), TSysParam(lo(nbytes)));
  683. {$else}
  684. {$if defined(cpupowerpc64)}
  685. sync_file_range := do_syscall(syscall_nr_sync_file_range2, TSysParam(fd), TSysParam(flags),
  686. TSysParam(offset), TSysParam(nbytes));
  687. {$else}
  688. {$ifdef cpu64}
  689. sync_file_range := do_syscall(syscall_nr_sync_file_range, TSysParam(fd), TSysParam(offset),
  690. TSysParam(nbytes), TSysParam(flags));
  691. {$else}
  692. sync_file_range := do_syscall(syscall_nr_sync_file_range, TSysParam(fd), TSysParam(lo(offset)),
  693. TSysParam(hi(offset)), TSysParam(lo(nbytes)), TSysParam(hi(nbytes)), TSysParam(flags));
  694. {$endif}
  695. {$endif}
  696. {$endif}
  697. end;
  698. {$endif android}
  699. function fdatasync (fd: cint): cint;
  700. begin
  701. fdatasync:=do_SysCall(syscall_nr_fdatasync, fd);
  702. end;
  703. {$ifndef android}
  704. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec;addr2:Pcint;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  705. begin
  706. futex:=do_syscall(syscall_nr_futex,Tsysparam(uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout),
  707. Tsysparam(addr2),Tsysparam(val3));
  708. end;
  709. function futex(var uaddr;op,val:cint;timeout:Ptimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  710. begin
  711. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout),
  712. Tsysparam(@addr2),Tsysparam(val3));
  713. end;
  714. function futex(var uaddr;op,val:cint;var timeout:Ttimespec;var addr2;val3:cint):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  715. begin
  716. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(@timeout),
  717. Tsysparam(@addr2),Tsysparam(val3));
  718. end;
  719. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  720. begin
  721. futex:=do_syscall(syscall_nr_futex,Tsysparam(uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout));
  722. end;
  723. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  724. begin
  725. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(timeout));
  726. end;
  727. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  728. begin
  729. futex:=do_syscall(syscall_nr_futex,Tsysparam(@uaddr),Tsysparam(op),Tsysparam(val),Tsysparam(@timeout));
  730. end;
  731. {$endif android}
  732. {$else}
  733. {Libc case.}
  734. (*
  735. function futex(uaddr:Pcint;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  736. begin
  737. futex:=futex(uaddr,op,val,nil,nil,0);
  738. end;
  739. function futex(var uaddr;op,val:cint;timeout:Ptimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  740. begin
  741. futex:=futex(@uaddr,op,val,nil,nil,0);
  742. end;
  743. function futex(var uaddr;op,val:cint;var timeout:Ttimespec):cint;{$ifdef SYSTEMINLINE}inline;{$endif}
  744. begin
  745. futex:=futex(@uaddr,op,val,@timeout,nil,0);
  746. end;
  747. *)
  748. {$endif} // non-libc
  749. {$if not defined(FPC_USE_LIBC) and not defined(android)}
  750. {$if defined(cpui386) or defined(cpux86_64)}
  751. { does not exist as a wrapper in glibc, and exists only for x86 }
  752. function modify_ldt(func:cint;p:pointer;bytecount:culong):cint;
  753. begin
  754. modify_ldt:=do_syscall(syscall_nr_modify_ldt,Tsysparam(func),
  755. Tsysparam(p),
  756. Tsysparam(bytecount));
  757. end;
  758. {$endif}
  759. {$endif}
  760. { FUTEX_OP is a macro, doesn't exist in libC as function}
  761. function FUTEX_OP(op, oparg, cmp, cmparg: cint): cint; {$ifdef SYSTEMINLINE}inline;{$endif}
  762. begin
  763. FUTEX_OP := ((op and $F) shl 28) or ((cmp and $F) shl 24) or ((oparg and $FFF) shl 12) or (cmparg and $FFF);
  764. end;
  765. {$ifndef FPC_USE_LIBC}
  766. function inotify_init:cint;
  767. begin
  768. inotify_init:=inotify_init1(0);
  769. end;
  770. function inotify_init1(flags:cint):cint;
  771. begin
  772. {$if defined(generic_linux_syscalls)}
  773. inotify_init1:=do_SysCall(syscall_nr_inotify_init1,tsysparam(flags));
  774. {$else}
  775. inotify_init1:=do_SysCall(syscall_nr_inotify_init,tsysparam(flags));
  776. {$endif}
  777. end;
  778. function inotify_add_watch(fd:cint; name:PAnsiChar; mask:cuint32):cint;
  779. begin
  780. inotify_add_watch:=do_SysCall(syscall_nr_inotify_add_watch,tsysparam(fd),tsysparam(name),tsysparam(mask));
  781. end;
  782. function inotify_rm_watch(fd:cint; wd:cint):cint;
  783. begin
  784. inotify_rm_watch:=do_SysCall(syscall_nr_inotify_rm_watch,tsysparam(fd),tsysparam(wd));
  785. end;
  786. function clock_getres(clk_id : clockid_t; res : ptimespec) : cint;
  787. begin
  788. clock_getres:=do_SysCall(syscall_nr_clock_getres,tsysparam(clk_id),tsysparam(res));
  789. end;
  790. function clock_gettime(clk_id : clockid_t; tp: ptimespec) : cint;
  791. begin
  792. clock_gettime:=do_SysCall(syscall_nr_clock_gettime,tsysparam(clk_id),tsysparam(tp));
  793. end;
  794. function clock_settime(clk_id : clockid_t; tp : ptimespec) : cint;
  795. begin
  796. clock_settime:=do_SysCall(syscall_nr_clock_settime,tsysparam(clk_id),tsysparam(tp));
  797. end;
  798. function setregid(rgid,egid : uid_t): cint;
  799. begin
  800. setregid:=do_syscall(syscall_nr_setregid,rgid,egid);
  801. end;
  802. function setreuid(ruid,euid : uid_t): cint;
  803. begin
  804. setreuid:=do_syscall(syscall_nr_setreuid,ruid,euid);
  805. end;
  806. function statx(dfd: cint; filename: PAnsiChar; flags,mask: cuint; var buf: tstatx):cint;
  807. begin
  808. statx:=do_syscall(syscall_nr_statx,TSysParam(dfd),TSysParam(filename),TSysParam(flags),TSysParam(mask),TSysParam(@buf));
  809. end;
  810. { on 32 bit systems, we should use the 64 bit time calls }
  811. {$if (sizeof(time_t)<=4)}
  812. { mipsel-android doesn't have them as it is not part of newer android versions anymode }
  813. {$if not(defined(ANDROID) and defined(CPUMIPSEL))}
  814. {$define USE_TIME64}
  815. {$endif not(defined(ANDROID) and defined(CPUMIPSEL))}
  816. {$endif (sizeof(clong)<=4)}
  817. Function utimensat(dfd: cint; path:PAnsiChar;const times:TTimespecArr;flags:cint):cint;
  818. var
  819. tsa: Array[0..1] of timespec;
  820. begin
  821. {$ifdef USE_TIME64}
  822. utimensat:=do_syscall(syscall_nr_utimensat_time64,dfd,TSysParam(path),TSysParam(@times),0);
  823. if (utimensat>=0) or (fpgeterrno<>ESysENOSYS) then
  824. exit;
  825. { try 32 bit fall back }
  826. tsa[0].tv_sec := times[0].tv_sec;
  827. tsa[0].tv_nsec := times[0].tv_nsec;
  828. tsa[1].tv_sec := times[1].tv_sec;
  829. tsa[1].tv_nsec := times[1].tv_nsec;
  830. utimensat:=do_syscall(syscall_nr_utimensat,dfd,TSysParam(path),TSysParam(@tsa),0);
  831. {$else USE_TIME64}
  832. utimensat:=do_syscall(syscall_nr_utimensat,dfd,TSysParam(path),TSysParam(@times),0);
  833. {$endif USE_TIME64}
  834. end;
  835. Function futimens(fd: cint; const times:TTimespecArr):cint;
  836. var
  837. tsa: Array[0..1] of timespec;
  838. begin
  839. {$ifdef USE_TIME64}
  840. futimens:=do_syscall(syscall_nr_utimensat_time64,fd,TSysParam(nil),TSysParam(@times),0);
  841. if (futimens>=0) or (fpgeterrno<>ESysENOSYS) then
  842. exit;
  843. { try 32 bit fall back }
  844. tsa[0].tv_sec := times[0].tv_sec;
  845. tsa[0].tv_nsec := times[0].tv_nsec;
  846. tsa[1].tv_sec := times[1].tv_sec;
  847. tsa[1].tv_nsec := times[1].tv_nsec;
  848. futimens:=do_syscall(syscall_nr_utimensat,fd,TSysParam(nil),TSysParam(@tsa),0);
  849. {$else USE_TIME64}
  850. futimens:=do_syscall(syscall_nr_utimensat,fd,TSysParam(nil),TSysParam(@times),0);
  851. {$endif USE_TIME64}
  852. end;
  853. {$if defined(cpuriscv)}
  854. function riscv_hwprobe(pairs:priscv_hwprobe; pair_count:size_t; cpusetsize:size_t; cpus:pdword; flags:dword):longint;
  855. begin
  856. riscv_hwprobe:=do_syscall(syscall_nr_riscv_hwprobe,TSysParam(pairs),TSysParam(pair_count),TSysParam(cpusetsize),TSysParam(cpus),TSysParam(flags));
  857. end;
  858. {$endif defined(cpuriscv)}
  859. {$endif not FPC_USE_LIBC}
  860. end.