Module Name:    src
Committed By:   christos
Date:           Sat Sep  8 14:02:15 UTC 2018

Modified Files:
        src/sys/external/bsd/libnv/dist: cnv.9 cnv.h cnvlist.c common_impl.h
            dnv.9 dnv.h dnvlist.c msgio.c msgio.h nv.9 nv.h nv_impl.h nvlist.c
            nvlist_impl.h nvpair.c nvpair_impl.h
Added Files:
        src/sys/external/bsd/libnv/dist: nv_compat.h nv_kern_netbsd.c

Log Message:
Add NetBSD stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/sys/external/bsd/libnv/dist/cnv.9 \
    src/sys/external/bsd/libnv/dist/cnv.h \
    src/sys/external/bsd/libnv/dist/cnvlist.c \
    src/sys/external/bsd/libnv/dist/common_impl.h \
    src/sys/external/bsd/libnv/dist/dnv.9 \
    src/sys/external/bsd/libnv/dist/dnv.h \
    src/sys/external/bsd/libnv/dist/dnvlist.c \
    src/sys/external/bsd/libnv/dist/msgio.c \
    src/sys/external/bsd/libnv/dist/msgio.h \
    src/sys/external/bsd/libnv/dist/nv.9 src/sys/external/bsd/libnv/dist/nv.h \
    src/sys/external/bsd/libnv/dist/nv_impl.h \
    src/sys/external/bsd/libnv/dist/nvlist.c \
    src/sys/external/bsd/libnv/dist/nvlist_impl.h \
    src/sys/external/bsd/libnv/dist/nvpair.c \
    src/sys/external/bsd/libnv/dist/nvpair_impl.h
cvs rdiff -u -r0 -r1.1 src/sys/external/bsd/libnv/dist/nv_compat.h \
    src/sys/external/bsd/libnv/dist/nv_kern_netbsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/libnv/dist/cnv.9
diff -u src/sys/external/bsd/libnv/dist/cnv.9:1.1.1.1 src/sys/external/bsd/libnv/dist/cnv.9:1.2
--- src/sys/external/bsd/libnv/dist/cnv.9:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/cnv.9	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,4 @@
+.\"	$NetBSD: cnv.9,v 1.2 2018/09/08 14:02:15 christos Exp $
 .\"
 .\" Copyright (c) 2016 Adam Starak <starak.a...@gmail.com>
 .\" All rights reserved.
Index: src/sys/external/bsd/libnv/dist/cnv.h
diff -u src/sys/external/bsd/libnv/dist/cnv.h:1.1.1.1 src/sys/external/bsd/libnv/dist/cnv.h:1.2
--- src/sys/external/bsd/libnv/dist/cnv.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/cnv.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: cnv.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -33,7 +35,7 @@
 
 #include <sys/cdefs.h>
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -70,7 +72,7 @@ const bool		*cnvlist_get_bool_array(cons
 const uint64_t		*cnvlist_get_number_array(const void *cookie, size_t *nitemsp);
 const char * const	*cnvlist_get_string_array(const void *cookie, size_t *nitemsp);
 const nvlist_t * const	*cnvlist_get_nvlist_array(const void *cookie, size_t *nitemsp);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int			 cnvlist_get_descriptor(const void *cookie);
 const int		*cnvlist_get_descriptor_array(const void *cookie, size_t *nitemsp);
 #endif
@@ -91,7 +93,7 @@ bool			 *cnvlist_take_bool_array(void *c
 uint64_t		 *cnvlist_take_number_array(void *cookie, size_t *nitemsp);
 char			**cnvlist_take_string_array(void *cookie, size_t *nitemsp);
 nvlist_t		**cnvlist_take_nvlist_array(void *cookie, size_t *nitemsp);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int			  cnvlist_take_descriptor(void *cookie);
 int			 *cnvlist_take_descriptor_array(void *cookie, size_t *nitemsp);
 #endif
@@ -110,7 +112,7 @@ void	cnvlist_free_bool_array(void *cooki
 void	cnvlist_free_number_array(void *cookie);
 void	cnvlist_free_string_array(void *cookie);
 void	cnvlist_free_nvlist_array(void *cookie);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void	cnvlist_free_descriptor(void *cookie);
 void	cnvlist_free_descriptor_array(void *cookie);
 #endif
Index: src/sys/external/bsd/libnv/dist/cnvlist.c
diff -u src/sys/external/bsd/libnv/dist/cnvlist.c:1.1.1.1 src/sys/external/bsd/libnv/dist/cnvlist.c:1.2
--- src/sys/external/bsd/libnv/dist/cnvlist.c:1.1.1.1	Sat Sep  8 09:27:47 2018
+++ src/sys/external/bsd/libnv/dist/cnvlist.c	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: cnvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -29,9 +31,13 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/sys/contrib/libnv/cnvlist.c 335343 2018-06-18 21:26:58Z oshogbo $");
+#else
+__RCSID("$NetBSD: cnvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $");
+#endif
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -39,7 +45,9 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <sys/systm.h>
 #include <sys/malloc.h>
 
+#ifdef __FreeBSD__
 #include <machine/stdarg.h>
+#endif
 
 #else
 #include <stdarg.h>
@@ -48,8 +56,13 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <stdlib.h>
 #endif
 
-#include <sys/cnv.h>
+#ifdef __FreeBSD__
 #include <sys/nv.h>
+#include <sys/cnv.h>
+#else
+#include "nv.h"
+#include "cnv.h"
+#endif
 
 #include "nv_impl.h"
 #include "nvlist_impl.h"
@@ -85,7 +98,7 @@ CNVLIST_GET(bool, bool, BOOL)
 CNVLIST_GET(uint64_t, number, NUMBER)
 CNVLIST_GET(const char *, string, STRING)
 CNVLIST_GET(const nvlist_t *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 CNVLIST_GET(int, descriptor, DESCRIPTOR)
 #endif
 
@@ -107,7 +120,7 @@ CNVLIST_GET_ARRAY(const bool *, bool_arr
 CNVLIST_GET_ARRAY(const uint64_t *, number_array, NUMBER_ARRAY)
 CNVLIST_GET_ARRAY(const char * const *, string_array, STRING_ARRAY)
 CNVLIST_GET_ARRAY(const nvlist_t * const *, nvlist_array, NVLIST_ARRAY)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 CNVLIST_GET_ARRAY(const int *, descriptor_array, DESCRIPTOR_ARRAY)
 #endif
 
@@ -144,7 +157,7 @@ CNVLIST_TAKE(bool, bool, BOOL)
 CNVLIST_TAKE(uint64_t, number, NUMBER)
 CNVLIST_TAKE(char *, string, STRING)
 CNVLIST_TAKE(nvlist_t *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 CNVLIST_TAKE(int, descriptor, DESCRIPTOR)
 #endif
 
@@ -172,7 +185,7 @@ CNVLIST_TAKE_ARRAY(bool *, bool_array, B
 CNVLIST_TAKE_ARRAY(uint64_t *, number_array, NUMBER_ARRAY)
 CNVLIST_TAKE_ARRAY(char **, string_array, STRING_ARRAY)
 CNVLIST_TAKE_ARRAY(nvlist_t **, nvlist_array, NVLIST_ARRAY)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 CNVLIST_TAKE_ARRAY(int *, descriptor_array, DESCRIPTOR_ARRAY);
 #endif
 
@@ -211,7 +224,7 @@ CNVLIST_FREE(bool_array)
 CNVLIST_FREE(number_array)
 CNVLIST_FREE(string_array)
 CNVLIST_FREE(nvlist_array)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 CNVLIST_FREE(descriptor)
 CNVLIST_FREE(descriptor_array)
 #endif
Index: src/sys/external/bsd/libnv/dist/common_impl.h
diff -u src/sys/external/bsd/libnv/dist/common_impl.h:1.1.1.1 src/sys/external/bsd/libnv/dist/common_impl.h:1.2
--- src/sys/external/bsd/libnv/dist/common_impl.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/common_impl.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: common_impl.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
Index: src/sys/external/bsd/libnv/dist/dnv.9
diff -u src/sys/external/bsd/libnv/dist/dnv.9:1.1.1.1 src/sys/external/bsd/libnv/dist/dnv.9:1.2
--- src/sys/external/bsd/libnv/dist/dnv.9:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/dnv.9	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,4 @@
+.\"	$NetBSD: dnv.9,v 1.2 2018/09/08 14:02:15 christos Exp $
 .\"
 .\" Copyright (c) 2016 Adam Starak <starak.a...@gmail.com>
 .\" All rights reserved.
Index: src/sys/external/bsd/libnv/dist/dnv.h
diff -u src/sys/external/bsd/libnv/dist/dnv.h:1.1.1.1 src/sys/external/bsd/libnv/dist/dnv.h:1.2
--- src/sys/external/bsd/libnv/dist/dnv.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/dnv.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: dnv.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -36,7 +38,7 @@
 
 #include <sys/cdefs.h>
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stddef.h>
Index: src/sys/external/bsd/libnv/dist/dnvlist.c
diff -u src/sys/external/bsd/libnv/dist/dnvlist.c:1.1.1.1 src/sys/external/bsd/libnv/dist/dnvlist.c:1.2
--- src/sys/external/bsd/libnv/dist/dnvlist.c:1.1.1.1	Sat Sep  8 09:27:47 2018
+++ src/sys/external/bsd/libnv/dist/dnvlist.c	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: dnvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -30,9 +32,13 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/sys/contrib/libnv/dnvlist.c 328474 2018-01-27 12:58:21Z oshogbo $");
+#else
+__RCSID("$NetBSD: dnvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $");
+#endif
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -40,7 +46,9 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <sys/systm.h>
 #include <sys/malloc.h>
 
+#ifndef __FreeBSD__
 #include <machine/stdarg.h>
+#endif
 
 #else
 #include <stdarg.h>
@@ -49,8 +57,13 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <stdlib.h>
 #endif
 
+#ifndef __FreeBSD__
 #include <sys/dnv.h>
 #include <sys/nv.h>
+#else
+#include "dnv.h"
+#include "nv.h"
+#endif
 
 #include "nv_impl.h"
 
@@ -69,7 +82,7 @@ DNVLIST_GET(bool, bool)
 DNVLIST_GET(uint64_t, number)
 DNVLIST_GET(const char *, string)
 DNVLIST_GET(const nvlist_t *, nvlist)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 DNVLIST_GET(int, descriptor)
 #endif
 
@@ -106,7 +119,7 @@ DNVLIST_TAKE(bool, bool)
 DNVLIST_TAKE(uint64_t, number)
 DNVLIST_TAKE(char *, string)
 DNVLIST_TAKE(nvlist_t *, nvlist)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 DNVLIST_TAKE(int, descriptor)
 #endif
 
Index: src/sys/external/bsd/libnv/dist/msgio.c
diff -u src/sys/external/bsd/libnv/dist/msgio.c:1.1.1.1 src/sys/external/bsd/libnv/dist/msgio.c:1.2
--- src/sys/external/bsd/libnv/dist/msgio.c:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/msgio.c	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: msgio.c,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -31,10 +33,15 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/lib/libnv/msgio.c 326219 2017-11-26 02:00:33Z pfg $");
+#else
+__RCSID("$NetBSD: msgio.c,v 1.2 2018/09/08 14:02:15 christos Exp $");
+#endif
 
 #include <sys/param.h>
 #include <sys/socket.h>
+#include <sys/select.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -58,7 +65,12 @@ __FBSDID("$FreeBSD: head/lib/libnv/msgio
 #define	PJDLOG_ABORT(...)		abort()
 #endif
 
+#ifdef __linux__
+/* Linux: arbitrary size, but must be lower than SCM_MAX_FD. */
+#define	PKG_MAX_SIZE	((64U - 1) * CMSG_SPACE(sizeof(int)))
+#else
 #define	PKG_MAX_SIZE	(MCLBYTES / CMSG_SPACE(sizeof(int)) - 1)
+#endif
 
 static int
 msghdr_add_fd(struct cmsghdr *cmsg, int fd)
@@ -162,6 +174,7 @@ msg_send(int sock, const struct msghdr *
 	return (0);
 }
 
+#ifdef __FreeBSD__
 int
 cred_send(int sock)
 {
@@ -237,6 +250,7 @@ cred_recv(int sock, struct cmsgcred *cre
 
 	return (0);
 }
+#endif
 
 static int
 fd_package_send(int sock, const int *fds, size_t nfds)
Index: src/sys/external/bsd/libnv/dist/msgio.h
diff -u src/sys/external/bsd/libnv/dist/msgio.h:1.1.1.1 src/sys/external/bsd/libnv/dist/msgio.h:1.2
--- src/sys/external/bsd/libnv/dist/msgio.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/msgio.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: msgio.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
Index: src/sys/external/bsd/libnv/dist/nv.9
diff -u src/sys/external/bsd/libnv/dist/nv.9:1.1.1.1 src/sys/external/bsd/libnv/dist/nv.9:1.2
--- src/sys/external/bsd/libnv/dist/nv.9:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nv.9	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,4 @@
+.\"	$NetBSD: nv.9,v 1.2 2018/09/08 14:02:15 christos Exp $
 .\"
 .\" Copyright (c) 2013 The FreeBSD Foundation
 .\" Copyright (c) 2013-2015 Mariusz Zaborski <osho...@freebsd.org>
Index: src/sys/external/bsd/libnv/dist/nv.h
diff -u src/sys/external/bsd/libnv/dist/nv.h:1.1.1.1 src/sys/external/bsd/libnv/dist/nv.h:1.2
--- src/sys/external/bsd/libnv/dist/nv.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nv.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nv.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
@@ -37,11 +39,13 @@
 
 #include <sys/cdefs.h>
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
+#else
+#include <sys/types.h>
 #endif
 
 #ifndef	_NVLIST_T_DECLARED
@@ -92,7 +96,7 @@ void		 nvlist_set_error(nvlist_t *nvl, i
 
 nvlist_t *nvlist_clone(const nvlist_t *nvl);
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void nvlist_dump(const nvlist_t *nvl, int fd);
 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
 #endif
@@ -132,7 +136,7 @@ bool nvlist_exists_bool_array(const nvli
 bool nvlist_exists_number_array(const nvlist_t *nvl, const char *name);
 bool nvlist_exists_string_array(const nvlist_t *nvl, const char *name);
 bool nvlist_exists_nvlist_array(const nvlist_t *nvl, const char *name);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
 bool nvlist_exists_descriptor_array(const nvlist_t *nvl, const char *name);
 #endif
@@ -157,7 +161,7 @@ void nvlist_add_bool_array(nvlist_t *nvl
 void nvlist_add_number_array(nvlist_t *nvl, const char *name, const uint64_t *value, size_t nitems);
 void nvlist_add_string_array(nvlist_t *nvl, const char *name, const char * const *value, size_t nitems);
 void nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t * const *value, size_t nitems);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
 void nvlist_add_descriptor_array(nvlist_t *nvl, const char *name, const int *value, size_t nitems);
 #endif
@@ -166,7 +170,7 @@ void nvlist_append_bool_array(nvlist_t *
 void nvlist_append_number_array(nvlist_t *nvl, const char *name, const uint64_t value);
 void nvlist_append_string_array(nvlist_t *nvl, const char *name, const char * const value);
 void nvlist_append_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t * const value);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void nvlist_append_descriptor_array(nvlist_t *nvl, const char *name, int value);
 #endif
 
@@ -182,7 +186,7 @@ void nvlist_move_bool_array(nvlist_t *nv
 void nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value, size_t nitems);
 void nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value, size_t nitems);
 void nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value, size_t nitems);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
 void nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value, size_t nitems);
 #endif
@@ -202,7 +206,7 @@ const bool		*nvlist_get_bool_array(const
 const uint64_t		*nvlist_get_number_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
 const char * const	*nvlist_get_string_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
 const nvlist_t * const	*nvlist_get_nvlist_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int			 nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
 const int		*nvlist_get_descriptor_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
 #endif
@@ -222,7 +226,7 @@ bool		 *nvlist_take_bool_array(nvlist_t 
 uint64_t	 *nvlist_take_number_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
 char		**nvlist_take_string_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
 nvlist_t	**nvlist_take_nvlist_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int		 nvlist_take_descriptor(nvlist_t *nvl, const char *name);
 int		 *nvlist_take_descriptor_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
 #endif
@@ -246,11 +250,33 @@ void nvlist_free_number_array(nvlist_t *
 void nvlist_free_string_array(nvlist_t *nvl, const char *name);
 void nvlist_free_nvlist_array(nvlist_t *nvl, const char *name);
 void nvlist_free_binary_array(nvlist_t *nvl, const char *name);
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
 void nvlist_free_descriptor_array(nvlist_t *nvl, const char *name);
 #endif
 
+#ifdef __NetBSD__
+/*
+ * ioctl kernel-userspace interface.
+ */
+
+typedef struct {
+	void *		buf;
+	size_t		len;
+	int		flags;
+} nvlist_ref_t;
+
+#if defined(_KERNEL)
+int nvlist_copyin(const nvlist_ref_t *nref, nvlist_t **nvlp, size_t lim);
+int nvlist_copyout(nvlist_ref_t *nref, const nvlist_t *nvl);
+#else
+int nvlist_xfer_ioctl(int fd, unsigned long cmd, const nvlist_t *nvl,
+    nvlist_t **nvlp);
+int nvlist_send_ioctl(int fd, unsigned long cmd, const nvlist_t *nvl);
+int nvlist_recv_ioctl(int fd, unsigned long cmd, nvlist_t **nvlp);
+#endif
+#endif
+
 __END_DECLS
 
 #endif	/* !_NV_H_ */
Index: src/sys/external/bsd/libnv/dist/nv_impl.h
diff -u src/sys/external/bsd/libnv/dist/nv_impl.h:1.1.1.1 src/sys/external/bsd/libnv/dist/nv_impl.h:1.2
--- src/sys/external/bsd/libnv/dist/nv_impl.h:1.1.1.1	Sat Sep  8 09:27:47 2018
+++ src/sys/external/bsd/libnv/dist/nv_impl.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nv_impl.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -35,6 +37,8 @@
 #ifndef	_NV_IMPL_H_
 #define	_NV_IMPL_H_
 
+#include "nv_compat.h"
+
 #ifndef	_NVPAIR_T_DECLARED
 #define	_NVPAIR_T_DECLARED
 struct nvpair;
@@ -51,22 +55,31 @@ typedef struct nvpair nvpair_t;
 #define	NV_FLAG_BIG_ENDIAN		0x080
 #define	NV_FLAG_IN_ARRAY		0x100
 
-#ifdef _KERNEL
+#if defined(_KERNEL)
 #define	nv_malloc(size)			malloc((size), M_NVLIST, M_WAITOK)
+#ifdef __FreeBSD__
 #define	nv_calloc(n, size)		mallocarray((n), (size), M_NVLIST, \
 					    M_WAITOK | M_ZERO)
+#else
+extern void *nv_calloc(size_t, size_t);
+#endif
 #define	nv_realloc(buf, size)		realloc((buf), (size), M_NVLIST, \
 					    M_WAITOK)
 #define	nv_free(buf)			free((buf), M_NVLIST)
+#ifdef __FreeBSD__
 #define	nv_strdup(buf)			strdup((buf), M_NVLIST)
+#else
+extern char *nv_strdup(const char *);
+#endif
+#define	nv_vasprintf(ptr, ...)		vasprintf(ptr, M_NVLIST, __VA_ARGS__)
+#endif
+#elif defined(_STANDALONE)
+extern void *nv_malloc(size_t);
+extern void *nv_calloc(size_t, size_t);
+extern void *nv_realloc(void *, size_t);
+extern void nv_free(void *);
+extern char *nv_strdup(const char *);
 #define	nv_vasprintf(ptr, ...)		vasprintf(ptr, M_NVLIST, __VA_ARGS__)
-
-#define	ERRNO_SET(var)			do { } while (0)
-#define	ERRNO_SAVE()			do { do { } while(0)
-#define	ERRNO_RESTORE()			} while (0)
-
-#define	ERRNO_OR_DEFAULT(default)	(default)
-
 #else
 
 #define	nv_malloc(size)			malloc((size))
@@ -89,6 +102,14 @@ typedef struct nvpair nvpair_t;
 
 #endif
 
+#ifndef ERRNO_SET
+#define	ERRNO_SET(var)			do { } while (/*CONSTCOND*/0)
+#define	ERRNO_SAVE()			do { do { } while(/*CONSTCOND*/0)
+#define	ERRNO_RESTORE()			} while (/*CONSTCOND*/0)
+
+#define	ERRNO_OR_DEFAULT(default)	(default)
+#endif
+
 int	*nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp);
 size_t	 nvlist_ndescriptors(const nvlist_t *nvl);
 void	 nvlist_set_flags(nvlist_t *nvl, int flags);
Index: src/sys/external/bsd/libnv/dist/nvlist.c
diff -u src/sys/external/bsd/libnv/dist/nvlist.c:1.1.1.1 src/sys/external/bsd/libnv/dist/nvlist.c:1.2
--- src/sys/external/bsd/libnv/dist/nvlist.c:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nvlist.c	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -31,13 +33,17 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/sys/contrib/libnv/nvlist.c 335347 2018-06-18 22:57:32Z oshogbo $");
+#else
+__RCSID("$NetBSD: nvlist.c,v 1.2 2018/09/08 14:02:15 christos Exp $");
+#endif
 
 #include <sys/param.h>
 #include <sys/endian.h>
 #include <sys/queue.h>
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 
 #include <sys/errno.h>
 #include <sys/kernel.h>
@@ -45,7 +51,9 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <sys/malloc.h>
 #include <sys/systm.h>
 
+#ifdef __FreeBSD__
 #include <machine/stdarg.h>
+#endif
 
 #else
 #include <sys/socket.h>
@@ -66,18 +74,27 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <pjdlog.h>
 #endif
 
+#ifdef __FreeBSD__
 #include <sys/nv.h>
+#else
+#incude "nv.h"
+#endif
 
 #include "nv_impl.h"
 #include "nvlist_impl.h"
 #include "nvpair_impl.h"
 
 #ifndef	HAVE_PJDLOG
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
+#ifdef __FreeBSD__
 #define	PJDLOG_ASSERT(...)		MPASS(__VA_ARGS__)
+#else
+#define	PJDLOG_ASSERT(...)		KASSERT(__VA_ARGS__)
+#endif
 #define	PJDLOG_RASSERT(expr, ...)	KASSERT(expr, (__VA_ARGS__))
 #define	PJDLOG_ABORT(...)		panic(__VA_ARGS__)
 #else
+#ifndef __lint__
 #include <assert.h>
 #define	PJDLOG_ASSERT(...)		assert(__VA_ARGS__)
 #define	PJDLOG_RASSERT(expr, ...)	assert(expr)
@@ -86,7 +103,12 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 	fprintf(stderr, __VA_ARGS__);					\
 	fprintf(stderr, "\n");						\
 	abort();							\
-} while (0)
+} while (/*CONSTCOND*/0)
+#else
+#define	PJDLOG_ASSERT(...)
+#define	PJDLOG_RASSERT(expr, ...)
+#define	PJDLOG_ABORT(...)
+#endif
 #endif
 #endif
 
@@ -107,7 +129,7 @@ struct nvlist {
 #define	NVLIST_ASSERT(nvl)	do {					\
 	PJDLOG_ASSERT((nvl) != NULL);					\
 	PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC);		\
-} while (0)
+} while (/*CONSTCOND*/0)
 
 #ifdef _KERNEL
 MALLOC_DEFINE(M_NVLIST, "nvlist", "kernel nvlist");
@@ -410,7 +432,7 @@ nvlist_clone(const nvlist_t *nvl)
 	return (newnvl);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 static bool
 nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
 {
@@ -705,7 +727,7 @@ out:
 	return (size);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 static int *
 nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
 {
@@ -764,7 +786,7 @@ nvlist_xdescriptors(const nvlist_t *nvl,
 }
 #endif
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int *
 nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
 {
@@ -787,7 +809,7 @@ nvlist_descriptors(const nvlist_t *nvl, 
 size_t
 nvlist_ndescriptors(const nvlist_t *nvl)
 {
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 	void *cookie;
 	nvpair_t *nvp;
 	size_t ndescs;
@@ -924,7 +946,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 			}
 			ptr = nvpair_pack_nvlist_up(ptr, &left);
 			break;
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 		case NV_TYPE_DESCRIPTOR:
 			ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
 			break;
@@ -1158,7 +1180,7 @@ nvlist_xunpack(const void *buf, size_t s
 				goto fail;
 			nvlist_set_parent(tmpnvl, nvp);
 			break;
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 		case NV_TYPE_DESCRIPTOR:
 			ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
 			    fds, nfds);
@@ -1242,7 +1264,7 @@ nvlist_unpack(const void *buf, size_t si
 	return (nvlist_xunpack(buf, size, NULL, 0, flags));
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE) && defined(WITH_MSGIO)
 int
 nvlist_send(int sock, const nvlist_t *nvl)
 {
@@ -1440,7 +1462,7 @@ NVLIST_EXISTS(bool_array, BOOL_ARRAY)
 NVLIST_EXISTS(number_array, NUMBER_ARRAY)
 NVLIST_EXISTS(string_array, STRING_ARRAY)
 NVLIST_EXISTS(nvlist_array, NVLIST_ARRAY)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_EXISTS(descriptor, DESCRIPTOR)
 NVLIST_EXISTS(descriptor_array, DESCRIPTOR_ARRAY)
 #endif
@@ -1476,6 +1498,7 @@ nvlist_add_nvpair(nvlist_t *nvl, const n
 	nvpair_insert(&nvl->nvl_head, newnvp, nvl);
 }
 
+#if !defined(_KERNEL) && !defined(_STANDALONE) && !defined(__NetBSD__)
 void
 nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
 {
@@ -1485,6 +1508,7 @@ nvlist_add_stringf(nvlist_t *nvl, const 
 	nvlist_add_stringv(nvl, name, valuefmt, valueap);
 	va_end(valueap);
 }
+#endif
 
 void
 nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
@@ -1570,7 +1594,7 @@ NVLIST_ADD(bool, bool)
 NVLIST_ADD(uint64_t, number)
 NVLIST_ADD(const char *, string)
 NVLIST_ADD(const nvlist_t *, nvlist)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_ADD(int, descriptor);
 #endif
 
@@ -1601,7 +1625,7 @@ NVLIST_ADD_ARRAY(const bool *, bool)
 NVLIST_ADD_ARRAY(const uint64_t *, number)
 NVLIST_ADD_ARRAY(const char * const *, string)
 NVLIST_ADD_ARRAY(const nvlist_t * const *, nvlist)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_ADD_ARRAY(const int *, descriptor)
 #endif
 
@@ -1632,7 +1656,7 @@ NVLIST_APPEND_ARRAY(const bool, bool, BO
 NVLIST_APPEND_ARRAY(const uint64_t, number, NUMBER)
 NVLIST_APPEND_ARRAY(const char *, string, STRING)
 NVLIST_APPEND_ARRAY(const nvlist_t *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_APPEND_ARRAY(const int, descriptor, DESCRIPTOR)
 #endif
 
@@ -1704,7 +1728,7 @@ nvlist_move_nvlist(nvlist_t *nvl, const 
 	}
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void
 nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value)
 {
@@ -1842,7 +1866,7 @@ nvlist_move_number_array(nvlist_t *nvl, 
 	}
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 void
 nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value,
     size_t nitems)
@@ -1894,7 +1918,7 @@ NVLIST_GET(bool, bool, BOOL)
 NVLIST_GET(uint64_t, number, NUMBER)
 NVLIST_GET(const char *, string, STRING)
 NVLIST_GET(const nvlist_t *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_GET(int, descriptor, DESCRIPTOR)
 #endif
 
@@ -1929,7 +1953,7 @@ NVLIST_GET_ARRAY(const bool *, bool, BOO
 NVLIST_GET_ARRAY(const uint64_t *, number, NUMBER)
 NVLIST_GET_ARRAY(const char * const *, string, STRING)
 NVLIST_GET_ARRAY(const nvlist_t * const *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_GET_ARRAY(const int *, descriptor, DESCRIPTOR)
 #endif
 
@@ -1955,7 +1979,7 @@ NVLIST_TAKE(bool, bool, BOOL)
 NVLIST_TAKE(uint64_t, number, NUMBER)
 NVLIST_TAKE(char *, string, STRING)
 NVLIST_TAKE(nvlist_t *, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_TAKE(int, descriptor, DESCRIPTOR)
 #endif
 
@@ -1998,7 +2022,7 @@ NVLIST_TAKE_ARRAY(bool *, bool, BOOL)
 NVLIST_TAKE_ARRAY(uint64_t *, number, NUMBER)
 NVLIST_TAKE_ARRAY(char **, string, STRING)
 NVLIST_TAKE_ARRAY(nvlist_t **, nvlist, NVLIST)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_TAKE_ARRAY(int *, descriptor, DESCRIPTOR)
 #endif
 
@@ -2038,7 +2062,7 @@ NVLIST_FREE(bool_array, BOOL_ARRAY)
 NVLIST_FREE(number_array, NUMBER_ARRAY)
 NVLIST_FREE(string_array, STRING_ARRAY)
 NVLIST_FREE(nvlist_array, NVLIST_ARRAY)
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 NVLIST_FREE(descriptor, DESCRIPTOR)
 NVLIST_FREE(descriptor_array, DESCRIPTOR_ARRAY)
 #endif
Index: src/sys/external/bsd/libnv/dist/nvlist_impl.h
diff -u src/sys/external/bsd/libnv/dist/nvlist_impl.h:1.1.1.1 src/sys/external/bsd/libnv/dist/nvlist_impl.h:1.2
--- src/sys/external/bsd/libnv/dist/nvlist_impl.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nvlist_impl.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nvlist_impl.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -35,9 +37,13 @@
 #ifndef	_NVLIST_IMPL_H_
 #define	_NVLIST_IMPL_H_
 
+#ifdef __FreeBSD__
 #include <sys/nv.h>
+#else
+#include "nv.h"
+#endif
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdint.h>
 #endif
 
Index: src/sys/external/bsd/libnv/dist/nvpair.c
diff -u src/sys/external/bsd/libnv/dist/nvpair.c:1.1.1.1 src/sys/external/bsd/libnv/dist/nvpair.c:1.2
--- src/sys/external/bsd/libnv/dist/nvpair.c:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nvpair.c	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nvpair.c,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -31,20 +33,26 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/sys/contrib/libnv/nvpair.c 335382 2018-06-19 18:43:02Z lwhsu $");
+#else
+__RCSID("$NetBSD: nvpair.c,v 1.2 2018/09/08 14:02:15 christos Exp $");
+#endif
 
 #include <sys/param.h>
 #include <sys/endian.h>
 #include <sys/queue.h>
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 
 #include <sys/errno.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/systm.h>
 
+#ifdef __FreeBSD__
 #include <machine/stdarg.h>
+#endif
 
 #else
 #include <errno.h>
@@ -63,22 +71,36 @@ __FBSDID("$FreeBSD: head/sys/contrib/lib
 #include <pjdlog.h>
 #endif
 
+#ifdef __FreeBSD__
 #include <sys/nv.h>
+#else
+#include "nv.h"
+#endif
 
 #include "nv_impl.h"
 #include "nvlist_impl.h"
 #include "nvpair_impl.h"
 
 #ifndef	HAVE_PJDLOG
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
+#ifdef __FreeBSD__
 #define	PJDLOG_ASSERT(...)		MPASS(__VA_ARGS__)
+#else
+#define	PJDLOG_ASSERT(...)		KASSERT(__VA_ARGS__)
+#endif
 #define	PJDLOG_RASSERT(expr, ...)	KASSERT(expr, (__VA_ARGS__))
 #define	PJDLOG_ABORT(...)		panic(__VA_ARGS__)
 #else
+#ifndef __lint__
 #include <assert.h>
 #define	PJDLOG_ASSERT(...)		assert(__VA_ARGS__)
 #define	PJDLOG_RASSERT(expr, ...)	assert(expr)
 #define	PJDLOG_ABORT(...)		abort()
+#else
+#define	PJDLOG_ASSERT(...)	
+#define	PJDLOG_RASSERT(expr, ...)
+#define	PJDLOG_ABORT(...)
+#endif
 #endif
 #endif
 
@@ -97,7 +119,7 @@ struct nvpair {
 #define	NVPAIR_ASSERT(nvp)	do {					\
 	PJDLOG_ASSERT((nvp) != NULL);					\
 	PJDLOG_ASSERT((nvp)->nvp_magic == NVPAIR_MAGIC);		\
-} while (0)
+} while (/*CONSTCOND*/0)
 
 struct nvpair_header {
 	uint8_t		nvph_type;
@@ -298,7 +320,7 @@ nvpair_clone(const nvpair_t *nvp)
 		data = nvpair_get_nvlist_array(nvp, &datasize);
 		newnvp = nvpair_create_nvlist_array(name, data, datasize);
 		break;
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 	case NV_TYPE_DESCRIPTOR:
 		newnvp = nvpair_create_descriptor(name,
 		    nvpair_get_descriptor(nvp));
@@ -470,7 +492,7 @@ nvpair_pack_nvlist_array_next(unsigned c
 	return (ptr);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 unsigned char *
 nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr, int64_t *fdidxp,
     size_t *leftp)
@@ -577,7 +599,7 @@ nvpair_pack_string_array(const nvpair_t 
 	return (ptr);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 unsigned char *
 nvpair_pack_descriptor_array(const nvpair_t *nvp, unsigned char *ptr,
     int64_t *fdidxp, size_t *leftp)
@@ -825,7 +847,7 @@ nvpair_unpack_nvlist(bool isbe __unused,
 	return (ptr);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 const unsigned char *
 nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
     size_t *leftp, const int *fds, size_t nfds)
@@ -1018,7 +1040,7 @@ out:
 	return (NULL);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE) && !defined(__NetBSD__)
 const unsigned char *
 nvpair_unpack_descriptor_array(bool isbe, nvpair_t *nvp,
     const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds)
@@ -1270,7 +1292,7 @@ nvpair_create_nvlist(const char *name, c
 	return (nvp);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 nvpair_t *
 nvpair_create_descriptor(const char *name, int value)
 {
@@ -1494,7 +1516,7 @@ fail:
 	return (NULL);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 nvpair_t *
 nvpair_create_descriptor_array(const char *name, const int *value,
     size_t nitems)
@@ -1593,7 +1615,7 @@ nvpair_move_nvlist(const char *name, nvl
 	return (nvp);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 nvpair_t *
 nvpair_move_descriptor(const char *name, int value)
 {
@@ -1767,7 +1789,7 @@ fail:
 	return (NULL);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 nvpair_t *
 nvpair_move_descriptor_array(const char *name, int *value, size_t nitems)
 {
@@ -1843,7 +1865,7 @@ nvpair_get_nvlist(const nvpair_t *nvp)
 	return ((const nvlist_t *)(intptr_t)nvp->nvp_data);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int
 nvpair_get_descriptor(const nvpair_t *nvp)
 {
@@ -1920,7 +1942,7 @@ nvpair_get_nvlist_array(const nvpair_t *
 	return ((const nvlist_t * const *)((intptr_t)nvp->nvp_data));
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 const int *
 nvpair_get_descriptor_array(const nvpair_t *nvp, size_t *nitems)
 {
@@ -2027,7 +2049,7 @@ fail:
 	return (-1);
 }
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 int
 nvpair_append_descriptor_array(nvpair_t *nvp, const int value)
 {
@@ -2061,7 +2083,7 @@ nvpair_free(nvpair_t *nvp)
 
 	nvp->nvp_magic = 0;
 	switch (nvp->nvp_type) {
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 	case NV_TYPE_DESCRIPTOR:
 		close((int)nvp->nvp_data);
 		break;
Index: src/sys/external/bsd/libnv/dist/nvpair_impl.h
diff -u src/sys/external/bsd/libnv/dist/nvpair_impl.h:1.1.1.1 src/sys/external/bsd/libnv/dist/nvpair_impl.h:1.2
--- src/sys/external/bsd/libnv/dist/nvpair_impl.h:1.1.1.1	Sat Sep  8 09:27:48 2018
+++ src/sys/external/bsd/libnv/dist/nvpair_impl.h	Sat Sep  8 10:02:15 2018
@@ -1,3 +1,5 @@
+/*	$NetBSD: nvpair_impl.h,v 1.2 2018/09/08 14:02:15 christos Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -35,10 +37,14 @@
 #ifndef	_NVPAIR_IMPL_H_
 #define	_NVPAIR_IMPL_H_
 
+#ifdef __FreeBSD__
 #include <sys/nv.h>
+#else
+#include "nv.h"
+#endif
 #include <sys/queue.h>
 
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdint.h>
 #endif
 

Added files:

Index: src/sys/external/bsd/libnv/dist/nv_compat.h
diff -u /dev/null src/sys/external/bsd/libnv/dist/nv_compat.h:1.1
--- /dev/null	Sat Sep  8 10:02:15 2018
+++ src/sys/external/bsd/libnv/dist/nv_compat.h	Sat Sep  8 10:02:15 2018
@@ -0,0 +1,96 @@
+/*	$NetBSD: nv_compat.h,v 1.1 2018/09/08 14:02:15 christos Exp $	*/
+
+/*
+ * Copyright (c) 1987, 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)endian.h	8.1 (Berkeley) 6/11/93
+ */
+
+#ifndef	_NV_COMPAT_H_
+#define	_NV_COMPAT_H_
+
+#if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))
+#ifdef _KERNEL
+#include <sys/malloc.h>
+#define	M_NVLIST		M_TEMP
+#endif
+#include <sys/stdarg.h>
+#include <lib/libkern/libkern.h>
+
+#endif
+
+#ifndef	__unused
+#define	__unused		__attribute__((__unused__))
+#endif
+
+#ifndef	__DECONST
+#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
+#endif
+
+#ifndef	__printflike
+#define __printflike(fmtarg, firstvararg)	\
+	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
+#endif
+
+#ifdef __linux__
+#include <endian.h>
+#else
+#include <sys/endian.h>
+#endif
+
+#ifdef __linux__
+static inline uint32_t
+be32dec(const void *buf)
+{
+	uint8_t const *p = (uint8_t const *)buf;
+	return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static inline uint32_t
+le32dec(const void *buf)
+{
+	uint8_t const *p = (uint8_t const *)buf;
+	return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+}
+
+static inline uint64_t
+be64dec(const void *buf)
+{
+	uint8_t const *p = (uint8_t const *)buf;
+	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
+}
+
+static inline uint64_t
+le64dec(const void *buf)
+{
+	uint8_t const *p = (uint8_t const *)buf;
+	return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
+}
+#endif
+
+#endif
Index: src/sys/external/bsd/libnv/dist/nv_kern_netbsd.c
diff -u /dev/null src/sys/external/bsd/libnv/dist/nv_kern_netbsd.c:1.1
--- /dev/null	Sat Sep  8 10:02:15 2018
+++ src/sys/external/bsd/libnv/dist/nv_kern_netbsd.c	Sat Sep  8 10:02:15 2018
@@ -0,0 +1,255 @@
+/*	$NetBSD: nv_kern_netbsd.c,v 1.1 2018/09/08 14:02:15 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Mindaugas Rasiukevicius.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/ctypes.h>
+__RCSID("$NetBSD: nv_kern_netbsd.c,v 1.1 2018/09/08 14:02:15 christos Exp $");
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <sys/mman.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#endif
+#ifdef _KERNEL
+#include <sys/param.h>
+#include <sys/lwp.h>
+#include <sys/kmem.h>
+#include <sys/malloc.h>
+#include <sys/mman.h>
+#include <uvm/uvm_extern.h>
+#endif
+#ifdef _STANDALONE
+/* XXX */
+extern void *alloc(unsigned int);
+extern void dealloc(void *, unsigned int);
+// #include "stand.h"
+#else
+#include <sys/ioctl.h>
+#endif
+#include "nv.h"
+#include "nv_impl.h"
+
+#ifndef _STANDALONE
+#ifdef _KERNEL
+
+int
+nvlist_copyin(const nvlist_ref_t *nref, nvlist_t **nvlp, size_t lim)
+{
+	const size_t len = nref->len;
+	nvlist_t *nvl;
+	void *buf;
+	int error;
+
+	if (len >= lim) {
+		return E2BIG;
+	}
+	buf = kmem_alloc(len, KM_SLEEP);
+	error = copyin(nref->buf, buf, len);
+	if (error) {
+		kmem_free(buf, len);
+		return error;
+	}
+	nvl = nvlist_unpack(buf, len, nref->flags);
+	kmem_free(buf, len);
+	if (nvl == NULL) {
+		return EINVAL;
+	}
+	*nvlp = nvl;
+	return 0;
+}
+
+int
+nvlist_copyout(nvlist_ref_t *nref, const nvlist_t *nvl)
+{
+	struct proc *p = curproc;
+	void *buf, *uaddr;
+	size_t len, rlen;
+	int error;
+
+	buf = nvlist_pack(nvl, &len);
+	if (buf == NULL) {
+		return ENOMEM;
+	}
+
+	/*
+	 * Map the user page(s).
+	 *
+	 * Note: nvlist_recv_ioctl() will unmap it.
+	 */
+	uaddr = NULL;
+	rlen = round_page(len);
+	error = uvm_mmap_anon(p, &uaddr, rlen);
+	if (error) {
+		goto err;
+	}
+	error = copyout(buf, uaddr, len);
+	if (error) {
+		uvm_unmap(&p->p_vmspace->vm_map, (vaddr_t)uaddr,
+		    (vaddr_t)uaddr + len);
+		goto err;
+	}
+	nref->flags = nvlist_error(nvl);
+	nref->buf = uaddr;
+	nref->len = len;
+err:
+	free(buf, M_TEMP);
+	return error;
+}
+
+#else
+
+int
+nvlist_xfer_ioctl(int fd, unsigned long cmd, const nvlist_t *nvl,
+    nvlist_t **nvlp)
+{
+	nvlist_ref_t nref;
+	void *buf = NULL;
+
+	memset(&nref, 0, sizeof(nvlist_ref_t));
+
+	if (nvl) {
+		/*
+		 * Sending: serialize the name-value list.
+		 */
+		buf = nvlist_pack(nvl, &nref.len);
+		if (buf == NULL) {
+			errno = ENOMEM;
+			return -1;
+		}
+		nref.buf = buf;
+		nref.flags = nvlist_flags(nvl);
+	}
+
+	/*
+	 * Exchange the nvlist reference data.
+	 */
+	if (ioctl(fd, cmd, &nref) == -1) {
+		free(buf);
+		return -1;
+	}
+	free(buf);
+
+	if (nvlp) {
+		nvlist_t *retnvl;
+
+		/*
+		 * Receiving: unserialize the nvlist.
+		 *
+		 * Note: pages are mapped by nvlist_kern_copyout() for us.
+		 */
+		if (nref.buf == NULL || nref.len == 0) {
+			errno = EIO;
+			return -1;
+		}
+		retnvl = nvlist_unpack(nref.buf, nref.len, nref.flags);
+		munmap(nref.buf, nref.len);
+		if (retnvl == NULL) {
+			errno = EIO;
+			return -1;
+		}
+		*nvlp = retnvl;
+	}
+	return 0;
+}
+
+int
+nvlist_send_ioctl(int fd, unsigned long cmd, const nvlist_t *nvl)
+{
+	return nvlist_xfer_ioctl(fd, cmd, nvl, NULL);
+}
+
+int
+nvlist_recv_ioctl(int fd, unsigned long cmd, nvlist_t **nvlp)
+{
+	return nvlist_xfer_ioctl(fd, cmd, NULL, nvlp);
+}
+#endif
+#endif
+
+void *
+nv_calloc(size_t n, size_t s)
+{
+	n *= s;
+	void *buf = nv_malloc(n);
+	if (buf == NULL)
+		return NULL;
+	memset(buf, 0, n);
+	return buf;
+}
+
+char *
+nv_strdup(const char *s1)
+{
+	size_t len = strlen(s1) + 1;
+	char *s2;
+
+	s2 = nv_malloc(len);
+	if (s2) {
+		memcpy(s2, s1, len);
+		s2[len] = '\0';
+	}
+	return s2;
+}
+
+#ifdef _STANDALONE
+
+void *
+nv_malloc(size_t len)
+{
+	return alloc(len);
+}
+
+void 
+nv_free(void *buf)
+{
+	if (buf == NULL)
+		return;
+	unsigned int *olen = (void *)((char *)buf - sizeof(unsigned int));
+	dealloc(buf, *olen);
+}
+
+void *
+nv_realloc(void *buf, size_t len)
+{
+	if (buf == NULL)
+		return alloc(len);
+
+	unsigned int *olen = (void *)((char *)buf - sizeof(unsigned int));
+	if (*olen < len)
+		return buf;
+
+	void *nbuf = alloc(len);
+	memcpy(nbuf, buf, *olen);
+	dealloc(buf, *olen);
+	return nbuf;
+}
+#endif

Reply via email to