aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2020-10-16 17:41:25 +0300
committerCem Keylan <cem@ckyln.com>2020-10-16 17:41:25 +0300
commite2abcdca396661cbe0ae2ddb13d5c2b85682c13a (patch)
treeacf9b5c80b645617f882c45224c6e07251711842 /sys
downloadotools-e2abcdca396661cbe0ae2ddb13d5c2b85682c13a.tar.gz
initial commit
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/CVS/Entries139
-rw-r--r--sys/sys/CVS/Repository1
-rw-r--r--sys/sys/CVS/Root1
-rw-r--r--sys/sys/_endian.h179
-rw-r--r--sys/sys/_lock.h70
-rw-r--r--sys/sys/_null.h18
-rw-r--r--sys/sys/_time.h64
-rw-r--r--sys/sys/_types.h78
-rw-r--r--sys/sys/acct.h79
-rw-r--r--sys/sys/ataio.h48
-rw-r--r--sys/sys/atomic.h258
-rw-r--r--sys/sys/audioio.h231
-rw-r--r--sys/sys/buf.h374
-rw-r--r--sys/sys/cdefs.h413
-rw-r--r--sys/sys/cdio.h435
-rw-r--r--sys/sys/chio.h176
-rw-r--r--sys/sys/conf.h633
-rw-r--r--sys/sys/core.h99
-rw-r--r--sys/sys/ctf.h186
-rw-r--r--sys/sys/device.h224
-rw-r--r--sys/sys/dir.h65
-rw-r--r--sys/sys/dirent.h100
-rw-r--r--sys/sys/disk.h160
-rw-r--r--sys/sys/disklabel.h533
-rw-r--r--sys/sys/dkio.h80
-rw-r--r--sys/sys/domain.h78
-rw-r--r--sys/sys/endian.h124
-rw-r--r--sys/sys/errno.h182
-rw-r--r--sys/sys/evcount.h50
-rw-r--r--sys/sys/event.h224
-rw-r--r--sys/sys/eventvar.h64
-rw-r--r--sys/sys/exec.h386
-rw-r--r--sys/sys/exec_elf.h785
-rw-r--r--sys/sys/exec_script.h43
-rw-r--r--sys/sys/extent.h130
-rw-r--r--sys/sys/fcntl.h220
-rw-r--r--sys/sys/file.h136
-rw-r--r--sys/sys/filedesc.h157
-rw-r--r--sys/sys/filio.h54
-rw-r--r--sys/sys/fusebuf.h148
-rw-r--r--sys/sys/futex.h41
-rw-r--r--sys/sys/gmon.h175
-rw-r--r--sys/sys/gpio.h80
-rw-r--r--sys/sys/hibernate.h159
-rw-r--r--sys/sys/hotplug.h40
-rw-r--r--sys/sys/ioccom.h68
-rw-r--r--sys/sys/ioctl.h55
-rw-r--r--sys/sys/ipc.h95
-rw-r--r--sys/sys/kcore.h65
-rw-r--r--sys/sys/kcov.h40
-rw-r--r--sys/sys/kernel.h65
-rw-r--r--sys/sys/kthread.h50
-rw-r--r--sys/sys/ktrace.h254
-rw-r--r--sys/sys/limits.h125
-rw-r--r--sys/sys/lock.h55
-rw-r--r--sys/sys/lockf.h45
-rw-r--r--sys/sys/malloc.h406
-rw-r--r--sys/sys/mbuf.h550
-rw-r--r--sys/sys/memrange.h97
-rw-r--r--sys/sys/mman.h165
-rw-r--r--sys/sys/mount.h637
-rw-r--r--sys/sys/mplock.h75
-rw-r--r--sys/sys/msg.h177
-rw-r--r--sys/sys/msgbuf.h53
-rw-r--r--sys/sys/mtio.h147
-rw-r--r--sys/sys/mutex.h165
-rw-r--r--sys/sys/namei.h279
-rw-r--r--sys/sys/param.h223
-rw-r--r--sys/sys/pciio.h78
-rw-r--r--sys/sys/percpu.h198
-rw-r--r--sys/sys/pipe.h96
-rw-r--r--sys/sys/pledge.h147
-rw-r--r--sys/sys/poll.h89
-rw-r--r--sys/sys/pool.h295
-rw-r--r--sys/sys/proc.h655
-rw-r--r--sys/sys/protosw.h237
-rw-r--r--sys/sys/ptrace.h137
-rw-r--r--sys/sys/queue.h536
-rw-r--r--sys/sys/radioio.h76
-rw-r--r--sys/sys/reboot.h106
-rw-r--r--sys/sys/refcnt.h38
-rw-r--r--sys/sys/resource.h128
-rw-r--r--sys/sys/resourcevar.h107
-rw-r--r--sys/sys/rwlock.h191
-rw-r--r--sys/sys/sched.h244
-rw-r--r--sys/sys/scsiio.h74
-rw-r--r--sys/sys/select.h137
-rw-r--r--sys/sys/selinfo.h57
-rw-r--r--sys/sys/sem.h198
-rw-r--r--sys/sys/sensors.h177
-rw-r--r--sys/sys/shm.h151
-rw-r--r--sys/sys/siginfo.h199
-rw-r--r--sys/sys/sigio.h95
-rw-r--r--sys/sys/signal.h202
-rw-r--r--sys/sys/signalvar.h144
-rw-r--r--sys/sys/smr.h440
-rw-r--r--sys/sys/socket.h572
-rw-r--r--sys/sys/socketvar.h365
-rw-r--r--sys/sys/sockio.h230
-rw-r--r--sys/sys/specdev.h113
-rw-r--r--sys/sys/srp.h190
-rw-r--r--sys/sys/stacktrace.h40
-rw-r--r--sys/sys/stat.h222
-rw-r--r--sys/sys/statvfs.h48
-rw-r--r--sys/sys/stdarg.h51
-rw-r--r--sys/sys/stdint.h231
-rw-r--r--sys/sys/swap.h62
-rw-r--r--sys/sys/syscall.h708
-rw-r--r--sys/sys/syscall_mi.h191
-rw-r--r--sys/sys/syscallargs.h1362
-rw-r--r--sys/sys/sysctl.h1061
-rw-r--r--sys/sys/syslimits.h77
-rw-r--r--sys/sys/syslog.h221
-rw-r--r--sys/sys/systm.h409
-rw-r--r--sys/sys/task.h60
-rw-r--r--sys/sys/termios.h299
-rw-r--r--sys/sys/time.h418
-rw-r--r--sys/sys/timeout.h137
-rw-r--r--sys/sys/times.h63
-rw-r--r--sys/sys/timetc.h107
-rw-r--r--sys/sys/tprintf.h41
-rw-r--r--sys/sys/tracepoint.h36
-rw-r--r--sys/sys/tree.h1006
-rw-r--r--sys/sys/tty.h336
-rw-r--r--sys/sys/ttycom.h151
-rw-r--r--sys/sys/ttydefaults.h95
-rw-r--r--sys/sys/types.h261
-rw-r--r--sys/sys/ucred.h84
-rw-r--r--sys/sys/uio.h108
-rw-r--r--sys/sys/un.h65
-rw-r--r--sys/sys/unistd.h106
-rw-r--r--sys/sys/unpcb.h111
-rw-r--r--sys/sys/user.h48
-rw-r--r--sys/sys/utsname.h59
-rw-r--r--sys/sys/uuid.h75
-rw-r--r--sys/sys/varargs.h56
-rw-r--r--sys/sys/videoio.h3372
-rw-r--r--sys/sys/vmmeter.h97
-rw-r--r--sys/sys/vnode.h665
-rw-r--r--sys/sys/wait.h103
-rw-r--r--sys/sys/witness.h156
141 files changed, 31311 insertions, 0 deletions
diff --git a/sys/sys/CVS/Entries b/sys/sys/CVS/Entries
new file mode 100644
index 0000000..5813030
--- /dev/null
+++ b/sys/sys/CVS/Entries
@@ -0,0 +1,139 @@
+/_endian.h/1.8/Thu Jan 11 23:13:37 2018//
+/_lock.h/1.4/Tue Apr 23 13:35:12 2019//
+/_null.h/1.2/Fri Sep 9 22:07:58 2016//
+/_time.h/1.9/Mon Dec 18 05:51:53 2017//
+/_types.h/1.9/Fri Aug 22 23:05:15 2014//
+/acct.h/1.9/Mon Sep 9 20:02:26 2019//
+/ataio.h/1.5/Fri Sep 26 21:43:32 2003//
+/atomic.h/1.6/Sat Mar 9 06:14:21 2019//
+/audioio.h/1.27/Wed Sep 14 06:12:20 2016//
+/buf.h/1.112/Fri Nov 29 01:04:08 2019//
+/cdefs.h/1.43/Mon Oct 29 17:10:40 2018//
+/cdio.h/1.17/Tue Oct 24 09:36:13 2017//
+/chio.h/1.7/Wed May 31 03:01:44 2006//
+/conf.h/1.150/Tue Apr 21 08:29:27 2020//
+/core.h/1.7/Sat Sep 17 06:09:08 2016//
+/ctf.h/1.5/Sun Aug 13 14:56:05 2017//
+/device.h/1.55/Mon Sep 10 16:18:34 2018//
+/dir.h/1.5/Mon Jun 2 23:28:21 2003//
+/dirent.h/1.11/Fri Dec 13 18:09:27 2013//
+/disk.h/1.36/Thu May 4 22:47:27 2017//
+/disklabel.h/1.75/Tue Oct 24 09:36:13 2017//
+/dkio.h/1.12/Tue Oct 24 09:36:13 2017//
+/domain.h/1.20/Thu Jun 13 08:12:11 2019//
+/endian.h/1.25/Sun Dec 21 04:49:00 2014//
+/errno.h/1.25/Tue Sep 5 03:06:26 2017//
+/evcount.h/1.3/Mon Sep 20 06:33:46 2010//
+/event.h/1.35/Tue Apr 7 13:27:52 2020//
+/eventvar.h/1.9/Tue Apr 7 13:27:52 2020//
+/exec.h/1.40/Fri Nov 29 06:34:46 2019//
+/exec_elf.h/1.87/Sun Dec 1 13:10:51 2019//
+/exec_script.h/1.6/Wed Feb 7 20:31:57 2018//
+/extent.h/1.14/Sat Feb 8 20:29:01 2014//
+/fcntl.h/1.22/Mon Jan 21 18:09:21 2019//
+/file.h/1.61/Fri Mar 13 10:07:01 2020//
+/filedesc.h/1.44/Thu Jan 30 15:33:04 2020//
+/filio.h/1.5/Fri Jun 1 22:30:48 2007//
+/fusebuf.h/1.13/Tue Jun 19 11:27:54 2018//
+/futex.h/1.2/Sun Jun 3 15:09:26 2018//
+/gmon.h/1.8/Sat May 7 19:30:52 2016//
+/gpio.h/1.8/Mon Oct 3 20:24:51 2011//
+/hibernate.h/1.42/Thu Jun 21 07:33:30 2018//
+/hotplug.h/1.5/Sun May 28 16:52:34 2006//
+/ioccom.h/1.5/Fri Mar 22 21:22:05 2013//
+/ioctl.h/1.17/Sun Feb 28 15:46:19 2016//
+/ipc.h/1.13/Sat Nov 15 21:42:50 2014//
+/kcore.h/1.1/Thu Apr 18 21:40:57 1996//
+/kcov.h/1.4/Sun Jan 20 09:57:23 2019//
+/kernel.h/1.22/Sat Sep 7 01:23:23 2019//
+/kthread.h/1.7/Tue Feb 18 12:13:40 2020//
+/ktrace.h/1.38/Tue Feb 26 22:24:41 2019//
+/limits.h/1.10/Sat Jun 30 20:21:10 2012//
+/lock.h/1.27/Sun Jun 19 11:54:33 2016//
+/lockf.h/1.17/Sat Apr 20 08:28:59 2019//
+/malloc.h/1.119/Thu Nov 28 16:23:11 2019//
+/mbuf.h/1.246/Wed Jan 22 22:56:35 2020//
+/memrange.h/1.10/Tue Aug 18 20:19:32 2015//
+/mman.h/1.34/Fri Mar 1 01:46:18 2019//
+/mount.h/1.147/Sat Jan 18 08:40:19 2020//
+/mplock.h/1.13/Tue Apr 23 13:35:12 2019//
+/msg.h/1.19/Sun Nov 23 04:31:42 2014//
+/msgbuf.h/1.11/Thu Jun 23 13:15:21 2016//
+/mtio.h/1.9/Fri Jun 1 18:44:48 2007//
+/mutex.h/1.18/Tue Apr 23 13:35:12 2019//
+/namei.h/1.45/Thu Mar 19 13:55:20 2020//
+/param.h/1.130/Sun Apr 5 06:34:20 2020//
+/pciio.h/1.7/Sun Sep 5 18:14:33 2010//
+/percpu.h/1.8/Tue Aug 28 15:15:02 2018//
+/pipe.h/1.24/Fri Jan 24 11:07:41 2020//
+/pledge.h/1.41/Sun Apr 5 07:31:45 2020//
+/poll.h/1.15/Tue Jun 7 06:12:37 2016//
+/pool.h/1.77/Fri Jul 19 09:03:03 2019//
+/proc.h/1.295/Tue Apr 28 08:29:40 2020//
+/protosw.h/1.31/Tue Jan 23 20:49:58 2018//
+/ptrace.h/1.16/Mon Mar 16 11:58:46 2020//
+/queue.h/1.45/Thu Jul 12 14:22:54 2018//
+/radioio.h/1.5/Wed Jan 14 21:15:36 2015//
+/reboot.h/1.18/Mon Apr 1 07:00:52 2019//
+/refcnt.h/1.4/Tue Jun 7 07:53:33 2016//
+/resource.h/1.14/Fri Oct 25 04:42:48 2013//
+/resourcevar.h/1.24/Fri Jun 21 09:39:48 2019//
+/rwlock.h/1.26/Tue Jul 16 01:40:49 2019//
+/sched.h/1.56/Mon Oct 21 10:24:01 2019//
+/scsiio.h/1.10/Wed Sep 5 17:17:47 2012//
+/select.h/1.17/Mon Sep 12 19:41:20 2016//
+/selinfo.h/1.5/Tue Jul 18 19:20:26 2017//
+/sem.h/1.24/Thu Sep 1 08:33:40 2016//
+/sensors.h/1.36/Mon Dec 10 13:35:54 2018//
+/shm.h/1.29/Sun Nov 3 20:16:01 2019//
+/siginfo.h/1.12/Fri Apr 7 04:48:44 2017//
+/sigio.h/1.4/Wed Jan 8 16:27:42 2020//
+/signal.h/1.29/Wed Apr 18 16:05:20 2018//
+/signalvar.h/1.40/Fri Mar 13 09:25:21 2020//
+/smr.h/1.6/Sun Apr 12 07:20:33 2020//
+/socket.h/1.98/Mon Jul 22 15:34:07 2019//
+/socketvar.h/1.91/Wed Jan 15 13:17:35 2020//
+/sockio.h/1.83/Wed Nov 13 11:54:01 2019//
+/specdev.h/1.39/Fri Dec 27 22:17:01 2019//
+/srp.h/1.14/Sun Mar 31 14:03:40 2019//
+/stacktrace.h/1.3/Sat Apr 18 04:45:20 2020//
+/stat.h/1.28/Sat Apr 4 18:06:08 2015//
+/statvfs.h/1.3/Sun Mar 24 17:45:50 2013//
+/stdarg.h/1.9/Thu Dec 12 15:55:36 2019//
+/stdint.h/1.11/Fri Jan 25 00:19:26 2019//
+/swap.h/1.7/Mon Sep 30 12:02:30 2013//
+/syscall.h/1.215/Wed Mar 18 19:35:00 2020//
+/syscall_mi.h/1.25/Tue Jan 21 16:16:23 2020//
+/syscallargs.h/1.218/Wed Mar 18 19:35:00 2020//
+/sysctl.h/1.205/Fri Mar 13 10:07:01 2020//
+/syslimits.h/1.14/Thu Apr 2 18:00:00 2020//
+/syslog.h/1.16/Tue Aug 8 14:23:23 2017//
+/systm.h/1.145/Fri Mar 20 03:37:08 2020//
+/task.h/1.16/Sun Jun 23 12:56:10 2019//
+/termios.h/1.13/Tue Sep 20 21:10:22 2016//
+/time.h/1.50/Wed Jan 15 13:17:35 2020//
+/timeout.h/1.36/Fri Jan 3 02:16:38 2020//
+/times.h/1.6/Sat Jul 6 18:44:21 2013//
+/timetc.h/1.10/Sat Oct 26 21:16:38 2019//
+/tprintf.h/1.6/Sun Aug 24 01:27:07 2003//
+/tracepoint.h/1.1/Tue Jan 21 16:16:23 2020//
+/tree.h/1.29/Sun Jul 30 19:27:20 2017//
+/tty.h/1.38/Fri Jul 19 00:17:16 2019//
+/ttycom.h/1.17/Sat Jun 16 13:55:03 2018//
+/ttydefaults.h/1.7/Tue Mar 12 11:01:25 2019//
+/types.h/1.48/Sat Feb 9 04:54:11 2019//
+/ucred.h/1.13/Thu Jun 21 13:58:21 2018//
+/uio.h/1.19/Mon Aug 20 16:00:22 2018//
+/un.h/1.14/Sat Jul 18 15:00:01 2015//
+/unistd.h/1.31/Mon Jul 20 00:56:10 2015//
+/unpcb.h/1.17/Mon Jul 15 12:28:06 2019//
+/user.h/1.9/Tue Jul 8 23:31:22 2014//
+/utsname.h/1.6/Sun Mar 24 17:45:50 2013//
+/uuid.h/1.3/Sun Aug 31 09:36:39 2014//
+/varargs.h/1.3/Sat Dec 7 06:55:20 2019//
+/videoio.h/1.16/Fri Feb 17 06:48:33 2017//
+/vmmeter.h/1.15/Wed Jul 27 14:44:59 2016//
+/vnode.h/1.156/Wed Apr 8 08:07:52 2020//
+/wait.h/1.17/Fri Jun 13 22:40:31 2014//
+/witness.h/1.5/Tue Apr 23 13:35:12 2019//
+D
diff --git a/sys/sys/CVS/Repository b/sys/sys/CVS/Repository
new file mode 100644
index 0000000..559e41f
--- /dev/null
+++ b/sys/sys/CVS/Repository
@@ -0,0 +1 @@
+src/sys/sys
diff --git a/sys/sys/CVS/Root b/sys/sys/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/sys/sys/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h
new file mode 100644
index 0000000..e1ce82e
--- /dev/null
+++ b/sys/sys/_endian.h
@@ -0,0 +1,179 @@
+/* $OpenBSD: _endian.h,v 1.8 2018/01/11 23:13:37 dlg Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. 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.
+ */
+
+/*
+ * Internal endianness macros. This pulls in <machine/endian.h> to
+ * get the correct setting direction for the platform and sets internal
+ * ('__' prefix) macros appropriately.
+ */
+
+#ifndef _SYS__ENDIAN_H_
+#define _SYS__ENDIAN_H_
+
+#include <sys/_types.h>
+
+#define __FROM_SYS__ENDIAN
+#include <machine/endian.h>
+#undef __FROM_SYS__ENDIAN
+
+#define _LITTLE_ENDIAN 1234
+#define _BIG_ENDIAN 4321
+#define _PDP_ENDIAN 3412
+
+/* Note that these macros evaluate their arguments several times. */
+
+#define __swap16gen(x) \
+ (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
+
+#define __swap32gen(x) \
+ (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
+ ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
+ ((__uint32_t)(x) & 0xff000000) >> 24)
+
+#define __swap64gen(x) \
+ (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
+ ((__uint64_t)(x) & 0xff00ULL) << 40 | \
+ ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
+ ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
+ ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
+ ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
+ ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
+ ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
+
+#ifndef __HAVE_MD_SWAP
+static __inline __uint16_t
+__swap16md(__uint16_t x)
+{
+ return (__swap16gen(x));
+}
+
+static __inline __uint32_t
+__swap32md(__uint32_t x)
+{
+ return (__swap32gen(x));
+}
+
+static __inline __uint64_t
+__swap64md(__uint64_t x)
+{
+ return (__swap64gen(x));
+}
+#endif
+
+#define __swap16(x) \
+ (__uint16_t)(__builtin_constant_p(x) ? __swap16gen(x) : __swap16md(x))
+#define __swap32(x) \
+ (__uint32_t)(__builtin_constant_p(x) ? __swap32gen(x) : __swap32md(x))
+#define __swap64(x) \
+ (__uint64_t)(__builtin_constant_p(x) ? __swap64gen(x) : __swap64md(x))
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+
+#define __htobe16 __swap16
+#define __htobe32 __swap32
+#define __htobe64 __swap64
+#define __htole16(x) ((__uint16_t)(x))
+#define __htole32(x) ((__uint32_t)(x))
+#define __htole64(x) ((__uint64_t)(x))
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __bemtoh16(_x) __mswap16(_x)
+#define __bemtoh32(_x) __mswap32(_x)
+#define __bemtoh64(_x) __mswap64(_x)
+
+#define __htobem16(_x, _v) __swapm16((_x), (_v))
+#define __htobem32(_x, _v) __swapm32((_x), (_v))
+#define __htobem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
+
+#define __htobe16(x) ((__uint16_t)(x))
+#define __htobe32(x) ((__uint32_t)(x))
+#define __htobe64(x) ((__uint64_t)(x))
+#define __htole16 __swap16
+#define __htole32 __swap32
+#define __htole64 __swap64
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __lemtoh16(_x) __mswap16(_x)
+#define __lemtoh32(_x) __mswap32(_x)
+#define __lemtoh64(_x) __mswap64(_x)
+
+#define __htolem16(_x, _v) __swapm16((_x), (_v))
+#define __htolem32(_x, _v) __swapm32((_x), (_v))
+#define __htolem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _BIG_ENDIAN */
+
+
+#ifdef _KERNEL
+/*
+ * Fill in the __hto[bl]em{16,32,64} and __[bl]emtoh{16,32,64} macros
+ * that haven't been defined yet
+ */
+
+#ifndef __bemtoh16
+#define __bemtoh16(_x) __htobe16(*(__uint16_t *)(_x))
+#define __bemtoh32(_x) __htobe32(*(__uint32_t *)(_x))
+#define __bemtoh64(_x) __htobe64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htobem16
+#define __htobem16(_x, _v) (*(__uint16_t *)(_x) = __htobe16(_v))
+#define __htobem32(_x, _v) (*(__uint32_t *)(_x) = __htobe32(_v))
+#define __htobem64(_x, _v) (*(__uint64_t *)(_x) = __htobe64(_v))
+#endif
+
+#ifndef __lemtoh16
+#define __lemtoh16(_x) __htole16(*(__uint16_t *)(_x))
+#define __lemtoh32(_x) __htole32(*(__uint32_t *)(_x))
+#define __lemtoh64(_x) __htole64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htolem16
+#define __htolem16(_x, _v) (*(__uint16_t *)(_x) = __htole16(_v))
+#define __htolem32(_x, _v) (*(__uint32_t *)(_x) = __htole32(_v))
+#define __htolem64(_x, _v) (*(__uint64_t *)(_x) = __htole64(_v))
+#endif
+#endif /* _KERNEL */
+
+#endif /* _SYS__ENDIAN_H_ */
diff --git a/sys/sys/_lock.h b/sys/sys/_lock.h
new file mode 100644
index 0000000..fbcfb0a
--- /dev/null
+++ b/sys/sys/_lock.h
@@ -0,0 +1,70 @@
+/* $OpenBSD: _lock.h,v 1.4 2019/04/23 13:35:12 visa Exp $ */
+
+/*-
+ * Copyright (c) 1997 Berkeley Software Design, 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. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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: head/sys/sys/_lock.h 179025 2008-05-15 20:10:06Z attilio $
+ */
+
+#ifndef _SYS__LOCK_H_
+#define _SYS__LOCK_H_
+
+#define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */
+#define LO_INITIALIZED 0x00010000 /* Lock has been initialized. */
+#define LO_WITNESS 0x00020000 /* Should witness monitor this lock. */
+#define LO_QUIET 0x00040000 /* Don't log locking operations. */
+#define LO_RECURSABLE 0x00080000 /* Lock may recurse. */
+#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */
+#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */
+#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */
+#define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */
+#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */
+#define LO_NOPROFILE 0x10000000 /* Don't profile this lock */
+#define LO_NEW 0x20000000 /* Don't check for double-init */
+
+#define LO_CLASSSHIFT 24
+
+enum lock_class_index {
+ LO_CLASS_KERNEL_LOCK,
+ LO_CLASS_SCHED_LOCK,
+ LO_CLASS_MUTEX,
+ LO_CLASS_RWLOCK,
+ LO_CLASS_RRWLOCK
+};
+
+struct lock_object {
+ const struct lock_type *lo_type;
+ const char *lo_name; /* Individual lock name. */
+ struct witness *lo_witness; /* Data for witness. */
+ unsigned int lo_flags;
+};
+
+struct lock_type {
+ const char *lt_name;
+};
+
+#endif /* !_SYS__LOCK_H_ */
diff --git a/sys/sys/_null.h b/sys/sys/_null.h
new file mode 100644
index 0000000..5d15401
--- /dev/null
+++ b/sys/sys/_null.h
@@ -0,0 +1,18 @@
+/* $OpenBSD: _null.h,v 1.2 2016/09/09 22:07:58 millert Exp $ */
+
+/*
+ * Written by Todd C. Miller, September 9, 2016
+ * Public domain.
+ */
+
+#ifndef NULL
+#if !defined(__cplusplus)
+#define NULL ((void *)0)
+#elif __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__GNUG__)
+#define NULL __null
+#else
+#define NULL 0L
+#endif
+#endif
diff --git a/sys/sys/_time.h b/sys/sys/_time.h
new file mode 100644
index 0000000..a8ac94e
--- /dev/null
+++ b/sys/sys/_time.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: _time.h,v 1.9 2017/12/18 05:51:53 cheloha 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.
+ */
+
+#ifndef _SYS__TIME_H_
+#define _SYS__TIME_H_
+
+#define CLOCK_REALTIME 0
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_MONOTONIC 3
+#define CLOCK_THREAD_CPUTIME_ID 4
+#define CLOCK_UPTIME 5
+#define CLOCK_BOOTTIME 6
+
+#if __BSD_VISIBLE
+/*
+ * Per-process and per-thread clocks encode the PID or TID into the
+ * high bits, with the type in the bottom bits
+ */
+#define __CLOCK_ENCODE(type,id) ((type) | ((id) << 12))
+#define __CLOCK_TYPE(c) ((c) & 0xfff)
+#define __CLOCK_PTID(c) (((c) >> 12) & 0xfffff)
+#endif
+
+/*
+ * Structure defined by POSIX 1003.1b to be like a itimerval,
+ * but with timespecs. Used in the timer_*() system calls.
+ */
+struct itimerspec {
+ struct timespec it_interval; /* timer interval */
+ struct timespec it_value; /* timer expiration */
+};
+
+#define TIMER_RELTIME 0x0 /* relative timer */
+#define TIMER_ABSTIME 0x1 /* absolute timer */
+
+#endif /* !_SYS__TIME_H_ */
diff --git a/sys/sys/_types.h b/sys/sys/_types.h
new file mode 100644
index 0000000..e058674
--- /dev/null
+++ b/sys/sys/_types.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: _types.h,v 1.9 2014/08/22 23:05:15 krw 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.
+ *
+ * @(#)types.h 8.3 (Berkeley) 1/5/94
+ */
+
+#ifndef _SYS__TYPES_H_
+#define _SYS__TYPES_H_
+
+#include <machine/_types.h>
+
+typedef __int64_t __blkcnt_t; /* blocks allocated for file */
+typedef __int32_t __blksize_t; /* optimal blocksize for I/O */
+typedef __int64_t __clock_t; /* ticks in CLOCKS_PER_SEC */
+typedef __int32_t __clockid_t; /* CLOCK_* identifiers */
+typedef unsigned long __cpuid_t; /* CPU id */
+typedef __int32_t __dev_t; /* device number */
+typedef __uint32_t __fixpt_t; /* fixed point number */
+typedef __uint64_t __fsblkcnt_t; /* file system block count */
+typedef __uint64_t __fsfilcnt_t; /* file system file count */
+typedef __uint32_t __gid_t; /* group id */
+typedef __uint32_t __id_t; /* may contain pid, uid or gid */
+typedef __uint32_t __in_addr_t; /* base type for internet address */
+typedef __uint16_t __in_port_t; /* IP port type */
+typedef __uint64_t __ino_t; /* inode number */
+typedef long __key_t; /* IPC key (for Sys V IPC) */
+typedef __uint32_t __mode_t; /* permissions */
+typedef __uint32_t __nlink_t; /* link count */
+typedef __int64_t __off_t; /* file offset or size */
+typedef __int32_t __pid_t; /* process id */
+typedef __uint64_t __rlim_t; /* resource limit */
+typedef __uint8_t __sa_family_t; /* sockaddr address family type */
+typedef __int32_t __segsz_t; /* segment size */
+typedef __uint32_t __socklen_t; /* length type for network syscalls */
+typedef long __suseconds_t; /* microseconds (signed) */
+typedef __int32_t __swblk_t; /* swap offset */
+typedef __int64_t __time_t; /* epoch time */
+typedef __int32_t __timer_t; /* POSIX timer identifiers */
+typedef __uint32_t __uid_t; /* user id */
+typedef __uint32_t __useconds_t; /* microseconds */
+
+/*
+ * 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 {
+ char __mbstate8[128];
+ __int64_t __mbstateL; /* for alignment */
+} __mbstate_t;
+
+#endif /* !_SYS__TYPES_H_ */
diff --git a/sys/sys/acct.h b/sys/sys/acct.h
new file mode 100644
index 0000000..db7c846
--- /dev/null
+++ b/sys/sys/acct.h
@@ -0,0 +1,79 @@
+/* $OpenBSD: acct.h,v 1.9 2019/09/09 20:02:26 bluhm Exp $ */
+/* $NetBSD: acct.h,v 1.16 1995/03/26 20:23:52 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)acct.h 8.3 (Berkeley) 7/10/94
+ */
+
+/*
+ * Accounting structures; these use a comp_t type which is a 3 bits base 8
+ * exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ
+ * seconds.
+ */
+typedef u_int16_t comp_t;
+
+struct acct {
+ char ac_comm[10]; /* command name */
+ comp_t ac_utime; /* user time */
+ comp_t ac_stime; /* system time */
+ comp_t ac_etime; /* elapsed time */
+ time_t ac_btime; /* starting time */
+ uid_t ac_uid; /* user id */
+ gid_t ac_gid; /* group id */
+ u_int16_t ac_mem; /* average memory usage */
+ comp_t ac_io; /* count of IO blocks */
+ dev_t ac_tty; /* controlling tty */
+
+#define AFORK 0x01 /* fork'd but not exec'd */
+#define ASU 0x02 /* used super-user permissions */
+#define AMAP 0x04 /* system call or stack mapping violation */
+#define ACORE 0x08 /* dumped core */
+#define AXSIG 0x10 /* killed by a signal */
+#define APLEDGE 0x20 /* killed due to pledge violation */
+#define ATRAP 0x40 /* memory access violation */
+#define AUNVEIL 0x80 /* unveil access violation */
+ u_int8_t ac_flag; /* accounting flags */
+};
+
+/*
+ * 1/AHZ is the granularity of the data encoded in the comp_t fields.
+ * This is not necessarily equal to hz.
+ */
+#define AHZ 64
+
+#ifdef _KERNEL
+int acct_process(struct proc *p);
+void acct_shutdown(void);
+#endif
diff --git a/sys/sys/ataio.h b/sys/sys/ataio.h
new file mode 100644
index 0000000..fe79794
--- /dev/null
+++ b/sys/sys/ataio.h
@@ -0,0 +1,48 @@
+/* $OpenBSD: ataio.h,v 1.5 2003/09/26 21:43:32 miod Exp $ */
+/* $NetBSD: ataio.h,v 1.2 1998/11/23 22:58:23 kenh Exp $ */
+
+#ifndef _SYS_ATAIO_H_
+#define _SYS_ATAIO_H_
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+typedef struct atareq {
+ u_long flags; /* info about the request status and type */
+ u_char command; /* command code */
+ u_char features; /* feature modifier bits for command */
+ u_char sec_count; /* sector count */
+ u_char sec_num; /* sector number */
+ u_char head; /* head number */
+ u_short cylinder; /* cylinder/lba address */
+
+ caddr_t databuf; /* pointer to I/O data buffer */
+ u_long datalen; /* length of data buffer */
+ int timeout; /* command timeout */
+ u_char retsts; /* return status for the command */
+ u_char error; /* error bits */
+} atareq_t;
+
+/* bit definitions for flags */
+#define ATACMD_READ 0x00000001
+#define ATACMD_WRITE 0x00000002
+#define ATACMD_READREG 0x00000004
+
+/* definitions for the return status (retsts) */
+#define ATACMD_OK 0x00
+#define ATACMD_TIMEOUT 0x01
+#define ATACMD_ERROR 0x02
+#define ATACMD_DF 0x03
+
+#define ATAIOCCOMMAND _IOWR('Q', 8, atareq_t)
+
+typedef struct atagettrace {
+ unsigned int buf_size; /* length of data buffer */
+ void *buf; /* pointer to data buffer */
+ unsigned int bytes_copied; /* number of bytes copied to buffer */
+ unsigned int bytes_left; /* number of bytes left */
+} atagettrace_t;
+
+#define ATAIOGETTRACE _IOWR('Q', 27, struct atagettrace)
+
+#endif /* _SYS_ATAIO_H_ */
diff --git a/sys/sys/atomic.h b/sys/sys/atomic.h
new file mode 100644
index 0000000..22b92b6
--- /dev/null
+++ b/sys/sys/atomic.h
@@ -0,0 +1,258 @@
+/* $OpenBSD: atomic.h,v 1.6 2019/03/09 06:14:21 visa Exp $ */
+/*
+ * Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_ATOMIC_H_
+#define _SYS_ATOMIC_H_
+
+#include <machine/atomic.h>
+
+/*
+ * an arch wanting to provide its own implementations does so by defining
+ * macros.
+ */
+
+/*
+ * atomic_cas_*
+ */
+
+#ifndef atomic_cas_uint
+static inline unsigned int
+atomic_cas_uint(volatile unsigned int *p, unsigned int o, unsigned int n)
+{
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+#ifndef atomic_cas_ulong
+static inline unsigned long
+atomic_cas_ulong(volatile unsigned long *p, unsigned long o, unsigned long n)
+{
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+#ifndef atomic_cas_ptr
+static inline void *
+atomic_cas_ptr(volatile void *pp, void *o, void *n)
+{
+ void * volatile *p = (void * volatile *)pp;
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+/*
+ * atomic_swap_*
+ */
+
+#ifndef atomic_swap_uint
+static inline unsigned int
+atomic_swap_uint(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+#ifndef atomic_swap_ulong
+static inline unsigned long
+atomic_swap_ulong(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+#ifndef atomic_swap_ptr
+static inline void *
+atomic_swap_ptr(volatile void *pp, void *v)
+{
+ void * volatile *p = (void * volatile *)pp;
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+/*
+ * atomic_add_*_nv - add and fetch
+ */
+
+#ifndef atomic_add_int_nv
+static inline unsigned int
+atomic_add_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_add_and_fetch(p, v);
+}
+#endif
+
+#ifndef atomic_add_long_nv
+static inline unsigned long
+atomic_add_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_add_and_fetch(p, v);
+}
+#endif
+
+/*
+ * atomic_add - add
+ */
+
+#ifndef atomic_add_int
+#define atomic_add_int(_p, _v) ((void)atomic_add_int_nv((_p), (_v)))
+#endif
+
+#ifndef atomic_add_long
+#define atomic_add_long(_p, _v) ((void)atomic_add_long_nv((_p), (_v)))
+#endif
+
+/*
+ * atomic_inc_*_nv - increment and fetch
+ */
+
+#ifndef atomic_inc_int_nv
+#define atomic_inc_int_nv(_p) atomic_add_int_nv((_p), 1)
+#endif
+
+#ifndef atomic_inc_long_nv
+#define atomic_inc_long_nv(_p) atomic_add_long_nv((_p), 1)
+#endif
+
+/*
+ * atomic_inc_* - increment
+ */
+
+#ifndef atomic_inc_int
+#define atomic_inc_int(_p) ((void)atomic_inc_int_nv(_p))
+#endif
+
+#ifndef atomic_inc_long
+#define atomic_inc_long(_p) ((void)atomic_inc_long_nv(_p))
+#endif
+
+/*
+ * atomic_sub_*_nv - sub and fetch
+ */
+
+#ifndef atomic_sub_int_nv
+static inline unsigned int
+atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_sub_and_fetch(p, v);
+}
+#endif
+
+#ifndef atomic_sub_long_nv
+static inline unsigned long
+atomic_sub_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_sub_and_fetch(p, v);
+}
+#endif
+
+/*
+ * atomic_sub_* - sub
+ */
+
+#ifndef atomic_sub_int
+#define atomic_sub_int(_p, _v) ((void)atomic_sub_int_nv((_p), (_v)))
+#endif
+
+#ifndef atomic_sub_long
+#define atomic_sub_long(_p, _v) ((void)atomic_sub_long_nv((_p), (_v)))
+#endif
+
+/*
+ * atomic_dec_*_nv - decrement and fetch
+ */
+
+#ifndef atomic_dec_int_nv
+#define atomic_dec_int_nv(_p) atomic_sub_int_nv((_p), 1)
+#endif
+
+#ifndef atomic_dec_long_nv
+#define atomic_dec_long_nv(_p) atomic_sub_long_nv((_p), 1)
+#endif
+
+/*
+ * atomic_dec_* - decrement
+ */
+
+#ifndef atomic_dec_int
+#define atomic_dec_int(_p) ((void)atomic_dec_int_nv(_p))
+#endif
+
+#ifndef atomic_dec_long
+#define atomic_dec_long(_p) ((void)atomic_dec_long_nv(_p))
+#endif
+
+/*
+ * memory barriers
+ */
+
+#ifndef membar_enter
+#define membar_enter() __sync_synchronize()
+#endif
+
+#ifndef membar_exit
+#define membar_exit() __sync_synchronize()
+#endif
+
+#ifndef membar_producer
+#define membar_producer() __sync_synchronize()
+#endif
+
+#ifndef membar_consumer
+#define membar_consumer() __sync_synchronize()
+#endif
+
+#ifndef membar_sync
+#define membar_sync() __sync_synchronize()
+#endif
+
+#ifndef membar_enter_after_atomic
+#define membar_enter_after_atomic() membar_enter()
+#endif
+
+#ifndef membar_exit_before_atomic
+#define membar_exit_before_atomic() membar_exit()
+#endif
+
+#ifdef _KERNEL
+
+/*
+ * Force any preceding reads to happen before any subsequent reads that
+ * depend on the value returned by the preceding reads.
+ */
+static inline void
+membar_datadep_consumer(void)
+{
+#ifdef __alpha__
+ membar_consumer();
+#endif
+}
+
+#define READ_ONCE(x) ({ \
+ typeof(x) __tmp = *(volatile typeof(x) *)&(x); \
+ membar_datadep_consumer(); \
+ __tmp; \
+})
+
+#define WRITE_ONCE(x, val) ({ \
+ typeof(x) __tmp = (val); \
+ *(volatile typeof(x) *)&(x) = __tmp; \
+ __tmp; \
+})
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_ATOMIC_H_ */
diff --git a/sys/sys/audioio.h b/sys/sys/audioio.h
new file mode 100644
index 0000000..62a98e8
--- /dev/null
+++ b/sys/sys/audioio.h
@@ -0,0 +1,231 @@
+/* $OpenBSD: audioio.h,v 1.27 2016/09/14 06:12:20 ratchov Exp $ */
+/* $NetBSD: audioio.h,v 1.24 1998/08/13 06:28:41 mrg Exp $ */
+
+/*
+ * Copyright (c) 1991-1993 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory 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.
+ *
+ */
+
+#ifndef _SYS_AUDIOIO_H_
+#define _SYS_AUDIOIO_H_
+
+#define AUMODE_PLAY 0x01
+#define AUMODE_RECORD 0x02
+
+#define AUDIO_INITPAR(p) \
+ (void)memset((void *)(p), 0xff, sizeof(struct audio_swpar))
+
+/*
+ * argument to AUDIO_SETPAR and AUDIO_GETPAR ioctls
+ */
+struct audio_swpar {
+ unsigned int sig; /* if 1, encoding is signed */
+ unsigned int le; /* if 1, encoding is little-endian */
+ unsigned int bits; /* bits per sample */
+ unsigned int bps; /* bytes per sample */
+ unsigned int msb; /* if 1, bits are msb-aligned */
+ unsigned int rate; /* common play & rec sample rate */
+ unsigned int pchan; /* play channels */
+ unsigned int rchan; /* rec channels */
+ unsigned int nblks; /* number of blocks in play buffer */
+ unsigned int round; /* common frames per block */
+ unsigned int _spare[6];
+};
+
+/*
+ * argument to AUDIO_GETSTATUS
+ */
+struct audio_status {
+ int mode;
+ int pause;
+ int active;
+ int _spare[5];
+};
+
+/*
+ * Parameter for the AUDIO_GETDEV ioctl to determine current
+ * audio devices.
+ */
+#define MAX_AUDIO_DEV_LEN 16
+typedef struct audio_device {
+ char name[MAX_AUDIO_DEV_LEN];
+ char version[MAX_AUDIO_DEV_LEN];
+ char config[MAX_AUDIO_DEV_LEN];
+} audio_device_t;
+
+struct audio_pos {
+ unsigned int play_pos; /* total bytes played */
+ unsigned int play_xrun; /* bytes of silence inserted */
+ unsigned int rec_pos; /* total bytes recorded */
+ unsigned int rec_xrun; /* bytes dropped */
+};
+
+/*
+ * Audio device operations
+ */
+#define AUDIO_GETDEV _IOR('A', 27, struct audio_device)
+#define AUDIO_GETPOS _IOR('A', 35, struct audio_pos)
+#define AUDIO_GETPAR _IOR('A', 36, struct audio_swpar)
+#define AUDIO_SETPAR _IOWR('A', 37, struct audio_swpar)
+#define AUDIO_START _IO('A', 38)
+#define AUDIO_STOP _IO('A', 39)
+#define AUDIO_GETSTATUS _IOR('A', 40, struct audio_status)
+
+/*
+ * Mixer device
+ */
+#define AUDIO_MIN_GAIN 0
+#define AUDIO_MAX_GAIN 255
+
+typedef struct mixer_level {
+ int num_channels;
+ u_char level[8]; /* [num_channels] */
+} mixer_level_t;
+#define AUDIO_MIXER_LEVEL_MONO 0
+#define AUDIO_MIXER_LEVEL_LEFT 0
+#define AUDIO_MIXER_LEVEL_RIGHT 1
+
+/*
+ * Device operations
+ */
+
+typedef struct audio_mixer_name {
+ char name[MAX_AUDIO_DEV_LEN];
+ int msg_id;
+} audio_mixer_name_t;
+
+typedef struct mixer_devinfo {
+ int index;
+ audio_mixer_name_t label;
+ int type;
+#define AUDIO_MIXER_CLASS 0
+#define AUDIO_MIXER_ENUM 1
+#define AUDIO_MIXER_SET 2
+#define AUDIO_MIXER_VALUE 3
+ int mixer_class;
+ int next, prev;
+#define AUDIO_MIXER_LAST -1
+ union {
+ struct audio_mixer_enum {
+ int num_mem;
+ struct {
+ audio_mixer_name_t label;
+ int ord;
+ } member[32];
+ } e;
+ struct audio_mixer_set {
+ int num_mem;
+ struct {
+ audio_mixer_name_t label;
+ int mask;
+ } member[32];
+ } s;
+ struct audio_mixer_value {
+ audio_mixer_name_t units;
+ int num_channels;
+ int delta;
+ } v;
+ } un;
+} mixer_devinfo_t;
+
+
+typedef struct mixer_ctrl {
+ int dev;
+ int type;
+ union {
+ int ord; /* enum */
+ int mask; /* set */
+ mixer_level_t value; /* value */
+ } un;
+} mixer_ctrl_t;
+
+/*
+ * Mixer operations
+ */
+#define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t)
+#define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t)
+#define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t)
+
+/*
+ * Well known device names
+ */
+#define AudioNmicrophone "mic"
+#define AudioNline "line"
+#define AudioNcd "cd"
+#define AudioNdac "dac"
+#define AudioNaux "aux"
+#define AudioNrecord "record"
+#define AudioNvolume "volume"
+#define AudioNmonitor "monitor"
+#define AudioNtreble "treble"
+#define AudioNmid "mid"
+#define AudioNbass "bass"
+#define AudioNbassboost "bassboost"
+#define AudioNspeaker "spkr"
+#define AudioNheadphone "hp"
+#define AudioNoutput "output"
+#define AudioNinput "input"
+#define AudioNmaster "master"
+#define AudioNstereo "stereo"
+#define AudioNmono "mono"
+#define AudioNloudness "loudness"
+#define AudioNspatial "spatial"
+#define AudioNsurround "surround"
+#define AudioNpseudo "pseudo"
+#define AudioNmute "mute"
+#define AudioNenhanced "enhanced"
+#define AudioNpreamp "preamp"
+#define AudioNon "on"
+#define AudioNoff "off"
+#define AudioNmode "mode"
+#define AudioNsource "source"
+#define AudioNfmsynth "fmsynth"
+#define AudioNwave "wave"
+#define AudioNmidi "midi"
+#define AudioNmixerout "mixerout"
+#define AudioNswap "swap" /* swap left and right channels */
+#define AudioNagc "agc"
+#define AudioNdelay "delay"
+#define AudioNselect "select" /* select destination */
+#define AudioNvideo "video"
+#define AudioNcenter "center"
+#define AudioNdepth "depth"
+#define AudioNlfe "lfe"
+#define AudioNextamp "extamp"
+
+#define AudioCinputs "inputs"
+#define AudioCoutputs "outputs"
+#define AudioCrecord "record"
+#define AudioCmonitor "monitor"
+#define AudioCequalization "equalization"
+
+#endif /* !_SYS_AUDIOIO_H_ */
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
new file mode 100644
index 0000000..ea01ac0
--- /dev/null
+++ b/sys/sys/buf.h
@@ -0,0 +1,374 @@
+/* $OpenBSD: buf.h,v 1.112 2019/11/29 01:04:08 beck Exp $ */
+/* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * 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.
+ *
+ * @(#)buf.h 8.7 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_BUF_H_
+#define _SYS_BUF_H_
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/mutex.h>
+#include <uvm/uvm_extern.h>
+
+#define NOLIST ((struct buf *)0x87654321)
+
+struct buf;
+struct vnode;
+
+LIST_HEAD(bufhead, buf);
+
+/*
+ * To avoid including <ufs/ffs/softdep.h>
+ */
+
+LIST_HEAD(workhead, worklist);
+
+/*
+ * Buffer queues
+ */
+#define BUFQ_NSCAN_N 128
+#define BUFQ_FIFO 0
+#define BUFQ_NSCAN 1
+#define BUFQ_DEFAULT BUFQ_NSCAN
+#define BUFQ_HOWMANY 2
+
+/*
+ * Write limits for bufq - defines high and low water marks for how
+ * many kva slots are allowed to be consumed to parallelize writes from
+ * the buffer cache from any individual bufq.
+ */
+#define BUFQ_HI 128
+#define BUFQ_LOW 64
+
+struct bufq_impl;
+
+struct bufq {
+ SLIST_ENTRY(bufq) bufq_entries;
+ struct mutex bufq_mtx;
+ void *bufq_data;
+ u_int bufq_outstanding;
+ u_int bufq_hi;
+ u_int bufq_low;
+ int bufq_waiting;
+ int bufq_stop;
+ int bufq_type;
+ const struct bufq_impl *bufq_impl;
+};
+
+int bufq_init(struct bufq *, int);
+int bufq_switch(struct bufq *, int);
+void bufq_destroy(struct bufq *);
+
+void bufq_queue(struct bufq *, struct buf *);
+struct buf *bufq_dequeue(struct bufq *);
+void bufq_requeue(struct bufq *, struct buf *);
+int bufq_peek(struct bufq *);
+void bufq_drain(struct bufq *);
+
+void bufq_wait(struct bufq *);
+void bufq_done(struct bufq *, struct buf *);
+void bufq_quiesce(void);
+void bufq_restart(void);
+
+/* fifo */
+SIMPLEQ_HEAD(bufq_fifo_head, buf);
+struct bufq_fifo {
+ SIMPLEQ_ENTRY(buf) bqf_entries;
+};
+
+/* nscan */
+SIMPLEQ_HEAD(bufq_nscan_head, buf);
+struct bufq_nscan {
+ SIMPLEQ_ENTRY(buf) bqf_entries;
+};
+
+/* bufq link in struct buf */
+union bufq_data {
+ struct bufq_fifo bufq_data_fifo;
+ struct bufq_nscan bufq_data_nscan;
+};
+
+/*
+ * These are currently used only by the soft dependency code, hence
+ * are stored once in a global variable. If other subsystems wanted
+ * to use these hooks, a pointer to a set of bio_ops could be added
+ * to each buffer.
+ */
+extern struct bio_ops {
+ void (*io_start)(struct buf *);
+ void (*io_complete)(struct buf *);
+ void (*io_deallocate)(struct buf *);
+ void (*io_movedeps)(struct buf *, struct buf *);
+ int (*io_countdeps)(struct buf *, int, int);
+} bioops;
+
+/* The buffer header describes an I/O operation in the kernel. */
+struct buf {
+ RBT_ENTRY(buf) b_rbbufs; /* vnode "hash" tree */
+ LIST_ENTRY(buf) b_list; /* All allocated buffers. */
+ LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */
+ TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */
+ int cache; /* which cache are we in */
+ struct proc *b_proc; /* Associated proc; NULL if kernel. */
+ volatile long b_flags; /* B_* flags. */
+ long b_bufsize; /* Allocated buffer size. */
+ long b_bcount; /* Valid bytes in buffer. */
+ size_t b_resid; /* Remaining I/O. */
+ int b_error; /* Errno value. */
+ dev_t b_dev; /* Device associated with buffer. */
+ caddr_t b_data; /* associated data */
+ void *b_saveaddr; /* Original b_data for physio. */
+
+ TAILQ_ENTRY(buf) b_valist; /* LRU of va to reuse. */
+
+ union bufq_data b_bufq;
+ struct bufq *b_bq; /* What bufq this buf is on */
+
+ struct uvm_object *b_pobj;
+ struct uvm_object b_uobj; /* Object containing the pages */
+ off_t b_poffs; /* Offset within object */
+
+ daddr_t b_lblkno; /* Logical block number. */
+ daddr_t b_blkno; /* Underlying physical block number. */
+ /* Function to call upon completion.
+ * Will be called at splbio(). */
+ void (*b_iodone)(struct buf *);
+ struct vnode *b_vp; /* Device vnode. */
+ int b_dirtyoff; /* Offset in buffer of dirty region. */
+ int b_dirtyend; /* Offset of end of dirty region. */
+ int b_validoff; /* Offset in buffer of valid region. */
+ int b_validend; /* Offset of end of valid region. */
+ struct workhead b_dep; /* List of filesystem dependencies. */
+};
+
+TAILQ_HEAD(bufqueue, buf);
+
+struct bufcache {
+ int64_t hotbufpages;
+ int64_t warmbufpages;
+ int64_t cachepages;
+ struct bufqueue hotqueue;
+ struct bufqueue coldqueue;
+ struct bufqueue warmqueue;
+};
+
+/* Device driver compatibility definitions. */
+#define b_active b_bcount /* Driver queue head: drive active. */
+
+/*
+ * These flags are kept in b_flags.
+ */
+#define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
+#define B_AGE 0x00000001 /* Move to age queue when I/O done. */
+#define B_NEEDCOMMIT 0x00000002 /* Needs committing to stable storage */
+#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */
+#define B_BAD 0x00000008 /* Bad block revectoring in progress. */
+#define B_BUSY 0x00000010 /* I/O in progress. */
+#define B_CACHE 0x00000020 /* Bread found us in the cache. */
+#define B_CALL 0x00000040 /* Call b_iodone from biodone. */
+#define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */
+#define B_DONE 0x00000100 /* I/O completed. */
+#define B_EINTR 0x00000200 /* I/O was interrupted */
+#define B_ERROR 0x00000400 /* I/O error occurred. */
+#define B_INVAL 0x00000800 /* Does not contain valid info. */
+#define B_NOCACHE 0x00001000 /* Do not cache block after use. */
+#define B_PHYS 0x00002000 /* I/O to user memory. */
+#define B_RAW 0x00004000 /* Set by physio for raw transfers. */
+#define B_READ 0x00008000 /* Read buffer. */
+#define B_WANTED 0x00010000 /* Process wants this buffer. */
+#define B_WRITEINPROG 0x00020000 /* Write in progress. */
+#define B_XXX 0x00040000 /* Debugging flag. */
+#define B_DEFERRED 0x00080000 /* Skipped over for cleaning */
+#define B_SCANNED 0x00100000 /* Block already pushed during sync */
+#define B_PDAEMON 0x00200000 /* I/O started by pagedaemon */
+#define B_RELEASED 0x00400000 /* free this buffer after its kvm */
+#define B_WARM 0x00800000 /* buffer is or has been on the warm queue */
+#define B_COLD 0x01000000 /* buffer is on the cold queue */
+#define B_BC 0x02000000 /* buffer is managed by the cache */
+#define B_DMA 0x04000000 /* buffer is DMA reachable */
+
+#define B_BITS "\20\001AGE\002NEEDCOMMIT\003ASYNC\004BAD\005BUSY" \
+ "\006CACHE\007CALL\010DELWRI\011DONE\012EINTR\013ERROR" \
+ "\014INVAL\015NOCACHE\016PHYS\017RAW\020READ" \
+ "\021WANTED\022WRITEINPROG\023XXX(FORMAT)\024DEFERRED" \
+ "\025SCANNED\026DAEMON\027RELEASED\030WARM\031COLD\032BC\033DMA"
+
+/*
+ * Zero out the buffer's data area.
+ */
+#define clrbuf(bp) { \
+ bzero((bp)->b_data, (bp)->b_bcount); \
+ (bp)->b_resid = 0; \
+}
+
+
+/* Flags to low-level allocation routines. */
+#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
+#define B_SYNC 0x02 /* Do all allocations synchronously. */
+
+struct cluster_info {
+ daddr_t ci_lastr; /* last read (read-ahead) */
+ daddr_t ci_lastw; /* last write (write cluster) */
+ daddr_t ci_cstart; /* start block of cluster */
+ daddr_t ci_lasta; /* last allocation */
+ int ci_clen; /* length of current cluster */
+ int ci_ralen; /* Read-ahead length */
+ daddr_t ci_maxra; /* last readahead block */
+};
+
+#ifdef _KERNEL
+__BEGIN_DECLS
+/* Kva slots (of size MAXPHYS) reserved for syncer and cleaner. */
+#define RESERVE_SLOTS 4
+/* Buffer cache pages reserved for syncer and cleaner. */
+#define RESERVE_PAGES (RESERVE_SLOTS * MAXPHYS / PAGE_SIZE)
+/* Minimum size of the buffer cache, in pages. */
+#define BCACHE_MIN (RESERVE_PAGES * 2)
+#define UNCLEAN_PAGES (bcstats.numbufpages - bcstats.numcleanpages)
+
+extern struct proc *cleanerproc;
+extern long bufpages; /* Max number of pages for buffers' data */
+extern struct pool bufpool;
+extern struct bufhead bufhead;
+
+void bawrite(struct buf *);
+void bdwrite(struct buf *);
+void biodone(struct buf *);
+int biowait(struct buf *);
+int bread(struct vnode *, daddr_t, int, struct buf **);
+int breadn(struct vnode *, daddr_t, int, daddr_t *, int *, int,
+ struct buf **);
+void brelse(struct buf *);
+#define bremfree bufcache_take
+void bufinit(void);
+void buf_dirty(struct buf *);
+void buf_undirty(struct buf *);
+void buf_adjcnt(struct buf *, long);
+int bwrite(struct buf *);
+struct buf *getblk(struct vnode *, daddr_t, int, int, uint64_t);
+struct buf *geteblk(size_t);
+struct buf *incore(struct vnode *, daddr_t);
+
+/*
+ * bufcache functions
+ */
+void bufcache_take(struct buf *);
+void bufcache_release(struct buf *);
+
+int buf_flip_high(struct buf *);
+void buf_flip_dma(struct buf *);
+struct buf *bufcache_getcleanbuf(int, int);
+struct buf *bufcache_getanycleanbuf(void);
+struct buf *bufcache_getdirtybuf(void);
+
+/*
+ * buf_kvm_init initializes the kvm handling for buffers.
+ * buf_acquire sets the B_BUSY flag and ensures that the buffer is
+ * mapped in the kvm.
+ * buf_release clears the B_BUSY flag and allows the buffer to become
+ * unmapped.
+ * buf_unmap is for internal use only. Unmaps the buffer from kvm.
+ */
+void buf_mem_init(vsize_t);
+void buf_acquire(struct buf *);
+void buf_acquire_unmapped(struct buf *);
+void buf_acquire_nomap(struct buf *);
+void buf_map(struct buf *);
+void buf_release(struct buf *);
+int buf_dealloc_mem(struct buf *);
+void buf_fix_mapping(struct buf *, vsize_t);
+void buf_alloc_pages(struct buf *, vsize_t);
+void buf_free_pages(struct buf *);
+
+void minphys(struct buf *bp);
+int physio(void (*strategy)(struct buf *), dev_t dev, int flags,
+ void (*minphys)(struct buf *), struct uio *uio);
+void brelvp(struct buf *);
+void reassignbuf(struct buf *);
+void bgetvp(struct vnode *, struct buf *);
+
+void buf_replacevnode(struct buf *, struct vnode *);
+void buf_daemon(void *);
+void buf_replacevnode(struct buf *, struct vnode *);
+int bread_cluster(struct vnode *, daddr_t, int, struct buf **);
+
+#ifdef DEBUG
+void buf_print(struct buf *);
+#endif
+
+static __inline void
+buf_start(struct buf *bp)
+{
+ if (bioops.io_start)
+ (*bioops.io_start)(bp);
+}
+
+static __inline void
+buf_complete(struct buf *bp)
+{
+ if (bioops.io_complete)
+ (*bioops.io_complete)(bp);
+}
+
+static __inline void
+buf_deallocate(struct buf *bp)
+{
+ if (bioops.io_deallocate)
+ (*bioops.io_deallocate)(bp);
+}
+
+static __inline void
+buf_movedeps(struct buf *bp, struct buf *bp2)
+{
+ if (bioops.io_movedeps)
+ (*bioops.io_movedeps)(bp, bp2);
+}
+
+static __inline int
+buf_countdeps(struct buf *bp, int i, int islocked)
+{
+ if (bioops.io_countdeps)
+ return ((*bioops.io_countdeps)(bp, i, islocked));
+ else
+ return (0);
+}
+
+void cluster_write(struct buf *, struct cluster_info *, u_quad_t);
+
+__END_DECLS
+#endif /* _KERNEL */
+#endif /* !_SYS_BUF_H_ */
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
new file mode 100644
index 0000000..ce9b811
--- /dev/null
+++ b/sys/sys/cdefs.h
@@ -0,0 +1,413 @@
+/* $OpenBSD: cdefs.h,v 1.43 2018/10/29 17:10:40 guenther Exp $ */
+/* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos 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.7 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_CDEFS_H_
+#define _SYS_CDEFS_H_
+
+#include <machine/cdefs.h>
+
+/*
+ * Macro to test if we're using a specific version of gcc or later.
+ */
+#ifdef __GNUC__
+#define __GNUC_PREREQ__(ma, mi) \
+ ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
+#else
+#define __GNUC_PREREQ__(ma, mi) 0
+#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. Do not use __CONCAT on double-quoted strings,
+ * such as those from the __STRING macro: to concatenate strings just put
+ * them next to each other.
+ */
+#if defined(__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++ keyword */
+#else
+#if !defined(__GNUC__)
+#define __inline /* delete GCC keyword */
+#endif /* !__GNUC__ */
+#endif /* !__cplusplus */
+
+#else /* !(__STDC__ || __cplusplus) */
+#define __P(protos) () /* traditional C preprocessor */
+#define __CONCAT(x,y) x/**/y
+#define __STRING(x) "x"
+
+#if !defined(__GNUC__)
+#define __const /* delete pseudo-ANSI C keywords */
+#define __inline
+#define __signed
+#define __volatile
+#endif /* !__GNUC__ */
+#endif /* !(__STDC__ || __cplusplus) */
+
+/*
+ * 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".
+ * GCC >= 2.5 uses the __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).
+ */
+
+#if !__GNUC_PREREQ__(2, 5) && !defined(__PCC__)
+#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#define __dead __volatile
+#define __pure __const
+#endif
+#else
+#define __dead __attribute__((__noreturn__))
+#define __pure __attribute__((__const__))
+#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 /* suppress -Wunused warnings */
+#endif
+
+#if __GNUC_PREREQ__(3,4)
+# define __warn_unused_result __attribute__((__warn_unused_result__))
+#else
+# define __warn_unused_result /* delete */
+#endif
+
+#if __GNUC_PREREQ__(3,3) && !defined(__clang__)
+# define __bounded(args) __attribute__ ((__bounded__ args ))
+#else
+# define __bounded(args) /* delete */
+#endif
+
+/*
+ * __returns_twice makes the compiler not assume the function
+ * only returns once. This affects registerisation of variables:
+ * even local variables need to be in memory across such a call.
+ * Example: setjmp()
+ */
+#if __GNUC_PREREQ__(4, 1)
+#define __returns_twice __attribute__((returns_twice))
+#else
+#define __returns_twice
+#endif
+
+/*
+ * __only_inline makes the compiler only use this function definition
+ * for inlining; references that can't be inlined will be left as
+ * external references instead of generating a local copy. The
+ * matching library should include a simple extern definition for
+ * the function to handle those references. c.f. ctype.h
+ */
+#ifdef __GNUC__
+# if __GNUC_PREREQ__(4, 2)
+#define __only_inline extern __inline __attribute__((__gnu_inline__))
+# else
+#define __only_inline extern __inline
+# endif
+#else
+#define __only_inline static __inline
+#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 utilize 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) != 0)
+#define __predict_false(exp) ((exp) != 0)
+#endif
+
+/* Delete pseudo-keywords wherever they are not available or needed. */
+#ifndef __dead
+#define __dead
+#define __pure
+#endif
+
+/*
+ * The __packed macro indicates that a variable or structure members
+ * should have the smallest possible alignment, despite any host CPU
+ * alignment requirements.
+ *
+ * The __aligned(x) macro specifies the minimum alignment of a
+ * variable or structure.
+ *
+ * These macros together are useful for describing the layout and
+ * alignment of messages exchanged with hardware or other systems.
+ */
+
+#if __GNUC_PREREQ__(2, 7) || defined(__PCC__)
+#define __packed __attribute__((__packed__))
+#define __aligned(x) __attribute__((__aligned__(x)))
+#endif
+
+#if !__GNUC_PREREQ__(2, 8)
+#define __extension__
+#endif
+
+#if __GNUC_PREREQ__(3, 0)
+#define __malloc __attribute__((__malloc__))
+#else
+#define __malloc
+#endif
+
+#if defined(__cplusplus)
+#define __BEGIN_EXTERN_C extern "C" {
+#define __END_EXTERN_C }
+#else
+#define __BEGIN_EXTERN_C
+#define __END_EXTERN_C
+#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_EXTERN_C
+#define __END_DECLS __END_EXTERN_C
+
+/*
+ * "The nice thing about standards is that there are so many to choose from."
+ * There are a number of "feature test macros" specified by (different)
+ * standards that determine which interfaces and types the header files
+ * should expose.
+ *
+ * Because of inconsistencies in these macros, we define our own
+ * set in the private name space that end in _VISIBLE. These are
+ * always defined and so headers can test their values easily.
+ * Things can get tricky when multiple feature macros are defined.
+ * We try to take the union of all the features requested.
+ *
+ * The following macros are guaranteed to have a value after cdefs.h
+ * has been included:
+ * __POSIX_VISIBLE
+ * __XPG_VISIBLE
+ * __ISO_C_VISIBLE
+ * __BSD_VISIBLE
+ */
+
+/*
+ * X/Open Portability Guides and Single Unix Specifications.
+ * _XOPEN_SOURCE XPG3
+ * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
+ * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
+ * _XOPEN_SOURCE == 500 XPG5
+ * _XOPEN_SOURCE == 520 XPG5v2
+ * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI
+ * _XOPEN_SOURCE == 700 POSIX 1003.1-2008 with XSI
+ *
+ * The XPG spec implies a specific value for _POSIX_C_SOURCE.
+ */
+#ifdef _XOPEN_SOURCE
+# if (_XOPEN_SOURCE - 0 >= 700)
+# define __XPG_VISIBLE 700
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200809L
+# elif (_XOPEN_SOURCE - 0 >= 600)
+# define __XPG_VISIBLE 600
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200112L
+# elif (_XOPEN_SOURCE - 0 >= 520)
+# define __XPG_VISIBLE 520
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# elif (_XOPEN_SOURCE - 0 >= 500)
+# define __XPG_VISIBLE 500
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# elif (_XOPEN_SOURCE_EXTENDED - 0 == 1)
+# define __XPG_VISIBLE 420
+# elif (_XOPEN_VERSION - 0 >= 4)
+# define __XPG_VISIBLE 400
+# else
+# define __XPG_VISIBLE 300
+# endif
+#endif
+
+/*
+ * POSIX macros, these checks must follow the XOPEN ones above.
+ *
+ * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE)
+ * _POSIX_C_SOURCE == 1 1003.1-1990
+ * _POSIX_C_SOURCE == 2 1003.2-1992
+ * _POSIX_C_SOURCE == 199309L 1003.1b-1993
+ * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
+ * and the omnibus ISO/IEC 9945-1:1996
+ * _POSIX_C_SOURCE == 200112L 1003.1-2001
+ * _POSIX_C_SOURCE == 200809L 1003.1-2008
+ *
+ * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though
+ * this may be overridden by the _ISOC99_SOURCE macro later.
+ */
+#ifdef _POSIX_C_SOURCE
+# if (_POSIX_C_SOURCE - 0 >= 200809)
+# define __POSIX_VISIBLE 200809
+# define __ISO_C_VISIBLE 1999
+# elif (_POSIX_C_SOURCE - 0 >= 200112)
+# define __POSIX_VISIBLE 200112
+# define __ISO_C_VISIBLE 1999
+# elif (_POSIX_C_SOURCE - 0 >= 199506)
+# define __POSIX_VISIBLE 199506
+# define __ISO_C_VISIBLE 1990
+# elif (_POSIX_C_SOURCE - 0 >= 199309)
+# define __POSIX_VISIBLE 199309
+# define __ISO_C_VISIBLE 1990
+# elif (_POSIX_C_SOURCE - 0 >= 2)
+# define __POSIX_VISIBLE 199209
+# define __ISO_C_VISIBLE 1990
+# else
+# define __POSIX_VISIBLE 199009
+# define __ISO_C_VISIBLE 1990
+# endif
+#elif defined(_POSIX_SOURCE)
+# define __POSIX_VISIBLE 198808
+# define __ISO_C_VISIBLE 0
+#endif
+
+/*
+ * _ANSI_SOURCE means to expose ANSI C89 interfaces only.
+ * If the user defines it in addition to one of the POSIX or XOPEN
+ * macros, assume the POSIX/XOPEN macro(s) should take precedence.
+ */
+#if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \
+ !defined(__XPG_VISIBLE)
+# define __POSIX_VISIBLE 0
+# define __XPG_VISIBLE 0
+# define __ISO_C_VISIBLE 1990
+#endif
+
+/*
+ * _ISOC99_SOURCE, _ISOC11_SOURCE, __STDC_VERSION__, and __cplusplus
+ * override any of the other macros since they are non-exclusive.
+ */
+#if defined(_ISOC11_SOURCE) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112) || \
+ (defined(__cplusplus) && __cplusplus >= 201703)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 2011
+#elif defined(_ISOC99_SOURCE) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
+ (defined(__cplusplus) && __cplusplus >= 201103)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 1999
+#endif
+
+/*
+ * Finally deal with BSD-specific interfaces that are not covered
+ * by any standards. We expose these when none of the POSIX or XPG
+ * macros is defined or if the user explicitly asks for them.
+ */
+#if !defined(_BSD_SOURCE) && \
+ (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
+# define __BSD_VISIBLE 0
+#endif
+
+/*
+ * Default values.
+ */
+#ifndef __XPG_VISIBLE
+# define __XPG_VISIBLE 700
+#endif
+#ifndef __POSIX_VISIBLE
+# define __POSIX_VISIBLE 200809
+#endif
+#ifndef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 2011
+#endif
+#ifndef __BSD_VISIBLE
+# define __BSD_VISIBLE 1
+#endif
+
+#endif /* !_SYS_CDEFS_H_ */
diff --git a/sys/sys/cdio.h b/sys/sys/cdio.h
new file mode 100644
index 0000000..02069c4
--- /dev/null
+++ b/sys/sys/cdio.h
@@ -0,0 +1,435 @@
+/* $OpenBSD: cdio.h,v 1.17 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: cdio.h,v 1.11 1996/02/19 18:29:04 scottr Exp $ */
+
+#ifndef _SYS_CDIO_H_
+#define _SYS_CDIO_H_
+
+#include <sys/types.h>
+#include <sys/ioccom.h>
+
+/* Shared between kernel & process */
+
+union msf_lba {
+ struct {
+ u_char unused;
+ u_char minute;
+ u_char second;
+ u_char frame;
+ } msf;
+ u_int32_t lba;
+ u_char addr[4];
+};
+
+struct cd_toc_entry {
+ u_char nothing1;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track;
+ u_char nothing2;
+ union msf_lba addr;
+};
+
+struct cd_sub_channel_header {
+ u_char nothing1;
+ u_char audio_status;
+#define CD_AS_AUDIO_INVALID 0x00
+#define CD_AS_PLAY_IN_PROGRESS 0x11
+#define CD_AS_PLAY_PAUSED 0x12
+#define CD_AS_PLAY_COMPLETED 0x13
+#define CD_AS_PLAY_ERROR 0x14
+#define CD_AS_NO_STATUS 0x15
+ u_char data_len[2];
+};
+
+struct cd_sub_channel_q_data {
+ u_char data_format;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track_number;
+ u_char index_number;
+ u_char absaddr[4];
+ u_char reladdr[4];
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int mc_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int mc_valid:1;
+ u_int :7;
+#endif
+ u_char mc_number[15];
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int ti_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int ti_valid:1;
+ u_int :7;
+#endif
+ u_char ti_number[15];
+};
+
+struct cd_sub_channel_position_data {
+ u_char data_format;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track_number;
+ u_char index_number;
+ union msf_lba absaddr;
+ union msf_lba reladdr;
+};
+
+struct cd_sub_channel_media_catalog {
+ u_char data_format;
+ u_char nothing1;
+ u_char nothing2;
+ u_char nothing3;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int mc_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int mc_valid:1;
+ u_int :7;
+#endif
+ u_char mc_number[15];
+};
+
+struct cd_sub_channel_track_info {
+ u_char data_format;
+ u_char nothing1;
+ u_char track_number;
+ u_char nothing2;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int ti_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int ti_valid:1;
+ u_int :7;
+#endif
+ u_char ti_number[15];
+};
+
+struct cd_sub_channel_info {
+ struct cd_sub_channel_header header;
+ union {
+ struct cd_sub_channel_q_data q_data;
+ struct cd_sub_channel_position_data position;
+ struct cd_sub_channel_media_catalog media_catalog;
+ struct cd_sub_channel_track_info track_info;
+ } what;
+};
+
+/*
+ * Ioctls for the CD drive
+ */
+struct ioc_play_track {
+ u_char start_track;
+ u_char start_index;
+ u_char end_track;
+ u_char end_index;
+};
+
+#define CDIOCPLAYTRACKS _IOW('c', 1, struct ioc_play_track)
+struct ioc_play_blocks {
+ int blk;
+ int len;
+};
+#define CDIOCPLAYBLOCKS _IOW('c', 2, struct ioc_play_blocks)
+
+struct ioc_read_subchannel {
+ u_char address_format;
+#define CD_LBA_FORMAT 1
+#define CD_MSF_FORMAT 2
+ u_char data_format;
+#define CD_SUBQ_DATA 0
+#define CD_CURRENT_POSITION 1
+#define CD_MEDIA_CATALOG 2
+#define CD_TRACK_INFO 3
+ u_char track;
+ int data_len;
+ struct cd_sub_channel_info *data;
+};
+#define CDIOCREADSUBCHANNEL _IOWR('c', 3, struct ioc_read_subchannel)
+
+struct ioc_toc_header {
+ u_short len;
+ u_char starting_track;
+ u_char ending_track;
+};
+
+#define CDIOREADTOCHEADER _IOR('c', 4, struct ioc_toc_header)
+
+struct ioc_read_toc_entry {
+ u_char address_format;
+ u_char starting_track;
+#define CD_TRACK_LEADOUT 0xaa
+ u_short data_len;
+ struct cd_toc_entry *data;
+};
+#define CDIOREADTOCENTRIES _IOWR('c', 5, struct ioc_read_toc_entry)
+#define CDIOREADTOCENTRYS CDIOREADTOCENTRIES
+
+/* read LBA start of a given session; 0=last, others not yet supported */
+#define CDIOREADMSADDR _IOWR('c', 6, int)
+
+struct ioc_patch {
+ u_char patch[4]; /* one for each channel */
+};
+#define CDIOCSETPATCH _IOW('c', 9, struct ioc_patch)
+
+struct ioc_vol {
+ u_char vol[4]; /* one for each channel */
+};
+#define CDIOCGETVOL _IOR('c', 10, struct ioc_vol)
+#define CDIOCSETVOL _IOW('c', 11, struct ioc_vol)
+#define CDIOCSETMONO _IO('c', 12)
+#define CDIOCSETSTEREO _IO('c', 13)
+#define CDIOCSETMUTE _IO('c', 14)
+#define CDIOCSETLEFT _IO('c', 15)
+#define CDIOCSETRIGHT _IO('c', 16)
+#define CDIOCSETDEBUG _IO('c', 17)
+#define CDIOCCLRDEBUG _IO('c', 18)
+#define CDIOCPAUSE _IO('c', 19)
+#define CDIOCRESUME _IO('c', 20)
+#define CDIOCRESET _IO('c', 21)
+#define CDIOCSTART _IO('c', 22)
+#define CDIOCSTOP _IO('c', 23)
+#define CDIOCEJECT _IO('c', 24)
+#define CDIOCALLOW _IO('c', 25)
+#define CDIOCPREVENT _IO('c', 26)
+#define CDIOCCLOSE _IO('c', 27)
+
+struct ioc_play_msf {
+ u_char start_m;
+ u_char start_s;
+ u_char start_f;
+ u_char end_m;
+ u_char end_s;
+ u_char end_f;
+};
+#define CDIOCPLAYMSF _IOW('c', 25, struct ioc_play_msf)
+
+struct ioc_load_unload {
+ u_char options;
+#define CD_LU_ABORT 0x1 /* NOTE: These are the same as the ATAPI */
+#define CD_LU_UNLOAD 0x2 /* op values for the LOAD_UNLOAD command */
+#define CD_LU_LOAD 0x3
+ u_char slot;
+};
+#define CDIOCLOADUNLOAD _IOW('c', 26, struct ioc_load_unload)
+
+/* DVD definitions */
+
+/* DVD-ROM Specific ioctls */
+#define DVD_READ_STRUCT _IOWR('d', 0, union dvd_struct)
+#define DVD_WRITE_STRUCT _IOWR('d', 1, union dvd_struct)
+#define DVD_AUTH _IOWR('d', 2, union dvd_authinfo)
+
+#define GPCMD_READ_DVD_STRUCTURE 0xad
+#define GPCMD_SEND_DVD_STRUCTURE 0xad
+#define GPCMD_REPORT_KEY 0xa4
+#define GPCMD_SEND_KEY 0xa3
+
+/* DVD struct types */
+#define DVD_STRUCT_PHYSICAL 0x00
+#define DVD_STRUCT_COPYRIGHT 0x01
+#define DVD_STRUCT_DISCKEY 0x02
+#define DVD_STRUCT_BCA 0x03
+#define DVD_STRUCT_MANUFACT 0x04
+
+struct dvd_layer {
+ u_int8_t book_version;
+ u_int8_t book_type;
+ u_int8_t min_rate;
+ u_int8_t disc_size;
+ u_int8_t layer_type;
+ u_int8_t track_path;
+ u_int8_t nlayers;
+ u_int8_t track_density;
+ u_int8_t linear_density;
+ u_int8_t bca;
+ u_int32_t start_sector;
+ u_int32_t end_sector;
+ u_int32_t end_sector_l0;
+};
+
+struct dvd_physical {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ struct dvd_layer layer[4];
+};
+
+struct dvd_copyright {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ u_int8_t cpst;
+ u_int8_t rmi;
+};
+
+struct dvd_disckey {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t value[2048];
+};
+
+struct dvd_bca {
+ u_int8_t type;
+
+ int len;
+ u_int8_t value[188];
+};
+
+struct dvd_manufact {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ int len;
+ u_int8_t value[2048];
+};
+
+union dvd_struct {
+ u_int8_t type;
+
+ struct dvd_physical physical;
+ struct dvd_copyright copyright;
+ struct dvd_disckey disckey;
+ struct dvd_bca bca;
+ struct dvd_manufact manufact;
+};
+
+/*
+ * DVD authentication ioctl
+ */
+
+/* Authentication states */
+#define DVD_LU_SEND_AGID 0
+#define DVD_HOST_SEND_CHALLENGE 1
+#define DVD_LU_SEND_KEY1 2
+#define DVD_LU_SEND_CHALLENGE 3
+#define DVD_HOST_SEND_KEY2 4
+
+/* Termination states */
+#define DVD_AUTH_ESTABLISHED 5
+#define DVD_AUTH_FAILURE 6
+
+/* Other functions */
+#define DVD_LU_SEND_TITLE_KEY 7
+#define DVD_LU_SEND_ASF 8
+#define DVD_INVALIDATE_AGID 9
+#define DVD_LU_SEND_RPC_STATE 10
+#define DVD_HOST_SEND_RPC_STATE 11
+
+#if 0
+/* State data */
+typedef u_int8_t dvd_key[5]; /* 40-bit value, MSB is first elem. */
+typedef u_int8_t dvd_challenge[10]; /* 80-bit value, MSB is first elem. */
+#endif
+
+#define DVD_KEY_SIZE 5
+#define DVD_CHALLENGE_SIZE 10
+
+struct dvd_lu_send_agid {
+ u_int8_t type;
+
+ u_int8_t agid;
+};
+
+struct dvd_host_send_challenge {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t chal[DVD_CHALLENGE_SIZE];
+};
+
+struct dvd_send_key {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t key[DVD_KEY_SIZE];
+};
+
+struct dvd_lu_send_challenge {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t chal[DVD_CHALLENGE_SIZE];
+};
+
+#define DVD_CPM_NO_COPYRIGHT 0
+#define DVD_CPM_COPYRIGHTED 1
+
+#define DVD_CP_SEC_NONE 0
+#define DVD_CP_SEC_EXIST 1
+
+#define DVD_CGMS_UNRESTRICTED 0
+#define DVD_CGMS_SINGLE 2
+#define DVD_CGMS_RESTRICTED 3
+
+struct dvd_lu_send_title_key {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t title_key[DVD_KEY_SIZE];
+ int lba;
+ u_int8_t cpm;
+ u_int8_t cp_sec;
+ u_int8_t cgms;
+};
+
+struct dvd_lu_send_asf {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t asf;
+};
+
+struct dvd_host_send_rpcstate {
+ u_int8_t type;
+ u_int8_t pdrc;
+};
+
+struct dvd_lu_send_rpcstate {
+ u_int8_t type;
+ u_int8_t vra;
+ u_int8_t ucca;
+ u_int8_t region_mask;
+ u_int8_t rpc_scheme;
+ };
+
+union dvd_authinfo {
+ u_int8_t type;
+
+ struct dvd_lu_send_agid lsa;
+ struct dvd_host_send_challenge hsc;
+ struct dvd_send_key lsk;
+ struct dvd_lu_send_challenge lsc;
+ struct dvd_send_key hsk;
+ struct dvd_lu_send_title_key lstk;
+ struct dvd_lu_send_asf lsasf;
+ struct dvd_host_send_rpcstate hrpcs;
+ struct dvd_lu_send_rpcstate lrpcs;
+};
+#endif /* !_SYS_CDIO_H_ */
diff --git a/sys/sys/chio.h b/sys/sys/chio.h
new file mode 100644
index 0000000..88afaa9
--- /dev/null
+++ b/sys/sys/chio.h
@@ -0,0 +1,176 @@
+/* $OpenBSD: chio.h,v 1.7 2006/05/31 03:01:44 beck Exp $ */
+/* $NetBSD: chio.h,v 1.8 1996/04/03 00:25:21 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
+ * 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 acknowledgements:
+ * This product includes software developed by Jason R. Thorpe
+ * for And Communications, http://www.and.com/
+ * 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_CHIO_H_
+#define _SYS_CHIO_H_
+
+/*
+ * Element types. Used as "to" and "from" type indicators in move
+ * and exchange operations.
+ *
+ * Note that code in sys/scsi/ch.c relies on these values (uses them
+ * as offsets in an array, and other evil), so don't muck with them
+ * unless you know what you're doing.
+ */
+#define CHET_MT 0 /* medium transport (picker) */
+#define CHET_ST 1 /* storage transport (slot) */
+#define CHET_IE 2 /* import/export (portal) */
+#define CHET_DT 3 /* data transfer (drive) */
+
+/*
+ * Maximum length of a volume identification string
+ */
+#define CH_VOLTAG_MAXLEN 32
+
+/*
+ * Structure used to execute a MOVE MEDIUM command.
+ */
+struct changer_move {
+ int cm_fromtype; /* element type to move from */
+ int cm_fromunit; /* logical unit of from element */
+ int cm_totype; /* element type to move to */
+ int cm_tounit; /* logical unit of to element */
+ int cm_flags; /* misc. flags */
+};
+
+/* cm_flags */
+#define CM_INVERT 0x01 /* invert media */
+
+/*
+ * Structure used to execute an EXCHANGE MEDIUM command. In an
+ * exchange operation, the following steps occur:
+ *
+ * - media from source is moved to first destination.
+ *
+ * - media previously occupying first destination is moved
+ * to the second destination.
+ *
+ * The second destination may or may not be the same as the source.
+ * In the case of a simple exchange, the source and second destination
+ * are the same.
+ */
+struct changer_exchange {
+ int ce_srctype; /* element type of source */
+ int ce_srcunit; /* logical unit of source */
+ int ce_fdsttype; /* element type of first destination */
+ int ce_fdstunit; /* logical unit of first destination */
+ int ce_sdsttype; /* element type of second destination */
+ int ce_sdstunit; /* logical unit of second destination */
+ int ce_flags; /* misc. flags */
+};
+
+/* ce_flags */
+#define CE_INVERT1 0x01 /* invert media 1 */
+#define CE_INVERT2 0x02 /* invert media 2 */
+
+/*
+ * Structure used to execute a POSITION TO ELEMENT command. This
+ * moves the current picker in front of the specified element.
+ */
+struct changer_position {
+ int cp_type; /* element type */
+ int cp_unit; /* logical unit of element */
+ int cp_flags; /* misc. flags */
+};
+
+/* cp_flags */
+#define CP_INVERT 0x01 /* invert picker */
+
+/*
+ * Data returned by CHIOGPARAMS.
+ */
+struct changer_params {
+ int cp_curpicker; /* current picker */
+ int cp_npickers; /* number of pickers */
+ int cp_nslots; /* number of slots */
+ int cp_nportals; /* number of import/export portals */
+ int cp_ndrives; /* number of drives */
+};
+
+struct changer_voltag {
+ u_char cv_volid[CH_VOLTAG_MAXLEN + 1];
+ u_int16_t cv_serial;
+};
+
+struct changer_element_status {
+ int ces_type; /* element type */
+ u_int8_t ces_flags; /* flags */
+ struct changer_voltag ces_pvoltag; /* primary voltag */
+ struct changer_voltag ces_avoltag; /* alternate voltag */
+};
+
+/*
+ * Command used to get element status.
+ */
+struct changer_element_status_request {
+ int cesr_type; /* element type */
+ int cesr_flags;
+#define CESR_VOLTAGS 0x01
+
+ struct changer_element_status *cesr_data; /* pre-allocated data storage */
+};
+
+/*
+ * Data returned by CHIOGSTATUS is an array of flags bytes.
+ * Not all flags have meaning for all element types.
+ */
+#define CESTATUS_FULL 0x01 /* element is full */
+#define CESTATUS_IMPEXP 0x02 /* media deposited by operator */
+#define CESTATUS_EXCEPT 0x04 /* element in abnormal state */
+#define CESTATUS_ACCESS 0x08 /* media accessible by picker */
+#define CESTATUS_EXENAB 0x10 /* element supports exporting */
+#define CESTATUS_INENAB 0x20 /* element supports importing */
+
+#define CESTATUS_PICKER_MASK 0x05 /* flags valid for pickers */
+#define CESTATUS_SLOT_MASK 0x0c /* flags valid for slots */
+#define CESTATUS_PORTAL_MASK 0x3f /* flags valid for portals */
+#define CESTATUS_DRIVE_MASK 0x0c /* flags valid for drives */
+
+#define CESTATUS_BITS \
+ "\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"
+
+/*
+ * XXX we have to renumber this since it chashes w/ the
+ * cdio ioctls, O* interface goes away right after 3.3
+ */
+#define CHIOMOVE _IOW('c', 0x41, struct changer_move)
+#define CHIOEXCHANGE _IOW('c', 0x42, struct changer_exchange)
+#define CHIOPOSITION _IOW('c', 0x43, struct changer_position)
+#define CHIOGPICKER _IOR('c', 0x44, int)
+#define CHIOSPICKER _IOW('c', 0x45, int)
+#define CHIOGPARAMS _IOR('c', 0x46, struct changer_params)
+#define CHIOGSTATUS _IOW('c', 0x48, struct changer_element_status_request)
+
+#endif /* _SYS_CHIO_H_ */
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
new file mode 100644
index 0000000..48470a0
--- /dev/null
+++ b/sys/sys/conf.h
@@ -0,0 +1,633 @@
+/* $OpenBSD: conf.h,v 1.150 2020/04/21 08:29:27 mpi Exp $ */
+/* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * 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.
+ *
+ * @(#)conf.h 8.3 (Berkeley) 1/21/94
+ */
+
+
+#ifndef _SYS_CONF_H_
+#define _SYS_CONF_H_
+
+/*
+ * Definitions of device driver entry switches
+ */
+
+struct buf;
+struct proc;
+struct tty;
+struct uio;
+struct vnode;
+struct knote;
+
+/*
+ * Types for d_type
+ */
+#define D_DISK 1
+#define D_TTY 2
+
+/*
+ * Flags for d_flags
+ */
+#define D_CLONE 0x0001 /* clone upon open */
+
+#ifdef _KERNEL
+
+#define dev_type_open(n) int n(dev_t, int, int, struct proc *)
+#define dev_type_close(n) int n(dev_t, int, int, struct proc *)
+#define dev_type_strategy(n) void n(struct buf *)
+#define dev_type_ioctl(n) \
+ int n(dev_t, u_long, caddr_t, int, struct proc *)
+
+#define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t))
+#define dev_init(c,n,t) \
+ ((c) > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
+
+#endif /* _KERNEL */
+
+/*
+ * Block device switch table
+ */
+struct bdevsw {
+ int (*d_open)(dev_t dev, int oflags, int devtype,
+ struct proc *p);
+ int (*d_close)(dev_t dev, int fflag, int devtype,
+ struct proc *p);
+ void (*d_strategy)(struct buf *bp);
+ int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data,
+ int fflag, struct proc *p);
+ int (*d_dump)(dev_t dev, daddr_t blkno, caddr_t va,
+ size_t size);
+ daddr_t (*d_psize)(dev_t dev);
+ u_int d_type;
+ /* u_int d_flags; */
+};
+
+#ifdef _KERNEL
+
+extern struct bdevsw bdevsw[];
+
+/* bdevsw-specific types */
+#define dev_type_dump(n) int n(dev_t, daddr_t, caddr_t, size_t)
+#define dev_type_size(n) daddr_t n(dev_t)
+
+/* bdevsw-specific initializations */
+#define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0)
+
+#define bdev_decl(n) \
+ dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
+ dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
+
+#define bdev_disk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ dev_init(c,n,strategy), dev_init(c,n,ioctl), \
+ dev_init(c,n,dump), dev_size_init(c,n), D_DISK }
+
+#define bdev_swap_init(c,n) { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ dev_init(c,n,strategy), (dev_type_ioctl((*))) enodev, \
+ (dev_type_dump((*))) enodev, 0 }
+
+#define bdev_notdef() { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ (dev_type_strategy((*))) enodev, (dev_type_ioctl((*))) enodev, \
+ (dev_type_dump((*))) enodev, 0 }
+
+#endif
+
+/*
+ * Character device switch table
+ */
+struct cdevsw {
+ int (*d_open)(dev_t dev, int oflags, int devtype,
+ struct proc *p);
+ int (*d_close)(dev_t dev, int fflag, int devtype,
+ struct proc *);
+ int (*d_read)(dev_t dev, struct uio *uio, int ioflag);
+ int (*d_write)(dev_t dev, struct uio *uio, int ioflag);
+ int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data,
+ int fflag, struct proc *p);
+ int (*d_stop)(struct tty *tp, int rw);
+ struct tty *
+ (*d_tty)(dev_t dev);
+ int (*d_poll)(dev_t dev, int events, struct proc *p);
+ paddr_t (*d_mmap)(dev_t, off_t, int);
+ u_int d_type;
+ u_int d_flags;
+ int (*d_kqfilter)(dev_t dev, struct knote *kn);
+};
+
+#ifdef _KERNEL
+
+extern struct cdevsw cdevsw[];
+
+/* cdevsw-specific types */
+#define dev_type_read(n) int n(dev_t, struct uio *, int)
+#define dev_type_write(n) int n(dev_t, struct uio *, int)
+#define dev_type_stop(n) int n(struct tty *, int)
+#define dev_type_tty(n) struct tty *n(dev_t)
+#define dev_type_poll(n) int n(dev_t, int, struct proc *)
+#define dev_type_mmap(n) paddr_t n(dev_t, off_t, int)
+#define dev_type_kqfilter(n) int n(dev_t, struct knote *)
+
+#define cdev_decl(n) \
+ dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
+ dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \
+ dev_decl(n,tty); dev_decl(n,poll); dev_decl(n,mmap); \
+ dev_decl(n,kqfilter)
+
+/* open, close, read, write, ioctl */
+#define cdev_disk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ D_DISK, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl */
+#define cdev_tape_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, stop, tty */
+#define cdev_tty_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ dev_init(c,n,tty), ttpoll, (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, ttkqfilter }
+
+/* open, close, read, ioctl, poll, kqfilter */
+#define cdev_mouse_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev , 0, 0, dev_init(c,n,kqfilter) }
+
+#define cdev_notdef() { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be a tty */
+#define cdev_cn_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, read, write, ioctl, poll, kqfilter -- XXX should be a tty */
+#define cdev_ctty_init(c,n) { \
+ dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, mmap */
+#define cdev_mm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, seltrue, dev_init(c,n,mmap), \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, tty, poll, kqfilter */
+#define cdev_ptc_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
+ dev_init(c,n,tty), dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, mmap */
+#define cdev_ptm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, ioctl, poll, kqfilter XXX should be a generic device */
+#define cdev_log_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open */
+#define cdev_fd_init(c,n) { \
+ dev_init(c,n,open), (dev_type_close((*))) enodev, \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
+ 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_tun_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_switch_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_vscsi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_pppx_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter, cloning -- XXX should be generic device */
+#define cdev_bpf_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_ch_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_uk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl, mmap */
+#define cdev_fb_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ dev_init(c,n,mmap) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_audio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_midi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read */
+#define cdev_ksyms_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, seltrue, \
+ (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, stop, tty, poll, mmap, kqfilter */
+#define cdev_wsdisplay_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ dev_init(c,n,tty), dev_init(c,n,poll), dev_init(c,n,mmap), \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_random_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl, poll, nokqfilter */
+#define cdev_usb_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, write */
+#define cdev_ulpt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_pf_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_usbdev_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, 0, 0, \
+ dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_fido_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,uhid,close), dev_init(c,uhid,read), \
+ dev_init(c,uhid,write), dev_init(c,fido,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,uhid,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) }
+
+/* open, close, init */
+#define cdev_pci_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_radio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl, read, mmap, poll */
+#define cdev_video_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ dev_init(c,n,mmap) }
+
+/* open, close, write, ioctl */
+#define cdev_spkr_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, write */
+#define cdev_lpt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, ioctl, mmap */
+#define cdev_bktr_init(c, n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, seltrue, dev_init(c,n,mmap), \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, ioctl, poll, kqfilter */
+#define cdev_hotplug_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_gpio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_bio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, ioctl, poll, mmap, nokqfilter */
+#define cdev_drm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c, n, read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ dev_init(c,n,mmap), 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_amdmsr_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, poll, ioctl */
+#define cdev_fuse_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_pvbus_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, \
+ dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_ipmi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev, 0 }
+
+/* open, close, ioctl, mmap */
+#define cdev_kcov_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_init(c,n,mmap)), 0, D_CLONE }
+
+/* open, close, read, ioctl */
+#define cdev_dt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev, 0, D_CLONE }
+
+#endif
+
+/*
+ * Line discipline switch table
+ */
+struct linesw {
+ int (*l_open)(dev_t dev, struct tty *tp, struct proc *p);
+ int (*l_close)(struct tty *tp, int flags, struct proc *p);
+ int (*l_read)(struct tty *tp, struct uio *uio,
+ int flag);
+ int (*l_write)(struct tty *tp, struct uio *uio,
+ int flag);
+ int (*l_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
+ int flag, struct proc *p);
+ int (*l_rint)(int c, struct tty *tp);
+ int (*l_start)(struct tty *tp);
+ int (*l_modem)(struct tty *tp, int flag);
+};
+
+#ifdef _KERNEL
+extern struct linesw linesw[];
+#endif
+
+/*
+ * Swap device table
+ */
+struct swdevt {
+ dev_t sw_dev;
+ int sw_flags;
+};
+#define SW_FREED 0x01
+#define SW_SEQUENTIAL 0x02
+#define sw_freed sw_flags /* XXX compat */
+
+#ifdef _KERNEL
+extern struct swdevt swdevt[];
+extern int chrtoblktbl[];
+extern int nchrtoblktbl;
+
+struct bdevsw *bdevsw_lookup(dev_t);
+struct cdevsw *cdevsw_lookup(dev_t);
+dev_t chrtoblk(dev_t);
+dev_t blktochr(dev_t);
+int iskmemdev(dev_t);
+int iszerodev(dev_t);
+dev_t getnulldev(void);
+
+cdev_decl(filedesc);
+
+cdev_decl(log);
+
+#define ptstty ptytty
+#define ptsioctl ptyioctl
+cdev_decl(pts);
+
+#define ptctty ptytty
+#define ptcioctl ptyioctl
+cdev_decl(ptc);
+
+cdev_decl(ptm);
+
+cdev_decl(ctty);
+
+cdev_decl(audio);
+cdev_decl(drm);
+cdev_decl(midi);
+cdev_decl(radio);
+cdev_decl(video);
+cdev_decl(cn);
+
+bdev_decl(sw);
+
+bdev_decl(vnd);
+cdev_decl(vnd);
+
+cdev_decl(ch);
+
+bdev_decl(sd);
+cdev_decl(sd);
+
+cdev_decl(ses);
+
+cdev_decl(st);
+
+bdev_decl(cd);
+cdev_decl(cd);
+
+bdev_decl(rd);
+cdev_decl(rd);
+
+bdev_decl(uk);
+cdev_decl(uk);
+
+cdev_decl(dt);
+
+cdev_decl(diskmap);
+
+cdev_decl(bpf);
+
+cdev_decl(pf);
+
+cdev_decl(tun);
+cdev_decl(tap);
+cdev_decl(switch);
+cdev_decl(pppx);
+cdev_decl(pppac);
+
+cdev_decl(random);
+
+cdev_decl(wsdisplay);
+cdev_decl(wskbd);
+cdev_decl(wsmouse);
+cdev_decl(wsmux);
+
+cdev_decl(ksyms);
+
+cdev_decl(bio);
+cdev_decl(vscsi);
+
+cdev_decl(gpr);
+cdev_decl(bktr);
+
+cdev_decl(usb);
+cdev_decl(ugen);
+cdev_decl(uhid);
+cdev_decl(fido);
+cdev_decl(ucom);
+cdev_decl(ulpt);
+cdev_decl(urio);
+
+cdev_decl(hotplug);
+cdev_decl(gpio);
+cdev_decl(amdmsr);
+cdev_decl(fuse);
+cdev_decl(pvbus);
+cdev_decl(ipmi);
+cdev_decl(kcov);
+
+#endif
+
+#endif /* _SYS_CONF_H_ */
diff --git a/sys/sys/core.h b/sys/sys/core.h
new file mode 100644
index 0000000..cd69b41
--- /dev/null
+++ b/sys/sys/core.h
@@ -0,0 +1,99 @@
+/* $OpenBSD: core.h,v 1.7 2016/09/17 06:09:08 guenther Exp $ */
+/* $NetBSD: core.h,v 1.4 1994/10/29 08:20:14 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994 Paul Kranenburg
+ * 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 Paul Kranenburg.
+ * 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.
+ */
+
+#define COREMAGIC 0507
+#define CORESEGMAGIC 0510
+
+/*
+ * The core structure's c_midmag field (like exec's a_midmag) is a
+ * network-byteorder encoding of this int
+ * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
+ * Where `F' is 6 bits of flag (currently unused),
+ * `m' is 10 bits of machine-id, and
+ * `M' is 16 bits worth of magic number, ie. COREMAGIC.
+ * The macros below will set/get the needed fields.
+ */
+#define CORE_GETMAGIC(c) ( ntohl(((c).c_midmag)) & 0xffff )
+#define CORE_GETMID(c) ( (ntohl(((c).c_midmag)) >> 16) & 0x03ff )
+#define CORE_GETFLAG(c) ( (ntohl(((c).c_midmag)) >> 26) & 0x03f )
+#define CORE_SETMAGIC(c,mag,mid,flag) ( (c).c_midmag = htonl ( \
+ ( ((flag) & 0x3f) << 26) | \
+ ( ((mid) & 0x03ff) << 16) | \
+ ( ((mag) & 0xffff) ) ) )
+
+/* Flag definitions */
+#define CORE_CPU 1
+#define CORE_DATA 2
+#define CORE_STACK 4
+
+#ifndef _KERNEL
+/*
+ * XXX OBSOLETE, NO LONGER USED
+ * XXX This header file exists to support binutils' netbsd-core format
+ * XXX which is still needed for the a.out-m88k-openbsd use in luna88k
+ * XXX boot block creation.
+ *
+ * A core file consists of a header followed by a number of segments.
+ * Each segment is preceded by a `coreseg' structure giving the
+ * segment's type, the virtual address where the bits resided in
+ * process address space and the size of the segment.
+ *
+ * The core header specifies the lengths of the core header itself and
+ * each of the following core segment headers to allow for any machine
+ * dependent alignment requirements.
+ */
+
+struct core {
+ u_int32_t c_midmag; /* magic, id, flags */
+ u_int16_t c_hdrsize; /* Size of this header (machdep algn) */
+ u_int16_t c_seghdrsize; /* Size of a segment header */
+ u_int32_t c_nseg; /* # of core segments */
+ char c_name[MAXCOMLEN+1]; /* Copy of p->p_comm */
+ u_int32_t c_signo; /* Killing signal */
+ u_long c_ucode; /* Hmm ? */
+ u_long c_cpusize; /* Size of machine dependent segment */
+ u_long c_tsize; /* Size of traditional text segment */
+ u_long c_dsize; /* Size of traditional data segment */
+ u_long c_ssize; /* Size of traditional stack segment */
+};
+
+struct coreseg {
+ u_int32_t c_midmag; /* magic, id, flags */
+ u_long c_addr; /* Virtual address of segment */
+ u_long c_size; /* Size of this segment */
+};
+
+#else
+int coredump_write(void *, enum uio_seg, const void *, size_t);
+void coredump_unmap(void *, vaddr_t, vaddr_t);
+#endif
diff --git a/sys/sys/ctf.h b/sys/sys/ctf.h
new file mode 100644
index 0000000..ece42df
--- /dev/null
+++ b/sys/sys/ctf.h
@@ -0,0 +1,186 @@
+/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */
+
+/*
+ * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_CTF_H_
+#define _SYS_CTF_H_
+
+/*
+ * CTF ``Compact ANSI-C Type Format'' ABI header file.
+ */
+
+struct ctf_header {
+ uint16_t cth_magic;
+ uint8_t cth_version;
+ uint8_t cth_flags;
+ uint32_t cth_parlabel;
+ uint32_t cth_parname;
+ uint32_t cth_lbloff;
+ uint32_t cth_objtoff;
+ uint32_t cth_funcoff;
+ uint32_t cth_typeoff;
+ uint32_t cth_stroff;
+ uint32_t cth_strlen;
+};
+
+#define CTF_F_COMPRESS (1 << 0) /* zlib compression */
+
+struct ctf_lblent {
+ uint32_t ctl_label;
+ uint32_t ctl_typeidx;
+};
+
+struct ctf_stype {
+ uint32_t cts_name;
+ uint16_t cts_info;
+ union {
+ uint16_t _size;
+ uint16_t _type;
+ } _ST;
+#define cts_size _ST._size
+#define cts_type _ST._type
+};
+
+struct ctf_type {
+ struct ctf_stype _ctt_stype;
+#define ctt_name _ctt_stype.cts_name
+#define ctt_info _ctt_stype.cts_info
+#define ctt_size _ctt_stype.cts_size
+#define ctt_type _ctt_stype.cts_type
+ uint32_t ctt_lsizehi;
+ uint32_t ctt_lsizelo;
+};
+
+struct ctf_array {
+ uint16_t cta_contents;
+ uint16_t cta_index;
+ uint32_t cta_nelems;
+};
+
+struct ctf_member {
+ uint32_t ctm_name;
+ uint16_t ctm_type;
+ uint16_t ctm_offset;
+};
+
+struct ctf_lmember {
+ struct ctf_member _ctlm_member;
+#define ctlm_name _ctlm_member.ctm_name
+#define ctlm_type _ctlm_member.ctm_type
+#define ctlm_pad0 _ctlm_member.ctm_offset
+ uint32_t ctlm_offsethi;
+ uint32_t ctlm_offsetlo;
+};
+
+#define CTF_LSTRUCT_THRESH 8192
+
+struct ctf_enum {
+ uint32_t cte_name;
+ int32_t cte_value;
+};
+
+#define CTF_MAGIC 0xcff1
+#define CTF_VERSION 2
+
+#define CTF_MAX_NAME 0x7fffffff
+#define CTF_MAX_VLEN 0x03ff
+#define CTF_MAX_SIZE 0xfffe
+#define CTF_LSIZE_SENT CTF_MAX_SIZE+1 /* sentinel for cts vs ctt */
+
+#define CTF_STRTAB_0 0
+#define CTF_STRTAB_1 1
+
+/*
+ * Info macro.
+ */
+#define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN))
+#define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
+#define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11)
+#define CTF_K_UNKNOWN 0
+#define CTF_K_INTEGER 1
+#define CTF_K_FLOAT 2
+#define CTF_K_POINTER 3
+#define CTF_K_ARRAY 4
+#define CTF_K_FUNCTION 5
+#define CTF_K_STRUCT 6
+#define CTF_K_UNION 7
+#define CTF_K_ENUM 8
+#define CTF_K_FORWARD 9
+#define CTF_K_TYPEDEF 10
+#define CTF_K_VOLATILE 11
+#define CTF_K_CONST 12
+#define CTF_K_RESTRICT 13
+#define CTF_K_MAX 31
+
+/*
+ * Integer/Float Encoding macro.
+ */
+#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
+#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
+#define _CTF_BITS(e) (((e) & 0x0000ffff))
+#define _CTF_DATA(encoding, offset, bits) \
+ (((encoding) << 24) | ((offset) << 16) | (bits))
+
+#define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
+#define CTF_INT_SIGNED (1 << 0)
+#define CTF_INT_CHAR (1 << 1)
+#define CTF_INT_BOOL (1 << 2)
+#define CTF_INT_VARARGS (1 << 3)
+#define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
+#define CTF_INT_BITS(e) _CTF_BITS(e)
+#define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
+
+#define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
+#define CTF_FP_SINGLE 1
+#define CTF_FP_DOUBLE 2
+#define CTF_FP_CPLX 3
+#define CTF_FP_DCPLX 4
+#define CTF_FP_LDCPLX 5
+#define CTF_FP_LDOUBLE 6
+#define CTF_FP_INTRVL 7
+#define CTF_FP_DINTRVL 8
+#define CTF_FP_LDINTRVL 9
+#define CTF_FP_IMAGRY 10
+#define CTF_FP_DIMAGRY 11
+#define CTF_FP_LDIMAGRY 12
+#define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
+#define CTF_FP_BITS(e) _CTF_BITS(e)
+#define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
+
+/*
+ * Name reference macro.
+ */
+#define CTF_NAME_STID(n) ((n) >> 31)
+#define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
+
+/*
+ * Type macro.
+ */
+#define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
+#define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
+#define CTF_TYPE_LSIZE(t) \
+ (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
+
+/*
+ * Member macro.
+ */
+#define CTF_LMEM_OFFSET(m) \
+ (((uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
+#define CTF_OFFSET_TO_LMEMHI(off) ((uint32_t)((uint64_t)(off) >> 32))
+#define CTF_OFFSET_TO_LMEMLO(off) ((uint32_t)(off))
+
+#endif /* _SYS_CTF_H_ */
diff --git a/sys/sys/device.h b/sys/sys/device.h
new file mode 100644
index 0000000..1faa019
--- /dev/null
+++ b/sys/sys/device.h
@@ -0,0 +1,224 @@
+/* $OpenBSD: device.h,v 1.55 2018/09/10 16:18:34 sashan Exp $ */
+/* $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd 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.
+ *
+ * @(#)device.h 8.2 (Berkeley) 2/17/94
+ */
+
+#ifndef _SYS_DEVICE_H_
+#define _SYS_DEVICE_H_
+
+#include <sys/queue.h>
+
+/*
+ * Minimal device structures.
+ * Note that all ``system'' device types are listed here.
+ */
+enum devclass {
+ DV_DULL, /* generic, no special info */
+ DV_CPU, /* CPU (carries resource utilization) */
+ DV_DISK, /* disk drive (label, etc) */
+ DV_IFNET, /* network interface */
+ DV_TAPE, /* tape device */
+ DV_TTY /* serial line interface (???) */
+};
+
+/*
+ * Actions for ca_activate.
+ */
+#define DVACT_DEACTIVATE 1 /* deactivate the device */
+#define DVACT_QUIESCE 2 /* warn the device about suspend */
+#define DVACT_SUSPEND 3 /* suspend the device */
+#define DVACT_RESUME 4 /* resume the device */
+#define DVACT_WAKEUP 5 /* tell device to recover after resume */
+#define DVACT_POWERDOWN 6 /* power device down */
+
+struct device {
+ enum devclass dv_class; /* this device's classification */
+ TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */
+ struct cfdata *dv_cfdata; /* config data that found us */
+ int dv_unit; /* device unit number */
+ char dv_xname[16]; /* external name (name + unit) */
+ struct device *dv_parent; /* pointer to parent device */
+ int dv_flags; /* misc. flags; see below */
+ int dv_ref; /* ref count */
+};
+
+/* dv_flags */
+#define DVF_ACTIVE 0x0001 /* device is activated */
+
+TAILQ_HEAD(devicelist, device);
+
+/*
+ * Configuration data (i.e., data placed in ioconf.c).
+ */
+struct cfdata {
+ struct cfattach *cf_attach; /* config attachment */
+ struct cfdriver *cf_driver; /* config driver */
+ short cf_unit; /* unit number */
+ short cf_fstate; /* finding state (below) */
+ long *cf_loc; /* locators (machine dependent) */
+ int cf_flags; /* flags from config */
+ short *cf_parents; /* potential parents */
+ int cf_locnames; /* start of names */
+ short cf_starunit1; /* 1st usable unit number by STAR */
+};
+extern struct cfdata cfdata[];
+#define FSTATE_NOTFOUND 0 /* has not been found */
+#define FSTATE_FOUND 1 /* has been found */
+#define FSTATE_STAR 2 /* duplicable */
+#define FSTATE_DNOTFOUND 3 /* has not been found, and is disabled */
+#define FSTATE_DSTAR 4 /* duplicable, and is disabled */
+
+typedef int (*cfmatch_t)(struct device *, void *, void *);
+typedef void (*cfscan_t)(struct device *, void *);
+
+/*
+ * `configuration' attachment and driver (what the machine-independent
+ * autoconf uses). As devices are found, they are applied against all
+ * the potential matches. The one with the best match is taken, and a
+ * device structure (plus any other data desired) is allocated. Pointers
+ * to these are placed into an array of pointers. The array itself must
+ * be dynamic since devices can be found long after the machine is up
+ * and running.
+ *
+ * Devices can have multiple configuration attachments if they attach
+ * to different attributes (busses, or whatever), to allow specification
+ * of multiple match and attach functions. There is only one configuration
+ * driver per driver, so that things like unit numbers and the device
+ * structure array will be shared.
+ */
+struct cfattach {
+ size_t ca_devsize; /* size of dev data (for malloc) */
+ cfmatch_t ca_match; /* returns a match level */
+ void (*ca_attach)(struct device *, struct device *, void *);
+ int (*ca_detach)(struct device *, int);
+ int (*ca_activate)(struct device *, int);
+};
+
+/* Flags given to config_detach(), and the ca_detach function. */
+#define DETACH_FORCE 0x01 /* force detachment; hardware gone */
+#define DETACH_QUIET 0x02 /* don't print a notice */
+
+struct cfdriver {
+ void **cd_devs; /* devices found */
+ char *cd_name; /* device name */
+ enum devclass cd_class; /* device classification */
+ int cd_indirect; /* indirectly configure subdevices */
+ int cd_ndevs; /* size of cd_devs array */
+};
+
+/*
+ * Configuration printing functions, and their return codes. The second
+ * argument is NULL if the device was configured; otherwise it is the name
+ * of the parent device. The return value is ignored if the device was
+ * configured, so most functions can return UNCONF unconditionally.
+ */
+typedef int (*cfprint_t)(void *, const char *);
+#define QUIET 0 /* print nothing */
+#define UNCONF 1 /* print " not configured\n" */
+#define UNSUPP 2 /* print " not supported\n" */
+
+/*
+ * Pseudo-device attach information (function + number of pseudo-devs).
+ */
+struct pdevinit {
+ void (*pdev_attach)(int);
+ int pdev_count;
+};
+
+#ifdef _KERNEL
+
+#ifdef DIAGNOSTIC
+extern int pdevinit_done;
+#endif
+
+extern struct devicelist alldevs; /* list of all devices */
+
+extern int autoconf_verbose;
+extern volatile int config_pending; /* semaphore for mountroot */
+
+void config_init(void);
+void *config_search(cfmatch_t, struct device *, void *);
+struct device *config_found_sm(struct device *, void *, cfprint_t,
+ cfmatch_t);
+struct device *config_rootfound(char *, void *);
+void config_scan(cfscan_t, struct device *);
+struct device *config_attach(struct device *, void *, void *, cfprint_t);
+int config_detach(struct device *, int);
+int config_detach_children(struct device *, int);
+int config_deactivate(struct device *);
+int config_suspend(struct device *, int);
+int config_suspend_all(int);
+int config_activate_children(struct device *, int);
+struct device *config_make_softc(struct device *parent,
+ struct cfdata *cf);
+void config_defer(struct device *, void (*)(struct device *));
+void config_pending_incr(void);
+void config_pending_decr(void);
+void config_mountroot(struct device *, void (*)(struct device *));
+void config_process_deferred_mountroot(void);
+
+struct device *device_mainbus(void);
+struct device *device_mpath(void);
+struct device *device_lookup(struct cfdriver *, int unit);
+void device_ref(struct device *);
+void device_unref(struct device *);
+
+struct nam2blk {
+ char *name;
+ int maj;
+};
+
+int findblkmajor(struct device *dv);
+char *findblkname(int);
+void setroot(struct device *, int, int);
+struct device *getdisk(char *str, int len, int defpart, dev_t *devp);
+struct device *parsedisk(char *str, int len, int defpart, dev_t *devp);
+void device_register(struct device *, void *);
+
+int loadfirmware(const char *name, u_char **bufp, size_t *buflen);
+#define FIRMWARE_MAX 5*1024*1024
+
+/* compatibility definitions */
+#define config_found(d, a, p) config_found_sm((d), (a), (p), NULL)
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_DEVICE_H_ */
diff --git a/sys/sys/dir.h b/sys/sys/dir.h
new file mode 100644
index 0000000..60587f0
--- /dev/null
+++ b/sys/sys/dir.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: dir.h,v 1.5 2003/06/02 23:28:21 millert Exp $ */
+/* $NetBSD: dir.h,v 1.9 1996/10/27 19:27:54 gwr Exp $ */
+
+/*
+ * 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.
+ *
+ * @(#)dir.h 8.2 (Berkeley) 1/4/94
+ */
+
+/*
+ * The information in this file should be obtained from <dirent.h>
+ * and is provided solely (and temporarily) for backward compatibility.
+ */
+
+#ifndef _SYS_DIR_H_
+#define _SYS_DIR_H_
+
+#ifdef _KERNEL
+/* This file should only be used by old user-level code. */
+#error "Please use <sys/dirent.h> instead"
+#endif
+
+#include <dirent.h>
+
+/*
+ * Backwards compatibility.
+ */
+#define direct dirent
+
+/*
+ * The DIRSIZ macro gives the minimum record length which will hold
+ * the directory entry. This requires the amount of space in struct direct
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
+ */
+#undef DIRSIZ
+#define DIRSIZ(dp) \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+
+#endif /* !_SYS_DIR_H_ */
diff --git a/sys/sys/dirent.h b/sys/sys/dirent.h
new file mode 100644
index 0000000..09ad39c
--- /dev/null
+++ b/sys/sys/dirent.h
@@ -0,0 +1,100 @@
+/* $OpenBSD: dirent.h,v 1.11 2013/12/13 18:09:27 zhuk Exp $ */
+/* $NetBSD: dirent.h,v 1.12 1996/04/09 20:55:25 cgd 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.
+ *
+ * @(#)dirent.h 8.3 (Berkeley) 8/10/94
+ */
+
+#ifndef _SYS_DIRENT_H_
+#define _SYS_DIRENT_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * The dirent structure defines the format of directory entries returned by
+ * the getdents(2) system call.
+ *
+ * A directory entry has a struct dirent at the front of it, containing its
+ * inode number, the length of the entry, and the length of the name
+ * contained in the entry. These are followed by the name padded to a 4
+ * byte boundary with null bytes. All names are guaranteed null terminated.
+ * The maximum length of a name in a directory is MAXNAMLEN.
+ */
+
+struct dirent {
+ __ino_t d_fileno; /* file number of entry */
+ __off_t d_off; /* offset after this entry */
+ __uint16_t d_reclen; /* length of this record */
+ __uint8_t d_type; /* file type, see below */
+ __uint8_t d_namlen; /* length of string in d_name */
+ __uint8_t __d_padding[4]; /* suppress padding after d_name */
+#if __BSD_VISIBLE
+#define MAXNAMLEN 255
+ char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
+#else
+ char d_name[255 + 1]; /* name must be no longer than this */
+#endif
+};
+
+#if __BSD_VISIBLE
+/*
+ * File types
+ */
+#define DT_UNKNOWN 0
+#define DT_FIFO 1
+#define DT_CHR 2
+#define DT_DIR 4
+#define DT_BLK 6
+#define DT_REG 8
+#define DT_LNK 10
+#define DT_SOCK 12
+
+/*
+ * Convert between stat structure types and directory types.
+ */
+#define IFTODT(mode) (((mode) & 0170000) >> 12)
+#define DTTOIF(dirtype) ((dirtype) << 12)
+
+#ifdef _KERNEL
+/*
+ * The DIRENT_RECSIZE macro gives the minimum record length which will hold
+ * a directory entry with a name of the given length, including the terminating
+ * nul byte, rounded up to proper alignment.
+ * The DIRENT_SIZE macro does the same when given a pointer to a struct dirent
+ */
+#define DIRENT_RECSIZE(namelen) \
+ ((offsetof(struct dirent, d_name) + (namelen) + 1 + 7) &~ 7)
+#define DIRENT_SIZE(dp) \
+ DIRENT_RECSIZE((dp)->d_namlen)
+#endif
+
+#endif /* __BSD_VISIBLE */
+
+#endif /* _SYS_DIRENT_H_ */
diff --git a/sys/sys/disk.h b/sys/sys/disk.h
new file mode 100644
index 0000000..4dcd488
--- /dev/null
+++ b/sys/sys/disk.h
@@ -0,0 +1,160 @@
+/* $OpenBSD: disk.h,v 1.36 2017/05/04 22:47:27 deraadt Exp $ */
+/* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1995 Jason R. Thorpe. All rights reserved.
+ * 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.
+ *
+ * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL)
+ *
+ * @(#)disk.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Disk device structures.
+ */
+
+#include <sys/device.h>
+#include <sys/time.h>
+#include <sys/queue.h>
+#include <sys/rwlock.h>
+#include <sys/mutex.h>
+
+struct buf;
+struct disklabel;
+
+#define DS_DISKNAMELEN 16
+
+struct diskstats {
+ char ds_name[DS_DISKNAMELEN];
+ int ds_busy; /* busy counter */
+ u_int64_t ds_rxfer; /* total number of read transfers */
+ u_int64_t ds_wxfer; /* total number of write transfers */
+ u_int64_t ds_seek; /* total independent seek operations */
+ u_int64_t ds_rbytes; /* total bytes read */
+ u_int64_t ds_wbytes; /* total bytes written */
+ struct timeval ds_attachtime; /* time disk was attached */
+ struct timeval ds_timestamp; /* time of first busy or any unbusy */
+ struct timeval ds_time; /* total time spent busy */
+};
+
+struct disk {
+ TAILQ_ENTRY(disk) dk_link; /* link in global disklist */
+ struct rwlock dk_lock; /* disk lock */
+ struct mutex dk_mtx; /* busy/unbusy mtx */
+ char *dk_name; /* disk name */
+ struct device *dk_device; /* disk device structure. */
+ dev_t dk_devno; /* disk device number. */
+ int dk_flags; /* disk flags */
+#define DKF_CONSTRUCTED 0x0001
+#define DKF_OPENED 0x0002
+#define DKF_NOLABELREAD 0x0004
+#define DKF_LABELVALID 0x0008
+
+ /*
+ * Metrics data; note that some metrics may have no meaning
+ * on certain types of disks.
+ */
+ int dk_busy; /* busy counter */
+ u_int64_t dk_rxfer; /* total number of read transfers */
+ u_int64_t dk_wxfer; /* total number of write transfers */
+ u_int64_t dk_seek; /* total independent seek operations */
+ u_int64_t dk_rbytes; /* total bytes read */
+ u_int64_t dk_wbytes; /* total bytes written */
+ struct timeval dk_attachtime; /* time disk was attached */
+ struct timeval dk_timestamp; /* time of first busy or any unbusy */
+ struct timeval dk_time; /* total time spent busy */
+
+ int dk_bopenmask; /* block devices open */
+ int dk_copenmask; /* character devices open */
+ int dk_openmask; /* composite (bopen|copen) */
+ int dk_state; /* label state ### */
+ int dk_blkshift; /* shift to convert DEV_BSIZE to blks*/
+ int dk_byteshift; /* shift to convert bytes to blks */
+
+ /*
+ * Disk label information. Storage for the in-core disk label
+ * must be dynamically allocated, otherwise the size of this
+ * structure becomes machine-dependent.
+ */
+ struct disklabel *dk_label;
+};
+
+/* states */
+#define DK_CLOSED 0 /* drive is closed */
+#define DK_WANTOPEN 1 /* drive being opened */
+#define DK_WANTOPENRAW 2 /* drive being opened */
+#define DK_RDLABEL 3 /* label being read */
+#define DK_OPEN 4 /* label read, drive open */
+#define DK_OPENRAW 5 /* open without label */
+
+/* Disk map flags. */
+#define DM_OPENPART 0x1 /* Open raw partition. */
+#define DM_OPENBLCK 0x2 /* Open block device. */
+
+/*
+ * disklist_head is defined here so that user-land has access to it.
+ */
+TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */
+
+#ifdef _KERNEL
+extern struct disklist_head disklist; /* list of disks attached to system */
+extern int disk_count; /* number of disks in global disklist */
+extern int disk_change; /* disk attached/detached */
+
+void disk_init(void);
+int disk_construct(struct disk *);
+void disk_attach(struct device *, struct disk *);
+void disk_detach(struct disk *);
+int disk_openpart(struct disk *, int, int, int);
+void disk_closepart(struct disk *, int, int);
+void disk_gone(int (*)(dev_t, int, int, struct proc *), int);
+void disk_busy(struct disk *);
+void disk_unbusy(struct disk *, long, daddr_t, int);
+
+int disk_lock(struct disk *);
+void disk_lock_nointr(struct disk *);
+void disk_unlock(struct disk *);
+struct device *disk_lookup(struct cfdriver *, int);
+
+char *disk_readlabel(struct disklabel *, dev_t, char *, size_t);
+
+int disk_map(char *, char *, int, int);
+
+int duid_iszero(u_char *);
+const char *duid_format(u_char *);
+#endif
diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h
new file mode 100644
index 0000000..70c6cfe
--- /dev/null
+++ b/sys/sys/disklabel.h
@@ -0,0 +1,533 @@
+/* $OpenBSD: disklabel.h,v 1.75 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */
+
+/*
+ * Copyright (c) 1987, 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.
+ *
+ * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
+ */
+
+/*
+ * Disk description table, see disktab(5)
+ */
+#define _PATH_DISKTAB "/etc/disktab"
+#define DISKTAB "/etc/disktab" /* deprecated */
+
+/*
+ * Each disk has a label which includes information about the hardware
+ * disk geometry, filesystem partitions, and drive specific information.
+ * The location of the label, as well as the number of partitions the
+ * label can describe and the number of the "whole disk" (raw)
+ * partition are machine dependent.
+ */
+#include <machine/disklabel.h>
+
+#include <sys/uuid.h>
+
+/*
+ * The absolute maximum number of disk partitions allowed.
+ * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
+ * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
+ */
+#define MAXMAXPARTITIONS 22
+#if MAXPARTITIONS > MAXMAXPARTITIONS
+#warn beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
+#endif
+
+/*
+ * Translate between device numbers and major/disk unit/disk partition.
+ */
+#define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
+#define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
+#define RAW_PART 2 /* 'c' partition */
+#define DISKMINOR(unit, part) \
+ (((unit) * MAXPARTITIONS) + (part))
+#define MAKEDISKDEV(maj, unit, part) \
+ (makedev((maj), DISKMINOR((unit), (part))))
+#define DISKLABELDEV(dev) \
+ (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
+
+#define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
+
+#define MAXDISKSIZE 0x7fffffffffffLL /* 47 bits of reach */
+
+#ifndef _LOCORE
+struct disklabel {
+ u_int32_t d_magic; /* the magic number */
+ u_int16_t d_type; /* drive type */
+ u_int16_t d_subtype; /* controller/d_type specific */
+ char d_typename[16]; /* type name, e.g. "eagle" */
+ char d_packname[16]; /* pack identifier */
+
+ /* disk geometry: */
+ u_int32_t d_secsize; /* # of bytes per sector */
+ u_int32_t d_nsectors; /* # of data sectors per track */
+ u_int32_t d_ntracks; /* # of tracks per cylinder */
+ u_int32_t d_ncylinders; /* # of data cylinders per unit */
+ u_int32_t d_secpercyl; /* # of data sectors per cylinder */
+ u_int32_t d_secperunit; /* # of data sectors (low part) */
+
+ u_char d_uid[8]; /* Unique label identifier. */
+
+ /*
+ * Alternate cylinders include maintenance, replacement, configuration
+ * description areas, etc.
+ */
+ u_int32_t d_acylinders; /* # of alt. cylinders per unit */
+
+ /* hardware characteristics: */
+ u_int16_t d_bstarth; /* start of useable region (high part) */
+ u_int16_t d_bendh; /* size of useable region (high part) */
+ u_int32_t d_bstart; /* start of useable region */
+ u_int32_t d_bend; /* end of useable region */
+ u_int32_t d_flags; /* generic flags */
+#define NDDATA 5
+ u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */
+ u_int16_t d_secperunith; /* # of data sectors (high part) */
+ u_int16_t d_version; /* version # (1=48 bit addressing) */
+#define NSPARE 4
+ u_int32_t d_spare[NSPARE]; /* reserved for future use */
+ u_int32_t d_magic2; /* the magic number (again) */
+ u_int16_t d_checksum; /* xor of data incl. partitions */
+
+ /* filesystem and partition information: */
+ u_int16_t d_npartitions; /* number of partitions in following */
+ u_int32_t d_bbsize; /* size of boot area at sn0, bytes */
+ u_int32_t d_sbsize; /* max size of fs superblock, bytes */
+ struct partition { /* the partition table */
+ u_int32_t p_size; /* number of sectors (low part) */
+ u_int32_t p_offset; /* starting sector (low part) */
+ u_int16_t p_offseth; /* starting sector (high part) */
+ u_int16_t p_sizeh; /* number of sectors (high part) */
+ u_int8_t p_fstype; /* filesystem type, see below */
+ u_int8_t p_fragblock; /* encoded filesystem frag/block */
+ u_int16_t p_cpg; /* UFS: FS cylinders per group */
+ } d_partitions[MAXPARTITIONS]; /* actually may be more */
+};
+
+
+struct __partitionv0 { /* old (v0) partition table entry */
+ u_int32_t p_size; /* number of sectors in partition */
+ u_int32_t p_offset; /* starting sector */
+ u_int32_t p_fsize; /* filesystem basic fragment size */
+ u_int8_t p_fstype; /* filesystem type, see below */
+ u_int8_t p_frag; /* filesystem fragments per block */
+ union {
+ u_int16_t cpg; /* UFS: FS cylinders per group */
+ u_int16_t sgs; /* LFS: FS segment shift */
+ } __partitionv0_u1;
+};
+#endif /* _LOCORE */
+
+
+#define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \
+ ((fsize) * (frag) == 0 ? 0 : \
+ (((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag))))
+
+#define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12)))
+#define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1)))
+#define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \
+ (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i)))
+
+#define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size)
+#define DL_SETPSIZE(p, n) do { \
+ u_int64_t x = (n); \
+ (p)->p_sizeh = x >> 32; \
+ (p)->p_size = x; \
+ } while (0)
+#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset)
+#define DL_SETPOFFSET(p, n) do { \
+ u_int64_t x = (n); \
+ (p)->p_offseth = x >> 32; \
+ (p)->p_offset = x; \
+ } while (0)
+
+#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \
+ (d)->d_secperunit)
+#define DL_SETDSIZE(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_secperunith = x >> 32; \
+ (d)->d_secperunit = x; \
+ } while (0)
+#define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \
+ (d)->d_bstart)
+#define DL_SETBSTART(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_bstarth = x >> 32; \
+ (d)->d_bstart = x; \
+ } while (0)
+#define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \
+ (d)->d_bend)
+#define DL_SETBEND(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_bendh = x >> 32; \
+ (d)->d_bend = x; \
+ } while (0)
+
+#define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE)
+#define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d))
+#define DL_BLKTOSEC(d, n) ((n) / DL_BLKSPERSEC(d))
+#define DL_BLKOFFSET(d, n) (((n) % DL_BLKSPERSEC(d)) * DEV_BSIZE)
+
+/* d_type values: */
+#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
+#define DTYPE_MSCP 2 /* MSCP */
+#define DTYPE_DEC 3 /* other DEC (rk, rl) */
+#define DTYPE_SCSI 4 /* SCSI */
+#define DTYPE_ESDI 5 /* ESDI interface */
+#define DTYPE_ST506 6 /* ST506 etc. */
+#define DTYPE_HPIB 7 /* CS/80 on HP-IB */
+#define DTYPE_HPFL 8 /* HP Fiber-link */
+#define DTYPE_FLOPPY 10 /* floppy */
+#define DTYPE_CCD 11 /* was: concatenated disk device */
+#define DTYPE_VND 12 /* vnode pseudo-disk */
+#define DTYPE_ATAPI 13 /* ATAPI */
+#define DTYPE_RAID 14 /* was: RAIDframe */
+#define DTYPE_RDROOT 15 /* ram disk root */
+
+#ifdef DKTYPENAMES
+static char *dktypenames[] = {
+ "unknown",
+ "SMD",
+ "MSCP",
+ "old DEC",
+ "SCSI",
+ "ESDI",
+ "ST506",
+ "HP-IB",
+ "HP-FL",
+ "type 9",
+ "floppy",
+ "ccd", /* deprecated */
+ "vnd",
+ "ATAPI",
+ "RAID",
+ "rdroot",
+ NULL
+};
+#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
+#endif
+
+/*
+ * Filesystem type and version.
+ * Used to interpret other filesystem-specific
+ * per-partition information.
+ */
+#define FS_UNUSED 0 /* unused */
+#define FS_SWAP 1 /* swap */
+#define FS_V6 2 /* Sixth Edition */
+#define FS_V7 3 /* Seventh Edition */
+#define FS_SYSV 4 /* System V */
+#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
+#define FS_V8 6 /* Eighth Edition, 4K blocks */
+#define FS_BSDFFS 7 /* 4.2BSD fast file system */
+#define FS_MSDOS 8 /* MSDOS file system */
+#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
+#define FS_OTHER 10 /* in use, but unknown/unsupported */
+#define FS_HPFS 11 /* OS/2 high-performance file system */
+#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
+#define FS_BOOT 13 /* partition contains bootstrap */
+#define FS_ADOS 14 /* AmigaDOS fast file system */
+#define FS_HFS 15 /* Macintosh HFS */
+#define FS_ADFS 16 /* Acorn Disk Filing System */
+#define FS_EXT2FS 17 /* ext2fs */
+#define FS_CCD 18 /* ccd component */
+#define FS_RAID 19 /* RAIDframe or softraid */
+#define FS_NTFS 20 /* Windows/NT file system */
+#define FS_UDF 21 /* UDF (DVD) filesystem */
+
+#ifdef DKTYPENAMES
+static char *fstypenames[] = {
+ "unused",
+ "swap",
+ "Version6",
+ "Version7",
+ "SystemV",
+ "4.1BSD",
+ "Eighth-Edition",
+ "4.2BSD",
+ "MSDOS",
+ "4.4LFS",
+ "unknown",
+ "HPFS",
+ "ISO9660",
+ "boot",
+ "ADOS",
+ "HFS",
+ "ADFS",
+ "ext2fs",
+ "ccd",
+ "RAID",
+ "NTFS",
+ "UDF",
+ NULL
+};
+
+/* Similar to the above, but used for things like the mount command. */
+static char *fstypesnames[] = {
+ "", /* 0 */
+ "", /* 1 */
+ "", /* 2 */
+ "", /* 3 */
+ "", /* 4 */
+ "", /* 5 */
+ "", /* 6 */
+ "ffs", /* 7 */
+ "msdos", /* 8 */
+ "lfs", /* 9 */
+ "", /* 10 */
+ "", /* 11 */
+ "cd9660", /* 12 */
+ "", /* 13 */
+ "ados", /* 14 */
+ "", /* 15 */
+ "", /* 16 */
+ "ext2fs", /* 17 */
+ "", /* 18 */
+ "", /* 19 */
+ "ntfs", /* 20 */
+ "udf", /* 21 */
+ NULL
+};
+
+#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
+#endif
+
+/*
+ * flags shared by various drives:
+ */
+#define D_BADSECT 0x04 /* supports bad sector forw. */
+#define D_VENDOR 0x08 /* vendor disklabel */
+
+/*
+ * Drive data for SMD.
+ */
+#define d_smdflags d_drivedata[0]
+#define D_SSE 0x1 /* supports skip sectoring */
+#define d_mindist d_drivedata[1]
+#define d_maxdist d_drivedata[2]
+#define d_sdist d_drivedata[3]
+
+/*
+ * Drive data for ST506.
+ */
+#define d_precompcyl d_drivedata[0]
+#define d_gap3 d_drivedata[1] /* used only when formatting */
+
+/*
+ * Drive data for SCSI.
+ */
+#define d_blind d_drivedata[0]
+
+#ifndef _LOCORE
+/*
+ * Structure used internally to retrieve information about a partition
+ * on a disk.
+ */
+struct partinfo {
+ struct disklabel *disklab;
+ struct partition *part;
+};
+
+/* GUID partition table -- located at sector 1 of some disks. */
+#define GPTSECTOR 1 /* DOS boot block relative sector # */
+#define GPTSIGNATURE 0x5452415020494645LL
+ /* ASCII string "EFI PART" encoded as 64-bit */
+#define GPTREVISION 0x10000 /* GPT header version 1.0 */
+#define NGPTPARTITIONS 128
+#define GPTDOSACTIVE 0x2
+#define GPTMINHDRSIZE 92
+#define GPTMINPARTSIZE 128
+#define GPTPARTNAMESIZE 36
+
+/* all values in the GPT need to be little endian as per UEFI specification */
+struct gpt_header {
+ u_int64_t gh_sig; /* "EFI PART" */
+ u_int32_t gh_rev; /* GPT Version 1.0: 0x00000100 */
+ u_int32_t gh_size; /* Little-Endian */
+ u_int32_t gh_csum; /* CRC32: with this field as 0 */
+ u_int32_t gh_rsvd; /* always zero */
+ u_int64_t gh_lba_self; /* LBA of this header */
+ u_int64_t gh_lba_alt; /* LBA of alternate header */
+ u_int64_t gh_lba_start; /* first usable LBA */
+ u_int64_t gh_lba_end; /* last usable LBA */
+ struct uuid gh_guid; /* disk GUID used to identify the disk */
+ u_int64_t gh_part_lba; /* starting LBA of GPT partition entries */
+ u_int32_t gh_part_num; /* # of partition entries */
+ u_int32_t gh_part_size; /* size per entry, shall be 128*(2**n)
+ with n >= 0 */
+ u_int32_t gh_part_csum; /* CRC32 checksum of all partition entries:
+ * starts at gh_part_lba and is computed over
+ * a byte length of gh_part_num*gh_part_size */
+ /* the rest of the block is reserved by UEFI and must be zero */
+};
+
+struct gpt_partition {
+ struct uuid gp_type; /* partition type GUID */
+ struct uuid gp_guid; /* unique partition GUID */
+ u_int64_t gp_lba_start; /* starting LBA of this partition */
+ u_int64_t gp_lba_end; /* ending LBA of this partition, inclusive,
+ usually odd */
+ u_int64_t gp_attrs; /* attribute flags */
+ u_int16_t gp_name[GPTPARTNAMESIZE]; /* partition name, utf-16le */
+ /* the rest of the GPT partition entry, if any, is reserved by UEFI
+ and must be zero */
+};
+
+#define GPT_UUID_UNUSED \
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+#define GPT_UUID_MSDOS \
+ { 0xeb, 0xd0, 0xa0, 0xa2, 0xb9, 0xe5, 0x44, 0x33, \
+ 0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 }
+#define GPT_UUID_EFI_SYSTEM \
+ { 0xc1, 0x2a, 0x73, 0x28, 0xf8, 0x1f, 0x11, 0xd2, \
+ 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b }
+#define GPT_UUID_LEGACY_MBR \
+ { 0x02, 0x4d, 0xee, 0x41, 0x33, 0x37, 0x11, 0xd3, \
+ 0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f }
+#define GPT_UUID_OPENBSD \
+ { 0x82, 0x4c, 0xc7, 0xa0, 0x36, 0xa8, 0x11, 0xe3, \
+ 0x89, 0x0a, 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 }
+#define GPT_UUID_CHROMEROOTFS \
+ { 0x3c, 0xb8, 0xe2, 0x02, 0x3b, 0x7e, 0x47, 0xdd, \
+ 0x8a, 0x3c, 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec }
+#define GPT_UUID_LINUX \
+ { 0x0f, 0xc6, 0x3d, 0xaf, 0x84, 0x83, 0x47, 0x72, \
+ 0x8e, 0x79, 0x3d, 0x69, 0xd8, 0x47, 0x7d, 0xe4 }
+#define GPT_UUID_LINUX_HOME \
+ { 0x93, 0x3a, 0xc7, 0xe1, 0x2e, 0xb4, 0x4f, 0x13, \
+ 0xb8, 0x44, 0x0e, 0x14, 0xe2, 0xae, 0xf9, 0x15 }
+#define GPT_UUID_LINUX_SRV \
+ { 0x3b, 0x8f, 0x84, 0x25, 0x20, 0xe0, 0x4f, 0x3b, \
+ 0x90, 0x7f, 0x1a, 0x25, 0xa7, 0x6f, 0x98, 0xe8 }
+#define GPT_UUID_FBSD_DATA \
+ { 0x51, 0x6e, 0x7c, 0xb4, 0x6e, 0xcf, 0x11, 0xd6, \
+ 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
+#define GPT_UUID_FBSD_UFS \
+ { 0x51, 0x6e, 0x7c, 0xb6, 0x6e, 0xcf, 0x11, 0xd6, \
+ 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
+#define GPT_UUID_NBSD_UFS \
+ { 0x49, 0xf4, 0x8d, 0x5a, 0xb1, 0x0e, 0x11, 0xdc, \
+ 0xb9, 0x9b, 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 }
+#define GPT_UUID_APPLE_HFS \
+ { 0x48, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
+ 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
+#define GPT_UUID_APPLE_UFS \
+ { 0x55, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
+ 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
+
+/* DOS partition table -- located at start of some disks. */
+#define DOS_LABELSECTOR 1
+#define DOSBBSECTOR 0 /* DOS boot block relative sector # */
+#define DOSPARTOFF 446
+#define DOSDISKOFF 444
+#define NDOSPART 4
+#define DOSACTIVE 0x80 /* active partition */
+
+#define DOSMBR_SIGNATURE (0xaa55)
+#define DOSMBR_SIGNATURE_OFF (0x1fe)
+
+/* Maximum number of Extended Boot Records (EBRs) to traverse. */
+#define DOS_MAXEBR 256
+
+struct dos_partition {
+ u_int8_t dp_flag; /* bootstrap flags */
+ u_int8_t dp_shd; /* starting head */
+ u_int8_t dp_ssect; /* starting sector */
+ u_int8_t dp_scyl; /* starting cylinder */
+ u_int8_t dp_typ; /* partition type (see below) */
+ u_int8_t dp_ehd; /* end head */
+ u_int8_t dp_esect; /* end sector */
+ u_int8_t dp_ecyl; /* end cylinder */
+ u_int32_t dp_start; /* absolute starting sector number */
+ u_int32_t dp_size; /* partition size in sectors */
+};
+
+/* Isolate the relevant bits to get sector and cylinder. */
+#define DPSECT(s) ((s) & 0x3f)
+#define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
+
+/* Known DOS partition types. */
+#define DOSPTYP_UNUSED 0x00 /* Unused partition */
+#define DOSPTYP_FAT12 0x01 /* 12-bit FAT */
+#define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */
+#define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */
+#define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */
+#define DOSPTYP_NTFS 0x07 /* NTFS */
+#define DOSPTYP_FAT32 0x0b /* 32-bit FAT */
+#define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */
+#define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */
+#define DOSPTYP_EXTENDL 0x0f /* Extended, LBA-mapped; (sub-partitions) */
+#define DOSPTYP_ONTRACK 0x54
+#define DOSPTYP_LINUX 0x83 /* That other thing */
+#define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */
+#define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */
+#define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */
+#define DOSPTYP_EFI 0xee /* EFI Protective Partition */
+#define DOSPTYP_EFISYS 0xef /* EFI System Partition */
+
+struct dos_mbr {
+ u_int8_t dmbr_boot[DOSPARTOFF];
+ struct dos_partition dmbr_parts[NDOSPART];
+ u_int16_t dmbr_sign;
+} __packed;
+
+#ifdef _KERNEL
+void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
+u_int dkcksum(struct disklabel *);
+int initdisklabel(struct disklabel *);
+int checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t);
+int setdisklabel(struct disklabel *, struct disklabel *, u_int);
+int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
+int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
+int bounds_check_with_label(struct buf *, struct disklabel *);
+int readdisksector(struct buf *, void (*)(struct buf *),
+ struct disklabel *, u_int64_t);
+int readdoslabel(struct buf *, void (*)(struct buf *),
+ struct disklabel *, daddr_t *, int);
+#ifdef CD9660
+int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
+ struct disklabel *lp);
+#endif
+#ifdef UDF
+int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
+ struct disklabel *lp);
+#endif
+#endif
+#endif /* _LOCORE */
+
+#if !defined(_KERNEL) && !defined(_LOCORE)
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+struct disklabel *getdiskbyname(const char *);
+__END_DECLS
+
+#endif
diff --git a/sys/sys/dkio.h b/sys/sys/dkio.h
new file mode 100644
index 0000000..94d56ec
--- /dev/null
+++ b/sys/sys/dkio.h
@@ -0,0 +1,80 @@
+/* $OpenBSD: dkio.h,v 1.12 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: dkio.h,v 1.1 1996/01/30 18:21:48 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1987, 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.
+ */
+
+#ifndef _SYS_DKIO_H_
+#define _SYS_DKIO_H_
+
+#include <sys/ioccom.h>
+
+/*
+ * Disk-specific ioctls.
+ */
+ /* get and set disklabel; DIOCGPART used internally */
+#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */
+#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */
+#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */
+#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */
+
+#define DIOCEJECT _IO('d', 112) /* eject removable disk */
+#define DIOCLOCK _IOW('d', 113, int) /* lock/unlock pack */
+
+#define DIOCGPDINFO _IOR('d', 114, struct disklabel)/* get physical */
+#define DIOCRLDINFO _IO('d', 115) /* reload disklabel */
+
+struct dk_inquiry {
+ char vendor[64];
+ char product[128];
+ char revision[64];
+ char serial[64];
+};
+
+#define DIOCINQ _IOR('d', 116, struct dk_inquiry)
+
+struct dk_cache {
+ unsigned int wrcache;
+ unsigned int rdcache;
+};
+
+#define DIOCGCACHE _IOR('d', 117, struct dk_cache) /* get cache enabled */
+#define DIOCSCACHE _IOW('d', 118, struct dk_cache) /* set cache enabled */
+
+struct dk_diskmap {
+ char *device;
+ int fd;
+ int flags;
+};
+
+#define DIOCMAP _IOWR('d', 119, struct dk_diskmap)
+
+#define DIOCCACHESYNC _IOW('d', 120, int) /* sync cache (force?) */
+
+#endif /* _SYS_DKIO_H_ */
diff --git a/sys/sys/domain.h b/sys/sys/domain.h
new file mode 100644
index 0000000..7614cfa
--- /dev/null
+++ b/sys/sys/domain.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: domain.h,v 1.20 2019/06/13 08:12:11 claudio Exp $ */
+/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 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.
+ *
+ * @(#)domain.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Structure per communications domain.
+ */
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+/*
+ * Forward structure declarations for function prototypes [sic].
+ */
+struct mbuf;
+struct ifnet;
+
+struct domain {
+ int dom_family; /* AF_xxx */
+ char *dom_name;
+ void (*dom_init)(void); /* initialize domain data structures */
+ /* externalize access rights */
+ int (*dom_externalize)(struct mbuf *, socklen_t, int);
+ /* dispose of internalized rights */
+ void (*dom_dispose)(struct mbuf *);
+ const struct protosw *dom_protosw, *dom_protoswNPROTOSW;
+ /* initialize routing table */
+ unsigned int dom_sasize; /* size of sockaddr structure */
+ unsigned int dom_rtoffset; /* offset of the key, in bytes */
+ unsigned int dom_maxplen; /* maxium prefix length, in bits */
+ void *(*dom_ifattach)(struct ifnet *);
+ void (*dom_ifdetach)(struct ifnet *, void *);
+ /* af-dependent data on ifnet */
+};
+
+#ifdef _KERNEL
+extern struct domain *domains[];
+void domaininit(void);
+
+extern struct domain inetdomain;
+
+#ifdef INET6
+extern struct domain inet6domain;
+#endif
+
+#endif /* _KERNEL */
diff --git a/sys/sys/endian.h b/sys/sys/endian.h
new file mode 100644
index 0000000..29d5955
--- /dev/null
+++ b/sys/sys/endian.h
@@ -0,0 +1,124 @@
+/* $OpenBSD: endian.h,v 1.25 2014/12/21 04:49:00 guenther Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. 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.
+ */
+
+/*
+ * Public definitions for little- and big-endian systems.
+ * This file should be included as <endian.h> in userspace and as
+ * <sys/endian.h> in the kernel.
+ *
+ * System headers that need endian information but that can't or don't
+ * want to export the public names here should include <sys/_endian.h>
+ * and use the internal names: _BYTE_ORDER, _*_ENDIAN, etc.
+ */
+
+#ifndef _SYS_ENDIAN_H_
+#define _SYS_ENDIAN_H_
+
+#include <sys/cdefs.h>
+#include <sys/_endian.h>
+
+/* Public names */
+#define LITTLE_ENDIAN _LITTLE_ENDIAN
+#define BIG_ENDIAN _BIG_ENDIAN
+#define PDP_ENDIAN _PDP_ENDIAN
+#define BYTE_ORDER _BYTE_ORDER
+
+
+/*
+ * These are specified to be function-like macros to match the spec
+ */
+#define htobe16(x) __htobe16(x)
+#define htobe32(x) __htobe32(x)
+#define htobe64(x) __htobe64(x)
+#define htole16(x) __htole16(x)
+#define htole32(x) __htole32(x)
+#define htole64(x) __htole64(x)
+
+/* POSIX names */
+#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)
+
+
+#if __BSD_VISIBLE
+#define swap16(x) __swap16(x)
+#define swap32(x) __swap32(x)
+#define swap64(x) __swap64(x)
+
+#define swap16_multi(v, n) do { \
+ __size_t __swap16_multi_n = (n); \
+ __uint16_t *__swap16_multi_v = (v); \
+ \
+ while (__swap16_multi_n) { \
+ *__swap16_multi_v = swap16(*__swap16_multi_v); \
+ __swap16_multi_v++; \
+ __swap16_multi_n--; \
+ } \
+} while (0)
+
+/* original BSD names */
+#define betoh16(x) __htobe16(x)
+#define betoh32(x) __htobe32(x)
+#define betoh64(x) __htobe64(x)
+#define letoh16(x) __htole16(x)
+#define letoh32(x) __htole32(x)
+#define letoh64(x) __htole64(x)
+
+#ifndef htons
+/* these were exposed here before */
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
+
+/* ancient stuff */
+#define NTOHL(x) (x) = ntohl((u_int32_t)(x))
+#define NTOHS(x) (x) = ntohs((u_int16_t)(x))
+#define HTONL(x) (x) = htonl((u_int32_t)(x))
+#define HTONS(x) (x) = htons((u_int16_t)(x))
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* to/from memory conversions */
+#define bemtoh16 __bemtoh16
+#define bemtoh32 __bemtoh32
+#define bemtoh64 __bemtoh64
+#define htobem16 __htobem16
+#define htobem32 __htobem32
+#define htobem64 __htobem64
+#define lemtoh16 __lemtoh16
+#define lemtoh32 __lemtoh32
+#define lemtoh64 __lemtoh64
+#define htolem16 __htolem16
+#define htolem32 __htolem32
+#define htolem64 __htolem64
+#endif /* _KERNEL */
+
+#endif /* _SYS_ENDIAN_H_ */
diff --git a/sys/sys/errno.h b/sys/sys/errno.h
new file mode 100644
index 0000000..cf86be7
--- /dev/null
+++ b/sys/sys/errno.h
@@ -0,0 +1,182 @@
+/* $OpenBSD: errno.h,v 1.25 2017/09/05 03:06:26 jsg Exp $ */
+/* $NetBSD: errno.h,v 1.10 1996/01/20 01:33:53 jtc Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * 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.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ */
+
+#include <sys/cdefs.h>
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#if __BSD_VISIBLE
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+/* math software */
+#define EDOM 33 /* Numerical argument out of domain */
+#define ERANGE 34 /* Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#if __BSD_VISIBLE
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#endif
+#define EOPNOTSUPP 45 /* Operation not supported */
+#if __BSD_VISIBLE
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#endif
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#if __BSD_VISIBLE
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#endif /* __BSD_VISIBLE */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#if __BSD_VISIBLE
+#define EHOSTDOWN 64 /* Host is down */
+#endif /* __BSD_VISIBLE */
+#define EHOSTUNREACH 65 /* No route to host */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#if __BSD_VISIBLE
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#endif /* __BSD_VISIBLE */
+#define EDQUOT 69 /* Disk quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#if __BSD_VISIBLE
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC program not available */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* __BSD_VISIBLE */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#if __BSD_VISIBLE
+#define EFTYPE 79 /* Inappropriate file type or format */
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+#define EIPSEC 82 /* IPsec processing failure */
+#define ENOATTR 83 /* Attribute not found */
+#endif /* __BSD_VISIBLE */
+#define EILSEQ 84 /* Illegal byte sequence */
+#if __BSD_VISIBLE
+#define ENOMEDIUM 85 /* No medium found */
+#define EMEDIUMTYPE 86 /* Wrong medium type */
+#endif /* __BSD_VISIBLE */
+#define EOVERFLOW 87 /* Value too large to be stored in data type */
+#define ECANCELED 88 /* Operation canceled */
+#define EIDRM 89 /* Identifier removed */
+#define ENOMSG 90 /* No message of desired type */
+#define ENOTSUP 91 /* Not supported */
+#define EBADMSG 92 /* Bad message */
+#define ENOTRECOVERABLE 93 /* State not recoverable */
+#define EOWNERDEAD 94 /* Previous owner died */
+#define EPROTO 95 /* Protocol error */
+#if __BSD_VISIBLE
+#define ELAST 95 /* Must be equal largest errno */
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* pseudo-errors returned inside kernel to modify return to process */
+#define ERESTART -1 /* restart syscall */
+#define EJUSTRETURN -2 /* don't modify regs, just return */
+#endif
diff --git a/sys/sys/evcount.h b/sys/sys/evcount.h
new file mode 100644
index 0000000..9124e94
--- /dev/null
+++ b/sys/sys/evcount.h
@@ -0,0 +1,50 @@
+/* $OpenBSD: evcount.h,v 1.3 2010/09/20 06:33:46 matthew Exp $ */
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ * Copyright (c) 2004 Aaron Campbell <aaron@openbsd.org>
+ * 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. 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 ``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_EVCOUNT_H__
+#define __SYS_EVCOUNT_H__
+
+#ifdef _KERNEL
+
+#include <sys/queue.h>
+
+struct evcount {
+ u_int64_t ec_count; /* main counter */
+ int ec_id; /* counter ID */
+ const char *ec_name; /* counter name */
+ void *ec_data; /* user data */
+
+ TAILQ_ENTRY(evcount) next;
+};
+
+void evcount_attach(struct evcount *, const char *, void *);
+void evcount_detach(struct evcount *);
+int evcount_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+
+#endif /* _KERNEL */
+
+#endif
diff --git a/sys/sys/event.h b/sys/sys/event.h
new file mode 100644
index 0000000..2c345f3
--- /dev/null
+++ b/sys/sys/event.h
@@ -0,0 +1,224 @@
+/* $OpenBSD: event.h,v 1.35 2020/04/07 13:27:52 visa Exp $ */
+
+/*-
+ * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD: src/sys/sys/event.h,v 1.11 2001/02/24 01:41:31 jlemon Exp $
+ */
+
+#ifndef _SYS_EVENT_H_
+#define _SYS_EVENT_H_
+
+#define EVFILT_READ (-1)
+#define EVFILT_WRITE (-2)
+#define EVFILT_AIO (-3) /* attached to aio requests */
+#define EVFILT_VNODE (-4) /* attached to vnodes */
+#define EVFILT_PROC (-5) /* attached to struct process */
+#define EVFILT_SIGNAL (-6) /* attached to struct process */
+#define EVFILT_TIMER (-7) /* timers */
+#define EVFILT_DEVICE (-8) /* devices */
+
+#define EVFILT_SYSCOUNT 8
+
+#define EV_SET(kevp, a, b, c, d, e, f) do { \
+ struct kevent *__kevp = (kevp); \
+ (__kevp)->ident = (a); \
+ (__kevp)->filter = (b); \
+ (__kevp)->flags = (c); \
+ (__kevp)->fflags = (d); \
+ (__kevp)->data = (e); \
+ (__kevp)->udata = (f); \
+} while(0)
+
+struct kevent {
+ __uintptr_t ident; /* identifier for this event */
+ short filter; /* filter for event */
+ unsigned short flags; /* action flags for kqueue */
+ unsigned int fflags; /* filter flag value */
+ __int64_t data; /* filter data value */
+ void *udata; /* opaque user data identifier */
+};
+
+/* actions */
+#define EV_ADD 0x0001 /* add event to kq (implies enable) */
+#define EV_DELETE 0x0002 /* delete event from kq */
+#define EV_ENABLE 0x0004 /* enable event */
+#define EV_DISABLE 0x0008 /* disable event (not reported) */
+
+/* flags */
+#define EV_ONESHOT 0x0010 /* only report one occurrence */
+#define EV_CLEAR 0x0020 /* clear event state after reporting */
+#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */
+#define EV_DISPATCH 0x0080 /* disable event after reporting */
+
+#define EV_SYSFLAGS 0xF000 /* reserved by system */
+#define EV_FLAG1 0x2000 /* filter-specific flag */
+
+/* returned values */
+#define EV_EOF 0x8000 /* EOF detected */
+#define EV_ERROR 0x4000 /* error, data contains errno */
+
+/*
+ * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
+ */
+#define NOTE_LOWAT 0x0001 /* low water mark */
+#define NOTE_EOF 0x0002 /* return on EOF */
+
+/*
+ * data/hint flags for EVFILT_VNODE, shared with userspace
+ */
+#define NOTE_DELETE 0x0001 /* vnode was removed */
+#define NOTE_WRITE 0x0002 /* data contents changed */
+#define NOTE_EXTEND 0x0004 /* size increased */
+#define NOTE_ATTRIB 0x0008 /* attributes changed */
+#define NOTE_LINK 0x0010 /* link count changed */
+#define NOTE_RENAME 0x0020 /* vnode was renamed */
+#define NOTE_REVOKE 0x0040 /* vnode access was revoked */
+#define NOTE_TRUNCATE 0x0080 /* vnode was truncated */
+
+/*
+ * data/hint flags for EVFILT_PROC, shared with userspace
+ */
+#define NOTE_EXIT 0x80000000 /* process exited */
+#define NOTE_FORK 0x40000000 /* process forked */
+#define NOTE_EXEC 0x20000000 /* process exec'd */
+#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */
+#define NOTE_PDATAMASK 0x000fffff /* mask for pid */
+
+/* additional flags for EVFILT_PROC */
+#define NOTE_TRACK 0x00000001 /* follow across forks */
+#define NOTE_TRACKERR 0x00000002 /* could not track child */
+#define NOTE_CHILD 0x00000004 /* am a child process */
+
+/* data/hint flags for EVFILT_DEVICE, shared with userspace */
+#define NOTE_CHANGE 0x00000001 /* device change event */
+
+/*
+ * This is currently visible to userland to work around broken
+ * programs which pull in <sys/proc.h> or <sys/selinfo.h>.
+ */
+#include <sys/queue.h>
+struct knote;
+SLIST_HEAD(knlist, knote);
+
+struct klist {
+ struct knlist kl_list;
+};
+
+#ifdef _KERNEL
+
+#define EVFILT_MARKER 0xf /* placemarker for tailq */
+
+/*
+ * hint flag for in-kernel use - must not equal any existing note
+ */
+#define NOTE_SUBMIT 0x01000000 /* initial knote submission */
+
+#define KNOTE(list_, hint) do { \
+ struct klist *list = (list_); \
+ if ((list) != NULL) \
+ knote((list), (hint)); \
+ } while (0)
+
+#define KN_HASHSIZE 64 /* XXX should be tunable */
+
+/*
+ * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also
+ * shared by EVFILT_PROC (all knotes attached to p->p_klist)
+ */
+#define NOTE_SIGNAL 0x08000000
+
+#define FILTEROP_ISFD 0x00000001 /* ident == filedescriptor */
+
+struct filterops {
+ int f_flags;
+ int (*f_attach)(struct knote *kn);
+ void (*f_detach)(struct knote *kn);
+ int (*f_event)(struct knote *kn, long hint);
+};
+
+struct knote {
+ SLIST_ENTRY(knote) kn_link; /* for fd */
+ SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */
+ TAILQ_ENTRY(knote) kn_tqe;
+ struct kqueue *kn_kq; /* which queue we are on */
+ struct kevent kn_kevent;
+ int kn_status;
+ int kn_sfflags; /* saved filter flags */
+ __int64_t kn_sdata; /* saved data field */
+ union {
+ struct file *p_fp; /* file data pointer */
+ struct process *p_process; /* process pointer */
+ } kn_ptr;
+ const struct filterops *kn_fop;
+ void *kn_hook;
+#define KN_ACTIVE 0x0001 /* event has been triggered */
+#define KN_QUEUED 0x0002 /* event is on queue */
+#define KN_DISABLED 0x0004 /* event is disabled */
+#define KN_DETACHED 0x0008 /* knote is detached */
+#define KN_PROCESSING 0x0010 /* knote is being processed */
+#define KN_WAITING 0x0020 /* waiting on processing */
+
+#define kn_id kn_kevent.ident
+#define kn_filter kn_kevent.filter
+#define kn_flags kn_kevent.flags
+#define kn_fflags kn_kevent.fflags
+#define kn_data kn_kevent.data
+#define kn_fp kn_ptr.p_fp
+};
+
+struct proc;
+
+extern const struct filterops sig_filtops;
+
+extern void knote(struct klist *list, long hint);
+extern void knote_activate(struct knote *);
+extern void knote_remove(struct proc *p, struct knlist *list);
+extern void knote_fdclose(struct proc *p, int fd);
+extern void knote_processexit(struct proc *);
+extern int kqueue_register(struct kqueue *kq,
+ struct kevent *kev, struct proc *p);
+extern int filt_seltrue(struct knote *kn, long hint);
+extern int seltrue_kqfilter(dev_t, struct knote *);
+extern void klist_insert(struct klist *, struct knote *);
+extern void klist_remove(struct klist *, struct knote *);
+extern int klist_empty(struct klist *);
+extern void klist_invalidate(struct klist *);
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+struct timespec;
+
+__BEGIN_DECLS
+int kqueue(void);
+int kevent(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents,
+ const struct timespec *timeout);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_EVENT_H_ */
diff --git a/sys/sys/eventvar.h b/sys/sys/eventvar.h
new file mode 100644
index 0000000..44338c5
--- /dev/null
+++ b/sys/sys/eventvar.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: eventvar.h,v 1.9 2020/04/07 13:27:52 visa Exp $ */
+
+/*-
+ * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD: src/sys/sys/eventvar.h,v 1.3 2000/05/26 02:06:54 jake Exp $
+ */
+
+#ifndef _SYS_EVENTVAR_H_
+#define _SYS_EVENTVAR_H_
+
+#include <sys/task.h>
+
+#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */
+#define KQEXTENT 256 /* linear growth by this amount */
+
+/*
+ * Locking:
+ * a atomic operations
+ */
+struct kqueue {
+ TAILQ_HEAD(, knote) kq_head; /* list of pending event */
+ int kq_count; /* number of pending events */
+ u_int kq_refs; /* [a] number of references */
+ struct selinfo kq_sel;
+ struct filedesc *kq_fdp;
+
+ LIST_ENTRY(kqueue) kq_next;
+
+ int kq_knlistsize; /* size of kq_knlist */
+ struct knlist *kq_knlist; /* list of attached knotes */
+ u_long kq_knhashmask; /* size of kq_knhash */
+ struct knlist *kq_knhash; /* hash table for attached knotes */
+ struct task kq_task; /* deferring of activation */
+
+ int kq_state;
+#define KQ_SEL 0x01
+#define KQ_SLEEP 0x02
+#define KQ_DYING 0x04
+};
+
+#endif /* !_SYS_EVENTVAR_H_ */
diff --git a/sys/sys/exec.h b/sys/sys/exec.h
new file mode 100644
index 0000000..ecaef3e
--- /dev/null
+++ b/sys/sys/exec.h
@@ -0,0 +1,386 @@
+/* $OpenBSD: exec.h,v 1.40 2019/11/29 06:34:46 deraadt Exp $ */
+/* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1994 Christopher G. Demetriou
+ * Copyright (c) 1993 Theo de Raadt
+ * Copyright (c) 1992, 1993
+ * 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.
+ *
+ * @(#)exec.h 8.3 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_EXEC_H_
+#define _SYS_EXEC_H_
+
+/*
+ * The following structure is found at the top of the user stack of each
+ * user process. The ps program uses it to locate argv and environment
+ * strings. Programs that wish ps to display other information may modify
+ * it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same
+ * as the program's argc. The fields ps_envstr and ps_nenvstr are the
+ * equivalent for the environment.
+ */
+struct ps_strings {
+ char **ps_argvstr; /* first of 0 or more argument strings */
+ int ps_nargvstr; /* the number of argument strings */
+ char **ps_envstr; /* first of 0 or more environment strings */
+ int ps_nenvstr; /* the number of environment strings */
+};
+
+/*
+ * Below the PS_STRINGS and sigtramp, we may require a gap on the stack
+ * (used to copyin/copyout various emulation data structures).
+ */
+#define STACKGAPLEN (2*1024) /* plenty enough for now */
+
+/*
+ * the following structures allow execve() to put together processes
+ * in a more extensible and cleaner way.
+ *
+ * the exec_package struct defines an executable being execve()'d.
+ * it contains the header, the vmspace-building commands, the vnode
+ * information, and the arguments associated with the newly-execve'd
+ * process.
+ *
+ * the exec_vmcmd struct defines a command description to be used
+ * in creating the new process's vmspace.
+ */
+
+struct proc;
+struct exec_package;
+
+typedef int (*exec_makecmds_fcn)(struct proc *, struct exec_package *);
+
+struct execsw {
+ u_int es_hdrsz; /* size of header for this format */
+ exec_makecmds_fcn es_check; /* function to check exec format */
+};
+
+struct exec_vmcmd {
+ int (*ev_proc)(struct proc *p, struct exec_vmcmd *cmd);
+ /* procedure to run for region of vmspace */
+ u_long ev_len; /* length of the segment to map */
+ u_long ev_addr; /* address in the vmspace to place it at */
+ struct vnode *ev_vp; /* vnode pointer for the file w/the data */
+ u_long ev_offset; /* offset in the file for the data */
+ u_int ev_prot; /* protections for segment */
+ int ev_flags;
+#define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */
+#define VMCMD_BASE 0x0002 /* marks a base entry */
+#define VMCMD_STACK 0x0004 /* create with UVM_FLAG_STACK */
+#define VMCMD_SYSCALL 0x0008 /* create with UVM_FLAG_SYSCALL */
+};
+
+#define EXEC_DEFAULT_VMCMD_SETSIZE 8 /* # of cmds in set to start */
+
+/* exec vmspace-creation command set; see below */
+struct exec_vmcmd_set {
+ u_int evs_cnt;
+ u_int evs_used;
+ struct exec_vmcmd *evs_cmds;
+ struct exec_vmcmd evs_start[EXEC_DEFAULT_VMCMD_SETSIZE];
+};
+
+struct exec_package {
+ char *ep_name; /* file's name */
+ void *ep_hdr; /* file's exec header */
+ u_int ep_hdrlen; /* length of ep_hdr */
+ u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */
+ struct nameidata *ep_ndp; /* namei data pointer for lookups */
+ struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */
+ struct vnode *ep_vp; /* executable's vnode */
+ struct vattr *ep_vap; /* executable's attributes */
+ u_long ep_taddr; /* process's text address */
+ u_long ep_tsize; /* size of process's text */
+ u_long ep_daddr; /* process's data(+bss) address */
+ u_long ep_dsize; /* size of process's data(+bss) */
+ u_long ep_maxsaddr; /* proc's max stack addr ("top") */
+ u_long ep_minsaddr; /* proc's min stack addr ("bottom") */
+ u_long ep_ssize; /* size of process's stack */
+ u_long ep_entry; /* process's entry point */
+ u_int ep_flags; /* flags; see below. */
+ char **ep_fa; /* a fake args vector for scripts */
+ int ep_fd; /* a file descriptor we're holding */
+ struct emul *ep_emul; /* os emulation */
+ void *ep_emul_arg; /* emulation argument */
+ size_t ep_emul_argsize; /* emulation argument size */
+ void *ep_emul_argp; /* emulation argument pointer */
+ char *ep_interp; /* name of interpreter if any */
+};
+#define EXEC_INDIR 0x0001 /* script handling already done */
+#define EXEC_HASFD 0x0002 /* holding a shell script */
+#define EXEC_HASARGL 0x0004 /* has fake args vector */
+#define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */
+#define EXEC_DESTR 0x0010 /* destructive ops performed */
+#define EXEC_WXNEEDED 0x0020 /* executable will violate W^X */
+
+#ifdef _KERNEL
+/*
+ * functions used either by execve() or the various cpu-dependent execve()
+ * hooks.
+ */
+int exec_makecmds(struct proc *, struct exec_package *);
+int exec_runcmds(struct proc *, struct exec_package *);
+void vmcmdset_extend(struct exec_vmcmd_set *);
+void kill_vmcmds(struct exec_vmcmd_set *evsp);
+int vmcmd_map_pagedvn(struct proc *, struct exec_vmcmd *);
+int vmcmd_map_readvn(struct proc *, struct exec_vmcmd *);
+int vmcmd_map_zero(struct proc *, struct exec_vmcmd *);
+int vmcmd_randomize(struct proc *, struct exec_vmcmd *);
+void *copyargs(struct exec_package *,
+ struct ps_strings *,
+ void *, void *);
+void setregs(struct proc *, struct exec_package *,
+ u_long, register_t *);
+int check_exec(struct proc *, struct exec_package *);
+int exec_setup_stack(struct proc *, struct exec_package *);
+int exec_process_vmcmds(struct proc *, struct exec_package *);
+
+#ifdef DEBUG
+void new_vmcmd(struct exec_vmcmd_set *evsp,
+ int (*proc)(struct proc *p, struct exec_vmcmd *),
+ u_long len, u_long addr, struct vnode *vp, u_long offset,
+ u_int prot, int flags);
+#define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
+ new_vmcmd(evsp,proc,len,addr,vp,offset,prot, 0);
+#define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) \
+ new_vmcmd(evsp,proc,len,addr,vp,offset,prot,flags)
+#else /* DEBUG */
+#define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
+ NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,0)
+#define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) do { \
+ struct exec_vmcmd *vcp; \
+ if ((evsp)->evs_used >= (evsp)->evs_cnt) \
+ vmcmdset_extend(evsp); \
+ vcp = &(evsp)->evs_cmds[(evsp)->evs_used++]; \
+ vcp->ev_proc = (proc); \
+ vcp->ev_len = (len); \
+ vcp->ev_addr = (addr); \
+ if ((vcp->ev_vp = (vp)) != NULLVP) \
+ vref(vp); \
+ vcp->ev_offset = (offset); \
+ vcp->ev_prot = (prot); \
+ vcp->ev_flags = (flags); \
+} while (0)
+
+#endif /* DEBUG */
+
+/* Initialize an empty vmcmd set */
+#define VMCMDSET_INIT(vmc) do { \
+ (vmc)->evs_cnt = EXEC_DEFAULT_VMCMD_SETSIZE; \
+ (vmc)->evs_cmds = (vmc)->evs_start; \
+ (vmc)->evs_used = 0; \
+} while (0)
+
+/*
+ * Exec function switch:
+ *
+ * Note that each makecmds function is responsible for loading the
+ * exec package with the necessary functions for any exec-type-specific
+ * handling.
+ *
+ * Functions for specific exec types should be defined in their own
+ * header file.
+ */
+extern struct execsw execsw[];
+extern int nexecs;
+extern int exec_maxhdrsz;
+
+/*
+ * If non-zero, stackgap_random specifies the upper limit of the random gap size
+ * added to the fixed stack position. Must be n^2.
+ */
+extern int stackgap_random;
+
+/* Limit on total PT_OPENBSD_RANDOMIZE bytes. */
+#define ELF_RANDOMIZE_LIMIT 1024*1024
+
+#endif /* _KERNEL */
+
+#ifndef N_PAGSIZ
+#define N_PAGSIZ(ex) (__LDPGSZ)
+#endif
+
+/*
+ * Legacy a.out structures and defines; start deleting these when
+ * external use no longer exist.
+ */
+
+
+/*
+ * Header prepended to each a.out file.
+ * only manipulate the a_midmag field via the
+ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
+ */
+struct exec {
+ u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */
+ u_int32_t a_text; /* text segment size */
+ u_int32_t a_data; /* initialized data size */
+ u_int32_t a_bss; /* uninitialized data size */
+ u_int32_t a_syms; /* symbol table size */
+ u_int32_t a_entry; /* entry point */
+ u_int32_t a_trsize; /* text relocation size */
+ u_int32_t a_drsize; /* data relocation size */
+};
+
+/* a_magic */
+#define OMAGIC 0407 /* old impure format */
+#define NMAGIC 0410 /* read-only text */
+#define ZMAGIC 0413 /* demand load format */
+#define QMAGIC 0314 /* "compact" demand load format; deprecated */
+
+/*
+ * a_mid - keep sorted in numerical order for sanity's sake
+ * ensure that: 0 < mid < 0x3ff
+ */
+#define MID_ZERO 0 /* unknown - implementation dependent */
+#define MID_SUN010 1 /* sun 68010/68020 binary */
+#define MID_SUN020 2 /* sun 68020-only binary */
+#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */
+#define MID_ROMPAOS 104 /* old IBM RT */
+#define MID_I386 134 /* i386 BSD binary */
+#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */
+#define MID_M68K4K 136 /* DO NOT USE: m68k BSD binary with 4K page sizes */
+#define MID_NS32532 137 /* ns32532 */
+#define MID_SPARC 138 /* sparc */
+#define MID_PMAX 139 /* pmax */
+#define MID_VAX1K 140 /* vax 1k page size */
+#define MID_ALPHA 141 /* Alpha BSD binary */
+#define MID_MIPS 142 /* big-endian MIPS */
+#define MID_ARM6 143 /* ARM6 */
+#define MID_SH3 145 /* SH3 */
+#define MID_POWERPC 149 /* big-endian PowerPC */
+#define MID_VAX 150 /* vax */
+#define MID_SPARC64 151 /* LP64 sparc */
+#define MID_MIPS2 152 /* MIPS2 */
+#define MID_M88K 153 /* m88k BSD binary */
+#define MID_HPPA 154 /* hppa */
+#define MID_AMD64 157 /* AMD64 */
+#define MID_MIPS64 158 /* big-endian MIPS64 */
+#define MID_ARM64 159 /* ARM64 */
+#define MID_HP200 200 /* hp200 (68010) BSD binary */
+#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
+#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
+#define MID_HPUX800 0x20B /* hp800 HP-UX binary pa1.0 */
+#define MID_HPPA11 0x210 /* hp700 HP-UX binary pa1.1 */
+#define MID_HPPA20 0x214 /* hp700 HP-UX binary pa2.0 */
+
+/*
+ * a_flags
+ */
+#define EX_DYNAMIC 0x20
+#define EX_PIC 0x10
+#define EX_DPMASK 0x30
+/*
+ * Interpretation of the (a_flags & EX_DPMASK) bits:
+ *
+ * 00 traditional executable or object file
+ * 01 object file contains PIC code (set by `as -k')
+ * 10 dynamic executable
+ * 11 position independent executable image
+ * (eg. a shared library)
+ *
+ */
+
+/*
+ * The a.out structure's a_midmag field is a network-byteorder encoding
+ * of this int
+ * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
+ * Where `F' is 6 bits of flag like EX_DYNAMIC,
+ * `m' is 10 bits of machine-id like MID_I386, and
+ * `M' is 16 bits worth of magic number, ie. ZMAGIC.
+ * The macros below will set/get the needed fields.
+ */
+#define N_GETMAGIC(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
+#define N_GETMAGIC2(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
+ (((ex).a_midmag) | 0x10000) )
+#define N_GETMID(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
+#define N_GETFLAG(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
+#define N_SETMAGIC(ex,mag,mid,flag) \
+ ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
+ (((mag)&0xffff)) ) )
+
+#define N_ALIGN(ex,x) \
+ (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
+ ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
+
+/* Valid magic number check. */
+#define N_BADMAG(ex) \
+ (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
+ N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
+
+/* Address of the bottom of the text segment. */
+#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
+
+/* Address of the bottom of the data segment. */
+#define N_DATADDR(ex) \
+ (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
+ (N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
+
+/* Address of the bottom of the bss segment. */
+#define N_BSSADDR(ex) \
+ (N_DATADDR(ex) + (ex).a_data)
+
+/* Text segment offset. */
+#define N_TXTOFF(ex) \
+ ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
+ 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
+ sizeof(struct exec)) )
+
+/* Data segment offset. */
+#define N_DATOFF(ex) \
+ N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
+
+/* Text relocation table offset. */
+#define N_TRELOFF(ex) \
+ (N_DATOFF(ex) + (ex).a_data)
+
+/* Data relocation table offset. */
+#define N_DRELOFF(ex) \
+ (N_TRELOFF(ex) + (ex).a_trsize)
+
+/* Symbol table offset. */
+#define N_SYMOFF(ex) \
+ (N_DRELOFF(ex) + (ex).a_drsize)
+
+/* String table offset. */
+#define N_STROFF(ex) \
+ (N_SYMOFF(ex) + (ex).a_syms)
+
+#include <machine/exec.h>
+
+#endif /* !_SYS_EXEC_H_ */
diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h
new file mode 100644
index 0000000..a40e051
--- /dev/null
+++ b/sys/sys/exec_elf.h
@@ -0,0 +1,785 @@
+/* $OpenBSD: exec_elf.h,v 1.87 2019/12/01 13:10:51 jsg Exp $ */
+/*
+ * Copyright (c) 1995, 1996 Erik Theisen. 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. 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.
+ */
+
+/*
+ * This is the ELF ABI header file
+ * formerly known as "elf_abi.h".
+ */
+
+#ifndef _SYS_EXEC_ELF_H_
+#define _SYS_EXEC_ELF_H_
+
+#include <sys/types.h>
+#include <machine/exec.h>
+
+typedef __uint32_t Elf32_Addr; /* Unsigned program address */
+typedef __uint32_t Elf32_Off; /* Unsigned file offset */
+typedef __int32_t Elf32_Sword; /* Signed large integer */
+typedef __uint32_t Elf32_Word; /* Unsigned large integer */
+typedef __uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef __uint64_t Elf32_Lword;
+
+typedef __uint64_t Elf64_Addr;
+typedef __uint64_t Elf64_Off;
+typedef __int32_t Elf64_Shalf;
+
+typedef __int32_t Elf64_Sword;
+typedef __uint32_t Elf64_Word;
+
+typedef __int64_t Elf64_Sxword;
+typedef __uint64_t Elf64_Xword;
+typedef __uint64_t Elf64_Lword;
+
+typedef __uint16_t Elf64_Half;
+
+/*
+ * e_ident[] identification indexes
+ * See http://www.sco.com/developers/gabi/latest/ch4.eheader.html
+ */
+#define EI_MAG0 0 /* file ID */
+#define EI_MAG1 1 /* file ID */
+#define EI_MAG2 2 /* file ID */
+#define EI_MAG3 3 /* file ID */
+#define EI_CLASS 4 /* file class */
+#define EI_DATA 5 /* data encoding */
+#define EI_VERSION 6 /* ELF header version */
+#define EI_OSABI 7 /* OS/ABI ID */
+#define EI_ABIVERSION 8 /* ABI version */
+#define EI_PAD 9 /* start of pad bytes */
+#define EI_NIDENT 16 /* Size of e_ident[] */
+
+/* e_ident[] magic number */
+#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
+#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
+#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
+#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
+#define ELFMAG "\177ELF" /* magic */
+#define SELFMAG 4 /* size of magic */
+
+/* e_ident[] file class */
+#define ELFCLASSNONE 0 /* invalid */
+#define ELFCLASS32 1 /* 32-bit objs */
+#define ELFCLASS64 2 /* 64-bit objs */
+#define ELFCLASSNUM 3 /* number of classes */
+
+/* e_ident[] data encoding */
+#define ELFDATANONE 0 /* invalid */
+#define ELFDATA2LSB 1 /* Little-Endian */
+#define ELFDATA2MSB 2 /* Big-Endian */
+#define ELFDATANUM 3 /* number of data encode defines */
+
+/* e_ident[] Operating System/ABI */
+#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
+#define ELFOSABI_HPUX 1 /* HP-UX operating system */
+#define ELFOSABI_NETBSD 2 /* NetBSD */
+#define ELFOSABI_LINUX 3 /* GNU/Linux */
+#define ELFOSABI_HURD 4 /* GNU/Hurd */
+#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
+#define ELFOSABI_SOLARIS 6 /* Solaris */
+#define ELFOSABI_MONTEREY 7 /* Monterey */
+#define ELFOSABI_IRIX 8 /* IRIX */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD */
+#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
+#define ELFOSABI_MODESTO 11 /* Novell Modesto */
+#define ELFOSABI_OPENBSD 12 /* OpenBSD */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+/* e_ident */
+#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
+ (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
+ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
+ (ehdr).e_ident[EI_MAG3] == ELFMAG3)
+
+/* ELF Header */
+typedef struct elfhdr {
+ unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
+ Elf32_Half e_type; /* object file type */
+ Elf32_Half e_machine; /* machine */
+ Elf32_Word e_version; /* object file version */
+ Elf32_Addr e_entry; /* virtual entry point */
+ Elf32_Off e_phoff; /* program header table offset */
+ Elf32_Off e_shoff; /* section header table offset */
+ Elf32_Word e_flags; /* processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size */
+ Elf32_Half e_phentsize; /* program header entry size */
+ Elf32_Half e_phnum; /* number of program header entries */
+ Elf32_Half e_shentsize; /* section header entry size */
+ Elf32_Half e_shnum; /* number of section header entries */
+ Elf32_Half e_shstrndx; /* section header table's "section
+ header string table" entry offset */
+} Elf32_Ehdr;
+
+typedef struct {
+ unsigned char e_ident[EI_NIDENT]; /* Id bytes */
+ Elf64_Half e_type; /* file type */
+ Elf64_Half e_machine; /* machine type */
+ Elf64_Word e_version; /* version number */
+ Elf64_Addr e_entry; /* entry point */
+ Elf64_Off e_phoff; /* Program hdr offset */
+ Elf64_Off e_shoff; /* Section hdr offset */
+ Elf64_Word e_flags; /* Processor flags */
+ Elf64_Half e_ehsize; /* sizeof ehdr */
+ Elf64_Half e_phentsize; /* Program header entry size */
+ Elf64_Half e_phnum; /* Number of program headers */
+ Elf64_Half e_shentsize; /* Section header entry size */
+ Elf64_Half e_shnum; /* Number of section headers */
+ Elf64_Half e_shstrndx; /* String table index */
+} Elf64_Ehdr;
+
+/* e_type */
+#define ET_NONE 0 /* No file type */
+#define ET_REL 1 /* relocatable file */
+#define ET_EXEC 2 /* executable file */
+#define ET_DYN 3 /* shared object file */
+#define ET_CORE 4 /* core file */
+#define ET_NUM 5 /* number of types */
+#define ET_LOPROC 0xff00 /* reserved range for processor */
+#define ET_HIPROC 0xffff /* specific e_type */
+
+/* e_machine */
+#define EM_NONE 0 /* No Machine */
+#define EM_M32 1 /* AT&T WE 32100 */
+#define EM_SPARC 2 /* SPARC */
+#define EM_386 3 /* Intel 80386 */
+#define EM_68K 4 /* Motorola 68000 */
+#define EM_88K 5 /* Motorola 88000 */
+#define EM_486 6 /* Intel 80486 - unused? */
+#define EM_860 7 /* Intel 80860 */
+#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
+/*
+ * Don't know if EM_MIPS_RS4_BE,
+ * EM_SPARC64, EM_PARISC,
+ * or EM_PPC are ABI compliant
+ */
+#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
+#define EM_SPARC64 11 /* SPARC v9 64-bit unofficial */
+#define EM_PARISC 15 /* HPPA */
+#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
+#define EM_PPC 20 /* PowerPC */
+#define EM_PPC64 21 /* PowerPC 64 */
+#define EM_ARM 40 /* Advanced RISC Machines ARM */
+#define EM_ALPHA 41 /* DEC ALPHA */
+#define EM_SH 42 /* Hitachi/Renesas Super-H */
+#define EM_SPARCV9 43 /* SPARC version 9 */
+#define EM_IA_64 50 /* Intel IA-64 Processor */
+#define EM_AMD64 62 /* AMD64 architecture */
+#define EM_X86_64 EM_AMD64
+#define EM_VAX 75 /* DEC VAX */
+#define EM_AARCH64 183 /* ARM 64-bit architecture (AArch64) */
+
+/* Non-standard */
+#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */
+#define EM__LAST__ (EM_ALPHA_EXP + 1)
+
+#define EM_NUM 22 /* number of machine types */
+
+/* Version */
+#define EV_NONE 0 /* Invalid */
+#define EV_CURRENT 1 /* Current */
+#define EV_NUM 2 /* number of versions */
+
+/* Magic for e_phnum: get real value from sh_info of first section header */
+#define PN_XNUM 0xffff
+
+/* Section Header */
+typedef struct {
+ Elf32_Word sh_name; /* name - index into section header
+ string table section */
+ Elf32_Word sh_type; /* type */
+ Elf32_Word sh_flags; /* flags */
+ Elf32_Addr sh_addr; /* address */
+ Elf32_Off sh_offset; /* file offset */
+ Elf32_Word sh_size; /* section size */
+ Elf32_Word sh_link; /* section header table index link */
+ Elf32_Word sh_info; /* extra information */
+ Elf32_Word sh_addralign; /* address alignment */
+ Elf32_Word sh_entsize; /* section entry size */
+} Elf32_Shdr;
+
+typedef struct {
+ Elf64_Word sh_name; /* section name */
+ Elf64_Word sh_type; /* section type */
+ Elf64_Xword sh_flags; /* section flags */
+ Elf64_Addr sh_addr; /* virtual address */
+ Elf64_Off sh_offset; /* file offset */
+ Elf64_Xword sh_size; /* section size */
+ Elf64_Word sh_link; /* link to another */
+ Elf64_Word sh_info; /* misc info */
+ Elf64_Xword sh_addralign; /* memory alignment */
+ Elf64_Xword sh_entsize; /* table entry size */
+} Elf64_Shdr;
+
+/* Special Section Indexes */
+#define SHN_UNDEF 0 /* undefined */
+#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
+#define SHN_LOPROC 0xff00 /* reserved range for processor */
+#define SHN_HIPROC 0xff1f /* specific section indexes */
+#define SHN_ABS 0xfff1 /* absolute value */
+#define SHN_COMMON 0xfff2 /* common symbol */
+#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */
+#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
+
+/* sh_type */
+#define SHT_NULL 0 /* inactive */
+#define SHT_PROGBITS 1 /* program defined information */
+#define SHT_SYMTAB 2 /* symbol table section */
+#define SHT_STRTAB 3 /* string table section */
+#define SHT_RELA 4 /* relocation section with addends*/
+#define SHT_HASH 5 /* symbol hash table section */
+#define SHT_DYNAMIC 6 /* dynamic section */
+#define SHT_NOTE 7 /* note section */
+#define SHT_NOBITS 8 /* no space section */
+#define SHT_REL 9 /* relation section without addends */
+#define SHT_SHLIB 10 /* reserved - purpose unknown */
+#define SHT_DYNSYM 11 /* dynamic symbol table section */
+#define SHT_NUM 12 /* number of section types */
+#define SHT_INIT_ARRAY 14 /* pointers to init functions */
+#define SHT_FINI_ARRAY 15 /* pointers to termination functions */
+#define SHT_PREINIT_ARRAY 16 /* ptrs to funcs called before init */
+#define SHT_GROUP 17 /* defines a section group */
+#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */
+#define SHT_LOOS 0x60000000 /* reserved range for OS specific */
+#define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */
+#define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */
+#define SHT_SUNW_move 0x6ffffffa /* inf for partially init'ed symbols */
+#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */
+#define SHT_SUNW_verdef 0x6ffffffd /* symbol versioning inf */
+#define SHT_SUNW_verneed 0x6ffffffe /* symbol versioning req */
+#define SHT_SUNW_versym 0x6fffffff /* symbol versioning table */
+#define SHT_HIOS 0x6fffffff /* section header types */
+#define SHT_LOPROC 0x70000000 /* reserved range for processor */
+#define SHT_HIPROC 0x7fffffff /* specific section header types */
+#define SHT_LOUSER 0x80000000 /* reserved range for application */
+#define SHT_HIUSER 0xffffffff /* specific indexes */
+
+#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table section */
+
+/* Section names */
+#define ELF_BSS ".bss" /* uninitialized data */
+#define ELF_DATA ".data" /* initialized data */
+#define ELF_CTF ".SUNW_ctf" /* CTF data */
+#define ELF_DEBUG ".debug" /* debug */
+#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
+#define ELF_DYNSTR ".dynstr" /* dynamic string table */
+#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
+#define ELF_FINI ".fini" /* termination code */
+#define ELF_GOT ".got" /* global offset table */
+#define ELF_HASH ".hash" /* symbol hash table */
+#define ELF_INIT ".init" /* initialization code */
+#define ELF_REL_DATA ".rel.data" /* relocation data */
+#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
+#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
+#define ELF_REL_DYN ".rel.dyn" /* relocation dynamic link info */
+#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
+#define ELF_REL_TEXT ".rel.text" /* relocation code */
+#define ELF_RODATA ".rodata" /* read-only data */
+#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
+#define ELF_STRTAB ".strtab" /* string table */
+#define ELF_SYMTAB ".symtab" /* symbol table */
+#define ELF_TEXT ".text" /* code */
+#define ELF_OPENBSDRANDOMDATA ".openbsd.randomdata" /* constant randomdata */
+
+
+/* Section Attribute Flags - sh_flags */
+#define SHF_WRITE 0x1 /* Writable */
+#define SHF_ALLOC 0x2 /* occupies memory */
+#define SHF_EXECINSTR 0x4 /* executable */
+#define SHF_MERGE 0x10 /* may be merged */
+#define SHF_STRINGS 0x20 /* contains strings */
+#define SHF_INFO_LINK 0x40 /* sh_info holds section index */
+#define SHF_LINK_ORDER 0x80 /* ordering requirements */
+#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required */
+#define SHF_GROUP 0x200 /* member of section group */
+#define SHF_TLS 0x400 /* thread local storage */
+#define SHF_COMPRESSED 0x800 /* contains compressed data */
+#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics */
+#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
+ /* specific section attributes */
+
+/* Symbol Table Entry */
+typedef struct elf32_sym {
+ Elf32_Word st_name; /* name - index into string table */
+ Elf32_Addr st_value; /* symbol value */
+ Elf32_Word st_size; /* symbol size */
+ unsigned char st_info; /* type and binding */
+ unsigned char st_other; /* 0 - no defined meaning */
+ Elf32_Half st_shndx; /* section header index */
+} Elf32_Sym;
+
+typedef struct {
+ Elf64_Word st_name; /* Symbol name index in str table */
+ unsigned char st_info; /* type / binding attrs */
+ unsigned char st_other; /* unused */
+ Elf64_Half st_shndx; /* section index of symbol */
+ Elf64_Addr st_value; /* value of symbol */
+ Elf64_Xword st_size; /* size of symbol */
+} Elf64_Sym;
+
+/* Symbol table index */
+#define STN_UNDEF 0 /* undefined */
+
+/* Extract symbol info - st_info */
+#define ELF32_ST_BIND(x) ((x) >> 4)
+#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
+#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
+
+#define ELF64_ST_BIND(x) ((x) >> 4)
+#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)
+#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
+
+/* Symbol Binding - ELF32_ST_BIND - st_info */
+#define STB_LOCAL 0 /* Local symbol */
+#define STB_GLOBAL 1 /* Global symbol */
+#define STB_WEAK 2 /* like global - lower precedence */
+#define STB_NUM 3 /* number of symbol bindings */
+#define STB_LOPROC 13 /* reserved range for processor */
+#define STB_HIPROC 15 /* specific symbol bindings */
+
+/* Symbol type - ELF32_ST_TYPE - st_info */
+#define STT_NOTYPE 0 /* not specified */
+#define STT_OBJECT 1 /* data object */
+#define STT_FUNC 2 /* function */
+#define STT_SECTION 3 /* section */
+#define STT_FILE 4 /* file */
+#define STT_TLS 6 /* thread local storage */
+#define STT_LOPROC 13 /* reserved range for processor */
+#define STT_HIPROC 15 /* specific symbol types */
+
+/* Extract symbol visibility - st_other */
+#define ELF_ST_VISIBILITY(v) ((v) & 0x3)
+#define ELF32_ST_VISIBILITY ELF_ST_VISIBILITY
+#define ELF64_ST_VISIBILITY ELF_ST_VISIBILITY
+
+#define STV_DEFAULT 0 /* Visibility set by binding type */
+#define STV_INTERNAL 1 /* OS specific version of STV_HIDDEN */
+#define STV_HIDDEN 2 /* can only be seen inside own .so */
+#define STV_PROTECTED 3 /* HIDDEN inside, DEFAULT outside */
+
+/* Relocation entry with implicit addend */
+typedef struct {
+ Elf32_Addr r_offset; /* offset of relocation */
+ Elf32_Word r_info; /* symbol table index and type */
+} Elf32_Rel;
+
+/* Relocation entry with explicit addend */
+typedef struct {
+ Elf32_Addr r_offset; /* offset of relocation */
+ Elf32_Word r_info; /* symbol table index and type */
+ Elf32_Sword r_addend;
+} Elf32_Rela;
+
+/* Extract relocation info - r_info */
+#define ELF32_R_SYM(i) ((i) >> 8)
+#define ELF32_R_TYPE(i) ((unsigned char) (i))
+#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
+
+typedef struct {
+ Elf64_Addr r_offset; /* where to do it */
+ Elf64_Xword r_info; /* index & type of relocation */
+} Elf64_Rel;
+
+typedef struct {
+ Elf64_Addr r_offset; /* where to do it */
+ Elf64_Xword r_info; /* index & type of relocation */
+ Elf64_Sxword r_addend; /* adjustment value */
+} Elf64_Rela;
+
+#define ELF64_R_SYM(info) ((info) >> 32)
+#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF)
+#define ELF64_R_INFO(s,t) (((s) << 32) + (__uint32_t)(t))
+
+#if defined(__mips64__) && defined(__MIPSEL__)
+/*
+ * The 64-bit MIPS ELF ABI uses a slightly different relocation format
+ * than the regular ELF ABI: the r_info field is split into several
+ * pieces (see gnu/usr.bin/binutils-2.17/include/elf/mips.h for details).
+ */
+#undef ELF64_R_SYM
+#undef ELF64_R_TYPE
+#undef ELF64_R_INFO
+#define ELF64_R_TYPE(info) ((__uint64_t)swap32((info) >> 32))
+#define ELF64_R_SYM(info) ((info) & 0xFFFFFFFF)
+#define ELF64_R_INFO(s,t) (((__uint64_t)swap32(t) << 32) + (__uint32_t)(s))
+#endif /* __mips64__ && __MIPSEL__ */
+
+/* Program Header */
+typedef struct {
+ Elf32_Word p_type; /* segment type */
+ Elf32_Off p_offset; /* segment offset */
+ Elf32_Addr p_vaddr; /* virtual address of segment */
+ Elf32_Addr p_paddr; /* physical address - ignored? */
+ Elf32_Word p_filesz; /* number of bytes in file for seg. */
+ Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
+ Elf32_Word p_flags; /* flags */
+ Elf32_Word p_align; /* memory alignment */
+} Elf32_Phdr;
+
+typedef struct {
+ Elf64_Word p_type; /* entry type */
+ Elf64_Word p_flags; /* flags */
+ Elf64_Off p_offset; /* offset */
+ Elf64_Addr p_vaddr; /* virtual address */
+ Elf64_Addr p_paddr; /* physical address */
+ Elf64_Xword p_filesz; /* file size */
+ Elf64_Xword p_memsz; /* memory size */
+ Elf64_Xword p_align; /* memory & file alignment */
+} Elf64_Phdr;
+
+/* Segment types - p_type */
+#define PT_NULL 0 /* unused */
+#define PT_LOAD 1 /* loadable segment */
+#define PT_DYNAMIC 2 /* dynamic linking section */
+#define PT_INTERP 3 /* the RTLD */
+#define PT_NOTE 4 /* auxiliary information */
+#define PT_SHLIB 5 /* reserved - purpose undefined */
+#define PT_PHDR 6 /* program header */
+#define PT_TLS 7 /* thread local storage */
+#define PT_LOOS 0x60000000 /* reserved range for OS */
+#define PT_HIOS 0x6fffffff /* specific segment types */
+#define PT_LOPROC 0x70000000 /* reserved range for processor */
+#define PT_HIPROC 0x7fffffff /* specific segment types */
+
+#define PT_GNU_EH_FRAME 0x6474e550 /* Exception handling info */
+#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
+
+#define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* fill with random data */
+#define PT_OPENBSD_WXNEEDED 0x65a3dbe7 /* program performs W^X violations */
+#define PT_OPENBSD_BOOTDATA 0x65a41be6 /* section for boot arguments */
+
+/* Segment flags - p_flags */
+#define PF_X 0x1 /* Executable */
+#define PF_W 0x2 /* Writable */
+#define PF_R 0x4 /* Readable */
+#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
+ /* specific segment flags */
+
+/* Dynamic structure */
+typedef struct {
+ Elf32_Sword d_tag; /* controls meaning of d_val */
+ union {
+ Elf32_Word d_val; /* Multiple meanings - see d_tag */
+ Elf32_Addr d_ptr; /* program virtual address */
+ } d_un;
+} Elf32_Dyn;
+
+typedef struct {
+ Elf64_Xword d_tag; /* controls meaning of d_val */
+ union {
+ Elf64_Addr d_ptr;
+ Elf64_Xword d_val;
+ } d_un;
+} Elf64_Dyn;
+
+/* Dynamic Array Tags - d_tag */
+#define DT_NULL 0 /* marks end of _DYNAMIC array */
+#define DT_NEEDED 1 /* string table offset of needed lib */
+#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
+#define DT_PLTGOT 3 /* address PLT/GOT */
+#define DT_HASH 4 /* address of symbol hash table */
+#define DT_STRTAB 5 /* address of string table */
+#define DT_SYMTAB 6 /* address of symbol table */
+#define DT_RELA 7 /* address of relocation table */
+#define DT_RELASZ 8 /* size of relocation table */
+#define DT_RELAENT 9 /* size of relocation entry */
+#define DT_STRSZ 10 /* size of string table */
+#define DT_SYMENT 11 /* size of symbol table entry */
+#define DT_INIT 12 /* address of initialization func. */
+#define DT_FINI 13 /* address of termination function */
+#define DT_SONAME 14 /* string table offset of shared obj */
+#define DT_RPATH 15 /* string table offset of library
+ search path */
+#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
+#define DT_REL 17 /* address of rel. tbl. w addends */
+#define DT_RELSZ 18 /* size of DT_REL relocation table */
+#define DT_RELENT 19 /* size of DT_REL relocation entry */
+#define DT_PLTREL 20 /* PLT referenced relocation entry */
+#define DT_DEBUG 21 /* bugger */
+#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
+#define DT_JMPREL 23 /* add. of PLT's relocation entries */
+#define DT_BIND_NOW 24 /* Bind now regardless of env setting */
+#define DT_INIT_ARRAY 25 /* address of array of init func */
+#define DT_FINI_ARRAY 26 /* address of array of term func */
+#define DT_INIT_ARRAYSZ 27 /* size of array of init func */
+#define DT_FINI_ARRAYSZ 28 /* size of array of term func */
+#define DT_RUNPATH 29 /* strtab offset of lib search path */
+#define DT_FLAGS 30 /* Set of DF_* flags */
+#define DT_ENCODING 31 /* further DT_* follow encoding rules */
+#define DT_PREINIT_ARRAY 32 /* address of array of preinit func */
+#define DT_PREINIT_ARRAYSZ 33 /* size of array of preinit func */
+#define DT_LOOS 0x6000000d /* reserved range for OS */
+#define DT_HIOS 0x6ffff000 /* specific dynamic array tags */
+#define DT_LOPROC 0x70000000 /* reserved range for processor */
+#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
+
+/* some other useful tags */
+#define DT_GNU_HASH 0x6ffffef5 /* address of GNU hash table */
+#define DT_RELACOUNT 0x6ffffff9 /* if present, number of RELATIVE */
+#define DT_RELCOUNT 0x6ffffffa /* relocs, which must come first */
+#define DT_FLAGS_1 0x6ffffffb
+
+/* Dynamic Flags - DT_FLAGS .dynamic entry */
+#define DF_ORIGIN 0x00000001
+#define DF_SYMBOLIC 0x00000002
+#define DF_TEXTREL 0x00000004
+#define DF_BIND_NOW 0x00000008
+#define DF_STATIC_TLS 0x00000010
+
+/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */
+#define DF_1_NOW 0x00000001
+#define DF_1_GLOBAL 0x00000002
+#define DF_1_GROUP 0x00000004
+#define DF_1_NODELETE 0x00000008
+#define DF_1_LOADFLTR 0x00000010
+#define DF_1_INITFIRST 0x00000020
+#define DF_1_NOOPEN 0x00000040
+#define DF_1_ORIGIN 0x00000080
+#define DF_1_DIRECT 0x00000100
+#define DF_1_TRANS 0x00000200
+#define DF_1_INTERPOSE 0x00000400
+#define DF_1_NODEFLIB 0x00000800
+#define DF_1_NODUMP 0x00001000
+#define DF_1_CONLFAT 0x00002000
+
+/*
+ * Note header
+ */
+typedef struct {
+ Elf32_Word n_namesz;
+ Elf32_Word n_descsz;
+ Elf32_Word n_type;
+} Elf32_Nhdr;
+
+typedef struct {
+ Elf64_Word n_namesz;
+ Elf64_Word n_descsz;
+ Elf64_Word n_type;
+} Elf64_Nhdr;
+
+/*
+ * Note Definitions
+ */
+typedef struct {
+ Elf32_Word namesz;
+ Elf32_Word descsz;
+ Elf32_Word type;
+} Elf32_Note;
+
+typedef struct {
+ Elf64_Word namesz;
+ Elf64_Word descsz;
+ Elf64_Word type;
+} Elf64_Note;
+
+/* Values for n_type. */
+#define NT_PRSTATUS 1 /* Process status. */
+#define NT_FPREGSET 2 /* Floating point registers. */
+#define NT_PRPSINFO 3 /* Process state info. */
+
+/*
+ * OpenBSD-specific core file information.
+ *
+ * OpenBSD ELF core files use notes to provide information about
+ * the process's state. The note name is "OpenBSD" for information
+ * that is global to the process, and "OpenBSD@nn", where "nn" is the
+ * thread ID of the thread that the information belongs to (such as
+ * register state).
+ *
+ * We use the following note identifiers:
+ *
+ * NT_OPENBSD_PROCINFO
+ * Note is a "elfcore_procinfo" structure.
+ * NT_OPENBSD_AUXV
+ * Note is a a bunch of Auxilliary Vectors, terminated by
+ * an AT_NULL entry.
+ * NT_OPENBSD_REGS
+ * Note is a "reg" structure.
+ * NT_OPENBSD_FPREGS
+ * Note is a "fpreg" structure.
+ *
+ * Please try to keep the members of the "elfcore_procinfo" structure
+ * nicely aligned, and if you add elements, add them to the end and
+ * bump the version.
+ */
+
+#define NT_OPENBSD_PROCINFO 10
+#define NT_OPENBSD_AUXV 11
+
+#define NT_OPENBSD_REGS 20
+#define NT_OPENBSD_FPREGS 21
+#define NT_OPENBSD_XFPREGS 22
+#define NT_OPENBSD_WCOOKIE 23
+
+struct elfcore_procinfo {
+ /* Version 1 fields start here. */
+ uint32_t cpi_version; /* netbsd_elfcore_procinfo version */
+#define ELFCORE_PROCINFO_VERSION 1
+ uint32_t cpi_cpisize; /* sizeof(netbsd_elfcore_procinfo) */
+ uint32_t cpi_signo; /* killing signal */
+ uint32_t cpi_sigcode; /* signal code */
+ uint32_t cpi_sigpend; /* pending signals */
+ uint32_t cpi_sigmask; /* blocked signals */
+ uint32_t cpi_sigignore; /* ignored signals */
+ uint32_t cpi_sigcatch; /* signals being caught by user */
+ int32_t cpi_pid; /* process ID */
+ int32_t cpi_ppid; /* parent process ID */
+ int32_t cpi_pgrp; /* process group ID */
+ int32_t cpi_sid; /* session ID */
+ uint32_t cpi_ruid; /* real user ID */
+ uint32_t cpi_euid; /* effective user ID */
+ uint32_t cpi_svuid; /* saved user ID */
+ uint32_t cpi_rgid; /* real group ID */
+ uint32_t cpi_egid; /* effective group ID */
+ uint32_t cpi_svgid; /* saved group ID */
+ int8_t cpi_name[32]; /* copy of pr->ps_comm */
+};
+
+/*
+ * XXX - these _KERNEL items aren't part of the ABI!
+ */
+#if defined(_KERNEL) || defined(_DYN_LOADER)
+
+#define ELF32_NO_ADDR ((uint32_t) ~0) /* Indicates addr. not yet filled in */
+
+typedef struct {
+ Elf32_Sword au_id; /* 32-bit id */
+ Elf32_Word au_v; /* 32-bit value */
+} Aux32Info;
+
+#define ELF64_NO_ADDR ((__uint64_t) ~0)/* Indicates addr. not yet filled in */
+
+typedef struct {
+ Elf64_Shalf au_id; /* 32-bit id */
+ Elf64_Xword au_v; /* 64-bit value */
+} Aux64Info;
+
+enum AuxID {
+ AUX_null = 0,
+ AUX_ignore = 1,
+ AUX_execfd = 2,
+ AUX_phdr = 3, /* &phdr[0] */
+ AUX_phent = 4, /* sizeof(phdr[0]) */
+ AUX_phnum = 5, /* # phdr entries */
+ AUX_pagesz = 6, /* PAGESIZE */
+ AUX_base = 7, /* ld.so base addr */
+ AUX_flags = 8, /* processor flags */
+ AUX_entry = 9, /* a.out entry */
+ AUX_sun_uid = 2000, /* euid */
+ AUX_sun_ruid = 2001, /* ruid */
+ AUX_sun_gid = 2002, /* egid */
+ AUX_sun_rgid = 2003 /* rgid */
+};
+
+struct elf_args {
+ u_long arg_entry; /* program entry point */
+ u_long arg_interp; /* Interpreter load address */
+ u_long arg_phaddr; /* program header address */
+ u_long arg_phentsize; /* Size of program header */
+ u_long arg_phnum; /* Number of program headers */
+};
+
+#endif
+
+#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#if defined(ELFSIZE)
+#define CONCAT(x,y) __CONCAT(x,y)
+#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
+#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
+#endif
+
+#if defined(ELFSIZE) && (ELFSIZE == 32)
+#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Phdr Elf32_Phdr
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Rel Elf32_Rel
+#define Elf_RelA Elf32_Rela
+#define Elf_Dyn Elf32_Dyn
+#define Elf_Half Elf32_Half
+#define Elf_Word Elf32_Word
+#define Elf_Sword Elf32_Sword
+#define Elf_Addr Elf32_Addr
+#define Elf_Off Elf32_Off
+#define Elf_Nhdr Elf32_Nhdr
+#define Elf_Note Elf32_Note
+
+#define ELF_R_SYM ELF32_R_SYM
+#define ELF_R_TYPE ELF32_R_TYPE
+#define ELF_R_INFO ELF32_R_INFO
+#define ELFCLASS ELFCLASS32
+
+#define ELF_ST_BIND ELF32_ST_BIND
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#define ELF_ST_INFO ELF32_ST_INFO
+
+#define ELF_NO_ADDR ELF32_NO_ADDR
+#define AuxInfo Aux32Info
+#elif defined(ELFSIZE) && (ELFSIZE == 64)
+#define Elf_Ehdr Elf64_Ehdr
+#define Elf_Phdr Elf64_Phdr
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Rel Elf64_Rel
+#define Elf_RelA Elf64_Rela
+#define Elf_Dyn Elf64_Dyn
+#define Elf_Half Elf64_Half
+#define Elf_Word Elf64_Word
+#define Elf_Sword Elf64_Sword
+#define Elf_Addr Elf64_Addr
+#define Elf_Off Elf64_Off
+#define Elf_Nhdr Elf64_Nhdr
+#define Elf_Note Elf64_Note
+
+#define ELF_R_SYM ELF64_R_SYM
+#define ELF_R_TYPE ELF64_R_TYPE
+#define ELF_R_INFO ELF64_R_INFO
+#define ELFCLASS ELFCLASS64
+
+#define ELF_ST_BIND ELF64_ST_BIND
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#define ELF_ST_INFO ELF64_ST_INFO
+
+#define ELF_NO_ADDR ELF64_NO_ADDR
+#define AuxInfo Aux64Info
+#endif
+
+#ifndef _KERNEL
+extern Elf_Dyn _DYNAMIC[];
+#endif
+
+#ifdef _KERNEL
+struct exec_package;
+
+int exec_elf_makecmds(struct proc *, struct exec_package *);
+#endif /* _KERNEL */
+
+#define ELF_TARG_VER 1 /* The ver for which this code is intended */
+
+#endif /* _SYS_EXEC_ELF_H_ */
diff --git a/sys/sys/exec_script.h b/sys/sys/exec_script.h
new file mode 100644
index 0000000..4f099a5
--- /dev/null
+++ b/sys/sys/exec_script.h
@@ -0,0 +1,43 @@
+/* $OpenBSD: exec_script.h,v 1.6 2018/02/07 20:31:57 tedu Exp $ */
+/* $NetBSD: exec_script.h,v 1.6 1995/03/26 20:24:11 jtc 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.
+ */
+
+#define EXEC_SCRIPT_MAGIC "#!"
+#define EXEC_SCRIPT_MAGICLEN 2
+#define EXEC_SCRIPT_HDRSZ (EXEC_SCRIPT_MAGICLEN + 1 + MAXINTERP + 1)
+
+#ifdef _KERNEL
+
+/* the shell script handler's entry in the exec switch */
+int exec_script_makecmds(struct proc *, struct exec_package *);
+
+#endif /* _KERNEL */
diff --git a/sys/sys/extent.h b/sys/sys/extent.h
new file mode 100644
index 0000000..21be296
--- /dev/null
+++ b/sys/sys/extent.h
@@ -0,0 +1,130 @@
+/* $OpenBSD: extent.h,v 1.14 2014/02/08 20:29:01 kettenis Exp $ */
+/* $NetBSD: extent.h,v 1.6 1997/10/09 07:43:05 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 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_EXTENT_H_
+#define _SYS_EXTENT_H_
+
+#include <sys/queue.h>
+
+struct extent_region {
+ LIST_ENTRY(extent_region) er_link; /* link in region list */
+ u_long er_start; /* start of region */
+ u_long er_end; /* end of region */
+ int er_flags; /* misc. flags */
+};
+
+/* er_flags */
+#define ER_ALLOC 0x01 /* region descriptor dynamically allocated */
+#define ER_DISCARD 0x02 /* discard region descriptor after use */
+
+struct extent {
+ char *ex_name; /* name of extent */
+ /* allocated regions in extent */
+ LIST_HEAD(, extent_region) ex_regions;
+ u_long ex_start; /* start of extent */
+ u_long ex_end; /* end of extent */
+ int ex_mtype; /* memory type */
+ int ex_flags; /* misc. information */
+
+ LIST_ENTRY(extent) ex_link;
+};
+
+struct extent_fixed {
+ struct extent fex_extent; /* MUST BE FIRST */
+ /* freelist of region descriptors */
+ LIST_HEAD(, extent_region) fex_freelist;
+ caddr_t fex_storage; /* storage space for descriptors */
+ size_t fex_storagesize; /* size of storage space */
+};
+
+/* ex_flags; for internal use only */
+#define EXF_FIXED 0x01 /* extent uses fixed storage */
+#define EXF_NOCOALESCE 0x02 /* coalescing of regions not allowed */
+#define EXF_WANTED 0x04 /* someone asleep on extent */
+#define EXF_FLWANTED 0x08 /* someone asleep on freelist */
+
+#define EXF_BITS "\20\4FLWANTED\3WANTED\2NOCOALESCE\1FIXED"
+
+/* misc. flags passed to extent functions */
+#define EX_NOWAIT 0x0000 /* not safe to sleep */
+#define EX_WAITOK 0x0001 /* safe to sleep */
+#define EX_FAST 0x0002 /* take first fit in extent_alloc() */
+#define EX_CATCH 0x0004 /* catch signals while sleeping */
+#define EX_NOCOALESCE 0x0008 /* create a non-coalescing extent */
+#define EX_MALLOCOK 0x0010 /* safe to call malloc() */
+#define EX_WAITSPACE 0x0020 /* wait for space to become free */
+#define EX_BOUNDZERO 0x0040 /* boundary lines start at 0 */
+#define EX_CONFLICTOK 0x0080 /* allow conflicts */
+#define EX_FILLED 0x0100 /* create a filled extent */
+
+/*
+ * Special place holders for "alignment" and "boundary" arguments,
+ * in the event the caller doesn't wish to use those features.
+ */
+#define EX_NOALIGN 1 /* don't do alignment */
+#define EX_NOBOUNDARY 0 /* don't do boundary checking */
+
+#if defined(_KERNEL) || defined(_EXTENT_TESTING)
+#define EXTENT_FIXED_STORAGE_SIZE(_nregions) \
+ (ALIGN(sizeof(struct extent_fixed)) + \
+ ((ALIGN(sizeof(struct extent_region))) * \
+ (_nregions)))
+
+void extent_print_all(void);
+
+struct extent *extent_create(char *, u_long, u_long, int,
+ caddr_t, size_t, int);
+void extent_destroy(struct extent *);
+int extent_alloc_subregion(struct extent *, u_long, u_long,
+ u_long, u_long, u_long, u_long, int, u_long *);
+int extent_alloc_subregion_with_descr(struct extent *, u_long, u_long,
+ u_long, u_long, u_long, u_long, int, struct extent_region *,
+ u_long *);
+int extent_alloc_region(struct extent *, u_long, u_long, int);
+int extent_free(struct extent *, u_long, u_long, int);
+void extent_print(struct extent *);
+
+/* Simple case of extent_alloc_subregion() */
+#define extent_alloc(_ex, _size, _alignment, _skew, _boundary, \
+ _flags, _result) \
+ extent_alloc_subregion((_ex), (_ex)->ex_start, (_ex)->ex_end, \
+ (_size), (_alignment), (_skew), (_boundary), (_flags), (_result))
+
+/* Simple case of extent_alloc_subregion_with_descr() */
+#define extent_alloc_with_descr(_ex, _size, _alignment, _skew, _boundary, \
+ _flags, _region, _result) \
+ extent_alloc_subregion_with_descr((_ex), (_ex)->ex_start, \
+ (_ex)->ex_end, (_size), (_alignment), (_skew), (_boundary), \
+ (_flags), (_region), (_result))
+#endif /* _KERNEL || _EXTENT_TESTING */
+
+#endif /* ! _SYS_EXTENT_H_ */
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
new file mode 100644
index 0000000..e964ea4
--- /dev/null
+++ b/sys/sys/fcntl.h
@@ -0,0 +1,220 @@
+/* $OpenBSD: fcntl.h,v 1.22 2019/01/21 18:09:21 anton Exp $ */
+/* $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1983, 1990, 1993
+ * 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.
+ *
+ * @(#)fcntl.h 8.3 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_FCNTL_H_
+#define _SYS_FCNTL_H_
+
+/*
+ * This file includes the definitions for open and fcntl
+ * described by POSIX for <fcntl.h>; it also includes
+ * related kernel definitions.
+ */
+
+#include <sys/cdefs.h>
+#ifndef _KERNEL
+#include <sys/types.h>
+#endif
+
+/*
+ * 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 0x0000 /* open for reading only */
+#define O_WRONLY 0x0001 /* open for writing only */
+#define O_RDWR 0x0002 /* open for reading and writing */
+#define O_ACCMODE 0x0003 /* mask for above modes */
+
+/*
+ * Kernel encoding of open mode; separate read and write bits that are
+ * independently testable: 1 greater than the above.
+ *
+ * XXX
+ * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
+ * which was documented to use FREAD/FWRITE, continues to work.
+ */
+#if __BSD_VISIBLE
+#define FREAD 0x0001
+#define FWRITE 0x0002
+#endif
+#define O_NONBLOCK 0x0004 /* no delay */
+#define O_APPEND 0x0008 /* set append mode */
+#if __BSD_VISIBLE
+#define O_SHLOCK 0x0010 /* open with shared file lock */
+#define O_EXLOCK 0x0020 /* open with exclusive file lock */
+#define O_ASYNC 0x0040 /* signal pgrp when data ready */
+#define O_FSYNC 0x0080 /* backwards compatibility */
+#define O_NOFOLLOW 0x0100 /* if path is a symlink, don't follow */
+#endif
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 420
+#define O_SYNC 0x0080 /* synchronous writes */
+#endif
+#define O_CREAT 0x0200 /* create if nonexistent */
+#define O_TRUNC 0x0400 /* truncate to zero length */
+#define O_EXCL 0x0800 /* error if already exists */
+
+/*
+ * POSIX 1003.1 specifies a higher granularity for synchronous operations
+ * than we support. Since synchronicity is all or nothing in OpenBSD
+ * we just define these to be the same as O_SYNC.
+ */
+#define O_DSYNC O_SYNC /* synchronous data writes */
+#define O_RSYNC O_SYNC /* synchronous reads */
+
+/* defined by POSIX 1003.1; BSD default, this bit is not required */
+#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
+
+/* defined by POSIX Issue 7 */
+#define O_CLOEXEC 0x10000 /* atomically set FD_CLOEXEC */
+#define O_DIRECTORY 0x20000 /* fail if not a directory */
+
+#ifdef _KERNEL
+/*
+ * convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE.
+ * For out-of-range values for the flags, be slightly careful (but lossy).
+ */
+#define FFLAGS(oflags) (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE))
+#define OFLAGS(fflags) (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE))
+
+/* bits to save after open */
+#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
+/* bits settable by fcntl(F_SETFL, ...) */
+#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
+#endif
+
+/*
+ * The O_* flags used to have only F* names, which were used in the kernel
+ * and by fcntl. We retain the F* names for the kernel f_flags field
+ * and for backward compatibility for fcntl.
+ */
+#if __BSD_VISIBLE
+#define FAPPEND O_APPEND /* kernel/compat */
+#define FASYNC O_ASYNC /* kernel/compat */
+#define FFSYNC O_SYNC /* kernel */
+#define FNONBLOCK O_NONBLOCK /* kernel */
+#define FNDELAY O_NONBLOCK /* compat */
+#define O_NDELAY O_NONBLOCK /* compat */
+#endif
+
+/*
+ * Constants used for fcntl(2)
+ */
+
+/* command values */
+#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 */
+#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 500
+#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
+#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
+#endif
+#define F_GETLK 7 /* get record locking information */
+#define F_SETLK 8 /* set record locking information */
+#define F_SETLKW 9 /* F_SETLK; wait if blocked */
+#if __POSIX_VISIBLE >= 200809
+#define F_DUPFD_CLOEXEC 10 /* duplicate with FD_CLOEXEC set */
+#endif
+#if __BSD_VISIBLE
+#define F_ISATTY 11 /* used by isatty(3) */
+#endif
+
+/* file descriptor flags (F_GETFD, F_SETFD) */
+#define FD_CLOEXEC 1 /* close-on-exec flag */
+
+/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
+#define F_RDLCK 1 /* shared or read lock */
+#define F_UNLCK 2 /* unlock */
+#define F_WRLCK 3 /* exclusive or write lock */
+#ifdef _KERNEL
+#define F_WAIT 0x010 /* Wait until lock is granted */
+#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */
+#define F_POSIX 0x040 /* Use POSIX semantics for lock */
+#define F_INTR 0x080 /* Lock operation interrupted */
+#endif
+
+/*
+ * Advisory file segment locking data type -
+ * information passed to system by user
+ */
+struct flock {
+ off_t l_start; /* starting offset */
+ off_t l_len; /* len = 0 means until end of file */
+ pid_t l_pid; /* lock owner */
+ short l_type; /* lock type: read/write, etc. */
+ short l_whence; /* type of l_start */
+};
+
+
+#if __BSD_VISIBLE
+/* lock operations for flock(2) */
+#define LOCK_SH 0x01 /* shared file lock */
+#define LOCK_EX 0x02 /* exclusive file lock */
+#define LOCK_NB 0x04 /* don't block when locking */
+#define LOCK_UN 0x08 /* unlock file */
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#define AT_FDCWD -100
+
+#define AT_EACCESS 0x01
+#define AT_SYMLINK_NOFOLLOW 0x02
+#define AT_SYMLINK_FOLLOW 0x04
+#define AT_REMOVEDIR 0x08
+#endif
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int open(const char *, int, ...);
+int creat(const char *, mode_t);
+int fcntl(int, int, ...);
+#if __BSD_VISIBLE
+int flock(int, int);
+#endif
+#if __POSIX_VISIBLE >= 200809
+int openat(int, const char *, int, ...);
+#endif
+__END_DECLS
+#endif
+
+#endif /* !_SYS_FCNTL_H_ */
diff --git a/sys/sys/file.h b/sys/sys/file.h
new file mode 100644
index 0000000..f638c15
--- /dev/null
+++ b/sys/sys/file.h
@@ -0,0 +1,136 @@
+/* $OpenBSD: file.h,v 1.61 2020/03/13 10:07:01 anton Exp $ */
+/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
+
+/*
+ * 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.2 (Berkeley) 8/20/94
+ */
+
+#ifndef _KERNEL
+#include <sys/fcntl.h>
+
+#else /* _KERNEL */
+#include <sys/queue.h>
+#include <sys/mutex.h>
+
+struct proc;
+struct uio;
+struct knote;
+struct stat;
+struct file;
+struct ucred;
+
+/**
+ * File operations.
+ * The following entries could be called without KERNEL_LOCK hold:
+ * - fo_read
+ * - fo_write
+ * - fo_close
+ */
+struct fileops {
+ int (*fo_read)(struct file *, struct uio *, int);
+ int (*fo_write)(struct file *, struct uio *, int);
+ int (*fo_ioctl)(struct file *, u_long, caddr_t, struct proc *);
+ int (*fo_poll)(struct file *, int, struct proc *);
+ int (*fo_kqfilter)(struct file *, struct knote *);
+ int (*fo_stat)(struct file *, struct stat *, struct proc *);
+ int (*fo_close)(struct file *, struct proc *);
+ int (*fo_seek)(struct file *, off_t *, int, struct proc *);
+};
+#define FO_POSITION 0x00000001 /* positioned read/write */
+
+/*
+ * Kernel descriptor table.
+ * One entry for each open kernel vnode and socket.
+ *
+ * Locks used to protect struct members in this file:
+ * I immutable after creation
+ * F global `fhdlk' mutex
+ * a atomic operations
+ * f per file `f_mtx'
+ * v vnode lock
+ */
+struct file {
+ LIST_ENTRY(file) f_list;/* [F] list of active files */
+ struct mutex f_mtx;
+ u_int f_flag; /* [a] see fcntl.h */
+#define DTYPE_VNODE 1 /* file */
+#define DTYPE_SOCKET 2 /* communications endpoint */
+#define DTYPE_PIPE 3 /* pipe */
+#define DTYPE_KQUEUE 4 /* event queue */
+#define DTYPE_DMABUF 5 /* DMA buffer (for DRM) */
+ u_int f_iflags; /* [a] internal flags */
+ int f_type; /* [I] descriptor type */
+ u_int f_count; /* [a] reference count */
+ struct ucred *f_cred; /* [I] credentials associated with descriptor */
+ const struct fileops *f_ops; /* [I] file operation pointers */
+ off_t f_offset; /* [f,v] offset */
+ void *f_data; /* [I] private data */
+ uint64_t f_rxfer; /* [f] total number of read transfers */
+ uint64_t f_wxfer; /* [f] total number of write transfers */
+ uint64_t f_seek; /* [f] total independent seek operations */
+ uint64_t f_rbytes; /* [f] total bytes read */
+ uint64_t f_wbytes; /* [f] total bytes written */
+};
+
+#define FIF_HASLOCK 0x01 /* descriptor holds advisory lock */
+#define FIF_INSERTED 0x80 /* present in `filehead' */
+
+#define FREF(fp) \
+ do { \
+ extern void vfs_stall_barrier(void); \
+ vfs_stall_barrier(); \
+ atomic_inc_int(&(fp)->f_count); \
+ } while (0)
+
+#define FRELE(fp,p) \
+ (atomic_dec_int_nv(&fp->f_count) == 0 ? fdrop(fp, p) : 0)
+
+#define FDUP_MAX_COUNT (UINT_MAX - 2 * MAXCPUS)
+
+int fdrop(struct file *, struct proc *);
+
+static inline off_t
+foffset(struct file *fp)
+{
+ off_t offset;
+
+ mtx_enter(&fp->f_mtx);
+ offset = fp->f_offset;
+ mtx_leave(&fp->f_mtx);
+ return (offset);
+}
+
+LIST_HEAD(filelist, file);
+extern int maxfiles; /* kernel limit on number of open files */
+extern int numfiles; /* actual number of open files */
+extern const struct fileops socketops; /* socket operations for files */
+extern const struct fileops vnops; /* vnode operations for files */
+
+#endif /* _KERNEL */
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
new file mode 100644
index 0000000..ef784f7
--- /dev/null
+++ b/sys/sys/filedesc.h
@@ -0,0 +1,157 @@
+/* $OpenBSD: filedesc.h,v 1.44 2020/01/30 15:33:04 visa Exp $ */
+/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd 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.
+ *
+ * @(#)filedesc.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/mutex.h>
+#include <sys/rwlock.h>
+/*
+ * This structure is used for the management of descriptors. It may be
+ * shared by multiple processes.
+ *
+ * A process is initially started out with NDFILE descriptors stored within
+ * this structure, selected to be enough for typical applications based on
+ * the historical limit of 20 open files (and the usage of descriptors by
+ * shells). If these descriptors are exhausted, a larger descriptor table
+ * may be allocated, up to a process' resource limit; the internal arrays
+ * are then unused. The initial expansion is set to NDEXTENT; each time
+ * it runs out, it is doubled until the resource limit is reached. NDEXTENT
+ * should be selected to be the biggest multiple of OFILESIZE (see below)
+ * that will fit in a power-of-two sized piece of memory.
+ */
+#define NDFILE 20
+#define NDEXTENT 50 /* 250 bytes in 256-byte alloc. */
+#define NDENTRIES 32 /* 32 fds per entry */
+#define NDENTRYMASK (NDENTRIES - 1)
+#define NDENTRYSHIFT 5 /* bits per entry */
+#define NDREDUCE(x) (((x) + NDENTRIES - 1) >> NDENTRYSHIFT)
+#define NDHISLOTS(x) (NDREDUCE(NDREDUCE(x)))
+#define NDLOSLOTS(x) (NDHISLOTS(x) << NDENTRYSHIFT)
+
+struct kqueue;
+
+/*
+ * Locking:
+ * a atomic operations
+ * f fd_lock
+ * f/w fd_lock when writing
+ * k kernel lock
+ * m fd_fplock
+ */
+struct filedesc {
+ struct file **fd_ofiles; /* [f/w,m] file structures for
+ * open files */
+ char *fd_ofileflags; /* [f] per-process open file flags */
+ struct vnode *fd_cdir; /* [k] current directory */
+ struct vnode *fd_rdir; /* [k] root directory */
+ int fd_nfiles; /* [f] number of open files allocated */
+ int fd_openfd; /* [f] number of files currently open */
+ u_int *fd_himap; /* [f] each bit points to 32 fds */
+ u_int *fd_lomap; /* [f] bitmap of free fds */
+ int fd_lastfile; /* [f] high-water mark of fd_ofiles */
+ int fd_freefile; /* [f] approx. next free file */
+ u_short fd_cmask; /* [f/w] mask for file creation */
+ u_short fd_refcnt; /* [k] reference count */
+ struct rwlock fd_lock; /* lock for the file descs */
+ struct mutex fd_fplock; /* lock for reading fd_ofiles without
+ * fd_lock */
+ LIST_HEAD(, kqueue) fd_kqlist; /* [f] kqueues attached to this
+ * filedesc */
+ int fd_flags; /* [a] flags on this filedesc */
+};
+
+/*
+ * Basic allocation of descriptors:
+ * one of the above, plus arrays for NDFILE descriptors.
+ */
+struct filedesc0 {
+ struct filedesc fd_fd;
+ /*
+ * These arrays are used when the number of open files is
+ * <= NDFILE, and are then pointed to by the pointers above.
+ */
+ struct file *fd_dfiles[NDFILE];
+ char fd_dfileflags[NDFILE];
+ /*
+ * There arrays are used when the number of open files is
+ * <= 1024, and are then pointed to by the pointers above.
+ */
+ u_int fd_dhimap[NDENTRIES >> NDENTRYSHIFT];
+ u_int fd_dlomap[NDENTRIES];
+};
+
+/*
+ * Per-process open flags.
+ */
+#define UF_EXCLOSE 0x01 /* auto-close on exec */
+#define UF_PLEDGED 0x02 /* open after pledge(2) */
+
+/*
+ * Flags on the file descriptor table.
+ */
+#define FD_ADVLOCK 0x01 /* May hold a POSIX adv. lock. */
+
+/*
+ * Storage required per open file descriptor.
+ */
+#define OFILESIZE (sizeof(struct file *) + sizeof(char))
+
+#ifdef _KERNEL
+/*
+ * Kernel global variables and routines.
+ */
+void filedesc_init(void);
+int dupfdopen(struct proc *, int, int);
+int fdalloc(struct proc *p, int want, int *result);
+void fdexpand(struct proc *);
+struct file *fnew(struct proc *_p);
+int falloc(struct proc *_p, struct file **_rfp, int *_rfd);
+struct filedesc *fdinit(void);
+struct filedesc *fdshare(struct process *);
+struct filedesc *fdcopy(struct process *);
+void fdfree(struct proc *p);
+int fdrelease(struct proc *p, int);
+void fdinsert(struct filedesc *, int, int, struct file *);
+void fdremove(struct filedesc *, int);
+void fdcloseexec(struct proc *);
+struct file *fd_iterfile(struct file *, struct proc *);
+struct file *fd_getfile(struct filedesc *, int);
+struct file *fd_getfile_mode(struct filedesc *, int, int);
+int fd_checkclosed(struct filedesc *, int, struct file *);
+
+int closef(struct file *, struct proc *);
+int getsock(struct proc *, int, struct file **);
+
+#define fdplock(fdp) do { NET_ASSERT_UNLOCKED(); rw_enter_write(&(fdp)->fd_lock); } while (0)
+#define fdpunlock(fdp) rw_exit_write(&(fdp)->fd_lock)
+#define fdpassertlocked(fdp) rw_assert_wrlock(&(fdp)->fd_lock)
+#endif
diff --git a/sys/sys/filio.h b/sys/sys/filio.h
new file mode 100644
index 0000000..19fd805
--- /dev/null
+++ b/sys/sys/filio.h
@@ -0,0 +1,54 @@
+/* $OpenBSD: filio.h,v 1.5 2007/06/01 22:30:48 deraadt Exp $ */
+/* $NetBSD: filio.h,v 1.5 1994/06/29 06:44:14 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 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.
+ *
+ * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
+
+#include <sys/ioccom.h>
+
+/* Generic file-descriptor ioctl's. */
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+
+#endif /* !_SYS_FILIO_H_ */
diff --git a/sys/sys/fusebuf.h b/sys/sys/fusebuf.h
new file mode 100644
index 0000000..8706605
--- /dev/null
+++ b/sys/sys/fusebuf.h
@@ -0,0 +1,148 @@
+/* $OpenBSD: fusebuf.h,v 1.13 2018/06/19 11:27:54 helg Exp $ */
+/*
+ * Copyright (c) 2013 Sylvestre Gallon
+ * Copyright (c) 2013 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_FUSEBUF_H_
+#define _SYS_FUSEBUF_H_
+
+/*
+ * Fusebufs are of a single size, 4096 bytes.
+ */
+#define FUSEBUFSIZE (sizeof(struct fusebuf))
+#define FUSEBUFMAXSIZE (4096*1024)
+
+/* header at beginning of each fusebuf: */
+struct fb_hdr {
+ SIMPLEQ_ENTRY(fusebuf) fh_next; /* next buffer in chain */
+ size_t fh_len; /* Amount of data */
+ int fh_err; /* errno to pass back */
+ int fh_type; /* type of data */
+ ino_t fh_ino; /* Inode of this fusebuf */
+ uint64_t fh_uuid; /* Uuid to track the answer */
+ pid_t fh_tid; /* calling proc thread id */
+ uid_t fh_uid; /* calling proc uid */
+ gid_t fh_gid; /* calling proc gid */
+ mode_t fh_umask; /* calling proc umask */
+};
+
+/* header for fuse file operations (like read/write/mkdir): */
+struct fb_io {
+ uint64_t fi_fd; /* fd where the io is performed */
+ ino_t fi_ino; /* ino for the io */
+ off_t fi_off; /* offset for the io */
+ size_t fi_len; /* Length of data */
+ mode_t fi_mode; /* mode for fd */
+ uint32_t fi_flags; /* flags on transfer */
+ dev_t fi_rdev; /* dev for mknod */
+};
+
+/*
+ * An operation is issued by the kernel through fuse(4) when the
+ * userland file system needs to execute an action (mkdir(2),
+ * link(2), etc).
+ *
+ * F_databuf can be superior to FUSELEN for fusefs_read, fusefs_writes and
+ * fusefs_readdir. If it is the case the transfer will be split in N
+ * fusebuf with a changing offset in FD_io.
+ *
+ * When the userland file system answers to this operation it uses
+ * the same ID (fh_uuid).
+ */
+struct fusebuf {
+ struct fb_hdr fb_hdr;
+ union {
+ struct statvfs FD_stat; /* vfs statfs */
+ struct stat FD_attr; /* for attr vnops */
+ struct fb_io FD_io; /* for file io vnops */
+ } FD;
+ uint8_t *fb_dat; /* data's */
+};
+
+#define fb_next fb_hdr.fh_next
+#define fb_len fb_hdr.fh_len
+#define fb_err fb_hdr.fh_err
+#define fb_type fb_hdr.fh_type
+#define fb_ino fb_hdr.fh_ino
+#define fb_uuid fb_hdr.fh_uuid
+#define fb_tid fb_hdr.fh_tid
+#define fb_uid fb_hdr.fh_uid
+#define fb_gid fb_hdr.fh_gid
+#define fb_umask fb_hdr.fh_umask
+
+#define fb_stat FD.FD_stat
+#define fb_attr FD.FD_attr
+#define fb_io_fd FD.FD_io.fi_fd
+#define fb_io_ino FD.FD_io.fi_ino
+#define fb_io_off FD.FD_io.fi_off
+#define fb_io_len FD.FD_io.fi_len
+#define fb_io_mode FD.FD_io.fi_mode
+#define fb_io_flags FD.FD_io.fi_flags
+#define fb_io_rdev FD.FD_io.fi_rdev
+
+/*
+ * Macros for type conversion
+ * fbtod(fb,t) - convert fusebuf pointer to data pointer of correct
+ * type
+ */
+#define fbtod(fb,t) ((t)((fb)->fb_dat))
+
+/* flags needed by setattr */
+#define FUSE_FATTR_MODE (1 << 0)
+#define FUSE_FATTR_UID (1 << 1)
+#define FUSE_FATTR_GID (1 << 2)
+#define FUSE_FATTR_SIZE (1 << 3)
+#define FUSE_FATTR_ATIME (1 << 4)
+#define FUSE_FATTR_MTIME (1 << 5)
+#define FUSE_FATTR_FH (1 << 6)
+
+/* fusebuf types */
+#define FBT_LOOKUP 0
+#define FBT_GETATTR 1
+#define FBT_SETATTR 2
+#define FBT_READLINK 3
+#define FBT_SYMLINK 4
+#define FBT_MKNOD 5
+#define FBT_MKDIR 6
+#define FBT_UNLINK 7
+#define FBT_RMDIR 8
+#define FBT_RENAME 9
+#define FBT_LINK 10
+#define FBT_OPEN 11
+#define FBT_READ 12
+#define FBT_WRITE 13
+#define FBT_STATFS 14
+#define FBT_RELEASE 16
+#define FBT_FSYNC 17
+#define FBT_FLUSH 18
+#define FBT_INIT 19
+#define FBT_OPENDIR 20
+#define FBT_READDIR 21
+#define FBT_RELEASEDIR 22
+#define FBT_FSYNCDIR 23
+#define FBT_ACCESS 24
+#define FBT_DESTROY 26
+#define FBT_RECLAIM 27
+
+#ifdef _KERNEL
+
+/* fusebuf prototypes */
+struct fusebuf *fb_setup(size_t, ino_t, int, struct proc *);
+int fb_queue(dev_t, struct fusebuf *);
+void fb_delete(struct fusebuf *);
+
+#endif /* _KERNEL */
+#endif /* _SYS_FUSEBUF_H_ */
diff --git a/sys/sys/futex.h b/sys/sys/futex.h
new file mode 100644
index 0000000..62e32c9
--- /dev/null
+++ b/sys/sys/futex.h
@@ -0,0 +1,41 @@
+/* $OpenBSD: futex.h,v 1.2 2018/06/03 15:09:26 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2016 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_FUTEX_H_
+#define _SYS_FUTEX_H_
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int futex(volatile uint32_t *, int, int, const struct timespec *,
+ volatile uint32_t *);
+__END_DECLS
+#endif /* ! _KERNEL */
+
+#define FUTEX_WAIT 1
+#define FUTEX_WAKE 2
+#define FUTEX_REQUEUE 3
+
+#define FUTEX_PRIVATE_FLAG 128
+
+#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
+#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
+
+#endif /* _SYS_FUTEX_H_ */
diff --git a/sys/sys/gmon.h b/sys/sys/gmon.h
new file mode 100644
index 0000000..1a63cb5
--- /dev/null
+++ b/sys/sys/gmon.h
@@ -0,0 +1,175 @@
+/* $OpenBSD: gmon.h,v 1.8 2016/05/07 19:30:52 guenther Exp $ */
+/* $NetBSD: gmon.h,v 1.5 1996/04/09 20:55:30 cgd 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 <machine/profile.h>
+
+/*
+ * 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
+ */
+#define HISTFRACTION 2
+
+/*
+ * 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;
+};
+
+/*
+ * general rounding functions.
+ */
+#define ROUNDDOWN(x,y) (((x)/(y))*(y))
+#define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
+
+/*
+ * 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;
+};
+
+/*
+ * 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) */
+
+#ifdef _KERNEL
+extern int gmoninit; /* Is the kernel ready for beeing profiled? */
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern struct gmonparam _gmonparam;
+void _mcleanup(void);
+void _monstartup(u_long, u_long);
+void moncontrol(int);
+void monstartup(u_long, u_long);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_GMON_H_ */
diff --git a/sys/sys/gpio.h b/sys/sys/gpio.h
new file mode 100644
index 0000000..95ce9cd
--- /dev/null
+++ b/sys/sys/gpio.h
@@ -0,0 +1,80 @@
+/* $OpenBSD: gpio.h,v 1.8 2011/10/03 20:24:51 matthieu Exp $ */
+/*
+ * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_GPIO_H_
+#define _SYS_GPIO_H_
+
+/* GPIO pin states */
+#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */
+#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */
+
+/* Max name length of a pin */
+#define GPIOPINMAXNAME 64
+
+/* GPIO pin configuration flags */
+#define GPIO_PIN_INPUT 0x0001 /* input direction */
+#define GPIO_PIN_OUTPUT 0x0002 /* output direction */
+#define GPIO_PIN_INOUT 0x0004 /* bi-directional */
+#define GPIO_PIN_OPENDRAIN 0x0008 /* open-drain output */
+#define GPIO_PIN_PUSHPULL 0x0010 /* push-pull output */
+#define GPIO_PIN_TRISTATE 0x0020 /* output disabled */
+#define GPIO_PIN_PULLUP 0x0040 /* internal pull-up enabled */
+#define GPIO_PIN_PULLDOWN 0x0080 /* internal pull-down enabled */
+#define GPIO_PIN_INVIN 0x0100 /* invert input */
+#define GPIO_PIN_INVOUT 0x0200 /* invert output */
+#define GPIO_PIN_USER 0x0400 /* user != 0 can access */
+#define GPIO_PIN_SET 0x8000 /* set for securelevel access */
+
+/* GPIO controller description */
+struct gpio_info {
+ int gpio_npins; /* total number of pins available */
+};
+
+/* GPIO pin operation (read/write/toggle) */
+struct gpio_pin_op {
+ char gp_name[GPIOPINMAXNAME]; /* pin name */
+ int gp_pin; /* pin number */
+ int gp_value; /* value */
+};
+
+/* GPIO pin configuration */
+struct gpio_pin_set {
+ char gp_name[GPIOPINMAXNAME];
+ int gp_pin;
+ int gp_caps;
+ int gp_flags;
+ char gp_name2[GPIOPINMAXNAME]; /* new name */
+};
+
+/* Attach/detach device drivers that use GPIO pins */
+struct gpio_attach {
+ char ga_dvname[16]; /* device name */
+ int ga_offset; /* pin number */
+ u_int32_t ga_mask; /* binary mask */
+ u_int32_t ga_flags; /* flags */
+};
+
+#define GPIOINFO _IOR('G', 0, struct gpio_info)
+#define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op)
+#define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op)
+#define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op)
+#define GPIOPINSET _IOWR('G', 4, struct gpio_pin_set)
+#define GPIOPINUNSET _IOWR('G', 5, struct gpio_pin_set)
+#define GPIOATTACH _IOWR('G', 6, struct gpio_attach)
+#define GPIODETACH _IOWR('G', 7, struct gpio_attach)
+
+#endif /* !_SYS_GPIO_H_ */
diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h
new file mode 100644
index 0000000..be09102
--- /dev/null
+++ b/sys/sys/hibernate.h
@@ -0,0 +1,159 @@
+/* $OpenBSD: hibernate.h,v 1.42 2018/06/21 07:33:30 mlarkin Exp $ */
+
+/*
+ * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_HIBERNATE_H_
+#define _SYS_HIBERNATE_H_
+
+#include <sys/types.h>
+#include <sys/tree.h>
+#include <lib/libz/zlib.h>
+#include <machine/vmparam.h>
+
+#define HIBERNATE_CHUNK_USED 1
+#define HIBERNATE_CHUNK_CONFLICT 2
+#define HIBERNATE_CHUNK_PLACED 4
+
+/* Magic number used to indicate hibernate signature block */
+#define HIBERNATE_MAGIC 0x0B5D0B5D
+
+/* Page skip operations used during unpack */
+#define HIB_MOVE 2
+#define HIB_SKIP 1
+
+struct hiballoc_entry;
+
+/*
+ * Allocator operates from an arena, that is pre-allocated by the caller.
+ */
+struct hiballoc_arena {
+ RBT_HEAD(hiballoc_addr, hiballoc_entry) hib_addrs;
+};
+
+/*
+ * Describes a zlib compression stream and its associated hiballoc area
+ */
+struct hibernate_zlib_state {
+ z_stream hib_stream;
+ struct hiballoc_arena hiballoc_arena;
+};
+
+/*
+ * Describes a range of physical memory on the machine
+ */
+struct hibernate_memory_range {
+ paddr_t base;
+ paddr_t end;
+};
+
+/*
+ * Describes a hibernate chunk structure, used when splitting the memory
+ * image of the machine into easy-to-manage pieces.
+ */
+struct hibernate_disk_chunk {
+ paddr_t base; /* Base of chunk */
+ paddr_t end; /* End of chunk */
+ daddr_t offset; /* Abs. disk block locating chunk */
+ size_t compressed_size; /* Compressed size on disk */
+ short flags; /* Flags */
+};
+
+#define HIB_INIT -1
+#define HIB_DONE -2
+#define HIB_R 0
+#define HIB_W 1
+typedef int (*hibio_fn)(dev_t, daddr_t, vaddr_t, size_t, int, void *);
+
+/*
+ * Used to store information about the hibernation state of the machine,
+ * such as memory range count and extents, disk sector size, and various
+ * offsets where things are located on disk.
+ */
+union hibernate_info {
+ struct {
+ u_int32_t magic;
+ size_t nranges;
+ struct hibernate_memory_range ranges[VM_PHYSSEG_MAX];
+ size_t image_size;
+ size_t chunk_ctr;
+ dev_t dev;
+ daddr_t sig_offset;
+ daddr_t chunktable_offset;
+ daddr_t image_offset;
+ paddr_t piglet_pa;
+ vaddr_t piglet_va;
+ char kernel_version[128];
+ u_int32_t kernel_sum;
+ hibio_fn io_func;
+ void *io_page;
+#ifndef NO_PROPOLICE
+ long guard;
+#endif /* ! NO_PROPOLICE */
+ u_int32_t retguard_ofs;
+ };
+
+ /* XXX - remove restriction to have this union fit in a single block */
+ char pad[512]; /* Pad to 512 bytes */
+};
+
+void *hib_alloc(struct hiballoc_arena*, size_t);
+void hib_free(struct hiballoc_arena*, void*);
+int hiballoc_init(struct hiballoc_arena*, void*, size_t len);
+void uvm_pmr_zero_everything(void);
+void uvm_pmr_dirty_everything(void);
+int uvm_pmr_alloc_pig(paddr_t*, psize_t, paddr_t);
+int uvm_pmr_alloc_piglet(vaddr_t*, paddr_t*, vsize_t, paddr_t);
+void uvm_pmr_free_piglet(vaddr_t, vsize_t);
+int uvm_page_rle(paddr_t);
+void uvmpd_hibernate(void);
+
+hibio_fn get_hibernate_io_function(dev_t);
+int get_hibernate_info(union hibernate_info *, int);
+
+int hibernate_zlib_reset(union hibernate_info *, int);
+void *hibernate_zlib_alloc(void *, int, int);
+void hibernate_zlib_free(void *, void *);
+void hibernate_inflate_region(union hibernate_info *, paddr_t, paddr_t,
+ size_t);
+size_t hibernate_deflate(union hibernate_info *, paddr_t, size_t *);
+void hibernate_process_chunk(union hibernate_info *,
+ struct hibernate_disk_chunk *, paddr_t);
+int hibernate_inflate_page(int *);
+
+int hibernate_block_io(union hibernate_info *, daddr_t, size_t, vaddr_t, int);
+int hibernate_write_signature(union hibernate_info *);
+int hibernate_write_chunktable(union hibernate_info *);
+int hibernate_write_chunks(union hibernate_info *);
+int hibernate_clear_signature(void);
+int hibernate_compare_signature(union hibernate_info *,
+ union hibernate_info *);
+void hibernate_resume(void);
+int hibernate_suspend(void);
+int hibernate_read_image(union hibernate_info *);
+int hibernate_read_chunks(union hibernate_info *, paddr_t, paddr_t, size_t,
+ struct hibernate_disk_chunk *);
+void hibernate_unpack_image(union hibernate_info *);
+void hibernate_populate_resume_pt(union hibernate_info *, paddr_t, paddr_t);
+int hibernate_alloc(void);
+void hibernate_free(void);
+void hib_getentropy(char **, size_t *);
+
+void hibernate_sort_ranges(union hibernate_info *);
+void hibernate_suspend_bufcache(void);
+void hibernate_resume_bufcache(void);
+
+#endif /* _SYS_HIBERNATE_H_ */
diff --git a/sys/sys/hotplug.h b/sys/sys/hotplug.h
new file mode 100644
index 0000000..f2da3f6
--- /dev/null
+++ b/sys/sys/hotplug.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: hotplug.h,v 1.5 2006/05/28 16:52:34 mk Exp $ */
+/*
+ * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_HOTPLUG_H_
+#define _SYS_HOTPLUG_H_
+
+/*
+ * Public interface for enqueuing and dequeueing device
+ * attachment and detachment notifications.
+ */
+
+#define HOTPLUG_DEVAT 0x01 /* device attached */
+#define HOTPLUG_DEVDT 0x02 /* device detached */
+
+struct hotplug_event {
+ int he_type; /* event type */
+ enum devclass he_devclass; /* device class */
+ char he_devname[16]; /* device name */
+};
+
+#ifdef _KERNEL
+void hotplug_device_attach(enum devclass, char *);
+void hotplug_device_detach(enum devclass, char *);
+#endif
+
+#endif /* _SYS_HOTPLUG_H_ */
diff --git a/sys/sys/ioccom.h b/sys/sys/ioccom.h
new file mode 100644
index 0000000..936fc13
--- /dev/null
+++ b/sys/sys/ioccom.h
@@ -0,0 +1,68 @@
+/* $OpenBSD: ioccom.h,v 1.5 2013/03/22 21:22:05 deraadt Exp $ */
+/* $NetBSD: ioccom.h,v 1.4 1994/10/30 21:49:56 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * 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.
+ *
+ * @(#)ioccom.h 8.2 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_IOCCOM_H_
+#define _SYS_IOCCOM_H_
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word. The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
+#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
+#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
+#define IOCGROUP(x) (((x) >> 8) & 0xff)
+
+#define IOCPARM_MAX PAGE_SIZE /* max size of ioctl args */
+ /* no parameters */
+#define IOC_VOID (unsigned long)0x20000000
+ /* copy parameters out */
+#define IOC_OUT (unsigned long)0x40000000
+ /* copy parameters in */
+#define IOC_IN (unsigned long)0x80000000
+ /* copy parameters in and out */
+#define IOC_INOUT (IOC_IN|IOC_OUT)
+ /* mask for IN/OUT/VOID */
+#define IOC_DIRMASK (unsigned long)0xe0000000
+
+#define _IOC(inout,group,num,len) \
+ (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
+#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
+#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
+#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
+
+#endif /* !_SYS_IOCCOM_H_ */
diff --git a/sys/sys/ioctl.h b/sys/sys/ioctl.h
new file mode 100644
index 0000000..eee6e34
--- /dev/null
+++ b/sys/sys/ioctl.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: ioctl.h,v 1.17 2016/02/28 15:46:19 naddy Exp $ */
+/* $NetBSD: ioctl.h,v 1.20 1996/01/30 18:21:47 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 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.
+ *
+ * @(#)ioctl.h 8.6 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_IOCTL_H_
+#define _SYS_IOCTL_H_
+
+#include <sys/ttycom.h>
+#include <sys/filio.h>
+#include <sys/sockio.h>
+
+#ifndef _KERNEL
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ioctl(int, unsigned long, ...);
+__END_DECLS
+#endif /* !_KERNEL */
+#endif /* !_SYS_IOCTL_H_ */
diff --git a/sys/sys/ipc.h b/sys/sys/ipc.h
new file mode 100644
index 0000000..d710de2
--- /dev/null
+++ b/sys/sys/ipc.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: ipc.h,v 1.13 2014/11/15 21:42:50 guenther Exp $ */
+/* $NetBSD: ipc.h,v 1.15 1996/02/09 18:25:12 christos Exp $ */
+
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990, 1993
+ * 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.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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.
+ *
+ * @(#)ipc.h 8.3 (Berkeley) 1/21/94
+ */
+
+/*
+ * SVID compatible ipc.h file
+ */
+#ifndef _SYS_IPC_H_
+#define _SYS_IPC_H_
+
+#include <sys/types.h>
+
+struct ipc_perm {
+ uid_t cuid; /* creator user id */
+ gid_t cgid; /* creator group id */
+ uid_t uid; /* user id */
+ gid_t gid; /* group id */
+ mode_t mode; /* r/w permission */
+ unsigned short seq; /* sequence # (to generate unique msg/sem/shm id) */
+ key_t key; /* user specified msg/sem/shm key */
+};
+
+/* common mode bits */
+#define IPC_R 000400 /* read permission */
+#define IPC_W 000200 /* write/alter permission */
+#define IPC_M 010000 /* permission to change control info */
+
+/* SVID 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 _KERNEL
+/* Macros to convert between ipc ids and array indices or sequence ids */
+#define IPCID_TO_IX(id) ((id) & 0xffff)
+#define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff)
+#define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff))
+
+struct ucred;
+
+int ipcperm(struct ucred *, struct ipc_perm *, int);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+key_t ftok(const char *, int);
+__END_DECLS
+#endif
+#endif /* !_SYS_IPC_H_ */
diff --git a/sys/sys/kcore.h b/sys/sys/kcore.h
new file mode 100644
index 0000000..4c5662b
--- /dev/null
+++ b/sys/sys/kcore.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: kcore.h,v 1.1 1996/04/18 21:40:57 niklas Exp $ */
+/* $NetBSD: kcore.h,v 1.1 1996/03/10 21:56:00 leo Exp $ */
+
+/*
+ * Copyright (c) 1996 Leo Weppelman.
+ * 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 Leo Weppelman.
+ * 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_KCORE_H_
+#define _SYS_KCORE_H_
+
+/*
+ * Definitions for the kernel crash-dump format. The structure of
+ * the files and headers is borrowed from the 'regular' core files
+ * as described in <sys/core.h>.
+ */
+#define KCORE_MAGIC 0x8fca
+#define KCORESEG_MAGIC 0x8fac
+
+/*
+ * Description of a memory segment. To make this suitable for sharing
+ * between all architectures, u_quad_t seems to be the necessary type...
+ */
+typedef struct {
+ u_quad_t start; /* Physical start address */
+ u_quad_t size; /* Size in bytes */
+} phys_ram_seg_t;
+
+typedef struct kcore_hdr {
+ u_int32_t c_midmag; /* Magic, id, flags */
+ u_int16_t c_hdrsize; /* Aligned header size */
+ u_int16_t c_seghdrsize; /* Aligned seg-header size */
+ u_int32_t c_nseg; /* Number of segments */
+} kcore_hdr_t;
+
+typedef struct kcore_seg {
+ u_int32_t c_midmag; /* Magic, id, flags */
+ u_int32_t c_size; /* Sizeof this segment */
+} kcore_seg_t;
+
+#endif /* _SYS_KCORE_H_ */
diff --git a/sys/sys/kcov.h b/sys/sys/kcov.h
new file mode 100644
index 0000000..717a5e8
--- /dev/null
+++ b/sys/sys/kcov.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: kcov.h,v 1.4 2019/01/20 09:57:23 anton Exp $ */
+
+/*
+ * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_KCOV_H_
+#define _SYS_KCOV_H_
+
+#include <sys/ioccom.h>
+
+#define KIOSETBUFSIZE _IOW('K', 1, unsigned long)
+#define KIOENABLE _IOW('K', 2, int)
+#define KIODISABLE _IO('K', 3)
+
+#define KCOV_MODE_NONE 0
+#define KCOV_MODE_TRACE_PC 1
+#define KCOV_MODE_TRACE_CMP 2
+
+#ifdef _KERNEL
+
+#define KCOV_BUF_MAX_NMEMB (256 << 10)
+
+void kcov_exit(struct proc *);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_KCOV_H_ */
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
new file mode 100644
index 0000000..f1c2aab
--- /dev/null
+++ b/sys/sys/kernel.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: kernel.h,v 1.22 2019/09/07 01:23:23 cheloha Exp $ */
+/* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * 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.
+ *
+ * @(#)kernel.h 8.3 (Berkeley) 1/21/94
+ */
+
+/* Global variables for the kernel. */
+
+/* 1.1 */
+extern long hostid;
+extern char hostname[MAXHOSTNAMELEN];
+extern int hostnamelen;
+extern char domainname[MAXHOSTNAMELEN];
+extern int domainnamelen;
+
+/* 1.2 */
+extern int utc_offset; /* seconds east of UTC */
+
+extern int tick; /* usec per tick (1000000 / hz) */
+extern int tick_nsec; /* nsec per tick */
+extern int tickfix; /* periodic tick adj. tick not integral */
+extern int tickfixinterval; /* interval at which to apply adjustment */
+extern int tickadj; /* "standard" clock skew, us./tick */
+extern int ticks; /* # of hardclock ticks */
+extern int hz; /* system clock's frequency */
+extern int stathz; /* statistics clock's frequency */
+extern int profhz; /* profiling clock's frequency */
+extern int lbolt; /* once a second sleep address */
+extern int tickdelta;
+extern long timedelta;
+
+extern struct bintime naptime; /* time spent suspended */
diff --git a/sys/sys/kthread.h b/sys/sys/kthread.h
new file mode 100644
index 0000000..b640045
--- /dev/null
+++ b/sys/sys/kthread.h
@@ -0,0 +1,50 @@
+/* $OpenBSD: kthread.h,v 1.7 2020/02/18 12:13:40 mpi Exp $ */
+/* $NetBSD: kthread.h,v 1.2 1998/11/14 00:08:49 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1998 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.
+ */
+
+#ifndef _SYS_KTHREAD_H_
+#define _SYS_KTHREAD_H_
+
+/*
+ * Kernel thread handling.
+ */
+
+#ifdef _KERNEL
+struct proc;
+int kthread_create(void (*)(void *), void *, struct proc **,
+ const char *);
+void kthread_create_deferred(void (*)(void *), void *);
+void kthread_run_deferred_queue(void);
+void kthread_exit(int) __attribute__((__noreturn__));
+#endif /* _KERNEL */
+
+#endif /* _SYS_KTHREAD_H_ */
diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h
new file mode 100644
index 0000000..c6a41cf
--- /dev/null
+++ b/sys/sys/ktrace.h
@@ -0,0 +1,254 @@
+/* $OpenBSD: ktrace.h,v 1.38 2019/02/26 22:24:41 deraadt Exp $ */
+/* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */
+
+/*
+ * Copyright (c) 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.
+ *
+ * @(#)ktrace.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/uio.h>
+
+/*
+ * operations to ktrace system call (KTROP(op))
+ */
+#define KTROP_SET 0 /* set trace points */
+#define KTROP_CLEAR 1 /* clear trace points */
+#define KTROP_CLEARFILE 2 /* stop all tracing to file */
+#define KTROP(o) ((o)&3) /* macro to extract operation */
+/*
+ * flags (ORed in with operation)
+ */
+#define KTRFLAG_DESCEND 4 /* perform op on all children too */
+
+/*
+ * ktrace record header
+ */
+struct ktr_header {
+ uint ktr_type; /* trace record type */
+ pid_t ktr_pid; /* process id */
+ pid_t ktr_tid; /* thread id */
+ struct timespec ktr_time; /* timestamp */
+ char ktr_comm[MAXCOMLEN+1]; /* command name */
+ size_t ktr_len; /* length of buf */
+};
+
+/*
+ * ktrace record types
+ */
+
+ /*
+ * KTR_START - start of trace record, one per ktrace(KTROP_SET) syscall
+ */
+#define KTR_START 0x4b545200 /* "KTR" */
+
+/*
+ * KTR_SYSCALL - system call record
+ */
+#define KTR_SYSCALL 1
+struct ktr_syscall {
+ int ktr_code; /* syscall number */
+ int ktr_argsize; /* size of arguments */
+ /*
+ * followed by ktr_argsize/sizeof(register_t) "register_t"s
+ */
+};
+
+/*
+ * KTR_SYSRET - return from system call record
+ */
+#define KTR_SYSRET 2
+struct ktr_sysret {
+ int ktr_code;
+ int ktr_error;
+ /*
+ * If ktr_error is zero, then followed by retval: register_t for
+ * all syscalls except lseek(), which uses long long
+ */
+};
+
+/*
+ * KTR_NAMEI - namei record
+ */
+#define KTR_NAMEI 3
+ /* record contains pathname */
+
+/*
+ * KTR_GENIO - trace generic process i/o
+ */
+#define KTR_GENIO 4
+struct ktr_genio {
+ int ktr_fd;
+ enum uio_rw ktr_rw;
+ /*
+ * followed by data successfully read/written
+ */
+};
+
+/*
+ * KTR_PSIG - trace processed signal
+ */
+#define KTR_PSIG 5
+struct ktr_psig {
+ int signo;
+ sig_t action;
+ int mask;
+ int code;
+ siginfo_t si;
+};
+
+/*
+ * KTR_STRUCT - misc. structs
+ */
+#define KTR_STRUCT 8
+ /*
+ * record contains null-terminated struct name followed by
+ * struct contents
+ */
+struct sockaddr;
+struct stat;
+
+/*
+ * KTR_USER - user record
+ */
+#define KTR_USER 9
+#define KTR_USER_MAXIDLEN 20
+#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
+struct ktr_user {
+ char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */
+ /*
+ * Followed by ktr_len - sizeof(struct ktr_user) of user data.
+ */
+};
+
+/*
+ * KTR_EXECARGS and KTR_EXECENV - args and evironment records
+ */
+#define KTR_EXECARGS 10
+#define KTR_EXECENV 11
+
+
+/*
+ * KTR_PLEDGE - details of pledge violation
+ */
+#define KTR_PLEDGE 12
+struct ktr_pledge {
+ int error;
+ int syscall;
+ uint64_t code;
+};
+
+/*
+ * kernel trace points (in p_traceflag)
+ */
+#define KTRFAC_MASK 0x00ffffff
+#define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
+#define KTRFAC_SYSRET (1<<KTR_SYSRET)
+#define KTRFAC_NAMEI (1<<KTR_NAMEI)
+#define KTRFAC_GENIO (1<<KTR_GENIO)
+#define KTRFAC_PSIG (1<<KTR_PSIG)
+#define KTRFAC_STRUCT (1<<KTR_STRUCT)
+#define KTRFAC_USER (1<<KTR_USER)
+#define KTRFAC_EXECARGS (1<<KTR_EXECARGS)
+#define KTRFAC_EXECENV (1<<KTR_EXECENV)
+#define KTRFAC_PLEDGE (1<<KTR_PLEDGE)
+
+/*
+ * trace flags (also in p_traceflags)
+ */
+#define KTRFAC_ROOT 0x80000000U /* root set this trace */
+#define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
+
+#ifndef _KERNEL
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ktrace(const char *, int, int, pid_t);
+int utrace(const char *, const void *, size_t);
+__END_DECLS
+
+#else
+
+/*
+ * Test for kernel trace point
+ */
+#define KTRPOINT(p, type) \
+ ((p)->p_p->ps_traceflag & (1<<(type)) && ((p)->p_flag & P_INKTR) == 0)
+
+void ktrgenio(struct proc *, int, enum uio_rw, struct iovec *, ssize_t);
+void ktrnamei(struct proc *, char *);
+void ktrpsig(struct proc *, int, sig_t, int, int, siginfo_t *);
+void ktrsyscall(struct proc *, register_t, size_t, register_t []);
+void ktrsysret(struct proc *, register_t, int, const register_t [2]);
+int ktruser(struct proc *, const char *, const void *, size_t);
+void ktrexec(struct proc *, int, const char *, ssize_t);
+void ktrpledge(struct proc *, int, uint64_t, int);
+
+void ktrcleartrace(struct process *);
+void ktrsettrace(struct process *, int, struct vnode *, struct ucred *);
+
+void ktrstruct(struct proc *, const char *, const void *, size_t);
+#define ktrsockaddr(p, s, l) \
+ ktrstruct((p), "sockaddr", (s), (l))
+#define ktrstat(p, s) \
+ ktrstruct((p), "stat", (s), sizeof(struct stat))
+#define ktrabstimespec(p, s) \
+ ktrstruct((p), "abstimespec", (s), sizeof(struct timespec))
+#define ktrreltimespec(p, s) \
+ ktrstruct((p), "reltimespec", (s), sizeof(struct timespec))
+#define ktrabstimeval(p, s) \
+ ktrstruct((p), "abstimeval", (s), sizeof(struct timeval))
+#define ktrreltimeval(p, s) \
+ ktrstruct((p), "reltimeval", (s), sizeof(struct timeval))
+#define ktrsigaction(p, s) \
+ ktrstruct((p), "sigaction", (s), sizeof(struct sigaction))
+#define ktrrlimit(p, s) \
+ ktrstruct((p), "rlimit", (s), sizeof(struct rlimit))
+#define ktrrusage(p, s) \
+ ktrstruct((p), "rusage", (s), sizeof(struct rusage))
+#define ktrfdset(p, s, l) \
+ ktrstruct((p), "fdset", (s), l)
+#define ktrquota(p, s) \
+ ktrstruct((p), "quota", (s), sizeof(struct dqblk))
+#define ktrmsghdr(p, s) \
+ ktrstruct(p, "msghdr", s, sizeof(struct msghdr))
+#define ktriovec(p, s, count) \
+ ktrstruct(p, "iovec", s, (count) * sizeof(struct iovec))
+#define ktrcmsghdr(p, c, len) \
+ ktrstruct(p, "cmsghdr", c, len)
+#define ktrevent(p, kev, count) \
+ ktrstruct(p, "kevent", kev, (count) * sizeof(struct kevent))
+#define ktrpollfd(p, pfd, count) \
+ ktrstruct(p, "pollfd", pfd, (count) * sizeof(struct pollfd))
+#define ktrfds(p, fds, count) \
+ ktrstruct(p, "fds", fds, (count) * sizeof(int))
+#define ktrflock(p, fl) \
+ ktrstruct(p, "flock", (fl), sizeof(struct flock))
+
+#endif /* !_KERNEL */
diff --git a/sys/sys/limits.h b/sys/sys/limits.h
new file mode 100644
index 0000000..1faba69
--- /dev/null
+++ b/sys/sys/limits.h
@@ -0,0 +1,125 @@
+/* $OpenBSD: limits.h,v 1.10 2012/06/30 20:21:10 guenther Exp $ */
+/*
+ * Copyright (c) 2002 Marc Espie.
+ *
+ * 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 OPENBSD 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 OPENBSD
+ * 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.
+ */
+#ifndef _SYS_LIMITS_H_
+#define _SYS_LIMITS_H_
+
+#include <sys/cdefs.h>
+
+/* Common definitions for limits.h. */
+
+/* Legacy */
+#include <machine/limits.h>
+
+#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 */
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN 0 /* min value for a char */
+# define CHAR_MAX 0xff /* max value for a char */
+#else
+# define CHAR_MAX 0x7f
+# define CHAR_MIN (-0x7f-1)
+#endif
+
+#define MB_LEN_MAX 4 /* Allow UTF-8 (RFC 3629) */
+
+#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 */
+
+#ifdef __LP64__
+# define ULONG_MAX 0xffffffffffffffffUL
+ /* max value for unsigned long */
+# define LONG_MAX 0x7fffffffffffffffL
+ /* max value for a signed long */
+# define LONG_MIN (-0x7fffffffffffffffL-1)
+ /* min value for a signed long */
+#else
+# 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 */
+#endif
+
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
+# define ULLONG_MAX 0xffffffffffffffffULL
+ /* max value for unsigned long long */
+# define LLONG_MAX 0x7fffffffffffffffLL
+ /* max value for a signed long long */
+# define LLONG_MIN (-0x7fffffffffffffffLL-1)
+ /* min value for a signed long long */
+#endif
+
+#if __BSD_VISIBLE
+# define UID_MAX UINT_MAX /* max value for a uid_t */
+# define GID_MAX UINT_MAX /* max value for a gid_t */
+#endif
+
+#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809
+# ifdef __LP64__
+# define LONG_BIT 64
+# else
+# define LONG_BIT 32
+# endif
+# define WORD_BIT 32
+#endif
+
+#if __XPG_VISIBLE < 600
+# include <machine/_float.h>
+
+/* XSI defines marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 */
+# ifndef FLT_DIG
+# define FLT_DIG __FLT_DIG
+# endif
+# ifndef FLT_MAX
+# define FLT_MAX __FLT_MAX
+# endif
+# ifndef DBL_DIG
+# define DBL_DIG __DBL_DIG
+# endif
+# ifndef DBL_MAX
+# define DBL_MAX __DBL_MAX
+# endif
+
+/* XSI defines marked LEGACY in XPG4v2 and removed in XPG5 */
+# if __XPG_VISIBLE < 500
+# ifndef FLT_MIN
+# define FLT_MIN __FLT_MIN
+# endif
+# ifndef DBL_MIN
+# define DBL_MIN __DBL_MIN
+# endif
+# endif
+
+#endif /* __XPG_VISIBLE < 600 */
+
+#endif
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
new file mode 100644
index 0000000..2388b59
--- /dev/null
+++ b/sys/sys/lock.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: lock.h,v 1.27 2016/06/19 11:54:33 natano Exp $ */
+
+/*
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code contains ideas from software contributed to Berkeley by
+ * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
+ * System project at Carnegie-Mellon University.
+ *
+ * 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.
+ *
+ * @(#)lock.h 8.12 (Berkeley) 5/19/95
+ */
+
+#ifndef _LOCK_H_
+#define _LOCK_H_
+
+#include <sys/rwlock.h>
+
+#define LK_EXCLUSIVE RW_WRITE /* exclusive lock */
+#define LK_SHARED RW_READ /* shared lock */
+#define LK_TYPE_MASK (RW_WRITE|RW_READ) /* type of lock sought */
+#define LK_NOWAIT RW_NOSLEEP /* do not sleep to await lock */
+#define LK_RECURSEFAIL RW_RECURSEFAIL /* fail if recursive exclusive lock */
+#define LK_EXCLOTHER RW_WRITE_OTHER /* exclusive lock held by some other thread */
+#define LK_RWFLAGS (RW_WRITE|RW_READ|RW_NOSLEEP|RW_RECURSEFAIL|RW_WRITE_OTHER)
+
+/* LK_ specific */
+#define LK_DRAIN 0x1000UL /* wait for all lock activity to end */
+#define LK_RETRY 0x2000UL /* vn_lock: retry until locked */
+
+#endif /* !_LOCK_H_ */
diff --git a/sys/sys/lockf.h b/sys/sys/lockf.h
new file mode 100644
index 0000000..8606339
--- /dev/null
+++ b/sys/sys/lockf.h
@@ -0,0 +1,45 @@
+/* $OpenBSD: lockf.h,v 1.17 2019/04/20 08:28:59 anton Exp $ */
+/* $NetBSD: lockf.h,v 1.5 1994/06/29 06:44:33 cgd 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
+ * Scooter Morris at Genentech 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.
+ *
+ * @(#)lockf.h 8.1 (Berkeley) 6/11/93
+ */
+
+#ifdef _KERNEL
+struct lockf_state;
+
+void lf_init(void);
+int lf_advlock(struct lockf_state **,
+ off_t, caddr_t, int, struct flock *, int);
+void lf_purgelocks(struct lockf_state **);
+#endif /* _KERNEL */
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
new file mode 100644
index 0000000..ff8e09b
--- /dev/null
+++ b/sys/sys/malloc.h
@@ -0,0 +1,406 @@
+/* $OpenBSD: malloc.h,v 1.119 2019/11/28 16:23:11 guenther Exp $ */
+/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
+
+/*
+ * Copyright (c) 1987, 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.
+ *
+ * @(#)malloc.h 8.5 (Berkeley) 5/3/95
+ */
+
+#ifndef _SYS_MALLOC_H_
+#define _SYS_MALLOC_H_
+
+#include <sys/queue.h>
+
+#define KERN_MALLOC_BUCKETS 1
+#define KERN_MALLOC_BUCKET 2
+#define KERN_MALLOC_KMEMNAMES 3
+#define KERN_MALLOC_KMEMSTATS 4
+#define KERN_MALLOC_MAXID 5
+
+#define CTL_KERN_MALLOC_NAMES { \
+ { 0, 0 }, \
+ { "buckets", CTLTYPE_STRING }, \
+ { "bucket", CTLTYPE_NODE }, \
+ { "kmemnames", CTLTYPE_STRING }, \
+ { "kmemstat", CTLTYPE_NODE }, \
+}
+
+/*
+ * flags to malloc
+ */
+#define M_WAITOK 0x0001
+#define M_NOWAIT 0x0002
+#define M_CANFAIL 0x0004
+#define M_ZERO 0x0008
+
+/*
+ * Types of memory to be allocated
+ */
+#define M_FREE 0 /* should be on free list */
+/* 1 - free */
+#define M_DEVBUF 2 /* device driver memory */
+/* 3 - free */
+#define M_PCB 4 /* protocol control block */
+#define M_RTABLE 5 /* routing tables */
+/* 6 - free */
+/* 7 - free */
+/* 8 - free */
+#define M_IFADDR 9 /* interface address */
+#define M_SOOPTS 10 /* socket options */
+#define M_SYSCTL 11 /* sysctl buffers (persistent storage) */
+#define M_COUNTERS 12 /* per CPU counters */
+/* 13 - free */
+#define M_IOCTLOPS 14 /* ioctl data buffer */
+/* 15-18 - free */
+#define M_IOV 19 /* large iov's */
+#define M_MOUNT 20 /* vfs mount struct */
+/* 21 - free */
+#define M_NFSREQ 22 /* NFS request header */
+#define M_NFSMNT 23 /* NFS mount structure */
+/* 24 - free */
+#define M_VNODE 25 /* Dynamically allocated vnodes */
+#define M_CACHE 26 /* Dynamically allocated cache entries */
+#define M_DQUOT 27 /* UFS quota entries */
+#define M_UFSMNT 28 /* UFS mount structure */
+#define M_SHM 29 /* SVID compatible shared memory segments */
+#define M_VMMAP 30 /* VM map structures */
+#define M_SEM 31 /* SVID compatible semaphores */
+#define M_DIRHASH 32 /* UFS dirhash */
+#define M_ACPI 33 /* ACPI */
+#define M_VMPMAP 34 /* VM pmap */
+/* 35-37 - free */
+#define M_FILE 38 /* Open file structure */
+#define M_FILEDESC 39 /* Open file descriptor table */
+#define M_SIGIO 40 /* Sigio structures */
+#define M_PROC 41 /* Proc structures */
+#define M_SUBPROC 42 /* Proc sub-structures */
+#define M_VCLUSTER 43 /* Cluster for VFS */
+/* 45-46 - free */
+#define M_MFSNODE 46 /* MFS vnode private part */
+/* 47-48 - free */
+#define M_NETADDR 49 /* Export host address structure */
+#define M_NFSSVC 50 /* Nfs server structure */
+/* 51 - free */
+#define M_NFSD 52 /* Nfs server daemon structure */
+#define M_IPMOPTS 53 /* internet multicast options */
+#define M_IPMADDR 54 /* internet multicast address */
+#define M_IFMADDR 55 /* link-level multicast address */
+#define M_MRTABLE 56 /* multicast routing tables */
+#define M_ISOFSMNT 57 /* ISOFS mount structure */
+#define M_ISOFSNODE 58 /* ISOFS vnode private part */
+#define M_MSDOSFSMNT 59 /* MSDOS FS mount structure */
+#define M_MSDOSFSFAT 60 /* MSDOS FS fat table */
+#define M_MSDOSFSNODE 61 /* MSDOS FS vnode private part */
+#define M_TTYS 62 /* allocated tty structures */
+#define M_EXEC 63 /* argument lists & other mem used by exec */
+#define M_MISCFSMNT 64 /* miscfs mount structures */
+#define M_FUSEFS 65 /* fusefs mount structures */
+/* 66-73 - free */
+#define M_PFKEY 74 /* pfkey data */
+#define M_TDB 75 /* Transforms database */
+#define M_XDATA 76 /* IPsec data */
+/* 77 - free */
+#define M_PAGEDEP 78 /* File page dependencies */
+#define M_INODEDEP 79 /* Inode dependencies */
+#define M_NEWBLK 80 /* New block allocation */
+/* 81-82 - free */
+#define M_INDIRDEP 83 /* Indirect block dependencies */
+/* 84-91 - free */
+#define M_VMSWAP 92 /* VM swap structures */
+/* 93-97 - free */
+#define M_UVMAMAP 98 /* UVM amap and related */
+#define M_UVMAOBJ 99 /* UVM aobj and related */
+/* 100 - free */
+#define M_USB 101 /* USB general */
+#define M_USBDEV 102 /* USB device driver */
+#define M_USBHC 103 /* USB host controller */
+#define M_WITNESS 104 /* witness data */
+#define M_MEMDESC 105 /* Memory range */
+/* 106-107 - free */
+#define M_CRYPTO_DATA 108 /* Crypto framework data buffers (keys etc.) */
+/* 109 - free */
+#define M_CREDENTIALS 110 /* IPsec-related credentials and ID info */
+/* 111-113 - free */
+#define M_EMULDATA 114 /* Per-process emulation data */
+/* 115-122 - free */
+
+/* KAME IPv6 */
+#define M_IP6OPT 123 /* IPv6 options */
+#define M_IP6NDP 124 /* IPv6 Neighbour Discovery */
+/* 125-126 - free */
+#define M_TEMP 127 /* misc temporary data buffers */
+
+#define M_NTFSMNT 128 /* NTFS mount structure */
+#define M_NTFSNTNODE 129 /* NTFS ntnode information */
+#define M_NTFSFNODE 130 /* NTFS fnode information */
+#define M_NTFSDIR 131 /* NTFS dir buffer */
+#define M_NTFSNTHASH 132 /* NTFS ntnode hash tables */
+#define M_NTFSNTVATTR 133 /* NTFS file attribute information */
+#define M_NTFSRDATA 134 /* NTFS resident data */
+#define M_NTFSDECOMP 135 /* NTFS decompression temporary */
+#define M_NTFSRUN 136 /* NTFS vrun storage */
+
+#define M_KEVENT 137 /* kqueue related */
+
+ /* 138 free */
+#define M_SYNCACHE 139 /* syn cache hash array */
+
+#define M_UDFMOUNT 140 /* UDF mount */
+#define M_UDFFENTRY 141 /* UDF file entry */
+#define M_UDFFID 142 /* UDF file id */
+
+ /* 143 free */
+
+#define M_AGP 144 /* AGP Memory */
+
+#define M_DRM 145 /* Direct Rendering Manager */
+
+#define M_LAST 146 /* Must be last type + 1 */
+
+#define INITKMEMNAMES { \
+ "free", /* 0 M_FREE */ \
+ NULL, \
+ "devbuf", /* 2 M_DEVBUF */ \
+ NULL, \
+ "pcb", /* 4 M_PCB */ \
+ "rtable", /* 5 M_RTABLE */ \
+ NULL, /* 6 */ \
+ NULL, \
+ NULL, \
+ "ifaddr", /* 9 M_IFADDR */ \
+ "soopts", /* 10 M_SOOPTS */ \
+ "sysctl", /* 11 M_SYSCTL */ \
+ "counters", /* 12 M_COUNTERS */ \
+ NULL, \
+ "ioctlops", /* 14 M_IOCTLOPS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ "iov", /* 19 M_IOV */ \
+ "mount", /* 20 M_MOUNT */ \
+ NULL, \
+ "NFS req", /* 22 M_NFSREQ */ \
+ "NFS mount", /* 23 M_NFSMNT */ \
+ NULL, \
+ "vnodes", /* 25 M_VNODE */ \
+ "namecache", /* 26 M_CACHE */ \
+ "UFS quota", /* 27 M_DQUOT */ \
+ "UFS mount", /* 28 M_UFSMNT */ \
+ "shm", /* 29 M_SHM */ \
+ "VM map", /* 30 M_VMMAP */ \
+ "sem", /* 31 M_SEM */ \
+ "dirhash", /* 32 M_DIRHASH */ \
+ "ACPI", /* 33 M_ACPI */ \
+ "VM pmap", /* 34 M_VMPMAP */ \
+ NULL, /* 35 */ \
+ NULL, /* 36 */ \
+ NULL, /* 37 */ \
+ "file", /* 38 M_FILE */ \
+ "file desc", /* 39 M_FILEDESC */ \
+ "sigio", /* 40 M_SIGIO */ \
+ "proc", /* 41 M_PROC */ \
+ "subproc", /* 42 M_SUBPROC */ \
+ "VFS cluster", /* 43 M_VCLUSTER */ \
+ NULL, \
+ NULL, \
+ "MFS node", /* 46 M_MFSNODE */ \
+ NULL, \
+ NULL, \
+ "Export Host", /* 49 M_NETADDR */ \
+ "NFS srvsock", /* 50 M_NFSSVC */ \
+ NULL, \
+ "NFS daemon", /* 52 M_NFSD */ \
+ "ip_moptions", /* 53 M_IPMOPTS */ \
+ "in_multi", /* 54 M_IPMADDR */ \
+ "ether_multi", /* 55 M_IFMADDR */ \
+ "mrt", /* 56 M_MRTABLE */ \
+ "ISOFS mount", /* 57 M_ISOFSMNT */ \
+ "ISOFS node", /* 58 M_ISOFSNODE */ \
+ "MSDOSFS mount", /* 59 M_MSDOSFSMNT */ \
+ "MSDOSFS fat", /* 60 M_MSDOSFSFAT */ \
+ "MSDOSFS node", /* 61 M_MSDOSFSNODE */ \
+ "ttys", /* 62 M_TTYS */ \
+ "exec", /* 63 M_EXEC */ \
+ "miscfs mount", /* 64 M_MISCFSMNT */ \
+ "fusefs mount", /* 65 M_FUSEFS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ "pfkey data", /* 74 M_PFKEY */ \
+ "tdb", /* 75 M_TDB */ \
+ "xform_data", /* 76 M_XDATA */ \
+ NULL, \
+ "pagedep", /* 78 M_PAGEDEP */ \
+ "inodedep", /* 79 M_INODEDEP */ \
+ "newblk", /* 80 M_NEWBLK */ \
+ NULL, \
+ NULL, \
+ "indirdep", /* 83 M_INDIRDEP */ \
+ NULL, NULL, NULL, NULL, \
+ NULL, NULL, NULL, NULL, \
+ "VM swap", /* 92 M_VMSWAP */ \
+ NULL, NULL, NULL, NULL, NULL, \
+ "UVM amap", /* 98 M_UVMAMAP */ \
+ "UVM aobj", /* 99 M_UVMAOBJ */ \
+ NULL, \
+ "USB", /* 101 M_USB */ \
+ "USB device", /* 102 M_USBDEV */ \
+ "USB HC", /* 103 M_USBHC */ \
+ "witness", /* 104 M_WITNESS */ \
+ "memdesc", /* 105 M_MEMDESC */ \
+ NULL, /* 106 */ \
+ NULL, \
+ "crypto data", /* 108 M_CRYPTO_DATA */ \
+ NULL, \
+ "IPsec creds", /* 110 M_CREDENTIALS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ "emuldata", /* 114 M_EMULDATA */ \
+ NULL, NULL, NULL, NULL, \
+ NULL, NULL, NULL, NULL, \
+ "ip6_options", /* 123 M_IP6OPT */ \
+ "NDP", /* 124 M_IP6NDP */ \
+ NULL, \
+ NULL, \
+ "temp", /* 127 M_TEMP */ \
+ "NTFS mount", /* 128 M_NTFSMNT */ \
+ "NTFS node", /* 129 M_NTFSNTNODE */ \
+ "NTFS fnode", /* 130 M_NTFSFNODE */ \
+ "NTFS dir", /* 131 M_NTFSDIR */ \
+ "NTFS hash", /* 132 M_NTFSNTHASH */ \
+ "NTFS attr", /* 133 M_NTFSNTVATTR */ \
+ "NTFS data", /* 134 M_NTFSRDATA */ \
+ "NTFS decomp", /* 135 M_NTFSDECOMP */ \
+ "NTFS vrun", /* 136 M_NTFSRUN */ \
+ "kqueue", /* 137 M_KEVENT */ \
+ NULL, /* 138 free */ \
+ "SYN cache", /* 139 M_SYNCACHE */ \
+ "UDF mount", /* 140 M_UDFMOUNT */ \
+ "UDF file entry", /* 141 M_UDFFENTRY */ \
+ "UDF file id", /* 142 M_UDFFID */ \
+ NULL, /* 143 free */ \
+ "AGP Memory", /* 144 M_AGP */ \
+ "DRM", /* 145 M_DRM */ \
+}
+
+struct kmemstats {
+ long ks_inuse; /* # of packets of this type currently in use */
+ long ks_calls; /* total packets of this type ever allocated */
+ long ks_memuse; /* total memory held in bytes */
+ u_short ks_limblocks; /* number of times blocked for hitting limit */
+ long ks_maxused; /* maximum number ever used */
+ long ks_limit; /* most that are allowed to exist */
+ long ks_size; /* sizes of this thing that are allocated */
+ long ks_spare;
+};
+
+/*
+ * Array of descriptors that describe the contents of each page
+ */
+struct kmemusage {
+ short ku_indx; /* bucket index */
+ union {
+ u_short freecnt;/* for small allocations, free pieces in page */
+ u_short pagecnt;/* for large allocations, pages alloced */
+ } ku_un;
+};
+#define ku_freecnt ku_un.freecnt
+#define ku_pagecnt ku_un.pagecnt
+
+struct kmem_freelist;
+
+/*
+ * Set of buckets for each size of memory block that is retained
+ */
+struct kmembuckets {
+ XSIMPLEQ_HEAD(, kmem_freelist) kb_freelist; /* list of free blocks */
+ u_int64_t kb_calls; /* total calls to allocate this size */
+ u_int64_t kb_total; /* total number of blocks allocated */
+ u_int64_t kb_totalfree; /* # of free elements in this bucket */
+ u_int64_t kb_elmpercl; /* # of elements in this sized allocation */
+ u_int64_t kb_highwat; /* high water mark */
+ u_int64_t kb_couldfree; /* over high water mark and could free */
+};
+
+/*
+ * Constants for setting the parameters of the kernel memory allocator.
+ *
+ * 2 ** MINBUCKET is the smallest unit of memory that will be
+ * allocated. It must be at least large enough to hold a pointer.
+ *
+ * Units of memory less or equal to MAXALLOCSAVE will permanently
+ * allocate physical memory; requests for these size pieces of
+ * memory are quite fast. Allocations greater than MAXALLOCSAVE must
+ * always allocate and free physical memory; requests for these
+ * size allocations should be done infrequently as they will be slow.
+ *
+ * Constraints: PAGE_SIZE <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
+ * MAXALLOCSIZE must be a power of two.
+ */
+#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
+
+#ifdef _KERNEL
+
+#define MINALLOCSIZE (1 << MINBUCKET)
+#define MAXALLOCSAVE (2 * PAGE_SIZE)
+
+/*
+ * Turn virtual addresses into kmem map indices
+ */
+#define kmemxtob(alloc) (kmembase + (alloc) * PAGE_SIZE)
+#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / PAGE_SIZE)
+#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PAGE_SHIFT])
+
+extern struct kmemstats kmemstats[];
+extern struct kmemusage *kmemusage;
+extern char *kmembase;
+extern struct kmembuckets bucket[];
+
+void *malloc(size_t, int, int);
+void *mallocarray(size_t, size_t, int, int);
+void free(void *, int, size_t);
+int sysctl_malloc(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+
+size_t malloc_roundup(size_t);
+void malloc_printit(int (*)(const char *, ...));
+
+void poison_mem(void *, size_t);
+int poison_check(void *, size_t, size_t *, uint32_t *);
+uint32_t poison_value(void *);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_MALLOC_H_ */
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
new file mode 100644
index 0000000..a54b003
--- /dev/null
+++ b/sys/sys/mbuf.h
@@ -0,0 +1,550 @@
+/* $OpenBSD: mbuf.h,v 1.246 2020/01/22 22:56:35 dlg Exp $ */
+/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 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.
+ *
+ * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
+ */
+
+#ifndef _SYS_MBUF_H_
+#define _SYS_MBUF_H_
+
+#include <sys/queue.h>
+
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than PAGE_SIZE (the software page size) and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 256 /* size of an mbuf */
+
+/*
+ * Mbufs are of a single size, MSIZE, which includes overhead. An mbuf may
+ * add a single "mbuf cluster" of size MCLBYTES, which has no additional
+ * overhead and is used instead of the internal data area; this is done when
+ * at least MINCLSIZE of data must be stored.
+ */
+
+#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
+#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
+
+#define MAXMCLBYTES (64 * 1024) /* largest cluster from the stack */
+#define MINCLSIZE (MHLEN + MLEN + 1) /* smallest amount to put in cluster */
+#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
+
+#define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+#define MCLOFSET (MCLBYTES - 1)
+
+/* Packet tags structure */
+struct m_tag {
+ SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
+ u_int16_t m_tag_id; /* Tag ID */
+ u_int16_t m_tag_len; /* Length of data */
+};
+
+/*
+ * Macros for type conversion
+ * mtod(m,t) - convert mbuf pointer to data pointer of correct type
+ */
+#define mtod(m,t) ((t)((m)->m_data))
+
+/* header at beginning of each mbuf: */
+struct m_hdr {
+ struct mbuf *mh_next; /* next buffer in chain */
+ struct mbuf *mh_nextpkt; /* next chain in queue/record */
+ caddr_t mh_data; /* location of data */
+ u_int mh_len; /* amount of data in this mbuf */
+ short mh_type; /* type of data in this mbuf */
+ u_short mh_flags; /* flags; see below */
+#ifndef __LP64__
+ u_int mh_pad; /* pad to 8-byte boundary */
+#endif
+};
+
+/* pf stuff */
+struct pf_state_key;
+struct inpcb;
+
+struct pkthdr_pf {
+ struct pf_state_key *statekey; /* pf stackside statekey */
+ struct inpcb *inp; /* connected pcb for outgoing packet */
+ u_int32_t qid; /* queue id */
+ u_int16_t tag; /* tag id */
+ u_int16_t delay; /* delay packet by X ms */
+ u_int8_t flags;
+ u_int8_t routed;
+ u_int8_t prio;
+ u_int8_t pad[1];
+};
+
+/* pkthdr_pf.flags */
+#define PF_TAG_GENERATED 0x01
+#define PF_TAG_SYNCOOKIE_RECREATED 0x02
+#define PF_TAG_TRANSLATE_LOCALHOST 0x04
+#define PF_TAG_DIVERTED 0x08
+#define PF_TAG_DIVERTED_PACKET 0x10
+#define PF_TAG_REROUTE 0x20
+#define PF_TAG_REFRAGMENTED 0x40 /* refragmented ipv6 packet */
+#define PF_TAG_PROCESSED 0x80 /* packet was checked by pf */
+
+#ifdef _KERNEL
+#define MPF_BITS \
+ ("\20\1GENERATED\2SYNCOOKIE_RECREATED\3TRANSLATE_LOCALHOST\4DIVERTED" \
+ "\5DIVERTED_PACKET\6REROUTE\7REFRAGMENTED\10PROCESSED")
+#endif
+
+/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
+struct pkthdr {
+ void *ph_cookie; /* additional data */
+ SLIST_HEAD(, m_tag) ph_tags; /* list of packet tags */
+ int64_t ph_timestamp; /* packet timestamp */
+ int len; /* total packet length */
+ u_int16_t ph_tagsset; /* mtags attached */
+ u_int16_t ph_flowid; /* pseudo unique flow id */
+ u_int16_t csum_flags; /* checksum flags */
+ u_int16_t ether_vtag; /* Ethernet 802.1p+Q vlan tag */
+ u_int ph_rtableid; /* routing table id */
+ u_int ph_ifidx; /* rcv interface index */
+ u_int8_t ph_loopcnt; /* mbuf is looping in kernel */
+ u_int8_t ph_family; /* af, used when queueing */
+ struct pkthdr_pf pf;
+};
+
+/* description of external storage mapped into mbuf, valid if M_EXT set */
+struct mbuf_ext {
+ caddr_t ext_buf; /* start of buffer */
+ void *ext_arg;
+ u_int ext_free_fn; /* index of free function */
+ u_int ext_size; /* size of buffer, for ext_free_fn */
+ struct mbuf *ext_nextref;
+ struct mbuf *ext_prevref;
+#ifdef DEBUG
+ const char *ext_ofile;
+ const char *ext_nfile;
+ int ext_oline;
+ int ext_nline;
+#endif
+};
+
+struct mbuf {
+ struct m_hdr m_hdr;
+ union {
+ struct {
+ struct pkthdr MH_pkthdr; /* M_PKTHDR set */
+ union {
+ struct mbuf_ext MH_ext; /* M_EXT set */
+ char MH_databuf[MHLEN];
+ } MH_dat;
+ } MH;
+ char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
+ } M_dat;
+};
+#define m_next m_hdr.mh_next
+#define m_len m_hdr.mh_len
+#define m_data m_hdr.mh_data
+#define m_type m_hdr.mh_type
+#define m_flags m_hdr.mh_flags
+#define m_nextpkt m_hdr.mh_nextpkt
+#define m_pkthdr M_dat.MH.MH_pkthdr
+#define m_ext M_dat.MH.MH_dat.MH_ext
+#define m_pktdat M_dat.MH.MH_dat.MH_databuf
+#define m_dat M_dat.M_databuf
+
+/* mbuf flags */
+#define M_EXT 0x0001 /* has associated external storage */
+#define M_PKTHDR 0x0002 /* start of record */
+#define M_EOR 0x0004 /* end of record */
+#define M_EXTWR 0x0008 /* external storage is writable */
+#define M_PROTO1 0x0010 /* protocol-specific */
+
+/* mbuf pkthdr flags, also in m_flags */
+#define M_VLANTAG 0x0020 /* ether_vtag is valid */
+#define M_LOOP 0x0040 /* packet has been sent from local machine */
+#define M_ACAST 0x0080 /* received as IPv6 anycast */
+#define M_BCAST 0x0100 /* sent/received as link-level broadcast */
+#define M_MCAST 0x0200 /* sent/received as link-level multicast */
+#define M_CONF 0x0400 /* payload was encrypted (ESP-transport) */
+#define M_AUTH 0x0800 /* payload was authenticated (AH or ESP auth) */
+#define M_TUNNEL 0x1000 /* IP-in-IP added by tunnel mode IPsec */
+#define M_ZEROIZE 0x2000 /* Zeroize data part on free */
+#define M_COMP 0x4000 /* header was decompressed */
+#define M_LINK0 0x8000 /* link layer specific flag */
+
+#ifdef _KERNEL
+#define M_BITS \
+ ("\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_EXTWR\5M_PROTO1\6M_VLANTAG\7M_LOOP" \
+ "\10M_ACAST\11M_BCAST\12M_MCAST\13M_CONF\14M_AUTH\15M_TUNNEL" \
+ "\16M_ZEROIZE\17M_COMP\20M_LINK0")
+#endif
+
+/* flags copied when copying m_pkthdr */
+#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_BCAST|M_MCAST|M_CONF|M_COMP|\
+ M_AUTH|M_LOOP|M_TUNNEL|M_LINK0|M_VLANTAG|M_ACAST|\
+ M_ZEROIZE)
+
+/* Checksumming flags */
+#define M_IPV4_CSUM_OUT 0x0001 /* IPv4 checksum needed */
+#define M_TCP_CSUM_OUT 0x0002 /* TCP checksum needed */
+#define M_UDP_CSUM_OUT 0x0004 /* UDP checksum needed */
+#define M_IPV4_CSUM_IN_OK 0x0008 /* IPv4 checksum verified */
+#define M_IPV4_CSUM_IN_BAD 0x0010 /* IPv4 checksum bad */
+#define M_TCP_CSUM_IN_OK 0x0020 /* TCP checksum verified */
+#define M_TCP_CSUM_IN_BAD 0x0040 /* TCP checksum bad */
+#define M_UDP_CSUM_IN_OK 0x0080 /* UDP checksum verified */
+#define M_UDP_CSUM_IN_BAD 0x0100 /* UDP checksum bad */
+#define M_ICMP_CSUM_OUT 0x0200 /* ICMP/ICMPv6 checksum needed */
+#define M_ICMP_CSUM_IN_OK 0x0400 /* ICMP/ICMPv6 checksum verified */
+#define M_ICMP_CSUM_IN_BAD 0x0800 /* ICMP/ICMPv6 checksum bad */
+#define M_IPV6_DF_OUT 0x1000 /* don't fragment outgoing IPv6 */
+#define M_TIMESTAMP 0x2000 /* ph_timestamp is set */
+
+#ifdef _KERNEL
+#define MCS_BITS \
+ ("\20\1IPV4_CSUM_OUT\2TCP_CSUM_OUT\3UDP_CSUM_OUT\4IPV4_CSUM_IN_OK" \
+ "\5IPV4_CSUM_IN_BAD\6TCP_CSUM_IN_OK\7TCP_CSUM_IN_BAD\10UDP_CSUM_IN_OK" \
+ "\11UDP_CSUM_IN_BAD\12ICMP_CSUM_OUT\13ICMP_CSUM_IN_OK\14ICMP_CSUM_IN_BAD" \
+ "\15IPV6_NODF_OUT" "\16TIMESTAMP")
+#endif
+
+/* mbuf types */
+#define MT_FREE 0 /* should be on free list */
+#define MT_DATA 1 /* dynamic (data) allocation */
+#define MT_HEADER 2 /* packet header */
+#define MT_SONAME 3 /* socket name */
+#define MT_SOOPTS 4 /* socket options */
+#define MT_FTABLE 5 /* fragment reassembly header */
+#define MT_CONTROL 6 /* extra-data protocol message */
+#define MT_OOBDATA 7 /* expedited data */
+#define MT_NTYPES 8
+
+/* flowid field */
+#define M_FLOWID_VALID 0x8000 /* is the flowid set */
+#define M_FLOWID_MASK 0x7fff /* flow id to map to path */
+
+/* flags to m_get/MGET */
+#include <sys/malloc.h>
+#define M_DONTWAIT M_NOWAIT
+#define M_WAIT M_WAITOK
+
+/*
+ * mbuf allocation/deallocation macros:
+ *
+ * MGET(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain internal data.
+ *
+ * MGETHDR(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain a packet header
+ * and internal data.
+ */
+#define MGET(m, how, type) m = m_get((how), (type))
+
+#define MGETHDR(m, how, type) m = m_gethdr((how), (type))
+
+/*
+ * Macros for tracking external storage associated with an mbuf.
+ */
+#ifdef DEBUG
+#define MCLREFDEBUGN(m, file, line) do { \
+ (m)->m_ext.ext_nfile = (file); \
+ (m)->m_ext.ext_nline = (line); \
+ } while (/* CONSTCOND */ 0)
+#define MCLREFDEBUGO(m, file, line) do { \
+ (m)->m_ext.ext_ofile = (file); \
+ (m)->m_ext.ext_oline = (line); \
+ } while (/* CONSTCOND */ 0)
+#else
+#define MCLREFDEBUGN(m, file, line)
+#define MCLREFDEBUGO(m, file, line)
+#endif
+
+#define MCLISREFERENCED(m) ((m)->m_ext.ext_nextref != (m))
+
+#define MCLADDREFERENCE(o, n) m_extref((o), (n))
+
+#define MCLINITREFERENCE(m) do { \
+ (m)->m_ext.ext_prevref = (m); \
+ (m)->m_ext.ext_nextref = (m); \
+ MCLREFDEBUGO((m), __FILE__, __LINE__); \
+ MCLREFDEBUGN((m), NULL, 0); \
+ } while (/* CONSTCOND */ 0)
+
+/*
+ * Macros for mbuf external storage.
+ *
+ * MEXTADD adds pre-allocated external storage to
+ * a normal mbuf; the flag M_EXT is set.
+ *
+ * MCLGET allocates and adds an mbuf cluster to a normal mbuf;
+ * the flag M_EXT is set upon success.
+ */
+#define MEXTADD(m, buf, size, mflags, freefn, arg) do { \
+ (m)->m_data = (m)->m_ext.ext_buf = (caddr_t)(buf); \
+ (m)->m_flags |= M_EXT | (mflags & M_EXTWR); \
+ (m)->m_ext.ext_size = (size); \
+ (m)->m_ext.ext_free_fn = (freefn); \
+ (m)->m_ext.ext_arg = (arg); \
+ MCLINITREFERENCE(m); \
+} while (/* CONSTCOND */ 0)
+
+#define MCLGET(m, how) (void) m_clget((m), (how), MCLBYTES)
+#define MCLGETI(m, how, ifp, l) m_clget((m), (how), (l))
+
+u_int mextfree_register(void (*)(caddr_t, u_int, void *));
+#define MEXTFREE_POOL 0
+
+/*
+ * Move just m_pkthdr from from to to,
+ * remove M_PKTHDR and clean flags/tags for from.
+ */
+#define M_MOVE_HDR(to, from) do { \
+ (to)->m_pkthdr = (from)->m_pkthdr; \
+ (from)->m_flags &= ~M_PKTHDR; \
+ SLIST_INIT(&(from)->m_pkthdr.ph_tags); \
+ (from)->m_pkthdr.pf.statekey = NULL; \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * MOVE mbuf pkthdr from from to to.
+ * from must have M_PKTHDR set, and to must be empty.
+ */
+#define M_MOVE_PKTHDR(to, from) do { \
+ (to)->m_flags = ((to)->m_flags & (M_EXT | M_EXTWR)); \
+ (to)->m_flags |= (from)->m_flags & M_COPYFLAGS; \
+ M_MOVE_HDR((to), (from)); \
+ if (((to)->m_flags & M_EXT) == 0) \
+ (to)->m_data = (to)->m_pktdat; \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * Determine if an mbuf's data area is read-only. This is true for
+ * non-cluster external storage and for clusters that are being
+ * referenced by more than one mbuf.
+ */
+#define M_READONLY(m) \
+ (((m)->m_flags & M_EXT) != 0 && \
+ (((m)->m_flags & M_EXTWR) == 0 || MCLISREFERENCED(m)))
+
+/*
+ * Arrange to prepend space of size plen to mbuf m.
+ * If a new mbuf must be allocated, how specifies whether to wait.
+ * If how is M_DONTWAIT and allocation fails, the original mbuf chain
+ * is freed and m is set to NULL.
+ */
+#define M_PREPEND(m, plen, how) \
+ (m) = m_prepend((m), (plen), (how))
+
+/* length to m_copy to copy all */
+#define M_COPYALL 1000000000
+
+/*
+ * Mbuf statistics.
+ * For statistics related to mbuf and cluster allocations, see also the
+ * pool headers (mbpool and mclpool).
+ */
+struct mbstat {
+ u_long m_drops; /* times failed to find space */
+ u_long m_wait; /* times waited for space */
+ u_long m_drain; /* times drained protocols for space */
+ u_short m_mtypes[256]; /* type specific mbuf allocations */
+};
+
+#define MBSTAT_TYPES MT_NTYPES
+#define MBSTAT_DROPS (MBSTAT_TYPES + 0)
+#define MBSTAT_WAIT (MBSTAT_TYPES + 1)
+#define MBSTAT_DRAIN (MBSTAT_TYPES + 2)
+#define MBSTAT_COUNT (MBSTAT_TYPES + 3)
+
+#include <sys/mutex.h>
+
+struct mbuf_list {
+ struct mbuf *ml_head;
+ struct mbuf *ml_tail;
+ u_int ml_len;
+};
+
+struct mbuf_queue {
+ struct mutex mq_mtx;
+ struct mbuf_list mq_list;
+ u_int mq_maxlen;
+ u_int mq_drops;
+};
+
+#ifdef _KERNEL
+struct pool;
+
+extern long nmbclust; /* limit on the # of clusters */
+extern int mblowat; /* mbuf low water mark */
+extern int mcllowat; /* mbuf cluster low water mark */
+extern int max_linkhdr; /* largest link-level header */
+extern int max_protohdr; /* largest protocol header */
+extern int max_hdr; /* largest link+protocol header */
+
+void mbinit(void);
+void mbcpuinit(void);
+int nmbclust_update(long);
+struct mbuf *m_copym(struct mbuf *, int, int, int);
+struct mbuf *m_free(struct mbuf *);
+struct mbuf *m_get(int, int);
+struct mbuf *m_getclr(int, int);
+struct mbuf *m_gethdr(int, int);
+struct mbuf *m_inithdr(struct mbuf *);
+void m_removehdr(struct mbuf *);
+void m_resethdr(struct mbuf *);
+void m_calchdrlen(struct mbuf *);
+int m_defrag(struct mbuf *, int);
+struct mbuf *m_prepend(struct mbuf *, int, int);
+struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
+struct mbuf *m_pullup(struct mbuf *, int);
+struct mbuf *m_split(struct mbuf *, int, int);
+struct mbuf *m_makespace(struct mbuf *, int, int, int *);
+struct mbuf *m_getptr(struct mbuf *, int, int *);
+int m_leadingspace(struct mbuf *);
+int m_trailingspace(struct mbuf *);
+void m_align(struct mbuf *, int);
+struct mbuf *m_clget(struct mbuf *, int, u_int);
+void m_extref(struct mbuf *, struct mbuf *);
+void m_pool_init(struct pool *, u_int, u_int, const char *);
+void m_extfree_pool(caddr_t, u_int, void *);
+void m_adj(struct mbuf *, int);
+int m_copyback(struct mbuf *, int, int, const void *, int);
+struct mbuf *m_freem(struct mbuf *);
+void m_purge(struct mbuf *);
+void m_reclaim(void *, int);
+void m_copydata(struct mbuf *, int, int, caddr_t);
+void m_cat(struct mbuf *, struct mbuf *);
+struct mbuf *m_devget(char *, int, int);
+int m_apply(struct mbuf *, int, int,
+ int (*)(caddr_t, caddr_t, unsigned int), caddr_t);
+struct mbuf *m_dup_pkt(struct mbuf *, unsigned int, int);
+int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
+
+void m_microtime(const struct mbuf *, struct timeval *);
+
+static inline struct mbuf *
+m_freemp(struct mbuf **mp)
+{
+ struct mbuf *m = *mp;
+
+ *mp = NULL;
+ return m_freem(m);
+}
+
+/* Packet tag routines */
+struct m_tag *m_tag_get(int, int, int);
+void m_tag_prepend(struct mbuf *, struct m_tag *);
+void m_tag_delete(struct mbuf *, struct m_tag *);
+void m_tag_delete_chain(struct mbuf *);
+struct m_tag *m_tag_find(struct mbuf *, int, struct m_tag *);
+struct m_tag *m_tag_copy(struct m_tag *, int);
+int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
+void m_tag_init(struct mbuf *);
+struct m_tag *m_tag_first(struct mbuf *);
+struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
+
+/* Packet tag types */
+#define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */
+#define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */
+#define PACKET_TAG_GIF 0x0040 /* GIF processing done */
+#define PACKET_TAG_GRE 0x0080 /* GRE processing done */
+#define PACKET_TAG_DLT 0x0100 /* data link layer type */
+#define PACKET_TAG_PF_DIVERT 0x0200 /* pf(4) diverted packet */
+#define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */
+#define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */
+#define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */
+#define PACKET_TAG_CARP_BAL_IP 0x4000 /* carp(4) ip balanced marker */
+
+#define MTAG_BITS \
+ ("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_IN_CRYPTO_DONE" \
+ "\4IPSEC_OUT_CRYPTO_NEEDED\5IPSEC_PENDING_TDB\6BRIDGE\7GIF\10GRE\11DLT" \
+ "\12PF_DIVERT\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL\17CARP_BAL_IP")
+
+/*
+ * Maximum tag payload length (that is excluding the m_tag structure).
+ * Please make sure to update this value when increasing the payload
+ * length for an existing packet tag type or when adding a new one that
+ * has payload larger than the value below.
+ */
+#define PACKET_TAG_MAXSIZE 60
+
+/* Detect mbufs looping in the kernel when spliced too often. */
+#define M_MAXLOOP 128
+
+/*
+ * mbuf lists
+ */
+
+#define MBUF_LIST_INITIALIZER() { NULL, NULL, 0 }
+
+void ml_init(struct mbuf_list *);
+void ml_enqueue(struct mbuf_list *, struct mbuf *);
+struct mbuf * ml_dequeue(struct mbuf_list *);
+void ml_enlist(struct mbuf_list *, struct mbuf_list *);
+struct mbuf * ml_dechain(struct mbuf_list *);
+unsigned int ml_purge(struct mbuf_list *);
+unsigned int ml_hdatalen(struct mbuf_list *);
+
+#define ml_len(_ml) ((_ml)->ml_len)
+#define ml_empty(_ml) ((_ml)->ml_len == 0)
+
+#define MBUF_LIST_FIRST(_ml) ((_ml)->ml_head)
+#define MBUF_LIST_NEXT(_m) ((_m)->m_nextpkt)
+
+#define MBUF_LIST_FOREACH(_ml, _m) \
+ for ((_m) = MBUF_LIST_FIRST(_ml); \
+ (_m) != NULL; \
+ (_m) = MBUF_LIST_NEXT(_m))
+
+/*
+ * mbuf queues
+ */
+
+#define MBUF_QUEUE_INITIALIZER(_maxlen, _ipl) \
+ { MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 }
+
+void mq_init(struct mbuf_queue *, u_int, int);
+int mq_enqueue(struct mbuf_queue *, struct mbuf *);
+struct mbuf * mq_dequeue(struct mbuf_queue *);
+int mq_enlist(struct mbuf_queue *, struct mbuf_list *);
+void mq_delist(struct mbuf_queue *, struct mbuf_list *);
+struct mbuf * mq_dechain(struct mbuf_queue *);
+unsigned int mq_purge(struct mbuf_queue *);
+unsigned int mq_hdatalen(struct mbuf_queue *);
+
+#define mq_len(_mq) ml_len(&(_mq)->mq_list)
+#define mq_empty(_mq) ml_empty(&(_mq)->mq_list)
+#define mq_full(_mq) (mq_len((_mq)) >= (_mq)->mq_maxlen)
+#define mq_drops(_mq) ((_mq)->mq_drops)
+#define mq_set_maxlen(_mq, _l) ((_mq)->mq_maxlen = (_l))
+
+#endif /* _KERNEL */
+#endif /* _SYS_MBUF_H_ */
diff --git a/sys/sys/memrange.h b/sys/sys/memrange.h
new file mode 100644
index 0000000..c806e39
--- /dev/null
+++ b/sys/sys/memrange.h
@@ -0,0 +1,97 @@
+/* $OpenBSD: memrange.h,v 1.10 2015/08/18 20:19:32 miod Exp $ */
+/*-
+ * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
+ * 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.
+ */
+/*
+ * Memory range attribute operations, performed on /dev/mem
+ */
+
+/* Memory range attributes */
+#define MDF_UNCACHEABLE (1<<0) /* region not cached */
+#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */
+#define MDF_WRITETHROUGH (1<<2) /* write-through cached */
+#define MDF_WRITEBACK (1<<3) /* write-back cached */
+#define MDF_WRITEPROTECT (1<<4) /* read-only region */
+#define MDF_UNKNOWN (1<<5) /* any state we don't understand */
+#define MDF_ATTRMASK (0x00ffffff)
+
+#define MDF_FIXBASE (1<<24) /* fixed base */
+#define MDF_FIXLEN (1<<25) /* fixed length */
+#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */
+#define MDF_ACTIVE (1<<27) /* currently active */
+#define MDF_BOGUS (1<<28) /* we don't like it */
+#define MDF_FIXACTIVE (1<<29) /* can't be turned off */
+#define MDF_FORCE (1<<31) /* force risky changes */
+
+struct mem_range_desc {
+ u_int64_t mr_base;
+ u_int64_t mr_len;
+ int mr_flags;
+ char mr_owner[8];
+};
+
+struct mem_range_op {
+ struct mem_range_desc *mo_desc;
+ int mo_arg[2];
+#define MEMRANGE_SET_UPDATE 0
+#define MEMRANGE_SET_REMOVE 1
+ /* XXX want a flag that says "set and undo when I exit" */
+};
+
+#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op)
+#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op)
+
+/* Offset indicating a write combining mapping is requested. */
+#define MEMRANGE_WC_RANGE 0x4000000000000000ULL
+
+#ifdef _KERNEL
+
+struct mem_range_softc;
+struct mem_range_ops {
+ void (*init)(struct mem_range_softc *sc);
+ int (*set)(struct mem_range_softc *sc,
+ struct mem_range_desc *mrd, int *arg);
+ void (*initAP)(struct mem_range_softc *sc);
+ void (*reload)(struct mem_range_softc *sc);
+};
+
+struct mem_range_softc {
+ struct mem_range_ops *mr_op;
+ int mr_cap;
+ int mr_ndesc;
+ struct mem_range_desc *mr_desc;
+};
+
+extern struct mem_range_softc mem_range_softc;
+
+__BEGIN_DECLS
+extern void mem_range_attach(void);
+extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg);
+extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg);
+extern void mem_range_AP_init(void);
+extern void mem_range_reload(void);
+__END_DECLS
+#endif /* _KERNEL */
+
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
new file mode 100644
index 0000000..47972b5
--- /dev/null
+++ b/sys/sys/mman.h
@@ -0,0 +1,165 @@
+/* $OpenBSD: mman.h,v 1.34 2019/03/01 01:46:18 cheloha Exp $ */
+/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc 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.
+ *
+ * @(#)mman.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+#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 */
+
+/*
+ * Other flags
+ */
+#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */
+#define __MAP_NOREPLACE 0x0800 /* fail if address not available */
+#define MAP_ANON 0x1000 /* allocated from memory, swap space */
+#define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */
+#define __MAP_NOFAULT 0x2000
+#define MAP_STACK 0x4000 /* mapping is used for a stack */
+#define MAP_CONCEAL 0x8000 /* omit from dumps */
+
+#define MAP_FLAGMASK 0xfff7
+
+#ifndef _KERNEL
+/*
+ * Legacy defines for userland source compatibility.
+ * Can be removed once no longer needed in base and ports.
+ */
+#define MAP_COPY MAP_PRIVATE /* "copy" region at mmap time */
+#define MAP_FILE 0 /* map from file (default) */
+#define MAP_HASSEMAPHORE 0 /* region may contain semaphores */
+#define MAP_INHERIT 0 /* region is retained after exec */
+#define MAP_NOEXTEND 0 /* for MAP_FILE, don't change file size */
+#define MAP_NORESERVE 0 /* Sun: don't reserve needed swap area */
+#define MAP_RENAME 0 /* Sun: rename private pages to file */
+#define MAP_TRYFIXED 0 /* attempt hint address, even within heap */
+#endif
+
+/*
+ * Error return from mmap()
+ */
+#define MAP_FAILED ((void *)-1)
+
+/*
+ * POSIX memory advisory values.
+ * Note: keep consistent with the original definitions below.
+ */
+#define POSIX_MADV_NORMAL 0 /* no further special treatment */
+#define POSIX_MADV_RANDOM 1 /* expect random page references */
+#define POSIX_MADV_SEQUENTIAL 2 /* expect sequential page references */
+#define POSIX_MADV_WILLNEED 3 /* will need these pages */
+#define POSIX_MADV_DONTNEED 4 /* don't need these pages */
+
+#if __BSD_VISIBLE
+/*
+ * Original advice values, equivalent to POSIX definitions,
+ * and few implementation-specific ones. For in-kernel and historic use.
+ */
+#define MADV_NORMAL POSIX_MADV_NORMAL
+#define MADV_RANDOM POSIX_MADV_RANDOM
+#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
+#define MADV_WILLNEED POSIX_MADV_WILLNEED
+#define MADV_DONTNEED POSIX_MADV_DONTNEED
+#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
+#define MADV_FREE 6 /* pages are empty, free them */
+#endif
+
+/*
+ * Flags to minherit
+ */
+#define MAP_INHERIT_SHARE 0 /* share with child */
+#define MAP_INHERIT_COPY 1 /* copy into child */
+#define MAP_INHERIT_NONE 2 /* absent from child */
+#define MAP_INHERIT_ZERO 3 /* zero in child */
+
+/*
+ * Flags to msync
+ */
+#define MS_ASYNC 0x01 /* perform asynchronous writes */
+#define MS_SYNC 0x02 /* perform synchronous writes */
+#define MS_INVALIDATE 0x04 /* invalidate cached data */
+
+/*
+ * Flags to mlockall
+ */
+#define MCL_CURRENT 0x01 /* lock all pages currently mapped */
+#define MCL_FUTURE 0x02 /* lock all pages mapped in the future */
+
+#ifndef _KERNEL
+#include <sys/_types.h>
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _OFF_T_DEFINED_
+#define _OFF_T_DEFINED_
+typedef __off_t off_t;
+#endif
+
+__BEGIN_DECLS
+void * mmap(void *, size_t, int, int, int, off_t);
+int mprotect(void *, size_t, int);
+int munmap(void *, size_t);
+int msync(void *, size_t, int);
+int mlock(const void *, size_t);
+int munlock(const void *, size_t);
+int mlockall(int);
+int munlockall(void);
+#if __BSD_VISIBLE
+int madvise(void *, size_t, int);
+int minherit(void *, size_t, int);
+void * mquery(void *, size_t, int, int, int, off_t);
+#endif
+int posix_madvise(void *, size_t, int);
+int shm_open(const char *, int, __mode_t);
+int shm_unlink(const char *);
+int shm_mkstemp(char *);
+__END_DECLS
+
+#endif /* !_KERNEL */
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
new file mode 100644
index 0000000..cdf31d3
--- /dev/null
+++ b/sys/sys/mount.h
@@ -0,0 +1,637 @@
+/* $OpenBSD: mount.h,v 1.147 2020/01/18 08:40:19 visa Exp $ */
+/* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */
+
+/*
+ * Copyright (c) 1989, 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.
+ *
+ * @(#)mount.h 8.15 (Berkeley) 7/14/94
+ */
+
+#ifndef _SYS_MOUNT_H_
+#define _SYS_MOUNT_H_
+
+#include <sys/cdefs.h>
+#ifndef _KERNEL
+#include <sys/ucred.h>
+#endif
+#include <sys/queue.h>
+#include <sys/rwlock.h>
+
+typedef struct { int32_t val[2]; } fsid_t; /* file system id type */
+
+/*
+ * File identifier.
+ * These are unique per filesystem on a single machine.
+ */
+#define MAXFIDSZ 16
+
+struct fid {
+ u_short fid_len; /* length of data in bytes */
+ u_short fid_reserved; /* force longword alignment */
+ char fid_data[MAXFIDSZ]; /* data (variable length) */
+};
+
+/*
+ * Export arguments for local filesystem mount calls.
+ */
+struct export_args {
+ int ex_flags; /* export related flags */
+ uid_t ex_root; /* mapping for root uid */
+ struct xucred ex_anon; /* mapping for anonymous user */
+ struct sockaddr *ex_addr; /* net address to which exported */
+ int ex_addrlen; /* and the net address length */
+ struct sockaddr *ex_mask; /* mask of valid bits in saddr */
+ int ex_masklen; /* and the smask length */
+};
+
+/*
+ * Arguments to mount UFS-based filesystems
+ */
+struct ufs_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export information */
+};
+
+/*
+ * Arguments to mount MFS
+ */
+struct mfs_args {
+ char *fspec; /* name to export for statfs */
+ struct export_args export_info;/* if exported MFSes are supported */
+ caddr_t base; /* base of file system in memory */
+ u_long size; /* size of file system */
+};
+
+/*
+ * Arguments to mount ISO 9660 filesystems.
+ */
+struct iso_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export info */
+ int flags; /* mounting flags, see below */
+ int sess; /* start sector of session */
+};
+
+#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/
+#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */
+#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attr. */
+#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/
+#define ISOFSMNT_SESS 0x00000010 /* use iso_args.sess */
+
+/*
+ * Arguments to mount NFS
+ */
+#define NFS_ARGSVERSION 4 /* change when nfs_args changes */
+struct nfs_args {
+ int version; /* args structure version number */
+ struct sockaddr *addr; /* file server address */
+ int addrlen; /* length of address */
+ int sotype; /* Socket type */
+ int proto; /* and Protocol */
+ u_char *fh; /* File handle to be mounted */
+ int fhsize; /* Size, in bytes, of fh */
+ int flags; /* flags */
+ int wsize; /* write size in bytes */
+ int rsize; /* read size in bytes */
+ int readdirsize; /* readdir size in bytes */
+ int timeo; /* initial timeout in .1 secs */
+ int retrans; /* times to retry send */
+ int maxgrouplist; /* Max. size of group list */
+ int readahead; /* # of blocks to readahead */
+ int leaseterm; /* Term (sec) of lease */
+ int deadthresh; /* Retrans threshold */
+ char *hostname; /* server's name */
+ int acregmin; /* Attr cache file recently modified */
+ int acregmax; /* ac file not recently modified */
+ int acdirmin; /* ac for dir recently modified */
+ int acdirmax; /* ac for dir not recently modified */
+};
+
+/*
+ * NFS mount option flags
+ */
+#define NFSMNT_RESVPORT 0x00000000 /* always use reserved ports */
+#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
+#define NFSMNT_WSIZE 0x00000002 /* set write size */
+#define NFSMNT_RSIZE 0x00000004 /* set read size */
+#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
+#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
+#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
+#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
+#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
+#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
+#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
+#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
+#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
+#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
+#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
+#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
+#define NFSMNT_NOAC 0x00008000 /* disable attribute cache */
+#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
+#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
+
+/* Flags valid only in mount syscall arguments */
+#define NFSMNT_ACREGMIN 0x00040000 /* acregmin field valid */
+#define NFSMNT_ACREGMAX 0x00080000 /* acregmax field valid */
+#define NFSMNT_ACDIRMIN 0x00100000 /* acdirmin field valid */
+#define NFSMNT_ACDIRMAX 0x00200000 /* acdirmax field valid */
+
+/* Flags valid only in kernel */
+#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
+#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
+#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
+#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
+#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
+#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
+#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
+#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
+#define NFSMNT_WANTSND 0x02000000 /* Want above */
+#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
+#define NFSMNT_WANTRCV 0x08000000 /* Want above */
+#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
+#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
+#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
+#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
+
+/*
+ * Arguments to mount MSDOS filesystems.
+ */
+struct msdosfs_args {
+ char *fspec; /* blocks special holding the fs to mount */
+ struct export_args export_info;
+ /* network export information */
+ uid_t uid; /* uid that owns msdosfs files */
+ gid_t gid; /* gid that owns msdosfs files */
+ mode_t mask; /* mask to be applied for msdosfs perms */
+ int flags; /* see below */
+};
+
+/*
+ * Msdosfs mount options:
+ */
+#define MSDOSFSMNT_SHORTNAME 0x01 /* Force old DOS short names only */
+#define MSDOSFSMNT_LONGNAME 0x02 /* Force Win'95 long names */
+#define MSDOSFSMNT_NOWIN95 0x04 /* Completely ignore Win95 entries */
+
+/*
+ * Arguments to mount ntfs filesystems
+ */
+struct ntfs_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export information */
+ uid_t uid; /* uid that owns ntfs files */
+ gid_t gid; /* gid that owns ntfs files */
+ mode_t mode; /* mask to be applied for ntfs perms */
+ u_long flag; /* additional flags */
+};
+
+/*
+ * ntfs mount options:
+ */
+#define NTFS_MFLAG_CASEINS 0x00000001
+#define NTFS_MFLAG_ALLNAMES 0x00000002
+
+/* Arguments to mount UDF file systems */
+struct udf_args {
+ char *fspec; /* Block special device to mount */
+ u_int32_t lastblock; /* Special device last block */
+};
+
+/*
+ * Arguments to mount tmpfs file systems
+ */
+#define TMPFS_ARGS_VERSION 1
+struct tmpfs_args {
+ int ta_version;
+
+ /* Size counters. */
+ ino_t ta_nodes_max;
+ off_t ta_size_max;
+
+ /* Root node attributes. */
+ uid_t ta_root_uid;
+ gid_t ta_root_gid;
+ mode_t ta_root_mode;
+};
+
+/*
+ * Arguments to mount fusefs filesystems
+ */
+struct fusefs_args {
+ char *name;
+ int fd;
+ int max_read;
+
+ /*
+ * FUSE does not allow the file system to be accessed by other users
+ * unless this option is specified. This is to prevent unintentional
+ * denial of service to other users if the file system is not
+ * responding. e.g. user executes df(1) or cron job that scans mounted
+ * file systems.
+ */
+ int allow_other;
+};
+
+/*
+ * file system statistics
+ */
+
+#define MFSNAMELEN 16 /* length of fs type name, including nul */
+#define MNAMELEN 90 /* length of buffer for returned name */
+
+/* per-filesystem mount options */
+union mount_info {
+ struct ufs_args ufs_args;
+ struct mfs_args mfs_args;
+ struct nfs_args nfs_args;
+ struct iso_args iso_args;
+ struct msdosfs_args msdosfs_args;
+ struct ntfs_args ntfs_args;
+ struct tmpfs_args tmpfs_args;
+ char __align[160]; /* 64-bit alignment and room to grow */
+};
+
+/* new statfs structure with mount options and statvfs fields */
+struct statfs {
+ u_int32_t f_flags; /* copy of mount flags */
+ u_int32_t f_bsize; /* file system block size */
+ u_int32_t f_iosize; /* optimal transfer block size */
+
+ /* unit is f_bsize */
+ u_int64_t f_blocks; /* total data blocks in file system */
+ u_int64_t f_bfree; /* free blocks in fs */
+ int64_t f_bavail; /* free blocks avail to non-superuser */
+
+ u_int64_t f_files; /* total file nodes in file system */
+ u_int64_t f_ffree; /* free file nodes in fs */
+ int64_t f_favail; /* free file nodes avail to non-root */
+
+ u_int64_t f_syncwrites; /* count of sync writes since mount */
+ u_int64_t f_syncreads; /* count of sync reads since mount */
+ u_int64_t f_asyncwrites; /* count of async writes since mount */
+ u_int64_t f_asyncreads; /* count of async reads since mount */
+
+ fsid_t f_fsid; /* file system id */
+ u_int32_t f_namemax; /* maximum filename length */
+ uid_t f_owner; /* user that mounted the file system */
+ u_int64_t f_ctime; /* last mount [-u] time */
+
+ char f_fstypename[MFSNAMELEN]; /* fs type name */
+ char f_mntonname[MNAMELEN]; /* directory on which mounted */
+ char f_mntfromname[MNAMELEN]; /* mounted file system */
+ char f_mntfromspec[MNAMELEN]; /* special for mount request */
+ union mount_info mount_info; /* per-filesystem mount options */
+};
+
+
+/*
+ * File system types.
+ */
+#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */
+#define MOUNT_UFS MOUNT_FFS /* for compatibility */
+#define MOUNT_NFS "nfs" /* Network Filesystem */
+#define MOUNT_MFS "mfs" /* Memory Filesystem */
+#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */
+#define MOUNT_AFS "afs" /* Andrew Filesystem */
+#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */
+#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */
+#define MOUNT_NCPFS "ncpfs" /* NetWare Network File System */
+#define MOUNT_NTFS "ntfs" /* NTFS */
+#define MOUNT_UDF "udf" /* UDF */
+#define MOUNT_TMPFS "tmpfs" /* tmpfs */
+#define MOUNT_FUSEFS "fuse" /* FUSE */
+
+/*
+ * Structure per mounted file system. Each mounted file system has an
+ * array of operations and an instance record. The file systems are
+ * put on a doubly linked list.
+ */
+struct mount {
+ TAILQ_ENTRY(mount) mnt_list; /* mount list */
+ SLIST_ENTRY(mount) mnt_dounmount; /* unmount work queue */
+ const struct vfsops *mnt_op; /* operations on fs */
+ struct vfsconf *mnt_vfc; /* configuration info */
+ struct vnode *mnt_vnodecovered; /* vnode we mounted on */
+ struct vnode *mnt_syncer; /* syncer vnode */
+ TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */
+ struct rwlock mnt_lock; /* mount structure lock */
+ int mnt_flag; /* flags */
+ struct statfs mnt_stat; /* cache of filesystem stats */
+ void *mnt_data; /* private data */
+};
+
+/*
+ * Mount flags.
+ *
+ * Unmount uses MNT_FORCE flag.
+ */
+#define MNT_RDONLY 0x00000001 /* read only filesystem */
+#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
+#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
+#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
+#define MNT_NODEV 0x00000010 /* don't interpret special files */
+#define MNT_NOPERM 0x00000020 /* don't enforce permission checks */
+#define MNT_ASYNC 0x00000040 /* file system written asynchronously */
+#define MNT_WXALLOWED 0x00000800 /* filesystem allows W|X mappings */
+
+/*
+ * exported mount flags.
+ */
+#define MNT_EXRDONLY 0x00000080 /* exported read only */
+#define MNT_EXPORTED 0x00000100 /* file system is exported */
+#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
+#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
+
+/*
+ * Flags set by internal operations.
+ */
+#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
+#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
+#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
+
+/*
+ * Extra post 4.4BSD-lite2 mount flags.
+ */
+#define MNT_NOATIME 0x00008000 /* don't update access times on fs */
+
+/*
+ * Mask of flags that are visible to statfs()
+ */
+#define MNT_VISFLAGMASK 0x0400ffff
+
+#define MNT_BITS \
+ "\20\001RDONLY\002SYNCHRONOUS\003NOEXEC\004NOSUID\005NODEV\006NOPERM" \
+ "\007ASYNC\010EXRDONLY\011EXPORTED\012DEFEXPORTED\013EXPORTANON" \
+ "\014WXALLOWED\015LOCAL\016QUOTA\017ROOTFS\020NOATIME"
+
+/*
+ * filesystem control flags.
+ */
+#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
+#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
+#define MNT_RELOAD 0x00040000 /* reload filesystem data */
+#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
+#define MNT_STALLED 0x00100000 /* filesystem stalled */
+#define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */
+#define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */
+#define MNT_SOFTDEP 0x04000000 /* soft dependencies being done */
+#define MNT_DOOMED 0x08000000 /* device behind filesystem is gone */
+
+#ifdef _KERNEL
+#define MNT_OP_FLAGS (MNT_UPDATE | MNT_RELOAD | MNT_FORCE | MNT_WANTRDWR)
+#endif
+
+/*
+ * Flags for various system call interfaces.
+ *
+ * waitfor flags to vfs_sync() and getfsstat()
+ */
+#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
+#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
+#define MNT_LAZY 3 /* push data not written by filesystem syncer */
+
+/*
+ * Generic file handle
+ */
+struct fhandle {
+ fsid_t fh_fsid; /* File system id of mount point */
+ struct fid fh_fid; /* File sys specific id */
+};
+typedef struct fhandle fhandle_t;
+
+/*
+ * Sysctl CTL_VFS definitions.
+ *
+ * Second level identifier specifies which filesystem. Second level
+ * identifier VFS_GENERIC returns information about all filesystems.
+ */
+#define VFS_GENERIC 0 /* generic filesystem information */
+/*
+ * Third level identifiers for VFS_GENERIC are given below; third
+ * level identifiers for specific filesystems are given in their
+ * mount specific header files.
+ */
+#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
+#define VFS_CONF 2 /* struct: vfsconf for filesystem given
+ as next argument */
+#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given
+ as next argument */
+#define CTL_VFSGENCTL_NAMES { \
+ { 0, 0 }, \
+ { "maxtypenum", CTLTYPE_INT }, \
+ { "conf", CTLTYPE_NODE }, \
+ { "bcachestat", CTLTYPE_STRUCT } \
+}
+
+/*
+ * Filesystem configuration information. One of these exists for each
+ * type of filesystem supported by the kernel. These are searched at
+ * mount time to identify the requested filesystem.
+ */
+struct vfsconf {
+ const struct vfsops *vfc_vfsops; /* filesystem operations vector */
+ char vfc_name[MFSNAMELEN]; /* filesystem type name */
+ int vfc_typenum; /* historic filesystem type number */
+ u_int vfc_refcount; /* number mounted of this type */
+ int vfc_flags; /* permanent flags */
+ size_t vfc_datasize; /* size of data args */
+};
+
+/* buffer cache statistics */
+struct bcachestats {
+ int64_t numbufs; /* number of buffers allocated */
+ int64_t numbufpages; /* number of pages in buffer cache */
+ int64_t numdirtypages; /* number of dirty free pages */
+ int64_t numcleanpages; /* number of clean free pages */
+ int64_t pendingwrites; /* number of pending writes */
+ int64_t pendingreads; /* number of pending reads */
+ int64_t numwrites; /* total writes started */
+ int64_t numreads; /* total reads started */
+ int64_t cachehits; /* total reads found in cache */
+ int64_t busymapped; /* number of busy and mapped buffers */
+ int64_t dmapages; /* dma reachable pages in buffer cache */
+ int64_t highpages; /* pages above dma region */
+ int64_t delwribufs; /* delayed write buffers */
+ int64_t kvaslots; /* kva slots total */
+ int64_t kvaslots_avail; /* available kva slots */
+ int64_t highflips; /* total flips to above DMA */
+ int64_t highflops; /* total failed flips to above DMA */
+ int64_t dmaflips; /* total flips from high to DMA */
+};
+#ifdef _KERNEL
+extern struct bcachestats bcstats;
+extern long buflowpages, bufhighpages, bufbackpages;
+#define BUFPAGES_DEFICIT (((buflowpages - bcstats.numbufpages) < 0) ? 0 \
+ : buflowpages - bcstats.numbufpages)
+#define BUFPAGES_INACT (((bcstats.numcleanpages - buflowpages) < 0) ? 0 \
+ : bcstats.numcleanpages - buflowpages)
+extern int bufcachepercent;
+extern void bufadjust(int);
+struct uvm_constraint_range;
+extern int bufbackoff(struct uvm_constraint_range*, long);
+
+/*
+ * Operations supported on mounted file system.
+ */
+struct nameidata;
+struct mbuf;
+
+extern int maxvfsconf; /* highest defined filesystem type */
+
+struct vfsops {
+ int (*vfs_mount)(struct mount *mp, const char *path,
+ void *data,
+ struct nameidata *ndp, struct proc *p);
+ int (*vfs_start)(struct mount *mp, int flags,
+ struct proc *p);
+ int (*vfs_unmount)(struct mount *mp, int mntflags,
+ struct proc *p);
+ int (*vfs_root)(struct mount *mp, struct vnode **vpp);
+ int (*vfs_quotactl)(struct mount *mp, int cmds, uid_t uid,
+ caddr_t arg, struct proc *p);
+ int (*vfs_statfs)(struct mount *mp, struct statfs *sbp,
+ struct proc *p);
+ int (*vfs_sync)(struct mount *mp, int waitfor, int stall,
+ struct ucred *cred, struct proc *p);
+ int (*vfs_vget)(struct mount *mp, ino_t ino,
+ struct vnode **vpp);
+ int (*vfs_fhtovp)(struct mount *mp, struct fid *fhp,
+ struct vnode **vpp);
+ int (*vfs_vptofh)(struct vnode *vp, struct fid *fhp);
+ int (*vfs_init)(struct vfsconf *);
+ int (*vfs_sysctl)(int *, u_int, void *, size_t *, void *,
+ size_t, struct proc *);
+ int (*vfs_checkexp)(struct mount *mp, struct mbuf *nam,
+ int *extflagsp, struct ucred **credanonp);
+};
+
+#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
+ (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
+#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
+#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
+#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
+#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
+#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
+#define VFS_SYNC(MP, W, S, C, P) (*(MP)->mnt_op->vfs_sync)(MP, W, S, C, P)
+#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
+#define VFS_FHTOVP(MP, FIDP, VPP) \
+ (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP)
+#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
+#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED) \
+ (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED)
+
+/* Set up the filesystem operations for vnodes. */
+extern const struct vfsops ffs_vfsops;
+extern const struct vfsops mfs_vfsops;
+extern const struct vfsops msdosfs_vfsops;
+extern const struct vfsops nfs_vfsops;
+extern const struct vfsops cd9660_vfsops;
+extern const struct vfsops ext2fs_vfsops;
+extern const struct vfsops ntfs_vfsops;
+extern const struct vfsops udf_vfsops;
+extern const struct vfsops fusefs_vfsops;
+extern const struct vfsops tmpfs_vfsops;
+
+#include <net/radix.h>
+#include <sys/socket.h> /* XXX for AF_MAX */
+
+/*
+ * Network address lookup element
+ */
+struct netcred {
+ struct radix_node netc_rnodes[2];
+ int netc_exflags;
+ int netc_len; /* size of the allocation */
+ struct ucred netc_anon;
+};
+
+/*
+ * Network export information
+ */
+struct netexport {
+ struct netcred ne_defexported; /* Default export */
+ struct radix_node_head *ne_rtable_inet;/* Individual exports */
+};
+
+/*
+ * exported vnode operations
+ */
+int vfs_busy(struct mount *, int);
+#define VB_READ 0x01
+#define VB_WRITE 0x02
+#define VB_NOWAIT 0x04 /* immediately fail on busy lock */
+#define VB_WAIT 0x08 /* sleep fail on busy lock */
+#define VB_DUPOK 0x10 /* permit duplicate mount busying */
+
+int vfs_isbusy(struct mount *);
+struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *);
+void vfs_mount_free(struct mount *);
+int vfs_mount_foreach_vnode(struct mount *, int (*func)(struct vnode *,
+ void *), void *);
+void vfs_getnewfsid(struct mount *);
+struct mount *vfs_getvfs(fsid_t *);
+int vfs_mountedon(struct vnode *);
+int vfs_rootmountalloc(char *, char *, struct mount **);
+void vfs_unbusy(struct mount *);
+extern TAILQ_HEAD(mntlist, mount) mountlist;
+int vfs_stall(struct proc *, int);
+void vfs_stall_barrier(void);
+
+struct mount *getvfs(fsid_t *); /* return vfs given fsid */
+ /* process mount export info */
+int vfs_export(struct mount *, struct netexport *, struct export_args *);
+ /* lookup host in fs export list */
+struct netcred *vfs_export_lookup(struct mount *, struct netexport *,
+ struct mbuf *);
+int vfs_allocate_syncvnode(struct mount *);
+int speedup_syncer(void);
+
+int vfs_syncwait(struct proc *, int); /* sync and wait for complete */
+void vfs_shutdown(struct proc *); /* unmount and sync file systems */
+int dounmount(struct mount *, int, struct proc *);
+void vfsinit(void);
+struct vfsconf *vfs_byname(const char *);
+struct vfsconf *vfs_bytypenum(int);
+#else /* _KERNEL */
+__BEGIN_DECLS
+int fstatfs(int, struct statfs *);
+int getfh(const char *, fhandle_t *);
+int getfsstat(struct statfs *, size_t, int);
+int getmntinfo(struct statfs **, int);
+int mount(const char *, const char *, int, void *);
+int statfs(const char *, struct statfs *);
+int unmount(const char *, int);
+#if __BSD_VISIBLE
+struct stat;
+int fhopen(const fhandle_t *, int);
+int fhstat(const fhandle_t *, struct stat *);
+int fhstatfs(const fhandle_t *, struct statfs *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+#endif /* _KERNEL */
+#endif /* !_SYS_MOUNT_H_ */
diff --git a/sys/sys/mplock.h b/sys/sys/mplock.h
new file mode 100644
index 0000000..34f2f97
--- /dev/null
+++ b/sys/sys/mplock.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: mplock.h,v 1.13 2019/04/23 13:35:12 visa Exp $ */
+
+/*
+ * Copyright (c) 2004 Niklas Hallqvist. 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 _MPLOCK_H_
+#define _MPLOCK_H_
+
+#include <machine/mplock.h>
+
+#ifdef __USE_MI_MPLOCK
+
+#include <sys/_lock.h>
+
+struct __mp_lock_cpu {
+ u_int mplc_ticket;
+ u_int mplc_depth;
+};
+
+struct __mp_lock {
+ struct __mp_lock_cpu mpl_cpus[MAXCPUS];
+ volatile u_int mpl_ticket;
+ u_int mpl_users;
+#ifdef WITNESS
+ struct lock_object mpl_lock_obj;
+#endif
+};
+
+void ___mp_lock_init(struct __mp_lock *, const struct lock_type *);
+void __mp_lock(struct __mp_lock *);
+void __mp_unlock(struct __mp_lock *);
+int __mp_release_all(struct __mp_lock *);
+int __mp_release_all_but_one(struct __mp_lock *);
+void __mp_acquire_count(struct __mp_lock *, int);
+int __mp_lock_held(struct __mp_lock *, struct cpu_info *);
+
+#ifdef WITNESS
+
+#define __mp_lock_init(mpl) do { \
+ static const struct lock_type __lock_type = { .lt_name = #mpl };\
+ ___mp_lock_init((mpl), &__lock_type); \
+} while (0)
+
+#else /* WITNESS */
+
+#define __mp_lock_init(mpl) ___mp_lock_init((mpl), NULL)
+
+#endif /* WITNESS */
+
+#endif /* __USE_MI_MPLOCK */
+
+extern struct __mp_lock kernel_lock;
+
+#endif /* !_MPLOCK_H */
diff --git a/sys/sys/msg.h b/sys/sys/msg.h
new file mode 100644
index 0000000..96a4a0c
--- /dev/null
+++ b/sys/sys/msg.h
@@ -0,0 +1,177 @@
+/* $OpenBSD: msg.h,v 1.19 2014/11/23 04:31:42 guenther Exp $ */
+/* $NetBSD: msg.h,v 1.9 1996/02/09 18:25:18 christos Exp $ */
+
+/*
+ * SVID compatible msg.h file
+ *
+ * Author: Daniel Boulet
+ *
+ * Copyright 1993 Daniel Boulet and RTMX Inc.
+ *
+ * This system call was implemented by Daniel Boulet under contract from RTMX.
+ *
+ * Redistribution and use in source forms, with and without modification,
+ * are permitted provided that this entire comment appears intact.
+ *
+ * Redistribution in binary form may occur without any restrictions.
+ * Obviously, it would be nice if you gave credit where credit is due
+ * but requiring it would be too onerous.
+ *
+ * This software is provided ``AS IS'' without any warranties of any kind.
+ */
+
+#ifndef _SYS_MSG_H_
+#define _SYS_MSG_H_
+
+#include <sys/ipc.h>
+
+/*
+ * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000 /* don't complain about too long msgs */
+
+struct msqid_ds {
+ struct ipc_perm msg_perm; /* msg queue permission bits */
+ struct msg *msg_first; /* first message in the queue */
+ struct msg *msg_last; /* last message in the queue */
+ unsigned long msg_cbytes; /* number of bytes in use on the queue */
+ unsigned long msg_qnum; /* number of msgs in the queue */
+ unsigned long msg_qbytes; /* max # of bytes on the queue */
+ pid_t msg_lspid; /* pid of last msgsnd() */
+ pid_t msg_lrpid; /* pid of last msgrcv() */
+ time_t msg_stime; /* time of last msgsnd() */
+ long msg_pad1;
+ time_t msg_rtime; /* time of last msgrcv() */
+ long msg_pad2;
+ time_t msg_ctime; /* time of last msgctl() */
+ long msg_pad3;
+ long msg_pad4[4];
+};
+
+#ifdef _KERNEL
+#include <sys/queue.h>
+
+struct msg {
+ long msg_type;
+ size_t msg_len;
+ struct mbuf *msg_data;
+
+ TAILQ_ENTRY(msg) msg_next;
+};
+
+struct que {
+ struct msqid_ds msqid_ds;
+ int que_ix; /* pseudo-index */
+ int que_flags;
+ int que_references;
+
+ TAILQ_ENTRY(que) que_next;
+ TAILQ_HEAD(, msg) que_msgs;
+};
+
+/* for que_flags */
+#define MSGQ_READERS 0x01
+#define MSGQ_WRITERS 0x02
+#define MSGQ_DYING 0x04
+
+#define QREF(q) (q)->que_references++
+
+#define QRELE(q) do { \
+ if (--(q)->que_references == 0 && (q)->que_flags & MSGQ_DYING) \
+ wakeup_one(&(q)->que_references); \
+} while (0)
+#endif
+
+/*
+ * Structure describing a message. The SVID doesn't suggest any
+ * particular name for this structure. There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:". This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below. It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+struct mymsg {
+ long mtype; /* message type (+ve integer) */
+ char mtext[1]; /* message body */
+};
+
+
+#ifdef _KERNEL
+/*
+ * Based on the configuration parameters described in an SVR2 (yes, two)
+ * config(1m) man page.
+ *
+ * Each message is broken up and stored in segments that are msgssz bytes
+ * long. For efficiency reasons, this should be a power of two. Also,
+ * it doesn't make sense if it is less than 8 or greater than about 256.
+ * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
+ * two between 8 and 1024 inclusive (and panic's if it isn't).
+ */
+struct msginfo {
+ int msgmax, /* max chars in a message */
+ msgmni, /* max message queue identifiers */
+ msgmnb, /* max chars in a queue */
+ msgtql, /* max messages in system */
+ msgssz, /* size of a message segment (see notes above) */
+ msgseg; /* number of message segments */
+};
+#ifdef SYSVMSG
+extern struct msginfo msginfo;
+#endif
+
+int sysctl_sysvmsg(int *, u_int, void *, size_t *);
+
+struct msg_sysctl_info {
+ struct msginfo msginfo;
+ struct msqid_ds msgids[1];
+};
+
+#ifndef MSGSSZ
+#define MSGSSZ 8 /* Each segment must be 2^N long */
+#endif
+#ifndef MSGSEG
+#define MSGSEG 2048 /* must be less than 32767 */
+#endif
+#undef MSGMAX /* ALWAYS compute MSGMAX! */
+#define MSGMAX (MSGSSZ*MSGSEG)
+#ifndef MSGMNB
+#define MSGMNB 2048 /* max # of bytes in a queue */
+#endif
+#ifndef MSGMNI
+#define MSGMNI 40
+#endif
+#ifndef MSGTQL
+#define MSGTQL 40
+#endif
+
+/*
+ * macros to convert between msqid_ds's and msqid's.
+ * XXX unused, going away
+ */
+#define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
+#define MSQID_IX(id) ((id) & 0xffff)
+#define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
+#endif
+
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int msgctl(int, int, struct msqid_ds *);
+int msgget(key_t, int);
+int msgsnd(int, const void *, size_t, int);
+int msgrcv(int, void *, size_t, long, int);
+__END_DECLS
+#else
+struct proc;
+
+void msginit(void);
+int msgctl1(struct proc *, int, int, caddr_t,
+ int (*)(const void *, void *, size_t),
+ int (*)(const void *, void *, size_t));
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_MSG_H_ */
diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h
new file mode 100644
index 0000000..3a53a5a
--- /dev/null
+++ b/sys/sys/msgbuf.h
@@ -0,0 +1,53 @@
+/* $OpenBSD: msgbuf.h,v 1.11 2016/06/23 13:15:21 bluhm Exp $ */
+/* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */
+
+/*
+ * Copyright (c) 1981, 1984, 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.
+ *
+ * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93
+ */
+
+struct msgbuf {
+#define MSG_MAGIC 0x063061
+ long msg_magic;
+ long msg_bufx; /* write pointer */
+ long msg_bufr; /* read pointer */
+ long msg_bufs; /* real msg_bufc size (bytes) */
+ long msg_bufl; /* # chars, <= msg_bufs */
+ long msg_bufd; /* number of dropped bytes */
+ char msg_bufc[1]; /* buffer */
+};
+#ifdef _KERNEL
+#define CONSBUFSIZE (16 * 1024) /* console message buffer size */
+extern struct msgbuf *msgbufp;
+extern struct msgbuf *consbufp;
+
+void initmsgbuf(caddr_t buf, size_t bufsize);
+void initconsbuf(void);
+void msgbuf_putchar(struct msgbuf *, const char c);
+#endif
diff --git a/sys/sys/mtio.h b/sys/sys/mtio.h
new file mode 100644
index 0000000..fa7a32b
--- /dev/null
+++ b/sys/sys/mtio.h
@@ -0,0 +1,147 @@
+/* $OpenBSD: mtio.h,v 1.9 2007/06/01 18:44:48 krw Exp $ */
+/* $NetBSD: mtio.h,v 1.14 1997/04/15 06:50:19 lukem 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.
+ *
+ * @(#)mtio.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_MTIO_H_
+#define _SYS_MTIO_H_
+
+/*
+ * Structures and definitions for mag tape io control commands
+ */
+
+/* structure for MTIOCTOP - mag tape op command */
+struct mtop {
+ short mt_op; /* operations defined below */
+ int mt_count; /* how many of them */
+};
+
+/* operations */
+#define MTWEOF 0 /* write an end-of-file record */
+#define MTFSF 1 /* forward space file */
+#define MTBSF 2 /* backward space file */
+#define MTFSR 3 /* forward space record */
+#define MTBSR 4 /* backward space record */
+#define MTREW 5 /* rewind */
+#define MTOFFL 6 /* rewind and put the drive offline */
+#define MTNOP 7 /* no operation, sets status only */
+#define MTRETEN 8 /* retension */
+#define MTERASE 9 /* erase entire tape */
+#define MTEOM 10 /* forward to end of media */
+#define MTNBSF 11 /* backward space to beginning of file */
+#define MTCACHE 12 /* enable controller cache */
+#define MTNOCACHE 13 /* disable controller cache */
+#define MTSETBSIZ 14 /* set block size; 0 for variable */
+#define MTSETDNSTY 15 /* set density code for current mode */
+
+/* structure for MTIOCGET - mag tape get status command */
+
+struct mtget {
+ short mt_type; /* type of magtape device */
+/* the following two registers are grossly device dependent */
+ short mt_dsreg; /* ``drive status'' register */
+ short mt_erreg; /* ``error'' register */
+/* end device-dependent registers */
+ short mt_resid; /* residual count */
+ int mt_fileno; /* current file number relative to BOT. */
+ int mt_blkno; /* current block number relative to BOF. */
+ int mt_blksiz; /* current block size */
+ int mt_density; /* current density code */
+ int mt_mblksiz; /* default block size */
+ int mt_mdensity; /* default density code */
+};
+
+/*
+ * Constants for mt_type byte. These are the same
+ * for controllers compatible with the types listed.
+ */
+#define MT_ISTS 0x01 /* TS-11 */
+#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */
+#define MT_ISTM 0x03 /* TM11/TE10 Unibus */
+#define MT_ISMT 0x04 /* TM78/TU78 Massbus */
+#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */
+#define MT_ISCPC 0x06 /* SUN */
+#define MT_ISAR 0x07 /* SUN */
+#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */
+#define MT_ISCY 0x09 /* CCI Cipher */
+#define MT_ISCT 0x0a /* HP 1/4 tape */
+#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */
+#define MT_ISEXABYTE 0x0c /* Exabyte */
+#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */
+#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */
+#define MT_ISVIPER1 0x0e /* Archive Viper-150 */
+#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */
+#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */
+#define MT_ISWANGTEK 0x11 /* WANGTEK 5150ES */
+#define MT_ISCALIPER 0x12 /* Caliper CP150 */
+#define MT_ISWTEK5099 0x13 /* WANGTEK 5099ES */
+#define MT_ISVIPER2525 0x14 /* Archive Viper 2525 */
+#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */
+#define MT_ISTK50 0x12 /* DEC SCSI TK50 */
+#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */
+
+/* bits defined for the mt_dsreg field */
+#define MT_DS_RDONLY 0x10 /* tape mounted readonly */
+#define MT_DS_MOUNTED 0x03 /* tape mounted (for control opens) */
+
+/* mag tape io control commands */
+#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */
+#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */
+#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */
+#define MTIOCEEOT _IO('m', 4) /* enable EOT error */
+
+/*
+ * When more SCSI-3 SSC (streaming device) devices are out there
+ * that support the full 32 byte type 2 structure, we'll have to
+ * rethink these ioctls to support all the entities they haul into
+ * the picture (64 bit blocks, logical file record numbers, etc..).
+ */
+#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */
+#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */
+#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */
+#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */
+
+#ifdef _KERNEL
+/*
+ * minor device number
+ */
+
+#define T_UNIT 003 /* unit selection */
+#define T_NOREWIND 004 /* no rewind on close */
+#define T_DENSEL 030 /* density select */
+#define T_800BPI 000 /* select 800 bpi */
+#define T_1600BPI 010 /* select 1600 bpi */
+#define T_6250BPI 020 /* select 6250 bpi */
+#define T_BADBPI 030 /* undefined selection */
+#endif /* _KERNEL */
+
+#endif /* !_SYS_MTIO_H_ */
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
new file mode 100644
index 0000000..22a375a
--- /dev/null
+++ b/sys/sys/mutex.h
@@ -0,0 +1,165 @@
+/* $OpenBSD: mutex.h,v 1.18 2019/04/23 13:35:12 visa Exp $ */
+
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_MUTEX_H_
+#define _SYS_MUTEX_H_
+
+/*
+ * A mutex is:
+ * - owned by a cpu.
+ * - non-recursive.
+ * - spinning.
+ * - not providing mutual exclusion between processes, only cpus.
+ * - providing interrupt blocking when necessary.
+ *
+ * Different mutexes can be nested, but not interleaved. This is ok:
+ * "mtx_enter(foo); mtx_enter(bar); mtx_leave(bar); mtx_leave(foo);"
+ * This is _not_ ok:
+ * "mtx_enter(foo); mtx_enter(bar); mtx_leave(foo); mtx_leave(bar);"
+ */
+
+#include <machine/mutex.h>
+
+#ifdef __USE_MI_MUTEX
+
+#include <sys/_lock.h>
+
+struct mutex {
+ volatile void *mtx_owner;
+ int mtx_wantipl;
+ int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
+};
+
+/*
+ * To prevent lock ordering problems with the kernel lock, we need to
+ * make sure we block all interrupts that can grab the kernel lock.
+ * The simplest way to achieve this is to make sure mutexes always
+ * raise the interrupt priority level to the highest level that has
+ * interrupts that grab the kernel lock.
+ */
+#ifdef MULTIPROCESSOR
+#define __MUTEX_IPL(ipl) \
+ (((ipl) > IPL_NONE && (ipl) < IPL_MPFLOOR) ? IPL_MPFLOOR : (ipl))
+#else
+#define __MUTEX_IPL(ipl) (ipl)
+#endif
+
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#endif
+
+void __mtx_init(struct mutex *, int);
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+
+#ifdef DIAGNOSTIC
+#define MUTEX_ASSERT_LOCKED(mtx) do { \
+ if (((mtx)->mtx_owner != curcpu()) && !(panicstr || db_active)) \
+ panic("mutex %p not held in %s", (mtx), __func__); \
+} while (0)
+
+#define MUTEX_ASSERT_UNLOCKED(mtx) do { \
+ if (((mtx)->mtx_owner == curcpu()) && !(panicstr || db_active)) \
+ panic("mutex %p held in %s", (mtx), __func__); \
+} while (0)
+#else
+#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0)
+#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
+#endif
+
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
+#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
+
+#endif /* __USE_MI_MUTEX */
+
+
+#define MTX_LO_FLAGS(flags) \
+ ((!((flags) & MTX_NOWITNESS) ? LO_WITNESS : 0) | \
+ ((flags) & MTX_DUPOK ? LO_DUPOK : 0) | \
+ LO_INITIALIZED | (LO_CLASS_MUTEX << LO_CLASSSHIFT))
+
+#define __MTX_STRING(x) #x
+#define __MTX_S(x) __MTX_STRING(x)
+#define __MTX_NAME __FILE__ ":" __MTX_S(__LINE__)
+
+#define MTX_LO_INITIALIZER(name, flags) \
+ { .lo_type = &(const struct lock_type){ .lt_name = __MTX_NAME }, \
+ .lo_name = (name), \
+ .lo_flags = MTX_LO_FLAGS(flags) }
+
+#define MTX_NOWITNESS 0x01
+#define MTX_DUPOK 0x02
+
+#define MUTEX_INITIALIZER(ipl) \
+ MUTEX_INITIALIZER_FLAGS(ipl, __MTX_NAME, 0)
+
+/*
+ * Some architectures need to do magic for the ipl, so they need a macro.
+ */
+#ifndef _mtx_init
+void _mtx_init(struct mutex *, int);
+#endif
+
+void mtx_enter(struct mutex *);
+int mtx_enter_try(struct mutex *);
+void mtx_leave(struct mutex *);
+
+#define mtx_init(m, ipl) mtx_init_flags(m, ipl, NULL, 0)
+
+#ifdef WITNESS
+
+void _mtx_init_flags(struct mutex *, int, const char *, int,
+ const struct lock_type *);
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #m }; \
+ _mtx_init_flags(m, ipl, name, flags, &__lock_type); \
+} while (0)
+
+#else /* WITNESS */
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ (void)(name); (void)(flags); \
+ _mtx_init(m, ipl); \
+} while (0)
+
+#define _mtx_init_flags(m,i,n,f,t) _mtx_init(m,i)
+
+#endif /* WITNESS */
+
+#if defined(_KERNEL) && defined(DDB)
+
+struct db_mutex {
+ struct cpu_info *mtx_owner;
+ unsigned long mtx_intr_state;
+};
+
+#define DB_MUTEX_INITIALIZER { NULL, 0 }
+
+void db_mtx_enter(struct db_mutex *);
+void db_mtx_leave(struct db_mutex *);
+
+#endif /* _KERNEL && DDB */
+
+#endif
diff --git a/sys/sys/namei.h b/sys/sys/namei.h
new file mode 100644
index 0000000..975dfa9
--- /dev/null
+++ b/sys/sys/namei.h
@@ -0,0 +1,279 @@
+/* $OpenBSD: namei.h,v 1.45 2020/03/19 13:55:20 anton Exp $ */
+/* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */
+
+/*
+ * Copyright (c) 1985, 1989, 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.
+ *
+ * @(#)namei.h 8.4 (Berkeley) 8/20/94
+ */
+
+#ifndef _SYS_NAMEI_H_
+#define _SYS_NAMEI_H_
+
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/uio.h>
+
+struct unveil;
+
+/*
+ * Encapsulation of namei parameters.
+ */
+struct nameidata {
+ /*
+ * Arguments to namei/lookup.
+ */
+ const char *ni_dirp; /* pathname pointer */
+ int ni_dirfd; /* dirfd from *at() functions */
+ enum uio_seg ni_segflg; /* location of pathname */
+ /* u_long ni_nameiop; namei operation */
+ /* u_long ni_flags; flags to namei */
+ /* struct proc *ni_proc; process requesting lookup */
+ /*
+ * Arguments to lookup.
+ */
+ /* struct ucred *ni_cred; credentials */
+ struct vnode *ni_startdir; /* starting directory */
+ struct vnode *ni_rootdir; /* logical root directory */
+ uint64_t ni_pledge; /* expected pledge for namei */
+ u_char ni_unveil; /* required unveil flags for namei */
+ /*
+ * Results: returned from/manipulated by lookup
+ */
+ struct vnode *ni_vp; /* vnode of result */
+ struct vnode *ni_dvp; /* vnode of intermediate directory */
+
+ /*
+ * Shared between namei and lookup/commit routines.
+ */
+ size_t ni_pathlen; /* remaining chars in path */
+ char *ni_next; /* next location in pathname */
+ u_long ni_loopcnt; /* count of symlinks encountered */
+ struct unveil *ni_unveil_match; /* last matching unveil component */
+ struct vnode **ni_tvp; /* traversed vnodes */
+ size_t ni_tvpend; /* end of traversed vnode list */
+ size_t ni_tvpsize; /* size of traversed vnode list */
+ int ni_unveil_eacces; /* indicates unveil flag mismatch */
+
+ /*
+ * Lookup parameters: this structure describes the subset of
+ * information from the nameidat satructure that is passed
+ * through the VOP interface.
+ */
+ struct componentname {
+ /*
+ * Arguments to lookup.
+ */
+ u_long cn_nameiop; /* namei operation */
+ u_long cn_flags; /* flags to namei */
+ struct proc *cn_proc; /* process requesting lookup */
+ struct ucred *cn_cred; /* credentials */
+ /*
+ * Shared between lookup and commit routines.
+ */
+ char *cn_pnbuf; /* pathname buffer */
+ char *cn_rpbuf; /* realpath buffer */
+ size_t cn_rpi; /* realpath index */
+ char *cn_nameptr; /* pointer to looked up name */
+ long cn_namelen; /* length of looked up component */
+ long cn_consume; /* chars to consume in lookup() */
+ } ni_cnd;
+};
+
+#ifdef _KERNEL
+/*
+ * namei operations
+ */
+#define LOOKUP 0 /* perform name lookup only */
+#define CREATE 1 /* setup for file creation */
+#define DELETE 2 /* setup for file deletion */
+#define RENAME 3 /* setup for file renaming */
+#define OPMASK 3 /* mask for operation */
+/*
+ * namei operational modifier flags, stored in ni_cnd.flags
+ */
+#define LOCKLEAF 0x0004 /* lock inode on return */
+#define LOCKPARENT 0x0008 /* want parent vnode returned locked */
+#define WANTPARENT 0x0010 /* want parent vnode returned unlocked */
+#define NOCACHE 0x0020 /* name must not be left in cache */
+#define FOLLOW 0x0040 /* follow symbolic links */
+#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
+#define MODMASK 0x00fc /* mask of operational modifiers */
+/*
+ * Namei parameter descriptors.
+ *
+ * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
+ * If the caller of namei sets the flag (for example execve wants to
+ * know the name of the program that is being executed), then it must
+ * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
+ * be freed by either the commit routine or the VOP_ABORT routine.
+ * SAVESTART is set only by the callers of namei. It implies SAVENAME
+ * plus the addition of saving the parent directory that contains the
+ * name in ni_startdir. It allows repeated calls to lookup for the
+ * name being sought. The caller is responsible for releasing the
+ * buffer and for vrele'ing ni_startdir.
+ */
+#define NOCROSSMOUNT 0x000100 /* do not cross mount points */
+#define RDONLY 0x000200 /* lookup with read-only semantics */
+#define HASBUF 0x000400 /* has allocated pathname buffer */
+#define SAVENAME 0x000800 /* save pathanme buffer */
+#define SAVESTART 0x001000 /* save starting directory */
+#define ISDOTDOT 0x002000 /* current component name is .. */
+#define MAKEENTRY 0x004000 /* entry is to be added to name cache */
+#define ISLASTCN 0x008000 /* this is last component of pathname */
+#define ISSYMLINK 0x010000 /* symlink needs interpretation */
+#define REALPATH 0x020000 /* save pathname buffer for realpath */
+#define REQUIREDIR 0x080000 /* must be a directory */
+#define STRIPSLASHES 0x100000 /* strip trailing slashes */
+#define PDIRUNLOCK 0x200000 /* vfs_lookup() unlocked parent dir */
+#define BYPASSUNVEIL 0x400000 /* bypass pledgepath check */
+#define KERNELPATH 0x800000 /* access file as kernel, not process */
+
+/*
+ * Initialization of an nameidata structure.
+ */
+void ndinitat(struct nameidata *ndp, u_long op, u_long flags,
+ enum uio_seg segflg, int dirfd, const char *namep, struct proc *p);
+
+#define NDINITAT(ndp, op, flags, segflg, dirfd, namep, p) \
+ ndinitat(ndp, op, flags, segflg, dirfd, namep, p)
+
+#define NDINIT(ndp, op, flags, segflp, namep, p) \
+ ndinitat(ndp, op, flags, segflp, AT_FDCWD, namep, p)
+
+/* Defined for users of NDINIT(). */
+#define AT_FDCWD -100
+#endif
+
+/*
+ * This structure describes the elements in the cache of recent
+ * names looked up by namei.
+ */
+
+#define NAMECACHE_MAXLEN 31 /* maximum name segment length we bother with */
+
+struct namecache {
+ TAILQ_ENTRY(namecache) nc_lru; /* Regular Entry LRU chain */
+ TAILQ_ENTRY(namecache) nc_neg; /* Negative Entry LRU chain */
+ RBT_ENTRY(namecache) n_rbcache; /* Namecache rb tree from vnode */
+ TAILQ_ENTRY(namecache) nc_me; /* ncp's referring to me */
+ struct vnode *nc_dvp; /* vnode of parent of name */
+ u_long nc_dvpid; /* capability number of nc_dvp */
+ struct vnode *nc_vp; /* vnode the name refers to */
+ u_long nc_vpid; /* capability number of nc_vp */
+ char nc_nlen; /* length of name */
+ char nc_name[NAMECACHE_MAXLEN]; /* segment name */
+};
+
+#ifdef _KERNEL
+struct namecache_rb_cache;
+
+int namei(struct nameidata *ndp);
+int vfs_lookup(struct nameidata *ndp);
+int vfs_relookup(struct vnode *dvp, struct vnode **vpp,
+ struct componentname *cnp);
+void cache_tree_init(struct namecache_rb_cache *);
+void cache_purge(struct vnode *);
+int cache_lookup(struct vnode *, struct vnode **, struct componentname *);
+void cache_enter(struct vnode *, struct vnode *, struct componentname *);
+int cache_revlookup(struct vnode *, struct vnode **, char **, char *);
+void nchinit(void);
+struct mount;
+void cache_purgevfs(struct mount *);
+
+int unveil_add(struct proc *, struct nameidata *, const char *);
+void unveil_removevnode(struct vnode *);
+void unveil_free_traversed_vnodes(struct nameidata *);
+ssize_t unveil_find_cover(struct vnode *, struct proc *);
+struct unveil *unveil_lookup(struct vnode *, struct process *, ssize_t *);
+void unveil_start_relative(struct proc *, struct nameidata *, struct vnode *);
+void unveil_check_component(struct proc *, struct nameidata *, struct vnode *);
+int unveil_check_final(struct proc *, struct nameidata *);
+
+extern struct pool namei_pool;
+
+#endif
+
+/*
+ * Stats on usefulness of namei caches.
+ */
+struct nchstats {
+ u_int64_t ncs_goodhits; /* hits that we can really use */
+ u_int64_t ncs_neghits; /* negative hits that we can use */
+ u_int64_t ncs_badhits; /* hits we must drop */
+ u_int64_t ncs_falsehits; /* hits with id mismatch */
+ u_int64_t ncs_miss; /* misses */
+ u_int64_t ncs_long; /* long names that ignore cache */
+ u_int64_t ncs_pass2; /* names found with passes == 2 */
+ u_int64_t ncs_2passes; /* number of times we attempt it */
+ u_int64_t ncs_revhits; /* reverse-cache hits */
+ u_int64_t ncs_revmiss; /* reverse-cache misses */
+ u_int64_t ncs_dothits; /* hits on '.' lookups */
+ u_int64_t ncs_dotdothits; /* hits on '..' lookups */
+};
+
+/* These sysctl names are only really used by sysctl(8) */
+#define KERN_NCHSTATS_GOODHITS 1
+#define KERN_NCHSTATS_NEGHITS 2
+#define KERN_NCHSTATS_BADHITS 3
+#define KERN_NCHSTATS_FALSEHITS 4
+#define KERN_NCHSTATS_MISS 5
+#define KERN_NCHSTATS_LONG 6
+#define KERN_NCHSTATS_PASS2 7
+#define KERN_NCHSTATS_2PASSES 8
+#define KERN_NCHSTATS_REVHITS 9
+#define KERN_NCHSTATS_REVMISS 10
+#define KERN_NCHSTATS_DOTHITS 11
+#define KERN_NCHSTATS_DOTDOTHITS 12
+#define KERN_NCHSTATS_MAXID 13
+
+#define CTL_KERN_NCHSTATS_NAMES { \
+ { 0, 0 }, \
+ { "good_hits", CTLTYPE_QUAD }, \
+ { "negative_hits", CTLTYPE_QUAD }, \
+ { "bad_hits", CTLTYPE_QUAD }, \
+ { "false_hits", CTLTYPE_QUAD }, \
+ { "misses", CTLTYPE_QUAD }, \
+ { "long_names", CTLTYPE_QUAD }, \
+ { "pass2", CTLTYPE_QUAD }, \
+ { "2passes", CTLTYPE_QUAD }, \
+ { "ncs_revhits", CTLTYPE_QUAD }, \
+ { "ncs_revmiss", CTLTYPE_QUAD }, \
+ { "ncs_dothits", CTLTYPE_QUAD }, \
+ { "nch_dotdothits", CTLTYPE_QUAD }, \
+}
+
+/* Unveil flags for namei */
+#define UNVEIL_READ 0x01
+#define UNVEIL_WRITE 0x02
+#define UNVEIL_CREATE 0x04
+#define UNVEIL_EXEC 0x08
+#define UNVEIL_USERSET 0x0F
+#define UNVEIL_INSPECT 0x80
+
+#endif /* !_SYS_NAMEI_H_ */
diff --git a/sys/sys/param.h b/sys/sys/param.h
new file mode 100644
index 0000000..76c5e2f
--- /dev/null
+++ b/sys/sys/param.h
@@ -0,0 +1,223 @@
+/* $OpenBSD: param.h,v 1.130 2020/04/05 06:34:20 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * 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.
+ */
+
+#ifndef _SYS_PARAM_H_
+#define _SYS_PARAM_H_
+
+#define BSD 199306 /* System version (year & month). */
+#define BSD4_3 1
+#define BSD4_4 1
+
+#define OpenBSD 202005 /* OpenBSD version (year & month). */
+#define OpenBSD6_7 1 /* OpenBSD 6.7 */
+
+#include <sys/_null.h>
+
+#ifndef _LOCORE
+#include <sys/types.h>
+#endif
+
+/*
+ * 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 <acct.h>)
+ * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
+ */
+#include <sys/syslimits.h>
+
+#define MAXCOMLEN 16 /* max command name remembered */
+#define MAXINTERP 128 /* max interpreter file name length */
+#define MAXLOGNAME LOGIN_NAME_MAX /* max login name length w/ NUL */
+#define MAXUPRC CHILD_MAX /* max simultaneous processes */
+#define NCARGS ARG_MAX /* max bytes for an exec function */
+#define NGROUPS NGROUPS_MAX /* max number groups */
+#define NOFILE OPEN_MAX /* max open files per process (soft) */
+#define NOFILE_MAX 1024 /* max open files per process (hard) */
+#define NOGROUP 65535 /* marker for empty group set member */
+#define MAXHOSTNAMELEN 256 /* max hostname length w/ NUL */
+
+/* More types and definitions used throughout the kernel. */
+#ifdef _KERNEL
+#include <sys/errno.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/ucred.h>
+#include <sys/uio.h>
+#include <sys/srp.h>
+#endif
+
+/* Signals. */
+#include <sys/signal.h>
+
+/* Machine type dependent parameters. */
+#include <sys/limits.h>
+#include <machine/param.h>
+
+#ifdef _KERNEL
+/*
+ * Priorities. Note that with 32 run queues, differences less than 4 are
+ * insignificant.
+ */
+#define PSWP 0
+#define PVM 4
+#define PINOD 8
+#define PRIBIO 16
+#define PVFS 20
+#endif /* _KERNEL */
+#define PZERO 22 /* No longer magic, shouldn't be here. XXX */
+#ifdef _KERNEL
+#define PSOCK 24
+#define PWAIT 32
+#define PLOCK 36
+#define PPAUSE 40
+#define PUSER 50
+#define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
+
+#define PRIMASK 0x0ff
+#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
+#define PNORELOCK 0x200 /* OR'd with pri for msleep to not reaquire
+ the mutex */
+#endif /* _KERNEL */
+
+#define NODEV (dev_t)(-1) /* non-existent device */
+
+#define ALIGNBYTES _ALIGNBYTES
+#define ALIGN(p) _ALIGN(p)
+#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t)
+
+/*
+ * 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 makes some file systems unmountable.
+ */
+#ifdef _KERNEL
+#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
+#endif /* _KERNEL */
+#define MAXBSIZE (64 * 1024)
+
+#define _DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1 << _DEV_BSHIFT)
+#ifdef _KERNEL
+#define DEV_BSHIFT _DEV_BSHIFT
+#define BLKDEV_IOSIZE PAGE_SIZE
+#endif /* _KERNEL */
+
+/* pages to disk blocks */
+#ifndef ctod
+#define ctod(x) ((x) << (PAGE_SHIFT - _DEV_BSHIFT))
+#endif
+#ifndef dtoc
+#define dtoc(x) ((x) >> (PAGE_SHIFT - _DEV_BSHIFT))
+#endif
+
+/* bytes to disk blocks */
+#ifndef btodb
+#define btodb(x) ((x) >> _DEV_BSHIFT)
+#endif
+#ifndef dbtob
+#define dbtob(x) ((x) << _DEV_BSHIFT)
+#endif
+
+/*
+ * 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.
+ */
+#define MAXPATHLEN PATH_MAX
+#define MAXSYMLINKS SYMLOOP_MAX
+
+/* Macros to set/clear/test flags. */
+#ifdef _KERNEL
+#define SET(t, f) ((t) |= (f))
+#define CLR(t, f) ((t) &= ~(f))
+#define ISSET(t, f) ((t) & (f))
+#endif /* _KERNEL */
+
+/* Bit map related macros. */
+#define setbit(a,i) ((a)[(i)>>3] |= 1<<((i)&(NBBY-1)))
+#define clrbit(a,i) ((a)[(i)>>3] &= ~(1<<((i)&(NBBY-1))))
+#define isset(a,i) ((a)[(i)>>3] & (1<<((i)&(NBBY-1))))
+#define isclr(a,i) (((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) == 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 powerof2(x) ((((x)-1)&(x))==0)
+
+/* Macros for min/max. */
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+/* Macros for calculating the offset of a field */
+#if !defined(offsetof) && defined(_KERNEL)
+#if __GNUC_PREREQ__(4, 0)
+#define offsetof(s, e) __builtin_offsetof(s, e)
+#else
+#define offsetof(s, e) ((size_t)&((s *)0)->e)
+#endif
+#endif /* !defined(offsetof) && defined(_KERNEL) */
+
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+
+/*
+ * Scale factor for scaled integers used to count %cpu time and load avgs.
+ *
+ * The number of CPU `tick's that map to a unique `%age' can be expressed
+ * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
+ * can be calculated (assuming 32 bits) can be closely approximated using
+ * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
+ *
+ * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
+ * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
+ */
+#define _FSHIFT 11 /* bits to right of fixed binary point */
+#ifdef _KERNEL
+#define FSHIFT _FSHIFT
+#endif
+#define FSCALE (1<<_FSHIFT)
+
+#endif /* !_SYS_PARAM_H_ */
diff --git a/sys/sys/pciio.h b/sys/sys/pciio.h
new file mode 100644
index 0000000..713e798
--- /dev/null
+++ b/sys/sys/pciio.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: pciio.h,v 1.7 2010/09/05 18:14:33 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1997, Stefan Esser <se@FreeBSD.ORG>
+ * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry <ken@FreeBSD.ORG>
+ * 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 unmodified, 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: src/sys/sys/pciio.h,v 1.5 1999/12/08 17:44:04 ken Exp $
+ *
+ */
+
+#ifndef _SYS_PCIIO_H_
+#define _SYS_PCIIO_H_
+
+#include <sys/ioccom.h>
+
+struct pcisel {
+ u_int8_t pc_bus; /* bus number */
+ u_int8_t pc_dev; /* device on this bus */
+ u_int8_t pc_func; /* function on this device */
+};
+
+struct pci_io {
+ struct pcisel pi_sel; /* device to operate on */
+ int pi_reg; /* configuration register to examine */
+ int pi_width; /* width (in bytes) of read or write */
+ u_int32_t pi_data; /* data to write or result of read */
+};
+
+struct pci_rom {
+ struct pcisel pr_sel;
+ int pr_romlen;
+ char *pr_rom;
+};
+
+struct pci_vga {
+ struct pcisel pv_sel;
+ int pv_lock;
+ int pv_decode;
+};
+
+#define PCI_VGA_UNLOCK 0x00
+#define PCI_VGA_LOCK 0x01
+#define PCI_VGA_TRYLOCK 0x02
+
+#define PCI_VGA_IO_ENABLE 0x01
+#define PCI_VGA_MEM_ENABLE 0x02
+
+#define PCIOCREAD _IOWR('p', 2, struct pci_io)
+#define PCIOCWRITE _IOWR('p', 3, struct pci_io)
+#define PCIOCGETROMLEN _IOWR('p', 4, struct pci_rom)
+#define PCIOCGETROM _IOWR('p', 5, struct pci_rom)
+#define PCIOCGETVGA _IOWR('p', 6, struct pci_vga)
+#define PCIOCSETVGA _IOWR('p', 7, struct pci_vga)
+#define PCIOCREADMASK _IOWR('p', 8, struct pci_io)
+
+#endif /* !_SYS_PCIIO_H_ */
diff --git a/sys/sys/percpu.h b/sys/sys/percpu.h
new file mode 100644
index 0000000..53a1a88
--- /dev/null
+++ b/sys/sys/percpu.h
@@ -0,0 +1,198 @@
+/* $OpenBSD: percpu.h,v 1.8 2018/08/28 15:15:02 mpi Exp $ */
+
+/*
+ * Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_PERCPU_H_
+#define _SYS_PERCPU_H_
+
+#ifndef CACHELINESIZE
+#define CACHELINESIZE 64
+#endif
+
+#ifndef __upunused /* this should go in param.h */
+#ifdef MULTIPROCESSOR
+#define __upunused
+#else
+#define __upunused __attribute__((__unused__))
+#endif
+#endif
+
+struct cpumem {
+ void *mem;
+};
+
+struct cpumem_iter {
+ unsigned int cpu;
+} __upunused;
+
+struct counters_ref {
+ uint64_t g;
+ uint64_t *c;
+};
+
+#ifdef _KERNEL
+
+#include <sys/atomic.h>
+
+struct pool;
+
+struct cpumem *cpumem_get(struct pool *);
+void cpumem_put(struct pool *, struct cpumem *);
+
+struct cpumem *cpumem_malloc(size_t, int);
+struct cpumem *cpumem_malloc_ncpus(struct cpumem *, size_t, int);
+void cpumem_free(struct cpumem *, int, size_t);
+
+void *cpumem_first(struct cpumem_iter *, struct cpumem *);
+void *cpumem_next(struct cpumem_iter *, struct cpumem *);
+
+static inline void *
+cpumem_enter(struct cpumem *cm)
+{
+#ifdef MULTIPROCESSOR
+ return (cm[cpu_number()].mem);
+#else
+ return (cm);
+#endif
+}
+
+static inline void
+cpumem_leave(struct cpumem *cm, void *mem)
+{
+ /* KDASSERT? */
+}
+
+#ifdef MULTIPROCESSOR
+
+#define CPUMEM_BOOT_MEMORY(_name, _sz) \
+static struct { \
+ unsigned char mem[_sz]; \
+ struct cpumem cpumem; \
+} __aligned(CACHELINESIZE) _name##_boot_cpumem = { \
+ .cpumem = { _name##_boot_cpumem.mem } \
+}
+
+#define CPUMEM_BOOT_INITIALIZER(_name) \
+ { &_name##_boot_cpumem.cpumem }
+
+#else /* MULTIPROCESSOR */
+
+#define CPUMEM_BOOT_MEMORY(_name, _sz) \
+static struct { \
+ unsigned char mem[_sz]; \
+} __aligned(sizeof(uint64_t)) _name##_boot_cpumem
+
+#define CPUMEM_BOOT_INITIALIZER(_name) \
+ { (struct cpumem *)&_name##_boot_cpumem.mem }
+
+#endif /* MULTIPROCESSOR */
+
+#define CPUMEM_FOREACH(_var, _iter, _cpumem) \
+ for ((_var) = cpumem_first((_iter), (_cpumem)); \
+ (_var) != NULL; \
+ (_var) = cpumem_next((_iter), (_cpumem)))
+
+/*
+ * per cpu counters
+ */
+
+struct cpumem *counters_alloc(unsigned int);
+struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int);
+void counters_free(struct cpumem *, unsigned int);
+void counters_read(struct cpumem *, uint64_t *, unsigned int);
+void counters_zero(struct cpumem *, unsigned int);
+
+static inline uint64_t *
+counters_enter(struct counters_ref *ref, struct cpumem *cm)
+{
+ ref->c = cpumem_enter(cm);
+#ifdef MULTIPROCESSOR
+ ref->g = ++(*ref->c); /* make the generation number odd */
+ membar_producer();
+ return (ref->c + 1);
+#else
+ return (ref->c);
+#endif
+}
+
+static inline void
+counters_leave(struct counters_ref *ref, struct cpumem *cm)
+{
+#ifdef MULTIPROCESSOR
+ membar_producer();
+ (*ref->c) = ++ref->g; /* make the generation number even again */
+#endif
+ cpumem_leave(cm, ref->c);
+}
+
+static inline void
+counters_inc(struct cpumem *cm, unsigned int c)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]++;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_dec(struct cpumem *cm, unsigned int c)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]--;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_add(struct cpumem *cm, unsigned int c, uint64_t v)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c] += v;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_pkt(struct cpumem *cm, unsigned int c, unsigned int b, uint64_t v)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]++;
+ counters[b] += v;
+ counters_leave(&ref, cm);
+}
+
+#ifdef MULTIPROCESSOR
+#define COUNTERS_BOOT_MEMORY(_name, _n) \
+ CPUMEM_BOOT_MEMORY(_name, ((_n) + 1) * sizeof(uint64_t))
+#else
+#define COUNTERS_BOOT_MEMORY(_name, _n) \
+ CPUMEM_BOOT_MEMORY(_name, (_n) * sizeof(uint64_t))
+#endif
+
+#define COUNTERS_BOOT_INITIALIZER(_name) CPUMEM_BOOT_INITIALIZER(_name)
+
+#endif /* _KERNEL */
+#endif /* _SYS_PERCPU_H_ */
diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h
new file mode 100644
index 0000000..d23f266
--- /dev/null
+++ b/sys/sys/pipe.h
@@ -0,0 +1,96 @@
+/* $OpenBSD: pipe.h,v 1.24 2020/01/24 11:07:41 anton Exp $ */
+
+/*
+ * Copyright (c) 1996 John S. Dyson
+ * 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 immediately at the beginning of the file, without modification,
+ * 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. Absolutely no warranty of function or purpose is made by the author
+ * John S. Dyson.
+ * 4. This work was done expressly for inclusion into FreeBSD. Other use
+ * is allowed if this notation is included.
+ * 5. Modifications may be freely made to this file if the above conditions
+ * are met.
+ */
+
+#ifndef _SYS_PIPE_H_
+#define _SYS_PIPE_H_
+
+#ifndef _KERNEL
+#include <sys/time.h> /* for struct timespec */
+#include <sys/selinfo.h> /* for struct selinfo */
+#endif /* _KERNEL */
+
+#include <sys/sigio.h> /* for struct sigio_ref */
+
+/*
+ * Pipe buffer size, keep moderate in value, pipes take kva space.
+ */
+#ifndef PIPE_SIZE
+#define PIPE_SIZE 16384
+#endif
+
+#ifndef BIG_PIPE_SIZE
+#define BIG_PIPE_SIZE (64*1024)
+#endif
+
+/*
+ * Pipe buffer information.
+ * Separate in, out, cnt are used to simplify calculations.
+ * Buffered write is active when the buffer.cnt field is set.
+ */
+struct pipebuf {
+ u_int cnt; /* number of chars currently in buffer */
+ u_int in; /* in pointer */
+ u_int out; /* out pointer */
+ u_int size; /* size of buffer */
+ caddr_t buffer; /* kva of buffer */
+};
+
+/*
+ * Bits in pipe_state.
+ */
+#define PIPE_ASYNC 0x004 /* Async? I/O. */
+#define PIPE_WANTR 0x008 /* Reader wants some characters. */
+#define PIPE_WANTW 0x010 /* Writer wants space to put characters. */
+#define PIPE_WANTD 0x020 /* Pipe is wanted to be run-down. */
+#define PIPE_SEL 0x040 /* Pipe has a select active. */
+#define PIPE_EOF 0x080 /* Pipe is in EOF condition. */
+#define PIPE_LOCK 0x100 /* Thread has exclusive I/O access. */
+#define PIPE_LWANT 0x200 /* Thread wants exclusive I/O access. */
+
+/*
+ * Per-pipe data structure.
+ * Two of these are linked together to produce bi-directional pipes.
+ *
+ * Locking:
+ * I immutable after creation
+ * S sigio_lock
+ * p pipe_lock
+ */
+struct pipe {
+ struct rwlock *pipe_lock;
+ struct pipebuf pipe_buffer; /* [p] data storage */
+ struct selinfo pipe_sel; /* [p] for compat with select */
+ struct timespec pipe_atime; /* [p] time of last access */
+ struct timespec pipe_mtime; /* [p] time of last modify */
+ struct timespec pipe_ctime; /* [I] time of status change */
+ struct sigio_ref pipe_sigio; /* [S] async I/O registration */
+ struct pipe *pipe_peer; /* [p] link with other direction */
+ u_int pipe_state; /* [p] pipe status info */
+ int pipe_busy; /* [p] # readers/writers */
+};
+
+#ifdef _KERNEL
+void pipe_init(void);
+#endif /* _KERNEL */
+
+#endif /* !_SYS_PIPE_H_ */
diff --git a/sys/sys/pledge.h b/sys/sys/pledge.h
new file mode 100644
index 0000000..6dce461
--- /dev/null
+++ b/sys/sys/pledge.h
@@ -0,0 +1,147 @@
+/* $OpenBSD: pledge.h,v 1.41 2020/04/05 07:31:45 visa Exp $ */
+
+/*
+ * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
+ * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_PLEDGE_H_
+#define _SYS_PLEDGE_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * pledge(2) requests
+ */
+#define PLEDGE_ALWAYS 0xffffffffffffffffULL
+#define PLEDGE_RPATH 0x0000000000000001ULL /* allow open for read */
+#define PLEDGE_WPATH 0x0000000000000002ULL /* allow open for write */
+#define PLEDGE_CPATH 0x0000000000000004ULL /* allow creat, mkdir, unlink etc */
+#define PLEDGE_STDIO 0x0000000000000008ULL /* operate on own pid */
+#define PLEDGE_TMPPATH 0x0000000000000010ULL /* for mk*temp() */
+#define PLEDGE_DNS 0x0000000000000020ULL /* DNS services */
+#define PLEDGE_INET 0x0000000000000040ULL /* AF_INET/AF_INET6 sockets */
+#define PLEDGE_FLOCK 0x0000000000000080ULL /* file locking */
+#define PLEDGE_UNIX 0x0000000000000100ULL /* AF_UNIX sockets */
+#define PLEDGE_ID 0x0000000000000200ULL /* allow setuid, setgid, etc */
+#define PLEDGE_TAPE 0x0000000000000400ULL /* Tape ioctl */
+#define PLEDGE_GETPW 0x0000000000000800ULL /* YP enables if ypbind.lock */
+#define PLEDGE_PROC 0x0000000000001000ULL /* fork, waitpid, etc */
+#define PLEDGE_SETTIME 0x0000000000002000ULL /* able to set/adj time/freq */
+#define PLEDGE_FATTR 0x0000000000004000ULL /* allow explicit file st_* mods */
+#define PLEDGE_PROTEXEC 0x0000000000008000ULL /* allow use of PROT_EXEC */
+#define PLEDGE_TTY 0x0000000000010000ULL /* tty setting */
+#define PLEDGE_SENDFD 0x0000000000020000ULL /* AF_UNIX CMSG fd sending */
+#define PLEDGE_RECVFD 0x0000000000040000ULL /* AF_UNIX CMSG fd receiving */
+#define PLEDGE_EXEC 0x0000000000080000ULL /* execve, child is free of pledge */
+#define PLEDGE_ROUTE 0x0000000000100000ULL /* routing lookups */
+#define PLEDGE_MCAST 0x0000000000200000ULL /* multicast joins */
+#define PLEDGE_VMINFO 0x0000000000400000ULL /* vminfo listings */
+#define PLEDGE_PS 0x0000000000800000ULL /* ps listings */
+#define PLEDGE_DISKLABEL 0x0000000002000000ULL /* disklabels */
+#define PLEDGE_PF 0x0000000004000000ULL /* pf ioctls */
+#define PLEDGE_AUDIO 0x0000000008000000ULL /* audio ioctls */
+#define PLEDGE_DPATH 0x0000000010000000ULL /* mknod & mkfifo */
+#define PLEDGE_DRM 0x0000000020000000ULL /* drm ioctls */
+#define PLEDGE_VMM 0x0000000040000000ULL /* vmm ioctls */
+#define PLEDGE_CHOWN 0x0000000080000000ULL /* chown(2) family */
+#define PLEDGE_CHOWNUID 0x0000000100000000ULL /* allow owner/group changes */
+#define PLEDGE_BPF 0x0000000200000000ULL /* bpf ioctl */
+#define PLEDGE_ERROR 0x0000000400000000ULL /* ENOSYS instead of kill */
+#define PLEDGE_WROUTE 0x0000000800000000ULL /* interface address ioctls */
+#define PLEDGE_UNVEIL 0x0000001000000000ULL /* allow unveil() */
+#define PLEDGE_VIDEO 0x0000002000000000ULL /* video ioctls */
+
+/*
+ * Bits outside PLEDGE_USERSET are used by the kernel itself
+ * to track program behaviours which have been observed.
+ */
+#define PLEDGE_USERSET 0x0fffffffffffffffULL
+#define PLEDGE_YPACTIVE 0x8000000000000000ULL /* YP use detected and allowed */
+
+#ifdef PLEDGENAMES
+static const struct {
+ uint64_t bits;
+ const char *name;
+} pledgenames[] = {
+ { PLEDGE_RPATH, "rpath" },
+ { PLEDGE_WPATH, "wpath" },
+ { PLEDGE_CPATH, "cpath" },
+ { PLEDGE_STDIO, "stdio" },
+ { PLEDGE_TMPPATH, "tmppath" },
+ { PLEDGE_DNS, "dns" },
+ { PLEDGE_INET, "inet" },
+ { PLEDGE_FLOCK, "flock" },
+ { PLEDGE_UNIX, "unix" },
+ { PLEDGE_ID, "id" },
+ { PLEDGE_TAPE, "tape" },
+ { PLEDGE_GETPW, "getpw" },
+ { PLEDGE_PROC, "proc" },
+ { PLEDGE_SETTIME, "settime" },
+ { PLEDGE_FATTR, "fattr" },
+ { PLEDGE_PROTEXEC, "prot_exec" },
+ { PLEDGE_TTY, "tty" },
+ { PLEDGE_SENDFD, "sendfd" },
+ { PLEDGE_RECVFD, "recvfd" },
+ { PLEDGE_EXEC, "exec" },
+ { PLEDGE_ROUTE, "route" },
+ { PLEDGE_MCAST, "mcast" },
+ { PLEDGE_VMINFO, "vminfo" },
+ { PLEDGE_PS, "ps" },
+ { PLEDGE_DISKLABEL, "disklabel" },
+ { PLEDGE_PF, "pf" },
+ { PLEDGE_AUDIO, "audio" },
+ { PLEDGE_DPATH, "dpath" },
+ { PLEDGE_DRM, "drm" },
+ { PLEDGE_VMM, "vmm" },
+ { PLEDGE_CHOWNUID, "chown" },
+ { PLEDGE_BPF, "bpf" },
+ { PLEDGE_ERROR, "error" },
+ { PLEDGE_WROUTE, "wroute" },
+ { PLEDGE_UNVEIL, "unveil" },
+ { PLEDGE_VIDEO, "video" },
+ { 0, NULL },
+};
+#endif
+
+#ifdef _KERNEL
+
+int pledge_syscall(struct proc *, int, uint64_t *);
+int pledge_fail(struct proc *, int, uint64_t);
+
+struct mbuf;
+struct nameidata;
+int pledge_namei(struct proc *, struct nameidata *, char *);
+int pledge_sendfd(struct proc *p, struct file *);
+int pledge_recvfd(struct proc *p, struct file *);
+int pledge_sysctl(struct proc *p, int namelen, int *name, void *new);
+int pledge_chown(struct proc *p, uid_t, gid_t);
+int pledge_adjtime(struct proc *p, const void *v);
+int pledge_sendit(struct proc *p, const void *to);
+int pledge_sockopt(struct proc *p, int set, int level, int optname);
+int pledge_socket(struct proc *p, int domain, unsigned int state);
+int pledge_ioctl(struct proc *p, long com, struct file *);
+int pledge_ioctl_drm(struct proc *p, long com, dev_t device);
+int pledge_ioctl_vmm(struct proc *p, long com);
+int pledge_flock(struct proc *p);
+int pledge_fcntl(struct proc *p, int cmd);
+int pledge_swapctl(struct proc *p);
+int pledge_kill(struct proc *p, pid_t pid);
+int pledge_protexec(struct proc *p, int prot);
+void ppath_destroy(struct process *ps);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_PLEDGE_H_ */
diff --git a/sys/sys/poll.h b/sys/sys/poll.h
new file mode 100644
index 0000000..30daa17
--- /dev/null
+++ b/sys/sys/poll.h
@@ -0,0 +1,89 @@
+/* $OpenBSD: poll.h,v 1.15 2016/06/07 06:12:37 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1996 Theo de Raadt
+ * 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_POLL_H_
+#define _SYS_POLL_H_
+
+typedef struct pollfd {
+ int fd;
+ short events;
+ short revents;
+} pollfd_t;
+
+typedef unsigned int nfds_t;
+
+#define POLLIN 0x0001
+#define POLLPRI 0x0002
+#define POLLOUT 0x0004
+#define POLLERR 0x0008
+#define POLLHUP 0x0010
+#define POLLNVAL 0x0020
+#define POLLRDNORM 0x0040
+#define POLLNORM POLLRDNORM
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0080
+#define POLLWRBAND 0x0100
+#ifdef _KERNEL
+#define POLL_NOHUP 0x1000 /* internal use only */
+#endif
+
+#define INFTIM (-1)
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+
+#if __BSD_VISIBLE
+#include <sys/_types.h>
+
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#ifndef _TIME_T_DEFINED_
+#define _TIME_T_DEFINED_
+typedef __time_t time_t;
+#endif
+
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+#endif /* __BSD_VISIBLE */
+
+__BEGIN_DECLS
+int poll(struct pollfd[], nfds_t, int);
+#if __BSD_VISIBLE
+int ppoll(struct pollfd[], nfds_t, const struct timespec *, const sigset_t *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+#endif /* _KERNEL */
+
+#endif /* !_SYS_POLL_H_ */
diff --git a/sys/sys/pool.h b/sys/sys/pool.h
new file mode 100644
index 0000000..7f68d50
--- /dev/null
+++ b/sys/sys/pool.h
@@ -0,0 +1,295 @@
+/* $OpenBSD: pool.h,v 1.77 2019/07/19 09:03:03 bluhm Exp $ */
+/* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Kranenburg; 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.
+ */
+
+#ifndef _SYS_POOL_H_
+#define _SYS_POOL_H_
+
+/*
+ * sysctls.
+ * kern.pool.npools
+ * kern.pool.name.<number>
+ * kern.pool.pool.<number>
+ */
+#define KERN_POOL_NPOOLS 1
+#define KERN_POOL_NAME 2
+#define KERN_POOL_POOL 3
+#define KERN_POOL_CACHE 4 /* global pool cache info */
+#define KERN_POOL_CACHE_CPUS 5 /* all cpus cache info */
+
+struct kinfo_pool {
+ unsigned int pr_size; /* size of a pool item */
+ unsigned int pr_pgsize; /* size of a "page" */
+ unsigned int pr_itemsperpage; /* number of items per "page" */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of idle pages to keep */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_nitems; /* # items in the pool */
+
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+};
+
+struct kinfo_pool_cache {
+ uint64_t pr_ngc; /* # of times a list has been gc'ed */
+ unsigned int pr_len; /* current target for list len */
+ unsigned int pr_nitems; /* # of idle items in the depot */
+ unsigned int pr_contention; /* # of times mtx was busy */
+};
+
+/*
+ * KERN_POOL_CACHE_CPUS provides an array, not a single struct. ie, it
+ * provides struct kinfo_pool_cache_cpu kppc[ncpusfound].
+ */
+struct kinfo_pool_cache_cpu {
+ unsigned int pr_cpu; /* which cpu this cache is on */
+
+ /* counters for times items were handled by the cache */
+ uint64_t pr_nget; /* # of requests */
+ uint64_t pr_nfail; /* # of unsuccessful requests */
+ uint64_t pr_nput; /* # of releases */
+
+ /* counters for times the cache interacted with the pool */
+ uint64_t pr_nlget; /* # of list requests */
+ uint64_t pr_nlfail; /* # of unsuccessful list requests */
+ uint64_t pr_nlput; /* # of list releases */
+};
+
+#if defined(_KERNEL) || defined(_LIBKVM)
+
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/mutex.h>
+#include <sys/rwlock.h>
+
+struct pool;
+struct pool_request;
+struct pool_lock_ops;
+TAILQ_HEAD(pool_requests, pool_request);
+
+struct pool_allocator {
+ void *(*pa_alloc)(struct pool *, int, int *);
+ void (*pa_free)(struct pool *, void *);
+ size_t pa_pagesz;
+};
+
+/*
+ * The pa_pagesz member encodes the sizes of pages that can be
+ * provided by the allocator, and whether the allocations can be
+ * aligned to their size.
+ *
+ * Page sizes can only be powers of two. Each available page size is
+ * represented by its value set as a bit. e.g., to indicate that an
+ * allocator can provide 16k and 32k pages you initialise pa_pagesz
+ * to (32768 | 16384).
+ *
+ * If the allocator can provide aligned pages the low bit in pa_pagesz
+ * is set. The POOL_ALLOC_ALIGNED macro is provided as a convenience.
+ *
+ * If pa_pagesz is unset (i.e. 0), POOL_ALLOC_DEFAULT will be used
+ * instead.
+ */
+
+#define POOL_ALLOC_ALIGNED 1UL
+#define POOL_ALLOC_SIZE(_sz, _a) ((_sz) | (_a))
+#define POOL_ALLOC_SIZES(_min, _max, _a) \
+ ((_max) | \
+ (((_max) - 1) & ~((_min) - 1)) | (_a))
+
+#define POOL_ALLOC_DEFAULT \
+ POOL_ALLOC_SIZE(PAGE_SIZE, POOL_ALLOC_ALIGNED)
+
+TAILQ_HEAD(pool_pagelist, pool_page_header);
+
+struct pool_cache_item;
+TAILQ_HEAD(pool_cache_lists, pool_cache_item);
+struct cpumem;
+
+union pool_lock {
+ struct mutex prl_mtx;
+ struct rwlock prl_rwlock;
+};
+
+struct pool {
+ union pool_lock pr_lock;
+ const struct pool_lock_ops *
+ pr_lock_ops;
+ SIMPLEQ_ENTRY(pool)
+ pr_poollist;
+ struct pool_pagelist
+ pr_emptypages; /* Empty pages */
+ struct pool_pagelist
+ pr_fullpages; /* Full pages */
+ struct pool_pagelist
+ pr_partpages; /* Partially-allocated pages */
+ struct pool_page_header *
+ pr_curpage;
+ unsigned int pr_size; /* Size of item */
+ unsigned int pr_minitems; /* minimum # of items to keep */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of idle pages to keep */
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_itemsperpage;/* # items that fit in a page */
+ unsigned int pr_slack; /* unused space in a page */
+ unsigned int pr_nitems; /* number of available items in pool */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+ unsigned int pr_serial; /* unique serial number of the pool */
+ unsigned int pr_pgsize; /* Size of a "page" */
+ vaddr_t pr_pgmask; /* Mask with an item to get a page */
+ struct pool_allocator *
+ pr_alloc; /* backend allocator */
+ const char * pr_wchan; /* tsleep(9) identifier */
+#define PR_WAITOK 0x0001 /* M_WAITOK */
+#define PR_NOWAIT 0x0002 /* M_NOWAIT */
+#define PR_LIMITFAIL 0x0004 /* M_CANFAIL */
+#define PR_ZERO 0x0008 /* M_ZERO */
+#define PR_RWLOCK 0x0010
+#define PR_WANTED 0x0100
+
+ int pr_flags;
+ int pr_ipl;
+
+ RBT_HEAD(phtree, pool_page_header)
+ pr_phtree;
+
+ struct cpumem * pr_cache;
+ unsigned long pr_cache_magic[2];
+ union pool_lock pr_cache_lock;
+ struct pool_cache_lists
+ pr_cache_lists; /* list of idle item lists */
+ u_int pr_cache_nitems; /* # of idle items */
+ u_int pr_cache_items; /* target list length */
+ u_int pr_cache_contention;
+ u_int pr_cache_contention_prev;
+ int pr_cache_tick; /* time idle list was empty */
+ int pr_cache_nout;
+ uint64_t pr_cache_ngc; /* # of times the gc released a list */
+
+ u_int pr_align;
+ u_int pr_maxcolors; /* Cache coloring */
+ int pr_phoffset; /* Offset in page of page header */
+
+ /*
+ * Warning message to be issued, and a per-time-delta rate cap,
+ * if the hard limit is reached.
+ */
+ const char *pr_hardlimit_warning;
+ struct timeval pr_hardlimit_ratecap;
+ struct timeval pr_hardlimit_warning_last;
+
+ /*
+ * pool item requests queue
+ */
+ union pool_lock pr_requests_lock;
+ struct pool_requests
+ pr_requests;
+ unsigned int pr_requesting;
+
+ /*
+ * Instrumentation
+ */
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+
+ /* Physical memory configuration. */
+ const struct kmem_pa_mode *
+ pr_crange;
+};
+
+#endif /* _KERNEL || _LIBKVM */
+
+#ifdef _KERNEL
+
+extern struct pool_allocator pool_allocator_single;
+extern struct pool_allocator pool_allocator_multi;
+
+struct pool_request {
+ TAILQ_ENTRY(pool_request) pr_entry;
+ void (*pr_handler)(struct pool *, void *, void *);
+ void *pr_cookie;
+ void *pr_item;
+};
+
+void pool_init(struct pool *, size_t, u_int, int, int,
+ const char *, struct pool_allocator *);
+void pool_cache_init(struct pool *);
+void pool_destroy(struct pool *);
+void pool_setlowat(struct pool *, int);
+void pool_sethiwat(struct pool *, int);
+int pool_sethardlimit(struct pool *, u_int, const char *, int);
+struct uvm_constraint_range; /* XXX */
+void pool_set_constraints(struct pool *,
+ const struct kmem_pa_mode *mode);
+
+void *pool_get(struct pool *, int) __malloc;
+void pool_request_init(struct pool_request *,
+ void (*)(struct pool *, void *, void *), void *);
+void pool_request(struct pool *, struct pool_request *);
+void pool_put(struct pool *, void *);
+void pool_wakeup(struct pool *);
+int pool_reclaim(struct pool *);
+void pool_reclaim_all(void);
+int pool_prime(struct pool *, int);
+
+#ifdef DDB
+/*
+ * Debugging and diagnostic aides.
+ */
+void pool_printit(struct pool *, const char *,
+ int (*)(const char *, ...));
+void pool_walk(struct pool *, int, int (*)(const char *, ...),
+ void (*)(void *, int, int (*)(const char *, ...)));
+#endif
+
+/* the allocator for dma-able memory is a thin layer on top of pool */
+void dma_alloc_init(void);
+void *dma_alloc(size_t size, int flags);
+void dma_free(void *m, size_t size);
+#endif /* _KERNEL */
+
+#endif /* _SYS_POOL_H_ */
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
new file mode 100644
index 0000000..357c0c0
--- /dev/null
+++ b/sys/sys/proc.h
@@ -0,0 +1,655 @@
+/* $OpenBSD: proc.h,v 1.295 2020/04/28 08:29:40 mpi Exp $ */
+/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 1986, 1989, 1991, 1993
+ * 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.
+ *
+ * @(#)proc.h 8.8 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_PROC_H_
+#define _SYS_PROC_H_
+
+#include <machine/proc.h> /* Machine-dependent proc substruct. */
+#include <sys/selinfo.h> /* For struct selinfo */
+#include <sys/syslimits.h> /* For LOGIN_NAME_MAX */
+#include <sys/queue.h>
+#include <sys/timeout.h> /* For struct timeout */
+#include <sys/event.h> /* For struct klist */
+#include <sys/mutex.h> /* For struct mutex */
+#include <sys/resource.h> /* For struct rusage */
+#include <sys/rwlock.h> /* For struct rwlock */
+#include <sys/sigio.h> /* For struct sigio */
+
+#ifdef _KERNEL
+#include <sys/atomic.h>
+#define __need_process
+#endif
+
+/*
+ * One structure allocated per session.
+ */
+struct process;
+struct session {
+ int s_count; /* Ref cnt; pgrps in session. */
+ struct process *s_leader; /* Session leader. */
+ struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
+ struct tty *s_ttyp; /* Controlling terminal. */
+ char s_login[LOGIN_NAME_MAX]; /* Setlogin() name. */
+ pid_t s_verauthppid;
+ uid_t s_verauthuid;
+ struct timeout s_verauthto;
+};
+
+void zapverauth(/* struct session */ void *);
+
+/*
+ * One structure allocated per process group.
+ */
+struct pgrp {
+ LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */
+ LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
+ struct session *pg_session; /* Pointer to session. */
+ struct sigiolst pg_sigiolst; /* List of sigio structures. */
+ pid_t pg_id; /* Pgrp id. */
+ int pg_jobc; /* # procs qualifying pgrp for job control */
+};
+
+/*
+ * One structure allocated per emulation.
+ */
+struct exec_package;
+struct proc;
+struct ps_strings;
+struct uvm_object;
+union sigval;
+
+struct emul {
+ char e_name[8]; /* Symbolic name */
+ int *e_errno; /* Errno array */
+ int e_nosys; /* Offset of the nosys() syscall */
+ int e_nsysent; /* Number of system call entries */
+ struct sysent *e_sysent; /* System call array */
+ char **e_syscallnames; /* System call name array */
+ int e_arglen; /* Extra argument size in words */
+ /* Copy arguments on the stack */
+ void *(*e_copyargs)(struct exec_package *, struct ps_strings *,
+ void *, void *);
+ /* Set registers before execution */
+ void (*e_setregs)(struct proc *, struct exec_package *,
+ u_long, register_t *);
+ int (*e_fixup)(struct proc *, struct exec_package *);
+ int (*e_coredump)(struct proc *, void *cookie);
+ char *e_sigcode; /* Start of sigcode */
+ char *e_esigcode; /* End of sigcode */
+ char *e_esigret; /* sigaction RET position */
+ struct uvm_object *e_sigobject; /* shared sigcode object */
+};
+
+/*
+ * time usage: accumulated times in ticks
+ * Once a second, each thread's immediate counts (p_[usi]ticks) are
+ * accumulated into these.
+ */
+struct tusage {
+ struct timespec tu_runtime; /* Realtime. */
+ uint64_t tu_uticks; /* Statclock hits in user mode. */
+ uint64_t tu_sticks; /* Statclock hits in system mode. */
+ uint64_t tu_iticks; /* Statclock hits processing intr. */
+};
+
+/*
+ * Description of a process.
+ *
+ * These structures contain the information needed to manage a thread of
+ * control, known in UN*X as a process; it has references to substructures
+ * containing descriptions of things that the process uses, but may share
+ * with related processes.
+ *
+ * struct process is the higher level process containing information
+ * shared by all threads in a process, while struct proc contains the
+ * run-time information needed by threads.
+ */
+#ifdef __need_process
+struct futex;
+LIST_HEAD(futex_list, futex);
+struct tslpentry;
+TAILQ_HEAD(tslpqueue, tslpentry);
+struct unveil;
+
+/*
+ * Locks used to protect struct members in this file:
+ * a atomic operations
+ * m this process' `ps_mtx'
+ * p this process' `ps_lock'
+ * r rlimit_lock
+ */
+struct process {
+ /*
+ * ps_mainproc is the original thread in the process.
+ * It's only still special for the handling of
+ * some signal and ptrace behaviors that need to be fixed.
+ */
+ struct proc *ps_mainproc;
+ struct ucred *ps_ucred; /* Process owner's identity. */
+
+ LIST_ENTRY(process) ps_list; /* List of all processes. */
+ TAILQ_HEAD(,proc) ps_threads; /* Threads in this process. */
+
+ LIST_ENTRY(process) ps_pglist; /* List of processes in pgrp. */
+ struct process *ps_pptr; /* Pointer to parent process. */
+ LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
+ LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
+ LIST_ENTRY(process) ps_hash; /* Hash chain. */
+
+ /*
+ * An orphan is the child that has been re-parented to the
+ * debugger as a result of attaching to it. Need to keep
+ * track of them for parent to be able to collect the exit
+ * status of what used to be children.
+ */
+ LIST_ENTRY(process) ps_orphan; /* List of orphan processes. */
+ LIST_HEAD(, process) ps_orphans;/* Pointer to list of orphans. */
+
+ struct sigiolst ps_sigiolst; /* List of sigio structures. */
+ struct sigacts *ps_sigacts; /* Signal actions, state */
+ struct vnode *ps_textvp; /* Vnode of executable. */
+ struct filedesc *ps_fd; /* Ptr to open files structure */
+ struct vmspace *ps_vmspace; /* Address space */
+ pid_t ps_pid; /* Process identifier. */
+
+ struct futex_list ps_ftlist; /* futexes attached to this process */
+ struct tslpqueue ps_tslpqueue; /* [p] queue of threads in thrsleep */
+ struct rwlock ps_lock; /* per-process rwlock */
+ struct mutex ps_mtx; /* per-process mutex */
+
+/* The following fields are all zeroed upon creation in process_new. */
+#define ps_startzero ps_klist
+ struct klist ps_klist; /* knotes attached to this process */
+ u_int ps_flags; /* [a] PS_* flags. */
+ int ps_siglist; /* Signals pending for the process. */
+
+ struct proc *ps_single; /* Single threading to this thread. */
+ u_int ps_singlecount; /* [a] Not yet suspended threads. */
+
+ int ps_traceflag; /* Kernel trace points. */
+ struct vnode *ps_tracevp; /* Trace to vnode. */
+ struct ucred *ps_tracecred; /* Creds for writing trace */
+
+ u_int ps_xexit; /* Exit status for wait */
+ int ps_xsig; /* Stopping or killing signal */
+
+ pid_t ps_oppid; /* Save parent pid during ptrace. */
+ int ps_ptmask; /* Ptrace event mask */
+ struct ptrace_state *ps_ptstat;/* Ptrace state */
+
+ struct rusage *ps_ru; /* sum of stats for dead threads. */
+ struct tusage ps_tu; /* accumulated times. */
+ struct rusage ps_cru; /* sum of stats for reaped children */
+ struct itimerspec ps_timer[3]; /* timers, indexed by ITIMER_* */
+ struct timeout ps_rucheck_to; /* [] resource limit check timer */
+ time_t ps_nextxcpu; /* when to send next SIGXCPU, */
+ /* in seconds of process runtime */
+
+ u_int64_t ps_wxcounter;
+
+ struct unveil *ps_uvpaths; /* unveil vnodes and names */
+ struct unveil *ps_uvpcwd; /* pointer to unveil of cwd, NULL if none */
+ ssize_t ps_uvvcount; /* count of unveil vnodes held */
+ size_t ps_uvncount; /* count of unveil names allocated */
+ int ps_uvshrink; /* do we need to shrink vnode list */
+ int ps_uvdone; /* no more unveil is permitted */
+
+/* End area that is zeroed on creation. */
+#define ps_endzero ps_startcopy
+
+/* The following fields are all copied upon creation in process_new. */
+#define ps_startcopy ps_limit
+ struct plimit *ps_limit; /* [m,r] Process limits. */
+ struct pgrp *ps_pgrp; /* Pointer to process group. */
+ struct emul *ps_emul; /* Emulation information */
+
+ char ps_comm[MAXCOMLEN+1];
+
+ vaddr_t ps_strings; /* User pointers to argv/env */
+ vaddr_t ps_sigcode; /* User pointer to the signal code */
+ vaddr_t ps_sigcoderet; /* User pointer to sigreturn retPC */
+ u_long ps_sigcookie;
+ u_int ps_rtableid; /* Process routing table/domain. */
+ char ps_nice; /* Process "nice" value. */
+
+ struct uprof { /* profile arguments */
+ caddr_t pr_base; /* buffer base */
+ size_t pr_size; /* buffer size */
+ u_long pr_off; /* pc offset */
+ u_int pr_scale; /* pc scaling */
+ } ps_prof;
+
+ u_short ps_acflag; /* Accounting flags. */
+
+ uint64_t ps_pledge;
+ uint64_t ps_execpledge;
+
+ int64_t ps_kbind_cookie;
+ u_long ps_kbind_addr;
+
+/* End area that is copied on creation. */
+#define ps_endcopy ps_refcnt
+ int ps_refcnt; /* Number of references. */
+
+ struct timespec ps_start; /* starting uptime. */
+ struct timeout ps_realit_to; /* real-time itimer trampoline. */
+};
+
+#define ps_session ps_pgrp->pg_session
+#define ps_pgid ps_pgrp->pg_id
+
+#endif /* __need_process */
+
+/*
+ * These flags are kept in ps_flags.
+ */
+#define PS_CONTROLT 0x00000001 /* Has a controlling terminal. */
+#define PS_EXEC 0x00000002 /* Process called exec. */
+#define PS_INEXEC 0x00000004 /* Process is doing an exec right now */
+#define PS_EXITING 0x00000008 /* Process is exiting. */
+#define PS_SUGID 0x00000010 /* Had set id privs since last exec. */
+#define PS_SUGIDEXEC 0x00000020 /* last execve() was set[ug]id */
+#define PS_PPWAIT 0x00000040 /* Parent waits for exec/exit. */
+#define PS_ISPWAIT 0x00000080 /* Is parent of PPWAIT child. */
+#define PS_PROFIL 0x00000100 /* Has started profiling. */
+#define PS_TRACED 0x00000200 /* Being ptraced. */
+#define PS_WAITED 0x00000400 /* Stopped proc was waited for. */
+#define PS_COREDUMP 0x00000800 /* Busy coredumping */
+#define PS_SINGLEEXIT 0x00001000 /* Other threads must die. */
+#define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */
+#define PS_NOZOMBIE 0x00004000 /* No signal or zombie at exit. */
+#define PS_STOPPED 0x00008000 /* Just stopped, need sig to parent. */
+#define PS_SYSTEM 0x00010000 /* No sigs, stats or swapping. */
+#define PS_EMBRYO 0x00020000 /* New process, not yet fledged */
+#define PS_ZOMBIE 0x00040000 /* Dead and ready to be waited for */
+#define PS_NOBROADCASTKILL 0x00080000 /* Process excluded from kill -1. */
+#define PS_PLEDGE 0x00100000 /* Has called pledge(2) */
+#define PS_WXNEEDED 0x00200000 /* Process may violate W^X */
+#define PS_EXECPLEDGE 0x00400000 /* Has exec pledges */
+#define PS_ORPHAN 0x00800000 /* Process is on an orphan list */
+
+#define PS_BITS \
+ ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \
+ "\06SUGIDEXEC" "\07PPWAIT" "\010ISPWAIT" "\011PROFIL" "\012TRACED" \
+ "\013WAITED" "\014COREDUMP" "\015SINGLEEXIT" "\016SINGLEUNWIND" \
+ "\017NOZOMBIE" "\020STOPPED" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \
+ "\024NOBROADCASTKILL" "\025PLEDGE" "\026WXNEEDED" "\027EXECPLEDGE" \
+ "\028ORPHAN")
+
+
+struct kcov_dev;
+struct lock_list_entry;
+
+struct p_inentry {
+ u_long ie_serial;
+ vaddr_t ie_start;
+ vaddr_t ie_end;
+};
+
+/*
+ * Locks used to protect struct members in this file:
+ * I immutable after creation
+ * s scheduler lock
+ * l read only reference, see lim_read_enter()
+ * o owned (read/modified only) by this thread
+ */
+struct proc {
+ TAILQ_ENTRY(proc) p_runq; /* [s] current run/sleep queue */
+ LIST_ENTRY(proc) p_list; /* List of all threads. */
+
+ struct process *p_p; /* [I] The process of this thread. */
+ TAILQ_ENTRY(proc) p_thr_link; /* Threads in a process linkage. */
+
+ TAILQ_ENTRY(proc) p_fut_link; /* Threads in a futex linkage. */
+ struct futex *p_futex; /* Current sleeping futex. */
+
+ /* substructures: */
+ struct filedesc *p_fd; /* copy of p_p->ps_fd */
+ struct vmspace *p_vmspace; /* [I] copy of p_p->ps_vmspace */
+ struct p_inentry p_spinentry; /* [o] cache for SP check */
+ struct p_inentry p_pcinentry; /* [o] cache for PC check */
+
+ int p_flag; /* P_* flags. */
+ u_char p_spare; /* unused */
+ char p_stat; /* [s] S* process status. */
+ u_char p_runpri; /* [s] Runqueue priority */
+ u_char p_descfd; /* if not 255, fdesc permits this fd */
+
+ pid_t p_tid; /* Thread identifier. */
+ LIST_ENTRY(proc) p_hash; /* Hash chain. */
+
+/* The following fields are all zeroed upon creation in fork. */
+#define p_startzero p_dupfd
+ int p_dupfd; /* Sideways return value from filedescopen. XXX */
+
+ /* scheduling */
+ int p_cpticks; /* Ticks of cpu time. */
+ const volatile void *p_wchan; /* [s] Sleep address. */
+ struct timeout p_sleep_to;/* timeout for tsleep() */
+ const char *p_wmesg; /* [s] Reason for sleep. */
+ fixpt_t p_pctcpu; /* [s] %cpu for this thread */
+ u_int p_slptime; /* [s] Time since last blocked. */
+ u_int p_uticks; /* Statclock hits in user mode. */
+ u_int p_sticks; /* Statclock hits in system mode. */
+ u_int p_iticks; /* Statclock hits processing intr. */
+ struct cpu_info * volatile p_cpu; /* [s] CPU we're running on. */
+
+ struct rusage p_ru; /* Statistics */
+ struct tusage p_tu; /* accumulated times. */
+ struct timespec p_rtime; /* Real time. */
+
+ struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */
+ struct kcov_dev *p_kd; /* kcov device handle */
+ struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */
+
+ int p_siglist; /* Signals arrived but not delivered. */
+
+/* End area that is zeroed on creation. */
+#define p_endzero p_startcopy
+
+/* The following fields are all copied upon creation in fork. */
+#define p_startcopy p_sigmask
+ sigset_t p_sigmask; /* Current signal mask. */
+
+ u_char p_slppri; /* [s] Sleeping priority */
+ u_char p_usrpri; /* [s] Priority based on p_estcpu & ps_nice */
+ u_int p_estcpu; /* [s] Time averaged val of p_cpticks */
+ int p_pledge_syscall; /* Cache of current syscall */
+
+ struct ucred *p_ucred; /* [o] cached credentials */
+ struct sigaltstack p_sigstk; /* sp & on stack state variable */
+
+ u_long p_prof_addr; /* tmp storage for profiling addr until AST */
+ u_long p_prof_ticks; /* tmp storage for profiling ticks until AST */
+
+/* End area that is copied on creation. */
+#define p_endcopy p_addr
+ struct user *p_addr; /* Kernel virtual addr of u-area */
+ struct mdproc p_md; /* Any machine-dependent fields. */
+
+ sigset_t p_oldmask; /* Saved mask from before sigpause */
+ int p_sisig; /* For core dump/debugger XXX */
+ union sigval p_sigval; /* For core dump/debugger XXX */
+ long p_sitrapno; /* For core dump/debugger XXX */
+ int p_sicode; /* For core dump/debugger XXX */
+};
+
+/* Status values. */
+#define SIDL 1 /* Thread being created by fork. */
+#define SRUN 2 /* Currently runnable. */
+#define SSLEEP 3 /* Sleeping on an address. */
+#define SSTOP 4 /* Debugging or suspension. */
+#define SZOMB 5 /* unused */
+#define SDEAD 6 /* Thread is almost gone */
+#define SONPROC 7 /* Thread is currently on a CPU. */
+
+#define P_ZOMBIE(p) ((p)->p_stat == SDEAD)
+#define P_HASSIBLING(p) (TAILQ_FIRST(&(p)->p_p->ps_threads) != (p) || \
+ TAILQ_NEXT((p), p_thr_link) != NULL)
+
+/*
+ * These flags are per-thread and kept in p_flag
+ */
+#define P_INKTR 0x00000001 /* In a ktrace op, don't recurse */
+#define P_PROFPEND 0x00000002 /* SIGPROF needs to be posted */
+#define P_ALRMPEND 0x00000004 /* SIGVTALRM needs to be posted */
+#define P_SIGSUSPEND 0x00000008 /* Need to restore before-suspend mask*/
+#define P_CANTSLEEP 0x00000010 /* insomniac thread */
+#define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger. */
+#define P_SINTR 0x00000080 /* Sleep is interruptible. */
+#define P_SYSTEM 0x00000200 /* No sigs, stats or swapping. */
+#define P_TIMEOUT 0x00000400 /* Timing out during sleep. */
+#define P_WEXIT 0x00002000 /* Working on exiting. */
+#define P_OWEUPC 0x00008000 /* Owe proc an addupc() at next ast. */
+#define P_SUSPSINGLE 0x00080000 /* Need to stop for single threading. */
+#define P_CONTINUED 0x00800000 /* Proc has continued from a stopped state. */
+#define P_THREAD 0x04000000 /* Only a thread, not a real process */
+#define P_SUSPSIG 0x08000000 /* Stopped from signal. */
+#define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */
+#define P_CPUPEG 0x40000000 /* Do not move to another cpu. */
+
+#define P_BITS \
+ ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \
+ "\05CANTSLEEP" "\07SELECT" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \
+ "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027XX" \
+ "\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG")
+
+#define THREAD_PID_OFFSET 100000
+
+#ifdef _KERNEL
+
+struct uidinfo {
+ LIST_ENTRY(uidinfo) ui_hash;
+ uid_t ui_uid;
+ long ui_proccnt; /* proc structs */
+ long ui_lockcnt; /* lockf structs */
+};
+
+struct uidinfo *uid_find(uid_t);
+void uid_release(struct uidinfo *);
+
+/*
+ * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
+ * as it is used to represent "no process group".
+ * We set PID_MAX to 99999 to keep it in 5 columns in ps
+ * When exposed to userspace, thread IDs have THREAD_PID_OFFSET
+ * added to keep them from overlapping the PID range. For them,
+ * we use a * a (0 .. 2^n] range for cheapness, picking 'n' such
+ * that 2^n + THREAD_PID_OFFSET and THREAD_PID_OFFSET have
+ * the same number of columns when printed.
+ */
+#define PID_MAX 99999
+#define TID_MASK 0x7ffff
+
+#define NO_PID (PID_MAX+1)
+
+#define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
+#define SESSHOLD(s) ((s)->s_count++)
+#define SESSRELE(s) do { \
+ if (--(s)->s_count == 0) { \
+ timeout_del(&(s)->s_verauthto); \
+ pool_put(&session_pool, (s)); \
+ } \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * Flags to fork1().
+ */
+#define FORK_FORK 0x00000001
+#define FORK_VFORK 0x00000002
+#define FORK_IDLE 0x00000004
+#define FORK_PPWAIT 0x00000008
+#define FORK_SHAREFILES 0x00000010
+#define FORK_SYSTEM 0x00000020
+#define FORK_NOZOMBIE 0x00000040
+#define FORK_SHAREVM 0x00000080
+#define FORK_PTRACE 0x00000400
+
+#define EXIT_NORMAL 0x00000001
+#define EXIT_THREAD 0x00000002
+#define EXIT_THREAD_NOCHECK 0x00000003
+
+#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash])
+extern LIST_HEAD(tidhashhead, proc) *tidhashtbl;
+extern u_long tidhash;
+
+#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
+extern LIST_HEAD(pidhashhead, process) *pidhashtbl;
+extern u_long pidhash;
+
+#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
+extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
+extern u_long pgrphash;
+
+extern struct proc proc0; /* Process slot for swapper. */
+extern struct process process0; /* Process slot for kernel threads. */
+extern int nprocesses, maxprocess; /* Cur and max number of processes. */
+extern int nthreads, maxthread; /* Cur and max number of threads. */
+extern int randompid; /* fork() should create random pid's */
+
+LIST_HEAD(proclist, proc);
+LIST_HEAD(processlist, process);
+extern struct processlist allprocess; /* List of all processes. */
+extern struct processlist zombprocess; /* List of zombie processes. */
+extern struct proclist allproc; /* List of all threads. */
+
+extern struct process *initprocess; /* Process slot for init. */
+extern struct proc *reaperproc; /* Thread slot for reaper. */
+extern struct proc *syncerproc; /* filesystem syncer daemon */
+
+extern struct pool process_pool; /* memory pool for processes */
+extern struct pool proc_pool; /* memory pool for procs */
+extern struct pool rusage_pool; /* memory pool for zombies */
+extern struct pool ucred_pool; /* memory pool for ucreds */
+extern struct pool session_pool; /* memory pool for sessions */
+extern struct pool pgrp_pool; /* memory pool for pgrps */
+
+void freepid(pid_t);
+
+struct process *prfind(pid_t); /* Find process by id. */
+struct process *zombiefind(pid_t); /* Find zombie process by id. */
+struct proc *tfind(pid_t); /* Find thread by id. */
+struct pgrp *pgfind(pid_t); /* Find process group by id. */
+void proc_printit(struct proc *p, const char *modif,
+ int (*pr)(const char *, ...));
+
+int chgproccnt(uid_t uid, int diff);
+void enternewpgrp(struct process *, struct pgrp *, struct session *);
+void enterthispgrp(struct process *, struct pgrp *);
+int inferior(struct process *, struct process *);
+void leavepgrp(struct process *);
+void killjobc(struct process *);
+void preempt(void);
+void procinit(void);
+void setpriority(struct proc *, uint32_t, uint8_t);
+void setrunnable(struct proc *);
+void endtsleep(void *);
+int wakeup_proc(struct proc *, const volatile void *);
+void unsleep(struct proc *);
+void reaper(void *);
+void exit1(struct proc *, int, int, int);
+void exit2(struct proc *);
+int dowait4(struct proc *, pid_t, int *, int, struct rusage *,
+ register_t *);
+void cpu_fork(struct proc *_curp, struct proc *_child, void *_stack,
+ void *_tcb, void (*_func)(void *), void *_arg);
+void cpu_exit(struct proc *);
+void process_initialize(struct process *, struct proc *);
+int fork1(struct proc *_curp, int _flags, void (*_func)(void *),
+ void *_arg, register_t *_retval, struct proc **_newprocp);
+int thread_fork(struct proc *_curp, void *_stack, void *_tcb,
+ pid_t *_tidptr, register_t *_retval);
+int groupmember(gid_t, struct ucred *);
+void dorefreshcreds(struct process *, struct proc *);
+void dosigsuspend(struct proc *, sigset_t);
+
+static inline void
+refreshcreds(struct proc *p)
+{
+ struct process *pr = p->p_p;
+
+ /* this is an unlocked access to ps_ucred, but the result is benign */
+ if (pr->ps_ucred != p->p_ucred)
+ dorefreshcreds(pr, p);
+}
+
+enum single_thread_mode {
+ SINGLE_SUSPEND, /* other threads to stop wherever they are */
+ SINGLE_PTRACE, /* other threads to stop but don't wait */
+ SINGLE_UNWIND, /* other threads to unwind and stop */
+ SINGLE_EXIT /* other threads to unwind and then exit */
+};
+int single_thread_set(struct proc *, enum single_thread_mode, int);
+int single_thread_wait(struct process *, int);
+void single_thread_clear(struct proc *, int);
+int single_thread_check(struct proc *, int);
+
+void child_return(void *);
+
+int proc_cansugid(struct proc *);
+
+struct sleep_state {
+ int sls_s;
+ int sls_catch;
+ int sls_do_sleep;
+ int sls_locked;
+ int sls_sig;
+ int sls_unwind;
+ int sls_timeout;
+};
+
+struct cond {
+ int c_wait;
+};
+
+#define COND_INITIALIZER() { 1 }
+
+#if defined(MULTIPROCESSOR)
+void proc_trampoline_mp(void); /* XXX */
+#endif
+
+/*
+ * functions to handle sets of cpus.
+ *
+ * For now we keep the cpus in ints so that we can use the generic
+ * atomic ops.
+ */
+#define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
+#define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
+struct cpuset {
+ int cs_set[CPUSET_SSIZE];
+};
+
+void cpuset_init_cpu(struct cpu_info *);
+
+void cpuset_clear(struct cpuset *);
+void cpuset_add(struct cpuset *, struct cpu_info *);
+void cpuset_del(struct cpuset *, struct cpu_info *);
+int cpuset_isset(struct cpuset *, struct cpu_info *);
+void cpuset_add_all(struct cpuset *);
+void cpuset_copy(struct cpuset *, struct cpuset *);
+void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
+void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
+void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
+int cpuset_cardinality(struct cpuset *);
+struct cpu_info *cpuset_first(struct cpuset *);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_PROC_H_ */
+
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
new file mode 100644
index 0000000..995a038
--- /dev/null
+++ b/sys/sys/protosw.h
@@ -0,0 +1,237 @@
+/* $OpenBSD: protosw.h,v 1.31 2018/01/23 20:49:58 bluhm Exp $ */
+/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd 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.
+ *
+ * @(#)protosw.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Protocol switch table.
+ *
+ * Each protocol has a handle initializing one of these structures,
+ * which is used for protocol-protocol and system-protocol communication.
+ *
+ * A protocol is called through the pr_init entry before any other.
+ * Thereafter it is called every 200ms through the pr_fasttimo entry and
+ * every 500ms through the pr_slowtimo for timer based actions.
+ *
+ * Protocols pass data between themselves as chains of mbufs using
+ * the pr_input and pr_output hooks. Pr_input passes data up (towards
+ * UNIX) and pr_output passes it down (towards the imps); control
+ * information passes up and down on pr_ctlinput and pr_ctloutput.
+ * The protocol is responsible for the space occupied by any the
+ * arguments to these entries and must dispose it.
+ *
+ * The userreq routine interfaces protocols to the system and is
+ * described below.
+ */
+
+struct mbuf;
+struct sockaddr;
+struct socket;
+struct domain;
+struct proc;
+
+struct protosw {
+ short pr_type; /* socket type used for */
+ struct domain *pr_domain; /* domain protocol a member of */
+ short pr_protocol; /* protocol number */
+ short pr_flags; /* see below */
+
+/* protocol-protocol hooks */
+ /* input to protocol (from below) */
+ int (*pr_input)(struct mbuf **, int *, int, int);
+ /* output to protocol (from above) */
+ int (*pr_output)(struct mbuf *, struct socket *, struct sockaddr *,
+ struct mbuf *);
+ /* control input (from below) */
+ void (*pr_ctlinput)(int, struct sockaddr *, u_int, void *);
+ /* control output (from above) */
+ int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *);
+
+/* user-protocol hook */
+ /* user request: see list below */
+ int (*pr_usrreq)(struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *);
+
+ int (*pr_attach)(struct socket *, int);
+ int (*pr_detach)(struct socket *);
+
+/* utility hooks */
+ void (*pr_init)(void); /* initialization hook */
+ void (*pr_fasttimo)(void); /* fast timeout (200ms) */
+ void (*pr_slowtimo)(void); /* slow timeout (500ms) */
+ /* sysctl for protocol */
+ int (*pr_sysctl)(int *, u_int, void *, size_t *, void *, size_t);
+};
+
+#define PR_SLOWHZ 2 /* 2 slow timeouts per second */
+#define PR_FASTHZ 5 /* 5 fast timeouts per second */
+
+/*
+ * Values for pr_flags.
+ * PR_ADDR requires PR_ATOMIC;
+ * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
+ */
+#define PR_ATOMIC 0x01 /* exchange atomic messages only */
+#define PR_ADDR 0x02 /* addresses given with messages */
+#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
+#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
+#define PR_RIGHTS 0x10 /* passes capabilities */
+#define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
+ socket */
+#define PR_SPLICE 0x40 /* socket splicing is possible */
+
+/*
+ * The arguments to usrreq are:
+ * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
+ * where up is a (struct socket *), req is one of these requests,
+ * m is a optional mbuf chain containing a message,
+ * nam is an optional mbuf chain containing an address,
+ * and opt is a pointer to a socketopt structure or nil.
+ * The protocol is responsible for disposal of the mbuf chain m,
+ * the caller is responsible for any space held by nam and opt.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRU_ATTACH 0 /* attach protocol to up */
+#define PRU_DETACH 1 /* detach protocol from up */
+#define PRU_BIND 2 /* bind socket to address */
+#define PRU_LISTEN 3 /* listen for connection */
+#define PRU_CONNECT 4 /* establish connection to peer */
+#define PRU_ACCEPT 5 /* accept connection from peer */
+#define PRU_DISCONNECT 6 /* disconnect from peer */
+#define PRU_SHUTDOWN 7 /* won't send any more data */
+#define PRU_RCVD 8 /* have taken data; more room now */
+#define PRU_SEND 9 /* send this data */
+#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */
+#define PRU_CONTROL 11 /* control operations on protocol */
+#define PRU_SENSE 12 /* return status into m */
+#define PRU_RCVOOB 13 /* retrieve out of band data */
+#define PRU_SENDOOB 14 /* send out of band data */
+#define PRU_SOCKADDR 15 /* fetch socket's address */
+#define PRU_PEERADDR 16 /* fetch peer's address */
+#define PRU_CONNECT2 17 /* connect two sockets */
+/* begin for protocols internal use */
+#define PRU_FASTTIMO 18 /* 200ms timeout */
+#define PRU_SLOWTIMO 19 /* 500ms timeout */
+#define PRU_PROTORCV 20 /* receive from below */
+#define PRU_PROTOSEND 21 /* send to below */
+
+#define PRU_NREQ 22
+
+#ifdef PRUREQUESTS
+const char *prurequests[] = {
+ "ATTACH", "DETACH", "BIND", "LISTEN",
+ "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
+ "RCVD", "SEND", "ABORT", "CONTROL",
+ "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
+ "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
+ "PROTORCV", "PROTOSEND",
+};
+#endif
+
+/*
+ * The arguments to the ctlinput routine are
+ * (*protosw[].pr_ctlinput)(cmd, sa, arg);
+ * where cmd is one of the commands below, sa is a pointer to a sockaddr,
+ * and arg is an optional caddr_t argument used within a protocol family.
+ */
+#define PRC_IFDOWN 0 /* interface transition */
+#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
+#define PRC_MTUINC 2 /* increase in mtu to host */
+#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
+#define PRC_QUENCH 4 /* some one said to slow down */
+#define PRC_MSGSIZE 5 /* message size forced drop */
+#define PRC_HOSTDEAD 6 /* host appears to be down */
+#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
+#define PRC_UNREACH_NET 8 /* no route to network */
+#define PRC_UNREACH_HOST 9 /* no route to host */
+#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
+#define PRC_UNREACH_PORT 11 /* bad port # */
+/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
+#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
+#define PRC_REDIRECT_NET 14 /* net routing redirect */
+#define PRC_REDIRECT_HOST 15 /* host routing redirect */
+#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
+#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
+#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
+#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
+#define PRC_PARAMPROB 20 /* header incorrect */
+
+#define PRC_NCMDS 21
+
+#define PRC_IS_REDIRECT(cmd) \
+ ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
+
+#ifdef PRCREQUESTS
+char *prcrequests[] = {
+ "IFDOWN", "ROUTEDEAD", "MTUINC", "DEC-BIT-QUENCH2",
+ "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
+ "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
+ "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
+ "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
+ "PARAMPROB"
+};
+#endif
+
+/*
+ * The arguments to ctloutput are:
+ * (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
+ * req is one of the actions listed below, so is a (struct socket *),
+ * level is an indication of which protocol layer the option is intended.
+ * optname is a protocol dependent socket option request,
+ * optval is a pointer to a mbuf-chain pointer, for value-return results.
+ * The protocol is responsible for disposal of the mbuf chain *optval
+ * if supplied,
+ * the caller is responsible for any space held by *optval, when returned.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRCO_GETOPT 0
+#define PRCO_SETOPT 1
+
+#define PRCO_NCMDS 2
+
+#ifdef PRCOREQUESTS
+char *prcorequests[] = {
+ "GETOPT", "SETOPT",
+};
+#endif
+
+#ifdef _KERNEL
+struct sockaddr;
+const struct protosw *pffindproto(int, int, int);
+const struct protosw *pffindtype(int, int);
+void pfctlinput(int, struct sockaddr *);
+
+extern u_char ip_protox[];
+extern const struct protosw inetsw[];
+#endif
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
new file mode 100644
index 0000000..8e127c5
--- /dev/null
+++ b/sys/sys/ptrace.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: ptrace.h,v 1.16 2020/03/16 11:58:46 mpi Exp $ */
+/* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */
+
+/*-
+ * Copyright (c) 1984, 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.
+ *
+ * @(#)ptrace.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_PTRACE_H_
+#define _SYS_PTRACE_H_
+
+#define PT_TRACE_ME 0 /* child declares it's being traced */
+#define PT_READ_I 1 /* read word in child's I space */
+#define PT_READ_D 2 /* read word in child's D space */
+#define PT_WRITE_I 4 /* write word in child's I space */
+#define PT_WRITE_D 5 /* write word in child's D space */
+#define PT_CONTINUE 7 /* continue the child */
+#define PT_KILL 8 /* kill the child process */
+#define PT_ATTACH 9 /* attach to running process */
+#define PT_DETACH 10 /* detach from running process */
+#define PT_IO 11 /* do I/O to/from the stopped process. */
+
+struct ptrace_io_desc {
+ int piod_op; /* I/O operation */
+ void *piod_offs; /* child offset */
+ void *piod_addr; /* parent offset */
+ size_t piod_len; /* request length */
+};
+
+/*
+ * Operations in piod_op.
+ */
+#define PIOD_READ_D 1 /* Read from D space */
+#define PIOD_WRITE_D 2 /* Write to D space */
+#define PIOD_READ_I 3 /* Read from I space */
+#define PIOD_WRITE_I 4 /* Write to I space */
+#define PIOD_READ_AUXV 5 /* Read from aux array */
+
+#define PT_SET_EVENT_MASK 12
+#define PT_GET_EVENT_MASK 13
+
+typedef struct ptrace_event {
+ int pe_set_event;
+} ptrace_event_t;
+
+#define PTRACE_FORK 0x0002 /* Report forks */
+
+#define PT_GET_PROCESS_STATE 14
+
+typedef struct ptrace_state {
+ int pe_report_event;
+ pid_t pe_other_pid;
+ pid_t pe_tid;
+} ptrace_state_t;
+
+#define PT_GET_THREAD_FIRST 15
+#define PT_GET_THREAD_NEXT 16
+
+struct ptrace_thread_state {
+ pid_t pts_tid;
+};
+
+#define PT_FIRSTMACH 32 /* for machine-specific requests */
+#include <machine/ptrace.h> /* machine-specific requests, if any */
+
+#ifdef _KERNEL
+
+/*
+ * There is a bunch of PT_ requests that are machine dependent, but not
+ * optional. Check if they were defined by MD code here.
+ */
+#if !defined(PT_GETREGS) || !defined(PT_SETREGS)
+#error Machine dependent ptrace not complete.
+#endif
+
+struct reg;
+#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
+struct fpreg;
+#endif
+
+void process_reparent(struct process *_child, struct process *_newparent);
+void process_untrace(struct process *_tr);
+#ifdef PT_GETFPREGS
+int process_read_fpregs(struct proc *_t, struct fpreg *);
+#endif
+int process_read_regs(struct proc *_t, struct reg *);
+int process_set_pc(struct proc *_t, caddr_t _addr);
+int process_sstep(struct proc *_t, int _sstep);
+#ifdef PT_SETFPREGS
+int process_write_fpregs(struct proc *_t, struct fpreg *);
+#endif
+int process_write_regs(struct proc *_t, struct reg *);
+int process_checkioperm(struct proc *_curp, struct process *_tr);
+int process_domem(struct proc *_curp, struct process *_tr, struct uio *,
+ int _req);
+
+#ifndef FIX_SSTEP
+#define FIX_SSTEP(p)
+#endif
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_PTRACE_H_ */
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
new file mode 100644
index 0000000..f28ba89
--- /dev/null
+++ b/sys/sys/queue.h
@@ -0,0 +1,536 @@
+/* $OpenBSD: queue.h,v 1.45 2018/07/12 14:22:54 sashan Exp $ */
+/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft 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 <sys/_null.h>
+
+/*
+ * This file defines five types of data structures: singly-linked lists,
+ * lists, simple queues, tail queues and XOR simple 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 to 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 before or 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.
+ *
+ * An XOR simple queue is used in the same way as a regular simple queue.
+ * The difference is that the head structure also includes a "cookie" that
+ * is XOR'd with the queue pointer (first, last or next) to generate the
+ * real pointer value.
+ *
+ * For details on the use of these macros, see the queue(3) manual page.
+ */
+
+#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
+#define _Q_INVALID ((void *)-1)
+#define _Q_INVALIDATE(a) (a) = _Q_INVALID
+#else
+#define _Q_INVALIDATE(a)
+#endif
+
+/*
+ * 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 access methods.
+ */
+#define SLIST_FIRST(head) ((head)->slh_first)
+#define SLIST_END(head) NULL
+#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
+
+#define SLIST_FOREACH(var, head, field) \
+ for((var) = SLIST_FIRST(head); \
+ (var) != SLIST_END(head); \
+ (var) = SLIST_NEXT(var, field))
+
+#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 functions.
+ */
+#define SLIST_INIT(head) { \
+ SLIST_FIRST(head) = SLIST_END(head); \
+}
+
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
+} while (0)
+
+#define SLIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
+} while (0)
+
+#define SLIST_REMOVE_AFTER(elm, field) do { \
+ (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
+} while (0)
+
+#define SLIST_REMOVE_HEAD(head, field) do { \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
+} while (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; \
+ } \
+ _Q_INVALIDATE((elm)->field.sle_next); \
+} while (0)
+
+/*
+ * 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 access methods.
+ */
+#define LIST_FIRST(head) ((head)->lh_first)
+#define LIST_END(head) NULL
+#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
+#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+
+#define LIST_FOREACH(var, head, field) \
+ for((var) = LIST_FIRST(head); \
+ (var)!= LIST_END(head); \
+ (var) = LIST_NEXT(var, field))
+
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = LIST_FIRST(head); \
+ (var) && ((tvar) = LIST_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * List functions.
+ */
+#define LIST_INIT(head) do { \
+ LIST_FIRST(head) = LIST_END(head); \
+} while (0)
+
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ 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 (0)
+
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ (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 (0)
+
+#define LIST_INSERT_HEAD(head, elm, field) do { \
+ 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 (0)
+
+#define LIST_REMOVE(elm, field) do { \
+ 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; \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+#define LIST_REPLACE(elm, elm2, field) do { \
+ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
+ (elm2)->field.le_next->field.le_prev = \
+ &(elm2)->field.le_next; \
+ (elm2)->field.le_prev = (elm)->field.le_prev; \
+ *(elm2)->field.le_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+/*
+ * 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 access methods.
+ */
+#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
+#define SIMPLEQ_END(head) NULL
+#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
+#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
+
+#define SIMPLEQ_FOREACH(var, head, field) \
+ for((var) = SIMPLEQ_FIRST(head); \
+ (var) != SIMPLEQ_END(head); \
+ (var) = SIMPLEQ_NEXT(var, field))
+
+#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = SIMPLEQ_FIRST(head); \
+ (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Simple queue functions.
+ */
+#define SIMPLEQ_INIT(head) do { \
+ (head)->sqh_first = NULL; \
+ (head)->sqh_last = &(head)->sqh_first; \
+} while (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 (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 (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 (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 (0)
+
+#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
+ if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
+ == NULL) \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (0)
+
+#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 (0)
+
+/*
+ * XOR Simple queue definitions.
+ */
+#define XSIMPLEQ_HEAD(name, type) \
+struct name { \
+ struct type *sqx_first; /* first element */ \
+ struct type **sqx_last; /* addr of last next element */ \
+ unsigned long sqx_cookie; \
+}
+
+#define XSIMPLEQ_ENTRY(type) \
+struct { \
+ struct type *sqx_next; /* next element */ \
+}
+
+/*
+ * XOR Simple queue access methods.
+ */
+#define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \
+ (unsigned long)(ptr)))
+#define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first))
+#define XSIMPLEQ_END(head) NULL
+#define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head))
+#define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next))
+
+
+#define XSIMPLEQ_FOREACH(var, head, field) \
+ for ((var) = XSIMPLEQ_FIRST(head); \
+ (var) != XSIMPLEQ_END(head); \
+ (var) = XSIMPLEQ_NEXT(head, var, field))
+
+#define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = XSIMPLEQ_FIRST(head); \
+ (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * XOR Simple queue functions.
+ */
+#define XSIMPLEQ_INIT(head) do { \
+ arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \
+ (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.sqx_next = (head)->sqx_first) == \
+ XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+ (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \
+ *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \
+ XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+ (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \
+} while (0)
+
+#define XSIMPLEQ_REMOVE_HEAD(head, field) do { \
+ if (((head)->sqx_first = XSIMPLEQ_XOR(head, \
+ (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \
+} while (0)
+
+#define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
+ if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \
+ (elm)->field.sqx_next)->field.sqx_next) \
+ == XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = \
+ XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+} while (0)
+
+
+/*
+ * Tail queue definitions.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * Tail queue access methods.
+ */
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+#define TAILQ_END(head) NULL
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+/* XXX */
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define TAILQ_EMPTY(head) \
+ (TAILQ_FIRST(head) == TAILQ_END(head))
+
+#define TAILQ_FOREACH(var, head, field) \
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_NEXT(var, field))
+
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_PREV(var, headname, field))
+
+#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
+ for ((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_PREV(var, headname, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_INIT(head) do { \
+ (head)->tqh_first = NULL; \
+ (head)->tqh_last = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ 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 (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ 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 (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (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 (0)
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ 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; \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_REPLACE(head, elm, elm2, field) do { \
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
+ (elm2)->field.tqe_next->field.tqe_prev = \
+ &(elm2)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm2)->field.tqe_next; \
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
+ *(elm2)->field.tqe_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#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 (0)
+
+#endif /* !_SYS_QUEUE_H_ */
diff --git a/sys/sys/radioio.h b/sys/sys/radioio.h
new file mode 100644
index 0000000..343d730
--- /dev/null
+++ b/sys/sys/radioio.h
@@ -0,0 +1,76 @@
+/* $OpenBSD: radioio.h,v 1.5 2015/01/14 21:15:36 deraadt Exp $ */
+/* $RuOBSD: radioio.h,v 1.4 2001/10/18 16:51:36 pva Exp $ */
+
+/*
+ * Copyright (c) 2001 Maxim Tsyplakov <tm@oganer.net>,
+ * Vladimir Popov <jumbo@narod.ru>
+ * 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 AUTHORS ``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 AUTHORS 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_RADIOIO_H_
+#define _SYS_RADIOIO_H_
+
+#include <sys/types.h>
+
+#define MIN_FM_FREQ 87500
+#define MAX_FM_FREQ 108000
+
+#define MIN_TV_CHAN 0
+#define MAX_TV_CHAN 150
+
+#define IF_FREQ 10700
+
+struct radio_info {
+ int mute;
+ int volume;
+ int stereo;
+ int rfreq; /* reference frequency */
+ int lock; /* locking field strength during an automatic search */
+ u_int32_t freq; /* in kHz */
+ u_int32_t caps; /* card capabilities */
+#define RADIO_CAPS_DETECT_STEREO (1<<0)
+#define RADIO_CAPS_DETECT_SIGNAL (1<<1)
+#define RADIO_CAPS_SET_MONO (1<<2)
+#define RADIO_CAPS_HW_SEARCH (1<<3)
+#define RADIO_CAPS_HW_AFC (1<<4)
+#define RADIO_CAPS_REFERENCE_FREQ (1<<5)
+#define RADIO_CAPS_LOCK_SENSITIVITY (1<<6)
+#define RADIO_CAPS_RESERVED1 (1<<7)
+#define RADIO_CAPS_RESERVED2 (0xFF<<8)
+#define RADIO_CARD_TYPE (0xFF<<16)
+ u_int32_t info;
+#define RADIO_INFO_STEREO (1<<0)
+#define RADIO_INFO_SIGNAL (1<<1)
+ u_int32_t tuner_mode;
+#define RADIO_TUNER_MODE_RADIO (1<<0)
+#define RADIO_TUNER_MODE_TV (1<<1)
+ u_int32_t chan;
+ u_int32_t chnlset;
+};
+
+/* Radio device operations */
+#define RIOCGINFO _IOR('R', 21, struct radio_info) /* get info */
+#define RIOCSINFO _IOWR('R', 22, struct radio_info) /* set info */
+#define RIOCSSRCH _IOW('R', 23, int) /* search up/down */
+
+#endif /* _SYS_RADIOIO_H_ */
diff --git a/sys/sys/reboot.h b/sys/sys/reboot.h
new file mode 100644
index 0000000..492b554
--- /dev/null
+++ b/sys/sys/reboot.h
@@ -0,0 +1,106 @@
+/* $OpenBSD: reboot.h,v 1.18 2019/04/01 07:00:52 tedu Exp $ */
+/* $NetBSD: reboot.h,v 1.9 1996/04/22 01:23:25 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * 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.
+ *
+ * @(#)reboot.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef _SYS_REBOOT_H_
+#define _SYS_REBOOT_H_
+
+/*
+ * Arguments to reboot system call. These are passed to the boot program,
+ * and then on to init.
+ */
+#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */
+
+#define RB_ASKNAME 0x0001 /* ask for file name to reboot from */
+#define RB_SINGLE 0x0002 /* reboot to single user only */
+#define RB_NOSYNC 0x0004 /* dont sync before reboot */
+#define RB_HALT 0x0008 /* don't reboot, just halt */
+#define RB_INITNAME 0x0010 /* name given for /etc/init (unused) */
+#define RB_DFLTROOT 0x0020 /* use compiled-in rootdev */
+#define RB_KDB 0x0040 /* give control to kernel debugger */
+#define RB_RDONLY 0x0080 /* mount root fs read-only */
+#define RB_DUMP 0x0100 /* dump kernel memory before reboot */
+#define RB_MINIROOT 0x0200 /* mini-root present in memory at boot time */
+#define RB_CONFIG 0x0400 /* change configured devices */
+#define RB_TIMEBAD 0x0800 /* don't call resettodr() in boot() */
+#define RB_POWERDOWN 0x1000 /* attempt to power down machine */
+#define RB_SERCONS 0x2000 /* use serial console if available */
+#define RB_USERREQ 0x4000 /* boot() called at user request (e.g. ddb) */
+#define RB_RESET 0x8000 /* just reset, no cleanup */
+
+/*
+ * Constants for converting boot-style device number to type,
+ * adaptor (uba, mba, etc), unit number and partition number.
+ * Type (== major device number) is in the low byte
+ * for backward compatibility. Except for that of the "magic
+ * number", each mask applies to the shifted value.
+ * Format:
+ * (4) (4) (4) (4) (8) (8)
+ * --------------------------------
+ * |MA | AD| CT| UN| PART | TYPE |
+ * --------------------------------
+ */
+#define B_ADAPTORSHIFT 24
+#define B_ADAPTORMASK 0x0f
+#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
+#define B_CONTROLLERSHIFT 20
+#define B_CONTROLLERMASK 0xf
+#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
+#define B_UNITSHIFT 16
+#define B_UNITMASK 0xf
+#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK)
+#define B_PARTITIONSHIFT 8
+#define B_PARTITIONMASK 0xff
+#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
+#define B_TYPESHIFT 0
+#define B_TYPEMASK 0xff
+#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK)
+
+#define B_MAGICMASK 0xf0000000
+#define B_DEVMAGIC 0xa0000000
+
+#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \
+ (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \
+ ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \
+ ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC)
+
+#if defined(_KERNEL) && !defined(_STANDALONE) && !defined(_LOCORE)
+
+__BEGIN_DECLS
+__dead void reboot(int);
+__dead void boot(int);
+__END_DECLS
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_REBOOT_H_ */
diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h
new file mode 100644
index 0000000..85e84cf
--- /dev/null
+++ b/sys/sys/refcnt.h
@@ -0,0 +1,38 @@
+/* $OpenBSD: refcnt.h,v 1.4 2016/06/07 07:53:33 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SYS_REFCNT_H_
+#define _SYS_REFCNT_H_
+
+struct refcnt {
+ unsigned int refs;
+};
+
+#define REFCNT_INITIALIZER() { .refs = 1 }
+
+#ifdef _KERNEL
+
+void refcnt_init(struct refcnt *);
+void refcnt_take(struct refcnt *);
+int refcnt_rele(struct refcnt *);
+void refcnt_rele_wake(struct refcnt *);
+void refcnt_finalize(struct refcnt *, const char *);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_REFCNT_H_ */
diff --git a/sys/sys/resource.h b/sys/sys/resource.h
new file mode 100644
index 0000000..9ca4bb6
--- /dev/null
+++ b/sys/sys/resource.h
@@ -0,0 +1,128 @@
+/* $OpenBSD: resource.h,v 1.14 2013/10/25 04:42:48 guenther Exp $ */
+/* $NetBSD: resource.h,v 1.14 1996/02/09 18:25:27 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.
+ *
+ * @(#)resource.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_RESOURCE_H_
+#define _SYS_RESOURCE_H_
+
+#include <sys/time.h>
+
+/*
+ * 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 utilization information.
+ */
+
+#define RUSAGE_SELF 0
+#define RUSAGE_CHILDREN (-1)
+#define RUSAGE_THREAD 1
+
+struct rusage {
+ struct timeval ru_utime; /* user time used */
+ struct timeval ru_stime; /* system time used */
+ long ru_maxrss; /* max resident set size */
+#define ru_first ru_ixrss
+ long ru_ixrss; /* integral shared text memory size */
+ long ru_idrss; /* integral unshared data " */
+ long ru_isrss; /* integral unshared stack " */
+ long ru_minflt; /* page reclaims */
+ long ru_majflt; /* page faults */
+ long ru_nswap; /* swaps */
+ long ru_inblock; /* block input operations */
+ long ru_oublock; /* block output operations */
+ long ru_msgsnd; /* messages sent */
+ long ru_msgrcv; /* messages received */
+ long ru_nsignals; /* signals received */
+ long ru_nvcsw; /* voluntary context switches */
+ long ru_nivcsw; /* involuntary " */
+#define ru_last ru_nivcsw
+};
+
+/*
+ * Resource limits
+ */
+#define RLIMIT_CPU 0 /* cpu time in milliseconds */
+#define RLIMIT_FSIZE 1 /* maximum file size */
+#define RLIMIT_DATA 2 /* data size */
+#define RLIMIT_STACK 3 /* stack size */
+#define RLIMIT_CORE 4 /* core file size */
+#define RLIMIT_RSS 5 /* resident set size */
+#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
+#define RLIMIT_NPROC 7 /* number of processes */
+#define RLIMIT_NOFILE 8 /* number of open files */
+
+#define RLIM_NLIMITS 9 /* number of resource limits */
+
+#define RLIM_INFINITY (((rlim_t)1 << 63) - 1)
+#define RLIM_SAVED_MAX RLIM_INFINITY
+#define RLIM_SAVED_CUR RLIM_INFINITY
+
+struct rlimit {
+ rlim_t rlim_cur; /* current (soft) limit */
+ rlim_t rlim_max; /* maximum value for rlim_cur */
+};
+
+#if __BSD_VISIBLE
+/* Load average structure. */
+struct loadavg {
+ fixpt_t ldavg[3];
+ long fscale;
+};
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+extern struct loadavg averunnable;
+struct process;
+int dosetrlimit(struct proc *, u_int, struct rlimit *);
+int donice(struct proc *, struct process *, int);
+int dogetrusage(struct proc *, int, struct rusage *);
+
+#else
+__BEGIN_DECLS
+int getpriority(int, id_t);
+int getrlimit(int, struct rlimit *);
+int getrusage(int, struct rusage *);
+int setpriority(int, id_t, int);
+int setrlimit(int, const struct rlimit *);
+__END_DECLS
+
+#endif /* _KERNEL */
+#endif /* !_SYS_RESOURCE_H_ */
diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h
new file mode 100644
index 0000000..4200758
--- /dev/null
+++ b/sys/sys/resourcevar.h
@@ -0,0 +1,107 @@
+/* $OpenBSD: resourcevar.h,v 1.24 2019/06/21 09:39:48 visa Exp $ */
+/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd 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.
+ *
+ * @(#)resourcevar.h 8.3 (Berkeley) 2/22/94
+ */
+
+#ifndef _SYS_RESOURCEVAR_H_
+#define _SYS_RESOURCEVAR_H_
+
+#include <sys/timeout.h>
+
+/*
+ * Kernel shareable process resource limits. Because this structure
+ * is moderately large but changes infrequently, it is shared
+ * copy-on-write after forks.
+ */
+struct plimit {
+ struct rlimit pl_rlimit[RLIM_NLIMITS];
+ u_int pl_refcnt; /* number of references */
+};
+
+/* add user profiling from AST */
+#define ADDUPROF(p) \
+do { \
+ atomic_clearbits_int(&(p)->p_flag, P_OWEUPC); \
+ addupc_task((p), (p)->p_prof_addr, (p)->p_prof_ticks); \
+ (p)->p_prof_ticks = 0; \
+} while (0)
+
+#ifdef _KERNEL
+
+#include <lib/libkern/libkern.h> /* for KASSERT() */
+
+void addupc_intr(struct proc *, u_long);
+void addupc_task(struct proc *, u_long, u_int);
+void tuagg_unlocked(struct process *, struct proc *);
+void tuagg(struct process *, struct proc *);
+struct tusage;
+void calctsru(struct tusage *, struct timespec *, struct timespec *,
+ struct timespec *);
+void calcru(struct tusage *, struct timeval *, struct timeval *,
+ struct timeval *);
+void lim_startup(struct plimit *);
+void lim_free(struct plimit *);
+void lim_fork(struct process *, struct process *);
+struct plimit *lim_read_enter(void);
+
+/*
+ * Finish read access to resource limits.
+ */
+static inline void
+lim_read_leave(struct plimit *limit)
+{
+ /* nothing */
+}
+
+/*
+ * Get the value of the resource limit in current process.
+ */
+static inline rlim_t
+lim_cur(int which)
+{
+ struct plimit *limit;
+ rlim_t val;
+
+ KASSERT(which >= 0 && which < RLIM_NLIMITS);
+
+ limit = lim_read_enter();
+ val = limit->pl_rlimit[which].rlim_cur;
+ lim_read_leave(limit);
+ return (val);
+}
+
+rlim_t lim_cur_proc(struct proc *, int);
+
+void ruadd(struct rusage *, struct rusage *);
+void rucheck(void *);
+#endif
+#endif /* !_SYS_RESOURCEVAR_H_ */
diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h
new file mode 100644
index 0000000..4b32e38
--- /dev/null
+++ b/sys/sys/rwlock.h
@@ -0,0 +1,191 @@
+/* $OpenBSD: rwlock.h,v 1.26 2019/07/16 01:40:49 jsg Exp $ */
+/*
+ * Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Multiple readers, single writer lock.
+ *
+ * Simplistic implementation modelled after rw locks in Solaris.
+ *
+ * The rwl_owner has the following layout:
+ * [ owner or count of readers | wrlock | wrwant | wait ]
+ *
+ * When the WAIT bit is set (bit 0), the lock has waiters sleeping on it.
+ * When the WRWANT bit is set (bit 1), at least one waiter wants a write lock.
+ * When the WRLOCK bit is set (bit 2) the lock is currently write-locked.
+ *
+ * When write locked, the upper bits contain the struct proc * pointer to
+ * the writer, otherwise they count the number of readers.
+ *
+ * We provide a simple machine independent implementation:
+ *
+ * void rw_enter_read(struct rwlock *)
+ * atomically test for RWLOCK_WRLOCK and if not set, increment the lock
+ * by RWLOCK_READ_INCR. While RWLOCK_WRLOCK is set, loop into rw_enter_wait.
+ *
+ * void rw_enter_write(struct rwlock *);
+ * atomically test for the lock being 0 (it's not possible to have
+ * owner/read count unset and waiter bits set) and if 0 set the owner to
+ * the proc and RWLOCK_WRLOCK. While not zero, loop into rw_enter_wait.
+ *
+ * void rw_exit_read(struct rwlock *);
+ * atomically decrement lock by RWLOCK_READ_INCR and unset RWLOCK_WAIT and
+ * RWLOCK_WRWANT remembering the old value of lock and if RWLOCK_WAIT was set,
+ * call rw_exit_waiters with the old contents of the lock.
+ *
+ * void rw_exit_write(struct rwlock *);
+ * atomically swap the contents of the lock with 0 and if RWLOCK_WAIT was
+ * set, call rw_exit_waiters with the old contents of the lock.
+ */
+
+#ifndef _SYS_RWLOCK_H
+#define _SYS_RWLOCK_H
+
+#include <sys/_lock.h>
+
+struct proc;
+
+struct rwlock {
+ volatile unsigned long rwl_owner;
+ const char *rwl_name;
+#ifdef WITNESS
+ struct lock_object rwl_lock_obj;
+#endif
+};
+
+#define RWLOCK_LO_FLAGS(flags) \
+ ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \
+ (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \
+ (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \
+ LO_INITIALIZED | LO_SLEEPABLE | LO_UPGRADABLE | \
+ (LO_CLASS_RWLOCK << LO_CLASSSHIFT))
+
+#define RRWLOCK_LO_FLAGS(flags) \
+ ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \
+ (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \
+ (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \
+ LO_INITIALIZED | LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE | \
+ (LO_CLASS_RRWLOCK << LO_CLASSSHIFT))
+
+#define RWLOCK_LO_INITIALIZER(name, flags) \
+ { .lo_type = &(const struct lock_type){ .lt_name = name }, \
+ .lo_name = (name), \
+ .lo_flags = RWLOCK_LO_FLAGS(flags) }
+
+#define RWL_DUPOK 0x01
+#define RWL_NOWITNESS 0x02
+#define RWL_IS_VNODE 0x04
+
+#ifdef WITNESS
+#define RWLOCK_INITIALIZER(name) \
+ { 0, name, .rwl_lock_obj = RWLOCK_LO_INITIALIZER(name, 0) }
+#else
+#define RWLOCK_INITIALIZER(name) \
+ { 0, name }
+#endif
+
+#define RWLOCK_WAIT 0x01UL
+#define RWLOCK_WRWANT 0x02UL
+#define RWLOCK_WRLOCK 0x04UL
+#define RWLOCK_MASK 0x07UL
+
+#define RWLOCK_OWNER(rwl) ((struct proc *)((rwl)->rwl_owner & ~RWLOCK_MASK))
+
+#define RWLOCK_READER_SHIFT 3UL
+#define RWLOCK_READ_INCR (1UL << RWLOCK_READER_SHIFT)
+
+#define RW_WRITE 0x0001UL /* exclusive lock */
+#define RW_READ 0x0002UL /* shared lock */
+#define RW_DOWNGRADE 0x0004UL /* downgrade exclusive to shared */
+#define RW_OPMASK 0x0007UL
+
+#define RW_INTR 0x0010UL /* interruptible sleep */
+#define RW_SLEEPFAIL 0x0020UL /* fail if we slept for the lock */
+#define RW_NOSLEEP 0x0040UL /* don't wait for the lock */
+#define RW_RECURSEFAIL 0x0080UL /* Fail on recursion for RRW locks. */
+#define RW_DUPOK 0x0100UL /* Permit duplicate lock */
+
+/*
+ * for rw_status() and rrw_status() only: exclusive lock held by
+ * some other thread
+ */
+#define RW_WRITE_OTHER 0x0100UL
+
+/* recursive rwlocks; */
+struct rrwlock {
+ struct rwlock rrwl_lock;
+ uint32_t rrwl_wcnt; /* # writers. */
+};
+
+#ifdef _KERNEL
+
+void _rw_init_flags(struct rwlock *, const char *, int,
+ const struct lock_type *);
+
+#ifdef WITNESS
+#define rw_init_flags(rwl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #rwl };\
+ _rw_init_flags(rwl, name, flags, &__lock_type); \
+} while (0)
+#define rw_init(rwl, name) rw_init_flags(rwl, name, 0)
+#else /* WITNESS */
+#define rw_init_flags(rwl, name, flags) \
+ _rw_init_flags(rwl, name, flags, NULL)
+#define rw_init(rwl, name) _rw_init_flags(rwl, name, 0, NULL)
+#endif /* WITNESS */
+
+void rw_enter_read(struct rwlock *);
+void rw_enter_write(struct rwlock *);
+void rw_exit_read(struct rwlock *);
+void rw_exit_write(struct rwlock *);
+
+#ifdef DIAGNOSTIC
+void rw_assert_wrlock(struct rwlock *);
+void rw_assert_rdlock(struct rwlock *);
+void rw_assert_anylock(struct rwlock *);
+void rw_assert_unlocked(struct rwlock *);
+#else
+#define rw_assert_wrlock(rwl) ((void)0)
+#define rw_assert_rdlock(rwl) ((void)0)
+#define rw_assert_anylock(rwl) ((void)0)
+#define rw_assert_unlocked(rwl) ((void)0)
+#endif
+
+int rw_enter(struct rwlock *, int);
+void rw_exit(struct rwlock *);
+int rw_status(struct rwlock *);
+
+void _rrw_init_flags(struct rrwlock *, const char *, int,
+ const struct lock_type *);
+int rrw_enter(struct rrwlock *, int);
+void rrw_exit(struct rrwlock *);
+int rrw_status(struct rrwlock *);
+
+#ifdef WITNESS
+#define rrw_init_flags(rrwl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #rrwl };\
+ _rrw_init_flags(rrwl, name, flags, &__lock_type); \
+} while (0)
+#define rrw_init(rrwl, name) rrw_init_flags(rrwl, name, 0)
+#else /* WITNESS */
+#define rrw_init_flags(rrwl, name, flags) \
+ _rrw_init_flags(rrwl, name, 0, NULL)
+#define rrw_init(rrwl, name) _rrw_init_flags(rrwl, name, 0, NULL)
+#endif /* WITNESS */
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_RWLOCK_H */
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
new file mode 100644
index 0000000..279d50f
--- /dev/null
+++ b/sys/sys/sched.h
@@ -0,0 +1,244 @@
+/* $OpenBSD: sched.h,v 1.56 2019/10/21 10:24:01 mpi Exp $ */
+/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ross Harvey.
+ *
+ * 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, 1991, 1993
+ * 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.
+ *
+ * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_SCHED_H_
+#define _SYS_SCHED_H_
+
+#include <sys/queue.h>
+
+/*
+ * Posix defines a <sched.h> which may want to include <sys/sched.h>
+ */
+
+/*
+ * CPU states.
+ * XXX Not really scheduler state, but no other good place to put
+ * it right now, and it really is per-CPU.
+ */
+#define CP_USER 0
+#define CP_NICE 1
+#define CP_SYS 2
+#define CP_SPIN 3
+#define CP_INTR 4
+#define CP_IDLE 5
+#define CPUSTATES 6
+
+#define SCHED_NQS 32 /* 32 run queues. */
+
+struct smr_entry;
+
+/*
+ * Per-CPU scheduler state.
+ */
+struct schedstate_percpu {
+ struct proc *spc_idleproc; /* idle proc for this cpu */
+ TAILQ_HEAD(prochead, proc) spc_qs[SCHED_NQS];
+ LIST_HEAD(,proc) spc_deadproc;
+ struct timespec spc_runtime; /* time curproc started running */
+ volatile int spc_schedflags; /* flags; see below */
+ u_int spc_schedticks; /* ticks for schedclock() */
+ u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
+ u_char spc_curpriority; /* usrpri of curproc */
+ int spc_rrticks; /* ticks until roundrobin() */
+ int spc_pscnt; /* prof/stat counter */
+ int spc_psdiv; /* prof/stat divisor */
+
+ u_int spc_nrun; /* procs on the run queues */
+ fixpt_t spc_ldavg; /* shortest load avg. for this cpu */
+
+ volatile uint32_t spc_whichqs;
+ volatile u_int spc_spinning; /* this cpu is currently spinning */
+
+ SIMPLEQ_HEAD(, smr_entry) spc_deferred; /* deferred smr calls */
+ u_int spc_ndeferred; /* number of deferred smr calls */
+ u_int spc_smrdepth; /* level of smr nesting */
+ u_char spc_smrexpedite; /* if set, dispatch smr entries
+ * without delay */
+};
+
+struct cpustats {
+ uint64_t cs_time[CPUSTATES]; /* CPU state statistics */
+ uint64_t cs_flags; /* see below */
+};
+
+#define CPUSTATS_ONLINE 0x0001 /* CPU is schedulable */
+
+#ifdef _KERNEL
+
+/* spc_flags */
+#define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */
+#define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */
+#define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD)
+#define SPCF_SHOULDHALT 0x0004 /* CPU should be vacated */
+#define SPCF_HALTED 0x0008 /* CPU has been halted */
+
+#define SCHED_PPQ (128 / SCHED_NQS) /* priorities per queue */
+#define NICE_WEIGHT 2 /* priorities per nice level */
+#define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - SCHED_PPQ)
+
+extern int schedhz; /* ideally: 16 */
+extern int rrticks_init; /* ticks per roundrobin() */
+
+struct proc;
+void schedclock(struct proc *);
+struct cpu_info;
+void roundrobin(struct cpu_info *);
+void scheduler_start(void);
+void userret(struct proc *p);
+
+void sched_init_cpu(struct cpu_info *);
+void sched_idle(void *);
+void sched_exit(struct proc *);
+void mi_switch(void);
+void cpu_switchto(struct proc *, struct proc *);
+struct proc *sched_chooseproc(void);
+struct cpu_info *sched_choosecpu(struct proc *);
+struct cpu_info *sched_choosecpu_fork(struct proc *parent, int);
+void cpu_idle_enter(void);
+void cpu_idle_cycle(void);
+void cpu_idle_leave(void);
+void sched_peg_curproc(struct cpu_info *ci);
+void sched_barrier(struct cpu_info *ci);
+
+int sysctl_hwsetperf(void *, size_t *, void *, size_t);
+int sysctl_hwperfpolicy(void *, size_t *, void *, size_t);
+int sysctl_hwsmt(void *, size_t *, void *, size_t);
+int sysctl_hwncpuonline(void);
+
+#ifdef MULTIPROCESSOR
+void sched_start_secondary_cpus(void);
+void sched_stop_secondary_cpus(void);
+#endif
+
+#define cpu_is_idle(ci) ((ci)->ci_schedstate.spc_whichqs == 0)
+int cpu_is_online(struct cpu_info *);
+
+void sched_init_runqueues(void);
+void setrunqueue(struct cpu_info *, struct proc *, uint8_t);
+void remrunqueue(struct proc *);
+
+/* Chargeback parents for the sins of their children. */
+#define scheduler_wait_hook(parent, child) do { \
+ (parent)->p_estcpu = ESTCPULIM((parent)->p_estcpu + (child)->p_estcpu);\
+} while (0)
+
+/* Allow other processes to progress */
+#define sched_pause(func) do { \
+ if (curcpu()->ci_schedstate.spc_schedflags & SPCF_SHOULDYIELD) \
+ func(); \
+} while (0)
+
+#if defined(MULTIPROCESSOR)
+#include <sys/lock.h>
+
+/*
+ * XXX Instead of using struct lock for the kernel lock and thus requiring us
+ * XXX to implement simplelocks, causing all sorts of fine-grained locks all
+ * XXX over our tree to be activated, the sched_lock is a different kind of
+ * XXX lock to avoid introducing locking protocol bugs.
+ */
+extern struct __mp_lock sched_lock;
+
+#define SCHED_ASSERT_LOCKED() \
+do { \
+ splassert(IPL_SCHED); \
+ KASSERT(__mp_lock_held(&sched_lock, curcpu())); \
+} while (0)
+#define SCHED_ASSERT_UNLOCKED() \
+do { \
+ KASSERT(__mp_lock_held(&sched_lock, curcpu()) == 0); \
+} while (0)
+
+#define SCHED_LOCK_INIT() __mp_lock_init(&sched_lock)
+
+#define SCHED_LOCK(s) \
+do { \
+ s = splsched(); \
+ __mp_lock(&sched_lock); \
+} while (/* CONSTCOND */ 0)
+
+#define SCHED_UNLOCK(s) \
+do { \
+ __mp_unlock(&sched_lock); \
+ splx(s); \
+} while (/* CONSTCOND */ 0)
+
+#else /* ! MULTIPROCESSOR */
+
+#define SCHED_ASSERT_LOCKED() splassert(IPL_SCHED);
+#define SCHED_ASSERT_UNLOCKED() /* nothing */
+
+#define SCHED_LOCK_INIT() /* nothing */
+
+#define SCHED_LOCK(s) s = splsched()
+#define SCHED_UNLOCK(s) splx(s)
+
+#endif /* MULTIPROCESSOR */
+
+#endif /* _KERNEL */
+#endif /* _SYS_SCHED_H_ */
diff --git a/sys/sys/scsiio.h b/sys/sys/scsiio.h
new file mode 100644
index 0000000..a217355
--- /dev/null
+++ b/sys/sys/scsiio.h
@@ -0,0 +1,74 @@
+/* $OpenBSD: scsiio.h,v 1.10 2012/09/05 17:17:47 deraadt Exp $ */
+/* $NetBSD: scsiio.h,v 1.3 1994/06/29 06:45:09 cgd Exp $ */
+
+#ifndef _SYS_SCSIIO_H_
+#define _SYS_SCSIIO_H_
+
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#define SENSEBUFLEN 48
+#define CMDBUFLEN 16
+
+typedef struct scsireq {
+ u_long flags; /* info about the request status and type */
+ u_long timeout;
+ u_char cmd[CMDBUFLEN];
+ u_char cmdlen;
+ caddr_t databuf; /* address in user space of buffer */
+ u_long datalen; /* size of user buffer (request) */
+ u_long datalen_used; /* size of user buffer (used)*/
+ u_char sense[SENSEBUFLEN]; /* returned sense will be in here */
+ u_char senselen; /* sensedata request size (MAX of SENSEBUFLEN)*/
+ u_char senselen_used; /* return value only */
+ u_char status; /* what the scsi status was from the adapter */
+ u_char retsts; /* the return status for the command */
+ int error; /* error bits */
+} scsireq_t;
+
+/* bit definitions for flags */
+#define SCCMD_READ 0x00000001
+#define SCCMD_WRITE 0x00000002
+#define SCCMD_IOV 0x00000004
+#define SCCMD_ESCAPE 0x00000010
+#define SCCMD_TARGET 0x00000020
+
+
+/* definitions for the return status (retsts) */
+#define SCCMD_OK 0x00
+#define SCCMD_TIMEOUT 0x01
+#define SCCMD_BUSY 0x02
+#define SCCMD_SENSE 0x03
+#define SCCMD_UNKNOWN 0x04
+
+#define SCIOCCOMMAND _IOWR('Q', 1, scsireq_t)
+
+#define SC_DB_CMDS 0x00000001 /* show all scsi cmds and errors */
+#define SC_DB_FLOW 0x00000002 /* show routines entered */
+#define SC_DB_FLOW2 0x00000004 /* show path INSIDE routines */
+#define SC_DB_DMA 0x00000008 /* show DMA segments etc */
+#define SCIOCDEBUG _IOW('Q', 2, int) /* from 0 to 15 */
+
+struct scsi_addr {
+ int type;
+#define TYPE_SCSI 0
+#define TYPE_ATAPI 1
+ int scbus; /* -1 if wildcard */
+ int target; /* -1 if wildcard */
+ int lun; /* -1 if wildcard */
+};
+
+#define SCIOCRESET _IO('Q', 7) /* reset the device */
+#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr)
+
+struct sbioc_device {
+ void *sd_cookie;
+ int sd_target;
+ int sd_lun;
+};
+
+#define SBIOCPROBE _IOWR('Q', 127, struct sbioc_device)
+#define SBIOCDETACH _IOWR('Q', 128, struct sbioc_device)
+
+#endif /* _SYS_SCSIIO_H_ */
diff --git a/sys/sys/select.h b/sys/sys/select.h
new file mode 100644
index 0000000..3c7aa20
--- /dev/null
+++ b/sys/sys/select.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: select.h,v 1.17 2016/09/12 19:41:20 guenther 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 <sys/types.h>
+
+#ifndef _TIMEVAL_DECLARED
+#define _TIMEVAL_DECLARED
+struct timeval {
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
+};
+#endif
+
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+
+/*
+ * 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 1024
+#endif
+
+/*
+ * We don't want to pollute the namespace with select(2) internals.
+ * Non-underscore versions are exposed later #if __BSD_VISIBLE
+ */
+#define __NBBY 8 /* number of bits in a byte */
+typedef uint32_t __fd_mask;
+#define __NFDBITS ((unsigned)(sizeof(__fd_mask) * __NBBY)) /* bits per mask */
+#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
+
+typedef struct fd_set {
+ __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
+} fd_set;
+
+static __inline void
+__fd_set(int fd, fd_set *p)
+{
+ p->fds_bits[fd / __NFDBITS] |= (1U << (fd % __NFDBITS));
+}
+#define FD_SET(n, p) __fd_set((n), (p))
+
+static __inline void
+__fd_clr(int fd, fd_set *p)
+{
+ p->fds_bits[fd / __NFDBITS] &= ~(1U << (fd % __NFDBITS));
+}
+#define FD_CLR(n, p) __fd_clr((n), (p))
+
+static __inline int
+__fd_isset(int fd, const fd_set *p)
+{
+ return (p->fds_bits[fd / __NFDBITS] & (1U << (fd % __NFDBITS)));
+}
+#define FD_ISSET(n, p) __fd_isset((n), (p))
+
+#if __BSD_VISIBLE
+#define FD_COPY(f, t) (void)(*(t) = *(f))
+#endif
+#define FD_ZERO(p) do { \
+ fd_set *_p = (p); \
+ __size_t _n = __howmany(FD_SETSIZE, __NFDBITS); \
+ \
+ while (_n > 0) \
+ _p->fds_bits[--_n] = 0; \
+} while (0)
+
+#if __BSD_VISIBLE
+#define NBBY __NBBY
+#define fd_mask __fd_mask
+#define NFDBITS __NFDBITS
+#ifndef howmany
+#define howmany(x, y) __howmany(x, y)
+#endif
+#endif /* __BSD_VISIBLE */
+
+#ifndef _KERNEL
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#ifndef _SELECT_DEFINED_
+#define _SELECT_DEFINED_
+__BEGIN_DECLS
+int select(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, struct timeval * __restrict);
+int pselect(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, const struct timespec * __restrict,
+ const sigset_t * __restrict);
+__END_DECLS
+#endif
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SELECT_H_ */
diff --git a/sys/sys/selinfo.h b/sys/sys/selinfo.h
new file mode 100644
index 0000000..1d9431b
--- /dev/null
+++ b/sys/sys/selinfo.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: selinfo.h,v 1.5 2017/07/18 19:20:26 sf 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_SELINFO_H_
+#define _SYS_SELINFO_H_
+
+#include <sys/event.h> /* for struct klist */
+
+/*
+ * Used to maintain information about processes that wish to be
+ * notified when I/O becomes possible.
+ */
+struct selinfo {
+ struct klist si_note; /* kernel note list */
+ pid_t si_seltid; /* thread to be notified */
+ short si_flags; /* see below */
+};
+#define SI_COLL 0x0001 /* collision occurred */
+
+#ifdef _KERNEL
+struct proc;
+
+void selrecord(struct proc *selector, struct selinfo *);
+void selwakeup(struct selinfo *);
+#endif
+
+#endif /* !_SYS_SELINFO_H_ */
diff --git a/sys/sys/sem.h b/sys/sys/sem.h
new file mode 100644
index 0000000..184482d
--- /dev/null
+++ b/sys/sys/sem.h
@@ -0,0 +1,198 @@
+/* $OpenBSD: sem.h,v 1.24 2016/09/01 08:33:40 tom Exp $ */
+/* $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos Exp $ */
+
+/*
+ * SVID compatible sem.h file
+ *
+ * Author: Daniel Boulet
+ */
+
+#ifndef _SYS_SEM_H_
+#define _SYS_SEM_H_
+
+#ifndef _SYS_IPC_H_
+#include <sys/ipc.h>
+#endif
+
+#if __BSD_VISIBLE
+
+/* sem-specific sysctl variables corresponding to members of struct seminfo */
+#define KERN_SEMINFO_SEMMNI 1 /* int: # of semaphore identifiers */
+#define KERN_SEMINFO_SEMMNS 2 /* int: # of semaphores in system */
+#define KERN_SEMINFO_SEMMNU 3 /* int: # of undo structures in system */
+#define KERN_SEMINFO_SEMMSL 4 /* int: max semaphores per id */
+#define KERN_SEMINFO_SEMOPM 5 /* int: max operations per semop call */
+#define KERN_SEMINFO_SEMUME 6 /* int: max undo entries per process */
+#define KERN_SEMINFO_SEMUSZ 7 /* int: size in bytes of struct undo */
+#define KERN_SEMINFO_SEMVMX 8 /* int: semaphore maximum value */
+#define KERN_SEMINFO_SEMAEM 9 /* int: adjust on exit max value */
+#define KERN_SEMINFO_MAXID 10 /* number of valid semaphore sysctls */
+
+#define CTL_KERN_SEMINFO_NAMES { \
+ { 0, 0 }, \
+ { "semmni", CTLTYPE_INT }, \
+ { "semmns", CTLTYPE_INT }, \
+ { "semmnu", CTLTYPE_INT }, \
+ { "semmsl", CTLTYPE_INT }, \
+ { "semopm", CTLTYPE_INT }, \
+ { "semume", CTLTYPE_INT }, \
+ { "semusz", CTLTYPE_INT }, \
+ { "semvmx", CTLTYPE_INT }, \
+ { "semaem", CTLTYPE_INT }, \
+}
+
+#endif /* __BSD_VISIBLE */
+
+struct sem {
+ unsigned short semval; /* semaphore value */
+ pid_t sempid; /* pid of last operation */
+ unsigned short semncnt; /* # awaiting semval > cval */
+ unsigned short semzcnt; /* # awaiting semval = 0 */
+};
+
+struct semid_ds {
+ struct ipc_perm sem_perm; /* operation permission struct */
+ struct sem *sem_base; /* pointer to first semaphore in set */
+ unsigned short sem_nsems; /* number of sems in set */
+ time_t sem_otime; /* last operation time */
+ long sem_pad1; /* SVABI/386 says I need this here */
+ time_t sem_ctime; /* last change time */
+ /* Times measured in secs since */
+ /* 00:00:00 GMT, Jan. 1, 1970 */
+ long sem_pad2; /* SVABI/386 says I need this here */
+ long sem_pad3[4]; /* SVABI/386 says I need this here */
+};
+
+/*
+ * 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 010000
+
+/*
+ * semctl's arg parameter structure
+ */
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ unsigned short *array; /* array for GETALL & SETALL */
+};
+
+/*
+ * commands for semctl
+ */
+#define GETNCNT 3 /* Return the value of semncnt {READ} */
+#define GETPID 4 /* Return the value of sempid {READ} */
+#define GETVAL 5 /* Return the value of semval {READ} */
+#define GETALL 6 /* Return semvals into arg.array {READ} */
+#define GETZCNT 7 /* Return the value of semzcnt {READ} */
+#define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
+#define SETALL 9 /* Set semvals from arg.array {ALTER} */
+
+
+/*
+ * Permissions
+ */
+#define SEM_A 0200 /* alter permission */
+#define SEM_R 0400 /* read permission */
+
+
+#ifdef _KERNEL
+#include <sys/queue.h>
+
+/*
+ * Kernel implementation stuff
+ */
+#define SEMVMX 32767 /* semaphore maximum value */
+#define SEMAEM 16384 /* adjust on exit max value */
+
+/*
+ * Undo structure (one per process)
+ */
+struct sem_undo {
+ SLIST_ENTRY(sem_undo) un_next; /* ptr to next active undo structure */
+ struct process *un_proc; /* owner of this structure */
+ short un_cnt; /* # of active entries */
+ struct undo {
+ short un_adjval; /* adjust on exit values */
+ short un_num; /* semaphore # */
+ int un_id; /* semid */
+ } un_ent[1]; /* undo entries */
+};
+
+/*
+ * semaphore info struct
+ */
+struct seminfo {
+ int semmni, /* # of semaphore identifiers */
+ semmns, /* # of semaphores in system */
+ semmnu, /* # of undo structures in system */
+ semmsl, /* max # of semaphores per id */
+ semopm, /* max # of operations per semop call */
+ semume, /* max # of undo entries per process */
+ semusz, /* size in bytes of undo structure */
+ semvmx, /* semaphore maximum value */
+ semaem; /* adjust on exit max value */
+};
+
+struct sem_sysctl_info {
+ struct seminfo seminfo;
+ struct semid_ds semids[1];
+};
+
+extern struct seminfo seminfo;
+
+/*
+ * Configuration parameters
+ */
+#ifndef SEMMNI
+#define SEMMNI 10 /* # of semaphore identifiers */
+#endif
+#ifndef SEMMNS
+#define SEMMNS 60 /* # of semaphores in system */
+#endif
+#ifndef SEMUME
+#define SEMUME 10 /* max # of undo entries per process */
+#endif
+#ifndef SEMMNU
+#define SEMMNU 30 /* # of undo structures in system */
+#endif
+
+/* shouldn't need tuning */
+#ifndef SEMMSL
+#define SEMMSL SEMMNS /* max # of semaphores per id */
+#endif
+#ifndef SEMOPM
+#define SEMOPM 100 /* max # of operations per semop call */
+#endif
+
+/* actual size of an undo structure */
+#define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
+
+extern struct semid_ds **sema; /* semaphore id list */
+
+struct proc;
+
+void seminit(void);
+void semexit(struct process *);
+int sysctl_sysvsem(int *, u_int, void *, size_t *, void *, size_t);
+int semctl1(struct proc *, int, int, int, union semun *, register_t *,
+ int (*)(const void *, void *, size_t),
+ int (*)(const void *, void *, size_t));
+
+#endif /* _KERNEL */
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int semctl(int, int, int, ...);
+int __semctl(int, int, int, union semun *);
+int semget(key_t, int, int);
+int semop(int, struct sembuf *, size_t);
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SEM_H_ */
diff --git a/sys/sys/sensors.h b/sys/sys/sensors.h
new file mode 100644
index 0000000..15725a6
--- /dev/null
+++ b/sys/sys/sensors.h
@@ -0,0 +1,177 @@
+/* $OpenBSD: sensors.h,v 1.36 2018/12/10 13:35:54 landry Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
+ * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru>
+ * 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_SENSORS_H_
+#define _SYS_SENSORS_H_
+
+/* Sensor types */
+enum sensor_type {
+ SENSOR_TEMP, /* temperature (uK) */
+ SENSOR_FANRPM, /* fan revolution speed */
+ SENSOR_VOLTS_DC, /* voltage (uV DC) */
+ SENSOR_VOLTS_AC, /* voltage (uV AC) */
+ SENSOR_OHMS, /* resistance */
+ SENSOR_WATTS, /* power (uW) */
+ SENSOR_AMPS, /* current (uA) */
+ SENSOR_WATTHOUR, /* power capacity (uWh) */
+ SENSOR_AMPHOUR, /* power capacity (uAh) */
+ SENSOR_INDICATOR, /* boolean indicator */
+ SENSOR_INTEGER, /* generic integer value */
+ SENSOR_PERCENT, /* percent (m%) */
+ SENSOR_LUX, /* illuminance (ulx) */
+ SENSOR_DRIVE, /* disk */
+ SENSOR_TIMEDELTA, /* system time error (nSec) */
+ SENSOR_HUMIDITY, /* humidity (m%RH) */
+ SENSOR_FREQ, /* frequency (uHz) */
+ SENSOR_ANGLE, /* angle (uDegrees) */
+ SENSOR_DISTANCE, /* distance (uMeter) */
+ SENSOR_PRESSURE, /* pressure (mPa) */
+ SENSOR_ACCEL, /* acceleration (u m/s^2) */
+ SENSOR_VELOCITY, /* velocity (u m/s) */
+ SENSOR_MAX_TYPES
+};
+
+#ifndef _KERNEL
+static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = {
+ "temp",
+ "fan",
+ "volt",
+ "acvolt",
+ "resistance",
+ "power",
+ "current",
+ "watthour",
+ "amphour",
+ "indicator",
+ "raw",
+ "percent",
+ "illuminance",
+ "drive",
+ "timedelta",
+ "humidity",
+ "frequency",
+ "angle",
+ "distance",
+ "pressure",
+ "acceleration",
+ "velocity",
+ "undefined"
+};
+#endif /* !_KERNEL */
+
+#define SENSOR_DRIVE_EMPTY 1
+#define SENSOR_DRIVE_READY 2
+#define SENSOR_DRIVE_POWERUP 3
+#define SENSOR_DRIVE_ONLINE 4
+#define SENSOR_DRIVE_IDLE 5
+#define SENSOR_DRIVE_ACTIVE 6
+#define SENSOR_DRIVE_REBUILD 7
+#define SENSOR_DRIVE_POWERDOWN 8
+#define SENSOR_DRIVE_FAIL 9
+#define SENSOR_DRIVE_PFAIL 10
+
+/* Sensor states */
+enum sensor_status {
+ SENSOR_S_UNSPEC, /* status is unspecified */
+ SENSOR_S_OK, /* status is ok */
+ SENSOR_S_WARN, /* status is warning */
+ SENSOR_S_CRIT, /* status is critical */
+ SENSOR_S_UNKNOWN /* status is unknown */
+};
+
+/* Sensor data:
+ * New fields should be added at the end to encourage backwards compat
+ */
+struct sensor {
+ char desc[32]; /* sensor description, may be empty */
+ struct timeval tv; /* sensor value last change time */
+ int64_t value; /* current value */
+ enum sensor_type type; /* sensor type */
+ enum sensor_status status; /* sensor status */
+ int numt; /* sensor number of .type type */
+ int flags; /* sensor flags */
+#define SENSOR_FINVALID 0x0001 /* sensor is invalid */
+#define SENSOR_FUNKNOWN 0x0002 /* sensor value is unknown */
+};
+
+/* Sensor device data:
+ * New fields should be added at the end to encourage backwards compat
+ */
+struct sensordev {
+ int num; /* sensordev number */
+ char xname[16]; /* unix device name */
+ int maxnumt[SENSOR_MAX_TYPES];
+ int sensors_count;
+};
+
+#ifdef _KERNEL
+
+/* Sensor data */
+struct ksensor {
+ SLIST_ENTRY(ksensor) list; /* device-scope list */
+ char desc[32]; /* sensor description, may be empty */
+ struct timeval tv; /* sensor value last change time */
+ int64_t value; /* current value */
+ enum sensor_type type; /* sensor type */
+ enum sensor_status status; /* sensor status */
+ int numt; /* sensor number of .type type */
+ int flags; /* sensor flags, ie. SENSOR_FINVALID */
+};
+SLIST_HEAD(ksensors_head, ksensor);
+
+/* Sensor device data */
+struct ksensordev {
+ SLIST_ENTRY(ksensordev) list;
+ int num; /* sensordev number */
+ char xname[16]; /* unix device name */
+ int maxnumt[SENSOR_MAX_TYPES];
+ int sensors_count;
+ struct ksensors_head sensors_list;
+};
+
+/* struct ksensordev */
+void sensordev_install(struct ksensordev *);
+void sensordev_deinstall(struct ksensordev *);
+int sensordev_get(int, struct ksensordev **);
+
+/* struct ksensor */
+void sensor_attach(struct ksensordev *, struct ksensor *);
+void sensor_detach(struct ksensordev *, struct ksensor *);
+int sensor_find(int, enum sensor_type, int, struct ksensor **);
+
+/* task scheduling */
+struct sensor_task;
+struct sensor_task *sensor_task_register(void *, void (*)(void *),
+ unsigned int);
+void sensor_task_unregister(struct sensor_task *);
+void sensor_quiesce(void);
+void sensor_restart(void);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_SENSORS_H_ */
diff --git a/sys/sys/shm.h b/sys/sys/shm.h
new file mode 100644
index 0000000..d46cbbe
--- /dev/null
+++ b/sys/sys/shm.h
@@ -0,0 +1,151 @@
+/* $OpenBSD: shm.h,v 1.29 2019/11/03 20:16:01 guenther Exp $ */
+/* $NetBSD: shm.h,v 1.20 1996/04/09 20:55:35 cgd Exp $ */
+
+/*
+ * 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_
+
+#ifndef _SYS_IPC_H_
+#include <sys/ipc.h>
+#endif
+
+#if __BSD_VISIBLE
+
+/* shm-specific sysctl variables corresponding to members of struct shminfo */
+#define KERN_SHMINFO_SHMMAX 1 /* int: max shm segment size (bytes) */
+#define KERN_SHMINFO_SHMMIN 2 /* int: min shm segment size (bytes) */
+#define KERN_SHMINFO_SHMMNI 3 /* int: max number of shm identifiers */
+#define KERN_SHMINFO_SHMSEG 4 /* int: max shm segments per process */
+#define KERN_SHMINFO_SHMALL 5 /* int: max amount of shm (pages) */
+#define KERN_SHMINFO_MAXID 6 /* number of valid shared memory ids */
+
+#define CTL_KERN_SHMINFO_NAMES { \
+ { 0, 0 }, \
+ { "shmmax", CTLTYPE_INT }, \
+ { "shmmin", CTLTYPE_INT }, \
+ { "shmmni", CTLTYPE_INT }, \
+ { "shmseg", CTLTYPE_INT }, \
+ { "shmall", CTLTYPE_INT }, \
+}
+
+/*
+ * Old (deprecated) access mode definitions--do not use.
+ * Provided for compatibility with old code only.
+ */
+#define SHM_R IPC_R
+#define SHM_W IPC_W
+
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Shared memory operation flags for shmat(2).
+ */
+#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */
+#define SHM_RND 020000 /* Round attach address to SHMLBA */
+
+/*
+ * Shared memory specific control commands for shmctl().
+ * We accept but ignore these (XXX).
+ */
+#define SHM_LOCK 3 /* Lock segment in memory. */
+#define SHM_UNLOCK 4 /* Unlock a segment locked by SHM_LOCK. */
+
+/*
+ * Segment low boundry address multiple
+ */
+#define SHMLBA (1U << _MAX_PAGE_SHIFT)
+
+typedef short shmatt_t;
+
+struct shmid_ds {
+ struct ipc_perm shm_perm; /* operation permission structure */
+ int shm_segsz; /* size of segment in bytes */
+ pid_t shm_lpid; /* process ID of last shm op */
+ pid_t shm_cpid; /* process ID of creator */
+ shmatt_t shm_nattch; /* number of current attaches */
+ time_t shm_atime; /* time of last shmat() */
+ long __shm_atimensec;
+ time_t shm_dtime; /* time of last shmdt() */
+ long __shm_dtimensec;
+ time_t shm_ctime; /* time of last change by shmctl() */
+ long __shm_ctimensec;
+ void *shm_internal; /* implementation specific data */
+};
+
+#if __BSD_VISIBLE
+/*
+ * System V style catch-all structure for shared memory constants that
+ * might be of interest to user programs. Do we really want/need this?
+ */
+struct shminfo {
+ int shmmax; /* max shared memory segment size (bytes) */
+ int shmmin; /* min shared memory segment size (bytes) */
+ int shmmni; /* max number of shared memory identifiers */
+ int shmseg; /* max shared memory segments per process */
+ int shmall; /* max amount of shared memory (pages) */
+};
+
+struct shm_sysctl_info {
+ struct shminfo shminfo;
+ struct shmid_ds shmids[1];
+};
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+extern struct shminfo shminfo;
+extern struct shmid_ds **shmsegs;
+
+struct proc;
+struct vmspace;
+
+void shminit(void);
+void shmfork(struct vmspace *, struct vmspace *);
+void shmexit(struct vmspace *);
+int sysctl_sysvshm(int *, u_int, void *, size_t *, void *, size_t);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+void *shmat(int, const void *, int);
+int shmctl(int, int, struct shmid_ds *);
+int shmdt(const void *);
+int shmget(key_t, size_t, int);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SHM_H_ */
diff --git a/sys/sys/siginfo.h b/sys/sys/siginfo.h
new file mode 100644
index 0000000..dd6b32f
--- /dev/null
+++ b/sys/sys/siginfo.h
@@ -0,0 +1,199 @@
+/* $OpenBSD: siginfo.h,v 1.12 2017/04/07 04:48:44 guenther Exp $ */
+
+/*
+ * Copyright (c) 1997 Theo de Raadt
+ * 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_SIGINFO_H
+#define _SYS_SIGINFO_H
+
+#include <sys/cdefs.h>
+
+union sigval {
+ int sival_int; /* integer value */
+ void *sival_ptr; /* pointer value */
+};
+
+/*
+ * Negative signal codes are reserved for future use for
+ * user generated signals.
+ */
+#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
+#define SI_FROMKERNEL(sip) ((sip)->si_code > 0)
+
+#define SI_NOINFO 32767 /* no signal information */
+#define SI_USER 0 /* user generated signal via kill() */
+#define SI_LWP (-1) /* user generated signal via lwp_kill()*/
+#define SI_QUEUE (-2) /* user generated signal via sigqueue()*/
+#define SI_TIMER (-3) /* from timer expiration */
+
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE
+/*
+ * The machine dependent signal codes (SIGILL, SIGFPE,
+ * SIGSEGV, and SIGBUS)
+ */
+#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 /* co-processor */
+#define ILL_BADSTK 8 /* bad stack */
+#define NSIGILL 8
+
+#define EMT_TAGOVF 1 /* tag overflow */
+#define NSIGEMT 1
+
+#define FPE_INTDIV 1 /* integer divide by zero */
+#define FPE_INTOVF 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 /* invalid floating point operation */
+#define FPE_FLTSUB 8 /* subscript out of range */
+#define NSIGFPE 8
+
+#define SEGV_MAPERR 1 /* address not mapped to object */
+#define SEGV_ACCERR 2 /* invalid permissions */
+#define NSIGSEGV 2
+
+#define BUS_ADRALN 1 /* invalid address alignment */
+#define BUS_ADRERR 2 /* non-existent physical address */
+#define BUS_OBJERR 3 /* object specific hardware error */
+#define NSIGBUS 3
+
+#endif /* __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE */
+
+/*
+ * SIGTRAP signal codes
+ */
+#define TRAP_BRKPT 1 /* breakpoint trap */
+#define TRAP_TRACE 2 /* trace trap */
+#define NSIGTRAP 2
+
+/*
+ * SIGCHLD signal codes
+ */
+#define CLD_EXITED 1 /* child has exited */
+#define CLD_KILLED 2 /* child was killed */
+#define CLD_DUMPED 3 /* child has coredumped */
+#define CLD_TRAPPED 4 /* traced child has stopped */
+#define CLD_STOPPED 5 /* child has stopped on signal */
+#define CLD_CONTINUED 6 /* stopped child has continued */
+#define NSIGCLD 6
+
+#if 0
+/*
+ * SIGPOLL signal codes - not supported
+ */
+#define POLL_IN 1 /* input available */
+#define POLL_OUT 2 /* output possible */
+#define POLL_MSG 3 /* message available */
+#define POLL_ERR 4 /* I/O error */
+#define POLL_PRI 5 /* high priority input available */
+#define POLL_HUP 6 /* device disconnected */
+#define NSIGPOLL 6
+
+/*
+ * SIGPROF signal codes - not supported
+ */
+#define PROF_SIG 1 /* have to set code non-zero */
+#define NSIGPROF 1
+#endif
+
+#define SI_MAXSZ 128
+#define SI_PAD ((SI_MAXSZ / sizeof (int)) - 3)
+
+#include <sys/time.h>
+
+typedef struct {
+ int si_signo; /* signal from signal.h */
+ int si_code; /* code from above */
+ int si_errno; /* error from errno.h */
+ union {
+ int _pad[SI_PAD]; /* for future growth */
+ struct { /* kill(), SIGCHLD */
+ pid_t _pid; /* process ID */
+ union {
+ struct {
+ uid_t _uid;
+ union sigval _value;
+ } _kill;
+ struct {
+ clock_t _utime;
+ clock_t _stime;
+ int _status;
+ } _cld;
+ } _pdata;
+ } _proc;
+ struct { /* SIGSEGV, SIGBUS, SIGILL and SIGFPE */
+ void *_addr; /* faulting address */
+ int _trapno; /* illegal trap number */
+ } _fault;
+#if 0
+ struct { /* SIGPOLL, SIGXFSZ */
+ /* fd not currently available for SIGPOLL */
+ int _fd; /* file descriptor */
+ long _band;
+ } _file;
+ struct { /* SIGPROF */
+ caddr_t _faddr; /* last fault address */
+ timespec _tstamp; /* real time stamp */
+ short _syscall; /* current syscall */
+ char _nsysarg; /* number of arguments */
+ char _fault; /* last fault type */
+ long _sysarg[8]; /* syscall arguments */
+ long _mstate[17]; /* exactly fills struct*/
+ } _prof;
+#endif
+ } _data;
+} siginfo_t;
+
+#define si_pid _data._proc._pid
+
+#define si_status _data._proc._pdata._cld._status
+#define si_stime _data._proc._pdata._cld._stime
+#define si_utime _data._proc._pdata._cld._utime
+#define si_uid _data._proc._pdata._kill._uid
+#define si_value _data._proc._pdata._kill._value
+#define si_addr _data._fault._addr
+#define si_trapno _data._fault._trapno
+#define si_fd _data._file._fd
+#define si_band _data._file._band
+
+#define si_tstamp _data._prof._tstamp
+#define si_syscall _data._prof._syscall
+#define si_nsysarg _data._prof._nsysarg
+#define si_sysarg _data._prof._sysarg
+#define si_fault _data._prof._fault
+#define si_faddr _data._prof._faddr
+#define si_mstate _data._prof._mstate
+
+#if defined(_KERNEL)
+void initsiginfo(siginfo_t *, int, u_long, int, union sigval);
+#endif
+
+#endif /* _SYS_SIGINFO_H */
diff --git a/sys/sys/sigio.h b/sys/sys/sigio.h
new file mode 100644
index 0000000..a20f983
--- /dev/null
+++ b/sys/sys/sigio.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: sigio.h,v 1.4 2020/01/08 16:27:42 visa 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.
+ *
+ * @(#)filedesc.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: head/sys/sys/sigio.h 326023 2017-11-20 19:43:44Z pfg $
+ */
+
+#ifndef _SYS_SIGIO_H_
+#define _SYS_SIGIO_H_
+
+struct sigio;
+LIST_HEAD(sigiolst, sigio);
+
+/*
+ * sigio registration
+ *
+ * Locking:
+ * S sigio_lock
+ */
+struct sigio_ref {
+ struct sigio *sir_sigio; /* [S] associated sigio struct */
+};
+
+#ifdef _KERNEL
+
+/*
+ * This structure holds the information needed to send a SIGIO or
+ * a SIGURG signal to a process or process group when new data arrives
+ * on a device or socket. The structure is placed on an LIST belonging
+ * to the proc or pgrp so that the entire list may be revoked when the
+ * process exits or the process group disappears.
+ *
+ * Locking:
+ * I immutable after creation
+ * S sigio_lock
+ */
+struct sigio {
+ union {
+ struct process *siu_proc;
+ /* [I] process to receive
+ * SIGIO/SIGURG */
+ struct pgrp *siu_pgrp; /* [I] process group to receive ... */
+ } sio_u;
+ LIST_ENTRY(sigio) sio_pgsigio; /* [S] sigio's for process or group */
+ struct sigio_ref *sio_myref; /* [I] location of the pointer that
+ * holds the reference to
+ * this structure */
+ struct ucred *sio_ucred; /* [I] current credentials */
+ pid_t sio_pgid; /* [I] pgid for signals */
+};
+#define sio_proc sio_u.siu_proc
+#define sio_pgrp sio_u.siu_pgrp
+
+static inline void
+sigio_init(struct sigio_ref *sir)
+{
+ sir->sir_sigio = NULL;
+}
+
+void sigio_copy(struct sigio_ref *, struct sigio_ref *);
+void sigio_free(struct sigio_ref *);
+void sigio_freelist(struct sigiolst *);
+void sigio_getown(struct sigio_ref *, u_long, caddr_t);
+int sigio_setown(struct sigio_ref *, u_long, caddr_t);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_SIGIO_H_ */
diff --git a/sys/sys/signal.h b/sys/sys/signal.h
new file mode 100644
index 0000000..dcb6810
--- /dev/null
+++ b/sys/sys/signal.h
@@ -0,0 +1,202 @@
+/* $OpenBSD: signal.h,v 1.29 2018/04/18 16:05:20 deraadt Exp $ */
+/* $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1991, 1993
+ * 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.
+ *
+ * @(#)signal.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_SIGNAL_H_
+#define _SYS_SIGNAL_H_
+
+#include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */
+
+#define _NSIG 33 /* counting 0 (mask is 1-32) */
+
+#if __BSD_VISIBLE
+#define NSIG _NSIG
+#endif
+
+#define SIGHUP 1 /* hangup */
+#define SIGINT 2 /* interrupt */
+#define SIGQUIT 3 /* quit */
+#define SIGILL 4 /* illegal instruction (not reset when caught) */
+#define SIGTRAP 5 /* trace trap (not reset when caught) */
+#define SIGABRT 6 /* abort() */
+#if __BSD_VISIBLE
+#define SIGIOT SIGABRT /* compatibility */
+#define SIGEMT 7 /* EMT instruction */
+#endif
+#define SIGFPE 8 /* floating point exception */
+#define SIGKILL 9 /* kill (cannot be caught or ignored) */
+#define SIGBUS 10 /* bus error */
+#define SIGSEGV 11 /* segmentation violation */
+#define SIGSYS 12 /* bad argument to system call */
+#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 SIGURG 16 /* urgent condition on IO channel */
+#define SIGSTOP 17 /* sendable stop signal not from tty */
+#define SIGTSTP 18 /* stop signal from tty */
+#define SIGCONT 19 /* continue a stopped process */
+#define SIGCHLD 20 /* to parent on child stop or exit */
+#define SIGTTIN 21 /* to readers pgrp upon background tty read */
+#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#if __BSD_VISIBLE
+#define SIGIO 23 /* input/output possible signal */
+#endif
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGPROF 27 /* profiling time alarm */
+#if __BSD_VISIBLE
+#define SIGWINCH 28 /* window size changes */
+#define SIGINFO 29 /* information request */
+#endif
+#define SIGUSR1 30 /* user defined signal 1 */
+#define SIGUSR2 31 /* user defined signal 2 */
+#if __BSD_VISIBLE
+#define SIGTHR 32 /* thread library AST */
+#endif
+
+/*
+ * Language spec says we must list exactly one parameter, even though we
+ * actually supply three. Ugh!
+ */
+#define SIG_DFL (void (*)(int))0
+#define SIG_IGN (void (*)(int))1
+#define SIG_ERR (void (*)(int))-1
+
+#if __POSIX_VISIBLE || __XPG_VISIBLE
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#include <sys/siginfo.h>
+
+/*
+ * Signal vector "template" used in sigaction call.
+ */
+struct sigaction {
+ union { /* signal handler */
+ void (*__sa_handler)(int);
+ void (*__sa_sigaction)(int, siginfo_t *, void *);
+ } __sigaction_u;
+ sigset_t sa_mask; /* signal mask to apply */
+ int sa_flags; /* see signal options below */
+};
+
+/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
+#define sa_handler __sigaction_u.__sa_handler
+#define sa_sigaction __sigaction_u.__sa_sigaction
+
+#if __XPG_VISIBLE >= 500
+#define SA_ONSTACK 0x0001 /* take signal on signal stack */
+#define SA_RESTART 0x0002 /* restart system on signal return */
+#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
+#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
+#define SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid 1) */
+#endif /* __XPG_VISIBLE >= 500 */
+#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500
+#define SA_SIGINFO 0x0040 /* generate siginfo_t */
+#endif
+
+/*
+ * Flags for sigprocmask:
+ */
+#define SIG_BLOCK 1 /* block specified signal set */
+#define SIG_UNBLOCK 2 /* unblock specified signal set */
+#define SIG_SETMASK 3 /* set specified signal set */
+#endif /* __POSIX_VISIBLE || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE
+typedef void (*sig_t)(int); /* type of signal function */
+
+/*
+ * 4.3 compatibility:
+ * Signal vector "template" used in sigvec call.
+ */
+struct sigvec {
+ void (*sv_handler)(int); /* signal handler */
+ int sv_mask; /* signal mask to apply */
+ int sv_flags; /* see signal options below */
+};
+#define SV_ONSTACK SA_ONSTACK
+#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
+#define SV_RESETHAND SA_RESETHAND
+#define sv_onstack sv_flags /* isn't compatibility wonderful! */
+
+/*
+ * Macro for converting signal number to a mask suitable for
+ * sigblock().
+ */
+#define sigmask(m) (1U << ((m)-1))
+
+#define BADSIG SIG_ERR
+
+#endif /* __BSD_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
+/*
+ * Structure used in sigaltstack call.
+ */
+typedef struct sigaltstack {
+ void *ss_sp; /* signal stack base */
+ size_t ss_size; /* signal stack length */
+ int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
+} stack_t;
+#define SS_ONSTACK 0x0001 /* take signals on alternate stack */
+#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
+#define MINSIGSTKSZ (3U << _MAX_PAGE_SHIFT) /* minimum allowable stack */
+#if _MAX_PAGE_SHIFT < 14 /* recommended stack size */
+#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 4)
+#else
+#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 2)
+#endif
+
+typedef struct sigcontext ucontext_t;
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
+
+#ifndef _KERNEL
+/*
+ * For historical reasons; programs expect signal's return value to be
+ * defined by <sys/signal.h>.
+ */
+__BEGIN_DECLS
+void (*signal(int, void (*)(int)))(int);
+__END_DECLS
+#endif /* !_KERNEL */
+#endif /* !_SYS_SIGNAL_H_ */
diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h
new file mode 100644
index 0000000..7ee361f
--- /dev/null
+++ b/sys/sys/signalvar.h
@@ -0,0 +1,144 @@
+/* $OpenBSD: signalvar.h,v 1.40 2020/03/13 09:25:21 mpi Exp $ */
+/* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos 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.
+ *
+ * @(#)signalvar.h 8.3 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
+#define _SYS_SIGNALVAR_H_
+
+/*
+ * Kernel signal definitions and data structures,
+ * not exported to user programs.
+ */
+
+/*
+ * Process signal actions and state, needed only within the process
+ * (not necessarily resident).
+ */
+struct sigacts {
+ sig_t ps_sigact[NSIG]; /* disposition of signals */
+ sigset_t ps_catchmask[NSIG]; /* signals to be blocked */
+ sigset_t ps_sigonstack; /* signals to take on sigstack */
+ sigset_t ps_sigintr; /* signals that interrupt syscalls */
+ sigset_t ps_sigreset; /* signals that reset when caught */
+ sigset_t ps_siginfo; /* signals that provide siginfo */
+ sigset_t ps_sigignore; /* signals being ignored */
+ sigset_t ps_sigcatch; /* signals being caught by user */
+ int ps_sigflags; /* signal flags, below */
+};
+
+/* signal flags */
+#define SAS_NOCLDSTOP 0x01 /* No SIGCHLD when children stop. */
+#define SAS_NOCLDWAIT 0x02 /* No zombies if child dies */
+
+/* additional signal action values, used only temporarily/internally */
+#define SIG_CATCH (void (*)(int))2
+#define SIG_HOLD (void (*)(int))3
+
+/*
+ * Check if process p has an unmasked signal pending.
+ * Return mask of pending signals.
+ */
+#define SIGPENDING(p) \
+ (((p)->p_siglist | (p)->p_p->ps_siglist) & ~(p)->p_sigmask)
+
+/*
+ * Determine signal that should be delivered to process p, the current
+ * process, 0 if none. If there is a pending stop signal with default
+ * action, the process stops in issignal().
+ */
+#define CURSIG(p) \
+ ((((p)->p_siglist | (p)->p_p->ps_siglist) == 0 || \
+ (((p)->p_p->ps_flags & PS_TRACED) == 0 && \
+ SIGPENDING(p) == 0)) ? \
+ 0 : issignal(p))
+
+/*
+ * Clear a pending signal from a process.
+ */
+#define CLRSIG(p, sig) do { \
+ int _mask = sigmask(sig); \
+ atomic_clearbits_int(&(p)->p_siglist, _mask); \
+ atomic_clearbits_int(&(p)->p_p->ps_siglist, _mask); \
+} while (0)
+
+/*
+ * Signal properties and actions.
+ * The array below categorizes the signals and their default actions
+ * according to the following properties:
+ */
+#define SA_KILL 0x01 /* terminates process by default */
+#define SA_CORE 0x02 /* ditto and coredumps */
+#define SA_STOP 0x04 /* suspend process */
+#define SA_TTYSTOP 0x08 /* ditto, from tty */
+#define SA_IGNORE 0x10 /* ignore by default */
+#define SA_CONT 0x20 /* continue if suspended */
+#define SA_CANTMASK 0x40 /* non-maskable, catchable */
+
+#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
+
+#ifdef _KERNEL
+enum signal_type { SPROCESS, STHREAD, SPROPAGATED };
+
+struct sigio_ref;
+
+/*
+ * Machine-independent functions:
+ */
+int coredump(struct proc *p);
+void execsigs(struct proc *p);
+int issignal(struct proc *p);
+void pgsigio(struct sigio_ref *sir, int sig, int checkctty);
+void pgsignal(struct pgrp *pgrp, int sig, int checkctty);
+void psignal(struct proc *p, int sig);
+void ptsignal(struct proc *p, int sig, enum signal_type type);
+#define prsignal(pr,sig) ptsignal((pr)->ps_mainproc, (sig), SPROCESS)
+void siginit(struct process *);
+void trapsignal(struct proc *p, int sig, u_long code, int type,<