1 /* $NetBSD: types.h,v 1.90 2013/02/02 14:00:37 matt Exp $ */ 2 3 /*- 4 * Copyright (c) 1982, 1986, 1991, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)types.h 8.4 (Berkeley) 1/21/94 37 */ 38 39 #ifndef _SYS_TYPES_H_ 40 #define _SYS_TYPES_H_ 41 42 #include <sys/featuretest.h> 43 44 /* Machine type dependent parameters. */ 45 #include <machine/types.h> 46 47 #include <machine/ansi.h> 48 #include <machine/int_types.h> 49 50 51 #include <sys/ansi.h> 52 53 #ifndef int8_t 54 typedef __int8_t int8_t; 55 #define int8_t __int8_t 56 #endif 57 58 #ifndef uint8_t 59 typedef __uint8_t uint8_t; 60 #define uint8_t __uint8_t 61 #endif 62 63 #ifndef int16_t 64 typedef __int16_t int16_t; 65 #define int16_t __int16_t 66 #endif 67 68 #ifndef uint16_t 69 typedef __uint16_t uint16_t; 70 #define uint16_t __uint16_t 71 #endif 72 73 #ifndef int32_t 74 typedef __int32_t int32_t; 75 #define int32_t __int32_t 76 #endif 77 78 #ifndef uint32_t 79 typedef __uint32_t uint32_t; 80 #define uint32_t __uint32_t 81 #endif 82 83 #ifndef int64_t 84 typedef __int64_t int64_t; 85 #define int64_t __int64_t 86 #endif 87 88 #ifndef uint64_t 89 typedef __uint64_t uint64_t; 90 #define uint64_t __uint64_t 91 #endif 92 93 typedef uint8_t u_int8_t; 94 typedef uint16_t u_int16_t; 95 typedef uint32_t u_int32_t; 96 typedef uint64_t u_int64_t; 97 98 #ifdef __minix 99 typedef uint8_t u8_t; 100 #define u8_t uint8_t 101 typedef uint16_t u16_t; 102 #define u16_t uint16_t 103 typedef uint32_t u32_t; 104 #define u32_t uint32_t 105 typedef uint64_t u64_t; 106 #define u64_t uint64_t 107 108 typedef int8_t i8_t; 109 #define i8_t int8_t 110 typedef int16_t i16_t; 111 #define i16_t int16_t 112 typedef int32_t i32_t; 113 #define i32_t int32_t 114 typedef int64_t i64_t; 115 #define i64_t int64_t 116 117 #ifdef _NETBSD_SOURCE 118 /* some Minix specific types that do not conflict with posix */ 119 typedef uint32_t zone_t; /* zone number */ 120 typedef uint32_t block_t; /* block number */ 121 typedef uint32_t bit_t; /* bit number in a bit map */ 122 typedef uint16_t zone1_t; /* zone number for V1 file systems */ 123 typedef uint32_t bitchunk_t; /* collection of bits in a bitmap */ 124 #endif 125 #endif /* __minix */ 126 127 #include <machine/endian.h> 128 129 #if defined(_NETBSD_SOURCE) 130 typedef unsigned char u_char; 131 typedef unsigned short u_short; 132 typedef unsigned int u_int; 133 typedef unsigned long u_long; 134 135 typedef unsigned char unchar; /* Sys V compatibility */ 136 typedef unsigned short ushort; /* Sys V compatibility */ 137 typedef unsigned int uint; /* Sys V compatibility */ 138 typedef unsigned long ulong; /* Sys V compatibility */ 139 #endif 140 141 typedef uint64_t u_quad_t; /* quads */ 142 typedef int64_t quad_t; 143 typedef quad_t * qaddr_t; 144 145 /* 146 * The types longlong_t and u_longlong_t exist for use with the 147 * Sun-derived XDR routines involving these types, and their usage 148 * in other contexts is discouraged. Further note that these types 149 * may not be equivalent to "long long" and "unsigned long long", 150 * they are only guaranteed to be signed and unsigned 64-bit types 151 * respectively. Portable programs that need 64-bit types should use 152 * the C99 types int64_t and uint64_t instead. 153 */ 154 155 typedef int64_t longlong_t; /* for XDR */ 156 typedef uint64_t u_longlong_t; /* for XDR */ 157 158 typedef int64_t blkcnt_t; /* fs block count */ 159 typedef int32_t blksize_t; /* fs optimal block size */ 160 161 #ifndef fsblkcnt_t 162 typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */ 163 #define fsblkcnt_t __fsblkcnt_t 164 #endif 165 166 #ifndef fsfilcnt_t 167 typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */ 168 #define fsfilcnt_t __fsfilcnt_t 169 #endif 170 171 #if !defined(_KERNEL) && !defined(_STANDALONE) 172 /* We don't and shouldn't use caddr_t in the kernel anymore */ 173 #ifndef caddr_t 174 typedef __caddr_t caddr_t; /* core address */ 175 #define caddr_t __caddr_t 176 #endif 177 #endif 178 179 #ifdef __daddr_t 180 typedef __daddr_t daddr_t; /* disk address */ 181 #undef __daddr_t 182 #else 183 typedef int64_t daddr_t; /* disk address */ 184 #endif 185 186 typedef uint64_t dev_t; /* device number */ 187 typedef uint32_t fixpt_t; /* fixed point number */ 188 189 #ifndef gid_t 190 typedef __gid_t gid_t; /* group id */ 191 #define gid_t __gid_t 192 #endif 193 194 typedef int idtype_t; /* type of the id */ 195 typedef uint32_t id_t; /* group id, process id or user id */ 196 typedef uint64_t ino_t; /* inode number */ 197 typedef long key_t; /* IPC key (for Sys V IPC) */ 198 199 #ifndef mode_t 200 typedef __mode_t mode_t; /* permissions */ 201 #define mode_t __mode_t 202 #endif 203 204 typedef uint32_t nlink_t; /* link count */ 205 206 #ifndef off_t 207 typedef __off_t off_t; /* file offset */ 208 #define off_t __off_t 209 #endif 210 211 #ifndef pid_t 212 typedef __pid_t pid_t; /* process id */ 213 #define pid_t __pid_t 214 #endif 215 typedef int32_t lwpid_t; /* LWP id */ 216 typedef uint64_t rlim_t; /* resource limit */ 217 typedef int32_t segsz_t; /* segment size */ 218 typedef int32_t swblk_t; /* swap offset */ 219 220 #ifndef uid_t 221 typedef __uid_t uid_t; /* user id */ 222 #define uid_t __uid_t 223 #endif 224 225 typedef int mqd_t; 226 227 typedef unsigned long cpuid_t; 228 229 typedef int psetid_t; 230 231 #if defined(_KERNEL) || defined(_STANDALONE) 232 /* 233 * Boolean type definitions for the kernel environment. User-space 234 * boolean definitions are found in <stdbool.h>. 235 */ 236 #ifndef __cplusplus 237 #define bool _Bool 238 #define true 1 239 #define false 0 240 #endif 241 242 /* 243 * Deprecated Mach-style boolean_t type. Should not be used by new code. 244 */ 245 typedef int boolean_t; 246 #ifndef TRUE 247 #define TRUE 1 248 #endif 249 #ifndef FALSE 250 #define FALSE 0 251 #endif 252 253 #endif /* _KERNEL || _STANDALONE */ 254 255 #if defined(_KERNEL) || defined(_LIBC) 256 /* 257 * semctl(2)'s argument structure. This is here for the benefit of 258 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2. 259 * The SUSv2 semctl(2) takes variable arguments. 260 */ 261 union __semun { 262 int val; /* value for SETVAL */ 263 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 264 unsigned short *array; /* array for GETALL & SETALL */ 265 }; 266 #include <sys/stdint.h> 267 #endif /* _KERNEL || _LIBC */ 268 269 /* 270 * These belong in unistd.h, but are placed here too to ensure that 271 * long arguments will be promoted to off_t if the program fails to 272 * include that header or explicitly cast them to off_t. 273 */ 274 #if defined(_NETBSD_SOURCE) 275 #ifndef __OFF_T_SYSCALLS_DECLARED 276 #define __OFF_T_SYSCALLS_DECLARED 277 #ifndef _KERNEL 278 #include <sys/cdefs.h> 279 __BEGIN_DECLS 280 off_t lseek(int, off_t, int); 281 int ftruncate(int, off_t); 282 int truncate(const char *, off_t); 283 __END_DECLS 284 #endif /* !_KERNEL */ 285 #endif /* __OFF_T_SYSCALLS_DECLARED */ 286 #endif /* defined(_NETBSD_SOURCE) */ 287 288 #if defined(_NETBSD_SOURCE) 289 /* Major, minor numbers, dev_t's. */ 290 typedef int32_t __devmajor_t, __devminor_t; 291 #define devmajor_t __devmajor_t 292 #define devminor_t __devminor_t 293 #define NODEVMAJOR (-1) 294 #define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8)) 295 #define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \ 296 (((uint32_t)(x) & 0x000000ff) >> 0))) 297 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 298 (((y) << 12) & 0xfff00000) | \ 299 (((y) << 0) & 0x000000ff))) 300 #endif 301 302 #ifdef _BSD_CLOCK_T_ 303 typedef _BSD_CLOCK_T_ clock_t; 304 #undef _BSD_CLOCK_T_ 305 #endif 306 307 #ifdef _BSD_SIZE_T_ 308 typedef _BSD_SIZE_T_ size_t; 309 #define _SIZE_T 310 #undef _BSD_SIZE_T_ 311 #endif 312 313 #ifdef _BSD_SSIZE_T_ 314 typedef _BSD_SSIZE_T_ ssize_t; 315 #undef _BSD_SSIZE_T_ 316 #endif 317 318 #ifdef _BSD_TIME_T_ 319 typedef _BSD_TIME_T_ time_t; 320 #undef _BSD_TIME_T_ 321 #endif 322 323 #ifdef _BSD_CLOCKID_T_ 324 typedef _BSD_CLOCKID_T_ clockid_t; 325 #undef _BSD_CLOCKID_T_ 326 #endif 327 328 #ifdef _BSD_TIMER_T_ 329 typedef _BSD_TIMER_T_ timer_t; 330 #undef _BSD_TIMER_T_ 331 #endif 332 333 #ifdef _BSD_SUSECONDS_T_ 334 typedef _BSD_SUSECONDS_T_ suseconds_t; 335 #undef _BSD_SUSECONDS_T_ 336 #endif 337 338 #ifdef _BSD_USECONDS_T_ 339 typedef _BSD_USECONDS_T_ useconds_t; 340 #undef _BSD_USECONDS_T_ 341 #endif 342 343 #ifdef _NETBSD_SOURCE 344 #include <sys/fd_set.h> 345 346 #define NBBY 8 347 348 typedef struct kauth_cred *kauth_cred_t; 349 350 typedef int pri_t; 351 352 #endif 353 354 #if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER)) 355 /* 356 * Forward structure declarations for function prototypes. We include the 357 * common structures that cross subsystem boundaries here; others are mostly 358 * used in the same place that the structure is defined. 359 */ 360 struct lwp; 361 typedef struct lwp lwp_t; 362 struct __ucontext; 363 struct proc; 364 typedef struct proc proc_t; 365 struct pgrp; 366 struct rusage; 367 struct file; 368 typedef struct file file_t; 369 struct buf; 370 typedef struct buf buf_t; 371 struct tty; 372 struct uio; 373 #endif 374 375 #ifdef _KERNEL 376 #define SET(t, f) ((t) |= (f)) 377 #define ISSET(t, f) ((t) & (f)) 378 #define CLR(t, f) ((t) &= ~(f)) 379 #endif 380 381 #ifndef __minix 382 #if !defined(_KERNEL) && !defined(_STANDALONE) 383 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ 384 defined(_NETBSD_SOURCE) 385 #include <pthread_types.h> 386 #endif 387 #endif 388 #endif /* !__minix */ 389 390 #endif /* !_SYS_TYPES_H_ */ 391