11541Srgrimes/*- 214500Shsu * Copyright (c) 1982, 1986, 1991, 1993, 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 3414500Shsu * @(#)types.h 8.6 (Berkeley) 2/19/95 3550477Speter * $FreeBSD$ 361541Srgrimes */ 371541Srgrimes 381541Srgrimes#ifndef _SYS_TYPES_H_ 391541Srgrimes#define _SYS_TYPES_H_ 401541Srgrimes 4133778Sbde#include <sys/cdefs.h> 4233778Sbde 431541Srgrimes/* Machine type dependent parameters. */ 4490868Smike#include <machine/endian.h> 4593514Smike#include <sys/_types.h> 461541Srgrimes 47146824Srodrigc#include <sys/_pthreadtypes.h> 48146824Srodrigc 49104341Smike#if __BSD_VISIBLE 501541Srgrimestypedef unsigned char u_char; 511541Srgrimestypedef unsigned short u_short; 521541Srgrimestypedef unsigned int u_int; 531541Srgrimestypedef unsigned long u_long; 54128448Sobrien#ifndef _KERNEL 551541Srgrimestypedef unsigned short ushort; /* Sys V compatibility */ 561541Srgrimestypedef unsigned int uint; /* Sys V compatibility */ 571541Srgrimes#endif 58128448Sobrien#endif 591541Srgrimes 6093514Smike/* 6193514Smike * XXX POSIX sized integrals that should appear only in <sys/stdint.h>. 6293514Smike */ 63221502Sobrien#include <sys/_stdint.h> 6493514Smike 65104341Smiketypedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ 6641927Sdttypedef __uint16_t u_int16_t; 6741927Sdttypedef __uint32_t u_int32_t; 6841927Sdttypedef __uint64_t u_int64_t; 6941927Sdt 70104341Smiketypedef __uint64_t u_quad_t; /* quads (deprecated) */ 71104341Smiketypedef __int64_t quad_t; 721541Srgrimestypedef quad_t * qaddr_t; 731541Srgrimes 741541Srgrimestypedef char * caddr_t; /* core address */ 75228468Sedtypedef const char * c_caddr_t; /* core address, pointer to const */ 76110051Smike 77143952Sdas#ifndef _BLKSIZE_T_DECLARED 78143952Sdastypedef __blksize_t blksize_t; 79143952Sdas#define _BLKSIZE_T_DECLARED 80143952Sdas#endif 81143952Sdas 82176730Sjefftypedef __cpuwhich_t cpuwhich_t; 83176730Sjefftypedef __cpulevel_t cpulevel_t; 84176730Sjefftypedef __cpusetid_t cpusetid_t; 85176730Sjeff 86143952Sdas#ifndef _BLKCNT_T_DECLARED 87143952Sdastypedef __blkcnt_t blkcnt_t; 88143952Sdas#define _BLKCNT_T_DECLARED 89143952Sdas#endif 90143952Sdas 91110051Smike#ifndef _CLOCK_T_DECLARED 92110051Smiketypedef __clock_t clock_t; 93110051Smike#define _CLOCK_T_DECLARED 94110051Smike#endif 95110051Smike 96110051Smike#ifndef _CLOCKID_T_DECLARED 97110051Smiketypedef __clockid_t clockid_t; 98110051Smike#define _CLOCKID_T_DECLARED 99110051Smike#endif 100110051Smike 101102227Smiketypedef __critical_t critical_t; /* Critical section value */ 102104341Smiketypedef __int64_t daddr_t; /* disk address */ 103110051Smike 104112745Smike#ifndef _DEV_T_DECLARED 105112745Smiketypedef __dev_t dev_t; /* device number or struct cdev */ 106112745Smike#define _DEV_T_DECLARED 107112745Smike#endif 108112745Smike 109110051Smike#ifndef _FFLAGS_T_DECLARED 110110051Smiketypedef __fflags_t fflags_t; /* file flags */ 111110051Smike#define _FFLAGS_T_DECLARED 112110051Smike#endif 113110051Smike 114130434Sdastypedef __fixpt_t fixpt_t; /* fixed point number */ 11591325Smike 116110051Smike#ifndef _FSBLKCNT_T_DECLARED /* for statvfs() */ 117110051Smiketypedef __fsblkcnt_t fsblkcnt_t; 118110051Smiketypedef __fsfilcnt_t fsfilcnt_t; 119110051Smike#define _FSBLKCNT_T_DECLARED 120110051Smike#endif 121110051Smike 122102227Smike#ifndef _GID_T_DECLARED 123102227Smiketypedef __gid_t gid_t; /* group id */ 124102227Smike#define _GID_T_DECLARED 12591325Smike#endif 12691325Smike 127105683Stjr#ifndef _IN_ADDR_T_DECLARED 128105683Stjrtypedef __uint32_t in_addr_t; /* base type for internet address */ 129105683Stjr#define _IN_ADDR_T_DECLARED 130105683Stjr#endif 131105683Stjr 132105683Stjr#ifndef _IN_PORT_T_DECLARED 133105683Stjrtypedef __uint16_t in_port_t; 134105683Stjr#define _IN_PORT_T_DECLARED 135105683Stjr#endif 136105683Stjr 137105650Smike#ifndef _ID_T_DECLARED 138105650Smiketypedef __id_t id_t; /* can hold a uid_t or pid_t */ 139105650Smike#define _ID_T_DECLARED 140105650Smike#endif 141105650Smike 142111705Smike#ifndef _INO_T_DECLARED 143111705Smiketypedef __ino_t ino_t; /* inode number */ 144111705Smike#define _INO_T_DECLARED 145111705Smike#endif 146102325Smike 147105142Smike#ifndef _KEY_T_DECLARED 148105142Smiketypedef __key_t key_t; /* IPC key (for Sys V IPC) */ 149105142Smike#define _KEY_T_DECLARED 150105142Smike#endif 151105142Smike 152130735Smarcel#ifndef _LWPID_T_DECLARED 153130735Smarceltypedef __lwpid_t lwpid_t; /* Thread ID (a.k.a. LWP) */ 154130735Smarcel#define _LWPID_T_DECLARED 155130735Smarcel#endif 156130735Smarcel 157102325Smike#ifndef _MODE_T_DECLARED 158102325Smiketypedef __mode_t mode_t; /* permissions */ 159102325Smike#define _MODE_T_DECLARED 160102325Smike#endif 161102325Smike 162184413Strasz#ifndef _ACCMODE_T_DECLARED 163184413Strasztypedef __accmode_t accmode_t; /* access permissions */ 164184413Strasz#define _ACCMODE_T_DECLARED 165184413Strasz#endif 166184413Strasz 167111705Smike#ifndef _NLINK_T_DECLARED 168111705Smiketypedef __nlink_t nlink_t; /* link count */ 169111705Smike#define _NLINK_T_DECLARED 170111705Smike#endif 171102325Smike 172102325Smike#ifndef _OFF_T_DECLARED 173102227Smiketypedef __off_t off_t; /* file offset */ 174102325Smike#define _OFF_T_DECLARED 175102325Smike#endif 176102325Smike 177103457Smike#ifndef _PID_T_DECLARED 178102227Smiketypedef __pid_t pid_t; /* process id */ 179103457Smike#define _PID_T_DECLARED 180103457Smike#endif 181103457Smike 182102227Smiketypedef __register_t register_t; 183105650Smike 184105650Smike#ifndef _RLIM_T_DECLARED 185105650Smiketypedef __rlim_t rlim_t; /* resource limit */ 186105650Smike#define _RLIM_T_DECLARED 187105650Smike#endif 188105650Smike 189247476Sdavidetypedef __int64_t sbintime_t; 190247476Sdavide 191102227Smiketypedef __segsz_t segsz_t; /* segment size (in pages) */ 192108190Smike 193110051Smike#ifndef _SIZE_T_DECLARED 194110051Smiketypedef __size_t size_t; 195110051Smike#define _SIZE_T_DECLARED 196110051Smike#endif 197110051Smike 198110051Smike#ifndef _SSIZE_T_DECLARED 199110051Smiketypedef __ssize_t ssize_t; 200110051Smike#define _SSIZE_T_DECLARED 201110051Smike#endif 202110051Smike 203108190Smike#ifndef _SUSECONDS_T_DECLARED 204108190Smiketypedef __suseconds_t suseconds_t; /* microseconds (signed) */ 205108190Smike#define _SUSECONDS_T_DECLARED 206108190Smike#endif 207108190Smike 208110051Smike#ifndef _TIME_T_DECLARED 209110051Smiketypedef __time_t time_t; 210110051Smike#define _TIME_T_DECLARED 211110051Smike#endif 212110051Smike 213110051Smike#ifndef _TIMER_T_DECLARED 214110051Smiketypedef __timer_t timer_t; 215110051Smike#define _TIMER_T_DECLARED 216110051Smike#endif 217110051Smike 218152825Sdavidxu#ifndef _MQD_T_DECLARED 219152825Sdavidxutypedef __mqd_t mqd_t; 220152825Sdavidxu#define _MQD_T_DECLARED 221152825Sdavidxu#endif 222152825Sdavidxu 223102227Smiketypedef __u_register_t u_register_t; 22494363Smike 225102227Smike#ifndef _UID_T_DECLARED 226102227Smiketypedef __uid_t uid_t; /* user id */ 227102227Smike#define _UID_T_DECLARED 22836735Sdfr#endif 22994363Smike 230108190Smike#ifndef _USECONDS_T_DECLARED 231108190Smiketypedef __useconds_t useconds_t; /* microseconds (unsigned) */ 232108190Smike#define _USECONDS_T_DECLARED 233108190Smike#endif 234108190Smike 235255219Spjd#ifndef _CAP_RIGHTS_T_DECLARED 236255219Spjd#define _CAP_RIGHTS_T_DECLARED 237255219Spjdstruct cap_rights; 238255219Spjd 239255219Spjdtypedef struct cap_rights cap_rights_t; 240255219Spjd#endif 241255219Spjd 242102227Smiketypedef __vm_offset_t vm_offset_t; 243102227Smiketypedef __vm_ooffset_t vm_ooffset_t; 244112569Sjaketypedef __vm_paddr_t vm_paddr_t; 245102227Smiketypedef __vm_pindex_t vm_pindex_t; 246102227Smiketypedef __vm_size_t vm_size_t; 2471541Srgrimes 24855205Speter#ifdef _KERNEL 24915481Sbdetypedef int boolean_t; 250150559Snjltypedef struct device *device_t; 251102227Smiketypedef __intfptr_t intfptr_t; 252102421Smike 253210365Strasz/* 254102421Smike * XXX this is fixed width for historical reasons. It should have had type 255102421Smike * __int_fast32_t. Fixed-width types should not be used unless binary 256102421Smike * compatibility is essential. Least-width types should be used even less 257102421Smike * since they provide smaller benefits. 258210365Strasz * 259102421Smike * XXX should be MD. 260210365Strasz * 261102421Smike * XXX this is bogus in -current, but still used for spl*(). 262102421Smike */ 263102421Smiketypedef __uint32_t intrmask_t; /* Interrupt mask (spl, xxx_imask...) */ 264102421Smike 265102227Smiketypedef __uintfptr_t uintfptr_t; 266104341Smiketypedef __uint64_t uoff_t; 267196615Sjhbtypedef char vm_memattr_t; /* memory attribute codes */ 26815481Sbdetypedef struct vm_page *vm_page_t; 26912642Sbde 270228444Smdf#if !defined(__bool_true_false_are_defined) && !defined(__cplusplus) 271228444Smdf#define __bool_true_false_are_defined 1 272228444Smdf#define false 0 273228444Smdf#define true 1 274228444Smdf#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 && !defined(__INTEL_COMPILER) 275228444Smdftypedef int _Bool; 276228444Smdf#endif 277228444Smdftypedef _Bool bool; 278228444Smdf#endif /* !__bool_true_false_are_defined && !__cplusplus */ 279228444Smdf 28067708Sphk#define offsetof(type, field) __offsetof(type, field) 28167708Sphk 28255205Speter#endif /* !_KERNEL */ 28346818Sphk 2841541Srgrimes/* 285103867Smike * The following are all things that really shouldn't exist in this header, 286103867Smike * since its purpose is to provide typedefs, not miscellaneous doodads. 2871541Srgrimes */ 2881541Srgrimes 289281538Sjhb#ifdef __POPCNT__ 290281538Sjhb#define __bitcount64(x) __builtin_popcountll((__uint64_t)(x)) 291281538Sjhb#define __bitcount32(x) __builtin_popcount((__uint32_t)(x)) 292281538Sjhb#define __bitcount16(x) __builtin_popcount((__uint16_t)(x)) 293281538Sjhb#define __bitcountl(x) __builtin_popcountl((unsigned long)(x)) 294281538Sjhb#define __bitcount(x) __builtin_popcount((unsigned int)(x)) 295281538Sjhb#else 29624896Sbde/* 297281538Sjhb * Population count algorithm using SWAR approach 298281538Sjhb * - "SIMD Within A Register". 299281538Sjhb */ 300281538Sjhbstatic __inline __uint16_t 301281538Sjhb__bitcount16(__uint16_t _x) 302281538Sjhb{ 303281538Sjhb 304281538Sjhb _x = (_x & 0x5555) + ((_x & 0xaaaa) >> 1); 305281538Sjhb _x = (_x & 0x3333) + ((_x & 0xcccc) >> 2); 306281538Sjhb _x = (_x + (_x >> 4)) & 0x0f0f; 307281538Sjhb _x = (_x + (_x >> 8)) & 0x00ff; 308281538Sjhb return (_x); 309281538Sjhb} 310281538Sjhb 311281538Sjhbstatic __inline __uint32_t 312281538Sjhb__bitcount32(__uint32_t _x) 313281538Sjhb{ 314281538Sjhb 315281538Sjhb _x = (_x & 0x55555555) + ((_x & 0xaaaaaaaa) >> 1); 316281538Sjhb _x = (_x & 0x33333333) + ((_x & 0xcccccccc) >> 2); 317281538Sjhb _x = (_x + (_x >> 4)) & 0x0f0f0f0f; 318281538Sjhb _x = (_x + (_x >> 8)); 319281538Sjhb _x = (_x + (_x >> 16)) & 0x000000ff; 320281538Sjhb return (_x); 321281538Sjhb} 322281538Sjhb 323281538Sjhb#ifdef __LP64__ 324281538Sjhbstatic __inline __uint64_t 325281538Sjhb__bitcount64(__uint64_t _x) 326281538Sjhb{ 327281538Sjhb 328281538Sjhb _x = (_x & 0x5555555555555555) + ((_x & 0xaaaaaaaaaaaaaaaa) >> 1); 329281538Sjhb _x = (_x & 0x3333333333333333) + ((_x & 0xcccccccccccccccc) >> 2); 330281538Sjhb _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0f; 331281538Sjhb _x = (_x + (_x >> 8)); 332281538Sjhb _x = (_x + (_x >> 16)); 333281538Sjhb _x = (_x + (_x >> 32)) & 0x000000ff; 334281538Sjhb return (_x); 335281538Sjhb} 336281538Sjhb 337281538Sjhb#define __bitcountl(x) __bitcount64((unsigned long)(x)) 338281538Sjhb#else 339281538Sjhbstatic __inline __uint64_t 340281538Sjhb__bitcount64(__uint64_t _x) 341281538Sjhb{ 342281538Sjhb 343281538Sjhb return (__bitcount32(_x >> 32) + __bitcount32(_x)); 344281538Sjhb} 345281538Sjhb 346281538Sjhb#define __bitcountl(x) __bitcount32((unsigned long)(x)) 347281538Sjhb#endif 348281538Sjhb#define __bitcount(x) __bitcount32((unsigned int)(x)) 349281538Sjhb#endif 350281538Sjhb 351289107Skib#if __BSD_VISIBLE 352289107Skib 353289107Skib#include <sys/select.h> 354289107Skib 355281538Sjhb/* 356104341Smike * minor() gives a cookie instead of an index since we don't want to 357104341Smike * change the meanings of bits 0-15 or waste time and space shifting 358104341Smike * bits 16-31 for devices that don't use them. 359104341Smike */ 360187830Sed#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ 361183406Sed#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ 362183406Sed#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */ 363104341Smike 364104341Smike/* 36524896Sbde * These declarations belong elsewhere, but are repeated here and in 36624896Sbde * <stdio.h> to give broken programs a better chance of working with 36724896Sbde * 64-bit off_t's. 36824896Sbde */ 36955205Speter#ifndef _KERNEL 37024896Sbde__BEGIN_DECLS 37124896Sbde#ifndef _FTRUNCATE_DECLARED 37224896Sbde#define _FTRUNCATE_DECLARED 37392719Salfredint ftruncate(int, off_t); 37424896Sbde#endif 37524896Sbde#ifndef _LSEEK_DECLARED 37624896Sbde#define _LSEEK_DECLARED 37792719Salfredoff_t lseek(int, off_t, int); 37824896Sbde#endif 37924896Sbde#ifndef _MMAP_DECLARED 38024896Sbde#define _MMAP_DECLARED 38192719Salfredvoid * mmap(void *, size_t, int, int, int, off_t); 38224896Sbde#endif 38324896Sbde#ifndef _TRUNCATE_DECLARED 38424896Sbde#define _TRUNCATE_DECLARED 38592719Salfredint truncate(const char *, off_t); 38624896Sbde#endif 38724896Sbde__END_DECLS 38855205Speter#endif /* !_KERNEL */ 38924896Sbde 39098271Swollman#endif /* __BSD_VISIBLE */ 3911541Srgrimes 3921541Srgrimes#endif /* !_SYS_TYPES_H_ */ 393