1 /* $NetBSD: types.h,v 1.95 2015/08/27 12:30:51 pooka 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 #if defined(__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 uint64_t block64_t; /* block number, 64-bit */ 122 typedef uint32_t bit_t; /* bit number in a bit map */ 123 typedef uint16_t zone1_t; /* zone number for V1 file systems */ 124 typedef uint32_t bitchunk_t; /* collection of bits in a bitmap */ 125 #endif 126 #endif /* defined(__minix) */ 127 128 #include <machine/endian.h> 129 130 #if defined(_NETBSD_SOURCE) 131 typedef unsigned char u_char; 132 typedef unsigned short u_short; 133 typedef unsigned int u_int; 134 typedef unsigned long u_long; 135 136 typedef unsigned char unchar; /* Sys V compatibility */ 137 typedef unsigned short ushort; /* Sys V compatibility */ 138 typedef unsigned int uint; /* Sys V compatibility */ 139 typedef unsigned long ulong; /* Sys V compatibility */ 140 #endif 141 142 typedef uint64_t u_quad_t; /* quads */ 143 typedef int64_t quad_t; 144 typedef quad_t * qaddr_t; 145 146 /* 147 * The types longlong_t and u_longlong_t exist for use with the 148 * Sun-derived XDR routines involving these types, and their usage 149 * in other contexts is discouraged. Further note that these types 150 * may not be equivalent to "long long" and "unsigned long long", 151 * they are only guaranteed to be signed and unsigned 64-bit types 152 * respectively. Portable programs that need 64-bit types should use 153 * the C99 types int64_t and uint64_t instead. 154 */ 155 156 typedef int64_t longlong_t; /* for XDR */ 157 typedef uint64_t u_longlong_t; /* for XDR */ 158 159 typedef int64_t blkcnt_t; /* fs block count */ 160 typedef int32_t blksize_t; /* fs optimal block size */ 161 162 #ifndef fsblkcnt_t 163 typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */ 164 #define fsblkcnt_t __fsblkcnt_t 165 #endif 166 167 #ifndef fsfilcnt_t 168 typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */ 169 #define fsfilcnt_t __fsfilcnt_t 170 #endif 171 172 #if !defined(_KERNEL) && !defined(_STANDALONE) 173 /* We don't and shouldn't use caddr_t in the kernel anymore */ 174 #ifndef caddr_t 175 typedef __caddr_t caddr_t; /* core address */ 176 #define caddr_t __caddr_t 177 #endif 178 #endif 179 180 #ifdef __daddr_t 181 typedef __daddr_t daddr_t; /* disk address */ 182 #undef __daddr_t 183 #else 184 typedef int64_t daddr_t; /* disk address */ 185 #endif 186 187 typedef uint64_t dev_t; /* device number */ 188 typedef uint32_t fixpt_t; /* fixed point number */ 189 190 #ifndef gid_t 191 typedef __gid_t gid_t; /* group id */ 192 #define gid_t __gid_t 193 #endif 194 195 typedef int idtype_t; /* type of the id */ 196 typedef uint32_t id_t; /* group id, process id or user id */ 197 typedef uint64_t ino_t; /* inode number */ 198 typedef long key_t; /* IPC key (for Sys V IPC) */ 199 200 #ifndef mode_t 201 typedef __mode_t mode_t; /* permissions */ 202 #define mode_t __mode_t 203 #endif 204 205 typedef uint32_t nlink_t; /* link count */ 206 207 #ifndef off_t 208 typedef __off_t off_t; /* file offset */ 209 #define off_t __off_t 210 #endif 211 212 #ifndef pid_t 213 typedef __pid_t pid_t; /* process id */ 214 #define pid_t __pid_t 215 #endif 216 typedef int32_t lwpid_t; /* LWP id */ 217 typedef uint64_t rlim_t; /* resource limit */ 218 typedef int32_t segsz_t; /* segment size */ 219 typedef int32_t swblk_t; /* swap offset */ 220 221 #ifndef uid_t 222 typedef __uid_t uid_t; /* user id */ 223 #define uid_t __uid_t 224 #endif 225 226 typedef int mqd_t; 227 228 typedef unsigned long cpuid_t; 229 230 typedef int psetid_t; 231 232 typedef volatile __cpu_simple_lock_nv_t __cpu_simple_lock_t; 233 234 #if defined(_KERNEL) || defined(_STANDALONE) 235 236 #include <sys/stdbool.h> 237 238 /* 239 * Deprecated Mach-style boolean_t type. Should not be used by new code. 240 */ 241 typedef int boolean_t; 242 #ifndef TRUE 243 #define TRUE 1 244 #endif 245 #ifndef FALSE 246 #define FALSE 0 247 #endif 248 249 #endif /* _KERNEL || _STANDALONE */ 250 251 #if defined(_KERNEL) || defined(_LIBC) 252 /* 253 * semctl(2)'s argument structure. This is here for the benefit of 254 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2. 255 * The SUSv2 semctl(2) takes variable arguments. 256 */ 257 union __semun { 258 int val; /* value for SETVAL */ 259 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 260 unsigned short *array; /* array for GETALL & SETALL */ 261 }; 262 #include <sys/stdint.h> 263 #endif /* _KERNEL || _LIBC */ 264 265 /* 266 * These belong in unistd.h, but are placed here too to ensure that 267 * long arguments will be promoted to off_t if the program fails to 268 * include that header or explicitly cast them to off_t. 269 */ 270 #if defined(_NETBSD_SOURCE) 271 #ifndef __OFF_T_SYSCALLS_DECLARED 272 #define __OFF_T_SYSCALLS_DECLARED 273 #ifndef _KERNEL 274 #include <sys/cdefs.h> 275 __BEGIN_DECLS 276 off_t lseek(int, off_t, int); 277 int ftruncate(int, off_t); 278 int truncate(const char *, off_t); 279 __END_DECLS 280 #endif /* !_KERNEL */ 281 #endif /* __OFF_T_SYSCALLS_DECLARED */ 282 #endif /* defined(_NETBSD_SOURCE) */ 283 284 #if defined(_NETBSD_SOURCE) 285 /* Major, minor numbers, dev_t's. */ 286 typedef int32_t __devmajor_t, __devminor_t; 287 #define devmajor_t __devmajor_t 288 #define devminor_t __devminor_t 289 #define NODEVMAJOR (-1) 290 #define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8)) 291 #define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \ 292 (((uint32_t)(x) & 0x000000ff) >> 0))) 293 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 294 (((y) << 12) & 0xfff00000) | \ 295 (((y) << 0) & 0x000000ff))) 296 #endif 297 298 #ifdef _BSD_CLOCK_T_ 299 typedef _BSD_CLOCK_T_ clock_t; 300 #undef _BSD_CLOCK_T_ 301 #endif 302 303 #ifdef _BSD_PTRDIFF_T_ 304 typedef _BSD_PTRDIFF_T_ ptrdiff_t; 305 #undef _BSD_PTRDIFF_T_ 306 #endif 307 308 #ifdef _BSD_SIZE_T_ 309 typedef _BSD_SIZE_T_ size_t; 310 #define _SIZE_T 311 #undef _BSD_SIZE_T_ 312 #endif 313 314 #ifdef _BSD_SSIZE_T_ 315 typedef _BSD_SSIZE_T_ ssize_t; 316 #undef _BSD_SSIZE_T_ 317 #endif 318 319 #ifdef _BSD_TIME_T_ 320 typedef _BSD_TIME_T_ time_t; 321 #undef _BSD_TIME_T_ 322 #endif 323 324 #ifdef _BSD_CLOCKID_T_ 325 typedef _BSD_CLOCKID_T_ clockid_t; 326 #undef _BSD_CLOCKID_T_ 327 #endif 328 329 #ifdef _BSD_TIMER_T_ 330 typedef _BSD_TIMER_T_ timer_t; 331 #undef _BSD_TIMER_T_ 332 #endif 333 334 #ifdef _BSD_SUSECONDS_T_ 335 typedef _BSD_SUSECONDS_T_ suseconds_t; 336 #undef _BSD_SUSECONDS_T_ 337 #endif 338 339 #ifdef _BSD_USECONDS_T_ 340 typedef _BSD_USECONDS_T_ useconds_t; 341 #undef _BSD_USECONDS_T_ 342 #endif 343 344 #ifdef _NETBSD_SOURCE 345 #include <sys/fd_set.h> 346 347 #define NBBY 8 348 349 typedef struct kauth_cred *kauth_cred_t; 350 351 typedef int pri_t; 352 353 #endif 354 355 #if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER)) 356 /* 357 * Forward structure declarations for function prototypes. We include the 358 * common structures that cross subsystem boundaries here; others are mostly 359 * used in the same place that the structure is defined. 360 */ 361 struct lwp; 362 typedef struct lwp lwp_t; 363 struct __ucontext; 364 struct proc; 365 typedef struct proc proc_t; 366 struct pgrp; 367 struct rusage; 368 struct file; 369 typedef struct file file_t; 370 struct buf; 371 typedef struct buf buf_t; 372 struct tty; 373 struct uio; 374 #endif 375 376 #ifdef _KERNEL 377 #define SET(t, f) ((t) |= (f)) 378 #define ISSET(t, f) ((t) & (f)) 379 #define CLR(t, f) ((t) &= ~(f)) 380 #endif 381 382 #if !defined(__minix) 383 #if !defined(_KERNEL) && !defined(_STANDALONE) 384 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ 385 defined(_NETBSD_SOURCE) 386 #include <pthread_types.h> 387 #endif 388 #endif 389 #endif /* !defined(__minix) */ 390 391 #endif /* !_SYS_TYPES_H_ */ 392