ptypes.inc 11 KB

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