Subversion Repositories Kolibri OS

Rev

Rev 6099 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* unified sys/types.h:
  2.    start with sef's sysvi386 version.
  3.    merge go32 version -- a few ifdefs.
  4.    h8300hms, h8300xray, and sysvnecv70 disagree on the following types:
  5.  
  6.    typedef int gid_t;
  7.    typedef int uid_t;
  8.    typedef int dev_t;
  9.    typedef int ino_t;
  10.    typedef int mode_t;
  11.    typedef int caddr_t;
  12.  
  13.    however, these aren't "reasonable" values, the sysvi386 ones make far
  14.    more sense, and should work sufficiently well (in particular, h8300
  15.    doesn't have a stat, and the necv70 doesn't matter.) -- eichin
  16.  */
  17.  
  18. #ifndef _SYS_TYPES_H
  19.  
  20. #include <_ansi.h>
  21. #include <sys/cdefs.h>
  22. #include <machine/_types.h>
  23.  
  24. /* BSD types permitted by POSIX and always exposed as in Glibc.  Only provided
  25.    for backward compatibility with BSD code.  The uintN_t standard types should
  26.    be preferred in new code. */
  27. #if ___int8_t_defined
  28. typedef __uint8_t       u_int8_t;
  29. #endif
  30. #if ___int16_t_defined
  31. typedef __uint16_t      u_int16_t;
  32. #endif
  33. #if ___int32_t_defined
  34. typedef __uint32_t      u_int32_t;
  35. #endif
  36. #if ___int64_t_defined
  37. typedef __uint64_t      u_int64_t;
  38. #endif
  39.  
  40. #if defined(__rtems__) || defined(__XMK__)
  41. /*
  42.  *  The following section is RTEMS specific and is needed to more
  43.  *  closely match the types defined in the BSD sys/types.h.
  44.  *  This is needed to let the RTEMS/BSD TCP/IP stack compile.
  45.  */
  46.  
  47. /* deprecated */
  48. #if ___int64_t_defined
  49. typedef __uint64_t      u_quad_t;
  50. typedef __int64_t       quad_t;
  51. typedef quad_t *        qaddr_t;
  52. #endif
  53.  
  54. #endif /* __rtems__ || __XMK__ */
  55.  
  56. #ifndef __need_inttypes
  57.  
  58. #define _SYS_TYPES_H
  59. #include <sys/_types.h>
  60. #include <sys/_stdint.h>
  61.  
  62. #ifdef __i386__
  63. #if defined (GO32) || defined (__MSDOS__)
  64. #define __MS_types__
  65. #endif
  66. #endif
  67.  
  68. # include <stddef.h>
  69. # include <machine/types.h>
  70.  
  71. /* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
  72.    changes, we assume sizeof short and long never change and have all types
  73.    used to define struct stat use them and not int where possible.
  74.    Where not possible, _ST_INTxx are used.  It would be preferable to not have
  75.    such assumptions, but until the extra fluff is necessary, it's avoided.
  76.    No 64 bit targets use stat yet.  What to do about them is postponed
  77.    until necessary.  */
  78. #ifdef __GNUC__
  79. #define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
  80. #else
  81. #define _ST_INT32
  82. #endif
  83.  
  84. #if __BSD_VISIBLE
  85. #include <sys/select.h>
  86. #  define       physadr         physadr_t
  87. #  define       quad            quad_t
  88. #endif
  89.  
  90. #if __MISC_VISIBLE
  91. #ifndef _BSDTYPES_DEFINED
  92. /* also defined in mingw/gmon.h and in w32api/winsock[2].h */
  93. #ifndef __u_char_defined
  94. typedef unsigned char   u_char;
  95. #define __u_char_defined
  96. #endif
  97. #ifndef __u_short_defined
  98. typedef unsigned short  u_short;
  99. #define __u_short_defined
  100. #endif
  101. #ifndef __u_int_defined
  102. typedef unsigned int    u_int;
  103. #define __u_int_defined
  104. #endif
  105. #ifndef __u_long_defined
  106. typedef unsigned long   u_long;
  107. #define __u_long_defined
  108. #endif
  109. #define _BSDTYPES_DEFINED
  110. #endif
  111. #endif  /*__BSD_VISIBLE || __CYGWIN__ */
  112.  
  113. #if __MISC_VISIBLE
  114. typedef unsigned short  ushort;         /* System V compatibility */
  115. typedef unsigned int    uint;           /* System V compatibility */
  116. typedef unsigned long   ulong;          /* System V compatibility */
  117. #endif
  118.  
  119. #ifndef __clock_t_defined
  120. typedef _CLOCK_T_ clock_t;
  121. #define __clock_t_defined
  122. #endif
  123.  
  124. #ifndef __time_t_defined
  125. typedef _TIME_T_ time_t;
  126. #define __time_t_defined
  127. #endif
  128.  
  129. #ifndef __daddr_t_defined
  130. typedef long    daddr_t;
  131. #define __daddr_t_defined
  132. #endif
  133. #ifndef __caddr_t_defined
  134. typedef char *  caddr_t;
  135. #define __caddr_t_defined
  136. #endif
  137.  
  138. #ifndef __CYGWIN__
  139. #if defined(__MS_types__) || defined(__rtems__) || \
  140.     defined(__sparc__) || defined(__SPU__)
  141. typedef unsigned long   ino_t;
  142. #else
  143. typedef unsigned short  ino_t;
  144. #endif
  145. #endif /*__CYGWIN__*/
  146.  
  147. #ifdef __MS_types__
  148. typedef unsigned long vm_offset_t;
  149. typedef unsigned long vm_size_t;
  150.  
  151. #define __BIT_TYPES_DEFINED__
  152.  
  153. typedef signed char int8_t;
  154. typedef unsigned char u_int8_t;
  155. typedef short int16_t;
  156. typedef unsigned short u_int16_t;
  157. typedef int int32_t;
  158. typedef unsigned int u_int32_t;
  159. typedef long long int64_t;
  160. typedef unsigned long long u_int64_t;
  161. typedef int32_t register_t;
  162. #endif /* __MS_types__ */
  163.  
  164. /*
  165.  * All these should be machine specific - right now they are all broken.
  166.  * However, for all of Cygnus' embedded targets, we want them to all be
  167.  * the same.  Otherwise things like sizeof (struct stat) might depend on
  168.  * how the file was compiled (e.g. -mint16 vs -mint32, etc.).
  169.  */
  170.  
  171. #ifndef __CYGWIN__      /* which defines these types in it's own types.h. */
  172. typedef _off_t  off_t;
  173. typedef __dev_t dev_t;
  174. typedef __uid_t uid_t;
  175. typedef __gid_t gid_t;
  176. #endif
  177.  
  178. #if defined(__XMK__)
  179. typedef signed char pid_t;
  180. #else
  181. typedef int pid_t;
  182. #endif
  183.  
  184. #if defined(__rtems__)
  185. typedef _mode_t mode_t;
  186. #endif
  187.  
  188. #ifndef __CYGWIN__
  189. typedef long key_t;
  190. #endif
  191.  
  192. #ifndef _SSIZE_T_DECLARED
  193. typedef _ssize_t ssize_t;
  194. #define _SSIZE_T_DECLARED
  195. #endif
  196.  
  197. #if !defined(__CYGWIN__) && !defined(__rtems__)
  198. #ifdef __MS_types__
  199. typedef char *  addr_t;
  200. typedef int mode_t;
  201. #else
  202. #if defined (__sparc__) && !defined (__sparc_v9__)
  203. #ifdef __svr4__
  204. typedef unsigned long mode_t;
  205. #else
  206. typedef unsigned short mode_t;
  207. #endif
  208. #else
  209. typedef unsigned int mode_t _ST_INT32;
  210. #endif
  211. #endif /* ! __MS_types__ */
  212. #endif /*__CYGWIN__*/
  213.  
  214. typedef unsigned short nlink_t;
  215.  
  216. #undef __MS_types__
  217. #undef _ST_INT32
  218.  
  219.  
  220. #ifndef __clockid_t_defined
  221. typedef _CLOCKID_T_ clockid_t;
  222. #define __clockid_t_defined
  223. #endif
  224.  
  225. #ifndef __timer_t_defined
  226. typedef _TIMER_T_ timer_t;
  227. #define __timer_t_defined
  228. #endif
  229.  
  230. typedef unsigned long useconds_t;
  231.  
  232. #ifndef _SUSECONDS_T_DECLARED
  233. typedef __suseconds_t   suseconds_t;
  234. #define _SUSECONDS_T_DECLARED
  235. #endif
  236.  
  237. typedef __int64_t       sbintime_t;
  238.  
  239. #include <sys/features.h>
  240.  
  241.  
  242. /* Cygwin will probably never have full posix compliance due to little things
  243.  * like an inability to set the stackaddress. Cygwin is also using void *  
  244.  * pointers rather than structs to ensure maximum binary compatability with
  245.  * previous releases.
  246.  * This means that we don't use the types defined here, but rather in
  247.  * <cygwin/types.h>
  248.  */
  249. #if defined(_POSIX_THREADS) && !defined(__CYGWIN__)
  250.  
  251. #include <sys/sched.h>
  252.  
  253. /*
  254.  *  2.5 Primitive System Data Types,  P1003.1c/D10, p. 19.
  255.  */
  256.  
  257. #if defined(__XMK__)
  258. typedef unsigned int pthread_t;          /* identify a thread */
  259. #else
  260. typedef __uint32_t pthread_t;            /* identify a thread */
  261. #endif
  262.  
  263. /* P1003.1c/D10, p. 118-119 */
  264. #define PTHREAD_SCOPE_PROCESS 0
  265. #define PTHREAD_SCOPE_SYSTEM  1
  266.  
  267. /* P1003.1c/D10, p. 111 */
  268. #define PTHREAD_INHERIT_SCHED  1      /* scheduling policy and associated */
  269.                                       /*   attributes are inherited from */
  270.                                       /*   the calling thread. */
  271. #define PTHREAD_EXPLICIT_SCHED 2      /* set from provided attribute object */
  272.  
  273. /* P1003.1c/D10, p. 141 */
  274. #define PTHREAD_CREATE_DETACHED 0
  275. #define PTHREAD_CREATE_JOINABLE  1
  276.  
  277. #if defined(__rtems__)
  278.   #include <sys/cpuset.h>
  279. #endif
  280.  
  281. #if defined(__XMK__)
  282. typedef struct pthread_attr_s {
  283.   int contentionscope;
  284.   struct sched_param schedparam;
  285.   int  detachstate;
  286.   void *stackaddr;
  287.   size_t stacksize;
  288. } pthread_attr_t;
  289.  
  290. #define PTHREAD_STACK_MIN       200
  291.  
  292. #else /* !defined(__XMK__) */
  293. typedef struct {
  294.   int is_initialized;
  295.   void *stackaddr;
  296.   int stacksize;
  297.   int contentionscope;
  298.   int inheritsched;
  299.   int schedpolicy;
  300.   struct sched_param schedparam;
  301. #if defined(__rtems__)
  302.   size_t guardsize;
  303. #endif
  304.  
  305.   /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute.  */
  306. #if defined(_POSIX_THREAD_CPUTIME)
  307.   int  cputime_clock_allowed;  /* see time.h */
  308. #endif
  309.   int  detachstate;
  310. #if defined(__rtems__)
  311.   size_t affinitysetsize;
  312.   cpu_set_t *affinityset;
  313.   cpu_set_t affinitysetpreallocated;
  314. #endif
  315. } pthread_attr_t;
  316.  
  317. #endif /* !defined(__XMK__) */
  318.  
  319. #if defined(_POSIX_THREAD_PROCESS_SHARED)
  320. /* NOTE: P1003.1c/D10, p. 81 defines following values for process_shared.  */
  321.  
  322. #define PTHREAD_PROCESS_PRIVATE 0 /* visible within only the creating process */
  323. #define PTHREAD_PROCESS_SHARED  1 /* visible too all processes with access to */
  324.                                   /*   the memory where the resource is */
  325.                                   /*   located */
  326. #endif
  327.  
  328. #if defined(_POSIX_THREAD_PRIO_PROTECT)
  329. /* Mutexes */
  330.  
  331. /* Values for blocking protocol. */
  332.  
  333. #define PTHREAD_PRIO_NONE    0
  334. #define PTHREAD_PRIO_INHERIT 1
  335. #define PTHREAD_PRIO_PROTECT 2
  336. #endif
  337.  
  338. #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
  339.  
  340. /* Values for mutex type */
  341.  
  342. /* The following defines are part of the X/Open System Interface (XSI). */
  343.  
  344. /*
  345.  * This type of mutex does not detect deadlock. A thread attempting to
  346.  * relock this mutex without first unlocking it shall deadlock. Attempting
  347.  * to unlock a mutex locked by a different thread results in undefined
  348.  * behavior.  Attempting to unlock an unlocked mutex results in undefined
  349.  * behavior.
  350.  */
  351. #define PTHREAD_MUTEX_NORMAL     0
  352.  
  353. /*
  354.  * A thread attempting to relock this mutex without first unlocking
  355.  * it shall succeed in locking the mutex.  The relocking deadlock which
  356.  * can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with
  357.  * this type of mutex.  Multiple locks of this mutex shall require the
  358.  * same number of unlocks to release the mutex before another thread can
  359.  * acquire the mutex. A thread attempting to unlock a mutex which another
  360.  * thread has locked shall return with an error.  A thread attempting to
  361.  * unlock an unlocked mutex shall return with an error.
  362.  */
  363. #define PTHREAD_MUTEX_RECURSIVE  1
  364.  
  365. /*
  366.  * This type of mutex provides error checking. A thread attempting
  367.  * to relock this mutex without first unlocking it shall return with an
  368.  * error. A thread attempting to unlock a mutex which another thread has
  369.  * locked shall return with an error. A thread attempting to unlock an
  370.  * unlocked mutex shall return with an error.
  371.  */
  372. #define PTHREAD_MUTEX_ERRORCHECK 2
  373.  
  374. /*
  375.  * Attempting to recursively lock a mutex of this type results
  376.  * in undefined behavior. Attempting to unlock a mutex of this type
  377.  * which was not locked by the calling thread results in undefined
  378.  * behavior. Attempting to unlock a mutex of this type which is not locked
  379.  * results in undefined behavior. An implementation may map this mutex to
  380.  * one of the other mutex types.
  381.  */
  382. #define PTHREAD_MUTEX_DEFAULT    3
  383.  
  384. #endif /* !defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) */
  385.  
  386. #if defined(__XMK__)
  387. typedef unsigned int pthread_mutex_t;    /* identify a mutex */
  388.  
  389. typedef struct {
  390.   int type;
  391. } pthread_mutexattr_t;
  392.  
  393. #else /* !defined(__XMK__) */
  394. typedef __uint32_t pthread_mutex_t;      /* identify a mutex */
  395.  
  396. typedef struct {
  397.   int   is_initialized;
  398. #if defined(_POSIX_THREAD_PROCESS_SHARED)
  399.   int   process_shared;  /* allow mutex to be shared amongst processes */
  400. #endif
  401. #if defined(_POSIX_THREAD_PRIO_PROTECT)
  402.   int   prio_ceiling;
  403.   int   protocol;
  404. #endif
  405. #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
  406.   int type;
  407. #endif
  408.   int   recursive;
  409. } pthread_mutexattr_t;
  410. #endif /* !defined(__XMK__) */
  411.  
  412. /* Condition Variables */
  413.  
  414. typedef __uint32_t pthread_cond_t;       /* identify a condition variable */
  415.  
  416. typedef struct {
  417.   int   is_initialized;
  418.   clock_t  clock;             /* specifiy clock for timeouts */
  419. #if defined(_POSIX_THREAD_PROCESS_SHARED)
  420.   int   process_shared;       /* allow this to be shared amongst processes */
  421. #endif
  422. } pthread_condattr_t;         /* a condition attribute object */
  423.  
  424. /* Keys */
  425.  
  426. typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
  427.  
  428. typedef struct {
  429.   int   is_initialized;  /* is this structure initialized? */
  430.   int   init_executed;   /* has the initialization routine been run? */
  431. } pthread_once_t;       /* dynamic package initialization */
  432. #else
  433. #if defined (__CYGWIN__)
  434. #include <cygwin/types.h>
  435. #endif
  436. #endif /* defined(_POSIX_THREADS) */
  437.  
  438. /* POSIX Barrier Types */
  439.  
  440. #if !defined(__CYGWIN__)
  441. #if defined(_POSIX_BARRIERS)
  442. typedef __uint32_t pthread_barrier_t;        /* POSIX Barrier Object */
  443. typedef struct {
  444.   int   is_initialized;  /* is this structure initialized? */
  445. #if defined(_POSIX_THREAD_PROCESS_SHARED)
  446.   int   process_shared;       /* allow this to be shared amongst processes */
  447. #endif
  448. } pthread_barrierattr_t;
  449. #endif /* defined(_POSIX_BARRIERS) */
  450.  
  451. /* POSIX Spin Lock Types */
  452.  
  453. #if defined(_POSIX_SPIN_LOCKS)
  454. typedef __uint32_t pthread_spinlock_t;        /* POSIX Spin Lock Object */
  455. #endif /* defined(_POSIX_SPIN_LOCKS) */
  456.  
  457. /* POSIX Reader/Writer Lock Types */
  458.  
  459. #if defined(_POSIX_READER_WRITER_LOCKS)
  460. typedef __uint32_t pthread_rwlock_t;         /* POSIX RWLock Object */
  461. typedef struct {
  462.   int   is_initialized;       /* is this structure initialized? */
  463. #if defined(_POSIX_THREAD_PROCESS_SHARED)
  464.   int   process_shared;       /* allow this to be shared amongst processes */
  465. #endif
  466. } pthread_rwlockattr_t;
  467. #endif /* defined(_POSIX_READER_WRITER_LOCKS) */
  468. #endif /* __CYGWIN__ */
  469.  
  470. #endif  /* !__need_inttypes */
  471.  
  472. #undef __need_inttypes
  473.  
  474. #endif  /* _SYS_TYPES_H */
  475.