ptypes.inc 11 KB

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