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