ptypes.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {***********************************************************************}
  14. { POSIX TYPE DEFINITIONS }
  15. {***********************************************************************}
  16. { Introduced defines
  17. - fs32bit, should be on if libc only supports sizeof(off_t)=4
  18. we assume one typically compiles C applications with
  19. #define _FILE_OFFSET_BITS 64
  20. All three tested systems (PPC,Alpha,2x i386) gave the same POSIX limits,
  21. and all three 32-bit systems returned completely identical types too
  22. (everything 32-bit except dev_t, which is assumed to be a result of devfs
  23. introduction)
  24. }
  25. {$ifdef CPUSPARC}
  26. { define __USE_LARGEFILE64}
  27. {$endif}
  28. {$if defined(CPUMIPS) or defined(cpuaarch64) or defined(cpusparc64)}
  29. {$define USE_PTHREAD_SIZEOF}
  30. {$if defined(cpuaarch64)}
  31. const
  32. __SIZEOF_PTHREAD_ATTR_T = 64;
  33. __SIZEOF_PTHREAD_MUTEXATTR_T = 8;
  34. __SIZEOF_PTHREAD_COND_T = 48;
  35. __SIZEOF_PTHREAD_CONDATTR_T = 8;
  36. __SIZEOF_PTHREAD_RWLOCK_T = 56;
  37. __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
  38. __SIZEOF_PTHREAD_BARRIER_T = 32;
  39. __SIZEOF_PTHREAD_BARRIERATTR_T = 8;
  40. {$elseif defined(CPU64)}
  41. const
  42. __SIZEOF_PTHREAD_ATTR_T = 56;
  43. __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
  44. __SIZEOF_PTHREAD_COND_T = 48;
  45. __SIZEOF_PTHREAD_CONDATTR_T = 4;
  46. __SIZEOF_PTHREAD_RWLOCK_T = 56;
  47. __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
  48. __SIZEOF_PTHREAD_BARRIER_T = 32;
  49. __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
  50. {$else : not CPU64, i.e. CPU32}
  51. const
  52. __SIZEOF_PTHREAD_ATTR_T = 36;
  53. __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
  54. __SIZEOF_PTHREAD_COND_T = 48;
  55. __SIZEOF_PTHREAD_CONDATTR_T = 4;
  56. __SIZEOF_PTHREAD_RWLOCK_T = 32;
  57. __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
  58. __SIZEOF_PTHREAD_BARRIER_T = 20;
  59. __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
  60. {$endif CPU32}
  61. {$endif}
  62. {$I ctypes.inc}
  63. {$packrecords c}
  64. Type
  65. dev_t = cuint64; { used for device numbers }
  66. TDev = dev_t;
  67. pDev = ^dev_t;
  68. kDev_t = cushort; // Linux has two different device conventions
  69. TkDev = KDev_t; // kernel and glibc. This is kernel.
  70. pkDev = ^kdev_t;
  71. ino_t = clong; { used for file serial numbers }
  72. TIno = ino_t;
  73. pIno = ^ino_t;
  74. ino64_t = cuint64;
  75. TIno64 = ino64_t;
  76. pIno64 = ^ino64_t;
  77. {$ifdef cpu64}
  78. mode_t = cint; { used for file attributes }
  79. {$else cpu64}
  80. mode_t = cuint32; { used for file attributes }
  81. {$endif cpu64}
  82. TMode = mode_t;
  83. pMode = ^mode_t;
  84. nlink_t = cuint32; { used for link counts }
  85. TnLink = nlink_t;
  86. pnLink = ^nlink_t;
  87. {$if not defined(fs32bit)}
  88. off_t = cint64; { used for file sizes }
  89. {$else}
  90. off_t = cint;
  91. {$endif}
  92. TOff = off_t;
  93. pOff = ^off_t;
  94. off64_t = cint64;
  95. TOff64 = off64_t;
  96. pOff64 = ^off64_t;
  97. pid_t = cint; { used as process identifier }
  98. TPid = pid_t;
  99. pPid = ^pid_t;
  100. {$ifdef cpu64}
  101. size_t = cuint64; { as definied in the C standard}
  102. ssize_t = cint64; { used by function for returning number of bytes }
  103. clock_t = cuint64;
  104. time_t = cint64; { used for returning the time }
  105. {$else}
  106. size_t = cuint32; { as definied in the C standard}
  107. ssize_t = cint32; { used by function for returning number of bytes }
  108. clock_t = culong;
  109. time_t = clong; { used for returning the time }
  110. {$endif}
  111. wint_t = cint32;
  112. TSize = size_t;
  113. pSize = ^size_t;
  114. psize_t = pSize;
  115. TSSize = ssize_t;
  116. pSSize = ^ssize_t;
  117. TClock = clock_t;
  118. pClock = ^clock_t;
  119. // TTime = time_t; // Not allowed in system unit, -> unixtype
  120. pTime = ^time_t;
  121. ptime_t = ^time_t;
  122. wchar_t = cint32;
  123. pwchar_t = ^wchar_t;
  124. {$ifdef cpu64}
  125. uid_t = cuint32; { used for user ID type }
  126. gid_t = cuint32; { used for group IDs }
  127. ipc_pid_t = cint;
  128. {$else cpu64}
  129. uid_t = cuint32; { used for user ID type }
  130. gid_t = cuint32; { used for group IDs }
  131. ipc_pid_t = cushort; // still 16-bit
  132. {$endif cpu64}
  133. TUid = uid_t;
  134. pUid = ^uid_t;
  135. TGid = gid_t;
  136. pGid = ^gid_t;
  137. TIOCtlRequest = culong;
  138. socklen_t= cuint32;
  139. TSockLen = socklen_t;
  140. pSockLen = ^socklen_t;
  141. timeval = record
  142. tv_sec:time_t;
  143. {$ifdef CPUSPARC64}
  144. tv_usec:cint;
  145. {$else CPUSPARC64}
  146. tv_usec:clong;
  147. {$endif CPUSPARC64}
  148. end;
  149. ptimeval = ^timeval;
  150. TTimeVal = timeval;
  151. timespec = record
  152. tv_sec : time_t;
  153. tv_nsec : clong;
  154. end;
  155. ptimespec = ^timespec;
  156. TTimeSpec = timespec;
  157. {$ifdef cpu64}
  158. TStatfs = record
  159. fstype, { File system type }
  160. bsize : clong; { Optimal block trensfer size }
  161. blocks, { Data blocks in system }
  162. bfree, { free blocks in system }
  163. bavail, { Available free blocks to non-root users }
  164. files, { File nodes in system }
  165. ffree : culong; { Free file nodes in system }
  166. fsid : array[0..1] of cint; { File system ID }
  167. namelen : clong; { Maximum name length in system }
  168. frsize : clong;
  169. flags : clong;
  170. spare : array [0..3] of clong; { For later use }
  171. end;
  172. {$else}
  173. TStatfs = record
  174. fstype, { File system type }
  175. bsize : cint; { Optimal block trensfer size }
  176. blocks, { Data blocks in system }
  177. bfree, { free blocks in system }
  178. bavail, { Available free blocks to non-root users }
  179. files, { File nodes in system }
  180. ffree :
  181. {$ifdef __USE_LARGEFILE64}
  182. culonglong; { Free file nodes in system }
  183. {$else}
  184. culong; { Free file nodes in system }
  185. {$endif}
  186. fsid : array[0..1] of cint; { File system ID }
  187. namelen, { Maximum name length in system }
  188. frsize : cint;
  189. flags : cint;
  190. spare : array [0..3] of cint; { For later use }
  191. end;
  192. {$endif}
  193. PStatFS=^TStatFS;
  194. mbstate_value_t = record
  195. case byte of
  196. 0: (__wch: wint_t);
  197. 1: (__wchb: array[0..3] of char);
  198. end;
  199. mbstate_t = record
  200. __count: cint;
  201. __value: mbstate_value_t;
  202. end;
  203. pmbstate_t = ^mbstate_t;
  204. pthread_t = culong;
  205. sched_param = record
  206. __sched_priority: cint;
  207. end;
  208. pthread_attr_t = record
  209. {$ifdef USE_PTHREAD_SIZEOF}
  210. case byte of
  211. 0 : (
  212. __size : array[0..__SIZEOF_PTHREAD_ATTR_T-1] of char;
  213. __align : clong;
  214. );
  215. 1 : (
  216. {$endif}
  217. __detachstate: cint;
  218. __schedpolicy: cint;
  219. __schedparam: sched_param;
  220. __inheritsched: cint;
  221. __scope: cint;
  222. __guardsize: size_t;
  223. __stackaddr_set: cint;
  224. __stackaddr: pointer;
  225. __stacksize: size_t;
  226. {$ifdef USE_PTHREAD_SIZEOF}
  227. );
  228. {$endif}
  229. end;
  230. _pthread_fastlock = record
  231. __status: clong;
  232. __spinlock: cint;
  233. end;
  234. {$macro on}
  235. {$define MUTEXTYPENAME := pthread_mutex_t}
  236. {$i pmutext.inc}
  237. {$undef MUTEXTYPENAME}
  238. {$macro off}
  239. pthread_mutexattr_t = record
  240. {$ifdef USE_PTHREAD_SIZEOF}
  241. case byte of
  242. 0 : (
  243. __size : array[0..__SIZEOF_PTHREAD_MUTEXATTR_T-1] of char;
  244. __align : clong;
  245. );
  246. 1 : (
  247. {$endif}
  248. __mutexkind: cint;
  249. {$ifdef USE_PTHREAD_SIZEOF}
  250. );
  251. {$endif}
  252. end;
  253. pthread_cond_t = record
  254. {$ifdef USE_PTHREAD_SIZEOF}
  255. case byte of
  256. 0 : (
  257. __size : array[0..__SIZEOF_PTHREAD_COND_T-1] of char;
  258. ___align : clong;
  259. );
  260. 1 : (
  261. {$endif}
  262. __c_lock: _pthread_fastlock;
  263. __c_waiting: pointer;
  264. __padding: array[0..48-1-sizeof(_pthread_fastlock)-sizeof(pointer)-sizeof(clonglong)] of byte;
  265. __align: clonglong;
  266. {$ifdef USE_PTHREAD_SIZEOF}
  267. );
  268. {$endif}
  269. end;
  270. pthread_condattr_t = record
  271. {$ifdef USE_PTHREAD_SIZEOF}
  272. case byte of
  273. 0 : (
  274. __size : array[0..__SIZEOF_PTHREAD_CONDATTR_T-1] of char;
  275. __align : clong;
  276. );
  277. 1 : (
  278. {$endif}
  279. __dummy: cint;
  280. {$ifdef USE_PTHREAD_SIZEOF}
  281. );
  282. {$endif}
  283. end;
  284. pthread_key_t = cuint;
  285. const
  286. pthreadrwlocksize = {$ifdef CPU64} 56{$else}32{$endif};
  287. type
  288. pthread_rwlock_t = record // should be 56 for 64-bit, 32 bytes for 32-bit mantis #21552
  289. {$ifdef USE_PTHREAD_SIZEOF}
  290. case byte of
  291. 0 : (
  292. __size : array[0..__SIZEOF_PTHREAD_RWLOCK_T-1] of char;
  293. __align : clong;
  294. );
  295. 1 : (
  296. {$endif}
  297. case boolean of
  298. false : (_data : array[0..pthreadrwlocksize-1] of char);
  299. true : (align : clong);
  300. {$ifdef USE_PTHREAD_SIZEOF}
  301. );
  302. {$endif}
  303. end;
  304. pthread_rwlockattr_t = record
  305. {$ifdef USE_PTHREAD_SIZEOF}
  306. case byte of
  307. 0 : (
  308. __size : array[0..__SIZEOF_PTHREAD_RWLOCKATTR_T-1] of char;
  309. __align : clong;
  310. );
  311. 1 : (
  312. {$endif}
  313. __lockkind: cint;
  314. __pshared: cint;
  315. {$ifdef USE_PTHREAD_SIZEOF}
  316. );
  317. {$endif}
  318. end;
  319. sem_t = record
  320. __sem_lock: _pthread_fastlock;
  321. __sem_value: cint;
  322. __sem_waiting: pointer;
  323. end;
  324. CONST
  325. _PTHREAD_MUTEX_TIMED_NP = 0;
  326. _PTHREAD_MUTEX_RECURSIVE_NP = 1;
  327. _PTHREAD_MUTEX_ERRORCHECK_NP = 2;
  328. _PTHREAD_MUTEX_ADAPTIVE_NP = 3;
  329. _PTHREAD_MUTEX_NORMAL = _PTHREAD_MUTEX_TIMED_NP;
  330. _PTHREAD_MUTEX_RECURSIVE = _PTHREAD_MUTEX_RECURSIVE_NP;
  331. _PTHREAD_MUTEX_ERRORCHECK = _PTHREAD_MUTEX_ERRORCHECK_NP;
  332. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_NORMAL;
  333. _PTHREAD_MUTEX_FAST_NP = _PTHREAD_MUTEX_ADAPTIVE_NP;
  334. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  335. { took idefix' values}
  336. ARG_MAX = 131072; {4096} { Maximum number of argument size }
  337. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  338. PATH_MAX = 4095; {255} { Maximum number of bytes in pathname }
  339. SYS_NMLN = 65;
  340. {$ifdef FPC_USE_LIBC}
  341. SIG_MAXSIG = 1024; // highest signal version
  342. {$else}
  343. {$ifdef cpumips}
  344. SIG_MAXSIG = 1024; // highest signal version
  345. {$else not cupmips}
  346. SIG_MAXSIG = 128; // highest signal version
  347. {$endif not cpumips}
  348. {$endif}
  349. { For getting/setting priority }
  350. Prio_Process = 0;
  351. Prio_PGrp = 1;
  352. Prio_User = 2;