aboutsummaryrefslogtreecommitdiff
path: root/cddl/lib
diff options
context:
space:
mode:
Diffstat (limited to 'cddl/lib')
-rw-r--r--cddl/lib/Makefile46
-rw-r--r--cddl/lib/Makefile.inc4
-rw-r--r--cddl/lib/drti/Makefile28
-rw-r--r--cddl/lib/drti/Makefile.depend13
-rw-r--r--cddl/lib/libavl/Makefile16
-rw-r--r--cddl/lib/libavl/Makefile.depend16
-rw-r--r--cddl/lib/libctf/Makefile40
-rw-r--r--cddl/lib/libctf/Makefile.depend18
-rw-r--r--cddl/lib/libdtrace/Makefile159
-rw-r--r--cddl/lib/libdtrace/Makefile.depend24
-rw-r--r--cddl/lib/libdtrace/errno.d349
-rw-r--r--cddl/lib/libdtrace/io.d262
-rw-r--r--cddl/lib/libdtrace/ip.d304
-rw-r--r--cddl/lib/libdtrace/libproc_compat.h63
-rw-r--r--cddl/lib/libdtrace/net.d41
-rw-r--r--cddl/lib/libdtrace/nfs.d105
-rw-r--r--cddl/lib/libdtrace/nfssrv.d53
-rw-r--r--cddl/lib/libdtrace/psinfo.d97
-rw-r--r--cddl/lib/libdtrace/regs_aarch64.d74
-rw-r--r--cddl/lib/libdtrace/regs_riscv.d74
-rw-r--r--cddl/lib/libdtrace/regs_x86.d116
-rw-r--r--cddl/lib/libdtrace/sched.d81
-rw-r--r--cddl/lib/libdtrace/sctp.d169
-rw-r--r--cddl/lib/libdtrace/siftr.d108
-rw-r--r--cddl/lib/libdtrace/signal.d151
-rw-r--r--cddl/lib/libdtrace/socket.d299
-rw-r--r--cddl/lib/libdtrace/tcp.d419
-rw-r--r--cddl/lib/libdtrace/udp.d74
-rw-r--r--cddl/lib/libdtrace/udplite.d75
-rw-r--r--cddl/lib/libdtrace/unistd.d54
-rw-r--r--cddl/lib/libicp/Makefile142
-rw-r--r--cddl/lib/libicp/Makefile.depend15
-rw-r--r--cddl/lib/libicp_rescue/Makefile137
-rw-r--r--cddl/lib/libicp_rescue/Makefile.depend15
-rw-r--r--cddl/lib/libnvpair/Makefile31
-rw-r--r--cddl/lib/libnvpair/Makefile.depend16
-rw-r--r--cddl/lib/libspl/Makefile52
-rw-r--r--cddl/lib/libspl/Makefile.depend15
-rw-r--r--cddl/lib/libtpool/Makefile32
-rw-r--r--cddl/lib/libtpool/Makefile.depend16
-rw-r--r--cddl/lib/libtpool/tests/Makefile13
-rw-r--r--cddl/lib/libtpool/tests/libtpool_test.c82
-rw-r--r--cddl/lib/libumem/Makefile11
-rw-r--r--cddl/lib/libumem/Makefile.depend14
-rw-r--r--cddl/lib/libuutil/Makefile26
-rw-r--r--cddl/lib/libuutil/Makefile.depend17
-rw-r--r--cddl/lib/libzdb/Makefile28
-rw-r--r--cddl/lib/libzdb/Makefile.depend14
-rw-r--r--cddl/lib/libzfs/Makefile110
-rw-r--r--cddl/lib/libzfs/Makefile.depend30
-rw-r--r--cddl/lib/libzfs_core/Makefile34
-rw-r--r--cddl/lib/libzfs_core/Makefile.depend18
-rw-r--r--cddl/lib/libzfsbootenv/Makefile37
-rw-r--r--cddl/lib/libzfsbootenv/Makefile.depend17
-rw-r--r--cddl/lib/libzpool/Makefile346
-rw-r--r--cddl/lib/libzpool/Makefile.depend23
-rw-r--r--cddl/lib/libzutil/Makefile42
-rw-r--r--cddl/lib/libzutil/Makefile.depend19
-rw-r--r--cddl/lib/pam_zfs_key/Makefile30
-rw-r--r--cddl/lib/tests/Makefile4
-rw-r--r--cddl/lib/tests/Makefile.depend10
61 files changed, 4728 insertions, 0 deletions
diff --git a/cddl/lib/Makefile b/cddl/lib/Makefile
new file mode 100644
index 000000000000..892798be347d
--- /dev/null
+++ b/cddl/lib/Makefile
@@ -0,0 +1,46 @@
+.include <src.opts.mk>
+
+.if ${MK_DTRACE} == yes || ${MK_ZFS} == yes
+SUBDIR= libspl
+.endif
+
+SUBDIR.${MK_DTRACE}+= \
+ drti \
+ libctf \
+ libdtrace
+
+SUBDIR.${MK_TESTS}+= tests
+
+SUBDIR.${MK_ZFS}+= \
+ libavl \
+ libicp \
+ libicp_rescue \
+ libnvpair \
+ libtpool \
+ libumem \
+ libuutil \
+ libzdb \
+ libzfs \
+ libzfs_core \
+ libzfsbootenv \
+ libzpool \
+ libzutil
+
+SUBDIR.${MK_ZFS}.${MK_OPENSSL} = pam_zfs_key
+
+SUBDIR_DEPEND_libavl= libspl
+SUBDIR_DEPEND_libctf= libspl
+SUBDIR_DEPEND_libdtrace= libctf
+SUBDIR_DEPEND_libnvpair= libspl
+SUBDIR_DEPEND_libtpool= libspl
+SUBDIR_DEPEND_libuutil= libavl libspl
+SUBDIR_DEPEND_libzfs_core= libnvpair libspl libzutil
+SUBDIR_DEPEND_libzfs= libavl libnvpair libumem libuutil libzfs_core libzutil
+SUBDIR_DEPEND_libzpool= libavl libnvpair libumem libicp
+SUBDIR_DEPEND_libzutil= libavl libtpool
+SUBDIR_DEPEND_libzfsbootenv= libzfs libnvpair
+SUBDIR_DEPEND_pam_zfs_key= libnvpair libuutil libzfs libzfs_core
+
+SUBDIR_PARALLEL=
+
+.include <bsd.subdir.mk>
diff --git a/cddl/lib/Makefile.inc b/cddl/lib/Makefile.inc
new file mode 100644
index 000000000000..ebcc06f3e956
--- /dev/null
+++ b/cddl/lib/Makefile.inc
@@ -0,0 +1,4 @@
+SHLIBDIR?= /lib
+SHLIB_MAJOR?= 2
+
+.include "../Makefile.inc"
diff --git a/cddl/lib/drti/Makefile b/cddl/lib/drti/Makefile
new file mode 100644
index 000000000000..4a7a8350cac8
--- /dev/null
+++ b/cddl/lib/drti/Makefile
@@ -0,0 +1,28 @@
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/common
+
+PACKAGE= dtrace
+SRCS= drti.c
+FILES= ${SRCS:R:S/$/.o/g}
+FILESOWN= ${LIBOWN}
+FILESGRP= ${LIBGRP}
+FILESMODE= ${LIBMODE}
+FILESDIR= ${LIBDIR}/dtrace
+CLEANFILES= ${FILES}
+# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY.
+.undef LIBRARIES_ONLY
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
+ -I${SRCTOP}/cddl/compat/opensolaris/include \
+ -I${OPENSOLARIS_USR_DISTDIR}/head \
+ -I${OPENSOLARIS_USR_DISTDIR}/lib/libctf/common \
+ -I${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common \
+ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common \
+ -DPIC ${PICFLAG}
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/drti/Makefile.depend b/cddl/lib/drti/Makefile.depend
new file mode 100644
index 000000000000..2c564fe515ff
--- /dev/null
+++ b/cddl/lib/drti/Makefile.depend
@@ -0,0 +1,13 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/libelf \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libavl/Makefile b/cddl/lib/libavl/Makefile
new file mode 100644
index 000000000000..4ce1de20a3d9
--- /dev/null
+++ b/cddl/lib/libavl/Makefile
@@ -0,0 +1,16 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/avl
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= avl
+LIBADD= spl
+SRCS= avl.c
+WARNS?= 3
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libavl/Makefile.depend b/cddl/lib/libavl/Makefile.depend
new file mode 100644
index 000000000000..409c3c86cc20
--- /dev/null
+++ b/cddl/lib/libavl/Makefile.depend
@@ -0,0 +1,16 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libspl \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libctf/Makefile b/cddl/lib/libctf/Makefile
new file mode 100644
index 000000000000..1c605182bc1d
--- /dev/null
+++ b/cddl/lib/libctf/Makefile
@@ -0,0 +1,40 @@
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/common/ctf
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libctf/common
+.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/ctf
+
+PACKAGE= ctf
+LIB_PACKAGE=
+LIB= ctf
+SRCS= ctf_create.c \
+ ctf_decl.c \
+ ctf_error.c \
+ ctf_hash.c \
+ ctf_labels.c \
+ ctf_lib.c \
+ ctf_lookup.c \
+ ctf_open.c \
+ ctf_subr.c \
+ ctf_types.c \
+ ctf_util.c
+MAN= ctf.5
+
+WARNS?= 2
+CFLAGS+= -DCTF_OLD_VERSIONS
+
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+
+CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
+ -I${SRCTOP}/cddl/compat/opensolaris/include \
+ -I${OPENSOLARIS_USR_DISTDIR}/head \
+ -I${OPENSOLARIS_USR_DISTDIR}/common/ctf \
+ -I${OPENSOLARIS_USR_DISTDIR}/lib/libctf/common \
+ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common
+
+LIBADD+= spl z
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libctf/Makefile.depend b/cddl/lib/libctf/Makefile.depend
new file mode 100644
index 000000000000..7cbc01413fbc
--- /dev/null
+++ b/cddl/lib/libctf/Makefile.depend
@@ -0,0 +1,18 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libspl \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libelf \
+ lib/libz \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile
new file mode 100644
index 000000000000..d086fffb07bc
--- /dev/null
+++ b/cddl/lib/libdtrace/Makefile
@@ -0,0 +1,159 @@
+SHLIBDIR?= /lib
+
+.include <src.opts.mk>
+
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/common
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libgen/common
+
+PACKAGE= dtrace
+LIB= dtrace
+
+SRCS= dt_aggregate.c \
+ dt_as.c \
+ dt_buf.c \
+ dt_cc.c \
+ dt_cg.c \
+ dt_consume.c \
+ dt_decl.c \
+ dt_dis.c \
+ dt_dof.c \
+ dt_error.c \
+ dt_errtags.c \
+ dt_grammar.y \
+ dt_handle.c \
+ dt_ident.c \
+ dt_isadep.c \
+ dt_inttab.c \
+ dt_lex.l \
+ dt_link.c \
+ dt_list.c \
+ dt_map.c \
+ dt_module.c \
+ dt_names.c \
+ dt_open.c \
+ dt_options.c \
+ dt_parser.c \
+ dt_pcb.c \
+ dt_pid.c \
+ dt_pq.c \
+ dt_pragma.c \
+ dt_print.c \
+ dt_printf.c \
+ dt_proc.c \
+ dt_program.c \
+ dt_provider.c \
+ dt_regset.c \
+ dt_string.c \
+ dt_strtab.c \
+ dt_subr.c \
+ dt_sugar.c \
+ dt_work.c \
+ dt_xlator.c \
+ gmatch.c
+
+DSRCS= errno.d \
+ io.d \
+ ip.d \
+ psinfo.d \
+ sctp.d \
+ siftr.d \
+ signal.d \
+ tcp.d \
+ socket.d \
+ udp.d \
+ udplite.d \
+ unistd.d
+
+FILES= ${DSRCS}
+FILESDIR= /usr/lib/dtrace
+FILESMODE= ${NOBINMODE}
+
+INCSGROUPS= INCS SYSINCS
+SYSINCSDIR= ${INCLUDEDIR}/sys
+INCS+= ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h
+SYSINCS+= ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
+SYSINCS+= ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/sys/ctf_api.h
+
+WARNS?= 1
+
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+
+
+CFLAGS+= -I${.OBJDIR} -I${.CURDIR} \
+ -I${SRCTOP}/sys/cddl/dev/dtrace/${MACHINE_ARCH} \
+ -I${SRCTOP}/sys/cddl/dev/kinst \
+ -I${SRCTOP}/sys/cddl/compat/opensolaris \
+ -I${SRCTOP}/cddl/compat/opensolaris/include \
+ -I${OPENSOLARIS_USR_DISTDIR}/head \
+ -I${OPENSOLARIS_USR_DISTDIR}/lib/libctf/common \
+ -I${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common \
+ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common
+
+#CFLAGS+= -DYYDEBUG
+
+.if ${MACHINE_CPUARCH} == "aarch64"
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/aarch64
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/aarch64
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/aarch64
+.elif ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
+CFLAGS+= -I${SRCTOP}/sys/cddl/dev/dtrace/x86
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel -DDIS_MEM
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/i386
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/${MACHINE_ARCH}
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/x86
+.elif ${MACHINE_CPUARCH} == "arm"
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/arm
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/arm
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/arm
+.elif ${MACHINE_CPUARCH} == "powerpc"
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/powerpc
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/powerpc
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/powerpc
+.elif ${MACHINE_CPUARCH} == "riscv"
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/riscv
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/riscv
+.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/riscv
+.else
+# temporary hack
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel
+.endif
+
+.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
+SRCS+= dis_tables.c instr_size.c
+DSRCS+= regs_x86.d
+.endif
+
+.if ${MACHINE_CPUARCH} == "riscv"
+SRCS+= instr_size.c
+DSRCS+= regs_riscv.d
+.endif
+
+.if ${MACHINE_CPUARCH} == "aarch64"
+SRCS+= instr_size.c
+DSRCS+= regs_aarch64.d
+.endif
+
+YFLAGS+=-d
+
+.if ${MK_DTRACE_ASAN} != "no"
+CFLAGS+= -fsanitize=address -fsanitize=undefined
+LDFLAGS+= -fsanitize=address -fsanitize=undefined
+.endif
+
+LIBADD= ctf elf proc pthread rtld_db xo
+
+CLEANFILES= dt_errtags.c dt_names.c
+
+.include <bsd.lib.mk>
+
+dt_errtags.c: ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/dt_errtags.h
+ sh ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/mkerrtags.sh < ${.ALLSRC} > ${.TARGET}
+
+dt_names.c: ${OPENSOLARIS_SYS_DISTDIR}/uts/common/sys/dtrace.h
+ sh ${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common/mknames.sh < ${.ALLSRC} > ${.TARGET}
diff --git a/cddl/lib/libdtrace/Makefile.depend b/cddl/lib/libdtrace/Makefile.depend
new file mode 100644
index 000000000000..92c6b0e658b5
--- /dev/null
+++ b/cddl/lib/libdtrace/Makefile.depend
@@ -0,0 +1,24 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ bin/sh.host \
+ cddl/lib/libctf \
+ include \
+ include/arpa \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libelf \
+ lib/libproc \
+ lib/librtld_db \
+ lib/libthr \
+ usr.bin/awk.host \
+ usr.bin/yacc.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libdtrace/errno.d b/cddl/lib/libdtrace/errno.d
new file mode 100644
index 000000000000..2045e3a7433d
--- /dev/null
+++ b/cddl/lib/libdtrace/errno.d
@@ -0,0 +1,349 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
+ * Portions Copyright 2018 Devin Teske dteske@freebsd.org
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+inline int EPERM = 1;
+#pragma D binding "1.0" EPERM
+inline int ENOENT = 2;
+#pragma D binding "1.0" ENOENT
+inline int ESRCH = 3;
+#pragma D binding "1.0" ESRCH
+inline int EINTR = 4;
+#pragma D binding "1.0" EINTR
+inline int EIO = 5;
+#pragma D binding "1.0" EIO
+inline int ENXIO = 6;
+#pragma D binding "1.0" ENXIO
+inline int E2BIG = 7;
+#pragma D binding "1.0" E2BIG
+inline int ENOEXEC = 8;
+#pragma D binding "1.0" ENOEXEC
+inline int EBADF = 9;
+#pragma D binding "1.0" EBADF
+inline int ECHILD = 10;
+#pragma D binding "1.0" ECHILD
+inline int EDEADLK = 11;
+#pragma D binding "1.0" EDEADLK
+inline int ENOMEM = 12;
+#pragma D binding "1.0" ENOMEM
+inline int EACCES = 13;
+#pragma D binding "1.0" EACCES
+inline int EFAULT = 14;
+#pragma D binding "1.0" EFAULT
+inline int ENOTBLK = 15;
+#pragma D binding "1.0" ENOTBLK
+inline int EBUSY = 16;
+#pragma D binding "1.0" EBUSY
+inline int EEXIST = 17;
+#pragma D binding "1.0" EEXIST
+inline int EXDEV = 18;
+#pragma D binding "1.0" EXDEV
+inline int ENODEV = 19;
+#pragma D binding "1.0" ENODEV
+inline int ENOTDIR = 20;
+#pragma D binding "1.0" ENOTDIR
+inline int EISDIR = 21;
+#pragma D binding "1.0" EISDIR
+inline int EINVAL = 22;
+#pragma D binding "1.0" EINVAL
+inline int ENFILE = 23;
+#pragma D binding "1.0" ENFILE
+inline int EMFILE = 24;
+#pragma D binding "1.0" EMFILE
+inline int ENOTTY = 25;
+#pragma D binding "1.0" ENOTTY
+inline int ETXTBSY = 26;
+#pragma D binding "1.0" ETXTBSY
+inline int EFBIG = 27;
+#pragma D binding "1.0" EFBIG
+inline int ENOSPC = 28;
+#pragma D binding "1.0" ENOSPC
+inline int ESPIPE = 29;
+#pragma D binding "1.0" ESPIPE
+inline int EROFS = 30;
+#pragma D binding "1.0" EROFS
+inline int EMLINK = 31;
+#pragma D binding "1.0" EMLINK
+inline int EPIPE = 32;
+#pragma D binding "1.0" EPIPE
+inline int EDOM = 33;
+#pragma D binding "1.0" EDOM
+inline int ERANGE = 34;
+#pragma D binding "1.0" ERANGE
+inline int EAGAIN = 35;
+#pragma D binding "1.0" EAGAIN
+inline int EWOULDBLOCK = EAGAIN;
+#pragma D binding "1.0" EWOULDBLOCK
+inline int EINPROGRESS = 36;
+#pragma D binding "1.0" EINPROGRESS
+inline int EALREADY = 37;
+#pragma D binding "1.0" EALREADY
+inline int ENOTSOCK = 38;
+#pragma D binding "1.0" ENOTSOCK
+inline int EDESTADDRREQ = 39;
+#pragma D binding "1.0" EDESTADDRREQ
+inline int EMSGSIZE = 40;
+#pragma D binding "1.0" EMSGSIZE
+inline int EPROTOTYPE = 41;
+#pragma D binding "1.0" EPROTOTYPE
+inline int ENOPROTOOPT = 42;
+#pragma D binding "1.0" ENOPROTOOPT
+inline int EPROTONOSUPPORT = 43;
+#pragma D binding "1.0" EPROTONOSUPPORT
+inline int ESOCKTNOSUPPORT = 44;
+#pragma D binding "1.0" ESOCKTNOSUPPORT
+inline int EOPNOTSUPP = 45;
+#pragma D binding "1.0" EOPNOTSUPP
+inline int ENOTSUP = EOPNOTSUPP;
+#pragma D binding "1.0" ENOTSUP
+inline int EPFNOSUPPORT = 46;
+#pragma D binding "1.0" EPFNOSUPPORT
+inline int EAFNOSUPPORT = 47;
+#pragma D binding "1.0" EAFNOSUPPORT
+inline int EADDRINUSE = 48;
+#pragma D binding "1.0" EADDRINUSE
+inline int EADDRNOTAVAIL = 49;
+#pragma D binding "1.0" EADDRNOTAVAIL
+inline int ENETDOWN = 50;
+#pragma D binding "1.0" ENETDOWN
+inline int ENETUNREACH = 51;
+#pragma D binding "1.0" ENETUNREACH
+inline int ENETRESET = 52;
+#pragma D binding "1.0" ENETRESET
+inline int ECONNABORTED = 53;
+#pragma D binding "1.0" ECONNABORTED
+inline int ECONNRESET = 54;
+#pragma D binding "1.0" ECONNRESET
+inline int ENOBUFS = 55;
+#pragma D binding "1.0" ENOBUFS
+inline int EISCONN = 56;
+#pragma D binding "1.0" EISCONN
+inline int ENOTCONN = 57;
+#pragma D binding "1.0" ENOTCONN
+inline int ESHUTDOWN = 58;
+#pragma D binding "1.0" ESHUTDOWN
+inline int ETOOMANYREFS = 59;
+#pragma D binding "1.0" ETOOMANYREFS
+inline int ETIMEDOUT = 60;
+#pragma D binding "1.0" ETIMEDOUT
+inline int ECONNREFUSED = 61;
+#pragma D binding "1.0" ECONNREFUSED
+inline int ELOOP = 62;
+#pragma D binding "1.0" ELOOP
+inline int ENAMETOOLONG = 63;
+#pragma D binding "1.0" ENAMETOOLONG
+inline int EHOSTDOWN = 64;
+#pragma D binding "1.0" EHOSTDOWN
+inline int EHOSTUNREACH = 65;
+#pragma D binding "1.0" EHOSTUNREACH
+inline int ENOTEMPTY = 66;
+#pragma D binding "1.0" ENOTEMPTY
+inline int EPROCLIM = 67;
+#pragma D binding "1.0" EPROCLIM
+inline int EUSERS = 68;
+#pragma D binding "1.0" EUSERS
+inline int EDQUOT = 69;
+#pragma D binding "1.0" EDQUOT
+inline int ESTALE = 70;
+#pragma D binding "1.0" ESTALE
+inline int EREMOTE = 71;
+#pragma D binding "1.0" EREMOTE
+inline int EBADRPC = 72;
+#pragma D binding "1.0" EBADRPC
+inline int ERPCMISMATCH = 73;
+#pragma D binding "1.0" ERPCMISMATCH
+inline int EPROGUNAVAIL = 74;
+#pragma D binding "1.0" EPROGUNAVAIL
+inline int EPROGMISMATCH = 75;
+#pragma D binding "1.0" EPROGMISMATCH
+inline int EPROCUNAVAIL = 76;
+#pragma D binding "1.0" EPROCUNAVAIL
+inline int ENOLCK = 77;
+#pragma D binding "1.0" ENOLCK
+inline int ENOSYS = 78;
+#pragma D binding "1.0" ENOSYS
+inline int EFTYPE = 79;
+#pragma D binding "1.0" EFTYPE
+inline int EAUTH = 80;
+#pragma D binding "1.0" EAUTH
+inline int ENEEDAUTH = 81;
+#pragma D binding "1.0" ENEEDAUTH
+inline int EIDRM = 82;
+#pragma D binding "1.0" EIDRM
+inline int ENOMSG = 83;
+#pragma D binding "1.0" ENOMSG
+inline int EOVERFLOW = 84;
+#pragma D binding "1.0" EOVERFLOW
+inline int ECANCELED = 85;
+#pragma D binding "1.0" ECANCELED
+inline int EILSEQ = 86;
+#pragma D binding "1.0" EILSEQ
+inline int ENOATTR = 87;
+#pragma D binding "1.0" ENOATTR
+inline int EDOOFUS = 88;
+#pragma D binding "1.0" EDOOFUS
+inline int EBADMSG = 89;
+#pragma D binding "1.0" EBADMSG
+inline int EMULTIHOP = 90;
+#pragma D binding "1.0" EMULTIHOP
+inline int ENOLINK = 91;
+#pragma D binding "1.0" ENOLINK
+inline int EPROTO = 92;
+#pragma D binding "1.0" EPROTO
+inline int ENOTCAPABLE = 93;
+#pragma D binding "1.13" ENOTCAPABLE
+inline int ECAPMODE = 94;
+#pragma D binding "1.13" ECAPMODE
+inline int ENOTRECOVERABLE = 95;
+#pragma D binding "1.13" ENOTRECOVERABLE
+inline int EOWNERDEAD = 96;
+#pragma D binding "1.13" EOWNERDEAD
+inline int EINTEGRITY = 97;
+#pragma D binding "1.13" EINTEGRITY
+inline int ELAST = 97;
+#pragma D binding "1.0" ELAST
+inline int ERESTART = -1;
+#pragma D binding "1.0" ERESTART
+inline int EJUSTRETURN = -2;
+#pragma D binding "1.0" EJUSTRETURN
+inline int ENOIOCTL = -3;
+#pragma D binding "1.0" ENOIOCTL
+inline int EDIRIOCTL = -4;
+#pragma D binding "1.0" EDIRIOCTL
+inline int ERELOOKUP = -5;
+#pragma D binding "1.13" ERELOOKUP
+
+/*
+ * Error strings from <sys/errno.h>
+ */
+#pragma D binding "1.13" strerror
+inline string strerror[int errno] =
+ errno == 0 ? "Success" :
+ errno == EPERM ? "Operation not permitted" :
+ errno == ENOENT ? "No such file or directory" :
+ errno == ESRCH ? "No such process" :
+ errno == EINTR ? "Interrupted system call" :
+ errno == EIO ? "Input/output error" :
+ errno == ENXIO ? "Device not configured" :
+ errno == E2BIG ? "Argument list too long" :
+ errno == ENOEXEC ? "Exec format error" :
+ errno == EBADF ? "Bad file descriptor" :
+ errno == ECHILD ? "No child processes" :
+ errno == EDEADLK ? "Resource deadlock avoided" :
+ errno == ENOMEM ? "Cannot allocate memory" :
+ errno == EACCES ? "Permission denied" :
+ errno == EFAULT ? "Bad address" :
+ errno == ENOTBLK ? "Block device required" :
+ errno == EBUSY ? "Device busy" :
+ errno == EEXIST ? "File exists" :
+ errno == EXDEV ? "Cross-device link" :
+ errno == ENODEV ? "Operation not supported by device" :
+ errno == ENOTDIR ? "Not a directory" :
+ errno == EISDIR ? "Is a directory" :
+ errno == EINVAL ? "Invalid argument" :
+ errno == ENFILE ? "Too many open files in system" :
+ errno == EMFILE ? "Too many open files" :
+ errno == ENOTTY ? "Inappropriate ioctl for device" :
+ errno == ETXTBSY ? "Text file busy" :
+ errno == EFBIG ? "File too large" :
+ errno == ENOSPC ? "No space left on device" :
+ errno == ESPIPE ? "Illegal seek" :
+ errno == EROFS ? "Read-only filesystem" :
+ errno == EMLINK ? "Too many links" :
+ errno == EPIPE ? "Broken pipe" :
+ errno == EDOM ? "Numerical argument out of domain" :
+ errno == ERANGE ? "Result too large" :
+ errno == EAGAIN ? "Resource temporarily unavailable" :
+ errno == EINPROGRESS ? "Operation now in progress" :
+ errno == EALREADY ? "Operation already in progress" :
+ errno == ENOTSOCK ? "Socket operation on non-socket" :
+ errno == EDESTADDRREQ ? "Destination address required" :
+ errno == EMSGSIZE ? "Message too long" :
+ errno == EPROTOTYPE ? "Protocol wrong type for socket" :
+ errno == ENOPROTOOPT ? "Protocol not available" :
+ errno == EPROTONOSUPPORT ? "Protocol not supported" :
+ errno == ESOCKTNOSUPPORT ? "Socket type not supported" :
+ errno == EOPNOTSUPP ? "Operation not supported" :
+ errno == EPFNOSUPPORT ? "Protocol family not supported" :
+ errno == EAFNOSUPPORT ? "Address family not supported by protocol family" :
+ errno == EADDRINUSE ? "Address already in use" :
+ errno == EADDRNOTAVAIL ? "Can't assign requested address" :
+ errno == ENETDOWN ? "Network is down" :
+ errno == ENETUNREACH ? "Network is unreachable" :
+ errno == ENETRESET ? "Network dropped connection on reset" :
+ errno == ECONNABORTED ? "Software caused connection abort" :
+ errno == ECONNRESET ? "Connection reset by peer" :
+ errno == ENOBUFS ? "No buffer space available" :
+ errno == EISCONN ? "Socket is already connected" :
+ errno == ENOTCONN ? "Socket is not connected" :
+ errno == ESHUTDOWN ? "Can't send after socket shutdown" :
+ errno == ETOOMANYREFS ? "Too many references: can't splice" :
+ errno == ETIMEDOUT ? "Operation timed out" :
+ errno == ECONNREFUSED ? "Connection refused" :
+ errno == ELOOP ? "Too many levels of symbolic links" :
+ errno == ENAMETOOLONG ? "File name too long" :
+ errno == EHOSTDOWN ? "Host is down" :
+ errno == EHOSTUNREACH ? "No route to host" :
+ errno == ENOTEMPTY ? "Directory not empty" :
+ errno == EPROCLIM ? "Too many processes" :
+ errno == EUSERS ? "Too many users" :
+ errno == EDQUOT ? "Disc quota exceeded" :
+ errno == ESTALE ? "Stale NFS file handle" :
+ errno == EREMOTE ? "Too many levels of remote in path" :
+ errno == EBADRPC ? "RPC struct is bad" :
+ errno == ERPCMISMATCH ? "RPC version wrong" :
+ errno == EPROGUNAVAIL ? "RPC prog. not avail" :
+ errno == EPROGMISMATCH ? "Program version wrong" :
+ errno == EPROCUNAVAIL ? "Bad procedure for program" :
+ errno == ENOLCK ? "No locks available" :
+ errno == ENOSYS ? "Function not implemented" :
+ errno == EFTYPE ? "Inappropriate file type or format" :
+ errno == EAUTH ? "Authentication error" :
+ errno == ENEEDAUTH ? "Need authenticator" :
+ errno == EIDRM ? "Identifier removed" :
+ errno == ENOMSG ? "No message of desired type" :
+ errno == EOVERFLOW ? "Value too large to be stored in data type" :
+ errno == ECANCELED ? "Operation canceled" :
+ errno == EILSEQ ? "Illegal byte sequence" :
+ errno == ENOATTR ? "Attribute not found" :
+ errno == EDOOFUS ? "Programming error" :
+ errno == EBADMSG ? "Bad message" :
+ errno == EMULTIHOP ? "Multihop attempted" :
+ errno == ENOLINK ? "Link has been severed" :
+ errno == EPROTO ? "Protocol error" :
+ errno == ENOTCAPABLE ? "Capabilities insufficient" :
+ errno == ECAPMODE ? "Not permitted in capability mode" :
+ errno == ENOTRECOVERABLE ? "State not recoverable" :
+ errno == EOWNERDEAD ? "Previous owner died" :
+ errno == EINTEGRITY ? "Integrity check failed" :
+ errno == ERESTART ? "restart syscall" :
+ errno == EJUSTRETURN ? "don't modify regs, just return" :
+ errno == ENOIOCTL ? "ioctl not handled by this layer" :
+ errno == EDIRIOCTL ? "do direct ioctl in GEOM" :
+ errno == ERELOOKUP ? "retry the directory lookup" :
+ "Unknown error";
diff --git a/cddl/lib/libdtrace/io.d b/cddl/lib/libdtrace/io.d
new file mode 100644
index 000000000000..d576f57476ce
--- /dev/null
+++ b/cddl/lib/libdtrace/io.d
@@ -0,0 +1,262 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2018 Devin Teske dteske@freebsd.org
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D depends_on module kernel
+#pragma D depends_on provider io
+
+typedef struct devinfo {
+ int dev_major; /* major number */
+ int dev_minor; /* minor number */
+ int dev_instance; /* instance number */
+ int dev_type; /* type of device */
+ string dev_name; /* name of device */
+ string dev_statname; /* name of device + instance/minor */
+ string dev_pathname; /* pathname of device */
+} devinfo_t;
+
+#pragma D binding "1.0" translator
+translator devinfo_t < struct devstat *D > {
+ dev_major = D->device_number;
+ dev_minor = D->unit_number;
+ dev_instance = 0;
+ dev_type = D->device_type;
+ dev_name = stringof(D->device_name);
+ dev_statname = stringof(D->device_name);
+ dev_pathname = stringof(D->device_name);
+};
+
+typedef struct bufinfo {
+ int b_cmd; /* I/O operation */
+ int b_flags; /* flags */
+ long b_bcount; /* number of bytes */
+ caddr_t b_addr; /* buffer address */
+ uint64_t b_blkno; /* expanded block # on device */
+ uint64_t b_lblkno; /* block # on device */
+ size_t b_resid; /* # of bytes not transferred */
+ size_t b_bufsize; /* size of allocated buffer */
+/* caddr_t b_iodone; I/O completion routine */
+ int b_error; /* expanded error field */
+/* dev_t b_edev; extended device */
+} bufinfo_t;
+
+#pragma D binding "1.0" translator
+translator bufinfo_t < struct bio *B > {
+ b_cmd = B->bio_cmd;
+ b_flags = B->bio_flags;
+ b_bcount = B->bio_bcount;
+ b_addr = B->bio_data;
+ b_blkno = 0;
+ b_lblkno = 0;
+ b_resid = B->bio_resid;
+ b_bufsize = 0; /* XXX gnn */
+ b_error = B->bio_error;
+};
+
+/*
+ * The following inline constants can be used to examine fi_oflags when using
+ * the fds[] array or a translated fileinfo_t. Note that the various open
+ * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
+ * To test the open mode, you write code similar to that used with the fcntl(2)
+ * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
+ */
+inline int O_ACCMODE = 0x0003;
+#pragma D binding "1.1" O_ACCMODE
+
+inline int O_RDONLY = 0x0000;
+#pragma D binding "1.1" O_RDONLY
+inline int O_WRONLY = 0x0001;
+#pragma D binding "1.1" O_WRONLY
+inline int O_RDWR = 0x0002;
+#pragma D binding "1.1" O_RDWR
+
+inline int O_APPEND = 0x0008;
+#pragma D binding "1.1" O_APPEND
+inline int O_CREAT = 0x0200;
+#pragma D binding "1.1" O_CREAT
+inline int O_EXCL = 0x0800;
+#pragma D binding "1.1" O_EXCL
+inline int O_NOCTTY = 0x8000;
+#pragma D binding "1.1" O_NOCTTY
+inline int O_NONBLOCK = 0x0004;
+#pragma D binding "1.1" O_NONBLOCK
+inline int O_NDELAY = 0x0004;
+#pragma D binding "1.1" O_NDELAY
+inline int O_SYNC = 0x0080;
+#pragma D binding "1.1" O_SYNC
+inline int O_TRUNC = 0x0400;
+#pragma D binding "1.1" O_TRUNC
+
+/*
+ * The following inline constants can be used to examine bio_cmd of struct bio
+ * or a translated bufinfo_t.
+ */
+inline int BIO_READ = 0x01;
+#pragma D binding "1.13" BIO_READ
+inline int BIO_WRITE = 0x02;
+#pragma D binding "1.13" BIO_WRITE
+inline int BIO_DELETE = 0x03;
+#pragma D binding "1.13" BIO_DELETE
+inline int BIO_GETATTR = 0x04;
+#pragma D binding "1.13" BIO_GETATTR
+inline int BIO_FLUSH = 0x05;
+#pragma D binding "1.13" BIO_FLUSH
+inline int BIO_CMD0 = 0x06;
+#pragma D binding "1.13" BIO_CMD0
+inline int BIO_CMD1 = 0x07;
+#pragma D binding "1.13" BIO_CMD1
+inline int BIO_CMD2 = 0x08;
+#pragma D binding "1.13" BIO_CMD2
+inline int BIO_ZONE = 0x09;
+#pragma D binding "1.13" BIO_ZONE
+
+/*
+ * The following inline constants can be used to examine bio_flags of struct
+ * bio or a translated bufinfo_t.
+ */
+inline int BIO_ERROR = 0x01;
+#pragma D binding "1.13" BIO_ERROR
+inline int BIO_DONE = 0x02;
+#pragma D binding "1.13" BIO_DONE
+inline int BIO_ONQUEUE = 0x04;
+#pragma D binding "1.13" BIO_ONQUEUE
+inline int BIO_ORDERED = 0x08;
+#pragma D binding "1.13" BIO_ORDERED
+inline int BIO_UNMAPPED = 0x10;
+#pragma D binding "1.13" BIO_UNMAPPED
+inline int BIO_TRANSIENT_MAPPING = 0x20;
+#pragma D binding "1.13" BIO_TRANSIENT_MAPPING
+inline int BIO_VLIST = 0x40;
+#pragma D binding "1.13" BIO_VLIST
+
+/*
+ * The following inline constants can be used to examine device_type of struct
+ * devstat or a translated devinfo_t.
+ */
+inline int DEVSTAT_TYPE_DIRECT = 0x000;
+#pragma D binding "1.13" DEVSTAT_TYPE_DIRECT
+inline int DEVSTAT_TYPE_SEQUENTIAL = 0x001;
+#pragma D binding "1.13" DEVSTAT_TYPE_SEQUENTIAL
+inline int DEVSTAT_TYPE_PRINTER = 0x002;
+#pragma D binding "1.13" DEVSTAT_TYPE_PRINTER
+inline int DEVSTAT_TYPE_PROCESSOR = 0x003;
+#pragma D binding "1.13" DEVSTAT_TYPE_PROCESSOR
+inline int DEVSTAT_TYPE_WORM = 0x004;
+#pragma D binding "1.13" DEVSTAT_TYPE_WORM
+inline int DEVSTAT_TYPE_CDROM = 0x005;
+#pragma D binding "1.13" DEVSTAT_TYPE_CDROM
+inline int DEVSTAT_TYPE_SCANNER = 0x006;
+#pragma D binding "1.13" DEVSTAT_TYPE_SCANNER
+inline int DEVSTAT_TYPE_OPTICAL = 0x007;
+#pragma D binding "1.13" DEVSTAT_TYPE_OPTICAL
+inline int DEVSTAT_TYPE_CHANGER = 0x008;
+#pragma D binding "1.13" DEVSTAT_TYPE_CHANGER
+inline int DEVSTAT_TYPE_COMM = 0x009;
+#pragma D binding "1.13" DEVSTAT_TYPE_COMM
+inline int DEVSTAT_TYPE_ASC0 = 0x00a;
+#pragma D binding "1.13" DEVSTAT_TYPE_ASC0
+inline int DEVSTAT_TYPE_ASC1 = 0x00b;
+#pragma D binding "1.13" DEVSTAT_TYPE_ASC1
+inline int DEVSTAT_TYPE_STORARRAY = 0x00c;
+#pragma D binding "1.13" DEVSTAT_TYPE_STORARRAY
+inline int DEVSTAT_TYPE_ENCLOSURE = 0x00d;
+#pragma D binding "1.13" DEVSTAT_TYPE_ENCLOSURE
+inline int DEVSTAT_TYPE_FLOPPY = 0x00e;
+#pragma D binding "1.13" DEVSTAT_TYPE_FLOPPY
+inline int DEVSTAT_TYPE_MASK = 0x00f;
+#pragma D binding "1.13" DEVSTAT_TYPE_MASK
+inline int DEVSTAT_TYPE_IF_SCSI = 0x010;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_SCSI
+inline int DEVSTAT_TYPE_IF_IDE = 0x020;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
+inline int DEVSTAT_TYPE_IF_OTHER = 0x030;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
+inline int DEVSTAT_TYPE_IF_NVME = 0x040;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_NVME
+inline int DEVSTAT_TYPE_IF_MASK = 0x0f0;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
+inline int DEVSTAT_TYPE_PASS = 0x100;
+#pragma D binding "1.13" DEVSTAT_TYPE_PASS
+
+#pragma D binding "1.13" device_type_string
+inline string device_type_string[int type] =
+ type == DEVSTAT_TYPE_DIRECT ? "DIRECT" :
+ type == DEVSTAT_TYPE_SEQUENTIAL ? "SEQUENTIAL" :
+ type == DEVSTAT_TYPE_PRINTER ? "PRINTER" :
+ type == DEVSTAT_TYPE_PROCESSOR ? "PROCESSOR" :
+ type == DEVSTAT_TYPE_WORM ? "WORM" :
+ type == DEVSTAT_TYPE_CDROM ? "CDROM" :
+ type == DEVSTAT_TYPE_SCANNER ? "SCANNER" :
+ type == DEVSTAT_TYPE_OPTICAL ? "OPTICAL" :
+ type == DEVSTAT_TYPE_CHANGER ? "CHANGER" :
+ type == DEVSTAT_TYPE_COMM ? "COMM" :
+ type == DEVSTAT_TYPE_ASC0 ? "ASC0" :
+ type == DEVSTAT_TYPE_ASC1 ? "ASC1" :
+ type == DEVSTAT_TYPE_STORARRAY ? "STORARRAY" :
+ type == DEVSTAT_TYPE_ENCLOSURE ? "ENCLOSURE" :
+ type == DEVSTAT_TYPE_FLOPPY ? "FLOPPY" :
+ strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
+
+#pragma D binding "1.13" device_type
+inline string device_type[int type] =
+ device_type_string[type & DEVSTAT_TYPE_MASK];
+
+#pragma D binding "1.13" device_if_string
+inline string device_if_string[int type] =
+ type == 0 ? "ACCESS" :
+ type == DEVSTAT_TYPE_IF_SCSI ? "SCSI" :
+ type == DEVSTAT_TYPE_IF_IDE ? "IDE" :
+ type == DEVSTAT_TYPE_IF_OTHER ? "OTHER" :
+ type == DEVSTAT_TYPE_IF_NVME ? "NVME" :
+ strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
+
+#pragma D binding "1.13" device_if
+inline string device_if[int type] =
+ device_if_string[type & DEVSTAT_TYPE_IF_MASK];
+
+#pragma D binding "1.13" bio_cmd_string
+inline string bio_cmd_string[int cmd] =
+ cmd == BIO_READ ? "READ" :
+ cmd == BIO_WRITE ? "WRITE" :
+ cmd == BIO_DELETE ? "DELETE" :
+ cmd == BIO_GETATTR ? "GETATTR" :
+ cmd == BIO_FLUSH ? "FLUSH" :
+ cmd == BIO_CMD0 ? "CMD0" :
+ cmd == BIO_CMD1 ? "CMD1" :
+ cmd == BIO_CMD2 ? "CMD2" :
+ cmd == BIO_ZONE ? "ZONE" :
+ strjoin("UNKNOWN(", strjoin(lltostr(cmd), ")"));
+
+#pragma D binding "1.13" bio_flag_string
+inline string bio_flag_string[int flag] =
+ flag == BIO_ERROR ? "ERROR" :
+ flag == BIO_DONE ? "DONE" :
+ flag == BIO_ONQUEUE ? "ONQUEUE" :
+ flag == BIO_ORDERED ? "ORDERED" :
+ flag == BIO_UNMAPPED ? "UNMAPPED" :
+ flag == BIO_TRANSIENT_MAPPING ? "TRANSIENT_MAPPING" :
+ flag == BIO_VLIST ? "VLIST" :
+ "";
diff --git a/cddl/lib/libdtrace/ip.d b/cddl/lib/libdtrace/ip.d
new file mode 100644
index 000000000000..2fe98858efc2
--- /dev/null
+++ b/cddl/lib/libdtrace/ip.d
@@ -0,0 +1,304 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 Mark Johnston <markj@freebsd.org>
+ */
+
+#pragma D depends_on module kernel
+#pragma D depends_on provider ip
+
+/*
+ * pktinfo is where packet ID info can be made available for deeper
+ * analysis if packet IDs become supported by the kernel in the future.
+ * The pkt_addr member is currently always NULL.
+ */
+typedef struct pktinfo {
+ uintptr_t pkt_addr;
+} pktinfo_t;
+
+/*
+ * csinfo is where connection state info is made available.
+ */
+typedef uint32_t zoneid_t;
+typedef struct csinfo {
+ uintptr_t cs_addr;
+ uint64_t cs_cid;
+ pid_t cs_pid;
+ zoneid_t cs_zoneid;
+} csinfo_t;
+
+/*
+ * ipinfo contains common IP info for both IPv4 and IPv6.
+ */
+typedef struct ipinfo {
+ uint8_t ip_ver; /* IP version (4, 6) */
+ uint32_t ip_plength; /* payload length */
+ string ip_saddr; /* source address */
+ string ip_daddr; /* destination address */
+} ipinfo_t;
+
+/*
+ * ifinfo contains network interface info.
+ */
+typedef struct ifinfo {
+ string if_name; /* interface name */
+ int8_t if_local; /* is delivered locally */
+ /*netstackid_t if_ipstack;*/ /* ipstack ID */
+ uintptr_t if_addr; /* pointer to raw ill_t */
+} ifinfo_t;
+
+typedef uint32_t ipaddr_t;
+typedef struct {
+ uint8_t ipha_version_and_hdr_length;
+ uint8_t ipha_type_of_service;
+ uint16_t ipha_length;
+ uint16_t ipha_ident;
+ uint16_t ipha_fragment_offset_and_flags;
+ uint8_t ipha_ttl;
+ uint8_t ipha_protocol;
+ uint16_t ipha_hdr_checksum;
+ ipaddr_t ipha_src;
+ ipaddr_t ipha_dst;
+} ipha_t;
+
+/*
+ * ipv4info is a translated version of the IPv4 header (with raw pointer).
+ * These values are NULL if the packet is not IPv4.
+ */
+typedef struct ipv4info {
+ uint8_t ipv4_ver; /* IP version (4) */
+ uint8_t ipv4_ihl; /* header length, bytes */
+ uint8_t ipv4_tos; /* type of service field */
+ uint16_t ipv4_length; /* length (header + payload) */
+ uint16_t ipv4_ident; /* identification */
+ uint8_t ipv4_flags; /* IP flags */
+ uint16_t ipv4_offset; /* fragment offset */
+ uint8_t ipv4_ttl; /* time to live */
+ uint8_t ipv4_protocol; /* next level protocol */
+ string ipv4_protostr; /* next level protocol, as a string */
+ uint16_t ipv4_checksum; /* header checksum */
+ ipaddr_t ipv4_src; /* source address */
+ ipaddr_t ipv4_dst; /* destination address */
+ string ipv4_saddr; /* source address, string */
+ string ipv4_daddr; /* destination address, string */
+ ipha_t *ipv4_hdr; /* pointer to raw header */
+} ipv4info_t;
+
+/*
+ * ipv6info is a translated version of the IPv6 header (with raw pointer).
+ * These values are NULL if the packet is not IPv6.
+ */
+typedef struct in6_addr in6_addr_t;
+typedef struct ipv6info {
+ uint8_t ipv6_ver; /* IP version (6) */
+ uint8_t ipv6_tclass; /* traffic class */
+ uint32_t ipv6_flow; /* flow label */
+ uint16_t ipv6_plen; /* payload length */
+ uint8_t ipv6_nexthdr; /* next header protocol */
+ string ipv6_nextstr; /* next header protocol, as a string */
+ uint8_t ipv6_hlim; /* hop limit */
+ in6_addr_t *ipv6_src; /* source address */
+ in6_addr_t *ipv6_dst; /* destination address */
+ string ipv6_saddr; /* source address, string */
+ string ipv6_daddr; /* destination address, string */
+ struct ip6_hdr *ipv6_hdr; /* pointer to raw header */
+} ipv6info_t;
+
+#pragma D binding "1.5" IPPROTO_IP
+inline short IPPROTO_IP = 0;
+#pragma D binding "1.5" IPPROTO_ICMP
+inline short IPPROTO_ICMP = 1;
+#pragma D binding "1.5" IPPROTO_IGMP
+inline short IPPROTO_IGMP = 2;
+#pragma D binding "1.5" IPPROTO_IPV4
+inline short IPPROTO_IPV4 = 4;
+#pragma D binding "1.5" IPPROTO_TCP
+inline short IPPROTO_TCP = 6;
+#pragma D binding "1.5" IPPROTO_UDP
+inline short IPPROTO_UDP = 17;
+#pragma D binding "1.5" IPPROTO_IPV6
+inline short IPPROTO_IPV6 = 41;
+#pragma D binding "1.5" IPPROTO_ROUTING
+inline short IPPROTO_ROUTING = 43;
+#pragma D binding "1.5" IPPROTO_FRAGMENT
+inline short IPPROTO_FRAGMENT = 44;
+#pragma D binding "1.5" IPPROTO_RSVP
+inline short IPPROTO_RSVP = 46;
+#pragma D binding "1.5" IPPROTO_GRE
+inline short IPPROTO_GRE = 47;
+#pragma D binding "1.5" IPPROTO_ESP
+inline short IPPROTO_ESP = 50;
+#pragma D binding "1.5" IPPROTO_AH
+inline short IPPROTO_AH = 51;
+#pragma D binding "1.5" IPPROTO_MOBILE
+inline short IPPROTO_MOBILE = 55;
+#pragma D binding "1.5" IPPROTO_ICMPV6
+inline short IPPROTO_ICMPV6 = 58;
+#pragma D binding "1.5" IPPROTO_DSTOPTS
+inline short IPPROTO_DSTOPTS = 60;
+#pragma D binding "1.5" IPPROTO_ETHERIP
+inline short IPPROTO_ETHERIP = 97;
+#pragma D binding "1.5" IPPROTO_PIM
+inline short IPPROTO_PIM = 103;
+#pragma D binding "1.5" IPPROTO_IPCOMP
+inline short IPPROTO_IPCOMP = 108;
+#pragma D binding "1.5" IPPROTO_SCTP
+inline short IPPROTO_SCTP = 132;
+#pragma D binding "1.5" IPPROTO_RAW
+inline short IPPROTO_RAW = 255;
+#pragma D binding "1.13" IPPROTO_UDPLITE
+inline short IPPROTO_UDPLITE = 136;
+
+inline uint8_t INP_IPV4 = 0x01;
+inline uint8_t INP_IPV6 = 0x02;
+
+#pragma D binding "1.5" protocols
+inline string protocols[int proto] =
+ proto == IPPROTO_IP ? "IP" :
+ proto == IPPROTO_ICMP ? "ICMP" :
+ proto == IPPROTO_IGMP ? "IGMP" :
+ proto == IPPROTO_IPV4 ? "IPV4" :
+ proto == IPPROTO_TCP ? "TCP" :
+ proto == IPPROTO_UDP ? "UDP" :
+ proto == IPPROTO_IPV6 ? "IPV6" :
+ proto == IPPROTO_ROUTING ? "ROUTING" :
+ proto == IPPROTO_FRAGMENT ? "FRAGMENT" :
+ proto == IPPROTO_RSVP ? "RSVP" :
+ proto == IPPROTO_GRE ? "GRE" :
+ proto == IPPROTO_ESP ? "ESP" :
+ proto == IPPROTO_AH ? "AH" :
+ proto == IPPROTO_MOBILE ? "MOBILE" :
+ proto == IPPROTO_ICMPV6 ? "ICMPV6" :
+ proto == IPPROTO_DSTOPTS ? "DSTOPTS" :
+ proto == IPPROTO_ETHERIP ? "ETHERIP" :
+ proto == IPPROTO_PIM ? "PIM" :
+ proto == IPPROTO_IPCOMP ? "IPCOMP" :
+ proto == IPPROTO_SCTP ? "SCTP" :
+ proto == IPPROTO_UDPLITE ? "UDPLITE" :
+ proto == IPPROTO_RAW ? "RAW" :
+ "<unknown>";
+
+/*
+ * This field is always NULL according to the current definition of the ip
+ * probes.
+ */
+#pragma D binding "1.5" translator
+translator pktinfo_t < void *p > {
+ pkt_addr = NULL;
+};
+
+#pragma D binding "1.5" translator
+translator csinfo_t < void *p > {
+ cs_addr = NULL;
+ cs_cid = (uint64_t)p;
+ cs_pid = 0;
+ cs_zoneid = 0;
+};
+
+#pragma D binding "1.6.3" translator
+translator csinfo_t < struct inpcb *p > {
+ cs_addr = NULL;
+ cs_cid = (uint64_t)p;
+ cs_pid = 0; /* XXX */
+ cs_zoneid = 0;
+};
+
+#pragma D binding "1.5" translator
+translator ipinfo_t < uint8_t *p > {
+ ip_ver = p == NULL ? 0 : ((struct ip *)p)->ip_v;
+ ip_plength = p == NULL ? 0 :
+ ((struct ip *)p)->ip_v == 4 ?
+ ntohs(((struct ip *)p)->ip_len) - (((struct ip *)p)->ip_hl << 2):
+ ntohs(((struct ip6_hdr *)p)->ip6_ctlun.ip6_un1.ip6_un1_plen);
+ ip_saddr = p == NULL ? "<unknown>" :
+ ((struct ip *)p)->ip_v == 4 ?
+ inet_ntoa(&((struct ip *)p)->ip_src.s_addr) :
+ inet_ntoa6(&((struct ip6_hdr *)p)->ip6_src);
+ ip_daddr = p == NULL ? "<unknown>" :
+ ((struct ip *)p)->ip_v == 4 ?
+ inet_ntoa(&((struct ip *)p)->ip_dst.s_addr) :
+ inet_ntoa6(&((struct ip6_hdr *)p)->ip6_dst);
+};
+
+#pragma D binding "1.13" translator
+translator ipinfo_t < struct mbuf *m > {
+ ip_ver = m == NULL ? 0 : ((struct ip *)m->m_data)->ip_v;
+ ip_plength = m == NULL ? 0 :
+ ((struct ip *)m->m_data)->ip_v == 4 ?
+ ntohs(((struct ip *)m->m_data)->ip_len) -
+ (((struct ip *)m->m_data)->ip_hl << 2):
+ ntohs(((struct ip6_hdr *)m->m_data)->ip6_ctlun.ip6_un1.ip6_un1_plen);
+ ip_saddr = m == NULL ? "<unknown>" :
+ ((struct ip *)m->m_data)->ip_v == 4 ?
+ inet_ntoa(&((struct ip *)m->m_data)->ip_src.s_addr) :
+ inet_ntoa6(&((struct ip6_hdr *)m->m_data)->ip6_src);
+ ip_daddr = m == NULL ? "<unknown>" :
+ ((struct ip *)m->m_data)->ip_v == 4 ?
+ inet_ntoa(&((struct ip *)m->m_data)->ip_dst.s_addr) :
+ inet_ntoa6(&((struct ip6_hdr *)m->m_data)->ip6_dst);
+};
+
+#pragma D binding "1.5" IFF_LOOPBACK
+inline int IFF_LOOPBACK = 0x8;
+
+#pragma D binding "1.5" translator
+translator ifinfo_t < struct ifnet *p > {
+ if_name = p == NULL ? "<unknown>" : p->if_xname;
+ if_local = p == NULL ? 0 : (p->if_flags & IFF_LOOPBACK) == 0 ? 0 : 1;
+ if_addr = (uintptr_t)p;
+};
+
+#pragma D binding "1.5" translator
+translator ipv4info_t < struct ip *p > {
+ ipv4_ver = p == NULL ? 0 : p->ip_v;
+ ipv4_ihl = p == NULL ? 0 : p->ip_hl;
+ ipv4_tos = p == NULL ? 0 : p->ip_tos;
+ ipv4_length = p == NULL ? 0 : ntohs(p->ip_len);
+ ipv4_ident = p == NULL ? 0 : ntohs(p->ip_id);
+ ipv4_flags = p == NULL ? 0 : (ntohs(p->ip_off) & 0xe000) >> 8;
+ ipv4_offset = p == NULL ? 0 : ntohs(p->ip_off) & 0x1fff;
+ ipv4_ttl = p == NULL ? 0 : p->ip_ttl;
+ ipv4_protocol = p == NULL ? 0 : p->ip_p;
+ ipv4_protostr = p == NULL ? "<null>" : protocols[p->ip_p];
+ ipv4_checksum = p == NULL ? 0 : ntohs(p->ip_sum);
+ ipv4_src = p == NULL ? 0 : (ipaddr_t)ntohl(p->ip_src.s_addr);
+ ipv4_dst = p == NULL ? 0 : (ipaddr_t)ntohl(p->ip_dst.s_addr);
+ ipv4_saddr = p == NULL ? 0 : inet_ntoa(&p->ip_src.s_addr);
+ ipv4_daddr = p == NULL ? 0 : inet_ntoa(&p->ip_dst.s_addr);
+ ipv4_hdr = (ipha_t *)p;
+};
+
+#pragma D binding "1.5" translator
+translator ipv6info_t < struct ip6_hdr *p > {
+ ipv6_ver = p == NULL ? 0 : (ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0xf0000000) >> 28;
+ ipv6_tclass = p == NULL ? 0 : (ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0x0ff00000) >> 20;
+ ipv6_flow = p == NULL ? 0 : ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0x000fffff;
+ ipv6_plen = p == NULL ? 0 : ntohs(p->ip6_ctlun.ip6_un1.ip6_un1_plen);
+ ipv6_nexthdr = p == NULL ? 0 : p->ip6_ctlun.ip6_un1.ip6_un1_nxt;
+ ipv6_nextstr = p == NULL ? "<null>" : protocols[p->ip6_ctlun.ip6_un1.ip6_un1_nxt];
+ ipv6_hlim = p == NULL ? 0 : p->ip6_ctlun.ip6_un1.ip6_un1_hlim;
+ ipv6_src = p == NULL ? 0 : (in6_addr_t *)&p->ip6_src;
+ ipv6_dst = p == NULL ? 0 : (in6_addr_t *)&p->ip6_dst;
+ ipv6_saddr = p == NULL ? 0 : inet_ntoa6(&p->ip6_src);
+ ipv6_daddr = p == NULL ? 0 : inet_ntoa6(&p->ip6_dst);
+ ipv6_hdr = p;
+};
diff --git a/cddl/lib/libdtrace/libproc_compat.h b/cddl/lib/libdtrace/libproc_compat.h
new file mode 100644
index 000000000000..7cdc8af18b56
--- /dev/null
+++ b/cddl/lib/libdtrace/libproc_compat.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Rui Paulo under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * Compatibility functions between Solaris libproc and FreeBSD libproc.
+ * Functions sorted alphabetically.
+ */
+#define PR_LMID_EVERY 0
+#define PGRAB_RDONLY PATTACH_RDONLY
+#define PGRAB_FORCE PATTACH_FORCE
+
+#define Psetrun(p, a1, a2) proc_continue((p))
+#define Pxlookup_by_addr(p, a, n, s, sym, i) \
+ proc_addr2sym(p, a, n, s, sym)
+#define Pxlookup_by_name(p, l, s1, s2, sym, a) \
+ proc_name2sym(p, s1, s2, sym, a)
+#define Paddr_to_map proc_addr2map
+#define Pcreate_error strerror
+#define Pdelbkpt proc_bkptdel
+#define Pgrab_error strerror
+#define Plmid(p, a, l) (-1)
+#define Plmid_to_map(p, l, o) proc_name2map(p, o)
+#define Plookup_by_addr proc_addr2sym
+#define Pname_to_ctf(p, obj) (ctf_file_t *)proc_name2ctf(p, obj)
+#define Pname_to_map proc_name2map
+#define Pobject_iter proc_iter_objs
+#define Pobject_iter_resolved(p, f, arg) proc_iter_objs(p, f, arg)
+#define Pobjname proc_objname
+#define Pread proc_read
+#define Prd_agent proc_rdagent
+#define Prelease proc_detach
+#define Psetbkpt proc_bkptset
+#define Pstate proc_state
+#define Psymbol_iter_by_addr proc_iter_symbyaddr
+#define Pupdate_maps proc_rdagent
+#define Pupdate_syms proc_updatesyms
+#define Pxecbkpt proc_bkptexec
diff --git a/cddl/lib/libdtrace/net.d b/cddl/lib/libdtrace/net.d
new file mode 100644
index 000000000000..fef61ea31f4b
--- /dev/null
+++ b/cddl/lib/libdtrace/net.d
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * The conninfo_t structure should be used by all application protocal
+ * providers as the first arguments to indicate some basic information
+ * about the connection. This structure may be augmented to accomodate
+ * the particularities of additional protocols in the future.
+ */
+typedef struct conninfo {
+ string ci_local; /* local host address */
+ string ci_remote; /* remote host address */
+ string ci_protocol; /* protocol (ipv4, ipv6, etc) */
+} conninfo_t;
diff --git a/cddl/lib/libdtrace/nfs.d b/cddl/lib/libdtrace/nfs.d
new file mode 100644
index 000000000000..4d55b39a809d
--- /dev/null
+++ b/cddl/lib/libdtrace/nfs.d
@@ -0,0 +1,105 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on library net.d
+#pragma D depends_on module kernel
+#pragma D depends_on module nfs
+
+typedef struct nfsv4opinfo {
+ uint64_t noi_xid; /* unique transation ID */
+ cred_t *noi_cred; /* credentials for operation */
+ string noi_curpath; /* current file handle path (if any) */
+} nfsv4opinfo_t;
+
+typedef struct nfsv4cbinfo {
+ string nci_curpath; /* current file handle path (if any) */
+} nfsv4cbinfo_t;
+
+#pragma D binding "1.5" translator
+translator conninfo_t < struct svc_req *P > {
+ ci_protocol = P->rq_xprt->xp_master->xp_netid == "tcp" ? "ipv4" :
+ P->rq_xprt->xp_master->xp_netid == "udp" ? "ipv4" :
+ P->rq_xprt->xp_master->xp_netid == "tcp6" ? "ipv6" :
+ P->rq_xprt->xp_master->xp_netid == "udp6" ? "ipv6" :
+ "<unknown>";
+
+ ci_local = (P->rq_xprt->xp_master->xp_netid == "tcp" ||
+ P->rq_xprt->xp_master->xp_netid == "udp") ?
+ inet_ntoa(&((struct sockaddr_in *)
+ P->rq_xprt->xp_xpc.xpc_lcladdr.buf)->sin_addr.S_un.S_addr) :
+ (P->rq_xprt->xp_master->xp_netid == "tcp6" ||
+ P->rq_xprt->xp_master->xp_netid == "udp6") ?
+ inet_ntoa6(&((struct sockaddr_in6 *)
+ P->rq_xprt->xp_xpc.xpc_lcladdr.buf)->sin6_addr) :
+ "unknown";
+
+ ci_remote = (P->rq_xprt->xp_master->xp_netid == "tcp" ||
+ P->rq_xprt->xp_master->xp_netid == "udp") ?
+ inet_ntoa(&((struct sockaddr_in *)
+ P->rq_xprt->xp_xpc.xpc_rtaddr.buf)->sin_addr.S_un.S_addr) :
+ (P->rq_xprt->xp_master->xp_netid == "tcp6" ||
+ P->rq_xprt->xp_master->xp_netid == "udp6") ?
+ inet_ntoa6(&((struct sockaddr_in6 *)
+ P->rq_xprt->xp_xpc.xpc_rtaddr.buf)->sin6_addr) :
+ "unknown";
+};
+
+#pragma D binding "1.5" translator
+translator conninfo_t < rfs4_client_t *P > {
+ ci_protocol = (P->rc_addr.ss_family == AF_INET) ? "ipv4" : "ipv6";
+
+ ci_local = "<unknown>";
+
+ ci_remote = (P->rc_addr.ss_family == AF_INET) ?
+ inet_ntoa((ipaddr_t *)
+ &((struct sockaddr_in *)&P->rc_addr)->sin_addr) :
+ inet_ntoa6(&((struct sockaddr_in6 *)&P->rc_addr)->sin6_addr);
+};
+
+#pragma D binding "1.5" translator
+translator nfsv4cbinfo_t < rfs4_deleg_state_t *P > {
+ nci_curpath = (P->rds_finfo->rf_vp == NULL) ? "<unknown>" :
+ P->rds_finfo->rf_vp->v_path;
+};
+
+typedef struct nfsv3opinfo {
+ uint64_t noi_xid; /* unique transation ID */
+ cred_t *noi_cred; /* credentials for operation */
+ string noi_curpath; /* current file handle path (if any) */
+} nfsv3opinfo_t;
+
+typedef struct nfsv3oparg nfsv3oparg_t;
+
+#pragma D binding "1.5" translator
+translator nfsv3opinfo_t < nfsv3oparg_t *P > {
+ noi_xid = ((struct svc_req *)arg0)->rq_xprt->xp_xid;
+ noi_cred = (cred_t *)arg1;
+ noi_curpath = (arg2 == 0 || ((vnode_t *)arg2)->v_path == NULL) ?
+ "<unknown>" : ((vnode_t *)arg2)->v_path;
+};
diff --git a/cddl/lib/libdtrace/nfssrv.d b/cddl/lib/libdtrace/nfssrv.d
new file mode 100644
index 000000000000..b5231bf7a2ec
--- /dev/null
+++ b/cddl/lib/libdtrace/nfssrv.d
@@ -0,0 +1,53 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
+ */
+
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on library net.d
+#pragma D depends_on library nfs.d
+#pragma D depends_on module kernel
+#pragma D depends_on module nfssrv
+
+#pragma D binding "1.5" translator
+translator conninfo_t < struct compound_state *P > {
+ ci_protocol = P->req->rq_xprt->xp_master->xp_netid == "tcp" ? "ipv4" :
+ P->req->rq_xprt->xp_master->xp_netid == "tcp6" ? "ipv6" :
+ "<unknown>";
+
+ ci_local = inet_ntoa6(&((conn_t *)P->req->rq_xprt->xp_xpc.
+ xpc_wq->q_next->q_ptr)->connua_v6addr.connua_laddr);
+
+ ci_remote = inet_ntoa6(&((conn_t *)P->req->rq_xprt->xp_xpc.
+ xpc_wq->q_next->q_ptr)->connua_v6addr.connua_faddr);
+};
+
+#pragma D binding "1.5" translator
+translator nfsv4opinfo_t < struct compound_state *P > {
+ noi_xid = P->req->rq_xprt->xp_xid;
+ noi_cred = P->basecr;
+ noi_curpath = (P->vp == NULL) ? "<unknown>" : P->vp->v_path;
+};
diff --git a/cddl/lib/libdtrace/psinfo.d b/cddl/lib/libdtrace/psinfo.d
new file mode 100644
index 000000000000..8dc27e812965
--- /dev/null
+++ b/cddl/lib/libdtrace/psinfo.d
@@ -0,0 +1,97 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006 John Birrell jb@freebsd.org
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D depends_on module kernel
+
+typedef struct psinfo {
+ int pr_nlwp; /* number of threads */
+ pid_t pr_pid; /* unique process id */
+ pid_t pr_ppid; /* process id of parent */
+ pid_t pr_pgid; /* pid of process group leader */
+ pid_t pr_sid; /* session id */
+ uid_t pr_uid; /* real user id */
+ uid_t pr_euid; /* effective user id */
+ gid_t pr_gid; /* real group id */
+ gid_t pr_egid; /* effective group id */
+ uintptr_t
+ pr_addr; /* address of process */
+ string pr_psargs; /* process arguments */
+ u_int pr_arglen; /* process argument length */
+ u_int pr_jailid; /* jail id */
+} psinfo_t;
+
+#pragma D binding "1.0" translator
+translator psinfo_t < struct proc *T > {
+ pr_nlwp = T->p_numthreads;
+ pr_pid = T->p_pid;
+ pr_ppid = (T->p_pptr == 0) ? 0 : T->p_pptr->p_pid;
+ pr_pgid = (T->p_leader == 0) ? 0 : T->p_leader->p_pid;
+ pr_sid = (T->p_pgrp == 0) ? 0 : ((T->p_pgrp->pg_session == 0) ? 0 : T->p_pgrp->pg_session->s_sid);
+ pr_uid = T->p_ucred->cr_ruid;
+ pr_euid = T->p_ucred->cr_uid;
+ pr_gid = T->p_ucred->cr_rgid;
+ pr_egid = T->p_ucred->cr_gid;
+ pr_addr = 0;
+ pr_psargs = (T->p_args == 0) ? "" :
+ memstr(T->p_args->ar_args, ' ', T->p_args->ar_length);
+ pr_arglen = T->p_args->ar_length;
+ pr_jailid = T->p_ucred->cr_prison->pr_id;
+};
+
+typedef struct lwpsinfo {
+ id_t pr_lwpid; /* thread ID. */
+ int pr_flag; /* thread flags. */
+ int pr_pri; /* thread priority. */
+ char pr_state; /* numeric lwp state */
+ char pr_sname; /* printable character for pr_state */
+ short pr_syscall; /* system call number (if in syscall) */
+ uintptr_t
+ pr_addr; /* internal address of lwp */
+ uintptr_t
+ pr_wchan; /* sleep address */
+} lwpsinfo_t;
+
+#pragma D binding "1.0" translator
+translator lwpsinfo_t < struct thread *T > {
+ pr_lwpid = T->td_tid;
+ pr_pri = T->td_priority;
+ pr_flag = T->td_flags;
+ pr_state = 0; /* XXX */
+ pr_sname = '?'; /* XXX */
+ pr_syscall = 0; /* XXX */
+ pr_addr = (uintptr_t)T;
+ pr_wchan = (uintptr_t)T->td_wchan;
+};
+
+inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread->td_proc);
+#pragma D attributes Stable/Stable/Common curpsinfo
+#pragma D binding "1.0" curpsinfo
+
+inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
+#pragma D attributes Stable/Stable/Common curlwpsinfo
+#pragma D binding "1.0" curlwpsinfo
diff --git a/cddl/lib/libdtrace/regs_aarch64.d b/cddl/lib/libdtrace/regs_aarch64.d
new file mode 100644
index 000000000000..7d20b5c546c5
--- /dev/null
+++ b/cddl/lib/libdtrace/regs_aarch64.d
@@ -0,0 +1,74 @@
+/*
+ * SPDX-License-Identifier: CDDL 1.0
+ *
+ * Copyright 2023 Christos Margiolis <christos@FreeBSD.org>
+ */
+
+inline int R_X0 = 0;
+#pragma D binding "1.13" R_X0
+inline int R_X1 = 1;
+#pragma D binding "1.13" R_X1
+inline int R_X2 = 2;
+#pragma D binding "1.13" R_X2
+inline int R_X3 = 3;
+#pragma D binding "1.13" R_X3
+inline int R_X4 = 4;
+#pragma D binding "1.13" R_X4
+inline int R_X5 = 5;
+#pragma D binding "1.13" R_X5
+inline int R_X6 = 6;
+#pragma D binding "1.13" R_X6
+inline int R_X7 = 7;
+#pragma D binding "1.13" R_X7
+inline int R_X8 = 8;
+#pragma D binding "1.13" R_X8
+inline int R_X9 = 9;
+#pragma D binding "1.13" R_X9
+inline int R_X10 = 10;
+#pragma D binding "1.13" R_X10
+inline int R_X11 = 11;
+#pragma D binding "1.13" R_X11
+inline int R_X12 = 12;
+#pragma D binding "1.13" R_X12
+inline int R_X13 = 13;
+#pragma D binding "1.13" R_X13
+inline int R_X14 = 14;
+#pragma D binding "1.13" R_X14
+inline int R_X15 = 15;
+#pragma D binding "1.13" R_X15
+inline int R_X16 = 16;
+#pragma D binding "1.13" R_X16
+inline int R_X17 = 17;
+#pragma D binding "1.13" R_X17
+inline int R_X18 = 18;
+#pragma D binding "1.13" R_X18
+inline int R_X19 = 19;
+#pragma D binding "1.13" R_X19
+inline int R_X20 = 20;
+#pragma D binding "1.13" R_X20
+inline int R_X21 = 21;
+#pragma D binding "1.13" R_X21
+inline int R_X22 = 22;
+#pragma D binding "1.13" R_X22
+inline int R_X23 = 23;
+#pragma D binding "1.13" R_X23
+inline int R_X24 = 24;
+#pragma D binding "1.13" R_X24
+inline int R_X25 = 25;
+#pragma D binding "1.13" R_X25
+inline int R_X26 = 26;
+#pragma D binding "1.13" R_X26
+inline int R_X27 = 27;
+#pragma D binding "1.13" R_X27
+inline int R_X28 = 28;
+#pragma D binding "1.13" R_X28
+inline int R_X29 = 29;
+#pragma D binding "1.13" R_X29
+inline int R_FP= 29;
+#pragma D binding "1.13" R_FP
+inline int R_LR = 30;
+#pragma D binding "1.13" R_LR
+inline int R_SP = 31;
+#pragma D binding "1.13" R_SP
+inline int R_PC = 32;
+#pragma D binding "1.13" R_PC
diff --git a/cddl/lib/libdtrace/regs_riscv.d b/cddl/lib/libdtrace/regs_riscv.d
new file mode 100644
index 000000000000..e8a9667d2efd
--- /dev/null
+++ b/cddl/lib/libdtrace/regs_riscv.d
@@ -0,0 +1,74 @@
+/*
+ * SPDX-License-Identifier: CDDL 1.0
+ *
+ * Copyright 2023 Christos Margiolis <christos@FreeBSD.org>
+ */
+
+inline int R_ZERO = 0;
+#pragma D binding "1.13" R_ZERO
+inline int R_RA = 1;
+#pragma D binding "1.13" R_RA
+inline int R_SP = 2;
+#pragma D binding "1.13" R_SP
+inline int R_GP = 3;
+#pragma D binding "1.13" R_GP
+inline int R_TP = 4;
+#pragma D binding "1.13" R_TP
+inline int R_T0 = 5;
+#pragma D binding "1.13" R_T0
+inline int R_T1 = 6;
+#pragma D binding "1.13" R_T1
+inline int R_T2 = 7;
+#pragma D binding "1.13" R_T2
+inline int R_S0 = 8;
+#pragma D binding "1.13" R_S0
+inline int R_FP = 8;
+#pragma D binding "1.13" R_FP
+inline int R_S1 = 9;
+#pragma D binding "1.13" R_S1
+inline int R_A0 = 10;
+#pragma D binding "1.13" R_A0
+inline int R_A1 = 11;
+#pragma D binding "1.13" R_A1
+inline int R_A2 = 12;
+#pragma D binding "1.13" R_A2
+inline int R_A3 = 13;
+#pragma D binding "1.13" R_A3
+inline int R_A4 = 14;
+#pragma D binding "1.13" R_A4
+inline int R_A5 = 15;
+#pragma D binding "1.13" R_A5
+inline int R_A6 = 16;
+#pragma D binding "1.13" R_A6
+inline int R_A7 = 17;
+#pragma D binding "1.13" R_A7
+inline int R_S2 = 18;
+#pragma D binding "1.13" R_S2
+inline int R_S3 = 19;
+#pragma D binding "1.13" R_S3
+inline int R_S4 = 20;
+#pragma D binding "1.13" R_S4
+inline int R_S5 = 21;
+#pragma D binding "1.13" R_S5
+inline int R_S6 = 22;
+#pragma D binding "1.13" R_S6
+inline int R_S7 = 23;
+#pragma D binding "1.13" R_S7
+inline int R_S8 = 24;
+#pragma D binding "1.13" R_S8
+inline int R_S9 = 25;
+#pragma D binding "1.13" R_S9
+inline int R_S10 = 26;
+#pragma D binding "1.13" R_S10
+inline int R_S11 = 27;
+#pragma D binding "1.13" R_S11
+inline int R_T3 = 28;
+#pragma D binding "1.13" R_T3
+inline int R_T4 = 29;
+#pragma D binding "1.13" R_T4
+inline int R_T5 = 30;
+#pragma D binding "1.13" R_T5
+inline int R_T6 = 31;
+#pragma D binding "1.13" R_T6
+inline int R_PC = 32;
+#pragma D binding "1.13" R_PC
diff --git a/cddl/lib/libdtrace/regs_x86.d b/cddl/lib/libdtrace/regs_x86.d
new file mode 100644
index 000000000000..2e31517fdd8d
--- /dev/null
+++ b/cddl/lib/libdtrace/regs_x86.d
@@ -0,0 +1,116 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2009 Stacey Son sson@FreeBSD.org
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+inline int R_GS = 0;
+#pragma D binding "1.0" R_GS
+inline int R_FS = 1;
+#pragma D binding "1.0" R_FS
+inline int R_ES = 2;
+#pragma D binding "1.0" R_ES
+inline int R_DS = 3;
+#pragma D binding "1.0" R_DS
+
+inline int R_EDI = 4;
+#pragma D binding "1.0" R_EDI
+inline int R_ESI = 5;
+#pragma D binding "1.0" R_ESI
+inline int R_EBP = 6;
+#pragma D binding "1.0" R_EBP
+inline int R_ESP = 7;
+#pragma D binding "1.0" R_ESP
+inline int R_EBX = 8;
+#pragma D binding "1.0" R_EBX
+inline int R_EDX = 9;
+#pragma D binding "1.0" R_EDX
+inline int R_ECX = 10;
+#pragma D binding "1.0" R_ECX
+inline int R_EAX = 11;
+#pragma D binding "1.0" R_EAX
+
+inline int R_TRAPNO = 12;
+#pragma D binding "1.0" R_TRAPNO
+inline int R_ERR = 13;
+#pragma D binding "1.0" R_ERR
+inline int R_EIP = 14;
+#pragma D binding "1.0" R_EIP
+inline int R_CS = 15;
+#pragma D binding "1.0" R_CS
+inline int R_EFL = 16;
+#pragma D binding "1.0" R_EFL
+inline int R_UESP = 17;
+#pragma D binding "1.0" R_UESP
+inline int R_SS = 18;
+#pragma D binding "1.0" R_SS
+
+inline int R_PC = R_EIP;
+#pragma D binding "1.0" R_PC
+inline int R_SP = R_UESP;
+#pragma D binding "1.0" R_SP
+inline int R_PS = R_EFL;
+#pragma D binding "1.0" R_PS
+inline int R_R0 = R_EAX;
+#pragma D binding "1.0" R_R0
+inline int R_R1 = R_EBX;
+#pragma D binding "1.0" R_R1
+
+inline int R_RSP = 18 + 1 + 24;
+#pragma D binding "1.0" R_RSP
+inline int R_RFL = 18 + 1 + 23;
+#pragma D binding "1.0" R_RFL
+inline int R_RIP = 18 + 1 + 21;
+#pragma D binding "1.0" R_RIP
+inline int R_RAX = 18 + 1 + 14;
+#pragma D binding "1.0" R_RAX
+inline int R_RCX = 18 + 1 + 13;
+#pragma D binding "1.0" R_RCX
+inline int R_RDX = 18 + 1 + 12;
+#pragma D binding "1.0" R_RDX
+inline int R_RBX = 18 + 1 + 11;
+#pragma D binding "1.0" R_RBX
+inline int R_RBP = 18 + 1 + 10;
+#pragma D binding "1.0" R_RBP
+inline int R_RSI = 18 + 1 + 9;
+#pragma D binding "1.0" R_RSI
+inline int R_RDI = 18 + 1 + 8;
+#pragma D binding "1.0" R_RDI
+inline int R_R8 = 18 + 1 + 7;
+#pragma D binding "1.0" R_R8
+inline int R_R9 = 18 + 1 + 6;
+#pragma D binding "1.0" R_R9
+inline int R_R10 = 18 + 1 + 5;
+#pragma D binding "1.0" R_R10
+inline int R_R11 = 18 + 1 + 4;
+#pragma D binding "1.0" R_R11
+inline int R_R12 = 18 + 1 + 3;
+#pragma D binding "1.0" R_R12
+inline int R_R13 = 18 + 1 + 2;
+#pragma D binding "1.0" R_R13
+inline int R_R14 = 18 + 1 + 1;
+#pragma D binding "1.0" R_R14
+inline int R_R15 = 18 + 1 + 0;
+#pragma D binding "1.0" R_R15
diff --git a/cddl/lib/libdtrace/sched.d b/cddl/lib/libdtrace/sched.d
new file mode 100644
index 000000000000..7eca118fc428
--- /dev/null
+++ b/cddl/lib/libdtrace/sched.d
@@ -0,0 +1,81 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D depends_on module kernel
+#pragma D depends_on provider sched
+
+struct cpuinfo {
+ processorid_t cpu_id; /* CPU identifier */
+ psetid_t cpu_pset; /* processor set identifier */
+ chipid_t cpu_chip; /* chip identifier */
+ lgrp_id_t cpu_lgrp; /* locality group identifer */
+ processor_info_t cpu_info; /* CPU information */
+};
+
+typedef struct cpuinfo cpuinfo_t;
+
+translator cpuinfo_t < cpu_t *C > {
+ cpu_id = C->cpu_id;
+ cpu_pset = C->cpu_part->cp_id;
+ cpu_chip = C->cpu_physid->cpu_chipid;
+ cpu_lgrp = C->cpu_lpl->lpl_lgrpid;
+ cpu_info = (processor_info_t)C->cpu_type_info;
+};
+
+translator cpuinfo_t < disp_t *D > {
+ cpu_id = D->disp_cpu == NULL ? -1 :
+ xlate <cpuinfo_t> (D->disp_cpu).cpu_id;
+ cpu_pset = D->disp_cpu == NULL ? -1 :
+ xlate <cpuinfo_t> (D->disp_cpu).cpu_pset;
+ cpu_chip = D->disp_cpu == NULL ? -1 :
+ xlate <cpuinfo_t> (D->disp_cpu).cpu_chip;
+ cpu_lgrp = D->disp_cpu == NULL ? -1 :
+ xlate <cpuinfo_t> (D->disp_cpu).cpu_lgrp;
+ cpu_info = D->disp_cpu == NULL ?
+ *((processor_info_t *)dtrace`dtrace_zero) :
+ (processor_info_t)xlate <cpuinfo_t> (D->disp_cpu).cpu_info;
+};
+
+inline cpuinfo_t *curcpu = xlate <cpuinfo_t *> (curthread->t_cpu);
+#pragma D attributes Stable/Stable/Common curcpu
+#pragma D binding "1.0" curcpu
+
+inline processorid_t cpu = curcpu->cpu_id;
+#pragma D attributes Stable/Stable/Common cpu
+#pragma D binding "1.0" cpu
+
+inline psetid_t pset = curcpu->cpu_pset;
+#pragma D attributes Stable/Stable/Common pset
+#pragma D binding "1.0" pset
+
+inline chipid_t chip = curcpu->cpu_chip;
+#pragma D attributes Stable/Stable/Common chip
+#pragma D binding "1.0" chip
+
+inline lgrp_id_t lgrp = curcpu->cpu_lgrp;
+#pragma D attributes Stable/Stable/Common lgrp
+#pragma D binding "1.0" lgrp
diff --git a/cddl/lib/libdtrace/sctp.d b/cddl/lib/libdtrace/sctp.d
new file mode 100644
index 000000000000..ef8c3bcc4a56
--- /dev/null
+++ b/cddl/lib/libdtrace/sctp.d
@@ -0,0 +1,169 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2018 Michael Tuexen <tuexen@FreeBSD.org>
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on library socket.d
+#pragma D depends_on module kernel
+#pragma D depends_on provider sctp
+
+#pragma D binding "1.13" SCTP_STATE_MASK
+inline int32_t SCTP_STATE_MASK = 0x0000007f;
+#pragma D binding "1.13" SCTP_STATE_SHUTDOWN_PENDING
+inline int32_t SCTP_STATE_SHUTDOWN_PENDING = 0x00000080;
+#pragma D binding "1.13" SCTP_STATE_CLOSED_SOCKET
+inline int32_t SCTP_STATE_CLOSED_SOCKET = 0x00000100;
+#pragma D binding "1.13" SCTP_STATE_ABOUT_TO_BE_FREED
+inline int32_t SCTP_STATE_ABOUT_TO_BE_FREED = 0x00000200;
+#pragma D binding "1.13" SCTP_STATE_ABOUT_TO_BE_FREED
+inline int32_t SCTP_STATE_PARTIAL_MSG_LEFT = 0x00000400;
+#pragma D binding "1.13" SCTP_STATE_PARTIAL_MSG_LEFT
+inline int32_t SCTP_STATE_WAS_ABORTED = 0x00000800;
+#pragma D binding "1.13" SCTP_STATE_IN_ACCEPT_QUEUE
+inline int32_t SCTP_STATE_IN_ACCEPT_QUEUE = 0x00001000;
+#pragma D binding "1.13" SCTP_STATE_BOUND
+inline int32_t SCTP_STATE_BOUND = 0x00001000;
+#pragma D binding "1.13" SCTP_STATE_EMPTY
+inline int32_t SCTP_STATE_EMPTY = 0x00000000;
+#pragma D binding "1.13" SCTP_STATE_CLOSED
+inline int32_t SCTP_STATE_CLOSED = 0x00000000;
+#pragma D binding "1.13" SCTP_STATE_INUSE
+inline int32_t SCTP_STATE_INUSE = 0x00000001;
+#pragma D binding "1.13" SCTP_STATE_COOKIE_WAIT
+inline int32_t SCTP_STATE_COOKIE_WAIT = 0x00000002;
+#pragma D binding "1.13" SCTP_STATE_COOKIE_ECHOED
+inline int32_t SCTP_STATE_COOKIE_ECHOED = 0x00000004;
+#pragma D binding "1.13" SCTP_STATE_ESTABLISHED
+inline int32_t SCTP_STATE_ESTABLISHED = 0x00000008;
+#pragma D binding "1.13" SCTP_STATE_OPEN
+inline int32_t SCTP_STATE_OPEN = 0x00000008;
+#pragma D binding "1.13" SCTP_STATE_SHUTDOWN_SENT
+inline int32_t SCTP_STATE_SHUTDOWN_SENT = 0x00000010;
+#pragma D binding "1.13" SCTP_STATE_SHUTDOWN_RECEIVED
+inline int32_t SCTP_STATE_SHUTDOWN_RECEIVED = 0x00000020;
+#pragma D binding "1.13" SCTP_STATE_SHUTDOWN_ACK_SENT
+inline int32_t SCTP_STATE_SHUTDOWN_ACK_SENT = 0x00000040;
+
+/* SCTP association state strings. */
+#pragma D binding "1.13" sctp_state_string
+inline string sctp_state_string[int32_t state] =
+ state & SCTP_STATE_ABOUT_TO_BE_FREED ? "state-closed" :
+ state & SCTP_STATE_SHUTDOWN_PENDING ? "state-shutdown-pending" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_EMPTY ? "state-closed" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_INUSE ? "state-closed" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_COOKIE_WAIT ? "state-cookie-wait" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_COOKIE_ECHOED ? "state-cookie-echoed" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_OPEN ? "state-established" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_SENT ? "state-shutdown-sent" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_RECEIVED ? "state-shutdown-received" :
+ (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_ACK_SENT ? "state-shutdown-ack-sent" :
+ "<unknown>";
+
+/*
+ * sctpsinfo contains stable SCTP details.
+ */
+typedef struct sctpsinfo {
+ uintptr_t sctps_addr; /* pointer to struct sctp_tcb */
+ int sctps_num_raddrs; /* number of remote addresses */
+ uintptr_t sctps_raddrs; /* pointer to struct sctp_nets */
+ int sctps_num_laddrs; /* number of local addresses */
+ uintptr_t sctps_laddrs; /* pointer to struct sctp_laddr */
+ uint16_t sctps_lport; /* local port */
+ uint16_t sctps_rport; /* remote port */
+ string sctps_laddr; /* local address, as a string */
+ string sctps_raddr; /* remote address, as a string */
+ int32_t sctps_state;
+} sctpsinfo_t;
+
+/*
+ * sctplsinfo provides the old SCTP state for state changes.
+ */
+typedef struct sctplsinfo {
+ int32_t sctps_state; /* previous SCTP state */
+} sctplsinfo_t;
+
+/*
+ * sctpinfo is the SCTP header fields.
+ */
+typedef struct sctpinfo {
+ uint16_t sctp_sport; /* source port */
+ uint16_t sctp_dport; /* destination port */
+ uint32_t sctp_verify; /* verification tag */
+ uint32_t sctp_checksum; /* CRC32C of the SCTP packet */
+ struct sctphdr *sctp_hdr; /* raw SCTP header */
+} sctpinfo_t;
+
+#pragma D binding "1.13" translator
+translator csinfo_t < struct sctp_tcb *p > {
+ cs_addr = NULL;
+ cs_cid = (uint64_t)p;
+ cs_pid = 0;
+ cs_zoneid = 0;
+};
+
+#pragma D binding "1.13" translator
+translator sctpsinfo_t < struct sctp_tcb *p > {
+ sctps_addr = (uintptr_t)p;
+ sctps_num_raddrs = p == NULL ? -1 : p->asoc.numnets;
+ sctps_raddrs = p == NULL ? NULL : (uintptr_t)(p->asoc.nets.tqh_first);
+ sctps_num_laddrs = p == NULL ? -1 :
+ p->sctp_ep == NULL ? -1 :
+ p->sctp_ep->laddr_count;
+ sctps_laddrs = p == NULL ? NULL :
+ p->sctp_ep == NULL ? NULL :
+ (uintptr_t)(p->sctp_ep->sctp_addr_list.lh_first);
+ sctps_lport = p == NULL ? 0 :
+ p->sctp_ep == NULL ? 0 :
+ ntohs(p->sctp_ep->ip_inp.inp.inp_inc.inc_ie.ie_lport);
+ sctps_rport = p == NULL ? 0 : ntohs(p->rport);
+ sctps_laddr = p == NULL ? "<unknown>" :
+ p->asoc.primary_destination == NULL ? "<unknown>" :
+ p->asoc.primary_destination->ro._s_addr == NULL ? "<unknown>" :
+ p->asoc.primary_destination->ro._s_addr->address.sa.sa_family == AF_INET ?
+ inet_ntoa(&p->asoc.primary_destination->ro._s_addr->address.sin.sin_addr.s_addr) :
+ p->asoc.primary_destination->ro._s_addr->address.sa.sa_family == AF_INET6 ?
+ inet_ntoa6(&p->asoc.primary_destination->ro._s_addr->address.sin6.sin6_addr) :
+ "<unknown>";
+ sctps_raddr = p == NULL ? "<unknown>" :
+ p->asoc.primary_destination == NULL ? "<unknown>" :
+ p->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET ?
+ inet_ntoa(&p->asoc.primary_destination->ro._l_addr.sin.sin_addr.s_addr) :
+ p->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET6 ?
+ inet_ntoa6(&p->asoc.primary_destination->ro._l_addr.sin6.sin6_addr) :
+ "<unknown>";
+ sctps_state = p == NULL ? SCTP_STATE_CLOSED : p->asoc.state;
+};
+
+#pragma D binding "1.13" translator
+translator sctpinfo_t < struct sctphdr *p > {
+ sctp_sport = p == NULL ? 0 : ntohs(p->src_port);
+ sctp_dport = p == NULL ? 0 : ntohs(p->dest_port);
+ sctp_verify = p == NULL ? 0 : ntohl(p->v_tag);
+ sctp_checksum = p == NULL ? 0 : ntohl(p->checksum);
+ sctp_hdr = p;
+};
+
+#pragma D binding "1.13" translator
+translator sctplsinfo_t < int state > {
+ sctps_state = state;
+};
diff --git a/cddl/lib/libdtrace/siftr.d b/cddl/lib/libdtrace/siftr.d
new file mode 100644
index 000000000000..bca3a0f0df7f
--- /dev/null
+++ b/cddl/lib/libdtrace/siftr.d
@@ -0,0 +1,108 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on module kernel
+#pragma D depends_on module siftr
+#pragma D depends_on provider tcp
+
+/*
+ * Convert a SIFTR direction value to a string
+ */
+#pragma D binding "1.12.1" SIFTR_IN
+inline int SIFTR_IN = 0;
+#pragma D binding "1.12.1" SIFTR_OUT
+inline int SIFTR_OUT = 1;
+
+/* SIFTR direction strings. */
+#pragma D binding "1.12.1" siftr_dir_string
+inline string siftr_dir_string[uint8_t direction] =
+ direction == SIFTR_IN ? "in" :
+ direction == SIFTR_OUT ? "out" :
+ "unknown" ;
+
+typedef struct siftrinfo {
+ struct timeval tval;
+ uint8_t direction;
+ uint8_t ipver;
+ uint16_t lport;
+ uint16_t rport;
+ string laddr;
+ string raddr;
+ uint32_t snd_cwnd;
+ uint32_t snd_wnd;
+ uint32_t rcv_wnd;
+ uint32_t t_flags2;
+ uint32_t snd_ssthresh;
+ int conn_state;
+ uint32_t mss;
+ uint32_t srtt;
+ u_char sack_enabled;
+ u_char snd_scale;
+ u_char rcv_scale;
+ u_int t_flags;
+ uint32_t rto;
+ u_int snd_buf_hiwater;
+ u_int snd_buf_cc;
+ u_int rcv_buf_hiwater;
+ u_int rcv_buf_cc;
+ u_int sent_inflight_bytes;
+ int t_segqlen;
+ u_int flowid;
+ u_int flowtype;
+} siftrinfo_t;
+
+#pragma D binding "1.12.1" translator
+translator siftrinfo_t < struct pkt_node *p > {
+ direction = p == NULL ? 0 : p->direction;
+ ipver = p == NULL ? 0 : p->ipver;
+ lport = p == NULL ? 0 : ntohs(p->lport);
+ rport = p == NULL ? 0 : ntohs(p->fport);
+ laddr = p == NULL ? "<unknown>" :
+ p->ipver == INP_IPV4 ?
+ inet_ntoa(&p->laddr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->laddr.id6_addr);
+ raddr = p == NULL ? "<unknown>" :
+ p->ipver == INP_IPV4 ?
+ inet_ntoa(&p->faddr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->faddr.id6_addr);
+ snd_cwnd = p == NULL ? 0 : p->snd_cwnd;
+ snd_wnd = p == NULL ? 0 : p->snd_wnd;
+ rcv_wnd = p == NULL ? 0 : p->rcv_wnd;
+ t_flags2 = p == NULL ? 0 : p->t_flags2;
+ snd_ssthresh = p == NULL ? 0 : p->snd_ssthresh;
+ conn_state = p == NULL ? 0 : p->conn_state;
+ mss = p == NULL ? 0 : p->mss;
+ srtt = p == NULL ? 0 : p->srtt;
+ sack_enabled = p == NULL ? 0 : p->sack_enabled;
+ snd_scale = p == NULL ? 0 : p->snd_scale;
+ rcv_scale = p == NULL ? 0 : p->rcv_scale;
+ t_flags = p == NULL ? 0 : p->t_flags;
+ rto = p == NULL ? 0 : p->rto;
+ snd_buf_hiwater = p == NULL ? 0 : p->snd_buf_hiwater;
+ snd_buf_cc = p == NULL ? 0 : p->snd_buf_cc;
+ rcv_buf_hiwater = p == NULL ? 0 : p->rcv_buf_hiwater;
+ rcv_buf_cc = p == NULL ? 0 : p->rcv_buf_cc;
+ sent_inflight_bytes = p == NULL ? 0 : p->sent_inflight_bytes;
+ t_segqlen = p == NULL ? 0 : p->t_segqlen;
+ flowid = p == NULL ? 0 : p->flowid;
+ flowtype = p == NULL ? 0 : p->flowtype;
+};
diff --git a/cddl/lib/libdtrace/signal.d b/cddl/lib/libdtrace/signal.d
new file mode 100644
index 000000000000..0f9b2567cc0d
--- /dev/null
+++ b/cddl/lib/libdtrace/signal.d
@@ -0,0 +1,151 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Portions Copyright 2008 John Birrell jb@freebsd.org
+ * Portions Copyright 2018 Devin Teske dteske@freebsd.org
+ */
+
+inline int SIGHUP = 1;
+#pragma D binding "1.0" SIGHUP
+inline int SIGINT = 2;
+#pragma D binding "1.0" SIGINT
+inline int SIGQUIT = 3;
+#pragma D binding "1.0" SIGQUIT
+inline int SIGILL = 4;
+#pragma D binding "1.0" SIGILL
+inline int SIGTRAP = 5;
+#pragma D binding "1.0" SIGTRAP
+inline int SIGABRT = 6;
+#pragma D binding "1.0" SIGABRT
+inline int SIGEMT = 7;
+#pragma D binding "1.0" SIGEMT
+inline int SIGFPE = 8;
+#pragma D binding "1.0" SIGFPE
+inline int SIGKILL = 9;
+#pragma D binding "1.0" SIGKILL
+inline int SIGBUS = 10;
+#pragma D binding "1.0" SIGBUS
+inline int SIGSEGV = 11;
+#pragma D binding "1.0" SIGSEGV
+inline int SIGSYS = 12;
+#pragma D binding "1.0" SIGSYS
+inline int SIGPIPE = 13;
+#pragma D binding "1.0" SIGPIPE
+inline int SIGALRM = 14;
+#pragma D binding "1.0" SIGALRM
+inline int SIGTERM = 15;
+#pragma D binding "1.0" SIGTERM
+inline int SIGURG = 16;
+#pragma D binding "1.0" SIGURG
+inline int SIGSTOP = 17;
+#pragma D binding "1.0" SIGSTOP
+inline int SIGTSTP = 18;
+#pragma D binding "1.0" SIGTSTP
+inline int SIGCONT = 19;
+#pragma D binding "1.0" SIGCONT
+inline int SIGCHLD = 20;
+#pragma D binding "1.0" SIGCHLD
+inline int SIGTTIN = 21;
+#pragma D binding "1.0" SIGTTIN
+inline int SIGTTOU = 22;
+#pragma D binding "1.0" SIGTTOU
+inline int SIGIO = 23;
+#pragma D binding "1.0" SIGIO
+inline int SIGXCPU = 24;
+#pragma D binding "1.0" SIGXCPU
+inline int SIGXFSZ = 25;
+#pragma D binding "1.0" SIGXFSZ
+inline int SIGVTALRM = 26;
+#pragma D binding "1.0" SIGVTALRM
+inline int SIGPROF = 27;
+#pragma D binding "1.0" SIGPROF
+inline int SIGWINCH = 28;
+#pragma D binding "1.0" SIGWINCH
+inline int SIGINFO = 29;
+#pragma D binding "1.0" SIGINFO
+inline int SIGUSR1 = 30;
+#pragma D binding "1.0" SIGUSR1
+inline int SIGUSR2 = 31;
+#pragma D binding "1.0" SIGUSR2
+inline int SIGTHR = 32;
+#pragma D binding "1.13" SIGTHR
+inline int SIGLIBRT = 33;
+#pragma D binding "1.13" SIGLIBRT
+
+#pragma D binding "1.13" signal_string
+inline string signal_string[int signal] =
+ signal == SIGHUP ? "SIGHUP" :
+ signal == SIGINT ? "SIGINT" :
+ signal == SIGQUIT ? "SIGQUIT" :
+ signal == SIGILL ? "SIGILL":
+ signal == SIGTRAP ? "SIGTRAP" :
+ signal == SIGABRT ? "SIGABRT" :
+ signal == SIGEMT ? "SIGEMT" :
+ signal == SIGFPE ? "SIGFPE" :
+ signal == SIGKILL ? "SIGKILL" :
+ signal == SIGBUS ? "SIGBUS" :
+ signal == SIGSEGV ? "SIGSEGV" :
+ signal == SIGSYS ? "SIGSYS" :
+ signal == SIGPIPE ? "SIGPIPE" :
+ signal == SIGALRM ? "SIGALRM" :
+ signal == SIGTERM ? "SIGTERM" :
+ signal == SIGURG ? "SIGURG" :
+ signal == SIGSTOP ? "SIGSTOP" :
+ signal == SIGTSTP ? "SIGTSTP" :
+ signal == SIGCONT ? "SIGCONT" :
+ signal == SIGCHLD ? "SIGCHLD" :
+ signal == SIGTTIN ? "SIGTTIN" :
+ signal == SIGTTOU ? "SIGTTOU" :
+ signal == SIGIO ? "SIGIO" :
+ signal == SIGXCPU ? "SIGXCPU" :
+ signal == SIGXFSZ ? "SIGXFSZ" :
+ signal == SIGVTALRM ? "SIGVTALRM" :
+ signal == SIGPROF ? "SIGPROF" :
+ signal == SIGWINCH ? "SIGWINCH" :
+ signal == SIGINFO ? "SIGINFO" :
+ signal == SIGUSR1 ? "SIGUSR1" :
+ signal == SIGUSR2 ? "SIGUSR2" :
+ signal == SIGTHR ? "SIGTHR" :
+ signal == SIGLIBRT ? "SIGLIBRT" :
+ "UNKNOWN";
+
+inline int CLD_EXITED = 1;
+#pragma D binding "1.0" CLD_EXITED
+inline int CLD_KILLED = 2;
+#pragma D binding "1.0" CLD_KILLED
+inline int CLD_DUMPED = 3;
+#pragma D binding "1.0" CLD_DUMPED
+inline int CLD_TRAPPED = 4;
+#pragma D binding "1.0" CLD_TRAPPED
+inline int CLD_STOPPED = 5;
+#pragma D binding "1.0" CLD_STOPPED
+inline int CLD_CONTINUED = 6;
+#pragma D binding "1.0" CLD_CONTINUED
+
+#pragma D binding "1.13" child_signal_string
+inline string child_signal_string[int child_signal] =
+ child_signal == CLD_EXITED ? "child exited" :
+ child_signal == CLD_KILLED ? "child terminated abnormally" :
+ child_signal == CLD_DUMPED ? "child core dumped" :
+ child_signal == CLD_TRAPPED ? "traced child trapped" :
+ child_signal == CLD_STOPPED ? "child stopped" :
+ child_signal == CLD_CONTINUED ? "stopped child continued" :
+ strjoin("unknown SIGCHLD code (", strjoin(lltostr(child_signal), ")"));
diff --git a/cddl/lib/libdtrace/socket.d b/cddl/lib/libdtrace/socket.d
new file mode 100644
index 000000000000..c8161f9b2d30
--- /dev/null
+++ b/cddl/lib/libdtrace/socket.d
@@ -0,0 +1,299 @@
+/*
+ * Copyright (c) 2017 George V. Neville-Neil
+ * 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.
+ *
+ * Translators and flags for the socket structure. FreeBSD specific code.
+ */
+
+#pragma D depends_on module kernel
+
+/*
+ * Option flags per-socket.
+ */
+#pragma D binding "1.13" SO_DEBUG
+inline int SO_DEBUG = 0x0001; /* turn on debugging info recording */
+#pragma D binding "1.13" SO_ACCEPTCONN
+inline int SO_ACCEPTCONN = 0x0002; /* socket has had listen() */
+#pragma D binding "1.13" SO_REUSEADDR
+inline int SO_REUSEADDR = 0x0004; /* allow local address reuse */
+#pragma D binding "1.13" SO_KEEPALIVE
+inline int SO_KEEPALIVE = 0x0008; /* keep connections alive */
+#pragma D binding "1.13" SO_DONTROUTE
+inline int SO_DONTROUTE = 0x0010; /* just use interface addresses */
+#pragma D binding "1.13" SO_BROADCAST
+inline int SO_BROADCAST = 0x0020; /* permit sending of broadcast msgs */
+#pragma D binding "1.13" SO_USELOOPBACK
+inline int SO_USELOOPBACK = 0x0040; /* bypass hardware when possible */
+#pragma D binding "1.13" SO_LINGER
+inline int SO_LINGER = 0x0080; /* linger on close if data present */
+#pragma D binding "1.13" SO_OOBINLINE
+inline int SO_OOBINLINE = 0x0100; /* leave received OOB data in line */
+#pragma D binding "1.13" SO_REUSEPORT
+inline int SO_REUSEPORT = 0x0200; /* allow local address & port reuse */
+#pragma D binding "1.13" SO_TIMESTAMP
+inline int SO_TIMESTAMP = 0x0400; /* timestamp received dgram traffic */
+#pragma D binding "1.13" SO_NOSIGPIPE
+inline int SO_NOSIGPIPE = 0x0800; /* no SIGPIPE from EPIPE */
+#pragma D binding "1.13" SO_ACCEPTFILTER
+inline int SO_ACCEPTFILTER = 0x1000; /* there is an accept filter */
+#pragma D binding "1.13" SO_BINTIME
+inline int SO_BINTIME = 0x2000; /* timestamp received dgram traffic */
+#pragma D binding "1.13" SO_NO_OFFLOAD
+inline int SO_NO_OFFLOAD = 0x4000; /* socket cannot be offloaded */
+#pragma D binding "1.13" SO_NO_DDP
+inline int SO_NO_DDP = 0x8000; /* disable direct data placement */
+
+/*
+ * Additional options, not kept in so_options.
+ */
+#pragma D binding "1.13" SO_SNDBUF
+inline int SO_SNDBUF = 0x1001; /* send buffer size */
+#pragma D binding "1.13" SO_RCVBUF
+inline int SO_RCVBUF = 0x1002; /* receive buffer size */
+#pragma D binding "1.13" SO_SNDLOWAT
+inline int SO_SNDLOWAT = 0x1003; /* send low-water mark */
+#pragma D binding "1.13" SO_RCVLOWAT
+inline int SO_RCVLOWAT = 0x1004; /* receive low-water mark */
+#pragma D binding "1.13" SO_SNDTIMEO
+inline int SO_SNDTIMEO = 0x1005; /* send timeout */
+#pragma D binding "1.13" SO_RCVTIMEO
+inline int SO_RCVTIMEO = 0x1006; /* receive timeout */
+#pragma D binding "1.13" SO_ERROR
+inline int SO_ERROR = 0x1007; /* get error status and clear */
+#pragma D binding "1.13" SO_TYPE
+inline int SO_TYPE = 0x1008; /* get socket type */
+#pragma D binding "1.13" SO_LABEL
+inline int SO_LABEL = 0x1009; /* socket's MAC label */
+#pragma D binding "1.13" SO_PEERLABEL
+inline int SO_PEERLABEL = 0x1010; /* socket's peer's MAC label */
+#pragma D binding "1.13" SO_LISTENQLIMIT
+inline int SO_LISTENQLIMIT = 0x1011; /* socket's backlog limit */
+#pragma D binding "1.13" SO_LISTENQLEN
+inline int SO_LISTENQLEN = 0x1012; /* socket's complete queue length */
+#pragma D binding "1.13" SO_LISTENINCQLEN
+inline int SO_LISTENINCQLEN = 0x1013; /* socket's incomplete queue length */
+#pragma D binding "1.13" SO_SETFIB
+inline int SO_SETFIB = 0x1014; /* use this FIB to route */
+#pragma D binding "1.13" SO_USER_COOKIE
+inline int SO_USER_COOKIE = 0x1015; /* user cookie (dummynet etc.) */
+#pragma D binding "1.13" SO_PROTOCOL
+inline int SO_PROTOCOL = 0x1016; /* get socket protocol (Linux name) */
+#pragma D binding "1.13" SO_PROTOTYPE
+inline int SO_PROTOTYPE = SO_PROTOCOL; /* alias for SO_PROTOCOL (SunOS name) */
+#pragma D binding "1.13" SO_TS_CLOCK
+inline int SO_TS_CLOCK = 0x1017; /* clock type used for SO_TIMESTAMP */
+#pragma D binding "1.13" SO_MAX_PACING_RATE
+inline int SO_MAX_PACING_RATE = 0x1018; /* socket's max TX pacing rate (Linux name) */
+
+#pragma D binding "1.13" SO_TS_REALTIME_MICRO
+inline int SO_TS_REALTIME_MICRO = 0; /* microsecond resolution, realtime */
+#pragma D binding "1.13" SO_TS_BINTIME
+inline int SO_TS_BINTIME = 1; /* sub-nanosecond resolution, realtime */
+#pragma D binding "1.13" SO_TS_REALTIME
+inline int SO_TS_REALTIME = 2; /* nanosecond resolution, realtime */
+#pragma D binding "1.13" SO_TS_MONOTONIC
+inline int SO_TS_MONOTONIC = 3; /* nanosecond resolution, monotonic */
+#pragma D binding "1.13" SO_TS_DEFAULT
+inline int SO_TS_DEFAULT = SO_TS_REALTIME_MICRO;
+#pragma D binding "1.13" SO_TS_CLOCK_MAX
+inline int SO_TS_CLOCK_MAX = SO_TS_MONOTONIC;
+
+#pragma D binding "1.13" AF_UNSPEC
+inline int AF_UNSPEC = 0; /* unspecified */
+#pragma D binding "1.13" AF_UNIX
+inline int AF_UNIX = 1; /* standardized name for AF_LOCAL */
+#pragma D binding "1.13" AF_LOCAL
+inline int AF_LOCAL = AF_UNIX; /* local to host (pipes, portals) */
+#pragma D binding "1.13" AF_INET
+inline int AF_INET = 2; /* internetwork: UDP, TCP, etc. */
+#pragma D binding "1.13" AF_IMPLINK
+inline int AF_IMPLINK = 3; /* arpanet imp addresses */
+#pragma D binding "1.13" AF_PUP
+inline int AF_PUP = 4; /* pup protocols: e.g. BSP */
+#pragma D binding "1.13" AF_CHAOS
+inline int AF_CHAOS = 5; /* mit CHAOS protocols */
+#pragma D binding "1.13" AF_NETBIOS
+inline int AF_NETBIOS = 6; /* SMB protocols */
+#pragma D binding "1.13" AF_ISO
+inline int AF_ISO = 7; /* ISO protocols */
+#pragma D binding "1.13" AF_OSI
+inline int AF_OSI = AF_ISO;
+#pragma D binding "1.13" AF_ECMA
+inline int AF_ECMA = 8; /* European computer manufacturers */
+#pragma D binding "1.13" AF_DATAKIT
+inline int AF_DATAKIT = 9; /* datakit protocols */
+#pragma D binding "1.13" AF_CCITT
+inline int AF_CCITT = 10; /* CCITT protocols, X.25 etc */
+#pragma D binding "1.13" AF_SNA
+inline int AF_SNA = 11; /* IBM SNA */
+#pragma D binding "1.13" AF_DECnet
+inline int AF_DECnet = 12; /* DECnet */
+#pragma D binding "1.13" AF_DLI
+inline int AF_DLI = 13; /* DEC Direct data link interface */
+#pragma D binding "1.13" AF_LAT
+inline int AF_LAT = 14; /* LAT */
+#pragma D binding "1.13" AF_HYLINK
+inline int AF_HYLINK = 15; /* NSC Hyperchannel */
+#pragma D binding "1.13" AF_APPLETALK
+inline int AF_APPLETALK = 16; /* Apple Talk */
+#pragma D binding "1.13" AF_ROUTE
+inline int AF_ROUTE = 17; /* Internal Routing Protocol */
+#pragma D binding "1.13" AF_LINK
+inline int AF_LINK = 18; /* Link layer interface */
+#pragma D binding "1.13" pseudo_AF_XTP
+inline int pseudo_AF_XTP = 19; /* eXpress Transfer Protocol (no AF) */
+#pragma D binding "1.13" AF_COIP
+inline int AF_COIP = 20; /* connection-oriented IP, aka ST II */
+#pragma D binding "1.13" AF_CNT
+inline int AF_CNT = 21; /* Computer Network Technology */
+#pragma D binding "1.13" pseudo_AF_RTIP
+inline int pseudo_AF_RTIP = 22; /* Help Identify RTIP packets */
+#pragma D binding "1.13" AF_IPX
+inline int AF_IPX = 23; /* Novell Internet Protocol */
+#pragma D binding "1.13" AF_SIP
+inline int AF_SIP = 24; /* Simple Internet Protocol */
+#pragma D binding "1.13" pseudo_AF_PIP
+inline int pseudo_AF_PIP = 25; /* Help Identify PIP packets */
+#pragma D binding "1.13" AF_ISDN
+inline int AF_ISDN = 26; /* Integrated Services Digital Network*/
+#pragma D binding "1.13" AF_E164
+inline int AF_E164 = AF_ISDN; /* CCITT E.164 recommendation */
+#pragma D binding "1.13" pseudo_AF_KEY
+inline int pseudo_AF_KEY = 27; /* Internal key-management function */
+#pragma D binding "1.13" AF_INET6
+inline int AF_INET6 = 28; /* IPv6 */
+#pragma D binding "1.13" AF_NATM
+inline int AF_NATM = 29; /* native ATM access */
+#pragma D binding "1.13" AF_ATM
+inline int AF_ATM = 30; /* ATM */
+#pragma D binding "1.13" pseudo_AF_HDRCMPLT
+inline int pseudo_AF_HDRCMPLT = 31; /* Used by BPF to not rewrite headers
+ * in interface output routine
+ */
+#pragma D binding "1.13" AF_NETGRAPH
+inline int AF_NETGRAPH = 32; /* Netgraph sockets */
+#pragma D binding "1.13" AF_SLOW
+inline int AF_SLOW = 33; /* 802.3ad slow protocol */
+#pragma D binding "1.13" AF_SCLUSTER
+inline int AF_SCLUSTER = 34; /* Sitara cluster protocol */
+#pragma D binding "1.13" AF_ARP
+inline int AF_ARP = 35; /* Address Resolution Protocol */
+#pragma D binding "1.13" AF_BLUETOOTH
+inline int AF_BLUETOOTH = 36; /* Bluetooth sockets */
+#pragma D binding "1.13" AF_IEEE80211
+inline int AF_IEEE80211 = 37; /* IEEE 802.11 protocol */
+#pragma D binding "1.13" AF_INET_SDP
+inline int AF_INET_SDP = 40; /* OFED Socket Direct Protocol ipv4 */
+#pragma D binding "1.13" AF_INET6_SDP
+inline int AF_INET6_SDP = 42; /* OFED Socket Direct Protocol ipv6 */
+#pragma D binding "1.13" AF_MAX
+inline int AF_MAX = 42;
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#pragma D binding "1.13" PF_UNSPEC
+inline int PF_UNSPEC = AF_UNSPEC;
+#pragma D binding "1.13" PF_LOCAL
+inline int PF_LOCAL = AF_LOCAL;
+#pragma D binding "1.13" PF_UNIX
+inline int PF_UNIX = PF_LOCAL; /* backward compatibility */
+#pragma D binding "1.13" PF_INET
+inline int PF_INET = AF_INET;
+#pragma D binding "1.13" PF_IMPLINK
+inline int PF_IMPLINK = AF_IMPLINK;
+#pragma D binding "1.13" PF_PUP
+inline int PF_PUP = AF_PUP;
+#pragma D binding "1.13" PF_CHAOS
+inline int PF_CHAOS = AF_CHAOS;
+#pragma D binding "1.13" PF_NETBIOS
+inline int PF_NETBIOS = AF_NETBIOS;
+#pragma D binding "1.13" PF_ISO
+inline int PF_ISO = AF_ISO;
+#pragma D binding "1.13" PF_OSI
+inline int PF_OSI = AF_ISO;
+#pragma D binding "1.13" PF_ECMA
+inline int PF_ECMA = AF_ECMA;
+#pragma D binding "1.13" PF_DATAKIT
+inline int PF_DATAKIT = AF_DATAKIT;
+#pragma D binding "1.13" PF_CCITT
+inline int PF_CCITT = AF_CCITT;
+#pragma D binding "1.13" PF_SNA
+inline int PF_SNA = AF_SNA;
+#pragma D binding "1.13" PF_DECnet
+inline int PF_DECnet = AF_DECnet;
+#pragma D binding "1.13" PF_DLI
+inline int PF_DLI = AF_DLI;
+#pragma D binding "1.13" PF_LAT
+inline int PF_LAT = AF_LAT;
+#pragma D binding "1.13" PF_HYLINK
+inline int PF_HYLINK = AF_HYLINK;
+#pragma D binding "1.13" PF_APPLETALK
+inline int PF_APPLETALK = AF_APPLETALK;
+#pragma D binding "1.13" PF_ROUTE
+inline int PF_ROUTE = AF_ROUTE;
+#pragma D binding "1.13" PF_LINK
+inline int PF_LINK = AF_LINK;
+#pragma D binding "1.13" PF_XTP
+inline int PF_XTP = pseudo_AF_XTP; /* really just proto family, no AF */
+#pragma D binding "1.13" PF_COIP
+inline int PF_COIP = AF_COIP;
+#pragma D binding "1.13" PF_CNT
+inline int PF_CNT = AF_CNT;
+#pragma D binding "1.13" PF_SIP
+inline int PF_SIP = AF_SIP;
+#pragma D binding "1.13" PF_IPX
+inline int PF_IPX = AF_IPX;
+#pragma D binding "1.13" PF_RTIP
+inline int PF_RTIP = pseudo_AF_RTIP; /* same format as AF_INET */
+#pragma D binding "1.13" PF_PIP
+inline int PF_PIP = pseudo_AF_PIP;
+#pragma D binding "1.13" PF_ISDN
+inline int PF_ISDN = AF_ISDN;
+#pragma D binding "1.13" PF_KEY
+inline int PF_KEY = pseudo_AF_KEY;
+#pragma D binding "1.13" PF_INET6
+inline int PF_INET6 = AF_INET6;
+#pragma D binding "1.13" PF_NATM
+inline int PF_NATM = AF_NATM;
+#pragma D binding "1.13" PF_ATM
+inline int PF_ATM = AF_ATM;
+#pragma D binding "1.13" PF_NETGRAPH
+inline int PF_NETGRAPH = AF_NETGRAPH;
+#pragma D binding "1.13" PF_SLOW
+inline int PF_SLOW = AF_SLOW;
+#pragma D binding "1.13" PF_SCLUSTER
+inline int PF_SCLUSTER = AF_SCLUSTER;
+#pragma D binding "1.13" PF_ARP
+inline int PF_ARP = AF_ARP;
+#pragma D binding "1.13" PF_BLUETOOTH
+inline int PF_BLUETOOTH = AF_BLUETOOTH;
+#pragma D binding "1.13" PF_IEEE80211
+inline int PF_IEEE80211 = AF_IEEE80211;
+#pragma D binding "1.13" PF_INET_SDP
+inline int PF_INET_SDP= AF_INET_SDP;
+#pragma D binding "1.13" PF_INET6_SDP
+inline int PF_INET6_SDP= AF_INET6_SDP;
+#pragma D binding "1.13" PF_MAX
+inline int PF_MAX = AF_MAX;
diff --git a/cddl/lib/libdtrace/tcp.d b/cddl/lib/libdtrace/tcp.d
new file mode 100644
index 000000000000..8f51675df305
--- /dev/null
+++ b/cddl/lib/libdtrace/tcp.d
@@ -0,0 +1,419 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 Mark Johnston <markj@freebsd.org>
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on module kernel
+#pragma D depends_on provider tcp
+
+/*
+ * Convert a TCP state value to a string.
+ */
+#pragma D binding "1.6.3" TCPS_CLOSED
+inline int TCPS_CLOSED = 0;
+#pragma D binding "1.6.3" TCPS_LISTEN
+inline int TCPS_LISTEN = 1;
+#pragma D binding "1.6.3" TCPS_SYN_SENT
+inline int TCPS_SYN_SENT = 2;
+#pragma D binding "1.6.3" TCPS_SYN_RECEIVED
+inline int TCPS_SYN_RECEIVED = 3;
+#pragma D binding "1.6.3" TCPS_ESTABLISHED
+inline int TCPS_ESTABLISHED = 4;
+#pragma D binding "1.6.3" TCPS_CLOSE_WAIT
+inline int TCPS_CLOSE_WAIT = 5;
+#pragma D binding "1.6.3" TCPS_FIN_WAIT_1
+inline int TCPS_FIN_WAIT_1 = 6;
+#pragma D binding "1.6.3" TCPS_CLOSING
+inline int TCPS_CLOSING = 7;
+#pragma D binding "1.6.3" TCPS_LAST_ACK
+inline int TCPS_LAST_ACK = 8;
+#pragma D binding "1.6.3" TCPS_FIN_WAIT_2
+inline int TCPS_FIN_WAIT_2 = 9;
+#pragma D binding "1.6.3" TCPS_TIME_WAIT
+inline int TCPS_TIME_WAIT = 10;
+
+/*
+ * For compatibility also provide the names used by Solaris.
+ */
+#pragma D binding "1.13" TCP_STATE_CLOSED
+inline int TCP_STATE_CLOSED = TCPS_CLOSED;
+#pragma D binding "1.13" TCP_STATE_LISTEN
+inline int TCP_STATE_LISTEN = TCPS_LISTEN;
+#pragma D binding "1.13" TCP_STATE_SYN_SENT
+inline int TCP_STATE_SYN_SENT = TCPS_SYN_SENT;
+#pragma D binding "1.13" TCP_STATE_SYN_RECEIVED
+inline int TCP_STATE_SYN_RECEIVED = TCPS_SYN_RECEIVED;
+#pragma D binding "1.13" TCP_STATE_ESTABLISHED
+inline int TCP_STATE_ESTABLISHED = TCPS_ESTABLISHED;
+#pragma D binding "1.13" TCP_STATE_CLOSE_WAIT
+inline int TCP_STATE_CLOSE_WAIT = TCPS_CLOSE_WAIT;
+#pragma D binding "1.13" TCP_STATE_FIN_WAIT_1
+inline int TCP_STATE_FIN_WAIT_1 = TCPS_FIN_WAIT_1;
+#pragma D binding "1.13" TCP_STATE_CLOSING
+inline int TCP_STATE_CLOSING = TCPS_CLOSING;
+#pragma D binding "1.13" TCP_STATE_LAST_ACK
+inline int TCP_STATE_LAST_ACK = TCPS_LAST_ACK;
+#pragma D binding "1.13" TCP_STATE_FIN_WAIT_2
+inline int TCP_STATE_FIN_WAIT_2 = TCPS_FIN_WAIT_2;
+#pragma D binding "1.13" TCP_STATE_TIME_WAIT
+inline int TCP_STATE_TIME_WAIT = TCPS_TIME_WAIT;
+
+/* TCP segment flags. */
+#pragma D binding "1.6.3" TH_FIN
+inline uint16_t TH_FIN = 0x01;
+#pragma D binding "1.6.3" TH_SYN
+inline uint16_t TH_SYN = 0x02;
+#pragma D binding "1.6.3" TH_RST
+inline uint16_t TH_RST = 0x04;
+#pragma D binding "1.6.3" TH_PUSH
+inline uint16_t TH_PUSH = 0x08;
+#pragma D binding "1.6.3" TH_ACK
+inline uint16_t TH_ACK = 0x10;
+#pragma D binding "1.6.3" TH_URG
+inline uint16_t TH_URG = 0x20;
+#pragma D binding "1.6.3" TH_ECE
+inline uint16_t TH_ECE = 0x40;
+#pragma D binding "1.6.3" TH_CWR
+inline uint16_t TH_CWR = 0x80;
+#pragma D binding "1.6.3" TH_AE
+inline uint16_t TH_AE = 0x100;
+
+/* TCP connection state strings. */
+#pragma D binding "1.6.3" tcp_state_string
+inline string tcp_state_string[int32_t state] =
+ state == TCPS_CLOSED ? "state-closed" :
+ state == TCPS_LISTEN ? "state-listen" :
+ state == TCPS_SYN_SENT ? "state-syn-sent" :
+ state == TCPS_SYN_RECEIVED ? "state-syn-received" :
+ state == TCPS_ESTABLISHED ? "state-established" :
+ state == TCPS_CLOSE_WAIT ? "state-close-wait" :
+ state == TCPS_FIN_WAIT_1 ? "state-fin-wait-1" :
+ state == TCPS_CLOSING ? "state-closing" :
+ state == TCPS_LAST_ACK ? "state-last-ack" :
+ state == TCPS_FIN_WAIT_2 ? "state-fin-wait-2" :
+ state == TCPS_TIME_WAIT ? "state-time-wait" :
+ "<unknown>";
+
+/*
+ * tcpsinfo contains stable TCP details from tcp_t.
+ */
+typedef struct tcpsinfo {
+ uintptr_t tcps_addr;
+ int tcps_local; /* is delivered locally, boolean */
+ int tcps_active; /* active open (from here), boolean */
+ uint16_t tcps_lport; /* local port */
+ uint16_t tcps_rport; /* remote port */
+ string tcps_laddr; /* local address, as a string */
+ string tcps_raddr; /* remote address, as a string */
+ int32_t tcps_state; /* TCP state */
+ uint32_t tcps_iss; /* Initial sequence # sent */
+ uint32_t tcps_irs; /* Initial sequence # received */
+ uint32_t tcps_suna; /* sequence # sent but unacked */
+ uint32_t tcps_smax; /* highest sequence number sent */
+ uint32_t tcps_snxt; /* next sequence # to send */
+ uint32_t tcps_rack; /* sequence # we have acked */
+ uint32_t tcps_rnxt; /* next sequence # expected */
+ u_long tcps_swnd; /* send window size */
+ int32_t tcps_snd_ws; /* send window scaling */
+ uint32_t tcps_swl1; /* window update seg seq number */
+ uint32_t tcps_swl2; /* window update seg ack number */
+ uint32_t tcps_rup; /* receive urgent pointer */
+ uint32_t tcps_radv; /* advertised window */
+ u_long tcps_rwnd; /* receive window size */
+ int32_t tcps_rcv_ws; /* receive window scaling */
+ u_long tcps_cwnd; /* congestion window */
+ u_long tcps_cwnd_ssthresh; /* threshold for congestion avoidance */
+ uint32_t tcps_srecover; /* for use in NewReno Fast Recovery */
+ uint32_t tcps_sack_fack; /* SACK sequence # we have acked */
+ uint32_t tcps_sack_snxt; /* next SACK seq # for retransmission */
+ uint32_t tcps_rto; /* round-trip timeout, msec */
+ uint32_t tcps_mss; /* max segment size */
+ int tcps_retransmit; /* retransmit send event, boolean */
+ int tcps_srtt; /* smoothed RTT in units of (TCP_RTT_SCALE*hz) */
+ int tcps_debug; /* socket has SO_DEBUG set */
+ int tcps_cookie; /* expose the socket's SO_USER_COOKIE */
+ int32_t tcps_dupacks; /* consecutive dup acks received */
+ uint32_t tcps_rtttime; /* RTT measurement start time */
+ uint32_t tcps_rtseq; /* sequence # being timed */
+ uint32_t tcps_ts_recent; /* timestamp echo data */
+} tcpsinfo_t;
+
+/*
+ * tcplsinfo provides the old tcp state for state changes.
+ */
+typedef struct tcplsinfo {
+ int32_t tcps_state; /* previous TCP state */
+} tcplsinfo_t;
+
+/*
+ * tcpinfo is the TCP header fields.
+ */
+typedef struct tcpinfo {
+ uint16_t tcp_sport; /* source port */
+ uint16_t tcp_dport; /* destination port */
+ uint32_t tcp_seq; /* sequence number */
+ uint32_t tcp_ack; /* acknowledgment number */
+ uint8_t tcp_offset; /* data offset, in bytes */
+ uint16_t tcp_flags; /* flags */
+ uint16_t tcp_window; /* window size */
+ uint16_t tcp_checksum; /* checksum */
+ uint16_t tcp_urgent; /* urgent data pointer */
+ struct tcphdr *tcp_hdr; /* raw TCP header */
+} tcpinfo_t;
+
+/*
+ * A clone of tcpinfo_t used to handle the fact that the TCP input path
+ * overwrites some fields of the TCP header with their host-order equivalents.
+ * Unfortunately, DTrace doesn't let us simply typedef a new name for struct
+ * tcpinfo and define a separate translator for it.
+ */
+typedef struct tcpinfoh {
+ uint16_t tcp_sport; /* source port */
+ uint16_t tcp_dport; /* destination port */
+ uint32_t tcp_seq; /* sequence number */
+ uint32_t tcp_ack; /* acknowledgment number */
+ uint8_t tcp_offset; /* data offset, in bytes */
+ uint16_t tcp_flags; /* flags */
+ uint16_t tcp_window; /* window size */
+ uint16_t tcp_checksum; /* checksum */
+ uint16_t tcp_urgent; /* urgent data pointer */
+ struct tcphdr *tcp_hdr; /* raw TCP header */
+} tcpinfoh_t;
+
+#pragma D binding "1.6.3" translator
+translator csinfo_t < struct tcpcb *p > {
+ cs_addr = NULL;
+ cs_cid = (uint64_t)(p == NULL ? 0 : &p->t_inpcb);
+ cs_pid = 0;
+ cs_zoneid = 0;
+};
+
+#pragma D binding "1.6.3" translator
+translator tcpsinfo_t < struct tcpcb *p > {
+ tcps_addr = (uintptr_t)p;
+ tcps_local = -1; /* XXX */
+ tcps_active = -1; /* XXX */
+ tcps_lport = p == NULL ? 0 : ntohs(p->t_inpcb.inp_inc.inc_ie.ie_lport);
+ tcps_rport = p == NULL ? 0 : ntohs(p->t_inpcb.inp_inc.inc_ie.ie_fport);
+ tcps_laddr = p == NULL ? "<unknown>" :
+ p->t_inpcb.inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->t_inpcb.inp_inc.inc_ie.ie_dependladdr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->t_inpcb.inp_inc.inc_ie.ie_dependladdr.id6_addr);
+ tcps_raddr = p == NULL ? "<unknown>" :
+ p->t_inpcb.inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->t_inpcb.inp_inc.inc_ie.ie_dependfaddr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->t_inpcb.inp_inc.inc_ie.ie_dependfaddr.id6_addr);
+ tcps_state = p == NULL ? -1 : p->t_state;
+ tcps_iss = p == NULL ? 0 : p->iss;
+ tcps_irs = p == NULL ? 0 : p->irs;
+ tcps_suna = p == NULL ? 0 : p->snd_una;
+ tcps_smax = p == NULL ? 0 : p->snd_max;
+ tcps_snxt = p == NULL ? 0 : p->snd_nxt;
+ tcps_rack = p == NULL ? 0 : p->last_ack_sent;
+ tcps_rnxt = p == NULL ? 0 : p->rcv_nxt;
+ tcps_swnd = p == NULL ? -1 : p->snd_wnd;
+ tcps_snd_ws = p == NULL ? -1 : p->snd_scale;
+ tcps_swl1 = p == NULL ? -1 : p->snd_wl1;
+ tcps_swl2 = p == NULL ? -1 : p->snd_wl2;
+ tcps_radv = p == NULL ? -1 : p->rcv_adv;
+ tcps_rwnd = p == NULL ? -1 : p->rcv_wnd;
+ tcps_rup = p == NULL ? -1 : p->rcv_up;
+ tcps_rcv_ws = p == NULL ? -1 : p->rcv_scale;
+ tcps_cwnd = p == NULL ? -1 : p->snd_cwnd;
+ tcps_cwnd_ssthresh = p == NULL ? -1 : p->snd_ssthresh;
+ tcps_srecover = p == NULL ? -1 : p->snd_recover;
+ tcps_sack_fack = p == NULL ? 0 : p->snd_fack;
+ tcps_sack_snxt = p == NULL ? 0 : p->snd_recover;
+ tcps_rto = p == NULL ? -1 : (p->t_rxtcur * 1000) / `hz;
+ tcps_mss = p == NULL ? -1 : p->t_maxseg;
+ tcps_retransmit = p == NULL ? -1 : p->t_rxtshift > 0 ? 1 : 0;
+ tcps_srtt = p == NULL ? -1 : p->t_srtt; /* smoothed RTT in units of (TCP_RTT_SCALE*hz) */
+ tcps_debug = p == NULL ? 0 :
+ p->t_inpcb.inp_socket->so_options & 1;
+ tcps_cookie = p == NULL ? -1 :
+ p->t_inpcb.inp_socket->so_user_cookie;
+ tcps_dupacks = p == NULL ? -1 : p->t_dupacks;
+ tcps_rtttime = p == NULL ? -1 : p->t_rtttime;
+ tcps_rtseq = p == NULL ? -1 : p->t_rtseq;
+ tcps_ts_recent = p == NULL ? -1 : p->ts_recent;
+};
+
+#pragma D binding "1.6.3" translator
+translator tcpinfo_t < struct tcphdr *p > {
+ tcp_sport = p == NULL ? 0 : ntohs(p->th_sport);
+ tcp_dport = p == NULL ? 0 : ntohs(p->th_dport);
+ tcp_seq = p == NULL ? -1 : ntohl(p->th_seq);
+ tcp_ack = p == NULL ? -1 : ntohl(p->th_ack);
+ tcp_offset = p == NULL ? -1 : (p->th_off << 2);
+ tcp_flags = p == NULL ? 0 : ((p->th_x2 << 8) | p->th_flags);
+ tcp_window = p == NULL ? 0 : ntohs(p->th_win);
+ tcp_checksum = p == NULL ? 0 : ntohs(p->th_sum);
+ tcp_urgent = p == NULL ? 0 : ntohs(p->th_urp);
+ tcp_hdr = (struct tcphdr *)p;
+};
+
+/*
+ * This translator differs from the one for tcpinfo_t in that the sequence
+ * number, acknowledgement number, window size and urgent pointer are already
+ * in host order and thus don't need to be converted.
+ */
+#pragma D binding "1.6.3" translator
+translator tcpinfoh_t < struct tcphdr *p > {
+ tcp_sport = p == NULL ? 0 : ntohs(p->th_sport);
+ tcp_dport = p == NULL ? 0 : ntohs(p->th_dport);
+ tcp_seq = p == NULL ? -1 : p->th_seq;
+ tcp_ack = p == NULL ? -1 : p->th_ack;
+ tcp_offset = p == NULL ? -1 : (p->th_off << 2);
+ tcp_flags = p == NULL ? 0 : ((p->th_x2 << 8) | p->th_flags);
+ tcp_window = p == NULL ? 0 : p->th_win;
+ tcp_checksum = p == NULL ? 0 : ntohs(p->th_sum);
+ tcp_urgent = p == NULL ? 0 : p->th_urp;
+ tcp_hdr = (struct tcphdr *)p;
+};
+
+#pragma D binding "1.6.3" translator
+translator tcplsinfo_t < int s > {
+ tcps_state = s;
+};
+
+
+/* Support for TCP debug */
+
+#pragma D binding "1.12.1" TA_INPUT
+inline int TA_INPUT = 0;
+#pragma D binding "1.12.1" TA_OUTPUT
+inline int TA_OUTPUT = 1;
+#pragma D binding "1.12.1" TA_USER
+inline int TA_USER = 2;
+#pragma D binding "1.12.1" TA_RESPOND
+inline int TA_RESPOND = 3;
+#pragma D binding "1.12.1" TA_DROP
+inline int TA_DROP = 4;
+
+/* direction strings. */
+
+#pragma D binding "1.13" tcpdebug_dir_string
+inline string tcpdebug_dir_string[uint8_t direction] =
+ direction == TA_INPUT ? "input" :
+ direction == TA_OUTPUT ? "output" :
+ direction == TA_USER ? "user" :
+ direction == TA_RESPOND ? "respond" :
+ direction == TA_DROP ? "drop" :
+ "unknown" ;
+
+#pragma D binding "1.13" tcpflag_string
+inline string tcpflag_string[uint16_t flags] =
+ flags & TH_FIN ? "FIN" :
+ flags & TH_SYN ? "SYN" :
+ flags & TH_RST ? "RST" :
+ flags & TH_PUSH ? "PUSH" :
+ flags & TH_ACK ? "ACK" :
+ flags & TH_URG ? "URG" :
+ flags & TH_ECE ? "ECE" :
+ flags & TH_CWR ? "CWR" :
+ flags & TH_AE ? "AE" :
+ "unknown" ;
+
+#pragma D binding "1.12.1" PRU_ATTACH
+inline int PRU_ATTACH = 0;
+#pragma D binding "1.12.1" PRU_DETACH
+inline int PRU_DETACH = 1;
+#pragma D binding "1.12.1" PRU_BIND
+inline int PRU_BIND = 2;
+#pragma D binding "1.12.1" PRU_LISTEN
+inline int PRU_LISTEN = 3;
+#pragma D binding "1.12.1" PRU_CONNECT
+inline int PRU_CONNECT = 4;
+#pragma D binding "1.12.1" PRU_ACCEPT
+inline int PRU_ACCEPT = 5 ;
+#pragma D binding "1.12.1" PRU_DISCONNECT
+inline int PRU_DISCONNECT = 6;
+#pragma D binding "1.12.1" PRU_SHUTDOWN
+inline int PRU_SHUTDOWN = 7;
+#pragma D binding "1.12.1" PRU_RCVD
+inline int PRU_RCVD = 8;
+#pragma D binding "1.12.1" PRU_SEND
+inline int PRU_SEND = 9;
+#pragma D binding "1.12.1" PRU_ABORT
+inline int PRU_ABORT = 10;
+#pragma D binding "1.12.1" PRU_CONTROL
+inline int PRU_CONTROL = 11;
+#pragma D binding "1.12.1" PRU_SENSE
+inline int PRU_SENSE = 12;
+#pragma D binding "1.12.1" PRU_RCVOOB
+inline int PRU_RCVOOB = 13;
+#pragma D binding "1.12.1" PRU_SENDOOB
+inline int PRU_SENDOOB = 14;
+#pragma D binding "1.12.1" PRU_SOCKADDR
+inline int PRU_SOCKADDR = 15;
+#pragma D binding "1.12.1" PRU_PEERADDR
+inline int PRU_PEERADDR = 16;
+#pragma D binding "1.12.1" PRU_CONNECT2
+inline int PRU_CONNECT2 = 17;
+#pragma D binding "1.12.1" PRU_FASTTIMO
+inline int PRU_FASTTIMO = 18;
+#pragma D binding "1.12.1" PRU_SLOWTIMO
+inline int PRU_SLOWTIMO = 19;
+#pragma D binding "1.12.1" PRU_PROTORCV
+inline int PRU_PROTORCV = 20;
+#pragma D binding "1.12.1" PRU_PROTOSEND
+inline int PRU_PROTOSEND = 21;
+#pragma D binding "1.12.1" PRU_SEND_EOF
+inline int PRU_SEND_EOF = 22;
+#pragma D binding "1.12.1" PRU_SOSETLABEL
+inline int PRU_SOSETLABEL = 23;
+#pragma D binding "1.12.1" PRU_CLOSE
+inline int PRU_CLOSE = 24;
+#pragma D binding "1.12.1" PRU_FLUSH
+inline int PRU_FLUSH = 25;
+
+#pragma D binding "1.12.1" prureq_string
+inline string prureq_string[uint8_t req] =
+ req == PRU_ATTACH ? "ATTACH" :
+ req == PRU_DETACH ? "DETACH" :
+ req == PRU_BIND ? "BIND" :
+ req == PRU_LISTEN ? "LISTEN" :
+ req == PRU_CONNECT ? "CONNECT" :
+ req == PRU_ACCEPT ? "ACCEPT" :
+ req == PRU_DISCONNECT ? "DISCONNECT" :
+ req == PRU_SHUTDOWN ? "SHUTDOWN" :
+ req == PRU_RCVD ? "RCVD" :
+ req == PRU_SEND ? "SEND" :
+ req == PRU_ABORT ? "ABORT" :
+ req == PRU_CONTROL ? "CONTROL" :
+ req == PRU_SENSE ? "SENSE" :
+ req == PRU_RCVOOB ? "RCVOOB" :
+ req == PRU_SENDOOB ? "SENDOOB" :
+ req == PRU_SOCKADDR ? "SOCKADDR" :
+ req == PRU_PEERADDR ? "PEERADDR" :
+ req == PRU_CONNECT2 ? "CONNECT2" :
+ req == PRU_FASTTIMO ? "FASTTIMO" :
+ req == PRU_SLOWTIMO ? "SLOWTIMO" :
+ req == PRU_PROTORCV ? "PROTORCV" :
+ req == PRU_PROTOSEND ? "PROTOSEND" :
+ req == PRU_SEND ? "SEND_EOF" :
+ req == PRU_SOSETLABEL ? "SOSETLABEL" :
+ req == PRU_CLOSE ? "CLOSE" :
+ req == PRU_FLUSH ? "FLUSE" :
+ "unknown" ;
diff --git a/cddl/lib/libdtrace/udp.d b/cddl/lib/libdtrace/udp.d
new file mode 100644
index 000000000000..fd28f5e2e7e9
--- /dev/null
+++ b/cddl/lib/libdtrace/udp.d
@@ -0,0 +1,74 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on module kernel
+#pragma D depends_on provider udp
+
+/*
+ * udpsinfo contains stable UDP details.
+ */
+typedef struct udpsinfo {
+ uintptr_t udps_addr;
+ uint16_t udps_lport; /* local port */
+ uint16_t udps_rport; /* remote port */
+ string udps_laddr; /* local address, as a string */
+ string udps_raddr; /* remote address, as a string */
+} udpsinfo_t;
+
+/*
+ * udpinfo is the UDP header fields.
+ */
+typedef struct udpinfo {
+ uint16_t udp_sport; /* source port */
+ uint16_t udp_dport; /* destination port */
+ uint16_t udp_length; /* total length */
+ uint16_t udp_checksum; /* headers + data checksum */
+ struct udphdr *udp_hdr; /* raw UDP header */
+} udpinfo_t;
+
+#pragma D binding "1.6.3" translator
+translator udpsinfo_t < struct inpcb *p > {
+ udps_addr = (uintptr_t)p;
+ udps_lport = p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
+ udps_rport = p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
+ udps_laddr = p == NULL ? "<unknown>" :
+ p->inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.id6_addr);
+ udps_raddr = p == NULL ? "<unknown>" :
+ p->inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.id6_addr);
+};
+
+#pragma D binding "1.6.3" translator
+translator udpinfo_t < struct udphdr *p > {
+ udp_sport = p == NULL ? 0 : ntohs(p->uh_sport);
+ udp_dport = p == NULL ? 0 : ntohs(p->uh_dport);
+ udp_length = p == NULL ? 0 : ntohs(p->uh_ulen);
+ udp_checksum = p == NULL ? 0 : ntohs(p->uh_sum);
+ udp_hdr = p;
+};
diff --git a/cddl/lib/libdtrace/udplite.d b/cddl/lib/libdtrace/udplite.d
new file mode 100644
index 000000000000..88c1c8553ce5
--- /dev/null
+++ b/cddl/lib/libdtrace/udplite.d
@@ -0,0 +1,75 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 Mark Johnston <markj@FreeBSD.org>
+ * Copyright (c) 2018 Michael Tuexen <tuexen@FreeBSD.org>
+ */
+
+#pragma D depends_on library ip.d
+#pragma D depends_on module kernel
+#pragma D depends_on provider udplite
+
+/*
+ * udplitesinfo contains stable UDPLite details.
+ */
+typedef struct udplitesinfo {
+ uintptr_t udplites_addr;
+ uint16_t udplites_lport; /* local port */
+ uint16_t udplites_rport; /* remote port */
+ string udplites_laddr; /* local address, as a string */
+ string udplites_raddr; /* remote address, as a string */
+} udplitesinfo_t;
+
+/*
+ * udpliteinfo is the UDPLite header fields.
+ */
+typedef struct udpliteinfo {
+ uint16_t udplite_sport; /* source port */
+ uint16_t udplite_dport; /* destination port */
+ uint16_t udplite_coverage; /* checksum coverage */
+ uint16_t udplite_checksum; /* headers + data checksum */
+ struct udplitehdr *udplite_hdr; /* raw UDPLite header */
+} udpliteinfo_t;
+
+#pragma D binding "1.13" translator
+translator udplitesinfo_t < struct inpcb *p > {
+ udplites_addr = (uintptr_t)p;
+ udplites_lport = p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_lport);
+ udplites_rport = p == NULL ? 0 : ntohs(p->inp_inc.inc_ie.ie_fport);
+ udplites_laddr = p == NULL ? "<unknown>" :
+ p->inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->inp_inc.inc_ie.ie_dependladdr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->inp_inc.inc_ie.ie_dependladdr.id6_addr);
+ udplites_raddr = p == NULL ? "<unknown>" :
+ p->inp_vflag == INP_IPV4 ?
+ inet_ntoa(&p->inp_inc.inc_ie.ie_dependfaddr.id46_addr.ia46_addr4.s_addr) :
+ inet_ntoa6(&p->inp_inc.inc_ie.ie_dependfaddr.id6_addr);
+};
+
+#pragma D binding "1.13" translator
+translator udpliteinfo_t < struct udphdr *p > {
+ udplite_sport = p == NULL ? 0 : ntohs(p->uh_sport);
+ udplite_dport = p == NULL ? 0 : ntohs(p->uh_dport);
+ udplite_coverage = p == NULL ? 0 : ntohs(p->uh_ulen);
+ udplite_checksum = p == NULL ? 0 : ntohs(p->uh_sum);
+ udplite_hdr = (struct udplitehdr *)p;
+};
diff --git a/cddl/lib/libdtrace/unistd.d b/cddl/lib/libdtrace/unistd.d
new file mode 100644
index 000000000000..ead9d23ce670
--- /dev/null
+++ b/cddl/lib/libdtrace/unistd.d
@@ -0,0 +1,54 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+inline int DTRACEFLT_UNKNOWN = 0; /* Unknown fault */
+#pragma D binding "1.0" DTRACEFLT_UNKNOWN
+
+inline int DTRACEFLT_BADADDR = 1; /* Bad address */
+#pragma D binding "1.0" DTRACEFLT_BADADDR
+
+inline int DTRACEFLT_BADALIGN = 2; /* Bad alignment */
+#pragma D binding "1.0" DTRACEFLT_BADALIGN
+
+inline int DTRACEFLT_ILLOP = 3; /* Illegal operation */
+#pragma D binding "1.0" DTRACEFLT_ILLOP
+
+inline int DTRACEFLT_DIVZERO = 4; /* Divide-by-zero */
+#pragma D binding "1.0" DTRACEFLT_DIVZERO
+
+inline int DTRACEFLT_NOSCRATCH = 5; /* Out of scratch space */
+#pragma D binding "1.0" DTRACEFLT_NOSCRATCH
+
+inline int DTRACEFLT_KPRIV = 6; /* Illegal kernel access */
+#pragma D binding "1.0" DTRACEFLT_KPRIV
+
+inline int DTRACEFLT_UPRIV = 7; /* Illegal user access */
+#pragma D binding "1.0" DTRACEFLT_UPRIV
+
+inline int DTRACEFLT_TUPOFLOW = 8; /* Tuple stack overflow */
+#pragma D binding "1.0" DTRACEFLT_TUPOFLOW
+
+inline int DTRACEFLT_BADSTACK = 9; /* Bad stack */
+#pragma D binding "1.4.1" DTRACEFLT_BADSTACK
diff --git a/cddl/lib/libicp/Makefile b/cddl/lib/libicp/Makefile
new file mode 100644
index 000000000000..1a9a79103b50
--- /dev/null
+++ b/cddl/lib/libicp/Makefile
@@ -0,0 +1,142 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= icp
+LIBADD=
+
+.if ${MACHINE_ARCH} == "amd64"
+ASM_SOURCES_C = asm-x86_64/aes/aeskey.c
+ASM_SOURCES_AS = \
+ asm-x86_64/aes/aes_amd64.S \
+ asm-x86_64/aes/aes_aesni.S \
+ asm-x86_64/modes/gcm_pclmulqdq.S \
+ asm-x86_64/modes/aesni-gcm-x86_64.S \
+ asm-x86_64/modes/aesni-gcm-avx2-vaes.S \
+ asm-x86_64/modes/ghash-x86_64.S \
+ asm-x86_64/sha2/sha256-x86_64.S \
+ asm-x86_64/sha2/sha512-x86_64.S \
+ asm-x86_64/blake3/blake3_avx2.S \
+ asm-x86_64/blake3/blake3_avx512.S \
+ asm-x86_64/blake3/blake3_sse2.S \
+ asm-x86_64/blake3/blake3_sse41.S
+
+CFLAGS+= -D__amd64 -D_SYS_STACK_H -UHAVE_AES
+.elif ${MACHINE_CPUARCH} == "arm"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-arm/sha2/sha256-armv7.S \
+ asm-arm/sha2/sha512-armv7.S
+.elif ${MACHINE_ARCH} == "aarch64"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-aarch64/blake3/b3_aarch64_sse2.S \
+ asm-aarch64/blake3/b3_aarch64_sse41.S \
+ asm-aarch64/sha2/sha256-armv8.S \
+ asm-aarch64/sha2/sha512-armv8.S
+.elif ${MACHINE_ARCH} == "powerpc64"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-ppc64/sha2/sha256-ppc.S \
+ asm-ppc64/sha2/sha512-ppc.S \
+ asm-ppc64/sha2/sha256-p8.S \
+ asm-ppc64/sha2/sha512-p8.S
+.elif ${MACHINE_ARCH} == "powerpc64le"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-ppc64/blake3/b3_ppc64le_sse2.S \
+ asm-ppc64/blake3/b3_ppc64le_sse41.S \
+ asm-ppc64/sha2/sha256-ppc.S \
+ asm-ppc64/sha2/sha512-ppc.S \
+ asm-ppc64/sha2/sha256-p8.S \
+ asm-ppc64/sha2/sha512-p8.S
+.else
+ASM_SOURCES_C =
+ASM_SOURCES_AS =
+.endif
+
+KERNEL_C = \
+ spi/kcf_spi.c \
+ api/kcf_ctxops.c \
+ api/kcf_cipher.c \
+ api/kcf_mac.c \
+ algs/aes/aes_impl_aesni.c \
+ algs/aes/aes_impl_generic.c \
+ algs/aes/aes_impl_x86-64.c \
+ algs/aes/aes_impl.c \
+ algs/aes/aes_modes.c \
+ algs/blake3/blake3.c \
+ algs/blake3/blake3_generic.c \
+ algs/blake3/blake3_impl.c \
+ algs/edonr/edonr.c \
+ algs/modes/modes.c \
+ algs/modes/gcm_generic.c \
+ algs/modes/gcm_pclmulqdq.c \
+ algs/modes/gcm.c \
+ algs/modes/ccm.c \
+ algs/sha2/sha2_generic.c \
+ algs/sha2/sha256_impl.c \
+ algs/sha2/sha512_impl.c \
+ algs/skein/skein.c \
+ algs/skein/skein_block.c \
+ algs/skein/skein_iv.c \
+ illumos-crypto.c \
+ io/aes.c \
+ io/sha2_mod.c \
+ core/kcf_sched.c \
+ core/kcf_prov_lib.c \
+ core/kcf_callprov.c \
+ core/kcf_mech_tabs.c \
+ core/kcf_prov_tabs.c \
+ $(ASM_SOURCES_C)
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zfs
+KERNEL_C+= zfs_impl.c
+
+SRCS= $(ASM_SOURCES_AS) $(KERNEL_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 3
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+CFLAGS.aes_amd64.S+= -DLOCORE
+CFLAGS.aes_aesni.S+= -DLOCORE
+CFLAGS.gcm_pclmulqdq.S+= -DLOCORE
+CFLAGS.aesni-gcm-x86_64.S+= -DLOCORE
+CFLAGS.aesni-gcm-avx2-vaes.S+= -DLOCORE
+CFLAGS.ghash-x86_64.S+= -DLOCORE
+CFLAGS.sha256-x86_64.S+= -DLOCORE
+CFLAGS.sha512-x86_64.S+= -DLOCORE
+CFLAGS.blake3_avx2.S = -DLOCORE
+CFLAGS.blake3_avx512.S = -DLOCORE
+CFLAGS.blake3_sse2.S = -DLOCORE
+CFLAGS.blake3_sse41.S = -DLOCORE
+CFLAGS.b3_aarch64_sse2.S = -DLOCORE
+CFLAGS.b3_aarch64_sse41.S = -DLOCORE
+CFLAGS.sha256-armv7.S = -DLOCORE
+CFLAGS.sha256-armv8.S = -DLOCORE
+CFLAGS.sha512-armv7.S = -DLOCORE
+CFLAGS.sha512-armv8.S = -DLOCORE
+CFLAGS.b3_ppc64le_sse2.S = -DLOCORE
+CFLAGS.b3_ppc64le_sse41.S = -DLOCORE
+CFLAGS.sha256-p8.S = -DLOCORE
+CFLAGS.sha256-ppc.S = -DLOCORE
+CFLAGS.sha512-p8.S = -DLOCORE
+CFLAGS.sha512-ppc.S = -DLOCORE
+
+
+LDFLAGS.bfd+= -Wl,-znoexecstack
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libicp/Makefile.depend b/cddl/lib/libicp/Makefile.depend
new file mode 100644
index 000000000000..6ef78fac5cbf
--- /dev/null
+++ b/cddl/lib/libicp/Makefile.depend
@@ -0,0 +1,15 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libicp_rescue/Makefile b/cddl/lib/libicp_rescue/Makefile
new file mode 100644
index 000000000000..0a5a81f4ab7f
--- /dev/null
+++ b/cddl/lib/libicp_rescue/Makefile
@@ -0,0 +1,137 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+
+PACKAGE= utilities
+LIB= icp_rescue
+LIBADD=
+
+.if ${MACHINE_ARCH} == "amd64"
+ASM_SOURCES_C = asm-x86_64/aes/aeskey.c
+ASM_SOURCES_AS = \
+ asm-x86_64/aes/aes_amd64.S \
+ asm-x86_64/aes/aes_aesni.S \
+ asm-x86_64/modes/gcm_pclmulqdq.S \
+ asm-x86_64/modes/aesni-gcm-x86_64.S \
+ asm-x86_64/modes/aesni-gcm-avx2-vaes.S \
+ asm-x86_64/sha2/sha256-x86_64.S \
+ asm-x86_64/sha2/sha512-x86_64.S \
+ asm-x86_64/blake3/blake3_avx2.S \
+ asm-x86_64/blake3/blake3_avx512.S \
+ asm-x86_64/blake3/blake3_sse2.S \
+ asm-x86_64/blake3/blake3_sse41.S
+
+CFLAGS+= -D__amd64 -D_SYS_STACK_H
+.elif ${MACHINE_CPUARCH} == "arm"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-arm/sha2/sha256-armv7.S \
+ asm-arm/sha2/sha512-armv7.S
+.elif ${MACHINE_ARCH} == "aarch64"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-aarch64/blake3/b3_aarch64_sse2.S \
+ asm-aarch64/blake3/b3_aarch64_sse41.S \
+ asm-aarch64/sha2/sha256-armv8.S \
+ asm-aarch64/sha2/sha512-armv8.S
+.elif ${MACHINE_ARCH} == "powerpc64"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-ppc64/sha2/sha256-ppc.S \
+ asm-ppc64/sha2/sha512-ppc.S \
+ asm-ppc64/sha2/sha256-p8.S \
+ asm-ppc64/sha2/sha512-p8.S
+.elif ${MACHINE_ARCH} == "powerpc64le"
+ASM_SOURCES_C =
+ASM_SOURCES_AS = \
+ asm-ppc64/blake3/b3_ppc64le_sse2.S \
+ asm-ppc64/blake3/b3_ppc64le_sse41.S \
+ asm-ppc64/sha2/sha256-ppc.S \
+ asm-ppc64/sha2/sha512-ppc.S \
+ asm-ppc64/sha2/sha256-p8.S \
+ asm-ppc64/sha2/sha512-p8.S
+.else
+ASM_SOURCES_C =
+ASM_SOURCES_AS =
+.endif
+
+KERNEL_C = \
+ spi/kcf_spi.c \
+ api/kcf_ctxops.c \
+ api/kcf_cipher.c \
+ api/kcf_mac.c \
+ algs/aes/aes_impl_aesni.c \
+ algs/aes/aes_impl_generic.c \
+ algs/aes/aes_impl_x86-64.c \
+ algs/aes/aes_impl.c \
+ algs/aes/aes_modes.c \
+ algs/blake3/blake3.c \
+ algs/blake3/blake3_generic.c \
+ algs/blake3/blake3_impl.c \
+ algs/edonr/edonr.c \
+ algs/modes/modes.c \
+ algs/modes/gcm_generic.c \
+ algs/modes/gcm_pclmulqdq.c \
+ algs/modes/gcm.c \
+ algs/modes/ccm.c \
+ algs/sha2/sha2_generic.c \
+ algs/sha2/sha256_impl.c \
+ algs/sha2/sha512_impl.c \
+ algs/skein/skein_block.c \
+ illumos-crypto.c \
+ io/aes.c \
+ io/sha2_mod.c \
+ core/kcf_sched.c \
+ core/kcf_prov_lib.c \
+ core/kcf_callprov.c \
+ core/kcf_mech_tabs.c \
+ core/kcf_prov_tabs.c \
+ $(ASM_SOURCES_C)
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zfs
+KERNEL_C+= zfs_impl.c
+
+SRCS= $(ASM_SOURCES_AS) $(KERNEL_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 3
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID -UHAVE_AVX -DRESCUE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+CFLAGS.aes_amd64.S+= -DLOCORE
+CFLAGS.aes_aesni.S+= -DLOCORE
+CFLAGS.gcm_pclmulqdq.S+= -DLOCORE
+CFLAGS.aesni-gcm-x86_64.S+= -DLOCORE
+CFLAGS.aesni-gcm-avx2-vaes.S+= -DLOCORE
+CFLAGS.ghash-x86_64.S+= -DLOCORE
+CFLAGS.sha256-x86_64.S+= -DLOCORE
+CFLAGS.sha512-x86_64.S+= -DLOCORE
+CFLAGS.gcm.c+= -UCAN_USE_GCM_ASM
+CFLAGS.blake3_avx2.S = -DLOCORE
+CFLAGS.blake3_avx512.S = -DLOCORE
+CFLAGS.blake3_sse2.S = -DLOCORE
+CFLAGS.blake3_sse41.S = -DLOCORE
+CFLAGS.b3_aarch64_sse2.S = -DLOCORE
+CFLAGS.b3_aarch64_sse41.S = -DLOCORE
+CFLAGS.sha256-armv7.S = -DLOCORE
+CFLAGS.sha512-armv7.S = -DLOCORE
+CFLAGS.sha256-armv8.S = -DLOCORE
+CFLAGS.sha512-armv8.S = -DLOCORE
+CFLAGS.b3_ppc64le_sse2.S = -DLOCORE
+CFLAGS.b3_ppc64le_sse41.S = -DLOCORE
+CFLAGS.sha256-ppc.S = -DLOCORE
+CFLAGS.sha256-p8.S = -DLOCORE
+CFLAGS.sha512-ppc.S = -DLOCORE
+CFLAGS.sha512-p8.S = -DLOCORE
+
+LDFLAGS.bfd+= -Wl,-znoexecstack
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libicp_rescue/Makefile.depend b/cddl/lib/libicp_rescue/Makefile.depend
new file mode 100644
index 000000000000..6ef78fac5cbf
--- /dev/null
+++ b/cddl/lib/libicp_rescue/Makefile.depend
@@ -0,0 +1,15 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libnvpair/Makefile b/cddl/lib/libnvpair/Makefile
new file mode 100644
index 000000000000..8245b324688b
--- /dev/null
+++ b/cddl/lib/libnvpair/Makefile
@@ -0,0 +1,31 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/nvpair
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libnvpair
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= nvpair
+LIBADD= spl
+
+# user
+INCS= libnvpair.h
+SRCS= libnvpair.c \
+ libnvpair_json.c \
+ nvpair_alloc_system.c
+# kernel
+SRCS+= nvpair_alloc_fixed.c \
+ nvpair.c \
+ fnvpair.c
+
+WARNS?= 2
+CFLAGS+= -DIN_BASE -DHAVE_RPC_TYPES
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID -DHAVE_CONFIG_H -DHAVE_XDR_BYTESREC
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libnvpair/Makefile.depend b/cddl/lib/libnvpair/Makefile.depend
new file mode 100644
index 000000000000..409c3c86cc20
--- /dev/null
+++ b/cddl/lib/libnvpair/Makefile.depend
@@ -0,0 +1,16 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libspl \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libspl/Makefile b/cddl/lib/libspl/Makefile
new file mode 100644
index 000000000000..26e14ea72b8a
--- /dev/null
+++ b/cddl/lib/libspl/Makefile
@@ -0,0 +1,52 @@
+.include <bsd.init.mk>
+.include <bsd.compiler.mk>
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= spl
+LIBADD=
+
+SRCS = \
+ assert.c \
+ backtrace.c \
+ list.c \
+ mkdirp.c \
+ os/freebsd/zone.c \
+ page.c \
+ timestamp.c \
+ include/sys/list.h \
+ include/sys/list_impl.h
+
+# These functions are not required when bootstrapping and the atomic code,
+# among others, will not compile when building on macOS.
+.if !defined(BOOTSTRAPPING)
+SRCS += \
+ atomic.c \
+ getexecname.c \
+ tunables.c \
+ os/freebsd/getexecname.c \
+ os/freebsd/gethostid.c \
+ os/freebsd/getmntany.c \
+ os/freebsd/mnttab.c
+.endif
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+.if ${COMPILER_TYPE} == "clang"
+CFLAGS.atomic.c+= -Wno-error=atomic-alignment
+.endif
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libspl/Makefile.depend b/cddl/lib/libspl/Makefile.depend
new file mode 100644
index 000000000000..6ef78fac5cbf
--- /dev/null
+++ b/cddl/lib/libspl/Makefile.depend
@@ -0,0 +1,15 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libtpool/Makefile b/cddl/lib/libtpool/Makefile
new file mode 100644
index 000000000000..3a50a21bf62c
--- /dev/null
+++ b/cddl/lib/libtpool/Makefile
@@ -0,0 +1,32 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libtpool
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= tpool
+SHLIBDIR?= /lib
+LIBADD= spl
+
+INCS= thread_pool_impl.h
+SRCS= thread_pool.c
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <src.opts.mk>
+
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libtpool/Makefile.depend b/cddl/lib/libtpool/Makefile.depend
new file mode 100644
index 000000000000..409c3c86cc20
--- /dev/null
+++ b/cddl/lib/libtpool/Makefile.depend
@@ -0,0 +1,16 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libspl \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libtpool/tests/Makefile b/cddl/lib/libtpool/tests/Makefile
new file mode 100644
index 000000000000..19e43cc18821
--- /dev/null
+++ b/cddl/lib/libtpool/tests/Makefile
@@ -0,0 +1,13 @@
+ZFSTOP= ${SRCTOP}/sys/contrib/openzfs
+
+ATF_TESTS_C+= libtpool_test
+
+TEST_METADATA+= timeout="10"
+
+CFLAGS+= -I${ZFSTOP}/include \
+ -I${ZFSTOP}/lib/libspl/include
+
+LIBADD+= pthread tpool
+
+.include "${SRCTOP}/cddl/Makefile.inc"
+.include <bsd.test.mk>
diff --git a/cddl/lib/libtpool/tests/libtpool_test.c b/cddl/lib/libtpool/tests/libtpool_test.c
new file mode 100644
index 000000000000..42bce269cb23
--- /dev/null
+++ b/cddl/lib/libtpool/tests/libtpool_test.c
@@ -0,0 +1,82 @@
+#include <sys/stdtypes.h>
+#include <sys/sysctl.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include <thread_pool.h>
+
+#include <atf-c.h>
+
+static void
+tp_delay(void *arg)
+{
+ pthread_barrier_t *barrier = arg;
+ int r;
+
+ /* Block this task until all thread pool workers have been created. */
+ r = pthread_barrier_wait(barrier);
+ ATF_REQUIRE_MSG(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD,
+ "pthread_barrier_wait failed: %s", strerror(r));
+}
+
+/*
+ * NB: we could reduce the test's resource cost by using rctl(4). But that
+ * isn't enabled by default. And even with a thread limit of 1500, it takes <
+ * 0.1s to run on my machine. So I don't think it's worth optimizing for the
+ * case where rctl is available.
+ */
+ATF_TC(complete_exhaustion);
+ATF_TC_HEAD(complete_exhaustion, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "A thread pool should fail to schedule tasks if it is completely impossible to spawn any threads.");
+}
+
+ATF_TC_BODY(complete_exhaustion, tc)
+{
+ pthread_barrier_t barrier;
+ tpool_t *tp0, *tp1;
+ size_t len;
+ int max_threads_per_proc = 0;
+ int nworkers;
+ int r, i;
+
+ len = sizeof(max_threads_per_proc);
+ r = sysctlbyname("kern.threads.max_threads_per_proc",
+ &max_threads_per_proc, &len, NULL, 0);
+ ATF_REQUIRE_EQ_MSG(r, 0, "sysctlbyname: %s", strerror(errno));
+ nworkers = max_threads_per_proc - 1;
+ pthread_barrier_init(&barrier, NULL, max_threads_per_proc);
+
+ /*
+ * Create the first thread pool and spawn the maximum allowed number of
+ * processes.
+ */
+ tp0 = tpool_create(nworkers, nworkers, 1, NULL);
+ ATF_REQUIRE(tp0 != NULL);
+ for (i = 0; i < nworkers; i++) {
+ ATF_REQUIRE_EQ(tpool_dispatch(tp0, tp_delay, &barrier), 0);
+ }
+
+ /*
+ * Now create a second thread pool. Unable to create new threads, the
+ * dispatch function should return an error.
+ */
+ tp1 = tpool_create(nworkers, 2 * nworkers, 1, NULL);
+ ATF_REQUIRE(tp1 != NULL);
+ ATF_REQUIRE_EQ(tpool_dispatch(tp1, tp_delay, NULL), -1);
+
+ /* Cleanup */
+ r = pthread_barrier_wait(&barrier);
+ ATF_REQUIRE_MSG(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD,
+ "pthread_barrier_wait failed: %s", strerror(r));
+ tpool_wait(tp1);
+ tpool_wait(tp0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, complete_exhaustion);
+
+ return (atf_no_error());
+}
diff --git a/cddl/lib/libumem/Makefile b/cddl/lib/libumem/Makefile
new file mode 100644
index 000000000000..512332275fec
--- /dev/null
+++ b/cddl/lib/libumem/Makefile
@@ -0,0 +1,11 @@
+.PATH: ${SRCTOP}/cddl/compat/opensolaris/lib/libumem
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= umem
+SRCS= umem.c
+WARNS?= 3
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/lib/libumem
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libumem/Makefile.depend b/cddl/lib/libumem/Makefile.depend
new file mode 100644
index 000000000000..93249906da4f
--- /dev/null
+++ b/cddl/lib/libumem/Makefile.depend
@@ -0,0 +1,14 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libuutil/Makefile b/cddl/lib/libuutil/Makefile
new file mode 100644
index 000000000000..947e755d4aae
--- /dev/null
+++ b/cddl/lib/libuutil/Makefile
@@ -0,0 +1,26 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libuutil
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= uutil
+SRCS=\
+ uu_alloc.c \
+ uu_avl.c \
+ uu_ident.c \
+ uu_list.c \
+ uu_misc.c \
+ uu_string.c
+
+WARNS?= 2
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+
+LIBADD= avl spl
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libuutil/Makefile.depend b/cddl/lib/libuutil/Makefile.depend
new file mode 100644
index 000000000000..808980b1879e
--- /dev/null
+++ b/cddl/lib/libuutil/Makefile.depend
@@ -0,0 +1,17 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libavl \
+ cddl/lib/libspl \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzdb/Makefile b/cddl/lib/libzdb/Makefile
new file mode 100644
index 000000000000..040d7d2c63f9
--- /dev/null
+++ b/cddl/lib/libzdb/Makefile
@@ -0,0 +1,28 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzdb
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zdb
+
+INCS = libzdb.h
+
+SRCS = libzdb.c
+
+WARNS?= 2
+CSTD= c99
+
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzutil
+CFLAGS+= -DHAVE_ISSETUGID -DIN_BASE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzdb/Makefile.depend b/cddl/lib/libzdb/Makefile.depend
new file mode 100644
index 000000000000..93249906da4f
--- /dev/null
+++ b/cddl/lib/libzdb/Makefile.depend
@@ -0,0 +1,14 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzfs/Makefile b/cddl/lib/libzfs/Makefile
new file mode 100644
index 000000000000..376e32fb893f
--- /dev/null
+++ b/cddl/lib/libzfs/Makefile
@@ -0,0 +1,110 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zcommon
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libshare
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zstd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zstd/lib
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zfs
+LIBADD= \
+ avl \
+ bsdxml \
+ crypto \
+ geom \
+ m \
+ md \
+ nvpair \
+ pthread \
+ rt \
+ umem \
+ util \
+ uutil \
+ z \
+ zfs_core \
+ zutil
+
+INCS= libzfs.h
+USER_C = \
+ libzfs_changelist.c \
+ libzfs_config.c \
+ libzfs_crypto.c \
+ libzfs_dataset.c \
+ libzfs_diff.c \
+ libzfs_import.c \
+ libzfs_iter.c \
+ libzfs_mount.c \
+ libzfs_pool.c \
+ libzfs_sendrecv.c \
+ libzfs_status.c \
+ libzfs_util.c
+
+# FreeBSD
+USER_C += \
+ libzfs_compat.c \
+ libzfs_zmount.c
+
+# libshare
+USER_C += \
+ libshare.c \
+ nfs.c \
+ os/freebsd/nfs.c \
+ os/freebsd/smb.c
+
+KERNEL_C = \
+ cityhash.c \
+ zfeature_common.c \
+ zfs_comutil.c \
+ zfs_deleg.c \
+ zfs_fletcher.c \
+ zfs_fletcher_superscalar.c \
+ zfs_fletcher_superscalar4.c \
+ zfs_namecheck.c \
+ zfs_prop.c \
+ zfs_valstr.c \
+ zpool_prop.c \
+ zprop_common.c
+
+ARCH_C =
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+ARCH_C += zfs_fletcher_intel.c \
+ zfs_fletcher_sse.c
+CFLAGS += -DHAVE_SSE2
+.endif
+.if ${MACHINE_ARCH} == "amd64"
+ARCH_C += zfs_fletcher_avx512.c
+CFLAGS+= -DHAVE_AVX2 -DHAVE_AVX -D__x86_64 -DHAVE_AVX512F
+.endif
+.if ${MACHINE_CPUARCH} == "aarch64"
+ARCH_C += zfs_fletcher_aarch64_neon.c
+.endif
+
+SRCS= $(USER_C) $(KERNEL_C) $(ARCH_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 4
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libshare
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/ck/include
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -DHAVE_EXECVPE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS+= -DSYSCONFDIR=\"/etc\"
+CFLAGS+= -DPKGDATADIR=\"/usr/share/zfs\"
+CFLAGS+= -DZFSEXECDIR=\"${LIBEXECDIR}/zfs\"
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzfs/Makefile.depend b/cddl/lib/libzfs/Makefile.depend
new file mode 100644
index 000000000000..1fead4b4f29d
--- /dev/null
+++ b/cddl/lib/libzfs/Makefile.depend
@@ -0,0 +1,30 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libavl \
+ cddl/lib/libnvpair \
+ cddl/lib/libumem \
+ cddl/lib/libuutil \
+ cddl/lib/libzfs_core \
+ cddl/lib/libzutil \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libexpat \
+ lib/libgeom \
+ lib/libmd \
+ lib/librt \
+ lib/libthr \
+ lib/libutil \
+ lib/libz \
+ lib/msun \
+ secure/lib/libcrypto \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzfs_core/Makefile b/cddl/lib/libzfs_core/Makefile
new file mode 100644
index 000000000000..10533c5de05b
--- /dev/null
+++ b/cddl/lib/libzfs_core/Makefile
@@ -0,0 +1,34 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs_core
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/os/freebsd/zfs
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zfs_core
+LIBADD= nvpair spl zutil
+
+INCS= libzfs_core.h
+SRCS= libzfs_core.c \
+ os/freebsd/libzfs_core_ioctl.c \
+ zfs_ioctl_compat.c
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzfs_core
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzfs_core/common
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzfs_core/Makefile.depend b/cddl/lib/libzfs_core/Makefile.depend
new file mode 100644
index 000000000000..fd295d12904d
--- /dev/null
+++ b/cddl/lib/libzfs_core/Makefile.depend
@@ -0,0 +1,18 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libnvpair \
+ cddl/lib/libspl \
+ cddl/lib/libzutil \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzfsbootenv/Makefile b/cddl/lib/libzfsbootenv/Makefile
new file mode 100644
index 000000000000..22f5da1ee5b1
--- /dev/null
+++ b/cddl/lib/libzfsbootenv/Makefile
@@ -0,0 +1,37 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfsbootenv
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zfsbootenv
+SHLIB_MAJOR= 1
+
+LIBADD= zfs
+LIBADD+= nvpair
+
+INCS= libzfsbootenv.h
+USER_C= \
+ lzbe_device.c \
+ lzbe_util.c \
+ lzbe_pair.c
+
+SRCS= $(USER_C)
+
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS.lzbe_device.c= -Wno-cast-qual
+CFLAGS.lzbe_util.c= -Wno-cast-qual
+CFLAGS.lzbe_pair.c= -Wno-cast-qual
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzfsbootenv/Makefile.depend b/cddl/lib/libzfsbootenv/Makefile.depend
new file mode 100644
index 000000000000..7209d9b784ef
--- /dev/null
+++ b/cddl/lib/libzfsbootenv/Makefile.depend
@@ -0,0 +1,17 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libnvpair \
+ cddl/lib/libzfs \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzpool/Makefile b/cddl/lib/libzpool/Makefile
new file mode 100644
index 000000000000..82ec0e890d56
--- /dev/null
+++ b/cddl/lib/libzpool/Makefile
@@ -0,0 +1,346 @@
+ZFSTOP= ${SRCTOP}/sys/contrib/openzfs
+
+.PATH: ${ZFSTOP}/lib/libzpool
+
+# ZFS_COMMON_SRCS
+.PATH: ${ZFSTOP}/module/zfs
+.PATH: ${ZFSTOP}/module/zcommon
+.PATH: ${ZFSTOP}/module/unicode
+# LUA_SRCS
+.PATH: ${ZFSTOP}/module/lua
+# ZSTD_SRCS
+.PATH: ${ZFSTOP}/module/zstd
+.PATH: ${ZFSTOP}/module/zstd/lib/common
+.PATH: ${ZFSTOP}/module/zstd/lib/compress
+.PATH: ${ZFSTOP}/module/zstd/lib/decompress
+
+.if exists(${SRCTOP}/sys/cddl/contrib/opensolaris/common/atomic/${MACHINE_ARCH}/opensolaris_atomic.S)
+.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/atomic/${MACHINE_ARCH}
+ATOMIC_SRCS= opensolaris_atomic.S
+ACFLAGS+= -Wa,--noexecstack
+.else
+.PATH: ${SRCTOP}/sys/cddl/compat/opensolaris/kern
+ATOMIC_SRCS= opensolaris_atomic.c
+.endif
+
+.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe"
+# Don't waste GOT entries on small data.
+PICFLAG= -fPIC
+.endif
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zpool
+
+USER_C = \
+ arc_os.c \
+ kernel.c \
+ taskq.c \
+ util.c \
+ zfs_debug.c
+
+.PATH: ${ZFSTOP}/module/os/linux/zfs
+
+KERNEL_C = \
+ simd_stat.c \
+ zfeature_common.c \
+ zfs_comutil.c \
+ zfs_deleg.c \
+ zfs_fletcher.c \
+ zfs_fletcher_superscalar.c \
+ zfs_fletcher_superscalar4.c \
+ zfs_namecheck.c \
+ zfs_prop.c \
+ zfs_zstd.c \
+ zpool_prop.c \
+ zprop_common.c \
+ abd.c \
+ abd_os.c \
+ aggsum.c \
+ arc.c \
+ blake3_zfs.c \
+ blkptr.c \
+ bplist.c \
+ bpobj.c \
+ bptree.c \
+ bqueue.c \
+ btree.c \
+ brt.c \
+ cityhash.c \
+ dbuf.c \
+ dbuf_stats.c \
+ ddt.c \
+ ddt_log.c \
+ ddt_stats.c \
+ ddt_zap.c \
+ dmu.c \
+ dmu_diff.c \
+ dmu_direct.c \
+ dmu_object.c \
+ dmu_objset.c \
+ dmu_recv.c \
+ dmu_redact.c \
+ dmu_send.c \
+ dmu_traverse.c \
+ dmu_tx.c \
+ dmu_zfetch.c \
+ dnode.c \
+ dnode_sync.c \
+ dsl_bookmark.c \
+ dsl_dataset.c \
+ dsl_deadlist.c \
+ dsl_deleg.c \
+ dsl_dir.c \
+ dsl_crypt.c \
+ dsl_pool.c \
+ dsl_prop.c \
+ dsl_scan.c \
+ dsl_synctask.c \
+ dsl_destroy.c \
+ dsl_userhold.c \
+ edonr_zfs.c \
+ entropy_common.c \
+ error_private.c \
+ fm.c \
+ fse_compress.c \
+ fse_decompress.c \
+ gzip.c \
+ hist.c \
+ hkdf.c \
+ huf_compress.c \
+ huf_decompress.c \
+ lzjb.c \
+ lz4.c \
+ lz4_zfs.c \
+ metaslab.c \
+ mmp.c \
+ multilist.c \
+ objlist.c \
+ pathname.c \
+ pool.c \
+ range_tree.c \
+ refcount.c \
+ rrwlock.c \
+ sa.c \
+ sha2_zfs.c \
+ skein_zfs.c \
+ spa.c \
+ spa_checkpoint.c \
+ spa_config.c \
+ spa_errlog.c \
+ spa_history.c \
+ spa_log_spacemap.c \
+ spa_misc.c \
+ spa_stats.c \
+ space_map.c \
+ space_reftree.c \
+ txg.c \
+ trace.c \
+ uberblock.c \
+ unique.c \
+ vdev.c \
+ vdev_draid.c \
+ vdev_draid_rand.c \
+ vdev_file.c \
+ vdev_indirect_births.c \
+ vdev_indirect.c \
+ vdev_indirect_mapping.c \
+ vdev_initialize.c \
+ vdev_label.c \
+ vdev_label_os.c \
+ vdev_mirror.c \
+ vdev_missing.c \
+ vdev_queue.c \
+ vdev_raidz.c \
+ vdev_raidz_math_aarch64_neon.c \
+ vdev_raidz_math_aarch64_neonx2.c \
+ vdev_raidz_math_avx2.c \
+ vdev_raidz_math_avx512bw.c \
+ vdev_raidz_math_avx512f.c \
+ vdev_raidz_math.c \
+ vdev_raidz_math_scalar.c \
+ vdev_rebuild.c \
+ vdev_removal.c \
+ vdev_root.c \
+ vdev_trim.c \
+ xxhash.c \
+ zap.c \
+ zap_leaf.c \
+ zap_micro.c \
+ zcp.c \
+ zcp_get.c \
+ zcp_global.c \
+ zcp_iter.c \
+ zcp_set.c \
+ zcp_synctask.c \
+ zfeature.c \
+ zfs_byteswap.c \
+ zfs_chksum.c \
+ zfs_crrd.c \
+ zfs_debug_common.c \
+ zfs_fm.c \
+ zfs_fuid.c \
+ zfs_sa.c \
+ zfs_znode.c \
+ zfs_racct.c \
+ zfs_ratelimit.c \
+ zfs_rlock.c \
+ zil.c \
+ zio.c \
+ zio_checksum.c \
+ zio_compress.c \
+ zio_crypt.c \
+ zio_inject.c \
+ zle.c \
+ zrlock.c \
+ zstd_common.c \
+ zstd_compress.c \
+ zstd_compress_literals.c \
+ zstd_compress_sequences.c \
+ zstd_compress_superblock.c \
+ zstd_ddict.c \
+ zstd_decompress.c \
+ zstd_decompress_block.c \
+ zstd_double_fast.c \
+ zstd_fast.c \
+ zstd_lazy.c \
+ zstd_ldm.c \
+ zstd_opt.c \
+ zthr.c
+
+ARCH_C =
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+ARCH_C += vdev_raidz_math_sse2.c \
+ vdev_raidz_math_ssse3.c \
+ zfs_fletcher_intel.c \
+ zfs_fletcher_sse.c
+CFLAGS += -DHAVE_SSE2 -DHAVE_SSE3
+.endif
+.if ${MACHINE_ARCH} == "amd64"
+ARCH_C += zfs_fletcher_avx512.c
+CFLAGS+= -DHAVE_AVX2 -DHAVE_AVX -D__x86_64 -DHAVE_AVX512F \
+ -DHAVE_AVX512BW
+.endif
+.if ${MACHINE_CPUARCH} == "aarch64"
+ARCH_C += zfs_fletcher_aarch64_neon.c
+.endif
+
+LUA_C = \
+ lapi.c \
+ lauxlib.c \
+ lbaselib.c \
+ lcode.c \
+ lcompat.c \
+ lcorolib.c \
+ lctype.c \
+ ldebug.c \
+ ldo.c \
+ lfunc.c \
+ lgc.c \
+ llex.c \
+ lmem.c \
+ lobject.c \
+ lopcodes.c \
+ lparser.c \
+ lstate.c \
+ lstring.c \
+ lstrlib.c \
+ ltable.c \
+ ltablib.c \
+ ltm.c \
+ lvm.c \
+ lzio.c
+
+UNICODE_C = u8_textprep.c
+
+SRCS+= ${USER_C} ${KERNEL_C} ${LUA_C} ${UNICODE_C} ${ARCH_C}
+
+
+WARNS?= 2
+CFLAGS+= \
+ -DIN_BASE \
+ -I${ZFSTOP}/include \
+ -I${ZFSTOP}/lib/libspl/include \
+ -I${ZFSTOP}/lib/libspl/include/os/freebsd \
+ -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include \
+ -I${SRCTOP}/sys \
+ -I${ZFSTOP}/include/os/freebsd/zfs \
+ -I${SRCTOP}/cddl/compat/opensolaris/include \
+ -I${ZFSTOP}/module/icp/include \
+ -I${SRCTOP}/compat/linuxkpi/common/include/linux \
+ -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h \
+ -DHAVE_ISSETUGID \
+ -include ${SRCTOP}/sys/modules/zfs/zfs_config.h \
+ -I${SRCTOP}/sys/modules/zfs \
+ -I${ZFSTOP}/include/os/freebsd/zfs \
+ -DLIB_ZPOOL_BUILD -DZFS_DEBUG \
+
+# XXX: pthread doesn't have mutex_owned() equivalent, so we need to look
+# into libthr private structures. That's sooo evil, but it's only for
+# ZFS debugging tools needs.
+CFLAGS+= -DWANTS_MUTEX_OWNED
+CFLAGS+= -I${SRCTOP}/lib/libpthread/thread
+CFLAGS+= -I${SRCTOP}/lib/libpthread/sys
+CFLAGS+= -I${SRCTOP}/lib/libthr/arch/${MACHINE_CPUARCH}/include
+CFLAGS.gcc+= -fms-extensions
+
+LIBADD= md pthread z spl icp nvpair avl umem
+
+CSTD= c99
+
+# Since there are many asserts in this library, it makes no sense to compile
+# it without debugging.
+
+CFLAGS+= -g -DDEBUG=1
+
+CFLAGS.gcc+= -Wno-pointer-to-int-cast
+
+# Pointer values are used as debugging "tags" to mark reference count
+# ownerships and in some cases the tag reference is dropped after an
+# object is freed.
+CFLAGS.dbuf.c= ${NO_WUSE_AFTER_FREE}
+CFLAGS.entropy_common.c= -fno-tree-vectorize
+CFLAGS.entropy_common.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.error_private.c= -fno-tree-vectorize
+CFLAGS.error_private.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.fse_compress.c= -fno-tree-vectorize
+CFLAGS.fse_compress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.fse_decompress.c= -fno-tree-vectorize
+CFLAGS.fse_decompress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.hist.c= -fno-tree-vectorize
+CFLAGS.hist.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.huf_compress.c= -fno-tree-vectorize
+CFLAGS.huf_compress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.huf_decompress.c= -fno-tree-vectorize
+CFLAGS.huf_decompress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.pool.c= -fno-tree-vectorize
+CFLAGS.pool.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.xxhash.c= -fno-tree-vectorize
+CFLAGS.xxhash.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_compress.c= -fno-tree-vectorize
+CFLAGS.zstd_compress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_compress_literals.c= -fno-tree-vectorize
+CFLAGS.zstd_compress_literals.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_compress_sequences.c= -fno-tree-vectorize
+CFLAGS.zstd_compress_sequences.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_compress_superblock.c= -fno-tree-vectorize
+CFLAGS.zstd_compress_superblock.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_double_fast.c= -fno-tree-vectorize
+CFLAGS.zstd_double_fast.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_fast.c= -fno-tree-vectorize
+CFLAGS.zstd_fast.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_lazy.c= -fno-tree-vectorize
+CFLAGS.zstd_lazy.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_ldm.c= -fno-tree-vectorize
+CFLAGS.zstd_ldm.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_opt.c= -fno-tree-vectorize
+CFLAGS.zstd_opt.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_ddict.c= -fno-tree-vectorize
+CFLAGS.zstd_ddict.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_decompress.c= -fno-tree-vectorize
+CFLAGS.zstd_decompress.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+CFLAGS.zstd_decompress_block.c= -fno-tree-vectorize
+CFLAGS.zstd_decompress_block.c+= ${NO_WBITWISE_INSTEAD_OF_LOGICAL}
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzpool/Makefile.depend b/cddl/lib/libzpool/Makefile.depend
new file mode 100644
index 000000000000..42b2995ff2d1
--- /dev/null
+++ b/cddl/lib/libzpool/Makefile.depend
@@ -0,0 +1,23 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libavl \
+ cddl/lib/libicp \
+ cddl/lib/libnvpair \
+ cddl/lib/libspl \
+ cddl/lib/libumem \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libmd \
+ lib/libthr \
+ lib/libz \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/libzutil/Makefile b/cddl/lib/libzutil/Makefile
new file mode 100644
index 000000000000..37e9e8dd5e63
--- /dev/null
+++ b/cddl/lib/libzutil/Makefile
@@ -0,0 +1,42 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzutil
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzutil/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/os/freebsd/zfs
+
+PACKAGE= zfs
+LIB_PACKAGE=
+
+LIB= zutil
+LIBADD= avl geom m tpool
+
+INCS = zutil_import.h
+
+SRCS = \
+ zutil_device_path.c \
+ zutil_import.c \
+ zutil_import.h \
+ zutil_nicenum.c \
+ zutil_pool.c
+
+SRCS += \
+ os/freebsd/zutil_device_path_os.c \
+ os/freebsd/zutil_import_os.c
+
+SRCS += zfs_ioctl_compat.c
+
+
+WARNS?= 2
+CSTD= c99
+
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzutil
+CFLAGS+= -DHAVE_ISSETUGID -DIN_BASE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libzutil/Makefile.depend b/cddl/lib/libzutil/Makefile.depend
new file mode 100644
index 000000000000..ddad58a70480
--- /dev/null
+++ b/cddl/lib/libzutil/Makefile.depend
@@ -0,0 +1,19 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libavl \
+ cddl/lib/libtpool \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libgeom \
+ lib/msun \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/cddl/lib/pam_zfs_key/Makefile b/cddl/lib/pam_zfs_key/Makefile
new file mode 100644
index 000000000000..517ca402d4da
--- /dev/null
+++ b/cddl/lib/pam_zfs_key/Makefile
@@ -0,0 +1,30 @@
+.PATH: ${SRCTOP}/sys/contrib/openzfs/contrib/pam_zfs_key
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+PACKAGE= zfs
+LIB= pam_zfs_key
+
+SHLIBDIR?= /usr/lib
+
+LIBADD= zfs zfs_core nvpair uutil crypto
+
+SRCS= pam_zfs_key.c
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS+= -DRUNSTATEDIR=\"/var/run\"
+
+.include "../../lib/libpam/modules/Makefile.inc"
+.include <bsd.lib.mk>
diff --git a/cddl/lib/tests/Makefile b/cddl/lib/tests/Makefile
new file mode 100644
index 000000000000..29b1b564beca
--- /dev/null
+++ b/cddl/lib/tests/Makefile
@@ -0,0 +1,4 @@
+.PATH: ${SRCTOP}/tests
+KYUAFILE= yes
+
+.include <bsd.test.mk>
diff --git a/cddl/lib/tests/Makefile.depend b/cddl/lib/tests/Makefile.depend
new file mode 100644
index 000000000000..11aba52f82cf
--- /dev/null
+++ b/cddl/lib/tests/Makefile.depend
@@ -0,0 +1,10 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif