ostypes.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. Types and structures for the BaseUnix unit.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. ***********************************************************************}
  11. {***********************************************************************}
  12. { Base Unix Structures }
  13. {***********************************************************************}
  14. {$IFDEF FPC_IS_SYSTEM}
  15. {$i ptypes.inc}
  16. {$ENDIF}
  17. CONST
  18. // SYS_NMLM = 65;
  19. UTSNAME_LENGTH = SYS_NMLN;
  20. UTSNAME_NODENAME_LENGTH = UTSNAME_LENGTH;
  21. {$ifdef usedomain}
  22. UTSNAME_DOMAIN_LENGTH = UTSNAME_LENGTH;
  23. {$endif}
  24. FD_MAXFDSET = 1024;
  25. BITSINWORD = 8*sizeof(cuLong);
  26. wordsinsigset = SIG_MAXSIG DIV BITSINWORD; // words in sigset_t
  27. wordsinfdset = FD_MAXFDSET DIV BITSINWORD; // words in fdset_t
  28. {$ifdef cpu32}
  29. ln2bitsinword = 5; { 32bit : ln(32)/ln(2)=5 }
  30. {$else cpu32}
  31. {$ifdef cpu64}
  32. ln2bitsinword = 6; { 64bit : ln(64)/ln(2)=6 }
  33. {$endif cpu64}
  34. {$endif cpu32}
  35. ln2bitmask = 1 shl ln2bitsinword - 1;
  36. TYPE
  37. Blksize_t = cuint;
  38. Blkcnt_t = cuint;
  39. Blkcnt64_t = cuint64;
  40. TBlkSize = BlkSize_t;
  41. PBlkSize = ^BlkSize_t;
  42. TBlkCnt = Blkcnt_t;
  43. PBlkCnt = ^Blkcnt_t;
  44. { system information services }
  45. UtsName = Record
  46. Sysname : Array[0..UTSNAME_LENGTH -1] OF AnsiChar; // Name of this OS
  47. Nodename: Array[0..UTSNAME_NODENAME_LENGTH-1] OF AnsiChar; // Name of this network node.
  48. Release : Array[0..UTSNAME_LENGTH -1] OF AnsiChar; // Release level.
  49. Version : Array[0..UTSNAME_LENGTH -1] OF AnsiChar; // Version level.
  50. Machine : Array[0..UTSNAME_LENGTH -1] OF AnsiChar; // Hardware type.
  51. {$ifdef usedomain}
  52. Domain : array[0..UTSNAME_DOMAIN_LENGTH-1] of AnsiChar {$ifndef ver2_2} platform; {$endif} // Linux addition "Domain"
  53. {$endif}
  54. end;
  55. TUtsName = UtsName;
  56. PUtsName = ^TUtsName;
  57. { Definition of (kernel) stat type }
  58. { see kernel/include/asm-<cpu>/stat.h, include/linux/types.h and }
  59. { include /include/asm-<cpu>/posix-types.h }
  60. const
  61. {$if not defined(cpux86_64) and not defined (cpuaarch64)}
  62. _STAT_VER_LINUX_OLD = 1;
  63. _STAT_VER_KERNEL = 1;
  64. _STAT_VER_SVR4 = 2;
  65. _STAT_VER_LINUX = 3;
  66. {$else}
  67. _STAT_VER_KERNEL = 0;
  68. {$if defined(cpuaarch64)}
  69. _STAT_VER_LINUX = 0;
  70. {$else}
  71. _STAT_VER_LINUX = 1;
  72. {$endif}
  73. {$endif}
  74. _STAT_VER = _STAT_VER_LINUX;
  75. type
  76. {$i stat.inc}
  77. TStat = Stat;
  78. PStat = ^Stat;
  79. { directory services }
  80. { the Dirent type for getdents64 is no longer declared as ending with
  81. an array 0..255, but as ending with a variable-sized array. While the
  82. maximum file name length hasn't changed, the getdents64 system call
  83. code does always check whether the size of the struct is a multiple
  84. of 8 bytes. On platforms where the maximum alignment is 4 bytes, the
  85. size of the Dirent struct ending with an array of 256 chars is
  86. however only 276 bytes. As a result, getdents64 fails for long file
  87. names with that Dirent size.
  88. Rather than slightly increasing the size to 280 bytes, immediately
  89. make it much larger so that the kernel can cache more entries per
  90. system call and as a result we have to perform less system calls.
  91. }
  92. Dirent = record
  93. d_fileno : ino64_t; // file number of entry
  94. d_off : off_t;
  95. d_reclen : cushort; // length of string in d_name
  96. d_type : cuchar; // file type, see below
  97. d_name : array[0..4095-sizeof(ino64_t)-sizeof(off_t)-sizeof(cushort)-sizeof(cuchar)] of AnsiChar; // name buffer + padding for extra records; align total record size to a page size
  98. end;
  99. TDirent = Dirent;
  100. pDirent = ^Dirent;
  101. {$ifdef oldreaddir}
  102. { Still old one. This is a userland struct}
  103. Dir = record
  104. dd_fd : longint;
  105. dd_loc : longint;
  106. dd_size : longint;
  107. dd_buf : pdirent;
  108. {The following are used in libc, but NOT in the linux kernel sources ??}
  109. dd_nextoff: cardinal;
  110. dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
  111. dd_lock : pointer;
  112. end;
  113. {$else}
  114. // new libc one. NOTE that off_t must be real, so 64-bit ifdef
  115. Dir = Record // packing doesn't matter. This is a userland struct.
  116. fd : cint;
  117. data : PAnsiChar;
  118. allocation: size_t;
  119. _size : size_t;
  120. offset : size_t;
  121. filepos : off_t;
  122. end;
  123. {$endif}
  124. TDir = Dir;
  125. pDir = ^Dir;
  126. UTimBuf = Record
  127. actime : time_t;
  128. modtime : time_t;
  129. end;
  130. TUtimBuf = UtimBuf;
  131. pUtimBuf = ^UtimBuf;
  132. kernel_off_t = clong;
  133. kernel_loff_t = clonglong;
  134. {$if defined(cpu32) and not(defined(cpupowerpc)) and not(defined(cpumips)) and not defined(cpumipsel))}
  135. kernel_mode_t = cushort;
  136. kernel_uid_t = cushort;
  137. kernel_gid_t = cushort;
  138. {$else}
  139. kernel_mode_t = cuint;
  140. kernel_uid_t = cuint;
  141. kernel_gid_t = cuint;
  142. {$endif}
  143. FLock = Record
  144. l_type : cshort; { lock type: read/write, etc. }
  145. l_whence: cshort; { type of l_start }
  146. { this must be really kernel_off_t: it must be 32 bit on i386 }
  147. l_start : kernel_off_t; { starting offset }
  148. l_len : kernel_off_t; { len = 0 means until end of file }
  149. l_pid : pid_t; { lock owner }
  150. {$if defined(cpusparc) or defined(cpusparc64)}
  151. __pad : cshort;
  152. {$endif}
  153. End;
  154. {$ifndef cpu64}
  155. FLock64 = Record
  156. l_type : cshort; { lock type: read/write, etc. }
  157. l_whence: cshort; { type of l_start }
  158. l_start : kernel_loff_t; { starting offset }
  159. l_len : kernel_loff_t; { len = 0 means until end of file }
  160. l_pid : pid_t; { lock owner }
  161. {$ifdef cpusparc}
  162. __pad : cshort;
  163. {$endif}
  164. End;
  165. {$endif}
  166. tms = Record
  167. tms_utime : clock_t; { User CPU time }
  168. tms_stime : clock_t; { System CPU time }
  169. tms_cutime : clock_t; { User CPU time of terminated child procs }
  170. tms_cstime : clock_t; { System CPU time of terminated child procs }
  171. end;
  172. TTms = tms;
  173. PTms = ^tms;
  174. TFDSetEl = cuLong;
  175. TFDSet = ARRAY[0..(FD_MAXFDSET div BITSINWORD)-1] of TFDSetEl;
  176. pFDSet = ^TFDSet;
  177. timezone = record
  178. tz_minuteswest,tz_dsttime:cint;
  179. end;
  180. ptimezone =^timezone;
  181. TTimeZone = timezone;
  182. const
  183. POLLIN = $0001;
  184. POLLPRI = $0002;
  185. POLLOUT = $0004;
  186. POLLERR = $0008;
  187. POLLHUP = $0010;
  188. POLLNVAL = $0020;
  189. { XOpen, XPG 4.2 }
  190. POLLRDNORM = $0040;
  191. POLLRDBAND = $0080;
  192. POLLWRNORM = $0100;
  193. POLLWRBAND = $0200;
  194. type
  195. pollfd = record
  196. fd: cint;
  197. events: cshort;
  198. revents: cshort;
  199. end;
  200. tpollfd = pollfd;
  201. ppollfd = ^pollfd;
  202. {***********************************************************************}
  203. { POSIX CONSTANT ROUTINE DEFINITIONS }
  204. {***********************************************************************}
  205. CONST
  206. { access routine - these maybe OR'ed together }
  207. F_OK = 0; { test for existence of file }
  208. R_OK = 4; { test for read permission on file }
  209. W_OK = 2; { test for write permission on file }
  210. X_OK = 1; { test for execute or search permission }
  211. { seek routine }
  212. SEEK_SET = 0; { seek from beginning of file }
  213. SEEK_CUR = 1; { seek from current position }
  214. SEEK_END = 2; { seek from end of file }
  215. { open routine }
  216. { File access modes for `open' and `fcntl'. }
  217. O_RDONLY = 0; { Open read-only. }
  218. O_WRONLY = 1; { Open write-only. }
  219. O_RDWR = 2; { Open read/write. }
  220. {$if defined(cpusparc) or defined(cpusparc64)}
  221. O_APPEND = 8;
  222. O_CREAT = $200;
  223. O_TRUNC = $400;
  224. O_EXCL = $800;
  225. O_SYNC = $2000;
  226. O_NONBLOCK = $4000;
  227. O_NDELAY = O_NONBLOCK or 4;
  228. O_NOCTTY = $8000;
  229. O_DIRECTORY = $10000;
  230. O_NOFOLLOW = $20000;
  231. O_DIRECT = $100000;
  232. {$else : not (cpusparc or cpusparc64)}
  233. {$ifdef cpumips}
  234. O_CREAT = $100;
  235. O_EXCL = $400;
  236. O_NOCTTY = $800;
  237. O_TRUNC = $200;
  238. O_APPEND = $8;
  239. O_NONBLOCK = $80;
  240. O_NDELAY = O_NONBLOCK;
  241. O_SYNC = $10;
  242. O_DIRECT = $8000;
  243. O_DIRECTORY = $10000;
  244. O_NOFOLLOW = $20000;
  245. {$else : not cpumips}
  246. O_CREAT = $40;
  247. O_EXCL = $80;
  248. O_NOCTTY = $100;
  249. O_TRUNC = $200;
  250. O_APPEND = $400;
  251. O_NONBLOCK = $800;
  252. O_NDELAY = O_NONBLOCK;
  253. O_SYNC = $1000;
  254. O_DIRECT = $4000;
  255. O_DIRECTORY = $10000;
  256. O_NOFOLLOW = $20000;
  257. {$endif not cpumips}
  258. {$endif not (cpusparc or cpusparc64)}
  259. AT_FDCWD = -100;
  260. AT_SYMLINK_NOFOLLOW = $100;
  261. AT_REMOVEDIR = $200;
  262. AT_SYMLINK_FOLLOW = $400;
  263. AT_NO_AUTOMOUNT = $800;
  264. AT_EMPTY_PATH = $1000;
  265. AT_STATX_SYNC_TYPE = $6000;
  266. AT_STATX_SYNC_AS_STAT = $0000;
  267. AT_STATX_FORCE_SYNC = $2000;
  268. AT_STATX_DONT_SYNC = $4000;
  269. AT_RECURSIVE = $8000;
  270. { SIGCHLD or CLONE_CHILD_CLEARTID or CLONE_CHILD_SETTID }
  271. clone_flags_fork = $01200011;
  272. {$if defined(cpuarm) or defined(cpualpha) or defined(cpublackfin) or defined(cpum68k) or defined(cpuaarch64)}
  273. O_LARGEFILE = $20000;
  274. {$endif}
  275. {$if defined(cpusparc) or defined(cpusparc64)}
  276. O_LARGEFILE = $40000;
  277. {$endif}
  278. {$if defined(cpupowerpc)}
  279. O_LARGEFILE = $10000;
  280. {$endif}
  281. {$if defined(cpui386) or defined(cpux86_64) or defined(cpuia64) or defined(cpuxtensa) or defined(cpuriscv32) or defined(loongarch64)}
  282. O_LARGEFILE = $8000;
  283. {$endif}
  284. {$if defined(cpumips) or defined(cpumipsel)}
  285. O_LARGEFILE = $2000;
  286. {$endif}
  287. {$if defined(cpuriscv64)}
  288. O_LARGEFILE = $0;
  289. {$endif}
  290. { mode_t possible values }
  291. S_IRUSR = %0100000000; { Read permission for owner }
  292. S_IWUSR = %0010000000; { Write permission for owner }
  293. S_IXUSR = %0001000000; { Exec permission for owner }
  294. S_IRGRP = %0000100000; { Read permission for group }
  295. S_IWGRP = %0000010000; { Write permission for group }
  296. S_IXGRP = %0000001000; { Exec permission for group }
  297. S_IROTH = %0000000100; { Read permission for world }
  298. S_IWOTH = %0000000010; { Write permission for world }
  299. S_IXOTH = %0000000001; { Exec permission for world }
  300. S_IRWXU = S_IRUSR or S_IWUSR or S_IXUSR;
  301. S_IRWXG = S_IRGRP or S_IWGRP or S_IXGRP;
  302. S_IRWXO = S_IROTH or S_IWOTH or S_IXOTH;
  303. { Used for waitpid }
  304. WNOHANG = 1; { don't block waiting }
  305. WUNTRACED = 2; { report status of stopped children }
  306. { File types }
  307. S_IFMT = 61440; { type of file mask}
  308. S_IFIFO = 4096; { named pipe (fifo)}
  309. S_IFCHR = 8192; { character special}
  310. S_IFDIR = 16384; { directory }
  311. S_IFBLK = 24576; { block special}
  312. S_IFREG = 32768; { regular }
  313. S_IFLNK = 40960; { symbolic link }
  314. S_IFSOCK= 49152; { socket }
  315. S_ISUID = &4000;
  316. S_ISGID = &2000;
  317. S_ISVTX = &1000;
  318. { Constansts for MMAP }
  319. {$IFDEF FPC_IS_SYSTEM}
  320. MAP_PRIVATE =2;
  321. {$ENDIF}
  322. {$if defined(cpumips) or defined(cpumipsel)}
  323. MAP_ANONYMOUS = $800;
  324. MAP_GROWSDOWN = $1000; { stack-like segment }
  325. MAP_DENYWRITE = $2000; { ETXTBSY }
  326. MAP_EXECUTABLE = $4000; { mark it as an executable }
  327. MAP_LOCKED = $8000; { pages are locked }
  328. MAP_NORESERVE = $4000; { don't check for reservations }
  329. {$else}
  330. MAP_ANONYMOUS = $20;
  331. MAP_GROWSDOWN = $100; { stack-like segment }
  332. MAP_DENYWRITE = $800; { ETXTBSY }
  333. MAP_EXECUTABLE = $1000; { mark it as an executable }
  334. MAP_LOCKED = $2000; { pages are locked }
  335. MAP_NORESERVE = $4000; { don't check for reservations }
  336. {$endif cpumips}
  337. { For File control mechanism }
  338. F_GetFd = 1;
  339. F_SetFd = 2;
  340. F_GetFl = 3;
  341. F_SetFl = 4;
  342. {$if defined(cpusparc) or defined(cpusparc64)}
  343. F_GetLk = 7;
  344. F_SetLk = 8;
  345. F_SetLkW = 9;
  346. F_SetOwn = 5;
  347. F_GetOwn = 6;
  348. {$else}
  349. F_GetLk = 5;
  350. F_SetLk = 6;
  351. F_SetLkW = 7;
  352. F_SetOwn = 8;
  353. F_GetOwn = 9;
  354. {$endif}
  355. F_SETLEASE = 1024;
  356. F_GETLEASE = 1025;
  357. F_CANCELLK = 1029;
  358. F_DUPFD_CLOEXEC = 1030;
  359. F_NOTIFY = 1026;
  360. F_SETPIPE_SZ = 1031;
  361. F_GETPIPE_SZ = 1032;
  362. F_ADD_SEALS = 1033;
  363. F_GET_SEALS = 1034;
  364. { getrlimit/ugetrlimit resource parameter constants }
  365. const
  366. RLIMIT_CPU = 0; { CPU time in ms }
  367. RLIMIT_FSIZE = 1; { Maximum filesize }
  368. RLIMIT_DATA = 2; { max data size }
  369. RLIMIT_STACK = 3; { max stack size }
  370. RLIMIT_CORE = 4; { max core file size }
  371. RLIMIT_RSS = 5; { max resident set size }
  372. RLIMIT_NPROC = 6; { max number of processes }
  373. RLIMIT_NOFILE = 7; { max number of open files }
  374. RLIMIT_MEMLOCK = 8; { max locked-in-memory address space }
  375. RLIMIT_AS = 9; { address space limit(?) }
  376. RLIMIT_LOCKS = 10; { maximum file locks held }
  377. type
  378. {$ifdef fs32bit}
  379. rlim_t = cULong;
  380. {$else}
  381. rlim_t = cULongLong;
  382. {$endif}
  383. PRLimit = ^TRLimit;
  384. TRLimit = record
  385. rlim_cur : rlim_t;
  386. rlim_max : rlim_t;
  387. end;
  388. iovec = record
  389. iov_base : pointer;
  390. iov_len : size_t;
  391. end;
  392. tiovec=iovec;
  393. piovec=^tiovec;
  394. cpu_set_t = record
  395. {$ifdef CPU64}
  396. __bits : array[0..15] of culong;
  397. {$else CPU64}
  398. __bits : array[0..0] of culong;
  399. {$endif CPU64}
  400. end;
  401. tcpu_set_t = cpu_set_t;
  402. pcpu_set_t = ^tcpu_set_t;
  403. {$if defined(cpupowerpc)}
  404. const
  405. { FP exception related constants for prctl(); PowerPC specific }
  406. PR_GET_FPEXC = 11; { get floating point exception mode }
  407. PR_SET_FPEXC = 12; { set floating point exception mode }
  408. PR_FP_EXC_DISABLED = 0; { FP exceptions disabled }
  409. PR_FP_EXC_NONREC = 1; { async non-recoverable exc. mode }
  410. PR_FP_EXC_ASYNC = 2; { async recoverable exc. mode }
  411. PR_FP_EXC_PRECISE = 3; { precise exception mode }
  412. {$endif}
  413. {*************************************************************************}
  414. { SIGNALS }
  415. {*************************************************************************}
  416. {$i signal.inc}