xref: /illumos-gate/usr/src/uts/common/sys/types.h (revision 2cb27123)
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 typedef id_t		lgrp_id_t;	/* lgroup ID */
304 
305 /*
306  * Type useconds_t is an unsigned integral type capable of storing
307  * values at least in the range of zero to 1,000,000.
308  */
309 typedef uint_t		useconds_t;	/* Time, in microseconds */
310 
311 #ifndef	_SUSECONDS_T
312 #define	_SUSECONDS_T
313 typedef long	suseconds_t;	/* signed # of microseconds */
314 #endif	/* _SUSECONDS_T */
315 
316 /*
317  * Typedefs for dev_t components.
318  */
319 #if defined(_LP64) || defined(_I32LPx)
320 typedef uint_t	major_t;	/* major part of device number */
321 typedef uint_t	minor_t;	/* minor part of device number */
322 #else
323 typedef ulong_t	major_t;	/* (historical version) */
324 typedef ulong_t	minor_t;	/* (historical version) */
325 #endif
326 
327 /*
328  * The data type of a thread priority.
329  */
330 typedef short	pri_t;
331 
332 /*
333  * The data type for a CPU flags field.  (Can be extended to larger unsigned
334  * types, if needed, limited by ability to update atomically.)
335  */
336 typedef ushort_t	cpu_flag_t;
337 
338 /*
339  * For compatibility reasons the following typedefs (prefixed o_)
340  * can't grow regardless of the EFT definition. Although,
341  * applications should not explicitly use these typedefs
342  * they may be included via a system header definition.
343  * WARNING: These typedefs may be removed in a future
344  * release.
345  *		ex. the definitions in s5inode.h (now obsoleted)
346  *			remained small to preserve compatibility
347  *			in the S5 file system type.
348  */
349 typedef	ushort_t o_mode_t;		/* old file attribute type */
350 typedef short	o_dev_t;		/* old device type	*/
351 typedef	ushort_t o_uid_t;		/* old UID type		*/
352 typedef	o_uid_t	o_gid_t;		/* old GID type		*/
353 typedef	short	o_nlink_t;		/* old file link type	*/
354 typedef short	o_pid_t;		/* old process id type	*/
355 typedef ushort_t o_ino_t;		/* old inode type	*/
356 
357 
358 /*
359  * POSIX and XOPEN Declarations
360  */
361 typedef	int	key_t;			/* IPC key type		*/
362 #if defined(_LP64) || defined(_I32LPx)
363 typedef	uint_t	mode_t;			/* file attribute type	*/
364 #else
365 typedef	ulong_t	mode_t;			/* (historical version) */
366 #endif
367 
368 #ifndef	_UID_T
369 #define	_UID_T
370 typedef	unsigned int uid_t;		/* UID type		*/
371 #endif	/* _UID_T */
372 
373 typedef	uid_t	gid_t;			/* GID type		*/
374 
375 typedef id_t    taskid_t;
376 typedef id_t    projid_t;
377 typedef	id_t	poolid_t;
378 typedef id_t	zoneid_t;
379 typedef id_t	ctid_t;
380 
381 /*
382  * POSIX definitions are same as defined in thread.h and synch.h.
383  * Any changes made to here should be reflected in corresponding
384  * files as described in comments.
385  */
386 typedef	uint_t	pthread_t;	/* = thread_t in thread.h */
387 typedef	uint_t	pthread_key_t;	/* = thread_key_t in thread.h */
388 
389 /* "Magic numbers" tagging synchronization object types */
390 #define	_MUTEX_MAGIC	0x4d58		/* "MX" */
391 #define	_SEMA_MAGIC	0x534d		/* "SM" */
392 #define	_COND_MAGIC	0x4356		/* "CV" */
393 #define	_RWL_MAGIC	0x5257		/* "RW" */
394 
395 typedef	struct _pthread_mutex {		/* = mutex_t in synch.h */
396 	struct {
397 		uint16_t	__pthread_mutex_flag1;
398 		uint8_t		__pthread_mutex_flag2;
399 		uint8_t		__pthread_mutex_ceiling;
400 		uint16_t 	__pthread_mutex_type;
401 		uint16_t 	__pthread_mutex_magic;
402 	} __pthread_mutex_flags;
403 	union {
404 		struct {
405 			uint8_t	__pthread_mutex_pad[8];
406 		} __pthread_mutex_lock64;
407 		struct {
408 			uint32_t __pthread_ownerpid;
409 			uint32_t __pthread_lockword;
410 		} __pthread_mutex_lock32;
411 		upad64_t __pthread_mutex_owner64;
412 	} __pthread_mutex_lock;
413 	upad64_t __pthread_mutex_data;
414 } pthread_mutex_t;
415 
416 typedef	struct _pthread_cond {		/* = cond_t in synch.h */
417 	struct {
418 		uint8_t		__pthread_cond_flag[4];
419 		uint16_t 	__pthread_cond_type;
420 		uint16_t 	__pthread_cond_magic;
421 	} __pthread_cond_flags;
422 	upad64_t __pthread_cond_data;
423 } pthread_cond_t;
424 
425 /*
426  * UNIX 98 Extension
427  */
428 typedef	struct _pthread_rwlock {	/* = rwlock_t in synch.h */
429 	int32_t		__pthread_rwlock_readers;
430 	uint16_t	__pthread_rwlock_type;
431 	uint16_t	__pthread_rwlock_magic;
432 	pthread_mutex_t	__pthread_rwlock_mutex;
433 	pthread_cond_t	__pthread_rwlock_readercv;
434 	pthread_cond_t	__pthread_rwlock_writercv;
435 } pthread_rwlock_t;
436 
437 /*
438  * SUSV3
439  */
440 typedef struct {
441 	uint32_t	__pthread_barrier_count;
442 	uint32_t	__pthread_barrier_current;
443 	upad64_t	__pthread_barrier_cycle;
444 	upad64_t	__pthread_barrier_reserved;
445 	pthread_mutex_t	__pthread_barrier_lock;
446 	pthread_cond_t	__pthread_barrier_cond;
447 } pthread_barrier_t;
448 
449 typedef	pthread_mutex_t	pthread_spinlock_t;
450 
451 /*
452  * attributes for threads, dynamically allocated by library
453  */
454 typedef struct _pthread_attr {
455 	void	*__pthread_attrp;
456 } pthread_attr_t;
457 
458 /*
459  * attributes for mutex, dynamically allocated by library
460  */
461 typedef struct _pthread_mutexattr {
462 	void	*__pthread_mutexattrp;
463 } pthread_mutexattr_t;
464 
465 /*
466  * attributes for cond, dynamically allocated by library
467  */
468 typedef struct _pthread_condattr {
469 	void	*__pthread_condattrp;
470 } pthread_condattr_t;
471 
472 /*
473  * pthread_once
474  */
475 typedef	struct _once {
476 	upad64_t	__pthread_once_pad[4];
477 } pthread_once_t;
478 
479 /*
480  * UNIX 98 Extensions
481  * attributes for rwlock, dynamically allocated by library
482  */
483 typedef struct _pthread_rwlockattr {
484 	void	*__pthread_rwlockattrp;
485 } pthread_rwlockattr_t;
486 
487 /*
488  * SUSV3
489  * attributes for pthread_barrier_t, dynamically allocated by library
490  */
491 typedef struct {
492 	void	*__pthread_barrierattrp;
493 } pthread_barrierattr_t;
494 
495 typedef ulong_t	dev_t;			/* expanded device type */
496 
497 #if defined(_LP64) || defined(_I32LPx)
498 typedef	uint_t nlink_t;			/* file link type	*/
499 typedef int	pid_t;			/* process id type	*/
500 #else
501 typedef	ulong_t	nlink_t;		/* (historical version) */
502 typedef	long	pid_t;			/* (historical version) */
503 #endif
504 
505 #if !defined(_SIZE_T) || __cplusplus >= 199711L
506 #define	_SIZE_T
507 #if defined(_LP64) || defined(_I32LPx)
508 typedef	ulong_t	size_t;		/* size of something in bytes */
509 #else
510 typedef	uint_t	size_t;		/* (historical version) */
511 #endif
512 #endif	/* _SIZE_T */
513 
514 #ifndef _SSIZE_T
515 #define	_SSIZE_T
516 #if defined(_LP64) || defined(_I32LPx)
517 typedef long	ssize_t;	/* size of something in bytes or -1 */
518 #else
519 typedef int	ssize_t;	/* (historical version) */
520 #endif
521 #endif	/* _SSIZE_T */
522 
523 #if !defined(_TIME_T) || __cplusplus >= 199711L
524 #define	_TIME_T
525 typedef	long		time_t;	/* time of day in seconds */
526 #endif	/* _TIME_T */
527 
528 #if !defined(_CLOCK_T) || __cplusplus >= 199711L
529 #define	_CLOCK_T
530 typedef	long		clock_t; /* relative time in a specified resolution */
531 #endif	/* ifndef _CLOCK_T */
532 
533 #ifndef _CLOCKID_T
534 #define	_CLOCKID_T
535 typedef	int	clockid_t;	/* clock identifier type */
536 #endif	/* ifndef _CLOCKID_T */
537 
538 #ifndef _TIMER_T
539 #define	_TIMER_T
540 typedef	int	timer_t;	/* timer identifier type */
541 #endif	/* ifndef _TIMER_T */
542 
543 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
544 
545 /* BEGIN CSTYLED */
546 typedef	unsigned char	unchar;
547 typedef	unsigned short	ushort;
548 typedef	unsigned int	uint;
549 typedef	unsigned long	ulong;
550 /* END CSTYLED */
551 
552 #if defined(_KERNEL)
553 
554 #define	SHRT_MIN	(-32768)	/* min value of a "short int" */
555 #define	SHRT_MAX	32767		/* max value of a "short int" */
556 #define	USHRT_MAX	65535		/* max of "unsigned short int" */
557 #define	INT_MIN		(-2147483647-1) /* min value of an "int" */
558 #define	INT_MAX		2147483647	/* max value of an "int" */
559 #define	UINT_MAX	4294967295U	/* max value of an "unsigned int" */
560 #if defined(_LP64)
561 #define	LONG_MIN	(-9223372036854775807L-1L)
562 					/* min value of a "long int" */
563 #define	LONG_MAX	9223372036854775807L
564 					/* max value of a "long int" */
565 #define	ULONG_MAX	18446744073709551615UL
566 					/* max of "unsigned long int" */
567 #else /* _ILP32 */
568 #define	LONG_MIN	(-2147483647L-1L)
569 					/* min value of a "long int" */
570 #define	LONG_MAX	2147483647L	/* max value of a "long int" */
571 #define	ULONG_MAX	4294967295UL	/* max of "unsigned long int" */
572 #endif
573 
574 #endif	/* defined(_KERNEL) */
575 
576 #define	P_MYPID	((pid_t)0)
577 
578 /*
579  * The following is the value of type id_t to use to indicate the
580  * caller's current id.  See procset.h for the type idtype_t
581  * which defines which kind of id is being specified.
582  */
583 #define	P_MYID	(-1)
584 #define	NOPID (pid_t)(-1)
585 
586 #ifndef NODEV
587 #define	NODEV	(dev_t)(-1l)
588 #ifdef _SYSCALL32
589 #define	NODEV32	(dev32_t)(-1)
590 #endif	/* _SYSCALL32 */
591 #endif	/* NODEV */
592 
593 /*
594  * The following value of type pfn_t is used to indicate
595  * invalid page frame number.
596  */
597 #define	PFN_INVALID	((pfn_t)-1)
598 #define	PFN_SUSPENDED	((pfn_t)-2)
599 
600 /* BEGIN CSTYLED */
601 typedef unsigned char	u_char;
602 typedef unsigned short	u_short;
603 typedef unsigned int	u_int;
604 typedef unsigned long	u_long;
605 typedef struct _quad { int val[2]; } quad_t;	/* used by UFS */
606 typedef quad_t		quad;			/* used by UFS */
607 /* END CSTYLED */
608 
609 /*
610  * Nested include for BSD/sockets source compatibility.
611  * (The select macros used to be defined here).
612  */
613 #include <sys/select.h>
614 
615 #endif	/* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
616 
617 /*
618  * _VOID was defined to be either void or char but this is not
619  * required because previous SunOS compilers have accepted the void
620  * type. However, because many system header and source files use the
621  * void keyword, the volatile keyword, and ANSI C function prototypes,
622  * non-ANSI compilers cannot compile the system anyway. The _VOID macro
623  * should therefore not be used and remains for source compatibility
624  * only.
625  */
626 /* CSTYLED */
627 #define	_VOID	void
628 
629 #ifdef	__cplusplus
630 }
631 #endif
632 
633 #endif	/* _SYS_TYPES_H */
634