ptypes.inc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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(cpuaarch64)}
  29. const
  30. __SIZEOF_PTHREAD_ATTR_T = 64;
  31. __SIZEOF_PTHREAD_MUTEXATTR_T = 8;
  32. __SIZEOF_PTHREAD_COND_T = 48;
  33. __SIZEOF_PTHREAD_CONDATTR_T = 8;
  34. __SIZEOF_PTHREAD_RWLOCK_T = 56;
  35. __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
  36. __SIZEOF_PTHREAD_BARRIER_T = 32;
  37. __SIZEOF_PTHREAD_BARRIERATTR_T = 8;
  38. __SIZEOF_SEM_T = 32;
  39. {$elseif defined(CPU64)}
  40. const
  41. __SIZEOF_PTHREAD_ATTR_T = 56;
  42. __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
  43. __SIZEOF_PTHREAD_COND_T = 48;
  44. __SIZEOF_PTHREAD_CONDATTR_T = 4;
  45. __SIZEOF_PTHREAD_RWLOCK_T = 56;
  46. __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
  47. __SIZEOF_PTHREAD_BARRIER_T = 32;
  48. __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
  49. __SIZEOF_SEM_T = 32;
  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. __SIZEOF_SEM_T = 16;
  61. {$endif CPU32}
  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 AnsiChar);
  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. case byte of
  210. 0 : (
  211. __size : array[0..__SIZEOF_PTHREAD_ATTR_T-1] of AnsiChar;
  212. );
  213. 1 : (
  214. __align : clong;
  215. );
  216. end;
  217. _pthread_fastlock = record
  218. __status: clong;
  219. __spinlock: cint;
  220. end;
  221. {$macro on}
  222. {$define MUTEXTYPENAME := pthread_mutex_t}
  223. {$i pmutext.inc}
  224. {$undef MUTEXTYPENAME}
  225. {$macro off}
  226. pthread_mutexattr_t = record
  227. case byte of
  228. 0 : (
  229. __size : array[0..__SIZEOF_PTHREAD_MUTEXATTR_T-1] of AnsiChar;
  230. );
  231. 1 : (
  232. __align : cint;
  233. );
  234. end;
  235. pthread_cond_t = record
  236. case byte of
  237. 0 : (
  238. __size : array[0..__SIZEOF_PTHREAD_COND_T-1] of AnsiChar;
  239. );
  240. 1 : (
  241. ___align : clonglong;
  242. );
  243. end;
  244. pthread_condattr_t = record
  245. case byte of
  246. 0 : (
  247. __size : array[0..__SIZEOF_PTHREAD_CONDATTR_T-1] of AnsiChar;
  248. );
  249. 1 : (
  250. __align : cint;
  251. );
  252. end;
  253. pthread_key_t = cuint;
  254. type
  255. pthread_rwlock_t = record // should be 56 for 64-bit, 32 bytes for 32-bit mantis #21552
  256. case byte of
  257. 0 : (
  258. __size : array[0..__SIZEOF_PTHREAD_RWLOCK_T-1] of AnsiChar;
  259. );
  260. 1 : (
  261. __align : clong;
  262. );
  263. end;
  264. pthread_rwlockattr_t = record
  265. case byte of
  266. 0 : (
  267. __size : array[0..__SIZEOF_PTHREAD_RWLOCKATTR_T-1] of AnsiChar;
  268. );
  269. 1 : (
  270. __align : cint;
  271. );
  272. end;
  273. sem_t = record
  274. case byte of
  275. 0 : (
  276. __size : array[0..__SIZEOF_SEM_T-1] of AnsiChar;
  277. );
  278. 1 : (
  279. __align : clonglong;
  280. );
  281. end;
  282. CONST
  283. _PTHREAD_MUTEX_TIMED_NP = 0;
  284. _PTHREAD_MUTEX_RECURSIVE_NP = 1;
  285. _PTHREAD_MUTEX_ERRORCHECK_NP = 2;
  286. _PTHREAD_MUTEX_ADAPTIVE_NP = 3;
  287. _PTHREAD_MUTEX_NORMAL = _PTHREAD_MUTEX_TIMED_NP;
  288. _PTHREAD_MUTEX_RECURSIVE = _PTHREAD_MUTEX_RECURSIVE_NP;
  289. _PTHREAD_MUTEX_ERRORCHECK = _PTHREAD_MUTEX_ERRORCHECK_NP;
  290. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_NORMAL;
  291. _PTHREAD_MUTEX_FAST_NP = _PTHREAD_MUTEX_ADAPTIVE_NP;
  292. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  293. { took idefix' values}
  294. ARG_MAX = 131072; {4096} { Maximum number of argument size }
  295. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  296. PATH_MAX = 4095; {255} { Maximum number of bytes in pathname }
  297. SYS_NMLN = 65;
  298. {$ifdef FPC_USE_LIBC}
  299. SIG_MAXSIG = 1024; // highest signal version
  300. {$else}
  301. {$ifdef cpumips}
  302. SIG_MAXSIG = 1024; // highest signal version
  303. {$else not cupmips}
  304. SIG_MAXSIG = 128; // highest signal version
  305. {$endif not cpumips}
  306. {$endif}
  307. { For getting/setting priority }
  308. Prio_Process = 0;
  309. Prio_PGrp = 1;
  310. Prio_User = 2;