ostypes.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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. {$if defined(use_statx_syscall)}
  76. STATX_BASIC_STATS=$000007ff;
  77. {$endif}
  78. type
  79. {$i stat.inc}
  80. TStat = Stat;
  81. PStat = ^Stat;
  82. { Referred to rtl/linux/linux.pp }
  83. statx64_timestamp = record
  84. tv_sec : cint64;
  85. tv_nsec : cuint32;
  86. __reserved : cint32;
  87. end;
  88. pstatx64_timestamp = ^statx64_timestamp;
  89. tstatx64 = record
  90. stx_mask : cuint32;
  91. stx_blksize : cuint32;
  92. stx_attributes : cuint64;
  93. stx_nlink : cuint32;
  94. stx_uid : cuint32;
  95. stx_gid : cuint32;
  96. stx_mode : word;
  97. __spare0 : array[0..0] of word;
  98. stx_ino : cuint64;
  99. stx_size : cuint64;
  100. stx_blocks : cuint64;
  101. stx_attributes_mask : cuint64;
  102. stx_atime : statx64_timestamp;
  103. stx_btime : statx64_timestamp;
  104. stx_ctime : statx64_timestamp;
  105. stx_mtime : statx64_timestamp;
  106. stx_rdev_major : cuint32;
  107. stx_rdev_minor : cuint32;
  108. stx_dev_major : cuint32;
  109. stx_dev_minor : cuint32;
  110. __spare2 : array[0..13] of cuint64;
  111. end;
  112. pstatx64 = ^tstatx64;
  113. { directory services }
  114. { the Dirent type for getdents64 is no longer declared as ending with
  115. an array 0..255, but as ending with a variable-sized array. While the
  116. maximum file name length hasn't changed, the getdents64 system call
  117. code does always check whether the size of the struct is a multiple
  118. of 8 bytes. On platforms where the maximum alignment is 4 bytes, the
  119. size of the Dirent struct ending with an array of 256 chars is
  120. however only 276 bytes. As a result, getdents64 fails for long file
  121. names with that Dirent size.
  122. Rather than slightly increasing the size to 280 bytes, immediately
  123. make it much larger so that the kernel can cache more entries per
  124. system call and as a result we have to perform less system calls.
  125. }
  126. Dirent = record
  127. d_fileno : ino64_t; // file number of entry
  128. d_off : off_t;
  129. d_reclen : cushort; // length of string in d_name
  130. d_type : cuchar; // file type, see below
  131. 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
  132. end;
  133. TDirent = Dirent;
  134. pDirent = ^Dirent;
  135. {$ifdef oldreaddir}
  136. { Still old one. This is a userland struct}
  137. Dir = record
  138. dd_fd : longint;
  139. dd_loc : longint;
  140. dd_size : longint;
  141. dd_buf : pdirent;
  142. {The following are used in libc, but NOT in the linux kernel sources ??}
  143. dd_nextoff: cardinal;
  144. dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
  145. dd_lock : pointer;
  146. end;
  147. {$else}
  148. // new libc one. NOTE that off_t must be real, so 64-bit ifdef
  149. Dir = Record // packing doesn't matter. This is a userland struct.
  150. fd : cint;
  151. data : PAnsiChar;
  152. allocation: size_t;
  153. _size : size_t;
  154. offset : size_t;
  155. filepos : off_t;
  156. end;
  157. {$endif}
  158. TDir = Dir;
  159. pDir = ^Dir;
  160. UTimBuf = Record
  161. actime : time_t;
  162. modtime : time_t;
  163. end;
  164. TUtimBuf = UtimBuf;
  165. pUtimBuf = ^UtimBuf;
  166. kernel_off_t = clong;
  167. kernel_loff_t = clonglong;
  168. {$if defined(cpu32) and not(defined(cpupowerpc)) and not(defined(cpumips)) and not defined(cpumipsel))}
  169. kernel_mode_t = cushort;
  170. kernel_uid_t = cushort;
  171. kernel_gid_t = cushort;
  172. {$else}
  173. kernel_mode_t = cuint;
  174. kernel_uid_t = cuint;
  175. kernel_gid_t = cuint;
  176. {$endif}
  177. FLock = Record
  178. l_type : cshort; { lock type: read/write, etc. }
  179. l_whence: cshort; { type of l_start }
  180. { this must be really kernel_off_t: it must be 32 bit on i386 }
  181. l_start : kernel_off_t; { starting offset }
  182. l_len : kernel_off_t; { len = 0 means until end of file }
  183. l_pid : pid_t; { lock owner }
  184. {$if defined(cpusparc) or defined(cpusparc64)}
  185. __pad : cshort;
  186. {$endif}
  187. End;
  188. {$ifndef cpu64}
  189. FLock64 = Record
  190. l_type : cshort; { lock type: read/write, etc. }
  191. l_whence: cshort; { type of l_start }
  192. l_start : kernel_loff_t; { starting offset }
  193. l_len : kernel_loff_t; { len = 0 means until end of file }
  194. l_pid : pid_t; { lock owner }
  195. {$ifdef cpusparc}
  196. __pad : cshort;
  197. {$endif}
  198. End;
  199. {$endif}
  200. tms = Record
  201. tms_utime : clock_t; { User CPU time }
  202. tms_stime : clock_t; { System CPU time }
  203. tms_cutime : clock_t; { User CPU time of terminated child procs }
  204. tms_cstime : clock_t; { System CPU time of terminated child procs }
  205. end;
  206. TTms = tms;
  207. PTms = ^tms;
  208. TFDSetEl = cuLong;
  209. TFDSet = ARRAY[0..(FD_MAXFDSET div BITSINWORD)-1] of TFDSetEl;
  210. pFDSet = ^TFDSet;
  211. timezone = record
  212. tz_minuteswest,tz_dsttime:cint;
  213. end;
  214. ptimezone =^timezone;
  215. TTimeZone = timezone;
  216. const
  217. POLLIN = $0001;
  218. POLLPRI = $0002;
  219. POLLOUT = $0004;
  220. POLLERR = $0008;
  221. POLLHUP = $0010;
  222. POLLNVAL = $0020;
  223. { XOpen, XPG 4.2 }
  224. POLLRDNORM = $0040;
  225. POLLRDBAND = $0080;
  226. POLLWRNORM = $0100;
  227. POLLWRBAND = $0200;
  228. type
  229. pollfd = record
  230. fd: cint;
  231. events: cshort;
  232. revents: cshort;
  233. end;
  234. tpollfd = pollfd;
  235. ppollfd = ^pollfd;
  236. {***********************************************************************}
  237. { POSIX CONSTANT ROUTINE DEFINITIONS }
  238. {***********************************************************************}
  239. CONST
  240. { access routine - these maybe OR'ed together }
  241. F_OK = 0; { test for existence of file }
  242. R_OK = 4; { test for read permission on file }
  243. W_OK = 2; { test for write permission on file }
  244. X_OK = 1; { test for execute or search permission }
  245. { seek routine }
  246. SEEK_SET = 0; { seek from beginning of file }
  247. SEEK_CUR = 1; { seek from current position }
  248. SEEK_END = 2; { seek from end of file }
  249. { open routine }
  250. { File access modes for `open' and `fcntl'. }
  251. O_RDONLY = 0; { Open read-only. }
  252. O_WRONLY = 1; { Open write-only. }
  253. O_RDWR = 2; { Open read/write. }
  254. {$if defined(cpusparc) or defined(cpusparc64)}
  255. O_APPEND = 8;
  256. O_CREAT = $200;
  257. O_TRUNC = $400;
  258. O_EXCL = $800;
  259. O_SYNC = $2000;
  260. O_NONBLOCK = $4000;
  261. O_NDELAY = O_NONBLOCK or 4;
  262. O_NOCTTY = $8000;
  263. O_DIRECTORY = $10000;
  264. O_NOFOLLOW = $20000;
  265. O_DIRECT = $100000;
  266. {$else : not (cpusparc or cpusparc64)}
  267. {$ifdef cpumips}
  268. O_CREAT = $100;
  269. O_EXCL = $400;
  270. O_NOCTTY = $800;
  271. O_TRUNC = $200;
  272. O_APPEND = $8;
  273. O_NONBLOCK = $80;
  274. O_NDELAY = O_NONBLOCK;
  275. O_SYNC = $10;
  276. O_DIRECT = $8000;
  277. O_DIRECTORY = $10000;
  278. O_NOFOLLOW = $20000;
  279. {$else : not cpumips}
  280. O_CREAT = $40;
  281. O_EXCL = $80;
  282. O_NOCTTY = $100;
  283. O_TRUNC = $200;
  284. O_APPEND = $400;
  285. O_NONBLOCK = $800;
  286. O_NDELAY = O_NONBLOCK;
  287. O_SYNC = $1000;
  288. O_DIRECT = $4000;
  289. O_DIRECTORY = $10000;
  290. O_NOFOLLOW = $20000;
  291. {$endif not cpumips}
  292. {$endif not (cpusparc or cpusparc64)}
  293. AT_FDCWD = -100;
  294. AT_SYMLINK_NOFOLLOW = $100;
  295. AT_REMOVEDIR = $200;
  296. AT_SYMLINK_FOLLOW = $400;
  297. AT_NO_AUTOMOUNT = $800;
  298. AT_EMPTY_PATH = $1000;
  299. AT_STATX_SYNC_TYPE = $6000;
  300. AT_STATX_SYNC_AS_STAT = $0000;
  301. AT_STATX_FORCE_SYNC = $2000;
  302. AT_STATX_DONT_SYNC = $4000;
  303. AT_RECURSIVE = $8000;
  304. { SIGCHLD or CLONE_CHILD_CLEARTID or CLONE_CHILD_SETTID }
  305. clone_flags_fork = $01200011;
  306. {$if defined(cpuarm) or defined(cpualpha) or defined(cpublackfin) or defined(cpum68k) or defined(cpuaarch64)}
  307. O_LARGEFILE = $20000;
  308. {$endif}
  309. {$if defined(cpusparc) or defined(cpusparc64)}
  310. O_LARGEFILE = $40000;
  311. {$endif}
  312. {$if defined(cpupowerpc)}
  313. O_LARGEFILE = $10000;
  314. {$endif}
  315. {$if defined(cpui386) or defined(cpux86_64) or defined(cpuia64) or defined(cpuxtensa) or defined(cpuriscv32) or defined(loongarch64)}
  316. O_LARGEFILE = $8000;
  317. {$endif}
  318. {$if defined(cpumips) or defined(cpumipsel)}
  319. O_LARGEFILE = $2000;
  320. {$endif}
  321. {$if defined(cpuriscv64)}
  322. O_LARGEFILE = $0;
  323. {$endif}
  324. { mode_t possible values }
  325. S_IRUSR = %0100000000; { Read permission for owner }
  326. S_IWUSR = %0010000000; { Write permission for owner }
  327. S_IXUSR = %0001000000; { Exec permission for owner }
  328. S_IRGRP = %0000100000; { Read permission for group }
  329. S_IWGRP = %0000010000; { Write permission for group }
  330. S_IXGRP = %0000001000; { Exec permission for group }
  331. S_IROTH = %0000000100; { Read permission for world }
  332. S_IWOTH = %0000000010; { Write permission for world }
  333. S_IXOTH = %0000000001; { Exec permission for world }
  334. S_IRWXU = S_IRUSR or S_IWUSR or S_IXUSR;
  335. S_IRWXG = S_IRGRP or S_IWGRP or S_IXGRP;
  336. S_IRWXO = S_IROTH or S_IWOTH or S_IXOTH;
  337. { Used for waitpid }
  338. WNOHANG = 1; { don't block waiting }
  339. WUNTRACED = 2; { report status of stopped children }
  340. { File types }
  341. S_IFMT = 61440; { type of file mask}
  342. S_IFIFO = 4096; { named pipe (fifo)}
  343. S_IFCHR = 8192; { character special}
  344. S_IFDIR = 16384; { directory }
  345. S_IFBLK = 24576; { block special}
  346. S_IFREG = 32768; { regular }
  347. S_IFLNK = 40960; { symbolic link }
  348. S_IFSOCK= 49152; { socket }
  349. S_ISUID = &4000;
  350. S_ISGID = &2000;
  351. S_ISVTX = &1000;
  352. { Constansts for MMAP }
  353. {$IFDEF FPC_IS_SYSTEM}
  354. MAP_PRIVATE =2;
  355. {$ENDIF}
  356. {$if defined(cpumips) or defined(cpumipsel)}
  357. MAP_ANONYMOUS = $800;
  358. MAP_GROWSDOWN = $1000; { stack-like segment }
  359. MAP_DENYWRITE = $2000; { ETXTBSY }
  360. MAP_EXECUTABLE = $4000; { mark it as an executable }
  361. MAP_LOCKED = $8000; { pages are locked }
  362. MAP_NORESERVE = $4000; { don't check for reservations }
  363. {$else}
  364. MAP_ANONYMOUS = $20;
  365. MAP_GROWSDOWN = $100; { stack-like segment }
  366. MAP_DENYWRITE = $800; { ETXTBSY }
  367. MAP_EXECUTABLE = $1000; { mark it as an executable }
  368. MAP_LOCKED = $2000; { pages are locked }
  369. MAP_NORESERVE = $4000; { don't check for reservations }
  370. {$endif cpumips}
  371. { For File control mechanism }
  372. F_GetFd = 1;
  373. F_SetFd = 2;
  374. F_GetFl = 3;
  375. F_SetFl = 4;
  376. {$if defined(cpusparc) or defined(cpusparc64)}
  377. F_GetLk = 7;
  378. F_SetLk = 8;
  379. F_SetLkW = 9;
  380. F_SetOwn = 5;
  381. F_GetOwn = 6;
  382. {$else}
  383. F_GetLk = 5;
  384. F_SetLk = 6;
  385. F_SetLkW = 7;
  386. F_SetOwn = 8;
  387. F_GetOwn = 9;
  388. {$endif}
  389. F_SETLEASE = 1024;
  390. F_GETLEASE = 1025;
  391. F_CANCELLK = 1029;
  392. F_DUPFD_CLOEXEC = 1030;
  393. F_NOTIFY = 1026;
  394. F_SETPIPE_SZ = 1031;
  395. F_GETPIPE_SZ = 1032;
  396. F_ADD_SEALS = 1033;
  397. F_GET_SEALS = 1034;
  398. { getrlimit/ugetrlimit resource parameter constants }
  399. const
  400. RLIMIT_CPU = 0; { CPU time in ms }
  401. RLIMIT_FSIZE = 1; { Maximum filesize }
  402. RLIMIT_DATA = 2; { max data size }
  403. RLIMIT_STACK = 3; { max stack size }
  404. RLIMIT_CORE = 4; { max core file size }
  405. RLIMIT_RSS = 5; { max resident set size }
  406. RLIMIT_NPROC = 6; { max number of processes }
  407. RLIMIT_NOFILE = 7; { max number of open files }
  408. RLIMIT_MEMLOCK = 8; { max locked-in-memory address space }
  409. RLIMIT_AS = 9; { address space limit(?) }
  410. RLIMIT_LOCKS = 10; { maximum file locks held }
  411. type
  412. {$ifdef fs32bit}
  413. rlim_t = cULong;
  414. {$else}
  415. rlim_t = cULongLong;
  416. {$endif}
  417. PRLimit = ^TRLimit;
  418. TRLimit = record
  419. rlim_cur : rlim_t;
  420. rlim_max : rlim_t;
  421. end;
  422. iovec = record
  423. iov_base : pointer;
  424. iov_len : size_t;
  425. end;
  426. tiovec=iovec;
  427. piovec=^tiovec;
  428. cpu_set_t = record
  429. {$ifdef CPU64}
  430. __bits : array[0..15] of culong;
  431. {$else CPU64}
  432. __bits : array[0..0] of culong;
  433. {$endif CPU64}
  434. end;
  435. tcpu_set_t = cpu_set_t;
  436. pcpu_set_t = ^tcpu_set_t;
  437. {$if defined(cpupowerpc)}
  438. const
  439. { FP exception related constants for prctl(); PowerPC specific }
  440. PR_GET_FPEXC = 11; { get floating point exception mode }
  441. PR_SET_FPEXC = 12; { set floating point exception mode }
  442. PR_FP_EXC_DISABLED = 0; { FP exceptions disabled }
  443. PR_FP_EXC_NONREC = 1; { async non-recoverable exc. mode }
  444. PR_FP_EXC_ASYNC = 2; { async recoverable exc. mode }
  445. PR_FP_EXC_PRECISE = 3; { precise exception mode }
  446. {$endif}
  447. {*************************************************************************}
  448. { SIGNALS }
  449. {*************************************************************************}
  450. {$i signal.inc}
  451. { For 32 bit 2038 safe support, we have to use the kernel_timespec on linux which
  452. makes all fields 64 bit regardless of the bit size of the CPU.
  453. I have no idea though how to work around this when libc is used
  454. }
  455. {$ifndef FPC_USE_LIBC}
  456. kernel_time64_t = clonglong;
  457. kernel_timespec = record
  458. tv_sec : kernel_time64_t;
  459. tv_nsec : clonglong;
  460. end;
  461. tkernel_timespec = kernel_timespec;
  462. pkernel_timespec = ^kernel_timespec;
  463. tkernel_timespecs = array[0..1] of kernel_timespec;
  464. TTimespecArr = tkernel_timespecs;
  465. {$else FPC_USE_LIBC}
  466. TTimespecArr = array[0..1] of ttimespec;
  467. {$endif FPC_USE_LIBC}