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 typedef unsigned int uid_t; /* UID type */ 369 #endif /* _UID_T */ 370 371 typedef uid_t gid_t; /* GID type */ 372 373 typedef id_t taskid_t; 374 typedef id_t projid_t; 375 typedef id_t poolid_t; 376 typedef id_t zoneid_t; 377 typedef id_t ctid_t; 378 379 /* 380 * POSIX definitions are same as defined in thread.h and synch.h. 381 * Any changes made to here should be reflected in corresponding 382 * files as described in comments. 383 */ 384 typedef uint_t pthread_t; /* = thread_t in thread.h */ 385 typedef uint_t pthread_key_t; /* = thread_key_t in thread.h */ 386 387 /* "Magic numbers" tagging synchronization object types */ 388 #define _MUTEX_MAGIC 0x4d58 /* "MX" */ 389 #define _SEMA_MAGIC 0x534d /* "SM" */ 390 #define _COND_MAGIC 0x4356 /* "CV" */ 391 #define _RWL_MAGIC 0x5257 /* "RW" */ 392 393 typedef struct _pthread_mutex { /* = mutex_t in synch.h */ 394 struct { 395 uint16_t __pthread_mutex_flag1; 396 uint8_t __pthread_mutex_flag2; 397 uint8_t __pthread_mutex_ceiling; 398 uint16_t __pthread_mutex_type; 399 uint16_t __pthread_mutex_magic; 400 } __pthread_mutex_flags; 401 union { 402 struct { 403 uint8_t __pthread_mutex_pad[8]; 404 } __pthread_mutex_lock64; 405 struct { 406 uint32_t __pthread_ownerpid; 407 uint32_t __pthread_lockword; 408 } __pthread_mutex_lock32; 409 upad64_t __pthread_mutex_owner64; 410 } __pthread_mutex_lock; 411 upad64_t __pthread_mutex_data; 412 } pthread_mutex_t; 413 414 typedef struct _pthread_cond { /* = cond_t in synch.h */ 415 struct { 416 uint8_t __pthread_cond_flag[4]; 417 uint16_t __pthread_cond_type; 418 uint16_t __pthread_cond_magic; 419 } __pthread_cond_flags; 420 upad64_t __pthread_cond_data; 421 } pthread_cond_t; 422 423 /* 424 * UNIX 98 Extension 425 */ 426 typedef struct _pthread_rwlock { /* = rwlock_t in synch.h */ 427 int32_t __pthread_rwlock_readers; 428 uint16_t __pthread_rwlock_type; 429 uint16_t __pthread_rwlock_magic; 430 pthread_mutex_t __pthread_rwlock_mutex; 431 pthread_cond_t __pthread_rwlock_readercv; 432 pthread_cond_t __pthread_rwlock_writercv; 433 } pthread_rwlock_t; 434 435 /* 436 * SUSV3 437 */ 438 typedef struct { 439 uint32_t __pthread_barrier_count; 440 uint32_t __pthread_barrier_current; 441 upad64_t __pthread_barrier_cycle; 442 upad64_t __pthread_barrier_reserved; 443 pthread_mutex_t __pthread_barrier_lock; 444 pthread_cond_t __pthread_barrier_cond; 445 } pthread_barrier_t; 446 447 typedef pthread_mutex_t pthread_spinlock_t; 448 449 /* 450 * attributes for threads, dynamically allocated by library 451 */ 452 typedef struct _pthread_attr { 453 void *__pthread_attrp; 454 } pthread_attr_t; 455 456 /* 457 * attributes for mutex, dynamically allocated by library 458 */ 459 typedef struct _pthread_mutexattr { 460 void *__pthread_mutexattrp; 461 } pthread_mutexattr_t; 462 463 /* 464 * attributes for cond, dynamically allocated by library 465 */ 466 typedef struct _pthread_condattr { 467 void *__pthread_condattrp; 468 } pthread_condattr_t; 469 470 /* 471 * pthread_once 472 */ 473 typedef struct _once { 474 upad64_t __pthread_once_pad[4]; 475 } pthread_once_t; 476 477 /* 478 * UNIX 98 Extensions 479 * attributes for rwlock, dynamically allocated by library 480 */ 481 typedef struct _pthread_rwlockattr { 482 void *__pthread_rwlockattrp; 483 } pthread_rwlockattr_t; 484 485 /* 486 * SUSV3 487 * attributes for pthread_barrier_t, dynamically allocated by library 488 */ 489 typedef struct { 490 void *__pthread_barrierattrp; 491 } pthread_barrierattr_t; 492 493 typedef ulong_t dev_t; /* expanded device type */ 494 495 #if defined(_LP64) || defined(_I32LPx) 496 typedef uint_t nlink_t; /* file link type */ 497 typedef int pid_t; /* process id type */ 498 #else 499 typedef ulong_t nlink_t; /* (historical version) */ 500 typedef long pid_t; /* (historical version) */ 501 #endif 502 503 #if !defined(_SIZE_T) || __cplusplus >= 199711L 504 #define _SIZE_T 505 #if defined(_LP64) || defined(_I32LPx) 506 typedef ulong_t size_t; /* size of something in bytes */ 507 #else 508 typedef uint_t size_t; /* (historical version) */ 509 #endif 510 #endif /* _SIZE_T */ 511 512 #ifndef _SSIZE_T 513 #define _SSIZE_T 514 #if defined(_LP64) || defined(_I32LPx) 515 typedef long ssize_t; /* size of something in bytes or -1 */ 516 #else 517 typedef int ssize_t; /* (historical version) */ 518 #endif 519 #endif /* _SSIZE_T */ 520 521 #if !defined(_TIME_T) || __cplusplus >= 199711L 522 #define _TIME_T 523 typedef long time_t; /* time of day in seconds */ 524 #endif /* _TIME_T */ 525 526 #if !defined(_CLOCK_T) || __cplusplus >= 199711L 527 #define _CLOCK_T 528 typedef long clock_t; /* relative time in a specified resolution */ 529 #endif /* ifndef _CLOCK_T */ 530 531 #ifndef _CLOCKID_T 532 #define _CLOCKID_T 533 typedef int clockid_t; /* clock identifier type */ 534 #endif /* ifndef _CLOCKID_T */ 535 536 #ifndef _TIMER_T 537 #define _TIMER_T 538 typedef int timer_t; /* timer identifier type */ 539 #endif /* ifndef _TIMER_T */ 540 541 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 542 543 /* BEGIN CSTYLED */ 544 typedef unsigned char unchar; 545 typedef unsigned short ushort; 546 typedef unsigned int uint; 547 typedef unsigned long ulong; 548 /* END CSTYLED */ 549 550 #if defined(_KERNEL) 551 552 #define SHRT_MIN (-32768) /* min value of a "short int" */ 553 #define SHRT_MAX 32767 /* max value of a "short int" */ 554 #define USHRT_MAX 65535 /* max of "unsigned short int" */ 555 #define INT_MIN (-2147483647-1) /* min value of an "int" */ 556 #define INT_MAX 2147483647 /* max value of an "int" */ 557 #define UINT_MAX 4294967295U /* max value of an "unsigned int" */ 558 #if defined(_LP64) 559 #define LONG_MIN (-9223372036854775807L-1L) 560 /* min value of a "long int" */ 561 #define LONG_MAX 9223372036854775807L 562 /* max value of a "long int" */ 563 #define ULONG_MAX 18446744073709551615UL 564 /* max of "unsigned long int" */ 565 #else /* _ILP32 */ 566 #define LONG_MIN (-2147483647L-1L) 567 /* min value of a "long int" */ 568 #define LONG_MAX 2147483647L /* max value of a "long int" */ 569 #define ULONG_MAX 4294967295UL /* max of "unsigned long int" */ 570 #endif 571 572 #endif /* defined(_KERNEL) */ 573 574 #define P_MYPID ((pid_t)0) 575 576 /* 577 * The following is the value of type id_t to use to indicate the 578 * caller's current id. See procset.h for the type idtype_t 579 * which defines which kind of id is being specified. 580 */ 581 #define P_MYID (-1) 582 #define NOPID (pid_t)(-1) 583 584 #ifndef NODEV 585 #define NODEV (dev_t)(-1l) 586 #ifdef _SYSCALL32 587 #define NODEV32 (dev32_t)(-1) 588 #endif /* _SYSCALL32 */ 589 #endif /* NODEV */ 590 591 /* 592 * The following value of type pfn_t is used to indicate 593 * invalid page frame number. 594 */ 595 #define PFN_INVALID ((pfn_t)-1) 596 #define PFN_SUSPENDED ((pfn_t)-2) 597 598 /* BEGIN CSTYLED */ 599 typedef unsigned char u_char; 600 typedef unsigned short u_short; 601 typedef unsigned int u_int; 602 typedef unsigned long u_long; 603 typedef struct _quad { int val[2]; } quad_t; /* used by UFS */ 604 typedef quad_t quad; /* used by UFS */ 605 /* END CSTYLED */ 606 607 /* 608 * Nested include for BSD/sockets source compatibility. 609 * (The select macros used to be defined here). 610 */ 611 #include <sys/select.h> 612 613 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 614 615 /* 616 * _VOID was defined to be either void or char but this is not 617 * required because previous SunOS compilers have accepted the void 618 * type. However, because many system header and source files use the 619 * void keyword, the volatile keyword, and ANSI C function prototypes, 620 * non-ANSI compilers cannot compile the system anyway. The _VOID macro 621 * should therefore not be used and remains for source compatibility 622 * only. 623 */ 624 /* CSTYLED */ 625 #define _VOID void 626 627 #ifdef __cplusplus 628 } 629 #endif 630 631 #endif /* _SYS_TYPES_H */ 632