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