Merge commit '281819e5f8b19cd8627541a22d261906fd190276' into merges
[unleashed.git] / include / sys / types.h
blob907371282666b037f5f1e68c9fba8e4d3eb8e348
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
26 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
29 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
30 * Copyright 2016 Joyent, Inc.
33 #ifndef _SYS_TYPES_H
34 #define _SYS_TYPES_H
36 #include <sys/feature_tests.h>
37 #include <sys/isa_defs.h>
40 * Machine dependent definitions moved to <sys/machtypes.h>.
42 #include <sys/machtypes.h>
45 * Include fixed width type declarations proposed by the ISO/JTC1/SC22/WG14 C
46 * committee's working draft for the revision of the current ISO C standard,
47 * ISO/IEC 9899:1990 Programming language - C. These are not currently
48 * required by any standard but constitute a useful, general purpose set
49 * of type definitions which is namespace clean with respect to all standards.
51 #ifdef _KERNEL
52 #include <sys/inttypes.h>
53 #else /* _KERNEL */
54 #include <sys/int_types.h>
55 #endif /* _KERNEL */
57 #if defined(_KERNEL) || defined(_SYSCALL32)
58 #include <sys/types32.h>
59 #endif
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
66 * Strictly conforming ANSI C environments prior to the 1999
67 * revision of the C Standard (ISO/IEC 9899:1999) do not have
68 * the long long data type.
70 #if defined(_LONGLONG_TYPE)
71 typedef long long longlong_t;
72 typedef unsigned long long u_longlong_t;
73 #else
74 /* used to reserve space and generate alignment */
75 typedef union {
76 double _d;
77 int32_t _l[2];
78 } longlong_t;
79 typedef union {
80 double _d;
81 uint32_t _l[2];
82 } u_longlong_t;
83 #endif /* defined(_LONGLONG_TYPE) */
86 * These types (t_{u}scalar_t) exist because the XTI/TPI/DLPI standards had
87 * to use them instead of int32_t and uint32_t because DEC had
88 * shipped 64-bit wide.
90 typedef int32_t t_scalar_t;
91 typedef uint32_t t_uscalar_t;
94 * POSIX Extensions
96 typedef unsigned char uchar_t;
97 typedef unsigned short ushort_t;
98 typedef unsigned int uint_t;
99 typedef unsigned long ulong_t;
101 typedef char *caddr_t; /* ?<core address> type */
102 typedef long daddr_t; /* <disk address> type */
103 typedef short cnt_t; /* ?<count> type */
105 #if !defined(_PTRDIFF_T) || __cplusplus >= 199711L
106 #define _PTRDIFF_T
107 #if defined(_LP64) || defined(_I32LPx)
108 typedef long ptrdiff_t; /* pointer difference */
109 #else
110 typedef int ptrdiff_t; /* (historical version) */
111 #endif
112 #endif
115 * VM-related types
117 typedef ulong_t pfn_t; /* page frame number */
118 typedef ulong_t pgcnt_t; /* number of pages */
119 typedef long spgcnt_t; /* signed number of pages */
121 typedef uchar_t use_t; /* use count for swap. */
122 typedef short sysid_t;
123 typedef short index_t;
124 typedef void *timeout_id_t; /* opaque handle from timeout(9F) */
125 typedef void *bufcall_id_t; /* opaque handle from bufcall(9F) */
128 * The size of off_t and related types depends on the setting of
129 * _FILE_OFFSET_BITS. (Note that other system headers define other types
130 * related to those defined here.)
132 * If _LARGEFILE64_SOURCE is defined, variants of these types that are
133 * explicitly 64 bits wide become available.
135 #ifndef _OFF_T
136 #define _OFF_T
138 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
139 typedef long off_t; /* offsets within files */
140 #elif _FILE_OFFSET_BITS == 64
141 typedef longlong_t off_t; /* offsets within files */
142 #endif
144 #if defined(_LARGEFILE64_SOURCE)
145 #ifdef _LP64
146 typedef off_t off64_t; /* offsets within files */
147 #else
148 typedef longlong_t off64_t; /* offsets within files */
149 #endif
150 #endif /* _LARGEFILE64_SOURCE */
152 #endif /* _OFF_T */
154 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
155 typedef ulong_t ino_t; /* expanded inode type */
156 typedef long blkcnt_t; /* count of file blocks */
157 typedef ulong_t fsblkcnt_t; /* count of file system blocks */
158 typedef ulong_t fsfilcnt_t; /* count of files */
159 #elif _FILE_OFFSET_BITS == 64
160 typedef u_longlong_t ino_t; /* expanded inode type */
161 typedef longlong_t blkcnt_t; /* count of file blocks */
162 typedef u_longlong_t fsblkcnt_t; /* count of file system blocks */
163 typedef u_longlong_t fsfilcnt_t; /* count of files */
164 #endif
166 #if defined(_LARGEFILE64_SOURCE)
167 #ifdef _LP64
168 typedef ino_t ino64_t; /* expanded inode type */
169 typedef blkcnt_t blkcnt64_t; /* count of file blocks */
170 typedef fsblkcnt_t fsblkcnt64_t; /* count of file system blocks */
171 typedef fsfilcnt_t fsfilcnt64_t; /* count of files */
172 #else
173 typedef u_longlong_t ino64_t; /* expanded inode type */
174 typedef longlong_t blkcnt64_t; /* count of file blocks */
175 typedef u_longlong_t fsblkcnt64_t; /* count of file system blocks */
176 typedef u_longlong_t fsfilcnt64_t; /* count of files */
177 #endif
178 #endif /* _LARGEFILE64_SOURCE */
180 #ifdef _LP64
181 typedef int blksize_t; /* used for block sizes */
182 #else
183 typedef long blksize_t; /* used for block sizes */
184 #endif
186 #if defined(__XOPEN_OR_POSIX)
187 typedef enum { _B_FALSE, _B_TRUE } boolean_t;
188 #else
189 typedef enum { B_FALSE, B_TRUE } boolean_t;
190 #endif /* defined(__XOPEN_OR_POSIX) */
193 * The {u,}pad64_t types can be used in structures such that those structures
194 * may be accessed by code produced by compilation environments which don't
195 * support a 64 bit integral datatype. The intention is not to allow
196 * use of these fields in such environments, but to maintain the alignment
197 * and offsets of the structure.
199 * Similar comments for {u,}pad128_t.
201 * Note that these types do NOT generate any stronger alignment constraints
202 * than those available in the underlying ABI. See <sys/isa_defs.h>
204 #if defined(_INT64_TYPE)
205 typedef int64_t pad64_t;
206 typedef uint64_t upad64_t;
207 #else
208 typedef union {
209 double _d;
210 int32_t _l[2];
211 } pad64_t;
213 typedef union {
214 double _d;
215 uint32_t _l[2];
216 } upad64_t;
217 #endif
219 typedef union {
220 long double _q;
221 int32_t _l[4];
222 } pad128_t;
224 typedef union {
225 long double _q;
226 uint32_t _l[4];
227 } upad128_t;
229 typedef longlong_t offset_t;
230 typedef u_longlong_t uoff_t;
231 typedef u_longlong_t len_t;
232 typedef u_longlong_t diskaddr_t;
233 #if (defined(_KERNEL) || defined(_KMEMUSER) || defined(_BOOT))
234 typedef uint64_t paddr_t;
235 #endif
238 * Definitions remaining from previous partial support for 64-bit file
239 * offsets. This partial support for devices greater than 2gb requires
240 * compiler support for long long.
242 #ifdef _LONG_LONG_LTOH
243 typedef union {
244 offset_t _f; /* Full 64 bit offset value */
245 struct {
246 int32_t _l; /* lower 32 bits of offset value */
247 int32_t _u; /* upper 32 bits of offset value */
248 } _p;
249 } lloff_t;
250 #endif
252 #ifdef _LONG_LONG_HTOL
253 typedef union {
254 offset_t _f; /* Full 64 bit offset value */
255 struct {
256 int32_t _u; /* upper 32 bits of offset value */
257 int32_t _l; /* lower 32 bits of offset value */
258 } _p;
259 } lloff_t;
260 #endif
262 #ifdef _LONG_LONG_LTOH
263 typedef union {
264 longlong_t _f; /* Full 64 bit disk address value */
265 struct {
266 int32_t _l; /* lower 32 bits of disk address value */
267 int32_t _u; /* upper 32 bits of disk address value */
268 } _p;
269 } lldaddr_t;
270 #endif
272 #ifdef _LONG_LONG_HTOL
273 typedef union {
274 longlong_t _f; /* Full 64 bit disk address value */
275 struct {
276 int32_t _u; /* upper 32 bits of disk address value */
277 int32_t _l; /* lower 32 bits of disk address value */
278 } _p;
279 } lldaddr_t;
280 #endif
282 typedef uint_t k_fltset_t; /* kernel fault set type */
285 * The following type is for various kinds of identifiers. The
286 * actual type must be the same for all since some system calls
287 * (such as sigsend) take arguments that may be any of these
288 * types. The enumeration type idtype_t defined in sys/procset.h
289 * is used to indicate what type of id is being specified --
290 * a process id, process group id, session id, scheduling class id,
291 * user id, group id, project id, task id or zone id.
293 typedef int id_t;
295 typedef id_t lgrp_id_t; /* lgroup ID */
298 * Type useconds_t is an unsigned integral type capable of storing
299 * values at least in the range of zero to 1,000,000.
301 typedef uint_t useconds_t; /* Time, in microseconds */
303 #ifndef _SUSECONDS_T
304 #define _SUSECONDS_T
305 typedef long suseconds_t; /* signed # of microseconds */
306 #endif /* _SUSECONDS_T */
309 * Typedefs for dev_t components.
311 typedef unsigned int major_t; /* major part of device number */
312 typedef unsigned int minor_t; /* minor part of device number */
315 * The data type of a thread priority.
317 typedef short pri_t;
320 * The data type for a CPU flags field. (Can be extended to larger unsigned
321 * types, if needed, limited by ability to update atomically.)
323 typedef ushort_t cpu_flag_t;
326 * For compatibility reasons the following typedefs (prefixed o_)
327 * can't grow regardless of the EFT definition. Although,
328 * applications should not explicitly use these typedefs
329 * they may be included via a system header definition.
330 * WARNING: These typedefs may be removed in a future
331 * release.
332 * ex. the definitions in s5inode.h (now obsoleted)
333 * remained small to preserve compatibility
334 * in the S5 file system type.
336 typedef ushort_t o_mode_t; /* old file attribute type */
337 typedef short o_dev_t; /* old device type */
338 typedef ushort_t o_uid_t; /* old UID type */
339 typedef o_uid_t o_gid_t; /* old GID type */
340 typedef short o_nlink_t; /* old file link type */
341 typedef short o_pid_t; /* old process id type */
342 typedef ushort_t o_ino_t; /* old inode type */
346 * POSIX and XOPEN Declarations
348 typedef int key_t; /* IPC key type */
349 typedef unsigned int mode_t; /* file attribute type */
351 #ifndef _UID_T
352 #define _UID_T
353 typedef unsigned int uid_t; /* UID type */
354 #endif /* _UID_T */
356 typedef uid_t gid_t; /* GID type */
358 typedef uint32_t datalink_id_t;
359 typedef uint32_t vrid_t;
361 typedef id_t taskid_t;
362 typedef id_t projid_t;
363 typedef id_t poolid_t;
364 typedef id_t zoneid_t;
365 typedef id_t ctid_t;
368 * POSIX definitions are same as defined in thread.h and synch.h.
369 * Any changes made to here should be reflected in corresponding
370 * files as described in comments.
372 typedef uint_t pthread_t; /* = thread_t in thread.h */
373 typedef uint_t pthread_key_t; /* = thread_key_t in thread.h */
375 /* "Magic numbers" tagging synchronization object types */
376 #define _MUTEX_MAGIC 0x4d58 /* "MX" */
377 #define _SEMA_MAGIC 0x534d /* "SM" */
378 #define _COND_MAGIC 0x4356 /* "CV" */
379 #define _RWL_MAGIC 0x5257 /* "RW" */
381 typedef struct _pthread_mutex { /* = mutex_t in synch.h */
382 struct {
383 uint16_t __pthread_mutex_flag1;
384 uint8_t __pthread_mutex_flag2;
385 uint8_t __pthread_mutex_ceiling;
386 uint16_t __pthread_mutex_type;
387 uint16_t __pthread_mutex_magic;
388 } __pthread_mutex_flags;
389 union {
390 struct {
391 uint8_t __pthread_mutex_pad[8];
392 } __pthread_mutex_lock64;
393 struct {
394 uint32_t __pthread_ownerpid;
395 uint32_t __pthread_lockword;
396 } __pthread_mutex_lock32;
397 upad64_t __pthread_mutex_owner64;
398 } __pthread_mutex_lock;
399 upad64_t __pthread_mutex_data;
400 } pthread_mutex_t;
402 typedef struct _pthread_cond { /* = cond_t in synch.h */
403 struct {
404 uint8_t __pthread_cond_flag[4];
405 uint16_t __pthread_cond_type;
406 uint16_t __pthread_cond_magic;
407 } __pthread_cond_flags;
408 upad64_t __pthread_cond_data;
409 } pthread_cond_t;
412 * UNIX 98 Extension
414 typedef struct _pthread_rwlock { /* = rwlock_t in synch.h */
415 int32_t __pthread_rwlock_readers;
416 uint16_t __pthread_rwlock_type;
417 uint16_t __pthread_rwlock_magic;
418 pthread_mutex_t __pthread_rwlock_mutex;
419 pthread_cond_t __pthread_rwlock_readercv;
420 pthread_cond_t __pthread_rwlock_writercv;
421 } pthread_rwlock_t;
424 * SUSV3
426 typedef struct {
427 uint32_t __pthread_barrier_count;
428 uint32_t __pthread_barrier_current;
429 upad64_t __pthread_barrier_cycle;
430 upad64_t __pthread_barrier_reserved;
431 pthread_mutex_t __pthread_barrier_lock;
432 pthread_cond_t __pthread_barrier_cond;
433 } pthread_barrier_t;
435 typedef pthread_mutex_t pthread_spinlock_t;
438 * attributes for threads, dynamically allocated by library
440 typedef struct _pthread_attr {
441 void *__pthread_attrp;
442 } pthread_attr_t;
445 * attributes for mutex, dynamically allocated by library
447 typedef struct _pthread_mutexattr {
448 void *__pthread_mutexattrp;
449 } pthread_mutexattr_t;
452 * attributes for cond, dynamically allocated by library
454 typedef struct _pthread_condattr {
455 void *__pthread_condattrp;
456 } pthread_condattr_t;
459 * pthread_once
461 typedef struct _once {
462 upad64_t __pthread_once_pad[4];
463 } pthread_once_t;
466 * UNIX 98 Extensions
467 * attributes for rwlock, dynamically allocated by library
469 typedef struct _pthread_rwlockattr {
470 void *__pthread_rwlockattrp;
471 } pthread_rwlockattr_t;
474 * SUSV3
475 * attributes for pthread_barrier_t, dynamically allocated by library
477 typedef struct {
478 void *__pthread_barrierattrp;
479 } pthread_barrierattr_t;
481 typedef ulong_t dev_t; /* expanded device type */
483 typedef unsigned int nlink_t; /* file link type */
484 typedef int pid_t; /* process id type */
486 #if !defined(_SIZE_T) || __cplusplus >= 199711L
487 #define _SIZE_T
488 #if defined(_LP64) || defined(_I32LPx)
489 typedef ulong_t size_t; /* size of something in bytes */
490 #else
491 typedef uint_t size_t; /* (historical version) */
492 #endif
493 #endif /* _SIZE_T */
495 #ifndef _SSIZE_T
496 #define _SSIZE_T
497 #if defined(_LP64) || defined(_I32LPx)
498 typedef long ssize_t; /* size of something in bytes or -1 */
499 #else
500 typedef int ssize_t; /* (historical version) */
501 #endif
502 #endif /* _SSIZE_T */
504 #if !defined(_TIME_T) || __cplusplus >= 199711L
505 #define _TIME_T
506 typedef long time_t; /* time of day in seconds */
507 #endif /* _TIME_T */
509 #if !defined(_CLOCK_T) || __cplusplus >= 199711L
510 #define _CLOCK_T
511 typedef long clock_t; /* relative time in a specified resolution */
512 #endif /* ifndef _CLOCK_T */
514 #ifndef _CLOCKID_T
515 #define _CLOCKID_T
516 typedef int clockid_t; /* clock identifier type */
517 #endif /* ifndef _CLOCKID_T */
519 #ifndef _TIMER_T
520 #define _TIMER_T
521 typedef int timer_t; /* timer identifier type */
522 #endif /* ifndef _TIMER_T */
524 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
526 /* BEGIN CSTYLED */
527 typedef unsigned char unchar;
528 typedef unsigned short ushort;
529 typedef unsigned int uint;
530 typedef unsigned long ulong;
531 /* END CSTYLED */
533 #if defined(_KERNEL)
535 #define SHRT_MIN (-32768) /* min value of a "short int" */
536 #define SHRT_MAX 32767 /* max value of a "short int" */
537 #define USHRT_MAX 65535 /* max of "unsigned short int" */
538 #define INT_MIN (-2147483647-1) /* min value of an "int" */
539 #define INT_MAX 2147483647 /* max value of an "int" */
540 #define UINT_MAX 4294967295U /* max value of an "unsigned int" */
541 #if defined(_LP64)
542 #define LONG_MIN (-9223372036854775807L-1L)
543 /* min value of a "long int" */
544 #define LONG_MAX 9223372036854775807L
545 /* max value of a "long int" */
546 #define ULONG_MAX 18446744073709551615UL
547 /* max of "unsigned long int" */
548 #else /* _ILP32 */
549 #define LONG_MIN (-2147483647L-1L)
550 /* min value of a "long int" */
551 #define LONG_MAX 2147483647L /* max value of a "long int" */
552 #define ULONG_MAX 4294967295UL /* max of "unsigned long int" */
553 #endif
555 #define LLONG_MIN (-9223372036854775807LL-1LL)
556 /* min of "long long int" */
557 #define LLONG_MAX 9223372036854775807LL
558 /* max of "long long int" */
559 #define ULLONG_MAX 18446744073709551615ULL
560 /* max of "unsigned long long int" */
562 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
563 #define OFF_MIN LONG_MIN
564 #define OFF_MAX LONG_MAX
565 #elif _FILE_OFFSET_BITS == 64
566 #define OFF_MIN LLONG_MIN
567 #define OFF_MAX LLONG_MAX
568 #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */
570 #endif /* defined(_KERNEL) */
572 #define P_MYPID ((pid_t)0)
575 * The following is the value of type id_t to use to indicate the
576 * caller's current id. See procset.h for the type idtype_t
577 * which defines which kind of id is being specified.
579 #define P_MYID (-1)
580 #define NOPID (pid_t)(-1)
582 #ifndef NODEV
583 #define NODEV (dev_t)(-1l)
584 #ifdef _SYSCALL32
585 #define NODEV32 (dev32_t)(-1)
586 #endif /* _SYSCALL32 */
587 #endif /* NODEV */
590 * The following value of type pfn_t is used to indicate
591 * invalid page frame number.
593 #define PFN_INVALID ((pfn_t)-1)
594 #define PFN_SUSPENDED ((pfn_t)-2)
596 /* BEGIN CSTYLED */
597 typedef unsigned char u_char;
598 typedef unsigned short u_short;
599 typedef unsigned int u_int;
600 typedef unsigned long u_long;
601 typedef struct _quad { int val[2]; } quad_t; /* used by UFS */
602 typedef quad_t quad; /* used by UFS */
603 /* END CSTYLED */
606 * Nested include for BSD/sockets source compatibility.
607 * (The select macros used to be defined here).
609 #include <sys/select.h>
611 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
614 * _VOID was defined to be either void or char but this is not
615 * required because previous SunOS compilers have accepted the void
616 * type. However, because many system header and source files use the
617 * void keyword, the volatile keyword, and ANSI C function prototypes,
618 * non-ANSI compilers cannot compile the system anyway. The _VOID macro
619 * should therefore not be used and remains for source compatibility
620 * only.
622 /* CSTYLED */
623 #define _VOID void
625 #ifdef __cplusplus
627 #endif
629 #endif /* _SYS_TYPES_H */