Subversion Repositories Kolibri OS

Rev

Rev 4874 | Rev 6099 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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