Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: types.h,v 1.110 2026/01/12 14:51:50 nia 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	_BSD_INT8_T_
     54 typedef	__int8_t	int8_t;
     55 #define	_BSD_INT8_T_
     56 #endif
     57 
     58 #ifndef	_BSD_UINT8_T_
     59 typedef	__uint8_t	uint8_t;
     60 #define	_BSD_UINT8_T_
     61 #endif
     62 
     63 #ifndef	_BSD_INT16_T_
     64 typedef	__int16_t	int16_t;
     65 #define	_BSD_INT16_T_
     66 #endif
     67 
     68 #ifndef	_BSD_UINT16_T_
     69 typedef	__uint16_t	uint16_t;
     70 #define	_BSD_UINT16_T_
     71 #endif
     72 
     73 #ifndef	_BSD_INT32_T_
     74 typedef	__int32_t	int32_t;
     75 #define	_BSD_INT32_T_
     76 #endif
     77 
     78 #ifndef	_BSD_UINT32_T_
     79 typedef	__uint32_t	uint32_t;
     80 #define	_BSD_UINT32_T_
     81 #endif
     82 
     83 #ifndef	_BSD_INT64_T_
     84 typedef	__int64_t	int64_t;
     85 #define	_BSD_INT64_T_
     86 #endif
     87 
     88 #ifndef	_BSD_UINT64_T_
     89 typedef	__uint64_t	uint64_t;
     90 #define	_BSD_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 #include <sys/stdint.h>
     99 
    100 #if defined(_NETBSD_SOURCE)
    101 typedef	unsigned char	u_char;
    102 typedef	unsigned short	u_short;
    103 typedef	unsigned int	u_int;
    104 typedef	unsigned long	u_long;
    105 
    106 typedef unsigned char	unchar;		/* Sys V compatibility */
    107 typedef	unsigned short	ushort;		/* Sys V compatibility */
    108 typedef	unsigned int	uint;		/* Sys V compatibility */
    109 typedef unsigned long	ulong;		/* Sys V compatibility */
    110 #endif
    111 
    112 typedef	uint64_t	u_quad_t;	/* quads */
    113 typedef	int64_t		quad_t;
    114 typedef	quad_t *	qaddr_t;
    115 
    116 /*
    117  * The types longlong_t and u_longlong_t exist for use with the
    118  * Sun-derived XDR routines involving these types, and their usage
    119  * in other contexts is discouraged.  Further note that these types
    120  * may not be equivalent to "long long" and "unsigned long long",
    121  * they are only guaranteed to be signed and unsigned 64-bit types
    122  * respectively.  Portable programs that need 64-bit types should use
    123  * the C99 types int64_t and uint64_t instead.
    124  */
    125 
    126 typedef	int64_t		longlong_t;	/* for XDR */
    127 typedef	uint64_t	u_longlong_t;	/* for XDR */
    128 
    129 typedef	int64_t		blkcnt_t;	/* fs block count */
    130 typedef	int32_t		blksize_t;	/* fs optimal block size */
    131 
    132 #ifndef	fsblkcnt_t
    133 typedef	__fsblkcnt_t	fsblkcnt_t;	/* fs block count (statvfs) */
    134 #define fsblkcnt_t	__fsblkcnt_t
    135 #endif
    136 
    137 #ifndef	fsfilcnt_t
    138 typedef	__fsfilcnt_t	fsfilcnt_t;	/* fs file count */
    139 #define fsfilcnt_t	__fsfilcnt_t
    140 #endif
    141 
    142 #if !defined(_KERNEL) && !defined(_STANDALONE)
    143 /* We don't and shouldn't use caddr_t in the kernel anymore */
    144 #ifndef	caddr_t
    145 typedef	__caddr_t	caddr_t;	/* core address */
    146 #define	caddr_t		__caddr_t
    147 #endif
    148 #endif
    149 
    150 #ifdef __daddr_t
    151 typedef	__daddr_t	daddr_t;	/* disk address */
    152 #undef __daddr_t
    153 #else
    154 typedef	int64_t		daddr_t;	/* disk address */
    155 #endif
    156 
    157 typedef	uint64_t	dev_t;		/* device number */
    158 typedef	uint32_t	fixpt_t;	/* fixed point number */
    159 
    160 #ifndef	gid_t
    161 typedef	__gid_t		gid_t;		/* group id */
    162 #define	gid_t		__gid_t
    163 #endif
    164 
    165 typedef	uint32_t	id_t;		/* group id, process id or user id */
    166 #ifdef __ino_t
    167 /*
    168  * Some first stage bootloaders may want to avoid 64bit math, especially
    169  * when the firmware can only access small disks/partitions anyway.
    170  * Example: hppa/stand/xxboot
    171  */
    172 typedef	__ino_t		ino_t;
    173 #undef __ino_t
    174 #else
    175 typedef	uint64_t	ino_t;		/* inode number */
    176 #endif
    177 typedef	long		key_t;		/* IPC key (for Sys V IPC) */
    178 
    179 #ifndef	mode_t
    180 typedef	__mode_t	mode_t;		/* permissions */
    181 #define	mode_t		__mode_t
    182 #endif
    183 
    184 #ifndef	accmode_t
    185 typedef	__accmode_t	accmode_t;	/* access permissions */
    186 #define	accmode_t	__accmode_t
    187 #endif
    188 
    189 typedef	uint32_t	nlink_t;	/* link count */
    190 
    191 #ifndef	off_t
    192 typedef	__off_t		off_t;		/* file offset */
    193 #define	off_t		__off_t
    194 #endif
    195 
    196 #ifndef	pid_t
    197 typedef	__pid_t		pid_t;		/* process id */
    198 #define	pid_t		__pid_t
    199 #endif
    200 typedef int32_t		lwpid_t;	/* LWP id */
    201 typedef uint64_t	rlim_t;		/* resource limit */
    202 typedef	int32_t		segsz_t;	/* segment size */
    203 typedef	int32_t		swblk_t;	/* swap offset */
    204 
    205 #ifndef	uid_t
    206 typedef	__uid_t		uid_t;		/* user id */
    207 #define	uid_t		__uid_t
    208 #endif
    209 
    210 typedef int		mqd_t;
    211 
    212 typedef	unsigned long	cpuid_t;
    213 
    214 typedef	int		psetid_t;
    215 
    216 typedef volatile __cpu_simple_lock_nv_t __cpu_simple_lock_t;
    217 
    218 #if defined(_KERNEL) || defined(_STANDALONE)
    219 
    220 #include <sys/stdbool.h>
    221 
    222 /*
    223  * Deprecated Mach-style boolean_t type.  Should not be used by new code.
    224  */
    225 typedef int	boolean_t;
    226 #ifndef TRUE
    227 #define	TRUE	1
    228 #endif
    229 #ifndef FALSE
    230 #define	FALSE	0
    231 #endif
    232 
    233 #endif /* _KERNEL || _STANDALONE */
    234 
    235 #if defined(_NETBSD_SOURCE)
    236 
    237 /*
    238  * Deprecated <sys/endian.h> transclusion.
    239  */
    240 #include <sys/endian.h>
    241 #endif
    242 
    243 #if defined(_KERNEL) || defined(_LIBC) || defined(_KMEMUSER)
    244 /*
    245  * semctl(2)'s argument structure.  This is here for the benefit of
    246  * <sys/syscallargs.h>.  It is not in the user's namespace in SUSv2.
    247  * The SUSv2 semctl(2) takes variable arguments.
    248  */
    249 union __semun {
    250 	int		val;		/* value for SETVAL */
    251 	struct semid_ds	*buf;		/* buffer for IPC_STAT & IPC_SET */
    252 	unsigned short	*array;		/* array for GETALL & SETALL */
    253 };
    254 #endif /* _KERNEL || _LIBC || _KMEMUSER */
    255 
    256 /*
    257  * These belong in unistd.h, but are placed here too to ensure that
    258  * long arguments will be promoted to off_t if the program fails to
    259  * include that header or explicitly cast them to off_t.
    260  */
    261 #if defined(_NETBSD_SOURCE)
    262 #ifndef __OFF_T_SYSCALLS_DECLARED
    263 #define __OFF_T_SYSCALLS_DECLARED
    264 #ifndef _KERNEL
    265 #include <sys/cdefs.h>
    266 __BEGIN_DECLS
    267 off_t	 lseek(int, off_t, int);
    268 int	 ftruncate(int, off_t);
    269 int	 truncate(const char *, off_t);
    270 __END_DECLS
    271 #endif /* !_KERNEL */
    272 #endif /* __OFF_T_SYSCALLS_DECLARED */
    273 #endif /* defined(_NETBSD_SOURCE) */
    274 
    275 #if defined(_NETBSD_SOURCE)
    276 /* Major, minor numbers, dev_t's. */
    277 typedef int32_t __devmajor_t, __devminor_t;
    278 #define devmajor_t __devmajor_t
    279 #define devminor_t __devminor_t
    280 #define NODEVMAJOR (-1)
    281 #define	major(x)	((devmajor_t)(((uint32_t)(x) & 0x000fff00) >>  8))
    282 #define	minor(x)	((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \
    283 				   (((uint32_t)(x) & 0x000000ff) >>  0)))
    284 #define	makedev(x,y)	((dev_t)((((dev_t)(x) <<  8) & 0x000fff00U) | \
    285 				 (((dev_t)(y) << 12) & 0xfff00000U) | \
    286 				 (((dev_t)(y) <<  0) & 0x000000ffU)))
    287 #endif
    288 
    289 #ifdef	_BSD_CLOCK_T_
    290 typedef	_BSD_CLOCK_T_		clock_t;
    291 #undef	_BSD_CLOCK_T_
    292 #endif
    293 
    294 #ifdef	_BSD_PTRDIFF_T_
    295 typedef	_BSD_PTRDIFF_T_		ptrdiff_t;
    296 #undef	_BSD_PTRDIFF_T_
    297 #endif
    298 
    299 #ifdef	_BSD_SIZE_T_
    300 typedef	_BSD_SIZE_T_		size_t;
    301 #define _SIZE_T
    302 #undef	_BSD_SIZE_T_
    303 #endif
    304 
    305 #ifdef	_BSD_SSIZE_T_
    306 typedef	_BSD_SSIZE_T_		ssize_t;
    307 #undef	_BSD_SSIZE_T_
    308 #endif
    309 
    310 #ifdef	_BSD_TIME_T_
    311 typedef	_BSD_TIME_T_		time_t;
    312 #undef	_BSD_TIME_T_
    313 #endif
    314 
    315 #ifdef	_BSD_CLOCKID_T_
    316 typedef	_BSD_CLOCKID_T_		clockid_t;
    317 #undef	_BSD_CLOCKID_T_
    318 #endif
    319 
    320 #ifdef	_BSD_TIMER_T_
    321 typedef	_BSD_TIMER_T_		timer_t;
    322 #undef	_BSD_TIMER_T_
    323 #endif
    324 
    325 #ifdef	_BSD_SUSECONDS_T_
    326 typedef	_BSD_SUSECONDS_T_	suseconds_t;
    327 #undef	_BSD_SUSECONDS_T_
    328 #endif
    329 
    330 #ifdef	_BSD_USECONDS_T_
    331 typedef	_BSD_USECONDS_T_	useconds_t;
    332 #undef	_BSD_USECONDS_T_
    333 #endif
    334 
    335 #ifdef _NETBSD_SOURCE
    336 #include <sys/fd_set.h>
    337 
    338 #define	NBBY			8
    339 
    340 typedef struct kauth_cred *kauth_cred_t;
    341 
    342 typedef int pri_t;
    343 
    344 #endif
    345 
    346 #if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER))
    347 /*
    348  * Forward structure declarations for function prototypes.  We include the
    349  * common structures that cross subsystem boundaries here; others are mostly
    350  * used in the same place that the structure is defined.
    351  */
    352 struct	lwp;
    353 typedef struct lwp lwp_t;
    354 struct	__ucontext;
    355 struct	proc;
    356 typedef struct proc proc_t;
    357 struct	pgrp;
    358 struct	rusage;
    359 struct	file;
    360 typedef struct file file_t;
    361 struct	buf;
    362 typedef struct buf buf_t;
    363 struct	tty;
    364 struct	uio;
    365 #endif
    366 
    367 #if defined(_KERNEL) || defined(_STANDALONE)
    368 #define SET(t, f)	((t) |= (f))
    369 #define	ISSET(t, f)	((t) & (f))
    370 #define	CLR(t, f)	((t) &= ~(f))
    371 #endif
    372 
    373 #if !defined(_KERNEL) && !defined(_STANDALONE)
    374 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
    375     defined(_NETBSD_SOURCE)
    376 #include <pthread_types.h>
    377 #endif
    378 #endif
    379 
    380 #endif /* !_SYS_TYPES_H_ */
    381