diff options
Diffstat (limited to 'sys')
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<OSTOP) */ +#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, + union sigval val); +void sigexit(struct proc *, int); +int sigonstack(size_t); +void setsigvec(struct proc *, int, struct sigaction *); +int killpg1(struct proc *, int, int, int); + +void signal_init(void); + +struct sigacts *sigactsinit(struct process *); +void sigstkinit(struct sigaltstack *); +void sigactsfree(struct process *); + +/* + * Machine-dependent functions: + */ +void sendsig(sig_t _catcher, int _sig, sigset_t _mask, const siginfo_t *_si); +#endif /* _KERNEL */ +#endif /* !_SYS_SIGNALVAR_H_ */ diff --git a/sys/sys/smr.h b/sys/sys/smr.h new file mode 100644 index 0000000..1ca42e0 --- /dev/null +++ b/sys/sys/smr.h @@ -0,0 +1,440 @@ +/* $OpenBSD: smr.h,v 1.6 2020/04/12 07:20:33 visa Exp $ */ + +/* + * Copyright (c) 2019 Visa Hankala + * + * 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_SMR_H_ +#define _SYS_SMR_H_ + +#include <sys/queue.h> + +struct smr_entry { + SIMPLEQ_ENTRY(smr_entry) smr_list; + void (*smr_func)(void *); + void *smr_arg; +}; + +SIMPLEQ_HEAD(smr_entry_list, smr_entry); + +#ifdef _KERNEL + +#include <sys/atomic.h> + +void smr_startup(void); +void smr_startup_thread(void); +void smr_idle(void); +void smr_read_enter(void); +void smr_read_leave(void); + +void smr_call_impl(struct smr_entry *, void (*)(void *), void *, int); +void smr_barrier_impl(int); + +#define smr_call(entry, func, arg) smr_call_impl(entry, func, arg, 0) +#define smr_barrier() smr_barrier_impl(0) +#define smr_flush() smr_barrier_impl(1) + +static inline void +smr_init(struct smr_entry *smr) +{ + smr->smr_func = NULL; + smr->smr_arg = NULL; +} + +#ifdef DIAGNOSTIC +#define SMR_ASSERT_CRITICAL() do { \ + if (panicstr == NULL && !db_active) \ + KASSERT(curcpu()->ci_schedstate.spc_smrdepth > 0); \ +} while (0) +#define SMR_ASSERT_NONCRITICAL() do { \ + if (panicstr == NULL && !db_active) \ + KASSERT(curcpu()->ci_schedstate.spc_smrdepth == 0); \ +} while (0) +#else +#define SMR_ASSERT_CRITICAL() do {} while (0) +#define SMR_ASSERT_NONCRITICAL() do {} while (0) +#endif + +#define SMR_PTR_GET(pptr) READ_ONCE(*pptr) + +#define SMR_PTR_GET_LOCKED(pptr) (*(pptr)) + +#define SMR_PTR_SET_LOCKED(pptr, val) do { \ + membar_producer(); \ + WRITE_ONCE(*pptr, val); \ +} while (0) + +/* + * List implementations for use with safe memory reclamation. + */ + +/* + * 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 + */ + +#include <sys/_null.h> + +/* + * This file defines three types of data structures: singly-linked lists, + * lists, and tail 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 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 only be traversed in the forward direction + * by lock-free readers. + */ + +/* + * Singly-linked List definitions. + */ +#define SMR_SLIST_HEAD(name, type) \ +struct name { \ + struct type *smr_slh_first; /* first element, SMR-protected */\ +} + +#define SMR_SLIST_HEAD_INITIALIZER(head) \ + { .smr_slh_first = NULL } + +#define SMR_SLIST_ENTRY(type) \ +struct { \ + struct type *smr_sle_next; /* next element, SMR-protected */\ +} + +/* + * Singly-linked List access methods. + */ +#define SMR_SLIST_END(head) NULL + +#define SMR_SLIST_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_slh_first) +#define SMR_SLIST_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_sle_next) + +#define SMR_SLIST_FIRST_LOCKED(head) \ + SMR_PTR_GET_LOCKED(&(head)->smr_slh_first) +#define SMR_SLIST_EMPTY_LOCKED(head) \ + (SMR_SLIST_FIRST_LOCKED(head) == SMR_SLIST_END(head)) +#define SMR_SLIST_NEXT_LOCKED(elm, field) \ + SMR_PTR_GET_LOCKED(&(elm)->field.smr_sle_next) + +#define SMR_SLIST_FOREACH(var, head, field) \ + for ((var) = SMR_SLIST_FIRST(head); \ + (var) != SMR_SLIST_END(head); \ + (var) = SMR_SLIST_NEXT(var, field)) + +#define SMR_SLIST_FOREACH_LOCKED(var, head, field) \ + for ((var) = SMR_SLIST_FIRST_LOCKED(head); \ + (var) != SMR_SLIST_END(head); \ + (var) = SMR_SLIST_NEXT_LOCKED(var, field)) + +#define SMR_SLIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_SLIST_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_SLIST_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List functions. + */ +#define SMR_SLIST_INIT(head) do { \ + (head)->smr_slh_first = SMR_SLIST_END(head); \ +} while (0) + +#define SMR_SLIST_INSERT_AFTER_LOCKED(slistelm, elm, field) do { \ + (elm)->field.smr_sle_next = (slistelm)->field.smr_sle_next; \ + membar_producer(); \ + (slistelm)->field.smr_sle_next = (elm); \ +} while (0) + +#define SMR_SLIST_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_sle_next = (head)->smr_slh_first; \ + membar_producer(); \ + (head)->smr_slh_first = (elm); \ +} while (0) + +#define SMR_SLIST_REMOVE_AFTER_LOCKED(elm, field) do { \ + (elm)->field.smr_sle_next = \ + (elm)->field.smr_sle_next->field.smr_sle_next; \ +} while (0) + +#define SMR_SLIST_REMOVE_HEAD_LOCKED(head, field) do { \ + (head)->smr_slh_first = (head)->smr_slh_first->field.smr_sle_next;\ +} while (0) + +#define SMR_SLIST_REMOVE_LOCKED(head, elm, type, field) do { \ + if ((head)->smr_slh_first == (elm)) { \ + SMR_SLIST_REMOVE_HEAD_LOCKED((head), field); \ + } else { \ + struct type *curelm = (head)->smr_slh_first; \ + \ + while (curelm->field.smr_sle_next != (elm)) \ + curelm = curelm->field.smr_sle_next; \ + curelm->field.smr_sle_next = \ + curelm->field.smr_sle_next->field.smr_sle_next; \ + } \ + /* (elm)->field.smr_sle_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +/* + * List definitions. + */ +#define SMR_LIST_HEAD(name, type) \ +struct name { \ + struct type *smr_lh_first; /* first element, SMR-protected */\ +} + +#define SMR_LIST_HEAD_INITIALIZER(head) \ + { .smr_lh_first = NULL } + +#define SMR_LIST_ENTRY(type) \ +struct { \ + struct type *smr_le_next; /* next element, SMR-protected */\ + struct type **smr_le_prev; /* address of previous next element */\ +} + +/* + * List access methods. + */ +#define SMR_LIST_END(head) NULL + +#define SMR_LIST_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_lh_first) +#define SMR_LIST_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_le_next) + +#define SMR_LIST_FIRST_LOCKED(head) ((head)->smr_lh_first) +#define SMR_LIST_NEXT_LOCKED(elm, field) ((elm)->field.smr_le_next) +#define SMR_LIST_EMPTY_LOCKED(head) \ + (SMR_LIST_FIRST_LOCKED(head) == SMR_LIST_END(head)) + +#define SMR_LIST_FOREACH(var, head, field) \ + for((var) = SMR_LIST_FIRST(head); \ + (var)!= SMR_LIST_END(head); \ + (var) = SMR_LIST_NEXT(var, field)) + +#define SMR_LIST_FOREACH_LOCKED(var, head, field) \ + for((var) = SMR_LIST_FIRST_LOCKED(head); \ + (var)!= SMR_LIST_END(head); \ + (var) = SMR_LIST_NEXT_LOCKED(var, field)) + +#define SMR_LIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_LIST_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_LIST_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * List functions. + */ +#define SMR_LIST_INIT(head) do { \ + (head)->smr_lh_first = LIST_END(head); \ +} while (0) + +#define SMR_LIST_INSERT_AFTER_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_le_next = (listelm)->field.smr_le_next; \ + if ((listelm)->field.smr_le_next != NULL) \ + (listelm)->field.smr_le_next->field.smr_le_prev = \ + &(elm)->field.smr_le_next; \ + (elm)->field.smr_le_prev = &(listelm)->field.smr_le_next; \ + membar_producer(); \ + (listelm)->field.smr_le_next = (elm); \ +} while (0) + +#define SMR_LIST_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_le_prev = (listelm)->field.smr_le_prev; \ + (elm)->field.smr_le_next = (listelm); \ + membar_producer(); \ + *(listelm)->field.smr_le_prev = (elm); \ + (listelm)->field.smr_le_prev = &(elm)->field.smr_le_next; \ +} while (0) + +#define SMR_LIST_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_le_next = (head)->smr_lh_first; \ + (elm)->field.smr_le_prev = &(head)->smr_lh_first; \ + if ((head)->smr_lh_first != NULL) \ + (head)->smr_lh_first->field.smr_le_prev = \ + &(elm)->field.smr_le_next; \ + membar_producer(); \ + (head)->smr_lh_first = (elm); \ +} while (0) + +#define SMR_LIST_REMOVE_LOCKED(elm, field) do { \ + if ((elm)->field.smr_le_next != NULL) \ + (elm)->field.smr_le_next->field.smr_le_prev = \ + (elm)->field.smr_le_prev; \ + *(elm)->field.smr_le_prev = (elm)->field.smr_le_next; \ + /* (elm)->field.smr_le_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +/* + * Tail queue definitions. + */ +#define SMR_TAILQ_HEAD(name, type) \ +struct name { \ + struct type *smr_tqh_first; /* first element, SMR-protected */\ + struct type **smr_tqh_last; /* last element, SMR-protected */\ +} + +#define SMR_TAILQ_HEAD_INITIALIZER(head) \ + { .smr_tqh_first = NULL, .smr_tqh_last = &(head).smr_tqh_first } + +#define SMR_TAILQ_ENTRY(type) \ +struct { \ + struct type *smr_tqe_next; /* next element, SMR-protected */\ + struct type **smr_tqe_prev; /* address of previous next element */\ +} + +/* + * Tail queue access methods. + */ +#define SMR_TAILQ_END(head) NULL + +#define SMR_TAILQ_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_tqh_first) +#define SMR_TAILQ_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_tqe_next) + +#define SMR_TAILQ_FIRST_LOCKED(head) ((head)->smr_tqh_first) +#define SMR_TAILQ_NEXT_LOCKED(elm, field) ((elm)->field.smr_tqe_next) +#define SMR_TAILQ_LAST_LOCKED(head, headname) \ + (*(((struct headname *)((head)->smr_tqh_last))->smr_tqh_last)) +#define SMR_TAILQ_EMPTY_LOCKED(head) \ + (SMR_TAILQ_FIRST_LOCKED(head) == SMR_TAILQ_END(head)) + +#define SMR_TAILQ_FOREACH(var, head, field) \ + for((var) = SMR_TAILQ_FIRST(head); \ + (var)!= SMR_TAILQ_END(head); \ + (var) = SMR_TAILQ_NEXT(var, field)) + +#define SMR_TAILQ_FOREACH_LOCKED(var, head, field) \ + for((var) = SMR_TAILQ_FIRST_LOCKED(head); \ + (var)!= SMR_TAILQ_END(head); \ + (var) = SMR_TAILQ_NEXT_LOCKED(var, field)) + +#define SMR_TAILQ_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_TAILQ_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_TAILQ_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * Tail queue functions. + */ +#define SMR_TAILQ_INIT(head) do { \ + (head)->smr_tqh_first = TAILQ_END(head); \ + (head)->smr_tqh_last = &(head)->smr_tqh_first; \ +} while (0) + +#define SMR_TAILQ_INSERT_AFTER_LOCKED(head, listelm, elm, field) do { \ + (elm)->field.smr_tqe_next = (listelm)->field.smr_tqe_next; \ + if ((listelm)->field.smr_tqe_next != NULL) \ + (listelm)->field.smr_tqe_next->field.smr_tqe_prev = \ + &(elm)->field.smr_tqe_next; \ + else \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ + (elm)->field.smr_tqe_prev = &(listelm)->field.smr_tqe_next; \ + membar_producer(); \ + (listelm)->field.smr_tqe_next = (elm); \ +} while (0) + +#define SMR_TAILQ_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_tqe_prev = (listelm)->field.smr_tqe_prev; \ + (elm)->field.smr_tqe_next = (listelm); \ + membar_producer(); \ + *(listelm)->field.smr_tqe_prev = (elm); \ + (listelm)->field.smr_tqe_prev = &(elm)->field.smr_tqe_next; \ +} while (0) + +#define SMR_TAILQ_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_tqe_next = (head)->smr_tqh_first; \ + (elm)->field.smr_tqe_prev = &(head)->smr_tqh_first; \ + if ((head)->smr_tqh_first != NULL) \ + (head)->smr_tqh_first->field.smr_tqe_prev = \ + &(elm)->field.smr_tqe_next; \ + else \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ + membar_producer(); \ + (head)->smr_tqh_first = (elm); \ +} while (0) + +#define SMR_TAILQ_INSERT_TAIL_LOCKED(head, elm, field) do { \ + (elm)->field.smr_tqe_next = NULL; \ + (elm)->field.smr_tqe_prev = (head)->smr_tqh_last; \ + membar_producer(); \ + *(head)->smr_tqh_last = (elm); \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ +} while (0) + +#define SMR_TAILQ_REMOVE_LOCKED(head, elm, field) do { \ + if ((elm)->field.smr_tqe_next != NULL) \ + (elm)->field.smr_tqe_next->field.smr_tqe_prev = \ + (elm)->field.smr_tqe_prev; \ + else \ + (head)->smr_tqh_last = (elm)->field.smr_tqe_prev; \ + *(elm)->field.smr_tqe_prev = (elm)->field.smr_tqe_next; \ + /* (elm)->field.smr_tqe_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +#endif /* _KERNEL */ + +#endif /* !_SYS_SMR_ */ diff --git a/sys/sys/socket.h b/sys/sys/socket.h new file mode 100644 index 0000000..927fd26 --- /dev/null +++ b/sys/sys/socket.h @@ -0,0 +1,572 @@ +/* $OpenBSD: socket.h,v 1.98 2019/07/22 15:34:07 robert Exp $ */ +/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ + +/* + * Copyright (c) 1982, 1985, 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. + * + * @(#)socket.h 8.4 (Berkeley) 2/21/94 + */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +/* get the definitions for struct iovec, size_t, ssize_t, and <sys/cdefs.h> */ +#include <sys/uio.h> + +#if __BSD_VISIBLE +#include <sys/types.h> /* for off_t, uid_t, and gid_t */ +#endif + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef __sa_family_t sa_family_t; /* sockaddr address family type */ +#endif + + +/* + * Definitions related to sockets: types, address families, options. + */ + +/* + * Types + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#define SOCK_RDM 4 /* reliably-delivered message */ +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ +#ifdef _KERNEL +#define SOCK_TYPE_MASK 0x000F /* mask that covers the above */ +#endif + +/* + * Socket creation flags + */ +#if __BSD_VISIBLE +#define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */ +#define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */ +#ifdef _KERNEL +#define SOCK_NONBLOCK_INHERIT 0x2000 /* inherit O_NONBLOCK from listener */ +#endif +#define SOCK_DNS 0x1000 /* set SS_DNS */ +#endif /* __BSD_VISIBLE */ + +/* + * Option flags per-socket. + */ +#define SO_DEBUG 0x0001 /* turn on debugging info recording */ +#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define SO_REUSEADDR 0x0004 /* allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_DONTROUTE 0x0010 /* just use interface addresses */ +#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ +#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ +#define SO_LINGER 0x0080 /* linger on close if data present */ +#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ +#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ +#define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */ +#define SO_BINDANY 0x1000 /* allow bind to any address */ +#define SO_ZEROIZE 0x2000 /* zero out all mbufs sent over socket */ + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#define SO_NETPROC 0x1020 /* multiplex; network processing */ +#define SO_RTABLE 0x1021 /* routing table to be used */ +#define SO_PEERCRED 0x1022 /* get connect-time credentials */ +#define SO_SPLICE 0x1023 /* splice data to other socket */ +#define SO_DOMAIN 0x1024 /* get socket domain */ +#define SO_PROTOCOL 0x1025 /* get socket protocol */ + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time */ +}; + +#if __BSD_VISIBLE + +#ifndef _TIMEVAL_DECLARED +#define _TIMEVAL_DECLARED +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +#endif + +/* + * Structure used for manipulating splice option. + */ +struct splice { + int sp_fd; /* drain socket file descriptor */ + off_t sp_max; /* if set, maximum bytes to splice */ + struct timeval sp_idle; /* idle timeout */ +}; + +/* + * Maximum number of alternate routing tables + */ +#define RT_TABLEID_MAX 255 +#define RT_TABLEID_BITS 8 +#define RT_TABLEID_MASK 0xff + +#endif /* __BSD_VISIBLE */ + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xffff /* options for socket level */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#define AF_UNIX 1 /* local to host */ +#define AF_LOCAL AF_UNIX /* draft POSIX compatibility */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NS 6 /* XEROX NS protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* european computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_INET6 24 /* IPv6 */ +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define AF_NATM 27 /* native ATM access */ +#define AF_ENCAP 28 +#define AF_SIP 29 /* Simple Internet Protocol */ +#define AF_KEY 30 +#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers + in interface output routine */ +#define AF_BLUETOOTH 32 /* Bluetooth */ +#define AF_MPLS 33 /* MPLS */ +#define pseudo_AF_PFLOW 34 /* pflow */ +#define pseudo_AF_PIPEX 35 /* PIPEX */ +#define AF_MAX 36 + +/* + * Structure used by kernel to store most + * addresses. + */ +struct sockaddr { + __uint8_t sa_len; /* total length */ + sa_family_t sa_family; /* address family */ + char sa_data[14]; /* actually longer; address value */ +}; + +/* + * Sockaddr type which can hold any sockaddr type available + * in the system. + * + * Note: __ss_{len,family} is defined in RFC2553. During RFC2553 discussion + * the field name went back and forth between ss_len and __ss_len, + * and RFC2553 specifies it to be __ss_len. openbsd picked ss_len. + * For maximum portability, userland programmer would need to + * (1) make the code never touch ss_len portion (cast it into sockaddr and + * touch sa_len), or (2) add "-Dss_len=__ss_len" into CFLAGS to unify all + * occurrences (including header file) to __ss_len. + */ +struct sockaddr_storage { + __uint8_t ss_len; /* total length */ + sa_family_t ss_family; /* address family */ + unsigned char __ss_pad1[6]; /* align to quad */ + __uint64_t __ss_pad2; /* force alignment for stupid compilers */ + unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */ +}; + +#ifdef _KERNEL +/* + * Structure used by kernel to pass protocol + * information in raw sockets. + */ +struct sockproto { + unsigned short sp_family; /* address family */ + unsigned short sp_protocol; /* protocol */ +}; +#endif /* _KERNEL */ + +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX AF_UNIX +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NS AF_NS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_IPX AF_IPX /* same format as AF_NS */ +#define PF_INET6 AF_INET6 +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#define PF_ISDN AF_ISDN +#define PF_NATM AF_NATM +#define PF_ENCAP AF_ENCAP +#define PF_SIP AF_SIP +#define PF_KEY AF_KEY +#define PF_BPF pseudo_AF_HDRCMPLT +#define PF_BLUETOOTH AF_BLUETOOTH +#define PF_MPLS AF_MPLS +#define PF_PFLOW pseudo_AF_PFLOW +#define PF_PIPEX pseudo_AF_PIPEX +#define PF_MAX AF_MAX + +/* + * These are the valid values for the "how" field used by shutdown(2). + */ +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 + +#if __BSD_VISIBLE +#define SA_LEN(x) ((x)->sa_len) + +/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */ +struct sockpeercred { + uid_t uid; /* effective user id */ + gid_t gid; /* effective group id */ + pid_t pid; +}; + +/* + * Definitions for network related sysctl, CTL_NET. + * + * Second level is protocol family. + * Third level is protocol number. + * + * Further levels are defined by the individual families below. + */ +#define NET_MAXID AF_MAX + +#define CTL_NET_NAMES { \ + { 0, 0 }, \ + { "unix", CTLTYPE_NODE }, \ + { "inet", CTLTYPE_NODE }, \ + { "implink", CTLTYPE_NODE }, \ + { "pup", CTLTYPE_NODE }, \ + { "chaos", CTLTYPE_NODE }, \ + { "xerox_ns", CTLTYPE_NODE }, \ + { "iso", CTLTYPE_NODE }, \ + { "emca", CTLTYPE_NODE }, \ + { "datakit", CTLTYPE_NODE }, \ + { "ccitt", CTLTYPE_NODE }, \ + { "ibm_sna", CTLTYPE_NODE }, \ + { "decnet", CTLTYPE_NODE }, \ + { "dec_dli", CTLTYPE_NODE }, \ + { "lat", CTLTYPE_NODE }, \ + { "hylink", CTLTYPE_NODE }, \ + { "appletalk", CTLTYPE_NODE }, \ + { "route", CTLTYPE_NODE }, \ + { "link", CTLTYPE_NODE }, \ + { "xtp", CTLTYPE_NODE }, \ + { "coip", CTLTYPE_NODE }, \ + { "cnt", CTLTYPE_NODE }, \ + { "rtip", CTLTYPE_NODE }, \ + { "ipx", CTLTYPE_NODE }, \ + { "inet6", CTLTYPE_NODE }, \ + { "pip", CTLTYPE_NODE }, \ + { "isdn", CTLTYPE_NODE }, \ + { "natm", CTLTYPE_NODE }, \ + { "encap", CTLTYPE_NODE }, \ + { "sip", CTLTYPE_NODE }, \ + { "key", CTLTYPE_NODE }, \ + { "bpf", CTLTYPE_NODE }, \ + { "bluetooth", CTLTYPE_NODE }, \ + { "mpls", CTLTYPE_NODE }, \ + { "pflow", CTLTYPE_NODE }, \ + { "pipex", CTLTYPE_NODE }, \ +} + +/* + * PF_ROUTE - Routing table + * + * Four additional levels are defined: + * Fourth: address family, 0 is wildcard + * Fifth: type of info, defined below + * Sixth: flag(s) to mask with for NET_RT_FLAGS + * Seventh: routing table to use (facultative, defaults to 0) + * NET_RT_TABLE has the table id as sixth element. + */ +#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ +#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ +#define NET_RT_IFLIST 3 /* survey interface list */ +#define NET_RT_STATS 4 /* routing table statistics */ +#define NET_RT_TABLE 5 +#define NET_RT_IFNAMES 6 +#define NET_RT_MAXID 7 + +#define CTL_NET_RT_NAMES { \ + { 0, 0 }, \ + { "dump", CTLTYPE_STRUCT }, \ + { "flags", CTLTYPE_STRUCT }, \ + { "iflist", CTLTYPE_STRUCT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { "table", CTLTYPE_STRUCT }, \ + { "ifnames", CTLTYPE_STRUCT }, \ +} + +/* + * PF_LINK - link layer or device tunables + */ +#define NET_LINK_IFRXQ 1 /* net.link.ifrxq */ +#define NET_LINK_MAXID 2 + +#define CTL_NET_LINK_NAMES { \ + { 0, 0 }, \ + { "ifrxq", CTLTYPE_NODE }, \ +} + +#define NET_LINK_IFRXQ_PRESSURE_RETURN \ + 1 /* net.link.ifrxq.pressure_return */ +#define NET_LINK_IFRXQ_PRESSURE_DROP \ + 2 /* net.link.ifrxq.pressure_drop */ +#define NET_LINK_IFRXQ_MAXID 3 + +#define CTL_NET_LINK_IFRXQ_NAMES { \ + { 0, 0 }, \ + { "pressure_return", CTLTYPE_INT }, \ + { "pressure_drop", CTLTYPE_INT }, \ +} + +/* + * PF_KEY - Key Management + */ +#define NET_KEY_SADB_DUMP 1 /* return SADB */ +#define NET_KEY_SPD_DUMP 2 /* return SPD */ +#define NET_KEY_MAXID 3 + +#define CTL_NET_KEY_NAMES { \ + { 0, 0 }, \ + { "sadb_dump", CTLTYPE_STRUCT }, \ + { "spd_dump", CTLTYPE_STRUCT }, \ +} + +/* + * PF_BPF not really a family, but connected under CTL_NET + */ +#define NET_BPF_BUFSIZE 1 /* default buffer size */ +#define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */ +#define NET_BPF_MAXID 3 + +#define CTL_NET_BPF_NAMES { \ + { 0, 0 }, \ + { "bufsize", CTLTYPE_INT }, \ + { "maxbufsize", CTLTYPE_INT }, \ +} + +/* + * PF_PFLOW not really a family, but connected under CTL_NET + */ +#define NET_PFLOW_STATS 1 /* statistics */ +#define NET_PFLOW_MAXID 2 + +#define CTL_NET_PFLOW_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_STRUCT }, \ +} +#endif /* __BSD_VISIBLE */ + +/* + * Maximum queue length specifiable by listen(2). + */ +#define SOMAXCONN 128 + +/* + * Message header for recvmsg and sendmsg calls. + * Used value-result for recvmsg, value only for sendmsg. + */ +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + unsigned int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; + +#define MSG_OOB 0x1 /* process out-of-band data */ +#define MSG_PEEK 0x2 /* peek at incoming message */ +#define MSG_DONTROUTE 0x4 /* send without using routing tables */ +#define MSG_EOR 0x8 /* data completes record */ +#define MSG_TRUNC 0x10 /* data discarded before delivery */ +#define MSG_CTRUNC 0x20 /* control data lost before delivery */ +#define MSG_WAITALL 0x40 /* wait for full request or error */ +#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ +#define MSG_BCAST 0x100 /* this message rec'd as broadcast */ +#define MSG_MCAST 0x200 /* this message rec'd as multicast */ +#define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */ +#define MSG_CMSG_CLOEXEC 0x800 /* set FD_CLOEXEC on received fds */ + +/* + * Header for ancillary data objects in msg_control buffer. + * Used for additional information with/about a datagram + * not expressible by flags. The format is a sequence + * of message elements headed by cmsghdr structures. + */ +struct cmsghdr { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; + +/* given pointer to struct cmsghdr, return pointer to data */ +#define CMSG_DATA(cmsg) \ + ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr))) + +/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ +#define CMSG_NXTHDR(mhdr, cmsg) \ + (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \ + _ALIGN(sizeof(struct cmsghdr)) > \ + ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len))) + +/* + * RFC 2292 requires to check msg_controllen, in case that the kernel returns + * an empty list for some reasons. + */ +#define CMSG_FIRSTHDR(mhdr) \ + ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL) + +/* Round len up to next alignment boundary */ +#ifdef _KERNEL +#define CMSG_ALIGN(n) _ALIGN(n) +#endif + +/* Length of the contents of a control message of length len */ +#define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len)) + +/* Length of the space taken up by a padded control message of length len */ +#define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len)) + +/* "Socket"-level control message types: */ +#define SCM_RIGHTS 0x01 /* access rights (array of int) */ +#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */ + +#ifndef _KERNEL + +__BEGIN_DECLS +int accept(int, struct sockaddr *, socklen_t *); +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +int getpeername(int, struct sockaddr *, socklen_t *); +int getsockname(int, struct sockaddr *, socklen_t *); +int getsockopt(int, int, int, void *, socklen_t *); +int listen(int, int); +ssize_t recv(int, void *, size_t, int); +ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); +ssize_t recvmsg(int, struct msghdr *, int); +ssize_t send(int, const void *, size_t, int); +ssize_t sendto(int, const void *, + size_t, int, const struct sockaddr *, socklen_t); +ssize_t sendmsg(int, const struct msghdr *, int); +int setsockopt(int, int, int, const void *, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int *); + +#if __BSD_VISIBLE +int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); +#endif + +#if __BSD_VISIBLE +int getpeereid(int, uid_t *, gid_t *); +int getrtable(void); +int setrtable(int); +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#else + +void pfctlinput(int, struct sockaddr *); + +static inline struct sockaddr * +sstosa(struct sockaddr_storage *ss) +{ + return ((struct sockaddr *)(ss)); +} + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SOCKET_H_ */ diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h new file mode 100644 index 0000000..abcf20e --- /dev/null +++ b/sys/sys/socketvar.h @@ -0,0 +1,365 @@ +/* $OpenBSD: socketvar.h,v 1.91 2020/01/15 13:17:35 mpi Exp $ */ +/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.1 (Berkeley) 6/2/93 + */ + +#include <sys/selinfo.h> /* for struct selinfo */ +#include <sys/queue.h> +#include <sys/sigio.h> /* for struct sigio_ref */ +#include <sys/task.h> +#include <sys/timeout.h> + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +TAILQ_HEAD(soqhead, socket); + +/* + * Kernel structure per socket. + * Contains send and receive buffer queues, + * handle on protocol and pointer to protocol + * private data and error information. + */ +struct socket { + const struct protosw *so_proto; /* protocol handle */ + void *so_pcb; /* protocol control block */ + u_int so_state; /* internal state flags SS_*, below */ + short so_type; /* generic type, see socket.h */ + short so_options; /* from socket call, see socket.h */ + short so_linger; /* time to linger while closing */ +/* + * Variables for connection queueing. + * Socket where accepts occur is so_head in all subsidiary sockets. + * If so_head is 0, socket is not related to an accept. + * For head socket so_q0 queues partially completed connections, + * while so_q is a queue of connections ready to be accepted. + * If a connection is aborted and it has so_head set, then + * it has to be pulled out of either so_q0 or so_q. + * We allow connections to queue up based on current queue lengths + * and limit on number of queued connections for this socket. + */ + struct socket *so_head; /* back pointer to accept socket */ + struct soqhead *so_onq; /* queue (q or q0) that we're on */ + struct soqhead so_q0; /* queue of partial connections */ + struct soqhead so_q; /* queue of incoming connections */ + struct sigio_ref so_sigio; /* async I/O registration */ + TAILQ_ENTRY(socket) so_qe; /* our queue entry (q or q0) */ + short so_q0len; /* partials on so_q0 */ + short so_qlen; /* number of connections on so_q */ + short so_qlimit; /* max number queued connections */ + short so_timeo; /* connection timeout */ + u_long so_oobmark; /* chars to oob mark */ + u_int so_error; /* error affecting connection */ +/* + * Variables for socket splicing, allocated only when needed. + */ + struct sosplice { + struct socket *ssp_socket; /* send data to drain socket */ + struct socket *ssp_soback; /* back ref to source socket */ + off_t ssp_len; /* number of bytes spliced */ + off_t ssp_max; /* maximum number of bytes */ + struct timeval ssp_idletv; /* idle timeout */ + struct timeout ssp_idleto; + struct task ssp_task; /* task for somove */ + } *so_sp; +/* + * Variables for socket buffering. + */ + struct sockbuf { +/* The following fields are all zeroed on flush. */ +#define sb_startzero sb_cc + u_long sb_cc; /* actual chars in buffer */ + u_long sb_datacc; /* data only chars in buffer */ + u_long sb_hiwat; /* max actual char count */ + u_long sb_wat; /* default watermark */ + u_long sb_mbcnt; /* chars of mbufs used */ + u_long sb_mbmax; /* max chars of mbufs to use */ + long sb_lowat; /* low water mark */ + struct mbuf *sb_mb; /* the mbuf chain */ + struct mbuf *sb_mbtail; /* the last mbuf in the chain */ + struct mbuf *sb_lastrecord;/* first mbuf of last record in + socket buffer */ + short sb_flags; /* flags, see below */ +/* End area that is zeroed on flush. */ +#define sb_endzero sb_flags + int sb_flagsintr; /* flags, changed atomically */ + uint64_t sb_timeo_nsecs;/* timeout for read/write */ + struct selinfo sb_sel; /* process selecting read/write */ + } so_rcv, so_snd; +#define SB_MAX (2*1024*1024) /* default for max chars in sockbuf */ +#define SB_LOCK 0x01 /* lock on data queue */ +#define SB_WANT 0x02 /* someone is waiting to lock */ +#define SB_WAIT 0x04 /* someone is waiting for data/space */ +#define SB_SEL 0x08 /* someone is selecting */ +#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ +#define SB_SPLICE 0x20 /* buffer is splice source or drain */ +#define SB_NOINTR 0x40 /* operations not interruptible */ +#define SB_KNOTE 0x80 /* kernel note attached */ + + void (*so_upcall)(struct socket *so, caddr_t arg, int waitf); + caddr_t so_upcallarg; /* Arg for above */ + uid_t so_euid, so_ruid; /* who opened the socket */ + gid_t so_egid, so_rgid; + pid_t so_cpid; /* pid of process that opened socket */ +}; + +/* + * Socket state bits. + */ +#define SS_NOFDREF 0x001 /* no file table ref any more */ +#define SS_ISCONNECTED 0x002 /* socket connected to a peer */ +#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */ +#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */ +#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */ +#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */ +#define SS_RCVATMARK 0x040 /* at mark on input */ +#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */ + +#define SS_PRIV 0x080 /* privileged for broadcast, raw... */ +#define SS_ASYNC 0x200 /* async i/o notify */ +#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */ +#define SS_ISSENDING 0x2000 /* hint for lower layer */ +#define SS_DNS 0x4000 /* created using SOCK_DNS socket(2) */ + +#ifdef _KERNEL + +#include <lib/libkern/libkern.h> + +/* + * Values for sounlock()/sofree(). + */ +#define SL_NOUNLOCK 0x00 +#define SL_LOCKED 0x42 + +void soassertlocked(struct socket *); + +/* + * Macros for sockets and socket buffering. + */ + +#define isspliced(so) ((so)->so_sp && (so)->so_sp->ssp_socket) +#define issplicedback(so) ((so)->so_sp && (so)->so_sp->ssp_soback) + +/* + * Do we need to notify the other side when I/O is possible? + */ +static inline int +sb_notify(struct socket *so, struct sockbuf *sb) +{ + int flags = (sb->sb_flags | sb->sb_flagsintr); + + KASSERT(sb == &so->so_rcv || sb == &so->so_snd); + soassertlocked(so); + return ((flags & (SB_WAIT|SB_SEL|SB_ASYNC|SB_SPLICE|SB_KNOTE)) != 0); +} + +/* + * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? + * This is problematical if the fields are unsigned, as the space might + * still be negative (cc > hiwat or mbcnt > mbmax). Should detect + * overflow and return 0. + */ +static inline long +sbspace(struct socket *so, struct sockbuf *sb) +{ + KASSERT(sb == &so->so_rcv || sb == &so->so_snd); + soassertlocked(so); + return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt); +} + +/* do we have to send all at once on a socket? */ +#define sosendallatonce(so) \ + ((so)->so_proto->pr_flags & PR_ATOMIC) + +/* are we sending on this socket? */ +#define soissending(so) \ + ((so)->so_state & SS_ISSENDING) + +/* can we read something from so? */ +static inline int +soreadable(struct socket *so) +{ + soassertlocked(so); + if (isspliced(so)) + return 0; + return (so->so_state & SS_CANTRCVMORE) || so->so_qlen || so->so_error || + so->so_rcv.sb_cc >= so->so_rcv.sb_lowat; +} + +/* can we write something to so? */ +#define sowriteable(so) \ + ((sbspace((so), &(so)->so_snd) >= (so)->so_snd.sb_lowat && \ + (((so)->so_state & SS_ISCONNECTED) || \ + ((so)->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || \ + ((so)->so_state & SS_CANTSENDMORE) || (so)->so_error) + +/* adjust counters in sb reflecting allocation of m */ +#define sballoc(sb, m) do { \ + (sb)->sb_cc += (m)->m_len; \ + if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ + (sb)->sb_datacc += (m)->m_len; \ + (sb)->sb_mbcnt += MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ +} while (/* CONSTCOND */ 0) + +/* adjust counters in sb reflecting freeing of m */ +#define sbfree(sb, m) do { \ + (sb)->sb_cc -= (m)->m_len; \ + if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ + (sb)->sb_datacc -= (m)->m_len; \ + (sb)->sb_mbcnt -= MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ +} while (/* CONSTCOND */ 0) + +/* + * Set lock on sockbuf sb; sleep if lock is already held. + * Unless SB_NOINTR is set on sockbuf, sleep is interruptible. + * Returns error without lock if sleep is interrupted. + */ +int sblock(struct socket *, struct sockbuf *, int); + +/* release lock on sockbuf sb */ +void sbunlock(struct socket *, struct sockbuf *); + +#define SB_EMPTY_FIXUP(sb) do { \ + if ((sb)->sb_mb == NULL) { \ + (sb)->sb_mbtail = NULL; \ + (sb)->sb_lastrecord = NULL; \ + } \ +} while (/*CONSTCOND*/0) + +extern u_long sb_max; + +extern struct pool socket_pool; + +struct mbuf; +struct sockaddr; +struct proc; +struct msghdr; +struct stat; +struct knote; + +/* + * File operations on sockets. + */ +int soo_read(struct file *, struct uio *, int); +int soo_write(struct file *, struct uio *, int); +int soo_ioctl(struct file *, u_long, caddr_t, struct proc *); +int soo_poll(struct file *, int events, struct proc *); +int soo_kqfilter(struct file *, struct knote *); +int soo_close(struct file *, struct proc *); +int soo_stat(struct file *, struct stat *, struct proc *); +void sbappend(struct socket *, struct sockbuf *, struct mbuf *); +void sbappendstream(struct socket *, struct sockbuf *, struct mbuf *); +int sbappendaddr(struct socket *, struct sockbuf *, + const struct sockaddr *, struct mbuf *, struct mbuf *); +int sbappendcontrol(struct socket *, struct sockbuf *, struct mbuf *, + struct mbuf *); +void sbappendrecord(struct socket *, struct sockbuf *, struct mbuf *); +void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n); +struct mbuf * + sbcreatecontrol(const void *, size_t, int type, int level); +void sbdrop(struct socket *, struct sockbuf *, int); +void sbdroprecord(struct sockbuf *sb); +void sbflush(struct socket *, struct sockbuf *); +void sbinsertoob(struct sockbuf *sb, struct mbuf *m0); +void sbrelease(struct socket *, struct sockbuf *); +int sbcheckreserve(u_long cnt, u_long defcnt); +int sbchecklowmem(void); +int sbreserve(struct socket *, struct sockbuf *, u_long); +int sbwait(struct socket *, struct sockbuf *sb); +int sb_lock(struct sockbuf *sb); +void soinit(void); +int soabort(struct socket *so); +int soaccept(struct socket *so, struct mbuf *nam); +int sobind(struct socket *so, struct mbuf *nam, struct proc *p); +void socantrcvmore(struct socket *so); +void socantsendmore(struct socket *so); +int soclose(struct socket *, int); +int soconnect(struct socket *so, struct mbuf *nam); +int soconnect2(struct socket *so1, struct socket *so2); +int socreate(int dom, struct socket **aso, int type, int proto); +int sodisconnect(struct socket *so); +void sofree(struct socket *so, int); +int sogetopt(struct socket *so, int level, int optname, struct mbuf *m); +void sohasoutofband(struct socket *so); +void soisconnected(struct socket *so); +void soisconnecting(struct socket *so); +void soisdisconnected(struct socket *so); +void soisdisconnecting(struct socket *so); +int solisten(struct socket *so, int backlog); +struct socket *sonewconn(struct socket *head, int connstatus); +void soqinsque(struct socket *head, struct socket *so, int q); +int soqremque(struct socket *so, int q); +int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, + struct mbuf **mp0, struct mbuf **controlp, int *flagsp, + socklen_t controllen); +int soreserve(struct socket *so, u_long sndcc, u_long rcvcc); +void sorflush(struct socket *so); +int sosend(struct socket *so, struct mbuf *addr, struct uio *uio, + struct mbuf *top, struct mbuf *control, int flags); +int sosetopt(struct socket *so, int level, int optname, struct mbuf *m); +int soshutdown(struct socket *so, int how); +void sowakeup(struct socket *so, struct sockbuf *sb); +void sorwakeup(struct socket *); +void sowwakeup(struct socket *); +int sockargs(struct mbuf **, const void *, size_t, int); + +int sosleep_nsec(struct socket *, void *, int, const char *, uint64_t); +int solock(struct socket *); +void sounlock(struct socket *, int); + +int sendit(struct proc *, int, struct msghdr *, int, register_t *); +int recvit(struct proc *, int, struct msghdr *, caddr_t, + register_t *); +int doaccept(struct proc *, int, struct sockaddr *, socklen_t *, int, + register_t *); + +#ifdef SOCKBUF_DEBUG +void sblastrecordchk(struct sockbuf *, const char *); +#define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where)) + +void sblastmbufchk(struct sockbuf *, const char *); +#define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where)) +void sbcheck(struct sockbuf *sb); +#define SBCHECK(sb) sbcheck(sb) +#else +#define SBLASTRECORDCHK(sb, where) /* nothing */ +#define SBLASTMBUFCHK(sb, where) /* nothing */ +#define SBCHECK(sb) /* nothing */ +#endif /* SOCKBUF_DEBUG */ + +#endif /* _KERNEL */ diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h new file mode 100644 index 0000000..1198dd8 --- /dev/null +++ b/sys/sys/sockio.h @@ -0,0 +1,230 @@ +/* $OpenBSD: sockio.h,v 1.83 2019/11/13 11:54:01 tobhe Exp $ */ +/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej 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. + * + * @(#)sockio.h 8.1 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_SOCKIO_H_ +#define _SYS_SOCKIO_H_ + +#include <sys/ioccom.h> + +/* Socket ioctl's. */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ +#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ + +#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ +#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ +#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ +#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ +#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ +#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ +#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ +#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ +#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ +#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ +#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ +#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ +#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ +#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ +#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ +#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */ +#define SIOCSIFLLADDR _IOW('i', 31, struct ifreq) /* set link level addr */ + +#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ +#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ +#define SIOCGETVIFCNT _IOWR('u', 51, struct sioc_vif_req)/* vif pkt cnt */ +#define SIOCGETSGCNT _IOWR('u', 52, struct sioc_sg_req) /* sg pkt cnt */ + +/* 53 and 54 used to be SIOC[SG]IFMEDIA with a 32 bit media word */ +#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ +#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ +#define SIOCGIFSFFPAGE _IOWR('i', 57, struct if_sffpage) /* get SFF page */ + +#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */ +#define SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) /* set gif addrs */ +#define SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) /* get gif addrs */ + +#define SIOCBRDGADD _IOW('i', 60, struct ifbreq) /* add bridge ifs */ +#define SIOCBRDGDEL _IOW('i', 61, struct ifbreq) /* del bridge ifs */ +#define SIOCBRDGGIFFLGS _IOWR('i', 62, struct ifbreq) /* get brdg if flags */ +#define SIOCBRDGSIFFLGS _IOW('i', 63, struct ifbreq) /* set brdg if flags */ +#define SIOCBRDGSCACHE _IOW('i', 64, struct ifbrparam)/* set cache size */ +#define SIOCBRDGGCACHE _IOWR('i', 65, struct ifbrparam)/* get cache size */ +#define SIOCBRDGADDS _IOW('i', 65, struct ifbreq) /* add span port */ +#define SIOCBRDGIFS _IOWR('i', 66, struct ifbreq) /* get member ifs */ +#define SIOCBRDGDELS _IOW('i', 66, struct ifbreq) /* del span port */ +#define SIOCBRDGRTS _IOWR('i', 67, struct ifbaconf) /* get addresses */ +#define SIOCBRDGSADDR _IOWR('i', 68, struct ifbareq) /* set addr flags */ +#define SIOCBRDGSTO _IOW('i', 69, struct ifbrparam)/* cache timeout */ +#define SIOCBRDGGTO _IOWR('i', 70, struct ifbrparam)/* cache timeout */ +#define SIOCBRDGDADDR _IOW('i', 71, struct ifbareq) /* delete addr */ +#define SIOCBRDGFLUSH _IOW('i', 72, struct ifbreq) /* flush addr cache */ +#define SIOCBRDGADDL _IOW('i', 73, struct ifbreq) /* add local port */ +#define SIOCBRDGSIFPROT _IOW('i', 74, struct ifbreq) /* set protected grp */ + +#define SIOCBRDGARL _IOW('i', 77, struct ifbrlreq) /* add bridge rule */ +#define SIOCBRDGFRL _IOW('i', 78, struct ifbrlreq) /* flush brdg rules */ +#define SIOCBRDGGRL _IOWR('i', 79, struct ifbrlconf)/* get bridge rules */ +#define SIOCBRDGGPRI _IOWR('i', 80, struct ifbrparam)/* get priority */ +#define SIOCBRDGSPRI _IOW('i', 80, struct ifbrparam)/* set priority */ +#define SIOCBRDGGHT _IOWR('i', 81, struct ifbrparam)/* get hello time */ +#define SIOCBRDGSHT _IOW('i', 81, struct ifbrparam)/* set hello time */ +#define SIOCBRDGGFD _IOWR('i', 82, struct ifbrparam)/* get forward delay */ +#define SIOCBRDGSFD _IOW('i', 82, struct ifbrparam)/* set forward delay */ +#define SIOCBRDGGMA _IOWR('i', 83, struct ifbrparam)/* get max age */ +#define SIOCBRDGSMA _IOW('i', 83, struct ifbrparam)/* set max age */ +#define SIOCBRDGSIFPRIO _IOW('i', 84, struct ifbreq) /* set if priority */ +#define SIOCBRDGSIFCOST _IOW('i', 85, struct ifbreq) /* set if cost */ + +#define SIOCBRDGGPARAM _IOWR('i', 88, struct ifbropreq)/* get brdg STP parms */ +#define SIOCBRDGSTXHC _IOW('i', 89, struct ifbrparam)/* set tx hold count */ +#define SIOCBRDGSPROTO _IOW('i', 90, struct ifbrparam)/* set protocol */ +#define SIOCBRDGS + +#define SIOCSWGDPID _IOWR('i', 91, struct ifbrparam)/* get datapath id */ +#define SIOCSWSDPID _IOW('i', 92, struct ifbrparam)/* set datapath id */ +#define SIOCSWGMAXGROUP _IOWR('i', 93, struct ifbrparam)/* get max groups */ +#define SIOCSWSPORTNO _IOWR('i', 95, struct ifbreq) /* set port number */ +#define SIOCSWGMAXFLOW _IOWR('i', 96, struct ifbrparam)/* get max flow per table */ + +#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet mtu */ +#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet mtu */ + +#define SIOCIFCREATE _IOW('i', 122, struct ifreq) /* create clone if */ +#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */ +#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */ + +#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */ +#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */ +#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */ +#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */ +#define SIOCGIFGATTR _IOWR('i', 139, struct ifgroupreq) /* get ifgroup attribs */ +#define SIOCSIFGATTR _IOW('i', 140, struct ifgroupreq) /* set ifgroup attribs */ +#define SIOCGIFGLIST _IOWR('i', 141, struct ifgroupreq) /* get ifgroup list */ + +#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */ +#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */ + +#define SIOCSIFRTLABEL _IOW('i', 130, struct ifreq) /* set ifnet rtlabel */ +#define SIOCGIFRTLABEL _IOWR('i', 131, struct ifreq) /* set ifnet rtlabel */ + +#define SIOCSETVLAN _IOW('i', 143, struct ifreq) /* set vlan parent if */ +#define SIOCGETVLAN _IOWR('i', 144, struct ifreq) /* get vlan parent if */ + +#define SIOCSSPPPPARAMS _IOW('i', 147, struct ifreq) /* set pppoe params */ +#define SIOCGSPPPPARAMS _IOWR('i', 148, struct ifreq) /* get pppoe params */ + +#define SIOCDELLABEL _IOW('i', 151, struct ifreq) /* del MPLS label */ +#define SIOCGPWE3 _IOWR('i', 152, struct ifreq) /* get MPLS PWE3 cap */ +#define SIOCSETLABEL _IOW('i', 153, struct ifreq) /* set MPLS label */ +#define SIOCGETLABEL _IOW('i', 154, struct ifreq) /* get MPLS label */ + +#define SIOCSIFPRIORITY _IOW('i', 155, struct ifreq) /* set if priority */ +#define SIOCGIFPRIORITY _IOWR('i', 156, struct ifreq) /* get if priority */ + +#define SIOCSIFXFLAGS _IOW('i', 157, struct ifreq) /* set ifnet xflags */ +#define SIOCGIFXFLAGS _IOWR('i', 158, struct ifreq) /* get ifnet xflags */ + +#define SIOCSIFRDOMAIN _IOW('i', 159, struct ifreq) /* set ifnet VRF id */ +#define SIOCGIFRDOMAIN _IOWR('i', 160, struct ifreq) /* get ifnet VRF id */ + +#define SIOCSLIFPHYRTABLE _IOW('i', 161, struct ifreq) /* set tunnel VRF id */ +#define SIOCGLIFPHYRTABLE _IOWR('i', 162, struct ifreq) /* get tunnel VRF id */ + +#define SIOCSETKALIVE _IOW('i', 163, struct ifkalivereq) +#define SIOCGETKALIVE _IOWR('i', 164, struct ifkalivereq) + +#define SIOCGIFHARDMTU _IOWR('i', 165, struct ifreq) /* get ifnet hardmtu */ + +#define SIOCSVNETID _IOW('i', 166, struct ifreq) /* set virt net id */ +#define SIOCGVNETID _IOWR('i', 167, struct ifreq) /* get virt net id */ + +#define SIOCSLIFPHYTTL _IOW('i', 168, struct ifreq) /* set tunnel ttl */ +#define SIOCGLIFPHYTTL _IOWR('i', 169, struct ifreq) /* get tunnel ttl */ + +#define SIOCGIFRXR _IOW('i', 170, struct ifreq) +#define SIOCIFAFATTACH _IOW('i', 171, struct if_afreq) /* attach given af */ +#define SIOCIFAFDETACH _IOW('i', 172, struct if_afreq) /* detach given af */ + +#define SIOCSETMPWCFG _IOW('i', 173, struct ifreq) /* set mpw config */ +#define SIOCGETMPWCFG _IOWR('i', 174, struct ifreq) /* get mpw config */ + +#define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */ + +#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */ +#define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */ + +#define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */ +#define SIOCGIFPARENT _IOWR('i', 179, struct if_parent) /* get parent if */ +#define SIOCDIFPARENT _IOW('i', 180, struct ifreq) /* del parent if */ + +#define SIOCSIFLLPRIO _IOW('i', 181, struct ifreq) /* set ifnet llprio */ +#define SIOCGIFLLPRIO _IOWR('i', 182, struct ifreq) /* get ifnet llprio */ + +#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */ +#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */ +#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */ + +#define SIOCSLIFPHYDF _IOW('i', 193, struct ifreq) /* set tunnel df/nodf */ +#define SIOCGLIFPHYDF _IOWR('i', 194, struct ifreq) /* set tunnel df/nodf */ + +#define SIOCSVNETFLOWID _IOW('i', 195, struct ifreq) /* set vnet flowid */ +#define SIOCGVNETFLOWID _IOWR('i', 196, struct ifreq) /* get vnet flowid */ + +#define SIOCSTXHPRIO _IOW('i', 197, struct ifreq) /* set tx hdr prio */ +#define SIOCGTXHPRIO _IOWR('i', 198, struct ifreq) /* get tx hdr prio */ + +#define SIOCSLIFPHYECN _IOW('i', 199, struct ifreq) /* set ecn copying */ +#define SIOCGLIFPHYECN _IOWR('i', 200, struct ifreq) /* get ecn copying */ + +#define SIOCSRXHPRIO _IOW('i', 219, struct ifreq) /* set rx hdr prio */ +#define SIOCGRXHPRIO _IOWR('i', 219, struct ifreq) /* get rx hdr prio */ + +#define SIOCSPWE3CTRLWORD _IOW('i', 220, struct ifreq) +#define SIOCGPWE3CTRLWORD _IOWR('i', 220, struct ifreq) +#define SIOCSPWE3FAT _IOW('i', 221, struct ifreq) +#define SIOCGPWE3FAT _IOWR('i', 221, struct ifreq) +#define SIOCSPWE3NEIGHBOR _IOW('i', 222, struct if_laddrreq) +#define SIOCGPWE3NEIGHBOR _IOWR('i', 222, struct if_laddrreq) +#define SIOCDPWE3NEIGHBOR _IOW('i', 222, struct ifreq) + +#define SIOCSVH _IOWR('i', 245, struct ifreq) /* set carp param */ +#define SIOCGVH _IOWR('i', 246, struct ifreq) /* get carp param */ + +#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq) +#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) + +#define SIOCSETPFLOW _IOW('i', 253, struct ifreq) +#define SIOCGETPFLOW _IOWR('i', 254, struct ifreq) + +#endif /* !_SYS_SOCKIO_H_ */ diff --git a/sys/sys/specdev.h b/sys/sys/specdev.h new file mode 100644 index 0000000..2570b20 --- /dev/null +++ b/sys/sys/specdev.h @@ -0,0 +1,113 @@ +/* $OpenBSD: specdev.h,v 1.39 2019/12/27 22:17:01 bluhm Exp $ */ +/* $NetBSD: specdev.h,v 1.12 1996/02/13 13:13:01 mycroft 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. + * + * @(#)specdev.h 8.3 (Berkeley) 8/10/94 + */ + +SLIST_HEAD(vnodechain, vnode); + +/* + * This structure defines the information maintained about + * special devices. It is allocated in checkalias and freed + * in vgone. + */ +struct specinfo { + struct vnodechain *si_hashchain; + SLIST_ENTRY(vnode) si_specnext; + struct mount *si_mountpoint; + dev_t si_rdev; + struct lockf_state *si_lockf; + daddr_t si_lastr; + union { + struct vnode *ci_parent; /* pointer back to parent device */ + u_int8_t *ci_bitmap; /* bitmap of devices cloned off us */ + } si_ci; +}; + +struct cloneinfo { + struct vnode *ci_vp; /* cloned vnode */ + void *ci_data; /* original vnode's v_data */ +}; + +/* + * Exported shorthand + */ +#define v_rdev v_specinfo->si_rdev +#define v_hashchain v_specinfo->si_hashchain +#define v_specnext v_specinfo->si_specnext +#define v_specmountpoint v_specinfo->si_mountpoint +#define v_speclockf v_specinfo->si_lockf +#define v_specparent v_specinfo->si_ci.ci_parent +#define v_specbitmap v_specinfo->si_ci.ci_bitmap + +/* + * We use the upper 16 bits of the minor to record the clone instance. + * This gives us 8 bits for encoding the real minor number. + */ +#define CLONE_SHIFT 8 +#define CLONE_MAPSZ 128 + +/* + * Special device management + */ +#define SPECHSZ 64 +#if ((SPECHSZ&(SPECHSZ-1)) == 0) +#define SPECHASH(rdev) (((rdev>>5)+(rdev))&(SPECHSZ-1)) +#else +#define SPECHASH(rdev) (((unsigned)((rdev>>5)+(rdev)))%SPECHSZ) +#endif + +#ifdef _KERNEL + +extern struct vnodechain speclisth[SPECHSZ]; + +/* + * Prototypes for special file operations on vnodes. + */ +int spec_badop(void *); +int spec_getattr(void *); +int spec_setattr(void *); +int spec_access(void *); +int spec_open(void *); +int spec_close(void *); +int spec_read(void *); +int spec_write(void *); +int spec_ioctl(void *); +int spec_poll(void *); +int spec_kqfilter(void *); +int spec_fsync(void *); +int spec_inactive(void *); +int spec_strategy(void *); +int spec_print(void *); +int spec_pathconf(void *); +int spec_advlock(void *); + +#endif /* _KERNEL */ diff --git a/sys/sys/srp.h b/sys/sys/srp.h new file mode 100644 index 0000000..a22e940 --- /dev/null +++ b/sys/sys/srp.h @@ -0,0 +1,190 @@ +/* $OpenBSD: srp.h,v 1.14 2019/03/31 14:03:40 mpi Exp $ */ + +/* + * Copyright (c) 2014 Jonathan Matthew <jmatthew@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_SRP_H_ +#define _SYS_SRP_H_ + +#include <sys/refcnt.h> + +#ifndef __upunused +#ifdef MULTIPROCESSOR +#define __upunused +#else +#define __upunused __attribute__((__unused__)) +#endif +#endif /* __upunused */ + +struct srp { + void *ref; +}; + +#define SRP_INITIALIZER() { NULL } + +struct srp_hazard { + struct srp *sh_p; + void *sh_v; +}; + +struct srp_ref { + struct srp_hazard *hz; +} __upunused; + +#define SRP_HAZARD_NUM 16 + +struct srp_gc { + void (*srp_gc_dtor)(void *, void *); + void *srp_gc_cookie; + struct refcnt srp_gc_refcnt; +}; + +#define SRP_GC_INITIALIZER(_d, _c) { (_d), (_c), REFCNT_INITIALIZER() } + +/* + * singly linked list built by following srps + */ + +struct srpl_rc { + void (*srpl_ref)(void *, void *); + struct srp_gc srpl_gc; +}; +#define srpl_cookie srpl_gc.srp_gc_cookie + +#define SRPL_RC_INITIALIZER(_r, _u, _c) { _r, SRP_GC_INITIALIZER(_u, _c) } + +struct srpl { + struct srp sl_head; +}; + +#define SRPL_HEAD(name, type) struct srpl + +#define SRPL_ENTRY(type) \ +struct { \ + struct srp se_next; \ +} + +#ifdef _KERNEL + +void srp_startup(void); +void srp_gc_init(struct srp_gc *, void (*)(void *, void *), void *); +void *srp_swap_locked(struct srp *, void *); +void srp_update_locked(struct srp_gc *, struct srp *, void *); +void *srp_get_locked(struct srp *); +void srp_gc_finalize(struct srp_gc *); + +void srp_init(struct srp *); + +#ifdef MULTIPROCESSOR +void *srp_swap(struct srp *, void *); +void srp_update(struct srp_gc *, struct srp *, void *); +void srp_finalize(void *, const char *); +void *srp_enter(struct srp_ref *, struct srp *); +void *srp_follow(struct srp_ref *, struct srp *); +void srp_leave(struct srp_ref *); +#else /* MULTIPROCESSOR */ +#define srp_swap(_srp, _v) srp_swap_locked((_srp), (_v)) +#define srp_update(_gc, _srp, _v) srp_update_locked((_gc), (_srp), (_v)) +#define srp_finalize(_v, _wchan) ((void)0) +#define srp_enter(_sr, _srp) ((_srp)->ref) +#define srp_follow(_sr, _srp) ((_srp)->ref) +#define srp_leave(_sr) do { } while (0) +#endif /* MULTIPROCESSOR */ + + +void srpl_rc_init(struct srpl_rc *, void (*)(void *, void *), + void (*)(void *, void *), void *); + +#define SRPL_INIT(_sl) srp_init(&(_sl)->sl_head) + +#define SRPL_FIRST(_sr, _sl) srp_enter((_sr), &(_sl)->sl_head) +#define SRPL_NEXT(_sr, _e, _ENTRY) srp_enter((_sr), &(_e)->_ENTRY.se_next) +#define SRPL_FOLLOW(_sr, _e, _ENTRY) srp_follow((_sr), &(_e)->_ENTRY.se_next) + +#define SRPL_FOREACH(_c, _sr, _sl, _ENTRY) \ + for ((_c) = SRPL_FIRST(_sr, _sl); \ + (_c) != NULL; \ + (_c) = SRPL_FOLLOW(_sr, _c, _ENTRY)) + +#define SRPL_LEAVE(_sr) srp_leave((_sr)) + +#define SRPL_FIRST_LOCKED(_sl) srp_get_locked(&(_sl)->sl_head) +#define SRPL_EMPTY_LOCKED(_sl) (SRPL_FIRST_LOCKED(_sl) == NULL) + +#define SRPL_NEXT_LOCKED(_e, _ENTRY) \ + srp_get_locked(&(_e)->_ENTRY.se_next) + +#define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY) \ + for ((_c) = SRPL_FIRST_LOCKED(_sl); \ + (_c) != NULL; \ + (_c) = SRPL_NEXT_LOCKED((_c), _ENTRY)) + +#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \ + for ((_c) = SRPL_FIRST_LOCKED(_sl); \ + (_c) && ((_tc) = SRPL_NEXT_LOCKED(_c, _ENTRY), 1); \ + (_c) = (_tc)) + +#define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY) do { \ + void *head; \ + \ + srp_init(&(_e)->_ENTRY.se_next); \ + \ + head = SRPL_FIRST_LOCKED(_sl); \ + if (head != NULL) { \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, head); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_e)->_ENTRY.se_next, head); \ + } \ + \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \ + srp_update_locked(&(_rc)->srpl_gc, &(_sl)->sl_head, (_e)); \ +} while (0) + +#define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY) do { \ + void *next; \ + \ + srp_init(&(_e)->_ENTRY.se_next); \ + \ + next = SRPL_NEXT_LOCKED(_se, _ENTRY); \ + if (next != NULL) { \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, next); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_e)->_ENTRY.se_next, next); \ + } \ + \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_se)->_ENTRY.se_next, (_e)); \ +} while (0) + +#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) do { \ + struct srp *ref; \ + struct _type *c, *n; \ + \ + ref = &(_sl)->sl_head; \ + while ((c = srp_get_locked(ref)) != (_e)) \ + ref = &c->_ENTRY.se_next; \ + \ + n = SRPL_NEXT_LOCKED(c, _ENTRY); \ + if (n != NULL) \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, n); \ + srp_update_locked(&(_rc)->srpl_gc, ref, n); \ + srp_update_locked(&(_rc)->srpl_gc, &c->_ENTRY.se_next, NULL); \ +} while (0) + +#endif /* _KERNEL */ + +#endif /* _SYS_SRP_H_ */ diff --git a/sys/sys/stacktrace.h b/sys/sys/stacktrace.h new file mode 100644 index 0000000..5d78b75 --- /dev/null +++ b/sys/sys/stacktrace.h @@ -0,0 +1,40 @@ +/* $OpenBSD: stacktrace.h,v 1.3 2020/04/18 04:45:20 visa Exp $ */ + +/* + * Copyright (c) 2017 Visa Hankala + * + * Permission to use, copy, modify, and/or 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_STACKTRACE_H_ +#define _SYS_STACKTRACE_H_ + +#define STACKTRACE_MAX 19 + +struct stacktrace { + unsigned int st_count; + unsigned long st_pc[STACKTRACE_MAX]; +}; + +#ifdef _KERNEL +void stacktrace_print(struct stacktrace *, int (*)(const char *, ...)); +void stacktrace_save_at(struct stacktrace *, unsigned int); + +static inline void +stacktrace_save(struct stacktrace *st) +{ + stacktrace_save_at(st, 0); +} +#endif + +#endif /* _SYS_STACKTRACE_H_ */ diff --git a/sys/sys/stat.h b/sys/sys/stat.h new file mode 100644 index 0000000..564548f --- /dev/null +++ b/sys/sys/stat.h @@ -0,0 +1,222 @@ +/* $OpenBSD: stat.h,v 1.28 2015/04/04 18:06:08 jca Exp $ */ +/* $NetBSD: stat.h,v 1.20 1996/05/16 22:17:49 cgd 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. + * + * @(#)stat.h 8.9 (Berkeley) 8/17/94 + */ + +#ifndef _SYS_STAT_H_ +#define _SYS_STAT_H_ + +#include <sys/time.h> + +struct stat { + mode_t st_mode; /* inode protection mode */ + dev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + dev_t st_rdev; /* device type */ +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ +#else + time_t st_atime; /* time of last access */ + long st_atimensec; /* nsec of last access */ + time_t st_mtime; /* time of last data modification */ + long st_mtimensec; /* nsec of last data modification */ + time_t st_ctime; /* time of last file status change */ + long st_ctimensec; /* nsec of last file status change */ +#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + u_int32_t st_flags; /* user defined flags for file */ + u_int32_t st_gen; /* file generation number */ +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE + struct timespec __st_birthtim; /* time of file creation */ +#else + time_t __st_birthtime; /* time of file creation */ + long __st_birthtimensec; /* nsec of file creation */ +#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */ +}; +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE +#define st_atime st_atim.tv_sec +#define st_mtime st_mtim.tv_sec +#define st_ctime st_ctim.tv_sec +#define __st_birthtime __st_birthtim.tv_sec +#endif +#if __BSD_VISIBLE +#define st_atimespec st_atim +#define st_atimensec st_atim.tv_nsec +#define st_mtimespec st_mtim +#define st_mtimensec st_mtim.tv_nsec +#define st_ctimespec st_ctim +#define st_ctimensec st_ctim.tv_nsec +#define __st_birthtimespec __st_birthtim +#define __st_birthtimensec __st_birthtim.tv_nsec +#endif + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#if __BSD_VISIBLE +#define S_ISTXT 0001000 /* sticky bit */ +#endif + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#if __BSD_VISIBLE +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#endif + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#if __XPG_VISIBLE || __BSD_VISIBLE +#define S_IFMT 0170000 /* type of file mask */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#endif + +#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ +#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ +#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ +#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ +#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ +#if __POSIX_VISIBLE >= 200112 || __BSD_VISIBLE +#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ +#define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */ +#endif + +#if __POSIX_VISIBLE >= 200809 +/* manadated to be present, but permitted to always return zero */ +#define S_TYPEISMQ(m) 0 +#define S_TYPEISSEM(m) 0 +#define S_TYPEISSHM(m) 0 +#endif + +#if __BSD_VISIBLE +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 00777 */ + /* 07777 */ +#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) + /* 00666 */ +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) + +#define S_BLKSIZE 512 /* block size used in the stat struct */ + +/* + * Definitions of flags stored in file flags word. + * + * Super-user and owner changeable flags. + */ +#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ +#define UF_NODUMP 0x00000001 /* do not dump file */ +#define UF_IMMUTABLE 0x00000002 /* file may not be changed */ +#define UF_APPEND 0x00000004 /* writes to file may only append */ +#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ +/* + * Super-user changeable flags. + */ +#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ +#define SF_ARCHIVED 0x00010000 /* file is archived */ +#define SF_IMMUTABLE 0x00020000 /* file may not be changed */ +#define SF_APPEND 0x00040000 /* writes to file may only append */ + +#ifdef _KERNEL +/* + * Shorthand abbreviations of above. + */ +#define OPAQUE (UF_OPAQUE) +#define APPEND (UF_APPEND | SF_APPEND) +#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) +#endif /* _KERNEL */ +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +#define UTIME_NOW -2L +#define UTIME_OMIT -1L +#endif /* __POSIX_VISIBLE */ + +#ifndef _KERNEL +__BEGIN_DECLS +int chmod(const char *, mode_t); +int fstat(int, struct stat *); +int mknod(const char *, mode_t, dev_t); +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +int stat(const char *, struct stat *); +mode_t umask(mode_t); +#if __POSIX_VISIBLE >= 200112L || __XPG_VISIBLE >= 420 || __BSD_VISIBLE +int fchmod(int, mode_t); +int lstat(const char *, struct stat *); +#endif +#if __POSIX_VISIBLE >= 200809 +int fchmodat(int, const char *, mode_t, int); +int fstatat(int, const char *, struct stat *, int); +int mkdirat(int, const char *, mode_t); +int mkfifoat(int, const char *, mode_t); +int mknodat(int, const char *, mode_t, dev_t); +int utimensat(int, const char *, const struct timespec [2], int); +int futimens(int, const struct timespec [2]); +#endif +#if __BSD_VISIBLE +int chflags(const char *, unsigned int); +int chflagsat(int, const char *, unsigned int, int); +int fchflags(int, unsigned int); +int isfdtype(int, int); +#endif +__END_DECLS +#endif +#endif /* !_SYS_STAT_H_ */ diff --git a/sys/sys/statvfs.h b/sys/sys/statvfs.h new file mode 100644 index 0000000..7c6492b --- /dev/null +++ b/sys/sys/statvfs.h @@ -0,0 +1,48 @@ +/* $OpenBSD: statvfs.h,v 1.3 2013/03/24 17:45:50 deraadt Exp $ */ + +/* + * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> + * + * 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_STATVFS_H_ +#define _SYS_STATVFS_H_ + +#include <sys/types.h> + +struct statvfs { + unsigned long f_bsize; /* file system block size */ + unsigned long f_frsize; /* fundamental file system block size */ + fsblkcnt_t f_blocks; /* number of blocks (unit f_frsize) */ + fsblkcnt_t f_bfree; /* free blocks in file system */ + fsblkcnt_t f_bavail; /* free blocks for non-root */ + fsfilcnt_t f_files; /* total file inodes */ + fsfilcnt_t f_ffree; /* free file inodes */ + fsfilcnt_t f_favail; /* free file inodes for to non-root */ + unsigned long f_fsid; /* file system id */ + unsigned long f_flag; /* bit mask of f_flag values */ + unsigned long f_namemax; /* maximum filename length */ +}; + +#define ST_RDONLY 0x0001UL /* read-only filesystem */ +#define ST_NOSUID 0x0002UL /* nosuid flag set */ + +#ifndef _KERNEL +__BEGIN_DECLS +int fstatvfs(int, struct statvfs *); +int statvfs(const char *, struct statvfs *); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_STATVFS_H_ */ diff --git a/sys/sys/stdarg.h b/sys/sys/stdarg.h new file mode 100644 index 0000000..7b9b403 --- /dev/null +++ b/sys/sys/stdarg.h @@ -0,0 +1,51 @@ +/* $OpenBSD: stdarg.h,v 1.9 2019/12/12 15:55:36 visa Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie <espie@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 _STDARG_H_ +#define _STDARG_H_ + +#include <sys/cdefs.h> + +#if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__PCC__) + +/* Define __gnuc_va_list. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +/* Note that the type used in va_arg is supposed to match the + actual type **after default promotions**. + Thus, va_arg (..., short) is not valid. */ + +#define va_start(ap, last) __builtin_va_start((ap), last) +#define va_end(ap) __builtin_va_end((ap)) +#define va_arg(ap, type) __builtin_va_arg((ap), type) +#define __va_copy(dst, src) __builtin_va_copy((dst),(src)) + +typedef __gnuc_va_list va_list; + +#else +#error "unsupported compiler" +#endif + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dst, src) __va_copy((dst), (src)) +#endif + +#endif /* not _STDARG_H_ */ diff --git a/sys/sys/stdint.h b/sys/sys/stdint.h new file mode 100644 index 0000000..5d3fd94 --- /dev/null +++ b/sys/sys/stdint.h @@ -0,0 +1,231 @@ +/* $OpenBSD: stdint.h,v 1.11 2019/01/25 00:19:26 millert Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller <millert@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_STDINT_H_ +#define _SYS_STDINT_H_ + +#include <sys/cdefs.h> +#include <machine/_types.h> + +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +#endif + +/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */ +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int_fast8_t int_fast8_t; +typedef __uint_fast8_t uint_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __int_fast64_t int_fast64_t; +typedef __uint_fast64_t uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +typedef __uintptr_t uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +/* + * 7.18.2 Limits of specified-width integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to the typedef names defined above. + */ + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-0x7f - 1) +#define INT16_MIN (-0x7fff - 1) +#define INT32_MIN (-0x7fffffff - 1) +#define INT64_MIN (-0x7fffffffffffffffLL - 1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffffLL + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU +#define UINT64_MAX 0xffffffffffffffffULL + +/* 7.18.2.2 Limits of minimum-width integer types */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ +#define INT_FAST8_MIN __INT_FAST8_MIN +#define INT_FAST16_MIN __INT_FAST16_MIN +#define INT_FAST32_MIN __INT_FAST32_MIN +#define INT_FAST64_MIN __INT_FAST64_MIN + +#define INT_FAST8_MAX __INT_FAST8_MAX +#define INT_FAST16_MAX __INT_FAST16_MAX +#define INT_FAST32_MAX __INT_FAST32_MAX +#define INT_FAST64_MAX __INT_FAST64_MAX + +#define UINT_FAST8_MAX __UINT_FAST8_MAX +#define UINT_FAST16_MAX __UINT_FAST16_MAX +#define UINT_FAST32_MAX __UINT_FAST32_MAX +#define UINT_FAST64_MAX __UINT_FAST64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ +#ifdef __LP64__ +#define INTPTR_MIN (-0x7fffffffffffffffL - 1) +#define INTPTR_MAX 0x7fffffffffffffffL +#define UINTPTR_MAX 0xffffffffffffffffUL +#else +#define INTPTR_MIN (-0x7fffffffL - 1) +#define INTPTR_MAX 0x7fffffffL +#define UINTPTR_MAX 0xffffffffUL +#endif + +/* 7.18.2.5 Limits of greatest-width integer types */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * 7.18.3 Limits of other integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to types specified in other standard + * header files. + */ + +/* Limits of ptrdiff_t */ +#define PTRDIFF_MIN INTPTR_MIN +#define PTRDIFF_MAX INTPTR_MAX + +/* Limits of sig_atomic_t */ +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +/* Limit of size_t */ +#ifndef SIZE_MAX +#define SIZE_MAX UINTPTR_MAX +#endif + +/* Limits of wchar_t */ +#ifndef WCHAR_MIN +#define WCHAR_MIN INT32_MIN +#endif +#ifndef WCHAR_MAX +#define WCHAR_MAX INT32_MAX +#endif + +/* Limits of wint_t */ +#define WINT_MIN INT32_MIN +#define WINT_MAX INT32_MAX + +/* + * 7.18.4 Macros for integer constants. + * + * The following function-like macros expand to integer constants + * suitable for initializing objects that have integer types corresponding + * to types defined in <stdint.h>. The argument in any instance of + * these macros shall be a decimal, octal, or hexadecimal constant with + * a value that does not exceed the limits for the corresponding type. + */ + +/* 7.18.4.1 Macros for minimum-width integer constants. */ +#define INT8_C(_c) (_c) +#define INT16_C(_c) (_c) +#define INT32_C(_c) (_c) +#define INT64_C(_c) __CONCAT(_c, LL) + +#define UINT8_C(_c) (_c) +#define UINT16_C(_c) (_c) +#define UINT32_C(_c) __CONCAT(_c, U) +#define UINT64_C(_c) __CONCAT(_c, ULL) + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(_c) __CONCAT(_c, LL) +#define UINTMAX_C(_c) __CONCAT(_c, ULL) + +#endif /* _SYS_STDINT_H_ */ diff --git a/sys/sys/swap.h b/sys/sys/swap.h new file mode 100644 index 0000000..ad7b442 --- /dev/null +++ b/sys/sys/swap.h @@ -0,0 +1,62 @@ +/* $OpenBSD: swap.h,v 1.7 2013/09/30 12:02:30 millert Exp $ */ +/* $NetBSD: swap.h,v 1.2 1998/09/13 14:46:24 christos Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1998 Matthew R. Green, Tobias Weingartner + * 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. + */ + +#ifndef _SYS_SWAP_H_ +#define _SYS_SWAP_H_ + +#include <sys/syslimits.h> + +/* These structures are used to return swap information for userland */ +struct swapent { + dev_t se_dev; /* device id */ + int se_flags; /* flags */ + int se_nblks; /* total blocks */ + int se_inuse; /* blocks in use */ + int se_priority; /* priority of this device */ + char se_path[PATH_MAX]; /* path name */ +}; + +#ifdef _KERNEL +#define NETDEV (dev_t)(-2) /* network device (for nfs swap) */ +#endif /* _KERNEL */ + +#define SWAP_ON 1 /* begin swapping on device */ +#define SWAP_OFF 2 /* (stop swapping on device) */ +#define SWAP_NSWAP 3 /* how many swap devices ? */ +#define SWAP_STATS 4 /* get device info */ +#define SWAP_CTL 5 /* change priority on device */ +#define SWAP_DUMPDEV 7 /* use this device as dump device */ + +#define SWF_INUSE 0x00000001 /* in use: we have swapped here */ +#define SWF_ENABLE 0x00000002 /* enabled: we can swap here */ +#define SWF_BUSY 0x00000004 /* busy: I/O happening here */ +#define SWF_FAKE 0x00000008 /* fake: still being built */ + +#endif /* _SYS_SWAP_H_ */ diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h new file mode 100644 index 0000000..3500f7f --- /dev/null +++ b/sys/sys/syscall.h @@ -0,0 +1,708 @@ +/* $OpenBSD: syscall.h,v 1.215 2020/03/18 19:35:00 anton Exp $ */ + +/* + * System call numbers. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; OpenBSD: syscalls.master,v 1.207 2020/03/18 19:33:36 anton Exp + */ + +/* syscall: "syscall" ret: "int" args: "int" "..." */ +#define SYS_syscall 0 + +/* syscall: "exit" ret: "void" args: "int" */ +#define SYS_exit 1 + +/* syscall: "fork" ret: "int" args: */ +#define SYS_fork 2 + +/* syscall: "read" ret: "ssize_t" args: "int" "void *" "size_t" */ +#define SYS_read 3 + +/* syscall: "write" ret: "ssize_t" args: "int" "const void *" "size_t" */ +#define SYS_write 4 + +/* syscall: "open" ret: "int" args: "const char *" "int" "..." */ +#define SYS_open 5 + +/* syscall: "close" ret: "int" args: "int" */ +#define SYS_close 6 + +/* syscall: "getentropy" ret: "int" args: "void *" "size_t" */ +#define SYS_getentropy 7 + +/* syscall: "__tfork" ret: "int" args: "const struct __tfork *" "size_t" */ +#define SYS___tfork 8 + +/* syscall: "link" ret: "int" args: "const char *" "const char *" */ +#define SYS_link 9 + +/* syscall: "unlink" ret: "int" args: "const char *" */ +#define SYS_unlink 10 + +/* syscall: "wait4" ret: "pid_t" args: "pid_t" "int *" "int" "struct rusage *" */ +#define SYS_wait4 11 + +/* syscall: "chdir" ret: "int" args: "const char *" */ +#define SYS_chdir 12 + +/* syscall: "fchdir" ret: "int" args: "int" */ +#define SYS_fchdir 13 + +/* syscall: "mknod" ret: "int" args: "const char *" "mode_t" "dev_t" */ +#define SYS_mknod 14 + +/* syscall: "chmod" ret: "int" args: "const char *" "mode_t" */ +#define SYS_chmod 15 + +/* syscall: "chown" ret: "int" args: "const char *" "uid_t" "gid_t" */ +#define SYS_chown 16 + +/* syscall: "break" ret: "int" args: "char *" */ +#define SYS_break 17 + +/* syscall: "getdtablecount" ret: "int" args: */ +#define SYS_getdtablecount 18 + +/* syscall: "getrusage" ret: "int" args: "int" "struct rusage *" */ +#define SYS_getrusage 19 + +/* syscall: "getpid" ret: "pid_t" args: */ +#define SYS_getpid 20 + +/* syscall: "mount" ret: "int" args: "const char *" "const char *" "int" "void *" */ +#define SYS_mount 21 + +/* syscall: "unmount" ret: "int" args: "const char *" "int" */ +#define SYS_unmount 22 + +/* syscall: "setuid" ret: "int" args: "uid_t" */ +#define SYS_setuid 23 + +/* syscall: "getuid" ret: "uid_t" args: */ +#define SYS_getuid 24 + +/* syscall: "geteuid" ret: "uid_t" args: */ +#define SYS_geteuid 25 + +/* syscall: "ptrace" ret: "int" args: "int" "pid_t" "caddr_t" "int" */ +#define SYS_ptrace 26 + +/* syscall: "recvmsg" ret: "ssize_t" args: "int" "struct msghdr *" "int" */ +#define SYS_recvmsg 27 + +/* syscall: "sendmsg" ret: "ssize_t" args: "int" "const struct msghdr *" "int" */ +#define SYS_sendmsg 28 + +/* syscall: "recvfrom" ret: "ssize_t" args: "int" "void *" "size_t" "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_recvfrom 29 + +/* syscall: "accept" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_accept 30 + +/* syscall: "getpeername" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_getpeername 31 + +/* syscall: "getsockname" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_getsockname 32 + +/* syscall: "access" ret: "int" args: "const char *" "int" */ +#define SYS_access 33 + +/* syscall: "chflags" ret: "int" args: "const char *" "u_int" */ +#define SYS_chflags 34 + +/* syscall: "fchflags" ret: "int" args: "int" "u_int" */ +#define SYS_fchflags 35 + +/* syscall: "sync" ret: "void" args: */ +#define SYS_sync 36 + +/* syscall: "msyscall" ret: "int" args: "void *" "size_t" */ +#define SYS_msyscall 37 + +/* syscall: "stat" ret: "int" args: "const char *" "struct stat *" */ +#define SYS_stat 38 + +/* syscall: "getppid" ret: "pid_t" args: */ +#define SYS_getppid 39 + +/* syscall: "lstat" ret: "int" args: "const char *" "struct stat *" */ +#define SYS_lstat 40 + +/* syscall: "dup" ret: "int" args: "int" */ +#define SYS_dup 41 + +/* syscall: "fstatat" ret: "int" args: "int" "const char *" "struct stat *" "int" */ +#define SYS_fstatat 42 + +/* syscall: "getegid" ret: "gid_t" args: */ +#define SYS_getegid 43 + +/* syscall: "profil" ret: "int" args: "caddr_t" "size_t" "u_long" "u_int" */ +#define SYS_profil 44 + +/* syscall: "ktrace" ret: "int" args: "const char *" "int" "int" "pid_t" */ +#define SYS_ktrace 45 + +/* syscall: "sigaction" ret: "int" args: "int" "const struct sigaction *" "struct sigaction *" */ +#define SYS_sigaction 46 + +/* syscall: "getgid" ret: "gid_t" args: */ +#define SYS_getgid 47 + +/* syscall: "sigprocmask" ret: "int" args: "int" "sigset_t" */ +#define SYS_sigprocmask 48 + + /* 49 is obsolete ogetlogin */ +/* syscall: "setlogin" ret: "int" args: "const char *" */ +#define SYS_setlogin 50 + +/* syscall: "acct" ret: "int" args: "const char *" */ +#define SYS_acct 51 + +/* syscall: "sigpending" ret: "int" args: */ +#define SYS_sigpending 52 + +/* syscall: "fstat" ret: "int" args: "int" "struct stat *" */ +#define SYS_fstat 53 + +/* syscall: "ioctl" ret: "int" args: "int" "u_long" "..." */ +#define SYS_ioctl 54 + +/* syscall: "reboot" ret: "int" args: "int" */ +#define SYS_reboot 55 + +/* syscall: "revoke" ret: "int" args: "const char *" */ +#define SYS_revoke 56 + +/* syscall: "symlink" ret: "int" args: "const char *" "const char *" */ +#define SYS_symlink 57 + +/* syscall: "readlink" ret: "ssize_t" args: "const char *" "char *" "size_t" */ +#define SYS_readlink 58 + +/* syscall: "execve" ret: "int" args: "const char *" "char *const *" "char *const *" */ +#define SYS_execve 59 + +/* syscall: "umask" ret: "mode_t" args: "mode_t" */ +#define SYS_umask 60 + +/* syscall: "chroot" ret: "int" args: "const char *" */ +#define SYS_chroot 61 + +/* syscall: "getfsstat" ret: "int" args: "struct statfs *" "size_t" "int" */ +#define SYS_getfsstat 62 + +/* syscall: "statfs" ret: "int" args: "const char *" "struct statfs *" */ +#define SYS_statfs 63 + +/* syscall: "fstatfs" ret: "int" args: "int" "struct statfs *" */ +#define SYS_fstatfs 64 + +/* syscall: "fhstatfs" ret: "int" args: "const fhandle_t *" "struct statfs *" */ +#define SYS_fhstatfs 65 + +/* syscall: "vfork" ret: "int" args: */ +#define SYS_vfork 66 + +/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" "struct timezone *" */ +#define SYS_gettimeofday 67 + +/* syscall: "settimeofday" ret: "int" args: "const struct timeval *" "const struct timezone *" */ +#define SYS_settimeofday 68 + +/* syscall: "setitimer" ret: "int" args: "int" "const struct itimerval *" "struct itimerval *" */ +#define SYS_setitimer 69 + +/* syscall: "getitimer" ret: "int" args: "int" "struct itimerval *" */ +#define SYS_getitimer 70 + +/* syscall: "select" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "struct timeval *" */ +#define SYS_select 71 + +/* syscall: "kevent" ret: "int" args: "int" "const struct kevent *" "int" "struct kevent *" "int" "const struct timespec *" */ +#define SYS_kevent 72 + +/* syscall: "munmap" ret: "int" args: "void *" "size_t" */ +#define SYS_munmap 73 + +/* syscall: "mprotect" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_mprotect 74 + +/* syscall: "madvise" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_madvise 75 + +/* syscall: "utimes" ret: "int" args: "const char *" "const struct timeval *" */ +#define SYS_utimes 76 + +/* syscall: "futimes" ret: "int" args: "int" "const struct timeval *" */ +#define SYS_futimes 77 + +/* syscall: "getgroups" ret: "int" args: "int" "gid_t *" */ +#define SYS_getgroups 79 + +/* syscall: "setgroups" ret: "int" args: "int" "const gid_t *" */ +#define SYS_setgroups 80 + +/* syscall: "getpgrp" ret: "int" args: */ +#define SYS_getpgrp 81 + +/* syscall: "setpgid" ret: "int" args: "pid_t" "pid_t" */ +#define SYS_setpgid 82 + +/* syscall: "futex" ret: "int" args: "uint32_t *" "int" "int" "const struct timespec *" "uint32_t *" */ +#define SYS_futex 83 + +/* syscall: "utimensat" ret: "int" args: "int" "const char *" "const struct timespec *" "int" */ +#define SYS_utimensat 84 + +/* syscall: "futimens" ret: "int" args: "int" "const struct timespec *" */ +#define SYS_futimens 85 + +/* syscall: "kbind" ret: "int" args: "const struct __kbind *" "size_t" "int64_t" */ +#define SYS_kbind 86 + +/* syscall: "clock_gettime" ret: "int" args: "clockid_t" "struct timespec *" */ +#define SYS_clock_gettime 87 + +/* syscall: "clock_settime" ret: "int" args: "clockid_t" "const struct timespec *" */ +#define SYS_clock_settime 88 + +/* syscall: "clock_getres" ret: "int" args: "clockid_t" "struct timespec *" */ +#define SYS_clock_getres 89 + +/* syscall: "dup2" ret: "int" args: "int" "int" */ +#define SYS_dup2 90 + +/* syscall: "nanosleep" ret: "int" args: "const struct timespec *" "struct timespec *" */ +#define SYS_nanosleep 91 + +/* syscall: "fcntl" ret: "int" args: "int" "int" "..." */ +#define SYS_fcntl 92 + +/* syscall: "accept4" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" "int" */ +#define SYS_accept4 93 + +/* syscall: "__thrsleep" ret: "int" args: "const volatile void *" "clockid_t" "const struct timespec *" "void *" "const int *" */ +#define SYS___thrsleep 94 + +/* syscall: "fsync" ret: "int" args: "int" */ +#define SYS_fsync 95 + +/* syscall: "setpriority" ret: "int" args: "int" "id_t" "int" */ +#define SYS_setpriority 96 + +/* syscall: "socket" ret: "int" args: "int" "int" "int" */ +#define SYS_socket 97 + +/* syscall: "connect" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_connect 98 + +/* syscall: "getdents" ret: "int" args: "int" "void *" "size_t" */ +#define SYS_getdents 99 + +/* syscall: "getpriority" ret: "int" args: "int" "id_t" */ +#define SYS_getpriority 100 + +/* syscall: "pipe2" ret: "int" args: "int *" "int" */ +#define SYS_pipe2 101 + +/* syscall: "dup3" ret: "int" args: "int" "int" "int" */ +#define SYS_dup3 102 + +/* syscall: "sigreturn" ret: "int" args: "struct sigcontext *" */ +#define SYS_sigreturn 103 + +/* syscall: "bind" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_bind 104 + +/* syscall: "setsockopt" ret: "int" args: "int" "int" "int" "const void *" "socklen_t" */ +#define SYS_setsockopt 105 + +/* syscall: "listen" ret: "int" args: "int" "int" */ +#define SYS_listen 106 + +/* syscall: "chflagsat" ret: "int" args: "int" "const char *" "u_int" "int" */ +#define SYS_chflagsat 107 + +/* syscall: "pledge" ret: "int" args: "const char *" "const char *" */ +#define SYS_pledge 108 + +/* syscall: "ppoll" ret: "int" args: "struct pollfd *" "u_int" "const struct timespec *" "const sigset_t *" */ +#define SYS_ppoll 109 + +/* syscall: "pselect" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "const struct timespec *" "const sigset_t *" */ +#define SYS_pselect 110 + +/* syscall: "sigsuspend" ret: "int" args: "int" */ +#define SYS_sigsuspend 111 + +/* syscall: "sendsyslog" ret: "int" args: "const char *" "size_t" "int" */ +#define SYS_sendsyslog 112 + +/* syscall: "unveil" ret: "int" args: "const char *" "const char *" */ +#define SYS_unveil 114 + +/* syscall: "__realpath" ret: "int" args: "const char *" "char *" */ +#define SYS___realpath 115 + + /* 116 is obsolete t32_gettimeofday */ + /* 117 is obsolete t32_getrusage */ +/* syscall: "getsockopt" ret: "int" args: "int" "int" "int" "void *" "socklen_t *" */ +#define SYS_getsockopt 118 + +/* syscall: "thrkill" ret: "int" args: "pid_t" "int" "void *" */ +#define SYS_thrkill 119 + +/* syscall: "readv" ret: "ssize_t" args: "int" "const struct iovec *" "int" */ +#define SYS_readv 120 + +/* syscall: "writev" ret: "ssize_t" args: "int" "const struct iovec *" "int" */ +#define SYS_writev 121 + +/* syscall: "kill" ret: "int" args: "int" "int" */ +#define SYS_kill 122 + +/* syscall: "fchown" ret: "int" args: "int" "uid_t" "gid_t" */ +#define SYS_fchown 123 + +/* syscall: "fchmod" ret: "int" args: "int" "mode_t" */ +#define SYS_fchmod 124 + + /* 125 is obsolete orecvfrom */ +/* syscall: "setreuid" ret: "int" args: "uid_t" "uid_t" */ +#define SYS_setreuid 126 + +/* syscall: "setregid" ret: "int" args: "gid_t" "gid_t" */ +#define SYS_setregid 127 + +/* syscall: "rename" ret: "int" args: "const char *" "const char *" */ +#define SYS_rename 128 + + /* 129 is obsolete otruncate */ + /* 130 is obsolete oftruncate */ +/* syscall: "flock" ret: "int" args: "int" "int" */ +#define SYS_flock 131 + +/* syscall: "mkfifo" ret: "int" args: "const char *" "mode_t" */ +#define SYS_mkfifo 132 + +/* syscall: "sendto" ret: "ssize_t" args: "int" "const void *" "size_t" "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_sendto 133 + +/* syscall: "shutdown" ret: "int" args: "int" "int" */ +#define SYS_shutdown 134 + +/* syscall: "socketpair" ret: "int" args: "int" "int" "int" "int *" */ +#define SYS_socketpair 135 + +/* syscall: "mkdir" ret: "int" args: "const char *" "mode_t" */ +#define SYS_mkdir 136 + +/* syscall: "rmdir" ret: "int" args: "const char *" */ +#define SYS_rmdir 137 + + /* 138 is obsolete t32_utimes */ + /* 139 is obsolete 4.2 sigreturn */ +/* syscall: "adjtime" ret: "int" args: "const struct timeval *" "struct timeval *" */ +#define SYS_adjtime 140 + +/* syscall: "getlogin_r" ret: "int" args: "char *" "u_int" */ +#define SYS_getlogin_r 141 + + /* 142 is obsolete ogethostid */ + /* 143 is obsolete osethostid */ + /* 144 is obsolete ogetrlimit */ + /* 145 is obsolete osetrlimit */ + /* 146 is obsolete okillpg */ +/* syscall: "setsid" ret: "int" args: */ +#define SYS_setsid 147 + +/* syscall: "quotactl" ret: "int" args: "const char *" "int" "int" "char *" */ +#define SYS_quotactl 148 + + /* 149 is obsolete oquota */ + /* 150 is obsolete ogetsockname */ +/* syscall: "nfssvc" ret: "int" args: "int" "void *" */ +#define SYS_nfssvc 155 + + /* 156 is obsolete ogetdirentries */ + /* 157 is obsolete statfs25 */ + /* 158 is obsolete fstatfs25 */ +/* syscall: "getfh" ret: "int" args: "const char *" "fhandle_t *" */ +#define SYS_getfh 161 + + /* 162 is obsolete ogetdomainname */ + /* 163 is obsolete osetdomainname */ +/* syscall: "__tmpfd" ret: "int" args: "int" */ +#define SYS___tmpfd 164 + +/* syscall: "sysarch" ret: "int" args: "int" "void *" */ +#define SYS_sysarch 165 + + /* 169 is obsolete semsys10 */ + /* 170 is obsolete msgsys10 */ + /* 171 is obsolete shmsys10 */ +/* syscall: "pread" ret: "ssize_t" args: "int" "void *" "size_t" "int" "off_t" */ +#define SYS_pread 173 + +/* syscall: "pwrite" ret: "ssize_t" args: "int" "const void *" "size_t" "int" "off_t" */ +#define SYS_pwrite 174 + +/* syscall: "setgid" ret: "int" args: "gid_t" */ +#define SYS_setgid 181 + +/* syscall: "setegid" ret: "int" args: "gid_t" */ +#define SYS_setegid 182 + +/* syscall: "seteuid" ret: "int" args: "uid_t" */ +#define SYS_seteuid 183 + + /* 184 is obsolete lfs_bmapv */ + /* 185 is obsolete lfs_markv */ + /* 186 is obsolete lfs_segclean */ + /* 187 is obsolete lfs_segwait */ + /* 188 is obsolete stat35 */ + /* 189 is obsolete fstat35 */ + /* 190 is obsolete lstat35 */ +/* syscall: "pathconf" ret: "long" args: "const char *" "int" */ +#define SYS_pathconf 191 + +/* syscall: "fpathconf" ret: "long" args: "int" "int" */ +#define SYS_fpathconf 192 + +/* syscall: "swapctl" ret: "int" args: "int" "const void *" "int" */ +#define SYS_swapctl 193 + +/* syscall: "getrlimit" ret: "int" args: "int" "struct rlimit *" */ +#define SYS_getrlimit 194 + +/* syscall: "setrlimit" ret: "int" args: "int" "const struct rlimit *" */ +#define SYS_setrlimit 195 + + /* 196 is obsolete ogetdirentries48 */ +/* syscall: "mmap" ret: "void *" args: "void *" "size_t" "int" "int" "int" "long" "off_t" */ +#define SYS_mmap 197 + +/* syscall: "__syscall" ret: "quad_t" args: "quad_t" "..." */ +#define SYS___syscall 198 + +/* syscall: "lseek" ret: "off_t" args: "int" "int" "off_t" "int" */ +#define SYS_lseek 199 + +/* syscall: "truncate" ret: "int" args: "const char *" "int" "off_t" */ +#define SYS_truncate 200 + +/* syscall: "ftruncate" ret: "int" args: "int" "int" "off_t" */ +#define SYS_ftruncate 201 + +/* syscall: "sysctl" ret: "int" args: "const int *" "u_int" "void *" "size_t *" "void *" "size_t" */ +#define SYS_sysctl 202 + +/* syscall: "mlock" ret: "int" args: "const void *" "size_t" */ +#define SYS_mlock 203 + +/* syscall: "munlock" ret: "int" args: "const void *" "size_t" */ +#define SYS_munlock 204 + + /* 206 is obsolete t32_futimes */ +/* syscall: "getpgid" ret: "pid_t" args: "pid_t" */ +#define SYS_getpgid 207 + + /* 208 is obsolete nnpfspioctl */ +/* syscall: "utrace" ret: "int" args: "const char *" "const void *" "size_t" */ +#define SYS_utrace 209 + +/* syscall: "semget" ret: "int" args: "key_t" "int" "int" */ +#define SYS_semget 221 + + /* 222 is obsolete semop35 */ + /* 223 is obsolete semconfig35 */ +/* syscall: "msgget" ret: "int" args: "key_t" "int" */ +#define SYS_msgget 225 + +/* syscall: "msgsnd" ret: "int" args: "int" "const void *" "size_t" "int" */ +#define SYS_msgsnd 226 + +/* syscall: "msgrcv" ret: "int" args: "int" "void *" "size_t" "long" "int" */ +#define SYS_msgrcv 227 + +/* syscall: "shmat" ret: "void *" args: "int" "const void *" "int" */ +#define SYS_shmat 228 + +/* syscall: "shmdt" ret: "int" args: "const void *" */ +#define SYS_shmdt 230 + + /* 231 is obsolete shmget35 */ + /* 232 is obsolete t32_clock_gettime */ + /* 233 is obsolete t32_clock_settime */ + /* 234 is obsolete t32_clock_getres */ + /* 240 is obsolete t32_nanosleep */ +/* syscall: "minherit" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_minherit 250 + + /* 251 is obsolete rfork */ +/* syscall: "poll" ret: "int" args: "struct pollfd *" "u_int" "int" */ +#define SYS_poll 252 + +/* syscall: "issetugid" ret: "int" args: */ +#define SYS_issetugid 253 + +/* syscall: "lchown" ret: "int" args: "const char *" "uid_t" "gid_t" */ +#define SYS_lchown 254 + +/* syscall: "getsid" ret: "pid_t" args: "pid_t" */ +#define SYS_getsid 255 + +/* syscall: "msync" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_msync 256 + + /* 257 is obsolete semctl35 */ + /* 258 is obsolete shmctl35 */ + /* 259 is obsolete msgctl35 */ +/* syscall: "pipe" ret: "int" args: "int *" */ +#define SYS_pipe 263 + +/* syscall: "fhopen" ret: "int" args: "const fhandle_t *" "int" */ +#define SYS_fhopen 264 + +/* syscall: "preadv" ret: "ssize_t" args: "int" "const struct iovec *" "int" "int" "off_t" */ +#define SYS_preadv 267 + +/* syscall: "pwritev" ret: "ssize_t" args: "int" "const struct iovec *" "int" "int" "off_t" */ +#define SYS_pwritev 268 + +/* syscall: "kqueue" ret: "int" args: */ +#define SYS_kqueue 269 + + /* 270 is obsolete t32_kevent */ +/* syscall: "mlockall" ret: "int" args: "int" */ +#define SYS_mlockall 271 + +/* syscall: "munlockall" ret: "int" args: */ +#define SYS_munlockall 272 + +/* syscall: "getresuid" ret: "int" args: "uid_t *" "uid_t *" "uid_t *" */ +#define SYS_getresuid 281 + +/* syscall: "setresuid" ret: "int" args: "uid_t" "uid_t" "uid_t" */ +#define SYS_setresuid 282 + +/* syscall: "getresgid" ret: "int" args: "gid_t *" "gid_t *" "gid_t *" */ +#define SYS_getresgid 283 + +/* syscall: "setresgid" ret: "int" args: "gid_t" "gid_t" "gid_t" */ +#define SYS_setresgid 284 + + /* 285 is obsolete sys_omquery */ +/* syscall: "mquery" ret: "void *" args: "void *" "size_t" "int" "int" "int" "long" "off_t" */ +#define SYS_mquery 286 + +/* syscall: "closefrom" ret: "int" args: "int" */ +#define SYS_closefrom 287 + +/* syscall: "sigaltstack" ret: "int" args: "const struct sigaltstack *" "struct sigaltstack *" */ +#define SYS_sigaltstack 288 + +/* syscall: "shmget" ret: "int" args: "key_t" "size_t" "int" */ +#define SYS_shmget 289 + +/* syscall: "semop" ret: "int" args: "int" "struct sembuf *" "size_t" */ +#define SYS_semop 290 + + /* 291 is obsolete t32_stat */ + /* 292 is obsolete t32_fstat */ + /* 293 is obsolete t32_lstat */ +/* syscall: "fhstat" ret: "int" args: "const fhandle_t *" "struct stat *" */ +#define SYS_fhstat 294 + +/* syscall: "__semctl" ret: "int" args: "int" "int" "int" "union semun *" */ +#define SYS___semctl 295 + +/* syscall: "shmctl" ret: "int" args: "int" "int" "struct shmid_ds *" */ +#define SYS_shmctl 296 + +/* syscall: "msgctl" ret: "int" args: "int" "int" "struct msqid_ds *" */ +#define SYS_msgctl 297 + +/* syscall: "sched_yield" ret: "int" args: */ +#define SYS_sched_yield 298 + +/* syscall: "getthrid" ret: "pid_t" args: */ +#define SYS_getthrid 299 + + /* 300 is obsolete t32___thrsleep */ +/* syscall: "__thrwakeup" ret: "int" args: "const volatile void *" "int" */ +#define SYS___thrwakeup 301 + +/* syscall: "__threxit" ret: "void" args: "pid_t *" */ +#define SYS___threxit 302 + +/* syscall: "__thrsigdivert" ret: "int" args: "sigset_t" "siginfo_t *" "const struct timespec *" */ +#define SYS___thrsigdivert 303 + +/* syscall: "__getcwd" ret: "int" args: "char *" "size_t" */ +#define SYS___getcwd 304 + +/* syscall: "adjfreq" ret: "int" args: "const int64_t *" "int64_t *" */ +#define SYS_adjfreq 305 + + /* 306 is obsolete getfsstat53 */ + /* 307 is obsolete statfs53 */ + /* 308 is obsolete fstatfs53 */ + /* 309 is obsolete fhstatfs53 */ +/* syscall: "setrtable" ret: "int" args: "int" */ +#define SYS_setrtable 310 + +/* syscall: "getrtable" ret: "int" args: */ +#define SYS_getrtable 311 + + /* 312 is obsolete t32_getdirentries */ +/* syscall: "faccessat" ret: "int" args: "int" "const char *" "int" "int" */ +#define SYS_faccessat 313 + +/* syscall: "fchmodat" ret: "int" args: "int" "const char *" "mode_t" "int" */ +#define SYS_fchmodat 314 + +/* syscall: "fchownat" ret: "int" args: "int" "const char *" "uid_t" "gid_t" "int" */ +#define SYS_fchownat 315 + + /* 316 is obsolete t32_fstatat */ +/* syscall: "linkat" ret: "int" args: "int" "const char *" "int" "const char *" "int" */ +#define SYS_linkat 317 + +/* syscall: "mkdirat" ret: "int" args: "int" "const char *" "mode_t" */ +#define SYS_mkdirat 318 + +/* syscall: "mkfifoat" ret: "int" args: "int" "const char *" "mode_t" */ +#define SYS_mkfifoat 319 + +/* syscall: "mknodat" ret: "int" args: "int" "const char *" "mode_t" "dev_t" */ +#define SYS_mknodat 320 + +/* syscall: "openat" ret: "int" args: "int" "const char *" "int" "..." */ +#define SYS_openat 321 + +/* syscall: "readlinkat" ret: "ssize_t" args: "int" "const char *" "char *" "size_t" */ +#define SYS_readlinkat 322 + +/* syscall: "renameat" ret: "int" args: "int" "const char *" "int" "const char *" */ +#define SYS_renameat 323 + +/* syscall: "symlinkat" ret: "int" args: "const char *" "int" "const char *" */ +#define SYS_symlinkat 324 + +/* syscall: "unlinkat" ret: "int" args: "int" "const char *" "int" */ +#define SYS_unlinkat 325 + + /* 326 is obsolete t32_utimensat */ + /* 327 is obsolete t32_futimens */ + /* 328 is obsolete __tfork51 */ +/* syscall: "__set_tcb" ret: "void" args: "void *" */ +#define SYS___set_tcb 329 + +/* syscall: "__get_tcb" ret: "void *" args: */ +#define SYS___get_tcb 330 + +#define SYS_MAXSYSCALL 331 diff --git a/sys/sys/syscall_mi.h b/sys/sys/syscall_mi.h new file mode 100644 index 0000000..76f34e0 --- /dev/null +++ b/sys/sys/syscall_mi.h @@ -0,0 +1,191 @@ +/* $OpenBSD: syscall_mi.h,v 1.25 2020/01/21 16:16:23 mpi 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. + * + * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 + */ + +#include <sys/param.h> +#include <sys/pledge.h> +#include <sys/tracepoint.h> +#include <uvm/uvm_extern.h> + +#ifdef KTRACE +#include <sys/ktrace.h> +#endif + +#include "dt.h" +#if NDT > 0 +#include <dev/dt/dtvar.h> +#endif + + +/* + * The MD setup for a system call has been done; here's the MI part. + */ +static inline int +mi_syscall(struct proc *p, register_t code, const struct sysent *callp, + register_t *argp, register_t retval[2]) +{ + uint64_t tval; + int lock = !(callp->sy_flags & SY_NOLOCK); + int error, pledged; + + /* refresh the thread's cache of the process's creds */ + refreshcreds(p); + +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_call(p, code, argp); + KERNEL_UNLOCK(); +#endif + TRACEPOINT(raw_syscalls, sys_enter, code, NULL); +#if NDT > 0 + DT_ENTER(syscall, code, callp->sy_argsize, argp); +#endif +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSCALL)) { + KERNEL_LOCK(); + ktrsyscall(p, code, callp->sy_argsize, argp); + KERNEL_UNLOCK(); + } +#endif + + /* SP must be within MAP_STACK space */ + if (!uvm_map_inentry(p, &p->p_spinentry, PROC_STACK(p), + "[%s]%d/%d sp=%lx inside %lx-%lx: not MAP_STACK\n", + uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial)) + return (EPERM); + + /* PC must be in un-writeable permitted text (sigtramp, libc, ld.so) */ + if (!uvm_map_inentry(p, &p->p_pcinentry, PROC_PC(p), + "[%s]%d/%d pc=%lx inside %lx-%lx: bogus syscall\n", + uvm_map_inentry_pc, p->p_vmspace->vm_map.wserial)) + return (EPERM); + + if (lock) + KERNEL_LOCK(); + pledged = (p->p_p->ps_flags & PS_PLEDGE); + if (pledged && (error = pledge_syscall(p, code, &tval))) { + if (!lock) + KERNEL_LOCK(); + error = pledge_fail(p, error, tval); + KERNEL_UNLOCK(); + return (error); + } + error = (*callp->sy_call)(p, argp, retval); + if (lock) + KERNEL_UNLOCK(); + + return (error); +} + +/* + * Finish MI stuff on return, after the registers have been set + */ +static inline void +mi_syscall_return(struct proc *p, register_t code, int error, + const register_t retval[2]) +{ +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_ret(p, code, error, retval); + KERNEL_UNLOCK(); +#endif +#if NDT > 0 + DT_LEAVE(syscall, code, error, retval[0], retval[1]); +#endif + TRACEPOINT(raw_syscalls, sys_exit, code, NULL); + + userret(p); + +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSRET)) { + KERNEL_LOCK(); + ktrsysret(p, code, error, retval); + KERNEL_UNLOCK(); + } +#endif +} + +/* + * Finish MI stuff for a new process/thread to return + */ +static inline void +mi_child_return(struct proc *p) +{ +#if defined(SYSCALL_DEBUG) || defined(KTRACE) || NDT > 0 + int code = (p->p_flag & P_THREAD) ? SYS___tfork : + (p->p_p->ps_flags & PS_PPWAIT) ? SYS_vfork : SYS_fork; + const register_t child_retval[2] = { 0, 1 }; +#endif + + TRACEPOINT(sched, on__cpu, NULL); + +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_ret(p, code, 0, child_retval); + KERNEL_UNLOCK(); +#endif +#if NDT > 0 + DT_LEAVE(syscall, code, 0, child_retval[0], child_retval[1]); +#endif + TRACEPOINT(raw_syscalls, sys_exit, code, NULL); + + userret(p); + +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSRET)) { + KERNEL_LOCK(); + ktrsysret(p, code, 0, child_retval); + KERNEL_UNLOCK(); + } +#endif +} + +/* + * Do the specific processing necessary for an AST + */ +static inline void +mi_ast(struct proc *p, int resched) +{ + if (p->p_flag & P_OWEUPC) { + KERNEL_LOCK(); + ADDUPROF(p); + KERNEL_UNLOCK(); + } + if (resched) + preempt(); + + /* + * XXX could move call to userret() here, but + * hppa calls ast() in syscall return and sh calls + * it after userret() + */ +} diff --git a/sys/sys/syscallargs.h b/sys/sys/syscallargs.h new file mode 100644 index 0000000..2209606 --- /dev/null +++ b/sys/sys/syscallargs.h @@ -0,0 +1,1362 @@ +/* $OpenBSD: syscallargs.h,v 1.218 2020/03/18 19:35:00 anton Exp $ */ + +/* + * System call argument lists. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; OpenBSD: syscalls.master,v 1.207 2020/03/18 19:33:36 anton Exp + */ + +#ifdef syscallarg +#undef syscallarg +#endif + +#define syscallarg(x) \ + union { \ + register_t pad; \ + struct { x datum; } le; \ + struct { \ + int8_t pad[ (sizeof (register_t) < sizeof (x)) \ + ? 0 \ + : sizeof (register_t) - sizeof (x)]; \ + x datum; \ + } be; \ + } + +struct sys_exit_args { + syscallarg(int) rval; +}; + +struct sys_read_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys_write_args { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys_open_args { + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(mode_t) mode; +}; + +struct sys_close_args { + syscallarg(int) fd; +}; + +struct sys_getentropy_args { + syscallarg(void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys___tfork_args { + syscallarg(const struct __tfork *) param; + syscallarg(size_t) psize; +}; + +struct sys_link_args { + syscallarg(const char *) path; + syscallarg(const char *) link; +}; + +struct sys_unlink_args { + syscallarg(const char *) path; +}; + +struct sys_wait4_args { + syscallarg(pid_t) pid; + syscallarg(int *) status; + syscallarg(int) options; + syscallarg(struct rusage *) rusage; +}; + +struct sys_chdir_args { + syscallarg(const char *) path; +}; + +struct sys_fchdir_args { + syscallarg(int) fd; +}; + +struct sys_mknod_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(dev_t) dev; +}; + +struct sys_chmod_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_chown_args { + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_obreak_args { + syscallarg(char *) nsize; +}; + +struct sys_getrusage_args { + syscallarg(int) who; + syscallarg(struct rusage *) rusage; +}; + +struct sys_mount_args { + syscallarg(const char *) type; + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(void *) data; +}; + +struct sys_unmount_args { + syscallarg(const char *) path; + syscallarg(int) flags; +}; + +struct sys_setuid_args { + syscallarg(uid_t) uid; +}; + +struct sys_ptrace_args { + syscallarg(int) req; + syscallarg(pid_t) pid; + syscallarg(caddr_t) addr; + syscallarg(int) data; +}; + +struct sys_recvmsg_args { + syscallarg(int) s; + syscallarg(struct msghdr *) msg; + syscallarg(int) flags; +}; + +struct sys_sendmsg_args { + syscallarg(int) s; + syscallarg(const struct msghdr *) msg; + syscallarg(int) flags; +}; + +struct sys_recvfrom_args { + syscallarg(int) s; + syscallarg(void *) buf; + syscallarg(size_t) len; + syscallarg(int) flags; + syscallarg(struct sockaddr *) from; + syscallarg(socklen_t *) fromlenaddr; +}; + +struct sys_accept_args { + syscallarg(int) s; + syscallarg(struct sockaddr *) name; + syscallarg(socklen_t *) anamelen; +}; + +struct sys_getpeername_args { + syscallarg(int) fdes; + syscallarg(struct sockaddr *) asa; + syscallarg(socklen_t *) alen; +}; + +struct sys_getsockname_args { + syscallarg(int) fdes; + syscallarg(struct sockaddr *) asa; + syscallarg(socklen_t *) alen; +}; + +struct sys_access_args { + syscallarg(const char *) path; + syscallarg(int) amode; +}; + +struct sys_chflags_args { + syscallarg(const char *) path; + syscallarg(u_int) flags; +}; + +struct sys_fchflags_args { + syscallarg(int) fd; + syscallarg(u_int) flags; +}; + +struct sys_msyscall_args { + syscallarg(void *) addr; + syscallarg(size_t) len; +}; + +struct sys_stat_args { + syscallarg(const char *) path; + syscallarg(struct stat *) ub; +}; + +struct sys_lstat_args { + syscallarg(const char *) path; + syscallarg(struct stat *) ub; +}; + +struct sys_dup_args { + syscallarg(int) fd; +}; + +struct sys_fstatat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(struct stat *) buf; + syscallarg(int) flag; +}; + +struct sys_profil_args { + syscallarg(caddr_t) samples; + syscallarg(size_t) size; + syscallarg(u_long) offset; + syscallarg(u_int) scale; +}; + +struct sys_ktrace_args { + syscallarg(const char *) fname; + syscallarg(int) ops; + syscallarg(int) facs; + syscallarg(pid_t) pid; +}; + +struct sys_sigaction_args { + syscallarg(int) signum; + syscallarg(const struct sigaction *) nsa; + syscallarg(struct sigaction *) osa; +}; + +struct sys_sigprocmask_args { + syscallarg(int) how; + syscallarg(sigset_t) mask; +}; + +struct sys_setlogin_args { + syscallarg(const char *) namebuf; +}; + +struct sys_acct_args { + syscallarg(const char *) path; +}; + +struct sys_fstat_args { + syscallarg(int) fd; + syscallarg(struct stat *) sb; +}; + +struct sys_ioctl_args { + syscallarg(int) fd; + syscallarg(u_long) com; + syscallarg(void *) data; +}; + +struct sys_reboot_args { + syscallarg(int) opt; +}; + +struct sys_revoke_args { + syscallarg(const char *) path; +}; + +struct sys_symlink_args { + syscallarg(const char *) path; + syscallarg(const char *) link; +}; + +struct sys_readlink_args { + syscallarg(const char *) path; + syscallarg(char *) buf; + syscallarg(size_t) count; +}; + +struct sys_execve_args { + syscallarg(const char *) path; + syscallarg(char *const *) argp; + syscallarg(char *const *) envp; +}; + +struct sys_umask_args { + syscallarg(mode_t) newmask; +}; + +struct sys_chroot_args { + syscallarg(const char *) path; +}; + +struct sys_getfsstat_args { + syscallarg(struct statfs *) buf; + syscallarg(size_t) bufsize; + syscallarg(int) flags; +}; + +struct sys_statfs_args { + syscallarg(const char *) path; + syscallarg(struct statfs *) buf; +}; + +struct sys_fstatfs_args { + syscallarg(int) fd; + syscallarg(struct statfs *) buf; +}; + +struct sys_fhstatfs_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(struct statfs *) buf; +}; + +struct sys_gettimeofday_args { + syscallarg(struct timeval *) tp; + syscallarg(struct timezone *) tzp; +}; + +struct sys_settimeofday_args { + syscallarg(const struct timeval *) tv; + syscallarg(const struct timezone *) tzp; +}; + +struct sys_setitimer_args { + syscallarg(int) which; + syscallarg(const struct itimerval *) itv; + syscallarg(struct itimerval *) oitv; +}; + +struct sys_getitimer_args { + syscallarg(int) which; + syscallarg(struct itimerval *) itv; +}; + +struct sys_select_args { + syscallarg(int) nd; + syscallarg(fd_set *) in; + syscallarg(fd_set *) ou; + syscallarg(fd_set *) ex; + syscallarg(struct timeval *) tv; +}; + +struct sys_kevent_args { + syscallarg(int) fd; + syscallarg(const struct kevent *) changelist; + syscallarg(int) nchanges; + syscallarg(struct kevent *) eventlist; + syscallarg(int) nevents; + syscallarg(const struct timespec *) timeout; +}; + +struct sys_munmap_args { + syscallarg(void *) addr; + syscallarg(size_t) len; +}; + +struct sys_mprotect_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; +}; + +struct sys_madvise_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) behav; +}; + +struct sys_utimes_args { + syscallarg(const char *) path; + syscallarg(const struct timeval *) tptr; +}; + +struct sys_futimes_args { + syscallarg(int) fd; + syscallarg(const struct timeval *) tptr; +}; + +struct sys_getgroups_args { + syscallarg(int) gidsetsize; + syscallarg(gid_t *) gidset; +}; + +struct sys_setgroups_args { + syscallarg(int) gidsetsize; + syscallarg(const gid_t *) gidset; +}; + +struct sys_setpgid_args { + syscallarg(pid_t) pid; + syscallarg(pid_t) pgid; +}; + +struct sys_futex_args { + syscallarg(uint32_t *) f; + syscallarg(int) op; + syscallarg(int) val; + syscallarg(const struct timespec *) timeout; + syscallarg(uint32_t *) g; +}; + +struct sys_utimensat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(const struct timespec *) times; + syscallarg(int) flag; +}; + +struct sys_futimens_args { + syscallarg(int) fd; + syscallarg(const struct timespec *) times; +}; + +struct sys_kbind_args { + syscallarg(const struct __kbind *) param; + syscallarg(size_t) psize; + syscallarg(int64_t) proc_cookie; +}; + +struct sys_clock_gettime_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_clock_settime_args { + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; +}; + +struct sys_clock_getres_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_dup2_args { + syscallarg(int) from; + syscallarg(int) to; +}; + +struct sys_nanosleep_args { + syscallarg(const struct timespec *) rqtp; + syscallarg(struct timespec *) rmtp; +}; + +struct sys_fcntl_args { + syscallarg(int) fd; + syscallarg(int) cmd; + syscallarg(void *) arg; +}; + +struct sys_accept4_args { + syscallarg(int) s; + syscallarg(struct sockaddr *) name; + syscallarg(socklen_t *) anamelen; + syscallarg(int) flags; +}; + +struct sys___thrsleep_args { + syscallarg(const volatile void *) ident; + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; + syscallarg(void *) lock; + syscallarg(const int *) abort; +}; + +struct sys_fsync_args { + syscallarg(int) fd; +}; + +struct sys_setpriority_args { + syscallarg(int) which; + syscallarg(id_t) who; + syscallarg(int) prio; +}; + +struct sys_socket_args { + syscallarg(int) domain; + syscallarg(int) type; + syscallarg(int) protocol; +}; + +struct sys_connect_args { + syscallarg(int) s; + syscallarg(const struct sockaddr *) name; + syscallarg(socklen_t) namelen; +}; + +struct sys_getdents_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) buflen; +}; + +struct sys_getpriority_args { + syscallarg(int) which; + syscallarg(id_t) who; +}; + +struct sys_pipe2_args { + syscallarg(int *) fdp; + syscallarg(int) flags; +}; + +struct sys_dup3_args { + syscallarg(int) from; + syscallarg(int) to; + syscallarg(int) flags; +}; + +struct sys_sigreturn_args { + syscallarg(struct sigcontext *) sigcntxp; +}; + +struct sys_bind_args { + syscallarg(int) s; + syscallarg(const struct sockaddr *) name; + syscallarg(socklen_t) namelen; +}; + +struct sys_setsockopt_args { + syscallarg(int) s; + syscallarg(int) level; + syscallarg(int) name; + syscallarg(const void *) val; + syscallarg(socklen_t) valsize; +}; + +struct sys_listen_args { + syscallarg(int) s; + syscallarg(int) backlog; +}; + +struct sys_chflagsat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(u_int) flags; + syscallarg(int) atflags; +}; + +struct sys_pledge_args { + syscallarg(const char *) promises; + syscallarg(const char *) execpromises; +}; + +struct sys_ppoll_args { + syscallarg(struct pollfd *) fds; + syscallarg(u_int) nfds; + syscallarg(const struct timespec *) ts; + syscallarg(const sigset_t *) mask; +}; + +struct sys_pselect_args { + syscallarg(int) nd; + syscallarg(fd_set *) in; + syscallarg(fd_set *) ou; + syscallarg(fd_set *) ex; + syscallarg(const struct timespec *) ts; + syscallarg(const sigset_t *) mask; +}; + +struct sys_sigsuspend_args { + syscallarg(int) mask; +}; + +struct sys_sendsyslog_args { + syscallarg(const char *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) flags; +}; + +struct sys_unveil_args { + syscallarg(const char *) path; + syscallarg(const char *) permissions; +}; + +struct sys___realpath_args { + syscallarg(const char *) pathname; + syscallarg(char *) resolved; +}; + +struct sys_getsockopt_args { + syscallarg(int) s; + syscallarg(int) level; + syscallarg(int) name; + syscallarg(void *) val; + syscallarg(socklen_t *) avalsize; +}; + +struct sys_thrkill_args { + syscallarg(pid_t) tid; + syscallarg(int) signum; + syscallarg(void *) tcb; +}; + +struct sys_readv_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; +}; + +struct sys_writev_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; +}; + +struct sys_kill_args { + syscallarg(int) pid; + syscallarg(int) signum; +}; + +struct sys_fchown_args { + syscallarg(int) fd; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_fchmod_args { + syscallarg(int) fd; + syscallarg(mode_t) mode; +}; + +struct sys_setreuid_args { + syscallarg(uid_t) ruid; + syscallarg(uid_t) euid; +}; + +struct sys_setregid_args { + syscallarg(gid_t) rgid; + syscallarg(gid_t) egid; +}; + +struct sys_rename_args { + syscallarg(const char *) from; + syscallarg(const char *) to; +}; + +struct sys_flock_args { + syscallarg(int) fd; + syscallarg(int) how; +}; + +struct sys_mkfifo_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_sendto_args { + syscallarg(int) s; + syscallarg(const void *) buf; + syscallarg(size_t) len; + syscallarg(int) flags; + syscallarg(const struct sockaddr *) to; + syscallarg(socklen_t) tolen; +}; + +struct sys_shutdown_args { + syscallarg(int) s; + syscallarg(int) how; +}; + +struct sys_socketpair_args { + syscallarg(int) domain; + syscallarg(int) type; + syscallarg(int) protocol; + syscallarg(int *) rsv; +}; + +struct sys_mkdir_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_rmdir_args { + syscallarg(const char *) path; +}; + +struct sys_adjtime_args { + syscallarg(const struct timeval *) delta; + syscallarg(struct timeval *) olddelta; +}; + +struct sys_getlogin_r_args { + syscallarg(char *) namebuf; + syscallarg(u_int) namelen; +}; + +struct sys_quotactl_args { + syscallarg(const char *) path; + syscallarg(int) cmd; + syscallarg(int) uid; + syscallarg(char *) arg; +}; + +struct sys_nfssvc_args { + syscallarg(int) flag; + syscallarg(void *) argp; +}; + +struct sys_getfh_args { + syscallarg(const char *) fname; + syscallarg(fhandle_t *) fhp; +}; + +struct sys___tmpfd_args { + syscallarg(int) flags; +}; + +struct sys_sysarch_args { + syscallarg(int) op; + syscallarg(void *) parms; +}; + +struct sys_pread_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; +}; + +struct sys_pwrite_args { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; +}; + +struct sys_setgid_args { + syscallarg(gid_t) gid; +}; + +struct sys_setegid_args { + syscallarg(gid_t) egid; +}; + +struct sys_seteuid_args { + syscallarg(uid_t) euid; +}; + +struct sys_pathconf_args { + syscallarg(const char *) path; + syscallarg(int) name; +}; + +struct sys_fpathconf_args { + syscallarg(int) fd; + syscallarg(int) name; +}; + +struct sys_swapctl_args { + syscallarg(int) cmd; + syscallarg(const void *) arg; + syscallarg(int) misc; +}; + +struct sys_getrlimit_args { + syscallarg(int) which; + syscallarg(struct rlimit *) rlp; +}; + +struct sys_setrlimit_args { + syscallarg(int) which; + syscallarg(const struct rlimit *) rlp; +}; + +struct sys_mmap_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; + syscallarg(int) flags; + syscallarg(int) fd; + syscallarg(long) pad; + syscallarg(off_t) pos; +}; + +struct sys_lseek_args { + syscallarg(int) fd; + syscallarg(int) pad; + syscallarg(off_t) offset; + syscallarg(int) whence; +}; + +struct sys_truncate_args { + syscallarg(const char *) path; + syscallarg(int) pad; + syscallarg(off_t) length; +}; + +struct sys_ftruncate_args { + syscallarg(int) fd; + syscallarg(int) pad; + syscallarg(off_t) length; +}; + +struct sys_sysctl_args { + syscallarg(const int *) name; + syscallarg(u_int) namelen; + syscallarg(void *) old; + syscallarg(size_t *) oldlenp; + syscallarg(void *) new; + syscallarg(size_t) newlen; +}; + +struct sys_mlock_args { + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_munlock_args { + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_getpgid_args { + syscallarg(pid_t) pid; +}; + +struct sys_utrace_args { + syscallarg(const char *) label; + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_semget_args { + syscallarg(key_t) key; + syscallarg(int) nsems; + syscallarg(int) semflg; +}; + +struct sys_msgget_args { + syscallarg(key_t) key; + syscallarg(int) msgflg; +}; + +struct sys_msgsnd_args { + syscallarg(int) msqid; + syscallarg(const void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(int) msgflg; +}; + +struct sys_msgrcv_args { + syscallarg(int) msqid; + syscallarg(void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(long) msgtyp; + syscallarg(int) msgflg; +}; + +struct sys_shmat_args { + syscallarg(int) shmid; + syscallarg(const void *) shmaddr; + syscallarg(int) shmflg; +}; + +struct sys_shmdt_args { + syscallarg(const void *) shmaddr; +}; + +struct sys_minherit_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) inherit; +}; + +struct sys_poll_args { + syscallarg(struct pollfd *) fds; + syscallarg(u_int) nfds; + syscallarg(int) timeout; +}; + +struct sys_lchown_args { + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_getsid_args { + syscallarg(pid_t) pid; +}; + +struct sys_msync_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) flags; +}; + +struct sys_pipe_args { + syscallarg(int *) fdp; +}; + +struct sys_fhopen_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(int) flags; +}; + +struct sys_preadv_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; +}; + +struct sys_pwritev_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; +}; + +struct sys_mlockall_args { + syscallarg(int) flags; +}; + +struct sys_getresuid_args { + syscallarg(uid_t *) ruid; + syscallarg(uid_t *) euid; + syscallarg(uid_t *) suid; +}; + +struct sys_setresuid_args { + syscallarg(uid_t) ruid; + syscallarg(uid_t) euid; + syscallarg(uid_t) suid; +}; + +struct sys_getresgid_args { + syscallarg(gid_t *) rgid; + syscallarg(gid_t *) egid; + syscallarg(gid_t *) sgid; +}; + +struct sys_setresgid_args { + syscallarg(gid_t) rgid; + syscallarg(gid_t) egid; + syscallarg(gid_t) sgid; +}; + +struct sys_mquery_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; + syscallarg(int) flags; + syscallarg(int) fd; + syscallarg(long) pad; + syscallarg(off_t) pos; +}; + +struct sys_closefrom_args { + syscallarg(int) fd; +}; + +struct sys_sigaltstack_args { + syscallarg(const struct sigaltstack *) nss; + syscallarg(struct sigaltstack *) oss; +}; + +struct sys_shmget_args { + syscallarg(key_t) key; + syscallarg(size_t) size; + syscallarg(int) shmflg; +}; + +struct sys_semop_args { + syscallarg(int) semid; + syscallarg(struct sembuf *) sops; + syscallarg(size_t) nsops; +}; + +struct sys_fhstat_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(struct stat *) sb; +}; + +struct sys___semctl_args { + syscallarg(int) semid; + syscallarg(int) semnum; + syscallarg(int) cmd; + syscallarg(union semun *) arg; +}; + +struct sys_shmctl_args { + syscallarg(int) shmid; + syscallarg(int) cmd; + syscallarg(struct shmid_ds *) buf; +}; + +struct sys_msgctl_args { + syscallarg(int) msqid; + syscallarg(int) cmd; + syscallarg(struct msqid_ds *) buf; +}; + +struct sys___thrwakeup_args { + syscallarg(const volatile void *) ident; + syscallarg(int) n; +}; + +struct sys___threxit_args { + syscallarg(pid_t *) notdead; +}; + +struct sys___thrsigdivert_args { + syscallarg(sigset_t) sigmask; + syscallarg(siginfo_t *) info; + syscallarg(const struct timespec *) timeout; +}; + +struct sys___getcwd_args { + syscallarg(char *) buf; + syscallarg(size_t) len; +}; + +struct sys_adjfreq_args { + syscallarg(const int64_t *) freq; + syscallarg(int64_t *) oldfreq; +}; + +struct sys_setrtable_args { + syscallarg(int) rtableid; +}; + +struct sys_faccessat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) amode; + syscallarg(int) flag; +}; + +struct sys_fchmodat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(int) flag; +}; + +struct sys_fchownat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; + syscallarg(int) flag; +}; + +struct sys_linkat_args { + syscallarg(int) fd1; + syscallarg(const char *) path1; + syscallarg(int) fd2; + syscallarg(const char *) path2; + syscallarg(int) flag; +}; + +struct sys_mkdirat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_mkfifoat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_mknodat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(dev_t) dev; +}; + +struct sys_openat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(mode_t) mode; +}; + +struct sys_readlinkat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(char *) buf; + syscallarg(size_t) count; +}; + +struct sys_renameat_args { + syscallarg(int) fromfd; + syscallarg(const char *) from; + syscallarg(int) tofd; + syscallarg(const char *) to; +}; + +struct sys_symlinkat_args { + syscallarg(const char *) path; + syscallarg(int) fd; + syscallarg(const char *) link; +}; + +struct sys_unlinkat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) flag; +}; + +struct sys___set_tcb_args { + syscallarg(void *) tcb; +}; + +/* + * System call prototypes. + */ + +int sys_exit(struct proc *, void *, register_t *); +int sys_fork(struct proc *, void *, register_t *); +int sys_read(struct proc *, void *, register_t *); +int sys_write(struct proc *, void *, register_t *); +int sys_open(struct proc *, void *, register_t *); +int sys_close(struct proc *, void *, register_t *); +int sys_getentropy(struct proc *, void *, register_t *); +int sys___tfork(struct proc *, void *, register_t *); +int sys_link(struct proc *, void *, register_t *); +int sys_unlink(struct proc *, void *, register_t *); +int sys_wait4(struct proc *, void *, register_t *); +int sys_chdir(struct proc *, void *, register_t *); +int sys_fchdir(struct proc *, void *, register_t *); +int sys_mknod(struct proc *, void *, register_t *); +int sys_chmod(struct proc *, void *, register_t *); +int sys_chown(struct proc *, void *, register_t *); +int sys_obreak(struct proc *, void *, register_t *); +int sys_getdtablecount(struct proc *, void *, register_t *); +int sys_getrusage(struct proc *, void *, register_t *); +int sys_getpid(struct proc *, void *, register_t *); +int sys_mount(struct proc *, void *, register_t *); +int sys_unmount(struct proc *, void *, register_t *); +int sys_setuid(struct proc *, void *, register_t *); +int sys_getuid(struct proc *, void *, register_t *); +int sys_geteuid(struct proc *, void *, register_t *); +#ifdef PTRACE +int sys_ptrace(struct proc *, void *, register_t *); +#else +#endif +int sys_recvmsg(struct proc *, void *, register_t *); +int sys_sendmsg(struct proc *, void *, register_t *); +int sys_recvfrom(struct proc *, void *, register_t *); +int sys_accept(struct proc *, void *, register_t *); +int sys_getpeername(struct proc *, void *, register_t *); +int sys_getsockname(struct proc *, void *, register_t *); +int sys_access(struct proc *, void *, register_t *); +int sys_chflags(struct proc *, void *, register_t *); +int sys_fchflags(struct proc *, void *, register_t *); +int sys_sync(struct proc *, void *, register_t *); +int sys_msyscall(struct proc *, void *, register_t *); +int sys_stat(struct proc *, void *, register_t *); +int sys_getppid(struct proc *, void *, register_t *); +int sys_lstat(struct proc *, void *, register_t *); +int sys_dup(struct proc *, void *, register_t *); +int sys_fstatat(struct proc *, void *, register_t *); +int sys_getegid(struct proc *, void *, register_t *); +int sys_profil(struct proc *, void *, register_t *); +#ifdef KTRACE +int sys_ktrace(struct proc *, void *, register_t *); +#else +#endif +int sys_sigaction(struct proc *, void *, register_t *); +int sys_getgid(struct proc *, void *, register_t *); +int sys_sigprocmask(struct proc *, void *, register_t *); +int sys_setlogin(struct proc *, void *, register_t *); +#ifdef ACCOUNTING +int sys_acct(struct proc *, void *, register_t *); +#else +#endif +int sys_sigpending(struct proc *, void *, register_t *); +int sys_fstat(struct proc *, void *, register_t *); +int sys_ioctl(struct proc *, void *, register_t *); +int sys_reboot(struct proc *, void *, register_t *); +int sys_revoke(struct proc *, void *, register_t *); +int sys_symlink(struct proc *, void *, register_t *); +int sys_readlink(struct proc *, void *, register_t *); +int sys_execve(struct proc *, void *, register_t *); +int sys_umask(struct proc *, void *, register_t *); +int sys_chroot(struct proc *, void *, register_t *); +int sys_getfsstat(struct proc *, void *, register_t *); +int sys_statfs(struct proc *, void *, register_t *); +int sys_fstatfs(struct proc *, void *, register_t *); +int sys_fhstatfs(struct proc *, void *, register_t *); +int sys_vfork(struct proc *, void *, register_t *); +int sys_gettimeofday(struct proc *, void *, register_t *); +int sys_settimeofday(struct proc *, void *, register_t *); +int sys_setitimer(struct proc *, void *, register_t *); +int sys_getitimer(struct proc *, void *, register_t *); +int sys_select(struct proc *, void *, register_t *); +int sys_kevent(struct proc *, void *, register_t *); +int sys_munmap(struct proc *, void *, register_t *); +int sys_mprotect(struct proc *, void *, register_t *); +int sys_madvise(struct proc *, void *, register_t *); +int sys_utimes(struct proc *, void *, register_t *); +int sys_futimes(struct proc *, void *, register_t *); +int sys_getgroups(struct proc *, void *, register_t *); +int sys_setgroups(struct proc *, void *, register_t *); +int sys_getpgrp(struct proc *, void *, register_t *); +int sys_setpgid(struct proc *, void *, register_t *); +int sys_futex(struct proc *, void *, register_t *); +int sys_utimensat(struct proc *, void *, register_t *); +int sys_futimens(struct proc *, void *, register_t *); +int sys_kbind(struct proc *, void *, register_t *); +int sys_clock_gettime(struct proc *, void *, register_t *); +int sys_clock_settime(struct proc *, void *, register_t *); +int sys_clock_getres(struct proc *, void *, register_t *); +int sys_dup2(struct proc *, void *, register_t *); +int sys_nanosleep(struct proc *, void *, register_t *); +int sys_fcntl(struct proc *, void *, register_t *); +int sys_accept4(struct proc *, void *, register_t *); +int sys___thrsleep(struct proc *, void *, register_t *); +int sys_fsync(struct proc *, void *, register_t *); +int sys_setpriority(struct proc *, void *, register_t *); +int sys_socket(struct proc *, void *, register_t *); +int sys_connect(struct proc *, void *, register_t *); +int sys_getdents(struct proc *, void *, register_t *); +int sys_getpriority(struct proc *, void *, register_t *); +int sys_pipe2(struct proc *, void *, register_t *); +int sys_dup3(struct proc *, void *, register_t *); +int sys_sigreturn(struct proc *, void *, register_t *); +int sys_bind(struct proc *, void *, register_t *); +int sys_setsockopt(struct proc *, void *, register_t *); +int sys_listen(struct proc *, void *, register_t *); +int sys_chflagsat(struct proc *, void *, register_t *); +int sys_pledge(struct proc *, void *, register_t *); +int sys_ppoll(struct proc *, void *, register_t *); +int sys_pselect(struct proc *, void *, register_t *); +int sys_sigsuspend(struct proc *, void *, register_t *); +int sys_sendsyslog(struct proc *, void *, register_t *); +int sys_unveil(struct proc *, void *, register_t *); +int sys___realpath(struct proc *, void *, register_t *); +int sys_getsockopt(struct proc *, void *, register_t *); +int sys_thrkill(struct proc *, void *, register_t *); +int sys_readv(struct proc *, void *, register_t *); +int sys_writev(struct proc *, void *, register_t *); +int sys_kill(struct proc *, void *, register_t *); +int sys_fchown(struct proc *, void *, register_t *); +int sys_fchmod(struct proc *, void *, register_t *); +int sys_setreuid(struct proc *, void *, register_t *); +int sys_setregid(struct proc *, void *, register_t *); +int sys_rename(struct proc *, void *, register_t *); +int sys_flock(struct proc *, void *, register_t *); +int sys_mkfifo(struct proc *, void *, register_t *); +int sys_sendto(struct proc *, void *, register_t *); +int sys_shutdown(struct proc *, void *, register_t *); +int sys_socketpair(struct proc *, void *, register_t *); +int sys_mkdir(struct proc *, void *, register_t *); +int sys_rmdir(struct proc *, void *, register_t *); +int sys_adjtime(struct proc *, void *, register_t *); +int sys_getlogin_r(struct proc *, void *, register_t *); +int sys_setsid(struct proc *, void *, register_t *); +int sys_quotactl(struct proc *, void *, register_t *); +#if defined(NFSCLIENT) || defined(NFSSERVER) +int sys_nfssvc(struct proc *, void *, register_t *); +#else +#endif +int sys_getfh(struct proc *, void *, register_t *); +int sys___tmpfd(struct proc *, void *, register_t *); +int sys_sysarch(struct proc *, void *, register_t *); +int sys_pread(struct proc *, void *, register_t *); +int sys_pwrite(struct proc *, void *, register_t *); +int sys_setgid(struct proc *, void *, register_t *); +int sys_setegid(struct proc *, void *, register_t *); +int sys_seteuid(struct proc *, void *, register_t *); +int sys_pathconf(struct proc *, void *, register_t *); +int sys_fpathconf(struct proc *, void *, register_t *); +int sys_swapctl(struct proc *, void *, register_t *); +int sys_getrlimit(struct proc *, void *, register_t *); +int sys_setrlimit(struct proc *, void *, register_t *); +int sys_mmap(struct proc *, void *, register_t *); +int sys_lseek(struct proc *, void *, register_t *); +int sys_truncate(struct proc *, void *, register_t *); +int sys_ftruncate(struct proc *, void *, register_t *); +int sys_sysctl(struct proc *, void *, register_t *); +int sys_mlock(struct proc *, void *, register_t *); +int sys_munlock(struct proc *, void *, register_t *); +int sys_getpgid(struct proc *, void *, register_t *); +int sys_utrace(struct proc *, void *, register_t *); +#ifdef SYSVSEM +int sys_semget(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVMSG +int sys_msgget(struct proc *, void *, register_t *); +int sys_msgsnd(struct proc *, void *, register_t *); +int sys_msgrcv(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSHM +int sys_shmat(struct proc *, void *, register_t *); +int sys_shmdt(struct proc *, void *, register_t *); +#else +#endif +int sys_minherit(struct proc *, void *, register_t *); +int sys_poll(struct proc *, void *, register_t *); +int sys_issetugid(struct proc *, void *, register_t *); +int sys_lchown(struct proc *, void *, register_t *); +int sys_getsid(struct proc *, void *, register_t *); +int sys_msync(struct proc *, void *, register_t *); +int sys_pipe(struct proc *, void *, register_t *); +int sys_fhopen(struct proc *, void *, register_t *); +int sys_preadv(struct proc *, void *, register_t *); +int sys_pwritev(struct proc *, void *, register_t *); +int sys_kqueue(struct proc *, void *, register_t *); +int sys_mlockall(struct proc *, void *, register_t *); +int sys_munlockall(struct proc *, void *, register_t *); +int sys_getresuid(struct proc *, void *, register_t *); +int sys_setresuid(struct proc *, void *, register_t *); +int sys_getresgid(struct proc *, void *, register_t *); +int sys_setresgid(struct proc *, void *, register_t *); +int sys_mquery(struct proc *, void *, register_t *); +int sys_closefrom(struct proc *, void *, register_t *); +int sys_sigaltstack(struct proc *, void *, register_t *); +#ifdef SYSVSHM +int sys_shmget(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSEM +int sys_semop(struct proc *, void *, register_t *); +#else +#endif +int sys_fhstat(struct proc *, void *, register_t *); +#ifdef SYSVSEM +int sys___semctl(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSHM +int sys_shmctl(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVMSG +int sys_msgctl(struct proc *, void *, register_t *); +#else +#endif +int sys_sched_yield(struct proc *, void *, register_t *); +int sys_getthrid(struct proc *, void *, register_t *); +int sys___thrwakeup(struct proc *, void *, register_t *); +int sys___threxit(struct proc *, void *, register_t *); +int sys___thrsigdivert(struct proc *, void *, register_t *); +int sys___getcwd(struct proc *, void *, register_t *); +int sys_adjfreq(struct proc *, void *, register_t *); +int sys_setrtable(struct proc *, void *, register_t *); +int sys_getrtable(struct proc *, void *, register_t *); +int sys_faccessat(struct proc *, void *, register_t *); +int sys_fchmodat(struct proc *, void *, register_t *); +int sys_fchownat(struct proc *, void *, register_t *); +int sys_linkat(struct proc *, void *, register_t *); +int sys_mkdirat(struct proc *, void *, register_t *); +int sys_mkfifoat(struct proc *, void *, register_t *); +int sys_mknodat(struct proc *, void *, register_t *); +int sys_openat(struct proc *, void *, register_t *); +int sys_readlinkat(struct proc *, void *, register_t *); +int sys_renameat(struct proc *, void *, register_t *); +int sys_symlinkat(struct proc *, void *, register_t *); +int sys_unlinkat(struct proc *, void *, register_t *); +int sys___set_tcb(struct proc *, void *, register_t *); +int sys___get_tcb(struct proc *, void *, register_t *); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h new file mode 100644 index 0000000..9e2fc55 --- /dev/null +++ b/sys/sys/sysctl.h @@ -0,0 +1,1061 @@ +/* $OpenBSD: sysctl.h,v 1.205 2020/03/13 10:07:01 anton Exp $ */ +/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Karels at 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. + * + * @(#)sysctl.h 8.2 (Berkeley) 3/30/95 + */ + +#ifndef _SYS_SYSCTL_H_ +#define _SYS_SYSCTL_H_ + +#include <uvm/uvmexp.h> + +/* + * Definitions for sysctl call. The sysctl call uses a hierarchical name + * for objects that can be examined or modified. The name is expressed as + * a sequence of integers. Like a file path name, the meaning of each + * component depends on its place in the hierarchy. The top-level and kern + * identifiers are defined here, and other identifiers are defined in the + * respective subsystem header files. + */ + +#define CTL_MAXNAME 12 /* largest number of components supported */ + +/* + * Each subsystem defined by sysctl defines a list of variables + * for that subsystem. Each name is either a node with further + * levels defined below it, or it is a leaf of some particular + * type given below. Each sysctl level defines a set of name/type + * pairs to be used by sysctl(1) in manipulating the subsystem. + */ +struct ctlname { + char *ctl_name; /* subsystem name */ + int ctl_type; /* type of name */ +}; +#define CTLTYPE_NODE 1 /* name is a node */ +#define CTLTYPE_INT 2 /* name describes an integer */ +#define CTLTYPE_STRING 3 /* name describes a string */ +#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */ +#define CTLTYPE_STRUCT 5 /* name describes a structure */ + +/* + * Top-level identifiers + */ +#define CTL_UNSPEC 0 /* unused */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +#define CTL_FS 3 /* file system, mount type is next */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +/*define gap 8 was CTL_USER: removed 2013-04 */ +#define CTL_DDB 9 /* DDB user interface, see db_var.h */ +#define CTL_VFS 10 /* VFS sysctl's */ +#define CTL_MAXID 11 /* number of valid top-level ids */ + +#define CTL_NAMES { \ + { 0, 0 }, \ + { "kern", CTLTYPE_NODE }, \ + { "vm", CTLTYPE_NODE }, \ + { "fs", CTLTYPE_NODE }, \ + { "net", CTLTYPE_NODE }, \ + { "debug", CTLTYPE_NODE }, \ + { "hw", CTLTYPE_NODE }, \ + { "machdep", CTLTYPE_NODE }, \ + { "gap", 0 }, \ + { "ddb", CTLTYPE_NODE }, \ + { "vfs", CTLTYPE_NODE }, \ +} + +/* + * CTL_KERN identifiers + */ +#define KERN_OSTYPE 1 /* string: system version */ +#define KERN_OSRELEASE 2 /* string: system release */ +#define KERN_OSREV 3 /* int: system revision */ +#define KERN_VERSION 4 /* string: compile time info */ +#define KERN_MAXVNODES 5 /* int: max vnodes */ +#define KERN_MAXPROC 6 /* int: max processes */ +#define KERN_MAXFILES 7 /* int: max open files */ +#define KERN_ARGMAX 8 /* int: max arguments to exec */ +#define KERN_SECURELVL 9 /* int: system security level */ +#define KERN_HOSTNAME 10 /* string: hostname */ +#define KERN_HOSTID 11 /* int: host identifier */ +#define KERN_CLOCKRATE 12 /* struct: struct clockinfo */ +/* was KERN_DNSJACKPORT 13 */ +/* was KERN_PROC 14 */ +/* was KERN_FILE 15 */ +#define KERN_PROF 16 /* node: kernel profiling info */ +#define KERN_POSIX1 17 /* int: POSIX.1 version */ +#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ +#define KERN_JOB_CONTROL 19 /* int: is job control available */ +#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ +#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ +#define KERN_DOMAINNAME 22 /* string: (YP) domainname */ +#define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */ +#define KERN_RAWPARTITION 24 /* int: raw partition number */ +#define KERN_MAXTHREAD 25 /* int: max threads */ +#define KERN_NTHREADS 26 /* int: number of threads */ +#define KERN_OSVERSION 27 /* string: kernel build version */ +#define KERN_SOMAXCONN 28 /* int: listen queue maximum */ +#define KERN_SOMINCONN 29 /* int: half-open controllable param */ +/* was KERN_USERMOUNT 30 */ +/* was KERN_RND 31 */ +#define KERN_NOSUIDCOREDUMP 32 /* int: no setuid coredumps ever */ +#define KERN_FSYNC 33 /* int: file synchronization support */ +#define KERN_SYSVMSG 34 /* int: SysV message queue suppoprt */ +#define KERN_SYSVSEM 35 /* int: SysV semaphore support */ +#define KERN_SYSVSHM 36 /* int: SysV shared memory support */ +/* was KERN_ARND 37 */ +#define KERN_MSGBUFSIZE 38 /* int: size of message buffer */ +#define KERN_MALLOCSTATS 39 /* node: malloc statistics */ +#define KERN_CPTIME 40 /* array: cp_time */ +#define KERN_NCHSTATS 41 /* struct: vfs cache statistics */ +#define KERN_FORKSTAT 42 /* struct: fork statistics */ +#define KERN_NSELCOLL 43 /* int: select(2) collisions */ +#define KERN_TTY 44 /* node: tty information */ +#define KERN_CCPU 45 /* int: ccpu */ +#define KERN_FSCALE 46 /* int: fscale */ +#define KERN_NPROCS 47 /* int: number of processes */ +#define KERN_MSGBUF 48 /* message buffer, KERN_MSGBUFSIZE */ +#define KERN_POOL 49 /* struct: pool information */ +#define KERN_STACKGAPRANDOM 50 /* int: stackgap_random */ +#define KERN_SYSVIPC_INFO 51 /* struct: SysV sem/shm/msg info */ +#define KERN_ALLOWKMEM 52 /* int: allowkmem */ +#define KERN_WITNESSWATCH 53 /* int: witnesswatch */ +#define KERN_SPLASSERT 54 /* int: splassert */ +#define KERN_PROC_ARGS 55 /* node: proc args and env */ +#define KERN_NFILES 56 /* int: number of open files */ +#define KERN_TTYCOUNT 57 /* int: number of tty devices */ +#define KERN_NUMVNODES 58 /* int: number of vnodes in use */ +#define KERN_MBSTAT 59 /* struct: mbuf statistics */ +#define KERN_WITNESS 60 /* node: witness */ +#define KERN_SEMINFO 61 /* struct: SysV struct seminfo */ +#define KERN_SHMINFO 62 /* struct: SysV struct shminfo */ +#define KERN_INTRCNT 63 /* node: interrupt counters */ +#define KERN_WATCHDOG 64 /* node: watchdog */ +#define KERN_ALLOWDT 65 /* int: allowdt */ +#define KERN_PROC 66 /* struct: process entries */ +#define KERN_MAXCLUSTERS 67 /* number of mclusters */ +#define KERN_EVCOUNT 68 /* node: event counters */ +#define KERN_TIMECOUNTER 69 /* node: timecounter */ +#define KERN_MAXLOCKSPERUID 70 /* int: locks per uid */ +#define KERN_CPTIME2 71 /* array: cp_time2 */ +#define KERN_CACHEPCT 72 /* buffer cache % of physmem */ +#define KERN_FILE 73 /* struct: file entries */ +#define KERN_WXABORT 74 /* int: w^x sigabrt & core */ +#define KERN_CONSDEV 75 /* dev_t: console terminal device */ +#define KERN_NETLIVELOCKS 76 /* int: number of network livelocks */ +#define KERN_POOL_DEBUG 77 /* int: enable pool_debug */ +#define KERN_PROC_CWD 78 /* node: proc cwd */ +#define KERN_PROC_NOBROADCASTKILL 79 /* node: proc no broadcast kill */ +#define KERN_PROC_VMMAP 80 /* node: proc vmmap */ +#define KERN_GLOBAL_PTRACE 81 /* allow ptrace globally */ +#define KERN_CONSBUFSIZE 82 /* int: console message buffer size */ +#define KERN_CONSBUF 83 /* console message buffer */ +#define KERN_AUDIO 84 /* struct: audio properties */ +#define KERN_CPUSTATS 85 /* struct: cpu statistics */ +#define KERN_PFSTATUS 86 /* struct: pf status and stats */ +#define KERN_TIMEOUT_STATS 87 /* struct: timeout status and stats */ +#define KERN_UTC_OFFSET 88 /* int: adjust RTC time to UTC */ +#define KERN_MAXID 89 /* number of valid kern ids */ + +#define CTL_KERN_NAMES { \ + { 0, 0 }, \ + { "ostype", CTLTYPE_STRING }, \ + { "osrelease", CTLTYPE_STRING }, \ + { "osrevision", CTLTYPE_INT }, \ + { "version", CTLTYPE_STRING }, \ + { "maxvnodes", CTLTYPE_INT }, \ + { "maxproc", CTLTYPE_INT }, \ + { "maxfiles", CTLTYPE_INT }, \ + { "argmax", CTLTYPE_INT }, \ + { "securelevel", CTLTYPE_INT }, \ + { "hostname", CTLTYPE_STRING }, \ + { "hostid", CTLTYPE_INT }, \ + { "clockrate", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "profiling", CTLTYPE_NODE }, \ + { "posix1version", CTLTYPE_INT }, \ + { "ngroups", CTLTYPE_INT }, \ + { "job_control", CTLTYPE_INT }, \ + { "saved_ids", CTLTYPE_INT }, \ + { "boottime", CTLTYPE_STRUCT }, \ + { "domainname", CTLTYPE_STRING }, \ + { "maxpartitions", CTLTYPE_INT }, \ + { "rawpartition", CTLTYPE_INT }, \ + { "maxthread", CTLTYPE_INT }, \ + { "nthreads", CTLTYPE_INT }, \ + { "osversion", CTLTYPE_STRING }, \ + { "somaxconn", CTLTYPE_INT }, \ + { "sominconn", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "nosuidcoredump", CTLTYPE_INT }, \ + { "fsync", CTLTYPE_INT }, \ + { "sysvmsg", CTLTYPE_INT }, \ + { "sysvsem", CTLTYPE_INT }, \ + { "sysvshm", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "msgbufsize", CTLTYPE_INT }, \ + { "malloc", CTLTYPE_NODE }, \ + { "cp_time", CTLTYPE_STRUCT }, \ + { "nchstats", CTLTYPE_STRUCT }, \ + { "forkstat", CTLTYPE_STRUCT }, \ + { "nselcoll", CTLTYPE_INT }, \ + { "tty", CTLTYPE_NODE }, \ + { "ccpu", CTLTYPE_INT }, \ + { "fscale", CTLTYPE_INT }, \ + { "nprocs", CTLTYPE_INT }, \ + { "msgbuf", CTLTYPE_STRUCT }, \ + { "pool", CTLTYPE_NODE }, \ + { "stackgap_random", CTLTYPE_INT }, \ + { "sysvipc_info", CTLTYPE_INT }, \ + { "allowkmem", CTLTYPE_INT }, \ + { "witnesswatch", CTLTYPE_INT }, \ + { "splassert", CTLTYPE_INT }, \ + { "procargs", CTLTYPE_NODE }, \ + { "nfiles", CTLTYPE_INT }, \ + { "ttycount", CTLTYPE_INT }, \ + { "numvnodes", CTLTYPE_INT }, \ + { "mbstat", CTLTYPE_STRUCT }, \ + { "witness", CTLTYPE_NODE }, \ + { "seminfo", CTLTYPE_STRUCT }, \ + { "shminfo", CTLTYPE_STRUCT }, \ + { "intrcnt", CTLTYPE_NODE }, \ + { "watchdog", CTLTYPE_NODE }, \ + { "allowdt", CTLTYPE_INT }, \ + { "proc", CTLTYPE_STRUCT }, \ + { "maxclusters", CTLTYPE_INT }, \ + { "evcount", CTLTYPE_NODE }, \ + { "timecounter", CTLTYPE_NODE }, \ + { "maxlocksperuid", CTLTYPE_INT }, \ + { "cp_time2", CTLTYPE_STRUCT }, \ + { "bufcachepercent", CTLTYPE_INT }, \ + { "file", CTLTYPE_STRUCT }, \ + { "wxabort", CTLTYPE_INT }, \ + { "consdev", CTLTYPE_STRUCT }, \ + { "netlivelocks", CTLTYPE_INT }, \ + { "pool_debug", CTLTYPE_INT }, \ + { "proc_cwd", CTLTYPE_NODE }, \ + { "proc_nobroadcastkill", CTLTYPE_NODE }, \ + { "proc_vmmap", CTLTYPE_NODE }, \ + { "global_ptrace", CTLTYPE_INT }, \ + { "consbufsize", CTLTYPE_INT }, \ + { "consbuf", CTLTYPE_STRUCT }, \ + { "audio", CTLTYPE_STRUCT }, \ + { "cpustats", CTLTYPE_STRUCT }, \ + { "pfstatus", CTLTYPE_STRUCT }, \ + { "timeout_stats", CTLTYPE_STRUCT }, \ + { "utc_offset", CTLTYPE_INT }, \ +} + +/* + * KERN_PROC subtypes + */ +#define KERN_PROC_ALL 0 /* everything but kernel threads */ +#define KERN_PROC_PID 1 /* by process id */ +#define KERN_PROC_PGRP 2 /* by process group id */ +#define KERN_PROC_SESSION 3 /* by session of pid */ +#define KERN_PROC_TTY 4 /* by controlling tty */ +#define KERN_PROC_UID 5 /* by effective uid */ +#define KERN_PROC_RUID 6 /* by real uid */ +#define KERN_PROC_KTHREAD 7 /* also return kernel threads */ +#define KERN_PROC_SHOW_THREADS 0x40000000/* also return normal threads */ + +/* + * KERN_SYSVIPC_INFO subtypes + */ +#define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */ +#define KERN_SYSVIPC_SEM_INFO 2 /* seminfo and semid_ds */ +#define KERN_SYSVIPC_SHM_INFO 3 /* shminfo and shmid_ds */ + +/* + * KERN_PROC_ARGS subtypes + */ +#define KERN_PROC_ARGV 1 +#define KERN_PROC_NARGV 2 +#define KERN_PROC_ENV 3 +#define KERN_PROC_NENV 4 + +/* + * KERN_AUDIO + */ +#define KERN_AUDIO_RECORD 1 +#define KERN_AUDIO_MAXID 2 + +#define CTL_KERN_AUDIO_NAMES { \ + { 0, 0 }, \ + { "record", CTLTYPE_INT }, \ +} + +/* + * KERN_WITNESS + */ +#define KERN_WITNESS_WATCH 1 /* int: operating mode */ +#define KERN_WITNESS_LOCKTRACE 2 /* int: stack trace saving mode */ +#define KERN_WITNESS_MAXID 3 + +#define CTL_KERN_WITNESS_NAMES { \ + { 0, 0 }, \ + { "watch", CTLTYPE_INT }, \ + { "locktrace", CTLTYPE_INT }, \ +} + +/* + * KERN_PROC subtype ops return arrays of relatively fixed size + * structures of process info. Use 8 byte alignment, and new + * elements should only be added to the end of this structure so + * binary compatibility can be preserved. + */ +#define KI_NGROUPS 16 +#define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */ +#define KI_WMESGLEN 8 +#define KI_MAXLOGNAME 32 +#define KI_EMULNAMELEN 8 + +#define KI_NOCPU (~(u_int64_t)0) + +struct kinfo_proc { + u_int64_t p_forw; /* PTR: linked run/sleep queue. */ + u_int64_t p_back; + u_int64_t p_paddr; /* PTR: address of proc */ + + u_int64_t p_addr; /* PTR: Kernel virtual addr of u-area */ + u_int64_t p_fd; /* PTR: Ptr to open files structure. */ + u_int64_t p_stats; /* unused, always zero. */ + u_int64_t p_limit; /* PTR: Process limits. */ + u_int64_t p_vmspace; /* PTR: Address space. */ + u_int64_t p_sigacts; /* PTR: Signal actions, state */ + u_int64_t p_sess; /* PTR: session pointer */ + u_int64_t p_tsess; /* PTR: tty session pointer */ + u_int64_t p_ru; /* PTR: Exit information. XXX */ + + int32_t p_eflag; /* LONG: extra kinfo_proc flags */ +#define EPROC_CTTY 0x01 /* controlling tty vnode active */ +#define EPROC_SLEADER 0x02 /* session leader */ +#define EPROC_UNVEIL 0x04 /* has unveil settings */ +#define EPROC_LKUNVEIL 0x08 /* unveil is locked */ + int32_t p_exitsig; /* unused, always zero. */ + int32_t p_flag; /* INT: P_* flags. */ + + int32_t p_pid; /* PID_T: Process identifier. */ + int32_t p_ppid; /* PID_T: Parent process id */ + int32_t p_sid; /* PID_T: session id */ + int32_t p__pgid; /* PID_T: process group id */ + /* XXX: <sys/proc.h> hijacks p_pgid */ + int32_t p_tpgid; /* PID_T: tty process group id */ + + u_int32_t p_uid; /* UID_T: effective user id */ + u_int32_t p_ruid; /* UID_T: real user id */ + u_int32_t p_gid; /* GID_T: effective group id */ + u_int32_t p_rgid; /* GID_T: real group id */ + + u_int32_t p_groups[KI_NGROUPS]; /* GID_T: groups */ + int16_t p_ngroups; /* SHORT: number of groups */ + + int16_t p_jobc; /* SHORT: job control counter */ + u_int32_t p_tdev; /* DEV_T: controlling tty dev */ + + u_int32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */ + u_int32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */ + u_int32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */ + int32_t p_cpticks; /* INT: Ticks of cpu time. */ + u_int32_t p_pctcpu; /* FIXPT_T: %cpu for this process */ + u_int32_t p_swtime; /* unused, always zero */ + u_int32_t p_slptime; /* U_INT: Time since last blocked. */ + int32_t p_schedflags; /* INT: PSCHED_* flags */ + + u_int64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */ + u_int64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */ + u_int64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */ + + u_int64_t p_tracep; /* PTR: Trace to vnode or file */ + int32_t p_traceflag; /* INT: Kernel trace points. */ + + int32_t p_holdcnt; /* INT: If non-zero, don't swap. */ + + int32_t p_siglist; /* INT: Signals arrived but not delivered. */ + u_int32_t p_sigmask; /* SIGSET_T: Current signal mask. */ + u_int32_t p_sigignore; /* SIGSET_T: Signals being ignored. */ + u_int32_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */ + + int8_t p_stat; /* CHAR: S* process status (from LWP). */ + u_int8_t p_priority; /* U_CHAR: Process priority. */ + u_int8_t p_usrpri; /* U_CHAR: User-priority based on p_estcpu and ps_nice. */ + u_int8_t p_nice; /* U_CHAR: Process "nice" value. */ + + u_int16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */ + u_int16_t p_acflag; /* U_SHORT: Accounting flags. */ + + char p_comm[KI_MAXCOMLEN]; + + char p_wmesg[KI_WMESGLEN]; /* wchan message */ + u_int64_t p_wchan; /* PTR: sleep address. */ + + char p_login[KI_MAXLOGNAME]; /* setlogin() name */ + + int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */ + int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */ + int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */ + int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */ + + int64_t p_uvalid; /* CHAR: following p_u* members from struct user are valid */ + /* XXX 64 bits for alignment */ + u_int64_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */ + u_int32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */ + + u_int32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */ + u_int32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */ + u_int32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */ + u_int32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */ + + u_int64_t p_uru_maxrss; /* LONG: max resident set size. */ + u_int64_t p_uru_ixrss; /* LONG: integral shared memory size. */ + u_int64_t p_uru_idrss; /* LONG: integral unshared data ". */ + u_int64_t p_uru_isrss; /* LONG: integral unshared stack ". */ + u_int64_t p_uru_minflt; /* LONG: page reclaims. */ + u_int64_t p_uru_majflt; /* LONG: page faults. */ + u_int64_t p_uru_nswap; /* LONG: swaps. */ + u_int64_t p_uru_inblock; /* LONG: block input operations. */ + u_int64_t p_uru_oublock; /* LONG: block output operations. */ + u_int64_t p_uru_msgsnd; /* LONG: messages sent. */ + u_int64_t p_uru_msgrcv; /* LONG: messages received. */ + u_int64_t p_uru_nsignals; /* LONG: signals received. */ + u_int64_t p_uru_nvcsw; /* LONG: voluntary context switches. */ + u_int64_t p_uru_nivcsw; /* LONG: involuntary ". */ + + u_int32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */ + u_int32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */ + u_int32_t p_psflags; /* UINT: PS_* flags on the process. */ + int32_t p_spare; /* INT: unused. */ + u_int32_t p_svuid; /* UID_T: saved user id */ + u_int32_t p_svgid; /* GID_T: saved group id */ + char p_emul[KI_EMULNAMELEN]; /* syscall emulation name */ + u_int64_t p_rlim_rss_cur; /* RLIM_T: soft limit for rss */ + u_int64_t p_cpuid; /* LONG: CPU id */ + u_int64_t p_vm_map_size; /* VSIZE_T: virtual size */ + int32_t p_tid; /* PID_T: Thread identifier. */ + u_int32_t p_rtableid; /* U_INT: Routing table identifier. */ + + u_int64_t p_pledge; /* U_INT64_T: Pledge flags. */ +}; + +/* + * VM address range entry, matching struct vm_map_entry. Useful for + * debuggers to know process's addresses. + * + * To iterate entries, set the last kve_end as the base address into + * kve_start. + */ +struct kinfo_vmentry { + u_long kve_start; /* vaddr_t */ + u_long kve_end; /* vaddr_t */ + u_long kve_guard; /* vsize_t */ + u_long kve_fspace; /* vsize_t */ + u_long kve_fspace_augment; /* vsize_t */ + u_int64_t kve_offset; /* voff_t */ + int kve_wired_count; + int kve_etype; + int kve_protection; + int kve_max_protection; + int kve_advice; + int kve_inheritance; + u_int8_t kve_flags; /* u_int8_t */ +}; + +/* keep in sync with UVM_ET_* */ +#define KVE_ET_OBJ 0x00000001 +#define KVE_ET_SUBMAP 0x00000002 +#define KVE_ET_COPYONWRITE 0x00000004 +#define KVE_ET_NEEDSCOPY 0x00000008 +#define KVE_ET_HOLE 0x00000010 +#define KVE_ET_NOFAULT 0x00000020 +#define KVE_ET_STACK 0x00000040 +#define KVE_ET_WC 0x00000080 +#define KVE_ET_CONCEAL 0x00000100 +#define KVE_ET_SYSCALL 0x00000200 +#define KVE_ET_FREEMAPPED 0x00000800 + +#define KVE_PROT_NONE 0x00000000 +#define KVE_PROT_READ 0x00000001 +#define KVE_PROT_WRITE 0x00000002 +#define KVE_PROT_EXEC 0x00000004 + +#define KVE_ADV_NORMAL 0x00000000 +#define KVE_ADV_RANDOM 0x00000001 +#define KVE_ADV_SEQUENTIAL 0x00000002 + +#define KVE_INH_SHARE 0x00000000 +#define KVE_INH_COPY 0x00000010 +#define KVE_INH_NONE 0x00000020 +#define KVE_INH_ZERO 0x00000030 + +#define KVE_F_STATIC 0x01 +#define KVE_F_KMEM 0x02 + +#if defined(_KERNEL) || defined(_LIBKVM) + +/* + * Macros for filling in the bulk of a kinfo_proc structure, used + * in the kernel to implement the KERN_PROC sysctl and in userland + * in libkvm to implement reading from kernel crashes. The macro + * arguments are all pointers; by name they are: + * kp - target kinfo_proc structure + * copy_str - a function or macro invoked as copy_str(dst,src,maxlen) + * that has strlcpy or memcpy semantics; the destination is + * pre-filled with zeros; for libkvm, src is a kvm address + * p - source struct proc + * pr - source struct process + * uc - source struct ucreds + * pg - source struct pgrp + * paddr - kernel address of the source struct proc + * praddr - kernel address of the source struct process + * sess - source struct session + * vm - source struct vmspace + * lim - source struct plimits + * sa - source struct sigacts + * There are some members that are not handled by these macros + * because they're too painful to generalize: p_ppid, p_sid, p_tdev, + * p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid + */ + +#if defined(_KERNEL) +#define PR_LOCK(pr) mtx_enter(&(pr)->ps_mtx) +#define PR_UNLOCK(pr) mtx_leave(&(pr)->ps_mtx) +#else +#define PR_LOCK(pr) /* nothing */ +#define PR_UNLOCK(pr) /* nothing */ +#endif + +#define _getcompatprio(_p) \ + ((_p)->p_stat == SRUN ? (_p)->p_runpri : \ + ((_p)->p_stat == SSLEEP) ? (_p)->p_slppri : (_p)->p_usrpri) + +#define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x)) + +#define FILL_KPROC(kp, copy_str, p, pr, uc, pg, paddr, \ + praddr, sess, vm, lim, sa, isthread, show_addresses) \ +do { \ + memset((kp), 0, sizeof(*(kp))); \ + \ + if (show_addresses) { \ + (kp)->p_paddr = PTRTOINT64(paddr); \ + (kp)->p_fd = PTRTOINT64((pr)->ps_fd); \ + (kp)->p_limit = PTRTOINT64((pr)->ps_limit); \ + (kp)->p_vmspace = PTRTOINT64((pr)->ps_vmspace); \ + (kp)->p_sigacts = PTRTOINT64((pr)->ps_sigacts); \ + (kp)->p_sess = PTRTOINT64((pg)->pg_session); \ + (kp)->p_ru = PTRTOINT64((pr)->ps_ru); \ + } \ + (kp)->p_stats = 0; \ + (kp)->p_exitsig = 0; \ + (kp)->p_flag = (p)->p_flag; \ + (kp)->p_pid = (pr)->ps_pid; \ + (kp)->p_psflags = (pr)->ps_flags; \ + \ + (kp)->p__pgid = (pg)->pg_id; \ + \ + (kp)->p_uid = (uc)->cr_uid; \ + (kp)->p_ruid = (uc)->cr_ruid; \ + (kp)->p_gid = (uc)->cr_gid; \ + (kp)->p_rgid = (uc)->cr_rgid; \ + (kp)->p_svuid = (uc)->cr_svuid; \ + (kp)->p_svgid = (uc)->cr_svgid; \ + \ + memcpy((kp)->p_groups, (uc)->cr_groups, \ + MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \ + (kp)->p_ngroups = (uc)->cr_ngroups; \ + \ + (kp)->p_jobc = (pg)->pg_jobc; \ + \ + (kp)->p_estcpu = (p)->p_estcpu; \ + if (isthread) { \ + (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_nsec/1000; \ + (kp)->p_tid = (p)->p_tid + THREAD_PID_OFFSET; \ + (kp)->p_uticks = (p)->p_tu.tu_uticks; \ + (kp)->p_sticks = (p)->p_tu.tu_sticks; \ + (kp)->p_iticks = (p)->p_tu.tu_iticks; \ + } else { \ + (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_nsec/1000; \ + (kp)->p_tid = -1; \ + (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \ + (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \ + (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \ + } \ + (kp)->p_cpticks = (p)->p_cpticks; \ + \ + if (show_addresses) \ + (kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp); \ + (kp)->p_traceflag = (pr)->ps_traceflag; \ + \ + (kp)->p_siglist = (p)->p_siglist | (pr)->ps_siglist; \ + (kp)->p_sigmask = (p)->p_sigmask; \ + (kp)->p_sigignore = (sa) ? (sa)->ps_sigignore : 0; \ + (kp)->p_sigcatch = (sa) ? (sa)->ps_sigcatch : 0; \ + \ + (kp)->p_stat = (p)->p_stat; \ + (kp)->p_nice = (pr)->ps_nice; \ + \ + (kp)->p_xstat = W_EXITCODE((pr)->ps_xexit, (pr)->ps_xsig); \ + (kp)->p_acflag = (pr)->ps_acflag; \ + (kp)->p_pledge = (pr)->ps_pledge; \ + \ + /* XXX depends on e_name being an array and not a pointer */ \ + copy_str((kp)->p_emul, (char *)(pr)->ps_emul + \ + offsetof(struct emul, e_name), sizeof((kp)->p_emul)); \ + strlcpy((kp)->p_comm, (pr)->ps_comm, sizeof((kp)->p_comm)); \ + strlcpy((kp)->p_login, (sess)->s_login, \ + MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \ + \ + if ((sess)->s_ttyvp) \ + (kp)->p_eflag |= EPROC_CTTY; \ + if ((pr)->ps_uvpaths) \ + (kp)->p_eflag |= EPROC_UNVEIL; \ + if ((pr)->ps_uvdone || \ + (((pr)->ps_flags & PS_PLEDGE) && \ + ((pr)->ps_pledge & PLEDGE_UNVEIL) == 0)) \ + (kp)->p_eflag |= EPROC_LKUNVEIL; \ + \ + if (((pr)->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0) { \ + if ((vm) != NULL) { \ + (kp)->p_vm_rssize = (vm)->vm_rssize; \ + (kp)->p_vm_tsize = (vm)->vm_tsize; \ + (kp)->p_vm_dsize = (vm)->vm_dused; \ + (kp)->p_vm_ssize = (vm)->vm_ssize; \ + } \ + (kp)->p_addr = PTRTOINT64((p)->p_addr); \ + (kp)->p_stat = (p)->p_stat; \ + (kp)->p_slptime = (p)->p_slptime; \ + (kp)->p_holdcnt = 1; \ + (kp)->p_priority = _getcompatprio(p); \ + (kp)->p_usrpri = (p)->p_usrpri; \ + if ((p)->p_wchan && (p)->p_wmesg) \ + copy_str((kp)->p_wmesg, (p)->p_wmesg, \ + sizeof((kp)->p_wmesg)); \ + if (show_addresses) \ + (kp)->p_wchan = PTRTOINT64((p)->p_wchan); \ + } \ + \ + PR_LOCK(pr); \ + if (lim) \ + (kp)->p_rlim_rss_cur = \ + (lim)->pl_rlimit[RLIMIT_RSS].rlim_cur; \ + PR_UNLOCK(pr); \ + \ + if (((pr)->ps_flags & PS_ZOMBIE) == 0) { \ + struct timeval tv; \ + \ + (kp)->p_uvalid = 1; \ + \ + (kp)->p_uru_maxrss = (p)->p_ru.ru_maxrss; \ + (kp)->p_uru_ixrss = (p)->p_ru.ru_ixrss; \ + (kp)->p_uru_idrss = (p)->p_ru.ru_idrss; \ + (kp)->p_uru_isrss = (p)->p_ru.ru_isrss; \ + (kp)->p_uru_minflt = (p)->p_ru.ru_minflt; \ + (kp)->p_uru_majflt = (p)->p_ru.ru_majflt; \ + (kp)->p_uru_nswap = (p)->p_ru.ru_nswap; \ + (kp)->p_uru_inblock = (p)->p_ru.ru_inblock; \ + (kp)->p_uru_oublock = (p)->p_ru.ru_oublock; \ + (kp)->p_uru_msgsnd = (p)->p_ru.ru_msgsnd; \ + (kp)->p_uru_msgrcv = (p)->p_ru.ru_msgrcv; \ + (kp)->p_uru_nsignals = (p)->p_ru.ru_nsignals; \ + (kp)->p_uru_nvcsw = (p)->p_ru.ru_nvcsw; \ + (kp)->p_uru_nivcsw = (p)->p_ru.ru_nivcsw; \ + \ + timeradd(&(pr)->ps_cru.ru_utime, \ + &(pr)->ps_cru.ru_stime, &tv); \ + (kp)->p_uctime_sec = tv.tv_sec; \ + (kp)->p_uctime_usec = tv.tv_usec; \ + } \ + \ + (kp)->p_cpuid = KI_NOCPU; \ + (kp)->p_rtableid = (pr)->ps_rtableid; \ +} while (0) + +#endif /* defined(_KERNEL) || defined(_LIBKVM) */ + + +/* + * kern.file returns an array of these structures, which are designed + * both to be immune to 32/64 bit emulation issues and to + * provide backwards compatibility. The order differs slightly from + * that of the real struct file, and some fields are taken from other + * structures (struct vnode, struct proc) in order to make the file + * information more useful. + */ +#define KERN_FILE_BYFILE 1 +#define KERN_FILE_BYPID 2 +#define KERN_FILE_BYUID 3 +#define KERN_FILESLOP 10 + +#define KERN_FILE_TEXT -1 +#define KERN_FILE_CDIR -2 +#define KERN_FILE_RDIR -3 +#define KERN_FILE_TRACE -4 + +#define KI_MNAMELEN 96 /* rounded up from 90 */ +#define KI_UNPPATHLEN 104 + +struct kinfo_file { + uint64_t f_fileaddr; /* PTR: address of struct file */ + uint32_t f_flag; /* UINT: flags (see fcntl.h) */ + uint32_t f_iflags; /* UINT: internal flags */ + uint32_t f_type; /* INT: descriptor type */ + uint32_t f_count; /* UINT: reference count */ + uint32_t f_msgcount; /* UINT: references from msg queue */ + uint32_t f_usecount; /* INT: number active users */ + uint64_t f_ucred; /* PTR: creds for descriptor */ + uint32_t f_uid; /* UID_T: descriptor credentials */ + uint32_t f_gid; /* GID_T: descriptor credentials */ + uint64_t f_ops; /* PTR: address of fileops */ + uint64_t f_offset; /* OFF_T: offset */ + uint64_t f_data; /* PTR: descriptor data */ + uint64_t f_rxfer; /* UINT64: number of read xfers */ + uint64_t f_rwfer; /* UINT64: number of write xfers */ + uint64_t f_seek; /* UINT64: number of seek operations */ + uint64_t f_rbytes; /* UINT64: total bytes read */ + uint64_t f_wbytes; /* UINT64: total bytes written */ + + /* information about the vnode associated with this file */ + uint64_t v_un; /* PTR: socket, specinfo, etc */ + uint32_t v_type; /* ENUM: vnode type */ + uint32_t v_tag; /* ENUM: type of underlying data */ + uint32_t v_flag; /* UINT: vnode flags */ + uint32_t va_rdev; /* DEV_T: raw device */ + uint64_t v_data; /* PTR: private data for fs */ + uint64_t v_mount; /* PTR: mount info for fs */ + uint64_t va_fileid; /* LONG: file id */ + uint64_t va_size; /* UINT64_T: file size in bytes */ + uint32_t va_mode; /* MODE_T: file access mode and type */ + uint32_t va_fsid; /* DEV_T: filesystem device */ + char f_mntonname[KI_MNAMELEN]; + + /* socket information */ + uint32_t so_type; /* SHORT: socket type */ + uint32_t so_state; /* SHORT: socket state */ + uint64_t so_pcb; /* PTR: socket pcb */ + /* for non-root: -1 if not NULL */ + uint32_t so_protocol; /* SHORT: socket protocol type */ + uint32_t so_family; /* INT: socket domain family */ + uint64_t inp_ppcb; /* PTR: pointer to per-protocol pcb */ + uint32_t inp_lport; /* SHORT: local inet port */ + uint32_t inp_laddru[4]; /* STRUCT: local inet addr */ + uint32_t inp_fport; /* SHORT: foreign inet port */ + uint32_t inp_faddru[4]; /* STRUCT: foreign inet addr */ + uint64_t unp_conn; /* PTR: connected socket cntrl block */ + + /* pipe information */ + uint64_t pipe_peer; /* PTR: link with other direction */ + uint32_t pipe_state; /* UINT: pipe status info */ + + /* kqueue information */ + uint32_t kq_count; /* INT: number of pending events */ + uint32_t kq_state; /* INT: kqueue status information */ + + uint32_t __unused1; /* INT: unused */ + + /* process information when retrieved via KERN_FILE_BY[PU]ID */ + uint32_t p_pid; /* PID_T: process id */ + int32_t fd_fd; /* INT: descriptor number */ + uint32_t fd_ofileflags; /* CHAR: open file flags */ + uint32_t p_uid; /* UID_T: process credentials */ + uint32_t p_gid; /* GID_T: process credentials */ + uint32_t p_tid; /* PID_T: thread id */ + char p_comm[KI_MAXCOMLEN]; + + /* more socket information */ + uint32_t inp_rtableid; /* UINT: Routing table identifier. */ + uint64_t so_splice; /* PTR: f_data of spliced socket */ + int64_t so_splicelen; /* OFF_T: already spliced count or */ + /* -1 if this is target of splice */ + uint64_t so_rcv_cc; /* LONG: chars in receive buf */ + uint64_t so_snd_cc; /* LONG: chars in send buf */ + uint64_t unp_refs; /* PTR: connected sockets */ + uint64_t unp_nextref; /* PTR: link to next connected socket */ + uint64_t unp_addr; /* PTR: address of the socket address */ + char unp_path[KI_UNPPATHLEN]; + uint32_t inp_proto; /* CHAR: raw protocol id */ + uint32_t t_state; /* SHORT: tcp state */ + uint64_t t_rcv_wnd; /* ULONG: tcp receive window */ + uint64_t t_snd_wnd; /* ULONG: tcp send window */ + uint64_t t_snd_cwnd; /* ULONG: congestion-controlled win */ + + uint32_t va_nlink; /* NLINK_T: number of references to file */ +}; + +/* + * KERN_INTRCNT + */ +#define KERN_INTRCNT_NUM 1 /* int: # intrcnt */ +#define KERN_INTRCNT_CNT 2 /* node: intrcnt */ +#define KERN_INTRCNT_NAME 3 /* node: names */ +#define KERN_INTRCNT_VECTOR 4 /* node: interrupt vector # */ +#define KERN_INTRCNT_MAXID 5 + +#define CTL_KERN_INTRCNT_NAMES { \ + { 0, 0 }, \ + { "nintrcnt", CTLTYPE_INT }, \ + { "intrcnt", CTLTYPE_NODE }, \ + { "intrname", CTLTYPE_NODE }, \ +} + +/* + * KERN_WATCHDOG + */ +#define KERN_WATCHDOG_PERIOD 1 /* int: watchdog period */ +#define KERN_WATCHDOG_AUTO 2 /* int: automatic tickle */ +#define KERN_WATCHDOG_MAXID 3 + +#define CTL_KERN_WATCHDOG_NAMES { \ + { 0, 0 }, \ + { "period", CTLTYPE_INT }, \ + { "auto", CTLTYPE_INT }, \ +} + +/* + * KERN_TIMECOUNTER + */ +#define KERN_TIMECOUNTER_TICK 1 /* int: number of revolutions */ +#define KERN_TIMECOUNTER_TIMESTEPWARNINGS 2 /* int: log a warning when time changes */ +#define KERN_TIMECOUNTER_HARDWARE 3 /* string: tick hardware used */ +#define KERN_TIMECOUNTER_CHOICE 4 /* string: tick hardware used */ +#define KERN_TIMECOUNTER_MAXID 5 + +#define CTL_KERN_TIMECOUNTER_NAMES { \ + { 0, 0 }, \ + { "tick", CTLTYPE_INT }, \ + { "timestepwarnings", CTLTYPE_INT }, \ + { "hardware", CTLTYPE_STRING }, \ + { "choice", CTLTYPE_STRING }, \ +} + +/* + * CTL_FS identifiers + */ +#define FS_POSIX 1 /* POSIX flags */ +#define FS_MAXID 2 + +#define CTL_FS_NAMES { \ + { 0, 0 }, \ + { "posix", CTLTYPE_NODE }, \ +} + +/* + * CTL_FS identifiers + */ +#define FS_POSIX_SETUID 1 /* int: always clear SGID/SUID bit when owner change */ +#define FS_POSIX_MAXID 2 + +#define CTL_FS_POSIX_NAMES { \ + { 0, 0 }, \ + { "setuid", CTLTYPE_INT }, \ +} + +/* + * CTL_HW identifiers + */ +#define HW_MACHINE 1 /* string: machine class */ +#define HW_MODEL 2 /* string: specific machine model */ +#define HW_NCPU 3 /* int: number of configured cpus */ +#define HW_BYTEORDER 4 /* int: machine byte order */ +#define HW_PHYSMEM 5 /* int: total memory */ +#define HW_USERMEM 6 /* int: non-kernel memory */ +#define HW_PAGESIZE 7 /* int: software page size */ +#define HW_DISKNAMES 8 /* strings: disk drive names */ +#define HW_DISKSTATS 9 /* struct: diskstats[] */ +#define HW_DISKCOUNT 10 /* int: number of disks */ +#define HW_SENSORS 11 /* node: hardware monitors */ +#define HW_CPUSPEED 12 /* get CPU frequency */ +#define HW_SETPERF 13 /* set CPU performance % */ +#define HW_VENDOR 14 /* string: vendor name */ +#define HW_PRODUCT 15 /* string: product name */ +#define HW_VERSION 16 /* string: hardware version */ +#define HW_SERIALNO 17 /* string: hardware serial number */ +#define HW_UUID 18 /* string: universal unique id */ +#define HW_PHYSMEM64 19 /* quad: total memory */ +#define HW_USERMEM64 20 /* quad: non-kernel memory */ +#define HW_NCPUFOUND 21 /* int: number of cpus found */ +#define HW_ALLOWPOWERDOWN 22 /* allow power button shutdown */ +#define HW_PERFPOLICY 23 /* set performance policy */ +#define HW_SMT 24 /* int: enable SMT/HT/CMT */ +#define HW_NCPUONLINE 25 /* int: number of cpus being used */ +#define HW_MAXID 26 /* number of valid hw ids */ + +#define CTL_HW_NAMES { \ + { 0, 0 }, \ + { "machine", CTLTYPE_STRING }, \ + { "model", CTLTYPE_STRING }, \ + { "ncpu", CTLTYPE_INT }, \ + { "byteorder", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "pagesize", CTLTYPE_INT }, \ + { "disknames", CTLTYPE_STRING }, \ + { "diskstats", CTLTYPE_STRUCT }, \ + { "diskcount", CTLTYPE_INT }, \ + { "sensors", CTLTYPE_NODE}, \ + { "cpuspeed", CTLTYPE_INT }, \ + { "setperf", CTLTYPE_INT }, \ + { "vendor", CTLTYPE_STRING }, \ + { "product", CTLTYPE_STRING }, \ + { "version", CTLTYPE_STRING }, \ + { "serialno", CTLTYPE_STRING }, \ + { "uuid", CTLTYPE_STRING }, \ + { "physmem", CTLTYPE_QUAD }, \ + { "usermem", CTLTYPE_QUAD }, \ + { "ncpufound", CTLTYPE_INT }, \ + { "allowpowerdown", CTLTYPE_INT }, \ + { "perfpolicy", CTLTYPE_STRING }, \ + { "smt", CTLTYPE_INT }, \ + { "ncpuonline", CTLTYPE_INT }, \ +} + +/* + * CTL_DEBUG definitions + * + * Second level identifier specifies which debug variable. + * Third level identifier specifies which structure component. + */ +#define CTL_DEBUG_NAME 0 /* string: variable name */ +#define CTL_DEBUG_VALUE 1 /* int: variable value */ +#define CTL_DEBUG_MAXID 20 + +#ifdef _KERNEL +#ifdef DEBUG +/* + * CTL_DEBUG variables. + * + * These are declared as separate variables so that they can be + * individually initialized at the location of their associated + * variable. The loader prevents multiple use by issuing errors + * if a variable is initialized in more than one place. They are + * aggregated into an array in debug_sysctl(), so that it can + * conveniently locate them when querried. If more debugging + * variables are added, they must also be declared here and also + * entered into the array. + */ +struct ctldebug { + char *debugname; /* name of debugging variable */ + int *debugvar; /* pointer to debugging variable */ +}; +extern struct ctldebug debug0, debug1, debug2, debug3, debug4; +extern struct ctldebug debug5, debug6, debug7, debug8, debug9; +extern struct ctldebug debug10, debug11, debug12, debug13, debug14; +extern struct ctldebug debug15, debug16, debug17, debug18, debug19; +#endif /* DEBUG */ + +/* + * Internal sysctl function calling convention: + * + * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen); + * + * The name parameter points at the next component of the name to be + * interpreted. The namelen parameter is the number of integers in + * the name. + */ +typedef int (sysctlfn)(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +int sysctl_int(void *, size_t *, void *, size_t, int *); +int sysctl_int_lower(void *, size_t *, void *, size_t, int *); +int sysctl_rdint(void *, size_t *, void *, int); +int sysctl_int_arr(int **, int *, u_int, void *, size_t *, void *, size_t); +int sysctl_quad(void *, size_t *, void *, size_t, int64_t *); +int sysctl_rdquad(void *, size_t *, void *, int64_t); +int sysctl_string(void *, size_t *, void *, size_t, char *, size_t); +int sysctl_tstring(void *, size_t *, void *, size_t, char *, size_t); +int sysctl__string(void *, size_t *, void *, size_t, char *, size_t, int); +int sysctl_rdstring(void *, size_t *, void *, const char *); +int sysctl_rdstruct(void *, size_t *, void *, const void *, size_t); +int sysctl_struct(void *, size_t *, void *, size_t, void *, size_t); +int sysctl_file(int *, u_int, char *, size_t *, struct proc *); +int sysctl_doproc(int *, u_int, char *, size_t *); +struct mbuf_queue; +int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t, + struct mbuf_queue *); +struct rtentry; +struct walkarg; +int sysctl_dumpentry(struct rtentry *, void *, unsigned int); +int sysctl_rtable(int *, u_int, void *, size_t *, void *, size_t); +int sysctl_clockrate(char *, size_t *, void *); +int sysctl_vnode(char *, size_t *, struct proc *); +#if defined(GPROF) || defined(DDBPROF) +int sysctl_doprof(int *, u_int, void *, size_t *, void *, size_t); +#endif +int sysctl_dopool(int *, u_int, char *, size_t *); + +int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int hw_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +#ifdef DEBUG +int debug_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +#endif +int vm_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int fs_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int fs_posix_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int net_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int cpu_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int vfs_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int sysctl_sysvipc(int *, u_int, void *, size_t *); +int sysctl_wdog(int *, u_int, void *, size_t *, void *, size_t); + +extern int (*cpu_cpuspeed)(int *); +extern void (*cpu_setperf)(int); + +int net_ifiq_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pipex_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pf_sysctl(void *, size_t *, void *, size_t); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +int sysctl(const int *, u_int, void *, size_t *, void *, size_t); +__END_DECLS +#endif /* _KERNEL */ +#endif /* !_SYS_SYSCTL_H_ */ diff --git a/sys/sys/syslimits.h b/sys/sys/syslimits.h new file mode 100644 index 0000000..891c9b4 --- /dev/null +++ b/sys/sys/syslimits.h @@ -0,0 +1,77 @@ +/* $OpenBSD: syslimits.h,v 1.14 2020/04/02 18:00:00 deraadt Exp $ */ +/* $NetBSD: syslimits.h,v 1.12 1995/10/05 05:26:19 thorpej 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. + * + * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 + */ + +#include <sys/cdefs.h> + +#if __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE +#define ARG_MAX (512 * 1024) /* max bytes for an exec function */ +#define CHILD_MAX 80 /* max simultaneous processes */ +#define LINK_MAX 32767 /* max file link count */ +#define MAX_CANON 255 /* max bytes in term canon input line */ +#define MAX_INPUT 255 /* max bytes in terminal input */ +#define NAME_MAX 255 /* max bytes in a file name */ +#define NGROUPS_MAX 16 /* max supplemental group id's */ +#define OPEN_MAX 64 /* max open files per process */ +#define PATH_MAX 1024 /* max bytes in pathname */ +#define PIPE_BUF 512 /* max bytes for atomic pipe writes */ +#define SYMLINK_MAX PATH_MAX /* max bytes in a symbolic link */ +#define SYMLOOP_MAX 32 /* max symlinks per path (for loops) */ + +#define BC_BASE_MAX INT_MAX /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 65535 /* max array elements in bc(1) */ +#define BC_SCALE_MAX INT_MAX /* max scale value in bc(1) */ +#define BC_STRING_MAX INT_MAX /* max const string length in bc(1) */ +#define COLL_WEIGHTS_MAX 2 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#ifndef RE_DUP_MAX +#define RE_DUP_MAX 255 /* max RE's in interval notation */ +#define SEM_VALUE_MAX UINT_MAX /* max value of a sem_* semaphore */ +#endif + +#if __XPG_VISIBLE +#define IOV_MAX 1024 /* max # of iov's (readv,sendmsg,etc) */ +#define NZERO 20 /* default "nice" */ +#endif /* __XPG_VISIBLE */ + +#endif /* __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE */ + +#if __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE +#define TTY_NAME_MAX 260 /* max tty device name length w/ NUL */ +#define LOGIN_NAME_MAX 32 /* max login name length w/ NUL */ +#endif /* __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200112 +#define HOST_NAME_MAX 255 /* max hostname length w/o NUL */ +#endif diff --git a/sys/sys/syslog.h b/sys/sys/syslog.h new file mode 100644 index 0000000..c70a660 --- /dev/null +++ b/sys/sys/syslog.h @@ -0,0 +1,221 @@ +/* $OpenBSD: syslog.h,v 1.16 2017/08/08 14:23:23 bluhm Exp $ */ +/* $NetBSD: syslog.h,v 1.14 1996/04/03 20:46:44 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/dev/log" + +#define LIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd */ + +#define LOG_MAXLINE 8192 /* maximum line length */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK (LOG_NFACILITIES<<3) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 }, +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 }, +}; +#endif + +/* Used by reentrant functions */ + +struct syslog_data { + int log_stat; + const char *log_tag; + int log_fac; + int log_mask; +}; + +#define SYSLOG_DATA_INIT {0, (const char *)0, LOG_USER, 0xff} + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifndef _KERNEL + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * __va_list from <machine/_types.h> and use it. + */ +#include <sys/cdefs.h> +#include <machine/_types.h> + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) + __attribute__((__format__(__syslog__,2,3))); +void vsyslog(int, const char *, __va_list); +void closelog_r(struct syslog_data *); +void openlog_r(const char *, int, int, struct syslog_data *); +int setlogmask_r(int, struct syslog_data *); +void syslog_r(int, struct syslog_data *, const char *, ...) + __attribute__((__format__(__syslog__,3,4))); +void vsyslog_r(int, struct syslog_data *, const char *, __va_list); +__END_DECLS + +#else /* !_KERNEL */ + +void logpri(int); +void log(int, const char *, ...) + __attribute__((__format__(__kprintf__,2,3))); +int addlog(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +void logwakeup(void); + +#endif /* !_KERNEL */ +#endif /* !_SYS_SYSLOG_H_ */ + diff --git a/sys/sys/systm.h b/sys/sys/systm.h new file mode 100644 index 0000000..5dec672 --- /dev/null +++ b/sys/sys/systm.h @@ -0,0 +1,409 @@ +/* $OpenBSD: systm.h,v 1.145 2020/03/20 03:37:08 cheloha Exp $ */ +/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ + +/*- + * Copyright (c) 1982, 1988, 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. + * + * @(#)systm.h 8.4 (Berkeley) 2/23/94 + */ + +#ifndef __SYSTM_H__ +#define __SYSTM_H__ + +#include <sys/queue.h> +#include <sys/stdarg.h> + +/* + * The `securelevel' variable controls the security level of the system. + * It can only be decreased by process 1 (/sbin/init). + * + * Security levels are as follows: + * -1 permanently insecure mode - always run system in level 0 mode. + * 0 insecure mode - immutable and append-only flags may be turned off. + * All devices may be read or written subject to permission modes. + * 1 secure mode - immutable and append-only flags may not be changed; + * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are + * read-only. + * 2 highly secure mode - same as (1) plus raw disks are always + * read-only whether mounted or not. This level precludes tampering + * with filesystems by unmounting them, but also inhibits running + * newfs while the system is secured. + * + * In normal operation, the system runs in level 0 mode while single user + * and in level 1 mode while multiuser. If level 2 mode is desired while + * running multiuser, it can be set in the multiuser startup script + * (/etc/rc.local) using sysctl(1). If it is desired to run the system + * in level 0 mode while multiuser, initialize the variable securelevel + * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to + * zero as that would allow the vmunix binary to be patched to -1. + * Without initialization, securelevel loads in the BSS area which only + * comes into existence when the kernel is loaded and hence cannot be + * patched by a stalking hacker. + */ +extern int securelevel; /* system security level */ +extern const char *panicstr; /* panic message */ +extern const char *faultstr; /* fault message */ +extern const char version[]; /* system version */ +extern const char copyright[]; /* system copyright */ +extern const char ostype[]; +extern const char osversion[]; +extern const char osrelease[]; +extern int cold; /* cold start flag initialized in locore */ +extern int db_active; /* running currently inside ddb(4) */ + +extern int ncpus; /* number of CPUs used */ +extern int ncpusfound; /* number of CPUs found */ +extern int nblkdev; /* number of entries in bdevsw */ +extern int nchrdev; /* number of entries in cdevsw */ + +extern int selwait; /* select timeout address */ +extern int maxmem; /* max memory per process */ +extern int physmem; /* physical memory */ + +extern dev_t dumpdev; /* dump device */ +extern long dumplo; /* offset into dumpdev */ + +extern dev_t rootdev; /* root device */ +extern u_char bootduid[8]; /* boot device disklabel uid */ +extern u_char rootduid[8]; /* root device disklabel uid */ +extern struct vnode *rootvp; /* vnode equivalent to above */ + +extern dev_t swapdev; /* swapping device */ +extern struct vnode *swapdev_vp;/* vnode equivalent to above */ + +struct proc; +struct process; +#define curproc curcpu()->ci_curproc + +typedef int sy_call_t(struct proc *, void *, register_t *); + +extern struct sysent { /* system call table */ + short sy_narg; /* number of args */ + short sy_argsize; /* total size of arguments */ + int sy_flags; + sy_call_t *sy_call; /* implementing function */ +} sysent[]; + +#define SY_NOLOCK 0x01 + +#if _BYTE_ORDER == _BIG_ENDIAN +#define SCARG(p, k) ((p)->k.be.datum) /* get arg from args pointer */ +#elif _BYTE_ORDER == _LITTLE_ENDIAN +#define SCARG(p, k) ((p)->k.le.datum) /* get arg from args pointer */ +#else +#error "what byte order is this machine?" +#endif + +#if defined(_KERNEL) && defined(SYSCALL_DEBUG) +void scdebug_call(struct proc *p, register_t code, const register_t retval[]); +void scdebug_ret(struct proc *p, register_t code, int error, + const register_t retval[]); +#endif /* _KERNEL && SYSCALL_DEBUG */ + +extern int boothowto; /* reboot flags, from console subsystem */ + +extern void (*v_putc)(int); /* Virtual console putc routine */ + +/* + * General function declarations. + */ +int nullop(void *); +int enodev(void); +int enosys(void); +int enoioctl(void); +int enxio(void); +int eopnotsupp(void *); + +struct vnodeopv_desc; +void vfs_opv_init_explicit(struct vnodeopv_desc *); +void vfs_opv_init_default(struct vnodeopv_desc *); +void vfs_op_init(void); + +int seltrue(dev_t dev, int which, struct proc *); +int selfalse(dev_t dev, int which, struct proc *); +void *hashinit(int, int, int, u_long *); +void hashfree(void *, int, int); +int sys_nosys(struct proc *, void *, register_t *); + +void panic(const char *, ...) + __attribute__((__noreturn__,__format__(__kprintf__,1,2))); +void __assert(const char *, const char *, int, const char *) + __attribute__((__noreturn__)); +int printf(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +void uprintf(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +int vprintf(const char *, va_list) + __attribute__((__format__(__kprintf__,1,0))); +int vsnprintf(char *, size_t, const char *, va_list) + __attribute__((__format__(__kprintf__,3,0))); +int snprintf(char *buf, size_t, const char *, ...) + __attribute__((__format__(__kprintf__,3,4))); +struct tty; +void ttyprintf(struct tty *, const char *, ...) + __attribute__((__format__(__kprintf__,2,3))); + +void splassert_fail(int, int, const char *); +extern int splassert_ctl; + +void assertwaitok(void); + +void tablefull(const char *); + +int kcopy(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); + +void bcopy(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +void explicit_bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +int bcmp(const void *, const void *, size_t); +void *memcpy(void *, const void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memmove(void *, const void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memset(void *, int, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))); + +int copystr(const void *, void *, size_t, size_t *) + __attribute__ ((__bounded__(__string__,2,3))); +int copyinstr(const void *, void *, size_t, size_t *) + __attribute__ ((__bounded__(__string__,2,3))); +int copyoutstr(const void *, void *, size_t, size_t *); +int copyin(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,2,3))); +int copyout(const void *, void *, size_t); +int copyin32(const uint32_t *, uint32_t *); + +struct arc4random_ctx; +void arc4random_buf(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +struct arc4random_ctx *arc4random_ctx_new(void); +void arc4random_ctx_free(struct arc4random_ctx *); +void arc4random_ctx_buf(struct arc4random_ctx *, void *, size_t); +u_int32_t arc4random(void); +u_int32_t arc4random_uniform(u_int32_t); + +struct timeval; +struct timespec; +int tvtohz(const struct timeval *); +int tstohz(const struct timespec *); +void realitexpire(void *); + +struct clockframe; +void hardclock(struct clockframe *); +void statclock(struct clockframe *); + +void initclocks(void); +void inittodr(time_t); +void resettodr(void); +void cpu_initclocks(void); + +void startprofclock(struct process *); +void stopprofclock(struct process *); +void setstatclockrate(int); + +void start_periodic_resettodr(void); +void stop_periodic_resettodr(void); + +struct sleep_state; +void sleep_setup(struct sleep_state *, const volatile void *, int, + const char *); +void sleep_setup_timeout(struct sleep_state *, int); +void sleep_setup_signal(struct sleep_state *); +void sleep_finish(struct sleep_state *, int); +int sleep_finish_timeout(struct sleep_state *); +int sleep_finish_signal(struct sleep_state *); +int sleep_finish_all(struct sleep_state *, int); +void sleep_queue_init(void); + +struct cond; +void cond_init(struct cond *); +void cond_wait(struct cond *, const char *); +void cond_signal(struct cond *); + +#define INFSLP UINT64_MAX +#define MAXTSLP (UINT64_MAX - 1) + +struct mutex; +struct rwlock; +void wakeup_n(const volatile void *, int); +void wakeup(const volatile void *); +#define wakeup_one(c) wakeup_n((c), 1) +int tsleep(const volatile void *, int, const char *, int); +int tsleep_nsec(const volatile void *, int, const char *, uint64_t); +int msleep(const volatile void *, struct mutex *, int, const char*, int); +int msleep_nsec(const volatile void *, struct mutex *, int, const char*, + uint64_t); +int rwsleep(const volatile void *, struct rwlock *, int, const char *, int); +int rwsleep_nsec(const volatile void *, struct rwlock *, int, const char *, + uint64_t); +void yield(void); + +void wdog_register(int (*)(void *, int), void *); +void wdog_shutdown(void *); + +/* + * Startup hooks are functions running after the scheduler has started + * but before any threads have been created or root has been mounted. + */ + +struct hook_desc { + TAILQ_ENTRY(hook_desc) hd_list; + void (*hd_fn)(void *); + void *hd_arg; +}; +TAILQ_HEAD(hook_desc_head, hook_desc); + +extern struct hook_desc_head startuphook_list; + +void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *); +void hook_disestablish(struct hook_desc_head *, void *); +void dohooks(struct hook_desc_head *, int); + +#define HOOK_REMOVE 0x01 +#define HOOK_FREE 0x02 + +#define startuphook_establish(fn, arg) \ + hook_establish(&startuphook_list, 1, (fn), (arg)) +#define startuphook_disestablish(vhook) \ + hook_disestablish(&startuphook_list, (vhook)) +#define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE) + +struct uio; +int uiomove(void *, size_t, struct uio *); + +#if defined(_KERNEL) + +#include <sys/rwlock.h> + +extern struct rwlock netlock; + +#define NET_LOCK() NET_WLOCK() +#define NET_UNLOCK() NET_WUNLOCK() +#define NET_ASSERT_UNLOCKED() NET_ASSERT_WUNLOCKED() + + +#define NET_WLOCK() do { rw_enter_write(&netlock); } while (0) +#define NET_WUNLOCK() do { rw_exit_write(&netlock); } while (0) + +#define NET_ASSERT_WLOCKED() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s != RW_WRITE)) \ + splassert_fail(RW_WRITE, _s, __func__); \ +} while (0) + +#define NET_ASSERT_WUNLOCKED() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s == RW_WRITE)) \ + splassert_fail(0, RW_WRITE, __func__); \ +} while (0) + +#define NET_RLOCK() do { rw_enter_read(&netlock); } while (0) +#define NET_RUNLOCK() do { rw_exit_read(&netlock); } while (0) + +#define NET_ASSERT_LOCKED() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s != RW_WRITE && _s != RW_READ)) \ + splassert_fail(RW_READ, _s, __func__); \ +} while (0) + +__returns_twice int setjmp(label_t *); +__dead void longjmp(label_t *); +#endif + +void consinit(void); + +void cpu_startup(void); +void cpu_configure(void); +void diskconf(void); + +int nfs_mountroot(void); +int dk_mountroot(void); +extern int (*mountroot)(void); + +#include <lib/libkern/libkern.h> + +#define bzero(b, n) __builtin_bzero((b), (n)) +#define memcmp(b1, b2, n) __builtin_memcmp((b1), (b2), (n)) +#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n)) +#define memset(b, c, n) __builtin_memset((b), (c), (n)) +#if (defined(__GNUC__) && __GNUC__ >= 4) +#define memmove(d, s, n) __builtin_memmove((d), (s), (n)) +#endif +#if !defined(__clang__) && (defined(__GNUC__) && __GNUC__ >= 4) +#define bcmp(b1, b2, n) __builtin_bcmp((b1), (b2), (n)) +#define bcopy(s, d, n) __builtin_bcopy((s), (d), (n)) +#endif + +#if defined(DDB) +/* debugger entry points */ +void db_enter(void); /* in DDB only */ +#endif + +#ifdef BOOT_CONFIG +void user_config(void); +#endif + +#if defined(MULTIPROCESSOR) +void _kernel_lock_init(void); +void _kernel_lock(void); +void _kernel_unlock(void); +int _kernel_lock_held(void); + +#define KERNEL_LOCK_INIT() _kernel_lock_init() +#define KERNEL_LOCK() _kernel_lock() +#define KERNEL_UNLOCK() _kernel_unlock() +#define KERNEL_ASSERT_LOCKED() KASSERT(_kernel_lock_held()) +#define KERNEL_ASSERT_UNLOCKED() KASSERT(!_kernel_lock_held()) + +#else /* ! MULTIPROCESSOR */ + +#define KERNEL_LOCK_INIT() /* nothing */ +#define KERNEL_LOCK() /* nothing */ +#define KERNEL_UNLOCK() /* nothing */ +#define KERNEL_ASSERT_LOCKED() /* nothing */ +#define KERNEL_ASSERT_UNLOCKED() /* nothing */ + +#endif /* MULTIPROCESSOR */ + +#endif /* __SYSTM_H__ */ diff --git a/sys/sys/task.h b/sys/sys/task.h new file mode 100644 index 0000000..222c2a7 --- /dev/null +++ b/sys/sys/task.h @@ -0,0 +1,60 @@ +/* $OpenBSD: task.h,v 1.16 2019/06/23 12:56:10 kettenis Exp $ */ + +/* + * Copyright (c) 2013 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_TASK_H_ +#define _SYS_TASK_H_ + +#include <sys/queue.h> + +struct taskq; + +struct task { + TAILQ_ENTRY(task) t_entry; + void (*t_func)(void *); + void *t_arg; + unsigned int t_flags; +}; + +#define TASK_ONQUEUE 1 +#define TASK_BARRIER 2 + +TAILQ_HEAD(task_list, task); + +#define TASKQ_MPSAFE (1 << 0) + +#define TASK_INITIALIZER(_f, _a) {{ NULL, NULL }, (_f), (_a), 0 } + +#ifdef _KERNEL +extern struct taskq *const systq; +extern struct taskq *const systqmp; + +struct taskq *taskq_create(const char *, unsigned int, int, unsigned int); +void taskq_destroy(struct taskq *); +void taskq_barrier(struct taskq *); + +void taskq_del_barrier(struct taskq *, struct task *); + +void task_set(struct task *, void (*)(void *), void *); +int task_add(struct taskq *, struct task *); +int task_del(struct taskq *, struct task *); + +#define task_pending(_t) ((_t)->t_flags & TASK_ONQUEUE) + +#endif /* _KERNEL */ + +#endif /* _SYS_TASK_H_ */ diff --git a/sys/sys/termios.h b/sys/sys/termios.h new file mode 100644 index 0000000..af21a97 --- /dev/null +++ b/sys/sys/termios.h @@ -0,0 +1,299 @@ +/* $OpenBSD: termios.h,v 1.13 2016/09/20 21:10:22 fcambus Exp $ */ +/* $NetBSD: termios.h,v 1.14 1996/04/09 20:55:41 cgd Exp $ */ + +/* + * Copyright (c) 1988, 1989, 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. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#include <sys/cdefs.h> + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#if __BSD_VISIBLE +#define VEOL2 2 /* ICANON */ +#endif +#define VERASE 3 /* ICANON */ +#if __BSD_VISIBLE +#define VWERASE 4 /* ICANON */ +#endif +#define VKILL 5 /* ICANON */ +#if __BSD_VISIBLE +#define VREPRINT 6 /* ICANON */ +#endif +/* 7 spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#if __BSD_VISIBLE +#define VDSUSP 11 /* ISIG */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#if __BSD_VISIBLE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#if __BSD_VISIBLE +#define VSTATUS 18 /* ICANON */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE (0377) + +#if __BSD_VISIBLE +#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0) +#endif + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINT */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#if __BSD_VISIBLE +#define IXANY 0x00000800 /* any char will restart after stop */ +#define IUCLC 0x00001000 /* translate upper to lower case */ +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif /* __BSD_VISIBLE */ + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#if __XPG_VISIBLE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#endif +#if __BSD_VISIBLE +#define OXTABS 0x00000004 /* expand tabs to spaces */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output */ +#endif +#if __XPG_VISIBLE +#define OCRNL 0x00000010 /* map CR to NL */ +#define OLCUC 0x00000020 /* translate lower case to upper case */ +#define ONOCR 0x00000040 /* No CR output at column 0 */ +#define ONLRET 0x00000080 /* NL performs the CR function */ +#endif /* __XPG_VISIBLE */ + +/* + * Control flags - hardware control of terminal + */ +#if __BSD_VISIBLE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#if __BSD_VISIBLE +#define CRTSCTS 0x00010000 /* RTS/CTS full-duplex flow control */ +#define CRTS_IFLOW CRTSCTS /* XXX compat */ +#define CCTS_OFLOW CRTSCTS /* XXX compat */ +#define MDMBUF 0x00100000 /* DTR/DCD hardware flow control */ +#define CHWFLOW (MDMBUF|CRTSCTS) /* all types of hw flow control */ +#endif /* __BSD_VISIBLE */ + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#if __BSD_VISIBLE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#if __BSD_VISIBLE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#if __BSD_VISIBLE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#if __BSD_VISIBLE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define XCASE 0x01000000 /* canonical upper/lower case */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + int c_ispeed; /* input speed */ + int c_ospeed; /* output speed */ +}; + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#if __BSD_VISIBLE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#if __BSD_VISIBLE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define EXTA 19200 +#define EXTB 38400 +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +#include <sys/_types.h> + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif +#endif + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +pid_t tcgetsid(int); +#endif + +#if __BSD_VISIBLE +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#if __BSD_VISIBLE +/* + * Include tty ioctl's that aren't just for backwards compatibility + * with the old tty driver. These ioctl definitions were previously + * in <sys/ioctl.h>. + */ +#include <sys/ttycom.h> +#endif + +/* + * END OF PROTECTED INCLUDE. + */ +#endif /* !_SYS_TERMIOS_H_ */ + +#if __BSD_VISIBLE +#include <sys/ttydefaults.h> +#endif diff --git a/sys/sys/time.h b/sys/sys/time.h new file mode 100644 index 0000000..564bae3 --- /dev/null +++ b/sys/sys/time.h @@ -0,0 +1,418 @@ +/* $OpenBSD: time.h,v 1.50 2020/01/15 13:17:35 mpi Exp $ */ +/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft 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. + * + * @(#)time.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include <sys/select.h> + +#ifndef _TIMEVAL_DECLARED +#define _TIMEVAL_DECLARED +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +/* + * Structure defined by POSIX.1b to be like a timeval. + */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ +} while (0) + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +/* Operations on timevals. */ +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timerisvalid(tvp) \ + ((tvp)->tv_usec >= 0 && (tvp)->tv_usec < 1000000) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) + +/* Operations on timespecs. */ +#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#define timespecisvalid(tsp) \ + ((tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L) +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +#if __BSD_VISIBLE +/* + * clock information structure for sysctl({CTL_KERN, KERN_CLOCKRATE}) + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int tickadj; /* clock skew rate for adjtime() */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; +#endif /* __BSD_VISIBLE */ + +#if defined(_KERNEL) || defined(_STANDALONE) +#include <sys/_time.h> + +/* Time expressed as seconds and fractions of a second + operations on it. */ +struct bintime { + time_t sec; + uint64_t frac; +}; + +#define bintimecmp(btp, ctp, cmp) \ + ((btp)->sec == (ctp)->sec ? \ + (btp)->frac cmp (ctp)->frac : \ + (btp)->sec cmp (ctp)->sec) + +static inline void +bintimeaddfrac(const struct bintime *bt, uint64_t x, struct bintime *ct) +{ + ct->sec = bt->sec; + if (bt->frac > bt->frac + x) + ct->sec++; + ct->frac = bt->frac + x; +} + +static inline void +bintimeadd(const struct bintime *bt, const struct bintime *ct, + struct bintime *dt) +{ + dt->sec = bt->sec + ct->sec; + if (bt->frac > bt->frac + ct->frac) + dt->sec++; + dt->frac = bt->frac + ct->frac; +} + +static inline void +bintimesub(const struct bintime *bt, const struct bintime *ct, + struct bintime *dt) +{ + dt->sec = bt->sec - ct->sec; + if (bt->frac < bt->frac - ct->frac) + dt->sec--; + dt->frac = bt->frac - ct->frac; +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static inline void +BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts) +{ + ts->tv_sec = bt->sec; + ts->tv_nsec = (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32); +} + +static inline void +TIMESPEC_TO_BINTIME(const struct timespec *ts, struct bintime *bt) +{ + bt->sec = ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + bt->frac = (uint64_t)ts->tv_nsec * (uint64_t)18446744073ULL; +} + +static inline void +BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv) +{ + tv->tv_sec = bt->sec; + tv->tv_usec = (long)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32); +} + +static inline void +TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt) +{ + bt->sec = (time_t)tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + bt->frac = (uint64_t)tv->tv_usec * (uint64_t)18446744073709ULL; +} + +extern volatile time_t time_second; /* Seconds since epoch, wall time. */ +extern volatile time_t time_uptime; /* Seconds since reboot. */ + +/* + * Functions for looking at our clocks: [get]{bin,nano,micro}[boot|up]time() + * + * Functions without the "get" prefix returns the best timestamp + * we can produce in the given format. + * + * "bin" == struct bintime == seconds + 64 bit fraction of seconds. + * "nano" == struct timespec == seconds + nanoseconds. + * "micro" == struct timeval == seconds + microseconds. + * + * Functions containing "up" returns time relative to boot and + * should be used for calculating time intervals. + * + * Functions containing "boot" return the GMT time at which the + * system booted. + * + * Functions with just "time" return the current GMT time. + * + * Functions with the "get" prefix returns a less precise result + * much faster than the functions without "get" prefix and should + * be used where a precision of 10 msec is acceptable or where + * performance is priority. (NB: "precision", _not_ "resolution" !) + */ + +void bintime(struct bintime *); +void nanotime(struct timespec *); +void microtime(struct timeval *); + +void getnanotime(struct timespec *); +void getmicrotime(struct timeval *); + +void binuptime(struct bintime *); +void nanouptime(struct timespec *); +void microuptime(struct timeval *); + +void getnanouptime(struct timespec *); +void getmicrouptime(struct timeval *); + +void binboottime(struct bintime *); +void microboottime(struct timeval *); +void nanoboottime(struct timespec *); + +struct proc; +int clock_gettime(struct proc *, clockid_t, struct timespec *); + +int itimerfix(struct timeval *); +int itimerdecr(struct itimerspec *, long); +int settime(const struct timespec *); +int ratecheck(struct timeval *, const struct timeval *); +int ppsratecheck(struct timeval *, int *, int); + +/* + * "POSIX time" to/from "YY/MM/DD/hh/mm/ss" + */ +struct clock_ymdhms { + u_short dt_year; + u_char dt_mon; + u_char dt_day; + u_char dt_wday; /* Day of week */ + u_char dt_hour; + u_char dt_min; + u_char dt_sec; +}; + +time_t clock_ymdhms_to_secs(struct clock_ymdhms *); +void clock_secs_to_ymdhms(time_t, struct clock_ymdhms *); +/* + * BCD to decimal and decimal to BCD. + */ +#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf)) +#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) + +/* Some handy constants. */ +#define SECDAY 86400L +#define SECYR (SECDAY * 365) + +/* Traditional POSIX base year */ +#define POSIX_BASE_YEAR 1970 + +#include <sys/stdint.h> + +static inline void +NSEC_TO_TIMEVAL(uint64_t ns, struct timeval *tv) +{ + tv->tv_sec = ns / 1000000000L; + tv->tv_usec = (ns % 1000000000L) / 1000; +} + +static inline uint64_t +TIMEVAL_TO_NSEC(const struct timeval *tv) +{ + uint64_t nsecs; + + if (tv->tv_sec > UINT64_MAX / 1000000000ULL) + return UINT64_MAX; + nsecs = tv->tv_sec * 1000000000ULL; + if (tv->tv_usec * 1000ULL > UINT64_MAX - nsecs) + return UINT64_MAX; + return nsecs + tv->tv_usec * 1000ULL; +} + +static inline void +NSEC_TO_TIMESPEC(uint64_t ns, struct timespec *ts) +{ + ts->tv_sec = ns / 1000000000L; + ts->tv_nsec = ns % 1000000000L; +} + +static inline uint64_t +SEC_TO_NSEC(uint64_t seconds) +{ + if (seconds > UINT64_MAX / 1000000000ULL) + return UINT64_MAX; + return seconds * 1000000000ULL; +} + +static inline uint64_t +MSEC_TO_NSEC(uint64_t milliseconds) +{ + if (milliseconds > UINT64_MAX / 1000000ULL) + return UINT64_MAX; + return milliseconds * 1000000ULL; +} + +static inline uint64_t +USEC_TO_NSEC(uint64_t microseconds) +{ + if (microseconds > UINT64_MAX / 1000ULL) + return UINT64_MAX; + return microseconds * 1000ULL; +} + +static inline uint64_t +TIMESPEC_TO_NSEC(const struct timespec *ts) +{ + if (ts->tv_sec > (UINT64_MAX - ts->tv_nsec) / 1000000000ULL) + return UINT64_MAX; + return ts->tv_sec * 1000000000ULL + ts->tv_nsec; +} + +#else /* !_KERNEL */ +#include <time.h> + +#if __BSD_VISIBLE || __XPG_VISIBLE +__BEGIN_DECLS +#if __BSD_VISIBLE +int adjtime(const struct timeval *, struct timeval *); +int adjfreq(const int64_t *, int64_t *); +#endif +#if __XPG_VISIBLE +int futimes(int, const struct timeval *); +int getitimer(int, struct itimerval *); +int gettimeofday(struct timeval *, struct timezone *); +int setitimer(int, const struct itimerval *, struct itimerval *); +int settimeofday(const struct timeval *, const struct timezone *); +int utimes(const char *, const struct timeval *); +#endif /* __XPG_VISIBLE */ +__END_DECLS +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#endif /* !_KERNEL */ + +#endif /* !_SYS_TIME_H_ */ diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h new file mode 100644 index 0000000..1cd9fca --- /dev/null +++ b/sys/sys/timeout.h @@ -0,0 +1,137 @@ +/* $OpenBSD: timeout.h,v 1.36 2020/01/03 02:16:38 cheloha Exp $ */ +/* + * Copyright (c) 2000-2001 Artur Grabowski <art@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_TIMEOUT_H_ +#define _SYS_TIMEOUT_H_ + +/* + * Interface for handling time driven events in the kernel. + * + * The basic component of this API is the struct timeout. The user should not + * touch the internals of this structure, but it's the users responsibility + * to allocate and deallocate timeouts. + * + * The functions used to manipulate timeouts are: + * - timeout_set(timeout, function, argument) + * Initializes a timeout struct to call the function with the argument. + * A timeout only needs to be initialized once. + * - timeout_add(timeout, ticks) + * Schedule this timeout to run in "ticks" ticks (there are hz ticks in + * one second). You may not touch the timeout with timeout_set once the + * timeout is scheduled. A second call to timeout_add with an already + * scheduled timeout will cause the old timeout to be canceled and the + * new will be scheduled. + * - timeout_del(timeout) + * Remove the timeout from the timeout queue. It's legal to remove + * a timeout that has already happened. + * + * These functions may be called in interrupt context (anything below splhigh). + */ + +struct circq { + struct circq *next; /* next element */ + struct circq *prev; /* previous element */ +}; + +struct timeout { + struct circq to_list; /* timeout queue, don't move */ + void (*to_func)(void *); /* function to call */ + void *to_arg; /* function argument */ + int to_time; /* ticks on event */ + int to_flags; /* misc flags */ +}; + +/* + * flags in the to_flags field. + */ +#define TIMEOUT_PROC 0x01 /* needs a process context */ +#define TIMEOUT_ONQUEUE 0x02 /* on any timeout queue */ +#define TIMEOUT_INITIALIZED 0x04 /* initialized */ +#define TIMEOUT_TRIGGERED 0x08 /* running or ran */ +#define TIMEOUT_SCHEDULED 0x10 /* put on wheel at least once */ + +struct timeoutstat { + uint64_t tos_added; /* timeout_add*(9) calls */ + uint64_t tos_cancelled; /* dequeued during timeout_del*(9) */ + uint64_t tos_deleted; /* timeout_del*(9) calls */ + uint64_t tos_late; /* run after deadline */ + uint64_t tos_pending; /* number currently ONQUEUE */ + uint64_t tos_readded; /* timeout_add*(9) + already ONQUEUE */ + uint64_t tos_rescheduled; /* bucketed + already SCHEDULED */ + uint64_t tos_run_softclock; /* run from softclock() */ + uint64_t tos_run_thread; /* run from softclock_thread() */ + uint64_t tos_scheduled; /* bucketed during softclock() */ + uint64_t tos_softclocks; /* softclock() calls */ + uint64_t tos_thread_wakeups; /* wakeups in softclock_thread() */ +}; + +#ifdef _KERNEL +int timeout_sysctl(void *, size_t *, void *, size_t); + +/* + * special macros + * + * timeout_pending(to) - is this timeout already scheduled to run? + * timeout_initialized(to) - is this timeout initialized? + */ +#define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE) +#define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED) +#define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED) + +#define TIMEOUT_INITIALIZER_FLAGS(fn, arg, flags) { \ + .to_list = { NULL, NULL }, \ + .to_func = (fn), \ + .to_arg = (arg), \ + .to_time = 0, \ + .to_flags = (flags) | TIMEOUT_INITIALIZED \ +} + +#define TIMEOUT_INITIALIZER(_f, _a) TIMEOUT_INITIALIZER_FLAGS((_f), (_a), 0) + +struct bintime; + +void timeout_set(struct timeout *, void (*)(void *), void *); +void timeout_set_flags(struct timeout *, void (*)(void *), void *, int); +void timeout_set_proc(struct timeout *, void (*)(void *), void *); +int timeout_add(struct timeout *, int); +int timeout_add_tv(struct timeout *, const struct timeval *); +int timeout_add_ts(struct timeout *, const struct timespec *); +int timeout_add_bt(struct timeout *, const struct bintime *); +int timeout_add_sec(struct timeout *, int); +int timeout_add_msec(struct timeout *, int); +int timeout_add_usec(struct timeout *, int); +int timeout_add_nsec(struct timeout *, int); +int timeout_del(struct timeout *); +int timeout_del_barrier(struct timeout *); +void timeout_barrier(struct timeout *); + +void timeout_adjust_ticks(int); +void timeout_hardclock_update(void); +void timeout_startup(void); + +#endif /* _KERNEL */ + +#endif /* _SYS_TIMEOUT_H_ */ diff --git a/sys/sys/times.h b/sys/sys/times.h new file mode 100644 index 0000000..4781ffd --- /dev/null +++ b/sys/sys/times.h @@ -0,0 +1,63 @@ +/* $OpenBSD: times.h,v 1.6 2013/07/06 18:44:21 naddy Exp $ */ +/* $NetBSD: times.h,v 1.8 1995/03/26 20:24:54 jtc 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. + * + * @(#)times.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TIMES_H_ +#define _SYS_TIMES_H_ + +#include <sys/cdefs.h> +#include <sys/_types.h> + +#ifndef _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED_ +typedef __clock_t clock_t; +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#ifndef _KERNEL +__BEGIN_DECLS +clock_t times(struct tms *); +__END_DECLS +#endif +#endif /* !_SYS_TIMES_H_ */ diff --git a/sys/sys/timetc.h b/sys/sys/timetc.h new file mode 100644 index 0000000..ce81c34 --- /dev/null +++ b/sys/sys/timetc.h @@ -0,0 +1,107 @@ +/* $OpenBSD: timetc.h,v 1.10 2019/10/26 21:16:38 cheloha Exp $ */ + +/* + * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.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. + */ + +/* + * If we meet some day, and you think this stuff is worth it, you + * can buy me a beer in return. Poul-Henning Kamp + */ + +#ifndef _SYS_TIMETC_H_ +#define _SYS_TIMETC_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +#include <sys/queue.h> + +/*- + * `struct timecounter' is the interface between the hardware which implements + * a timecounter and the MI code which uses this to keep track of time. + * + * A timecounter is a binary counter which has two properties: + * * it runs at a fixed, known frequency. + * * it has sufficient bits to not roll over in less than approximately + * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta, + * for some indeterminate value of delta.) + */ + +struct timecounter; +typedef u_int timecounter_get_t(struct timecounter *); +typedef void timecounter_pps_t(struct timecounter *); + +/* + * Locks used to protect struct members in this file: + * I immutable after initialization + * t tc_lock + * w windup_mtx + */ + +struct timecounter { + timecounter_get_t *tc_get_timecount; /* [I] */ + /* + * This function reads the counter. It is not required to + * mask any unimplemented bits out, as long as they are + * constant. + */ + timecounter_pps_t *tc_poll_pps; /* [I] */ + /* + * This function is optional. It will be called whenever the + * timecounter is rewound, and is intended to check for PPS + * events. Normal hardware does not need it but timecounters + * which latch PPS in hardware (like sys/pci/xrpu.c) do. + */ + u_int tc_counter_mask; /* [I] */ + /* This mask should mask off any unimplemented bits. */ + u_int64_t tc_frequency; /* [I] */ + /* Frequency of the counter in Hz. */ + char *tc_name; /* [I] */ + /* Name of the timecounter. */ + int tc_quality; /* [I] */ + /* + * Used to determine if this timecounter is better than + * another timecounter higher means better. Negative + * means "only use at explicit request". + */ + void *tc_priv; /* [I] */ + /* Pointer to the timecounter's private parts. */ + SLIST_ENTRY(timecounter) tc_next; /* [I] */ + /* Pointer to the next timecounter. */ + int64_t tc_freq_adj; /* [tw] */ + /* Current frequency adjustment. */ + u_int64_t tc_precision; /* [I] */ + /* Precision of the counter. Computed in tc_init(). */ +}; + +struct rwlock; +extern struct rwlock tc_lock; + +extern struct timecounter *timecounter; + +u_int64_t tc_getfrequency(void); +u_int64_t tc_getprecision(void); +void tc_init(struct timecounter *tc); +void tc_setclock(const struct timespec *ts); +void tc_setrealtimeclock(const struct timespec *ts); +void tc_ticktock(void); +void inittimecounter(void); +int sysctl_tc(int *, u_int, void *, size_t *, void *, size_t); +void tc_adjfreq(int64_t *, int64_t *); +void tc_adjtime(int64_t *, int64_t *); + +#endif /* !_SYS_TIMETC_H_ */ diff --git a/sys/sys/tprintf.h b/sys/sys/tprintf.h new file mode 100644 index 0000000..e17877c --- /dev/null +++ b/sys/sys/tprintf.h @@ -0,0 +1,41 @@ +/* $OpenBSD: tprintf.h,v 1.6 2003/08/24 01:27:07 avsm Exp $ */ +/* $NetBSD: tprintf.h,v 1.10 1996/04/09 20:55:43 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. + * + * @(#)tprintf.h 8.1 (Berkeley) 6/2/93 + */ + +typedef struct session *tpr_t; + +tpr_t tprintf_open(struct proc *); +void tprintf_close(tpr_t); + +void tprintf(tpr_t, const char *fmt, ...) + __attribute__((__format__(__kprintf__,2,3))); diff --git a/sys/sys/tracepoint.h b/sys/sys/tracepoint.h new file mode 100644 index 0000000..d9a674a --- /dev/null +++ b/sys/sys/tracepoint.h @@ -0,0 +1,36 @@ +/* $OpenBSD: tracepoint.h,v 1.1 2020/01/21 16:16:23 mpi Exp $ */ + +/* + * Copyright (c) 2019 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_TRACEPOINT_H_ +#define _SYS_TRACEPOINT_H_ + +#ifdef _KERNEL + +#include "dt.h" +#if NDT > 0 +#include <dev/dt/dtvar.h> + +#define TRACEPOINT(func, name, args...) DT_STATIC_ENTER(func, name, args) + +#else /* NDT > 0 */ + +#define TRACEPOINT(func, name, args...) + +#endif /* NDT > 0 */ +#endif /* _KERNEL */ +#endif /* _SYS_TRACEPOINT_H_ */ diff --git a/sys/sys/tree.h b/sys/sys/tree.h new file mode 100644 index 0000000..ffcac90 --- /dev/null +++ b/sys/sys/tree.h @@ -0,0 +1,1006 @@ +/* $OpenBSD: tree.h,v 1.29 2017/07/30 19:27:20 deraadt Exp $ */ +/* + * Copyright 2002 Niels Provos <provos@citi.umich.edu> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +#include <sys/_null.h> + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __unused __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root))) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *); \ +attr struct type *name##_RB_NFIND(struct name *, struct type *); \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)))\ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)))\ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field))) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field))); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ + (x) = (y)) + + +/* + * 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. + */ + +struct rb_type { + int (*t_compare)(const void *, const void *); + void (*t_augment)(void *); + unsigned int t_offset; /* offset of rb_entry in type */ +}; + +struct rb_tree { + struct rb_entry *rbt_root; +}; + +struct rb_entry { + struct rb_entry *rbt_parent; + struct rb_entry *rbt_left; + struct rb_entry *rbt_right; + unsigned int rbt_color; +}; + +#define RBT_HEAD(_name, _type) \ +struct _name { \ + struct rb_tree rbh_root; \ +} + +#define RBT_ENTRY(_type) struct rb_entry + +static inline void +_rb_init(struct rb_tree *rbt) +{ + rbt->rbt_root = NULL; +} + +static inline int +_rb_empty(struct rb_tree *rbt) +{ + return (rbt->rbt_root == NULL); +} + +void *_rb_insert(const struct rb_type *, struct rb_tree *, void *); +void *_rb_remove(const struct rb_type *, struct rb_tree *, void *); +void *_rb_find(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_root(const struct rb_type *, struct rb_tree *); +void *_rb_min(const struct rb_type *, struct rb_tree *); +void *_rb_max(const struct rb_type *, struct rb_tree *); +void *_rb_next(const struct rb_type *, void *); +void *_rb_prev(const struct rb_type *, void *); +void *_rb_left(const struct rb_type *, void *); +void *_rb_right(const struct rb_type *, void *); +void *_rb_parent(const struct rb_type *, void *); +void _rb_set_left(const struct rb_type *, void *, void *); +void _rb_set_right(const struct rb_type *, void *, void *); +void _rb_set_parent(const struct rb_type *, void *, void *); +void _rb_poison(const struct rb_type *, void *, unsigned long); +int _rb_check(const struct rb_type *, void *, unsigned long); + +#define RBT_INITIALIZER(_head) { { NULL } } + +#define RBT_PROTOTYPE(_name, _type, _field, _cmp) \ +extern const struct rb_type *const _name##_RBT_TYPE; \ + \ +__unused static inline void \ +_name##_RBT_INIT(struct _name *head) \ +{ \ + _rb_init(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_INSERT(struct _name *head, struct _type *elm) \ +{ \ + return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_REMOVE(struct _name *head, struct _type *elm) \ +{ \ + return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_FIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NFIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_ROOT(struct _name *head) \ +{ \ + return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline int \ +_name##_RBT_EMPTY(struct _name *head) \ +{ \ + return _rb_empty(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MIN(struct _name *head) \ +{ \ + return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MAX(struct _name *head) \ +{ \ + return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NEXT(struct _type *elm) \ +{ \ + return _rb_next(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PREV(struct _type *elm) \ +{ \ + return _rb_prev(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_LEFT(struct _type *elm) \ +{ \ + return _rb_left(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_RIGHT(struct _type *elm) \ +{ \ + return _rb_right(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PARENT(struct _type *elm) \ +{ \ + return _rb_parent(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_LEFT(struct _type *elm, struct _type *left) \ +{ \ + return _rb_set_left(_name##_RBT_TYPE, elm, left); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_RIGHT(struct _type *elm, struct _type *right) \ +{ \ + return _rb_set_right(_name##_RBT_TYPE, elm, right); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_PARENT(struct _type *elm, struct _type *parent) \ +{ \ + return _rb_set_parent(_name##_RBT_TYPE, elm, parent); \ +} \ + \ +__unused static inline void \ +_name##_RBT_POISON(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_poison(_name##_RBT_TYPE, elm, poison); \ +} \ + \ +__unused static inline int \ +_name##_RBT_CHECK(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_check(_name##_RBT_TYPE, elm, poison); \ +} + +#define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ +static int \ +_name##_RBT_COMPARE(const void *lptr, const void *rptr) \ +{ \ + const struct _type *l = lptr, *r = rptr; \ + return _cmp(l, r); \ +} \ +static const struct rb_type _name##_RBT_INFO = { \ + _name##_RBT_COMPARE, \ + _aug, \ + offsetof(struct _type, _field), \ +}; \ +const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO + +#define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ +static void \ +_name##_RBT_AUGMENT(void *ptr) \ +{ \ + struct _type *p = ptr; \ + return _aug(p); \ +} \ +RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT) + +#define RBT_GENERATE(_name, _type, _field, _cmp) \ + RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) + +#define RBT_INIT(_name, _head) _name##_RBT_INIT(_head) +#define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm) +#define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm) +#define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key) +#define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key) +#define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head) +#define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head) +#define RBT_MIN(_name, _head) _name##_RBT_MIN(_head) +#define RBT_MAX(_name, _head) _name##_RBT_MAX(_head) +#define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm) +#define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm) +#define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm) +#define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm) +#define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm) +#define RBT_SET_LEFT(_name, _elm, _l) _name##_RBT_SET_LEFT(_elm, _l) +#define RBT_SET_RIGHT(_name, _elm, _r) _name##_RBT_SET_RIGHT(_elm, _r) +#define RBT_SET_PARENT(_name, _elm, _p) _name##_RBT_SET_PARENT(_elm, _p) +#define RBT_POISON(_name, _elm, _p) _name##_RBT_POISON(_elm, _p) +#define RBT_CHECK(_name, _elm, _p) _name##_RBT_CHECK(_elm, _p) + +#define RBT_FOREACH(_e, _name, _head) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_NEXT(_name, (_e))) + +#define RBT_FOREACH_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \ + (_e) = (_n)) + +#define RBT_FOREACH_REVERSE(_e, _name, _head) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_PREV(_name, (_e))) + +#define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \ + (_e) = (_n)) + +#endif /* _SYS_TREE_H_ */ diff --git a/sys/sys/tty.h b/sys/sys/tty.h new file mode 100644 index 0000000..efe0bfb --- /dev/null +++ b/sys/sys/tty.h @@ -0,0 +1,336 @@ +/* $OpenBSD: tty.h,v 1.38 2019/07/19 00:17:16 cheloha Exp $ */ +/* $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)tty.h 8.6 (Berkeley) 1/21/94 + */ + +#include <sys/termios.h> +#include <sys/queue.h> +#include <sys/selinfo.h> /* For struct selinfo. */ +#include <sys/timeout.h> + +#define KERN_TTY_TKNIN 1 /* quad: input chars */ +#define KERN_TTY_TKNOUT 2 /* quad: output chars */ +#define KERN_TTY_TKRAWCC 3 /* quad: input chars, raw mode */ +#define KERN_TTY_TKCANCC 4 /* quad: input char, cooked mode */ +#define KERN_TTY_INFO 5 /* struct: tty stats */ +/* was KERN_TTY_MAXPTYS 6 */ +/* was KERN_TTY_NPTYS 7 */ +#define KERN_TTY_MAXID 8 + +#define CTL_KERN_TTY_NAMES { \ + { 0, 0 }, \ + { "tk_nin", CTLTYPE_QUAD }, \ + { "tk_nout", CTLTYPE_QUAD }, \ + { "tk_rawcc", CTLTYPE_QUAD }, \ + { "tk_cancc", CTLTYPE_QUAD }, \ + { "ttyinfo", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ +} + +/* ptmget, for /dev/ptm pty getting ioctl PTMGET */ + +struct ptmget { + int cfd; + int sfd; + char cn[16]; + char sn[16]; +}; +#define PTMGET _IOR('t', 1, struct ptmget) /* get ptys */ +#define PATH_PTMDEV "/dev/ptm" +#define TTY_GID 4 /* XXX evil hardcoding of tty gid */ + +/* + * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have + * exactly the same behaviour as in true clists. + * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality + * (but, saves memory and cpu time) + * + * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!! + */ +struct clist { + int c_cc; /* count of characters in queue */ + int c_cn; /* total ring buffer length */ + u_char *c_cf; /* points to first character */ + u_char *c_cl; /* points to next open character */ + u_char *c_cs; /* start of ring buffer */ + u_char *c_ce; /* c_ce + c_len */ + u_char *c_cq; /* N bits/bytes long, see tty_subr.c */ +}; + +/* + * Per-tty structure. + * + * Should be split in two, into device and tty drivers. + * Glue could be masks of what to echo and circular buffer + * (low, high, timeout). + */ +struct tty { + TAILQ_ENTRY(tty) tty_link; /* Link in global tty list. */ + struct clist t_rawq; /* Device raw input queue. */ + long t_rawcc; /* Raw input queue statistics. */ + struct clist t_canq; /* Device canonical queue. */ + long t_cancc; /* Canonical queue statistics. */ + struct clist t_outq; /* Device output queue. */ + long t_outcc; /* Output queue statistics. */ + int t_qlen; /* Length of above queues */ + u_char t_line; /* Interface to device drivers. */ + dev_t t_dev; /* Device. */ + int t_state; /* Device and driver (TS*) state. */ + int t_flags; /* Tty flags. */ + struct pgrp *t_pgrp; /* Foreground process group. */ + struct session *t_session; /* Enclosing session. */ + struct selinfo t_rsel; /* Tty read/oob select. */ + struct selinfo t_wsel; /* Tty write select. */ + struct termios t_termios; /* Termios state. */ + struct winsize t_winsize; /* Window size. */ + /* Start output. */ + void (*t_oproc)(struct tty *); + /* Set hardware state. */ + int (*t_param)(struct tty *, struct termios *); + /* Set hardware flow control. */ + int (*t_hwiflow)(struct tty *tp, int flag); + void *t_sc; /* XXX: net/if_sl.c:sl_softc. */ + short t_column; /* Tty output column. */ + short t_rocount, t_rocol; /* Tty. */ + short t_hiwat; /* High water mark. */ + short t_lowat; /* Low water mark. */ + short t_gen; /* Generation number. */ + struct timeout t_rstrt_to; /* restart timeout */ + struct timeval t_tv; /* timestamp */ +}; + +/* + * Small version of struct tty exported via sysctl KERN_TTY_INFO + */ +struct itty { + dev_t t_dev; + int t_rawq_c_cc; + int t_canq_c_cc; + int t_outq_c_cc; + short t_hiwat; + short t_lowat; + short t_column; + int t_state; + struct session *t_session; + pid_t t_pgrp_pg_id; + u_char t_line; +}; + +#define t_cc t_termios.c_cc +#define t_cflag t_termios.c_cflag +#define t_iflag t_termios.c_iflag +#define t_ispeed t_termios.c_ispeed +#define t_lflag t_termios.c_lflag +#define t_min t_termios.c_min +#define t_oflag t_termios.c_oflag +#define t_ospeed t_termios.c_ospeed +#define t_time t_termios.c_time + +#define TTIPRI 25 /* Sleep priority for tty reads. */ +#define TTOPRI 26 /* Sleep priority for tty writes. */ + +#define TTMASK 15 +#define OBUFSIZ 512 +#define TTYHOG(tp) (tp)->t_qlen + +#ifdef _KERNEL +#define TTMAXLOWAT 256 +#define TTMINLOWAT 32 +#define TTMINHIWAT 100 +#define TTHIWATMINSPACE 200 /* Min space above hiwat */ +#endif + +/* These flags are kept in t_state. */ +#define TS_ASLEEP 0x00001 /* Process waiting for tty. */ +#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */ +#define TS_BUSY 0x00004 /* Draining output. */ +#define TS_CARR_ON 0x00008 /* Carrier is present. */ +#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */ +#define TS_ISOPEN 0x00020 /* Open has completed. */ +#define TS_TBLOCK 0x00040 /* Further input blocked. */ +#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */ +#define TS_TTSTOP 0x00100 /* Output paused. */ +#define TS_WOPEN 0x00200 /* Open in progress. */ +#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */ + +/* State for intra-line fancy editing work. */ +#define TS_BKSL 0x00800 /* State for lowercase \ work. */ +#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */ +#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */ +#define TS_LNCH 0x04000 /* Next character is literal. */ +#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */ +#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN) + +#define TS_TSTAMPDCDSET 0x10000 /* update timestamp on DCD set */ +#define TS_TSTAMPDCDCLR 0x20000 /* update timestamp on DCD clr */ +#define TS_TSTAMPCTSSET 0x40000 /* update timestamp on CTS set */ +#define TS_TSTAMPCTSCLR 0x80000 /* update timestamp on CTS clr */ + +/* Character type information. */ +#define ORDINARY 0 +#define CONTROL 1 +#define BACKSPACE 2 +#define NEWLINE 3 +#define TAB 4 +#define VTAB 5 +#define RETURN 6 + +struct speedtab { + int sp_speed; /* Speed. */ + int sp_code; /* Code. */ +}; + +/* Modem control commands (driver). */ +#define DMSET 0 +#define DMBIS 1 +#define DMBIC 2 +#define DMGET 3 + +/* Flags on a character passed to ttyinput. */ +#define TTY_CHARMASK 0x000000ff /* Character mask */ +#define TTY_QUOTE 0x00000100 /* Character quoted */ +#define TTY_ERRORMASK 0xff000000 /* Error mask */ +#define TTY_FE 0x01000000 /* Framing error or BREAK condition */ +#define TTY_PE 0x02000000 /* Parity error */ + +/* Is tp controlling terminal for pr? */ +#define isctty(pr, tp) \ + ((pr)->ps_session == (tp)->t_session && (pr)->ps_flags & PS_CONTROLT) + +/* Is pr in background of tp? */ +#define isbackground(pr, tp) \ + (isctty((pr), (tp)) && (pr)->ps_pgrp != (tp)->t_pgrp) + +/* + * ttylist_head is defined here so that user-land has access to it. + */ +TAILQ_HEAD(ttylist_head, tty); /* the ttylist is a TAILQ */ + +#ifdef _KERNEL + +extern int tty_count; /* number of ttys in global ttylist */ +extern struct ttychars ttydefaults; + +/* Symbolic sleep message strings. */ +extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; + +extern int64_t tk_cancc, tk_nin, tk_nout, tk_rawcc; + +int sysctl_tty(int *, u_int, void *, size_t *, void *, size_t); +int sysctl_pty(int *, u_int, void *, size_t *, void *, size_t); + +int b_to_q(u_char *cp, int cc, struct clist *q); +void catq(struct clist *from, struct clist *to); +void clist_init(void); +int getc(struct clist *q); +void ndflush(struct clist *q, int cc); +int ndqb(struct clist *q, int flag); +u_char *nextc(struct clist *q, u_char *cp, int *c); +int putc(int c, struct clist *q); +int q_to_b(struct clist *q, u_char *cp, int cc); +int unputc(struct clist *q); + +int nullmodem(struct tty *tp, int flag); +int tputchar(int c, struct tty *tp); +int ttioctl(struct tty *tp, u_long com, caddr_t data, int flag, + struct proc *p); +int ttread(struct tty *tp, struct uio *uio, int flag); +void ttrstrt(void *tp); +int ttpoll(dev_t device, int events, struct proc *p); +int ttkqfilter(dev_t dev, struct knote *kn); +void ttsetwater(struct tty *tp); +int ttspeedtab(int speed, const struct speedtab *table); +int ttstart(struct tty *tp); +void ttwakeupwr(struct tty *tp); +void ttwakeup(struct tty *tp); +int ttwrite(struct tty *tp, struct uio *uio, int flag); +void ttychars(struct tty *tp); +int ttycheckoutq(struct tty *tp, int wait); +int ttyclose(struct tty *tp); +void ttyflush(struct tty *tp, int rw); +void ttyinfo(struct tty *tp); +int ttyinput(int c, struct tty *tp); +int ttylclose(struct tty *tp, int flag, struct proc *p); +int ttymodem(struct tty *tp, int flag); +int ttyopen(dev_t device, struct tty *tp, struct proc *p); +int ttyoutput(int c, struct tty *tp); +void ttypend(struct tty *tp); +void ttyretype(struct tty *tp); +void ttyrub(int c, struct tty *tp); +int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg); +int ttywait(struct tty *tp); +int ttywflush(struct tty *tp); +void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd); + +void tty_init(void); +struct tty *ttymalloc(int); +void ttyfree(struct tty *); +u_char *firstc(struct clist *clp, int *c); + +int cttyopen(dev_t, int, int, struct proc *); +int cttyread(dev_t, struct uio *, int); +int cttywrite(dev_t, struct uio *, int); +int cttyioctl(dev_t, u_long, caddr_t, int, struct proc *); +int cttypoll(dev_t, int, struct proc *); + +void clalloc(struct clist *, int, int); +void clfree(struct clist *); + +int nullioctl(struct tty *, u_long, caddr_t, int, struct proc *); + +int pppopen(dev_t dev, struct tty *, struct proc *); +int pppclose(struct tty *, int, struct proc *); +int ppptioctl(struct tty *, u_long, caddr_t, int, struct proc *); +int pppinput(int c, struct tty *); +int pppstart(struct tty *); +int pppread(struct tty *, struct uio *, int); +int pppwrite(struct tty *, struct uio *, int); + +int nmeaopen(dev_t, struct tty *, struct proc *); +int nmeaclose(struct tty *, int, struct proc *); +int nmeainput(int, struct tty *); + +int mstsopen(dev_t, struct tty *, struct proc *); +int mstsclose(struct tty *, int, struct proc *); +int mstsinput(int, struct tty *); + +int endrunopen(dev_t, struct tty *, struct proc *); +int endrunclose(struct tty *, int, struct proc *); +int endruninput(int, struct tty *); + +#endif /* _KERNEL */ diff --git a/sys/sys/ttycom.h b/sys/sys/ttycom.h new file mode 100644 index 0000000..82af7e8 --- /dev/null +++ b/sys/sys/ttycom.h @@ -0,0 +1,151 @@ +/* $OpenBSD: ttycom.h,v 1.17 2018/06/16 13:55:03 deraadt Exp $ */ +/* $NetBSD: ttycom.h,v 1.4 1996/05/19 17:17:53 jonathan 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. + * + * @(#)ttycom.h 8.1 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_TTYCOM_H_ +#define _SYS_TTYCOM_H_ + +#include <sys/ioccom.h> + +/* Tty ioctl's. */ + +/* + * Window/terminal size structure. This information is stored by the kernel + * in order to provide a consistent interface, but is not used by the kernel. + */ +struct winsize { + unsigned short ws_row; /* rows, in characters */ + unsigned short ws_col; /* columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, pixels */ + unsigned short ws_ypixel; /* vertical size, pixels */ +}; + +struct tstamps { + int ts_set; /* TIOCM_CAR and/or TIOCM_CTS */ + int ts_clr; +}; + +#define TIOCM_LE 0001 /* line enable */ +#define TIOCM_DTR 0002 /* data terminal ready */ +#define TIOCM_RTS 0004 /* request to send */ +#define TIOCM_ST 0010 /* secondary transmit */ +#define TIOCM_SR 0020 /* secondary receive */ +#define TIOCM_CTS 0040 /* clear to send */ +#define TIOCM_CAR 0100 /* carrier detect */ +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RNG 0200 /* ring */ +#define TIOCM_RI TIOCM_RNG +#define TIOCM_DSR 0400 /* data set ready */ + /* 8-10 compat */ +#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */ +#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */ + /* 15 unused */ +#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ + /* 17-18 compat */ +#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */ +#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ +#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ +#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ +#define TIOCGETD _IOR('t', 26, int) /* get line discipline */ +#define TIOCSETD _IOW('t', 27, int) /* set line discipline */ +#define TIOCSETVERAUTH _IOW('t', 28, int) /* set verified auth */ +#define TIOCCLRVERAUTH _IO('t', 29) /* clear verified auth */ +#define TIOCCHKVERAUTH _IO('t', 30) /* check verified auth */ + /* 127-124 compat */ +#define TIOCSBRK _IO('t', 123) /* set break bit */ +#define TIOCCBRK _IO('t', 122) /* clear break bit */ +#define TIOCSDTR _IO('t', 121) /* set data terminal ready */ +#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */ +#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ +#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ + /* 117-116 compat */ +#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ +#define TIOCNOTTY _IO('t', 113) /* void tty association */ +#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ +#define TIOCPKT_DATA 0x00 /* data packet */ +#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define TIOCPKT_STOP 0x04 /* stop output */ +#define TIOCPKT_START 0x08 /* start output */ +#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ +#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ +#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ +#define TIOCSTART _IO('t', 110) /* start output, like ^Q */ +#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ +#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ +#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ +#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ +#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ +#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ +#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ +#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ +#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ +#define TIOCUCNTL_SBRK (TIOCSBRK & 0xff)/* set break bit, usr ctnl */ +#define TIOCUCNTL_CBRK (TIOCCBRK & 0xff)/* clear break bit, usr ctnl */ +#define TIOCSTAT _IO('t', 101) /* generate status message */ +#define TIOCGSID _IOR('t', 99, int) /* get sid of tty */ +#define TIOCCONS _IOW('t', 98, int) /* become virtual console */ +#define TIOCSCTTY _IO('t', 97) /* become controlling tty */ +#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ +#define TIOCSIG _IOW('t', 95, int) /* pty: generate signal */ +#define TIOCDRAIN _IO('t', 94) /* wait till output drained */ +#define TIOCGFLAGS _IOR('t', 93, int) /* get device flags */ +#define TIOCSFLAGS _IOW('t', 92, int) /* set device flags */ +#define TIOCFLAG_SOFTCAR 0x01 /* ignore hardware carrier */ +#define TIOCFLAG_CLOCAL 0x02 /* set clocal on open */ +#define TIOCFLAG_CRTSCTS 0x04 /* set crtscts on open */ +#define TIOCFLAG_MDMBUF 0x08 /* set mdmbuf on open */ +#define TIOCFLAG_PPS 0x10 /* call hardpps on carrier up */ +#define TIOCGTSTAMP _IOR('t', 91, struct timeval) /* get timestamp */ +#define TIOCSTSTAMP _IOW('t', 90, struct tstamps) /* timestamp reasons */ + +/* Backwards compatibility */ +#define TIOCMODG TIOCMGET +#define TIOCMODS TIOCMSET + +#define TTYDISC 0 /* termios tty line discipline */ +#define TABLDISC 3 /* tablet discipline */ +#define SLIPDISC 4 /* serial IP discipline */ +#define PPPDISC 5 /* ppp discipline */ +#define STRIPDISC 6 /* metricom wireless IP discipline */ +#define NMEADISC 7 /* NMEA0183 discipline */ +#define MSTSDISC 8 /* Meinberg time string discipline */ +#define ENDRUNDISC 9 /* EndRun time format discipline */ + +#endif /* !_SYS_TTYCOM_H_ */ diff --git a/sys/sys/ttydefaults.h b/sys/sys/ttydefaults.h new file mode 100644 index 0000000..07ddac2 --- /dev/null +++ b/sys/sys/ttydefaults.h @@ -0,0 +1,95 @@ +/* $OpenBSD: ttydefaults.h,v 1.7 2019/03/12 11:01:25 nicm Exp $ */ +/* $NetBSD: ttydefaults.h,v 1.8 1996/04/09 20:55:45 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94 + */ + +/* + * System wide defaults for terminal state. + */ +#ifndef _SYS_TTYDEFAULTS_H_ +#define _SYS_TTYDEFAULTS_H_ + +/* + * Defaults on "first" open. + */ +#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) +#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) +#define TTYDEF_SPEED (B9600) + +/* + * Control Character Defaults + */ +#define CTRL(x) (x&037) +#define CEOF CTRL('d') +#define CEOL ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */ +#define CERASE 0177 +#define CINTR CTRL('c') +#define CSTATUS ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */ +#define CKILL CTRL('u') +#define CMIN 1 +#define CQUIT 034 /* FS, ^\ */ +#define CSUSP CTRL('z') +#define CTIME 0 +#define CDSUSP CTRL('y') +#define CSTART CTRL('q') +#define CSTOP CTRL('s') +#define CLNEXT CTRL('v') +#define CDISCARD CTRL('o') +#define CWERASE CTRL('w') +#define CREPRINT CTRL('r') +#define CEOT CEOF +/* compat */ +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD + +/* PROTECTED INCLUSION ENDS HERE */ +#endif /* !_SYS_TTYDEFAULTS_H_ */ + +/* + * #define TTYDEFCHARS to include an array of default control characters. + */ +#ifdef TTYDEFCHARS +cc_t ttydefchars[NCCS] = { + CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, + _POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, + CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE +}; +#undef TTYDEFCHARS +#endif diff --git a/sys/sys/types.h b/sys/sys/types.h new file mode 100644 index 0000000..dbbde58 --- /dev/null +++ b/sys/sys/types.h @@ -0,0 +1,261 @@ +/* $OpenBSD: types.h,v 1.48 2019/02/09 04:54:11 guenther Exp $ */ +/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */ + +/*- + * 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. + * + * @(#)types.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include <sys/cdefs.h> +#if __BSD_VISIBLE +#include <sys/endian.h> +#else +#include <sys/_endian.h> +#endif + +#if __BSD_VISIBLE +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef unsigned char unchar; /* Sys V compatibility */ +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +typedef unsigned long ulong; /* Sys V compatibility */ + +typedef __cpuid_t cpuid_t; /* CPU id */ +typedef __register_t register_t; /* register-sized type */ +#endif /* __BSD_VISIBLE */ + +/* + * XXX The exact-width bit types should only be exposed if __BSD_VISIBLE + * but the rest of the includes are not ready for that yet. + */ +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +#endif + +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* BSD-style unsigned bits types */ +typedef __uint8_t u_int8_t; +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; + +/* quads, deprecated in favor of 64 bit int types */ +typedef __int64_t quad_t; +typedef __uint64_t u_quad_t; + +#if __BSD_VISIBLE +/* VM system types */ +typedef __vaddr_t vaddr_t; +typedef __paddr_t paddr_t; +typedef __vsize_t vsize_t; +typedef __psize_t psize_t; +#endif /* __BSD_VISIBLE */ + +/* Standard system types */ +typedef __blkcnt_t blkcnt_t; /* blocks allocated for file */ +typedef __blksize_t blksize_t; /* optimal blocksize for I/O */ +typedef char * caddr_t; /* core address */ +typedef __int32_t daddr32_t; /* 32-bit disk address */ +typedef __int64_t daddr_t; /* 64-bit disk address */ +typedef __dev_t dev_t; /* device number */ +typedef __fixpt_t fixpt_t; /* fixed point number */ +typedef __gid_t gid_t; /* group id */ +typedef __id_t id_t; /* may contain pid, uid or gid */ +typedef __ino_t ino_t; /* inode number */ +typedef __key_t key_t; /* IPC key (for Sys V IPC) */ +typedef __mode_t mode_t; /* permissions */ +typedef __nlink_t nlink_t; /* link count */ +typedef __rlim_t rlim_t; /* resource limit */ +typedef __segsz_t segsz_t; /* segment size */ +typedef __swblk_t swblk_t; /* swap offset */ +typedef __uid_t uid_t; /* user id */ +typedef __useconds_t useconds_t; /* microseconds */ +typedef __suseconds_t suseconds_t; /* microseconds (signed) */ +typedef __fsblkcnt_t fsblkcnt_t; /* file system block count */ +typedef __fsfilcnt_t fsfilcnt_t; /* file system file count */ + +/* + * The following types may be defined in multiple header files. + */ +#ifndef _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED_ +typedef __clock_t clock_t; +#endif + +#ifndef _CLOCKID_T_DEFINED_ +#define _CLOCKID_T_DEFINED_ +typedef __clockid_t clockid_t; +#endif + +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _SSIZE_T_DEFINED_ +#define _SSIZE_T_DEFINED_ +typedef __ssize_t ssize_t; +#endif + +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +#ifndef _TIMER_T_DEFINED_ +#define _TIMER_T_DEFINED_ +typedef __timer_t timer_t; +#endif + +#ifndef _OFF_T_DEFINED_ +#define _OFF_T_DEFINED_ +typedef __off_t off_t; +#endif + +/* + * These belong in unistd.h, but are placed here too to ensure that + * long arguments will be promoted to off_t if the program fails to + * include that header or explicitly cast them to off_t. + */ +#if __BSD_VISIBLE && !defined(_KERNEL) +__BEGIN_DECLS +off_t lseek(int, off_t, int); +int ftruncate(int, off_t); +int truncate(const char *, off_t); +__END_DECLS +#endif /* __BSD_VISIBLE && !_KERNEL */ + +#if __BSD_VISIBLE +/* Major, minor numbers, dev_t's. */ +#define major(x) (((unsigned)(x) >> 8) & 0xff) +#define minor(x) ((unsigned)((x) & 0xff) | (((x) & 0xffff0000) >> 8)) +#define makedev(x,y) ((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) & 0xffff00) << 8))) +#endif + +#if defined(__STDC__) && defined(_KERNEL) +/* + * Forward structure declarations for function prototypes. We include the + * common structures that cross subsystem boundaries here; others are mostly + * used in the same place that the structure is defined. + */ +struct proc; +struct pgrp; +struct ucred; +struct rusage; +struct file; +struct buf; +struct tty; +struct uio; +#endif + +#ifdef _KERNEL +#if defined(__GNUC__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +/* Support for C99: type _Bool is already built-in. */ +#define false 0 +#define true 1 + +#else +/* `_Bool' type must promote to `int' or `unsigned int'. */ +typedef enum { + false = 0, + true = 1 +} _Bool; + +/* And those constants must also be available as macros. */ +#define false false +#define true true + +#endif + +/* User visible type `bool' is provided as a macro which may be redefined */ +#define bool _Bool + +/* Inform that everything is fine */ +#define __bool_true_false_are_defined 1 + +#endif /* _KERNEL */ + +#endif /* !_SYS_TYPES_H_ */ diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h new file mode 100644 index 0000000..7ce0fd6 --- /dev/null +++ b/sys/sys/ucred.h @@ -0,0 +1,84 @@ +/* $OpenBSD: ucred.h,v 1.13 2018/06/21 13:58:21 visa Exp $ */ +/* $NetBSD: ucred.h,v 1.12 1995/06/01 22:44:50 jtc 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. + * + * @(#)ucred.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_UCRED_H_ +#define _SYS_UCRED_H_ + +#include <sys/syslimits.h> + +/* + * Credentials. + */ +struct ucred { + u_int cr_ref; /* reference count */ + +/* The following fields are all copied by crset() */ +#define cr_startcopy cr_uid + uid_t cr_uid; /* effective user id */ + uid_t cr_ruid; /* Real user id. */ + uid_t cr_svuid; /* Saved effective user id. */ + gid_t cr_gid; /* effective group id */ + gid_t cr_rgid; /* Real group id. */ + gid_t cr_svgid; /* Saved effective group id. */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS_MAX]; /* groups */ +}; +#define NOCRED ((struct ucred *)-1) /* no credential available */ +#define FSCRED ((struct ucred *)-2) /* filesystem credential */ + +/* + * Userspace version, for use in syscalls arguments + */ +struct xucred { + uid_t cr_uid; /* user id */ + gid_t cr_gid; /* group id */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS_MAX]; /* groups */ +}; + +#ifdef _KERNEL + +int crfromxucred(struct ucred *, const struct xucred *); +void crset(struct ucred *, const struct ucred *); +struct ucred *crcopy(struct ucred *cr); +struct ucred *crdup(struct ucred *cr); +void crfree(struct ucred *cr); +struct ucred *crget(void); +struct ucred *crhold(struct ucred *); +int suser(struct proc *p); +int suser_ucred(struct ucred *cred); + +#endif /* _KERNEL */ + +#endif /* !_SYS_UCRED_H_ */ diff --git a/sys/sys/uio.h b/sys/sys/uio.h new file mode 100644 index 0000000..fdc4690 --- /dev/null +++ b/sys/sys/uio.h @@ -0,0 +1,108 @@ +/* $OpenBSD: uio.h,v 1.19 2018/08/20 16:00:22 mpi Exp $ */ +/* $NetBSD: uio.h,v 1.12 1996/02/09 18:25:45 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include <sys/cdefs.h> +#include <sys/_types.h> + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _SSIZE_T_DEFINED_ +#define _SSIZE_T_DEFINED_ +typedef __ssize_t ssize_t; +#endif + +struct iovec { + void *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; + +#if __BSD_VISIBLE /* needed by kdump */ +enum uio_rw { UIO_READ, UIO_WRITE }; + +/* Segment flag values. */ +enum uio_seg { + UIO_USERSPACE, /* from user data space */ + UIO_SYSSPACE /* from system space */ +}; +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +struct uio { + struct iovec *uio_iov; /* pointer to array of iovecs */ + int uio_iovcnt; /* number of iovecs in array */ + off_t uio_offset; /* offset into file this uio corresponds to */ + size_t uio_resid; /* residual i/o count */ + enum uio_seg uio_segflg; /* see above */ + enum uio_rw uio_rw; /* see above */ + struct proc *uio_procp;/* associated thread or NULL */ +}; + +/* + * Limits + */ +#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ +#endif /* _KERNEL */ + +#if __BSD_VISIBLE +#define UIO_MAXIOV 1024 /* Deprecated, use IOV_MAX instead */ +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +#if __BSD_VISIBLE +ssize_t preadv(int, const struct iovec *, int, __off_t); +ssize_t pwritev(int, const struct iovec *, int, __off_t); +#endif /* __BSD_VISIBLE */ +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); +__END_DECLS +#else +int ureadc(int c, struct uio *); + +struct file; +int iovec_copyin(const struct iovec *, struct iovec **, struct iovec *, + unsigned int, size_t *); +void iovec_free(struct iovec *, unsigned int ); +int dofilereadv(struct proc *, int, struct uio *, int, register_t *); +int dofilewritev(struct proc *, int, struct uio *, int, register_t *); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_UIO_H_ */ diff --git a/sys/sys/un.h b/sys/sys/un.h new file mode 100644 index 0000000..63619fa --- /dev/null +++ b/sys/sys/un.h @@ -0,0 +1,65 @@ +/* $OpenBSD: un.h,v 1.14 2015/07/18 15:00:01 guenther Exp $ */ +/* $NetBSD: un.h,v 1.11 1996/02/04 02:12:47 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. + * + * @(#)un.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_UN_H_ +#define _SYS_UN_H_ + +#include <sys/cdefs.h> +#include <sys/_types.h> + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef __sa_family_t sa_family_t; /* sockaddr address family type */ +#endif + +/* + * Definitions for UNIX IPC domain. + */ +struct sockaddr_un { + unsigned char sun_len; /* sockaddr len excluding NUL */ + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[104]; /* path name (gag) */ +}; + +#ifndef _KERNEL +#if __BSD_VISIBLE + +/* actual length of an initialized sockaddr_un */ +#define SUN_LEN(su) \ + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) + +#endif /* __BSD_VISIBLE */ + +#endif /* _KERNEL */ +#endif /* !_SYS_UN_H_ */ diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h new file mode 100644 index 0000000..1b90fb1 --- /dev/null +++ b/sys/sys/unistd.h @@ -0,0 +1,106 @@ +/* $OpenBSD: unistd.h,v 1.31 2015/07/20 00:56:10 guenther Exp $ */ +/* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 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. + * + * @(#)unistd.h 8.2 (Berkeley) 1/7/94 + */ + +#ifndef _SYS_UNISTD_H_ +#define _SYS_UNISTD_H_ + +#include <sys/cdefs.h> + +#define _POSIX_VDISABLE (0377) +#define _POSIX_ASYNC_IO (-1) +#define _POSIX_PRIO_IO (-1) +#define _POSIX_SYNC_IO (-1) + +/* Define the POSIX.1 version we target for compliance. */ +#define _POSIX_VERSION 200809L + +/* access function */ +#define F_OK 0 /* test for existence of file */ +#define X_OK 0x01 /* test for execute or search permission */ +#define W_OK 0x02 /* test for write permission */ +#define R_OK 0x04 /* test for read permission */ + +/* whence values for lseek(2) */ +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ + +#if __BSD_VISIBLE +/* old BSD whence values for lseek(2); renamed by POSIX 1003.1 */ +#define L_SET SEEK_SET +#define L_INCR SEEK_CUR +#define L_XTND SEEK_END + +/* the parameters argument passed to the __tfork() syscall */ +struct __tfork { + void *tf_tcb; + pid_t *tf_tid; + void *tf_stack; +}; + +/* the parameters argument for the kbind() syscall */ +struct __kbind { + void *kb_addr; + size_t kb_size; +}; +#define KBIND_BLOCK_MAX 2 /* powerpc, sparc, and sparc64 need 2 blocks */ +#define KBIND_DATA_MAX 24 /* sparc64 needs 6, four-byte words */ +#endif + +/* the pathconf(2) variable values are part of the ABI */ + +/* configurable pathname variables */ +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_CHOWN_RESTRICTED 7 +#define _PC_NO_TRUNC 8 +#define _PC_VDISABLE 9 +#define _PC_2_SYMLINKS 10 +#define _PC_ALLOC_SIZE_MIN 11 +#define _PC_ASYNC_IO 12 +#define _PC_FILESIZEBITS 13 +#define _PC_PRIO_IO 14 +#define _PC_REC_INCR_XFER_SIZE 15 +#define _PC_REC_MAX_XFER_SIZE 16 +#define _PC_REC_MIN_XFER_SIZE 17 +#define _PC_REC_XFER_ALIGN 18 +#define _PC_SYMLINK_MAX 19 +#define _PC_SYNC_IO 20 +#define _PC_TIMESTAMP_RESOLUTION 21 + +#endif /* !_SYS_UNISTD_H_ */ diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h new file mode 100644 index 0000000..daa22a1 --- /dev/null +++ b/sys/sys/unpcb.h @@ -0,0 +1,111 @@ +/* $OpenBSD: unpcb.h,v 1.17 2019/07/15 12:28:06 bluhm Exp $ */ +/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd 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. + * + * @(#)unpcb.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * Protocol control block for an active + * instance of a UNIX internal protocol. + * + * A socket may be associated with an vnode in the + * file system. If so, the unp_vnode pointer holds + * a reference count to this vnode, which should be vrele'd + * when the socket goes away. + * + * A socket may be connected to another socket, in which + * case the control block of the socket to which it is connected + * is given by unp_conn. + * + * A socket may be referenced by a number of sockets (e.g. several + * sockets may be connected to a datagram socket.) These sockets + * are in a linked list starting with unp_refs, linked through + * unp_nextref and null-terminated. Note that a socket may be referenced + * by a number of other sockets and may also reference a socket (not + * necessarily one which is referencing it). This generates + * the need for unp_refs and unp_nextref to be separate fields. + * + * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt + * so that changes in the sockbuf may be computed to modify + * back pressure on the sender accordingly. + */ + +struct unpcb { + struct socket *unp_socket; /* pointer back to socket */ + struct vnode *unp_vnode; /* if associated with file */ + struct file *unp_file; /* backpointer for unp_gc() */ + struct unpcb *unp_conn; /* control block of connected socket */ + ino_t unp_ino; /* fake inode number */ + SLIST_HEAD(,unpcb) unp_refs; /* referencing socket linked list */ + SLIST_ENTRY(unpcb) unp_nextref; /* link in unp_refs list */ + struct mbuf *unp_addr; /* bound address of socket */ + long unp_msgcount; /* references from socket rcv buf */ + int unp_flags; /* this unpcb contains peer eids */ + struct sockpeercred unp_connid;/* id of peer process */ + struct timespec unp_ctime; /* holds creation time */ + LIST_ENTRY(unpcb) unp_link; /* link in per-AF list of sockets */ +}; + +/* + * flag bits in unp_flags + */ +#define UNP_FEIDS 0x01 /* unp_connid contains information */ +#define UNP_FEIDSBIND 0x02 /* unp_connid was set by a bind */ +#define UNP_GCMARK 0x04 /* mark during unp_gc() */ +#define UNP_GCDEFER 0x08 /* ref'd, but not marked in this pass */ +#define UNP_GCDEAD 0x10 /* unref'd in this pass */ + +#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb)) + +#ifdef _KERNEL +struct fdpass { + struct file *fp; + int flags; +}; + +int uipc_usrreq(struct socket *, int , struct mbuf *, + struct mbuf *, struct mbuf *, struct proc *); +int uipc_attach(struct socket *, int); +int uipc_detach(struct socket *); + +void unp_init(void); +int unp_bind(struct unpcb *, struct mbuf *, struct proc *); +int unp_connect(struct socket *, struct mbuf *, struct proc *); +int unp_connect2(struct socket *, struct socket *); +void unp_detach(struct unpcb *); +void unp_disconnect(struct unpcb *); +void unp_drop(struct unpcb *, int); +void unp_gc(void *); +void unp_shutdown(struct unpcb *); +int unp_externalize(struct mbuf *, socklen_t, int); +int unp_internalize(struct mbuf *, struct proc *); +void unp_dispose(struct mbuf *); +#endif /* _KERNEL */ diff --git a/sys/sys/user.h b/sys/sys/user.h new file mode 100644 index 0000000..7ab7205 --- /dev/null +++ b/sys/sys/user.h @@ -0,0 +1,48 @@ +/* $OpenBSD: user.h,v 1.9 2014/07/08 23:31:22 deraadt Exp $ */ +/* $NetBSD: user.h,v 1.10 1996/04/09 20:55:49 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)user.h 8.2 (Berkeley) 9/23/93 + */ + +#include <machine/pcb.h> +#include <sys/resource.h> +#include <sys/resourcevar.h> + +/* + * Per process structure containing data that isn't needed in core + * when the process isn't running (esp. when swapped out). + * This structure may or may not be at the same kernel address + * in all processes. + */ + +struct user { + struct pcb u_pcb; +}; diff --git a/sys/sys/utsname.h b/sys/sys/utsname.h new file mode 100644 index 0000000..22bbd59 --- /dev/null +++ b/sys/sys/utsname.h @@ -0,0 +1,59 @@ +/* $OpenBSD: utsname.h,v 1.6 2013/03/24 17:45:50 deraadt Exp $ */ +/* $NetBSD: utsname.h,v 1.6 1994/06/29 06:46:11 cgd Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, 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. + * + * @(#)utsname.h 8.1 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H + +#define SYS_NMLN 256 + +struct utsname { + char sysname[SYS_NMLN]; /* Name of this OS. */ + char nodename[SYS_NMLN]; /* Name of this network node. */ + char release[SYS_NMLN]; /* Release level. */ + char version[SYS_NMLN]; /* Version level. */ + char machine[SYS_NMLN]; /* Hardware type. */ +}; + +#include <sys/cdefs.h> + +#ifndef _KERNEL +__BEGIN_DECLS +int uname(struct utsname *); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_UTSNAME_H */ diff --git a/sys/sys/uuid.h b/sys/sys/uuid.h new file mode 100644 index 0000000..d7353af --- /dev/null +++ b/sys/sys/uuid.h @@ -0,0 +1,75 @@ +/* $OpenBSD: uuid.h,v 1.3 2014/08/31 09:36:39 miod Exp $ */ +/* $NetBSD: uuid.h,v 1.5 2008/11/18 14:01:03 joerg Exp $ */ + +/* + * Copyright (c) 2002 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: /repoman/r/ncvs/src/sys/sys/uuid.h,v 1.3 2003/05/31 16:47:07 phk Exp $ + */ + +#ifndef _SYS_UUID_H_ +#define _SYS_UUID_H_ + +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* Length of a printed UUID. */ +#define _UUID_BUF_LEN 38 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +}; + +#ifdef _KERNEL + +#define UUID_NODE_LEN _UUID_NODE_LEN +#define UUID_BUF_LEN _UUID_BUF_LEN + +int uuid_snprintf(char *, size_t, const struct uuid *); +int uuid_printf(const struct uuid *); +void uuid_dec_be(const void *, struct uuid *); +void uuid_dec_le(const void *, struct uuid *); +void uuid_enc_be(void *, const struct uuid *); +void uuid_enc_le(void *, const struct uuid *); + +#else /* _KERNEL */ + +typedef struct uuid uuid_t; + +#endif /* _KERNEL */ + +#endif /* _SYS_UUID_H_ */ diff --git a/sys/sys/varargs.h b/sys/sys/varargs.h new file mode 100644 index 0000000..bdd161b --- /dev/null +++ b/sys/sys/varargs.h @@ -0,0 +1,56 @@ +/* $OpenBSD: varargs.h,v 1.3 2019/12/07 06:55:20 visa Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie <espie@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 _VARARGS_H_ +#define _VARARGS_H_ + +#if defined(__GNUC__) && __GNUC__ >= 3 +/* These macros implement traditional (non-ANSI) varargs + for GNU C. */ + +#define va_alist __builtin_va_alist + +#define __va_ellipsis ... + +/* ??? We don't process attributes correctly in K&R argument context. */ +typedef int __builtin_va_alist_t __attribute__((__mode__(__word__))); + +/* ??? It would be nice to get rid of the ellipsis here. It causes + current_function_varargs to be set in cc1. */ +#define va_dcl __builtin_va_alist_t __builtin_va_alist; ... + +/* Define __gnuc_va_list, just as in stdarg.h. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +#define va_start(v) __builtin_varargs_start((v)) +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg +#define __va_copy(d,s) __builtin_va_copy((d),(s)) + +/* Define va_list from __gnuc_va_list. */ + +typedef __gnuc_va_list va_list; + +#else +#error "unsupported compiler" +#endif + +#endif /* _VARARGS_H_ */ diff --git a/sys/sys/videoio.h b/sys/sys/videoio.h new file mode 100644 index 0000000..d9533b3 --- /dev/null +++ b/sys/sys/videoio.h @@ -0,0 +1,3372 @@ +/* $OpenBSD: videoio.h,v 1.16 2017/02/17 06:48:33 feinerer Exp $ */ +/* + * Video for Linux Two header file + * + * Copyright (C) 1999-2012 the contributors + * Copyright (C) 2012 Nokia Corporation + * Contact: Sakari Ailus <sakari.ailus@iki.fi> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Alternatively you can redistribute this file under the terms of the + * BSD license as stated below: + * + * 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 names of its contributors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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. + * + * Header file for v4l or V4L2 drivers and applications + * with public API. + * All kernel-specific stuff were moved to media/v4l2-dev.h, so + * no #if __KERNEL tests are allowed here + * + * See https://linuxtv.org for more info + * + * Author: Bill Dirks <bill@thedirks.org> + * Justin Schoeman + * Hans Verkuil <hverkuil@xs4all.nl> + * et al. + */ + +#ifndef _SYS_VIDEOIO_H_ +#define _SYS_VIDEOIO_H_ +#include <sys/time.h> +#include <sys/types.h> +#include <sys/ioccom.h> +/* Inline #include <linux/v4l2-common.h> + * (v4l2-common.h was split off from videodev2.h and has the same BSD license.) + * + * Begin of v4l2-common.h + */ +/* + * + * Selection interface definitions + * + */ + +/* Current cropping area */ +#define V4L2_SEL_TGT_CROP 0x0000 +/* Default cropping area */ +#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001 +/* Cropping bounds */ +#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002 +/* Native frame size */ +#define V4L2_SEL_TGT_NATIVE_SIZE 0x0003 +/* Current composing area */ +#define V4L2_SEL_TGT_COMPOSE 0x0100 +/* Default composing area */ +#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101 +/* Composing bounds */ +#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102 +/* Current composing area plus all padding pixels */ +#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103 + +/* Backward compatibility target definitions --- to be removed. */ +#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP +#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS + +/* Selection flags */ +#define V4L2_SEL_FLAG_GE (1 << 0) +#define V4L2_SEL_FLAG_LE (1 << 1) +#define V4L2_SEL_FLAG_KEEP_CONFIG (1 << 2) + +/* Backward compatibility flag definitions --- to be removed. */ +#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE V4L2_SEL_FLAG_GE +#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE V4L2_SEL_FLAG_LE +#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG V4L2_SEL_FLAG_KEEP_CONFIG + +struct v4l2_edid { + u_int32_t pad; + u_int32_t start_block; + u_int32_t blocks; + u_int32_t reserved[5]; + u_int8_t *edid; +}; +/* + * End of v4l2-common.h + */ +/* Inline #include <linux/v4l2-controls.h> + * (v4l2-controls.h was split off from videodev2.h and has the same BSD license.) + * + * Begin of v4l2-controls.h + */ +/* Control classes */ +#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ +#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ +#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */ +#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator controls */ +#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */ +#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */ +#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */ +#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */ +#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */ +#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */ +#define V4L2_CTRL_CLASS_RF_TUNER 0x00a20000 /* RF tuner controls */ +#define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */ + +/* User-class control IDs */ + +#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) +#define V4L2_CID_USER_BASE V4L2_CID_BASE +#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1) +#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) +#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) +#define V4L2_CID_SATURATION (V4L2_CID_BASE+2) +#define V4L2_CID_HUE (V4L2_CID_BASE+3) +#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5) +#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6) +#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7) +#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8) +#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9) +#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10) +#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */ +#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12) +#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13) +#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14) +#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15) +#define V4L2_CID_GAMMA (V4L2_CID_BASE+16) +#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */ +#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17) +#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18) +#define V4L2_CID_GAIN (V4L2_CID_BASE+19) +#define V4L2_CID_HFLIP (V4L2_CID_BASE+20) +#define V4L2_CID_VFLIP (V4L2_CID_BASE+21) + +#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24) +enum v4l2_power_line_frequency { + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0, + V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1, + V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2, + V4L2_CID_POWER_LINE_FREQUENCY_AUTO = 3, +}; +#define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25) +#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26) +#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27) +#define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28) +#define V4L2_CID_CHROMA_AGC (V4L2_CID_BASE+29) +#define V4L2_CID_COLOR_KILLER (V4L2_CID_BASE+30) +#define V4L2_CID_COLORFX (V4L2_CID_BASE+31) +enum v4l2_colorfx { + V4L2_COLORFX_NONE = 0, + V4L2_COLORFX_BW = 1, + V4L2_COLORFX_SEPIA = 2, + V4L2_COLORFX_NEGATIVE = 3, + V4L2_COLORFX_EMBOSS = 4, + V4L2_COLORFX_SKETCH = 5, + V4L2_COLORFX_SKY_BLUE = 6, + V4L2_COLORFX_GRASS_GREEN = 7, + V4L2_COLORFX_SKIN_WHITEN = 8, + V4L2_COLORFX_VIVID = 9, + V4L2_COLORFX_AQUA = 10, + V4L2_COLORFX_ART_FREEZE = 11, + V4L2_COLORFX_SILHOUETTE = 12, + V4L2_COLORFX_SOLARIZATION = 13, + V4L2_COLORFX_ANTIQUE = 14, + V4L2_COLORFX_SET_CBCR = 15, +}; +#define V4L2_CID_AUTOBRIGHTNESS (V4L2_CID_BASE+32) +#define V4L2_CID_BAND_STOP_FILTER (V4L2_CID_BASE+33) + +#define V4L2_CID_ROTATE (V4L2_CID_BASE+34) +#define V4L2_CID_BG_COLOR (V4L2_CID_BASE+35) + +#define V4L2_CID_CHROMA_GAIN (V4L2_CID_BASE+36) + +#define V4L2_CID_ILLUMINATORS_1 (V4L2_CID_BASE+37) +#define V4L2_CID_ILLUMINATORS_2 (V4L2_CID_BASE+38) + +#define V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (V4L2_CID_BASE+39) +#define V4L2_CID_MIN_BUFFERS_FOR_OUTPUT (V4L2_CID_BASE+40) + +#define V4L2_CID_ALPHA_COMPONENT (V4L2_CID_BASE+41) +#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42) + +/* last CID + 1 */ +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+43) + +/* USER-class private control IDs */ + +/* The base for the meye driver controls. See linux/meye.h for the list + * of controls. We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_MEYE_BASE (V4L2_CID_USER_BASE + 0x1000) + +/* The base for the bttv driver controls. + * We reserve 32 controls for this driver. */ +#define V4L2_CID_USER_BTTV_BASE (V4L2_CID_USER_BASE + 0x1010) + + +/* The base for the s2255 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_S2255_BASE (V4L2_CID_USER_BASE + 0x1030) + +/* + * The base for the si476x driver controls. See include/media/drv-intf/si476x.h + * for the list of controls. Total of 16 controls is reserved for this driver + */ +#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040) + +/* The base for the TI VPE driver controls. Total of 16 controls is reserved for + * this driver */ +#define V4L2_CID_USER_TI_VPE_BASE (V4L2_CID_USER_BASE + 0x1050) + +/* The base for the saa7134 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_SAA7134_BASE (V4L2_CID_USER_BASE + 0x1060) + +/* The base for the adv7180 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_ADV7180_BASE (V4L2_CID_USER_BASE + 0x1070) + +/* The base for the tc358743 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) + +/* MPEG-class control IDs */ +/* The MPEG controls are applicable to all codec controls + * and the 'MPEG' part of the define is historical */ + +#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900) +#define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1) + +/* MPEG streams, specific to multiplexed streams */ +#define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0) +enum v4l2_mpeg_stream_type { + V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */ +}; +#define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1) +#define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2) +#define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3) +#define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4) +#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5) +#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6) +#define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_MPEG_BASE+7) +enum v4l2_mpeg_stream_vbi_fmt { + V4L2_MPEG_STREAM_VBI_FMT_NONE = 0, /* No VBI in the MPEG stream */ + V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1, /* VBI in private packets, IVTV format */ +}; + +/* MPEG audio controls specific to multiplexed streams */ +#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100) +enum v4l2_mpeg_audio_sampling_freq { + V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101) +enum v4l2_mpeg_audio_encoding { + V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2, + V4L2_MPEG_AUDIO_ENCODING_AAC = 3, + V4L2_MPEG_AUDIO_ENCODING_AC3 = 4, +}; +#define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102) +enum v4l2_mpeg_audio_l1_bitrate { + V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1, + V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2, + V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3, + V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4, + V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5, + V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6, + V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7, + V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8, + V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9, + V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10, + V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11, + V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12, + V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103) +enum v4l2_mpeg_audio_l2_bitrate { + V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1, + V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2, + V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3, + V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4, + V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5, + V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6, + V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7, + V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8, + V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9, + V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10, + V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11, + V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12, + V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104) +enum v4l2_mpeg_audio_l3_bitrate { + V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1, + V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2, + V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3, + V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4, + V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5, + V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6, + V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7, + V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8, + V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9, + V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10, + V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11, + V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12, + V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105) +enum v4l2_mpeg_audio_mode { + V4L2_MPEG_AUDIO_MODE_STEREO = 0, + V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1, + V4L2_MPEG_AUDIO_MODE_DUAL = 2, + V4L2_MPEG_AUDIO_MODE_MONO = 3, +}; +#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106) +enum v4l2_mpeg_audio_mode_extension { + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3, +}; +#define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107) +enum v4l2_mpeg_audio_emphasis { + V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0, + V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1, + V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108) +enum v4l2_mpeg_audio_crc { + V4L2_MPEG_AUDIO_CRC_NONE = 0, + V4L2_MPEG_AUDIO_CRC_CRC16 = 1, +}; +#define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_MPEG_BASE+109) +#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE (V4L2_CID_MPEG_BASE+110) +#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE (V4L2_CID_MPEG_BASE+111) +enum v4l2_mpeg_audio_ac3_bitrate { + V4L2_MPEG_AUDIO_AC3_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_AC3_BITRATE_40K = 1, + V4L2_MPEG_AUDIO_AC3_BITRATE_48K = 2, + V4L2_MPEG_AUDIO_AC3_BITRATE_56K = 3, + V4L2_MPEG_AUDIO_AC3_BITRATE_64K = 4, + V4L2_MPEG_AUDIO_AC3_BITRATE_80K = 5, + V4L2_MPEG_AUDIO_AC3_BITRATE_96K = 6, + V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7, + V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8, + V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9, + V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10, + V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11, + V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12, + V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13, + V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14, + V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15, + V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16, + V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17, + V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18, +}; +#define V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK (V4L2_CID_MPEG_BASE+112) +enum v4l2_mpeg_audio_dec_playback { + V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO = 0, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO = 1, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT = 2, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT = 3, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO = 4, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO = 5, +}; +#define V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK (V4L2_CID_MPEG_BASE+113) + +/* MPEG video controls specific to multiplexed streams */ +#define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200) +enum v4l2_mpeg_video_encoding { + V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0, + V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1, + V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2, +}; +#define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201) +enum v4l2_mpeg_video_aspect { + V4L2_MPEG_VIDEO_ASPECT_1x1 = 0, + V4L2_MPEG_VIDEO_ASPECT_4x3 = 1, + V4L2_MPEG_VIDEO_ASPECT_16x9 = 2, + V4L2_MPEG_VIDEO_ASPECT_221x100 = 3, +}; +#define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202) +#define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203) +#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204) +#define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205) +#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206) +enum v4l2_mpeg_video_bitrate_mode { + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1, +}; +#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207) +#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208) +#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209) +#define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_MPEG_BASE+210) +#define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_MPEG_BASE+211) +#define V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (V4L2_CID_MPEG_BASE+212) +#define V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (V4L2_CID_MPEG_BASE+213) +#define V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (V4L2_CID_MPEG_BASE+214) +#define V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (V4L2_CID_MPEG_BASE+215) +#define V4L2_CID_MPEG_VIDEO_HEADER_MODE (V4L2_CID_MPEG_BASE+216) +enum v4l2_mpeg_video_header_mode { + V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE = 0, + V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME = 1, + +}; +#define V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (V4L2_CID_MPEG_BASE+217) +#define V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (V4L2_CID_MPEG_BASE+218) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (V4L2_CID_MPEG_BASE+219) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (V4L2_CID_MPEG_BASE+220) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE (V4L2_CID_MPEG_BASE+221) +enum v4l2_mpeg_video_multi_slice_mode { + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE = 0, + V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB = 1, + V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES = 2, +}; +#define V4L2_CID_MPEG_VIDEO_VBV_SIZE (V4L2_CID_MPEG_BASE+222) +#define V4L2_CID_MPEG_VIDEO_DEC_PTS (V4L2_CID_MPEG_BASE+223) +#define V4L2_CID_MPEG_VIDEO_DEC_FRAME (V4L2_CID_MPEG_BASE+224) +#define V4L2_CID_MPEG_VIDEO_VBV_DELAY (V4L2_CID_MPEG_BASE+225) +#define V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (V4L2_CID_MPEG_BASE+226) +#define V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE (V4L2_CID_MPEG_BASE+227) +#define V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE (V4L2_CID_MPEG_BASE+228) +#define V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (V4L2_CID_MPEG_BASE+229) + +#define V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (V4L2_CID_MPEG_BASE+300) +#define V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (V4L2_CID_MPEG_BASE+301) +#define V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (V4L2_CID_MPEG_BASE+302) +#define V4L2_CID_MPEG_VIDEO_H263_MIN_QP (V4L2_CID_MPEG_BASE+303) +#define V4L2_CID_MPEG_VIDEO_H263_MAX_QP (V4L2_CID_MPEG_BASE+304) +#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (V4L2_CID_MPEG_BASE+350) +#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (V4L2_CID_MPEG_BASE+351) +#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (V4L2_CID_MPEG_BASE+352) +#define V4L2_CID_MPEG_VIDEO_H264_MIN_QP (V4L2_CID_MPEG_BASE+353) +#define V4L2_CID_MPEG_VIDEO_H264_MAX_QP (V4L2_CID_MPEG_BASE+354) +#define V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (V4L2_CID_MPEG_BASE+355) +#define V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (V4L2_CID_MPEG_BASE+356) +#define V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE (V4L2_CID_MPEG_BASE+357) +enum v4l2_mpeg_video_h264_entropy_mode { + V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC = 0, + V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (V4L2_CID_MPEG_BASE+358) +#define V4L2_CID_MPEG_VIDEO_H264_LEVEL (V4L2_CID_MPEG_BASE+359) +enum v4l2_mpeg_video_h264_level { + V4L2_MPEG_VIDEO_H264_LEVEL_1_0 = 0, + V4L2_MPEG_VIDEO_H264_LEVEL_1B = 1, + V4L2_MPEG_VIDEO_H264_LEVEL_1_1 = 2, + V4L2_MPEG_VIDEO_H264_LEVEL_1_2 = 3, + V4L2_MPEG_VIDEO_H264_LEVEL_1_3 = 4, + V4L2_MPEG_VIDEO_H264_LEVEL_2_0 = 5, + V4L2_MPEG_VIDEO_H264_LEVEL_2_1 = 6, + V4L2_MPEG_VIDEO_H264_LEVEL_2_2 = 7, + V4L2_MPEG_VIDEO_H264_LEVEL_3_0 = 8, + V4L2_MPEG_VIDEO_H264_LEVEL_3_1 = 9, + V4L2_MPEG_VIDEO_H264_LEVEL_3_2 = 10, + V4L2_MPEG_VIDEO_H264_LEVEL_4_0 = 11, + V4L2_MPEG_VIDEO_H264_LEVEL_4_1 = 12, + V4L2_MPEG_VIDEO_H264_LEVEL_4_2 = 13, + V4L2_MPEG_VIDEO_H264_LEVEL_5_0 = 14, + V4L2_MPEG_VIDEO_H264_LEVEL_5_1 = 15, +}; +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (V4L2_CID_MPEG_BASE+360) +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (V4L2_CID_MPEG_BASE+361) +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE (V4L2_CID_MPEG_BASE+362) +enum v4l2_mpeg_video_h264_loop_filter_mode { + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED = 0, + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED = 1, + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2, +}; +#define V4L2_CID_MPEG_VIDEO_H264_PROFILE (V4L2_CID_MPEG_BASE+363) +enum v4l2_mpeg_video_h264_profile { + V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE = 0, + V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE = 1, + V4L2_MPEG_VIDEO_H264_PROFILE_MAIN = 2, + V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED = 3, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH = 4, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 = 5, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 = 6, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE = 7, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA = 8, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA = 9, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA = 10, + V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA = 11, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE = 12, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH = 13, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA = 14, + V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH = 15, + V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH = 16, +}; +#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (V4L2_CID_MPEG_BASE+364) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (V4L2_CID_MPEG_BASE+365) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (V4L2_CID_MPEG_BASE+366) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC (V4L2_CID_MPEG_BASE+367) +enum v4l2_mpeg_video_h264_vui_sar_idc { + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED = 0, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 = 1, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 = 2, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 = 3, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 = 4, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 = 5, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 = 6, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 = 7, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 = 8, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 = 9, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 = 10, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 = 11, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 = 12, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 = 13, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 = 14, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 = 15, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 = 16, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED = 17, +}; +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (V4L2_CID_MPEG_BASE+368) +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (V4L2_CID_MPEG_BASE+369) +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE (V4L2_CID_MPEG_BASE+370) +enum v4l2_mpeg_video_h264_sei_fp_arrangement_type { + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHECKERBOARD = 0, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN = 1, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW = 2, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE = 3, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM = 4, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL = 5, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO (V4L2_CID_MPEG_BASE+371) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE (V4L2_CID_MPEG_BASE+372) +enum v4l2_mpeg_video_h264_fmo_map_type { + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES = 0, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES = 1, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER = 2, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT = 3, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN = 4, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN = 5, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT = 6, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (V4L2_CID_MPEG_BASE+373) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION (V4L2_CID_MPEG_BASE+374) +enum v4l2_mpeg_video_h264_fmo_change_dir { + V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT = 0, + V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (V4L2_CID_MPEG_BASE+375) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (V4L2_CID_MPEG_BASE+376) +#define V4L2_CID_MPEG_VIDEO_H264_ASO (V4L2_CID_MPEG_BASE+377) +#define V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (V4L2_CID_MPEG_BASE+378) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (V4L2_CID_MPEG_BASE+379) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE (V4L2_CID_MPEG_BASE+380) +enum v4l2_mpeg_video_h264_hierarchical_coding_type { + V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B = 0, + V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (V4L2_CID_MPEG_BASE+381) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (V4L2_CID_MPEG_BASE+382) +#define V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (V4L2_CID_MPEG_BASE+400) +#define V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (V4L2_CID_MPEG_BASE+401) +#define V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (V4L2_CID_MPEG_BASE+402) +#define V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (V4L2_CID_MPEG_BASE+403) +#define V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (V4L2_CID_MPEG_BASE+404) +#define V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL (V4L2_CID_MPEG_BASE+405) +enum v4l2_mpeg_video_mpeg4_level { + V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 = 0, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B = 1, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 = 2, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 = 3, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 = 4, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B = 5, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 = 6, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 = 7, +}; +#define V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE (V4L2_CID_MPEG_BASE+406) +enum v4l2_mpeg_video_mpeg4_profile { + V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE = 0, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE = 1, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE = 2, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE = 3, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY = 4, +}; +#define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407) + +/* Control IDs for VP8 streams + * Although VP8 is not part of MPEG we add these controls to the MPEG class + * as that class is already handling other video compression standards + */ +#define V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS (V4L2_CID_MPEG_BASE+500) +enum v4l2_vp8_num_partitions { + V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION = 0, + V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS = 1, + V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS = 2, + V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS = 3, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (V4L2_CID_MPEG_BASE+501) +#define V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES (V4L2_CID_MPEG_BASE+502) +enum v4l2_vp8_num_ref_frames { + V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME = 0, + V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME = 1, + V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME = 2, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (V4L2_CID_MPEG_BASE+503) +#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (V4L2_CID_MPEG_BASE+504) +#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (V4L2_CID_MPEG_BASE+505) +#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL (V4L2_CID_MPEG_BASE+506) +enum v4l2_vp8_golden_frame_sel { + V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV = 0, + V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD = 1, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_MIN_QP (V4L2_CID_MPEG_BASE+507) +#define V4L2_CID_MPEG_VIDEO_VPX_MAX_QP (V4L2_CID_MPEG_BASE+508) +#define V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (V4L2_CID_MPEG_BASE+509) +#define V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (V4L2_CID_MPEG_BASE+510) +#define V4L2_CID_MPEG_VIDEO_VPX_PROFILE (V4L2_CID_MPEG_BASE+511) + +/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ +#define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000) +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0) +enum v4l2_mpeg_cx2341x_video_spatial_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2) +enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3) +enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4) +enum v4l2_mpeg_cx2341x_video_temporal_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5) +#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6) +enum v4l2_mpeg_cx2341x_video_median_filter_type { + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10) +#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11) + +/* MPEG-class control IDs specific to the Samsung MFC 5.1 driver as defined by V4L2 */ +#define V4L2_CID_MPEG_MFC51_BASE (V4L2_CTRL_CLASS_MPEG | 0x1100) + +#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (V4L2_CID_MPEG_MFC51_BASE+0) +#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (V4L2_CID_MPEG_MFC51_BASE+1) +#define V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE (V4L2_CID_MPEG_MFC51_BASE+2) +enum v4l2_mpeg_mfc51_video_frame_skip_mode { + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED = 0, + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1, + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2, +}; +#define V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE (V4L2_CID_MPEG_MFC51_BASE+3) +enum v4l2_mpeg_mfc51_video_force_frame_type { + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED = 0, + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1, + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED = 2, +}; +#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING (V4L2_CID_MPEG_MFC51_BASE+4) +#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_MPEG_MFC51_BASE+5) +#define V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (V4L2_CID_MPEG_MFC51_BASE+6) +#define V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (V4L2_CID_MPEG_MFC51_BASE+7) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (V4L2_CID_MPEG_MFC51_BASE+50) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_MPEG_MFC51_BASE+51) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (V4L2_CID_MPEG_MFC51_BASE+52) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (V4L2_CID_MPEG_MFC51_BASE+53) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (V4L2_CID_MPEG_MFC51_BASE+54) + + +/* Camera class control IDs */ + +#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900) +#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1) + +#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1) +enum v4l2_exposure_auto_type { + V4L2_EXPOSURE_AUTO = 0, + V4L2_EXPOSURE_MANUAL = 1, + V4L2_EXPOSURE_SHUTTER_PRIORITY = 2, + V4L2_EXPOSURE_APERTURE_PRIORITY = 3 +}; +#define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2) +#define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3) + +#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4) +#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5) +#define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6) +#define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7) + +#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8) +#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9) + +#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10) +#define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11) +#define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12) + +#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13) +#define V4L2_CID_ZOOM_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+14) +#define V4L2_CID_ZOOM_CONTINUOUS (V4L2_CID_CAMERA_CLASS_BASE+15) + +#define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16) + +#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17) +#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) + +#define V4L2_CID_AUTO_EXPOSURE_BIAS (V4L2_CID_CAMERA_CLASS_BASE+19) + +#define V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE (V4L2_CID_CAMERA_CLASS_BASE+20) +enum v4l2_auto_n_preset_white_balance { + V4L2_WHITE_BALANCE_MANUAL = 0, + V4L2_WHITE_BALANCE_AUTO = 1, + V4L2_WHITE_BALANCE_INCANDESCENT = 2, + V4L2_WHITE_BALANCE_FLUORESCENT = 3, + V4L2_WHITE_BALANCE_FLUORESCENT_H = 4, + V4L2_WHITE_BALANCE_HORIZON = 5, + V4L2_WHITE_BALANCE_DAYLIGHT = 6, + V4L2_WHITE_BALANCE_FLASH = 7, + V4L2_WHITE_BALANCE_CLOUDY = 8, + V4L2_WHITE_BALANCE_SHADE = 9, +}; + +#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21) +#define V4L2_CID_IMAGE_STABILIZATION (V4L2_CID_CAMERA_CLASS_BASE+22) + +#define V4L2_CID_ISO_SENSITIVITY (V4L2_CID_CAMERA_CLASS_BASE+23) +#define V4L2_CID_ISO_SENSITIVITY_AUTO (V4L2_CID_CAMERA_CLASS_BASE+24) +enum v4l2_iso_sensitivity_auto_type { + V4L2_ISO_SENSITIVITY_MANUAL = 0, + V4L2_ISO_SENSITIVITY_AUTO = 1, +}; + +#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25) +enum v4l2_exposure_metering { + V4L2_EXPOSURE_METERING_AVERAGE = 0, + V4L2_EXPOSURE_METERING_CENTER_WEIGHTED = 1, + V4L2_EXPOSURE_METERING_SPOT = 2, + V4L2_EXPOSURE_METERING_MATRIX = 3, +}; + +#define V4L2_CID_SCENE_MODE (V4L2_CID_CAMERA_CLASS_BASE+26) +enum v4l2_scene_mode { + V4L2_SCENE_MODE_NONE = 0, + V4L2_SCENE_MODE_BACKLIGHT = 1, + V4L2_SCENE_MODE_BEACH_SNOW = 2, + V4L2_SCENE_MODE_CANDLE_LIGHT = 3, + V4L2_SCENE_MODE_DAWN_DUSK = 4, + V4L2_SCENE_MODE_FALL_COLORS = 5, + V4L2_SCENE_MODE_FIREWORKS = 6, + V4L2_SCENE_MODE_LANDSCAPE = 7, + V4L2_SCENE_MODE_NIGHT = 8, + V4L2_SCENE_MODE_PARTY_INDOOR = 9, + V4L2_SCENE_MODE_PORTRAIT = 10, + V4L2_SCENE_MODE_SPORTS = 11, + V4L2_SCENE_MODE_SUNSET = 12, + V4L2_SCENE_MODE_TEXT = 13, +}; + +#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27) +#define V4L2_LOCK_EXPOSURE (1 << 0) +#define V4L2_LOCK_WHITE_BALANCE (1 << 1) +#define V4L2_LOCK_FOCUS (1 << 2) + +#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28) +#define V4L2_CID_AUTO_FOCUS_STOP (V4L2_CID_CAMERA_CLASS_BASE+29) +#define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30) +#define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0) +#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0) +#define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1) +#define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2) + +#define V4L2_CID_AUTO_FOCUS_RANGE (V4L2_CID_CAMERA_CLASS_BASE+31) +enum v4l2_auto_focus_range { + V4L2_AUTO_FOCUS_RANGE_AUTO = 0, + V4L2_AUTO_FOCUS_RANGE_NORMAL = 1, + V4L2_AUTO_FOCUS_RANGE_MACRO = 2, + V4L2_AUTO_FOCUS_RANGE_INFINITY = 3, +}; + +#define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) +#define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) + +/* FM Modulator class control IDs */ + +#define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) +#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1) + +#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1) +#define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 2) +#define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 3) +#define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 5) +#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6) +#define V4L2_CID_RDS_TX_MONO_STEREO (V4L2_CID_FM_TX_CLASS_BASE + 7) +#define V4L2_CID_RDS_TX_ARTIFICIAL_HEAD (V4L2_CID_FM_TX_CLASS_BASE + 8) +#define V4L2_CID_RDS_TX_COMPRESSED (V4L2_CID_FM_TX_CLASS_BASE + 9) +#define V4L2_CID_RDS_TX_DYNAMIC_PTY (V4L2_CID_FM_TX_CLASS_BASE + 10) +#define V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_TX_CLASS_BASE + 11) +#define V4L2_CID_RDS_TX_TRAFFIC_PROGRAM (V4L2_CID_FM_TX_CLASS_BASE + 12) +#define V4L2_CID_RDS_TX_MUSIC_SPEECH (V4L2_CID_FM_TX_CLASS_BASE + 13) +#define V4L2_CID_RDS_TX_ALT_FREQS_ENABLE (V4L2_CID_FM_TX_CLASS_BASE + 14) +#define V4L2_CID_RDS_TX_ALT_FREQS (V4L2_CID_FM_TX_CLASS_BASE + 15) + +#define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 64) +#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 65) +#define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 66) + +#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80) +#define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 81) +#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 82) +#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83) +#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84) + +#define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 96) +#define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 97) +#define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 98) + +#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112) +enum v4l2_preemphasis { + V4L2_PREEMPHASIS_DISABLED = 0, + V4L2_PREEMPHASIS_50_uS = 1, + V4L2_PREEMPHASIS_75_uS = 2, +}; +#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113) +#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114) + + +/* Flash and privacy (indicator) light controls */ + +#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900) +#define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1) + +#define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1) +enum v4l2_flash_led_mode { + V4L2_FLASH_LED_MODE_NONE, + V4L2_FLASH_LED_MODE_FLASH, + V4L2_FLASH_LED_MODE_TORCH, +}; + +#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2) +enum v4l2_flash_strobe_source { + V4L2_FLASH_STROBE_SOURCE_SOFTWARE, + V4L2_FLASH_STROBE_SOURCE_EXTERNAL, +}; + +#define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3) +#define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4) +#define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5) + +#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6) +#define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7) +#define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8) +#define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9) + +#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10) +#define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0) +#define V4L2_FLASH_FAULT_TIMEOUT (1 << 1) +#define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2) +#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3) +#define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4) +#define V4L2_FLASH_FAULT_INDICATOR (1 << 5) +#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6) +#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7) +#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE (1 << 8) + +#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11) +#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12) + + +/* JPEG-class control IDs */ + +#define V4L2_CID_JPEG_CLASS_BASE (V4L2_CTRL_CLASS_JPEG | 0x900) +#define V4L2_CID_JPEG_CLASS (V4L2_CTRL_CLASS_JPEG | 1) + +#define V4L2_CID_JPEG_CHROMA_SUBSAMPLING (V4L2_CID_JPEG_CLASS_BASE + 1) +enum v4l2_jpeg_chroma_subsampling { + V4L2_JPEG_CHROMA_SUBSAMPLING_444 = 0, + V4L2_JPEG_CHROMA_SUBSAMPLING_422 = 1, + V4L2_JPEG_CHROMA_SUBSAMPLING_420 = 2, + V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3, + V4L2_JPEG_CHROMA_SUBSAMPLING_410 = 4, + V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY = 5, +}; +#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2) +#define V4L2_CID_JPEG_COMPRESSION_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 3) + +#define V4L2_CID_JPEG_ACTIVE_MARKER (V4L2_CID_JPEG_CLASS_BASE + 4) +#define V4L2_JPEG_ACTIVE_MARKER_APP0 (1 << 0) +#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1) +#define V4L2_JPEG_ACTIVE_MARKER_COM (1 << 16) +#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17) +#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18) + + +/* Image source controls */ +#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900) +#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1) + +#define V4L2_CID_VBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1) +#define V4L2_CID_HBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2) +#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3) +#define V4L2_CID_TEST_PATTERN_RED (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 4) +#define V4L2_CID_TEST_PATTERN_GREENR (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 5) +#define V4L2_CID_TEST_PATTERN_BLUE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 6) +#define V4L2_CID_TEST_PATTERN_GREENB (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 7) + + +/* Image processing controls */ + +#define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900) +#define V4L2_CID_IMAGE_PROC_CLASS (V4L2_CTRL_CLASS_IMAGE_PROC | 1) + +#define V4L2_CID_LINK_FREQ (V4L2_CID_IMAGE_PROC_CLASS_BASE + 1) +#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2) +#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3) +#define V4L2_CID_DEINTERLACING_MODE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 4) + + +/* DV-class control IDs defined by V4L2 */ +#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900) +#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1) + +#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1) +#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2) +#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3) +#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4) +enum v4l2_dv_tx_mode { + V4L2_DV_TX_MODE_DVI_D = 0, + V4L2_DV_TX_MODE_HDMI = 1, +}; +#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5) +enum v4l2_dv_rgb_range { + V4L2_DV_RGB_RANGE_AUTO = 0, + V4L2_DV_RGB_RANGE_LIMITED = 1, + V4L2_DV_RGB_RANGE_FULL = 2, +}; + +#define V4L2_CID_DV_TX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 6) +enum v4l2_dv_it_content_type { + V4L2_DV_IT_CONTENT_TYPE_GRAPHICS = 0, + V4L2_DV_IT_CONTENT_TYPE_PHOTO = 1, + V4L2_DV_IT_CONTENT_TYPE_CINEMA = 2, + V4L2_DV_IT_CONTENT_TYPE_GAME = 3, + V4L2_DV_IT_CONTENT_TYPE_NO_ITC = 4, +}; + +#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100) +#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101) +#define V4L2_CID_DV_RX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 102) + +#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900) +#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1) + +#define V4L2_CID_TUNE_DEEMPHASIS (V4L2_CID_FM_RX_CLASS_BASE + 1) +enum v4l2_deemphasis { + V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED, + V4L2_DEEMPHASIS_50_uS = V4L2_PREEMPHASIS_50_uS, + V4L2_DEEMPHASIS_75_uS = V4L2_PREEMPHASIS_75_uS, +}; + +#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2) +#define V4L2_CID_RDS_RX_PTY (V4L2_CID_FM_RX_CLASS_BASE + 3) +#define V4L2_CID_RDS_RX_PS_NAME (V4L2_CID_FM_RX_CLASS_BASE + 4) +#define V4L2_CID_RDS_RX_RADIO_TEXT (V4L2_CID_FM_RX_CLASS_BASE + 5) +#define V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_RX_CLASS_BASE + 6) +#define V4L2_CID_RDS_RX_TRAFFIC_PROGRAM (V4L2_CID_FM_RX_CLASS_BASE + 7) +#define V4L2_CID_RDS_RX_MUSIC_SPEECH (V4L2_CID_FM_RX_CLASS_BASE + 8) + +#define V4L2_CID_RF_TUNER_CLASS_BASE (V4L2_CTRL_CLASS_RF_TUNER | 0x900) +#define V4L2_CID_RF_TUNER_CLASS (V4L2_CTRL_CLASS_RF_TUNER | 1) + +#define V4L2_CID_RF_TUNER_BANDWIDTH_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 11) +#define V4L2_CID_RF_TUNER_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 12) +#define V4L2_CID_RF_TUNER_RF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 32) +#define V4L2_CID_RF_TUNER_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 41) +#define V4L2_CID_RF_TUNER_LNA_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 42) +#define V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 51) +#define V4L2_CID_RF_TUNER_MIXER_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 52) +#define V4L2_CID_RF_TUNER_IF_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 61) +#define V4L2_CID_RF_TUNER_IF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 62) +#define V4L2_CID_RF_TUNER_PLL_LOCK (V4L2_CID_RF_TUNER_CLASS_BASE + 91) + + +/* Detection-class control IDs defined by V4L2 */ +#define V4L2_CID_DETECT_CLASS_BASE (V4L2_CTRL_CLASS_DETECT | 0x900) +#define V4L2_CID_DETECT_CLASS (V4L2_CTRL_CLASS_DETECT | 1) + +#define V4L2_CID_DETECT_MD_MODE (V4L2_CID_DETECT_CLASS_BASE + 1) +enum v4l2_detect_md_mode { + V4L2_DETECT_MD_MODE_DISABLED = 0, + V4L2_DETECT_MD_MODE_GLOBAL = 1, + V4L2_DETECT_MD_MODE_THRESHOLD_GRID = 2, + V4L2_DETECT_MD_MODE_REGION_GRID = 3, +}; +#define V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD (V4L2_CID_DETECT_CLASS_BASE + 2) +#define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) +#define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) +/* + * End of v4l2-controls.h + */ + +#ifndef __user +#define __user +#endif + +/* + * Common stuff for both V4L1 and V4L2 + * Moved from videodev.h + */ +#define VIDEO_MAX_FRAME 32 +#define VIDEO_MAX_PLANES 8 + +/* + * M I S C E L L A N E O U S + */ + +/* Four-character-code (FOURCC) */ +#define v4l2_fourcc(a, b, c, d)\ + ((u_int32_t)(a) | ((u_int32_t)(b) << 8) | ((u_int32_t)(c) << 16) | ((u_int32_t)(d) << 24)) +#define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1 << 31)) + +/* + * E N U M S + */ +enum v4l2_field { + V4L2_FIELD_ANY = 0, /* driver can choose from none, + top, bottom, interlaced + depending on whatever it thinks + is approximate ... */ + V4L2_FIELD_NONE = 1, /* this device has no fields ... */ + V4L2_FIELD_TOP = 2, /* top field only */ + V4L2_FIELD_BOTTOM = 3, /* bottom field only */ + V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */ + V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one + buffer, top-bottom order */ + V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */ + V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into + separate buffers */ + V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field + first and the top field is + transmitted first */ + V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field + first and the bottom field is + transmitted first */ +}; +#define V4L2_FIELD_HAS_TOP(field) \ + ((field) == V4L2_FIELD_TOP ||\ + (field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_BOTTOM(field) \ + ((field) == V4L2_FIELD_BOTTOM ||\ + (field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_BOTH(field) \ + ((field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_T_OR_B(field) \ + ((field) == V4L2_FIELD_BOTTOM ||\ + (field) == V4L2_FIELD_TOP ||\ + (field) == V4L2_FIELD_ALTERNATE) + +enum v4l2_buf_type { + V4L2_BUF_TYPE_VIDEO_CAPTURE = 1, + V4L2_BUF_TYPE_VIDEO_OUTPUT = 2, + V4L2_BUF_TYPE_VIDEO_OVERLAY = 3, + V4L2_BUF_TYPE_VBI_CAPTURE = 4, + V4L2_BUF_TYPE_VBI_OUTPUT = 5, + V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6, + V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7, + V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10, + V4L2_BUF_TYPE_SDR_CAPTURE = 11, + V4L2_BUF_TYPE_SDR_OUTPUT = 12, + /* Deprecated, do not use */ + V4L2_BUF_TYPE_PRIVATE = 0x80, +}; + +#define V4L2_TYPE_IS_MULTIPLANAR(type) \ + ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) + +#define V4L2_TYPE_IS_OUTPUT(type) \ + ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE \ + || (type) == V4L2_BUF_TYPE_VIDEO_OVERLAY \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY \ + || (type) == V4L2_BUF_TYPE_VBI_OUTPUT \ + || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT \ + || (type) == V4L2_BUF_TYPE_SDR_OUTPUT) + +enum v4l2_tuner_type { + V4L2_TUNER_RADIO = 1, + V4L2_TUNER_ANALOG_TV = 2, + V4L2_TUNER_DIGITAL_TV = 3, + V4L2_TUNER_SDR = 4, + V4L2_TUNER_RF = 5, +}; + +/* Deprecated, do not use */ +#define V4L2_TUNER_ADC V4L2_TUNER_SDR + +enum v4l2_memory { + V4L2_MEMORY_MMAP = 1, + V4L2_MEMORY_USERPTR = 2, + V4L2_MEMORY_OVERLAY = 3, + V4L2_MEMORY_DMABUF = 4, +}; + +/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ +enum v4l2_colorspace { + /* + * Default colorspace, i.e. let the driver figure it out. + * Can only be used with video capture. + */ + V4L2_COLORSPACE_DEFAULT = 0, + + /* SMPTE 170M: used for broadcast NTSC/PAL SDTV */ + V4L2_COLORSPACE_SMPTE170M = 1, + + /* Obsolete pre-1998 SMPTE 240M HDTV standard, superseded by Rec 709 */ + V4L2_COLORSPACE_SMPTE240M = 2, + + /* Rec.709: used for HDTV */ + V4L2_COLORSPACE_REC709 = 3, + + /* + * Deprecated, do not use. No driver will ever return this. This was + * based on a misunderstanding of the bt878 datasheet. + */ + V4L2_COLORSPACE_BT878 = 4, + + /* + * NTSC 1953 colorspace. This only makes sense when dealing with + * really, really old NTSC recordings. Superseded by SMPTE 170M. + */ + V4L2_COLORSPACE_470_SYSTEM_M = 5, + + /* + * EBU Tech 3213 PAL/SECAM colorspace. This only makes sense when + * dealing with really old PAL/SECAM recordings. Superseded by + * SMPTE 170M. + */ + V4L2_COLORSPACE_470_SYSTEM_BG = 6, + + /* + * Effectively shorthand for V4L2_COLORSPACE_SRGB, V4L2_YCBCR_ENC_601 + * and V4L2_QUANTIZATION_FULL_RANGE. To be used for (Motion-)JPEG. + */ + V4L2_COLORSPACE_JPEG = 7, + + /* For RGB colorspaces such as produces by most webcams. */ + V4L2_COLORSPACE_SRGB = 8, + + /* AdobeRGB colorspace */ + V4L2_COLORSPACE_ADOBERGB = 9, + + /* BT.2020 colorspace, used for UHDTV. */ + V4L2_COLORSPACE_BT2020 = 10, + + /* Raw colorspace: for RAW unprocessed images */ + V4L2_COLORSPACE_RAW = 11, + + /* DCI-P3 colorspace, used by cinema projectors */ + V4L2_COLORSPACE_DCI_P3 = 12, +}; + +/* + * Determine how COLORSPACE_DEFAULT should map to a proper colorspace. + * This depends on whether this is a SDTV image (use SMPTE 170M), an + * HDTV image (use Rec. 709), or something else (use sRGB). + */ +#define V4L2_MAP_COLORSPACE_DEFAULT(is_sdtv, is_hdtv) \ + ((is_sdtv) ? V4L2_COLORSPACE_SMPTE170M : \ + ((is_hdtv) ? V4L2_COLORSPACE_REC709 : V4L2_COLORSPACE_SRGB)) + +enum v4l2_xfer_func { + /* + * Mapping of V4L2_XFER_FUNC_DEFAULT to actual transfer functions + * for the various colorspaces: + * + * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M, + * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_REC709 and + * V4L2_COLORSPACE_BT2020: V4L2_XFER_FUNC_709 + * + * V4L2_COLORSPACE_SRGB, V4L2_COLORSPACE_JPEG: V4L2_XFER_FUNC_SRGB + * + * V4L2_COLORSPACE_ADOBERGB: V4L2_XFER_FUNC_ADOBERGB + * + * V4L2_COLORSPACE_SMPTE240M: V4L2_XFER_FUNC_SMPTE240M + * + * V4L2_COLORSPACE_RAW: V4L2_XFER_FUNC_NONE + * + * V4L2_COLORSPACE_DCI_P3: V4L2_XFER_FUNC_DCI_P3 + */ + V4L2_XFER_FUNC_DEFAULT = 0, + V4L2_XFER_FUNC_709 = 1, + V4L2_XFER_FUNC_SRGB = 2, + V4L2_XFER_FUNC_ADOBERGB = 3, + V4L2_XFER_FUNC_SMPTE240M = 4, + V4L2_XFER_FUNC_NONE = 5, + V4L2_XFER_FUNC_DCI_P3 = 6, + V4L2_XFER_FUNC_SMPTE2084 = 7, +}; + +/* + * Determine how XFER_FUNC_DEFAULT should map to a proper transfer function. + * This depends on the colorspace. + */ +#define V4L2_MAP_XFER_FUNC_DEFAULT(colsp) \ + ((colsp) == V4L2_COLORSPACE_ADOBERGB ? V4L2_XFER_FUNC_ADOBERGB : \ + ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_XFER_FUNC_SMPTE240M : \ + ((colsp) == V4L2_COLORSPACE_DCI_P3 ? V4L2_XFER_FUNC_DCI_P3 : \ + ((colsp) == V4L2_COLORSPACE_RAW ? V4L2_XFER_FUNC_NONE : \ + ((colsp) == V4L2_COLORSPACE_SRGB || (colsp) == V4L2_COLORSPACE_JPEG ? \ + V4L2_XFER_FUNC_SRGB : V4L2_XFER_FUNC_709))))) + +enum v4l2_ycbcr_encoding { + /* + * Mapping of V4L2_YCBCR_ENC_DEFAULT to actual encodings for the + * various colorspaces: + * + * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M, + * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_SRGB, + * V4L2_COLORSPACE_ADOBERGB and V4L2_COLORSPACE_JPEG: V4L2_YCBCR_ENC_601 + * + * V4L2_COLORSPACE_REC709 and V4L2_COLORSPACE_DCI_P3: V4L2_YCBCR_ENC_709 + * + * V4L2_COLORSPACE_BT2020: V4L2_YCBCR_ENC_BT2020 + * + * V4L2_COLORSPACE_SMPTE240M: V4L2_YCBCR_ENC_SMPTE240M + */ + V4L2_YCBCR_ENC_DEFAULT = 0, + + /* ITU-R 601 -- SDTV */ + V4L2_YCBCR_ENC_601 = 1, + + /* Rec. 709 -- HDTV */ + V4L2_YCBCR_ENC_709 = 2, + + /* ITU-R 601/EN 61966-2-4 Extended Gamut -- SDTV */ + V4L2_YCBCR_ENC_XV601 = 3, + + /* Rec. 709/EN 61966-2-4 Extended Gamut -- HDTV */ + V4L2_YCBCR_ENC_XV709 = 4, + +#ifndef __KERNEL__ + /* + * sYCC (Y'CbCr encoding of sRGB), identical to ENC_601. It was added + * originally due to a misunderstanding of the sYCC standard. It should + * not be used, instead use V4L2_YCBCR_ENC_601. + */ + V4L2_YCBCR_ENC_SYCC = 5, +#endif + + /* BT.2020 Non-constant Luminance Y'CbCr */ + V4L2_YCBCR_ENC_BT2020 = 6, + + /* BT.2020 Constant Luminance Y'CbcCrc */ + V4L2_YCBCR_ENC_BT2020_CONST_LUM = 7, + + /* SMPTE 240M -- Obsolete HDTV */ + V4L2_YCBCR_ENC_SMPTE240M = 8, +}; + +/* + * enum v4l2_hsv_encoding values should not collide with the ones from + * enum v4l2_ycbcr_encoding. + */ +enum v4l2_hsv_encoding { + + /* Hue mapped to 0 - 179 */ + V4L2_HSV_ENC_180 = 128, + + /* Hue mapped to 0-255 */ + V4L2_HSV_ENC_256 = 129, +}; + +/* + * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding. + * This depends on the colorspace. + */ +#define V4L2_MAP_YCBCR_ENC_DEFAULT(colsp) \ + (((colsp) == V4L2_COLORSPACE_REC709 || \ + (colsp) == V4L2_COLORSPACE_DCI_P3) ? V4L2_YCBCR_ENC_709 : \ + ((colsp) == V4L2_COLORSPACE_BT2020 ? V4L2_YCBCR_ENC_BT2020 : \ + ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_YCBCR_ENC_SMPTE240M : \ + V4L2_YCBCR_ENC_601))) + +enum v4l2_quantization { + /* + * The default for R'G'B' quantization is always full range, except + * for the BT2020 colorspace. For Y'CbCr the quantization is always + * limited range, except for COLORSPACE_JPEG, SRGB, ADOBERGB, + * XV601 or XV709: those are full range. + */ + V4L2_QUANTIZATION_DEFAULT = 0, + V4L2_QUANTIZATION_FULL_RANGE = 1, + V4L2_QUANTIZATION_LIM_RANGE = 2, +}; + +/* + * Determine how QUANTIZATION_DEFAULT should map to a proper quantization. + * This depends on whether the image is RGB or not, the colorspace and the + * Y'CbCr encoding. + */ +#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb_or_hsv, colsp, ycbcr_enc) \ + (((is_rgb_or_hsv) && (colsp) == V4L2_COLORSPACE_BT2020) ? \ + V4L2_QUANTIZATION_LIM_RANGE : \ + (((is_rgb_or_hsv) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \ + (ycbcr_enc) == V4L2_YCBCR_ENC_XV709 || (colsp) == V4L2_COLORSPACE_JPEG) || \ + (colsp) == V4L2_COLORSPACE_ADOBERGB || (colsp) == V4L2_COLORSPACE_SRGB ? \ + V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE)) + +enum v4l2_priority { + V4L2_PRIORITY_UNSET = 0, /* not initialized */ + V4L2_PRIORITY_BACKGROUND = 1, + V4L2_PRIORITY_INTERACTIVE = 2, + V4L2_PRIORITY_RECORD = 3, + V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE, +}; + +struct v4l2_rect { + int32_t left; + int32_t top; + u_int32_t width; + u_int32_t height; +}; + +struct v4l2_fract { + u_int32_t numerator; + u_int32_t denominator; +}; + +/** + * struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP + * + * @driver: name of the driver module (e.g. "bttv") + * @card: name of the card (e.g. "Hauppauge WinTV") + * @bus_info: name of the bus (e.g. "PCI:" + pci_name(pci_dev) ) + * @version: KERNEL_VERSION + * @capabilities: capabilities of the physical device as a whole + * @device_caps: capabilities accessed via this particular device (node) + * @reserved: reserved fields for future extensions + */ +struct v4l2_capability { + u_int8_t driver[16]; + u_int8_t card[32]; + u_int8_t bus_info[32]; + u_int32_t version; + u_int32_t capabilities; + u_int32_t device_caps; + u_int32_t reserved[3]; +}; + +/* Values for 'capabilities' field */ +#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */ +#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */ +#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */ +#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */ +#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */ +#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */ +#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */ +#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */ +#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */ +#define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */ +#define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */ + +/* Is a video capture device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000 +/* Is a video output device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000 +/* Is a video mem-to-mem device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000 +/* Is a video mem-to-mem device */ +#define V4L2_CAP_VIDEO_M2M 0x00008000 + +#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */ +#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */ +#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */ +#define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */ + +#define V4L2_CAP_SDR_CAPTURE 0x00100000 /* Is a SDR capture device */ +#define V4L2_CAP_EXT_PIX_FORMAT 0x00200000 /* Supports the extended pixel format */ +#define V4L2_CAP_SDR_OUTPUT 0x00400000 /* Is a SDR output device */ + +#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */ +#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */ +#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */ + +#define V4L2_CAP_TOUCH 0x10000000 /* Is a touch device */ + +#define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */ + +/* + * V I D E O I M A G E F O R M A T + */ +struct v4l2_pix_format { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; /* enum v4l2_field */ + u_int32_t bytesperline; /* for padding, zero if unused */ + u_int32_t sizeimage; + u_int32_t colorspace; /* enum v4l2_colorspace */ + u_int32_t priv; /* private data, depends on pixelformat */ + u_int32_t flags; /* format flags (V4L2_PIX_FMT_FLAG_*) */ + union { + /* enum v4l2_ycbcr_encoding */ + u_int32_t ycbcr_enc; + /* enum v4l2_hsv_encoding */ + u_int32_t hsv_enc; + }; + u_int32_t quantization; /* enum v4l2_quantization */ + u_int32_t xfer_func; /* enum v4l2_xfer_func */ +}; + +/* Pixel format FOURCC depth Description */ + +/* RGB formats */ +#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */ +#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */ +#define V4L2_PIX_FMT_ARGB444 v4l2_fourcc('A', 'R', '1', '2') /* 16 aaaarrrr ggggbbbb */ +#define V4L2_PIX_FMT_XRGB444 v4l2_fourcc('X', 'R', '1', '2') /* 16 xxxxrrrr ggggbbbb */ +#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */ +#define V4L2_PIX_FMT_ARGB555 v4l2_fourcc('A', 'R', '1', '5') /* 16 ARGB-1-5-5-5 */ +#define V4L2_PIX_FMT_XRGB555 v4l2_fourcc('X', 'R', '1', '5') /* 16 XRGB-1-5-5-5 */ +#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */ +#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */ +#define V4L2_PIX_FMT_ARGB555X v4l2_fourcc_be('A', 'R', '1', '5') /* 16 ARGB-5-5-5 BE */ +#define V4L2_PIX_FMT_XRGB555X v4l2_fourcc_be('X', 'R', '1', '5') /* 16 XRGB-5-5-5 BE */ +#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */ +#define V4L2_PIX_FMT_BGR666 v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */ +#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */ +#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */ +#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */ +#define V4L2_PIX_FMT_ABGR32 v4l2_fourcc('A', 'R', '2', '4') /* 32 BGRA-8-8-8-8 */ +#define V4L2_PIX_FMT_XBGR32 v4l2_fourcc('X', 'R', '2', '4') /* 32 BGRX-8-8-8-8 */ +#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */ +#define V4L2_PIX_FMT_ARGB32 v4l2_fourcc('B', 'A', '2', '4') /* 32 ARGB-8-8-8-8 */ +#define V4L2_PIX_FMT_XRGB32 v4l2_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */ + +/* Grey formats */ +#define V4L2_PIX_FMT_GREY v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */ +#define V4L2_PIX_FMT_Y4 v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */ +#define V4L2_PIX_FMT_Y6 v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */ +#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */ +#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */ +#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */ +#define V4L2_PIX_FMT_Y16_BE v4l2_fourcc_be('Y', '1', '6', ' ') /* 16 Greyscale BE */ + +/* Grey bit-packed formats */ +#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */ + +/* Palette formats */ +#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */ + +/* Chrominance formats */ +#define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */ + +/* Luminance+Chrominance formats */ +#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */ +#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */ +#define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */ +#define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */ +#define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */ +#define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */ +#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */ +#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */ +#define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */ + +/* two planes -- one Y, one Cr + Cb interleaved */ +#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */ +#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */ +#define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */ +#define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */ +#define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */ +#define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */ + +/* two non contiguous planes - one Y, one Cr + Cb interleaved */ +#define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */ +#define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */ +#define V4L2_PIX_FMT_NV16M v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */ +#define V4L2_PIX_FMT_NV61M v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */ +#define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */ +#define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */ + +/* three planes - Y Cb, Cr */ +#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */ +#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */ +#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 12 YVU411 planar */ +#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */ +#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */ +#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */ + +/* three non contiguous planes - Y, Cb, Cr */ +#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */ +#define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */ +#define V4L2_PIX_FMT_YUV422M v4l2_fourcc('Y', 'M', '1', '6') /* 16 YUV422 planar */ +#define V4L2_PIX_FMT_YVU422M v4l2_fourcc('Y', 'M', '6', '1') /* 16 YVU422 planar */ +#define V4L2_PIX_FMT_YUV444M v4l2_fourcc('Y', 'M', '2', '4') /* 24 YUV444 planar */ +#define V4L2_PIX_FMT_YVU444M v4l2_fourcc('Y', 'M', '4', '2') /* 24 YVU444 planar */ + +/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */ +#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */ +#define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */ + /* 10bit raw bayer packed, 5 bytes for every 4 pixels */ +#define V4L2_PIX_FMT_SBGGR10P v4l2_fourcc('p', 'B', 'A', 'A') +#define V4L2_PIX_FMT_SGBRG10P v4l2_fourcc('p', 'G', 'A', 'A') +#define V4L2_PIX_FMT_SGRBG10P v4l2_fourcc('p', 'g', 'A', 'A') +#define V4L2_PIX_FMT_SRGGB10P v4l2_fourcc('p', 'R', 'A', 'A') + /* 10bit raw bayer a-law compressed to 8 bits */ +#define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8') +#define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8') +#define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8') +#define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8') + /* 10bit raw bayer DPCM compressed to 8 bits */ +#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8') +#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8') +#define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0') +#define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8') +#define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */ +#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG16 v4l2_fourcc('G', 'B', '1', '6') /* 16 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG16 v4l2_fourcc('G', 'R', '1', '6') /* 16 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB16 v4l2_fourcc('R', 'G', '1', '6') /* 16 RGRG.. GBGB.. */ + +/* HSV formats */ +#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3') +#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4') + +/* compressed formats */ +#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */ +#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */ +#define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */ +#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */ +#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */ +#define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */ +#define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */ +#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */ +#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */ +#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */ +#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */ +#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */ +#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */ +#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ +#define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ +#define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */ + +/* Vendor-specific formats */ +#define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ +#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */ +#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */ +#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */ +#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */ +#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */ +#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */ +#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */ +#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */ +#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */ +#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */ +#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */ +#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */ +#define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */ +#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */ +#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */ +#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */ +#define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */ +#define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */ +#define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */ +#define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */ +#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */ +#define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */ +#define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */ +#define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */ +#define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */ +#define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */ +#define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */ +#define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ +#define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */ + +/* SDR formats - used only for Software Defined Radio devices */ +#define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */ +#define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */ +#define V4L2_SDR_FMT_CS8 v4l2_fourcc('C', 'S', '0', '8') /* complex s8 */ +#define V4L2_SDR_FMT_CS14LE v4l2_fourcc('C', 'S', '1', '4') /* complex s14le */ +#define V4L2_SDR_FMT_RU12LE v4l2_fourcc('R', 'U', '1', '2') /* real u12le */ + +/* Touch formats - used for Touch devices */ +#define V4L2_TCH_FMT_DELTA_TD16 v4l2_fourcc('T', 'D', '1', '6') /* 16-bit signed deltas */ +#define V4L2_TCH_FMT_DELTA_TD08 v4l2_fourcc('T', 'D', '0', '8') /* 8-bit signed deltas */ +#define V4L2_TCH_FMT_TU16 v4l2_fourcc('T', 'U', '1', '6') /* 16-bit unsigned touch data */ +#define V4L2_TCH_FMT_TU08 v4l2_fourcc('T', 'U', '0', '8') /* 8-bit unsigned touch data */ + +/* priv field value to indicates that subsequent fields are valid. */ +#define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe + +/* Flags */ +#define V4L2_PIX_FMT_FLAG_PREMUL_ALPHA 0x00000001 + +/* + * F O R M A T E N U M E R A T I O N + */ +struct v4l2_fmtdesc { + u_int32_t index; /* Format number */ + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t flags; + u_int8_t description[32]; /* Description string */ + u_int32_t pixelformat; /* Format fourcc */ + u_int32_t reserved[4]; +}; + +#define V4L2_FMT_FLAG_COMPRESSED 0x0001 +#define V4L2_FMT_FLAG_EMULATED 0x0002 + + /* Frame Size and frame rate enumeration */ +/* + * F R A M E S I Z E E N U M E R A T I O N + */ +enum v4l2_frmsizetypes { + V4L2_FRMSIZE_TYPE_DISCRETE = 1, + V4L2_FRMSIZE_TYPE_CONTINUOUS = 2, + V4L2_FRMSIZE_TYPE_STEPWISE = 3, +}; + +struct v4l2_frmsize_discrete { + u_int32_t width; /* Frame width [pixel] */ + u_int32_t height; /* Frame height [pixel] */ +}; + +struct v4l2_frmsize_stepwise { + u_int32_t min_width; /* Minimum frame width [pixel] */ + u_int32_t max_width; /* Maximum frame width [pixel] */ + u_int32_t step_width; /* Frame width step size [pixel] */ + u_int32_t min_height; /* Minimum frame height [pixel] */ + u_int32_t max_height; /* Maximum frame height [pixel] */ + u_int32_t step_height; /* Frame height step size [pixel] */ +}; + +struct v4l2_frmsizeenum { + u_int32_t index; /* Frame size number */ + u_int32_t pixel_format; /* Pixel format */ + u_int32_t type; /* Frame size type the device supports. */ + + union { /* Frame size */ + struct v4l2_frmsize_discrete discrete; + struct v4l2_frmsize_stepwise stepwise; + }; + + u_int32_t reserved[2]; /* Reserved space for future use */ +}; + +/* + * F R A M E R A T E E N U M E R A T I O N + */ +enum v4l2_frmivaltypes { + V4L2_FRMIVAL_TYPE_DISCRETE = 1, + V4L2_FRMIVAL_TYPE_CONTINUOUS = 2, + V4L2_FRMIVAL_TYPE_STEPWISE = 3, +}; + +struct v4l2_frmival_stepwise { + struct v4l2_fract min; /* Minimum frame interval [s] */ + struct v4l2_fract max; /* Maximum frame interval [s] */ + struct v4l2_fract step; /* Frame interval step size [s] */ +}; + +struct v4l2_frmivalenum { + u_int32_t index; /* Frame format index */ + u_int32_t pixel_format; /* Pixel format */ + u_int32_t width; /* Frame width */ + u_int32_t height; /* Frame height */ + u_int32_t type; /* Frame interval type the device supports. */ + + union { /* Frame interval */ + struct v4l2_fract discrete; + struct v4l2_frmival_stepwise stepwise; + }; + + u_int32_t reserved[2]; /* Reserved space for future use */ +}; + +/* + * T I M E C O D E + */ +struct v4l2_timecode { + u_int32_t type; + u_int32_t flags; + u_int8_t frames; + u_int8_t seconds; + u_int8_t minutes; + u_int8_t hours; + u_int8_t userbits[4]; +}; + +/* Type */ +#define V4L2_TC_TYPE_24FPS 1 +#define V4L2_TC_TYPE_25FPS 2 +#define V4L2_TC_TYPE_30FPS 3 +#define V4L2_TC_TYPE_50FPS 4 +#define V4L2_TC_TYPE_60FPS 5 + +/* Flags */ +#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */ +#define V4L2_TC_FLAG_COLORFRAME 0x0002 +#define V4L2_TC_USERBITS_field 0x000C +#define V4L2_TC_USERBITS_USERDEFINED 0x0000 +#define V4L2_TC_USERBITS_8BITCHARS 0x0008 +/* The above is based on SMPTE timecodes */ + +struct v4l2_jpegcompression { + int quality; + + int APPn; /* Number of APP segment to be written, + * must be 0..15 */ + int APP_len; /* Length of data in JPEG APPn segment */ + char APP_data[60]; /* Data in the JPEG APPn segment. */ + + int COM_len; /* Length of data in JPEG COM segment */ + char COM_data[60]; /* Data in JPEG COM segment */ + + u_int32_t jpeg_markers; /* Which markers should go into the JPEG + * output. Unless you exactly know what + * you do, leave them untouched. + * Including less markers will make the + * resulting code smaller, but there will + * be fewer applications which can read it. + * The presence of the APP and COM marker + * is influenced by APP_len and COM_len + * ONLY, not by this property! */ + +#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */ +#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */ +#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ +#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */ +#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will + * always use APP0 */ +}; + +/* + * M E M O R Y - M A P P I N G B U F F E R S + */ +struct v4l2_requestbuffers { + u_int32_t count; + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t memory; /* enum v4l2_memory */ + u_int32_t reserved[2]; +}; + +/** + * struct v4l2_plane - plane info for multi-planar buffers + * @bytesused: number of bytes occupied by data in the plane (payload) + * @length: size of this plane (NOT the payload) in bytes + * @mem_offset: when memory in the associated struct v4l2_buffer is + * V4L2_MEMORY_MMAP, equals the offset from the start of + * the device memory for this plane (or is a "cookie" that + * should be passed to mmap() called on the video node) + * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer + * pointing to this plane + * @fd: when memory is V4L2_MEMORY_DMABUF, a userspace file + * descriptor associated with this plane + * @data_offset: offset in the plane to the start of data; usually 0, + * unless there is a header in front of the data + * + * Multi-planar buffers consist of one or more planes, e.g. an YCbCr buffer + * with two planes can have one plane for Y, and another for interleaved CbCr + * components. Each plane can reside in a separate memory buffer, or even in + * a completely separate memory node (e.g. in embedded devices). + */ +struct v4l2_plane { + u_int32_t bytesused; + u_int32_t length; + union { + u_int32_t mem_offset; + unsigned long userptr; + int32_t fd; + } m; + u_int32_t data_offset; + u_int32_t reserved[11]; +}; + +/** + * struct v4l2_buffer - video buffer info + * @index: id number of the buffer + * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for + * multiplanar buffers); + * @bytesused: number of bytes occupied by data in the buffer (payload); + * unused (set to 0) for multiplanar buffers + * @flags: buffer informational flags + * @field: enum v4l2_field; field order of the image in the buffer + * @timestamp: frame timestamp + * @timecode: frame timecode + * @sequence: sequence count of this frame + * @memory: enum v4l2_memory; the method, in which the actual video data is + * passed + * @offset: for non-multiplanar buffers with memory == V4L2_MEMORY_MMAP; + * offset from the start of the device memory for this plane, + * (or a "cookie" that should be passed to mmap() as offset) + * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR; + * a userspace pointer pointing to this buffer + * @fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF; + * a userspace file descriptor associated with this buffer + * @planes: for multiplanar buffers; userspace pointer to the array of plane + * info structs for this buffer + * @length: size in bytes of the buffer (NOT its payload) for single-plane + * buffers (when type != *_MPLANE); number of elements in the + * planes array for multi-plane buffers + * + * Contains data exchanged by application and driver using one of the Streaming + * I/O methods. + */ +struct v4l2_buffer { + u_int32_t index; + u_int32_t type; + u_int32_t bytesused; + u_int32_t flags; + u_int32_t field; + struct timeval timestamp; + struct v4l2_timecode timecode; + u_int32_t sequence; + + /* memory location */ + u_int32_t memory; + union { + u_int32_t offset; + unsigned long userptr; + struct v4l2_plane *planes; + int32_t fd; + } m; + u_int32_t length; + u_int32_t reserved2; + u_int32_t reserved; +}; + +/* Flags for 'flags' field */ +/* Buffer is mapped (flag) */ +#define V4L2_BUF_FLAG_MAPPED 0x00000001 +/* Buffer is queued for processing */ +#define V4L2_BUF_FLAG_QUEUED 0x00000002 +/* Buffer is ready */ +#define V4L2_BUF_FLAG_DONE 0x00000004 +/* Image is a keyframe (I-frame) */ +#define V4L2_BUF_FLAG_KEYFRAME 0x00000008 +/* Image is a P-frame */ +#define V4L2_BUF_FLAG_PFRAME 0x00000010 +/* Image is a B-frame */ +#define V4L2_BUF_FLAG_BFRAME 0x00000020 +/* Buffer is ready, but the data contained within is corrupted. */ +#define V4L2_BUF_FLAG_ERROR 0x00000040 +/* timecode field is valid */ +#define V4L2_BUF_FLAG_TIMECODE 0x00000100 +/* Buffer is prepared for queuing */ +#define V4L2_BUF_FLAG_PREPARED 0x00000400 +/* Cache handling flags */ +#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x00000800 +#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x00001000 +/* Timestamp type */ +#define V4L2_BUF_FLAG_TIMESTAMP_MASK 0x0000e000 +#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x00000000 +#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x00002000 +#define V4L2_BUF_FLAG_TIMESTAMP_COPY 0x00004000 +/* Timestamp sources. */ +#define V4L2_BUF_FLAG_TSTAMP_SRC_MASK 0x00070000 +#define V4L2_BUF_FLAG_TSTAMP_SRC_EOF 0x00000000 +#define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 +/* mem2mem encoder/decoder */ +#define V4L2_BUF_FLAG_LAST 0x00100000 + +/** + * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor + * + * @index: id number of the buffer + * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for + * multiplanar buffers); + * @plane: index of the plane to be exported, 0 for single plane queues + * @flags: flags for newly created file, currently only O_CLOEXEC is + * supported, refer to manual of open syscall for more details + * @fd: file descriptor associated with DMABUF (set by driver) + * + * Contains data used for exporting a video buffer as DMABUF file descriptor. + * The buffer is identified by a 'cookie' returned by VIDIOC_QUERYBUF + * (identical to the cookie used to mmap() the buffer to userspace). All + * reserved fields must be set to zero. The field reserved0 is expected to + * become a structure 'type' allowing an alternative layout of the structure + * content. Therefore this field should not be used for any other extensions. + */ +struct v4l2_exportbuffer { + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t index; + u_int32_t plane; + u_int32_t flags; + int32_t fd; + u_int32_t reserved[11]; +}; + +/* + * O V E R L A Y P R E V I E W + */ +struct v4l2_framebuffer { + u_int32_t capability; + u_int32_t flags; +/* FIXME: in theory we should pass something like PCI device + memory + * region + offset instead of some physical address */ + void *base; + struct { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; /* enum v4l2_field */ + u_int32_t bytesperline; /* for padding, zero if unused */ + u_int32_t sizeimage; + u_int32_t colorspace; /* enum v4l2_colorspace */ + u_int32_t priv; /* reserved field, set to 0 */ + } fmt; +}; +/* Flags for the 'capability' field. Read only */ +#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001 +#define V4L2_FBUF_CAP_CHROMAKEY 0x0002 +#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004 +#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008 +#define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010 +#define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020 +#define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040 +#define V4L2_FBUF_CAP_SRC_CHROMAKEY 0x0080 +/* Flags for the 'flags' field. */ +#define V4L2_FBUF_FLAG_PRIMARY 0x0001 +#define V4L2_FBUF_FLAG_OVERLAY 0x0002 +#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004 +#define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008 +#define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010 +#define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020 +#define V4L2_FBUF_FLAG_SRC_CHROMAKEY 0x0040 + +struct v4l2_clip { + struct v4l2_rect c; + struct v4l2_clip __user *next; +}; + +struct v4l2_window { + struct v4l2_rect w; + u_int32_t field; /* enum v4l2_field */ + u_int32_t chromakey; + struct v4l2_clip __user *clips; + u_int32_t clipcount; + void __user *bitmap; + u_int8_t global_alpha; +}; + +/* + * C A P T U R E P A R A M E T E R S + */ +struct v4l2_captureparm { + u_int32_t capability; /* Supported modes */ + u_int32_t capturemode; /* Current mode */ + struct v4l2_fract timeperframe; /* Time per frame in seconds */ + u_int32_t extendedmode; /* Driver-specific extensions */ + u_int32_t readbuffers; /* # of buffers for read */ + u_int32_t reserved[4]; +}; + +/* Flags for 'capability' and 'capturemode' fields */ +#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */ +#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */ + +struct v4l2_outputparm { + u_int32_t capability; /* Supported modes */ + u_int32_t outputmode; /* Current mode */ + struct v4l2_fract timeperframe; /* Time per frame in seconds */ + u_int32_t extendedmode; /* Driver-specific extensions */ + u_int32_t writebuffers; /* # of buffers for write */ + u_int32_t reserved[4]; +}; + +/* + * I N P U T I M A G E C R O P P I N G + */ +struct v4l2_cropcap { + u_int32_t type; /* enum v4l2_buf_type */ + struct v4l2_rect bounds; + struct v4l2_rect defrect; + struct v4l2_fract pixelaspect; +}; + +struct v4l2_crop { + u_int32_t type; /* enum v4l2_buf_type */ + struct v4l2_rect c; +}; + +/** + * struct v4l2_selection - selection info + * @type: buffer type (do not use *_MPLANE types) + * @target: Selection target, used to choose one of possible rectangles; + * defined in v4l2-common.h; V4L2_SEL_TGT_* . + * @flags: constraints flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*. + * @r: coordinates of selection window + * @reserved: for future use, rounds structure size to 64 bytes, set to zero + * + * Hardware may use multiple helper windows to process a video stream. + * The structure is used to exchange this selection areas between + * an application and a driver. + */ +struct v4l2_selection { + u_int32_t type; + u_int32_t target; + u_int32_t flags; + struct v4l2_rect r; + u_int32_t reserved[9]; +}; + + +/* + * A N A L O G V I D E O S T A N D A R D + */ + +typedef u_int64_t v4l2_std_id; + +/* one bit for each */ +#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) +#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) +#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) +#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) +#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) +#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) +#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) +#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080) + +#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) +#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) +#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) +#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800) + +#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) /* BTSC */ +#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) /* EIA-J */ +#define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000) +#define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000) /* FM A2 */ + +#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) +#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) +#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) +#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) +#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) +#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) +#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) +#define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000) + +/* ATSC/HDTV */ +#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) +#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000) + +/* FIXME: + Although std_id is 64 bits, there is an issue on PPC32 architecture that + makes switch(u_int64_t) to break. So, there's a hack on v4l2-common.c rounding + this value to 32 bits. + As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide), + it should work fine. However, if needed to add more than two standards, + v4l2-common.c should be fixed. + */ + +/* + * Some macros to merge video standards in order to make live easier for the + * drivers and V4L2 applications + */ + +/* + * "Common" NTSC/M - It should be noticed that V4L2_STD_NTSC_443 is + * Missing here. + */ +#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\ + V4L2_STD_NTSC_M_JP |\ + V4L2_STD_NTSC_M_KR) +/* Secam macros */ +#define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\ + V4L2_STD_SECAM_K |\ + V4L2_STD_SECAM_K1) +/* All Secam Standards */ +#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\ + V4L2_STD_SECAM_G |\ + V4L2_STD_SECAM_H |\ + V4L2_STD_SECAM_DK |\ + V4L2_STD_SECAM_L |\ + V4L2_STD_SECAM_LC) +/* PAL macros */ +#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\ + V4L2_STD_PAL_B1 |\ + V4L2_STD_PAL_G) +#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\ + V4L2_STD_PAL_D1 |\ + V4L2_STD_PAL_K) +/* + * "Common" PAL - This macro is there to be compatible with the old + * V4L1 concept of "PAL": /BGDKHI. + * Several PAL standards are missing here: /M, /N and /Nc + */ +#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\ + V4L2_STD_PAL_DK |\ + V4L2_STD_PAL_H |\ + V4L2_STD_PAL_I) +/* Chroma "agnostic" standards */ +#define V4L2_STD_B (V4L2_STD_PAL_B |\ + V4L2_STD_PAL_B1 |\ + V4L2_STD_SECAM_B) +#define V4L2_STD_G (V4L2_STD_PAL_G |\ + V4L2_STD_SECAM_G) +#define V4L2_STD_H (V4L2_STD_PAL_H |\ + V4L2_STD_SECAM_H) +#define V4L2_STD_L (V4L2_STD_SECAM_L |\ + V4L2_STD_SECAM_LC) +#define V4L2_STD_GH (V4L2_STD_G |\ + V4L2_STD_H) +#define V4L2_STD_DK (V4L2_STD_PAL_DK |\ + V4L2_STD_SECAM_DK) +#define V4L2_STD_BG (V4L2_STD_B |\ + V4L2_STD_G) +#define V4L2_STD_MN (V4L2_STD_PAL_M |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc |\ + V4L2_STD_NTSC) + +/* Standards where MTS/BTSC stereo could be found */ +#define V4L2_STD_MTS (V4L2_STD_NTSC_M |\ + V4L2_STD_PAL_M |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc) + +/* Standards for Countries with 60Hz Line frequency */ +#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\ + V4L2_STD_PAL_60 |\ + V4L2_STD_NTSC |\ + V4L2_STD_NTSC_443) +/* Standards for Countries with 50Hz Line frequency */ +#define V4L2_STD_625_50 (V4L2_STD_PAL |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc |\ + V4L2_STD_SECAM) + +#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\ + V4L2_STD_ATSC_16_VSB) +/* Macros with none and all analog standards */ +#define V4L2_STD_UNKNOWN 0 +#define V4L2_STD_ALL (V4L2_STD_525_60 |\ + V4L2_STD_625_50) + +struct v4l2_standard { + u_int32_t index; + v4l2_std_id id; + u_int8_t name[24]; + struct v4l2_fract frameperiod; /* Frames, not fields */ + u_int32_t framelines; + u_int32_t reserved[4]; +}; + +/* + * D V B T T I M I N G S + */ + +/** struct v4l2_bt_timings - BT.656/BT.1120 timing data + * @width: total width of the active video in pixels + * @height: total height of the active video in lines + * @interlaced: Interlaced or progressive + * @polarities: Positive or negative polarities + * @pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @hfrontporch:Horizontal front porch in pixels + * @hsync: Horizontal Sync length in pixels + * @hbackporch: Horizontal back porch in pixels + * @vfrontporch:Vertical front porch in lines + * @vsync: Vertical Sync length in lines + * @vbackporch: Vertical back porch in lines + * @il_vfrontporch:Vertical front porch for the even field + * (aka field 2) of interlaced field formats + * @il_vsync: Vertical Sync length for the even field + * (aka field 2) of interlaced field formats + * @il_vbackporch:Vertical back porch for the even field + * (aka field 2) of interlaced field formats + * @standards: Standards the timing belongs to + * @flags: Flags + * @picture_aspect: The picture aspect ratio (hor/vert). + * @cea861_vic: VIC code as per the CEA-861 standard. + * @hdmi_vic: VIC code as per the HDMI standard. + * @reserved: Reserved fields, must be zeroed. + * + * A note regarding vertical interlaced timings: height refers to the total + * height of the active video frame (= two fields). The blanking timings refer + * to the blanking of each field. So the height of the total frame is + * calculated as follows: + * + * tot_height = height + vfrontporch + vsync + vbackporch + + * il_vfrontporch + il_vsync + il_vbackporch + * + * The active height of each field is height / 2. + */ +struct v4l2_bt_timings { + u_int32_t width; + u_int32_t height; + u_int32_t interlaced; + u_int32_t polarities; + u_int64_t pixelclock; + u_int32_t hfrontporch; + u_int32_t hsync; + u_int32_t hbackporch; + u_int32_t vfrontporch; + u_int32_t vsync; + u_int32_t vbackporch; + u_int32_t il_vfrontporch; + u_int32_t il_vsync; + u_int32_t il_vbackporch; + u_int32_t standards; + u_int32_t flags; + struct v4l2_fract picture_aspect; + u_int8_t cea861_vic; + u_int8_t hdmi_vic; + u_int8_t reserved[46]; +} __attribute__ ((packed)); + +/* Interlaced or progressive format */ +#define V4L2_DV_PROGRESSIVE 0 +#define V4L2_DV_INTERLACED 1 + +/* Polarities. If bit is not set, it is assumed to be negative polarity */ +#define V4L2_DV_VSYNC_POS_POL 0x00000001 +#define V4L2_DV_HSYNC_POS_POL 0x00000002 + +/* Timings standards */ +#define V4L2_DV_BT_STD_CEA861 (1 << 0) /* CEA-861 Digital TV Profile */ +#define V4L2_DV_BT_STD_DMT (1 << 1) /* VESA Discrete Monitor Timings */ +#define V4L2_DV_BT_STD_CVT (1 << 2) /* VESA Coordinated Video Timings */ +#define V4L2_DV_BT_STD_GTF (1 << 3) /* VESA Generalized Timings Formula */ +#define V4L2_DV_BT_STD_SDI (1 << 4) /* SDI Timings */ + +/* Flags */ + +/* + * CVT/GTF specific: timing uses reduced blanking (CVT) or the 'Secondary + * GTF' curve (GTF). In both cases the horizontal and/or vertical blanking + * intervals are reduced, allowing a higher resolution over the same + * bandwidth. This is a read-only flag. + */ +#define V4L2_DV_FL_REDUCED_BLANKING (1 << 0) +/* + * CEA-861 specific: set for CEA-861 formats with a framerate of a multiple + * of six. These formats can be optionally played at 1 / 1.001 speed. + * This is a read-only flag. + */ +#define V4L2_DV_FL_CAN_REDUCE_FPS (1 << 1) +/* + * CEA-861 specific: only valid for video transmitters, the flag is cleared + * by receivers. + * If the framerate of the format is a multiple of six, then the pixelclock + * used to set up the transmitter is divided by 1.001 to make it compatible + * with 60 Hz based standards such as NTSC and PAL-M that use a framerate of + * 29.97 Hz. Otherwise this flag is cleared. If the transmitter can't generate + * such frequencies, then the flag will also be cleared. + */ +#define V4L2_DV_FL_REDUCED_FPS (1 << 2) +/* + * Specific to interlaced formats: if set, then field 1 is really one half-line + * longer and field 2 is really one half-line shorter, so each field has + * exactly the same number of half-lines. Whether half-lines can be detected + * or used depends on the hardware. + */ +#define V4L2_DV_FL_HALF_LINE (1 << 3) +/* + * If set, then this is a Consumer Electronics (CE) video format. Such formats + * differ from other formats (commonly called IT formats) in that if RGB + * encoding is used then by default the RGB values use limited range (i.e. + * use the range 16-235) as opposed to 0-255. All formats defined in CEA-861 + * except for the 640x480 format are CE formats. + */ +#define V4L2_DV_FL_IS_CE_VIDEO (1 << 4) +/* Some formats like SMPTE-125M have an interlaced signal with a odd + * total height. For these formats, if this flag is set, the first + * field has the extra line. If not, it is the second field. + */ +#define V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE (1 << 5) +/* + * If set, then the picture_aspect field is valid. Otherwise assume that the + * pixels are square, so the picture aspect ratio is the same as the width to + * height ratio. + */ +#define V4L2_DV_FL_HAS_PICTURE_ASPECT (1 << 6) +/* + * If set, then the cea861_vic field is valid and contains the Video + * Identification Code as per the CEA-861 standard. + */ +#define V4L2_DV_FL_HAS_CEA861_VIC (1 << 7) +/* + * If set, then the hdmi_vic field is valid and contains the Video + * Identification Code as per the HDMI standard (HDMI Vendor Specific + * InfoFrame). + */ +#define V4L2_DV_FL_HAS_HDMI_VIC (1 << 8) + +/* A few useful defines to calculate the total blanking and frame sizes */ +#define V4L2_DV_BT_BLANKING_WIDTH(bt) \ + ((bt)->hfrontporch + (bt)->hsync + (bt)->hbackporch) +#define V4L2_DV_BT_FRAME_WIDTH(bt) \ + ((bt)->width + V4L2_DV_BT_BLANKING_WIDTH(bt)) +#define V4L2_DV_BT_BLANKING_HEIGHT(bt) \ + ((bt)->vfrontporch + (bt)->vsync + (bt)->vbackporch + \ + (bt)->il_vfrontporch + (bt)->il_vsync + (bt)->il_vbackporch) +#define V4L2_DV_BT_FRAME_HEIGHT(bt) \ + ((bt)->height + V4L2_DV_BT_BLANKING_HEIGHT(bt)) + +/** struct v4l2_dv_timings - DV timings + * @type: the type of the timings + * @bt: BT656/1120 timings + */ +struct v4l2_dv_timings { + u_int32_t type; + union { + struct v4l2_bt_timings bt; + u_int32_t reserved[32]; + }; +} __attribute__ ((packed)); + +/* Values for the type field */ +#define V4L2_DV_BT_656_1120 0 /* BT.656/1120 timing type */ + + +/** struct v4l2_enum_dv_timings - DV timings enumeration + * @index: enumeration index + * @pad: the pad number for which to enumerate timings (used with + * v4l-subdev nodes only) + * @reserved: must be zeroed + * @timings: the timings for the given index + */ +struct v4l2_enum_dv_timings { + u_int32_t index; + u_int32_t pad; + u_int32_t reserved[2]; + struct v4l2_dv_timings timings; +}; + +/** struct v4l2_bt_timings_cap - BT.656/BT.1120 timing capabilities + * @min_width: width in pixels + * @max_width: width in pixels + * @min_height: height in lines + * @max_height: height in lines + * @min_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @max_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @standards: Supported standards + * @capabilities: Supported capabilities + * @reserved: Must be zeroed + */ +struct v4l2_bt_timings_cap { + u_int32_t min_width; + u_int32_t max_width; + u_int32_t min_height; + u_int32_t max_height; + u_int64_t min_pixelclock; + u_int64_t max_pixelclock; + u_int32_t standards; + u_int32_t capabilities; + u_int32_t reserved[16]; +} __attribute__ ((packed)); + +/* Supports interlaced formats */ +#define V4L2_DV_BT_CAP_INTERLACED (1 << 0) +/* Supports progressive formats */ +#define V4L2_DV_BT_CAP_PROGRESSIVE (1 << 1) +/* Supports CVT/GTF reduced blanking */ +#define V4L2_DV_BT_CAP_REDUCED_BLANKING (1 << 2) +/* Supports custom formats */ +#define V4L2_DV_BT_CAP_CUSTOM (1 << 3) + +/** struct v4l2_dv_timings_cap - DV timings capabilities + * @type: the type of the timings (same as in struct v4l2_dv_timings) + * @pad: the pad number for which to query capabilities (used with + * v4l-subdev nodes only) + * @bt: the BT656/1120 timings capabilities + */ +struct v4l2_dv_timings_cap { + u_int32_t type; + u_int32_t pad; + u_int32_t reserved[2]; + union { + struct v4l2_bt_timings_cap bt; + u_int32_t raw_data[32]; + }; +}; + + +/* + * V I D E O I N P U T S + */ +struct v4l2_input { + u_int32_t index; /* Which input */ + u_int8_t name[32]; /* Label */ + u_int32_t type; /* Type of input */ + u_int32_t audioset; /* Associated audios (bitfield) */ + u_int32_t tuner; /* enum v4l2_tuner_type */ + v4l2_std_id std; + u_int32_t status; + u_int32_t capabilities; + u_int32_t reserved[3]; +}; + +/* Values for the 'type' field */ +#define V4L2_INPUT_TYPE_TUNER 1 +#define V4L2_INPUT_TYPE_CAMERA 2 +#define V4L2_INPUT_TYPE_TOUCH 3 + +/* field 'status' - general */ +#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */ +#define V4L2_IN_ST_NO_SIGNAL 0x00000002 +#define V4L2_IN_ST_NO_COLOR 0x00000004 + +/* field 'status' - sensor orientation */ +/* If sensor is mounted upside down set both bits */ +#define V4L2_IN_ST_HFLIP 0x00000010 /* Frames are flipped horizontally */ +#define V4L2_IN_ST_VFLIP 0x00000020 /* Frames are flipped vertically */ + +/* field 'status' - analog */ +#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ +#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */ +#define V4L2_IN_ST_NO_V_LOCK 0x00000400 /* No vertical sync lock */ +#define V4L2_IN_ST_NO_STD_LOCK 0x00000800 /* No standard format lock */ + +/* field 'status' - digital */ +#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */ +#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */ +#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */ + +/* field 'status' - VCR and set-top box */ +#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */ +#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */ +#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */ + +/* capabilities flags */ +#define V4L2_IN_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */ +#define V4L2_IN_CAP_CUSTOM_TIMINGS V4L2_IN_CAP_DV_TIMINGS /* For compatibility */ +#define V4L2_IN_CAP_STD 0x00000004 /* Supports S_STD */ +#define V4L2_IN_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */ + +/* + * V I D E O O U T P U T S + */ +struct v4l2_output { + u_int32_t index; /* Which output */ + u_int8_t name[32]; /* Label */ + u_int32_t type; /* Type of output */ + u_int32_t audioset; /* Associated audios (bitfield) */ + u_int32_t modulator; /* Associated modulator */ + v4l2_std_id std; + u_int32_t capabilities; + u_int32_t reserved[3]; +}; +/* Values for the 'type' field */ +#define V4L2_OUTPUT_TYPE_MODULATOR 1 +#define V4L2_OUTPUT_TYPE_ANALOG 2 +#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3 + +/* capabilities flags */ +#define V4L2_OUT_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */ +#define V4L2_OUT_CAP_CUSTOM_TIMINGS V4L2_OUT_CAP_DV_TIMINGS /* For compatibility */ +#define V4L2_OUT_CAP_STD 0x00000004 /* Supports S_STD */ +#define V4L2_OUT_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */ + +/* + * C O N T R O L S + */ +struct v4l2_control { + u_int32_t id; + int32_t value; +}; + +struct v4l2_ext_control { + u_int32_t id; + u_int32_t size; + u_int32_t reserved2[1]; + union { + int32_t value; + int64_t value64; + char __user *string; + u_int8_t __user *p_u8; + u_int16_t __user *p_u16; + u_int32_t __user *p_u32; + void __user *ptr; + }; +} __attribute__ ((packed)); + +struct v4l2_ext_controls { + union { +#ifndef __KERNEL__ + u_int32_t ctrl_class; +#endif + u_int32_t which; + }; + u_int32_t count; + u_int32_t error_idx; + u_int32_t reserved[2]; + struct v4l2_ext_control *controls; +}; + +#define V4L2_CTRL_ID_MASK (0x0fffffff) +#ifndef __KERNEL__ +#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) +#endif +#define V4L2_CTRL_ID2WHICH(id) ((id) & 0x0fff0000UL) +#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000) +#define V4L2_CTRL_MAX_DIMS (4) +#define V4L2_CTRL_WHICH_CUR_VAL 0 +#define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000 + +enum v4l2_ctrl_type { + V4L2_CTRL_TYPE_INTEGER = 1, + V4L2_CTRL_TYPE_BOOLEAN = 2, + V4L2_CTRL_TYPE_MENU = 3, + V4L2_CTRL_TYPE_BUTTON = 4, + V4L2_CTRL_TYPE_INTEGER64 = 5, + V4L2_CTRL_TYPE_CTRL_CLASS = 6, + V4L2_CTRL_TYPE_STRING = 7, + V4L2_CTRL_TYPE_BITMASK = 8, + V4L2_CTRL_TYPE_INTEGER_MENU = 9, + + /* Compound types are >= 0x0100 */ + V4L2_CTRL_COMPOUND_TYPES = 0x0100, + V4L2_CTRL_TYPE_U8 = 0x0100, + V4L2_CTRL_TYPE_U16 = 0x0101, + V4L2_CTRL_TYPE_U32 = 0x0102, +}; + +/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ +struct v4l2_queryctrl { + u_int32_t id; + u_int32_t type; /* enum v4l2_ctrl_type */ + u_int8_t name[32]; /* Whatever */ + int32_t minimum; /* Note signedness */ + int32_t maximum; + int32_t step; + int32_t default_value; + u_int32_t flags; + u_int32_t reserved[2]; +}; + +/* Used in the VIDIOC_QUERY_EXT_CTRL ioctl for querying extended controls */ +struct v4l2_query_ext_ctrl { + u_int32_t id; + u_int32_t type; + char name[32]; + int64_t minimum; + int64_t maximum; + u_int64_t step; + int64_t default_value; + u_int32_t flags; + u_int32_t elem_size; + u_int32_t elems; + u_int32_t nr_of_dims; + u_int32_t dims[V4L2_CTRL_MAX_DIMS]; + u_int32_t reserved[32]; +}; + +/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ +struct v4l2_querymenu { + u_int32_t id; + u_int32_t index; + union { + u_int8_t name[32]; /* Whatever */ + int64_t value; + }; + u_int32_t reserved; +} __attribute__ ((packed)); + +/* Control flags */ +#define V4L2_CTRL_FLAG_DISABLED 0x0001 +#define V4L2_CTRL_FLAG_GRABBED 0x0002 +#define V4L2_CTRL_FLAG_READ_ONLY 0x0004 +#define V4L2_CTRL_FLAG_UPDATE 0x0008 +#define V4L2_CTRL_FLAG_INACTIVE 0x0010 +#define V4L2_CTRL_FLAG_SLIDER 0x0020 +#define V4L2_CTRL_FLAG_WRITE_ONLY 0x0040 +#define V4L2_CTRL_FLAG_VOLATILE 0x0080 +#define V4L2_CTRL_FLAG_HAS_PAYLOAD 0x0100 +#define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200 + +/* Query flags, to be ORed with the control ID */ +#define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 +#define V4L2_CTRL_FLAG_NEXT_COMPOUND 0x40000000 + +/* User-class control IDs defined by V4L2 */ +#define V4L2_CID_MAX_CTRLS 1024 +/* IDs reserved for driver specific controls */ +#define V4L2_CID_PRIVATE_BASE 0x08000000 + + +/* + * T U N I N G + */ +struct v4l2_tuner { + u_int32_t index; + u_int8_t name[32]; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t rxsubchans; + u_int32_t audmode; + int32_t signal; + int32_t afc; + u_int32_t reserved[4]; +}; + +struct v4l2_modulator { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t txsubchans; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t reserved[3]; +}; + +/* Flags for the 'capability' field */ +#define V4L2_TUNER_CAP_LOW 0x0001 +#define V4L2_TUNER_CAP_NORM 0x0002 +#define V4L2_TUNER_CAP_HWSEEK_BOUNDED 0x0004 +#define V4L2_TUNER_CAP_HWSEEK_WRAP 0x0008 +#define V4L2_TUNER_CAP_STEREO 0x0010 +#define V4L2_TUNER_CAP_LANG2 0x0020 +#define V4L2_TUNER_CAP_SAP 0x0020 +#define V4L2_TUNER_CAP_LANG1 0x0040 +#define V4L2_TUNER_CAP_RDS 0x0080 +#define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100 +#define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200 +#define V4L2_TUNER_CAP_FREQ_BANDS 0x0400 +#define V4L2_TUNER_CAP_HWSEEK_PROG_LIM 0x0800 +#define V4L2_TUNER_CAP_1HZ 0x1000 + +/* Flags for the 'rxsubchans' field */ +#define V4L2_TUNER_SUB_MONO 0x0001 +#define V4L2_TUNER_SUB_STEREO 0x0002 +#define V4L2_TUNER_SUB_LANG2 0x0004 +#define V4L2_TUNER_SUB_SAP 0x0004 +#define V4L2_TUNER_SUB_LANG1 0x0008 +#define V4L2_TUNER_SUB_RDS 0x0010 + +/* Values for the 'audmode' field */ +#define V4L2_TUNER_MODE_MONO 0x0000 +#define V4L2_TUNER_MODE_STEREO 0x0001 +#define V4L2_TUNER_MODE_LANG2 0x0002 +#define V4L2_TUNER_MODE_SAP 0x0002 +#define V4L2_TUNER_MODE_LANG1 0x0003 +#define V4L2_TUNER_MODE_LANG1_LANG2 0x0004 + +struct v4l2_frequency { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t frequency; + u_int32_t reserved[8]; +}; + +#define V4L2_BAND_MODULATION_VSB (1 << 1) +#define V4L2_BAND_MODULATION_FM (1 << 2) +#define V4L2_BAND_MODULATION_AM (1 << 3) + +struct v4l2_frequency_band { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t index; + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t modulation; + u_int32_t reserved[9]; +}; + +struct v4l2_hw_freq_seek { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t seek_upward; + u_int32_t wrap_around; + u_int32_t spacing; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t reserved[5]; +}; + +/* + * R D S + */ + +struct v4l2_rds_data { + u_int8_t lsb; + u_int8_t msb; + u_int8_t block; +} __attribute__ ((packed)); + +#define V4L2_RDS_BLOCK_MSK 0x7 +#define V4L2_RDS_BLOCK_A 0 +#define V4L2_RDS_BLOCK_B 1 +#define V4L2_RDS_BLOCK_C 2 +#define V4L2_RDS_BLOCK_D 3 +#define V4L2_RDS_BLOCK_C_ALT 4 +#define V4L2_RDS_BLOCK_INVALID 7 + +#define V4L2_RDS_BLOCK_CORRECTED 0x40 +#define V4L2_RDS_BLOCK_ERROR 0x80 + +/* + * A U D I O + */ +struct v4l2_audio { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t mode; + u_int32_t reserved[2]; +}; + +/* Flags for the 'capability' field */ +#define V4L2_AUDCAP_STEREO 0x00001 +#define V4L2_AUDCAP_AVL 0x00002 + +/* Flags for the 'mode' field */ +#define V4L2_AUDMODE_AVL 0x00001 + +struct v4l2_audioout { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t mode; + u_int32_t reserved[2]; +}; + +/* + * M P E G S E R V I C E S + */ +#if 1 +#define V4L2_ENC_IDX_FRAME_I (0) +#define V4L2_ENC_IDX_FRAME_P (1) +#define V4L2_ENC_IDX_FRAME_B (2) +#define V4L2_ENC_IDX_FRAME_MASK (0xf) + +struct v4l2_enc_idx_entry { + u_int64_t offset; + u_int64_t pts; + u_int32_t length; + u_int32_t flags; + u_int32_t reserved[2]; +}; + +#define V4L2_ENC_IDX_ENTRIES (64) +struct v4l2_enc_idx { + u_int32_t entries; + u_int32_t entries_cap; + u_int32_t reserved[4]; + struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES]; +}; + + +#define V4L2_ENC_CMD_START (0) +#define V4L2_ENC_CMD_STOP (1) +#define V4L2_ENC_CMD_PAUSE (2) +#define V4L2_ENC_CMD_RESUME (3) + +/* Flags for V4L2_ENC_CMD_STOP */ +#define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0) + +struct v4l2_encoder_cmd { + u_int32_t cmd; + u_int32_t flags; + union { + struct { + u_int32_t data[8]; + } raw; + }; +}; + +/* Decoder commands */ +#define V4L2_DEC_CMD_START (0) +#define V4L2_DEC_CMD_STOP (1) +#define V4L2_DEC_CMD_PAUSE (2) +#define V4L2_DEC_CMD_RESUME (3) + +/* Flags for V4L2_DEC_CMD_START */ +#define V4L2_DEC_CMD_START_MUTE_AUDIO (1 << 0) + +/* Flags for V4L2_DEC_CMD_PAUSE */ +#define V4L2_DEC_CMD_PAUSE_TO_BLACK (1 << 0) + +/* Flags for V4L2_DEC_CMD_STOP */ +#define V4L2_DEC_CMD_STOP_TO_BLACK (1 << 0) +#define V4L2_DEC_CMD_STOP_IMMEDIATELY (1 << 1) + +/* Play format requirements (returned by the driver): */ + +/* The decoder has no special format requirements */ +#define V4L2_DEC_START_FMT_NONE (0) +/* The decoder requires full GOPs */ +#define V4L2_DEC_START_FMT_GOP (1) + +/* The structure must be zeroed before use by the application + This ensures it can be extended safely in the future. */ +struct v4l2_decoder_cmd { + u_int32_t cmd; + u_int32_t flags; + union { + struct { + u_int64_t pts; + } stop; + + struct { + /* 0 or 1000 specifies normal speed, + 1 specifies forward single stepping, + -1 specifies backward single stepping, + >1: playback at speed/1000 of the normal speed, + <-1: reverse playback at (-speed/1000) of the normal speed. */ + int32_t speed; + u_int32_t format; + } start; + + struct { + u_int32_t data[16]; + } raw; + }; +}; +#endif + + +/* + * D A T A S E R V I C E S ( V B I ) + * + * Data services API by Michael Schimek + */ + +/* Raw VBI */ +struct v4l2_vbi_format { + u_int32_t sampling_rate; /* in 1 Hz */ + u_int32_t offset; + u_int32_t samples_per_line; + u_int32_t sample_format; /* V4L2_PIX_FMT_* */ + int32_t start[2]; + u_int32_t count[2]; + u_int32_t flags; /* V4L2_VBI_* */ + u_int32_t reserved[2]; /* must be zero */ +}; + +/* VBI flags */ +#define V4L2_VBI_UNSYNC (1 << 0) +#define V4L2_VBI_INTERLACED (1 << 1) + +/* ITU-R start lines for each field */ +#define V4L2_VBI_ITU_525_F1_START (1) +#define V4L2_VBI_ITU_525_F2_START (264) +#define V4L2_VBI_ITU_625_F1_START (1) +#define V4L2_VBI_ITU_625_F2_START (314) + +/* Sliced VBI + * + * This implements is a proposal V4L2 API to allow SLICED VBI + * required for some hardware encoders. It should change without + * notice in the definitive implementation. + */ + +struct v4l2_sliced_vbi_format { + u_int16_t service_set; + /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field + service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field + (equals frame lines 313-336 for 625 line video + standards, 263-286 for 525 line standards) */ + u_int16_t service_lines[2][24]; + u_int32_t io_size; + u_int32_t reserved[2]; /* must be zero */ +}; + +/* Teletext World System Teletext + (WST), defined on ITU-R BT.653-2 */ +#define V4L2_SLICED_TELETEXT_B (0x0001) +/* Video Program System, defined on ETS 300 231*/ +#define V4L2_SLICED_VPS (0x0400) +/* Closed Caption, defined on EIA-608 */ +#define V4L2_SLICED_CAPTION_525 (0x1000) +/* Wide Screen System, defined on ITU-R BT1119.1 */ +#define V4L2_SLICED_WSS_625 (0x4000) + +#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525) +#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625) + +struct v4l2_sliced_vbi_cap { + u_int16_t service_set; + /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field + service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field + (equals frame lines 313-336 for 625 line video + standards, 263-286 for 525 line standards) */ + u_int16_t service_lines[2][24]; + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t reserved[3]; /* must be 0 */ +}; + +struct v4l2_sliced_vbi_data { + u_int32_t id; + u_int32_t field; /* 0: first field, 1: second field */ + u_int32_t line; /* 1-23 */ + u_int32_t reserved; /* must be 0 */ + u_int8_t data[48]; +}; + +/* + * Sliced VBI data inserted into MPEG Streams + */ + +/* + * V4L2_MPEG_STREAM_VBI_FMT_IVTV: + * + * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an + * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI + * data + * + * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header + * definitions are not included here. See the MPEG-2 specifications for details + * on these headers. + */ + +/* Line type IDs */ +#define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1) +#define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4) +#define V4L2_MPEG_VBI_IVTV_WSS_625 (5) +#define V4L2_MPEG_VBI_IVTV_VPS (7) + +struct v4l2_mpeg_vbi_itv0_line { + u_int8_t id; /* One of V4L2_MPEG_VBI_IVTV_* above */ + u_int8_t data[42]; /* Sliced VBI data for the line */ +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_itv0 { + u_int32_t linemask[2]; /* Bitmasks of VBI service lines present */ + struct v4l2_mpeg_vbi_itv0_line line[35]; +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_ITV0 { + struct v4l2_mpeg_vbi_itv0_line line[36]; +} __attribute__ ((packed)); + +#define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0" +#define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0" + +struct v4l2_mpeg_vbi_fmt_ivtv { + u_int8_t magic[4]; + union { + struct v4l2_mpeg_vbi_itv0 itv0; + struct v4l2_mpeg_vbi_ITV0 ITV0; + }; +} __attribute__ ((packed)); + +/* + * A G G R E G A T E S T R U C T U R E S + */ + +/** + * struct v4l2_plane_pix_format - additional, per-plane format definition + * @sizeimage: maximum size in bytes required for data, for which + * this plane will be used + * @bytesperline: distance in bytes between the leftmost pixels in two + * adjacent lines + */ +struct v4l2_plane_pix_format { + u_int32_t sizeimage; + u_int32_t bytesperline; + u_int16_t reserved[6]; +} __attribute__ ((packed)); + +/** + * struct v4l2_pix_format_mplane - multiplanar format definition + * @width: image width in pixels + * @height: image height in pixels + * @pixelformat: little endian four character code (fourcc) + * @field: enum v4l2_field; field order (for interlaced video) + * @colorspace: enum v4l2_colorspace; supplemental to pixelformat + * @plane_fmt: per-plane information + * @num_planes: number of planes for this format + * @flags: format flags (V4L2_PIX_FMT_FLAG_*) + * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding + * @quantization: enum v4l2_quantization, colorspace quantization + * @xfer_func: enum v4l2_xfer_func, colorspace transfer function + */ +struct v4l2_pix_format_mplane { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; + u_int32_t colorspace; + + struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES]; + u_int8_t num_planes; + u_int8_t flags; + union { + u_int8_t ycbcr_enc; + u_int8_t hsv_enc; + }; + u_int8_t quantization; + u_int8_t xfer_func; + u_int8_t reserved[7]; +} __attribute__ ((packed)); + +/** + * struct v4l2_sdr_format - SDR format definition + * @pixelformat: little endian four character code (fourcc) + * @buffersize: maximum size in bytes required for data + */ +struct v4l2_sdr_format { + u_int32_t pixelformat; + u_int32_t buffersize; + u_int8_t reserved[24]; +} __attribute__ ((packed)); + +/** + * struct v4l2_format - stream data format + * @type: enum v4l2_buf_type; type of the data stream + * @pix: definition of an image format + * @pix_mp: definition of a multiplanar image format + * @win: definition of an overlaid image + * @vbi: raw VBI capture or output parameters + * @sliced: sliced VBI capture or output parameters + * @raw_data: placeholder for future extensions and custom formats + */ +struct v4l2_format { + u_int32_t type; + union { + struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */ + struct v4l2_pix_format_mplane pix_mp; /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */ + struct v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */ + struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */ + struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */ + struct v4l2_sdr_format sdr; /* V4L2_BUF_TYPE_SDR_CAPTURE */ + u_int8_t raw_data[200]; /* user-defined */ + } fmt; +}; + +/* Stream type-dependent parameters + */ +struct v4l2_streamparm { + u_int32_t type; /* enum v4l2_buf_type */ + union { + struct v4l2_captureparm capture; + struct v4l2_outputparm output; + u_int8_t raw_data[200]; /* user-defined */ + } parm; +}; + +/* + * E V E N T S + */ + +#define V4L2_EVENT_ALL 0 +#define V4L2_EVENT_VSYNC 1 +#define V4L2_EVENT_EOS 2 +#define V4L2_EVENT_CTRL 3 +#define V4L2_EVENT_FRAME_SYNC 4 +#define V4L2_EVENT_SOURCE_CHANGE 5 +#define V4L2_EVENT_MOTION_DET 6 +#define V4L2_EVENT_PRIVATE_START 0x08000000 + +/* Payload for V4L2_EVENT_VSYNC */ +struct v4l2_event_vsync { + /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */ + u_int8_t field; +} __attribute__ ((packed)); + +/* Payload for V4L2_EVENT_CTRL */ +#define V4L2_EVENT_CTRL_CH_VALUE (1 << 0) +#define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1) +#define V4L2_EVENT_CTRL_CH_RANGE (1 << 2) + +struct v4l2_event_ctrl { + u_int32_t changes; + u_int32_t type; + union { + int32_t value; + int64_t value64; + }; + u_int32_t flags; + int32_t minimum; + int32_t maximum; + int32_t step; + int32_t default_value; +}; + +struct v4l2_event_frame_sync { + u_int32_t frame_sequence; +}; + +#define V4L2_EVENT_SRC_CH_RESOLUTION (1 << 0) + +struct v4l2_event_src_change { + u_int32_t changes; +}; + +#define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ (1 << 0) + +/** + * struct v4l2_event_motion_det - motion detection event + * @flags: if V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ is set, then the + * frame_sequence field is valid. + * @frame_sequence: the frame sequence number associated with this event. + * @region_mask: which regions detected motion. + */ +struct v4l2_event_motion_det { + u_int32_t flags; + u_int32_t frame_sequence; + u_int32_t region_mask; +}; + +struct v4l2_event { + u_int32_t type; + union { + struct v4l2_event_vsync vsync; + struct v4l2_event_ctrl ctrl; + struct v4l2_event_frame_sync frame_sync; + struct v4l2_event_src_change src_change; + struct v4l2_event_motion_det motion_det; + u_int8_t data[64]; + } u; + u_int32_t pending; + u_int32_t sequence; + struct timespec timestamp; + u_int32_t id; + u_int32_t reserved[8]; +}; + +#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0) +#define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1) + +struct v4l2_event_subscription { + u_int32_t type; + u_int32_t id; + u_int32_t flags; + u_int32_t reserved[5]; +}; + +/* + * A D V A N C E D D E B U G G I N G + * + * NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS! + * FOR DEBUGGING, TESTING AND INTERNAL USE ONLY! + */ + +/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */ + +#define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */ +#define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */ + +/* The following four defines are no longer in use */ +#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE +#define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */ +#define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */ +#define V4L2_CHIP_MATCH_AC97 3 /* Match against ancillary AC97 chip */ + +struct v4l2_dbg_match { + u_int32_t type; /* Match type */ + union { /* Match this chip, meaning determined by type */ + u_int32_t addr; + char name[32]; + }; +} __attribute__ ((packed)); + +struct v4l2_dbg_register { + struct v4l2_dbg_match match; + u_int32_t size; /* register size in bytes */ + u_int64_t reg; + u_int64_t val; +} __attribute__ ((packed)); + +#define V4L2_CHIP_FL_READABLE (1 << 0) +#define V4L2_CHIP_FL_WRITABLE (1 << 1) + +/* VIDIOC_DBG_G_CHIP_INFO */ +struct v4l2_dbg_chip_info { + struct v4l2_dbg_match match; + char name[32]; + u_int32_t flags; + u_int32_t reserved[32]; +} __attribute__ ((packed)); + +/** + * struct v4l2_create_buffers - VIDIOC_CREATE_BUFS argument + * @index: on return, index of the first created buffer + * @count: entry: number of requested buffers, + * return: number of created buffers + * @memory: enum v4l2_memory; buffer memory type + * @format: frame format, for which buffers are requested + * @reserved: future extensions + */ +struct v4l2_create_buffers { + u_int32_t index; + u_int32_t count; + u_int32_t memory; + struct v4l2_format format; + u_int32_t reserved[8]; +}; + +/* + * I O C T L C O D E S F O R V I D E O D E V I C E S + * + */ +#define VIDIOC_QUERYCAP _IOR('V', 0, struct v4l2_capability) +#define VIDIOC_RESERVED _IO('V', 1) +#define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc) +#define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format) +#define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format) +#define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers) +#define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer) +#define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer) +#define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer) +#define VIDIOC_OVERLAY _IOW('V', 14, int) +#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer) +#define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer) +#define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer) +#define VIDIOC_STREAMON _IOW('V', 18, int) +#define VIDIOC_STREAMOFF _IOW('V', 19, int) +#define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm) +#define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm) +#define VIDIOC_G_STD _IOR('V', 23, v4l2_std_id) +#define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id) +#define VIDIOC_ENUMSTD _IOWR('V', 25, struct v4l2_standard) +#define VIDIOC_ENUMINPUT _IOWR('V', 26, struct v4l2_input) +#define VIDIOC_G_CTRL _IOWR('V', 27, struct v4l2_control) +#define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control) +#define VIDIOC_G_TUNER _IOWR('V', 29, struct v4l2_tuner) +#define VIDIOC_S_TUNER _IOW('V', 30, struct v4l2_tuner) +#define VIDIOC_G_AUDIO _IOR('V', 33, struct v4l2_audio) +#define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio) +#define VIDIOC_QUERYCTRL _IOWR('V', 36, struct v4l2_queryctrl) +#define VIDIOC_QUERYMENU _IOWR('V', 37, struct v4l2_querymenu) +#define VIDIOC_G_INPUT _IOR('V', 38, int) +#define VIDIOC_S_INPUT _IOWR('V', 39, int) +#define VIDIOC_G_EDID _IOWR('V', 40, struct v4l2_edid) +#define VIDIOC_S_EDID _IOWR('V', 41, struct v4l2_edid) +#define VIDIOC_G_OUTPUT _IOR('V', 46, int) +#define VIDIOC_S_OUTPUT _IOWR('V', 47, int) +#define VIDIOC_ENUMOUTPUT _IOWR('V', 48, struct v4l2_output) +#define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout) +#define VIDIOC_S_AUDOUT _IOW('V', 50, struct v4l2_audioout) +#define VIDIOC_G_MODULATOR _IOWR('V', 54, struct v4l2_modulator) +#define VIDIOC_S_MODULATOR _IOW('V', 55, struct v4l2_modulator) +#define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency) +#define VIDIOC_S_FREQUENCY _IOW('V', 57, struct v4l2_frequency) +#define VIDIOC_CROPCAP _IOWR('V', 58, struct v4l2_cropcap) +#define VIDIOC_G_CROP _IOWR('V', 59, struct v4l2_crop) +#define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop) +#define VIDIOC_G_JPEGCOMP _IOR('V', 61, struct v4l2_jpegcompression) +#define VIDIOC_S_JPEGCOMP _IOW('V', 62, struct v4l2_jpegcompression) +#define VIDIOC_QUERYSTD _IOR('V', 63, v4l2_std_id) +#define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format) +#define VIDIOC_ENUMAUDIO _IOWR('V', 65, struct v4l2_audio) +#define VIDIOC_ENUMAUDOUT _IOWR('V', 66, struct v4l2_audioout) +#define VIDIOC_G_PRIORITY _IOR('V', 67, u_int32_t) /* enum v4l2_priority */ +#define VIDIOC_S_PRIORITY _IOW('V', 68, u_int32_t) /* enum v4l2_priority */ +#define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap) +#define VIDIOC_LOG_STATUS _IO('V', 70) +#define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls) +#define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls) +#define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls) +#define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum) +#define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum) +#define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx) +#define VIDIOC_ENCODER_CMD _IOWR('V', 77, struct v4l2_encoder_cmd) +#define VIDIOC_TRY_ENCODER_CMD _IOWR('V', 78, struct v4l2_encoder_cmd) + +/* + * Experimental, meant for debugging, testing and internal use. + * Only implemented if CONFIG_VIDEO_ADV_DEBUG is defined. + * You must be root to use these ioctls. Never use these in applications! + */ +#define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register) +#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register) + +#define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek) +#define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings) +#define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings) +#define VIDIOC_DQEVENT _IOR('V', 89, struct v4l2_event) +#define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 90, struct v4l2_event_subscription) +#define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription) +#define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers) +#define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer) +#define VIDIOC_G_SELECTION _IOWR('V', 94, struct v4l2_selection) +#define VIDIOC_S_SELECTION _IOWR('V', 95, struct v4l2_selection) +#define VIDIOC_DECODER_CMD _IOWR('V', 96, struct v4l2_decoder_cmd) +#define VIDIOC_TRY_DECODER_CMD _IOWR('V', 97, struct v4l2_decoder_cmd) +#define VIDIOC_ENUM_DV_TIMINGS _IOWR('V', 98, struct v4l2_enum_dv_timings) +#define VIDIOC_QUERY_DV_TIMINGS _IOR('V', 99, struct v4l2_dv_timings) +#define VIDIOC_DV_TIMINGS_CAP _IOWR('V', 100, struct v4l2_dv_timings_cap) +#define VIDIOC_ENUM_FREQ_BANDS _IOWR('V', 101, struct v4l2_frequency_band) + +/* + * Experimental, meant for debugging, testing and internal use. + * Never use this in applications! + */ +#define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info) + +#define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl) + +/* Reminder: when adding new ioctls please add support for them to + drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ + +#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */ + +#endif /* _SYS_VIDEOIO_H */ diff --git a/sys/sys/vmmeter.h b/sys/sys/vmmeter.h new file mode 100644 index 0000000..2da0836 --- /dev/null +++ b/sys/sys/vmmeter.h @@ -0,0 +1,97 @@ +/* $OpenBSD: vmmeter.h,v 1.15 2016/07/27 14:44:59 tedu Exp $ */ +/* $NetBSD: vmmeter.h,v 1.9 1995/03/26 20:25:04 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. + * + * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef __VMMETER_H__ +#define __VMMETER_H__ + +/* + * System wide statistics counters. Look in <uvm/uvm_extern.h> for the + * UVM equivalent. + */ + +/* systemwide totals computed every five seconds */ +struct vmtotal { + u_int16_t t_rq; /* length of the run queue */ + u_int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */ + u_int16_t t_pw; /* jobs in page wait */ + u_int16_t t_sl; /* jobs sleeping in core */ + u_int16_t t_sw; /* swapped out runnable/short block jobs */ + u_int32_t t_vm; /* total virtual memory */ + u_int32_t t_avm; /* active virtual memory */ + u_int32_t t_rm; /* total real memory in use */ + u_int32_t t_arm; /* active real memory */ + u_int32_t t_vmshr; /* shared virtual memory */ + u_int32_t t_avmshr; /* active shared virtual memory */ + u_int32_t t_rmshr; /* shared real memory */ + u_int32_t t_armshr; /* active shared real memory */ + u_int32_t t_free; /* free memory pages */ +}; + +/* + * Fork/vfork/__tfork accounting. + */ +struct forkstat { + uint32_t cntfork; /* number of fork() calls */ + uint32_t cntvfork; /* number of vfork() calls */ + uint32_t cnttfork; /* number of __tfork() calls */ + uint32_t cntkthread; /* number of kernel threads created */ + uint64_t sizfork; /* VM pages affected by fork() */ + uint64_t sizvfork; /* VM pages affected by vfork() */ + uint64_t siztfork; /* VM pages affected by __tfork() */ + uint64_t sizkthread; /* VM pages affected by kernel threads */ +}; + +/* These sysctl names are only really used by sysctl(8) */ +#define KERN_FORKSTAT_FORK 1 +#define KERN_FORKSTAT_VFORK 2 +#define KERN_FORKSTAT_TFORK 3 +#define KERN_FORKSTAT_KTHREAD 4 +#define KERN_FORKSTAT_SIZFORK 5 +#define KERN_FORKSTAT_SIZVFORK 6 +#define KERN_FORKSTAT_SIZTFORK 7 +#define KERN_FORKSTAT_SIZKTHREAD 8 +#define KERN_FORKSTAT_MAXID 9 + +#define CTL_KERN_FORKSTAT_NAMES { \ + { 0, 0 }, \ + { "forks", CTLTYPE_INT }, \ + { "vforks", CTLTYPE_INT }, \ + { "tforks", CTLTYPE_INT }, \ + { "kthreads", CTLTYPE_INT }, \ + { "fork_pages", CTLTYPE_INT }, \ + { "vfork_pages", CTLTYPE_INT }, \ + { "tfork_pages", CTLTYPE_INT }, \ + { "kthread_pages", CTLTYPE_INT }, \ +} +#endif /* __VMMETER_H__ */ diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h new file mode 100644 index 0000000..0899340 --- /dev/null +++ b/sys/sys/vnode.h @@ -0,0 +1,665 @@ +/* $OpenBSD: vnode.h,v 1.156 2020/04/08 08:07:52 mpi Exp $ */ +/* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 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. + * + * @(#)vnode.h 8.11 (Berkeley) 11/21/94 + */ + +#ifndef _SYS_VNODE_H_ +#define _SYS_VNODE_H_ + +#include <sys/buf.h> +#include <sys/types.h> +#include <sys/queue.h> +#include <sys/selinfo.h> +#include <sys/tree.h> + +/* + * The vnode is the focus of all file activity in UNIX. There is a + * unique vnode allocated for each active file, each current directory, + * each mounted-on file, text file, and the root. + */ + +/* + * Vnode types. VNON means no type. + */ +enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; + +#define VTYPE_NAMES \ + "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD" + +/* + * Vnode tag types. + * These are for the benefit of external programs only (e.g., pstat) + * and should NEVER be inspected by the kernel. + * + * Note that v_tag is actually used to tell MFS from FFS, and EXT2FS from + * the rest, so don't believe the above comment! + */ +enum vtagtype { + VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, + VT_PORTAL, VT_PROCFS, VT_AFS, VT_ISOFS, VT_ADOSFS, + VT_EXT2FS, VT_VFS, VT_NTFS, VT_UDF, VT_FUSEFS, VT_TMPFS, +}; + +#define VTAG_NAMES \ + "NON", "UFS", "NFS", "MFS", "MSDOSFS", \ + "unused", "unused", "unused", "ISOFS", "unused", \ + "EXT2FS", "VFS", "NTFS", "UDF", "FUSEFS", "TMPFS" + +/* + * Each underlying filesystem allocates its own private area and hangs + * it from v_data. If non-null, this area is freed in getnewvnode(). + */ +LIST_HEAD(buflists, buf); + +RBT_HEAD(buf_rb_bufs, buf); + +struct namecache; +RBT_HEAD(namecache_rb_cache, namecache); + +struct uvm_vnode; +struct vnode { + struct uvm_vnode *v_uvm; /* uvm data */ + const struct vops *v_op; /* vnode operations vector */ + enum vtype v_type; /* vnode type */ + enum vtagtype v_tag; /* type of underlying data */ + u_int v_flag; /* vnode flags (see below) */ + u_int v_usecount; /* reference count of users */ + u_int v_uvcount; /* unveil references */ + /* reference count of writers */ + u_int v_writecount; + u_int v_lockcount; /* # threads waiting on lock */ + /* Flags that can be read/written in interrupts */ + u_int v_bioflag; + u_int v_holdcnt; /* buffer references */ + u_int v_id; /* capability identifier */ + u_int v_inflight; + struct mount *v_mount; /* ptr to vfs we are in */ + TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ + TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ + struct buf_rb_bufs v_bufs_tree; /* lookup of all bufs */ + struct buflists v_cleanblkhd; /* clean blocklist head */ + struct buflists v_dirtyblkhd; /* dirty blocklist head */ + u_int v_numoutput; /* num of writes in progress */ + LIST_ENTRY(vnode) v_synclist; /* vnode with dirty buffers */ + union { + struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ + struct socket *vu_socket; /* unix ipc (VSOCK) */ + struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ + struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ + } v_un; + + /* VFS namecache */ + struct namecache_rb_cache v_nc_tree; + TAILQ_HEAD(, namecache) v_cache_dst; /* cache entries to us */ + + void *v_data; /* private data for fs */ + struct selinfo v_selectinfo; /* identity of poller(s) */ +}; +#define v_mountedhere v_un.vu_mountedhere +#define v_socket v_un.vu_socket +#define v_specinfo v_un.vu_specinfo +#define v_fifoinfo v_un.vu_fifoinfo + +/* + * Vnode flags. + */ +#define VROOT 0x0001 /* root of its file system */ +#define VTEXT 0x0002 /* vnode is a pure text prototype */ +#define VSYSTEM 0x0004 /* vnode being used by kernel */ +#define VISTTY 0x0008 /* vnode represents a tty */ +#define VXLOCK 0x0100 /* vnode is locked to change underlying type */ +#define VXWANT 0x0200 /* process is waiting for vnode */ +#define VCLONED 0x0400 /* vnode was cloned */ +#define VALIASED 0x0800 /* vnode has an alias */ +#define VLARVAL 0x1000 /* vnode data not yet set up by higher level */ +#define VLOCKSWORK 0x4000 /* FS supports locking discipline */ +#define VCLONE 0x8000 /* vnode is a clone */ + +/* + * (v_bioflag) Flags that may be manipulated by interrupt handlers + */ +#define VBIOWAIT 0x0001 /* waiting for output to complete */ +#define VBIOONSYNCLIST 0x0002 /* Vnode is on syncer worklist */ +#define VBIOONFREELIST 0x0004 /* Vnode is on a free list */ +#define VBIOERROR 0x0008 /* A write failed */ + +/* + * Vnode attributes. A field value of VNOVAL represents a field whose value + * is unavailable (getattr) or which is not to be changed (setattr). For + * the timespec fields, only the tv_nsec member needs to be set to VNOVAL: + * if tv_nsec != VNOVAL then both tv_sec and tv_nsec are valid. + */ +struct vattr { + enum vtype va_type; /* vnode type (for create) */ + mode_t va_mode; /* files access mode and type */ + nlink_t va_nlink; /* number of references to file */ + uid_t va_uid; /* owner user id */ + gid_t va_gid; /* owner group id */ + long va_fsid; /* file system id (dev for now) */ + u_quad_t va_fileid; /* file id */ + u_quad_t va_size; /* file size in bytes */ + long va_blocksize; /* blocksize preferred for i/o */ + struct timespec va_atime; /* time of last access */ + struct timespec va_mtime; /* time of last modification */ + struct timespec va_ctime; /* time file changed */ + u_long va_gen; /* generation number of file */ + u_long va_flags; /* flags defined for file */ + dev_t va_rdev; /* device the special file represents */ + u_quad_t va_bytes; /* bytes of disk space held by file */ + u_quad_t va_filerev; /* file modification number */ + u_int va_vaflags; /* operations flags, see below */ + long va_spare; /* remain quad aligned */ +}; + +/* + * Flags for va_vaflags. + */ +#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ +#define VA_EXCLUSIVE 0x02 /* exclusive create request */ +#define VA_UTIMES_CHANGE 0x04 /* ctime should be updated */ +/* + * Flags for ioflag. + */ +#define IO_UNIT 0x01 /* do I/O as atomic unit */ +#define IO_APPEND 0x02 /* append write to end */ +#define IO_SYNC 0x04 /* do I/O synchronously */ +#define IO_NODELOCKED 0x08 /* underlying node already locked */ +#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ +#define IO_NOLIMIT 0x20 /* don't enforce limits on i/o */ +#define IO_NOCACHE 0x40 /* don't cache result of this i/o */ + +/* + * Modes. Some values same as Ixxx entries from inode.h for now. + */ +#define VSUID 04000 /* set user id on execution */ +#define VSGID 02000 /* set group id on execution */ +#define VSVTX 01000 /* save swapped text even after use */ +#define VREAD 00400 /* read, write, execute permissions */ +#define VWRITE 00200 +#define VEXEC 00100 + +/* + * Token indicating no attribute value yet assigned. + */ +#define VNOVAL (-1) + +#ifdef _KERNEL +RBT_PROTOTYPE(buf_rb_bufs, buf, b_rbbufs, rb_buf_compare); +/* + * Convert between vnode types and inode formats (since POSIX.1 + * defines mode word of stat structure in terms of inode formats). + */ +extern enum vtype iftovt_tab[]; +extern int vttoif_tab[]; +#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) +#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) +#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) + +/* + * Flags to various vnode functions. + */ +#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ +#define FORCECLOSE 0x0002 /* vflush: force file closeure */ +#define WRITECLOSE 0x0004 /* vflush: only close writeable files */ +#define DOCLOSE 0x0008 /* vclean: close active files */ +#define IGNORECLEAN 0x0010 /* vflush: ignore clean vnodes */ +#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ +#define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */ + +#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ + + +TAILQ_HEAD(freelst, vnode); +extern struct freelst vnode_hold_list; /* free vnodes referencing buffers */ +extern struct freelst vnode_free_list; /* vnode free list */ + +#define VATTR_NULL(vap) vattr_null(vap) +#define NULLVP ((struct vnode *)NULL) +#define VN_KNOTE(vp, b) \ + KNOTE(&vp->v_selectinfo.si_note, (b)) + +/* + * Global vnode data. + */ +extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ +extern int initialvnodes; /* XXX number of vnodes to start */ +extern int maxvnodes; /* XXX number of vnodes to allocate */ +extern int syncdelay; /* seconds to delay syncing vnodes */ +extern int rushjob; /* # of slots syncer should run ASAP */ +extern void vhold(struct vnode *); +extern void vdrop(struct vnode *); + +/* vnode operations */ +struct vops { + int (*vop_lock)(void *); + int (*vop_unlock)(void *); + int (*vop_islocked)(void *); + int (*vop_abortop)(void *); + int (*vop_access)(void *); + int (*vop_advlock)(void *); + int (*vop_bmap)(void *); + int (*vop_bwrite)(void *); + int (*vop_close)(void *); + int (*vop_create)(void *); + int (*vop_fsync)(void *); + int (*vop_getattr)(void *); + int (*vop_inactive)(void *); + int (*vop_ioctl)(void *); + int (*vop_link)(void *); + int (*vop_lookup)(void *); + int (*vop_mknod)(void *); + int (*vop_open)(void *); + int (*vop_pathconf)(void *); + int (*vop_poll)(void *); + int (*vop_print)(void *); + int (*vop_read)(void *); + int (*vop_readdir)(void *); + int (*vop_readlink)(void *); + int (*vop_reclaim)(void *); + int (*vop_remove)(void *); + int (*vop_rename)(void *); + int (*vop_revoke)(void *); + int (*vop_mkdir)(void *); + int (*vop_rmdir)(void *); + int (*vop_setattr)(void *); + int (*vop_strategy)(void *); + int (*vop_symlink)(void *); + int (*vop_write)(void *); + int (*vop_kqfilter)(void *); +}; + +extern const struct vops dead_vops; +extern const struct vops spec_vops; + +struct vop_generic_args { + void *a_garbage; + /* Other data probably follows; */ +}; + +struct vop_islocked_args { + struct vnode *a_vp; +}; +int VOP_ISLOCKED(struct vnode *); + +struct vop_lookup_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; +}; +int VOP_LOOKUP(struct vnode *, struct vnode **, struct componentname *); + +struct vop_create_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_CREATE(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_mknod_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_MKNOD(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_open_args { + struct vnode *a_vp; + int a_mode; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_OPEN(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_close_args { + struct vnode *a_vp; + int a_fflag; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_CLOSE(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_access_args { + struct vnode *a_vp; + int a_mode; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_ACCESS(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_getattr_args { + struct vnode *a_vp; + struct vattr *a_vap; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_GETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *); + +struct vop_setattr_args { + struct vnode *a_vp; + struct vattr *a_vap; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_SETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *); + +struct vop_read_args { + struct vnode *a_vp; + struct uio *a_uio; + int a_ioflag; + struct ucred *a_cred; +}; +int VOP_READ(struct vnode *, struct uio *, int, struct ucred *); + +struct vop_write_args { + struct vnode *a_vp; + struct uio *a_uio; + int a_ioflag; + struct ucred *a_cred; +}; +int VOP_WRITE(struct vnode *, struct uio *, int, struct ucred *); + +struct vop_ioctl_args { + struct vnode *a_vp; + u_long a_command; + void *a_data; + int a_fflag; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_IOCTL(struct vnode *, u_long, void *, int, struct ucred *, + struct proc *); + +struct vop_poll_args { + struct vnode *a_vp; + int a_fflag; + int a_events; + struct proc *a_p; +}; +int VOP_POLL(struct vnode *, int, int, struct proc *); + +struct vop_kqfilter_args { + struct vnode *a_vp; + int a_fflag; + struct knote *a_kn; +}; +int VOP_KQFILTER(struct vnode *, int, struct knote *); + +struct vop_revoke_args { + struct vnode *a_vp; + int a_flags; +}; +int VOP_REVOKE(struct vnode *, int); + +struct vop_fsync_args { + struct vnode *a_vp; + struct ucred *a_cred; + int a_waitfor; + struct proc *a_p; +}; +int VOP_FSYNC(struct vnode *, struct ucred *, int, struct proc *); + +struct vop_remove_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_REMOVE(struct vnode *, struct vnode *, struct componentname *); + +struct vop_link_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_LINK(struct vnode *, struct vnode *, struct componentname *); + +struct vop_rename_args { + struct vnode *a_fdvp; + struct vnode *a_fvp; + struct componentname *a_fcnp; + struct vnode *a_tdvp; + struct vnode *a_tvp; + struct componentname *a_tcnp; +}; +int VOP_RENAME(struct vnode *, struct vnode *, struct componentname *, + struct vnode *, struct vnode *, struct componentname *); + +struct vop_mkdir_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_MKDIR(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_rmdir_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_RMDIR(struct vnode *, struct vnode *, struct componentname *); + +struct vop_symlink_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; + char *a_target; +}; +int VOP_SYMLINK(struct vnode *, struct vnode **, struct componentname *, + struct vattr *, char *); + +struct vop_readdir_args { + struct vnode *a_vp; + struct uio *a_uio; + struct ucred *a_cred; + int *a_eofflag; +}; +int VOP_READDIR(struct vnode *, struct uio *, struct ucred *, int *); + +struct vop_readlink_args { + struct vnode *a_vp; + struct uio *a_uio; + struct ucred *a_cred; +}; +int VOP_READLINK(struct vnode *, struct uio *, struct ucred *); + +struct vop_abortop_args { + struct vnode *a_dvp; + struct componentname *a_cnp; +}; +int VOP_ABORTOP(struct vnode *, struct componentname *); + +struct vop_inactive_args { + struct vnode *a_vp; + struct proc *a_p; +}; +int VOP_INACTIVE(struct vnode *, struct proc *); + +struct vop_reclaim_args { + struct vnode *a_vp; + struct proc *a_p; +}; +int VOP_RECLAIM(struct vnode *, struct proc *); + +struct vop_lock_args { + struct vnode *a_vp; + int a_flags; +}; +int VOP_LOCK(struct vnode *, int); + +struct vop_unlock_args { + struct vnode *a_vp; +}; +int VOP_UNLOCK(struct vnode *); + +struct vop_bmap_args { + struct vnode *a_vp; + daddr_t a_bn; + struct vnode **a_vpp; + daddr_t *a_bnp; + int *a_runp; +}; +int VOP_BMAP(struct vnode *, daddr_t, struct vnode **, daddr_t *, int *); + +struct vop_print_args { + struct vnode *a_vp; +}; +int VOP_PRINT(struct vnode *); + +struct vop_pathconf_args { + struct vnode *a_vp; + int a_name; + register_t *a_retval; +}; +int VOP_PATHCONF(struct vnode *, int, register_t *); + +struct vop_advlock_args { + struct vnode *a_vp; + void *a_id; + int a_op; + struct flock *a_fl; + int a_flags; +}; +int VOP_ADVLOCK(struct vnode *, void *, int, struct flock *, int); + +/* Special cases: */ +struct vop_strategy_args { + struct buf *a_bp; +}; +int VOP_STRATEGY(struct buf *); + +struct vop_bwrite_args { + struct buf *a_bp; +}; +int VOP_BWRITE(struct buf *); +/* End of special cases. */ + + +/* Public vnode manipulation functions. */ +struct file; +struct filedesc; +struct mount; +struct nameidata; +struct proc; +struct stat; +struct statfs; +struct ucred; +struct uio; +struct vattr; +struct vnode; + +/* vfs_subr */ +int bdevvp(dev_t, struct vnode **); +int cdevvp(dev_t, struct vnode **); +struct vnode *checkalias(struct vnode *, dev_t, struct mount *); +int getnewvnode(enum vtagtype, struct mount *, const struct vops *, + struct vnode **); +int vaccess(enum vtype, mode_t, uid_t, gid_t, mode_t, struct ucred *); +int vnoperm(struct vnode *); +void vattr_null(struct vattr *); +void vdevgone(int, int, int, enum vtype); +int vcount(struct vnode *); +int vfinddev(dev_t, enum vtype, struct vnode **); +void vflushbuf(struct vnode *, int); +int vflush(struct mount *, struct vnode *, int); +int vget(struct vnode *, int); +void vgone(struct vnode *); +void vgonel(struct vnode *, struct proc *); +int vinvalbuf(struct vnode *, int, struct ucred *, struct proc *, + int, uint64_t); +void vntblinit(void); +int vwaitforio(struct vnode *, int, char *, uint64_t); +void vwakeup(struct vnode *); +void vput(struct vnode *); +int vrecycle(struct vnode *, struct proc *); +int vrele(struct vnode *); +void vref(struct vnode *); +void vprint(char *, struct vnode *); +void copy_statfs_info(struct statfs *, const struct mount *); + +/* vfs_getcwd.c */ +#define GETCWD_CHECK_ACCESS 0x0001 +int vfs_getcwd_scandir(struct vnode **, struct vnode **, char **, char *, + struct proc *); +int vfs_getcwd_common(struct vnode *, struct vnode *, char **, char *, int, + int, struct proc *); +int vfs_getcwd_getcache(struct vnode **, struct vnode **, char **, char *); + +/* vfs_default.c */ +int vop_generic_abortop(void *); +int vop_generic_bmap(void *); +int vop_generic_bwrite(void *); +int vop_generic_islocked(void *); +int vop_generic_lock(void *); +int vop_generic_unlock(void *); +int vop_generic_revoke(void *); +int vop_generic_kqfilter(void *); +int vop_generic_lookup(void *); + +/* vfs_vnops.c */ +int vn_isunder(struct vnode *, struct vnode *, struct proc *); +int vn_close(struct vnode *, int, struct ucred *, struct proc *); +int vn_open(struct nameidata *, int, int); +int vn_rdwr(enum uio_rw, struct vnode *, caddr_t, int, off_t, + enum uio_seg, int, struct ucred *, size_t *, struct proc *); +int vn_stat(struct vnode *, struct stat *, struct proc *); +int vn_statfile(struct file *, struct stat *, struct proc *); +int vn_lock(struct vnode *, int); +int vn_writechk(struct vnode *); +int vn_fsizechk(struct vnode *, struct uio *, int, ssize_t *); +int vn_ioctl(struct file *, u_long, caddr_t, struct proc *); +void vn_marktext(struct vnode *); + +/* vfs_sync.c */ +void syncer_thread(void *); +void vn_initialize_syncerd(void); +void vn_syncer_add_to_worklist(struct vnode *, int); + +/* misc */ +int vn_isdisk(struct vnode *, int *); +int softdep_fsync(struct vnode *); +int getvnode(struct proc *, int, struct file **); + +/* uvm */ +void uvm_vnp_setsize(struct vnode *, off_t); +void uvm_vnp_sync(struct mount *); +void uvm_vnp_terminate(struct vnode *); +int uvm_vnp_uncache(struct vnode *); + + +#endif /* _KERNEL */ +#endif /* _SYS_VNODE_H_ */ diff --git a/sys/sys/wait.h b/sys/sys/wait.h new file mode 100644 index 0000000..0e85f40 --- /dev/null +++ b/sys/sys/wait.h @@ -0,0 +1,103 @@ +/* $OpenBSD: wait.h,v 1.17 2014/06/13 22:40:31 matthew Exp $ */ +/* $NetBSD: wait.h,v 1.11 1996/04/09 20:55:51 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 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. + * + * @(#)wait.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_WAIT_H_ +#define _SYS_WAIT_H_ + +#include <sys/cdefs.h> + +/* + * This file holds definitions relevent to the wait4 system call + * and the alternate interfaces that use it (wait, wait3, waitpid). + */ + +/* + * Macros to test the exit status returned by wait + * and extract the relevant values. + */ +#define _WSTATUS(x) ((x) & 0177) +#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ +#define _WCONTINUED 0177777 /* process has continued */ +#define WIFSTOPPED(x) (((x) & 0xff) == _WSTOPPED) +#define WSTOPSIG(x) (int)(((unsigned)(x) >> 8) & 0xff) +#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) +#define WTERMSIG(x) (_WSTATUS(x)) +#define WIFEXITED(x) (_WSTATUS(x) == 0) +#define WEXITSTATUS(x) (int)(((unsigned)(x) >> 8) & 0xff) +#define WIFCONTINUED(x) (((x) & _WCONTINUED) == _WCONTINUED) +#if __XPG_VISIBLE +#define WCOREFLAG 0200 +#define WCOREDUMP(x) ((x) & WCOREFLAG) + +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) +#endif + +/* + * Option bits for the third argument of wait4. WNOHANG causes the + * wait to not hang if there are no stopped or terminated processes, rather + * returning an error indication in this case (pid==0). WUNTRACED + * indicates that the caller should receive status about untraced children + * which stop due to signals. If children are stopped and a wait without + * this option is done, it is as though they were still running... nothing + * about them is returned. + */ +#define WNOHANG 1 /* don't hang in wait */ +#define WUNTRACED 2 /* tell about stopped, untraced children */ +#define WCONTINUED 8 /* report a job control continued process */ + +#if __BSD_VISIBLE +/* + * Tokens for special values of the "pid" parameter to wait4. + */ +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL +#include <sys/types.h> + +__BEGIN_DECLS +struct rusage; /* forward declaration */ + +pid_t wait(int *); +pid_t waitpid(pid_t, int *, int); +#if __BSD_VISIBLE +pid_t wait3(int *, int, struct rusage *); +pid_t wait4(pid_t, int *, int, struct rusage *); +#endif /* __BSD_VISIBLE */ +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_WAIT_H_ */ diff --git a/sys/sys/witness.h b/sys/sys/witness.h new file mode 100644 index 0000000..c7d318b --- /dev/null +++ b/sys/sys/witness.h @@ -0,0 +1,156 @@ +/* $OpenBSD: witness.h,v 1.5 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. + * + * from BSDI Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp + * $FreeBSD: head/sys/sys/lock.h 313908 2017-02-18 01:52:10Z mjg $ + */ + +#ifndef _SYS_WITNESS_H_ +#define _SYS_WITNESS_H_ + +#include <sys/_lock.h> + +/* + * Lock classes are statically assigned an index into the global lock_classes + * array. Debugging code looks up the lock class for a given lock object + * by indexing the array. + */ +#define LO_CLASSINDEX(lock) \ + ((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT) +#define LOCK_CLASS(lock) \ + (lock_classes[LO_CLASSINDEX((lock))]) +#define LOCK_CLASS_MAX \ + (LO_CLASSMASK >> LO_CLASSSHIFT) + +/* + * Option flags passed to lock operations that witness also needs to know + * about or that are generic across all locks. + */ +#define LOP_NEWORDER 0x00000001 /* Define a new lock order. */ +#define LOP_QUIET 0x00000002 /* Don't log locking operations. */ +#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */ +#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */ +#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */ + +/* Flags passed to witness_assert. */ +#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */ +#define LA_UNLOCKED 0x00000000 /* Lock is unlocked. */ +#define LA_LOCKED 0x00000001 /* Lock is at least share locked. */ +#define LA_SLOCKED 0x00000002 /* Lock is exactly share locked. */ +#define LA_XLOCKED 0x00000004 /* Lock is exclusively locked. */ +#define LA_RECURSED 0x00000008 /* Lock is recursed. */ +#define LA_NOTRECURSED 0x00000010 /* Lock is not recursed. */ + +#ifdef _KERNEL + +void witness_initialize(void); +void witness_init(struct lock_object *, const struct lock_type *); +int witness_defineorder(struct lock_object *, struct lock_object *); +void witness_checkorder(struct lock_object *, int, struct lock_object *); +void witness_lock(struct lock_object *, int); +void witness_upgrade(struct lock_object *, int); +void witness_downgrade(struct lock_object *, int); +void witness_unlock(struct lock_object *, int); +int witness_warn(int, struct lock_object *, const char *, ...); +void witness_assert(const struct lock_object *, int); +void witness_display_spinlock(struct lock_object *, struct proc *, + int (*)(const char *, ...)); +int witness_line(struct lock_object *); +void witness_norelease(struct lock_object *); +void witness_releaseok(struct lock_object *); +const char *witness_file(struct lock_object *); +void witness_thread_exit(struct proc *); +int witness_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int witness_sysctl_watch(void *, size_t *, void *, size_t); + +#ifdef WITNESS + +/* Flags for witness_warn(). */ +#define WARN_KERNELOK 0x01 /* Kernel lock is exempt from this check. */ +#define WARN_PANIC 0x02 /* Panic if check fails. */ +#define WARN_SLEEPOK 0x04 /* Sleepable locks are exempt from check. */ + +#define WITNESS_INITIALIZE() \ + witness_initialize() + +#define WITNESS_INIT(lock, type) \ + witness_init((lock), (type)) + +#define WITNESS_CHECKORDER(lock, flags, interlock) \ + witness_checkorder((lock), (flags), (interlock)) + +#define WITNESS_DEFINEORDER(lock1, lock2) \ + witness_defineorder((struct lock_object *)(lock1), \ + (struct lock_object *)(lock2)) + +#define WITNESS_LOCK(lock, flags) \ + witness_lock((lock), (flags)) + +#define WITNESS_UPGRADE(lock, flags) \ + witness_upgrade((lock), (flags)) + +#define WITNESS_DOWNGRADE(lock, flags) \ + witness_downgrade((lock), (flags)) + +#define WITNESS_UNLOCK(lock, flags) \ + witness_unlock((lock), (flags)) + +#define WITNESS_CHECK(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_WARN(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_NORELEASE(lock) \ + witness_norelease(&(lock)->lock_object) + +#define WITNESS_RELEASEOK(lock) \ + witness_releaseok(&(lock)->lock_object) + +#define WITNESS_THREAD_EXIT(p) \ + witness_thread_exit((p)) + +#else /* WITNESS */ +#define WITNESS_INITIALIZE() (void)0 +#define WITNESS_INIT(lock, type) (void)0 +#define WITNESS_DEFINEORDER(lock1, lock2) 0 +#define WITNESS_CHECKORDER(lock, flagsi, interlock) (void)0 +#define WITNESS_LOCK(lock, flags) (void)0 +#define WITNESS_UPGRADE(lock, flags) (void)0 +#define WITNESS_DOWNGRADE(lock, flags) (void)0 +#define WITNESS_UNLOCK(lock, flags) (void)0 +#define WITNESS_CHECK(flags, lock, fmt, ...) 0 +#define WITNESS_WARN(flags, lock, fmt, ...) (void)0 +#define WITNESS_NORELEASE(lock) (void)0 +#define WITNESS_RELEASEOK(lock) (void)0 +#define WITNESS_THREAD_EXIT(p) (void)0 +#endif /* WITNESS */ + +#endif /* _KERNEL */ +#endif /* _SYS_WITNESS_H_ */ |