1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 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 37 #ifndef _SYS_TYPES_H_ 38 #define _SYS_TYPES_H_ 39 40 #include <sys/cdefs.h> 41 42 /* Machine type dependent parameters. */ 43 #include <machine/endian.h> 44 #include <sys/_types.h> 45 46 #include <sys/_pthreadtypes.h> 47 48 #if __BSD_VISIBLE 49 typedef unsigned char u_char; 50 typedef unsigned short u_short; 51 typedef unsigned int u_int; 52 typedef unsigned long u_long; 53 #ifndef _KERNEL 54 typedef unsigned short ushort; /* Sys V compatibility */ 55 typedef unsigned int uint; /* Sys V compatibility */ 56 #endif 57 #endif 58 59 /* 60 * XXX POSIX sized integrals that should appear only in <sys/stdint.h>. 61 */ 62 #include <sys/_stdint.h> 63 64 typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ 65 typedef __uint16_t u_int16_t; 66 typedef __uint32_t u_int32_t; 67 typedef __uint64_t u_int64_t; 68 69 typedef __uint64_t u_quad_t; /* quads (deprecated) */ 70 typedef __int64_t quad_t; 71 typedef quad_t * qaddr_t; 72 73 typedef char * caddr_t; /* core address */ 74 typedef const char * c_caddr_t; /* core address, pointer to const */ 75 76 #ifndef _BLKSIZE_T_DECLARED 77 typedef __blksize_t blksize_t; 78 #define _BLKSIZE_T_DECLARED 79 #endif 80 81 typedef __cpuwhich_t cpuwhich_t; 82 typedef __cpulevel_t cpulevel_t; 83 typedef __cpusetid_t cpusetid_t; 84 85 #ifndef _BLKCNT_T_DECLARED 86 typedef __blkcnt_t blkcnt_t; 87 #define _BLKCNT_T_DECLARED 88 #endif 89 90 #ifndef _CLOCK_T_DECLARED 91 typedef __clock_t clock_t; 92 #define _CLOCK_T_DECLARED 93 #endif 94 95 #ifndef _CLOCKID_T_DECLARED 96 typedef __clockid_t clockid_t; 97 #define _CLOCKID_T_DECLARED 98 #endif 99 100 typedef __critical_t critical_t; /* Critical section value */ 101 typedef __daddr_t daddr_t; /* disk address */ 102 103 #ifndef _DEV_T_DECLARED 104 typedef __dev_t dev_t; /* device number or struct cdev */ 105 #define _DEV_T_DECLARED 106 #endif 107 108 #ifndef _FFLAGS_T_DECLARED 109 typedef __fflags_t fflags_t; /* file flags */ 110 #define _FFLAGS_T_DECLARED 111 #endif 112 113 typedef __fixpt_t fixpt_t; /* fixed point number */ 114 115 #ifndef _FSBLKCNT_T_DECLARED /* for statvfs() */ 116 typedef __fsblkcnt_t fsblkcnt_t; 117 typedef __fsfilcnt_t fsfilcnt_t; 118 #define _FSBLKCNT_T_DECLARED 119 #endif 120 121 #ifndef _GID_T_DECLARED 122 typedef __gid_t gid_t; /* group id */ 123 #define _GID_T_DECLARED 124 #endif 125 126 #ifndef _IN_ADDR_T_DECLARED 127 typedef __uint32_t in_addr_t; /* base type for internet address */ 128 #define _IN_ADDR_T_DECLARED 129 #endif 130 131 #ifndef _IN_PORT_T_DECLARED 132 typedef __uint16_t in_port_t; 133 #define _IN_PORT_T_DECLARED 134 #endif 135 136 #ifndef _ID_T_DECLARED 137 typedef __id_t id_t; /* can hold a uid_t or pid_t */ 138 #define _ID_T_DECLARED 139 #endif 140 141 #ifndef _INO_T_DECLARED 142 typedef __ino_t ino_t; /* inode number */ 143 #define _INO_T_DECLARED 144 #endif 145 146 #ifndef _KEY_T_DECLARED 147 typedef __key_t key_t; /* IPC key (for Sys V IPC) */ 148 #define _KEY_T_DECLARED 149 #endif 150 151 #ifndef _LWPID_T_DECLARED 152 typedef __lwpid_t lwpid_t; /* Thread ID (a.k.a. LWP) */ 153 #define _LWPID_T_DECLARED 154 #endif 155 156 #ifndef _MODE_T_DECLARED 157 typedef __mode_t mode_t; /* permissions */ 158 #define _MODE_T_DECLARED 159 #endif 160 161 #ifndef _ACCMODE_T_DECLARED 162 typedef __accmode_t accmode_t; /* access permissions */ 163 #define _ACCMODE_T_DECLARED 164 #endif 165 166 #ifndef _NLINK_T_DECLARED 167 typedef __nlink_t nlink_t; /* link count */ 168 #define _NLINK_T_DECLARED 169 #endif 170 171 #ifndef _OFF_T_DECLARED 172 typedef __off_t off_t; /* file offset */ 173 #define _OFF_T_DECLARED 174 #endif 175 176 #ifndef _OFF64_T_DECLARED 177 typedef __off64_t off64_t; /* file offset (alias) */ 178 #define _OFF64_T_DECLARED 179 #endif 180 181 #ifndef _PID_T_DECLARED 182 typedef __pid_t pid_t; /* process id */ 183 #define _PID_T_DECLARED 184 #endif 185 186 typedef __register_t register_t; 187 188 #ifndef _RLIM_T_DECLARED 189 typedef __rlim_t rlim_t; /* resource limit */ 190 #define _RLIM_T_DECLARED 191 #endif 192 193 typedef __sbintime_t sbintime_t; 194 195 typedef __segsz_t segsz_t; /* segment size (in pages) */ 196 197 #ifndef _SIZE_T_DECLARED 198 typedef __size_t size_t; 199 #define _SIZE_T_DECLARED 200 #endif 201 202 #ifndef _SSIZE_T_DECLARED 203 typedef __ssize_t ssize_t; 204 #define _SSIZE_T_DECLARED 205 #endif 206 207 #ifndef _SUSECONDS_T_DECLARED 208 typedef __suseconds_t suseconds_t; /* microseconds (signed) */ 209 #define _SUSECONDS_T_DECLARED 210 #endif 211 212 #ifndef _TIME_T_DECLARED 213 typedef __time_t time_t; 214 #define _TIME_T_DECLARED 215 #endif 216 217 #ifndef _TIMER_T_DECLARED 218 typedef __timer_t timer_t; 219 #define _TIMER_T_DECLARED 220 #endif 221 222 #ifndef _MQD_T_DECLARED 223 typedef __mqd_t mqd_t; 224 #define _MQD_T_DECLARED 225 #endif 226 227 typedef __u_register_t u_register_t; 228 229 #ifndef _UID_T_DECLARED 230 typedef __uid_t uid_t; /* user id */ 231 #define _UID_T_DECLARED 232 #endif 233 234 #ifndef _USECONDS_T_DECLARED 235 typedef __useconds_t useconds_t; /* microseconds (unsigned) */ 236 #define _USECONDS_T_DECLARED 237 #endif 238 239 #ifndef _CAP_IOCTL_T_DECLARED 240 #define _CAP_IOCTL_T_DECLARED 241 typedef unsigned long cap_ioctl_t; 242 #endif 243 244 #ifndef _CAP_RIGHTS_T_DECLARED 245 #define _CAP_RIGHTS_T_DECLARED 246 struct cap_rights; 247 248 typedef struct cap_rights cap_rights_t; 249 #endif 250 251 /* 252 * Types suitable for exporting physical addresses, virtual addresses 253 * (pointers), and memory object sizes from the kernel independent of native 254 * word size. These should be used in place of vm_paddr_t, (u)intptr_t, and 255 * size_t in structs which contain such types that are shared with userspace. 256 */ 257 typedef __uint64_t kpaddr_t; 258 typedef __uint64_t kvaddr_t; 259 typedef __uint64_t ksize_t; 260 typedef __int64_t kssize_t; 261 262 typedef __vm_offset_t vm_offset_t; 263 typedef __uint64_t vm_ooffset_t; 264 typedef __vm_paddr_t vm_paddr_t; 265 typedef __uint64_t vm_pindex_t; 266 typedef __vm_size_t vm_size_t; 267 268 typedef __rman_res_t rman_res_t; 269 270 typedef __register_t syscallarg_t; 271 272 #ifdef _KERNEL 273 typedef unsigned int boolean_t; 274 typedef struct _device *device_t; 275 typedef __intfptr_t intfptr_t; 276 277 /* 278 * XXX this is fixed width for historical reasons. It should have had type 279 * __int_fast32_t. Fixed-width types should not be used unless binary 280 * compatibility is essential. Least-width types should be used even less 281 * since they provide smaller benefits. 282 * 283 * XXX should be MD. 284 * 285 * XXX this is bogus in -current, but still used for spl*(). 286 */ 287 typedef __uint32_t intrmask_t; /* Interrupt mask (spl, xxx_imask...) */ 288 289 typedef __uintfptr_t uintfptr_t; 290 typedef __uint64_t uoff_t; 291 typedef char vm_memattr_t; /* memory attribute codes */ 292 typedef struct vm_page *vm_page_t; 293 294 #define offsetof(type, field) __offsetof(type, field) 295 #endif /* _KERNEL */ 296 297 #if defined(_KERNEL) || defined(_STANDALONE) 298 #if !defined(__bool_true_false_are_defined) && !defined(__cplusplus) 299 #define __bool_true_false_are_defined 1 300 #define false 0 301 #define true 1 302 typedef _Bool bool; 303 #endif /* !__bool_true_false_are_defined && !__cplusplus */ 304 #endif /* KERNEL || _STANDALONE */ 305 306 /* 307 * The following are all things that really shouldn't exist in this header, 308 * since its purpose is to provide typedefs, not miscellaneous doodads. 309 */ 310 #include <sys/bitcount.h> 311 312 #if __BSD_VISIBLE 313 314 #include <sys/select.h> 315 316 /* 317 * The major and minor numbers are encoded in dev_t as MMMmmmMm (where 318 * letters correspond to bytes). The encoding of the lower 4 bytes is 319 * constrained by compatibility with 16-bit and 32-bit dev_t's. The 320 * encoding of of the upper 4 bytes is the least unnatural one consistent 321 * with this and other constraints. Also, the decoding of the m bytes by 322 * minor() is unnatural to maximize compatibility subject to not discarding 323 * bits. The upper m byte is shifted into the position of the lower M byte 324 * instead of shifting 3 upper m bytes to close the gap. Compatibility for 325 * minor() is achieved iff the upper m byte is 0. 326 */ 327 #define major(d) __major(d) 328 static __inline int 329 __major(dev_t _d) 330 { 331 return (((_d >> 32) & 0xffffff00) | ((_d >> 8) & 0xff)); 332 } 333 #define minor(d) __minor(d) 334 static __inline int 335 __minor(dev_t _d) 336 { 337 return (((_d >> 24) & 0xff00) | (_d & 0xffff00ff)); 338 } 339 #define makedev(M, m) __makedev((M), (m)) 340 static __inline dev_t 341 __makedev(int _Major, int _Minor) 342 { 343 return (((dev_t)(_Major & 0xffffff00) << 32) | ((_Major & 0xff) << 8) | 344 ((dev_t)(_Minor & 0xff00) << 24) | (_Minor & 0xffff00ff)); 345 } 346 347 #if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 13)) 348 #define __enum_uint8_decl(name) enum enum_ ## name ## _uint8 : uint8_t 349 #define __enum_uint8(name) enum enum_ ## name ## _uint8 350 #else 351 /* 352 * Note: there is no real size checking here, but the code below can be 353 * removed once we require GCC 13. 354 */ 355 #define __enum_uint8_decl(name) enum __attribute__((packed)) enum_ ## name ## _uint8 356 #define __enum_uint8(name) enum __attribute__((packed)) enum_ ## name ## _uint8 357 #endif 358 359 /* 360 * These declarations belong elsewhere, but are repeated here and in 361 * <stdio.h> to give broken programs a better chance of working with 362 * 64-bit off_t's. 363 */ 364 #ifndef _KERNEL 365 __BEGIN_DECLS 366 #ifndef _FTRUNCATE_DECLARED 367 #define _FTRUNCATE_DECLARED 368 int ftruncate(int, off_t); 369 #endif 370 #ifndef _LSEEK_DECLARED 371 #define _LSEEK_DECLARED 372 off_t lseek(int, off_t, int); 373 #endif 374 #ifndef _MMAP_DECLARED 375 #define _MMAP_DECLARED 376 void * mmap(void *, size_t, int, int, int, off_t); 377 #endif 378 #ifndef _TRUNCATE_DECLARED 379 #define _TRUNCATE_DECLARED 380 int truncate(const char *, off_t); 381 #endif 382 __END_DECLS 383 #endif /* !_KERNEL */ 384 385 #endif /* __BSD_VISIBLE */ 386 387 #endif /* !_SYS_TYPES_H_ */ 388