Subversion Repositories Kolibri OS

Rev

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