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