From 4cf101caae2554c65a1d0b9165ec297fd1ea2e8a Mon Sep 17 00:00:00 2001 From: Gianluca Guida Date: Mon, 21 Feb 2011 13:13:55 +0000 Subject: [PATCH] Add NBSD-like Minix system includes. --- nbsd_include/Makefile | 1 + nbsd_include/arch/Makefile | 62 ++ nbsd_include/arch/i386/Makefile | 6 + nbsd_include/arch/i386/include/Makefile | 16 + nbsd_include/arch/i386/include/ansi.h | 76 ++ nbsd_include/arch/i386/include/asm.h | 223 +++++ nbsd_include/arch/i386/include/bswap.h | 13 + nbsd_include/arch/i386/include/byte_swap.h | 68 ++ nbsd_include/arch/i386/include/cdefs.h | 14 + nbsd_include/arch/i386/include/disklabel.h | 74 ++ nbsd_include/arch/i386/include/endian.h | 3 + .../arch/i386/include/endian_machdep.h | 3 + nbsd_include/arch/i386/include/fenv.h | 116 +++ nbsd_include/arch/i386/include/float.h | 3 + nbsd_include/arch/i386/include/ieee.h | 3 + nbsd_include/arch/i386/include/ieeefp.h | 3 + nbsd_include/arch/i386/include/int_const.h | 56 ++ nbsd_include/arch/i386/include/int_fmtio.h | 212 +++++ nbsd_include/arch/i386/include/int_limits.h | 127 +++ .../arch/i386/include/int_mwgwtypes.h | 87 ++ nbsd_include/arch/i386/include/int_types.h | 68 ++ nbsd_include/arch/i386/include/limits.h | 94 ++ nbsd_include/arch/i386/include/math.h | 3 + nbsd_include/arch/i386/include/mcontext.h | 22 + nbsd_include/arch/i386/include/npx.h | 199 +++++ nbsd_include/arch/i386/include/param.h | 90 ++ nbsd_include/arch/i386/include/profile.h | 137 +++ nbsd_include/arch/i386/include/setjmp.h | 7 + nbsd_include/arch/i386/include/signal.h | 64 ++ nbsd_include/arch/i386/include/stdarg.h | 86 ++ nbsd_include/arch/i386/include/types.h | 120 +++ nbsd_include/arch/i386/include/vmparam.h | 52 ++ nbsd_include/arch/i386/include/wchar_limits.h | 47 + nbsd_include/arch/x86/include/Makefile | 10 + nbsd_include/arch/x86/include/float.h | 27 + nbsd_include/arch/x86/include/ieee.h | 117 +++ nbsd_include/arch/x86/include/ieeefp.h | 29 + nbsd_include/arch/x86/include/math.h | 4 + nbsd_include/minix/Makefile | 12 + nbsd_include/minix/paths.h | 7 + nbsd_include/minix/types.h | 8 + nbsd_include/net/Makefile | 5 + nbsd_include/net/ethertypes.h | 313 +++++++ nbsd_include/net/hton.h | 5 + nbsd_include/net/if.h | 6 + nbsd_include/net/if_ether.h | 109 +++ nbsd_include/net/netlib.h | 15 + nbsd_include/netinet/Makefile | 5 + nbsd_include/netinet/in.h | 512 +++++++++++ nbsd_include/netinet/tcp.h | 119 +++ nbsd_include/netinet6/Makefile | 5 + nbsd_include/netinet6/in6.h | 808 ++++++++++++++++++ nbsd_include/sys/Makefile | 63 ++ nbsd_include/sys/ansi.h | 69 ++ nbsd_include/sys/atomic.h | 154 ++++ nbsd_include/sys/bitops.h | 294 +++++++ nbsd_include/sys/bswap.h | 79 ++ nbsd_include/sys/cdefs.h | 485 +++++++++++ nbsd_include/sys/cdefs_aout.h | 131 +++ nbsd_include/sys/ctype_bits.h | 56 ++ nbsd_include/sys/ctype_inline.h | 82 ++ nbsd_include/sys/dirent.h | 66 ++ nbsd_include/sys/endian.h | 340 ++++++++ nbsd_include/sys/errno.h | 173 ++++ nbsd_include/sys/fcntl.h | 137 +++ nbsd_include/sys/fd_set.h | 108 +++ nbsd_include/sys/featuretest.h | 81 ++ nbsd_include/sys/file.h | 169 ++++ nbsd_include/sys/float_ieee754.h | 111 +++ nbsd_include/sys/gcq.h | 463 ++++++++++ nbsd_include/sys/gmon.h | 153 ++++ nbsd_include/sys/hash.h | 103 +++ nbsd_include/sys/ieee754.h | 152 ++++ nbsd_include/sys/inttypes.h | 45 + nbsd_include/sys/ioc_net.h | 99 +++ nbsd_include/sys/ioctl.h | 34 + nbsd_include/sys/ipc.h | 51 ++ nbsd_include/sys/localedef.h | 100 +++ nbsd_include/sys/md4.h | 58 ++ nbsd_include/sys/md5.h | 58 ++ nbsd_include/sys/mman.h | 76 ++ nbsd_include/sys/mount.h | 7 + nbsd_include/sys/null.h | 16 + nbsd_include/sys/param.h | 182 ++++ nbsd_include/sys/poll.h | 67 ++ nbsd_include/sys/ptrace.h | 58 ++ nbsd_include/sys/ptree.h | 188 ++++ nbsd_include/sys/queue.h | 739 ++++++++++++++++ nbsd_include/sys/rbtree.h | 194 +++++ nbsd_include/sys/reboot.h | 13 + nbsd_include/sys/resource.h | 51 ++ nbsd_include/sys/rmd160.h | 56 ++ nbsd_include/sys/select.h | 76 ++ nbsd_include/sys/sem.h | 121 +++ nbsd_include/sys/sha1.h | 37 + nbsd_include/sys/sha2.h | 120 +++ nbsd_include/sys/shm.h | 148 ++++ nbsd_include/sys/siginfo.h | 240 ++++++ nbsd_include/sys/signal.h | 214 +++++ nbsd_include/sys/sigtypes.h | 68 ++ nbsd_include/sys/socket.h | 301 +++++++ nbsd_include/sys/stat.h | 179 ++++ nbsd_include/sys/statvfs.h | 64 ++ nbsd_include/sys/stdint.h | 100 +++ nbsd_include/sys/sysctl.h | 22 + nbsd_include/sys/syslimits.h | 72 ++ nbsd_include/sys/syslog.h | 241 ++++++ nbsd_include/sys/termios.h | 17 + nbsd_include/sys/time.h | 266 ++++++ nbsd_include/sys/times.h | 24 + nbsd_include/sys/tree.h | 741 ++++++++++++++++ nbsd_include/sys/ttycom.h | 6 + nbsd_include/sys/ttydefaults.h | 45 + nbsd_include/sys/types.h | 396 +++++++++ nbsd_include/sys/ucontext.h | 38 + nbsd_include/sys/ucred.h | 13 + nbsd_include/sys/uio.h | 37 + nbsd_include/sys/un.h | 34 + nbsd_include/sys/unistd.h | 208 +++++ nbsd_include/sys/utsname.h | 48 ++ nbsd_include/sys/uuid.h | 82 ++ nbsd_include/sys/wait.h | 64 ++ 122 files changed, 13854 insertions(+) create mode 100644 nbsd_include/arch/Makefile create mode 100644 nbsd_include/arch/i386/Makefile create mode 100644 nbsd_include/arch/i386/include/Makefile create mode 100644 nbsd_include/arch/i386/include/ansi.h create mode 100644 nbsd_include/arch/i386/include/asm.h create mode 100644 nbsd_include/arch/i386/include/bswap.h create mode 100644 nbsd_include/arch/i386/include/byte_swap.h create mode 100644 nbsd_include/arch/i386/include/cdefs.h create mode 100644 nbsd_include/arch/i386/include/disklabel.h create mode 100644 nbsd_include/arch/i386/include/endian.h create mode 100644 nbsd_include/arch/i386/include/endian_machdep.h create mode 100644 nbsd_include/arch/i386/include/fenv.h create mode 100644 nbsd_include/arch/i386/include/float.h create mode 100644 nbsd_include/arch/i386/include/ieee.h create mode 100644 nbsd_include/arch/i386/include/ieeefp.h create mode 100644 nbsd_include/arch/i386/include/int_const.h create mode 100644 nbsd_include/arch/i386/include/int_fmtio.h create mode 100644 nbsd_include/arch/i386/include/int_limits.h create mode 100644 nbsd_include/arch/i386/include/int_mwgwtypes.h create mode 100644 nbsd_include/arch/i386/include/int_types.h create mode 100644 nbsd_include/arch/i386/include/limits.h create mode 100644 nbsd_include/arch/i386/include/math.h create mode 100644 nbsd_include/arch/i386/include/mcontext.h create mode 100644 nbsd_include/arch/i386/include/npx.h create mode 100644 nbsd_include/arch/i386/include/param.h create mode 100644 nbsd_include/arch/i386/include/profile.h create mode 100644 nbsd_include/arch/i386/include/setjmp.h create mode 100644 nbsd_include/arch/i386/include/signal.h create mode 100644 nbsd_include/arch/i386/include/stdarg.h create mode 100644 nbsd_include/arch/i386/include/types.h create mode 100644 nbsd_include/arch/i386/include/vmparam.h create mode 100644 nbsd_include/arch/i386/include/wchar_limits.h create mode 100644 nbsd_include/arch/x86/include/Makefile create mode 100644 nbsd_include/arch/x86/include/float.h create mode 100644 nbsd_include/arch/x86/include/ieee.h create mode 100644 nbsd_include/arch/x86/include/ieeefp.h create mode 100644 nbsd_include/arch/x86/include/math.h create mode 100644 nbsd_include/minix/Makefile create mode 100644 nbsd_include/minix/paths.h create mode 100644 nbsd_include/minix/types.h create mode 100644 nbsd_include/net/Makefile create mode 100644 nbsd_include/net/ethertypes.h create mode 100644 nbsd_include/net/hton.h create mode 100644 nbsd_include/net/if.h create mode 100644 nbsd_include/net/if_ether.h create mode 100644 nbsd_include/net/netlib.h create mode 100644 nbsd_include/netinet/Makefile create mode 100644 nbsd_include/netinet/in.h create mode 100644 nbsd_include/netinet/tcp.h create mode 100644 nbsd_include/netinet6/Makefile create mode 100644 nbsd_include/netinet6/in6.h create mode 100644 nbsd_include/sys/Makefile create mode 100644 nbsd_include/sys/ansi.h create mode 100644 nbsd_include/sys/atomic.h create mode 100644 nbsd_include/sys/bitops.h create mode 100644 nbsd_include/sys/bswap.h create mode 100644 nbsd_include/sys/cdefs.h create mode 100644 nbsd_include/sys/cdefs_aout.h create mode 100644 nbsd_include/sys/ctype_bits.h create mode 100644 nbsd_include/sys/ctype_inline.h create mode 100644 nbsd_include/sys/dirent.h create mode 100644 nbsd_include/sys/endian.h create mode 100644 nbsd_include/sys/errno.h create mode 100644 nbsd_include/sys/fcntl.h create mode 100644 nbsd_include/sys/fd_set.h create mode 100644 nbsd_include/sys/featuretest.h create mode 100644 nbsd_include/sys/file.h create mode 100644 nbsd_include/sys/float_ieee754.h create mode 100644 nbsd_include/sys/gcq.h create mode 100644 nbsd_include/sys/gmon.h create mode 100644 nbsd_include/sys/hash.h create mode 100644 nbsd_include/sys/ieee754.h create mode 100644 nbsd_include/sys/inttypes.h create mode 100644 nbsd_include/sys/ioc_net.h create mode 100644 nbsd_include/sys/ioctl.h create mode 100644 nbsd_include/sys/ipc.h create mode 100644 nbsd_include/sys/localedef.h create mode 100644 nbsd_include/sys/md4.h create mode 100644 nbsd_include/sys/md5.h create mode 100644 nbsd_include/sys/mman.h create mode 100644 nbsd_include/sys/mount.h create mode 100644 nbsd_include/sys/null.h create mode 100644 nbsd_include/sys/param.h create mode 100644 nbsd_include/sys/poll.h create mode 100644 nbsd_include/sys/ptrace.h create mode 100644 nbsd_include/sys/ptree.h create mode 100644 nbsd_include/sys/queue.h create mode 100644 nbsd_include/sys/rbtree.h create mode 100644 nbsd_include/sys/reboot.h create mode 100644 nbsd_include/sys/resource.h create mode 100644 nbsd_include/sys/rmd160.h create mode 100644 nbsd_include/sys/select.h create mode 100644 nbsd_include/sys/sem.h create mode 100644 nbsd_include/sys/sha1.h create mode 100644 nbsd_include/sys/sha2.h create mode 100644 nbsd_include/sys/shm.h create mode 100644 nbsd_include/sys/siginfo.h create mode 100644 nbsd_include/sys/signal.h create mode 100644 nbsd_include/sys/sigtypes.h create mode 100644 nbsd_include/sys/socket.h create mode 100644 nbsd_include/sys/stat.h create mode 100644 nbsd_include/sys/statvfs.h create mode 100644 nbsd_include/sys/stdint.h create mode 100644 nbsd_include/sys/sysctl.h create mode 100644 nbsd_include/sys/syslimits.h create mode 100644 nbsd_include/sys/syslog.h create mode 100644 nbsd_include/sys/termios.h create mode 100644 nbsd_include/sys/time.h create mode 100644 nbsd_include/sys/times.h create mode 100644 nbsd_include/sys/tree.h create mode 100644 nbsd_include/sys/ttycom.h create mode 100644 nbsd_include/sys/ttydefaults.h create mode 100644 nbsd_include/sys/types.h create mode 100644 nbsd_include/sys/ucontext.h create mode 100644 nbsd_include/sys/ucred.h create mode 100644 nbsd_include/sys/uio.h create mode 100644 nbsd_include/sys/un.h create mode 100644 nbsd_include/sys/unistd.h create mode 100644 nbsd_include/sys/utsname.h create mode 100644 nbsd_include/sys/uuid.h create mode 100644 nbsd_include/sys/wait.h diff --git a/nbsd_include/Makefile b/nbsd_include/Makefile index 2e2821230..8c4a912a5 100644 --- a/nbsd_include/Makefile +++ b/nbsd_include/Makefile @@ -77,6 +77,7 @@ SUBDIR+= ../common/include/prop .if defined(__MINIX) .include "${MINIXSRCDIR}/common/include/Makefile.inc" +SUBDIR+= arch/${MACHINE} SUBDIR+= arch sys minix SUBDIR+= net netinet netinet6 .endif diff --git a/nbsd_include/arch/Makefile b/nbsd_include/arch/Makefile new file mode 100644 index 000000000..4d47046e9 --- /dev/null +++ b/nbsd_include/arch/Makefile @@ -0,0 +1,62 @@ +# $NetBSD: Makefile,v 1.40 2009/12/13 05:01:33 nakayama Exp $ + +# For now, we install the machine and arch includes, and symlink 'machine' +# to the location of the machine includes (usually). +# +# Eventually, we should install everything. + +.include + +SUBDIR= ${MACHINE} +ARCHSUBDIR= ${MACHINE_CPU} + +.if ${ARCHSUBDIR} == "mips64" +ARCHSUBDIR= mips +.endif +.if ${ARCHSUBDIR} == "powerpc64" +ARCHSUBDIR= powerpc +.endif + +.if ${MACHINE} != ${ARCHSUBDIR} +.if exists(${ARCHSUBDIR}) +SUBDIR+= ${ARCHSUBDIR} +.endif +.endif +.if ${MACHINE} == sparc +SUBDIR+= sparc64 +.endif +.if (${MACHINE} == hpcmips || ${MACHINE} == hpcsh) +SUBDIR+= hpc +.endif +.if (${MACHINE} == sun2 || ${MACHINE} == sun3) +SUBDIR+= sun68k +.endif +.if defined(XEN_BUILD) +SUBDIR+= xen +.endif + +#SUBDIR=acorn26 acorn32 algor alpha amiga amigappc arm arc atari \ +# bebox \ +# cats cesfic cobalt \ +# dreamcast \ +# evbarm evbmips evbppc evbsh3 ews4800mips\ +# hp300 hpc hpcarm hpcmips hpcsh \ +# i386 iyonix \ +# luna68k \ +# m68k mac68k macppc mips mipsco mmeye mvme68k \ +# netwinder news68k newsmips next68k \ +# ofppc \ +# pmax powerpc prep \ +# sandpoint sbmips sgimips sh3 shark sparc sparc64 sun2 sun3 sun68k \ +# rs6000 \ +# vax \ +# x68k x86_64 xen \ +# zaurus + +INCSYMLINKS= ${MACHINE} /usr/netbsd/include/machine + +INCSYMLINKS+= /usr/netbsd/include/machine/float.h /usr/netbsd/include/float.h \ + /usr/netbsd/include/machine/stdarg.h /usr/netbsd/include/stdarg.h + + +.include diff --git a/nbsd_include/arch/i386/Makefile b/nbsd_include/arch/i386/Makefile new file mode 100644 index 000000000..4aa9208bf --- /dev/null +++ b/nbsd_include/arch/i386/Makefile @@ -0,0 +1,6 @@ +# $NetBSD: Makefile,v 1.38 2009/08/30 02:00:56 dyoung Exp $ + + +SUBDIR= include ../x86/include + +.include diff --git a/nbsd_include/arch/i386/include/Makefile b/nbsd_include/arch/i386/include/Makefile new file mode 100644 index 000000000..c01b94fb4 --- /dev/null +++ b/nbsd_include/arch/i386/include/Makefile @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.36 2007/12/20 23:46:12 ad Exp $ +.include + +INCSDIR= /usr/netbsd/include/i386 + +INCS= ansi.h asm.h bswap.h byte_swap.h cdefs.h \ + endian.h endian_machdep.h fenv.h float.h ieee.h \ + ieeefp.h int_const.h int_fmtio.h int_limits.h \ + int_mwgwtypes.h int_types.h limits.h \ + math.h mcontext.h npx.h param.h profile.h \ + setjmp.h signal.h stdarg.h types.h \ + vmparam.h wchar_limits.h + + +.include "${MINIXSRCDIR}/common/include/arch/i386/Makefile.inc" +.include diff --git a/nbsd_include/arch/i386/include/ansi.h b/nbsd_include/arch/i386/include/ansi.h new file mode 100644 index 000000000..9c1cfe470 --- /dev/null +++ b/nbsd_include/arch/i386/include/ansi.h @@ -0,0 +1,76 @@ +/* $NetBSD: ansi.h,v 1.24 2010/03/27 22:14:09 tnozaki Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ansi.h 8.2 (Berkeley) 1/4/94 + */ + +/* These types are Minix specific. */ + +#ifndef _I386_ANSI_H_ +#define _I386_ANSI_H_ + +#include + +#include + +/* + * Types which are fundamental to the implementation and may appear in + * more than one standard header are defined here. Standard headers + * then use: + * #ifdef _BSD_SIZE_T_ + * typedef _BSD_SIZE_T_ size_t; + * #undef _BSD_SIZE_T_ + * #endif + */ + +#define _BSD_CLOCK_T_ long + +#if _EM_PSIZE == _EM_WSIZE +#define _BSD_PTRDIFF_T_ int +#else /* _EM_PSIZE == _EM_LSIZE */ +#define _BSD_PTRDIFF_T_ long +#endif + +#define _BSD_SIZE_T_ unsigned int +#define _BSD_SSIZE_T_ int +#define _BSD_TIME_T_ long /* time() */ +#if __GNUC_PREREQ__(2, 96) +#define _BSD_VA_LIST_ __builtin_va_list /* GCC built-in type */ +#else +#define _BSD_VA_LIST_ char * /* va_list */ +#endif +#define _BSD_CLOCKID_T_ int /* clockid_t */ +#define _BSD_TIMER_T_ int /* timer_t */ +#define _BSD_SUSECONDS_T_ long /* suseconds_t */ +#define _BSD_USECONDS_T_ long /* useconds_t */ +#define _BSD_WCHAR_T_ int /* wchar_t */ +#define _BSD_WINT_T_ int /* wint_t */ + +#endif /* _I386_ANSI_H_ */ diff --git a/nbsd_include/arch/i386/include/asm.h b/nbsd_include/arch/i386/include/asm.h new file mode 100644 index 000000000..cb15ecf55 --- /dev/null +++ b/nbsd_include/arch/i386/include/asm.h @@ -0,0 +1,223 @@ +/* $NetBSD: asm.h,v 1.39 2010/12/20 21:11:24 joerg Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _I386_ASM_H_ +#define _I386_ASM_H_ + +#ifdef _KERNEL_OPT +#include "opt_multiprocessor.h" +#endif + +#ifdef PIC +#define PIC_PROLOGUE \ + pushl %ebx; \ + call 1f; \ +1: \ + popl %ebx; \ + addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx +#define PIC_EPILOGUE \ + popl %ebx +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOT(%ebx) +#define PIC_GOTOFF(x) x@GOTOFF(%ebx) +#else +#define PIC_PROLOGUE +#define PIC_EPILOGUE +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#define PIC_GOTOFF(x) x +#endif + +#ifdef __ELF__ +# define _C_LABEL(x) x +#else +# ifdef __STDC__ +# define _C_LABEL(x) _ ## x +# else +# define _C_LABEL(x) _/**/x +# endif +#endif +#define _ASM_LABEL(x) x + +#define CVAROFF(x, y) _C_LABEL(x) + y + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +/* let kernels and others override entrypoint alignment */ +#if !defined(_ALIGN_TEXT) && !defined(_KERNEL) +# ifdef _STANDALONE +# define _ALIGN_TEXT .align 4 +# elif defined __ELF__ +# define _ALIGN_TEXT .align 16 +# else +# define _ALIGN_TEXT .align 4 +# endif +#endif + +#define _ENTRY(x) \ + .text; _ALIGN_TEXT; .globl x; .type x,@function; x: +#define _LABEL(x) \ + .globl x; x: + +#ifdef _KERNEL + +#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off) + +/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */ +#ifdef __ELF__ +#ifdef __STDC__ +#define IDTVEC(name) \ + ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name: +#define IDTVEC_END(name) \ + .size X ## name, . - X ## name +#else +#define IDTVEC(name) \ + ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name: +#define IDTVEC_END(name) \ + .size X/**/name, . - X/**/name +#endif /* __STDC__ */ +#else +#ifdef __STDC__ +#define IDTVEC(name) \ + ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name: +#define IDTVEC_END(name) \ + .size _X ## name, . - _X ## name +#else +#define IDTVEC(name) \ + ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name: +#define IDTVEC_END(name) \ + .size _X/**/name, . - _X/**/name +#endif /* __STDC__ */ +#endif /* __ELF__ */ + +#ifdef _STANDALONE +#define ALIGN_DATA .align 4 +#define ALIGN_TEXT .align 4 /* 4-byte boundaries */ +#define SUPERALIGN_TEXT .align 16 /* 15-byte boundaries */ +#elif defined __ELF__ +#define ALIGN_DATA .align 4 +#define ALIGN_TEXT .align 16 /* 16-byte boundaries */ +#define SUPERALIGN_TEXT .align 16 /* 16-byte boundaries */ +#else +#define ALIGN_DATA .align 2 +#define ALIGN_TEXT .align 4 /* 16-byte boundaries */ +#define SUPERALIGN_TEXT .align 4 /* 16-byte boundaries */ +#endif /* __ELF__ */ + +#define _ALIGN_TEXT ALIGN_TEXT + +#ifdef GPROF +#ifdef __ELF__ +#define MCOUNT_ASM call _C_LABEL(__mcount) +#else /* __ELF__ */ +#define MCOUNT_ASM call _C_LABEL(mcount) +#endif /* __ELF__ */ +#else /* GPROF */ +#define MCOUNT_ASM /* nothing */ +#endif /* GPROF */ + +#endif /* _KERNEL */ + + + +#ifdef GPROF +# ifdef __ELF__ +# define _PROF_PROLOGUE \ + pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp +# else +# define _PROF_PROLOGUE \ + pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp +# endif +#else +# define _PROF_PROLOGUE +#endif + +#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE +#define NENTRY(y) _ENTRY(_C_LABEL(y)) +#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE +#define LABEL(y) _LABEL(_C_LABEL(y)) +#define END(y) .size y, . - y + +#define ASMSTR .asciz + +#ifdef __ELF__ +#define RCSID(x) .pushsection ".ident"; .asciz x; .popsection +#else +#define RCSID(x) .text; .asciz x +#endif + +#ifdef NO_KERNEL_RCSIDS +#define __KERNEL_RCSID(_n, _s) /* nothing */ +#else +#define __KERNEL_RCSID(_n, _s) RCSID(_s) +#endif + +#if defined(__ELF__) || defined(__minix) +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym +#endif +/* + * STRONG_ALIAS: create a strong alias. + */ +#define STRONG_ALIAS(alias,sym) \ + .globl alias; \ + alias = sym + +#ifdef __STDC__ +#define WARN_REFERENCES(sym,msg) \ + .pushsection .gnu.warning. ## sym; \ + .ascii msg; \ + .popsection +#else +#define WARN_REFERENCES(sym,msg) \ + .pushsection .gnu.warning./**/sym; \ + .ascii msg; \ + .popsection +#endif /* __STDC__ */ + +#ifdef __minix +#define IMPORT(sym) \ + .extern _C_LABEL(sym) +#endif + +#endif /* !_I386_ASM_H_ */ diff --git a/nbsd_include/arch/i386/include/bswap.h b/nbsd_include/arch/i386/include/bswap.h new file mode 100644 index 000000000..9d3d55b73 --- /dev/null +++ b/nbsd_include/arch/i386/include/bswap.h @@ -0,0 +1,13 @@ +/* $NetBSD: bswap.h,v 1.4 2008/10/26 06:57:30 mrg Exp $ */ + +/* Written by Manuel Bouyer. Public domain */ + +#ifndef _I386_BSWAP_H_ +#define _I386_BSWAP_H_ + +#include + +#define __BSWAP_RENAME +#include + +#endif /* !_I386_BSWAP_H_ */ diff --git a/nbsd_include/arch/i386/include/byte_swap.h b/nbsd_include/arch/i386/include/byte_swap.h new file mode 100644 index 000000000..9f769b705 --- /dev/null +++ b/nbsd_include/arch/i386/include/byte_swap.h @@ -0,0 +1,68 @@ +/* $NetBSD: byte_swap.h,v 1.15 2008/04/28 20:23:24 martin Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_BYTE_SWAP_H_ +#define _I386_BYTE_SWAP_H_ + +#include + +#ifdef __GNUC__ +__BEGIN_DECLS + +#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable +static __inline uint32_t __byte_swap_u32_variable(uint32_t); +static __inline uint32_t +__byte_swap_u32_variable(uint32_t x) +{ + __asm volatile ( + "bswap %1" + : "=r" (x) : "0" (x)); + return (x); +} + +#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable +static __inline uint16_t __byte_swap_u16_variable(uint16_t); +static __inline uint16_t +__byte_swap_u16_variable(uint16_t x) +{ + __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x)); + return (x); +} + +__END_DECLS +#elif defined(_KERNEL) || defined(_LKM) +#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable +#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable +uint32_t __byte_swap_u32_variable(uint32_t); +uint16_t __byte_swap_u16_variable(uint16_t); +#endif + +#endif /* !_I386_BYTE_SWAP_H_ */ diff --git a/nbsd_include/arch/i386/include/cdefs.h b/nbsd_include/arch/i386/include/cdefs.h new file mode 100644 index 000000000..6fe7a7383 --- /dev/null +++ b/nbsd_include/arch/i386/include/cdefs.h @@ -0,0 +1,14 @@ +/* $NetBSD: cdefs.h,v 1.7 2008/10/26 06:57:30 mrg Exp $ */ + +#ifndef _I386_CDEFS_H_ +#define _I386_CDEFS_H_ + +#ifdef __minix +#define __LEADING_UNDERSCORE +#else /* !__minix */ +/* No arch-specific cdefs. */ +#endif + + + +#endif /* !_I386_CDEFS_H_ */ diff --git a/nbsd_include/arch/i386/include/disklabel.h b/nbsd_include/arch/i386/include/disklabel.h new file mode 100644 index 000000000..bf567de6d --- /dev/null +++ b/nbsd_include/arch/i386/include/disklabel.h @@ -0,0 +1,74 @@ +/* $NetBSD: disklabel.h,v 1.15 2009/11/23 13:40:10 pooka Exp $ */ + +/* + * Copyright (c) 1994 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_DISKLABEL_H_ +#define _I386_DISKLABEL_H_ + +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ +#define MAXPARTITIONS 16 /* number of partitions */ +#define OLDMAXPARTITIONS 8 /* number of partitions before 1.6 */ +#define RAW_PART 3 /* raw partition: XX?d (XXX) */ + +/* + * We use the highest bit of the minor number for the partition number. + * This maintains backward compatibility with device nodes created before + * MAXPARTITIONS was increased. + */ +#define __I386_MAXDISKS ((1 << 20) / MAXPARTITIONS) +#define DISKUNIT(dev) ((minor(dev) / OLDMAXPARTITIONS) % __I386_MAXDISKS) +#define DISKPART(dev) ((minor(dev) % OLDMAXPARTITIONS) + \ + ((minor(dev) / (__I386_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS)) +#define DISKMINOR(unit, part) \ + (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \ + ((part) / OLDMAXPARTITIONS) * (__I386_MAXDISKS * OLDMAXPARTITIONS)) + +/* Pull in MBR partition definitions. */ +#if HAVE_NBTOOL_CONFIG_H +#include +#else +#include +#endif /* HAVE_NBTOOL_CONFIG_H */ + +#ifndef __ASSEMBLER__ +#if HAVE_NBTOOL_CONFIG_H +#include +#else +#include +#endif /* HAVE_NBTOOL_CONFIG_H */ +struct cpu_disklabel { +#define __HAVE_DISKLABEL_DKBAD + struct dkbad bad; +}; +#endif + +#endif /* _I386_DISKLABEL_H_ */ diff --git a/nbsd_include/arch/i386/include/endian.h b/nbsd_include/arch/i386/include/endian.h new file mode 100644 index 000000000..32be6403c --- /dev/null +++ b/nbsd_include/arch/i386/include/endian.h @@ -0,0 +1,3 @@ +/* $NetBSD: endian.h,v 1.29 2000/03/17 00:09:20 mycroft Exp $ */ + +#include diff --git a/nbsd_include/arch/i386/include/endian_machdep.h b/nbsd_include/arch/i386/include/endian_machdep.h new file mode 100644 index 000000000..1266b399c --- /dev/null +++ b/nbsd_include/arch/i386/include/endian_machdep.h @@ -0,0 +1,3 @@ +/* $NetBSD: endian_machdep.h,v 1.3 2006/01/30 21:52:38 dsl Exp $ */ + +#define _BYTE_ORDER _LITTLE_ENDIAN diff --git a/nbsd_include/arch/i386/include/fenv.h b/nbsd_include/arch/i386/include/fenv.h new file mode 100644 index 000000000..e38c6b5a3 --- /dev/null +++ b/nbsd_include/arch/i386/include/fenv.h @@ -0,0 +1,116 @@ +/* $NetBSD: fenv.h,v 1.1 2010/07/31 21:47:54 joerg Exp $ */ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _X86_FENV_H_ +#define _X86_FENV_H_ + +#include +#include + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 /* 000000000001 */ +#define FE_DENORMAL 0x02 /* 000000000010 */ +#define FE_DIVBYZERO 0x04 /* 000000000100 */ +#define FE_OVERFLOW 0x08 /* 000000001000 */ +#define FE_UNDERFLOW 0x10 /* 000000010000 */ +#define FE_INEXACT 0x20 /* 000000100000 */ + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 /* 000000000000 */ +#define FE_DOWNWARD 0x400 /* 010000000000 */ +#define FE_UPWARD 0x800 /* 100000000000 */ +#define FE_TOWARDZERO 0xC00 /* 110000000000 */ + +/* + * As compared to the x87 control word, the SSE unit's control has the rounding + * control bits offset by 3 and the exception mask bits offset by 7 + */ +#define __X87_ROUND_MASK 0xC00 /* 110000000000 */ +#define __SSE_ROUND_SHIFT 3 +#define __SSE_EMASK_SHIFT 7 + +/* + * fenv_t represents the entire floating-point environment + */ +typedef struct { + struct { + uint16_t control; /* Control word register */ + uint16_t unused1; + uint16_t status; /* Status word register */ + uint16_t unused2; + uint16_t tag; /* Tag word register */ + uint16_t unused3; + uint32_t others[4]; /* EIP, Pointer Selector, etc */ + } x87; + + uint32_t mxcsr; /* Control and status register */ +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment. + */ +extern fenv_t __fe_dfl_env; +#define FE_DFL_ENV ((const fenv_t *) &__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef uint32_t fexcept_t; + +#endif /* ! _X86_FENV_H_ */ diff --git a/nbsd_include/arch/i386/include/float.h b/nbsd_include/arch/i386/include/float.h new file mode 100644 index 000000000..1993473e3 --- /dev/null +++ b/nbsd_include/arch/i386/include/float.h @@ -0,0 +1,3 @@ +/* $NetBSD: float.h,v 1.12 2003/02/26 21:29:00 fvdl Exp $ */ + +#include diff --git a/nbsd_include/arch/i386/include/ieee.h b/nbsd_include/arch/i386/include/ieee.h new file mode 100644 index 000000000..8e887872e --- /dev/null +++ b/nbsd_include/arch/i386/include/ieee.h @@ -0,0 +1,3 @@ +/* $NetBSD: ieee.h,v 1.2 2003/02/26 21:29:01 fvdl Exp $ */ + +#include diff --git a/nbsd_include/arch/i386/include/ieeefp.h b/nbsd_include/arch/i386/include/ieeefp.h new file mode 100644 index 000000000..06c4c573b --- /dev/null +++ b/nbsd_include/arch/i386/include/ieeefp.h @@ -0,0 +1,3 @@ +/* $NetBSD: ieeefp.h,v 1.3 2003/02/26 21:29:01 fvdl Exp $ */ + +#include diff --git a/nbsd_include/arch/i386/include/int_const.h b/nbsd_include/arch/i386/include/int_const.h new file mode 100644 index 000000000..9a75f6870 --- /dev/null +++ b/nbsd_include/arch/i386/include/int_const.h @@ -0,0 +1,56 @@ +/* $NetBSD: int_const.h,v 1.3 2010/05/29 17:33:57 tnozaki Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_INT_CONST_H_ +#define _I386_INT_CONST_H_ + +/* + * 7.18.4 Macros for integer constants + */ + +/* 7.18.4.1 Macros for minimum-width integer constants */ + +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c +#define INT64_C(c) c ## LL + +#define UINT8_C(c) c +#define UINT16_C(c) c +#define UINT32_C(c) c ## U +#define UINT64_C(c) c ## ULL + +/* 7.18.4.2 Macros for greatest-width integer constants */ + +#define INTMAX_C(c) c ## LL +#define UINTMAX_C(c) c ## ULL + +#endif /* !_I386_INT_CONST_H_ */ diff --git a/nbsd_include/arch/i386/include/int_fmtio.h b/nbsd_include/arch/i386/include/int_fmtio.h new file mode 100644 index 000000000..c0778c114 --- /dev/null +++ b/nbsd_include/arch/i386/include/int_fmtio.h @@ -0,0 +1,212 @@ +/* $NetBSD: int_fmtio.h,v 1.7 2008/04/28 20:23:24 martin Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_INT_FMTIO_H_ +#define _I386_INT_FMTIO_H_ + +/* + * 7.8.1 Macros for format specifiers + */ + +/* fprintf macros for signed integers */ + +#define PRId8 "d" /* int8_t */ +#define PRId16 "d" /* int16_t */ +#define PRId32 "d" /* int32_t */ +#define PRId64 "lld" /* int64_t */ +#define PRIdLEAST8 "d" /* int_least8_t */ +#define PRIdLEAST16 "d" /* int_least16_t */ +#define PRIdLEAST32 "d" /* int_least32_t */ +#define PRIdLEAST64 "lld" /* int_least64_t */ +#define PRIdFAST8 "d" /* int_fast8_t */ +#define PRIdFAST16 "d" /* int_fast16_t */ +#define PRIdFAST32 "d" /* int_fast32_t */ +#define PRIdFAST64 "lld" /* int_fast64_t */ +#define PRIdMAX "lld" /* intmax_t */ +#define PRIdPTR "d" /* intptr_t */ + +#define PRIi8 "i" /* int8_t */ +#define PRIi16 "i" /* int16_t */ +#define PRIi32 "i" /* int32_t */ +#define PRIi64 "lli" /* int64_t */ +#define PRIiLEAST8 "i" /* int_least8_t */ +#define PRIiLEAST16 "i" /* int_least16_t */ +#define PRIiLEAST32 "i" /* int_least32_t */ +#define PRIiLEAST64 "lli" /* int_least64_t */ +#define PRIiFAST8 "i" /* int_fast8_t */ +#define PRIiFAST16 "i" /* int_fast16_t */ +#define PRIiFAST32 "i" /* int_fast32_t */ +#define PRIiFAST64 "lli" /* int_fast64_t */ +#define PRIiMAX "lli" /* intmax_t */ +#define PRIiPTR "i" /* intptr_t */ + +/* fprintf macros for unsigned integers */ + +#define PRIo8 "o" /* uint8_t */ +#define PRIo16 "o" /* uint16_t */ +#define PRIo32 "o" /* uint32_t */ +#define PRIo64 "llo" /* uint64_t */ +#define PRIoLEAST8 "o" /* uint_least8_t */ +#define PRIoLEAST16 "o" /* uint_least16_t */ +#define PRIoLEAST32 "o" /* uint_least32_t */ +#define PRIoLEAST64 "llo" /* uint_least64_t */ +#define PRIoFAST8 "o" /* uint_fast8_t */ +#define PRIoFAST16 "o" /* uint_fast16_t */ +#define PRIoFAST32 "o" /* uint_fast32_t */ +#define PRIoFAST64 "llo" /* uint_fast64_t */ +#define PRIoMAX "llo" /* uintmax_t */ +#define PRIoPTR "o" /* uintptr_t */ + +#define PRIu8 "u" /* uint8_t */ +#define PRIu16 "u" /* uint16_t */ +#define PRIu32 "u" /* uint32_t */ +#define PRIu64 "llu" /* uint64_t */ +#define PRIuLEAST8 "u" /* uint_least8_t */ +#define PRIuLEAST16 "u" /* uint_least16_t */ +#define PRIuLEAST32 "u" /* uint_least32_t */ +#define PRIuLEAST64 "llu" /* uint_least64_t */ +#define PRIuFAST8 "u" /* uint_fast8_t */ +#define PRIuFAST16 "u" /* uint_fast16_t */ +#define PRIuFAST32 "u" /* uint_fast32_t */ +#define PRIuFAST64 "llu" /* uint_fast64_t */ +#define PRIuMAX "llu" /* uintmax_t */ +#define PRIuPTR "u" /* uintptr_t */ + +#define PRIx8 "x" /* uint8_t */ +#define PRIx16 "x" /* uint16_t */ +#define PRIx32 "x" /* uint32_t */ +#define PRIx64 "llx" /* uint64_t */ +#define PRIxLEAST8 "x" /* uint_least8_t */ +#define PRIxLEAST16 "x" /* uint_least16_t */ +#define PRIxLEAST32 "x" /* uint_least32_t */ +#define PRIxLEAST64 "llx" /* uint_least64_t */ +#define PRIxFAST8 "x" /* uint_fast8_t */ +#define PRIxFAST16 "x" /* uint_fast16_t */ +#define PRIxFAST32 "x" /* uint_fast32_t */ +#define PRIxFAST64 "llx" /* uint_fast64_t */ +#define PRIxMAX "llx" /* uintmax_t */ +#define PRIxPTR "x" /* uintptr_t */ + +#define PRIX8 "X" /* uint8_t */ +#define PRIX16 "X" /* uint16_t */ +#define PRIX32 "X" /* uint32_t */ +#define PRIX64 "llX" /* uint64_t */ +#define PRIXLEAST8 "X" /* uint_least8_t */ +#define PRIXLEAST16 "X" /* uint_least16_t */ +#define PRIXLEAST32 "X" /* uint_least32_t */ +#define PRIXLEAST64 "llX" /* uint_least64_t */ +#define PRIXFAST8 "X" /* uint_fast8_t */ +#define PRIXFAST16 "X" /* uint_fast16_t */ +#define PRIXFAST32 "X" /* uint_fast32_t */ +#define PRIXFAST64 "llX" /* uint_fast64_t */ +#define PRIXMAX "llX" /* uintmax_t */ +#define PRIXPTR "X" /* uintptr_t */ + +/* fscanf macros for signed integers */ + +#define SCNd8 "hhd" /* int8_t */ +#define SCNd16 "hd" /* int16_t */ +#define SCNd32 "d" /* int32_t */ +#define SCNd64 "lld" /* int64_t */ +#define SCNdLEAST8 "hhd" /* int_least8_t */ +#define SCNdLEAST16 "hd" /* int_least16_t */ +#define SCNdLEAST32 "d" /* int_least32_t */ +#define SCNdLEAST64 "lld" /* int_least64_t */ +#define SCNdFAST8 "hhd" /* int_fast8_t */ +#define SCNdFAST16 "d" /* int_fast16_t */ +#define SCNdFAST32 "d" /* int_fast32_t */ +#define SCNdFAST64 "lld" /* int_fast64_t */ +#define SCNdMAX "lld" /* intmax_t */ +#define SCNdPTR "d" /* intptr_t */ + +#define SCNi8 "hhi" /* int8_t */ +#define SCNi16 "hi" /* int16_t */ +#define SCNi32 "i" /* int32_t */ +#define SCNi64 "lli" /* int64_t */ +#define SCNiLEAST8 "hhi" /* int_least8_t */ +#define SCNiLEAST16 "hi" /* int_least16_t */ +#define SCNiLEAST32 "i" /* int_least32_t */ +#define SCNiLEAST64 "lli" /* int_least64_t */ +#define SCNiFAST8 "hhi" /* int_fast8_t */ +#define SCNiFAST16 "i" /* int_fast16_t */ +#define SCNiFAST32 "i" /* int_fast32_t */ +#define SCNiFAST64 "lli" /* int_fast64_t */ +#define SCNiMAX "lli" /* intmax_t */ +#define SCNiPTR "i" /* intptr_t */ + +/* fscanf macros for unsigned integers */ + +#define SCNo8 "hho" /* uint8_t */ +#define SCNo16 "ho" /* uint16_t */ +#define SCNo32 "o" /* uint32_t */ +#define SCNo64 "llo" /* uint64_t */ +#define SCNoLEAST8 "hho" /* uint_least8_t */ +#define SCNoLEAST16 "ho" /* uint_least16_t */ +#define SCNoLEAST32 "o" /* uint_least32_t */ +#define SCNoLEAST64 "llo" /* uint_least64_t */ +#define SCNoFAST8 "hho" /* uint_fast8_t */ +#define SCNoFAST16 "o" /* uint_fast16_t */ +#define SCNoFAST32 "o" /* uint_fast32_t */ +#define SCNoFAST64 "llo" /* uint_fast64_t */ +#define SCNoMAX "llo" /* uintmax_t */ +#define SCNoPTR "o" /* uintptr_t */ + +#define SCNu8 "hhu" /* uint8_t */ +#define SCNu16 "hu" /* uint16_t */ +#define SCNu32 "u" /* uint32_t */ +#define SCNu64 "llu" /* uint64_t */ +#define SCNuLEAST8 "hhu" /* uint_least8_t */ +#define SCNuLEAST16 "hu" /* uint_least16_t */ +#define SCNuLEAST32 "u" /* uint_least32_t */ +#define SCNuLEAST64 "llu" /* uint_least64_t */ +#define SCNuFAST8 "hhu" /* uint_fast8_t */ +#define SCNuFAST16 "u" /* uint_fast16_t */ +#define SCNuFAST32 "u" /* uint_fast32_t */ +#define SCNuFAST64 "llu" /* uint_fast64_t */ +#define SCNuMAX "llu" /* uintmax_t */ +#define SCNuPTR "u" /* uintptr_t */ + +#define SCNx8 "hhx" /* uint8_t */ +#define SCNx16 "hx" /* uint16_t */ +#define SCNx32 "x" /* uint32_t */ +#define SCNx64 "llx" /* uint64_t */ +#define SCNxLEAST8 "hhx" /* uint_least8_t */ +#define SCNxLEAST16 "hx" /* uint_least16_t */ +#define SCNxLEAST32 "x" /* uint_least32_t */ +#define SCNxLEAST64 "llx" /* uint_least64_t */ +#define SCNxFAST8 "hhx" /* uint_fast8_t */ +#define SCNxFAST16 "x" /* uint_fast16_t */ +#define SCNxFAST32 "x" /* uint_fast32_t */ +#define SCNxFAST64 "llx" /* uint_fast64_t */ +#define SCNxMAX "llx" /* uintmax_t */ +#define SCNxPTR "x" /* uintptr_t */ + +#endif /* !_I386_INT_FMTIO_H_ */ diff --git a/nbsd_include/arch/i386/include/int_limits.h b/nbsd_include/arch/i386/include/int_limits.h new file mode 100644 index 000000000..3d3b7de48 --- /dev/null +++ b/nbsd_include/arch/i386/include/int_limits.h @@ -0,0 +1,127 @@ +/* $NetBSD: int_limits.h,v 1.8 2008/04/28 20:23:24 martin Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_INT_LIMITS_H_ +#define _I386_INT_LIMITS_H_ + +/* + * 7.18.2 Limits of specified-width integer types + */ + +/* 7.18.2.1 Limits of exact-width integer types */ + +/* minimum values of exact-width signed integer types */ +#define INT8_MIN (-0x7f-1) /* int8_t */ +#define INT16_MIN (-0x7fff-1) /* int16_t */ +#define INT32_MIN (-0x7fffffff-1) /* int32_t */ +#define INT64_MIN (-0x7fffffffffffffffLL-1) /* int64_t */ + +/* maximum values of exact-width signed integer types */ +#define INT8_MAX 0x7f /* int8_t */ +#define INT16_MAX 0x7fff /* int16_t */ +#define INT32_MAX 0x7fffffff /* int32_t */ +#define INT64_MAX 0x7fffffffffffffffLL /* int64_t */ + +/* maximum values of exact-width unsigned integer types */ +#define UINT8_MAX 0xff /* uint8_t */ +#define UINT16_MAX 0xffff /* uint16_t */ +#define UINT32_MAX 0xffffffffU /* uint32_t */ +#define UINT64_MAX 0xffffffffffffffffULL /* uint64_t */ + +/* 7.18.2.2 Limits of minimum-width integer types */ + +/* minimum values of minimum-width signed integer types */ +#define INT_LEAST8_MIN (-0x7f-1) /* int_least8_t */ +#define INT_LEAST16_MIN (-0x7fff-1) /* int_least16_t */ +#define INT_LEAST32_MIN (-0x7fffffff-1) /* int_least32_t */ +#define INT_LEAST64_MIN (-0x7fffffffffffffffLL-1) /* int_least64_t */ + +/* maximum values of minimum-width signed integer types */ +#define INT_LEAST8_MAX 0x7f /* int_least8_t */ +#define INT_LEAST16_MAX 0x7fff /* int_least16_t */ +#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t */ +#define INT_LEAST64_MAX 0x7fffffffffffffffLL /* int_least64_t */ + +/* maximum values of minimum-width unsigned integer types */ +#define UINT_LEAST8_MAX 0xff /* uint_least8_t */ +#define UINT_LEAST16_MAX 0xffff /* uint_least16_t */ +#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */ +#define UINT_LEAST64_MAX 0xffffffffffffffffULL /* uint_least64_t */ + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ + +/* minimum values of fastest minimum-width signed integer types */ +#define INT_FAST8_MIN (-0x7f-1) /* int_fast8_t */ +#define INT_FAST16_MIN (-0x7fffffff-1) /* int_fast16_t */ +#define INT_FAST32_MIN (-0x7fffffff-1) /* int_fast32_t */ +#define INT_FAST64_MIN (-0x7fffffffffffffffLL-1) /* int_fast64_t */ + +/* maximum values of fastest minimum-width signed integer types */ +#define INT_FAST8_MAX 0x7f /* int_fast8_t */ +#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t */ +#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t */ +#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t */ + +/* maximum values of fastest minimum-width unsigned integer types */ +#define UINT_FAST8_MAX 0xff /* uint_fast8_t */ +#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t */ +#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t */ +#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t */ + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ + +#define INTPTR_MIN (-0x7fffffff-1) /* intptr_t */ +#define INTPTR_MAX 0x7fffffff /* intptr_t */ +#define UINTPTR_MAX 0xffffffffU /* uintptr_t */ + +/* 7.18.2.5 Limits of greatest-width integer types */ + +#define INTMAX_MIN (-0x7fffffffffffffffLL-1) /* intmax_t */ +#define INTMAX_MAX 0x7fffffffffffffffLL /* intmax_t */ +#define UINTMAX_MAX 0xffffffffffffffffULL /* uintmax_t */ + + +/* + * 7.18.3 Limits of other integer types + */ + +/* limits of ptrdiff_t */ +#define PTRDIFF_MIN (-0x7fffffff-1) /* ptrdiff_t */ +#define PTRDIFF_MAX 0x7fffffff /* ptrdiff_t */ + +/* limits of sig_atomic_t */ +#define SIG_ATOMIC_MIN (-0x7fffffff-1) /* sig_atomic_t */ +#define SIG_ATOMIC_MAX 0x7fffffff /* sig_atomic_t */ + +/* limit of size_t */ +#define SIZE_MAX 0xffffffffU /* size_t */ + +#endif /* !_I386_INT_LIMITS_H_ */ diff --git a/nbsd_include/arch/i386/include/int_mwgwtypes.h b/nbsd_include/arch/i386/include/int_mwgwtypes.h new file mode 100644 index 000000000..bf3fc888b --- /dev/null +++ b/nbsd_include/arch/i386/include/int_mwgwtypes.h @@ -0,0 +1,87 @@ +/* $NetBSD: int_mwgwtypes.h,v 1.6 2008/04/28 20:23:24 martin Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_INT_MWGWTYPES_H_ +#define _I386_INT_MWGWTYPES_H_ + +/* + * 7.18.1 Integer types + */ + +/* 7.18.1.2 Minimum-width integer types */ + +typedef signed char int_least8_t; +typedef unsigned char uint_least8_t; +typedef short int int_least16_t; +typedef unsigned short int uint_least16_t; +typedef int int_least32_t; +typedef unsigned int uint_least32_t; +#ifdef __COMPILER_INT64__ +typedef __COMPILER_INT64__ int_least64_t; +typedef __COMPILER_UINT64__ uint_least64_t; +#else +/* LONGLONG */ +typedef long long int int_least64_t; +/* LONGLONG */ +typedef unsigned long long int uint_least64_t; +#endif + +/* 7.18.1.3 Fastest minimum-width integer types */ + +typedef signed char int_fast8_t; +typedef unsigned char uint_fast8_t; +typedef int int_fast16_t; +typedef unsigned int uint_fast16_t; +typedef int int_fast32_t; +typedef unsigned int uint_fast32_t; +#ifdef __COMPILER_INT64__ +typedef __COMPILER_INT64__ int_fast64_t; +typedef __COMPILER_UINT64__ uint_fast64_t; +#else +/* LONGLONG */ +typedef long long int int_fast64_t; +/* LONGLONG */ +typedef unsigned long long int uint_fast64_t; +#endif + +/* 7.18.1.5 Greatest-width integer types */ + +#ifdef __COMPILER_INT64__ +typedef __COMPILER_INT64__ intmax_t; +typedef unsigned __COMPILER_INT64__ uintmax_t; +#else +/* LONGLONG */ +typedef long long int intmax_t; +/* LONGLONG */ +typedef unsigned long long int uintmax_t; +#endif + +#endif /* !_I386_INT_MWGWTYPES_H_ */ diff --git a/nbsd_include/arch/i386/include/int_types.h b/nbsd_include/arch/i386/include/int_types.h new file mode 100644 index 000000000..db4114176 --- /dev/null +++ b/nbsd_include/arch/i386/include/int_types.h @@ -0,0 +1,68 @@ +/* $NetBSD: int_types.h,v 1.10 2005/12/24 20:07:10 perry Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)types.h 7.5 (Berkeley) 3/9/91 + */ + +#ifndef _I386_INT_TYPES_H_ +#define _I386_INT_TYPES_H_ + +#include + +/* + * 7.18.1 Integer types + */ + +/* 7.18.1.1 Exact-width integer types */ + +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef short int __int16_t; +typedef unsigned short int __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; +#ifdef __COMPILER_INT64__ +typedef __COMPILER_INT64__ __int64_t; +typedef __COMPILER_UINT64__ __uint64_t; +#else +/* LONGLONG */ +typedef long long int __int64_t; +/* LONGLONG */ +typedef unsigned long long int __uint64_t; +#endif + +#define __BIT_TYPES_DEFINED__ + +/* 7.18.1.4 Integer types capable of holding object pointers */ + +typedef int __intptr_t; +typedef unsigned int __uintptr_t; + +#endif /* !_I386_INT_TYPES_H_ */ diff --git a/nbsd_include/arch/i386/include/limits.h b/nbsd_include/arch/i386/include/limits.h new file mode 100644 index 000000000..2e78d7bae --- /dev/null +++ b/nbsd_include/arch/i386/include/limits.h @@ -0,0 +1,94 @@ +/* $NetBSD: limits.h,v 1.22 2010/06/07 13:52:30 tnozaki Exp $ */ + +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)limits.h 7.2 (Berkeley) 6/28/90 + */ + +#ifndef _I386_LIMITS_H_ +#define _I386_LIMITS_H_ + +#include + +#define CHAR_BIT 8 /* number of bits in a char */ + +#define SCHAR_MAX 0x7f /* max value for a signed char */ +#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */ + +#define UCHAR_MAX 0xff /* max value for an unsigned char */ +#define CHAR_MAX 0x7f /* max value for a char */ +#define CHAR_MIN (-0x7f-1) /* min value for a char */ + +#define USHRT_MAX 0xffff /* max value for an unsigned short */ +#define SHRT_MAX 0x7fff /* max value for a short */ +#define SHRT_MIN (-0x7fff-1) /* min value for a short */ + +#define UINT_MAX 0xffffffffU /* max value for an unsigned int */ +#define INT_MAX 0x7fffffff /* max value for an int */ +#define INT_MIN (-0x7fffffff-1) /* min value for an int */ + +#define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ +#define LONG_MAX 0x7fffffffL /* max value for a long */ +#define LONG_MIN (-0x7fffffffL-1) /* min value for a long */ + +#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_NETBSD_SOURCE) +#define SSIZE_MAX INT_MAX /* max value for a ssize_t */ + +#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ + defined(_NETBSD_SOURCE) +#define ULLONG_MAX 0xffffffffffffffffULL /* max unsigned long long */ +#define LLONG_MAX 0x7fffffffffffffffLL /* max signed long long */ +#define LLONG_MIN (-0x7fffffffffffffffLL-1) /* min signed long long */ +#endif + +#if defined(_NETBSD_SOURCE) +#define SIZE_T_MAX UINT_MAX /* max value for a size_t */ + +#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */ +#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */ +#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */ + +#endif /* _NETBSD_SOURCE */ +#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */ + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#define LONG_BIT 32 +#define WORD_BIT 32 + +#define DBL_DIG 15 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MIN 2.2250738585072014E-308 + +#define FLT_DIG 6 +#define FLT_MAX 3.40282347E+38F +#define FLT_MIN 1.17549435E-38F +#endif + +#endif /* _I386_LIMITS_H_ */ diff --git a/nbsd_include/arch/i386/include/math.h b/nbsd_include/arch/i386/include/math.h new file mode 100644 index 000000000..19a0d9be1 --- /dev/null +++ b/nbsd_include/arch/i386/include/math.h @@ -0,0 +1,3 @@ +/* $NetBSD: math.h,v 1.5 2003/10/22 11:54:23 kleink Exp $ */ + +#include diff --git a/nbsd_include/arch/i386/include/mcontext.h b/nbsd_include/arch/i386/include/mcontext.h new file mode 100644 index 000000000..3f8ab0064 --- /dev/null +++ b/nbsd_include/arch/i386/include/mcontext.h @@ -0,0 +1,22 @@ +#ifndef _MACHINE_MCONTEXT_H +#define _MACHINE_MCONTEXT_H 1 + +#include +#include + +#define MCF_MAGIC 0xc0ffee + +/* Context to describe processor state */ +typedef struct __mcontext { + int mc_magic; + struct stackframe_s mc_p_reg; + union fpu_state_u mc_fpu_state; + short mc_fpu_flags; +} mcontext_t; + +__BEGIN_DECLS +int setmcontext(const mcontext_t *mcp); +int getmcontext(mcontext_t *mcp); +__END_DECLS + +#endif /* _MACHINE_MCONTEXT_H */ diff --git a/nbsd_include/arch/i386/include/npx.h b/nbsd_include/arch/i386/include/npx.h new file mode 100644 index 000000000..08b9c43cc --- /dev/null +++ b/nbsd_include/arch/i386/include/npx.h @@ -0,0 +1,199 @@ +/* $NetBSD: npx.h,v 1.25 2010/07/31 21:47:54 joerg Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)npx.h 5.3 (Berkeley) 1/18/91 + */ + +/* + * 287/387 NPX Coprocessor Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _I386_NPX_H_ +#define _I386_NPX_H_ + +#ifndef __minix +/* Environment information of floating point unit */ +struct env87 { + long en_cw; /* control word (16bits) */ + long en_sw; /* status word (16bits) */ + long en_tw; /* tag word (16bits) */ + long en_fip; /* floating point instruction pointer */ + uint16_t en_fcs; /* floating code segment selector */ + uint16_t en_opcode; /* opcode last executed (11 bits ) */ + long en_foo; /* floating operand offset */ + long en_fos; /* floating operand segment selector */ +}; + +/* Contents of each floating point accumulator */ +struct fpacc87 { +#ifdef dontdef /* too unportable */ + uint32_t fp_mantlo; /* mantissa low (31:0) */ + uint32_t fp_manthi; /* mantissa high (63:32) */ + int fp_exp:15; /* exponent */ + int fp_sgn:1; /* mantissa sign */ +#else + uint8_t fp_bytes[10]; +#endif +}; + +/* Floating point context */ +struct save87 { + struct env87 sv_env; /* floating point control/status */ + struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ +#ifndef dontdef + uint32_t sv_ex_sw; /* status word for last exception (was pad) */ + uint32_t sv_ex_tw; /* tag word for last exception (was pad) */ + uint8_t sv_pad[8 * 2 - 2 * 4]; /* bogus historical padding */ +#endif +}; + +/* Environment of FPU/MMX/SSE/SSE2. */ +struct envxmm { +/*0*/ uint16_t en_cw; /* FPU Control Word */ + uint16_t en_sw; /* FPU Status Word */ + uint8_t en_tw; /* FPU Tag Word (abridged) */ + uint8_t en_rsvd0; + uint16_t en_opcode; /* FPU Opcode */ + uint32_t en_fip; /* FPU Instruction Pointer */ + uint16_t en_fcs; /* FPU IP selector */ + uint16_t en_rsvd1; +/*16*/ uint32_t en_foo; /* FPU Data pointer */ + uint16_t en_fos; /* FPU Data pointer selector */ + uint16_t en_rsvd2; + uint32_t en_mxcsr; /* MXCSR Register State */ + uint32_t en_rsvd3; +}; + +/* FPU regsters in the extended save format. */ +struct fpaccxmm { + uint8_t fp_bytes[10]; + uint8_t fp_rsvd[6]; +}; + +/* SSE/SSE2 registers. */ +struct xmmreg { + uint8_t sse_bytes[16]; +}; + +/* FPU/MMX/SSE/SSE2 context */ +struct savexmm { + struct envxmm sv_env; /* control/status context */ + struct fpaccxmm sv_ac[8]; /* ST/MM regs */ + struct xmmreg sv_xmmregs[8]; /* XMM regs */ + uint8_t sv_rsvd[16 * 14]; + /* 512-bytes --- end of hardware portion of save area */ + uint32_t sv_ex_sw; /* saved SW from last exception */ + uint32_t sv_ex_tw; /* saved TW from last exception */ +} __aligned(16); + +union savefpu { + struct save87 sv_87; + struct savexmm sv_xmm; +}; +#endif /* !__minix */ + +/* + * The i387 defaults to Intel extended precision mode and round to nearest, + * with all exceptions masked. + */ +#define __INITIAL_NPXCW__ 0x037f +/* NetBSD uses IEEE double precision. */ +#define __NetBSD_NPXCW__ 0x127f +/* FreeBSD leaves some exceptions unmasked as well. */ +#define __FreeBSD_NPXCW__ 0x1272 +/* iBCS2 goes a bit further and leaves the underflow exception unmasked. */ +#define __iBCS2_NPXCW__ 0x0262 +/* Linux just uses the default control word. */ +#define __Linux_NPXCW__ 0x037f +/* SVR4 uses the same control word as iBCS2. */ +#define __SVR4_NPXCW__ 0x0262 + +/* + * The default MXCSR value at reset is 0x1f80, IA-32 Instruction + * Set Reference, pg. 3-369. + */ +#define __INITIAL_MXCSR__ 0x1f80 + + +/* + * 80387 control word bits + */ +#define EN_SW_INVOP 0x0001 /* Invalid operation */ +#define EN_SW_DENORM 0x0002 /* Denormalized operand */ +#define EN_SW_ZERODIV 0x0004 /* Divide by zero */ +#define EN_SW_OVERFLOW 0x0008 /* Overflow */ +#define EN_SW_UNDERFLOW 0x0010 /* Underflow */ +#define EN_SW_PRECLOSS 0x0020 /* Loss of precision */ +#define EN_SW_DATACHAIN 0x0080 /* Data chain exception */ +#define EN_SW_CTL_PREC 0x0300 /* Precision control */ +#define EN_SW_CTL_ROUND 0x0c00 /* Rounding control */ +#define EN_SW_CTL_INF 0x1000 /* Infinity control */ + +/* + * The standard control word from finit is 0x37F, giving: + * round to nearest + * 64-bit precision + * all exceptions masked. + * + * Now we want: + * affine mode (if we decide to support 287's) + * round to nearest + * 53-bit precision + * all exceptions masked. + * + * 64-bit precision often gives bad results with high level languages + * because it makes the results of calculations depend on whether + * intermediate values are stored in memory or in FPU registers. + * + * The iBCS control word has underflow, overflow, zero divide, and invalid + * operation exceptions unmasked. But that causes an unexpected exception + * in the test program 'paranoia' and makes denormals useless (DBL_MIN / 2 + * underflows). It doesn't make a lot of sense to trap underflow without + * trapping denormals. + */ + +#ifdef _KERNEL + +void probeintr(void); +void probetrap(void); +int npx586bug1(int, int); +void npxinit(struct cpu_info *); +void process_xmm_to_s87(const struct savexmm *, struct save87 *); +void process_s87_to_xmm(const struct save87 *, struct savexmm *); +struct lwp; +int npxtrap(struct lwp *); + +#endif + +#endif /* !_I386_NPX_H_ */ diff --git a/nbsd_include/arch/i386/include/param.h b/nbsd_include/arch/i386/include/param.h new file mode 100644 index 000000000..3d0f98644 --- /dev/null +++ b/nbsd_include/arch/i386/include/param.h @@ -0,0 +1,90 @@ +/* $NetBSD: param.h,v 1.72 2010/02/08 19:02:29 joerg Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)param.h 5.8 (Berkeley) 6/28/91 + */ + +#ifndef _I386_PARAM_H_ +#define _I386_PARAM_H_ + +/* + * Machine dependent constants for Intel 386. + */ + +#ifdef _KERNEL +#include +#endif + +#ifndef _MINIX +#define _MACHINE i386 +#define MACHINE "i386" +#define _MACHINE_ARCH i386 +#define MACHINE_ARCH "i386" +#define MID_MACHINE MID_I386 +#endif + +/* + * Round p (pointer or byte index) up to a correctly-aligned value + * for all data types (int, long, ...). The result is u_int and + * must be cast to any desired pointer type. + * + * ALIGNED_POINTER is a boolean macro that checks whether an address + * is valid to fetch data elements of type t from on this architecture. + * This does not reflect the optimal alignment, just the possibility + * (within reasonable limits). + * + */ +#define ALIGNBYTES (sizeof(int) - 1) +#define ALIGN(p) (((u_int)(u_long)(p) + ALIGNBYTES) &~ \ + ALIGNBYTES) +#define ALIGNED_POINTER(p,t) 1 + +#define PGSHIFT 12 /* LOG2(NBPG) */ +#define NBPG (1 << PGSHIFT) /* bytes/page */ +#define PGOFSET (NBPG-1) /* byte offset into page */ +#define NPTEPG (NBPG/(sizeof (pt_entry_t))) + +/* + * Mach derived conversion macros + */ +#define x86_round_pdr(x) \ + ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1)) +#define x86_trunc_pdr(x) ((unsigned long)(x) & ~(NBPD_L2 - 1)) +#define x86_btod(x) ((unsigned long)(x) >> L2_SHIFT) +#define x86_dtob(x) ((unsigned long)(x) << L2_SHIFT) +#define x86_round_page(x) ((((paddr_t)(x)) + PGOFSET) & ~PGOFSET) +#define x86_trunc_page(x) ((paddr_t)(x) & ~PGOFSET) +#define x86_btop(x) ((paddr_t)(x) >> PGSHIFT) +#define x86_ptob(x) ((paddr_t)(x) << PGSHIFT) + +#endif /* _I386_PARAM_H_ */ diff --git a/nbsd_include/arch/i386/include/profile.h b/nbsd_include/arch/i386/include/profile.h new file mode 100644 index 000000000..d49e95abc --- /dev/null +++ b/nbsd_include/arch/i386/include/profile.h @@ -0,0 +1,137 @@ +/* $NetBSD: profile.h,v 1.33 2007/12/20 23:46:13 ad Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#ifdef _KERNEL_OPT +#include "opt_multiprocessor.h" +#endif + +#ifdef _KERNEL +#include +#include +#endif + +#define _MCOUNT_DECL static __inline void _mcount + +#ifdef __ELF__ +#define MCOUNT_ENTRY "__mcount" +#define MCOUNT_COMPAT __weak_alias(mcount, __mcount) +#else +#define MCOUNT_ENTRY "mcount" +#define MCOUNT_COMPAT /* nothing */ +#endif + +#define MCOUNT \ +MCOUNT_COMPAT \ +extern void mcount(void) __asm(MCOUNT_ENTRY) \ + __attribute__((__no_instrument_function__)); \ +void \ +mcount(void) \ +{ \ + int selfpc, frompcindex; \ + int eax, ecx, edx; \ + \ + __asm volatile("movl %%eax,%0" : "=g" (eax)); \ + __asm volatile("movl %%ecx,%0" : "=g" (ecx)); \ + __asm volatile("movl %%edx,%0" : "=g" (edx)); \ + /* \ + * find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * selfpc = pc pushed by mcount call \ + */ \ + __asm volatile("movl 4(%%ebp),%0" : "=r" (selfpc)); \ + /* \ + * frompcindex = pc pushed by call into self. \ + */ \ + __asm volatile("movl (%%ebp),%0;movl 4(%0),%0" \ + : "=r" (frompcindex)); \ + _mcount((u_long)frompcindex, (u_long)selfpc); \ + \ + __asm volatile("movl %0,%%edx" : : "g" (edx)); \ + __asm volatile("movl %0,%%ecx" : : "g" (ecx)); \ + __asm volatile("movl %0,%%eax" : : "g" (eax)); \ +} + +#ifdef _KERNEL +#ifdef MULTIPROCESSOR +__cpu_simple_lock_t __mcount_lock; + +static inline void +MCOUNT_ENTER_MP(void) +{ + __cpu_simple_lock(&__mcount_lock); + __insn_barrier(); +} + +static inline void +MCOUNT_EXIT_MP(void) +{ + __insn_barrier(); + __mcount_lock = __SIMPLELOCK_UNLOCKED; +} +#else +#define MCOUNT_ENTER_MP() +#define MCOUNT_EXIT_MP() +#endif + +static inline void +mcount_disable_intr(void) +{ + __asm volatile("cli"); +} + +static inline u_long +mcount_read_psl(void) +{ + u_long ef; + + __asm volatile("pushfl; popl %0" : "=r" (ef)); + return (ef); +} + +static inline void +mcount_write_psl(u_long ef) +{ + __asm volatile("pushl %0; popfl" : : "r" (ef)); +} + +#define MCOUNT_ENTER \ + s = (int)mcount_read_psl(); \ + mcount_disable_intr(); \ + MCOUNT_ENTER_MP(); + +#define MCOUNT_EXIT \ + MCOUNT_EXIT_MP(); \ + mcount_write_psl(s); + +#endif /* _KERNEL */ diff --git a/nbsd_include/arch/i386/include/setjmp.h b/nbsd_include/arch/i386/include/setjmp.h new file mode 100644 index 000000000..a33f195b2 --- /dev/null +++ b/nbsd_include/arch/i386/include/setjmp.h @@ -0,0 +1,7 @@ +/* $NetBSD: setjmp.h,v 1.2 1998/09/14 21:31:52 thorpej Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 13 /* size, in longs, of a jmp_buf */ diff --git a/nbsd_include/arch/i386/include/signal.h b/nbsd_include/arch/i386/include/signal.h new file mode 100644 index 000000000..d8f696f52 --- /dev/null +++ b/nbsd_include/arch/i386/include/signal.h @@ -0,0 +1,64 @@ +#ifndef _I386_SIGNAL_H_ +#define _I386_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +/* The following structure should match the stackframe_s structure used + * by the kernel's context switching code. Floating point registers should + * be added in a different struct. + */ + +#include +#include + +typedef struct stackframe_s sigregs; +struct sigframe { /* stack frame created for signalled process */ + void (*sf_retadr)(void); + int sf_signo; + int sf_code; + struct sigcontext *sf_scp; + int sf_fp; + void (*sf_retadr2)(void); + struct sigcontext *sf_scpcopy; +}; + +struct sigcontext { + int sc_flags; /* sigstack state to restore (including + * MF_FPU_INITIALIZED) + */ + long sc_mask; /* signal mask to restore */ + sigregs sc_regs; /* register set to restore */ + union fpu_state_u sc_fpu_state; +}; + +#if _WORD_SIZE == 4 +#define sc_gs sc_regs.gs +#define sc_fs sc_regs.fs +#endif /* _WORD_SIZE == 4 */ +#define sc_es sc_regs.es +#define sc_ds sc_regs.ds +#define sc_di sc_regs.di +#define sc_si sc_regs.si +#define sc_fp sc_regs.bp +#define sc_st sc_regs.st /* stack top -- used in kernel */ +#define sc_bx sc_regs.bx +#define sc_dx sc_regs.dx +#define sc_cx sc_regs.cx +#define sc_retreg sc_regs.retreg +#define sc_retadr sc_regs.retadr /* return address to caller of + save -- used in kernel */ +#define sc_pc sc_regs.pc +#define sc_cs sc_regs.cs +#define sc_psw sc_regs.psw +#define sc_sp sc_regs.sp +#define sc_ss sc_regs.ss + +#ifdef _MINIX +__BEGIN_DECLS +int sigreturn(struct sigcontext *_scp); +__END_DECLS +#endif /* _MINIX */ + +#endif /* !_I386_SIGNAL_H_ */ diff --git a/nbsd_include/arch/i386/include/stdarg.h b/nbsd_include/arch/i386/include/stdarg.h new file mode 100644 index 000000000..38d0f81f2 --- /dev/null +++ b/nbsd_include/arch/i386/include/stdarg.h @@ -0,0 +1,86 @@ +/* $NetBSD: stdarg.h,v 1.23 2009/08/18 17:40:39 drochner Exp $ */ + +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _I386_STDARG_H_ +#define _I386_STDARG_H_ + +#include +#include + +typedef _BSD_VA_LIST_ va_list; + +#ifdef __lint__ +#define __builtin_next_arg(t) ((t) ? 0 : 0) +#define __builtin_stdarg_start(a, l) ((a) = ((l) ? 0 : 0)) +#define __builtin_va_arg(a, t) ((a) ? 0 : 0) +#define __builtin_va_end /* nothing */ +#define __builtin_va_copy(d, s) ((d) = (s)) +#endif + +#if __GNUC_PREREQ__(4, 1) +#define va_start(ap, last) __builtin_va_start((ap), (last)) +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) +#elif __GNUC_PREREQ__(2, 96) +#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) +#elif defined(__PCC__) +#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) +#else +#define __va_size(type) \ + (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long)) + +#define va_start(ap, last) \ + ((ap) = (va_list)__builtin_next_arg(last)) + +#define va_arg(ap, type) \ + (*(type *)(void *)((ap) += __va_size(type), (ap) - __va_size(type))) + +#define va_end(ap) + +#define __va_copy(dest, src) ((dest) = (src)) +#endif + +#if !defined(_ANSI_SOURCE) && \ + (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ + defined(_NETBSD_SOURCE)) +#define va_copy(dest, src) __va_copy((dest), (src)) +#endif + +#endif /* !_I386_STDARG_H_ */ diff --git a/nbsd_include/arch/i386/include/types.h b/nbsd_include/arch/i386/include/types.h new file mode 100644 index 000000000..e33bb2c21 --- /dev/null +++ b/nbsd_include/arch/i386/include/types.h @@ -0,0 +1,120 @@ +/* $NetBSD: types.h,v 1.70 2010/12/22 04:15:02 christos Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 7.5 (Berkeley) 3/9/91 + */ + +#ifndef _I386_MACHTYPES_H_ +#define _I386_MACHTYPES_H_ + +#ifdef _KERNEL_OPT +#include "opt_xen.h" +#endif +#include +#include +#include + +#if defined(_KERNEL) +typedef struct label_t { + int val[6]; +} label_t; +#endif + +#if defined(_NETBSD_SOURCE) +#if defined(_KERNEL) + +/* + * XXX JYM for now, in kernel paddr_t can be 32 or 64 bits, depending + * on PAE. Revisit when paddr_t becomes 64 bits for !PAE systems. + */ +#ifdef PAE +typedef __uint64_t paddr_t; +typedef __uint64_t psize_t; +#define PRIxPADDR "llx" +#define PRIxPSIZE "llx" +#define PRIuPSIZE "llu" +#else /* PAE */ +typedef unsigned long paddr_t; +typedef unsigned long psize_t; +#define PRIxPADDR "lx" +#define PRIxPSIZE "lx" +#define PRIuPSIZE "lu" +#endif /* PAE */ + +#else /* _KERNEL */ +/* paddr_t is always 64 bits for userland */ +typedef __uint64_t paddr_t; +typedef __uint64_t psize_t; +#define PRIxPADDR "llx" +#define PRIxPSIZE "llx" +#define PRIuPSIZE "llu" + +#endif /* _KERNEL */ + +typedef unsigned long vaddr_t; +typedef unsigned long vsize_t; +#define PRIxVADDR "lx" +#define PRIxVSIZE "lx" +#define PRIuVSIZE "lu" +#endif /* _NETBSD_SOURCE */ + +typedef int pmc_evid_t; +typedef __uint64_t pmc_ctr_t; +typedef int register_t; +#define PRIxREGISTER "x" + +typedef volatile unsigned char __cpu_simple_lock_t; + +/* __cpu_simple_lock_t used to be a full word. */ +#define __CPU_SIMPLE_LOCK_PAD + +#define __SIMPLELOCK_LOCKED 1 +#define __SIMPLELOCK_UNLOCKED 0 + +/* The x86 does not have strict alignment requirements. */ +#define __NO_STRICT_ALIGNMENT + +#define __HAVE_DEVICE_REGISTER +#define __HAVE_CPU_DATA_FIRST +#define __HAVE_CPU_COUNTER +#define __HAVE_MD_CPU_OFFLINE +#define __HAVE_SYSCALL_INTERN +#define __HAVE_MINIMAL_EMUL +#define __HAVE_OLD_DISKLABEL +#define __HAVE_ATOMIC64_OPS +#define __HAVE_ATOMIC_AS_MEMBAR +#define __HAVE_CPU_LWP_SETPRIVATE +#define __HAVE_INTR_CONTROL + +#if defined(_KERNEL) +#define __HAVE_RAS +#endif + +#endif /* _I386_MACHTYPES_H_ */ diff --git a/nbsd_include/arch/i386/include/vmparam.h b/nbsd_include/arch/i386/include/vmparam.h new file mode 100644 index 000000000..63aef5c2c --- /dev/null +++ b/nbsd_include/arch/i386/include/vmparam.h @@ -0,0 +1,52 @@ +/* $NetBSD: vmparam.h,v 1.72 2010/11/14 13:33:21 uebayasi Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _I386_VMPARAM_H_ +#define _I386_VMPARAM_H_ + +/* + * Machine dependent constants for 386. + */ + +/* + * Page size on the IA-32 is not variable in the traditional sense. + * We override the PAGE_* definitions to compile-time constants. + */ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#endif /* _I386_VMPARAM_H_ */ diff --git a/nbsd_include/arch/i386/include/wchar_limits.h b/nbsd_include/arch/i386/include/wchar_limits.h new file mode 100644 index 000000000..e3bf3b709 --- /dev/null +++ b/nbsd_include/arch/i386/include/wchar_limits.h @@ -0,0 +1,47 @@ +/* $NetBSD: wchar_limits.h,v 1.2 2008/04/28 20:23:24 martin Exp $ */ + +/*- + * Copyright (c) 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_WCHAR_LIMITS_H_ +#define _I386_WCHAR_LIMITS_H_ + +/* + * 7.18.3 Limits of other integer types + */ + +/* limits of wchar_t */ +#define WCHAR_MIN (-0x7fffffff-1) /* wchar_t */ +#define WCHAR_MAX 0x7fffffff /* wchar_t */ + +/* limits of wint_t */ +#define WINT_MIN (-0x7fffffff-1) /* wint_t */ +#define WINT_MAX 0x7fffffff /* wint_t */ + +#endif /* !_I386_WCHAR_LIMITS_H_ */ diff --git a/nbsd_include/arch/x86/include/Makefile b/nbsd_include/arch/x86/include/Makefile new file mode 100644 index 000000000..86b9686a3 --- /dev/null +++ b/nbsd_include/arch/x86/include/Makefile @@ -0,0 +1,10 @@ +# $NetBSD: Makefile,v 1.13 2008/05/11 15:32:20 ad Exp $ + +INCSDIR=/usr/netbsd/include/x86 + +INCS= float.h \ + ieee.h \ + ieeefp.h \ + math.h + +.include diff --git a/nbsd_include/arch/x86/include/float.h b/nbsd_include/arch/x86/include/float.h new file mode 100644 index 000000000..5f5d8afb2 --- /dev/null +++ b/nbsd_include/arch/x86/include/float.h @@ -0,0 +1,27 @@ +/* $NetBSD: float.h,v 1.5 2003/10/23 23:26:06 kleink Exp $ */ + +#ifndef _X86_FLOAT_H_ +#define _X86_FLOAT_H_ + +#define LDBL_MANT_DIG 64 +#define LDBL_EPSILON 1.0842021724855044340E-19L +#define LDBL_DIG 18 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.3621031431120935063E-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.1897314953572317650E+4932L +#define LDBL_MAX_10_EXP 4932 + +#include + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ + !defined(_XOPEN_SOURCE) || \ + ((__STDC_VERSION__ - 0) >= 199901L) || \ + ((_POSIX_C_SOURCE - 0) >= 200112L) || \ + ((_XOPEN_SOURCE - 0) >= 600) || \ + defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) +#define DECIMAL_DIG 21 +#endif /* !defined(_ANSI_SOURCE) && ... */ + +#endif /* _X86_FLOAT_H_ */ diff --git a/nbsd_include/arch/x86/include/ieee.h b/nbsd_include/arch/x86/include/ieee.h new file mode 100644 index 000000000..1ee6838c0 --- /dev/null +++ b/nbsd_include/arch/x86/include/ieee.h @@ -0,0 +1,117 @@ +/* $NetBSD: ieee.h,v 1.11 2010/09/15 16:11:28 christos Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +#include + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS) + +#define EXT_TO_ARRAY32(u, a) do { \ + (a)[0] = (uint32_t)(u).extu_ext.ext_fracl; \ + (a)[1] = (uint32_t)(u).extu_ext.ext_frach; \ +} while(/*CONSTCOND*/0) + +/* + * struct ieee_ext is the raw storage layout of the 80-bit + * extended-precision type as implemented by the FPU. Per the + * respective ABI specifications, it is followed by a tail padding of + * + * amd64: 48 bits, + * i386: 16 bits. + */ +struct ieee_ext { + u_int ext_fracl:EXT_FRACLBITS; + u_int ext_frach:EXT_FRACHBITS; +#if 0 + u_int ext_int:1; +#endif + u_int ext_exp:EXT_EXPBITS; + u_int ext_sign:1; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define EXT_EXP_INFNAN 0x7fff +#define EXT_EXP_INF 0x7fff +#define EXT_EXP_NAN 0x7fff + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 30) +#endif + +/* + * Exponent biases. + */ +#define EXT_EXP_BIAS 16383 + +/* + * Convenience data structures. + */ +union ieee_ext_u { + long double extu_ld; + struct ieee_ext extu_ext; +}; + +#define extu_exp extu_ext.ext_exp +#define extu_sign extu_ext.ext_sign +#define extu_fracl extu_ext.ext_fracl +#define extu_frach extu_ext.ext_frach + +#define LDBL_NBIT 0x80000000 +#define mask_nbit_l(u) ((u).extu_frach &= ~LDBL_NBIT) diff --git a/nbsd_include/arch/x86/include/ieeefp.h b/nbsd_include/arch/x86/include/ieeefp.h new file mode 100644 index 000000000..348544dd7 --- /dev/null +++ b/nbsd_include/arch/x86/include/ieeefp.h @@ -0,0 +1,29 @@ +/* $NetBSD: ieeefp.h,v 1.3 2010/07/31 21:47:54 joerg Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _X86_IEEEFP_H_ +#define _X86_IEEEFP_H_ + +#include +#include + +typedef int fp_except; +#define FP_X_INV FE_INVALID /* invalid operation exception */ +#define FP_X_DNML FE_DENORMAL /* denormalization exception */ +#define FP_X_DZ FE_DIVBYZERO /* divide-by-zero exception */ +#define FP_X_OFL FE_OVERFLOW /* overflow exception */ +#define FP_X_UFL FE_UNDERFLOW /* underflow exception */ +#define FP_X_IMP FE_INEXACT /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=FE_TONEAREST, /* round to nearest representable number */ + FP_RM=FE_DOWNWARD, /* round toward negative infinity */ + FP_RP=FE_UPWARD, /* round toward positive infinity */ + FP_RZ=FE_TOWARDZERO /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _X86_IEEEFP_H_ */ diff --git a/nbsd_include/arch/x86/include/math.h b/nbsd_include/arch/x86/include/math.h new file mode 100644 index 000000000..6d26ccc53 --- /dev/null +++ b/nbsd_include/arch/x86/include/math.h @@ -0,0 +1,4 @@ +/* $NetBSD: math.h,v 1.2 2003/10/28 00:55:28 kleink Exp $ */ + +#define __HAVE_LONG_DOUBLE +#define __HAVE_NANF diff --git a/nbsd_include/minix/Makefile b/nbsd_include/minix/Makefile new file mode 100644 index 000000000..10a5c5faa --- /dev/null +++ b/nbsd_include/minix/Makefile @@ -0,0 +1,12 @@ +NOOBJ= # defined + +.include + +INCSDIR= /usr/netbsd/include/minix + +INCS+= paths.h types.h + +.include "${MINIXSRCDIR}/common/include/sys/Makefile.mount.inc" +.include "${MINIXSRCDIR}/common/include/Makefile.termios.inc" + +.include diff --git a/nbsd_include/minix/paths.h b/nbsd_include/minix/paths.h new file mode 100644 index 000000000..f359103a6 --- /dev/null +++ b/nbsd_include/minix/paths.h @@ -0,0 +1,7 @@ +#ifndef _MINIX_PATHS_H_ +#define _MINIX_PATHS_H_ + +#define _PATH_SERVICE "/bin/service" +#define _PATH_PROC "/proc/" + +#endif /* _MINIX_PATHS_H_ */ diff --git a/nbsd_include/minix/types.h b/nbsd_include/minix/types.h new file mode 100644 index 000000000..b7e2c43c2 --- /dev/null +++ b/nbsd_include/minix/types.h @@ -0,0 +1,8 @@ +#ifndef _MINIX_TYPES_H_ +#define _MINIX_TYPES_H_ + +/* Dummy file used in legacy (and shared) minix includes. */ +#include +#include + +#endif diff --git a/nbsd_include/net/Makefile b/nbsd_include/net/Makefile new file mode 100644 index 000000000..1a5a4e9b0 --- /dev/null +++ b/nbsd_include/net/Makefile @@ -0,0 +1,5 @@ +INCSDIR= /usr/netbsd/include/net + +INCS+= hton.h ethertypes.h if.h if_ether.h netlib.h + +.include diff --git a/nbsd_include/net/ethertypes.h b/nbsd_include/net/ethertypes.h new file mode 100644 index 000000000..1cfd2cd7e --- /dev/null +++ b/nbsd_include/net/ethertypes.h @@ -0,0 +1,313 @@ +/* $NetBSD: ethertypes.h,v 1.17 2005/12/10 23:21:38 elad Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Ethernet protocol types. + * + * According to "assigned numbers", the Ethernet protocol numbers are also + * used as ARP protocol type numbers. + * + * I factor them out here to avoid pulling all the Ethernet header file + * into the hardware independent ARP code. -is + * + * Additional sources of information: + * http://www.mit.edu/~map/Ethernet/Ethernet.txt + * ftp://venera.isi.edu/in-notes/iana/assignments/ethernet-numbers + * + */ + +#ifndef _NET_ETHERTYPES_H_ +#define _NET_ETHERTYPES_H_ + +/* + * NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields. + * However, there are some conflicts. + */ + +#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */ + /* 0x0101 .. 0x1FF Experimental */ +#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */ +#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */ +#define ETHERTYPE_SPRITE 0x0500 /* ??? */ + /* 0x0400 Nixdorf */ +#define ETHERTYPE_NS 0x0600 /* XNS */ +#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */ +#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */ +#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */ +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#define ETHERTYPE_X75 0x0801 /* X.75 Internet */ +#define ETHERTYPE_NBS 0x0802 /* NBS Internet */ +#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */ +#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */ +#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */ +#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */ +#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */ +#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */ + /* 0x081C Symbolics Private */ + /* 0x0888 - 0x088A Xyplex */ +#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */ +#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */ +#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */ +#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */ +#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */ +#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */ + +/* 0x1000 - 0x100F Berkeley Trailer */ +/* + * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have + * (type-ETHERTYPE_TRAIL)*512 bytes of data followed + * by an ETHER type (as given above) and then the (variable-length) header. + */ +#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ +#define ETHERTYPE_NTRAILER 16 + +#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */ +#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */ +#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */ +#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */ + + /* The following 3C0x types + are unregistered: */ +#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */ +#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */ +#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */ +#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect repsonse not registered */ +#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */ +#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */ +#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */ +#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */ +#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */ +#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */ +#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete Netbios name not registered */ +#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */ +#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */ +#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */ + +#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */ +#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */ +#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */ +#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */ +#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */ +#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */ +#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */ +#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */ +#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */ +#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */ +#define ETHERTYPE_LAT 0x6004 /* DEC LAT */ +#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */ +#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */ +#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */ +#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */ +#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */ + /* 0x6010 - 0x6014 3Com Corporation */ +#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/ +#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */ +#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */ +#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */ +#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */ +#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */ +#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */ +#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */ +#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */ + /* 0x7020 - 0x7029 LRT (England) (now Sintrom) */ +#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */ +#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */ +#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */ +#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */ +#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */ +#define ETHERTYPE_HP 0x8005 /* HP Probe */ +#define ETHERTYPE_NESTAR 0x8006 /* Nestar */ +#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */ +#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */ +#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */ +#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */ +#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */ +#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */ +#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */ +#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */ +#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */ +#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */ +#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */ +#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */ +#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */ +#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */ +#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */ +#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */ +#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */ +#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */ +#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */ +#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */ +#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */ +#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */ + /* 0x8042 DEC Unassigned */ +#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */ + /* 0x8046 - 0x8047 AT&T */ +#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */ +#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */ +#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */ +#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */ +#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */ +#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */ +#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */ + /* 0x8065 - 0x8066 Univ. of Mass @ Amherst */ +#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */ +#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */ +#define ETHERTYPE_ATT 0x8069 /* AT&T */ +#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */ +#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */ +#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */ + /* 0x806E - 0x8077 Landmark Graphics Corp. */ +#define ETHERTYPE_MATRA 0x807A /* Matra */ +#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */ +#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */ + /* 0x807D - 0x807F Vitalink Communications */ +#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */ + /* 0x8081 - 0x8083 Counterpoint Computers */ + /* 0x8088 - 0x808A Xyplex */ +#define ETHERTYPE_ATALK 0x809B /* AppleTalk */ +#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */ +#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */ + /* 0x809C - 0x809E Datability */ +#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */ + /* 0x80A3 Nixdorf */ + /* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */ + /* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */ + /* 0x80C4 - 0x80C5 Banyan Systems */ +#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */ +#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */ + /* 0x80C8 - 0x80CC Intergraph Corporation */ + /* 0x80CD - 0x80CE Harris Corporation */ + /* 0x80CF - 0x80D2 Taylor Instrument */ + /* 0x80D3 - 0x80D4 Rosemount Corporation */ +#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */ +#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */ + /* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */ + /* 0x80E0 - 0x80E3 Allen-Bradley */ + /* 0x80E4 - 0x80F0 Datability */ +#define ETHERTYPE_RETIX 0x80F2 /* Retix */ +#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */ + /* 0x80F4 - 0x80F5 Kinetics */ +#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */ +#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */ + /* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */ +#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */ +#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */ + /* 0x8107 - 0x8109 Symbolics Private */ +#define ETHERTYPE_TALARIS 0x812B /* Talaris */ +#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */ +#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */ +#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */ + /* 0x8132 - 0x8137 Bridge Communications */ +#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */ +#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */ + /* 0x8139 - 0x813D KTI */ +#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */ +#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */ +#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */ +#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */ +#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */ +#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */ +#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */ +#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */ + /* 0x814D - 0x814E BIIN */ +#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */ +#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */ + /* 0x8151 - 0x8153 Qualcomm */ + /* 0x815C - 0x815E Computer Protocol Pty Ltd */ + /* 0x8164 - 0x8166 Charles River Data Systems */ +#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */ +#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */ +#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */ +#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */ + /* 0x8182 - 0x8183 Reserved for HIPPI-6400 */ + /* 0x8184 - 0x818C SGI prop. */ +#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */ +#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */ + /* 0x819A - 0x81A3 RAD Network Devices */ + /* 0x81B7 - 0x81B9 Xyplex */ + /* 0x81CC - 0x81D5 Apricot Computers */ + /* 0x81D6 - 0x81DD Artisoft Lantastic */ + /* 0x81E6 - 0x81EF Polygon */ + /* 0x81F0 - 0x81F2 Comsat Labs */ + /* 0x81F3 - 0x81F5 SAIC */ + /* 0x81F6 - 0x81F8 VG Analytical */ + /* 0x8203 - 0x8205 QNX Software Systems Ltd. */ + /* 0x8221 - 0x8222 Ascom Banking Systems */ + /* 0x823E - 0x8240 Advanced Encryption Systems */ + /* 0x8263 - 0x826A Charles River Data Systems */ + /* 0x827F - 0x8282 Athena Programming */ + /* 0x829A - 0x829B Inst Ind Info Tech */ + /* 0x829C - 0x82AB Taurus Controls */ + /* 0x82AC - 0x8693 Walker Richer & Quinn */ +#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */ +#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */ +#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */ + /* 0x8694 - 0x869D Idea Courier */ + /* 0x869E - 0x86A1 Computer Network Tech */ + /* 0x86A3 - 0x86AC Gateway Communications */ +#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */ +#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */ +#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */ +#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */ + /* 0x86E0 - 0x86EF Landis & Gyr Powers */ + /* 0x8700 - 0x8710 Motorola */ +#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */ +#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */ + /* 0x873B - 0x873C Control Technology Inc. Proprietary */ +#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */ +#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */ +#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */ +#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */ +#define ETHERTYPE_SLOWPROTOCOLS 0x8809 /* Slow protocols */ +#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPOE) */ +#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */ +#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */ +#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */ +#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */ +#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ +#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ +#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */ +#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */ +#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback */ +#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */ +#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */ +#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */ +#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */ +#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */ +#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */ +#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */ + /* 0xFF00 - 0xFFOF ISC Bunker Ramo */ + +#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */ + +#endif /* !_NET_ETHERTYPES_H_ */ diff --git a/nbsd_include/net/hton.h b/nbsd_include/net/hton.h new file mode 100644 index 000000000..bc036016e --- /dev/null +++ b/nbsd_include/net/hton.h @@ -0,0 +1,5 @@ +/* + * Dummy file for Minix old includes compatibility. + */ +#include +#include diff --git a/nbsd_include/net/if.h b/nbsd_include/net/if.h new file mode 100644 index 000000000..39446f23f --- /dev/null +++ b/nbsd_include/net/if.h @@ -0,0 +1,6 @@ +#ifndef _NET_IF_H_ +#define _NET_IF_H_ + +#define IFF_UP 0x0001 /* interface is up */ + +#endif /* _NET_IF_H_ */ diff --git a/nbsd_include/net/if_ether.h b/nbsd_include/net/if_ether.h new file mode 100644 index 000000000..3cc90642a --- /dev/null +++ b/nbsd_include/net/if_ether.h @@ -0,0 +1,109 @@ +/* $NetBSD: if_ether.h,v 1.58 2010/05/19 20:41:59 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_ETHER_H_ +#define _NET_IF_ETHER_H_ + +/* + * Some basic Ethernet constants. + */ +#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */ +#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */ +#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */ +#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN) +#define ETHER_MIN_LEN 64 /* minimum frame length, including CRC */ +#define ETHER_MAX_LEN 1518 /* maximum frame length, including CRC */ +#define ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */ + +/* + * Some Ethernet extensions. + */ +#define ETHER_VLAN_ENCAP_LEN 4 /* length of 802.1Q VLAN encapsulation */ +#define ETHER_PPPOE_ENCAP_LEN 8 /* length of PPPoE encapsulation */ + +/* + * Ethernet address - 6 octets + * this is only used by the ethers(3) functions. + */ +struct ether_addr { + uint8_t ether_addr_octet[ETHER_ADDR_LEN]; +} __packed; + +/* + * Structure of a 10Mb/s Ethernet header. + */ +struct ether_header { + uint8_t ether_dhost[ETHER_ADDR_LEN]; + uint8_t ether_shost[ETHER_ADDR_LEN]; + uint16_t ether_type; +} __packed; + +#include + +#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ +#define ETHER_IS_LOCAL(addr) (*(addr) & 0x02) /* is address local? */ + +#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN) +#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) +#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) + +/* + * Compute the maximum frame size based on ethertype (i.e. possible + * encapsulation) and whether or not an FCS is present. + */ +#define ETHER_MAX_FRAME(ifp, etype, hasfcs) \ + ((ifp)->if_mtu + ETHER_HDR_LEN + \ + ((hasfcs) ? ETHER_CRC_LEN : 0) + \ + (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0) + \ + (((etype) == ETHERTYPE_PPPOE) ? ETHER_PPPOE_ENCAP_LEN : 0)) + +/* + * Ethernet CRC32 polynomials (big- and little-endian verions). + */ +#define ETHER_CRC_POLY_LE 0xedb88320 +#define ETHER_CRC_POLY_BE 0x04c11db6 + +/* + * Prototype ethers(3) functions. + */ +#include +__BEGIN_DECLS +char * ether_ntoa(const struct ether_addr *); +struct ether_addr * + ether_aton(const char *); +int ether_ntohost(char *, const struct ether_addr *); +int ether_hostton(const char *, struct ether_addr *); +int ether_line(const char *, struct ether_addr *, char *); +__END_DECLS + +#endif /* !_NET_IF_ETHER_H_ */ diff --git a/nbsd_include/net/netlib.h b/nbsd_include/net/netlib.h new file mode 100644 index 000000000..6477cde03 --- /dev/null +++ b/nbsd_include/net/netlib.h @@ -0,0 +1,15 @@ +/* +net/netlib.h +*/ + +#ifndef _NET__NETLIB_H_ +#define _NET__NETLIB_H_ + +#define IPSTAT_DEVICE "/dev/ipstat" +#define ETH_DEVICE "/dev/eth" +#define IP_DEVICE "/dev/ip" +#define TCP_DEVICE "/dev/tcp" +#define UDP_DEVICE "/dev/udp" +#define UDS_DEVICE "/dev/uds" + +#endif /* _NET__NETLIB_H_ */ diff --git a/nbsd_include/netinet/Makefile b/nbsd_include/netinet/Makefile new file mode 100644 index 000000000..c83b50dc5 --- /dev/null +++ b/nbsd_include/netinet/Makefile @@ -0,0 +1,5 @@ +INCSDIR= /usr/netbsd/include/netinet + +INCS+= in.h tcp.h + +.include diff --git a/nbsd_include/netinet/in.h b/nbsd_include/netinet/in.h new file mode 100644 index 000000000..ba9d45c4d --- /dev/null +++ b/nbsd_include/netinet/in.h @@ -0,0 +1,512 @@ +/* $NetBSD: in.h,v 1.86 2009/09/14 10:36:50 degroote Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)in.h 8.3 (Berkeley) 1/3/94 + */ + +/* + * Constants and structures defined by the internet system, + * Per RFC 790, September 1981, and numerous additions. + */ + +#ifndef _NETINET_IN_H_ +#define _NETINET_IN_H_ + +#include + +#ifndef uint8_t +typedef __uint8_t uint8_t; +#define uint8_t __uint8_t +#endif + +#ifndef uint32_t +typedef __uint32_t uint32_t; +#define uint32_t __uint32_t +#endif + +#include + +#ifndef in_addr_t +typedef __in_addr_t in_addr_t; +#define in_addr_t __in_addr_t +#endif + +#ifndef in_port_t +typedef __in_port_t in_port_t; +#define in_port_t __in_port_t +#endif + +#ifndef sa_family_t +typedef __sa_family_t sa_family_t; +#define sa_family_t __sa_family_t +#endif + +/* + * Protocols + */ +#define IPPROTO_IP 0 /* dummy for IP */ +#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */ +#define IPPROTO_ICMP 1 /* control message protocol */ +#define IPPROTO_IGMP 2 /* group mgmt protocol */ +#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ +#define IPPROTO_IPV4 4 /* IP header */ +#define IPPROTO_IPIP 4 /* IP inside IP */ +#define IPPROTO_TCP 6 /* tcp */ +#define IPPROTO_EGP 8 /* exterior gateway protocol */ +#define IPPROTO_PUP 12 /* pup */ +#define IPPROTO_UDP 17 /* user datagram protocol */ +#define IPPROTO_IDP 22 /* xns idp */ +#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ +#define IPPROTO_IPV6 41 /* IP6 header */ +#define IPPROTO_ROUTING 43 /* IP6 routing header */ +#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */ +#define IPPROTO_RSVP 46 /* resource reservation */ +#define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */ +#define IPPROTO_ESP 50 /* encap. security payload */ +#define IPPROTO_AH 51 /* authentication header */ +#define IPPROTO_MOBILE 55 /* IP Mobility RFC 2004 */ +#define IPPROTO_IPV6_ICMP 58 /* IPv6 ICMP */ +#define IPPROTO_ICMPV6 58 /* ICMP6 */ +#define IPPROTO_NONE 59 /* IP6 no next header */ +#define IPPROTO_DSTOPTS 60 /* IP6 destination option */ +#define IPPROTO_EON 80 /* ISO cnlp */ +#define IPPROTO_ETHERIP 97 /* Ethernet-in-IP */ +#define IPPROTO_ENCAP 98 /* encapsulation header */ +#define IPPROTO_PIM 103 /* Protocol indep. multicast */ +#define IPPROTO_IPCOMP 108 /* IP Payload Comp. Protocol */ +#define IPPROTO_VRRP 112 /* VRRP RFC 2338 */ +#define IPPROTO_CARP 112 /* Common Address Resolution Protocol */ +#define IPPROTO_PFSYNC 240 /* PFSYNC */ +#define IPPROTO_RAW 255 /* raw IP packet */ +#define IPPROTO_MAX 256 + +/* last return value of *_input(), meaning "all job for this pkt is done". */ +#define IPPROTO_DONE 257 + +/* sysctl placeholder for (FAST_)IPSEC */ +#define CTL_IPPROTO_IPSEC 258 + + +/* + * Local port number conventions: + * + * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), + * unless a kernel is compiled with IPNOPRIVPORTS defined. + * + * When a user does a bind(2) or connect(2) with a port number of zero, + * a non-conflicting local port address is chosen. + * + * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although + * that is settable by sysctl(3); net.inet.ip.anonportmin and + * net.inet.ip.anonportmax respectively. + * + * A user may set the IPPROTO_IP option IP_PORTRANGE to change this + * default assignment range. + * + * The value IP_PORTRANGE_DEFAULT causes the default behavior. + * + * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, + * and exists only for FreeBSD compatibility purposes. + * + * The value IP_PORTRANGE_LOW changes the range to the "low" are + * that is (by convention) restricted to privileged processes. + * This convention is based on "vouchsafe" principles only. + * It is only secure if you trust the remote host to restrict these ports. + * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. + */ + +#define IPPORT_RESERVED 1024 +#define IPPORT_ANONMIN 49152 +#define IPPORT_ANONMAX 65535 +#define IPPORT_RESERVEDMIN 600 +#define IPPORT_RESERVEDMAX (IPPORT_RESERVED-1) + +/* + * Internet address (a structure for historical reasons) + */ +struct in_addr { + in_addr_t s_addr; +} __packed; + +/* + * Definitions of bits in internet address integers. + * On subnets, the decomposition of addresses to host and net parts + * is done according to subnet mask, not the masks here. + * + * By byte-swapping the constants, we avoid ever having to byte-swap IP + * addresses inside the kernel. Unfortunately, user-level programs rely + * on these macros not doing byte-swapping. + */ +#ifdef _KERNEL +#define __IPADDR(x) ((uint32_t) htonl((uint32_t)(x))) +#else +#define __IPADDR(x) ((uint32_t)(x)) +#endif + +#define IN_CLASSA(i) (((uint32_t)(i) & __IPADDR(0x80000000)) == \ + __IPADDR(0x00000000)) +#define IN_CLASSA_NET __IPADDR(0xff000000) +#define IN_CLASSA_NSHIFT 24 +#define IN_CLASSA_HOST __IPADDR(0x00ffffff) +#define IN_CLASSA_MAX 128 + +#define IN_CLASSB(i) (((uint32_t)(i) & __IPADDR(0xc0000000)) == \ + __IPADDR(0x80000000)) +#define IN_CLASSB_NET __IPADDR(0xffff0000) +#define IN_CLASSB_NSHIFT 16 +#define IN_CLASSB_HOST __IPADDR(0x0000ffff) +#define IN_CLASSB_MAX 65536 + +#define IN_CLASSC(i) (((uint32_t)(i) & __IPADDR(0xe0000000)) == \ + __IPADDR(0xc0000000)) +#define IN_CLASSC_NET __IPADDR(0xffffff00) +#define IN_CLASSC_NSHIFT 8 +#define IN_CLASSC_HOST __IPADDR(0x000000ff) + +#define IN_CLASSD(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xe0000000)) +/* These ones aren't really net and host fields, but routing needn't know. */ +#define IN_CLASSD_NET __IPADDR(0xf0000000) +#define IN_CLASSD_NSHIFT 28 +#define IN_CLASSD_HOST __IPADDR(0x0fffffff) +#define IN_MULTICAST(i) IN_CLASSD(i) + +#define IN_EXPERIMENTAL(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xf0000000)) +#define IN_BADCLASS(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xf0000000)) + +#define IN_LINKLOCAL(i) (((uint32_t)(i) & __IPADDR(0xffff0000)) == \ + __IPADDR(0xa9fe0000)) + +#define IN_PRIVATE(i) ((((uint32_t)(i) & __IPADDR(0xff000000)) == \ + __IPADDR(0x0a000000)) || \ + (((uint32_t)(i) & __IPADDR(0xfff00000)) == \ + __IPADDR(0xac100000)) || \ + (((uint32_t)(i) & __IPADDR(0xffff0000)) == \ + __IPADDR(0xc0a80000))) + +#define IN_LOCAL_GROUP(i) (((uint32_t)(i) & __IPADDR(0xffffff00)) == \ + __IPADDR(0xe0000000)) + +#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i)) + +#define INADDR_ANY __IPADDR(0x00000000) +#define INADDR_LOOPBACK __IPADDR(0x7f000001) +#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */ +#define INADDR_NONE __IPADDR(0xffffffff) /* -1 return */ + +#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */ +#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */ +#define INADDR_ALLRTRS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */ +#define INADDR_CARP_GROUP __IPADDR(0xe0000012) /* 224.0.0.18 */ +#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */ + +#define IN_LOOPBACKNET 127 /* official! */ + +/* + * Socket address, internet style. + */ +#ifdef __minix +struct sockaddr_in +{ + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; +}; +#else /* !__minix */ +struct sockaddr_in { + uint8_t sin_len; + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + __int8_t sin_zero[8]; +}; +#endif /* !__minix */ + +#define INET_ADDRSTRLEN 16 + +#ifndef __minix +/* + * Structure used to describe IP options. + * Used to store options internally, to pass them to a process, + * or to restore options retrieved earlier. + * The ip_dst is used for the first-hop gateway when using a source route + * (this gets put into the header proper). + */ +struct ip_opts { + struct in_addr ip_dst; /* first hop, 0 w/o src rt */ +#if defined(__cplusplus) + __int8_t Ip_opts[40]; /* actually variable in size */ +#else + __int8_t ip_opts[40]; /* actually variable in size */ +#endif +}; +#endif /* __minix */ + +/* + * Options for use with [gs]etsockopt at the IP level. + * First word of comment is data type; bool is stored in int. + */ +#ifndef __minix +#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ +#define IP_HDRINCL 2 /* int; header is included with data */ +#define IP_TOS 3 /* int; IP type of service and preced. */ +#define IP_TTL 4 /* int; IP time to live */ +#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ +#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ +#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ +#define IP_RETOPTS 8 /* ip_opts; set/get IP options */ +#define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */ +#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ +#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ +#endif /* !__minix */ +#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ +#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ +#ifndef __minix +#define IP_PORTRANGE 19 /* int; range to use for ephemeral port */ +#define IP_RECVIF 20 /* bool; receive reception if w/dgram */ +#define IP_ERRORMTU 21 /* int; get MTU of last xmit = EMSGSIZE */ +#if 1 /*IPSEC*/ +#define IP_IPSEC_POLICY 22 /* struct; get/set security policy */ +#endif +#define IP_RECVTTL 23 /* bool; receive IP TTL w/dgram */ +#define IP_MINTTL 24 /* minimum TTL for packet or drop */ +#endif /* !__minix */ + +#ifndef __minix +/* + * Defaults and limits for options + */ +#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ +#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ +#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */ +#endif /* !__minix */ + +/* + * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. + */ +struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +}; + +#ifndef __minix +/* + * Argument for IP_PORTRANGE: + * - which range to search when port is unspecified at bind() or connect() + */ +#define IP_PORTRANGE_DEFAULT 0 /* default range */ +#define IP_PORTRANGE_HIGH 1 /* same as DEFAULT (FreeBSD compat) */ +#define IP_PORTRANGE_LOW 2 /* use privileged range */ + +#if defined(_NETBSD_SOURCE) +/* + * Definitions for inet sysctl operations. + * + * Third level is protocol number. + * Fourth level is desired variable within that protocol. + */ +#define IPPROTO_MAXID (IPPROTO_AH + 1) /* don't list to IPPROTO_MAX */ + +#define CTL_IPPROTO_NAMES { \ + { "ip", CTLTYPE_NODE }, \ + { "icmp", CTLTYPE_NODE }, \ + { "igmp", CTLTYPE_NODE }, \ + { "ggp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "tcp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { "egp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "pup", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "udp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "idp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "ipsec", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "pim", CTLTYPE_NODE }, \ +} + +/* + * Names for IP sysctl objects + */ +#define IPCTL_FORWARDING 1 /* act as router */ +#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ +#define IPCTL_DEFTTL 3 /* default TTL */ +#ifdef notyet +#define IPCTL_DEFMTU 4 /* default MTU */ +#endif +#define IPCTL_FORWSRCRT 5 /* forward source-routed packets */ +#define IPCTL_DIRECTEDBCAST 6 /* default broadcast behavior */ +#define IPCTL_ALLOWSRCRT 7 /* allow/drop all source-routed pkts */ +#define IPCTL_SUBNETSARELOCAL 8 /* treat subnets as local addresses */ +#define IPCTL_MTUDISC 9 /* allow path MTU discovery */ +#define IPCTL_ANONPORTMIN 10 /* minimum ephemeral port */ +#define IPCTL_ANONPORTMAX 11 /* maximum ephemeral port */ +#define IPCTL_MTUDISCTIMEOUT 12 /* allow path MTU discovery */ +#define IPCTL_MAXFLOWS 13 /* maximum ip flows allowed */ +#define IPCTL_HOSTZEROBROADCAST 14 /* is host zero a broadcast addr? */ +#define IPCTL_GIF_TTL 15 /* default TTL for gif encap packet */ +#define IPCTL_LOWPORTMIN 16 /* minimum reserved port */ +#define IPCTL_LOWPORTMAX 17 /* maximum reserved port */ +#define IPCTL_MAXFRAGPACKETS 18 /* max packets reassembly queue */ +#define IPCTL_GRE_TTL 19 /* default TTL for gre encap packet */ +#define IPCTL_CHECKINTERFACE 20 /* drop pkts in from 'wrong' iface */ +#define IPCTL_IFQ 21 /* ipintrq node */ +#define IPCTL_RANDOMID 22 /* use random IP ids (if configured) */ +#define IPCTL_LOOPBACKCKSUM 23 /* do IP checksum on loopback */ +#define IPCTL_STATS 24 /* IP statistics */ +#define IPCTL_MAXID 25 + +#define IPCTL_NAMES { \ + { 0, 0 }, \ + { "forwarding", CTLTYPE_INT }, \ + { "redirect", CTLTYPE_INT }, \ + { "ttl", CTLTYPE_INT }, \ + { "mtu", CTLTYPE_INT }, \ + { "forwsrcrt", CTLTYPE_INT }, \ + { "directed-broadcast", CTLTYPE_INT }, \ + { "allowsrcrt", CTLTYPE_INT }, \ + { "subnetsarelocal", CTLTYPE_INT }, \ + { "mtudisc", CTLTYPE_INT }, \ + { "anonportmin", CTLTYPE_INT }, \ + { "anonportmax", CTLTYPE_INT }, \ + { "mtudisctimeout", CTLTYPE_INT }, \ + { "maxflows", CTLTYPE_INT }, \ + { "hostzerobroadcast", CTLTYPE_INT }, \ + { "gifttl", CTLTYPE_INT }, \ + { "lowportmin", CTLTYPE_INT }, \ + { "lowportmax", CTLTYPE_INT }, \ + { "maxfragpackets", CTLTYPE_INT }, \ + { "grettl", CTLTYPE_INT }, \ + { "checkinterface", CTLTYPE_INT }, \ + { "ifq", CTLTYPE_NODE }, \ + { "random_id", CTLTYPE_INT }, \ + { "do_loopback_cksum", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} +#endif /* _NETBSD_SOURCE */ +#endif /* __minix */ + +/* INET6 stuff */ +#define __KAME_NETINET_IN_H_INCLUDED_ +#include +#undef __KAME_NETINET_IN_H_INCLUDED_ + +#endif /* !_NETINET_IN_H_ */ diff --git a/nbsd_include/netinet/tcp.h b/nbsd_include/netinet/tcp.h new file mode 100644 index 000000000..17a0540d3 --- /dev/null +++ b/nbsd_include/netinet/tcp.h @@ -0,0 +1,119 @@ +/* $NetBSD: tcp.h,v 1.28 2007/12/25 18:33:47 perry Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)tcp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_H_ +#define _NETINET_TCP_H_ + +#include + +#if defined(_NETBSD_SOURCE) + +typedef u_int32_t tcp_seq; +/* + * TCP header. + * Per RFC 793, September, 1981. + * Updated by RFC 3168, September, 2001. + */ +struct tcphdr { + u_int16_t th_sport; /* source port */ + u_int16_t th_dport; /* destination port */ + tcp_seq th_seq; /* sequence number */ + tcp_seq th_ack; /* acknowledgement number */ +#if BYTE_ORDER == LITTLE_ENDIAN + /*LINTED non-portable bitfields*/ + u_int8_t th_x2:4, /* (unused) */ + th_off:4; /* data offset */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + /*LINTED non-portable bitfields*/ + u_int8_t th_off:4, /* data offset */ + th_x2:4; /* (unused) */ +#endif + u_int8_t th_flags; +#define TH_FIN 0x01 +#define TH_SYN 0x02 +#define TH_RST 0x04 +#define TH_PUSH 0x08 +#define TH_ACK 0x10 +#define TH_URG 0x20 +#define TH_ECE 0x40 +#define TH_CWR 0x80 + u_int16_t th_win; /* window */ + u_int16_t th_sum; /* checksum */ + u_int16_t th_urp; /* urgent pointer */ +} __packed; + +#define TCPOPT_EOL 0 +#define TCPOPT_NOP 1 +#define TCPOPT_MAXSEG 2 +#define TCPOLEN_MAXSEG 4 +#define TCPOPT_WINDOW 3 +#define TCPOLEN_WINDOW 3 +#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ +#define TCPOLEN_SACK_PERMITTED 2 +#define TCPOPT_SACK 5 /* Experimental */ +#define TCPOPT_TIMESTAMP 8 +#define TCPOLEN_TIMESTAMP 10 +#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ + +#define TCPOPT_TSTAMP_HDR \ + (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) + +#define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */ +#define TCPOLEN_SIGNATURE 18 +#define TCPOLEN_SIGLEN (TCPOLEN_SIGNATURE+2) /* padding */ + +#define MAX_TCPOPTLEN 40 /* max # bytes that go in options */ + +/* + * Default maximum segment size for TCP. + * This is defined by RFC 1112 Sec 4.2.2.6. + */ +#define TCP_MSS 536 + +#define TCP_MINMSS 216 + +#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ + +#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ + +#define TCP_MAXBURST 4 /* maximum segments in a burst */ + +#endif /* _NETBSD_SOURCE */ + +/* + * User-settable options (used with setsockopt). + */ +#define TCP_NODELAY 1 /* don't delay send to coalesce packets */ + +#endif /* !_NETINET_TCP_H_ */ diff --git a/nbsd_include/netinet6/Makefile b/nbsd_include/netinet6/Makefile new file mode 100644 index 000000000..32c07e9f4 --- /dev/null +++ b/nbsd_include/netinet6/Makefile @@ -0,0 +1,5 @@ +INCSDIR= /usr/netbsd/include/netinet6 + +INCS+= in6.h + +.include diff --git a/nbsd_include/netinet6/in6.h b/nbsd_include/netinet6/in6.h new file mode 100644 index 000000000..a2fbf896d --- /dev/null +++ b/nbsd_include/netinet6/in6.h @@ -0,0 +1,808 @@ +/* $NetBSD: in6.h,v 1.68 2009/09/11 22:06:29 dyoung Exp $ */ +/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)in.h 8.3 (Berkeley) 1/3/94 + */ + +#ifndef _NETINET6_IN6_H_ +#define _NETINET6_IN6_H_ + +#ifndef __KAME_NETINET_IN_H_INCLUDED_ +#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" +#endif + +#include + +/* + * Identification of the network protocol stack + * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE + * has the table of implementation/integration differences. + */ +#define __KAME__ +#define __KAME_VERSION "NetBSD-current" + +/* + * Local port number conventions: + * + * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), + * unless a kernel is compiled with IPNOPRIVPORTS defined. + * + * When a user does a bind(2) or connect(2) with a port number of zero, + * a non-conflicting local port address is chosen. + * + * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although + * that is settable by sysctl(3); net.inet.ip.anonportmin and + * net.inet.ip.anonportmax respectively. + * + * A user may set the IPPROTO_IP option IP_PORTRANGE to change this + * default assignment range. + * + * The value IP_PORTRANGE_DEFAULT causes the default behavior. + * + * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, + * and exists only for FreeBSD compatibility purposes. + * + * The value IP_PORTRANGE_LOW changes the range to the "low" are + * that is (by convention) restricted to privileged processes. + * This convention is based on "vouchsafe" principles only. + * It is only secure if you trust the remote host to restrict these ports. + * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. + */ + +#if defined(_NETBSD_SOURCE) +#define IPV6PORT_RESERVED 1024 +#define IPV6PORT_ANONMIN 49152 +#define IPV6PORT_ANONMAX 65535 +#define IPV6PORT_RESERVEDMIN 600 +#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) +#endif + +/* + * IPv6 address + */ +struct in6_addr { + union { + __uint8_t __u6_addr8[16]; + __uint16_t __u6_addr16[8]; + uint32_t __u6_addr32[4]; + } __u6_addr; /* 128-bit IP6 address */ +}; + +#define s6_addr __u6_addr.__u6_addr8 +#ifdef _KERNEL /* XXX nonstandard */ +#define s6_addr8 __u6_addr.__u6_addr8 +#define s6_addr16 __u6_addr.__u6_addr16 +#define s6_addr32 __u6_addr.__u6_addr32 +#endif + +#define INET6_ADDRSTRLEN 46 + +/* + * Socket address for IPv6 + */ +#if defined(_NETBSD_SOURCE) +#define SIN6_LEN +#endif +struct sockaddr_in6 { +#ifndef __minix + uint8_t sin6_len; /* length of this struct(socklen_t)*/ +#endif /* !__minix */ + sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */ + in_port_t sin6_port; /* Transport layer port */ + uint32_t sin6_flowinfo; /* IP6 flow information */ + struct in6_addr sin6_addr; /* IP6 address */ + uint32_t sin6_scope_id; /* scope zone index */ +}; + +#ifndef __minix +/* + * Local definition for masks + */ +#ifdef _KERNEL /* XXX nonstandard */ +#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} +#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} +#endif + +#ifdef _KERNEL +extern const struct sockaddr_in6 sa6_any; + +extern const struct in6_addr in6mask0; +extern const struct in6_addr in6mask32; +extern const struct in6_addr in6mask64; +extern const struct in6_addr in6mask96; +extern const struct in6_addr in6mask128; +#endif /* _KERNEL */ + +/* + * Macros started with IPV6_ADDR is KAME local + */ +#ifdef _KERNEL /* XXX nonstandard */ +#if BYTE_ORDER == BIG_ENDIAN +#define IPV6_ADDR_INT32_ONE 1 +#define IPV6_ADDR_INT32_TWO 2 +#define IPV6_ADDR_INT32_MNL 0xff010000 +#define IPV6_ADDR_INT32_MLL 0xff020000 +#define IPV6_ADDR_INT32_SMP 0x0000ffff +#define IPV6_ADDR_INT16_ULL 0xfe80 +#define IPV6_ADDR_INT16_USL 0xfec0 +#define IPV6_ADDR_INT16_MLL 0xff02 +#elif BYTE_ORDER == LITTLE_ENDIAN +#define IPV6_ADDR_INT32_ONE 0x01000000 +#define IPV6_ADDR_INT32_TWO 0x02000000 +#define IPV6_ADDR_INT32_MNL 0x000001ff +#define IPV6_ADDR_INT32_MLL 0x000002ff +#define IPV6_ADDR_INT32_SMP 0xffff0000 +#define IPV6_ADDR_INT16_ULL 0x80fe +#define IPV6_ADDR_INT16_USL 0xc0fe +#define IPV6_ADDR_INT16_MLL 0x02ff +#endif +#endif +#endif /* !__minix */ + +/* + * Definition of some useful macros to handle IP6 addresses + */ +#define IN6ADDR_ANY_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6ADDR_LOOPBACK_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ + {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ + {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ + {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} + +extern const struct in6_addr in6addr_any; +extern const struct in6_addr in6addr_loopback; +extern const struct in6_addr in6addr_nodelocal_allnodes; +extern const struct in6_addr in6addr_linklocal_allnodes; +extern const struct in6_addr in6addr_linklocal_allrouters; + +#define IN6_ARE_ADDR_EQUAL(a, b) \ + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) + +/* + * Unspecified + */ +#define IN6_IS_ADDR_UNSPECIFIED(a) \ + ((a)->__u6_addr.__u6_addr32[0] == 0 && \ + (a)->__u6_addr.__u6_addr32[1] == 0 && \ + (a)->__u6_addr.__u6_addr32[2] == 0 && \ + (a)->__u6_addr.__u6_addr32[3] == 0) + +/* + * Loopback + */ +#define IN6_IS_ADDR_LOOPBACK(a) \ + ((a)->__u6_addr.__u6_addr32[0] == 0 && \ + (a)->__u6_addr.__u6_addr32[1] == 0 && \ + (a)->__u6_addr.__u6_addr32[2] == 0 && \ + (a)->__u6_addr.__u6_addr32[3] == ntohl(1)) + +/* + * IPv4 compatible + */ +#define IN6_IS_ADDR_V4COMPAT(a) \ + ((a)->__u6_addr.__u6_addr32[0] == 0 && \ + (a)->__u6_addr.__u6_addr32[1] == 0 && \ + (a)->__u6_addr.__u6_addr32[2] == 0 && \ + (a)->__u6_addr.__u6_addr32[3] != 0 && \ + (a)->__u6_addr.__u6_addr32[3] != ntohl(1)) + +/* + * Mapped + */ +#define IN6_IS_ADDR_V4MAPPED(a) \ + ((a)->__u6_addr.__u6_addr32[0] == 0 && \ + (a)->__u6_addr.__u6_addr32[1] == 0 && \ + (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff)) + +/* + * KAME Scope Values + */ + +#ifdef _KERNEL /* XXX nonstandard */ +#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 +#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 +#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 +#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 +#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ +#define IPV6_ADDR_SCOPE_GLOBAL 0x0e +#else +#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 +#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 +#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 +#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ +#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e +#endif + +/* + * Unicast Scope + * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). + */ +#define IN6_IS_ADDR_LINKLOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) +#define IN6_IS_ADDR_SITELOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) + +/* + * Multicast + */ +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) + +#ifdef _KERNEL /* XXX nonstandard */ +#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) +#else +#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) +#endif + +/* + * Multicast Scope + */ +#ifdef _KERNEL /* refers nonstandard items */ +#define IN6_IS_ADDR_MC_NODELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) +#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) +#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) +#define IN6_IS_ADDR_MC_SITELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) +#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) +#define IN6_IS_ADDR_MC_GLOBAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) +#else +#define IN6_IS_ADDR_MC_NODELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) +#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) +#define IN6_IS_ADDR_MC_SITELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) +#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) +#define IN6_IS_ADDR_MC_GLOBAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) +#endif + +#ifdef _KERNEL /* nonstandard */ +/* + * KAME Scope + */ +#define IN6_IS_SCOPE_LINKLOCAL(a) \ + ((IN6_IS_ADDR_LINKLOCAL(a)) || \ + (IN6_IS_ADDR_MC_LINKLOCAL(a))) + +#define IN6_IS_SCOPE_EMBEDDABLE(__a) \ + (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a)) + +#define IFA6_IS_DEPRECATED(a) \ + ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ + (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ + (a)->ia6_lifetime.ia6t_pltime) +#define IFA6_IS_INVALID(a) \ + ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ + (u_int32_t)((time_second - (a)->ia6_updatetime)) > \ + (a)->ia6_lifetime.ia6t_vltime) +#endif + +#ifndef __minix +/* + * Options for use with [gs]etsockopt at the IPV6 level. + * First word of comment is data type; bool is stored in int. + */ +/* no hdrincl */ +#if 0 +/* These are deprecated non-standard options which are no longer supported. */ +#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ +#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ +#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ +#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ +#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ +#endif +#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ +#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ +#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ +#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ +#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ +#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ +#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ +#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ +#if defined(_NETBSD_SOURCE) +#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ +#endif +/* RFC2292 options */ +#ifdef _KERNEL +#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ +#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ +#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ +#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ +#define IPV6_2292DSTOPTS 23 /* bool; destination option */ +#define IPV6_2292RTHDR 24 /* bool; routing header */ +#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ +#endif +#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ +#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ + +#if 1 /* IPSEC */ +#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ +#endif +#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ + +/* new socket options introduced in RFC3542 */ +#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ + +#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ +#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ +#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ +#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ +#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ +#ifdef _KERNEL +#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ +#endif +#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ +#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ +#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), + 4 bytes int; MTU notification (cmsg) */ + +/* more new socket options introduced in RFC3542 */ +#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ +#define IPV6_HOPLIMIT 47 /* int; send hop limit */ +#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ +#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ +#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ +#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ + +#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ +#ifdef _KERNEL +#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */ +#endif + +#define IPV6_TCLASS 61 /* int; send traffic class value */ +#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ +/* to define items, should talk with KAME guys first, for *BSD compatibility */ + +#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ +#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ +#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ + +/* + * Defaults and limits for options + */ +#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ +#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ + +/* + * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. + */ +struct ipv6_mreq { + struct in6_addr ipv6mr_multiaddr; + unsigned int ipv6mr_interface; +}; + +/* + * IPV6_PKTINFO: Packet information(RFC2292 sec 5) + */ +struct in6_pktinfo { + struct in6_addr ipi6_addr; /* src/dst IPv6 address */ + unsigned int ipi6_ifindex; /* send/recv interface index */ +}; + +/* + * Control structure for IPV6_RECVPATHMTU socket option. + */ +struct ip6_mtuinfo { + struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ + uint32_t ip6m_mtu; +}; + +/* + * Argument for IPV6_PORTRANGE: + * - which range to search when port is unspecified at bind() or connect() + */ +#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ +#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ +#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ + +#if defined(_NETBSD_SOURCE) +/* + * Definitions for inet6 sysctl operations. + * + * Third level is protocol number. + * Fourth level is desired variable within that protocol. + */ +#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */ + +#define CTL_IPV6PROTO_NAMES { \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "tcp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "udp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "ip6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "ipsec6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "icmp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "pim6", CTLTYPE_NODE }, \ +} + +/* + * Names for IP sysctl objects + */ +#define IPV6CTL_FORWARDING 1 /* act as router */ +#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ +#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ +#ifdef notyet +#define IPV6CTL_DEFMTU 4 /* default MTU */ +#endif +#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ +#define IPV6CTL_STATS 6 /* stats */ +#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ +#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ +#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ +#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ +#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ +#define IPV6CTL_ACCEPT_RTADV 12 +#define IPV6CTL_KEEPFAITH 13 +#define IPV6CTL_LOG_INTERVAL 14 +#define IPV6CTL_HDRNESTLIMIT 15 +#define IPV6CTL_DAD_COUNT 16 +#define IPV6CTL_AUTO_FLOWLABEL 17 +#define IPV6CTL_DEFMCASTHLIM 18 +#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ +#define IPV6CTL_KAME_VERSION 20 +#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ +#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */ +/* 23: reserved */ +#define IPV6CTL_V6ONLY 24 +/* 25 to 27: reserved */ +#define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */ +#define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */ +#define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */ +#define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */ +/* 32 to 38: reserved */ +#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */ +/* 40: reserved */ +#define IPV6CTL_MAXFRAGS 41 /* max fragments */ +#define IPV6CTL_IFQ 42 /* ip6intrq node */ +/* New entries should be added here from current IPV6CTL_MAXID value. */ +/* to define items, should talk with KAME guys first, for *BSD compatibility */ +#define IPV6CTL_MAXID 43 + +#define IPV6CTL_NAMES { \ + { 0, 0 }, \ + { "forwarding", CTLTYPE_INT }, \ + { "redirect", CTLTYPE_INT }, \ + { "hlim", CTLTYPE_INT }, \ + { "mtu", CTLTYPE_INT }, \ + { "forwsrcrt", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { 0, 0 }, \ + { "mrtproto", CTLTYPE_INT }, \ + { "maxfragpackets", CTLTYPE_INT }, \ + { "sourcecheck", CTLTYPE_INT }, \ + { "sourcecheck_logint", CTLTYPE_INT }, \ + { "accept_rtadv", CTLTYPE_INT }, \ + { "keepfaith", CTLTYPE_INT }, \ + { "log_interval", CTLTYPE_INT }, \ + { "hdrnestlimit", CTLTYPE_INT }, \ + { "dad_count", CTLTYPE_INT }, \ + { "auto_flowlabel", CTLTYPE_INT }, \ + { "defmcasthlim", CTLTYPE_INT }, \ + { "gifhlim", CTLTYPE_INT }, \ + { "kame_version", CTLTYPE_STRING }, \ + { "use_deprecated", CTLTYPE_INT }, \ + { "rr_prune", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "v6only", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "anonportmin", CTLTYPE_INT }, \ + { "anonportmax", CTLTYPE_INT }, \ + { "lowportmin", CTLTYPE_INT }, \ + { "lowportmax", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "maxfrags", CTLTYPE_INT }, \ + { "ifq", CTLTYPE_NODE }, \ +} + +#endif /* _NETBSD_SOURCE */ + +#ifdef _KERNEL +struct cmsghdr; + +/* + * in6_cksum_phdr: + * + * Compute significant parts of the IPv6 checksum pseudo-header + * for use in a delayed TCP/UDP checksum calculation. + * + * Args: + * + * src Source IPv6 address + * dst Destination IPv6 address + * len htonl(proto-hdr-len) + * nxt htonl(next-proto-number) + * + * NOTE: We expect the src and dst addresses to be 16-bit + * aligned! + */ +static __inline u_int16_t __unused +in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst, + u_int32_t len, u_int32_t nxt) +{ + u_int32_t sum = 0; + const u_int16_t *w; + + /*LINTED*/ + w = (const u_int16_t *) src; + sum += w[0]; + if (!IN6_IS_SCOPE_LINKLOCAL(src)) + sum += w[1]; + sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; + sum += w[6]; sum += w[7]; + + /*LINTED*/ + w = (const u_int16_t *) dst; + sum += w[0]; + if (!IN6_IS_SCOPE_LINKLOCAL(dst)) + sum += w[1]; + sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; + sum += w[6]; sum += w[7]; + + sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/); + + sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/); + + sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/); + + if (sum > 0xffff) + sum -= 0xffff; + + return (sum); +} + +struct mbuf; +struct ifnet; +int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *); +struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t, + const struct sockaddr *); +int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t); +void in6_delayed_cksum(struct mbuf *); +int in6_localaddr(const struct in6_addr *); +int in6_addrscope(const struct in6_addr *); +struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); +extern void in6_if_up(struct ifnet *); +#ifndef __FreeBSD__ +extern int in6_src_sysctl(void *, size_t *, void *, size_t); +#endif +extern void addrsel_policy_init(void); +extern u_char ip6_protox[]; + +#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) +#define satocsin6(sa) ((const struct sockaddr_in6 *)(sa)) +#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) +#define sin6tocsa(sin6) ((const struct sockaddr *)(sin6)) +#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) + +static inline void +sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr, + in_port_t port, uint32_t flowinfo, uint32_t scope_id) +{ + sin6->sin6_port = port; + sin6->sin6_flowinfo = flowinfo; + sin6->sin6_addr = *addr; + sin6->sin6_scope_id = scope_id; +} + +static inline void +sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr, + in_port_t port, uint32_t flowinfo, uint32_t scope_id) +{ + sin6->sin6_family = AF_INET6; + sin6->sin6_len = sizeof(*sin6); + sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id); +} + +static inline struct sockaddr * +sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port, + uint32_t flowinfo, uint32_t scope_id, int flags) +{ + struct sockaddr *sa; + + if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6), + flags)) == NULL) + return NULL; + + sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id); + + return sa; +} +#endif /* _KERNEL */ + +#if defined(_NETBSD_SOURCE) + +#include + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#define _SIZE_T +#undef _BSD_SIZE_T_ +#endif + +#include + +__BEGIN_DECLS +struct cmsghdr; + +void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *); +void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *); +void in6_sin6_2_sin_in_sock(struct sockaddr *); +void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **); + +extern int inet6_option_space(int); +extern int inet6_option_init(void *, struct cmsghdr **, int); +extern int inet6_option_append(struct cmsghdr *, const uint8_t *, + int, int); +extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int); +extern int inet6_option_next(const struct cmsghdr *, uint8_t **); +extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int); + +extern size_t inet6_rthdr_space(int, int); +extern struct cmsghdr *inet6_rthdr_init(void *, int); +extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *, + unsigned int); +extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int); +#if 0 /* not implemented yet */ +extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *); +#endif +extern int inet6_rthdr_segments(const struct cmsghdr *); +extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int); +extern int inet6_rthdr_getflags(const struct cmsghdr *, int); + +extern int inet6_opt_init(void *, socklen_t); +extern int inet6_opt_append(void *, socklen_t, int, uint8_t, + socklen_t, uint8_t, void **); +extern int inet6_opt_finish(void *, socklen_t, int); +extern int inet6_opt_set_val(void *, int, void *, socklen_t); + +extern int inet6_opt_next(void *, socklen_t, int, uint8_t *, + socklen_t *, void **); +extern int inet6_opt_find(void *, socklen_t, int, uint8_t, + socklen_t *, void **); +extern int inet6_opt_get_val(void *, int, void *, socklen_t); +extern socklen_t inet6_rth_space(int, int); +extern void *inet6_rth_init(void *, socklen_t, int, int); +extern int inet6_rth_add(void *, const struct in6_addr *); +extern int inet6_rth_reverse(const void *, void *); +extern int inet6_rth_segments(const void *); +extern struct in6_addr *inet6_rth_getaddr(const void *, int); +__END_DECLS +#endif /* _NETBSD_SOURCE */ +#endif /* !__minix */ + +#endif /* !_NETINET6_IN6_H_ */ diff --git a/nbsd_include/sys/Makefile b/nbsd_include/sys/Makefile new file mode 100644 index 000000000..cc5930275 --- /dev/null +++ b/nbsd_include/sys/Makefile @@ -0,0 +1,63 @@ +# $NetBSD: Makefile,v 1.126 2010/03/01 21:10:13 darran Exp $ + +NETBSDINCSDIR= /usr/netbsd/include +INCSDIR= /usr/netbsd/include/sys + +.include + + +# Present only in minix +INCS+= ioc_net.h + +INCS+= ansi.h atomic.h \ + bitops.h bswap.h \ + cdefs.h cdefs_aout.h ctype_bits.h ctype_inline.h \ + dirent.h \ + endian.h errno.h \ + fcntl.h fd_set.h featuretest.h file.h \ + float_ieee754.h gcq.h gmon.h hash.h \ + ieee754.h inttypes.h ioctl.h ipc.h \ + localedef.h \ + md4.h md5.h \ + mman.h mount.h \ + null.h \ + param.h poll.h ptrace.h \ + ptree.h \ + queue.h \ + rbtree.h resource.h rmd160.h \ + select.h sha1.h \ + sha2.h siginfo.h signal.h sigtypes.h \ + reboot.h sem.h shm.h socket.h \ + stat.h statvfs.h \ + sysctl.h stdint.h \ + syslimits.h syslog.h \ + termios.h time.h times.h \ + tree.h ttycom.h ttydefaults.h \ + types.h \ + ucontext.h ucred.h uio.h un.h unistd.h utsname.h uuid.h \ + wait.h + +INCSYMLINKS=\ + ${NETBSDINCSDIR}/sys/fcntl.h ${NETBSDINCSDIR}/fcntl.h \ + ${NETBSDINCSDIR}/sys/poll.h ${NETBSDINCSDIR}/poll.h \ + ${NETBSDINCSDIR}/sys/stdint.h ${NETBSDINCSDIR}/stdint.h \ + ${NETBSDINCSDIR}/sys/syslog.h ${NETBSDINCSDIR}/syslog.h \ + ${NETBSDINCSDIR}/sys/termios.h ${NETBSDINCSDIR}/termios.h \ + ${NETBSDINCSDIR}/sys/rmd160.h ${NETBSDINCSDIR}/rmd160.h \ + ${NETBSDINCSDIR}/sys/sha1.h ${NETBSDINCSDIR}/sha1.h \ + ${NETBSDINCSDIR}/sys/sha2.h ${NETBSDINCSDIR}/sha2.h \ + ${NETBSDINCSDIR}/sys/md4.h ${NETBSDINCSDIR}/md4.h \ + ${NETBSDINCSDIR}/sys/md5.h ${NETBSDINCSDIR}/md5.h +# sys/exec_elf.h /usr/include/elf.h \ + + +#INCSYMLINKS+= ../soundcard.h ${INCSDIR}/soundcard.h + +namei: namei.src gennameih.awk + ${TOOL_AWK} -f gennameih.awk < namei.src + +.include +.include "${MINIXSRCDIR}/common/include/sys/Makefile.inc" + +.include +.include diff --git a/nbsd_include/sys/ansi.h b/nbsd_include/sys/ansi.h new file mode 100644 index 000000000..2f9365892 --- /dev/null +++ b/nbsd_include/sys/ansi.h @@ -0,0 +1,69 @@ +/* $NetBSD: ansi.h,v 1.13 2010/03/27 22:14:10 tnozaki Exp $ */ + +/*- + * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jun-ichiro itojun Hagino and by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_ANSI_H_ +#define _SYS_ANSI_H_ + +#include + +typedef char * __caddr_t; /* core address */ +typedef char __gid_t; /* group id */ +typedef __uint32_t __in_addr_t; /* IP(v4) address */ +typedef __uint16_t __in_port_t; /* "Internet" port number */ +typedef unsigned short __mode_t; /* file permissions */ +typedef long __off_t; /* file offset */ +typedef int __pid_t; /* process id */ +typedef __uint8_t __sa_family_t; /* socket address family */ +typedef __int32_t __socklen_t; /* socket-related datum length */ +typedef short __uid_t; /* user id */ +typedef unsigned long __fsblkcnt_t; /* fs block count (statvfs) */ +typedef unsigned long __fsfilcnt_t; /* fs file count */ + +struct __tag_wctrans_t; +typedef struct __tag_wctrans_t *__wctrans_t; + +struct __tag_wctype_t; +typedef struct __tag_wctype_t *__wctype_t; + +/* + * mbstate_t is an opaque object to keep conversion state, during multibyte + * stream conversions. The content must not be referenced by user programs. + */ +typedef union { + __int64_t __mbstateL; /* for alignment */ + char __mbstate8[128]; +} __mbstate_t; + +#define _BSD_WCTRANS_T_ __wctrans_t /* wctrans_t */ +#define _BSD_WCTYPE_T_ __wctype_t /* wctype_t */ +#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */ + +#endif /* !_SYS_ANSI_H_ */ diff --git a/nbsd_include/sys/atomic.h b/nbsd_include/sys/atomic.h new file mode 100644 index 000000000..8a2765f3b --- /dev/null +++ b/nbsd_include/sys/atomic.h @@ -0,0 +1,154 @@ +/* $NetBSD: atomic.h,v 1.11 2009/11/20 02:17:07 christos Exp $ */ + +/*- + * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_ATOMIC_H_ +#define _SYS_ATOMIC_H_ + +#include +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +#endif + +__BEGIN_DECLS +/* + * Atomic ADD + */ +void atomic_add_32(volatile uint32_t *, int32_t); +void atomic_add_int(volatile unsigned int *, int); +void atomic_add_long(volatile unsigned long *, long); +void atomic_add_ptr(volatile void *, ssize_t); +void atomic_add_64(volatile uint64_t *, int64_t); + +uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t); +unsigned int atomic_add_int_nv(volatile unsigned int *, int); +unsigned long atomic_add_long_nv(volatile unsigned long *, long); +void * atomic_add_ptr_nv(volatile void *, ssize_t); +uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t); + +/* + * Atomic AND + */ +void atomic_and_32(volatile uint32_t *, uint32_t); +void atomic_and_uint(volatile unsigned int *, unsigned int); +void atomic_and_ulong(volatile unsigned long *, unsigned long); +void atomic_and_64(volatile uint64_t *, uint64_t); + +uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t); +unsigned int atomic_and_uint_nv(volatile unsigned int *, unsigned int); +unsigned long atomic_and_ulong_nv(volatile unsigned long *, unsigned long); +uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t); + +/* + * Atomic OR + */ +void atomic_or_32(volatile uint32_t *, uint32_t); +void atomic_or_uint(volatile unsigned int *, unsigned int); +void atomic_or_ulong(volatile unsigned long *, unsigned long); +void atomic_or_64(volatile uint64_t *, uint64_t); + +uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t); +unsigned int atomic_or_uint_nv(volatile unsigned int *, unsigned int); +unsigned long atomic_or_ulong_nv(volatile unsigned long *, unsigned long); +uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t); + +/* + * Atomic COMPARE-AND-SWAP + */ +uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t); +unsigned int atomic_cas_uint(volatile unsigned int *, unsigned int, + unsigned int); +unsigned long atomic_cas_ulong(volatile unsigned long *, unsigned long, + unsigned long); +void * atomic_cas_ptr(volatile void *, void *, void *); +uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t); + +/* + * Non-interlocked atomic COMPARE-AND-SWAP. + */ +uint32_t atomic_cas_32_ni(volatile uint32_t *, uint32_t, uint32_t); +unsigned int atomic_cas_uint_ni(volatile unsigned int *, unsigned int, + unsigned int); +unsigned long atomic_cas_ulong_ni(volatile unsigned long *, unsigned long, + unsigned long); +void * atomic_cas_ptr_ni(volatile void *, void *, void *); +uint64_t atomic_cas_64_ni(volatile uint64_t *, uint64_t, uint64_t); + +/* + * Atomic SWAP + */ +uint32_t atomic_swap_32(volatile uint32_t *, uint32_t); +unsigned int atomic_swap_uint(volatile unsigned int *, unsigned int); +unsigned long atomic_swap_ulong(volatile unsigned long *, unsigned long); +void * atomic_swap_ptr(volatile void *, void *); +uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); + +/* + * Atomic DECREMENT + */ +void atomic_dec_32(volatile uint32_t *); +void atomic_dec_uint(volatile unsigned int *); +void atomic_dec_ulong(volatile unsigned long *); +void atomic_dec_ptr(volatile void *); +void atomic_dec_64(volatile uint64_t *); + +uint32_t atomic_dec_32_nv(volatile uint32_t *); +unsigned int atomic_dec_uint_nv(volatile unsigned int *); +unsigned long atomic_dec_ulong_nv(volatile unsigned long *); +void * atomic_dec_ptr_nv(volatile void *); +uint64_t atomic_dec_64_nv(volatile uint64_t *); + +/* + * Atomic INCREMENT + */ +void atomic_inc_32(volatile uint32_t *); +void atomic_inc_uint(volatile unsigned int *); +void atomic_inc_ulong(volatile unsigned long *); +void atomic_inc_ptr(volatile void *); +void atomic_inc_64(volatile uint64_t *); + +uint32_t atomic_inc_32_nv(volatile uint32_t *); +unsigned int atomic_inc_uint_nv(volatile unsigned int *); +unsigned long atomic_inc_ulong_nv(volatile unsigned long *); +void * atomic_inc_ptr_nv(volatile void *); +uint64_t atomic_inc_64_nv(volatile uint64_t *); + +/* + * Memory barrier operations + */ +void membar_enter(void); +void membar_exit(void); +void membar_producer(void); +void membar_consumer(void); +void membar_sync(void); + +__END_DECLS + +#endif /* ! _SYS_ATOMIC_H_ */ diff --git a/nbsd_include/sys/bitops.h b/nbsd_include/sys/bitops.h new file mode 100644 index 000000000..f3b3ba193 --- /dev/null +++ b/nbsd_include/sys/bitops.h @@ -0,0 +1,294 @@ +/* $NetBSD: bitops.h,v 1.7 2010/03/21 14:28:15 christos Exp $ */ + +/*- + * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas and Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_BITOPS_H_ +#define _SYS_BITOPS_H_ + +#include + +/* + * Find First Set functions + */ +#ifndef ffs32 +static __inline int __unused +ffs32(uint32_t _n) +{ + int _v; + + if (!_n) + return 0; + + _v = 1; + if ((_n & 0x0000FFFFU) == 0) { + _n >>= 16; + _v += 16; + } + if ((_n & 0x000000FFU) == 0) { + _n >>= 8; + _v += 8; + } + if ((_n & 0x0000000FU) == 0) { + _n >>= 4; + _v += 4; + } + if ((_n & 0x00000003U) == 0) { + _n >>= 2; + _v += 2; + } + if ((_n & 0x00000001U) == 0) { + _n >>= 1; + _v += 1; + } + return _v; +} +#endif + +#ifndef ffs64 +static __inline int __unused +ffs64(uint64_t _n) +{ + int _v; + + if (!_n) + return 0; + + _v = 1; + if ((_n & 0x00000000FFFFFFFFULL) == 0) { + _n >>= 32; + _v += 32; + } + if ((_n & 0x000000000000FFFFULL) == 0) { + _n >>= 16; + _v += 16; + } + if ((_n & 0x00000000000000FFULL) == 0) { + _n >>= 8; + _v += 8; + } + if ((_n & 0x000000000000000FULL) == 0) { + _n >>= 4; + _v += 4; + } + if ((_n & 0x0000000000000003ULL) == 0) { + _n >>= 2; + _v += 2; + } + if ((_n & 0x0000000000000001ULL) == 0) { + _n >>= 1; + _v += 1; + } + return _v; +} +#endif + +/* + * Find Last Set functions + */ +#ifndef fls32 +static __inline int __unused +fls32(uint32_t _n) +{ + int _v; + + if (!_n) + return 0; + + _v = 32; + if ((_n & 0xFFFF0000U) == 0) { + _n <<= 16; + _v -= 16; + } + if ((_n & 0xFF000000U) == 0) { + _n <<= 8; + _v -= 8; + } + if ((_n & 0xF0000000U) == 0) { + _n <<= 4; + _v -= 4; + } + if ((_n & 0xC0000000U) == 0) { + _n <<= 2; + _v -= 2; + } + if ((_n & 0x80000000U) == 0) { + _n <<= 1; + _v -= 1; + } + return _v; +} +#endif + +#ifndef fls64 +static __inline int __unused +fls64(uint64_t _n) +{ + int _v; + + if (!_n) + return 0; + + _v = 64; + if ((_n & 0xFFFFFFFF00000000ULL) == 0) { + _n <<= 32; + _v -= 32; + } + if ((_n & 0xFFFF000000000000ULL) == 0) { + _n <<= 16; + _v -= 16; + } + if ((_n & 0xFF00000000000000ULL) == 0) { + _n <<= 8; + _v -= 8; + } + if ((_n & 0xF000000000000000ULL) == 0) { + _n <<= 4; + _v -= 4; + } + if ((_n & 0xC000000000000000ULL) == 0) { + _n <<= 2; + _v -= 2; + } + if ((_n & 0x8000000000000000ULL) == 0) { + _n <<= 1; + _v -= 1; + } + return _v; +} +#endif + +/* + * Integer logarithm, returns -1 on error. Inspired by the linux + * version written by David Howells. + */ +#define _ilog2_helper(_n, _x) ((_n) & (1ULL << (_x))) ? _x : +#define ilog2(_n) \ +( \ + __builtin_constant_p(_n) ? ( \ + _ilog2_helper(_n, 63) \ + _ilog2_helper(_n, 62) \ + _ilog2_helper(_n, 61) \ + _ilog2_helper(_n, 60) \ + _ilog2_helper(_n, 59) \ + _ilog2_helper(_n, 58) \ + _ilog2_helper(_n, 57) \ + _ilog2_helper(_n, 56) \ + _ilog2_helper(_n, 55) \ + _ilog2_helper(_n, 54) \ + _ilog2_helper(_n, 53) \ + _ilog2_helper(_n, 52) \ + _ilog2_helper(_n, 51) \ + _ilog2_helper(_n, 50) \ + _ilog2_helper(_n, 49) \ + _ilog2_helper(_n, 48) \ + _ilog2_helper(_n, 47) \ + _ilog2_helper(_n, 46) \ + _ilog2_helper(_n, 45) \ + _ilog2_helper(_n, 44) \ + _ilog2_helper(_n, 43) \ + _ilog2_helper(_n, 42) \ + _ilog2_helper(_n, 41) \ + _ilog2_helper(_n, 40) \ + _ilog2_helper(_n, 39) \ + _ilog2_helper(_n, 38) \ + _ilog2_helper(_n, 37) \ + _ilog2_helper(_n, 36) \ + _ilog2_helper(_n, 35) \ + _ilog2_helper(_n, 34) \ + _ilog2_helper(_n, 33) \ + _ilog2_helper(_n, 32) \ + _ilog2_helper(_n, 31) \ + _ilog2_helper(_n, 30) \ + _ilog2_helper(_n, 29) \ + _ilog2_helper(_n, 28) \ + _ilog2_helper(_n, 27) \ + _ilog2_helper(_n, 26) \ + _ilog2_helper(_n, 25) \ + _ilog2_helper(_n, 24) \ + _ilog2_helper(_n, 23) \ + _ilog2_helper(_n, 22) \ + _ilog2_helper(_n, 21) \ + _ilog2_helper(_n, 20) \ + _ilog2_helper(_n, 19) \ + _ilog2_helper(_n, 18) \ + _ilog2_helper(_n, 17) \ + _ilog2_helper(_n, 16) \ + _ilog2_helper(_n, 15) \ + _ilog2_helper(_n, 14) \ + _ilog2_helper(_n, 13) \ + _ilog2_helper(_n, 12) \ + _ilog2_helper(_n, 11) \ + _ilog2_helper(_n, 10) \ + _ilog2_helper(_n, 9) \ + _ilog2_helper(_n, 8) \ + _ilog2_helper(_n, 7) \ + _ilog2_helper(_n, 6) \ + _ilog2_helper(_n, 5) \ + _ilog2_helper(_n, 4) \ + _ilog2_helper(_n, 3) \ + _ilog2_helper(_n, 2) \ + _ilog2_helper(_n, 1) \ + _ilog2_helper(_n, 0) \ + -1) : ((sizeof(_n) >= 4 ? fls64(_n) : fls32(_n)) - 1) \ +) + +static __inline void +fast_divide32_prepare(uint32_t _div, uint32_t * __restrict _m, + uint8_t *__restrict _s1, uint8_t *__restrict _s2) +{ + uint64_t _mt; + int _l; + + _l = fls32(_div - 1); + _mt = 0x100000000ULL * ((1ULL << _l) - _div); + *_m = (uint32_t)(_mt / _div + 1); + *_s1 = (_l > 1) ? 1 : _l; + *_s2 = (_l == 0) ? 0 : _l - 1; +} + +/* ARGSUSED */ +static __inline uint32_t +fast_divide32(uint32_t _v, uint32_t _div, uint32_t _m, uint8_t _s1, + uint8_t _s2) +{ + uint32_t _t; + + _t = (uint32_t)(((uint64_t)_v * _m) >> 32); + return (_t + ((_v - _t) >> _s1)) >> _s2; +} + +static __inline uint32_t +fast_remainder32(uint32_t _v, uint32_t _div, uint32_t _m, uint8_t _s1, + uint8_t _s2) +{ + + return _v - _div * fast_divide32(_v, _div, _m, _s1, _s2); +} + +#endif /* _SYS_BITOPS_H_ */ diff --git a/nbsd_include/sys/bswap.h b/nbsd_include/sys/bswap.h new file mode 100644 index 000000000..c9ea1e988 --- /dev/null +++ b/nbsd_include/sys/bswap.h @@ -0,0 +1,79 @@ +/* $NetBSD: bswap.h,v 1.16 2009/08/08 21:23:15 christos Exp $ */ + +/* Written by Manuel Bouyer. Public domain */ + +#ifndef _SYS_BSWAP_H_ +#define _SYS_BSWAP_H_ + +#ifndef _LOCORE +#include +#include + +#include + +__BEGIN_DECLS +/* Always declare the functions in case their address is taken (etc) */ +#if defined(_KERNEL) || defined(_STANDALONE) || !defined(__BSWAP_RENAME) +uint16_t bswap16(uint16_t) __constfunc; +uint32_t bswap32(uint32_t) __constfunc; +#else +uint16_t bswap16(uint16_t) __RENAME(__bswap16) __constfunc; +uint32_t bswap32(uint32_t) __RENAME(__bswap32) __constfunc; +#endif +uint64_t bswap64(uint64_t) __constfunc; +__END_DECLS + +#if defined(__GNUC__) && defined(__OPTIMIZE__) && !defined(__lint__) + +/* machine/byte_swap.h might have defined inline versions */ +#ifndef __BYTE_SWAP_U64_VARIABLE +#define __BYTE_SWAP_U64_VARIABLE bswap64 +#endif + +#ifndef __BYTE_SWAP_U32_VARIABLE +#define __BYTE_SWAP_U32_VARIABLE bswap32 +#endif + +#ifndef __BYTE_SWAP_U16_VARIABLE +#define __BYTE_SWAP_U16_VARIABLE bswap16 +#endif + +#define __byte_swap_u64_constant(x) \ + (__CAST(uint64_t, \ + ((((x) & 0xff00000000000000ull) >> 56) | \ + (((x) & 0x00ff000000000000ull) >> 40) | \ + (((x) & 0x0000ff0000000000ull) >> 24) | \ + (((x) & 0x000000ff00000000ull) >> 8) | \ + (((x) & 0x00000000ff000000ull) << 8) | \ + (((x) & 0x0000000000ff0000ull) << 24) | \ + (((x) & 0x000000000000ff00ull) << 40) | \ + (((x) & 0x00000000000000ffull) << 56)))) + +#define __byte_swap_u32_constant(x) \ + (__CAST(uint32_t, \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)))) + +#define __byte_swap_u16_constant(x) \ + (__CAST(uint16_t, \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)))) + +#define bswap64(x) \ + (__builtin_constant_p((x)) ? \ + __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x)) + +#define bswap32(x) \ + (__builtin_constant_p((x)) ? \ + __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x)) + +#define bswap16(x) \ + (__builtin_constant_p((x)) ? \ + __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x)) + +#endif /* __GNUC__ && __OPTIMIZE__ */ +#endif /* !_LOCORE */ + +#endif /* !_SYS_BSWAP_H_ */ diff --git a/nbsd_include/sys/cdefs.h b/nbsd_include/sys/cdefs.h new file mode 100644 index 000000000..d4345690a --- /dev/null +++ b/nbsd_include/sys/cdefs.h @@ -0,0 +1,485 @@ +/* $NetBSD: cdefs.h,v 1.81 2010/12/25 22:30:52 joerg Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ + +/* + * Macro to test if we're using a GNU C compiler of a specific vintage + * or later, for e.g. features that appeared in a particular version + * of GNU C. Usage: + * + * #if __GNUC_PREREQ__(major, minor) + * ...cool feature... + * #else + * ...delete feature... + * #endif + */ +#ifdef __GNUC__ +#define __GNUC_PREREQ__(x, y) \ + ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ + (__GNUC__ > (x))) +#else +#define __GNUC_PREREQ__(x, y) 0 +#endif + +#include +#ifdef __ELF__ +#include +#else +#include +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky -- make sure you don't put spaces + * in between its arguments. __CONCAT can also concatenate double-quoted + * strings produced by the __STRING macro, but this only works with ANSI C. + */ + +#define ___STRING(x) __STRING(x) +#define ___CONCAT(x,y) __CONCAT(x,y) + +#if __STDC__ || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT(x,y) x ## y +#define __STRING(x) #x + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) || defined(__PCC__) +#define __inline inline /* convert to C++/C99 keyword */ +#else +#if !defined(__GNUC__) && !defined(__lint__) +#define __inline /* delete GCC keyword */ +#endif /* !__GNUC__ && !__lint__ */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#ifndef __GNUC__ +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +#endif /* !__GNUC__ */ + +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * Programs using the ANSI C keywords const, inline etc. as normal + * identifiers should define -DNO_ANSI_KEYWORDS. + */ +#ifndef NO_ANSI_KEYWORDS +#define const __const /* convert ANSI C keywords */ +#define inline __inline +#define signed __signed +#define volatile __volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * Used for internal auditing of the NetBSD source tree. + */ +#ifdef __AUDIT__ +#define __aconst __const +#else +#define __aconst +#endif + +/* + * The following macro is used to remove const cast-away warnings + * from gcc -Wcast-qual; it should be used with caution because it + * can hide valid errors; in particular most valid uses are in + * situations where the API requires it, not to cast away string + * constants. We don't use *intptr_t on purpose here and we are + * explicit about unsigned long so that we don't have additional + * dependencies. + */ +#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) + +/* + * The following macro is used to remove the volatile cast-away warnings + * from gcc -Wcast-qual; as above it should be used with caution + * because it can hide valid errors or warnings. Valid uses include + * making it possible to pass a volatile pointer to memset(). + * For the same reasons as above, we use unsigned long and not intptr_t. + */ +#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) + +/* + * GCC2 provides __extension__ to suppress warnings for various GNU C + * language extensions under "-ansi -pedantic". + */ +#if !__GNUC_PREREQ__(2, 0) +#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ +#endif + +/* + * GCC1 and some versions of GCC2 declare dead (non-returning) and + * pure (no side effects) functions using "volatile" and "const"; + * unfortunately, these then cause warnings under "-ansi -pedantic". + * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of + * these work for GNU C++ (modulo a slight glitch in the C++ grammar + * in the distribution version of 2.5.5). + * + * GCC defines a pure function as depending only on its arguments and + * global variables. Typical examples are strlen and sqrt. + * + * GCC defines a const function as depending only on its arguments. + * Therefore calling a const function again with identical arguments + * will always produce the same result. + * + * Rounding modes for floating point operations are considered global + * variables and prevent sqrt from being a const function. + * + * Calls to const functions can be optimised away and moved around + * without limitations. + */ +#if !__GNUC_PREREQ__(2, 0) +#define __attribute__(x) +#endif + +#if __GNUC_PREREQ__(2, 5) +#define __dead __attribute__((__noreturn__)) +#elif defined(__GNUC__) +#define __dead __volatile +#else +#define __dead +#endif + +#if __GNUC_PREREQ__(2, 96) +#define __pure __attribute__((__pure__)) +#elif defined(__GNUC__) +#define __pure __const +#else +#define __pure +#endif + +#if __GNUC_PREREQ__(2, 5) +#define __constfunc __attribute__((__const__)) +#else +#define __constfunc +#endif + +#if __GNUC_PREREQ__(3, 0) +#define __noinline __attribute__((__noinline__)) +#else +#define __noinline /* nothing */ +#endif + +#if __GNUC_PREREQ__(2, 7) +#define __unused __attribute__((__unused__)) +#else +#define __unused /* delete */ +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __used __attribute__((__used__)) +#else +#define __used __unused +#endif + +#if defined(__cplusplus) +#define __BEGIN_EXTERN_C extern "C" { +#define __END_EXTERN_C } +#define __static_cast(x,y) static_cast(y) +#else +#define __BEGIN_EXTERN_C +#define __END_EXTERN_C +#define __static_cast(x,y) (x)y +#endif + +#if __GNUC_PREREQ__(4, 0) +# define __dso_public __attribute__((__visibility__("default"))) +# define __dso_hidden __attribute__((__visibility__("hidden"))) +# define __BEGIN_PUBLIC_DECLS \ + _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C +# define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") +# define __BEGIN_HIDDEN_DECLS \ + _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C +# define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") +#else +# define __dso_public +# define __dso_hidden +# define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C +# define __END_PUBLIC_DECLS __END_EXTERN_C +# define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C +# define __END_HIDDEN_DECLS __END_EXTERN_C +#endif + +#define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS +#define __END_DECLS __END_PUBLIC_DECLS + +/* + * Non-static C99 inline functions are optional bodies. They don't + * create global symbols if not used, but can be replaced if desirable. + * This differs from the behavior of GCC before version 4.3. The nearest + * equivalent for older GCC is `extern inline'. For newer GCC, use the + * gnu_inline attribute additionally to get the old behavior. + * + * For C99 compilers other than GCC, the C99 behavior is expected. + */ +#if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) +#define __c99inline extern __attribute__((__gnu_inline__)) __inline +#elif defined(__GNUC__) +#define __c99inline extern __inline +#elif defined(__STDC_VERSION__) +#define __c99inline __inline +#endif + +#if defined(__lint__) +#define __packed __packed +#define __aligned(x) /* delete */ +#define __section(x) /* delete */ +#elif __GNUC_PREREQ__(2, 7) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#elif defined(__PCC__) +#define __packed _Pragma("packed 1") +#define __aligned(x) _Pragma("aligned " __STRING(x)) +#define __section(x) _Pragma("section " ## x) +#else +#define __packed error: no __packed for this compiler +#define __aligned(x) error: no __aligned for this compiler +#define __section(x) error: no __section for this compiler +#endif + +/* + * C99 defines the restrict type qualifier keyword, which was made available + * in GCC 2.92. + */ +#if defined(__lint__) +#define __restrict /* delete __restrict when not supported */ +#elif __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !__GNUC_PREREQ__(2, 92) +#define __restrict /* delete __restrict when not supported */ +#endif + +/* + * C99 defines __func__ predefined identifier, which was made available + * in GCC 2.95. + */ +#if !(__STDC_VERSION__ >= 199901L) +#if __GNUC_PREREQ__(2, 6) +#define __func__ __PRETTY_FUNCTION__ +#elif __GNUC_PREREQ__(2, 4) +#define __func__ __FUNCTION__ +#else +#define __func__ "" +#endif +#endif /* !(__STDC_VERSION__ >= 199901L) */ + +#if defined(_KERNEL) +#if defined(NO_KERNEL_RCSIDS) +#undef __KERNEL_RCSID +#define __KERNEL_RCSID(_n, _s) /* nothing */ +#endif /* NO_KERNEL_RCSIDS */ +#endif /* _KERNEL */ + +#if !defined(_STANDALONE) && !defined(_KERNEL) +#if defined(__GNUC__) || defined(__PCC__) +#define __RENAME(x) ___RENAME(x) +#else +#ifdef __lint__ +#define __RENAME(x) __symbolrename(x) +#else +#error "No function renaming possible" +#endif /* __lint__ */ +#endif /* __GNUC__ */ +#else /* _STANDALONE || _KERNEL */ +#define __RENAME(x) no renaming in kernel or standalone environment +#endif + +/* + * A barrier to stop the optimizer from moving code or assume live + * register values. This is gcc specific, the version is more or less + * arbitrary, might work with older compilers. + */ +#if __GNUC_PREREQ__(2, 95) +#define __insn_barrier() __asm __volatile("":::"memory") +#else +#define __insn_barrier() /* */ +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to use this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect((exp) != 0, 1) +#define __predict_false(exp) __builtin_expect((exp) != 0, 0) +#else +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if __GNUC_PREREQ__(2, 7) +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) +#else +#define __printflike(fmtarg, firstvararg) /* nothing */ +#define __scanflike(fmtarg, firstvararg) /* nothing */ +#define __format_arg(fmtarg) /* nothing */ +#endif + +/* + * Macros for manipulating "link sets". Link sets are arrays of pointers + * to objects, which are gathered up by the linker. + * + * Object format-specific code has provided us with the following macros: + * + * __link_set_add_text(set, sym) + * Add a reference to the .text symbol `sym' to `set'. + * + * __link_set_add_rodata(set, sym) + * Add a reference to the .rodata symbol `sym' to `set'. + * + * __link_set_add_data(set, sym) + * Add a reference to the .data symbol `sym' to `set'. + * + * __link_set_add_bss(set, sym) + * Add a reference to the .bss symbol `sym' to `set'. + * + * __link_set_decl(set, ptype) + * Provide an extern declaration of the set `set', which + * contains an array of the pointer type `ptype'. This + * macro must be used by any code which wishes to reference + * the elements of a link set. + * + * __link_set_start(set) + * This points to the first slot in the link set. + * + * __link_set_end(set) + * This points to the (non-existent) slot after the last + * entry in the link set. + * + * __link_set_count(set) + * Count the number of entries in link set `set'. + * + * In addition, we provide the following macros for accessing link sets: + * + * __link_set_foreach(pvar, set) + * Iterate over the link set `set'. Because a link set is + * an array of pointers, pvar must be declared as "type **pvar", + * and the actual entry accessed as "*pvar". + * + * __link_set_entry(set, idx) + * Access the link set entry at index `idx' from set `set'. + */ +#define __link_set_foreach(pvar, set) \ + for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) + +#define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) + +/* + * Return the number of elements in a statically-allocated array, + * __x. + */ +#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) + +/* __BIT(n): nth bit, where __BIT(0) == 0x1. */ +#define __BIT(__n) \ + (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << (uintmax_t)(__n))) + +/* __BITS(m, n): bits m through n, m < n. */ +#define __BITS(__m, __n) \ + ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) + +/* find least significant bit that is set */ +#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) + +#define __PRIuBIT PRIuMAX +#define __PRIuBITS __PRIuBIT + +#define __PRIxBIT PRIxMAX +#define __PRIxBITS __PRIxBIT + +#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) +#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) +#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) + +/* + * Only to be used in other headers that are included from both c or c++ + * NOT to be used in code. + */ +#ifdef __cplusplus +#define __CAST(__dt, __st) static_cast<__dt>(__st) +#else +#define __CAST(__dt, __st) ((__dt)(__st)) +#endif + +#endif /* !_SYS_CDEFS_H_ */ diff --git a/nbsd_include/sys/cdefs_aout.h b/nbsd_include/sys/cdefs_aout.h new file mode 100644 index 000000000..b9035cd28 --- /dev/null +++ b/nbsd_include/sys/cdefs_aout.h @@ -0,0 +1,131 @@ +/* $NetBSD: cdefs_aout.h,v 1.20 2006/05/18 17:55:38 christos Exp $ */ + +/* + * Written by J.T. Conklin 01/17/95. + * Public domain. + */ + +#ifndef _SYS_CDEFS_AOUT_H_ +#define _SYS_CDEFS_AOUT_H_ + +#define _C_LABEL(x) __CONCAT(_,x) +#define _C_LABEL_STRING(x) "_"x + +#if __STDC__ +#define ___RENAME(x) __asm(___STRING(_C_LABEL(x))) +#else +#define ___RENAME(x) ____RENAME(_/**/x) +#define ____RENAME(x) __asm(___STRING(x)) +#endif + +#define __indr_reference(sym,alias) /* nada, since we do weak refs */ + +#ifdef __GNUC__ +#if __STDC__ +#define __strong_alias(alias,sym) \ + __asm(".global " _C_LABEL_STRING(#alias) "\n" \ + _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym)); +#define __weak_alias(alias,sym) \ + __asm(".weak " _C_LABEL_STRING(#alias) "\n" \ + _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym)); + +/* Do not use __weak_extern, use __weak_reference instead */ +#define __weak_extern(sym) \ + __asm(".weak " _C_LABEL_STRING(#sym)); + +#if __GNUC_PREREQ__(4, 0) +#define __weak_reference(sym) __attribute__((__weakref__)) +#else +#define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym)) +#endif + +#define __warn_references(sym,msg) \ + __asm(".stabs \"" msg "\",30,0,0,0"); \ + __asm(".stabs \"_" #sym "\",1,0,0,0"); +#else /* __STDC__ */ +#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym) +#define ___weak_alias(alias,sym) \ + __asm(".weak alias\nalias = sym"); +/* Do not use __weak_extern, use __weak_reference instead */ +#define __weak_extern(sym) ___weak_extern(_/**/sym) +#define ___weak_extern(sym) \ + __asm(".weak sym"); + +#if __GNUC_PREREQ__(4, 0) +#define __weak_reference(sym) __attribute__((__weakref__)) +#else +#define ___weak_reference(sym) ; __asm(".weak sym"); +#define __weak_reference(sym) ___weak_reference(_/**/sym) +#endif + +#define __warn_references(sym,msg) \ + __asm(".stabs msg,30,0,0,0"); \ + __asm(".stabs \"_/**/sym\",1,0,0,0"); +#endif /* __STDC__ */ +#else /* __GNUC__ */ +#define __warn_references(sym,msg) +#endif /* __GNUC__ */ + +#if defined(__sh__) /* XXX SH COFF */ +#undef __indr_reference(sym,alias) +#undef __warn_references(sym,msg) +#define __warn_references(sym,msg) +#endif + +#define __IDSTRING(_n,_s) \ + __asm(".data ; .asciz \"" _s "\" ; .text") + +#undef __KERNEL_RCSID + +#define __RCSID(_s) __IDSTRING(rcsid,_s) +#define __SCCSID(_s) +#define __SCCSID2(_s) +#if 0 /* XXX userland __COPYRIGHTs have \ns in them */ +#define __COPYRIGHT(_s) __IDSTRING(copyright,_s) +#else +#define __COPYRIGHT(_s) \ + static const char copyright[] __attribute__((__unused__)) = _s +#endif + +#if defined(USE_KERNEL_RCSIDS) || !defined(_KERNEL) +#define __KERNEL_RCSID(_n,_s) __IDSTRING(__CONCAT(rcsid,_n),_s) +#else +#define __KERNEL_RCSID(_n,_s) +#endif +#define __KERNEL_SCCSID(_n,_s) +#define __KERNEL_COPYRIGHT(_n, _s) __IDSTRING(__CONCAT(copyright,_n),_s) + +#ifndef __lint__ +#define __link_set_make_entry(set, sym, type) \ + static void const * const \ + __link_set_##set##_sym_##sym __used = &sym; \ + __asm(".stabs \"___link_set_" #set "\", " #type ", 0, 0, _" #sym) +#else +#define __link_set_make_entry(set, sym, type) \ + extern void const * const __link_set_##set##_sym_##sym +#endif /* __lint__ */ + +#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym, 23) +#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym, 23) +#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym, 25) +#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym, 27) + +#ifdef __minix +/* GNU binutils 2.x doesn't support a.out link sets. We need to workaround + * this by explicitely creating the N_SETV structure. */ +#define __link_set_decl(set, ptype) +#else +#define __link_set_decl(set, ptype) \ +extern struct { \ + int __ls_length; \ + ptype *__ls_items[1]; \ +} __link_set_##set +#endif /* !__minix */ + +#define __link_set_start(set) (&(__link_set_##set).__ls_items[0]) +#define __link_set_end(set) \ + (&(__link_set_##set).__ls_items[(__link_set_##set).__ls_length]) + +#define __link_set_count(set) ((__link_set_##set).__ls_length) + +#endif /* !_SYS_CDEFS_AOUT_H_ */ diff --git a/nbsd_include/sys/ctype_bits.h b/nbsd_include/sys/ctype_bits.h new file mode 100644 index 000000000..2be1899b0 --- /dev/null +++ b/nbsd_include/sys/ctype_bits.h @@ -0,0 +1,56 @@ +/* $NetBSD: ctype_bits.h,v 1.2 2010/12/14 02:28:57 joerg Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ctype.h 5.3 (Berkeley) 4/3/91 + * NetBSD: ctype.h,v 1.30 2010/05/22 06:38:15 tnozaki Exp + */ + +#ifndef _SYS_CTYPE_BITS_H_ +#define _SYS_CTYPE_BITS_H_ + +#define _CTYPE_U 0x01 +#define _CTYPE_L 0x02 +#define _CTYPE_N 0x04 +#define _CTYPE_S 0x08 +#define _CTYPE_P 0x10 +#define _CTYPE_C 0x20 +#define _CTYPE_X 0x40 +#define _CTYPE_B 0x80 + +extern const unsigned char *_ctype_; +extern const short *_tolower_tab_; +extern const short *_toupper_tab_; + +#endif /* !_SYS_CTYPE_BITS_H_ */ diff --git a/nbsd_include/sys/ctype_inline.h b/nbsd_include/sys/ctype_inline.h new file mode 100644 index 000000000..105cdcb2c --- /dev/null +++ b/nbsd_include/sys/ctype_inline.h @@ -0,0 +1,82 @@ +/* $NetBSD: ctype_inline.h,v 1.2 2010/12/14 02:28:57 joerg Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ctype.h 5.3 (Berkeley) 4/3/91 + * NetBSD: ctype.h,v 1.30 2010/05/22 06:38:15 tnozaki Exp + */ + +#ifndef _CTYPE_INLINE_H_ +#define _CTYPE_INLINE_H_ + +#include +#include + +#include + +#define isdigit(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_N)) +#define islower(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_L)) +#define isspace(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_S)) +#define ispunct(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_P)) +#define isupper(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_U)) +#define isalpha(c) ((int)((_ctype_ + 1)[(c)] & (_CTYPE_U|_CTYPE_L))) +#define isxdigit(c) ((int)((_ctype_ + 1)[(c)] & (_CTYPE_N|_CTYPE_X))) +#define isalnum(c) ((int)((_ctype_ + 1)[(c)] & (_CTYPE_U|_CTYPE_L|_CTYPE_N))) +#define isprint(c) ((int)((_ctype_ + 1)[(c)] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))) +#define isgraph(c) ((int)((_ctype_ + 1)[(c)] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))) +#define iscntrl(c) ((int)((_ctype_ + 1)[(c)] & _CTYPE_C)) +#define tolower(c) ((int)((_tolower_tab_ + 1)[(c)])) +#define toupper(c) ((int)((_toupper_tab_ + 1)[(c)])) + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#define isascii(c) ((unsigned)(c) <= 0177) +#define toascii(c) ((c) & 0177) +#define _tolower(c) ((c) - 'A' + 'a') +#define _toupper(c) ((c) - 'a' + 'A') +#endif + +#if defined(_ISO_C99_SOURCE) || (_POSIX_C_SOURCE - 0) > 200112L || \ + (_XOPEN_SOURCE - 0) > 600 || defined(_NETBSD_SOURCE) + +/* + * isblank() is implemented as C function, due to insufficient bitwidth in + * _ctype_. Note that _B does not mean isblank - it means isprint && !isgraph. + */ +#if 0 +#define isblank(c) ((int)((_ctype_ + 1)[(c)] & _B)) +#endif + +#endif + +#endif /* !_CTYPE_INLINE_H_ */ diff --git a/nbsd_include/sys/dirent.h b/nbsd_include/sys/dirent.h new file mode 100644 index 000000000..5129c7d55 --- /dev/null +++ b/nbsd_include/sys/dirent.h @@ -0,0 +1,66 @@ +#ifndef _SYS_DIRENT_H_ +#define _SYS_DIRENT_H_ + +#include + +/* Redefine d_ino here. */ +#define d_ino d_fileno + +/* + * The dirent structure defines the format of directory entries returned by + * the getdents(2) system call. + */ + +struct dirent { /* Largest entry (8 slots) */ + ino_t d_ino; /* I-node number */ + off_t d_off; /* Offset in directory */ + unsigned short d_reclen; /* Length of this record */ + char d_name[1]; /* Null terminated name */ +}; + +#define _DIRENT_NAME_LEN 61 /* Backward compatibility with Minix. */ +#if defined(_NETBSD_SOURCE) +#define MAXNAMLEN _DIRENT_NAME_LEN +#endif + + +/* + * The _DIRENT_ALIGN macro returns the alignment of struct dirent. It + * is used to check for bogus pointers and to calculate in advance the + * memory required to store a dirent. + * Unfortunately Minix doesn't use any standard alignment in dirents + * at the moment, so, in order to calculate a safe dirent size, we add + * an arbitrary number of bytes to the structure (_DIRENT_PAD), and we + * set _DIRENT_ALIGN to zero to pass the pointers checks. + * Please, FIXME. + */ +#define _DIRENT_ALIGN(dp) 0 +#define _DIRENT_PAD 64 +/* + * The _DIRENT_NAMEOFF macro returns the offset of the d_name field in + * struct dirent + */ +#define _DIRENT_NAMEOFF(dp) \ + ((char *)(void *)&(dp)->d_name - (char *)(void *)dp) +/* + * The _DIRENT_RECLEN macro gives the minimum record length which will hold + * a name of size "namlen". + */ +#define _DIRENT_RECLEN(dp, namlen) \ + ((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_PAD + _DIRENT_ALIGN(dp)) & \ + ~_DIRENT_ALIGN(dp)) +/* + * The _DIRENT_SIZE macro returns the minimum record length required for + * name name stored in the current record. + */ +#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, strlen(dp->d_name)) +/* + * The _DIRENT_NEXT macro advances to the next dirent record. + */ +#define _DIRENT_NEXT(dp) ((void *)((char *)(void *)(dp) + (dp)->d_reclen)) +/* + * The _DIRENT_MINSIZE returns the size of an empty (invalid) record. + */ +#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0) + +#endif /* !_SYS_DIRENT_H_ */ diff --git a/nbsd_include/sys/endian.h b/nbsd_include/sys/endian.h new file mode 100644 index 000000000..ac5418c15 --- /dev/null +++ b/nbsd_include/sys/endian.h @@ -0,0 +1,340 @@ +/* $NetBSD: endian.h,v 1.28 2009/08/08 21:23:15 christos Exp $ */ + +/* + * Copyright (c) 1987, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)endian.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#include + +/* + * Definitions for byte order, according to byte significance from low + * address to high. + */ +#define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ + + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#ifndef _LOCORE + +/* C-family endian-ness definitions */ + +#include +#include +#include + +#ifndef in_addr_t +typedef __in_addr_t in_addr_t; +#define in_addr_t __in_addr_t +#endif + +#ifndef in_port_t +typedef __in_port_t in_port_t; +#define in_port_t __in_port_t +#endif + +__BEGIN_DECLS +uint32_t htonl(uint32_t) __constfunc; +uint16_t htons(uint16_t) __constfunc; +uint32_t ntohl(uint32_t) __constfunc; +uint16_t ntohs(uint16_t) __constfunc; +__END_DECLS + +#endif /* !_LOCORE */ +#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ + + +#include + +/* + * Define the order of 32-bit words in 64-bit words. + */ +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 +#endif + +#if _BYTE_ORDER == _BIG_ENDIAN +#define _QUAD_HIGHWORD 0 +#define _QUAD_LOWWORD 1 +#endif + + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +/* + * Traditional names for byteorder. These are defined as the numeric + * sequences so that third party code can "#define XXX_ENDIAN" and not + * cause errors. + */ +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ +#define BYTE_ORDER _BYTE_ORDER + +#ifndef _LOCORE + +#include + +/* + * Macros for network/external number representation conversion. + */ +#if BYTE_ORDER == BIG_ENDIAN && !defined(__lint__) +#define ntohl(x) (x) +#define ntohs(x) (x) +#define htonl(x) (x) +#define htons(x) (x) + +#define NTOHL(x) (void) (x) +#define NTOHS(x) (void) (x) +#define HTONL(x) (void) (x) +#define HTONS(x) (void) (x) + +#else /* LITTLE_ENDIAN || !defined(__lint__) */ + +#define ntohl(x) bswap32(__CAST(uint32_t, (x))) +#define ntohs(x) bswap16(__CAST(uint16_t, (x))) +#define htonl(x) bswap32(__CAST(uint32_t, (x))) +#define htons(x) bswap16(__CAST(uint16_t, (x))) + +#define NTOHL(x) (x) = ntohl(__CAST(uint32_t, (x))) +#define NTOHS(x) (x) = ntohs(__CAST(uint16_t, (x))) +#define HTONL(x) (x) = htonl(__CAST(uint32_t, (x))) +#define HTONS(x) (x) = htons(__CAST(uint16_t, (x))) +#endif /* LITTLE_ENDIAN || !defined(__lint__) */ + +/* + * Macros to convert to a specific endianness. + */ + +#if BYTE_ORDER == BIG_ENDIAN + +#define htobe16(x) (x) +#define htobe32(x) (x) +#define htobe64(x) (x) +#define htole16(x) bswap16(__CAST(uint16_t, (x))) +#define htole32(x) bswap32(__CAST(uint32_t, (x))) +#define htole64(x) bswap64(__CAST(uint64_t, (x))) + +#define HTOBE16(x) __CAST(void, (x)) +#define HTOBE32(x) __CAST(void, (x)) +#define HTOBE64(x) __CAST(void, (x)) +#define HTOLE16(x) (x) = bswap16(__CAST(uint16_t, (x))) +#define HTOLE32(x) (x) = bswap32(__CAST(uint32_t, (x))) +#define HTOLE64(x) (x) = bswap64(__CAST(uint64_t, (x))) + +#else /* LITTLE_ENDIAN */ + +#define htobe16(x) bswap16(__CAST(uint16_t, (x))) +#define htobe32(x) bswap32(__CAST(uint32_t, (x))) +#define htobe64(x) bswap64(__CAST(uint64_t, (x))) +#define htole16(x) (x) +#define htole32(x) (x) +#define htole64(x) (x) + +#define HTOBE16(x) (x) = bswap16(__CAST(uint16_t, (x))) +#define HTOBE32(x) (x) = bswap32(__CAST(uint32_t, (x))) +#define HTOBE64(x) (x) = bswap64(__CAST(uint64_t, (x))) +#define HTOLE16(x) __CAST(void, (x)) +#define HTOLE32(x) __CAST(void, (x)) +#define HTOLE64(x) __CAST(void, (x)) + +#endif /* LITTLE_ENDIAN */ + +#define be16toh(x) htobe16(x) +#define be32toh(x) htobe32(x) +#define be64toh(x) htobe64(x) +#define le16toh(x) htole16(x) +#define le32toh(x) htole32(x) +#define le64toh(x) htole64(x) + +#define BE16TOH(x) HTOBE16(x) +#define BE32TOH(x) HTOBE32(x) +#define BE64TOH(x) HTOBE64(x) +#define LE16TOH(x) HTOLE16(x) +#define LE32TOH(x) HTOLE32(x) +#define LE64TOH(x) HTOLE64(x) + +/* + * Routines to encode/decode big- and little-endian multi-octet values + * to/from an octet stream. + */ + +#if __GNUC_PREREQ__(2, 95) + +#define __GEN_ENDIAN_ENC(bits, endian) \ +static __inline __unused void \ +endian ## bits ## enc(void *dst, uint ## bits ## _t u) \ +{ \ + u = hto ## endian ## bits (u); \ + __builtin_memcpy(dst, &u, sizeof(u)); \ +} + +__GEN_ENDIAN_ENC(16, be) +__GEN_ENDIAN_ENC(32, be) +__GEN_ENDIAN_ENC(64, be) +__GEN_ENDIAN_ENC(16, le) +__GEN_ENDIAN_ENC(32, le) +__GEN_ENDIAN_ENC(64, le) +#undef __GEN_ENDIAN_ENC + +#define __GEN_ENDIAN_DEC(bits, endian) \ +static __inline __unused uint ## bits ## _t \ +endian ## bits ## dec(const void *buf) \ +{ \ + uint ## bits ## _t u; \ + __builtin_memcpy(&u, buf, sizeof(u)); \ + return endian ## bits ## toh (u); \ +} + +__GEN_ENDIAN_DEC(16, be) +__GEN_ENDIAN_DEC(32, be) +__GEN_ENDIAN_DEC(64, be) +__GEN_ENDIAN_DEC(16, le) +__GEN_ENDIAN_DEC(32, le) +__GEN_ENDIAN_DEC(64, le) +#undef __GEN_ENDIAN_DEC + +#else /* !(GCC >= 2.95) */ + +static __inline void __unused +be16enc(void *buf, uint16_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, ((__CAST(unsigned, u) >> 8) & 0xff)); + p[1] = __CAST(uint8_t, (u & 0xff)); +} + +static __inline void __unused +le16enc(void *buf, uint16_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, (u & 0xff)); + p[1] = __CAST(uint8_t, ((__CAST(unsigned, u) >> 8) & 0xff)); +} + +static __inline uint16_t __unused +be16dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return __CAST(uint16_t, ((p[0] << 8) | p[1])); +} + +static __inline uint16_t __unused +le16dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return __CAST(uint16_t, ((p[1] << 8) | p[0])); +} + +static __inline void __unused +be32enc(void *buf, uint32_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, ((u >> 24) & 0xff)); + p[1] = __CAST(uint8_t, ((u >> 16) & 0xff)); + p[2] = __CAST(uint8_t, ((u >> 8) & 0xff)); + p[3] = __CAST(uint8_t, (u & 0xff)); +} + +static __inline void __unused +le32enc(void *buf, uint32_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + p[0] = __CAST(uint8_t, (u & 0xff)); + p[1] = __CAST(uint8_t, ((u >> 8) & 0xff)); + p[2] = __CAST(uint8_t, ((u >> 16) & 0xff)); + p[3] = __CAST(uint8_t, ((u >> 24) & 0xff)); +} + +static __inline uint32_t __unused +be32dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); +} + +static __inline uint32_t __unused +le32dec(const void *buf) +{ + const uint8_t *p = __CAST(const uint8_t *, buf); + + return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); +} + +static __inline void __unused +be64enc(void *buf, uint64_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + be32enc(p, __CAST(uint32_t, (u >> 32))); + be32enc(p + 4, __CAST(uint32_t, (u & 0xffffffffULL))); +} + +static __inline void __unused +le64enc(void *buf, uint64_t u) +{ + uint8_t *p = __CAST(uint8_t *, buf); + + le32enc(p, __CAST(uint32_t, (u & 0xffffffffULL))); + le32enc(p + 4, __CAST(uint32_t, (u >> 32))); +} + +static __inline uint64_t __unused +be64dec(const void *buf) +{ + const uint8_t *p = (const uint8_t *)buf; + + return ((__CAST(uint64_t, be32dec(p)) << 32) | be32dec(p + 4)); +} + +static __inline uint64_t __unused +le64dec(const void *buf) +{ + const uint8_t *p = (const uint8_t *)buf; + + return (le32dec(p) | (__CAST(uint64_t, le32dec(p + 4)) << 32)); +} + +#endif /* GCC >= 2.95 */ + +#endif /* !_LOCORE */ +#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ +#endif /* !_SYS_ENDIAN_H_ */ diff --git a/nbsd_include/sys/errno.h b/nbsd_include/sys/errno.h new file mode 100644 index 000000000..8b4b966dd --- /dev/null +++ b/nbsd_include/sys/errno.h @@ -0,0 +1,173 @@ +/* The header defines the numbers of the various errors that can + * occur during program execution. They are visible to user programs and + * should be small positive integers. However, they are also used within + * MINIX, where they must be negative. For example, the READ system call is + * executed internally by calling do_read(). This function returns either a + * (negative) error number or a (positive) number of bytes actually read. + * + * To solve the problem of having the error numbers be negative inside the + * the system and positive outside, the following mechanism is used. All the + * definitions are are the form: + * + * EPERM (_SIGN 1 ) + * + * If the macro _SYSTEM is defined, then _SIGN is set to "-", otherwise it is + * set to "". Thus when compiling the operating system, the macro _SYSTEM + * will be defined, setting EPERM to (- 1), whereas when when this + * file is included in an ordinary user program, EPERM has the value ( 1). + */ + +#ifndef _ERRNO_H /* check if is already included */ +# define _ERRNO_H /* it is not included; note that fact */ + +/* Now define _SIGN as "" or "-" depending on _SYSTEM. */ +#ifdef _SYSTEM +# define _SIGN - +# define OK 0 +#else +# define _SIGN +#endif + + + +#define EGENERIC (_SIGN 99 ) /* generic error */ +#define EPERM (_SIGN 1 ) /* operation not permitted */ +#define ENOENT (_SIGN 2 ) /* no such file or directory */ +#define ESRCH (_SIGN 3 ) /* no such process */ +#define EINTR (_SIGN 4 ) /* interrupted function call */ +#define EIO (_SIGN 5 ) /* input/output error */ +#define ENXIO (_SIGN 6 ) /* no such device or address */ +#define E2BIG (_SIGN 7 ) /* arg list too long */ +#define ENOEXEC (_SIGN 8 ) /* exec format error */ +#define EBADF (_SIGN 9 ) /* bad file descriptor */ +#define ECHILD (_SIGN 10 ) /* no child process */ +#define EAGAIN (_SIGN 11 ) /* resource temporarily unavailable */ +#define ENOMEM (_SIGN 12 ) /* not enough space */ +#define EACCES (_SIGN 13 ) /* permission denied */ +#define EFAULT (_SIGN 14 ) /* bad address */ +#define ENOTBLK (_SIGN 15 ) /* Extension: not a block special file */ +#define EBUSY (_SIGN 16 ) /* resource busy */ +#define EEXIST (_SIGN 17 ) /* file exists */ +#define EXDEV (_SIGN 18 ) /* improper link */ +#define ENODEV (_SIGN 19 ) /* no such device */ +#define ENOTDIR (_SIGN 20 ) /* not a directory */ +#define EISDIR (_SIGN 21 ) /* is a directory */ +#define EINVAL (_SIGN 22 ) /* invalid argument */ +#define ENFILE (_SIGN 23 ) /* too many open files in system */ +#define EMFILE (_SIGN 24 ) /* too many open files */ +#define ENOTTY (_SIGN 25 ) /* inappropriate I/O control operation */ +#define ETXTBSY (_SIGN 26 ) /* no longer used */ +#define EFBIG (_SIGN 27 ) /* file too large */ +#define ENOSPC (_SIGN 28 ) /* no space left on device */ +#define ESPIPE (_SIGN 29 ) /* invalid seek */ +#define EROFS (_SIGN 30 ) /* read-only file system */ +#define EMLINK (_SIGN 31 ) /* too many links */ +#define EPIPE (_SIGN 32 ) /* broken pipe */ +#define EDOM (_SIGN 33 ) /* domain error (from ANSI C std ) */ +#define ERANGE (_SIGN 34 ) /* result too large (from ANSI C std ) */ +#define EDEADLK (_SIGN 35 ) /* resource deadlock avoided */ +#define ENAMETOOLONG (_SIGN 36 ) /* file name too long */ +#define ENOLCK (_SIGN 37 ) /* no locks available */ +#define ENOSYS (_SIGN 38 ) /* function not implemented */ +#define ENOTEMPTY (_SIGN 39 ) /* directory not empty */ +#define ELOOP (_SIGN 40 ) /* too many levels of symlinks detected */ +#define ERESTART (_SIGN 41 ) /* service restarted */ +#define EIDRM (_SIGN 43 ) /* Identifier removed */ +#define EILSEQ (_SIGN 44 ) /* illegal byte sequence */ +#define ENOMSG (_SIGN 45 ) /* No message of desired type */ +#define EOVERFLOW (_SIGN 46 ) /* Value too large to be stored in data type */ + +/* The following errors relate to networking. */ +#define EPACKSIZE (_SIGN 50 ) /* invalid packet size for some protocol */ +#define ENOBUFS (_SIGN 51 ) /* not enough buffers left */ +#define EBADIOCTL (_SIGN 52 ) /* illegal ioctl for device */ +#define EBADMODE (_SIGN 53 ) /* badmode in ioctl */ +#define EWOULDBLOCK (_SIGN 54 ) /* call would block on nonblocking socket */ +#define ENETUNREACH (_SIGN 55 ) /* network unreachable */ +#define EHOSTUNREACH (_SIGN 56 ) /* host unreachable */ +#define EISCONN (_SIGN 57 ) /* already connected */ +#define EADDRINUSE (_SIGN 58 ) /* address in use */ +#define ECONNREFUSED (_SIGN 59 ) /* connection refused */ +#define ECONNRESET (_SIGN 60 ) /* connection reset */ +#define ETIMEDOUT (_SIGN 61 ) /* connection timed out */ +#define EURG (_SIGN 62 ) /* urgent data present */ +#define ENOURG (_SIGN 63 ) /* no urgent data present */ +#define ENOTCONN (_SIGN 64 ) /* no connection (yet or anymore ) */ +#define ESHUTDOWN (_SIGN 65 ) /* a write call to a shutdown connection */ +#define ENOCONN (_SIGN 66 ) /* no such connection */ +#define EAFNOSUPPORT (_SIGN 67 ) /* address family not supported */ +#define EPROTONOSUPPORT (_SIGN 68 ) /* protocol not supported by AF */ +#define EPROTOTYPE (_SIGN 69 ) /* Protocol wrong type for socket */ +#define EINPROGRESS (_SIGN 70 ) /* Operation now in progress */ +#define EADDRNOTAVAIL (_SIGN 71 ) /* Can't assign requested address */ +#define EALREADY (_SIGN 72 ) /* Connection already in progress */ +#define EMSGSIZE (_SIGN 73 ) /* Message too long */ +#define ENOTSOCK (_SIGN 74 ) /* Socket operation on non-socket */ +#define ENOPROTOOPT (_SIGN 75 ) /* Protocol not available */ +#define EOPNOTSUPP (_SIGN 76 ) /* Operation not supported */ +#define ENOTSUP EOPNOTSUPP /* Not supported */ +#define ENETDOWN (_SIGN 77 ) /* network is down */ +#define ECONNABORTED (_SIGN 78 ) /* Software caused connection abort */ +#define EDESTADDRREQ (_SIGN 79 ) /* Destination address required */ +#define EHOSTDOWN (_SIGN 80 ) /* Host is down */ +#define ENETRESET (_SIGN 81 ) /* Network dropped connection on reset */ +#define ESOCKTNOSUPPORT (_SIGN 82 ) /* Socket type not supported */ +#define EPFNOSUPPORT (_SIGN 83 ) /* Protocol family not supported */ +#define ETOOMANYREFS (_SIGN 84 ) /* Too many references: can't splice */ + +/* The following are not POSIX errors, but they can still happen. + * All of these are generated by the kernel and relate to message passing. + */ +#define ELOCKED (_SIGN 101 ) /* can't send message due to deadlock */ +#define EBADCALL (_SIGN 102 ) /* illegal system call number */ +#define EBADSRCDST (_SIGN 103 ) /* bad source or destination process */ +#define ECALLDENIED (_SIGN 104 ) /* no permission for system call */ +#define EDEADSRCDST (_SIGN 105 ) /* source or destination is not alive */ +#define ENOTREADY (_SIGN 106 ) /* source or destination is not ready */ +#define EBADREQUEST (_SIGN 107 ) /* destination cannot handle request */ +#define ETRAPDENIED (_SIGN 110 ) /* IPC trap not allowed */ +#define EDONTREPLY (_SIGN 201 ) /* pseudo-code: don't send a reply */ + +/* The following errors are NetBSD errors. */ +#define EFTYPE (_SIGN 150 ) /* Inappropriate file type or format */ +#define EAUTH (_SIGN 151 ) /* Authentication error */ +#define ENEEDAUTH (_SIGN 152 ) /* Need authenticator */ +/* Realtime option errors */ +#define ECANCELED (_SIGN 153 ) /* Operation canceled */ + +/* Network File System */ +#define ESTALE (_SIGN 160 ) /* Stale NFS file handle */ +#define EREMOTE (_SIGN 161 ) /* Too many levels of remote in path */ +#define EBADRPC (_SIGN 162 ) /* RPC struct is bad */ +#define ERPCMISMATCH (_SIGN 163 ) /* RPC version wrong */ +#define EPROGUNAVAIL (_SIGN 164 ) /* RPC prog. not avail */ +#define EPROGMISMATCH (_SIGN 165 ) /* Program version wrong */ +#define EPROCUNAVAIL (_SIGN 166 ) /* Bad procedure for program */ + +/* Realtime, XSI STREAMS option errors */ +#define EBADMSG (_SIGN 170 ) /* Bad or Corrupt message */ + +/* quotas & mush */ +#define EPROCLIM (_SIGN 175 ) /* Too many processes */ +#define EUSERS (_SIGN 176 ) /* Too many users */ +#define EDQUOT (_SIGN 177 ) /* Disc quota exceeded */ + +/* Realtime, XSI STREAMS option errors */ +#define EMULTIHOP (_SIGN 180 ) /* Multihop attempted */ +#define ENOLINK (_SIGN 181 ) /* Link has been severed */ +#define EPROTO (_SIGN 182 ) /* Protocol error */ + +/* File system extended attribute errors */ +#define ENOATTR (_SIGN 185 ) /* Attribute not found */ + +/* XSI STREAMS option errors */ +#define ENODATA (_SIGN 190 ) /* No message available */ +#define ENOSR (_SIGN 191 ) /* No STREAM resources */ +#define ENOSTR (_SIGN 192 ) /* Not a STREAM */ +#define ETIME (_SIGN 193 ) /* STREAM ioctl timeout */ + +#define ELAST EDONTREPLY /* Must equal largest errno */ + +/* Here are the numerical values of the error numbers. */ +#define _NERROR 201 /* number of errors */ +#endif /* _ERRNO_H */ diff --git a/nbsd_include/sys/fcntl.h b/nbsd_include/sys/fcntl.h new file mode 100644 index 000000000..373e471c6 --- /dev/null +++ b/nbsd_include/sys/fcntl.h @@ -0,0 +1,137 @@ +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for . + */ +#include +#include +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#include +#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x00000000 /* open for reading only */ +#define O_WRONLY 0x00000001 /* open for writing only */ +#define O_RDWR 0x00000002 /* open for reading and writing */ +#define O_ACCMODE 0x00000003 /* mask for above modes */ + +/* File status flags for open() and fcntl(). POSIX Table 6-5. */ +#define O_APPEND 02000 /* set append mode */ +#define O_NONBLOCK 04000 /* no delay */ +#define O_REOPEN 010000 /* automatically re-open device after driver + * restart + */ + + +#ifndef __minix /* NOT SUPPORTED! */ +#if defined(_NETBSD_SOURCE) +#define O_SHLOCK 0x00000010 /* open with shared file lock */ +#define O_EXLOCK 0x00000020 /* open with exclusive file lock */ +#define O_ASYNC 0x00000040 /* signal pgrp when data ready */ +#endif +#if (_POSIX_C_SOURCE - 0) >= 199309L || \ + (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +#define O_SYNC 0x00000080 /* synchronous writes */ +#endif +#if defined(_NETBSD_SOURCE) +#define O_NOFOLLOW 0x00000100 /* don't follow symlinks on the last */ + /* path component */ +#endif +#endif /* !__minix */ + +/* Oflag values for open(). POSIX Table 6-4. */ +#define O_CREAT 00100 /* creat file if it doesn't exist */ +#define O_EXCL 00200 /* exclusive use flag */ +#define O_NOCTTY 00400 /* do not assign a controlling terminal */ +#define O_TRUNC 01000 /* truncate flag */ + +#ifndef __minix /* NOT SUPPORTED! */ +#if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +#define O_DSYNC 0x00010000 /* write: I/O data completion */ +#define O_RSYNC 0x00020000 /* read: I/O completion as for write */ +#endif + +#if defined(_NETBSD_SOURCE) +#define O_ALT_IO 0x00040000 /* use alternate i/o semantics */ +#define O_DIRECT 0x00080000 /* direct I/O hint */ +#endif +#endif /* !__minix */ + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +/* These values are used for cmd in fcntl(). POSIX Table 6-1. */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#define F_GETLK 5 /* get record locking information */ +#define F_SETLK 6 /* set record locking information */ +#define F_SETLKW 7 /* set record locking info; wait if blocked */ +#define F_FREESP 8 /* free a section of a regular file */ + +/* File descriptor flags used for fcntl(). POSIX Table 6-2. */ +#define FD_CLOEXEC 1 /* close on exec flag for third arg of fcntl */ + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_WRLCK 2 /* exclusive or write lock */ +#define F_UNLCK 3 /* unlock */ + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + short l_type; /* type: F_RDLCK, F_WRLCK, or F_UNLCK */ + short l_whence; /* flag for starting offset */ + off_t l_start; /* relative offset in bytes */ + off_t l_len; /* size; if 0, then until EOF */ + pid_t l_pid; /* process id of the locks' owner */ +}; + +#if defined(_NETBSD_SOURCE) +/* lock operations for flock(2) */ +#define LOCK_SH F_RDLCK /* Shared lock */ +#define LOCK_EX F_WRLCK /* Exclusive lock */ +#define LOCK_NB 0x0080 /* Do not block when locking */ +#define LOCK_UN F_UNLCK /* Unlock */ +#endif + +/* Always ensure that these are consistent with and ! */ +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#include + +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if defined(_NETBSD_SOURCE) +int flock(int, int); +#endif /* _NETBSD_SOURCE */ +__END_DECLS + +#endif /* !_SYS_FCNTL_H_ */ diff --git a/nbsd_include/sys/fd_set.h b/nbsd_include/sys/fd_set.h new file mode 100644 index 000000000..5ed7a4612 --- /dev/null +++ b/nbsd_include/sys/fd_set.h @@ -0,0 +1,108 @@ +/* $NetBSD: fd_set.h,v 1.2 2005/12/11 12:25:20 christos Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)types.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_FD_SET_H_ +#define _SYS_FD_SET_H_ + +#include +#include +#include + +/* + * Implementation dependent defines, hidden from user space. X/Open does not + * specify them. + */ +#define __NBBY 8 /* number of bits in a byte */ +typedef __int32_t __fd_mask; + +/* bits per mask */ +#define __NFDBITS ((unsigned int)sizeof(__fd_mask) * __NBBY) + +#define __howmany(x, y) (((x) + ((y) - 1)) / (y)) + +/* + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 256 +#endif + +typedef struct fd_set { + __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)]; +} fd_set; + +#define FD_SET(n, p) \ + ((p)->fds_bits[(n)/__NFDBITS] |= (1 << ((n) % __NFDBITS))) +#define FD_CLR(n, p) \ + ((p)->fds_bits[(n)/__NFDBITS] &= ~(1 << ((n) % __NFDBITS))) +#define FD_ISSET(n, p) \ + ((p)->fds_bits[(n)/__NFDBITS] & (1 << ((n) % __NFDBITS))) +#if __GNUC_PREREQ__(2, 95) +#define FD_ZERO(p) (void)__builtin_memset((p), 0, sizeof(*(p))) +#else +#define FD_ZERO(p) do { \ + fd_set *__fds = (p); \ + unsigned int __i; \ + for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \ + __fds->fds_bits[__i] = 0; \ + } while (/* CONSTCOND */ 0) +#endif /* GCC 2.95 */ + +/* + * Expose our internals if we are not required to hide them. + */ +#if defined(_NETBSD_SOURCE) + +#define fd_mask __fd_mask +#define NFDBITS __NFDBITS +#ifndef howmany +#define howmany(a, b) __howmany(a, b) +#endif + +#if __GNUC_PREREQ__(2, 95) +#define FD_COPY(f, t) (void)__builtin_memcpy((t), (f), sizeof(*(f))) +#else +#define FD_COPY(f, t) do { \ + fd_set *__f = (f), *__t = (t); \ + unsigned int __i; \ + for (__i = 0; __i < __howmany(FD_SETSIZE, __NFDBITS); __i++) \ + __t->fds_bits[__i] = __f->fds_bits[__i]; \ + } while (/* CONSTCOND */ 0) +#endif /* GCC 2.95 */ + +#endif /* _NETBSD_SOURCE */ + +#endif /* _SYS_FD_SET_H_ */ diff --git a/nbsd_include/sys/featuretest.h b/nbsd_include/sys/featuretest.h new file mode 100644 index 000000000..c5738a763 --- /dev/null +++ b/nbsd_include/sys/featuretest.h @@ -0,0 +1,81 @@ +/* $NetBSD: featuretest.h,v 1.9 2009/05/04 16:44:14 ginsbach Exp $ */ + +/* + * Written by Klaus Klein , February 2, 1998. + * Public domain. + * + * NOTE: Do not protect this header against multiple inclusion. Doing + * so can have subtle side-effects due to header file inclusion order + * and testing of e.g. _POSIX_SOURCE vs. _POSIX_C_SOURCE. Instead, + * protect each CPP macro that we want to supply. + */ + +/* + * Feature-test macros are defined by several standards, and allow an + * application to specify what symbols they want the system headers to + * expose, and hence what standard they want them to conform to. + * There are two classes of feature-test macros. The first class + * specify complete standards, and if one of these is defined, header + * files will try to conform to the relevant standard. They are: + * + * ANSI macros: + * _ANSI_SOURCE ANSI C89 + * + * POSIX macros: + * _POSIX_SOURCE == 1 IEEE Std 1003.1 (version?) + * _POSIX_C_SOURCE == 1 IEEE Std 1003.1-1990 + * _POSIX_C_SOURCE == 2 IEEE Std 1003.2-1992 + * _POSIX_C_SOURCE == 199309L IEEE Std 1003.1b-1993 + * _POSIX_C_SOURCE == 199506L ISO/IEC 9945-1:1996 + * _POSIX_C_SOURCE == 200112L IEEE Std 1003.1-2001 + * _POSIX_C_SOURCE == 200809L IEEE Std 1003.1-2008 + * + * X/Open macros: + * _XOPEN_SOURCE System Interfaces and Headers, Issue 4, Ver 2 + * _XOPEN_SOURCE_EXTENDED == 1 XSH4.2 UNIX extensions + * _XOPEN_SOURCE == 500 System Interfaces and Headers, Issue 5 + * _XOPEN_SOURCE == 520 Networking Services (XNS), Issue 5.2 + * _XOPEN_SOURCE == 600 IEEE Std 1003.1-2001, XSI option + * _XOPEN_SOURCE == 700 IEEE Std 1003.1-2008, XSI option + * + * NetBSD macros: + * _NETBSD_SOURCE == 1 Make all NetBSD features available. + * + * If more than one of these "major" feature-test macros is defined, + * then the set of facilities provided (and namespace used) is the + * union of that specified by the relevant standards, and in case of + * conflict, the earlier standard in the above list has precedence (so + * if both _POSIX_C_SOURCE and _NETBSD_SOURCE are defined, the version + * of rename() that's used is the POSIX one). If none of the "major" + * feature-test macros is defined, _NETBSD_SOURCE is assumed. + * + * There are also "minor" feature-test macros, which enable extra + * functionality in addition to some base standard. They should be + * defined along with one of the "major" macros. The "minor" macros + * are: + * + * _REENTRANT + * _ISOC99_SOURCE + * _LARGEFILE_SOURCE Large File Support + * + */ + +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 1L +#endif + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ + !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE) +#define _NETBSD_SOURCE 1 +#endif + +/* Never define _REENTRANT on Minix */ + +#ifdef __minix + +#if ((_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500) && \ + !defined(_REENTRANT) +#define _REENTRANT +#endif + +#endif /* __minix */ diff --git a/nbsd_include/sys/file.h b/nbsd_include/sys/file.h new file mode 100644 index 000000000..96a0cfac4 --- /dev/null +++ b/nbsd_include/sys/file.h @@ -0,0 +1,169 @@ +/* $NetBSD: file.h,v 1.71 2009/12/24 19:01:12 elad Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)file.h 8.3 (Berkeley) 1/9/95 + */ + +#ifndef _SYS_FILE_H_ +#define _SYS_FILE_H_ + +#include +#include + +#ifdef _KERNEL +#include +#include +#include +#include + +struct proc; +struct lwp; +struct uio; +struct iovec; +struct stat; +struct knote; + +/* + * Kernel file descriptor. One entry for each open kernel vnode and + * socket. + * + * This structure is exported via the KERN_FILE and KERN_FILE2 sysctl + * calls. Only add members to the end, do not delete them. + */ +struct file { + off_t f_offset; /* first, is 64-bit */ + kauth_cred_t f_cred; /* creds associated with descriptor */ + const struct fileops { + int (*fo_read) (struct file *, off_t *, struct uio *, + kauth_cred_t, int); + int (*fo_write) (struct file *, off_t *, struct uio *, + kauth_cred_t, int); + int (*fo_ioctl) (struct file *, u_long, void *); + int (*fo_fcntl) (struct file *, u_int, void *); + int (*fo_poll) (struct file *, int); + int (*fo_stat) (struct file *, struct stat *); + int (*fo_close) (struct file *); + int (*fo_kqfilter) (struct file *, struct knote *); + void (*fo_restart) (struct file *); + void (*fo_spare1) (void); + void (*fo_spare2) (void); + } *f_ops; + void *f_data; /* descriptor data, e.g. vnode/socket */ + LIST_ENTRY(file) f_list; /* list of active files */ + kmutex_t f_lock; /* lock on structure */ + int f_flag; /* see fcntl.h */ + u_int f_marker; /* traversal marker (sysctl) */ +#define DTYPE_VNODE 1 /* file */ +#define DTYPE_SOCKET 2 /* communications endpoint */ +#define DTYPE_PIPE 3 /* pipe */ +#define DTYPE_KQUEUE 4 /* event queue */ +#define DTYPE_MISC 5 /* misc file descriptor type */ +#define DTYPE_CRYPTO 6 /* crypto */ +#define DTYPE_MQUEUE 7 /* message queue */ +#define DTYPE_NAMES \ + "0", "file", "socket", "pipe", "kqueue", "misc", "crypto", "mqueue" + u_int f_type; /* descriptor type */ + u_int f_advice; /* access pattern hint; UVM_ADV_* */ + u_int f_count; /* reference count */ + u_int f_msgcount; /* references from message queue */ + u_int f_unpcount; /* deferred close: see uipc_usrreq.c */ + SLIST_ENTRY(file) f_unplist; /* deferred close: see uipc_usrreq.c */ +}; + +/* + * Flags for fo_read and fo_write and do_fileread/write/v + */ +#define FOF_UPDATE_OFFSET 0x0001 /* update the file offset */ +#define FOF_IOV_SYSSPACE 0x0100 /* iov structure in kernel memory */ + +LIST_HEAD(filelist, file); +extern struct filelist filehead; /* head of list of open files */ +extern u_int maxfiles; /* kernel limit on # of open files */ +extern u_int nfiles; /* actual number of open files */ + +extern const struct fileops vnops; /* vnode operations for files */ + +int dofileread(int, struct file *, void *, size_t, + off_t *, int, register_t *); +int dofilewrite(int, struct file *, const void *, + size_t, off_t *, int, register_t *); + +int do_filereadv(int, const struct iovec *, int, off_t *, + int, register_t *); +int do_filewritev(int, const struct iovec *, int, off_t *, + int, register_t *); + +int fsetown(pid_t *, u_long, const void *); +int fgetown(pid_t, u_long, void *); +void fownsignal(pid_t, int, int, int, void *); + +/* Commonly used fileops */ +int fnullop_fcntl(struct file *, u_int, void *); +int fnullop_poll(struct file *, int); +int fnullop_kqfilter(struct file *, struct knote *); +int fbadop_read(struct file *, off_t *, struct uio *, kauth_cred_t, int); +int fbadop_write(struct file *, off_t *, struct uio *, kauth_cred_t, int); +int fbadop_ioctl(struct file *, u_long, void *); +int fbadop_close(struct file *); +int fbadop_stat(struct file *, struct stat *); +void fnullop_restart(struct file *); + +#endif /* _KERNEL */ + +#endif /* _SYS_FILE_H_ */ diff --git a/nbsd_include/sys/float_ieee754.h b/nbsd_include/sys/float_ieee754.h new file mode 100644 index 000000000..f5224594f --- /dev/null +++ b/nbsd_include/sys/float_ieee754.h @@ -0,0 +1,111 @@ +/* $NetBSD: float_ieee754.h,v 1.8 2005/12/11 12:25:20 christos Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)float.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * NOTICE: This is not a standalone file. To use it, #include it in + * your port's float.h header. + */ + +#ifndef _SYS_FLOAT_IEEE754_H_ +#define _SYS_FLOAT_IEEE754_H_ + +#include +#include + +#ifndef FLT_ROUNDS +__BEGIN_DECLS +extern int __flt_rounds(void); +__END_DECLS +#define FLT_ROUNDS __flt_rounds() +#endif + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ + !defined(_XOPEN_SOURCE) || \ + ((__STDC_VERSION__ - 0) >= 199901L) || \ + ((_POSIX_C_SOURCE - 0) >= 200112L) || \ + ((_XOPEN_SOURCE - 0) >= 600) || \ + defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) +#ifndef FLT_EVAL_METHOD +#if __GNUC_PREREQ__(3, 3) +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +#endif /* GCC >= 3.3 */ +#endif /* defined(FLT_EVAL_METHOD) */ +#endif /* !defined(_ANSI_SOURCE) && ... */ + +#define FLT_RADIX 2 /* b */ + +#define FLT_MANT_DIG 24 /* p */ +#define FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define FLT_MIN_EXP (-125) /* emin */ +#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP 128 /* emax */ +#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_10_EXP 308 + +/* + * If no extended-precision type is defined by the machine-dependent + * header including this, default to `long double' being double-precision. + */ +#ifndef LDBL_MANT_DIG +#define LDBL_MANT_DIG DBL_MANT_DIG +#define LDBL_EPSILON DBL_EPSILON +#define LDBL_DIG DBL_DIG +#define LDBL_MIN_EXP DBL_MIN_EXP +#define LDBL_MIN DBL_MIN +#define LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define LDBL_MAX_EXP DBL_MAX_EXP +#define LDBL_MAX DBL_MAX +#define LDBL_MAX_10_EXP DBL_MAX_10_EXP +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ + !defined(_XOPEN_SOURCE) || \ + ((__STDC_VERSION__ - 0) >= 199901L) || \ + ((_POSIX_C_SOURCE - 0) >= 200112L) || \ + ((_XOPEN_SOURCE - 0) >= 600) || \ + defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) +#define DECIMAL_DIG 17 /* ceil((1+p*log10(b))-(b==10) */ +#endif /* !defined(_ANSI_SOURCE) && ... */ +#endif /* LDBL_MANT_DIG */ + +#endif /* _SYS_FLOAT_IEEE754_H_ */ diff --git a/nbsd_include/sys/gcq.h b/nbsd_include/sys/gcq.h new file mode 100644 index 000000000..b09ca3624 --- /dev/null +++ b/nbsd_include/sys/gcq.h @@ -0,0 +1,463 @@ +/* $NetBSD: gcq.h,v 1.2 2007/08/19 07:35:32 kiyohara Exp $ */ +/* + * Not (c) 2007 Matthew Orgass + * This file is public domain, meaning anyone can make any use of part or all + * of this file including copying into other works without credit. Any use, + * modified or not, is solely the responsibility of the user. If this file is + * part of a collection then use in the collection is governed by the terms of + * the collection. + */ + +/* + * Generic Circular Queues: Pointer arithmetic is used to recover the + * enclosing object. Merge operation is provided. Items can be multiply + * removed, but queue traversal requires separate knowledge of the queue head. + */ + +#ifndef _GCQ_H +#define _GCQ_H + +#ifdef _KERNEL +#include +#include +#include +#else +#include +#include +#include +#include +#endif + +#ifdef GCQ_USE_ASSERT +#define GCQ_ASSERT(x) assert(x) +#else +#ifdef _KERNEL +#define GCQ_ASSERT(x) KASSERT(x) +#else +#define GCQ_ASSERT(x) _DIAGASSERT(x) +#endif +#endif + +struct gcq { + struct gcq *q_next; + struct gcq *q_prev; +}; + +struct gcq_head { + struct gcq hq; +}; + +#define GCQ_INIT(q) { &(q), &(q) } +#define GCQ_INIT_HEAD(head) { GCQ_INIT((head).hq) } + +__attribute__((nonnull, always_inline)) static inline void +gcq_init(struct gcq *q) +{ + q->q_next = q->q_prev = q; +} + +__attribute__((nonnull, const, warn_unused_result, always_inline)) +static inline struct gcq * +gcq_q(struct gcq *q) +{ + return q; +} + +__attribute__((nonnull, const, warn_unused_result, always_inline)) +static inline struct gcq * +gcq_hq(struct gcq_head *head) +{ + return (struct gcq *)head; +} + +__attribute__((nonnull, const, warn_unused_result, always_inline)) +static inline struct gcq_head * +gcq_head(struct gcq *q) +{ + return (struct gcq_head *)q; +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_init_head(struct gcq_head *head) +{ + gcq_init(gcq_hq(head)); +} + +__attribute__((nonnull, pure, warn_unused_result, always_inline)) +static inline bool +gcq_onlist(struct gcq *q) +{ + return (q->q_next != q); +} + +__attribute__((nonnull, pure, warn_unused_result, always_inline)) +static inline bool +gcq_empty(struct gcq_head *head) +{ + return (!gcq_onlist(gcq_hq(head))); +} + +__attribute__((nonnull, pure, warn_unused_result, always_inline)) +static inline bool +gcq_linked(struct gcq *prev, struct gcq *next) +{ + return (prev->q_next == next && next->q_prev == prev); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_insert_after(struct gcq *on, struct gcq *off) +{ + struct gcq *on_next; + GCQ_ASSERT(off->q_next == off && off->q_prev == off); + on_next = on->q_next; + + off->q_prev = on; + off->q_next = on_next; + on_next->q_prev = off; + on->q_next = off; +} + +__attribute__((nonnull)) static inline void +gcq_insert_before(struct gcq *on, struct gcq *off) +{ + struct gcq *on_prev; + GCQ_ASSERT(off->q_next == off && off->q_prev == off); + on_prev = on->q_prev; + + off->q_next = on; + off->q_prev = on_prev; + on_prev->q_next = off; + on->q_prev = off; +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_insert_head(struct gcq_head *head, struct gcq *q) +{ + gcq_insert_after(gcq_hq(head), q); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_insert_tail(struct gcq_head *head, struct gcq *q) +{ + gcq_insert_before(gcq_hq(head), q); +} + +__attribute__((nonnull)) static inline void +gcq_tie(struct gcq *dst, struct gcq *src) +{ + struct gcq *dst_next, *src_prev; + dst_next = dst->q_next; + src_prev = src->q_prev; + + src_prev->q_next = dst_next; + dst_next->q_prev = src_prev; + src->q_prev = dst; + dst->q_next = src; +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_tie_after(struct gcq *dst, struct gcq *src) +{ + GCQ_ASSERT(dst != src && dst->q_prev != src); + gcq_tie(dst, src); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_tie_before(struct gcq *dst, struct gcq *src) +{ + gcq_tie_after(dst->q_prev, src); +} + +__attribute__((nonnull)) static inline struct gcq * +gcq_remove(struct gcq *q) +{ + struct gcq *next, *prev; + next = q->q_next; + prev = q->q_prev; + + prev->q_next = next; + next->q_prev = prev; + gcq_init(q); + return q; +} + +#ifdef GCQ_UNCONDITIONAL_MERGE +__attribute__((nonnull)) static inline void +gcq_merge(struct gcq *dst, struct gcq *src) +{ + GCQ_ASSERT(dst != src && dst->q_prev != src); + gcq_tie(dst, src); + gcq_tie(src, src); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_merge_head(struct gcq_head *dst, struct gcq_head *src) +{ + gcq_merge(gcq_hq(dst), gcq_hq(src)); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_merge_tail(struct gcq_head *dst, struct gcq_head *src) +{ + gcq_merge(gcq_hq(dst)->q_prev, gcq_hq(src)); +} +#else +__attribute__((nonnull)) static inline void +gcq_merge(struct gcq *dst, struct gcq *src) +{ + struct gcq *dst_next, *src_prev, *src_next; + GCQ_ASSERT(dst != src && dst->q_prev != src); + + if (gcq_onlist(src)) { + dst_next = dst->q_next; + src_prev = src->q_prev; + src_next = src->q_next; + + dst_next->q_prev = src_prev; + src_prev->q_next = dst_next; + dst->q_next = src_next; + src_next->q_prev = dst; + gcq_init(src); + } +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_merge_head(struct gcq_head *dst, struct gcq_head *src) +{ + gcq_merge(gcq_hq(dst), gcq_hq(src)); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_merge_tail(struct gcq_head *dst, struct gcq_head *src) +{ + gcq_merge(gcq_hq(dst)->q_prev, gcq_hq(src)); +} +#endif + +__attribute__((nonnull)) static inline void +gcq_clear(struct gcq *q) +{ + struct gcq *nq, *next; + nq=q; + do { + next = nq->q_next; + gcq_init(nq); + nq = next; + } while (next != q); +} + +__attribute__((nonnull, always_inline)) static inline void +gcq_remove_all(struct gcq_head *head) +{ + gcq_clear(gcq_hq(head)); +} + +__attribute__((nonnull, always_inline)) static inline struct gcq * +_gcq_next(struct gcq *current, struct gcq_head *head, struct gcq *start) +{ + struct gcq *q, *hq; + hq = gcq_hq(head); + q = current->q_next; + if (hq != start && q == hq) + q = hq->q_next; + if (current != start) + GCQ_ASSERT(gcq_onlist(current)); + return q; +} + +__attribute__((nonnull, always_inline)) static inline struct gcq * +_gcq_prev(struct gcq *current, struct gcq_head *head, struct gcq *start) +{ + struct gcq *q, *hq; + hq = gcq_hq(head); + q = current->q_prev; + if (hq != start && q == hq) + q = hq->q_prev; + if (current != start) + GCQ_ASSERT(gcq_onlist(current)); + return q; +} + + +#define GCQ_ITEM(q, type, name) \ + ((type *)(void *)((uint8_t *)gcq_q(q) - offsetof(type, name))) + + +#define _GCQ_GDQ(var, h, ptr, fn) (gcq_hq(h)->ptr != gcq_hq(h) ? \ + (var = fn(gcq_hq(h)->ptr), true) : (var = NULL, false)) +#define _GCQ_GDQ_TYPED(tvar, h, type, name, ptr, fn) \ + (gcq_hq(h)->ptr != gcq_hq(h) ? (tvar = GCQ_ITEM(fn(gcq_hq(h)->ptr), \ + type, name), true) : (tvar = NULL, false)) +#define _GCQ_NP(var, current, head, start, np, fn) \ + (np(current, head, start) != (start) ? \ + (var = fn(np(current, head, start)), true) : (var = NULL, false)) +#define _GCQ_NP_TYPED(tvar, current, head, start, type, name, np, fn) \ + (np(current, head, start) != (start) ? \ + (tvar = GCQ_ITEM(fn(np(current, head, start)), type, name), true) : \ + (tvar = NULL, false)) + +#define _GCQ_GDQ_COND(var, h, ptr, rem, cond) \ + (gcq_hq(h)->ptr != gcq_hq(h) ? (var = gcq_hq(h)->ptr, \ + ((cond) ? (rem, true) : (var = NULL, false))) : \ + (var = NULL, false)) +#define _GCQ_GDQ_COND_TYPED(tvar, h, type, name, ptr, rem, cond) \ + (gcq_hq(h)->ptr != gcq_hq(h) ? (tvar = GCQ_ITEM(gcq_hq(h)->ptr, \ + type, name), ((cond) ? (rem, true) : (tvar = NULL, false))) : \ + (tvar = NULL, false)) +#define _GCQ_NP_COND(var, current, head, start, np, rem, cond) \ + (np(current, head, start) != (start) ? \ + (var = fn(np(current, head, start)), ((cond) ? (rem), true) : \ + (var = NULL, false))) : (var = NULL, false)) +#define _GCQ_NP_COND_TYPED(tvar, current, head, start, type, name, np, \ + rem, cond) (np(current, head, start) != (start) ? \ + (tvar = GCQ_ITEM(fn(np(current, head, start)), type, name), \ + ((cond) ? (rem, true) : (var = NULL, false))) : \ + (tvar = NULL, false)) + +#define GCQ_GOT_FIRST(var, h) _GCQ_GDQ(var, h, q_next, gcq_q) +#define GCQ_GOT_LAST(var, h) _GCQ_GDQ(var, h, q_prev, gcq_q) +#define GCQ_DEQUEUED_FIRST(var, h) _GCQ_GDQ(var, h, q_next, gcq_remove) +#define GCQ_DEQUEUED_LAST(var, h) _GCQ_GDQ(var, h, q_prev, gcq_remove) +#define GCQ_GOT_FIRST_TYPED(tvar, h, type, name) \ + _GCQ_GDQ_TYPED(tvar, h, type, name, q_next, gcq_q) +#define GCQ_GOT_LAST_TYPED(tvar, h, type, name) \ + _GCQ_GDQ_TYPED(tvar, h, type, name, q_prev, gcq_q) +#define GCQ_DEQUEUED_FIRST_TYPED(tvar, h, type, name) \ + _GCQ_GDQ_TYPED(tvar, h, type, name, q_next, gcq_remove) +#define GCQ_DEQUEUED_LAST_TYPED(tvar, h, type, name) \ + _GCQ_GDQ_TYPED(tvar, h, type, name, q_prev, gcq_remove) +#define GCQ_GOT_NEXT(var, current, head, start) \ + _GCQ_NP(var, current, head, start, _gcq_next, gcq_q) +#define GCQ_GOT_PREV(var, current, head, start) \ + _GCQ_NP(var, current, head, start, _gcq_prev, gcq_q) +#define GCQ_DEQUEUED_NEXT(var, current, head, start) \ + _GCQ_NP(var, current, head, start, _gcq_next, gcq_remove) +#define GCQ_DEQUEUED_PREV(var, current, head, start) \ + _GCQ_NP(var, current, head, start, _gcq_prev, gcq_remove) +#define GCQ_GOT_NEXT_TYPED(tvar, current, head, start, type, name) \ + _GCQ_NP_TYPED(tvar, current, head, start, type, name, \ + _gcq_next, gcq_q) +#define GCQ_GOT_PREV_TYPED(tvar, current, head, start, type, name) \ + _GCQ_NP_TYPED(tvar, current, head, start, type, name, \ + _gcq_prev, gcq_q) +#define GCQ_DEQUEUED_NEXT_TYPED(tvar, current, head, start, type, name) \ + _GCQ_NP_TYPED(tvar, current, head, start, type, name, \ + _gcq_next, gcq_remove) +#define GCQ_DEQUEUED_PREV_TYPED(tvar, current, head, start, type, name) \ + _GCQ_NP_TYPED(tvar, current, head, start, type, name, \ + _gcq_prev, gcq_remove) + +#define GCQ_GOT_FIRST_COND(var, h, cond) \ + _GCQ_GDQ_COND(var, h, q_next, ((void)0), cond) +#define GCQ_GOT_LAST_COND(var, h, cond) \ + _GCQ_GDQ_COND(var, h, q_prev, ((void)0), cond) +#define GCQ_DEQUEUED_FIRST_COND(var, h, cond) \ + _GCQ_GDQ_COND(var, h, q_next, gcq_remove(var), cond) +#define GCQ_DEQUEUED_LAST_COND(var, h, cond) \ + _GCQ_GDQ_COND(var, h, q_prev, gcq_remove(var), cond) +#define GCQ_GOT_FIRST_COND_TYPED(tvar, h, type, name, cond) \ + _GCQ_GDQ_COND_TYPED(tvar, h, type, name, q_next, ((void)0), cond) +#define GCQ_GOT_LAST_COND_TYPED(tvar, h, type, name, cond) \ + _GCQ_GDQ_COND_TYPED(tvar, h, type, name, q_prev, ((void)0), cond) +#define GCQ_DEQUEUED_FIRST_COND_TYPED(tvar, h, type, name, cond) \ + _GCQ_GDQ_COND_TYPED(tvar, h, type, name, q_next, \ + gcq_remove(&(tvar)->name), cond) +#define GCQ_DEQUEUED_LAST_COND_TYPED(tvar, h, type, name, cond) \ + _GCQ_GDQ_COND_TYPED(tvar, h, type, name, q_prev, \ + gcq_remove(&(tvar)->name), cond) +#define GCQ_GOT_NEXT_COND(var, current, head, start, cond) \ + _GCQ_NP_COND(var, current, head, start, _gcq_next, ((void)0), cond) +#define GCQ_GOT_PREV_COND(var, current, head, start, cond) \ + _GCQ_NP_COND(var, current, head, start, _gcq_prev, ((void)0), cond) +#define GCQ_DEQUEUED_NEXT_COND(var, current, head, start, cond) \ + _GCQ_NP_COND(var, current, head, start, _gcq_next, gcq_remove(var), \ + cond) +#define GCQ_DEQUEUED_PREV_COND(var, current, head, start, cond) \ + _GCQ_NP_COND(var, current, head, start, _gcq_prev, gcq_remove(var), \ + cond) +#define GCQ_GOT_NEXT_COND_TYPED(tvar, current, head, start, type, name, \ + cond) _GCQ_NP_COND_TYPED(tvar, current, head, start, type, name, \ + _gcq_next, ((void)0), cond) +#define GCQ_GOT_PREV_COND_TYPED(tvar, current, head, start, type, name, \ + cond) _GCQ_NP_COND_TYPED(tvar, current, head, start, type, name, \ + _gcq_prev, ((void)0), cond) +#define GCQ_DEQUEUED_NEXT_COND_TYPED(tvar, current, head, start, type, \ + name, cond) _GCQ_NP_COND_TYPED(tvar, current, head, start, type, \ + name, _gcq_next, gcq_remove(&(tvar)->name), cond) +#define GCQ_DEQUEUED_PREV_COND_TYPED(tvar, current, head, start, type, \ + name, cond) _GCQ_NP_COND_TYPED(tvar, current, head, start, type, \ + name, _gcq_prev, gcq_remove(&(tvar)->name), cond) + + +#define _GCQ_FOREACH(var, h, tnull, item, ptr) \ + for ((var)=gcq_hq(h)->ptr; ((var) != gcq_hq(h) && \ + (GCQ_ASSERT(gcq_onlist(var)), item, true)) || \ + (tnull, false); (var)=(var)->ptr) +#define _GCQ_FOREACH_NVAR(var, nvar, h, tnull, item, ptr, ol, rem, ro) \ + for ((nvar)=gcq_hq(h)->ptr; (((var)=(nvar), (nvar) != gcq_hq(h)) && \ + (ol, (nvar)=(nvar)->ptr, rem, item, true)) || (tnull, false); ro) + +#define GCQ_FOREACH(var, h) \ + _GCQ_FOREACH(var, h, ((void)0), ((void)0), q_next) +#define GCQ_FOREACH_REV(var, h) \ + _GCQ_FOREACH(var, h, ((void)0), ((void)0), q_prev) +#define GCQ_FOREACH_NVAR(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_next, GCQ_ASSERT(gcq_onlist(nvar)), ((void)0), ((void)0)) +#define GCQ_FOREACH_NVAR_REV(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_prev, GCQ_ASSERT(gcq_onlist(nvar)), ((void)0), ((void)0)) +#define GCQ_FOREACH_RO(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_next, ((void)0), ((void)0), GCQ_ASSERT(gcq_linked(var, nvar))) +#define GCQ_FOREACH_RO_REV(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_prev, ((void)0), ((void)0), GCQ_ASSERT(gcq_linked(nvar, var))) +#define GCQ_FOREACH_DEQUEUED(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_next, GCQ_ASSERT(gcq_onlist(nvar)), gcq_remove(var), ((void)0) +#define GCQ_FOREACH_DEQUEUED_REV(var, nvar, h) \ + _GCQ_FOREACH_NVAR(var, nvar, h, ((void)0), ((void)0), \ + q_prev, GCQ_ASSERT(gcq_onlist(nvar)), gcq_remove(var), ((void)0) + +#define GCQ_FOREACH_TYPED(var, h, tvar, type, name) \ + _GCQ_FOREACH(var, h, (tvar)=NULL, (tvar)=GCQ_ITEM(var, type, name), \ + q_next) +#define GCQ_FOREACH_TYPED_REV(var, h, tvar, type, name) \ + _GCQ_FOREACH(var, h, (tvar)=NULL, (tvar)=GCQ_ITEM(var, type, name), \ + q_prev) +#define GCQ_FOREACH_NVAR_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_next, GCQ_ASSERT(gcq_onlist(nvar)), ((void)0), ((void)0)) +#define GCQ_FOREACH_NVAR_REV_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_prev, GCQ_ASSERT(gcq_onlist(nvar)), ((void)0), ((void)0)) +#define GCQ_FOREACH_RO_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_next, ((void)0), ((void)0), GCQ_ASSERT(gcq_lined(var, nvar))) +#define GCQ_FOREACH_RO_REV_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_prev, ((void)0), ((void)0), GCQ_ASSERT(gcq_linked(nvar, var))) +#define GCQ_FOREACH_DEQUEUED_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_next, GCQ_ASSERT(gcq_onlist(nvar)), gcq_remove(var), ((void)0)) +#define GCQ_FOREACH_DEQUEUED_REV_TYPED(var, nvar, h, tvar, type, name) \ + _GCQ_FOREACH_NVAR(var, nvar, h, (tvar)=NULL, \ + (tvar)=GCQ_ITEM(var, type, name), \ + q_prev, GCQ_ASSERT(gcq_onlist(nvar)), gcq_remove(var), ((void)0)) + +#define _GCQ_COND(fe, cond) do { fe { if (cond) break; } } while (0) + +#define GCQ_FIND(var, h, cond) _GCQ_COND(GCQ_FOREACH(var, h), cond) +#define GCQ_FIND_REV(var, h, cond) _GCQ_COND(GCQ_FOREACH_REV(var, h), cond) +#define GCQ_FIND_TYPED(var, h, tvar, type, name, cond) \ + _GCQ_COND(GCQ_FOREACH_TYPED(var, h, tvar, type, name), cond) +#define GCQ_FIND_TYPED_REV(var, h, tvar, type, name, cond) \ + _GCQ_COND(GCQ_FOREACH_REV_TYPED(var, h, tvar, type, name), cond) + +#endif /* _GCQ_H */ diff --git a/nbsd_include/sys/gmon.h b/nbsd_include/sys/gmon.h new file mode 100644 index 000000000..ac997b922 --- /dev/null +++ b/nbsd_include/sys/gmon.h @@ -0,0 +1,153 @@ +/* $NetBSD: gmon.h,v 1.9 2006/10/04 14:22:58 christos Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)gmon.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_GMON_H_ +#define _SYS_GMON_H_ + +#include + +/* + * Structure prepended to gmon.out profiling data file. + */ +struct gmonhdr { + u_long lpc; /* base pc address of sample buffer */ + u_long hpc; /* max pc address of sampled buffer */ + int ncnt; /* size of sample buffer (plus this header) */ + int version; /* version number */ + int profrate; /* profiling clock rate */ + int spare[3]; /* reserved */ +}; +#define GMONVERSION 0x00051879 + +/* + * histogram counters are unsigned shorts (according to the kernel). + */ +#define HISTCOUNTER unsigned short + +/* + * fraction of text space to allocate for histogram counters here, 1/2 + */ +#ifndef HISTFRACTION +#define HISTFRACTION 2 +#endif /* HISTFRACTION */ + +/* + * Fraction of text space to allocate for from hash buckets. + * The value of HASHFRACTION is based on the minimum number of bytes + * of separation between two subroutine call points in the object code. + * Given MIN_SUBR_SEPARATION bytes of separation the value of + * HASHFRACTION is calculated as: + * + * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); + * + * For example, on the VAX, the shortest two call sequence is: + * + * calls $0,(r0) + * calls $0,(r0) + * + * which is separated by only three bytes, thus HASHFRACTION is + * calculated as: + * + * HASHFRACTION = 3 / (2 * 2 - 1) = 1 + * + * Note that the division above rounds down, thus if MIN_SUBR_FRACTION + * is less than three, this algorithm will not work! + * + * In practice, however, call instructions are rarely at a minimal + * distance. Hence, we will define HASHFRACTION to be 2 across all + * architectures. This saves a reasonable amount of space for + * profiling data structures without (in practice) sacrificing + * any granularity. + */ +#define HASHFRACTION 2 + +/* + * percent of text space to allocate for tostructs with a minimum. + */ +#define ARCDENSITY 2 +#define MINARCS 50 +#define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2) + +struct tostruct { + u_long selfpc; + long count; + u_short link; + u_short pad; +}; + +/* + * a raw arc, with pointers to the calling site and + * the called site and a count. + */ +struct rawarc { + u_long raw_frompc; + u_long raw_selfpc; + long raw_count; +}; + +/* + * The profiling data structures are housed in this structure. + */ +struct gmonparam { + int state; + u_short *kcount; + u_long kcountsize; + u_short *froms; + u_long fromssize; + struct tostruct *tos; + u_long tossize; + long tolimit; + u_long lowpc; + u_long highpc; + u_long textsize; + u_long hashfraction; +}; +extern struct gmonparam _gmonparam; + +/* + * Possible states of profiling. + */ +#define GMON_PROF_ON 0 +#define GMON_PROF_BUSY 1 +#define GMON_PROF_ERROR 2 +#define GMON_PROF_OFF 3 + +/* + * Sysctl definitions for extracting profiling information from the kernel. + */ +#define GPROF_STATE 0 /* int: profiling enabling variable */ +#define GPROF_COUNT 1 /* struct: profile tick count buffer */ +#define GPROF_FROMS 2 /* struct: from location hash bucket */ +#define GPROF_TOS 3 /* struct: destination/count structure */ +#define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */ +#endif /* !_SYS_GMON_H_ */ diff --git a/nbsd_include/sys/hash.h b/nbsd_include/sys/hash.h new file mode 100644 index 000000000..45041abb0 --- /dev/null +++ b/nbsd_include/sys/hash.h @@ -0,0 +1,103 @@ +/* $NetBSD: hash.h,v 1.6 2008/04/28 20:24:10 martin Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_HASH_H_ +#define _SYS_HASH_H_ + +#include +#ifdef __HAVE_MACHINE_HASH_H +#include +#endif + + +#ifndef __HAVE_HASH32_BUF /* not overridden by MD hash */ + +#define HASH32_BUF_INIT 5381 + +/* + * uint32_t + * hash32_buf(const void *bf, size_t len, uint32_t hash) + * return a 32 bit hash of the binary buffer buf (size len), + * seeded with an initial hash value of hash (usually HASH32_BUF_INIT). + */ +static __inline uint32_t +hash32_buf(const void *bf, size_t len, uint32_t hash) +{ + const uint8_t *s = bf; + + while (len-- != 0) /* "nemesi": k=257, r=r*257 */ + hash = hash * 257 + *s++; + return (hash * 257); +} +#endif /* __HAVE_HASH32_BUF */ + + +#ifndef __HAVE_HASH32_STR /* not overridden by MD hash */ + +#define HASH32_STR_INIT 5381 +/* + * uint32_t + * hash32_str(const void *bf, uint32_t hash) + * return a 32 bit hash of NUL terminated ASCII string buf, + * seeded with an initial hash value of hash (usually HASH32_STR_INIT). + */ +static __inline uint32_t +hash32_str(const void *bf, uint32_t hash) +{ + const uint8_t *s = bf; + uint8_t c; + + while ((c = *s++) != 0) + hash = hash * 33 + c; /* "perl": k=33, r=r+r/32 */ + return (hash + (hash >> 5)); +} + +/* + * uint32_t + * hash32_strn(const void *bf, size_t len, uint32_t hash) + * return a 32 bit hash of NUL terminated ASCII string buf up to + * a maximum of len bytes, + * seeded with an initial hash value of hash (usually HASH32_STR_INIT). + */ +static __inline uint32_t +hash32_strn(const void *bf, size_t len, uint32_t hash) +{ + const uint8_t *s = bf; + uint8_t c; + + while ((c = *s++) != 0 && len-- != 0) + hash = hash * 33 + c; /* "perl": k=33, r=r+r/32 */ + return (hash + (hash >> 5)); +} +#endif /* __HAVE_HASH32_STR */ + + +#endif /* !_SYS_HASH_H_ */ diff --git a/nbsd_include/sys/ieee754.h b/nbsd_include/sys/ieee754.h new file mode 100644 index 000000000..468bb994c --- /dev/null +++ b/nbsd_include/sys/ieee754.h @@ -0,0 +1,152 @@ +/* $NetBSD: ieee754.h,v 1.7 2007/02/02 23:08:22 christos Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ +#ifndef _SYS_IEEE754_H_ +#define _SYS_IEEE754_H_ + +/* + * NOTICE: This is not a standalone file. To use it, #include it in + * your port's ieee.h header. + */ + +#include + +/* + * defines the layout of IEEE 754 floating point types. + * Only single-precision and double-precision types are defined here; + * extended types, if available, are defined in the machine-dependent + * header. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +struct ieee_single { +#if _BYTE_ORDER == _BIG_ENDIAN + u_int sng_sign:1; + u_int sng_exp:SNG_EXPBITS; + u_int sng_frac:SNG_FRACBITS; +#else + u_int sng_frac:SNG_FRACBITS; + u_int sng_exp:SNG_EXPBITS; + u_int sng_sign:1; +#endif +}; + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS (DBL_FRACHBITS + DBL_FRACLBITS) + +struct ieee_double { +#if _BYTE_ORDER == _BIG_ENDIAN + u_int dbl_sign:1; + u_int dbl_exp:DBL_EXPBITS; + u_int dbl_frach:DBL_FRACHBITS; + u_int dbl_fracl:DBL_FRACLBITS; +#else + u_int dbl_fracl:DBL_FRACLBITS; + u_int dbl_frach:DBL_FRACHBITS; + u_int dbl_exp:DBL_EXPBITS; + u_int dbl_sign:1; +#endif +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * At least one `signalling NaN' and one `quiet NaN' value must be + * implemented. It is left to the architecture to specify how to + * distinguish between these. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 + +/* + * Convenience data structures. + */ +union ieee_single_u { + float sngu_f; + struct ieee_single sngu_sng; +}; + +union ieee_double_u { + double dblu_d; + struct ieee_double dblu_dbl; +}; +#endif /* _SYS_IEEE754_H_ */ diff --git a/nbsd_include/sys/inttypes.h b/nbsd_include/sys/inttypes.h new file mode 100644 index 000000000..ec7b1a463 --- /dev/null +++ b/nbsd_include/sys/inttypes.h @@ -0,0 +1,45 @@ +/* $NetBSD: inttypes.h,v 1.5 2008/04/28 20:24:10 martin Exp $ */ + +/*- + * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus J. Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_INTTYPES_H_ +#define _SYS_INTTYPES_H_ + +/* + * 7.8 Format conversion of integer types + */ + +#include + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) +#include +#endif + +#endif /* !_SYS_INTTYPES_H_ */ diff --git a/nbsd_include/sys/ioc_net.h b/nbsd_include/sys/ioc_net.h new file mode 100644 index 000000000..12f4188a2 --- /dev/null +++ b/nbsd_include/sys/ioc_net.h @@ -0,0 +1,99 @@ +/* sys/ioc_net.h - NetBSD-friendly version of Minix net/ioctl.h + */ +/* net/ioctl.h - Network ioctl() command codes. Author: Kees J. Bot + * 23 Nov 2002 + * + */ + +#ifndef _SYS_IOC_NET_H_ +#define _SYS_IOC_NET_H_ + +#include +#include + +#include +#ifndef socklen_t +typedef __socklen_t socklen_t; +#define socklen_t __socklen_t +#endif + +#define MSG_CONTROL_MAX (1024 - sizeof(socklen_t)) +struct msg_control +{ + char msg_control[MSG_CONTROL_MAX]; + socklen_t msg_controllen; +}; + + +/* Network ioctls. */ +#define NWIOSETHOPT _IOW('n', 16, struct nwio_ethopt) +#define NWIOGETHOPT _IOR('n', 17, struct nwio_ethopt) +#define NWIOGETHSTAT _IOR('n', 18, struct nwio_ethstat) + +#define NWIOARPGIP _IORW('n',20, struct nwio_arp) +#define NWIOARPGNEXT _IORW('n',21, struct nwio_arp) +#define NWIOARPSIP _IOW ('n',22, struct nwio_arp) +#define NWIOARPDIP _IOW ('n',23, struct nwio_arp) + +#define NWIOSIPCONF2 _IOW('n', 32, struct nwio_ipconf2) +#define NWIOSIPCONF _IOW('n', 32, struct nwio_ipconf) +#define NWIOGIPCONF2 _IOR('n', 33, struct nwio_ipconf2) +#define NWIOGIPCONF _IOR('n', 33, struct nwio_ipconf) +#define NWIOSIPOPT _IOW('n', 34, struct nwio_ipopt) +#define NWIOGIPOPT _IOR('n', 35, struct nwio_ipopt) + +#define NWIOGIPOROUTE _IORW('n', 40, struct nwio_route) +#define NWIOSIPOROUTE _IOW ('n', 41, struct nwio_route) +#define NWIODIPOROUTE _IOW ('n', 42, struct nwio_route) +#define NWIOGIPIROUTE _IORW('n', 43, struct nwio_route) +#define NWIOSIPIROUTE _IOW ('n', 44, struct nwio_route) +#define NWIODIPIROUTE _IOW ('n', 45, struct nwio_route) + +#define NWIOSTCPCONF _IOW('n', 48, struct nwio_tcpconf) +#define NWIOGTCPCONF _IOR('n', 49, struct nwio_tcpconf) +#define NWIOTCPCONN _IOW('n', 50, struct nwio_tcpcl) +#define NWIOTCPLISTEN _IOW('n', 51, struct nwio_tcpcl) +#define NWIOTCPATTACH _IOW('n', 52, struct nwio_tcpatt) +#define NWIOTCPSHUTDOWN _IO ('n', 53) +#define NWIOSTCPOPT _IOW('n', 54, struct nwio_tcpopt) +#define NWIOGTCPOPT _IOR('n', 55, struct nwio_tcpopt) +#define NWIOTCPPUSH _IO ('n', 56) +#define NWIOTCPLISTENQ _IOW('n', 57, int) +#define NWIOGTCPCOOKIE _IOR('n', 58, struct tcp_cookie) +#define NWIOTCPACCEPTTO _IOW('n', 59, struct tcp_cookie) +#define NWIOTCPGERROR _IOR('n', 60, int) + +#define NWIOSUDPOPT _IOW('n', 64, struct nwio_udpopt) +#define NWIOGUDPOPT _IOR('n', 65, struct nwio_udpopt) +#define NWIOUDPPEEK _IOR('n', 66, struct udp_io_hdr) + +#define NWIOGUDSFADDR _IOR ('n', 67, struct sockaddr_un) /* recvfrom() */ +#define NWIOSUDSTADDR _IOW ('n', 68, struct sockaddr_un) /* sendto() */ +#define NWIOSUDSADDR _IOW ('n', 69, struct sockaddr_un) /* bind() */ +#define NWIOGUDSADDR _IOR ('n', 70, struct sockaddr_un) /* getsockname() */ +#define NWIOGUDSPADDR _IOR ('n', 71, struct sockaddr_un) /* getpeername() */ +#define NWIOSUDSTYPE _IOW ('n', 72, int) /* socket() */ +#define NWIOSUDSBLOG _IOW ('n', 73, int) /* listen() */ +#define NWIOSUDSCONN _IOW ('n', 74, struct sockaddr_un) /* connect() */ +#define NWIOSUDSSHUT _IOW ('n', 75, int) /* shutdown() */ +#define NWIOSUDSPAIR _IOW ('n', 76, dev_t) /* socketpair() */ +#define NWIOSUDSACCEPT _IOW ('n', 77, struct sockaddr_un) /* accept() */ +#define NWIOSUDSCTRL _IOW ('n', 78, struct msg_control) /* sendmsg() */ +#define NWIOGUDSCTRL _IORW('n', 79, struct msg_control) /* recvmsg() */ + +#define NWIOSPSIPOPT _IOW('n', 80, struct nwio_psipopt) +#define NWIOGPSIPOPT _IOR('n', 81, struct nwio_psipopt) + +/* setsockopt/setsockopt for unix domain sockets */ +#define NWIOGUDSSOTYPE _IOR('n', 90, int) /* SO_TYPE */ +#define NWIOGUDSPEERCRED _IOR('n', 91, struct ucred) /* SO_PEERCRED */ +#define NWIOGUDSSNDBUF _IOR('n', 92, size_t) /* SO_SNDBUF */ +#define NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */ +#define NWIOGUDSRCVBUF _IOR('n', 94, size_t) /* SO_RCVBUF */ +#define NWIOSUDSRCVBUF _IOW('n', 95, size_t) /* SO_RCVBUF */ + +#endif /* _NET__IOCTL_H */ + +/* + * $PchId: ioctl.h,v 1.2 2003/07/25 14:34:03 philip Exp $ + */ diff --git a/nbsd_include/sys/ioctl.h b/nbsd_include/sys/ioctl.h new file mode 100644 index 000000000..85ebe1983 --- /dev/null +++ b/nbsd_include/sys/ioctl.h @@ -0,0 +1,34 @@ +/* sys/ioctl.h - All ioctl() command codes. Author: Kees J. Bot + * 23 Nov 2002 + * + * This header file includes all other ioctl command code headers. + */ + +#ifndef _S_IOCTL_H +#define _S_IOCTL_H + +/* A driver that uses ioctls claims a character for its series of commands. + * For instance: #define TCGETS _IOR('T', 8, struct termios) + * This is a terminal ioctl that uses the character 'T'. The character(s) + * used in each header file are shown in the comment following. + */ + +#include /* 'T' 't' 'k' */ +#include /* 'n' */ +#include /* 'd' */ +#include /* 'f' */ +#include /* 'm' */ +#include /* 'c' */ +#include /* 'M' */ +#include /* 'S' */ +#include /* 's' */ + +#if defined(_NETBSD_SOURCE) +#define TIOCDRAIN TCDRAIN +#define TIOCGETA TCGETS +#define TIOCSETA TCSETS +#define TIOCSETAW TCSETSW +#define TIOCSETAF TCSETSF +#endif + +#endif /* _S_IOCTL_H */ diff --git a/nbsd_include/sys/ipc.h b/nbsd_include/sys/ipc.h new file mode 100644 index 000000000..ae52b64fb --- /dev/null +++ b/nbsd_include/sys/ipc.h @@ -0,0 +1,51 @@ +/* + * SVID compatible ipc.h file + */ + +#ifndef _SYS_IPC_H_ +#define _SYS_IPC_H_ + +#include +#include + +/* Data structure used to pass permission information to IPC operations. */ +struct ipc_perm +{ + key_t key; /* Key. */ + uid_t uid; /* Owner's user ID. */ + gid_t gid; /* Owner's group ID. */ + uid_t cuid; /* Creator's user ID. */ + gid_t cgid; /* Creator's group ID. */ + unsigned short int mode; /* Reader/write permission. */ + unsigned short int __seq; /* Sequence number. */ +}; + +/* X/Open required constants (same values as system 5) */ +#define IPC_CREAT 001000 /* create entry if key does not exist */ +#define IPC_EXCL 002000 /* fail if key exists */ +#define IPC_NOWAIT 004000 /* error if request must wait */ + +#define IPC_PRIVATE (key_t)0 /* private key */ + +#define IPC_RMID 0 /* remove identifier */ +#define IPC_SET 1 /* set options */ +#define IPC_STAT 2 /* get options */ + +#ifdef __minix +#define IPC_INFO 3 /* See ipcs. */ +#endif /* !__minix */ + +/* + * Macro to convert between ipc ids and array indices or sequence ids. + */ +#if defined(_NETBSD_SOURCE) +#define IXSEQ_TO_IPCID(ix,perm) (((perm._seq) << 16) | (ix & 0xffff)) +#endif + +#include + +__BEGIN_DECLS +key_t ftok(const char *, int); +__END_DECLS + +#endif /* !_SYS_IPC_H_ */ diff --git a/nbsd_include/sys/localedef.h b/nbsd_include/sys/localedef.h new file mode 100644 index 000000000..e20208c41 --- /dev/null +++ b/nbsd_include/sys/localedef.h @@ -0,0 +1,100 @@ +/* $NetBSD: localedef.h,v 1.9 2008/05/17 03:49:54 ginsbach Exp $ */ + +/* + * Copyright (c) 1994 Winning Strategies, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_LOCALEDEF_H_ +#define _SYS_LOCALEDEF_H_ + +typedef struct { + const char *yesexpr; + const char *noexpr; + const char *yesstr; + const char *nostr; +} _MessagesLocale; + +extern const _MessagesLocale *_CurrentMessagesLocale; +extern const _MessagesLocale _DefaultMessagesLocale; + + +typedef struct { + const char *int_curr_symbol; + const char *currency_symbol; + const char *mon_decimal_point; + const char *mon_thousands_sep; + const char *mon_grouping; + const char *positive_sign; + const char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +} _MonetaryLocale; + +extern const _MonetaryLocale *_CurrentMonetaryLocale; +extern const _MonetaryLocale _DefaultMonetaryLocale; + + +typedef struct { + const char *decimal_point; + const char *thousands_sep; + const char *grouping; +} _NumericLocale; + +extern const _NumericLocale *_CurrentNumericLocale; +extern const _NumericLocale _DefaultNumericLocale; + + +typedef struct { + const char *abday[7]; + const char *day[7]; + const char *abmon[12]; + const char *mon[12]; + const char *am_pm[2]; + const char *d_t_fmt; + const char *d_fmt; + const char *t_fmt; + const char *t_fmt_ampm; +} _TimeLocale; + +extern const _TimeLocale *_CurrentTimeLocale; +extern const _TimeLocale _DefaultTimeLocale; + +#endif /* !_SYS_LOCALEDEF_H_ */ diff --git a/nbsd_include/sys/md4.h b/nbsd_include/sys/md4.h new file mode 100644 index 000000000..62789efee --- /dev/null +++ b/nbsd_include/sys/md4.h @@ -0,0 +1,58 @@ +/* $NetBSD: md4.h,v 1.7 2005/12/26 18:41:36 perry Exp $ */ + +/* + * This file is derived from the RSA Data Security, Inc. MD4 Message-Digest + * Algorithm and has been modified by Jason R. Thorpe + * for portability and formatting. + */ + +/* + * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + * rights reserved. + * + * License to copy and use this software is granted provided that it + * is identified as the "RSA Data Security, Inc. MD4 Message-Digest + * Algorithm" in all material mentioning or referencing this software + * or this function. + * + * License is also granted to make and use derivative works provided + * that such works are identified as "derived from the RSA Data + * Security, Inc. MD4 Message-Digest Algorithm" in all material + * mentioning or referencing the derived work. + * + * RSA Data Security, Inc. makes no representations concerning either + * the merchantability of this software or the suitability of this + * software for any particular purpose. It is provided "as is" + * without express or implied warranty of any kind. + * + * These notices must be retained in any copies of any part of this + * documentation and/or software. + */ + +#ifndef _SYS_MD4_H_ +#define _SYS_MD4_H_ + +#include +#include + +#define MD4_DIGEST_LENGTH 16 + +/* MD4 context. */ +typedef struct MD4Context { + uint32_t state[4]; /* state (ABCD) */ + uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD4_CTX; + +__BEGIN_DECLS +void MD4Init(MD4_CTX *); +void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); +void MD4Final(unsigned char[MD4_DIGEST_LENGTH], MD4_CTX *); +#ifndef _KERNEL +char *MD4End(MD4_CTX *, char *); +char *MD4File(const char *, char *); +char *MD4Data(const unsigned char *, unsigned int, char *); +#endif /* _KERNEL */ +__END_DECLS + +#endif /* _SYS_MD4_H_ */ diff --git a/nbsd_include/sys/md5.h b/nbsd_include/sys/md5.h new file mode 100644 index 000000000..d2715ec74 --- /dev/null +++ b/nbsd_include/sys/md5.h @@ -0,0 +1,58 @@ +/* $NetBSD: md5.h,v 1.9 2005/12/26 18:41:36 perry Exp $ */ + +/* + * This file is derived from the RSA Data Security, Inc. MD5 Message-Digest + * Algorithm and has been modified by Jason R. Thorpe + * for portability and formatting. + */ + +/* + * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + * rights reserved. + * + * License to copy and use this software is granted provided that it + * is identified as the "RSA Data Security, Inc. MD5 Message-Digest + * Algorithm" in all material mentioning or referencing this software + * or this function. + * + * License is also granted to make and use derivative works provided + * that such works are identified as "derived from the RSA Data + * Security, Inc. MD5 Message-Digest Algorithm" in all material + * mentioning or referencing the derived work. + * + * RSA Data Security, Inc. makes no representations concerning either + * the merchantability of this software or the suitability of this + * software for any particular purpose. It is provided "as is" + * without express or implied warranty of any kind. + * + * These notices must be retained in any copies of any part of this + * documentation and/or software. + */ + +#ifndef _SYS_MD5_H_ +#define _SYS_MD5_H_ + +#include + +#define MD5_DIGEST_LENGTH 16 +#define MD5_DIGEST_STRING_LENGTH 33 + +/* MD5 context. */ +typedef struct MD5Context { + uint32_t state[4]; /* state (ABCD) */ + uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +__BEGIN_DECLS +void MD5Init(MD5_CTX *); +void MD5Update(MD5_CTX *, const unsigned char *, unsigned int); +void MD5Final(unsigned char[MD5_DIGEST_LENGTH], MD5_CTX *); +#ifndef _KERNEL +char *MD5End(MD5_CTX *, char *); +char *MD5File(const char *, char *); +char *MD5Data(const unsigned char *, unsigned int, char *); +#endif /* _KERNEL */ +__END_DECLS + +#endif /* _SYS_MD5_H_ */ diff --git a/nbsd_include/sys/mman.h b/nbsd_include/sys/mman.h new file mode 100644 index 000000000..75860eaa4 --- /dev/null +++ b/nbsd_include/sys/mman.h @@ -0,0 +1,76 @@ +#ifndef _SYS_MMAN_H_ +#define _SYS_MMAN_H_ + +#include + +#include + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#undef _BSD_SIZE_T_ +#endif + +#include + +#ifndef mode_t +typedef __mode_t mode_t; +#define mode_t __mode_t +#endif + +#ifndef off_t +typedef __off_t off_t; /* file offset */ +#define off_t __off_t +#endif + + +/* + * Protections are chosen from these bits, or-ed together + */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* + * Flags contain sharing type and options. + * Sharing types; choose one. + */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ + +/* + * Mapping type + */ +#define MAP_ANON 0x0004 /* anonymous memory */ + +/* + * Minix specific flags. + */ +#define MAP_PREALLOC 0x0008 /* not on-demand */ +#define MAP_CONTIG 0x0010 /* contiguous in physical memory */ +#define MAP_LOWER16M 0x0020 /* physically below 16MB */ +#define MAP_ALIGN64K 0x0040 /* physically aligned at 64kB */ +#define MAP_LOWER1M 0x0080 /* physically below 16MB */ +#define MAP_ALIGNMENT_64KB MAP_ALIGN64K + +/* + * Error indicator returned by mmap(2) + */ +#define MAP_FAILED ((void *) -1) /* mmap() failed */ + +#include + +__BEGIN_DECLS +void * mmap(void *, size_t, int, int, int, off_t); +int munmap(void *, size_t); + +#ifdef __minix +int munmap_text(void *, size_t); +void * vm_remap(int d, int s, void *da, void *sa, size_t si); +int vm_unmap(int endpt, void *addr); +unsigned long vm_getphys(int endpt, void *addr); +u8_t vm_getrefcount(int endpt, void *addr); +#endif /* __minix */ +__END_DECLS + +#endif /* !_SYS_MMAN_H_ */ diff --git a/nbsd_include/sys/mount.h b/nbsd_include/sys/mount.h new file mode 100644 index 000000000..5abe7e093 --- /dev/null +++ b/nbsd_include/sys/mount.h @@ -0,0 +1,7 @@ +#ifndef _SYS_MOUNT_H +#define _SYS_MOUNT_H_ + +#include +#include + +#endif /* !_SYS_MOUNT_H_ */ diff --git a/nbsd_include/sys/null.h b/nbsd_include/sys/null.h new file mode 100644 index 000000000..18836fcb8 --- /dev/null +++ b/nbsd_include/sys/null.h @@ -0,0 +1,16 @@ +/* $NetBSD: null.h,v 1.8 2009/10/13 17:19:00 dsl Exp $ */ + +#ifndef _SYS_NULL_H_ +#define _SYS_NULL_H_ +#ifndef NULL +#if !defined(__GNUG__) || __GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 90) +#if !defined(__cplusplus) +#define NULL ((void *)0) +#else +#define NULL 0 +#endif /* !__cplusplus */ +#else +#define NULL __null +#endif +#endif +#endif /* _SYS_NULL_H_ */ diff --git a/nbsd_include/sys/param.h b/nbsd_include/sys/param.h new file mode 100644 index 000000000..ff6aef823 --- /dev/null +++ b/nbsd_include/sys/param.h @@ -0,0 +1,182 @@ +#ifndef _SYS_PARAM_H_ +#define _SYS_PARAM_H_ + +/* + * Historic BSD #defines -- probably will remain untouched for all time. + */ +#define BSD 199506 /* System version (year & month). */ +#define BSD4_3 1 +#define BSD4_4 1 + +/* + * #define __NetBSD_Version__ MMmmrrpp00 + * + * M = major version + * m = minor version; a minor number of 99 indicates current. + * r = 0 (*) + * p = patchlevel + * + * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local + * needs to be updated and the changes sent back to the groff maintainers. + * + * (*) Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric + * e.g. NetBSD-1.2D = 102040000 ('D' == 4) + * NetBSD-2.0H (200080000) was changed on 20041001 to: + * 2.99.9 (299000900) + */ + +#define __NetBSD_Version__ 599002900 /* NetBSD 5.99.29 */ + +#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \ + (m) * 1000000) + (p) * 100) <= __NetBSD_Version__) + +/* + * Historical NetBSD #define + * + * NetBSD 1.4 was the last release for which this value was incremented. + * The value is now permanently fixed at 199905. It will never be + * changed again. + * + * New code must use __NetBSD_Version__ instead, and should not even + * count on NetBSD being defined. + * + */ + +#define NetBSD 199905 /* NetBSD version (year & month). */ + +#include + +#ifndef __ASSEMBLER__ +#include +#include + +/* + * Machine-independent constants (some used in following include files). + * Redefined constants are from POSIX 1003.1 limits file. + * + * MAXCOMLEN should be >= sizeof(ac_comm) (see ) + * MAXHOSTNAMELEN should be >= (_POSIX_HOST_NAME_MAX + 1) (see ) + * MAXLOGNAME should be >= UT_NAMESIZE (see ) + */ +#include + + +#define MAXCOMLEN 16 /* max command name remembered */ +#define MAXINTERP PATH_MAX /* max interpreter file name length */ +/* DEPRECATED: use LOGIN_NAME_MAX instead. */ +#define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */ +#ifndef __minix +#define NCARGS ARG_MAX /* max bytes for an exec function */ +#endif +#define NGROUPS NGROUPS_MAX /* max number groups */ +#define NOGROUP 65535 /* marker for empty group set member */ + +#define MAXHOSTNAMELEN 256 /* max hostname size */ + +#ifndef NOFILE +#define NOFILE OPEN_MAX /* max open files per process */ +#endif +#ifndef MAXUPRC /* max simultaneous processes */ +#define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */ +#else +#if (MAXUPRC - 0) < CHILD_MAX +#error MAXUPRC less than CHILD_MAX. See options(4) for details. +#endif /* (MAXUPRC - 0) < CHILD_MAX */ +#endif /* !defined(MAXUPRC) */ + +/* Signals. */ +#include + +/* Machine type dependent parameters. */ +#include +#include + +/* pages ("clicks") to disk blocks */ +#define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) +#define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT)) + +/* bytes to pages */ +#define ctob(x) ((x) << PGSHIFT) +#define btoc(x) (((x) + PGOFSET) >> PGSHIFT) + +/* bytes to disk blocks */ +#define dbtob(x) ((x) << DEV_BSHIFT) +#define btodb(x) ((x) >> DEV_BSHIFT) + +#ifndef COHERENCY_UNIT +#define COHERENCY_UNIT 64 +#endif +#ifndef CACHE_LINE_SIZE +#define CACHE_LINE_SIZE 64 +#endif +#ifndef MAXCPUS +#define MAXCPUS 32 +#endif +#ifndef MAX_LWP_PER_PROC +#define MAX_LWP_PER_PROC 8000 +#endif + +/* + * Miscellaneous. + */ +#define NBPW sizeof(int) /* number of bytes per word (integer) */ + +#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ +#define NODEV (dev_t)(-1) /* non-existent device */ + +#define CBLOCK 64 /* Clist block size, must be a power of 2. */ +#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */ + /* Data chars/clist. */ +#define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE) +#define CROUND (CBLOCK - 1) /* Clist rounding. */ + +/* + * File system parameters and macros. + * + * The file system is made out of blocks of at most MAXBSIZE units, with + * smaller units (fragments) only in the last direct block. MAXBSIZE + * primarily determines the size of buffers in the buffer pool. It may be + * made larger without any effect on existing file systems; however making + * it smaller may make some file systems unmountable. + */ +#ifndef MAXBSIZE /* XXX */ +#define MAXBSIZE MAXPHYS +#endif +#define MAXFRAG 8 + +/* + * MAXPATHLEN defines the longest permissible path length after expanding + * symbolic links. It is used to allocate a temporary buffer from the buffer + * pool in which to do the name expansion, hence should be a power of two, + * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the + * maximum number of symbolic links that may be expanded in a path name. + * It should be set high enough to allow all legitimate uses, but halt + * infinite loops reasonably quickly. + * + * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see ) + */ +#define MAXPATHLEN PATH_MAX +#define MAXSYMLINKS 32 + +/* Bit map related macros. */ +#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) +#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) +#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) +#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) + +/* Macros for counting and rounding. */ +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#define rounddown(x,y) (((x)/(y))*(y)) +#define roundup2(x, m) (((x) + (m) - 1) & ~((m) - 1)) +#define powerof2(x) ((((x)-1)&(x))==0) + +/* Macros for min/max. */ +#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) +#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) + +#endif /* !__ASSEMBLER__ */ + +#endif /* !_SYS_PARAM_H_ */ diff --git a/nbsd_include/sys/poll.h b/nbsd_include/sys/poll.h new file mode 100644 index 000000000..6e93bed78 --- /dev/null +++ b/nbsd_include/sys/poll.h @@ -0,0 +1,67 @@ +/* $NetBSD: poll.h,v 1.3 2008/04/29 05:46:08 martin Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NBCOMPAT_POLL_H_ +#define _NBCOMPAT_POLL_H_ + +typedef unsigned int nfds_t; + +#define INFTIM -1 + +struct pollfd { + int fd; /* file descriptor */ + short events; /* events to look for */ + short revents; /* events returned */ +}; + +/* + * Testable events (may be specified in events field). + */ +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLRDNORM 0x0040 +#define POLLWRNORM POLLOUT +#define POLLRDBAND 0x0080 +#define POLLWRBAND 0x0100 + +/* + * Non-testable events (may not be specified in events field). + */ +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 + +__BEGIN_DECLS +int poll (struct pollfd *, nfds_t, int); +__END_DECLS + +#endif /* !_NBCOMPAT_POLL_H_ */ diff --git a/nbsd_include/sys/ptrace.h b/nbsd_include/sys/ptrace.h new file mode 100644 index 000000000..b829771a4 --- /dev/null +++ b/nbsd_include/sys/ptrace.h @@ -0,0 +1,58 @@ +/* + * definitions for ptrace(2) + */ + +#ifndef _PTRACE_H +#define _PTRACE_H + +/* Trace requests. */ +#define T_STOP -1 /* stop the process */ +#define T_OK 0 /* enable tracing by parent for this process */ +#define T_GETINS 1 /* return value from instruction space */ +#define T_GETDATA 2 /* return value from data space */ +#define T_GETUSER 3 /* return value from user process table */ +#define T_SETINS 4 /* set value from instruction space */ +#define T_SETDATA 5 /* set value from data space */ +#define T_SETUSER 6 /* set value in user process table */ +#define T_RESUME 7 /* resume execution */ +#define T_EXIT 8 /* exit */ +#define T_STEP 9 /* set trace bit */ +#define T_SYSCALL 10 /* trace system call */ +#define T_ATTACH 11 /* attach to a running process */ +#define T_DETACH 12 /* detach from a traced process */ +#define T_SETOPT 13 /* set trace options */ +#define T_GETRANGE 14 /* get range of values */ +#define T_SETRANGE 15 /* set range of values */ + +#define T_READB_INS 100 /* Read a byte from the text segment of an + * untraced process (only for root) + */ +#define T_WRITEB_INS 101 /* Write a byte in the text segment of an + * untraced process (only for root) + */ + +/* Trace options. */ +#define TO_TRACEFORK 0x1 /* automatically attach to forked children */ +#define TO_ALTEXEC 0x2 /* send SIGSTOP on successful exec() */ +#define TO_NOEXEC 0x4 /* do not send signal on successful exec() */ + +/* Trace spaces. */ +#define TS_INS 0 /* text space */ +#define TS_DATA 1 /* data space */ + +/* Trance range structure. */ +struct ptrace_range { + int pr_space; /* space in traced process */ + long pr_addr; /* address in traced process */ + void *pr_ptr; /* buffer in caller process */ + size_t pr_size; /* size of range, in bytes */ +}; + +/* Function Prototypes. */ +#include + +__BEGIN_DECLS +long ptrace(int _req, pid_t _pid, long _addr, long _data); +__END_DECLS + +#endif /* _PTRACE_H */ diff --git a/nbsd_include/sys/ptree.h b/nbsd_include/sys/ptree.h new file mode 100644 index 000000000..03f9930de --- /dev/null +++ b/nbsd_include/sys/ptree.h @@ -0,0 +1,188 @@ +/* $NetBSD: ptree.h,v 1.3 2008/11/25 15:13:47 ad Exp $ */ +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_PTREE_H_ +#define _SYS_PTREE_H_ + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +#include +#endif + +typedef enum { + PT_DESCENDING=-1, + PT_ASCENDING=1 +} pt_direction_t; + +typedef unsigned int pt_slot_t; +typedef unsigned int pt_bitoff_t; +typedef unsigned int pt_bitlen_t; + +typedef struct pt_node { + uintptr_t ptn_slots[2]; /* must be first */ +#define PT_SLOT_LEFT 0 +#define PT_SLOT_RIGHT 1 +#ifdef _PT_PRIVATE +#define PT_SLOT_ROOT 0 +#define PT_SLOT_OTHER 1 +#define PT_SLOT_ODDMAN 1 +#define PT_TYPE_LEAF 0x00000000 +#define PT_TYPE_BRANCH 0x00000001 +#define PT_TYPE_MASK 0x00000001 +#endif /* _PT_PRIVATE */ + + uint32_t ptn_nodedata; +#ifdef _PT_PRIVATE +#define PTN_LEAF_POSITION_BITS 8 +#define PTN_LEAF_POSITION_SHIFT 0 +#define PTN_BRANCH_POSITION_BITS 8 +#define PTN_BRANCH_POSITION_SHIFT 8 +#ifndef PTNOMASK +#define PTN_MASK_BITLEN_BITS 15 +#define PTN_MASK_BITLEN_SHIFT 16 +#define PTN_MASK_FLAG 0x80000000 +#endif +#endif /* _PT_PRIVATE */ + + uint32_t ptn_branchdata; +#ifdef _PT_PRIVATE +#define PTN_BRANCH_BITOFF_BITS 15 +#define PTN_BRANCH_BITOFF_SHIFT 0 +#define PTN_BRANCH_BITLEN_BITS 8 +#define PTN_BRANCH_BITLEN_SHIFT 16 +#if 0 +#define PTN_ORIENTATION_BITS 1 +#define PTN_ORIENTATION_SHIFT 30 +#endif +#define PTN_BRANCH_UNUSED 0x3f000000 +#define PTN_XBRANCH_FLAG 0x80000000 +#endif /* _PT_PRIVATE */ +} pt_node_t; + +#ifdef _PT_PRIVATE +#define PT_NODE(node) ((pt_node_t *)(node & ~PT_TYPE_MASK)) +#define PT_TYPE(node) ((node) & PT_TYPE_MASK) +#define PT_NULL 0 +#define PT_NULL_P(node) ((node) == PT_NULL) +#define PT_LEAF_P(node) (PT_TYPE(node) == PT_TYPE_LEAF) +#define PT_BRANCH_P(node) (PT_TYPE(node) == PT_TYPE_BRANCH) +#define PTN__TYPELESS(ptn) (((uintptr_t)ptn) & ~PT_TYPE_MASK) +#define PTN_LEAF(ptn) (PTN__TYPELESS(ptn) | PT_TYPE_LEAF) +#define PTN_BRANCH(ptn) (PTN__TYPELESS(ptn) | PT_TYPE_BRANCH) + +#ifndef PTNOMASK +#define PTN_MARK_MASK(ptn) ((ptn)->ptn_nodedata |= PTN_MASK_FLAG) +#define PTN_ISMASK_P(ptn) (((ptn)->ptn_nodedata & PTN_MASK_FLAG) != 0) +#endif +#define PTN_MARK_XBRANCH(ptn) ((ptn)->ptn_branchdata |= PTN_XBRANCH_FLAG) +#define PTN_ISXBRANCH_P(ptn) (((ptn)->ptn_branchdata & PTN_XBRANCH_FLAG) != 0) +#define PTN_ISROOT_P(pt, ptn) ((ptn) == &(pt)->pt_rootnode) + +#define PTN_BRANCH_SLOT(ptn,slot) ((ptn)->ptn_slots[slot]) +#define PTN_BRANCH_ROOT_SLOT(ptn) ((ptn)->ptn_slots[PT_SLOT_ROOT]) +#define PTN_BRANCH_ODDMAN_SLOT(ptn) ((ptn)->ptn_slots[PT_SLOT_ODDMAN]) +#define PTN_COPY_BRANCH_SLOTS(dst,src) \ + ((dst)->ptn_slots[PT_SLOT_LEFT ] = (src)->ptn_slots[PT_SLOT_LEFT ], \ + (dst)->ptn_slots[PT_SLOT_RIGHT] = (src)->ptn_slots[PT_SLOT_RIGHT]) +#define PTN_ISSLOTVALID_P(ptn,slot) ((slot) < (1 << PTN_BRANCH_BITLEN(pt))) + +#define PT__MASK(n) ((1 << n ## _BITS) - 1) +#define PT__SHIFT(n) (n ## _SHIFT) +#define PTN__EXTRACT(field, b) \ + (((field) >> PT__SHIFT(b)) & PT__MASK(b)) +#define PTN__INSERT2(field, v, shift, mask) \ + ((field) = ((field) & ~((mask) << (shift))) | ((v) << (shift))) +#define PTN__INSERT(field, b, v) \ + PTN__INSERT2(field, v, PT__SHIFT(b), PT__MASK(b)) + +#define PTN_BRANCH_BITOFF(ptn) \ + PTN__EXTRACT((ptn)->ptn_branchdata, PTN_BRANCH_BITOFF) +#define PTN_BRANCH_BITLEN(ptn) \ + PTN__EXTRACT((ptn)->ptn_branchdata, PTN_BRANCH_BITLEN) +#define PTN_SET_BRANCH_BITOFF(ptn,bitoff) \ + PTN__INSERT((ptn)->ptn_branchdata, PTN_BRANCH_BITOFF, bitoff) +#define PTN_SET_BRANCH_BITLEN(ptn,bitlen) \ + PTN__INSERT((ptn)->ptn_branchdata, PTN_BRANCH_BITLEN, bitlen) + +#define PTN_LEAF_POSITION(ptn) \ + PTN__EXTRACT((ptn)->ptn_nodedata, PTN_LEAF_POSITION) +#define PTN_BRANCH_POSITION(ptn) \ + PTN__EXTRACT((ptn)->ptn_nodedata, PTN_BRANCH_POSITION) +#define PTN_SET_LEAF_POSITION(ptn,slot) \ + PTN__INSERT((ptn)->ptn_nodedata, PTN_LEAF_POSITION, slot) +#define PTN_SET_BRANCH_POSITION(ptn,slot) \ + PTN__INSERT((ptn)->ptn_nodedata, PTN_BRANCH_POSITION, slot) + +#ifndef PTNOMASK +#define PTN_MASK_BITLEN(ptn) \ + PTN__EXTRACT((ptn)->ptn_nodedata, PTN_MASK_BITLEN) +#define PTN_SET_MASK_BITLEN(ptn,masklen) \ + PTN__INSERT((ptn)->ptn_nodedata, PTN_MASK_BITLEN, masklen) +#endif + +#if 0 +#define PTN_ORIENTATION(ptn) \ + PTN__EXTRACT((ptn)->ptn_branchdata, PTN_ORIENTATION) +#define PTN_SET_ORIENTATION(ptn,slot) \ + PTN__INSERT((ptn)->ptn_branchdata, PTN_ORIENTATION, slot) +#endif +#endif /* _PT_PRIVATE */ + +typedef struct pt_tree_ops { + bool (*ptto_matchnode)(const void *, const void *, pt_bitoff_t, + pt_bitoff_t *, pt_slot_t *); + bool (*ptto_matchkey)(const void *, const void *, pt_bitoff_t, + pt_bitlen_t); + pt_slot_t (*ptto_testnode)(const void *, pt_bitoff_t, pt_bitlen_t); + pt_slot_t (*ptto_testkey)(const void *, pt_bitoff_t, pt_bitlen_t); +} pt_tree_ops_t; + +typedef struct pt_tree { + pt_node_t pt_rootnode; +#define pt_root pt_rootnode.ptn_slots[PT_SLOT_ROOT] +#define pt_oddman pt_rootnode.ptn_slots[PT_SLOT_ODDMAN] + const pt_tree_ops_t *pt_ops; + size_t pt_node_offset; + size_t pt_key_offset; + uintptr_t pt_spare[4]; +} pt_tree_t; + +#define PT_FILTER_MASK 0x00000001 /* node is a mask */ +typedef bool (*pt_filter_t)(void *, const void *, int); + +void ptree_init(pt_tree_t *, const pt_tree_ops_t *, size_t, size_t); +bool ptree_insert_node(pt_tree_t *, void *); +bool ptree_insert_mask_node(pt_tree_t *, void *, pt_bitlen_t); +void * ptree_find_filtered_node(pt_tree_t *, void *, pt_filter_t, void *); +#define ptree_find_node(pt,key) \ + ptree_find_filtered_node((pt), (key), NULL, NULL) +void ptree_remove_node(pt_tree_t *, void *); +void * ptree_iterate(pt_tree_t *, const void *, pt_direction_t); + +#endif /* _SYS_PTREE_H_ */ diff --git a/nbsd_include/sys/queue.h b/nbsd_include/sys/queue.h new file mode 100644 index 000000000..4c72a39dd --- /dev/null +++ b/nbsd_include/sys/queue.h @@ -0,0 +1,739 @@ +/* $NetBSD: queue.h,v 1.52 2009/04/20 09:56:08 mschuett Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#include + +/* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues, and circular queues. + * + * A singly-linked list is headed by a single forward pointer. The + * elements are singly linked for minimum space and pointer manipulation + * overhead at the expense of O(n) removal for arbitrary elements. New + * elements can be added to the list after an existing element or at the + * head of the list. Elements being removed from the head of the list + * should use the explicit macro for this purpose for optimum + * efficiency. A singly-linked list may only be traversed in the forward + * direction. Singly-linked lists are ideal for applications with large + * datasets and few or no removals or for implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ +#if defined(_KERNEL) && defined(QUEUEDEBUG) +#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \ + if ((head)->lh_first && \ + (head)->lh_first->field.le_prev != &(head)->lh_first) \ + panic("LIST_INSERT_HEAD %p %s:%d", (head), __FILE__, __LINE__); +#define QUEUEDEBUG_LIST_OP(elm, field) \ + if ((elm)->field.le_next && \ + (elm)->field.le_next->field.le_prev != \ + &(elm)->field.le_next) \ + panic("LIST_* forw %p %s:%d", (elm), __FILE__, __LINE__);\ + if (*(elm)->field.le_prev != (elm)) \ + panic("LIST_* back %p %s:%d", (elm), __FILE__, __LINE__); +#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field) \ + (elm)->field.le_next = (void *)1L; \ + (elm)->field.le_prev = (void *)1L; +#else +#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) +#define QUEUEDEBUG_LIST_OP(elm, field) +#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field) +#endif + +#define LIST_INIT(head) do { \ + (head)->lh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + QUEUEDEBUG_LIST_OP((listelm), field) \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + QUEUEDEBUG_LIST_OP((listelm), field) \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + QUEUEDEBUG_LIST_INSERT_HEAD((head), (elm), field) \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (/*CONSTCOND*/0) + +#define LIST_REMOVE(elm, field) do { \ + QUEUEDEBUG_LIST_OP((elm), field) \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \ +} while (/*CONSTCOND*/0) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = ((head)->lh_first); \ + (var); \ + (var) = ((var)->field.le_next)) + +/* + * List access methods. + */ +#define LIST_EMPTY(head) ((head)->lh_first == NULL) +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) do { \ + (head)->slh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (/*CONSTCOND*/0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = (head)->slh_first; \ + while(curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define SLIST_REMOVE_AFTER(slistelm, field) do { \ + (slistelm)->field.sle_next = \ + SLIST_NEXT(SLIST_NEXT((slistelm), field), field); \ +} while (/*CONSTCOND*/0) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List access methods. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first; /* first element */ \ + struct type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_INIT(head) do { \ + (head)->stqh_first = NULL; \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (head)->stqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.stqe_next = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &(elm)->field.stqe_next; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (listelm)->field.stqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (/*CONSTCOND*/0) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if ((head)->stqh_first == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->stqh_first; \ + while (curelm->field.stqe_next != (elm)) \ + curelm = curelm->field.stqe_next; \ + if ((curelm->field.stqe_next = \ + curelm->field.stqe_next->field.stqe_next) == NULL) \ + (head)->stqh_last = &(curelm)->field.stqe_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->stqh_first); \ + (var); \ + (var) = ((var)->field.stqe_next)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->stqh_last) - offsetof(struct type, field)))) + +/* + * Singly-linked Tail queue access methods. + */ +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) +#define STAILQ_FIRST(head) ((head)->stqh_first) +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_REMOVE(head, elm, type, field) do { \ + if ((head)->sqh_first == (elm)) { \ + SIMPLEQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->sqh_first; \ + while (curelm->field.sqe_next != (elm)) \ + curelm = curelm->field.sqe_next; \ + if ((curelm->field.sqe_next = \ + curelm->field.sqe_next->field.sqe_next) == NULL) \ + (head)->sqh_last = &(curelm)->field.sqe_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for ((var) = ((head)->sqh_first); \ + (var); \ + (var) = ((var)->field.sqe_next)) + +#define SIMPLEQ_FOREACH_SAFE(var, head, field, next) \ + for ((var) = ((head)->sqh_first); \ + (var) && ((next = ((var)->field.sqe_next)), 1); \ + (var) = (next)) + +#define SIMPLEQ_CONCAT(head1, head2) do { \ + if (!SIMPLEQ_EMPTY((head2))) { \ + *(head1)->sqh_last = (head2)->sqh_first; \ + (head1)->sqh_last = (head2)->sqh_last; \ + SIMPLEQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +#define SIMPLEQ_LAST(head, type, field) \ + (SIMPLEQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->sqh_last) - offsetof(struct type, field)))) + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL) +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + + +/* + * Tail queue definitions. + */ +#define _TAILQ_HEAD(name, type, qual) \ +struct name { \ + qual type *tqh_first; /* first element */ \ + qual type *qual *tqh_last; /* addr of last next element */ \ +} +#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,) + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define _TAILQ_ENTRY(type, qual) \ +struct { \ + qual type *tqe_next; /* next element */ \ + qual type *qual *tqe_prev; /* address of previous next element */\ +} +#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,) + +/* + * Tail queue functions. + */ +#if defined(_KERNEL) && defined(QUEUEDEBUG) +#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \ + if ((head)->tqh_first && \ + (head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \ + panic("TAILQ_INSERT_HEAD %p %s:%d", (head), __FILE__, __LINE__); +#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \ + if (*(head)->tqh_last != NULL) \ + panic("TAILQ_INSERT_TAIL %p %s:%d", (head), __FILE__, __LINE__); +#define QUEUEDEBUG_TAILQ_OP(elm, field) \ + if ((elm)->field.tqe_next && \ + (elm)->field.tqe_next->field.tqe_prev != \ + &(elm)->field.tqe_next) \ + panic("TAILQ_* forw %p %s:%d", (elm), __FILE__, __LINE__);\ + if (*(elm)->field.tqe_prev != (elm)) \ + panic("TAILQ_* back %p %s:%d", (elm), __FILE__, __LINE__); +#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field) \ + if ((elm)->field.tqe_next == NULL && \ + (head)->tqh_last != &(elm)->field.tqe_next) \ + panic("TAILQ_PREREMOVE head %p elm %p %s:%d", \ + (head), (elm), __FILE__, __LINE__); +#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field) \ + (elm)->field.tqe_next = (void *)1L; \ + (elm)->field.tqe_prev = (void *)1L; +#else +#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) +#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) +#define QUEUEDEBUG_TAILQ_OP(elm, field) +#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field) +#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field) +#endif + +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + QUEUEDEBUG_TAILQ_INSERT_HEAD((head), (elm), field) \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + QUEUEDEBUG_TAILQ_INSERT_TAIL((head), (elm), field) \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QUEUEDEBUG_TAILQ_OP((listelm), field) \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + QUEUEDEBUG_TAILQ_OP((listelm), field) \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + QUEUEDEBUG_TAILQ_PREREMOVE((head), (elm), field) \ + QUEUEDEBUG_TAILQ_OP((elm), field) \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \ +} while (/*CONSTCOND*/0) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->tqh_first); \ + (var); \ + (var) = ((var)->field.tqe_next)) + +#define TAILQ_FOREACH_SAFE(var, head, field, next) \ + for ((var) = ((head)->tqh_first); \ + (var) != NULL && ((next) = TAILQ_NEXT(var, field), 1); \ + (var) = (next)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ + (var); \ + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((prev) = TAILQ_PREV((var), headname, field), 1);\ + (var) = (prev)) + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +/* + * Tail queue access methods. + */ +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + + +/* + * Circular queue definitions. + */ +#if defined(_KERNEL) && defined(QUEUEDEBUG) +#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field) \ + if ((head)->cqh_first != (void *)(head) && \ + (head)->cqh_first->field.cqe_prev != (void *)(head)) \ + panic("CIRCLEQ head forw %p %s:%d", (head), \ + __FILE__, __LINE__); \ + if ((head)->cqh_last != (void *)(head) && \ + (head)->cqh_last->field.cqe_next != (void *)(head)) \ + panic("CIRCLEQ head back %p %s:%d", (head), \ + __FILE__, __LINE__); +#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field) \ + if ((elm)->field.cqe_next == (void *)(head)) { \ + if ((head)->cqh_last != (elm)) \ + panic("CIRCLEQ elm last %p %s:%d", (elm), \ + __FILE__, __LINE__); \ + } else { \ + if ((elm)->field.cqe_next->field.cqe_prev != (elm)) \ + panic("CIRCLEQ elm forw %p %s:%d", (elm), \ + __FILE__, __LINE__); \ + } \ + if ((elm)->field.cqe_prev == (void *)(head)) { \ + if ((head)->cqh_first != (elm)) \ + panic("CIRCLEQ elm first %p %s:%d", (elm), \ + __FILE__, __LINE__); \ + } else { \ + if ((elm)->field.cqe_prev->field.cqe_next != (elm)) \ + panic("CIRCLEQ elm prev %p %s:%d", (elm), \ + __FILE__, __LINE__); \ + } +#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field) \ + (elm)->field.cqe_next = (void *)1L; \ + (elm)->field.cqe_prev = (void *)1L; +#else +#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field) +#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field) +#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field) +#endif + +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { (void *)&head, (void *)&head } + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Circular queue functions. + */ +#define CIRCLEQ_INIT(head) do { \ + (head)->cqh_first = (void *)(head); \ + (head)->cqh_last = (void *)(head); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \ + QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \ + QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = (void *)(head); \ + if ((head)->cqh_last == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \ + (elm)->field.cqe_next = (void *)(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \ + QUEUEDEBUG_CIRCLEQ_ELM((head), (elm), field) \ + if ((elm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ + QUEUEDEBUG_CIRCLEQ_POSTREMOVE((elm), field) \ +} while (/*CONSTCOND*/0) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for ((var) = ((head)->cqh_first); \ + (var) != (const void *)(head); \ + (var) = ((var)->field.cqe_next)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for ((var) = ((head)->cqh_last); \ + (var) != (const void *)(head); \ + (var) = ((var)->field.cqe_prev)) + +/* + * Circular queue access methods. + */ +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CIRCLEQ_LAST(head) ((head)->cqh_last) +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) + +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \ + (((elm)->field.cqe_next == (void *)(head)) \ + ? ((head)->cqh_first) \ + : (elm->field.cqe_next)) +#define CIRCLEQ_LOOP_PREV(head, elm, field) \ + (((elm)->field.cqe_prev == (void *)(head)) \ + ? ((head)->cqh_last) \ + : (elm->field.cqe_prev)) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/nbsd_include/sys/rbtree.h b/nbsd_include/sys/rbtree.h new file mode 100644 index 000000000..34caeff89 --- /dev/null +++ b/nbsd_include/sys/rbtree.h @@ -0,0 +1,194 @@ +/* $NetBSD: rbtree.h,v 1.1 2010/09/25 01:42:40 matt Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_RBTREE_H_ +#define _SYS_RBTREE_H_ + +#if defined(_KERNEL) || defined(_STANDALONE) +#include +#else +#include +#include +#endif +#include +#include + +__BEGIN_DECLS + +typedef struct rb_node { + struct rb_node *rb_nodes[2]; +#define RB_DIR_LEFT 0 +#define RB_DIR_RIGHT 1 +#define RB_DIR_OTHER 1 +#define rb_left rb_nodes[RB_DIR_LEFT] +#define rb_right rb_nodes[RB_DIR_RIGHT] + + /* + * rb_info contains the two flags and the parent back pointer. + * We put the two flags in the low two bits since we know that + * rb_node will have an alignment of 4 or 8 bytes. + */ + uintptr_t rb_info; +#define RB_FLAG_POSITION 0x2 +#define RB_FLAG_RED 0x1 +#define RB_FLAG_MASK (RB_FLAG_POSITION|RB_FLAG_RED) +#define RB_FATHER(rb) \ + ((struct rb_node *)((rb)->rb_info & ~RB_FLAG_MASK)) +#define RB_SET_FATHER(rb, father) \ + ((void)((rb)->rb_info = (uintptr_t)(father)|((rb)->rb_info & RB_FLAG_MASK))) + +#define RB_SENTINEL_P(rb) ((rb) == NULL) +#define RB_LEFT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_left) +#define RB_RIGHT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_right) +#define RB_FATHER_SENTINEL_P(rb) RB_SENTINEL_P(RB_FATHER((rb))) +#define RB_CHILDLESS_P(rb) \ + (RB_SENTINEL_P(rb) || (RB_LEFT_SENTINEL_P(rb) && RB_RIGHT_SENTINEL_P(rb))) +#define RB_TWOCHILDREN_P(rb) \ + (!RB_SENTINEL_P(rb) && !RB_LEFT_SENTINEL_P(rb) && !RB_RIGHT_SENTINEL_P(rb)) + +#define RB_POSITION(rb) \ + (((rb)->rb_info & RB_FLAG_POSITION) ? RB_DIR_RIGHT : RB_DIR_LEFT) +#define RB_RIGHT_P(rb) (RB_POSITION(rb) == RB_DIR_RIGHT) +#define RB_LEFT_P(rb) (RB_POSITION(rb) == RB_DIR_LEFT) +#define RB_RED_P(rb) (!RB_SENTINEL_P(rb) && ((rb)->rb_info & RB_FLAG_RED) != 0) +#define RB_BLACK_P(rb) (RB_SENTINEL_P(rb) || ((rb)->rb_info & RB_FLAG_RED) == 0) +#define RB_MARK_RED(rb) ((void)((rb)->rb_info |= RB_FLAG_RED)) +#define RB_MARK_BLACK(rb) ((void)((rb)->rb_info &= ~RB_FLAG_RED)) +#define RB_INVERT_COLOR(rb) ((void)((rb)->rb_info ^= RB_FLAG_RED)) +#define RB_ROOT_P(rbt, rb) ((rbt)->rbt_root == (rb)) +#define RB_SET_POSITION(rb, position) \ + ((void)((position) ? ((rb)->rb_info |= RB_FLAG_POSITION) : \ + ((rb)->rb_info &= ~RB_FLAG_POSITION))) +#define RB_ZERO_PROPERTIES(rb) ((void)((rb)->rb_info &= ~RB_FLAG_MASK)) +#define RB_COPY_PROPERTIES(dst, src) \ + ((void)((dst)->rb_info ^= ((dst)->rb_info ^ (src)->rb_info) & RB_FLAG_MASK)) +#define RB_SWAP_PROPERTIES(a, b) do { \ + uintptr_t xorinfo = ((a)->rb_info ^ (b)->rb_info) & RB_FLAG_MASK; \ + (a)->rb_info ^= xorinfo; \ + (b)->rb_info ^= xorinfo; \ + } while (/*CONSTCOND*/ 0) +#ifdef RBDEBUG + TAILQ_ENTRY(rb_node) rb_link; +#endif +} rb_node_t; + +#define RB_TREE_MIN(T) rb_tree_iterate((T), NULL, RB_DIR_LEFT) +#define RB_TREE_MAX(T) rb_tree_iterate((T), NULL, RB_DIR_RIGHT) +#define RB_TREE_FOREACH(N, T) \ + for ((N) = RB_TREE_MIN(T); (N); \ + (N) = rb_tree_iterate((T), (N), RB_DIR_RIGHT)) +#define RB_TREE_FOREACH_REVERSE(N, T) \ + for ((N) = RB_TREE_MAX(T); (N); \ + (N) = rb_tree_iterate((T), (N), RB_DIR_LEFT)) + +#ifdef RBDEBUG +TAILQ_HEAD(rb_node_qh, rb_node); + +#define RB_TAILQ_REMOVE(a, b, c) TAILQ_REMOVE(a, b, c) +#define RB_TAILQ_INIT(a) TAILQ_INIT(a) +#define RB_TAILQ_INSERT_HEAD(a, b, c) TAILQ_INSERT_HEAD(a, b, c) +#define RB_TAILQ_INSERT_BEFORE(a, b, c) TAILQ_INSERT_BEFORE(a, b, c) +#define RB_TAILQ_INSERT_AFTER(a, b, c, d) TAILQ_INSERT_AFTER(a, b, c, d) +#else +#define RB_TAILQ_REMOVE(a, b, c) do { } while (/*CONSTCOND*/0) +#define RB_TAILQ_INIT(a) do { } while (/*CONSTCOND*/0) +#define RB_TAILQ_INSERT_HEAD(a, b, c) do { } while (/*CONSTCOND*/0) +#define RB_TAILQ_INSERT_BEFORE(a, b, c) do { } while (/*CONSTCOND*/0) +#define RB_TAILQ_INSERT_AFTER(a, b, c, d) do { } while (/*CONSTCOND*/0) +#endif /* RBDEBUG */ + +/* + * rbto_compare_nodes_fn: + * return a positive value if the first node > the second node. + * return a negative value if the first node < the second node. + * return 0 if they are considered same. + * + * rbto_compare_key_fn: + * return a positive value if the node > the key. + * return a negative value if the node < the key. + * return 0 if they are considered same. + */ + +typedef signed int (*const rbto_compare_nodes_fn)(void *, + const void *, const void *); +typedef signed int (*const rbto_compare_key_fn)(void *, + const void *, const void *); + +typedef struct { + rbto_compare_nodes_fn rbto_compare_nodes; + rbto_compare_key_fn rbto_compare_key; + size_t rbto_node_offset; + void *rbto_context; +} rb_tree_ops_t; + +typedef struct rb_tree { + struct rb_node *rbt_root; + const rb_tree_ops_t *rbt_ops; + struct rb_node *rbt_minmax[2]; +#ifdef RBDEBUG + struct rb_node_qh rbt_nodes; +#endif +#ifdef RBSTATS + unsigned int rbt_count; + unsigned int rbt_insertions; + unsigned int rbt_removals; + unsigned int rbt_insertion_rebalance_calls; + unsigned int rbt_insertion_rebalance_passes; + unsigned int rbt_removal_rebalance_calls; + unsigned int rbt_removal_rebalance_passes; +#endif +} rb_tree_t; + +#ifdef RBSTATS +#define RBSTAT_INC(v) ((void)((v)++)) +#define RBSTAT_DEC(v) ((void)((v)--)) +#else +#define RBSTAT_INC(v) do { } while (/*CONSTCOND*/0) +#define RBSTAT_DEC(v) do { } while (/*CONSTCOND*/0) +#endif + +void rb_tree_init(rb_tree_t *, const rb_tree_ops_t *); +void * rb_tree_insert_node(rb_tree_t *, void *); +void * rb_tree_find_node(rb_tree_t *, const void *); +void * rb_tree_find_node_geq(rb_tree_t *, const void *); +void * rb_tree_find_node_leq(rb_tree_t *, const void *); +void rb_tree_remove_node(rb_tree_t *, void *); +void * rb_tree_iterate(rb_tree_t *, void *, const unsigned int); +#ifdef RBDEBUG +void rb_tree_check(const rb_tree_t *, bool); +#endif +#ifdef RBSTATS +void rb_tree_depths(const rb_tree_t *, size_t *); +#endif + +__END_DECLS + +#endif /* _SYS_RBTREE_H_*/ diff --git a/nbsd_include/sys/reboot.h b/nbsd_include/sys/reboot.h new file mode 100644 index 000000000..6a4edd825 --- /dev/null +++ b/nbsd_include/sys/reboot.h @@ -0,0 +1,13 @@ +#ifndef _SYS_REBOOT_H_ +#define _SYS_REBOOT_H_ + +/* How to exit the system or stop a server process. */ +#define RBT_HALT 0 /* shutdown and return to monitor */ +#define RBT_REBOOT 1 /* reboot the system through the monitor */ +#define RBT_PANIC 2 /* a server panics */ +#define RBT_MONITOR 3 /* let the monitor do this */ +#define RBT_RESET 4 /* hard reset the system */ +#define RBT_DEFAULT 5 /* return to monitor, reset if not possible */ +#define RBT_INVALID 6 /* first invalid reboot flag */ + +#endif diff --git a/nbsd_include/sys/resource.h b/nbsd_include/sys/resource.h new file mode 100644 index 000000000..2aef2e853 --- /dev/null +++ b/nbsd_include/sys/resource.h @@ -0,0 +1,51 @@ +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ + +#include +#include + +/* + * Process priority specifications to get/setpriority. + */ +#define PRIO_MIN -20 +#define PRIO_MAX 20 + +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 + +/* + * Resource limits + */ +#define RLIMIT_CORE 1 +#define RLIMIT_CPU 2 +#define RLIMIT_DATA 3 +#define RLIMIT_FSIZE 4 +#define RLIMIT_NOFILE 5 +#define RLIMIT_STACK 6 +#define RLIMIT_AS 7 +#define RLIMIT_VMEM RLIMIT_AS /* common alias */ + +#if defined(_NETBSD_SOURCE) +#define RLIM_NLIMITS 8 /* number of resource limits */ +#endif + +#define RLIM_INFINITY ((rlim_t) -1) +#define RLIM_SAVED_CUR RLIM_INFINITY +#define RLIM_SAVED_MAX RLIM_INFINITY + +struct rlimit +{ + rlim_t rlim_cur; + rlim_t rlim_max; +}; + +#include + +__BEGIN_DECLS +int getpriority(int, int); +int getrlimit(int, struct rlimit *); +int setpriority(int, int, int); +__END_DECLS + +#endif /* !_SYS_RESOURCE_H_ */ diff --git a/nbsd_include/sys/rmd160.h b/nbsd_include/sys/rmd160.h new file mode 100644 index 000000000..0ef2c748f --- /dev/null +++ b/nbsd_include/sys/rmd160.h @@ -0,0 +1,56 @@ +/* $NetBSD: rmd160.h,v 1.2 2008/02/16 17:37:13 apb Exp $ */ +/* $KAME: rmd160.h,v 1.2 2003/07/25 09:37:55 itojun Exp $ */ +/* $OpenBSD: rmd160.h,v 1.3 2002/03/14 01:26:51 millert Exp $ */ +/* + * Copyright (c) 2001 Markus Friedl. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _RMD160_H +#define _RMD160_H + +#include +#include + +#define RMD160_DIGEST_LENGTH 20 +#define RMD160_DIGEST_STRING_LENGTH 41 + +/* RMD160 context. */ +typedef struct RMD160Context { + uint32_t state[5]; /* state */ + uint64_t count; /* number of bits, modulo 2^64 */ + u_char buffer[64]; /* input buffer */ +} RMD160_CTX; + +__BEGIN_DECLS +void RMD160Init(RMD160_CTX *); +void RMD160Transform(uint32_t [5], const u_char [64]); +void RMD160Update(RMD160_CTX *, const u_char *, uint32_t); +void RMD160Final(u_char [RMD160_DIGEST_LENGTH], RMD160_CTX *); +#ifndef _KERNEL +char *RMD160End(RMD160_CTX *, char *); +char *RMD160FileChunk(const char *, char *, off_t, off_t); +char *RMD160File(const char *, char *); +char *RMD160Data(const u_char *, size_t, char *); +#endif /* _KERNEL */ +__END_DECLS + +#endif /* _RMD160_H */ diff --git a/nbsd_include/sys/select.h b/nbsd_include/sys/select.h new file mode 100644 index 000000000..a54af4f50 --- /dev/null +++ b/nbsd_include/sys/select.h @@ -0,0 +1,76 @@ +/* $NetBSD: select.h,v 1.36 2009/11/11 09:48:51 rmind Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)select.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_SELECT_H_ +#define _SYS_SELECT_H_ + +#include +#include +#include + +#ifdef _KERNEL +#include /* for struct selinfo */ +#include /* for sigset_t */ + +struct lwp; +struct proc; +struct timespec; +struct cpu_info; +struct socket; + +int selcommon(register_t *, int, fd_set *, fd_set *, fd_set *, + struct timespec *, sigset_t *); +void selrecord(struct lwp *selector, struct selinfo *); +void selnotify(struct selinfo *, int, long); +void selsysinit(struct cpu_info *); +void selinit(struct selinfo *); +void seldestroy(struct selinfo *); +int pollsock(struct socket *, const struct timespec *, int); + +#else /* _KERNEL */ + +#include +#include + +__BEGIN_DECLS +#ifndef __LIBC12_SOURCE__ +int pselect(int, fd_set * __restrict, fd_set * __restrict, + fd_set * __restrict, const struct timespec * __restrict, + const sigset_t * __restrict) __RENAME(__pselect50); +int select(int, fd_set * __restrict, fd_set * __restrict, + fd_set * __restrict, struct timeval * __restrict) __RENAME(__select50); +#endif /* __LIBC12_SOURCE__ */ +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_SELECT_H_ */ diff --git a/nbsd_include/sys/sem.h b/nbsd_include/sys/sem.h new file mode 100644 index 000000000..05971dde1 --- /dev/null +++ b/nbsd_include/sys/sem.h @@ -0,0 +1,121 @@ +/* $NetBSD: sem.h,v 1.29 2009/01/19 19:39:41 christos Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * SVID compatible sem.h file + * + * Author: Daniel Boulet + */ + +#ifndef _SYS_SEM_H_ +#define _SYS_SEM_H_ + +#include + +#include + +struct semid_ds { + struct ipc_perm sem_perm; /* operation permission struct */ + time_t sem_otime; /* last semop() time */ + unsigned long int __unused1; + time_t sem_ctime; /* last time changed by semctl() */ + unsigned long int __unused2; + unsigned long int sem_nsems; /* number of semaphores in set */ + unsigned long int __unused3; + unsigned long int __unused4; +}; + +/* + * semop's sops parameter structure + */ +struct sembuf { + unsigned short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +}; +#define SEM_UNDO 0x1000 /* undo changes on process exit */ + +/* + * commands for semctl + */ +#define GETPID 11 /* get sempid */ +#define GETVAL 12 /* get semval */ +#define GETALL 13 /* get all semval's */ +#define GETNCNT 14 /* get semncnt */ +#define GETZCNT 15 /* get semzcnt */ +#define SETVAL 16 /* set semval */ +#define SETALL 17 /* set all semval's */ + +#ifdef __USE_MISC + +/* ipcs ctl cmds */ +# define SEM_STAT 18 +# define SEM_INFO 19 + +/* + * semaphore info struct + */ +struct seminfo { + int32_t semmap; /* # of entries in semaphore map */ + int32_t semmni; /* # of semaphore identifiers */ + int32_t semmns; /* # of semaphores in system */ + int32_t semmnu; /* # of undo structures in system */ + int32_t semmsl; /* max # of semaphores per id */ + int32_t semopm; /* max # of operations per semop call */ + int32_t semume; /* max # of undo entries per process */ + int32_t semusz; /* size in bytes of undo structure */ + int32_t semvmx; /* semaphore maximum value */ + int32_t semaem; /* adjust on exit max value */ +}; + +#endif /* __USE_MISC */ + +/* + * Configuration parameters + */ +#define SEMMNI 128 +#define SEMMSL 250 +#define SEMMNS (SEMMSL*SEMMNI) + +#define SEMOPM 32 +#define SEMVMX 32767 + + +#include + +__BEGIN_DECLS +int semctl(int, int, int, ...); +int semget(key_t, int, int); +int semop(int, struct sembuf *, size_t); +__END_DECLS + +#endif /* !_SYS_SEM_H_ */ diff --git a/nbsd_include/sys/sha1.h b/nbsd_include/sys/sha1.h new file mode 100644 index 000000000..b936c3938 --- /dev/null +++ b/nbsd_include/sys/sha1.h @@ -0,0 +1,37 @@ +/* $NetBSD: sha1.h,v 1.14 2009/11/06 20:31:19 joerg Exp $ */ + +/* + * SHA-1 in C + * By Steve Reid + * 100% Public Domain + */ + +#ifndef _SYS_SHA1_H_ +#define _SYS_SHA1_H_ + +#include +#include + +#define SHA1_DIGEST_LENGTH 20 +#define SHA1_DIGEST_STRING_LENGTH 41 + +typedef struct { + uint32_t state[5]; + uint32_t count[2]; + uint8_t buffer[64]; +} SHA1_CTX; + +__BEGIN_DECLS +void SHA1Transform(uint32_t[5], const uint8_t[64]); +void SHA1Init(SHA1_CTX *); +void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int); +void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *); +#ifndef _KERNEL +char *SHA1End(SHA1_CTX *, char *); +char *SHA1FileChunk(const char *, char *, off_t, off_t); +char *SHA1File(const char *, char *); +char *SHA1Data(const uint8_t *, size_t, char *); +#endif /* _KERNEL */ +__END_DECLS + +#endif /* _SYS_SHA1_H_ */ diff --git a/nbsd_include/sys/sha2.h b/nbsd_include/sys/sha2.h new file mode 100644 index 000000000..b985efccf --- /dev/null +++ b/nbsd_include/sys/sha2.h @@ -0,0 +1,120 @@ +/* $NetBSD: sha2.h,v 1.3 2009/05/26 08:04:12 joerg Exp $ */ +/* $KAME: sha2.h,v 1.4 2003/07/20 00:28:38 itojun Exp $ */ + +/* + * sha2.h + * + * Version 1.0.0beta1 + * + * Written by Aaron D. Gifford + * + * Copyright 2000 Aaron D. Gifford. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __SHA2_H__ +#define __SHA2_H__ + +#include +#include + +/*** SHA-224/256/384/512 Various Length Definitions ***********************/ +#define SHA224_BLOCK_LENGTH 64 +#define SHA224_DIGEST_LENGTH 28 +#define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1) +#define SHA256_BLOCK_LENGTH 64 +#define SHA256_DIGEST_LENGTH 32 +#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) +#define SHA384_BLOCK_LENGTH 128 +#define SHA384_DIGEST_LENGTH 48 +#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) +#define SHA512_BLOCK_LENGTH 128 +#define SHA512_DIGEST_LENGTH 64 +#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) + + +/*** SHA-256/384/512 Context Structures *******************************/ +typedef struct _SHA256_CTX { + uint32_t state[8]; + uint64_t bitcount; + uint8_t buffer[SHA256_BLOCK_LENGTH]; +} SHA256_CTX; + +typedef struct _SHA512_CTX { + uint64_t state[8]; + uint64_t bitcount[2]; + uint8_t buffer[SHA512_BLOCK_LENGTH]; +} SHA512_CTX; + +typedef SHA256_CTX SHA224_CTX; +typedef SHA512_CTX SHA384_CTX; + + +/*** SHA-256/384/512 Function Prototypes ******************************/ +__BEGIN_DECLS +int SHA224_Init(SHA224_CTX *); +int SHA224_Update(SHA224_CTX*, const uint8_t*, size_t); +int SHA224_Final(uint8_t[SHA224_DIGEST_LENGTH], SHA224_CTX*); +#ifndef _KERNEL +char *SHA224_End(SHA224_CTX *, char[SHA224_DIGEST_STRING_LENGTH]); +char *SHA224_FileChunk(const char *, char *, off_t, off_t); +char *SHA224_File(const char *, char *); +char *SHA224_Data(const uint8_t *, size_t, char[SHA224_DIGEST_STRING_LENGTH]); +#endif /* !_KERNEL */ + +int SHA256_Init(SHA256_CTX *); +int SHA256_Update(SHA256_CTX*, const uint8_t*, size_t); +int SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); +#ifndef _KERNEL +char *SHA256_End(SHA256_CTX *, char[SHA256_DIGEST_STRING_LENGTH]); +char *SHA256_FileChunk(const char *, char *, off_t, off_t); +char *SHA256_File(const char *, char *); +char *SHA256_Data(const uint8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH]); +#endif /* !_KERNEL */ + +int SHA384_Init(SHA384_CTX*); +int SHA384_Update(SHA384_CTX*, const uint8_t*, size_t); +int SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*); +#ifndef _KERNEL +char *SHA384_End(SHA384_CTX *, char[SHA384_DIGEST_STRING_LENGTH]); +char *SHA384_FileChunk(const char *, char *, off_t, off_t); +char *SHA384_File(const char *, char *); +char *SHA384_Data(const uint8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH]); +#endif /* !_KERNEL */ + +int SHA512_Init(SHA512_CTX*); +int SHA512_Update(SHA512_CTX*, const uint8_t*, size_t); +int SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); +#ifndef _KERNEL +char *SHA512_End(SHA512_CTX *, char[SHA512_DIGEST_STRING_LENGTH]); +char *SHA512_FileChunk(const char *, char *, off_t, off_t); +char *SHA512_File(const char *, char *); +char *SHA512_Data(const uint8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH]); +#endif /* !_KERNEL */ +__END_DECLS + +#endif /* __SHA2_H__ */ diff --git a/nbsd_include/sys/shm.h b/nbsd_include/sys/shm.h new file mode 100644 index 000000000..2003c72af --- /dev/null +++ b/nbsd_include/sys/shm.h @@ -0,0 +1,148 @@ +/* $NetBSD: shm.h,v 1.48 2009/01/19 19:39:41 christos Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1994 Adam Glass + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Adam Glass. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * As defined+described in "X/Open System Interfaces and Headers" + * Issue 4, p. XXX + */ + +#ifndef _SYS_SHM_H_ +#define _SYS_SHM_H_ + +#include +#include + +#include + +#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ +#define SHM_RND 020000 /* Round attach address to SHMLBA */ + +/* Segment low boundry address multiple */ +#define SHMLBA getpagesize() +#define SHMMNI 4096 +#define SHMSEG 32 /* max shared segs per process */ + +typedef unsigned int shmatt_t; + +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permission structure */ + size_t shm_segsz; /* size of segment in bytes */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ + pid_t shm_cpid; /* process ID of creator */ + pid_t shm_lpid; /* process ID of last shm operation */ + shmatt_t shm_nattch; /* number of current attaches */ +}; + + +/* shm_mode upper byte flags */ +#define SHM_DEST 01000 /* segment will be destroyed on last detach */ +#define SHM_LOCKED 02000 /* segment will not be swapped */ + +/* ipcs ctl commands */ +#define SHM_STAT 13 +#define SHM_INFO 14 + + +#if defined(_NETBSD_SOURCE) || defined(__minix) +/* + * Permission definitions used in shmflag arguments to shmat(2) and shmget(2). + * Provided for source compatibility only; do not use in new code! + */ +#define SHM_R 0400 +#define SHM_W 0200 + +/* + * System 5 style catch-all structure for shared memory constants that + * might be of interest to user programs. Do we really want/need this? + */ +struct shminfo { + unsigned long int shmmax; /* max shared memory segment size (bytes) */ + unsigned long int shmmin; /* min shared memory segment size (bytes) */ + unsigned long int shmmni; /* max number of shared memory identifiers */ + unsigned long int shmseg; /* max shared memory segments per process */ + unsigned long int shmall; /* max amount of shared memory (pages) */ +}; + +#ifdef __minix +struct shm_info +{ + int used_ids; + unsigned long int shm_tot; /* total allocated shm */ + unsigned long int shm_rss; /* total resident shm */ + unsigned long int shm_swp; /* total swapped shm */ + unsigned long int swap_attempts; + unsigned long int swap_successes; +}; +#endif /* __minix */ + +#endif /* _NETBSD_SOURCE */ + +__BEGIN_DECLS +void *shmat(int, const void *, int); +int shmctl(int, int, struct shmid_ds *) __RENAME(__shmctl50); +int shmdt(const void *); +int shmget(key_t, size_t, int); +__END_DECLS + +#endif /* !_SYS_SHM_H_ */ diff --git a/nbsd_include/sys/siginfo.h b/nbsd_include/sys/siginfo.h new file mode 100644 index 000000000..20e627a9f --- /dev/null +++ b/nbsd_include/sys/siginfo.h @@ -0,0 +1,240 @@ +/* $NetBSD: siginfo.h,v 1.19 2009/03/27 11:05:43 drochner Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SIGINFO_H_ +#define _SYS_SIGINFO_H_ + +#include /* XXX: __HAVE_SIGINFO */ +#ifdef _KERNEL +#include +#endif + +typedef union sigval { + int sival_int; + void *sival_ptr; +} sigval_t; + +struct _ksiginfo { + int _signo; + int _code; + int _errno; +#ifdef _LP64 + /* In _LP64 the union starts on an 8-byte boundary. */ + int _pad; +#endif + union { + struct { + pid_t _pid; + uid_t _uid; + sigval_t _value; + } _rt; + + struct { + pid_t _pid; + uid_t _uid; + int _status; + clock_t _utime; + clock_t _stime; + } _child; + + struct { + void *_addr; + int _trap; + } _fault; + + struct { + long _band; + int _fd; + } _poll; + } _reason; +}; + +#ifdef _KERNEL +typedef struct ksiginfo { + u_long ksi_flags; /* 4 or 8 bytes (LP64) */ + CIRCLEQ_ENTRY(ksiginfo) ksi_list; + struct _ksiginfo ksi_info; + lwpid_t ksi_lid; /* 0, or directed to LWP */ +} ksiginfo_t; + +#define KSI_TRAP 0x01 /* signal caused by trap */ +#define KSI_EMPTY 0x02 /* no additional information */ +#define KSI_QUEUED 0x04 /* on a sigpend_t queue */ +#define KSI_FROMPOOL 0x08 /* allocated from the ksiginfo pool */ + +/* Macros to initialize a ksiginfo_t. */ +#define KSI_INIT(ksi) \ +do { \ + memset((ksi), 0, sizeof(*(ksi))); \ +} while (/*CONSTCOND*/0) + +#define KSI_INIT_EMPTY(ksi) \ +do { \ + KSI_INIT((ksi)); \ + (ksi)->ksi_flags = KSI_EMPTY; \ +} while (/*CONSTCOND*/0) + +#define KSI_INIT_TRAP(ksi) \ +do { \ + KSI_INIT((ksi)); \ + (ksi)->ksi_flags = KSI_TRAP; \ +} while (/*CONSTCOND*/0) + +/* Copy the part of ksiginfo_t without the queue pointers */ +#define KSI_COPY(fksi, tksi) \ +do { \ + (tksi)->ksi_info = (fksi)->ksi_info; \ + (tksi)->ksi_flags = (fksi)->ksi_flags; \ +} while (/*CONSTCOND*/0) + + +/* Predicate macros to test how a ksiginfo_t was generated. */ +#define KSI_TRAP_P(ksi) (((ksi)->ksi_flags & KSI_TRAP) != 0) +#define KSI_EMPTY_P(ksi) (((ksi)->ksi_flags & KSI_EMPTY) != 0) + +/* + * Old-style signal handler "code" arguments were only non-zero for + * signals caused by traps. + */ +#define KSI_TRAPCODE(ksi) (KSI_TRAP_P(ksi) ? (ksi)->ksi_trap : 0) +#endif /* _KERNEL */ + +typedef union siginfo { + char si_pad[128]; /* Total size; for future expansion */ + struct _ksiginfo _info; +} siginfo_t; + +/** Field access macros */ +#define si_signo _info._signo +#define si_code _info._code +#define si_errno _info._errno + +#define si_value _info._reason._rt._value +#define si_pid _info._reason._child._pid +#define si_uid _info._reason._child._uid +#define si_status _info._reason._child._status +#define si_utime _info._reason._child._utime +#define si_stime _info._reason._child._stime + +#define si_addr _info._reason._fault._addr +#define si_trap _info._reason._fault._trap + +#define si_band _info._reason._poll._band +#define si_fd _info._reason._poll._fd + +#ifdef _KERNEL +/** Field access macros */ +#define ksi_signo ksi_info._signo +#define ksi_code ksi_info._code +#define ksi_errno ksi_info._errno + +#define ksi_value ksi_info._reason._rt._value +#define ksi_pid ksi_info._reason._child._pid +#define ksi_uid ksi_info._reason._child._uid +#define ksi_status ksi_info._reason._child._status +#define ksi_utime ksi_info._reason._child._utime +#define ksi_stime ksi_info._reason._child._stime + +#define ksi_addr ksi_info._reason._fault._addr +#define ksi_trap ksi_info._reason._fault._trap + +#define ksi_band ksi_info._reason._poll._band +#define ksi_fd ksi_info._reason._poll._fd +#endif /* _KERNEL */ + +/** si_code */ +/* SIGILL */ +#define ILL_ILLOPC 1 /* Illegal opcode */ +#define ILL_ILLOPN 2 /* Illegal operand */ +#define ILL_ILLADR 3 /* Illegal addressing mode */ +#define ILL_ILLTRP 4 /* Illegal trap */ +#define ILL_PRVOPC 5 /* Privileged opcode */ +#define ILL_PRVREG 6 /* Privileged register */ +#define ILL_COPROC 7 /* Coprocessor error */ +#define ILL_BADSTK 8 /* Internal stack error */ + +/* SIGFPE */ +#define FPE_INTOVF 1 /* integer divide by zero */ +#define FPE_INTDIV 2 /* integer overflow */ +#define FPE_FLTDIV 3 /* floating-point divide by zero */ +#define FPE_FLTOVF 4 /* floating-point overflow */ +#define FPE_FLTUND 5 /* floating-point underflow */ +#define FPE_FLTRES 6 /* floating-point inexact result */ +#define FPE_FLTINV 7 /* floating-point invalid operation */ +#define FPE_FLTSUB 8 /* subscript out of range */ + +/* SIGSEGV */ +#define SEGV_MAPERR 1 /* Address not mapped to object */ +#define SEGV_ACCERR 2 /* Invalid permissions for mapped object*/ + +/* SIGBUS */ +#define BUS_ADRALN 1 /* Invalid address alignment */ +#define BUS_ADRERR 2 /* Non-existent physical address */ +#define BUS_OBJERR 3 /* Object specific hardware error */ + +/* SIGTRAP */ +#define TRAP_BRKPT 1 /* Process breakpoint */ +#define TRAP_TRACE 2 /* Process trace trap */ + +/* SIGCHLD */ +#define CLD_EXITED 1 /* Child has exited */ +#define CLD_KILLED 2 /* Child has terminated abnormally but */ + /* did not create a core file */ +#define CLD_DUMPED 3 /* Child has terminated abnormally and */ + /* created a core file */ +#define CLD_TRAPPED 4 /* Traced child has trapped */ +#define CLD_STOPPED 5 /* Child has stopped */ +#define CLD_CONTINUED 6 /* Stopped child has continued */ + +/* SIGPOLL */ +#define POLL_IN 1 /* Data input available */ +#define POLL_OUT 2 /* Output buffers available */ +#define POLL_MSG 3 /* Input message available */ +#define POLL_ERR 4 /* I/O Error */ +#define POLL_PRI 5 /* High priority input available */ +#define POLL_HUP 6 /* Device disconnected */ + + +/** si_code */ +#define SI_USER 0 /* Sent by kill(2) */ +#define SI_QUEUE -1 /* Sent by the sigqueue(2) */ +#define SI_TIMER -2 /* Generated by expiration of a timer */ + /* set by timer_settime(2) */ +#define SI_ASYNCIO -3 /* Generated by completion of an */ + /* asynchronous I/O signal */ +#define SI_MESGQ -4 /* Generated by arrival of a message on */ + /* an empty message queue */ +#if defined(_KERNEL) || defined(_NETBSD_SOURCE) +#define SI_LWP -5 /* Generated by _lwp_kill(2) */ +#define SI_NOINFO 32767 /* No signal specific info available */ +#endif + +#endif /* !_SYS_SIGINFO_H_ */ diff --git a/nbsd_include/sys/signal.h b/nbsd_include/sys/signal.h new file mode 100644 index 000000000..934042856 --- /dev/null +++ b/nbsd_include/sys/signal.h @@ -0,0 +1,214 @@ +#ifndef _SYS_SIGNAL_H_ +#define _SYS_SIGNAL_H_ + +#include +#include + +#define _NSIG 26 + +#if defined(_NETBSD_SOURCE) +#define NSIG _NSIG + +#endif /* _NETBSD_SOURCE */ + + +/* Regular signals. */ +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt (DEL) */ +#define SIGQUIT 3 /* quit (ASCII FS) */ +#define SIGILL 4 /* illegal instruction */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGABRT 6 /* IOT instruction */ +#define SIGBUS 7 /* bus error */ +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGUSR1 10 /* user defined signal # 1 */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGUSR2 12 /* user defined signal # 2 */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGEMT 16 /* EMT instruction */ +#define SIGCHLD 17 /* child process terminated or stopped */ +#define SIGWINCH 21 /* window size has changed */ +#define SIGVTALRM 24 /* virtual alarm */ +#define SIGPROF 25 /* profiler alarm */ + +/* POSIX requires the following signals to be defined, even if they are + * not supported. Here are the definitions, but they are not supported. + */ +#define SIGCONT 18 /* continue if stopped */ +#define SIGSTOP 19 /* stop signal */ +#define SIGTSTP 20 /* interactive stop signal */ +#define SIGTTIN 22 /* background process wants to read */ +#define SIGTTOU 23 /* background process wants to write */ + +#define _NSIG 26 /* highest signal number plus one */ +#define NSIG _NSIG + +#ifdef _MINIX +#define SIGIOT SIGABRT /* for people who speak PDP-11 */ + +/* MINIX specific signals. These signals are not used by user proceses, + * but meant to inform system processes, like the PM, about system events. + * The order here determines the order signals are processed by system + * processes in user-space. Higher-priority signals should be first. + */ +/* Signals delivered by a signal manager. */ +#define SIGSNDELAY 26 /* end of delay for signal delivery */ + +#define SIGS_FIRST SIGHUP /* first system signal */ +#define SIGS_LAST SIGSNDELAY /* last system signal */ +#define IS_SIGS(signo) (signo>=SIGS_FIRST && signo<=SIGS_LAST) + +/* Signals delivered by the kernel. */ +#define SIGKMEM 27 /* kernel memory request pending */ +#define SIGKMESS 28 /* new kernel message */ +#define SIGKSIGSM 29 /* kernel signal pending for signal manager */ +#define SIGKSIG 30 /* kernel signal pending */ + +#define SIGK_FIRST SIGKMEM /* first kernel signal */ +#define SIGK_LAST SIGKSIG /* last kernel signal */ +#define IS_SIGK(signo) (signo>=SIGK_FIRST && signo<=SIGK_LAST) + +/* Termination signals for Minix system processes. */ +#define SIGS_IS_LETHAL(sig) \ + (sig == SIGILL || sig == SIGBUS || sig == SIGFPE || sig == SIGSEGV \ + || sig == SIGEMT || sig == SIGABRT) +#define SIGS_IS_TERMINATION(sig) (SIGS_IS_LETHAL(sig) \ + || (sig == SIGKILL || sig == SIGPIPE)) +#define SIGS_IS_STACKTRACE(sig) (SIGS_IS_LETHAL(sig) && sig != SIGABRT) + +#endif + +#include + +typedef void (*__sighandler_t)(int); + +/* Macros used as function pointers. */ +#define SIG_ERR ((__sighandler_t) -1) /* error return */ +#define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ +#define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ +#define SIG_HOLD ((__sighandler_t) 2) /* block signal */ +#define SIG_CATCH ((__sighandler_t) 3) /* catch signal */ + +#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_NETBSD_SOURCE) + +#if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +#include +#endif + +#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +#include +#endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ + +/* + * Signal vector "template" used in sigaction call. + */ +struct sigaction { + union { + void (*_sa_handler)(int); +#if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) + void (*_sa_sigaction)(int, siginfo_t *, void *); +#endif + } _sa_u; /* signal handler */ + sigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; + +#define sa_handler _sa_u._sa_handler +#if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +#define sa_sigaction _sa_u._sa_sigaction +#endif + +#include /* sigcontext; codes for SIGILL, SIGFPE */ + +/* Fields for sa_flags. */ +#define SA_ONSTACK 0x0001 /* deliver signal on alternate stack */ +#define SA_RESETHAND 0x0002 /* reset signal handler when signal caught */ +#define SA_NODEFER 0x0004 /* don't block signal while catching it */ +#define SA_RESTART 0x0008 /* automatic system call restart */ +#define SA_SIGINFO 0x0010 /* extended signal handling */ +#define SA_NOCLDWAIT 0x0020 /* don't create zombies */ +#define SA_NOCLDSTOP 0x0040 /* don't receive SIGCHLD when child stops */ + +/* POSIX requires these values for use with sigprocmask(2). */ +#define SIG_BLOCK 0 /* for blocking signals */ +#define SIG_UNBLOCK 1 /* for unblocking signals */ +#define SIG_SETMASK 2 /* for setting the signal mask */ +#define SIG_INQUIRE 4 /* for internal use only */ + +#if defined(_NETBSD_SOURCE) +typedef void (*sig_t)(int); /* type of signal function */ +#endif + +#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +/* + * Flags used with stack_t/struct sigaltstack. + */ +#define SS_ONSTACK 1 /* Process is executing on an alternate stack */ +#define SS_DISABLE 2 /* Alternate stack is disabled */ + +#define MINSIGSTKSZ 2048 /* Minimal stack size is 2k */ +#define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ +#endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ + +#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +/* + * Structure used in sigstack call. + */ +struct sigstack { + void *ss_sp; /* signal stack pointer */ + int ss_onstack; /* current status */ +}; +#endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ + +#if defined(_NETBSD_SOURCE) && !defined(_KERNEL) +/* + * Macro for converting signal number to a mask suitable for + * sigblock(). + */ +#define sigmask(n) __sigmask(n) + +#define BADSIG SIG_ERR +#endif /* _NETBSD_SOURCE */ + +#if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +struct sigevent { + int sigev_notify; + int sigev_signo; + union sigval sigev_value; + void (*sigev_notify_function)(union sigval); + void /* pthread_attr_t */ *sigev_notify_attributes; +}; + +#define SIGEV_NONE 0 +#define SIGEV_SIGNAL 1 +#define SIGEV_THREAD 2 +#if defined(_NETBSD_SOURCE) +#define SIGEV_SA 3 +#endif +#endif /* (_POSIX_C_SOURCE - 0) >= 199309L || ... */ + +#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */ + +/* + * For historical reasons; programs expect signal's return value to be + * defined by . + */ +__BEGIN_DECLS +void (*signal(int, void (*)(int)))(int); +__END_DECLS +#endif /* !_SYS_SIGNAL_H_ */ + + + + diff --git a/nbsd_include/sys/sigtypes.h b/nbsd_include/sys/sigtypes.h new file mode 100644 index 000000000..26e30243b --- /dev/null +++ b/nbsd_include/sys/sigtypes.h @@ -0,0 +1,68 @@ +#ifndef _SYS_SIGTYPES_H_ +#define _SYS_SIGTYPES_H_ + +/* + * This header file defines various signal-related types. We also keep + * the macros to manipulate sigset_t here, to encapsulate knowledge of + * its internals. + */ + +#include +#include +#include + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#undef _BSD_SIZE_T_ +#endif + +#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_NETBSD_SOURCE) +typedef unsigned long sigset_t; + +/* + * Macro for manipulating signal masks. + */ +#define __sigmask(n) (1 << (((unsigned int)(n) - 1))) +#define __sigaddset(s, n) \ + do { \ + *(s) = *(unsigned long *)(s) | __sigmask(n); \ + } while(0) +#define __sigdelset(s, n) \ + do { \ + *(s) = *(unsigned long *)(s) & ~__sigmask(n); \ + } while (0) + +#define __sigismember(s, n) (((*(const unsigned long *)(s)) & __sigmask(n)) != 0) +#define __sigemptyset(s) (*(unsigned long *)(s) = 0) +#define __sigsetequal(s1, s2) (*(unsigned long *)(s1) = *(unsigned long *)(s2)) +#define __sigfillset(s) (*(long *)(s) = -1L) +#define __sigplusset(s, t) \ + do { \ + *(t) = *(unsigned long *)(t) | *(unsigned long *)(s); \ + } while (0) +#define __sigminusset(s, t) \ + do { \ + *(t) = *(unsigned long *)(t) & ~*(unsigned long *)(s); \ + } while (0) +#define __sigandset(s, t) \ + do { \ + *(t) = *(unsigned long *)(t) & *(unsigned long *)(s); \ + } while (0) + +#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +typedef struct +#if defined(_NETBSD_SOURCE) + sigaltstack +#endif /* _NETBSD_SOURCE */ + { + void *ss_sp; /* signal stack base */ + size_t ss_size; /* signal stack length */ + int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ +} stack_t; + +#endif /* _XOPEN_SOURCE_EXTENDED || XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ + +#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || ... */ +#endif /* !_SYS_SIGTYPES_H_ */ diff --git a/nbsd_include/sys/socket.h b/nbsd_include/sys/socket.h new file mode 100644 index 000000000..a8628cdef --- /dev/null +++ b/nbsd_include/sys/socket.h @@ -0,0 +1,301 @@ +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include + +/* + * Definitions related to sockets: types, address families, options. + */ + +/* + * Data types. + */ +#include + +#ifndef sa_family_t +typedef __sa_family_t sa_family_t; +#define sa_family_t __sa_family_t +#endif + +#ifndef socklen_t +typedef __socklen_t socklen_t; +#define socklen_t __socklen_t +#endif + +#include + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#undef _BSD_SIZE_T_ +#endif + +#ifdef _BSD_SSIZE_T_ +typedef _BSD_SSIZE_T_ ssize_t; +#undef _BSD_SSIZE_T_ +#endif + +#include + +/* + * Socket types. + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#define SOCK_RDM 4 /* reliably-delivered message */ +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ + +/* + * Option flags per-socket. + */ +#define SO_DEBUG 0x0001 /* turn on debugging info recording */ +#define SO_REUSEADDR 0x0004 /* allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_TYPE 0x0010 /* get socket type */ + +#define SO_PASSCRED 0x0012 +#define SO_PEERCRED 0x0014 + +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_ERROR 0x1007 /* get error status and clear */ + + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xffff /* options for socket level */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#define AF_LOCAL 1 /* local to host */ +#define AF_UNIX AF_LOCAL /* backward compatibility */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NS 6 /* XEROX NS protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* european computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#if defined(_NETBSD_SOURCE) +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#endif +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#if defined(_NETBSD_SOURCE) +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#endif +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_INET6 24 /* IP version 6 */ +#if defined(_NETBSD_SOURCE) +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#endif +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define AF_NATM 27 /* native ATM access */ +#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */ +#if defined(_NETBSD_SOURCE) +#define pseudo_AF_KEY 29 /* Internal key management protocol */ +#define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs + in interface output routine */ +#endif +#define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */ +#define AF_IEEE80211 32 /* IEEE80211 */ + +#define AF_MAX 33 + +#ifndef gid_t +typedef __gid_t gid_t; /* group id */ +#define gid_t __gid_t +#endif + +#ifndef uid_t +typedef __uid_t uid_t; /* user id */ +#define uid_t __uid_t +#endif + +#include + +/* + * Structure used by kernel to store most + * addresses. + */ +struct sockaddr +{ + sa_family_t sa_family; + char sa_data[8]; /* Big enough for sockaddr_in */ +}; + +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128 +#define _SS_ALIGNSIZE (sizeof(__int64_t)) +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 1) +#define _SS_PAD2SIZE (_SS_MAXSIZE - 1 - \ + _SS_PAD1SIZE - _SS_ALIGNSIZE) + +#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +struct sockaddr_storage { + sa_family_t ss_family; /* address family */ + char __ss_pad1[_SS_PAD1SIZE]; + __int64_t __ss_align;/* force desired structure storage alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; +#define sstosa(__ss) ((struct sockaddr *)(__ss)) +#define sstocsa(__ss) ((const struct sockaddr *)(__ss)) +#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ + +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX PF_LOCAL /* backward compatibility */ +#define PF_FILE PF_LOCAL /* Minix compatibility */ +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NS AF_NS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#if defined(_NETBSD_SOURCE) +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#endif +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_INET6 AF_INET6 +#define PF_IPX AF_IPX /* same format as AF_NS */ +#if defined(_NETBSD_SOURCE) +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#endif +#define PF_ISDN AF_ISDN /* same as E164 */ +#define PF_E164 AF_E164 +#define PF_NATM AF_NATM +#define PF_ARP AF_ARP +#if defined(_NETBSD_SOURCE) +#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */ +#endif +#define PF_BLUETOOTH AF_BLUETOOTH + +#define PF_MAX AF_MAX + +/* + * Message header for recvmsg and sendmsg calls. + * Used value-result for recvmsg, value only for sendmsg. + */ +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; + +/* + * Header for ancillary data objects in msg_control buffer. + * Used for additional information with/about a datagram + * not expressible by flags. The format is a sequence + * of message elements headed by cmsghdr structures. + */ +struct cmsghdr { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; + +#define CMSG_FIRSTHDR(mhdr) \ + ( (mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL ) + +#define CMSG_ALIGN(len) \ + ( (len % sizeof(long) == 0) ? \ + len : \ + len + sizeof(long) - (len % sizeof(long)) ) + +#define CMSG_NXTHDR(mhdr, cmsg) \ + ( ((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ + (((unsigned char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) \ + + CMSG_ALIGN(sizeof(struct cmsghdr)) > \ + (unsigned char *)((mhdr)->msg_control) + \ + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((unsigned char *)(cmsg) + \ + CMSG_ALIGN((cmsg)->cmsg_len))) ) + +#define CMSG_DATA(cmsg) \ + ( (unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)) ) + +#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l)) +#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l)) + +/* "Socket"-level control message types: */ +#define SCM_RIGHTS 0x01 +#define SCM_CREDENTIALS 0x02 +#define SCM_SECURITY 0x04 + + +/* + * Types of socket shutdown(2). + */ +#define SHUT_RD 0 /* Disallow further receives. */ +#define SHUT_WR 1 /* Disallow further sends. */ +#define SHUT_RDWR 2 /* Disallow further sends/receives. */ + +#include + + +__BEGIN_DECLS +int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict); +int listen(int, int); +ssize_t recv(int, void *, size_t, int); +ssize_t recvfrom(int, void *__restrict, size_t, int, + struct sockaddr * __restrict, socklen_t * __restrict); +ssize_t recvmsg(int, struct msghdr *, int); +ssize_t send(int, const void *, size_t, int); +ssize_t sendto(int, const void *, + size_t, int, const struct sockaddr *, socklen_t); +ssize_t sendmsg(int, const struct msghdr *, int); +int setsockopt(int, int, int, const void *, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int *); +__END_DECLS + +#endif /* !_SYS_SOCKET_H_ */ diff --git a/nbsd_include/sys/stat.h b/nbsd_include/sys/stat.h new file mode 100644 index 000000000..23506ceda --- /dev/null +++ b/nbsd_include/sys/stat.h @@ -0,0 +1,179 @@ +#ifndef _SYS_STAT_H_ +#define _SYS_STAT_H_ + +#include +#include /* XXX */ + +#if defined(_NETBSD_SOURCE) +#include +#endif + +#define __MINIX_EMULATE_NETBSD_STAT + +/* + * __MINIX_EMULATE_NETBSD_STAT + * + * Userspace flag to emulate netbsd stat structure. Please note that + * this might be dangerous, and should be enabled only when we're sure + * that the program doesn't use the emulated information for doing + * something harmful. + * It is meant to be temporary, until we add a new syscall. + */ +#ifdef __MINIX_EMULATE_NETBSD_STAT +#define __netbsd_stat stat +#else +#define __minix_stat stat +#endif + +struct __minix_stat { + dev_t st_dev; /* major/minor device number */ + ino_t st_ino; /* i-node number */ + mode_t st_mode; /* file mode, protection bits, etc. */ + nlink_t st_nlink; /* # links; */ + uid_t st_uid; /* uid of the file's owner */ + gid_t st_gid; /* gid */ + dev_t st_rdev; + off_t st_size; /* file size */ + time_t st_atime; /* time of last access */ + time_t st_mtime; /* time of last data modification */ + time_t st_ctime; /* time of last file status change */ +}; + +struct __netbsd_stat { + dev_t st_dev; /* major/minor device number */ + ino_t st_ino; /* i-node number */ + mode_t st_mode; /* file mode, protection bits, etc. */ + nlink_t st_nlink; /* # links; */ + uid_t st_uid; /* uid of the file's owner */ + gid_t st_gid; /* gid */ + dev_t st_rdev; + off_t st_size; /* file size */ + time_t st_atime; /* time of last access */ + time_t st_mtime; /* time of last data modification */ + time_t st_ctime; /* time of last file status change */ + + /* XXX: Currently not supported by Minix, and here are just emulated. */ + struct timespec st_atimespec;/* time of last access */ + struct timespec st_mtimespec;/* time of last data modification */ + struct timespec st_ctimespec;/* time of last file status change */ + struct timespec st_birthtimespec; /* time of creation */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + uint32_t st_flags; /* user defined flags for file */ + uint32_t st_gen; /* file generation number */ + uint32_t st_spare[2]; +}; + +#ifdef __MINIX_EMULATE_NETBSD_STAT +#define st_atimensec st_atimespec.tv_nsec +#define st_mtimensec st_mtimespec.tv_nsec +#define st_ctimensec st_ctimespec.tv_nsec +#define st_birthtime st_birthtimespec.tv_sec +#define st_birthtimensec st_birthtimespec.tv_nsec +#endif + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#if defined(_NETBSD_SOURCE) +#define S_ISTXT 0001000 /* sticky bit */ +#endif + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#if defined(_NETBSD_SOURCE) +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#endif + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#define _S_IFMT 0170000 /* type of file mask */ +#define _S_IFIFO 0010000 /* named pipe (fifo) */ +#define _S_IFCHR 0020000 /* character special */ +#define _S_IFDIR 0040000 /* directory */ +#define _S_IFBLK 0060000 /* block special */ +#define _S_IFREG 0100000 /* regular */ +#define _S_IFLNK 0120000 /* symbolic link */ +#define _S_IFSOCK 0140000 /* socket */ +#define _S_ISVTX 0001000 /* save swapped text even after use */ + +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#define S_IFMT _S_IFMT +#define S_IFIFO _S_IFIFO +#define S_IFCHR _S_IFCHR +#define S_IFDIR _S_IFDIR +#define S_IFBLK _S_IFBLK +#define S_IFREG _S_IFREG +#define S_IFLNK _S_IFLNK +#define S_ISVTX _S_ISVTX +#endif +#if ((_XOPEN_SOURCE - 0) >= 600) || defined(_NETBSD_SOURCE) +#define S_IFSOCK _S_IFSOCK +#endif + +#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) /* directory */ +#define S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR) /* char special */ +#define S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK) /* block special */ +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) /* regular file */ +#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) /* fifo */ +#if ((_POSIX_C_SOURCE - 0) >= 200112L) || defined(_XOPEN_SOURCE) || \ + defined(_NETBSD_SOURCE) +#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) /* symbolic link */ +#endif +#if ((_POSIX_C_SOURCE - 0) >= 200112L) || ((_XOPEN_SOURCE - 0) >= 600) || \ + defined(_NETBSD_SOURCE) +#define S_ISSOCK(m) (((m) & _S_IFMT) == _S_IFSOCK) /* socket */ +#endif + +#if defined(_NETBSD_SOURCE) +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ + /* 7777 */ +#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) + /* 0666 */ +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) + +#define S_BLKSIZE 512 /* block size used in the stat struct */ + +#endif /* _NETBSD_SOURCE */ + +#if defined(__minix) +#include +/* Convenient constant to use when st_blocksize field is required. */ +#define MINIX_ST_BLKSIZE PAGE_SIZE +#endif + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include + +__BEGIN_DECLS +int chmod(const char *, mode_t); +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +#ifndef __LIBC12_SOURCE__ +int stat(const char *, struct stat *); +int fstat(int, struct stat *); +#endif +mode_t umask(mode_t); +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +int fchmod(int, mode_t); +#ifndef __LIBC12_SOURCE__ +int lstat(const char *, struct stat *); +int mknod(const char *, mode_t, dev_t) __RENAME(__mknod50); +#endif +#endif /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */ +__END_DECLS + +#endif /* !_KERNEL && !_STANDALONE */ +#endif /* !_SYS_STAT_H_ */ diff --git a/nbsd_include/sys/statvfs.h b/nbsd_include/sys/statvfs.h new file mode 100644 index 000000000..b68d3dc1c --- /dev/null +++ b/nbsd_include/sys/statvfs.h @@ -0,0 +1,64 @@ +#ifndef _SYS_STATVFS_H_ +#define _SYS_STATVFS_H_ + +#include +#include +#include +#include +#include + +#define _VFS_NAMELEN 32 +#define _VFS_MNAMELEN 1024 + +#ifndef fsblkcnt_t +typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */ +#define fsblkcnt_t __fsblkcnt_t +#endif + +#ifndef fsfilcnt_t +typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */ +#define fsfilcnt_t __fsfilcnt_t +#endif + +#ifndef uid_t +typedef __uid_t uid_t; /* user id */ +#define uid_t __uid_t +#endif + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#define _SIZE_T +#undef _BSD_SIZE_T_ +#endif + +struct statvfs { + unsigned long f_bsize; /* File system block size. */ + unsigned long f_frsize; /* Fundamental file system block size. */ + fsblkcnt_t f_blocks; /* Total number of blocks on file system */ + /* in units of f_frsize. */ + fsblkcnt_t f_bfree; /* Total number of free blocks. */ + fsblkcnt_t f_bavail; /* Number of free blocks available to */ + /* non-privileged process. */ + fsfilcnt_t f_files; /* Total number of file serial numbers. */ + fsfilcnt_t f_ffree; /* Total number of free file serial numbers. */ + fsfilcnt_t f_favail; /* Number of file serial numbers available */ + /* to non-privileged process. */ + unsigned long f_fsid; /* File system ID. */ + unsigned long f_flag; /* Bit mask of f_flag values. */ + unsigned long f_namemax; /* Maximum filename length. */ + unsigned char __padding[32]; /* Padding for future compatibility */ +}; + +/* Possible values for statvfs->f_flag */ +#define ST_RDONLY 0x1 +#define ST_NOSUID 0x2 +#ifdef __minix +#define ST_NOTRUNC 0x4 +#endif /* !__minix*/ + +__BEGIN_DECLS +int statvfs(const char *__restrict, struct statvfs *__restrict); +int fstatvfs(int, struct statvfs *); +__END_DECLS + +#endif /* _SYS_STATVFS_H_ */ diff --git a/nbsd_include/sys/stdint.h b/nbsd_include/sys/stdint.h new file mode 100644 index 000000000..a6ae2407e --- /dev/null +++ b/nbsd_include/sys/stdint.h @@ -0,0 +1,100 @@ +/* $NetBSD: stdint.h,v 1.6 2008/04/28 20:24:11 martin Exp $ */ + +/*- + * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#ifndef int8_t +typedef __int8_t int8_t; +#define int8_t __int8_t +#endif + +#ifndef uint8_t +typedef __uint8_t uint8_t; +#define uint8_t __uint8_t +#endif + +#ifndef int16_t +typedef __int16_t int16_t; +#define int16_t __int16_t +#endif + +#ifndef uint16_t +typedef __uint16_t uint16_t; +#define uint16_t __uint16_t +#endif + +#ifndef int32_t +typedef __int32_t int32_t; +#define int32_t __int32_t +#endif + +#ifndef uint32_t +typedef __uint32_t uint32_t; +#define uint32_t __uint32_t +#endif + +#ifndef int64_t +typedef __int64_t int64_t; +#define int64_t __int64_t +#endif + +#ifndef uint64_t +typedef __uint64_t uint64_t; +#define uint64_t __uint64_t +#endif + +#ifndef intptr_t +typedef __intptr_t intptr_t; +#define intptr_t __intptr_t +#endif + +#ifndef uintptr_t +typedef __uintptr_t uintptr_t; +#define uintptr_t __uintptr_t +#endif + +#include + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +#include +#endif + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) +#include +#endif + +#include + +#endif /* !_SYS_STDINT_H_ */ diff --git a/nbsd_include/sys/sysctl.h b/nbsd_include/sys/sysctl.h new file mode 100644 index 000000000..4706eae88 --- /dev/null +++ b/nbsd_include/sys/sysctl.h @@ -0,0 +1,22 @@ +#ifndef _SYS_SYSCTL_H +#define _SYS_SYSCTL_H + +/* + * sysctl() is not supported. Warn non-libc programs including this header. + */ +#ifndef _LIBC +#warning Including sysctl.h header. sysctl() is not supported in Minix. +#endif /* !_LIBC */ + +/* + * Used by gmon. + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int tickadj; /* clock skew rate for adjtime() */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; + +#endif /* _SYS_SYSCTL_H */ diff --git a/nbsd_include/sys/syslimits.h b/nbsd_include/sys/syslimits.h new file mode 100644 index 000000000..a3a4f1c3e --- /dev/null +++ b/nbsd_include/sys/syslimits.h @@ -0,0 +1,72 @@ +#ifndef _SYS_SYSLIMITS_H_ +#define _SYS_SYSLIMITS_H_ + +#include +#include + +/* Values actually implemented by MINIX (Tables 2-4, 2-5, 2-6, and 2-7). */ +/* Some of these old names had better be defined when not POSIX. */ +#define _NO_LIMIT 160 /* arbitrary number; limit not enforced */ + + +#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_NETBSD_SOURCE) + +#if _EM_WSIZE > 2 +#define ARG_MAX 262144 /* # bytes of args + environ for exec() */ +#else +#define ARG_MAX 4096 /* args + environ on small machines */ +#endif + +#ifndef CHILD_MAX +#define CHILD_MAX _NO_LIMIT /* max simultaneous processes */ +#endif + +#define GID_MAX CHAR_MAX /* max value for a gid_t */ +#define LINK_MAX SHRT_MAX /* # links a file may have */ +#define MAX_CANON 255 /* size of the canonical input queue */ +#define MAX_INPUT 255 /* size of the type-ahead buffer */ +#define NAME_MAX 60 /* # chars in a file name (actually DIRSZ) */ +#define NGROUPS_MAX 8 /* max. number of supplemental groups */ +#define UID_MAX SHRT_MAX /* max value for a uid_t */ +#ifndef OPEN_MAX +#define OPEN_MAX __MINIX_OPEN_MAX /* max open files per process */ +#endif +#define PATH_MAX __MINIX_PATH_MAX /* # chars in a path name */ +#define PIPE_BUF 7168 /* # bytes in atomic write to a pipe */ + +#define BC_BASE_MAX INT_MAX /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 65535 /* max array elements in bc(1) */ +#define BC_SCALE_MAX INT_MAX /* max scale value in bc(1) */ +#define BC_STRING_MAX INT_MAX /* max const string length in bc(1) */ +#define COLL_WEIGHTS_MAX 2 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#define RE_DUP_MAX 255 /* max RE's in interval notation */ + +/* + * IEEE Std 1003.1c-95, adopted in X/Open CAE Specification Issue 5 Version 2 + */ +#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +#define LOGIN_NAME_MAX 17 /* max login name length incl. NUL */ +#endif + +/* + * X/Open CAE Specification Issue 5 Version 2 + */ +#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +#define IOV_MAX 1024 /* max # of iovec's for readv(2) etc. */ +#define NZERO 20 /* default "nice" */ +#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ + +#endif /* !_ANSI_SOURCE */ + +#ifdef __minix +#define STREAM_MAX 8 /* == _POSIX_STREAM_MAX */ +#define TZNAME_MAX 6 /* == _POSIX_TZNAME_MAX */ +#define TIME_MAX LONG_MAX +#endif + +#endif /* !_SYS_SYSLIMITS_H_ */ + diff --git a/nbsd_include/sys/syslog.h b/nbsd_include/sys/syslog.h new file mode 100644 index 000000000..39f6d9d3c --- /dev/null +++ b/nbsd_include/sys/syslog.h @@ -0,0 +1,241 @@ +/* $NetBSD: syslog.h,v 1.32 2008/10/31 16:12:18 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/var/run/log" + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 } +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 } +}; +#endif + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifndef _KERNEL + +/* Used by reentrant functions */ + +struct syslog_data { + int log_file; + int connected; + int opened; + int log_stat; + const char *log_tag; + int log_fac; + int log_mask; +}; + +#define SYSLOG_DATA_INIT { \ + .log_file = -1, \ + .log_fac = LOG_USER, \ + .log_mask = 0xff, \ +} + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * _BSD_VA_LIST_ from and use it. + */ +#include +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) + __attribute__((__format__(__printf__,2,3))); +#if defined(_NETBSD_SOURCE) +void vsyslog(int, const char *, _BSD_VA_LIST_) + __attribute__((__format__(__printf__,2,0))); +void closelog_r(struct syslog_data *); +void openlog_r(const char *, int, int, struct syslog_data *); +int setlogmask_r(int, struct syslog_data *); +void syslog_r(int, struct syslog_data *, const char *, ...) + __attribute__((__format__(__printf__,3,4))); +void vsyslog_r(int, struct syslog_data *, const char *, _BSD_VA_LIST_) + __attribute__((__format__(__printf__,3,0))); +void syslogp(int, const char *, const char *, const char *, ...) + __attribute__((__format__(__printf__,4,5))); +void vsyslogp(int, const char *, const char *, const char *, _BSD_VA_LIST_) + __attribute__((__format__(__printf__,4,0))); +void syslogp_r(int, struct syslog_data *, const char *, const char *, + const char *, ...) + __attribute__((__format__(__printf__,5,6))); +void vsyslogp_r(int, struct syslog_data *, const char *, const char *, + const char *, _BSD_VA_LIST_) + __attribute__((__format__(__printf__,5,0))); +#endif +__END_DECLS + +#else /* !_KERNEL */ + +void logpri(int); +void log(int, const char *, ...) + __attribute__((__format__(__printf__,2,3))); +void vlog(int, const char *, _BSD_VA_LIST_) + __attribute__((__format__(__printf__,2,0))); +void addlog(const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void logwakeup(void); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SYSLOG_H_ */ diff --git a/nbsd_include/sys/termios.h b/nbsd_include/sys/termios.h new file mode 100644 index 000000000..9a1e7059c --- /dev/null +++ b/nbsd_include/sys/termios.h @@ -0,0 +1,17 @@ +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#include + +#include + +__BEGIN_DECLS +#if defined(_NETBSD_SOURCE) +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* defined(_NETBSD_SOURCE) */ +__END_DECLS + +#endif /* !_SYS_TERMIOS_H_ */ + +#include diff --git a/nbsd_include/sys/time.h b/nbsd_include/sys/time.h new file mode 100644 index 000000000..d7b1e707a --- /dev/null +++ b/nbsd_include/sys/time.h @@ -0,0 +1,266 @@ +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include + +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; + +/* + * Structure defined by POSIX.1b to be like a timeval. + */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#if defined(_NETBSD_SOURCE) +#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} while (/*CONSTCOND*/0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (suseconds_t)(ts)->tv_nsec / 1000; \ +} while (/*CONSTCOND*/0) + +/* + * Note: timezone is obsolete. All timezone handling is now in + * userland. Its just here for back compatibility. + */ +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +/* Operations on timevals. */ +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0L +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (/* CONSTCOND */ 0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (/* CONSTCOND */ 0) + + +/* + * hide bintime for _STANDALONE because this header is used for hpcboot.exe, + * which is built with compilers which don't recognize LL suffix. + * http://mail-index.NetBSD.org/tech-userlevel/2008/02/27/msg000181.html + */ +#if !defined(_STANDALONE) +struct bintime { + time_t sec; + uint64_t frac; +}; + +static __inline void +bintime_addx(struct bintime *bt, uint64_t x) +{ + uint64_t u; + + u = bt->frac; + bt->frac += x; + if (u > bt->frac) + bt->sec++; +} + +static __inline void +bintime_add(struct bintime *bt, const struct bintime *bt2) +{ + uint64_t u; + + u = bt->frac; + bt->frac += bt2->frac; + if (u > bt->frac) + bt->sec++; + bt->sec += bt2->sec; +} + +static __inline void +bintime_sub(struct bintime *bt, const struct bintime *bt2) +{ + uint64_t u; + + u = bt->frac; + bt->frac -= bt2->frac; + if (u < bt->frac) + bt->sec--; + bt->sec -= bt2->sec; +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static __inline void +bintime2timespec(const struct bintime *bt, struct timespec *ts) +{ + + ts->tv_sec = bt->sec; + ts->tv_nsec = + (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32); +} + +static __inline void +timespec2bintime(const struct timespec *ts, struct bintime *bt) +{ + + bt->sec = ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; +} + +static __inline void +bintime2timeval(const struct bintime *bt, struct timeval *tv) +{ + + tv->tv_sec = bt->sec; + tv->tv_usec = + (suseconds_t)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32); +} + +static __inline void +timeval2bintime(const struct timeval *tv, struct bintime *bt) +{ + + bt->sec = tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + bt->frac = tv->tv_usec * (uint64_t)18446744073709LL; +} +#endif /* !defined(_STANDALONE) */ + +/* Operations on timespecs. */ +#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L) +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (/* CONSTCOND */ 0) +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (/* CONSTCOND */ 0) +#define timespec2ns(x) (((uint64_t)(x)->tv_sec) * 1000000000L + (x)->tv_nsec) +#endif /* _NETBSD_SOURCE */ + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +/* + * Structure defined by POSIX.1b to be like a itimerval, but with + * timespecs. Used in the timer_*() system calls. + */ +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; + +#ifndef __minix +#define CLOCK_REALTIME 0 +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 +#define CLOCK_MONOTONIC 3 +#endif + +#if defined(_NETBSD_SOURCE) +#define TIMER_RELTIME 0x0 /* relative timer */ +#endif +#define TIMER_ABSTIME 0x1 /* absolute timer */ + +#ifdef _KERNEL +#include +#else /* !_KERNEL */ +#ifndef _STANDALONE +#if (_POSIX_C_SOURCE - 0) >= 200112L || \ + (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ + (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) +#include +#endif + +#include +#include + +__BEGIN_DECLS +#ifndef __LIBC12_SOURCE__ +#if (_POSIX_C_SOURCE - 0) >= 200112L || \ + defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) +int getitimer(int, struct itimerval *) __RENAME(__getitimer50); +int gettimeofday(struct timeval * __restrict, void *__restrict); +int setitimer(int, const struct itimerval * __restrict, + struct itimerval * __restrict) __RENAME(__setitimer50); +#endif /* _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE || _NETBSD_SOURCE */ + +#if defined(_NETBSD_SOURCE) || defined(HAVE_NBTOOL_CONFIG_H) +#ifndef __minix +int adjtime(const struct timeval *, struct timeval *) __RENAME(__adjtime50); +int futimes(int, const struct timeval [2]) __RENAME(__futimes50); +int lutimes(const char *, const struct timeval [2]) __RENAME(__lutimes50); +#endif /* !__minix */ +int settimeofday(const struct timeval * __restrict, + const void *__restrict) __RENAME(__settimeofday50); +#endif /* _NETBSD_SOURCE */ +#endif /* __LIBC12_SOURCE__ */ +__END_DECLS + +#endif /* !_STANDALONE */ +#endif /* !_KERNEL */ +#endif /* !_SYS_TIME_H_ */ diff --git a/nbsd_include/sys/times.h b/nbsd_include/sys/times.h new file mode 100644 index 000000000..c90a2835d --- /dev/null +++ b/nbsd_include/sys/times.h @@ -0,0 +1,24 @@ +#ifndef _SYS_TIMES_H_ +#define _SYS_TIMES_H_ + +#include + +#ifdef _BSD_CLOCK_T_ +typedef _BSD_CLOCK_T_ clock_t; +#undef _BSD_CLOCK_T_ +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#include + +__BEGIN_DECLS +clock_t times(struct tms *); +__END_DECLS + +#endif /* !_SYS_TIMES_H_ */ diff --git a/nbsd_include/sys/tree.h b/nbsd_include/sys/tree.h new file mode 100644 index 000000000..d044f9899 --- /dev/null +++ b/nbsd_include/sys/tree.h @@ -0,0 +1,741 @@ +/* $NetBSD: tree.h,v 1.16 2008/03/21 13:07:15 ad Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* + * Copyright 2002 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) (void)(x) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *); \ +attr struct type *name##_RB_NFIND(struct name *, struct type *); \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#endif /* _SYS_TREE_H_ */ diff --git a/nbsd_include/sys/ttycom.h b/nbsd_include/sys/ttycom.h new file mode 100644 index 000000000..88a8f7075 --- /dev/null +++ b/nbsd_include/sys/ttycom.h @@ -0,0 +1,6 @@ +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#include + +#endif /* !_SYS_TERMIOS_H_ */ diff --git a/nbsd_include/sys/ttydefaults.h b/nbsd_include/sys/ttydefaults.h new file mode 100644 index 000000000..216589420 --- /dev/null +++ b/nbsd_include/sys/ttydefaults.h @@ -0,0 +1,45 @@ +/* + * System wide defaults for terminal state. + */ +#ifndef _SYS_TTYDEFAULTS_H_ +#define _SYS_TTYDEFAULTS_H_ + +/* NetBSD-like definition of values aready set up in termios.h */ + +/* + * Defaults on "first" open. + */ +#define TTYDEF_IFLAG (BRKINT | ICRNL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR ) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE) +#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) +#define TTYDEF_SPEED (B9600) + +/* + * Control Character Defaults + */ +#define CTRL(x) (x&037) +#define CEOF CTRL('d') +#define CEOL _POSIX_VDISABLE +#define CERASE CTRL('h') +#define CINTR CTRL('c') +#define CSTATUS CTRL('t') +#define CKILL CTRL('u') +#define CMIN 1 +#define CQUIT 034 /* FS, ^\ */ +#define CSUSP CTRL('z') +#define CTIME 0 +#define CDSUSP CTRL('y') +#define CSTART CTRL('q') +#define CSTOP CTRL('s') +#define CLNEXT CTRL('v') +#define CDISCARD CTRL('o') +#define CWERASE CTRL('w') +#define CREPRINT CTRL('r') +#define CEOT CEOF +/* compat */ +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD + +#endif /* _SYS_TTYDEFAULTS_H_ */ diff --git a/nbsd_include/sys/types.h b/nbsd_include/sys/types.h new file mode 100644 index 000000000..41f403c2b --- /dev/null +++ b/nbsd_include/sys/types.h @@ -0,0 +1,396 @@ +/* $NetBSD: types.h,v 1.86 2009/03/07 21:59:25 ad Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include + +/* Machine type dependent parameters. */ +#include + +#include +#include + +#include + +#ifndef int8_t +typedef __int8_t int8_t; +#define int8_t __int8_t +#endif + +#ifndef uint8_t +typedef __uint8_t uint8_t; +#define uint8_t __uint8_t +#endif + +#ifndef int16_t +typedef __int16_t int16_t; +#define int16_t __int16_t +#endif + +#ifndef uint16_t +typedef __uint16_t uint16_t; +#define uint16_t __uint16_t +#endif + +#ifndef int32_t +typedef __int32_t int32_t; +#define int32_t __int32_t +#endif + +#ifndef uint32_t +typedef __uint32_t uint32_t; +#define uint32_t __uint32_t +#endif + +#ifndef int64_t +typedef __int64_t int64_t; +#define int64_t __int64_t +#endif + +#ifndef uint64_t +typedef __uint64_t uint64_t; +#define uint64_t __uint64_t +#endif + +typedef uint8_t u_int8_t; +typedef uint16_t u_int16_t; +typedef uint32_t u_int32_t; +typedef uint64_t u_int64_t; + +#ifdef __minix +typedef uint8_t u8_t; +typedef uint16_t u16_t; +typedef uint32_t u32_t; +typedef uint64_t u64_t; + +typedef int8_t i8_t; +typedef int16_t i16_t; +typedef int32_t i32_t; +typedef int64_t i64_t; + + +/* some Minix specific types that do not conflict with posix */ +typedef u32_t zone_t; /* zone number */ +typedef u32_t block_t; /* block number */ +typedef u32_t bit_t; /* bit number in a bit map */ +typedef u16_t zone1_t; /* zone number for V1 file systems */ +typedef u32_t bitchunk_t; /* collection of bits in a bitmap */ + +/* ANSI C makes writing down the promotion of unsigned types very messy. When + * sizeof(short) == sizeof(int), there is no promotion, so the type stays + * unsigned. When the compiler is not ANSI, there is usually no loss of + * unsignedness, and there are usually no prototypes so the promoted type + * doesn't matter. The use of types like Ino_t is an attempt to use ints + * (which are not promoted) while providing information to the reader. + */ + +typedef unsigned long Ino_t; + +#endif /* __minix */ + +#include + +#if defined(_NETBSD_SOURCE) +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef unsigned char unchar; /* Sys V compatibility */ +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +typedef unsigned long ulong; /* Sys V compatibility */ +#endif + +typedef uint64_t u_quad_t; /* quads */ +typedef int64_t quad_t; +typedef quad_t * qaddr_t; + +/* + * The types longlong_t and u_longlong_t exist for use with the + * Sun-derived XDR routines involving these types, and their usage + * in other contexts is discouraged. Further note that these types + * may not be equivalent to "long long" and "unsigned long long", + * they are only guaranteed to be signed and unsigned 64-bit types + * respectively. Portable programs that need 64-bit types should use + * the C99 types int64_t and uint64_t instead. + */ + +typedef int64_t longlong_t; /* for XDR */ +typedef uint64_t u_longlong_t; /* for XDR */ + +typedef int64_t blkcnt_t; /* fs block count */ +typedef uint32_t blksize_t; /* fs optimal block size */ + +#ifndef fsblkcnt_t +typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */ +#define fsblkcnt_t __fsblkcnt_t +#endif + +#ifndef fsfilcnt_t +typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */ +#define fsfilcnt_t __fsfilcnt_t +#endif + +#if !defined(_KERNEL) && !defined(_STANDALONE) +/* We don't and shouldn't use caddr_t in the kernel anymore */ +#ifndef caddr_t +typedef __caddr_t caddr_t; /* core address */ +#define caddr_t __caddr_t +#endif +#endif + +#ifdef __daddr_t +typedef __daddr_t daddr_t; /* disk address */ +#undef __daddr_t +#else +typedef int64_t daddr_t; /* disk address */ +#endif + + +typedef short dev_t; /* device number */ +typedef uint32_t fixpt_t; /* fixed point number */ + +#ifndef gid_t +typedef __gid_t gid_t; /* group id */ +#define gid_t __gid_t +#endif + +typedef int idtype_t; /* type of the id */ +typedef uint32_t id_t; /* group id, process id or user id */ +typedef unsigned long ino_t; /* inode number */ +typedef long key_t; /* IPC key (for Sys V IPC) */ + +#ifndef mode_t +typedef __mode_t mode_t; /* permissions */ +#define mode_t __mode_t +#endif + +typedef short nlink_t; /* link count */ + +#ifndef off_t +typedef __off_t off_t; /* file offset */ +#define off_t __off_t +#endif + +#ifndef pid_t +typedef __pid_t pid_t; /* process id */ +#define pid_t __pid_t +#endif + +typedef int32_t lwpid_t; /* LWP id */ +typedef unsigned long rlim_t; /* resource limit */ +typedef int32_t segsz_t; /* segment size */ +typedef int32_t swblk_t; /* swap offset */ + +#ifndef uid_t +typedef __uid_t uid_t; /* user id */ +#define uid_t __uid_t +#endif + + +typedef int mqd_t; + +typedef unsigned long cpuid_t; + +typedef int psetid_t; + +#if defined(_KERNEL) || defined(_STANDALONE) +/* + * Boolean type definitions for the kernel environment. User-space + * boolean definitions are found in . + */ +#define bool _Bool +#define true 1 +#define false 0 + +/* + * Deprecated Mach-style boolean_t type. Should not be used by new code. + */ +typedef int boolean_t; +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#endif /* _KERNEL || _STANDALONE */ + +#if defined(_KERNEL) || defined(_LIBC) +/* + * semctl(2)'s argument structure. This is here for the benefit of + * . It is not in the user's namespace in SUSv2. + * The SUSv2 semctl(2) takes variable arguments. + */ +union __semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + unsigned short *array; /* array for GETALL & SETALL */ +}; +#include +#endif /* _KERNEL || _LIBC */ + +/* + * These belong in unistd.h, but are placed here too to ensure that + * long arguments will be promoted to off_t if the program fails to + * include that header or explicitly cast them to off_t. + */ +#if defined(_NETBSD_SOURCE) +#ifndef __OFF_T_SYSCALLS_DECLARED +#define __OFF_T_SYSCALLS_DECLARED +#ifndef _KERNEL +#include +__BEGIN_DECLS +off_t lseek(int, off_t, int); +int ftruncate(int, off_t); +int truncate(const char *, off_t); +__END_DECLS +#endif /* !_KERNEL */ +#endif /* __OFF_T_SYSCALLS_DECLARED */ +#endif /* defined(_NETBSD_SOURCE) */ + +#if defined(_NETBSD_SOURCE) +typedef int32_t __devmajor_t, __devminor_t; +#define devmajor_t __devmajor_t +#define devminor_t __devminor_t +#define NODEVMAJOR (-1) + +/* Major, minor numbers, dev_t's. */ +#define MAJOR 8 /* major device = (dev>>MAJOR) & 0377 */ +#define MINOR 0 /* minor device = (dev>>MINOR) & 0377 */ +#define minor(dev) ((devminor_t)(((dev) >> MINOR) & 0xff)) +#define major(dev) ((devmajor_t)(((dev) >> MAJOR) & 0xff)) +#define makedev(major, minor) \ + ((dev_t) (((major) << MAJOR) | ((minor) << MINOR))) + +#endif + +#ifdef _BSD_CLOCK_T_ +typedef _BSD_CLOCK_T_ clock_t; +#undef _BSD_CLOCK_T_ +#endif + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#define _SIZE_T +#undef _BSD_SIZE_T_ +#endif + +#ifdef _BSD_SSIZE_T_ +typedef _BSD_SSIZE_T_ ssize_t; +#undef _BSD_SSIZE_T_ +#endif + +#ifdef _BSD_TIME_T_ +typedef _BSD_TIME_T_ time_t; +#undef _BSD_TIME_T_ +#endif + +#ifdef _BSD_CLOCKID_T_ +typedef _BSD_CLOCKID_T_ clockid_t; +#undef _BSD_CLOCKID_T_ +#endif + +#ifndef __minix +#ifdef _BSD_TIMER_T_ +typedef _BSD_TIMER_T_ timer_t; +#undef _BSD_TIMER_T_ +#endif +#endif + +#ifdef _BSD_SUSECONDS_T_ +typedef _BSD_SUSECONDS_T_ suseconds_t; +#undef _BSD_SUSECONDS_T_ +#endif + +#ifdef _BSD_USECONDS_T_ +typedef _BSD_USECONDS_T_ useconds_t; +#undef _BSD_USECONDS_T_ +#endif + +#ifdef _NETBSD_SOURCE +#include +#define NBBY __NBBY + +typedef struct kauth_cred *kauth_cred_t; + +typedef int pri_t; + +#endif + +#if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER)) +/* + * Forward structure declarations for function prototypes. We include the + * common structures that cross subsystem boundaries here; others are mostly + * used in the same place that the structure is defined. + */ +struct lwp; +typedef struct lwp lwp_t; +struct user; +struct __ucontext; +struct proc; +typedef struct proc proc_t; +struct pgrp; +struct rusage; +struct file; +typedef struct file file_t; +struct buf; +typedef struct buf buf_t; +struct tty; +struct uio; +#endif + +#ifdef _KERNEL +#define SET(t, f) ((t) |= (f)) +#define ISSET(t, f) ((t) & (f)) +#define CLR(t, f) ((t) &= ~(f)) +#endif + +#ifndef __minix +#if !defined(_KERNEL) && !defined(_STANDALONE) +#if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ + defined(_NETBSD_SOURCE) +#include +#endif +#endif +#endif /* !__minix */ + +#endif /* !_SYS_TYPES_H_ */ diff --git a/nbsd_include/sys/ucontext.h b/nbsd_include/sys/ucontext.h new file mode 100644 index 000000000..dc2d293c9 --- /dev/null +++ b/nbsd_include/sys/ucontext.h @@ -0,0 +1,38 @@ +#ifndef _SYS_UCONTEXT_H_ +#define _SYS_UCONTEXT_H_ + +#include +#include + +typedef struct __ucontext ucontext_t; + +struct __ucontext { + unsigned int uc_flags; /* Properties of ucontext */ + ucontext_t *uc_link; /* Next context to resume when current is finished */ + mcontext_t uc_mcontext; /* Machine state */ + sigset_t uc_sigmask; /* Signals blocked in this context */ + stack_t uc_stack; /* The stack used by this context */ +}; + +#ifndef _UC_UCONTEXT_ALIGN +#define _UC_UCONTEXT_ALIGN (~0) +#endif + +#define UCF_SWAPPED 001 /* Context has been swapped in by swapcontext(3) */ +#define UCF_IGNFPU 002 /* Ignore FPU context by get or setcontext(3) */ +#define UCF_IGNSIGM 004 /* Ignore signal mask by get or setcontext(3) */ + +#define NCARGS 6 + +#ifdef __minix +__BEGIN_DECLS +void resumecontext(ucontext_t *ucp); + +/* These functions get and set ucontext structure through PM/kernel. They don't + * manipulate the stack. */ +int getuctx(ucontext_t *ucp); +int setuctx(const ucontext_t *ucp); +__END_DECLS +#endif /* __minix */ + +#endif /* !_SYS_UCONTEXT_H_ */ diff --git a/nbsd_include/sys/ucred.h b/nbsd_include/sys/ucred.h new file mode 100644 index 000000000..15cda1ff9 --- /dev/null +++ b/nbsd_include/sys/ucred.h @@ -0,0 +1,13 @@ +#ifndef __SYS_UCRED_H +#define __SYS_UCRED_H + +#include + +struct ucred +{ + pid_t pid; + uid_t uid; + gid_t gid; +}; + +#endif diff --git a/nbsd_include/sys/uio.h b/nbsd_include/sys/uio.h new file mode 100644 index 000000000..f85a2d185 --- /dev/null +++ b/nbsd_include/sys/uio.h @@ -0,0 +1,37 @@ +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include + +#ifdef _BSD_SIZE_T_ +typedef _BSD_SIZE_T_ size_t; +#undef _BSD_SIZE_T_ +#endif + +#ifdef _BSD_SSIZE_T_ +typedef _BSD_SSIZE_T_ ssize_t; +#undef _BSD_SSIZE_T_ +#endif + +struct iovec { + void *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; + +#if defined(_NETBSD_SOURCE) +/* + * Limits + */ +/* Deprecated: use IOV_MAX from instead. */ +#define UIO_MAXIOV 1024 /* max 1K of iov's */ +#endif /* _NETBSD_SOURCE */ + +#include + +__BEGIN_DECLS +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); +__END_DECLS + +#endif /* !_SYS_UIO_H_ */ diff --git a/nbsd_include/sys/un.h b/nbsd_include/sys/un.h new file mode 100644 index 000000000..c3c4b71fe --- /dev/null +++ b/nbsd_include/sys/un.h @@ -0,0 +1,34 @@ +#ifndef _SYS_UN_H_ +#define _SYS_UN_H_ + +#include +#include +#include + +#ifndef sa_family_t +typedef __sa_family_t sa_family_t; +#define sa_family_t __sa_family_t +#endif + +#define UNIX_PATH_MAX 127 + +/* + * Definitions for UNIX IPC domain. + */ +struct sockaddr_un { + sa_family_t sun_family; + char sun_path[UNIX_PATH_MAX]; +}; + +#include + +/* Compute the actual length of a struct sockaddr_un pointed + * to by 'unp'. sun_path must be NULL terminated. Length does + * not include the NULL byte. This is not a POSIX standard + * definition, but BSD and Linux have it, so it is here for + * compatibility. + */ +#define SUN_LEN(unp) \ +((size_t)((sizeof(*(unp)) - sizeof((unp)->sun_path)) + strlen((unp)->sun_path))) + +#endif /* _SYS_UN_H_ */ diff --git a/nbsd_include/sys/unistd.h b/nbsd_include/sys/unistd.h new file mode 100644 index 000000000..708960584 --- /dev/null +++ b/nbsd_include/sys/unistd.h @@ -0,0 +1,208 @@ +/* $NetBSD: unistd.h,v 1.52 2009/08/30 16:38:48 christos Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unistd.h 8.2 (Berkeley) 1/7/94 + */ + +#ifndef _SYS_UNISTD_H_ +#define _SYS_UNISTD_H_ + +#include + +/* compile-time symbolic constants */ +#define _POSIX_JOB_CONTROL 1 + /* implementation supports job control */ + +/* + * According to POSIX 1003.1: + * "The saved set-user-ID capability allows a program to regain the + * effective user ID established at the last exec call." + * However, the setuid/setgid function as specified by POSIX 1003.1 does + * not allow changing the effective ID from the super-user without also + * changed the saved ID, so it is impossible to get super-user privileges + * back later. Instead we provide this feature independent of the current + * effective ID through the seteuid/setegid function. In addition, we do + * not use the saved ID as specified by POSIX 1003.1 in setuid/setgid, + * because this would make it impossible for a set-user-ID executable + * owned by a user other than the super-user to permanently revoke its + * extra privileges. + */ +#ifdef _NOT_AVAILABLE +#define _POSIX_SAVED_IDS 1 + /* saved set-user-ID and set-group-ID */ +#endif + +#define _POSIX_VERSION 200112L +#define _POSIX2_VERSION 200112L + +/* execution-time symbolic constants */ + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. Those options which are implemented (or not) entirely + * in user mode are defined in . Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ + /* Advisory information */ +#undef _POSIX_ADVISORY_INFO + /* asynchronous I/O is available */ +#define _POSIX_ASYNCHRONOUS_IO 200112L + /* barriers */ +#define _POSIX_BARRIERS 200112L + /* chown requires correct privileges */ +#define _POSIX_CHOWN_RESTRICTED 1 + /* clock selection */ +#define _POSIX_CLOCK_SELECTION -1 + /* CPU type */ +#undef _POSIX_CPUTYPE + /* file synchronization is available */ +#define _POSIX_FSYNC 1 + /* support IPv6 */ +#define _POSIX_IPV6 0 + /* job control is available */ +#define _POSIX_JOB_CONTROL 1 + /* memory mapped files */ +#define _POSIX_MAPPED_FILES 1 + /* memory locking whole address space */ +#define _POSIX_MEMLOCK 1 + /* memory locking address ranges */ +#define _POSIX_MEMLOCK_RANGE 1 + /* memory access protections */ +#define _POSIX_MEMORY_PROTECTION 1 + /* message passing is available */ +#define _POSIX_MESSAGE_PASSING 200112L + /* monotonic clock */ +#define _POSIX_MONOTONIC_CLOCK 200112L + /* too-long path comp generate errors */ +#define _POSIX_NO_TRUNC 1 + /* prioritized I/O */ +#define _POSIX_PRIORITIZED_IO -1 + /* priority scheduling */ +#define _POSIX_PRIORITY_SCHEDULING 200112L + /* raw sockets */ +#define _POSIX_RAW_SOCKETS 200112L + /* read/write locks */ +#define _POSIX_READER_WRITER_LOCKS 200112L + /* realtime signals */ +#undef _POSIX_REALTIME_SIGNALS + /* regular expressions */ +#define _POSIX_REGEXP 1 + /* semaphores */ +#define _POSIX_SEMAPHORES 0 + /* shared memory */ +#undef _POSIX_SHARED_MEMORY_OBJECTS + /* shell */ +#define _POSIX_SHELL 1 + /* spin locks */ +#define _POSIX_SPIN_LOCKS 200112L + /* sporadic server */ +#undef _POSIX_SPORADIC_SERVER + /* synchronized I/O is available */ +#define _POSIX_SYNCHRONIZED_IO 1 + /* threads */ +#define _POSIX_THREADS 200112L + /* pthread_attr for stack size */ +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L + /* pthread_attr for stack address */ +#define _POSIX_THREAD_ATTR_STACKADDR 200112L + /* _r functions */ +#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L + /* timeouts */ +#undef _POSIX_TIMEOUTS + /* timers */ +#define _POSIX_TIMERS 200112L + /* typed memory objects */ +#undef _POSIX_TYPED_MEMORY_OBJECTS + /* may disable terminal spec chars */ +#define _POSIX_VDISABLE __CAST(unsigned char, '\377') + + /* C binding */ +#define _POSIX2_C_BIND 200112L + + /* XPG4.2 shared memory */ +#define _XOPEN_SHM 0 + +/* access function */ +#define F_OK 0 /* test for existence of file */ +#define X_OK 0x01 /* test for execute or search permission */ +#define W_OK 0x02 /* test for write permission */ +#define R_OK 0x04 /* test for read permission */ + +/* whence values for lseek(2) */ +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ + +#if defined(_NETBSD_SOURCE) +/* whence values for lseek(2); renamed by POSIX 1003.1 */ +#define L_SET SEEK_SET +#define L_INCR SEEK_CUR +#define L_XTND SEEK_END +#endif + +/* configurable pathname variables; use as argument to pathconf(3) */ +#define _PC_LINK_MAX 1 /* link count */ +#define _PC_MAX_CANON 2 /* size of the canonical input queue */ +#define _PC_MAX_INPUT 3 /* type-ahead buffer size */ +#define _PC_NAME_MAX 4 /* file name size */ +#define _PC_PATH_MAX 5 /* pathname size */ +#define _PC_PIPE_BUF 6 /* pipe size */ +#define _PC_NO_TRUNC 7 /* treatment of long name components */ +#define _PC_VDISABLE 8 /* tty disable */ +#define _PC_CHOWN_RESTRICTED 9 /* chown restricted or not */ + +/* configurable system variables; use as argument to sysconf(3) */ +/* + * XXX The value of _SC_CLK_TCK is embedded in . + * XXX The value of _SC_PAGESIZE is embedded in . + */ +#define _SC_ARG_MAX 1 +#define _SC_CHILD_MAX 2 +#define _SC_CLOCKS_PER_SEC 3 +#define _SC_CLK_TCK 3 +#define _SC_NGROUPS_MAX 4 +#define _SC_OPEN_MAX 5 +#define _SC_JOB_CONTROL 6 +#define _SC_SAVED_IDS 7 +#define _SC_VERSION 8 +#define _SC_STREAM_MAX 9 +#define _SC_TZNAME_MAX 10 +#define _SC_PAGESIZE 11 +#define _SC_PAGE_SIZE _SC_PAGESIZE + +#endif /* !_SYS_UNISTD_H_ */ diff --git a/nbsd_include/sys/utsname.h b/nbsd_include/sys/utsname.h new file mode 100644 index 000000000..0338c2791 --- /dev/null +++ b/nbsd_include/sys/utsname.h @@ -0,0 +1,48 @@ +#ifndef _SYS_UTSNAME_H_ +#define _SYS_UTSNAME_H_ + +#include + +#define _SYS_NMLN 256 + +#if defined(_NETBSD_SOURCE) +#define SYS_NMLN _SYS_NMLN +#endif + +struct utsname { + char sysname[_SYS_NMLN]; /* Name of this OS. */ + char nodename[_SYS_NMLN]; /* Name of this network node. */ + char release[_SYS_NMLN]; /* Release level. */ + char version[_SYS_NMLN]; /* Version level. */ + char machine[_SYS_NMLN]; /* Hardware type. */ + char arch[_SYS_NMLN]; +}; + +#include + +__BEGIN_DECLS +int uname(struct utsname *); +#ifdef __minix +int sysuname(int _req, int _field, char *_value, size_t _len); +#endif +__END_DECLS + +#ifdef __minix +/* req: Get or set a string. */ +#define _UTS_GET 0 +#define _UTS_SET 1 + +/* field: What field to get or set. These values can't be changed lightly. */ +#define _UTS_ARCH 0 +#define _UTS_KERNEL 1 +#define _UTS_MACHINE 2 +#define _UTS_HOSTNAME 3 +#define _UTS_NODENAME 4 +#define _UTS_RELEASE 5 +#define _UTS_VERSION 6 +#define _UTS_SYSNAME 7 +#define _UTS_BUS 8 +#define _UTS_MAX 9 /* Number of strings. */ +#endif /* __minix */ + +#endif /* !_SYS_UTSNAME_H_ */ diff --git a/nbsd_include/sys/uuid.h b/nbsd_include/sys/uuid.h new file mode 100644 index 000000000..086aa51cb --- /dev/null +++ b/nbsd_include/sys/uuid.h @@ -0,0 +1,82 @@ +/* $NetBSD: uuid.h,v 1.5 2008/11/18 14:01:03 joerg Exp $ */ + +/* + * Copyright (c) 2002 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: /repoman/r/ncvs/src/sys/sys/uuid.h,v 1.3 2003/05/31 16:47:07 phk Exp $ + */ + +#ifndef _SYS_UUID_H_ +#define _SYS_UUID_H_ + +#include + +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* Length of a printed UUID. */ +#define _UUID_STR_LEN 38 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +}; + +#ifdef _KERNEL + +#define UUID_NODE_LEN _UUID_NODE_LEN +#define UUID_STR_LEN _UUID_STR_LEN + +int uuid_snprintf(char *, size_t, const struct uuid *); +int uuid_printf(const struct uuid *); +void uuid_dec_be(const void *, struct uuid *); +void uuid_dec_le(const void *, struct uuid *); +void uuid_enc_be(void *, const struct uuid *); +void uuid_enc_le(void *, const struct uuid *); +void uuid_init(void); +int uuidgen(struct uuid *, int); + +#else /* _KERNEL */ + +typedef struct uuid uuid_t; + +__BEGIN_DECLS +int uuidgen(struct uuid *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* _SYS_UUID_H_ */ diff --git a/nbsd_include/sys/wait.h b/nbsd_include/sys/wait.h new file mode 100644 index 000000000..132610216 --- /dev/null +++ b/nbsd_include/sys/wait.h @@ -0,0 +1,64 @@ +#ifndef _SYS_WAIT_H_ +#define _SYS_WAIT_H_ + +#include +#include +#include + +/* The header contains macros related to wait(). The value + * returned by wait() and waitpid() depends on whether the process + * terminated by an exit() call, was killed by a signal, or was stopped + * due to job control, as follows: + * + * High byte Low byte + * +---------------------+ + * exit(status) | status | 0 | + * +---------------------+ + * killed by signal | 0 | signal | + * +---------------------+ + * stopped (job control) | signal | 0177 | + * +---------------------+ + */ + +/* + * Macros to test the exit status returned by wait + * and extract the relevant values. + */ + +#define _LOW(v) ( (v) & 0377) +#define _HIGH(v) ( ((v) >> 8) & 0377) + +#define WIFEXITED(s) (_LOW(s) == 0) /* normal exit */ +#define WEXITSTATUS(s) (_HIGH(s)) /* exit status */ +#define WTERMSIG(s) (_LOW(s) & 0177) /* sig value */ +#define WIFSIGNALED(s) ((((unsigned int)(s)-1) & 0xFFFFU) < 0xFFU) /* signaled */ +#define WIFSTOPPED(s) (_LOW(s) == 0177) /* stopped */ +#define WSTOPSIG(s) (_HIGH(s) & 0377) /* stop signal */ + +/* + * Option bits for the third argument of waitpid. WNOHANG causes the + * wait to not hang if there are no stopped or terminated processes, rather + * returning an error indication in this case (pid==0). WUNTRACED + * indicates that the caller should receive status about untraced children + * which stop due to signals. If children are stopped and a wait without + * this option is done, it is as though they were still running... nothing + * about them is returned. + */ +#define WNOHANG 0x00000001 /* don't hang in wait */ +#define WUNTRACED 0x00000002 /* tell about stopped, + untraced children */ + +/* POSIX extensions and 4.2/4.3 compatibility: */ + +/* + * Tokens for special values of the "pid" parameter to waitpid. + */ +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ + +__BEGIN_DECLS +pid_t wait(int *); +pid_t waitpid(pid_t, int *, int); +__END_DECLS + +#endif /* !_SYS_WAIT_H_ */ -- 2.44.0