summaryrefslogtreecommitdiff
path: root/usr/src/compat/freebsd/sys
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/compat/freebsd/sys')
-rw-r--r--usr/src/compat/freebsd/sys/_cpuset.h33
-rw-r--r--usr/src/compat/freebsd/sys/_iovec.h24
-rw-r--r--usr/src/compat/freebsd/sys/_pthreadtypes.h19
-rw-r--r--usr/src/compat/freebsd/sys/_types.h22
-rw-r--r--usr/src/compat/freebsd/sys/bus.h21
-rw-r--r--usr/src/compat/freebsd/sys/callout.h74
-rw-r--r--usr/src/compat/freebsd/sys/cdefs.h101
-rw-r--r--usr/src/compat/freebsd/sys/clock.h110
-rw-r--r--usr/src/compat/freebsd/sys/cpuset.h134
-rw-r--r--usr/src/compat/freebsd/sys/disk.h19
-rw-r--r--usr/src/compat/freebsd/sys/endian.h136
-rw-r--r--usr/src/compat/freebsd/sys/errno.h27
-rw-r--r--usr/src/compat/freebsd/sys/eventhandler.h19
-rw-r--r--usr/src/compat/freebsd/sys/fcntl.h23
-rw-r--r--usr/src/compat/freebsd/sys/ioctl.h24
-rw-r--r--usr/src/compat/freebsd/sys/kernel.h42
-rw-r--r--usr/src/compat/freebsd/sys/ktr.h27
-rw-r--r--usr/src/compat/freebsd/sys/libkern.h25
-rw-r--r--usr/src/compat/freebsd/sys/limits.h24
-rw-r--r--usr/src/compat/freebsd/sys/lock.h23
-rw-r--r--usr/src/compat/freebsd/sys/malloc.h49
-rw-r--r--usr/src/compat/freebsd/sys/module.h19
-rw-r--r--usr/src/compat/freebsd/sys/mutex.h78
-rw-r--r--usr/src/compat/freebsd/sys/param.h57
-rw-r--r--usr/src/compat/freebsd/sys/pcpu.h21
-rw-r--r--usr/src/compat/freebsd/sys/sched.h19
-rw-r--r--usr/src/compat/freebsd/sys/sdt.h37
-rw-r--r--usr/src/compat/freebsd/sys/select.h23
-rw-r--r--usr/src/compat/freebsd/sys/sglist.h29
-rw-r--r--usr/src/compat/freebsd/sys/smp.h26
-rw-r--r--usr/src/compat/freebsd/sys/socket.h23
-rw-r--r--usr/src/compat/freebsd/sys/sysctl.h27
-rw-r--r--usr/src/compat/freebsd/sys/systm.h44
-rw-r--r--usr/src/compat/freebsd/sys/time.h124
-rw-r--r--usr/src/compat/freebsd/sys/types.h85
-rw-r--r--usr/src/compat/freebsd/sys/uio.h26
36 files changed, 1614 insertions, 0 deletions
diff --git a/usr/src/compat/freebsd/sys/_cpuset.h b/usr/src/compat/freebsd/sys/_cpuset.h
new file mode 100644
index 0000000000..286d26fc00
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/_cpuset.h
@@ -0,0 +1,33 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS__CPUSET_H_
+#define _COMPAT_FREEBSD_SYS__CPUSET_H_
+
+#ifdef _KERNEL
+/*
+ * The sys/_cpuset.h header is used to communicate the layout of cpuset_t while
+ * sys/cpuset.h contains the manipulation routines.
+ *
+ * The explicit guard definition below is necessary as other contrib headers
+ * change their behavior based on its presence.
+ */
+#define _SYS__CPUSET_H_
+
+#include <sys/cpuvar.h>
+
+#endif /* _KERNEL */
+
+#endif /* _COMPAT_FREEBSD_SYS__CPUSET_H_ */
diff --git a/usr/src/compat/freebsd/sys/_iovec.h b/usr/src/compat/freebsd/sys/_iovec.h
new file mode 100644
index 0000000000..b755ae7e21
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/_iovec.h
@@ -0,0 +1,24 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2015 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS__IOVEC_H_
+#define _COMPAT_FREEBSD_SYS__IOVEC_H_
+
+struct iovec {
+ void *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
+};
+
+#endif /* _COMPAT_FREEBSD_SYS__IOVEC_H_ */
diff --git a/usr/src/compat/freebsd/sys/_pthreadtypes.h b/usr/src/compat/freebsd/sys/_pthreadtypes.h
new file mode 100644
index 0000000000..d746da3712
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/_pthreadtypes.h
@@ -0,0 +1,19 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_
+#define _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_
+
+#endif /* _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_ */
diff --git a/usr/src/compat/freebsd/sys/_types.h b/usr/src/compat/freebsd/sys/_types.h
new file mode 100644
index 0000000000..62c327d216
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/_types.h
@@ -0,0 +1,22 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS__TYPES_H_
+#define _COMPAT_FREEBSD_SYS__TYPES_H_
+
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+#endif /* _COMPAT_FREEBSD_SYS__TYPES_H_ */
diff --git a/usr/src/compat/freebsd/sys/bus.h b/usr/src/compat/freebsd/sys/bus.h
new file mode 100644
index 0000000000..e3b5e0e69d
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/bus.h
@@ -0,0 +1,21 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_BUS_H
+#define _COMPAT_FREEBSD_SYS_BUS_H
+
+#define device_get_softc(dev) ddi_get_driver_private(dev)
+
+#endif /* _COMPAT_FREEBSD_SYS_BUS_H */
diff --git a/usr/src/compat/freebsd/sys/callout.h b/usr/src/compat/freebsd/sys/callout.h
new file mode 100644
index 0000000000..6087a09f54
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/callout.h
@@ -0,0 +1,74 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_CALLOUT_H_
+#define _COMPAT_FREEBSD_SYS_CALLOUT_H_
+
+#include <sys/cyclic.h>
+
+struct callout {
+ cyclic_id_t c_cyc_id;
+ int c_flags;
+ void (*c_func)(void *);
+ void *c_arg;
+
+};
+
+#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */
+#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
+
+#define C_ABSOLUTE 0x0200 /* event time is absolute. */
+
+#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE)
+#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE)
+#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
+
+void vmm_glue_callout_init(struct callout *c, int mpsafe);
+int vmm_glue_callout_reset_sbt(struct callout *c, sbintime_t sbt,
+ sbintime_t pr, void (*func)(void *), void *arg, int flags);
+int vmm_glue_callout_stop(struct callout *c);
+int vmm_glue_callout_drain(struct callout *c);
+
+/* illumos-custom function for resource locality optimization */
+void vmm_glue_callout_localize(struct callout *c);
+
+static __inline void
+callout_init(struct callout *c, int mpsafe)
+{
+ vmm_glue_callout_init(c, mpsafe);
+}
+
+static __inline int
+callout_stop(struct callout *c)
+{
+ return (vmm_glue_callout_stop(c));
+}
+
+static __inline int
+callout_drain(struct callout *c)
+{
+ return (vmm_glue_callout_drain(c));
+}
+
+static __inline int
+callout_reset_sbt(struct callout *c, sbintime_t sbt, sbintime_t pr,
+ void (*func)(void *), void *arg, int flags)
+{
+ return (vmm_glue_callout_reset_sbt(c, sbt, pr, func, arg, flags));
+}
+
+
+#endif /* _COMPAT_FREEBSD_SYS_CALLOUT_H_ */
diff --git a/usr/src/compat/freebsd/sys/cdefs.h b/usr/src/compat/freebsd/sys/cdefs.h
new file mode 100644
index 0000000000..1713b05630
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/cdefs.h
@@ -0,0 +1,101 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_
+#define _COMPAT_FREEBSD_SYS_CDEFS_H_
+
+/*
+ * Testing against Clang-specific extensions.
+ */
+#ifndef __has_extension
+#define __has_extension __has_feature
+#endif
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+/*
+ * Macro to test if we're using a specific version of gcc or later.
+ */
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+#define __GNUC_PREREQ__(ma, mi) \
+ (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
+#else
+#define __GNUC_PREREQ__(ma, mi) 0
+#endif
+
+#define __FBSDID(s)
+
+#ifdef __GNUC__
+#define asm __asm
+#define inline __inline
+
+#define __GNUCLIKE___SECTION 1
+
+#define __dead2 __attribute__((__noreturn__))
+#define __used __attribute__((__used__))
+#define __packed __attribute__((__packed__))
+#define __aligned(x) __attribute__((__aligned__(x)))
+#define __section(x) __attribute__((__section__(x)))
+#define __weak_symbol __attribute__((__weak__))
+#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 to use if it must work in non-ANSI
+ * mode -- there must be no spaces between its arguments, and for nested
+ * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also
+ * concatenate double-quoted strings produced by the __STRING macro, but
+ * this only works with ANSI C.
+ *
+ * __XSTRING is like __STRING, but it expands any macros in its argument
+ * first. It is only available with ANSI C.
+ */
+#if defined(__STDC__) || defined(__cplusplus)
+#define __P(protos) protos /* full-blown ANSI C */
+#define __CONCAT1(x,y) x ## y
+#define __CONCAT(x,y) __CONCAT1(x,y)
+#define __STRING(x) #x /* stringify without expanding x */
+#define __XSTRING(x) __STRING(x) /* expand x, then stringify */
+#else /* !(__STDC__ || __cplusplus) */
+#define __P(protos) () /* traditional C preprocessor */
+#define __CONCAT(x,y) x/**/y
+#define __STRING(x) "x"
+#endif /* !(__STDC__ || __cplusplus) */
+
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
+
+#if !__has_extension(c_static_assert)
+#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
+ __has_extension(cxx_static_assert)
+#define _Static_assert(x, y) static_assert(x, y)
+#elif __GNUC_PREREQ__(4,6)
+/* Nothing, gcc 4.6 and higher has _Static_assert built-in */
+#elif defined(__COUNTER__)
+#define _Static_assert(x, y) __Static_assert(x, __COUNTER__)
+#define __Static_assert(x, y) ___Static_assert(x, y)
+#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \
+ __unused
+#else
+#define _Static_assert(x, y) struct __hack
+#endif
+#endif
+#define static_assert(x, y) _Static_assert(x, y)
+
+#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
+
+#endif /* _COMPAT_FREEBSD_SYS_CDEFS_H_ */
diff --git a/usr/src/compat/freebsd/sys/clock.h b/usr/src/compat/freebsd/sys/clock.h
new file mode 100644
index 0000000000..ebf7f171a3
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/clock.h
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Gordon W. Ross
+ *
+ * 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.
+ *
+ * $NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $
+ *
+ *
+ * This file is the central clearing-house for calendrical issues.
+ *
+ * In general the kernel does not know about minutes, hours, days, timezones,
+ * daylight savings time, leap-years and such. All that is theoretically a
+ * matter for userland only.
+ *
+ * Parts of kernel code does however care: badly designed filesystems store
+ * timestamps in local time and RTC chips sometimes track time in a local
+ * timezone instead of UTC and so on.
+ *
+ * All that code should go here for service.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_CLOCK_H_
+#define _COMPAT_FREEBSD_SYS_CLOCK_H_
+
+#include_next <sys/clock.h>
+
+#ifdef _KERNEL /* No user serviceable parts */
+
+#ifdef __FreeBSD__
+/*
+ * Timezone info from settimeofday(2), usually not used
+ */
+extern int tz_minuteswest;
+extern int tz_dsttime;
+extern struct mtx resettodr_lock;
+
+int utc_offset(void);
+#endif /* __FreeBSD__ */
+
+/*
+ * Structure to hold the values typically reported by time-of-day clocks.
+ * This can be passed to the generic conversion functions to be converted
+ * to a struct timespec.
+ */
+struct clocktime {
+ int year; /* year (4 digit year) */
+ int mon; /* month (1 - 12) */
+ int day; /* day (1 - 31) */
+ int hour; /* hour (0 - 23) */
+ int min; /* minute (0 - 59) */
+ int sec; /* second (0 - 59) */
+ int dow; /* day of week (0 - 6; 0 = Sunday) */
+ long nsec; /* nano seconds */
+};
+
+int clock_ct_to_ts(struct clocktime *, struct timespec *);
+void clock_ts_to_ct(struct timespec *, struct clocktime *);
+#ifdef __FreeBSD__
+void clock_register(device_t, long);
+#endif
+
+#ifndef __FreeBSD__
+extern u_char const bin2bcd_data[];
+#define bin2bcd(x) (bin2bcd_data[bin])
+#endif
+
+/*
+ * BCD to decimal and decimal to BCD.
+ */
+#define FROMBCD(x) bcd2bin(x)
+#define TOBCD(x) bin2bcd(x)
+
+/* Some handy constants. */
+#define SECDAY (24 * 60 * 60)
+#define SECYR (SECDAY * 365)
+
+/* Traditional POSIX base year */
+#define POSIX_BASE_YEAR 1970
+
+void timespec2fattime(struct timespec *tsp, int utc, u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp);
+void fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, struct timespec *tsp);
+
+#endif /* _KERNEL */
+
+#endif /* _COMPAT_FREEBSD_SYS_CLOCK_H_ */
diff --git a/usr/src/compat/freebsd/sys/cpuset.h b/usr/src/compat/freebsd/sys/cpuset.h
new file mode 100644
index 0000000000..626b323d7d
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/cpuset.h
@@ -0,0 +1,134 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2019 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_CPUSET_H_
+#define _COMPAT_FREEBSD_SYS_CPUSET_H_
+
+#define NOCPU -1
+
+#ifdef _KERNEL
+
+#include <sys/_cpuset.h>
+
+#define CPU_SET(cpu, set) cpuset_add((set), (cpu))
+#define CPU_SETOF(cpu, set) cpuset_only((set), (cpu))
+#define CPU_ZERO(set) cpuset_zero((cpuset_t *)(set))
+#define CPU_CLR(cpu, set) cpuset_del((set), (cpu))
+#define CPU_EMPTY(set) cpuset_isnull((set))
+#define CPU_FFS(set) cpusetobj_ffs(set)
+#define CPU_ISSET(cpu, set) cpu_in_set((cpuset_t *)(set), (cpu))
+#define CPU_AND(dst, src) cpuset_and( \
+ (cpuset_t *)(dst), \
+ (cpuset_t *)(src))
+#define CPU_OR(dst, src) cpuset_or( \
+ (cpuset_t *)(dst), \
+ (cpuset_t *)(src))
+#define CPU_CMP(set1, set2) (cpuset_isequal( \
+ (cpuset_t *)(set1), \
+ (cpuset_t *)(set2)) == 0)
+#define CPU_SET_ATOMIC(cpu, set) cpuset_atomic_add( \
+ (cpuset_t *)(set), \
+ (cpu))
+#define CPU_CLR_ATOMIC(cpu, set) cpuset_atomic_del( \
+ (cpuset_t *)(set), \
+ (cpu))
+
+#define CPU_SET_ATOMIC_ACQ(cpu, set) cpuset_atomic_add((set), (cpu))
+
+
+int cpusetobj_ffs(const cpuset_t *set);
+
+#else
+
+#include <sys/bitmap.h>
+#include <machine/atomic.h>
+#include <machine/cpufunc.h>
+
+/* For now, assume NCPU of 256 */
+#define CPU_SETSIZE (256)
+
+typedef struct {
+ ulong_t _bits[BT_BITOUL(CPU_SETSIZE)];
+} cpuset_t;
+
+static __inline int
+cpuset_isempty(const cpuset_t *set)
+{
+ uint_t i;
+
+ for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) {
+ if (set->_bits[i] != 0)
+ return (0);
+ }
+ return (1);
+}
+
+static __inline void
+cpuset_zero(cpuset_t *dst)
+{
+ uint_t i;
+
+ for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) {
+ dst->_bits[i] = 0;
+ }
+}
+
+static __inline int
+cpuset_isequal(cpuset_t *s1, cpuset_t *s2)
+{
+ uint_t i;
+
+ for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) {
+ if (s1->_bits[i] != s2->_bits[i])
+ return (0);
+ }
+ return (1);
+}
+
+static __inline uint_t
+cpusetobj_ffs(const cpuset_t *set)
+{
+ uint_t i, cbit;
+
+ cbit = 0;
+ for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) {
+ if (set->_bits[i] != 0) {
+ cbit = ffsl(set->_bits[i]);
+ cbit += i * sizeof (set->_bits[0]);
+ break;
+ }
+ }
+ return (cbit);
+}
+
+
+#define CPU_SET(cpu, setp) BT_SET((setp)->_bits, cpu)
+#define CPU_CLR(cpu, setp) BT_CLEAR((setp)->_bits, cpu)
+#define CPU_ZERO(setp) cpuset_zero((setp))
+#define CPU_CMP(set1, set2) (cpuset_isequal( \
+ (cpuset_t *)(set1), \
+ (cpuset_t *)(set2)) == 0)
+#define CPU_FFS(set) cpusetobj_ffs(set)
+#define CPU_ISSET(cpu, setp) BT_TEST((setp)->_bits, cpu)
+#define CPU_EMPTY(setp) cpuset_isempty((setp))
+#define CPU_SET_ATOMIC(cpu, setp) \
+ atomic_set_long(&(BT_WIM((setp)->_bits, cpu)), BT_BIW(cpu))
+#define CPU_CLR_ATOMIC(cpu, setp) \
+ atomic_clear_long(&(BT_WIM((setp)->_bits, cpu)), BT_BIW(cpu))
+
+#endif
+
+#endif /* _COMPAT_FREEBSD_SYS_CPUSET_H_ */
diff --git a/usr/src/compat/freebsd/sys/disk.h b/usr/src/compat/freebsd/sys/disk.h
new file mode 100644
index 0000000000..c9bdc6a2d8
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/disk.h
@@ -0,0 +1,19 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_DISK_H_
+#define _COMPAT_FREEBSD_SYS_DISK_H_
+
+#endif /* _COMPAT_FREEBSD_SYS_DISK_H_ */
diff --git a/usr/src/compat/freebsd/sys/endian.h b/usr/src/compat/freebsd/sys/endian.h
new file mode 100644
index 0000000000..24ea02d251
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/endian.h
@@ -0,0 +1,136 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_ENDIAN_H_
+#define _COMPAT_FREEBSD_SYS_ENDIAN_H_
+
+static __inline uint16_t
+be16dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return ((p[0] << 8) | p[1]);
+}
+
+static __inline uint32_t
+be32dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static __inline uint64_t
+be64dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+
+static __inline uint16_t
+le16dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return ((p[1] << 8) | p[0]);
+}
+
+static __inline uint32_t
+le32dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+
+static __inline uint64_t
+le64dec(const void *pp)
+{
+ uint8_t const *p = (uint8_t const *)pp;
+
+ return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
+}
+
+static __inline void
+be16enc(void *pp, uint16_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ p[0] = (u >> 8) & 0xff;
+ p[1] = u & 0xff;
+}
+
+static __inline void
+be32enc(void *pp, uint32_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ p[0] = (u >> 24) & 0xff;
+ p[1] = (u >> 16) & 0xff;
+ p[2] = (u >> 8) & 0xff;
+ p[3] = u & 0xff;
+}
+
+static __inline void
+be64enc(void *pp, uint64_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ be32enc(p, (uint32_t)(u >> 32));
+ be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
+}
+
+static __inline void
+le16enc(void *pp, uint16_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ p[0] = u & 0xff;
+ p[1] = (u >> 8) & 0xff;
+}
+
+static __inline void
+le32enc(void *pp, uint32_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ p[0] = u & 0xff;
+ p[1] = (u >> 8) & 0xff;
+ p[2] = (u >> 16) & 0xff;
+ p[3] = (u >> 24) & 0xff;
+}
+
+static __inline void
+le64enc(void *pp, uint64_t u)
+{
+ uint8_t *p = (uint8_t *)pp;
+
+ le32enc(p, (uint32_t)(u & 0xffffffffU));
+ le32enc(p + 4, (uint32_t)(u >> 32));
+}
+
+#ifdef _LITTLE_ENDIAN
+#define htole16(x) ((uint16_t)(x))
+#define htole32(x) ((uint32_t)(x))
+#define htole64(x) ((uint64_t)(x))
+
+#define le16toh(x) ((uint16_t)(x))
+#define le32toh(x) ((uint32_t)(x))
+#define le64toh(x) ((uint64_t)(x))
+#endif
+
+#endif /* _COMPAT_FREEBSD_SYS_ENDIAN_H_ */
diff --git a/usr/src/compat/freebsd/sys/errno.h b/usr/src/compat/freebsd/sys/errno.h
new file mode 100644
index 0000000000..bd37f43065
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/errno.h
@@ -0,0 +1,27 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_ERRNO_H_
+#define _COMPAT_FREEBSD_SYS_ERRNO_H_
+
+#ifndef _KERNEL
+extern int *___errno();
+
+#define errno (*(___errno()))
+#endif
+
+#include_next <sys/errno.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_ERRNO_H_ */
diff --git a/usr/src/compat/freebsd/sys/eventhandler.h b/usr/src/compat/freebsd/sys/eventhandler.h
new file mode 100644
index 0000000000..133aa664f0
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/eventhandler.h
@@ -0,0 +1,19 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_
+#define _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_
+
+#endif /* _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_ */
diff --git a/usr/src/compat/freebsd/sys/fcntl.h b/usr/src/compat/freebsd/sys/fcntl.h
new file mode 100644
index 0000000000..062a3b84ac
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/fcntl.h
@@ -0,0 +1,23 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_FCNTL_H_
+#define _COMPAT_FREEBSD_SYS_FCNTL_H_
+
+#define O_DIRECT 0x0
+
+#include_next <sys/fcntl.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_FCNTL_H_ */
diff --git a/usr/src/compat/freebsd/sys/ioctl.h b/usr/src/compat/freebsd/sys/ioctl.h
new file mode 100644
index 0000000000..72a46b8085
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/ioctl.h
@@ -0,0 +1,24 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_IOCTL_H_
+#define _COMPAT_FREEBSD_SYS_IOCTL_H_
+
+#include <sys/ioccom.h>
+/* Get BSD compatibility from the ioctl header */
+#define BSD_COMP
+#include_next <sys/ioctl.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_IOCTL_H_ */
diff --git a/usr/src/compat/freebsd/sys/kernel.h b/usr/src/compat/freebsd/sys/kernel.h
new file mode 100644
index 0000000000..adf96f40fc
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/kernel.h
@@ -0,0 +1,42 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_KERNEL_H_
+#define _COMPAT_FREEBSD_SYS_KERNEL_H_
+
+#define TUNABLE_INT_FETCH(path, var)
+
+#include <sys/linker_set.h>
+
+typedef void (*sysinit_func_t)(const void *);
+
+struct sysinit {
+ const sysinit_func_t func;
+ const void *data;
+};
+
+#define SYSINIT(uniquifier, subsystem, order, func, ident) \
+ static struct sysinit uniquifier ## _sys_init = { \
+ (const sysinit_func_t)func, \
+ (const void *)&(ident) \
+ }; \
+ DATA_SET(sysinit_set, uniquifier ## _sys_init);
+
+extern void sysinit(void);
+
+#define ticks ddi_get_lbolt()
+
+#endif /* _COMPAT_FREEBSD_SYS_KERNEL_H_ */
diff --git a/usr/src/compat/freebsd/sys/ktr.h b/usr/src/compat/freebsd/sys/ktr.h
new file mode 100644
index 0000000000..96c499ef18
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/ktr.h
@@ -0,0 +1,27 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_KTR_H_
+#define _COMPAT_FREEBSD_SYS_KTR_H_
+
+#define CTR0(m, format)
+#define CTR1(m, format, p1)
+#define CTR2(m, format, p1, p2)
+#define CTR3(m, format, p1, p2, p3)
+#define CTR4(m, format, p1, p2, p3, p4)
+#define CTR5(m, format, p1, p2, p3, p4, p5)
+#define CTR6(m, d, p1, p2, p3, p4, p5, p6)
+
+#endif /* _COMPAT_FREEBSD_SYS_KTR_H_ */
diff --git a/usr/src/compat/freebsd/sys/libkern.h b/usr/src/compat/freebsd/sys/libkern.h
new file mode 100644
index 0000000000..94675a0d66
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/libkern.h
@@ -0,0 +1,25 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_LIBKERN_H_
+#define _COMPAT_FREEBSD_SYS_LIBKERN_H_
+
+#include <sys/systm.h>
+
+#ifndef min
+static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
+#endif
+
+#endif /* _COMPAT_FREEBSD_SYS_LIBKERN_H_ */
diff --git a/usr/src/compat/freebsd/sys/limits.h b/usr/src/compat/freebsd/sys/limits.h
new file mode 100644
index 0000000000..0e66319791
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/limits.h
@@ -0,0 +1,24 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_LIMITS_H_
+#define _COMPAT_FREEBSD_SYS_LIMITS_H_
+
+#include_next <limits.h>
+
+#define OFF_MAX ((off_t)-1)
+
+#endif /* _COMPAT_FREEBSD_SYS_LIMITS_H_ */
diff --git a/usr/src/compat/freebsd/sys/lock.h b/usr/src/compat/freebsd/sys/lock.h
new file mode 100644
index 0000000000..fd6021a87e
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/lock.h
@@ -0,0 +1,23 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_LOCK_H_
+#define _COMPAT_FREEBSD_SYS_LOCK_H_
+
+#include_next <sys/lock.h>
+
+#define WITNESS_WARN(...)
+
+#endif /* _COMPAT_FREEBSD_SYS_LOCK_H_ */
diff --git a/usr/src/compat/freebsd/sys/malloc.h b/usr/src/compat/freebsd/sys/malloc.h
new file mode 100644
index 0000000000..341d57b807
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/malloc.h
@@ -0,0 +1,49 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_MALLOC_H_
+#define _COMPAT_FREEBSD_SYS_MALLOC_H_
+
+/*
+ * flags to malloc.
+ */
+#define M_NOWAIT 0x0001 /* do not block */
+#define M_WAITOK 0x0002 /* ok to block */
+#define M_ZERO 0x0100 /* bzero the allocation */
+
+struct malloc_type {
+ const char *ks_shortdesc; /* Printable type name. */
+};
+
+#ifdef _KERNEL
+#define MALLOC_DEFINE(type, shortdesc, longdesc) \
+ struct malloc_type type[1] = { \
+ { shortdesc } \
+ }
+
+#define MALLOC_DECLARE(type) \
+ extern struct malloc_type type[1]
+
+void free(void *addr, struct malloc_type *type);
+void *malloc(unsigned long size, struct malloc_type *type, int flags);
+void *old_malloc(unsigned long size, struct malloc_type *type , int flags);
+void *contigmalloc(unsigned long, struct malloc_type *, int, vm_paddr_t,
+ vm_paddr_t, unsigned long, vm_paddr_t);
+void contigfree(void *, unsigned long, struct malloc_type *);
+
+
+#endif /* _KERNEL */
+
+#endif /* _COMPAT_FREEBSD_SYS_MALLOC_H_ */
diff --git a/usr/src/compat/freebsd/sys/module.h b/usr/src/compat/freebsd/sys/module.h
new file mode 100644
index 0000000000..87b73e3fa3
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/module.h
@@ -0,0 +1,19 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_MODULE_H_
+#define _COMPAT_FREEBSD_SYS_MODULE_H_
+
+#endif /* _COMPAT_FREEBSD_SYS_MODULE_H_ */
diff --git a/usr/src/compat/freebsd/sys/mutex.h b/usr/src/compat/freebsd/sys/mutex.h
new file mode 100644
index 0000000000..9e588cb98a
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/mutex.h
@@ -0,0 +1,78 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_MUTEX_H_
+#define _COMPAT_FREEBSD_SYS_MUTEX_H_
+
+#ifdef _KERNEL
+
+#include <sys/debug.h>
+
+#define MTX_DEF 0x00000000
+#define MTX_SPIN 0x00000001
+
+struct mtx;
+
+void mtx_init(struct mtx *, char *name, const char *type_name, int opts);
+void mtx_destroy(struct mtx *);
+
+#endif /* KERNEL */
+#include_next <sys/mutex.h>
+#ifdef _KERNEL
+
+struct mtx {
+ kmutex_t m;
+};
+
+static __inline void mtx_lock(struct mtx *mtx)
+{
+ mutex_enter(&mtx->m);
+}
+
+static __inline void mtx_unlock(struct mtx *mtx)
+{
+ mutex_exit(&mtx->m);
+}
+
+static __inline void mtx_lock_spin(struct mtx *mtx)
+{
+ mutex_enter(&mtx->m);
+}
+
+static __inline void mtx_unlock_spin(struct mtx *mtx)
+{
+ mutex_exit(&mtx->m);
+}
+
+static __inline int mtx_owned(struct mtx *mtx)
+{
+ return (mutex_owned(&mtx->m));
+}
+
+#define MA_OWNED 0
+
+static __inline void mtx_assert(struct mtx *mtx, int what)
+{
+ switch (what) {
+ case MA_OWNED:
+ ASSERT(mutex_owned(&mtx->m));
+ break;
+ }
+}
+
+#endif /* _KERNEL */
+
+#endif /* _COMPAT_FREEBSD_SYS_MUTEX_H_ */
diff --git a/usr/src/compat/freebsd/sys/param.h b/usr/src/compat/freebsd/sys/param.h
new file mode 100644
index 0000000000..b125f9014f
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/param.h
@@ -0,0 +1,57 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_PARAM_H_
+#define _COMPAT_FREEBSD_SYS_PARAM_H_
+
+#ifndef _KERNEL
+#define MAXCOMLEN 16
+/* default value of the kernel tunable 'maxphys' in i86pc */
+#define MAXPHYS (56 * 1024)
+#endif
+#define MAXHOSTNAMELEN 256
+#define SPECNAMELEN 63
+
+#ifdef _KERNEL
+#include <sys/time.h>
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE 1
+#endif
+#endif
+
+#include <machine/param.h>
+
+#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
+#define rounddown(x,y) (((x)/(y))*(y))
+#define rounddown2(x, y) ((x)&(~((y)-1))) /* if y is power of two */
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
+#define roundup2(x,y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
+#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))
+
+#define trunc_page(x) ((unsigned long)(x) & ~(PAGE_MASK))
+#define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT)
+
+#include_next <sys/param.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_PARAM_H_ */
diff --git a/usr/src/compat/freebsd/sys/pcpu.h b/usr/src/compat/freebsd/sys/pcpu.h
new file mode 100644
index 0000000000..f29c9c5018
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/pcpu.h
@@ -0,0 +1,21 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_PCPU_H_
+#define _COMPAT_FREEBSD_SYS_PCPU_H_
+
+#define curcpu (CPU->cpu_id)
+
+#endif /* _COMPAT_FREEBSD_SYS_PCPU_H_ */
diff --git a/usr/src/compat/freebsd/sys/sched.h b/usr/src/compat/freebsd/sys/sched.h
new file mode 100644
index 0000000000..b426ee757e
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/sched.h
@@ -0,0 +1,19 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SCHED_H_
+#define _COMPAT_FREEBSD_SYS_SCHED_H_
+
+#endif /* _COMPAT_FREEBSD_SYS_SCHED_H_ */
diff --git a/usr/src/compat/freebsd/sys/sdt.h b/usr/src/compat/freebsd/sys/sdt.h
new file mode 100644
index 0000000000..32d887c0d8
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/sdt.h
@@ -0,0 +1,37 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SDT_H_
+#define _COMPAT_FREEBSD_SYS_SDT_H_
+
+/* Empty macros to cover FreeBSD's SDT linker tricks */
+
+#define SDT_PROVIDER_DECLARE(mod)
+#define SDT_PROVIDER_DEFINE(mod)
+
+#define SDT_PROBE_DEFINE1(...)
+#define SDT_PROBE_DEFINE2(...)
+#define SDT_PROBE_DEFINE3(...)
+#define SDT_PROBE_DEFINE4(...)
+#define SDT_PROBE_DEFINE5(...)
+#define SDT_PROBE1(...)
+#define SDT_PROBE2(...)
+#define SDT_PROBE3(...)
+#define SDT_PROBE4(...)
+#define SDT_PROBE5(...)
+
+#include_next <sys/sdt.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_SDT_H_ */
diff --git a/usr/src/compat/freebsd/sys/select.h b/usr/src/compat/freebsd/sys/select.h
new file mode 100644
index 0000000000..fcb40c23b1
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/select.h
@@ -0,0 +1,23 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_MODULE_H_
+#define _COMPAT_FREEBSD_SYS_MODULE_H_
+
+void *memset(void *s, int c, size_t n);
+
+#include_next <sys/select.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_MODULE_H_ */
diff --git a/usr/src/compat/freebsd/sys/sglist.h b/usr/src/compat/freebsd/sys/sglist.h
new file mode 100644
index 0000000000..519c67915f
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/sglist.h
@@ -0,0 +1,29 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SGLIST_H_
+#define _COMPAT_FREEBSD_SYS_SGLIST_H_
+
+#ifdef _KERNEL
+
+struct sglist;
+
+struct sglist *sglist_alloc(int, int);
+void sglist_free(struct sglist *);
+int sglist_append_phys(struct sglist *, vm_paddr_t, size_t);
+
+#endif /* _KERNEL */
+
+#endif /* _COMPAT_FREEBSD_SYS_SGLIST_H_ */
diff --git a/usr/src/compat/freebsd/sys/smp.h b/usr/src/compat/freebsd/sys/smp.h
new file mode 100644
index 0000000000..3d6413ce16
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/smp.h
@@ -0,0 +1,26 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SMP_H_
+#define _COMPAT_FREEBSD_SYS_SMP_H_
+
+#include <sys/cpuset.h>
+
+#define IPI_AST 0
+
+void ipi_cpu(int cpu, u_int ipi);
+
+#endif /* _COMPAT_FREEBSD_SYS_SMP_H_ */
diff --git a/usr/src/compat/freebsd/sys/socket.h b/usr/src/compat/freebsd/sys/socket.h
new file mode 100644
index 0000000000..3bf7a8f440
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/socket.h
@@ -0,0 +1,23 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SOCKET_H
+#define _COMPAT_FREEBSD_SYS_SOCKET_H
+
+#include_next <sys/socket.h>
+
+#define SO_NOSIGPIPE 0
+
+#endif /* _COMPAT_FREEBSD_SYS_SOCKET_H */
diff --git a/usr/src/compat/freebsd/sys/sysctl.h b/usr/src/compat/freebsd/sys/sysctl.h
new file mode 100644
index 0000000000..9f6a695e34
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/sysctl.h
@@ -0,0 +1,27 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SYSCTL_H_
+#define _COMPAT_FREEBSD_SYS_SYSCTL_H_
+
+#define SYSCTL_DECL(name)
+
+#define SYSCTL_NODE(parent, nbr, name, access, handler, descr)
+
+#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr)
+#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)
+#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)
+
+#endif /* _COMPAT_FREEBSD_SYS_SYSCTL_H_ */
diff --git a/usr/src/compat/freebsd/sys/systm.h b/usr/src/compat/freebsd/sys/systm.h
new file mode 100644
index 0000000000..43fa16d450
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/systm.h
@@ -0,0 +1,44 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_SYSTM_H_
+#define _COMPAT_FREEBSD_SYS_SYSTM_H_
+
+#include <machine/atomic.h>
+#include <machine/cpufunc.h>
+#include <sys/callout.h>
+#include <sys/queue.h>
+
+struct mtx;
+
+#define KASSERT(exp,msg) do { \
+ if (!(exp)) \
+ panic msg; \
+} while (0)
+
+void critical_enter(void);
+void critical_exit(void);
+
+struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
+void delete_unrhdr(struct unrhdr *uh);
+int alloc_unr(struct unrhdr *uh);
+void free_unr(struct unrhdr *uh, u_int item);
+
+#include <sys/libkern.h>
+
+#include_next <sys/systm.h>
+#include <sys/cmn_err.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_SYSTM_H_ */
diff --git a/usr/src/compat/freebsd/sys/time.h b/usr/src/compat/freebsd/sys/time.h
new file mode 100644
index 0000000000..4e0fbfc02c
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/time.h
@@ -0,0 +1,124 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_TIME_H_
+#define _COMPAT_FREEBSD_SYS_TIME_H_
+
+#include_next <sys/time.h>
+
+#define tc_precexp 0
+
+struct bintime {
+ ulong_t sec; /* seconds */
+ uint64_t frac; /* 64 bit fraction of a second */
+};
+
+#define BT2FREQ(bt) \
+ (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \
+ ((bt)->frac >> 1))
+
+#define FREQ2BT(freq, bt) \
+{ \
+ (bt)->sec = 0; \
+ (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \
+}
+
+static __inline void
+binuptime(struct bintime *bt)
+{
+ hrtime_t now = gethrtime();
+
+ bt->sec = now / 1000000000;
+ /* 18446744073 = int(2^64 / 1000000000) = 1ns in 64-bit fractions */
+ bt->frac = (now % 1000000000) * (uint64_t)18446744073LL;
+}
+
+#define bintime_cmp(a, b, cmp) \
+ (((a)->sec == (b)->sec) ? \
+ ((a)->frac cmp (b)->frac) : \
+ ((a)->sec cmp (b)->sec))
+
+#define SBT_1S ((sbintime_t)1 << 32)
+#define SBT_1M (SBT_1S * 60)
+#define SBT_1MS (SBT_1S / 1000)
+#define SBT_1US (SBT_1S / 1000000)
+#define SBT_1NS (SBT_1S / 1000000000)
+#define SBT_MAX 0x7fffffffffffffffLL
+
+
+static __inline void
+bintime_add(struct bintime *bt, const struct bintime *bt2)
+{
+ uint64_t u;
+
+ u = bt->frac;
+ bt->frac += bt2->frac;
+ if (u > bt->frac)
+ bt->sec++;
+ bt->sec += bt2->sec;
+}
+
+static __inline void
+bintime_sub(struct bintime *bt, const struct bintime *bt2)
+{
+ uint64_t u;
+
+ u = bt->frac;
+ bt->frac -= bt2->frac;
+ if (u < bt->frac)
+ bt->sec--;
+ bt->sec -= bt2->sec;
+}
+
+static __inline void
+bintime_mul(struct bintime *bt, u_int x)
+{
+ uint64_t p1, p2;
+
+ p1 = (bt->frac & 0xffffffffull) * x;
+ p2 = (bt->frac >> 32) * x + (p1 >> 32);
+ bt->sec *= x;
+ bt->sec += (p2 >> 32);
+ bt->frac = (p2 << 32) | (p1 & 0xffffffffull);
+}
+
+static __inline sbintime_t
+bttosbt(const struct bintime bt)
+{
+ return (((sbintime_t)bt.sec << 32) + (bt.frac >> 32));
+}
+
+static __inline struct bintime
+sbttobt(sbintime_t _sbt)
+{
+ struct bintime _bt;
+
+ _bt.sec = _sbt >> 32;
+ _bt.frac = _sbt << 32;
+ return (_bt);
+}
+
+static __inline sbintime_t
+sbinuptime(void)
+{
+ hrtime_t hrt = gethrtime();
+ uint64_t sec = hrt / NANOSEC;
+ uint64_t nsec = hrt % NANOSEC;
+
+ return (((sbintime_t)sec << 32) +
+ (nsec * (((uint64_t)1 << 63) / 500000000) >> 32));
+}
+
+#endif /* _COMPAT_FREEBSD_SYS_TIME_H_ */
diff --git a/usr/src/compat/freebsd/sys/types.h b/usr/src/compat/freebsd/sys/types.h
new file mode 100644
index 0000000000..63731da42e
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/types.h
@@ -0,0 +1,85 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2014 Pluribus Networks Inc.
+ * Copyright 2018 Joyent, Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_TYPES_H_
+#define _COMPAT_FREEBSD_SYS_TYPES_H_
+
+#include <sys/_types.h>
+
+typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */
+typedef __uint16_t u_int16_t;
+typedef __uint32_t u_int32_t;
+typedef __uint64_t u_int64_t;
+
+#ifndef __REGISTER_T_DEFINED
+#define __REGISTER_T_DEFINED
+typedef __register_t register_t;
+#endif
+
+#ifndef __SBINTIME_T_DEFINED
+#define __SBINTIME_T_DEFINED
+typedef __int64_t sbintime_t;
+#endif
+
+#ifndef __VM_MEMATTR_T_DEFINED
+#define __VM_MEMATTR_T_DEFINED
+typedef char vm_memattr_t;
+#endif
+
+#ifndef __VM_OFFSET_T_DEFINED
+#define __VM_OFFSET_T_DEFINED
+typedef __vm_offset_t vm_offset_t;
+#endif
+
+#ifndef __VM_OOFFSET_T_DEFINED
+#define __VM_OOFFSET_T_DEFINED
+typedef __vm_ooffset_t vm_ooffset_t;
+#endif
+
+#ifndef __VM_PADDR_T_DEFINED
+#define __VM_PADDR_T_DEFINED
+typedef __vm_paddr_t vm_paddr_t;
+#endif
+
+#ifndef __VM_PINDEX_T_DEFINED
+#define __VM_PINDEX_T_DEFINED
+typedef __uint64_t vm_pindex_t;
+#endif
+
+#ifndef __VM_SIZE_T_DEFINED
+#define __VM_SIZE_T_DEFINED
+typedef __vm_size_t vm_size_t;
+#endif
+
+#ifndef __VM_MEMATTR_T_DEFINED
+#define __VM_MEMATTR_T_DEFINED
+typedef char vm_memattr_t;
+#endif
+
+#ifndef __bool_true_false_are_defined
+#define __bool_true_false_are_defined 1
+#define false 0
+#define true 1
+typedef _Bool bool;
+#endif
+
+#if defined(_KERNEL)
+typedef struct __dev_info **device_t;
+#endif
+
+#include_next <sys/types.h>
+
+#endif /* _COMPAT_FREEBSD_SYS_TYPES_H_ */
diff --git a/usr/src/compat/freebsd/sys/uio.h b/usr/src/compat/freebsd/sys/uio.h
new file mode 100644
index 0000000000..05c6f2a028
--- /dev/null
+++ b/usr/src/compat/freebsd/sys/uio.h
@@ -0,0 +1,26 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2013 Pluribus Networks Inc.
+ */
+
+#ifndef _COMPAT_FREEBSD_SYS_UIO_H_
+#define _COMPAT_FREEBSD_SYS_UIO_H_
+
+#include_next <sys/uio.h>
+
+#ifndef _KERNEL
+ssize_t preadv(int, const struct iovec *, int, off_t);
+ssize_t pwritev(int, const struct iovec *, int, off_t);
+#endif
+
+#endif /* _COMPAT_FREEBSD_SYS_UIO_H_ */