2
0

ptypes.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. {$ifdef cpusparc64}
  135. TIOCtlRequest = culong;
  136. {$else cpusparc64}
  137. TIOCtlRequest = cInt;
  138. {$endif cpusparc64}
  139. socklen_t= cuint32;
  140. TSockLen = socklen_t;
  141. pSockLen = ^socklen_t;
  142. timeval = record
  143. tv_sec:time_t;
  144. {$ifdef CPUSPARC64}
  145. tv_usec:cint;
  146. {$else CPUSPARC64}
  147. tv_usec:clong;
  148. {$endif CPUSPARC64}
  149. end;
  150. ptimeval = ^timeval;
  151. TTimeVal = timeval;
  152. timespec = record
  153. tv_sec : time_t;
  154. tv_nsec : clong;
  155. end;
  156. ptimespec = ^timespec;
  157. TTimeSpec = timespec;
  158. {$ifdef cpu64}
  159. TStatfs = record
  160. fstype, { File system type }
  161. bsize : clong; { Optimal block trensfer size }
  162. blocks, { Data blocks in system }
  163. bfree, { free blocks in system }
  164. bavail, { Available free blocks to non-root users }
  165. files, { File nodes in system }
  166. ffree : culong; { Free file nodes in system }
  167. fsid : array[0..1] of cint; { File system ID }
  168. namelen : clong; { Maximum name length in system }
  169. frsize : clong;
  170. spare : array [0..4] 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 : culong; { Free file nodes in system }
  181. fsid : array[0..1] of cint; { File system ID }
  182. namelen, { Maximum name length in system }
  183. frsize : cint;
  184. spare : array [0..4] of cint; { For later use }
  185. end;
  186. {$endif}
  187. PStatFS=^TStatFS;
  188. mbstate_value_t = record
  189. case byte of
  190. 0: (__wch: wint_t);
  191. 1: (__wchb: array[0..3] of char);
  192. end;
  193. mbstate_t = record
  194. __count: cint;
  195. __value: mbstate_value_t;
  196. end;
  197. pmbstate_t = ^mbstate_t;
  198. pthread_t = culong;
  199. sched_param = record
  200. __sched_priority: cint;
  201. end;
  202. pthread_attr_t = record
  203. {$ifdef USE_PTHREAD_SIZEOF}
  204. case byte of
  205. 0 : (
  206. __size : array[0..__SIZEOF_PTHREAD_ATTR_T-1] of char;
  207. __align : clong;
  208. );
  209. 1 : (
  210. {$endif}
  211. __detachstate: cint;
  212. __schedpolicy: cint;
  213. __schedparam: sched_param;
  214. __inheritsched: cint;
  215. __scope: cint;
  216. __guardsize: size_t;
  217. __stackaddr_set: cint;
  218. __stackaddr: pointer;
  219. __stacksize: size_t;
  220. {$ifdef USE_PTHREAD_SIZEOF}
  221. );
  222. {$endif}
  223. end;
  224. _pthread_fastlock = record
  225. __status: clong;
  226. __spinlock: cint;
  227. end;
  228. {$macro on}
  229. {$define MUTEXTYPENAME := pthread_mutex_t}
  230. {$i pmutext.inc}
  231. {$undef MUTEXTYPENAME}
  232. {$macro off}
  233. pthread_mutexattr_t = record
  234. {$ifdef USE_PTHREAD_SIZEOF}
  235. case byte of
  236. 0 : (
  237. __size : array[0..__SIZEOF_PTHREAD_MUTEXATTR_T-1] of char;
  238. __align : clong;
  239. );
  240. 1 : (
  241. {$endif}
  242. __mutexkind: cint;
  243. {$ifdef USE_PTHREAD_SIZEOF}
  244. );
  245. {$endif}
  246. end;
  247. pthread_cond_t = record
  248. {$ifdef USE_PTHREAD_SIZEOF}
  249. case byte of
  250. 0 : (
  251. __size : array[0..__SIZEOF_PTHREAD_COND_T-1] of char;
  252. ___align : clong;
  253. );
  254. 1 : (
  255. {$endif}
  256. __c_lock: _pthread_fastlock;
  257. __c_waiting: pointer;
  258. __padding: array[0..48-1-sizeof(_pthread_fastlock)-sizeof(pointer)-sizeof(clonglong)] of byte;
  259. __align: clonglong;
  260. {$ifdef USE_PTHREAD_SIZEOF}
  261. );
  262. {$endif}
  263. end;
  264. pthread_condattr_t = record
  265. {$ifdef USE_PTHREAD_SIZEOF}
  266. case byte of
  267. 0 : (
  268. __size : array[0..__SIZEOF_PTHREAD_CONDATTR_T-1] of char;
  269. __align : clong;
  270. );
  271. 1 : (
  272. {$endif}
  273. __dummy: cint;
  274. {$ifdef USE_PTHREAD_SIZEOF}
  275. );
  276. {$endif}
  277. end;
  278. pthread_key_t = cuint;
  279. const
  280. pthreadrwlocksize = {$ifdef CPU64} 56{$else}32{$endif};
  281. type
  282. pthread_rwlock_t = record // should be 56 for 64-bit, 32 bytes for 32-bit mantis #21552
  283. {$ifdef USE_PTHREAD_SIZEOF}
  284. case byte of
  285. 0 : (
  286. __size : array[0..__SIZEOF_PTHREAD_RWLOCK_T-1] of char;
  287. __align : clong;
  288. );
  289. 1 : (
  290. {$endif}
  291. case boolean of
  292. false : (_data : array[0..pthreadrwlocksize-1] of char);
  293. true : (align : clong);
  294. {$ifdef USE_PTHREAD_SIZEOF}
  295. );
  296. {$endif}
  297. end;
  298. pthread_rwlockattr_t = record
  299. {$ifdef USE_PTHREAD_SIZEOF}
  300. case byte of
  301. 0 : (
  302. __size : array[0..__SIZEOF_PTHREAD_RWLOCKATTR_T-1] of char;
  303. __align : clong;
  304. );
  305. 1 : (
  306. {$endif}
  307. __lockkind: cint;
  308. __pshared: cint;
  309. {$ifdef USE_PTHREAD_SIZEOF}
  310. );
  311. {$endif}
  312. end;
  313. sem_t = record
  314. __sem_lock: _pthread_fastlock;
  315. __sem_value: cint;
  316. __sem_waiting: pointer;
  317. end;
  318. CONST
  319. _PTHREAD_MUTEX_TIMED_NP = 0;
  320. _PTHREAD_MUTEX_RECURSIVE_NP = 1;
  321. _PTHREAD_MUTEX_ERRORCHECK_NP = 2;
  322. _PTHREAD_MUTEX_ADAPTIVE_NP = 3;
  323. _PTHREAD_MUTEX_NORMAL = _PTHREAD_MUTEX_TIMED_NP;
  324. _PTHREAD_MUTEX_RECURSIVE = _PTHREAD_MUTEX_RECURSIVE_NP;
  325. _PTHREAD_MUTEX_ERRORCHECK = _PTHREAD_MUTEX_ERRORCHECK_NP;
  326. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_NORMAL;
  327. _PTHREAD_MUTEX_FAST_NP = _PTHREAD_MUTEX_ADAPTIVE_NP;
  328. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  329. { took idefix' values}
  330. ARG_MAX = 131072; {4096} { Maximum number of argument size }
  331. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  332. PATH_MAX = 4095; {255} { Maximum number of bytes in pathname }
  333. SYS_NMLN = 65;
  334. {$ifdef FPC_USE_LIBC}
  335. SIG_MAXSIG = 1024; // highest signal version
  336. {$else}
  337. {$ifdef cpumips}
  338. SIG_MAXSIG = 1024; // highest signal version
  339. {$else not cupmips}
  340. SIG_MAXSIG = 128; // highest signal version
  341. {$endif not cpumips}
  342. {$endif}
  343. { For getting/setting priority }
  344. Prio_Process = 0;
  345. Prio_PGrp = 1;
  346. Prio_User = 2;