Resolve conflicts from previous merge (all resulting from $NetBSD prg-localcount2
authorpgoyette <pgoyette@NetBSD.org>
Fri, 19 May 2017 00:22:50 +0000
branchprg-localcount2
changeset 279125 61d81c0ff0a6
parent 279124 40ff68699e63
child 445114 b3b0cb9510c4
Resolve conflicts from previous merge (all resulting from $NetBSD keywork expansion)
bin/sh/Makefile
bin/sh/builtins.def
bin/sh/eval.c
bin/sh/exec.c
bin/sh/jobs.c
bin/sh/main.c
bin/sh/miscbltin.c
bin/sh/options.c
bin/sh/options.h
bin/sh/output.c
bin/sh/parser.c
bin/sh/redir.c
bin/sh/sh.1
bin/sh/shell.h
bin/sh/show.c
bin/sh/show.h
bin/sh/syntax.h
bin/sh/var.c
distrib/amd64/installimage/Makefile
distrib/amd64/uefi-installimage/Makefile
distrib/arc/ramdisk/Makefile
distrib/notes/common/main
distrib/sets/lists/base/shl.mi
distrib/sets/lists/debug/shl.mi
distrib/sets/lists/man/mi
distrib/sets/lists/tests/mi
distrib/utils/embedded/conf/evbarm.conf
doc/CHANGES
etc/mtree/NetBSD.dist.tests
external/bsd/atf/dist/atf-sh/atf-sh-api.3
external/bsd/bind/lib/libdns/Makefile
external/cddl/osnet/dist/cmd/dtrace/dtrace.1
external/gpl3/gcc/dist/gcc/auto-profile.c
external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c
external/gpl3/gcc/dist/gcc/system.h
lib/libc/gen/assert.c
lib/libc/gen/signalname.3
lib/libc/sys/execve.2
lib/libc/sys/getdents.2
lib/libc/sys/intro.2
lib/libc/sys/lfs_markv.2
lib/libc/sys/lfs_segclean.2
lib/libc/sys/lfs_segwait.2
lib/libc/sys/mmap.2
lib/libc/sys/mount.2
lib/libc/sys/mprotect.2
lib/libc/sys/open.2
lib/libc/sys/statvfs.2
lib/libc/sys/sync.2
lib/libc/sys/truncate.2
lib/libc/sys/undelete.2
lib/libcurses/curses.3
lib/libm/compat/compat_cabs.c
lib/libm/compat/compat_cabsf.c
lib/libm/shlib_version
lib/librumpclient/Makefile
lib/librumpclient/rumpclient.h
lib/librumphijack/Makefile
lib/librumpuser/Makefile
lib/librumpuser/rumpuser_port.h
lib/libterminfo/term.c
regress/Makefile
regress/sys/Makefile
regress/sys/crypto/Makefile
regress/sys/crypto/Makefile.inc
regress/sys/crypto/blowfish/Makefile
regress/sys/crypto/blowfish/bftest.c
regress/sys/crypto/blowfish_asm/Makefile
regress/sys/crypto/cast128/Makefile
regress/sys/crypto/cast128/casttest.c
regress/sys/crypto/des/Makefile
regress/sys/crypto/des/destest.c
regress/sys/crypto/des_asm/Makefile
regress/sys/crypto/rijndael/Makefile
regress/sys/crypto/rijndael/rijndaeltest.c
regress/sys/fs/Makefile
regress/sys/fs/getdents/Makefile
regress/sys/fs/getdents/getdents.c
regress/sys/fs/lseek/Makefile
regress/sys/fs/lseek/lseek.c
regress/sys/kern/callout1/Makefile
regress/sys/kern/callout1/test_callout1.c
regress/sys/kern/mutex1/Makefile
regress/sys/kern/mutex1/test_mutex1.c
regress/sys/kern/mutex2/Makefile
regress/sys/kern/mutex2/test_mutex2.c
regress/sys/kern/priority_inheritance1/Makefile
regress/sys/kern/priority_inheritance1/test_priority_inheritance1.c
regress/sys/kern/rwlock1/Makefile
regress/sys/kern/rwlock1/test_rwlock1.c
regress/sys/net/Makefile
regress/sys/net/bpf/Makefile
regress/sys/net/bpf/interface/Makefile
regress/sys/net/bpf/interface/interface.c
regress/sys/net/bpf/out-of-bounds/Makefile
regress/sys/net/bpf/out-of-bounds/out-of-bounds.sh
regress/sys/uvm/Makefile
regress/sys/uvm/Makefile.inc
regress/sys/uvm/stack_exec/Makefile
regress/sys/uvm/stack_exec/tramptest.c
regress/sys/uvm/stack_noexec/Makefile
regress/sys/uvm/stack_noexec/tramptest.c
regress/usr.bin/Makefile
regress/usr.bin/c++/Makefile
regress/usr.bin/c++/static_destructor/Makefile
regress/usr.bin/c++/static_destructor/expected
regress/usr.bin/c++/static_destructor/static_destructor.cc
regress/usr.bin/rtld/Makefile
regress/usr.bin/rtld/testlib/Makefile
regress/usr.bin/rtld/testlib/ccexc.cc
regress/usr.bin/rtld/testlib/construct.cc
regress/usr.bin/rtld/testlib/virt.cc
share/man/man4/Makefile
share/man/man4/vioscsi.4
share/man/man4/virtio.4
share/man/man9/uvm_map.9
share/misc/acronyms.comp
share/misc/airport
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/arm/arm/ast.c
sys/arch/evbmips/conf/LOONGSON
sys/arch/mips/mips/cache.c
sys/arch/mips/mips/mipsX_subr.S
sys/arch/mips/mips/pmap_machdep.c
sys/arch/mips/mips/vm_machdep.c
sys/arch/pmax/ibus/dz_ibus.c
sys/arch/pmax/pmax/bus.c
sys/arch/pmax/pmax/bus_dma.c
sys/arch/x86/include/cpu.h
sys/arch/x86/include/specialreg.h
sys/arch/x86/x86/procfs_machdep.c
sys/dev/audio.c
sys/dev/i2c/axp20x.c
sys/dev/ic/rtl8169.c
sys/dev/pci/if_re_pci.c
sys/dev/pci/if_rtwn.c
sys/dev/pci/if_vioif.c
sys/dev/pci/ixgbe/ix_txrx.c
sys/dev/pci/ixgbe/ixgbe.c
sys/dev/pci/ixgbe/ixgbe_type.h
sys/dev/pci/vioscsi.c
sys/dev/rasops/rasops.c
sys/dev/usb/uaudio.c
sys/dev/usb/uts.c
sys/external/bsd/ipf/netinet/ip_fil_netbsd.c
sys/kern/kern_descrip.c
sys/kern/kern_event.c
sys/kern/vfs_mount.c
sys/kern/vfs_vnode.c
sys/modules/lua/lua.c
sys/net/npf/npf_ctl.c
sys/netinet/if_arp.c
sys/netinet/in.c
sys/netinet/in_var.h
sys/netinet/ip_carp.c
sys/netinet/ip_output.c
sys/netinet6/mld6.c
sys/netipsec/ipsec.c
sys/netipsec/ipsec.h
sys/netipsec/ipsec_input.c
sys/netipsec/ipsec_output.c
sys/netipsec/key.c
sys/netipsec/key.h
sys/netipsec/keydb.h
sys/netipsec/keysock.c
sys/netipsec/xform_ah.c
sys/netipsec/xform_esp.c
sys/netipsec/xform_ipcomp.c
sys/netipsec/xform_ipip.c
sys/opencrypto/crypto.c
sys/opencrypto/cryptodev.c
sys/opencrypto/cryptodev.h
sys/opencrypto/cryptosoft.c
sys/opencrypto/deflate.c
sys/opencrypto/ocryptodev.c
sys/rump/include/rump/rump.h
sys/rump/librump/rumpkern/vm.c
sys/uvm/pmap/pmap.c
sys/uvm/pmap/pmap_segtab.c
sys/uvm/uvm_extern.h
sys/uvm/uvm_map.h
tests/bin/sh/t_expand.sh
tests/bin/sh/t_redircloexec.sh
tests/net/carp/t_basic.sh
tests/net/ipsec/Makefile
tests/net/ipsec/algorithms.sh
tests/net/ipsec/common.sh
tests/net/ipsec/t_ipsec_gif.sh
tests/net/ipsec/t_ipsec_l2tp.sh
tests/net/ipsec/t_ipsec_misc.sh
tests/net/ipsec/t_ipsec_transport.sh
tests/net/ipsec/t_ipsec_tunnel.sh
tests/net/ipsec/t_ipsec_tunnel_odd.sh
tests/net/net_common.sh
tests/usr.bin/Makefile
tests/usr.bin/c++/Makefile
tests/usr.bin/c++/t_cxxruntime.sh
tests/usr.bin/c++/t_hello.sh
tests/usr.bin/c++/t_static_destructor.sh
tests/usr.bin/cc/t_hello.sh
usr.bin/infocmp/infocmp.c
usr.bin/rump_allserver/Makefile
usr.bin/rump_dhcpclient/Makefile
usr.bin/rump_halt/Makefile
usr.bin/rump_server/Makefile
usr.bin/su/su.1
usr.sbin/npf/npfctl/npf_show.c
usr.sbin/npf/npftest/npftest.c
--- a/bin/sh/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.104 2017/03/20 11:26:07 kre Exp $
+#	$NetBSD: Makefile,v 1.104.2.1 2017/05/19 00:22:50 pgoyette Exp $
 #	@(#)Makefile	8.4 (Berkeley) 5/5/95
 
 .include <bsd.own.mk>
@@ -14,8 +14,8 @@
 
 DPSRCS+=${GENHDRS}
 
-LDADD+=	-ll -ledit -lterminfo
-DPADD+=	${LIBL} ${LIBEDIT} ${LIBTERMINFO}
+LDADD+=	-ledit -lterminfo
+DPADD+=	${LIBEDIT} ${LIBTERMINFO}
 
 # Environment for scripts executed during build.
 SCRIPT_ENV= \
@@ -29,6 +29,14 @@
 #CFLAGS+=-funsigned-char
 #TARGET_CHARFLAG?= -DTARGET_CHAR="unsigned char" -funsigned-char
 
+# Reproducible build parameters ... export into sh for NETBSD_SHELL setting
+.if ${MKREPRO_TIMESTAMP:Uno} != "no"
+BUILD_DATE!=	date -u -r "${MKREPRO_TIMESTAMP}" "+%Y%m%d%H%M%S"
+# These are (should be) equivalent, but the 2nd is easier to understand
+#CPPFLAGS+= -DBUILD_DATE='"${BUILD_DATE:C/([^0]0?)(00)*$/\1/}Z"'
+CPPFLAGS+= -DBUILD_DATE='"${BUILD_DATE:S/00$//:S/00$//:S/00$//}Z"'
+.endif
+
 .ifdef SMALLPROG
 CPPFLAGS+=-DSMALL
 .endif
--- a/bin/sh/builtins.def	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/builtins.def	Fri May 19 00:22:50 2017 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#	$NetBSD: builtins.def,v 1.24 2017/02/02 20:00:40 christos Exp $
+#	$NetBSD: builtins.def,v 1.24.2.1 2017/05/19 00:22:50 pgoyette Exp $
 #
 # Copyright (c) 1991, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -91,4 +91,8 @@
 wordexpcmd	wordexp
 #newgrp		-u newgrp	# optional command in posix
 
+#ifdef	DEBUG
+debugcmd	debug
+#endif
+
 #exprcmd	expr
--- a/bin/sh/eval.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/eval.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.131.2.1 2017/05/11 02:58:28 pgoyette Exp $	*/
+/*	$NetBSD: eval.c,v 1.131.2.2 2017/05/19 00:22:50 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.131.2.1 2017/05/11 02:58:28 pgoyette Exp $");
+__RCSID("$NetBSD: eval.c,v 1.131.2.2 2017/05/19 00:22:50 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -931,6 +931,7 @@
 			savelocalvars = localvars;
 			localvars = NULL;
 			vforked = 1;
+	VFORK_BLOCK
 			switch (pid = vfork()) {
 			case -1:
 				serrno = errno;
@@ -942,6 +943,7 @@
 				/* Make sure that exceptions only unwind to
 				 * after the vfork(2)
 				 */
+				SHELL_FORKED();
 				if (setjmp(jmploc.loc)) {
 					if (exception == EXSHELLPROC) {
 						/* We can't progress with the vfork,
@@ -960,6 +962,7 @@
 				forkchild(jp, cmd, mode, vforked);
 				break;
 			default:
+				VFORK_UNDO();
 				handler = savehandler;	/* restore from vfork(2) */
 				poplocalvars();
 				localvars = savelocalvars;
@@ -974,6 +977,7 @@
 				forkparent(jp, cmd, mode, pid);
 				goto parent;
 			}
+	VFORK_END
 		} else {
 normal_fork:
 #endif
--- a/bin/sh/exec.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/exec.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.c,v 1.46 2016/05/03 17:21:02 christos Exp $	*/
+/*	$NetBSD: exec.c,v 1.46.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)exec.c	8.4 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: exec.c,v 1.46 2016/05/03 17:21:02 christos Exp $");
+__RCSID("$NetBSD: exec.c,v 1.46.6.1 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -340,32 +340,82 @@
 	struct tblentry **pp;
 	struct tblentry *cmdp;
 	int c;
-	int verbose;
 	struct cmdentry entry;
 	char *name;
+	int allopt=0, bopt=0, fopt=0, ropt=0, sopt=0, uopt=0, verbose=0;
 
-	verbose = 0;
-	while ((c = nextopt("rv")) != '\0') {
-		if (c == 'r') {
-			clearcmdentry(0);
-		} else if (c == 'v') {
-			verbose++;
+	while ((c = nextopt("bcfrsuv")) != '\0')
+		switch (c) {
+		case 'b':	bopt = 1;	break;
+		case 'c':	uopt = 1;	break;	/* c == u */
+		case 'f':	fopt = 1;	break;
+		case 'r':	ropt = 1;	break;
+		case 's':	sopt = 1;	break;
+		case 'u':	uopt = 1;	break;
+		case 'v':	verbose = 1;	break;
 		}
-	}
+
+	if (ropt)
+		clearcmdentry(0);
+
+	if (bopt == 0 && fopt == 0 && sopt == 0 && uopt == 0)
+		allopt = bopt = fopt = sopt = uopt = 1;
+
 	if (*argptr == NULL) {
 		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
 			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-				if (verbose || cmdp->cmdtype == CMDNORMAL)
+				switch (cmdp->cmdtype) {
+				case CMDNORMAL:
+					if (!uopt)
+						continue;
+					break;
+				case CMDBUILTIN:
+					if (!bopt)
+						continue;
+					break;
+				case CMDSPLBLTIN:
+					if (!sopt)
+						continue;
+					break;
+				case CMDFUNCTION:
+					if (!fopt)
+						continue;
+					break;
+				default:	/* never happens */
+					continue;
+				}
+				if (!allopt || verbose ||
+				    cmdp->cmdtype == CMDNORMAL)
 					printentry(cmdp, verbose);
 			}
 		}
 		return 0;
 	}
-	while ((name = *argptr) != NULL) {
-		if ((cmdp = cmdlookup(name, 0)) != NULL
-		 && (cmdp->cmdtype == CMDNORMAL
-		     || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
-			delete_cmd_entry();
+
+	while ((name = *argptr++) != NULL) {
+		if ((cmdp = cmdlookup(name, 0)) != NULL) {
+			switch (cmdp->cmdtype) {
+			case CMDNORMAL:
+				if (!uopt)
+					continue;
+				delete_cmd_entry();
+				break;
+			case CMDBUILTIN:
+				if (!bopt)
+					continue;
+				if (builtinloc >= 0)
+					delete_cmd_entry();
+				break;
+			case CMDSPLBLTIN:
+				if (!sopt)
+					continue;
+				break;
+			case CMDFUNCTION:
+				if (!fopt)
+					continue;
+				break;
+			}
+		}
 		find_command(name, &entry, DO_ERR, pathval());
 		if (verbose) {
 			if (entry.cmdtype != CMDUNKNOWN) {	/* if no error msg */
@@ -375,12 +425,10 @@
 			}
 			flushall();
 		}
-		argptr++;
 	}
 	return 0;
 }
 
-
 STATIC void
 printentry(struct tblentry *cmdp, int verbose)
 {
@@ -396,16 +444,24 @@
 			name = padvance(&path, cmdp->cmdname);
 			stunalloc(name);
 		} while (--idx >= 0);
+		if (verbose)
+			out1fmt("Command from PATH[%d]: ",
+			    cmdp->param.index);
 		out1str(name);
 		break;
 	case CMDSPLBLTIN:
-		out1fmt("special builtin %s", cmdp->cmdname);
-		break;
+		if (verbose)
+			out1str("special ");
+		/* FALLTHROUGH */
 	case CMDBUILTIN:
-		out1fmt("builtin %s", cmdp->cmdname);
+		if (verbose)
+			out1str("builtin ");
+		out1fmt("%s", cmdp->cmdname);
 		break;
 	case CMDFUNCTION:
-		out1fmt("function %s", cmdp->cmdname);
+		if (verbose)
+			out1str("function ");
+		out1fmt("%s", cmdp->cmdname);
 		if (verbose) {
 			struct procstat ps;
 			INTOFF;
@@ -417,7 +473,8 @@
 		}
 		break;
 	default:
-		error("internal error: %s cmdtype %d", cmdp->cmdname, cmdp->cmdtype);
+		error("internal error: %s cmdtype %d",
+		    cmdp->cmdname, cmdp->cmdtype);
 	}
 	if (cmdp->rehash)
 		out1c('*');
--- a/bin/sh/jobs.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/jobs.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: jobs.c,v 1.79.6.2 2017/05/11 02:58:28 pgoyette Exp $	*/
+/*	$NetBSD: jobs.c,v 1.79.6.3 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c	8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.79.6.2 2017/05/11 02:58:28 pgoyette Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.79.6.3 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -869,6 +869,7 @@
 		error("Cannot fork (%s)", strerror(serrno));
 		break;
 	case 0:
+		SHELL_FORKED();
 		forkchild(jp, n, mode, 0);
 		return 0;
 	default:
@@ -1423,7 +1424,7 @@
 	int subtype = 0;
 	int quoted = 0;
 	static char vstype[16][4] = { "", "}", "-", "+", "?", "=",
-					"#", "##", "%", "%%" };
+					"#", "##", "%", "%%", "}" };
 
 	p = s;
 	nextc = cmdnextc;
@@ -1435,22 +1436,28 @@
 			break;
 		case CTLVAR:
 			subtype = *p++;
-			if ((subtype & VSTYPE) == VSLENGTH)
+			if (subtype & VSLINENO) {
+				if ((subtype & VSTYPE) == VSLENGTH)
+					str = "${#LINENO";
+				else
+					str = "${LINENO";
+				while (is_digit(*p))
+					p++;
+			} else if ((subtype & VSTYPE) == VSLENGTH)
 				str = "${#";
 			else
 				str = "${";
 			if (!(subtype & VSQUOTE) != !(quoted & 1)) {
 				quoted ^= 1;
 				c = '"';
-			} else
+			} else {
 				c = *str++;
+			}
 			break;
 		case CTLENDVAR:
-			if (quoted & 1) {
-				c = '"';
-				str = "}";
-			} else
-				c = '}';
+			c = '}';
+			if (quoted & 1)
+				str = "\"";
 			quoted >>= 1;
 			subtype = 0;
 			break;
@@ -1474,6 +1481,10 @@
 			quoted ^= 1;
 			c = '"';
 			break;
+		case CTLQUOTEEND:
+			quoted >>= 1;
+			c = '"';
+			break;
 		case '=':
 			if (subtype == 0)
 				break;
@@ -1484,6 +1495,9 @@
 				c = *str++;
 			if (c != '}')
 				quoted <<= 1;
+			else if (*p == CTLENDVAR)
+				c = *str++;
+			subtype = 0;
 			break;
 		case '\'':
 		case '\\':
@@ -1497,7 +1511,7 @@
 		default:
 			break;
 		}
-		do {
+		if (c != '\0') do {	/* c == 0 implies nothing in str */
 			*nextc++ = c;
 		} while (--nleft > 0 && str && (c = *str++));
 		str = 0;
--- a/bin/sh/main.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/main.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.68 2017/04/22 16:02:39 kre Exp $	*/
+/*	$NetBSD: main.c,v 1.68.2.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c	8.7 (Berkeley) 7/19/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.68 2017/04/22 16:02:39 kre Exp $");
+__RCSID("$NetBSD: main.c,v 1.68.2.1 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -173,7 +173,7 @@
 	handler = &jmploc;
 #ifdef DEBUG
 #if DEBUG == 2
-	debug = 1;
+	debug = 1;	/* this may be reset by procargs() later */
 #endif
 	opentrace();
 	trputs("Shell args:  ");  trargs(argv);
--- a/bin/sh/miscbltin.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/miscbltin.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: miscbltin.c,v 1.43 2015/05/09 13:28:55 christos Exp $	*/
+/*	$NetBSD: miscbltin.c,v 1.43.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)miscbltin.c	8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: miscbltin.c,v 1.43 2015/05/09 13:28:55 christos Exp $");
+__RCSID("$NetBSD: miscbltin.c,v 1.43.6.1 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -321,7 +321,7 @@
 #ifdef RLIMIT_STACK
 	{ "stack",	"kbytes",	RLIMIT_STACK,	1024, 's' },
 #endif
-#ifdef  RLIMIT_CORE
+#ifdef RLIMIT_CORE
 	{ "coredump",	"blocks",	RLIMIT_CORE,	 512, 'c' },
 #endif
 #ifdef RLIMIT_RSS
--- a/bin/sh/options.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/options.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.c,v 1.46 2016/03/31 16:16:35 christos Exp $	*/
+/*	$NetBSD: options.c,v 1.46.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: options.c,v 1.46 2016/03/31 16:16:35 christos Exp $");
+__RCSID("$NetBSD: options.c,v 1.46.6.1 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,13 +88,23 @@
 procargs(int argc, char **argv)
 {
 	size_t i;
+	int psx;
 
 	argptr = argv;
 	if (argc > 0)
 		argptr++;
+
+	psx = posix;		/* save what we set it to earlier */
+	/*
+	 * option values are mostly boolean 0:off 1:on
+	 * we use 2 (just in this routine) to mean "unknown yet"
+	 */
 	for (i = 0; i < NOPTS; i++)
 		optlist[i].val = 2;
+	posix = psx;		/* restore before processing -o ... */
+
 	options(1);
+
 	if (*argptr == NULL && minusc == NULL)
 		sflag = 1;
 	if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1))
@@ -107,12 +117,24 @@
 	if (usefork == 2)
 		usefork = 1;
 #endif
-	for (i = 0; i < NOPTS; i++)
+#if DEBUG == 2
+	if (debug == 2)
+		debug = 1;
+#endif
+	/*
+	 * Any options not dealt with as special cases just above,
+	 * and which were not set on the command line, are set to
+	 * their expected default values (mostly "off")
+	 *
+	 * then as each option is initialised, save its setting now
+	 * as its "default" value for future use ("set -o default").
+	 */
+	for (i = 0; i < NOPTS; i++) {
 		if (optlist[i].val == 2)
-			optlist[i].val = 0;
-#if DEBUG == 2
-	debug = 1;
-#endif
+			optlist[i].val = optlist[i].dflt;
+		optlist[i].dflt = optlist[i].val;
+	}
+
 	arg0 = argv[0];
 	if (sflag == 0 && minusc == NULL) {
 		commandname = argv[0];
@@ -187,13 +209,30 @@
 			break;
 		}
 		while ((c = *p++) != '\0') {
-			if (c == 'c' && cmdline) {
+			if (val == 1 && c == 'c' && cmdline) {
 				/* command is after shell args*/
 				minusc = empty;
 			} else if (c == 'o') {
-				minus_o(*argptr, val);
-				if (*argptr)
-					argptr++;
+				if (*p != '\0')
+					minus_o(p, val + (cmdline ? val : 0));
+				else if (*argptr)
+					minus_o(*argptr++,
+					    val + (cmdline ? val : 0));
+				else if (!cmdline)
+					minus_o(NULL, val);
+				else
+					error("arg for %co missing", "+-"[val]);
+				break;
+#ifdef DEBUG
+			} else if (c == 'D') {
+				if (*p) {
+					set_debug(p, val);
+					break;
+				} else if (*argptr)
+					set_debug(*argptr++, val);
+				else
+					set_debug("*$", val);
+#endif
 			} else {
 				setoption(c, val);
 			}
@@ -240,12 +279,14 @@
 			out1c('\n');
 			for (i = 0; i < NOPTS; i++) {
 				if (optlist[i].name)
-				    out1fmt("%-16s%s\n", optlist[i].name,
+				    out1fmt("%-19s %s\n", optlist[i].name,
 					optlist[i].val ? "on" : "off");
 			}
 		} else {
-			out1str("set");
+			out1str("set -o default");
 			for (i = 0; i < NOPTS; i++) {
+				if (optlist[i].val == optlist[i].dflt)
+					continue;
 				if (optlist[i].name)
 				    out1fmt(" %co %s",
 					"+-"[optlist[i].val], optlist[i].name);
@@ -256,12 +297,19 @@
 			out1c('\n');
 		}
 	} else {
+		if (val == 1 && equal(name, "default")) { /* special case */
+			for (i = 0; i < NOPTS; i++)
+				set_opt_val(i, optlist[i].dflt);
+			return;
+		}
+		if (val)
+			val = 1;
 		for (i = 0; i < NOPTS; i++)
 			if (optlist[i].name && equal(name, optlist[i].name)) {
 				set_opt_val(i, val);
 				return;
 			}
-		error("Illegal option -o %s", name);
+		error("Illegal option %co %s", "+-"[val], name);
 	}
 }
 
@@ -276,7 +324,7 @@
 			set_opt_val( i, val );
 			return;
 		}
-	error("Illegal option -%c", flag);
+	error("Illegal option %c%c", "+-"[val], flag);
 	/* NOTREACHED */
 }
 
--- a/bin/sh/options.h	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/options.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.h,v 1.25 2016/03/31 16:16:35 christos Exp $	*/
+/*	$NetBSD: options.h,v 1.25.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -43,23 +43,29 @@
 	char *optptr;		/* used by getopts */
 };
 
-
+/*
+ * Note that option default values can be changed at shell startup
+ * depending upon the environment in which the shell is running.
+ */
 struct optent {
 	const char *name;		/* for set -o <name> */
 	const char letter;		/* set [+/-]<letter> and $- */
 	const char opt_set;		/* mutually exclusive option set */
 	unsigned char val;		/* value of <letter>flag */
+	unsigned char dflt;		/* default value of flag */
 };
 
 /* Those marked [U] are required by posix, but have no effect! */
 
 #ifdef DEFINE_OPTIONS
-#define DEF_OPTS(name, letter, opt_set) {name, letter, opt_set, 0},
+#define DEF_OPTS_D(name,letter,opt_set,dflt) {name, letter, opt_set, 0, dflt },
 struct optent optlist[] = {
 #else
-#define DEF_OPTS(name, letter, opt_set)
+#define DEF_OPTS_D(name,letter,opt_set,dflt)
 #endif
-#define DEF_OPT(name,letter) DEF_OPTS(name, letter, 0)
+#define DEF_OPTS(name,letter,opt_set)	DEF_OPTS_D(name, letter, opt_set, 0)
+#define DEF_OPT(name,letter)		DEF_OPTS_D(name, letter, 0, 0)
+#define DEF_OPT_D(name,letter,dflt)	DEF_OPTS_D(name, letter, 0, dflt)
 
 DEF_OPT( "errexit",	'e' )	/* exit on error */
 #define eflag optlist[0].val
@@ -113,7 +119,7 @@
 #endif
 
 #ifdef DEFINE_OPTIONS
-	{ 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0 },
 };
 #define NOPTS (sizeof optlist / sizeof optlist[0] - 1)
 int sizeof_optlist = sizeof optlist;
--- a/bin/sh/output.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/output.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: output.c,v 1.35 2016/03/12 14:59:26 christos Exp $	*/
+/*	$NetBSD: output.c,v 1.35.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)output.c	8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: output.c,v 1.35 2016/03/12 14:59:26 christos Exp $");
+__RCSID("$NetBSD: output.c,v 1.35.6.1 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -147,7 +147,7 @@
 
 
 static const char norm_chars [] = \
-    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-=_.'";
+    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+-=_,.'";
 
 static int
 inquote(const char *p)
@@ -176,7 +176,7 @@
 	 */
 	if (need_q) {
 		if ((inq = inquote(p)) != 0)
-				outc('\'', file);
+			outc('\'', file);
 	} else
 		inq = 0;
 
--- a/bin/sh/parser.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/parser.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.120.6.1 2017/05/11 02:58:28 pgoyette Exp $	*/
+/*	$NetBSD: parser.c,v 1.120.6.2 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.120.6.1 2017/05/11 02:58:28 pgoyette Exp $");
+__RCSID("$NetBSD: parser.c,v 1.120.6.2 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -1748,10 +1748,39 @@
 		if (c == OPENBRACE) {
 			c = pgetc_linecont();
 			if (c == '#') {
-				if ((c = pgetc()) == CLOSEBRACE)
+				if ((c = pgetc_linecont()) == CLOSEBRACE)
 					c = '#';
-				else
+				else if (is_name(c) || isdigit(c))
 					subtype = VSLENGTH;
+				else if (is_special(c)) {
+					/*
+					 * ${#} is $# - the number of sh params
+					 * ${##} is the length of ${#}
+					 * ${###} is ${#} with as much nothing
+					 *        as possible removed from start
+					 * ${##1} is ${#} with leading 1 gone
+					 * ${##\#} is ${#} with leading # gone
+					 *
+					 * this stuff is UGLY!
+					 */
+					if (pgetc_linecont() == CLOSEBRACE) {
+						pungetc();
+						subtype = VSLENGTH;
+					} else {
+						static char cbuf[2];
+
+						pungetc();   /* would like 2 */
+						cbuf[0] = c; /* so ... */
+						cbuf[1] = '\0';
+						pushstring(cbuf, 1, NULL);
+						c = '#';     /* ${#:...} */
+						subtype = 0; /* .. or similar */
+					}
+				} else {
+					pungetc();
+					c = '#';
+					subtype = 0;
+				}
 			}
 			else
 				subtype = 0;
@@ -1818,6 +1847,8 @@
 				}
 			}
 		} else {
+			if (subtype == VSLENGTH && c != /*{*/ '}')
+				synerror("no modifiers allowed with ${#var}");
 			pungetc();
 		}
 		if (ISDBLQUOTE() || arinest)
--- a/bin/sh/redir.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/redir.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: redir.c,v 1.53.2.1 2017/05/02 03:19:14 pgoyette Exp $	*/
+/*	$NetBSD: redir.c,v 1.53.2.2 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)redir.c	8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: redir.c,v 1.53.2.1 2017/05/02 03:19:14 pgoyette Exp $");
+__RCSID("$NetBSD: redir.c,v 1.53.2.2 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -338,7 +338,7 @@
 		abort();
 	}
 
-	cloexec = fd > 2 && (flags & REDIR_KEEP) == 0;
+	cloexec = fd > 2 && (flags & REDIR_KEEP) == 0 && !posix;
 	if (f != fd) {
 		if (copyfd(f, fd, cloexec) < 0) {
 			int e = errno;
@@ -653,42 +653,43 @@
 
 static const struct flgnames {
 	const char *name;
+	uint16_t minch;
 	uint32_t value;
 } nv[] = {
 #ifdef O_APPEND
-	{ "append",	O_APPEND 	},
+	{ "append",	2,	O_APPEND 	},
 #endif
 #ifdef O_ASYNC
-	{ "async",	O_ASYNC		},
+	{ "async",	2,	O_ASYNC		},
 #endif
 #ifdef O_SYNC
-	{ "sync",	O_SYNC		},
+	{ "sync",	2,	O_SYNC		},
 #endif
 #ifdef O_NONBLOCK
-	{ "nonblock",	O_NONBLOCK	},
+	{ "nonblock",	3,	O_NONBLOCK	},
 #endif
 #ifdef O_FSYNC
-	{ "fsync",	O_FSYNC		},
+	{ "fsync",	2,	O_FSYNC		},
 #endif
 #ifdef O_DSYNC
-	{ "dsync",	O_DSYNC		},
+	{ "dsync",	2,	O_DSYNC		},
 #endif
 #ifdef O_RSYNC
-	{ "rsync",	O_RSYNC		},
+	{ "rsync",	2,	O_RSYNC		},
 #endif
 #ifdef O_ALTIO
-	{ "altio",	O_ALT_IO	},
+	{ "altio",	2,	O_ALT_IO	},
 #endif
 #ifdef O_DIRECT
-	{ "direct",	O_DIRECT	},
+	{ "direct",	2,	O_DIRECT	},
 #endif
 #ifdef O_NOSIGPIPE
-	{ "nosigpipe",	O_NOSIGPIPE	},
+	{ "nosigpipe",	3,	O_NOSIGPIPE	},
 #endif
 #ifdef O_CLOEXEC
-	{ "cloexec",	O_CLOEXEC	},
+	{ "cloexec",	2,	O_CLOEXEC	},
 #endif
-	{ 0, 0 }
+	{ 0, 0, 0 }
 };
 #define ALLFLAGS (O_APPEND|O_ASYNC|O_SYNC|O_NONBLOCK|O_DSYNC|O_RSYNC|\
     O_ALT_IO|O_DIRECT|O_NOSIGPIPE|O_CLOEXEC)
@@ -752,6 +753,7 @@
 {
 	int *v, *w;
 	const struct flgnames *fn;
+	size_t len;
 
 	*p = 0;
 	*n = 0;
@@ -769,8 +771,9 @@
 			error("Missing +/- indicator before flag %s", s-1);
 		}
 			
+		len = strlen(s);
 		for (fn = nv; fn->name; fn++)
-			if (strcmp(s, fn->name) == 0) {
+			if (len >= fn->minch && strncmp(s,fn->name,len) == 0) {
 				*v |= fn->value;
 				*w &=~ fn->value;
 				break;
@@ -846,11 +849,6 @@
 		if (setflags)
 			goto msg;
 
-		/*
-		 * XXX  we should only ever operate on user defined fds
-		 * XXX  not on sh internal fds that might be open.
-		 * XXX  but for that we need to know their range (later)
-		 */
 		for (i = 0; i <= max_user_fd; i++)
 			printone(i, 0, verbose, 1);
 		return 0;
--- a/bin/sh/sh.1	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/sh.1	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sh.1,v 1.131.2.2 2017/05/11 02:58:28 pgoyette Exp $
+.\"	$NetBSD: sh.1,v 1.131.2.3 2017/05/19 00:22:51 pgoyette Exp $
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -31,7 +31,7 @@
 .\"
 .\"	@(#)sh.1	8.6 (Berkeley) 5/4/95
 .\"
-.Dd May 7, 2017
+.Dd May 12, 2017
 .Dt SH 1
 .ds flags abCEeFfhnuvxIimpqV
 .Os
@@ -90,12 +90,6 @@
 features which make it appear similar in some respects to the Korn shell,
 but it is not a Korn shell clone (see
 .Xr ksh 1 ) .
-Only features designated by
-.Tn POSIX ,
-plus a few Berkeley extensions, are being incorporated into this shell.
-.\" We expect
-.\" .Tn POSIX
-.\" conformance by the time 4.4 BSD is released.
 This man page is not intended
 to be a tutorial or a complete specification of the shell.
 .Ss Overview
@@ -116,8 +110,9 @@
 can be typed directly to the running shell or can be put into a file and
 the file can be executed directly by the shell.
 .Ss Invocation
-If no arguments are present and if the standard input of the shell
-is connected to a terminal (or if the
+If no arguments are present and if the standard input,
+and output, of the shell
+are connected to a terminal (or if the
 .Fl i
 flag is set),
 and the
@@ -140,9 +135,14 @@
 if they exist.
 If the environment variable
 .Ev ENV
-is set on entry to a shell, or is set in the
+is set on entry to a shell,
+or is set in the
 .Pa .profile
-of a login shell, the shell next reads
+of a login shell,
+and either the shell is interactive, or the
+.Cm posix
+option is not set,
+the shell next reads
 commands from the file named in
 .Ev ENV .
 Therefore, a user should place commands that are to be executed only at
@@ -164,15 +164,15 @@
 any filename you wish.
 Since the
 .Ev ENV
-file is read for every invocation of the shell, including shell scripts
+file can be read for every invocation of the shell, including shell scripts
 and non-interactive shells, the following paradigm is useful for
 restricting commands in the
 .Ev ENV
 file to interactive invocations.
 Place commands within the
-.Dq case
+.Dq Ic case
 and
-.Dq esac
+.Dq Ic esac
 below (these commands are described later):
 .Pp
 .Bl -item -compact -offset indent
@@ -195,26 +195,33 @@
 Otherwise, the shell
 reads commands from its standard input.
 .Ss Argument List Processing
-All of the single letter options have a corresponding name that can be
-used as an argument to the
+Currently, all of the single letter options that can meaningfully
+be set using the
+.Ic set
+built-in, have a corresponding name
+that can be used as an argument to the
 .Fl o
 option.
 The set
 .Fl o
 name is provided next to the single letter option in
 the description below.
+Other options described are for the command line only.
 Specifying a dash
 .Dq -
 turns the option on, while using a plus
 .Dq +
 disables the option.
-The following options can be set from the command line or
-with the
+The following options can be set from the command line and,
+unless otherwise stated, with the
 .Ic set
 built-in (described later).
-.Bl -tag -width aaaallexportfoo -offset indent
+.Bl -tag -width \-WXXlineno_fn_relativeXX -offset indent
 .It Fl a Em allexport
 Export all variables assigned to.
+.It Fl b Em notify
+Enable asynchronous notification of background job completion.
+(Not implemented.)
 .It Fl c
 Read commands from the
 .Ar command_string
@@ -253,55 +260,6 @@
 is tested when
 .Fl e
 is set to determine if the shell should exit.
-.It Fl f Em noglob
-Disable pathname expansion.
-.It Fl n Em noexec
-If not interactive, read commands but do not execute them.
-This is useful for checking the syntax of shell scripts.
-.It Fl u Em nounset
-Write a message to standard error when attempting to expand a variable
-that is not set, and if the shell is not interactive, exit immediately.
-.It Fl v Em verbose
-The shell writes its input to standard error as it is read.
-Useful for debugging.
-.It Fl x Em xtrace
-Write each command to standard error (preceded by a
-.Sq +\  )
-before it is executed.
-Useful for debugging.
-.It Fl q Em quietprofile
-If the
-.Fl v
-or
-.Fl x
-options have been set, do not apply them when reading
-initialization files, these being
-.Pa /etc/profile ,
-.Pa .profile ,
-and the file specified by the
-.Ev ENV
-environment variable.
-.It Fl I Em ignoreeof
-Ignore EOFs from input when interactive.
-.It Fl i Em interactive
-Force the shell to behave interactively.
-.It Fl m Em monitor
-Turn on job control (set automatically when interactive).
-.It Fl s Em stdin
-Read commands from standard input (set automatically if no file arguments
-are present).
-This option has no effect when set or reset after the shell has
-already started running (i.e. with
-.Ic set ) .
-.It Fl V Em vi
-Enable the built-in
-.Xr vi 1
-command line editor (disables
-.Fl E
-if it has been set).
-(See the
-.Sx Command Line Editing
-section below.)
 .It Fl E Em emacs
 Enable the built-in emacs style
 command line editor (disables
@@ -310,9 +268,8 @@
 (See the
 .Sx Command Line Editing
 section below.)
-.It Fl b Em notify
-Enable asynchronous notification of background job completion.
-(Not implemented.)
+.It Fl f Em noglob
+Disable pathname expansion.
 .It Fl F Em fork
 Cause the shell to always use
 .Xr fork 2
@@ -333,6 +290,28 @@
 When off,
 the file system is searched for commands each time the function is invoked.
 (Not implemented.)
+.It Fl i Em interactive
+Force the shell to behave interactively.
+.It Fl I Em ignoreeof
+Ignore EOFs from input when interactive.
+.\" .It Fl L Em lineno_fn_relative
+.\" When set, before a function is defined,
+.\" causes the variable
+.\" .Ev LINENO
+.\" when used within the function,
+.\" to refer to the line number defined such that
+.\" first line of the function is line 1.
+.\" When reset,
+.\" .Ev LINENO
+.\" in a function refers to the line number within the file
+.\" in which the definition of the function occurs
+.\" (which can be the number of lines of shell input from standard input
+.\" when a function is defined interactively from the command prompt.)
+.It Fl m Em monitor
+Turn on job control (set automatically when interactive).
+.It Fl n Em noexec
+If not interactive, read commands but do not execute them.
+This is useful for checking the syntax of shell scripts.
 .It Fl p Em nopriv
 Do not attempt to reset effective UID if it does not match UID.
 This is not set by default to help avoid incorrect usage by setuid
@@ -340,6 +319,44 @@
 .Xr system 3
 or
 .Xr popen 3 .
+.It Fl q Em quietprofile
+If the
+.Fl v
+or
+.Fl x
+options have been set, do not apply them when reading
+initialization files, these being
+.Pa /etc/profile ,
+.Pa .profile ,
+and the file specified by the
+.Ev ENV
+environment variable.
+.It Fl s Em stdin
+Read commands from standard input (set automatically if no file arguments
+are present).
+This option has no effect when set or reset after the shell has
+already started running (i.e. with
+.Ic set ) .
+.It Fl u Em nounset
+Write a message to standard error when attempting to expand a variable
+that is not set, and if the shell is not interactive, exit immediately.
+.It Fl v Em verbose
+The shell writes its input to standard error as it is read.
+Useful for debugging.
+.It Fl x Em xtrace
+Write each command to standard error (preceded by a
+.Sq +\  )
+before it is executed.
+Useful for debugging.
+.It Fl V Em vi
+Enable the built-in
+.Xr vi 1
+command line editor (disables
+.Fl E
+if it has been set).
+(See the
+.Sx Command Line Editing
+section below.)
 .It "\ \ " Em cdprint
 Make an interactive shell always print the new directory name when
 changed by the
@@ -365,9 +382,16 @@
 the file given by the
 .Ev ENV
 variable is read at startup by a non-interactive shell.
-Consequently, while it can be manipulated by the
-.Ic set
-command, doing so has no current purpose.
+It also controls whether file descriptors greater than 2
+opened using the
+.Ic exec
+built-in command are passed on to utilities executed,
+and whether the shell treats
+an empty compound statement as a syntax error (required
+by posix) or permits it.
+Empty compound statements
+.Dq "{ }"
+can be useful when defining dummy functions.
 .It "\ \ " Em tabcomplete
 Enables filename completion in the command line editor.
 Typing a tab character will extend the current input word to match a
@@ -387,10 +411,10 @@
 .Dq operators .
 There are two types of operators: control operators and redirection
 operators (their meaning is discussed later).
-Following is a list of operators:
+The following is a list of operators:
 .Bl -ohang -offset indent
 .It "Control operators:"
-.Dl \*[Am]  \*[Am]\*[Am]  \&(  \&)  \&;  ;; | || \*[Lt]newline\*[Gt]
+.Dl \*[Am]  \*[Am]\*[Am]  \&(  \&)  \&;  ;; ;\*[Am] | || \*[Lt]newline\*[Gt]
 .It "Redirection operators:"
 .Dl \*[Lt]  \*[Gt]  \*[Gt]|  \*[Lt]\*[Lt]  \*[Gt]\*[Gt]  \*[Lt]\*[Am]  \*[Gt]\*[Am]  \*[Lt]\*[Lt]-  \*[Lt]\*[Gt]
 .El
@@ -400,12 +424,12 @@
 There are three types of quoting: matched single quotes,
 matched double quotes, and backslash.
 .Ss Backslash
-A backslash preserves the literal meaning of the following
+An unquoted backslash preserves the literal meaning of the following
 character, with the exception of
 .Aq newline .
-A backslash preceding a
+An unquoted backslash preceding a
 .Aq newline
-is treated as a line continuation.
+is treated as a line continuation, the two characters are simply removed.
 .Ss Single Quotes
 Enclosing characters in single quotes preserves the literal meaning of all
 the characters (except single quotes, making it impossible to put
@@ -419,26 +443,28 @@
 and backslash
 .Pq \e .
 The backslash inside double quotes is historically weird, and serves to
-quote only the following characters:
-.Dl $  `  \*q  \e  \*[Lt]newline\*[Gt] .
+quote only the following characters (and these not in all contexts):
+.Dl $  `  \*q  \e  \*[Lt]newline\*[Gt] ,
+where a backslash newline is a line continuation as above.
 Otherwise it remains literal.
 .Ss Reserved Words
 Reserved words are words that have special meaning to the
 shell and are recognized at the beginning of a line and
 after a control operator.
 The following are reserved words:
-.Bl -column while while while while while -offset indent
-.It ! Ta elif Ta fi Ta while Ta case
-.It else Ta for Ta then Ta { Ta }
-.It do Ta done Ta until Ta if Ta esac
+.Bl -column while while while while -offset indent
+.It Ic \&! Ta Ic \&{ Ta Ic \&} Ta Ic case
+.It Ic do Ta Ic done Ta Ic elif Ta Ic else
+.It Ic esac Ta Ic fi Ta Ic for Ta Ic if
+.It Ic in Ta Ic then Ta Ic until Ta Ic while
 .El
 .Pp
-Their meaning is discussed later.
+Their meanings are discussed later.
 .Ss Aliases
 An alias is a name and corresponding value set using the
 .Ic alias
 built-in command.
-Whenever a reserved word may occur (see above),
+Whenever a reserved word (see above) may occur,
 and after checking for reserved words, the shell
 checks the word to see if it matches an alias.
 If it does, it replaces it in the input stream with its value.
@@ -457,7 +483,7 @@
 Aliases provide a convenient way for naive users to create shorthands for
 commands without having to learn how to create functions with arguments.
 They can also be used to create lexically obscure code.
-This use is discouraged.
+This use is strongly discouraged.
 .Ss Commands
 The shell interprets the words it reads according to a language, the
 specification of which is outside the scope of this man page (refer to the
@@ -476,21 +502,23 @@
 .It
 Leading words of the form
 .Dq name=value
-are stripped off and assigned to the environment of the simple command.
+are stripped off, the value is expanded, as described below,
+and the results are assigned to the environment of the simple command.
 Redirection operators and their arguments (as described below) are
-stripped off and saved for processing.
+stripped off and saved for processing in step 3 below.
 .It
 The remaining words are expanded as described in the
 .Sx Word Expansions
-section below,
-and the first remaining word is considered the command name and the
+section below.
+The first remaining word is considered the command name and the
 command is located.
-The remaining words are considered the arguments of the command.
+Any remaining words are considered the arguments of the command.
 If no command name resulted, then the
 .Dq name=value
 variable assignments recognized in item 1 affect the current shell.
 .It
-Redirections are performed as described in the next section.
+Redirections are performed, from first to last, in the order given,
+as described in the next section.
 .El
 .Ss Redirections
 Redirections are used to change where a command reads its input or sends
@@ -504,7 +532,7 @@
 where
 .Va redir-op
 is one of the redirection operators mentioned previously.
-Following is a list of the possible redirections.
+The following is a list of the possible redirections.
 The
 .Bq n
 is an optional number, as in
@@ -512,27 +540,47 @@
 (not
 .Sq Bq 3 ) ,
 that refers to a file descriptor.
+If present it must occur immediately before the redirection
+operator, with no intervening white space, and becomes a
+part of that operator.
 .Bl -tag -width aaabsfiles -offset indent
-.It [n] Ns \*[Gt] file
-Redirect standard output (or n) to file.
-.It [n] Ns \*[Gt]| file
-Same, but override the
+.It Oo Ar n Oc Ns \*[Gt] Ar file
+Redirect standard output (or n) to
+.Ar file .
+.It Oo Ar n Oc Ns \*[Gt]| file
+The same, but override the
 .Fl C
 option.
-.It [n] Ns \*[Gt]\*[Gt] file
-Append standard output (or n) to file.
-.It [n] Ns \*[Lt] file
-Redirect standard input (or n) from file.
-.It [n1] Ns \*[Lt]\*[Am] Ns n2
-Duplicate standard input (or n1) from file descriptor n2.
-.It [n] Ns \*[Lt]\*[Am]-
-Close standard input (or n).
-.It [n1] Ns \*[Gt]\*[Am] Ns n2
-Duplicate standard output (or n1) to n2.
-.It [n] Ns \*[Gt]\*[Am]-
+.It Oo Ar n Oc Ns \*[Gt]\*[Gt] Ar file
+Append standard output (or n) to
+.Ar file .
+.It Oo Ar n Oc Ns \*[Lt] Ar file
+Redirect standard input (or
+.Ar n )
+from
+.Ar file .
+.It Oo Ar n1 Oc Ns \*[Lt]\*[Am] Ns Ar n2
+Duplicate standard input (or
+.Ar n1 )
+from file descriptor
+.Ar n2 .
+.Ar n2
+is expanded if not a digit string, the result must be a number.
+.It Oo Ar n Oc Ns \*[Lt]\*[Am]-
+Close standard input (or
+.Ar n ) .
+.It Oo Ar n1 Oc Ns \*[Gt]\*[Am] Ns Ar n2
+Duplicate standard output (or
+.Ar n1 )
+to
+.Ar n2 .
+.It Oo Ar n Oc Ns \*[Gt]\*[Am]-
 Close standard output (or n).
-.It [n] Ns \*[Lt]\*[Gt] file
-Open file for reading and writing on standard input (or n).
+.It Oo Ar n Oc Ns \*[Lt]\*[Gt] Ar file
+Open
+.Ar file
+for reading and writing on standard input (or
+.Ar n ) .
 .El
 .Pp
 The following redirection is often called a
@@ -544,6 +592,16 @@
 .Li delimiter
 .El
 .Pp
+The
+.Dq here-doc-text
+starts immediately after the next unquoted newline character following
+the here-doc redirection operator.
+If there is more than one here-document redirection on the same
+line, then the text for the first (from left to right) is read
+first, and subsequent here-doc-text for later here-doc redirections
+follows immediately after, until all such redirections have been
+processed.
+.Pp
 All the text on successive lines up to the delimiter,
 which must appear on a line by itself, with nothing other
 than an immediately following newline, is
@@ -551,7 +609,11 @@
 descriptor n if it is specified.
 If the delimiter as specified on the initial line is
 quoted, then the here-doc-text is treated literally; otherwise, the text is
-subjected to parameter expansion, command substitution, and arithmetic
+treated much like a double quoted string, except that
+.Sq \&"
+characters have no special meaning, and are not escaped by
+.Sq \&\e ,
+and is subjected to parameter expansion, command substitution, and arithmetic
 expansion as described in the
 .Sx Word Expansions
 section below.
@@ -565,9 +627,15 @@
 an unquoted \e are joined to the following line, the \e and following
 newline are simply removed while reading the here-doc, which thus guarantees
 that neither of those lines can be the end delimiter.
+.Pp
+It is a syntax error for the end of the input file (or string) to be
+reached before the delimiter is encountered.
 .Ss Search and Execution
 There are three types of commands: shell functions, built-in commands, and
 normal programs -- and the command is searched for (by name) in that order.
+A command that contains a slash
+.Sq \&/
+in its name is always a normal program.
 They each are executed in a different way.
 .Pp
 When a shell function is executed, all of the shell positional parameters
@@ -575,11 +643,13 @@
 function.
 The variables which are explicitly placed in the environment of
 the command (by placing assignments to them before the function name) are
-made local to the function and are set to the values given.
+made local to the function and are set to the values given,
+and exported for the benefit of programs executed with the function.
 Then the command given in the function definition is executed.
-The positional parameters are restored to their original values
-when the command completes.
-This all occurs within the current shell.
+The positional parameters, and local variables, are restored to
+their original values when the command completes.
+This all occurs within the current shell, and the function
+can alter variables, or other settings, of the shell.
 .Pp
 Shell built-ins are executed internally to the shell, without spawning a
 new process.
@@ -589,14 +659,14 @@
 described in the next section).
 When a normal program is executed, the shell runs the program,
 passing the arguments and the environment to the program.
-If the program is not a normal executable file (i.e., if it does
+If the program is not a normal executable file, and if it does
 not begin with the "magic number" whose
 .Tn ASCII
 representation is "#!", so
 .Xr execve 2
 returns
 .Er ENOEXEC
-then) the shell will interpret the program in a subshell.
+then) the shell will interpret the program in a sub-shell.
 The child shell will reinitialize itself in this case,
 so that the effect will be as if a
 new shell had been invoked to handle the ad-hoc shell script, except that
@@ -616,7 +686,7 @@
 Command names containing a slash are simply executed without performing
 any searches.
 .It
-The shell searches each entry in
+Otherwise, the shell searches each entry in
 .Ev PATH
 in turn for the command.
 The value of the
@@ -625,12 +695,16 @@
 Each entry consists of a directory name.
 The current directory may be indicated
 implicitly by an empty directory name, or explicitly by a single period.
+If a directory searched contains an executable file with the same
+name as the command given,
+the search terminates, and that program is executed.
 .El
 .Ss Command Exit Status
 Each command has an exit status that can influence the behavior
 of other shell commands.
 The paradigm is that a command exits
-with zero for normal or success, and non-zero for failure,
+with zero in normal cases, or to indicate success,
+and non-zero for failure,
 error, or a false indication.
 The man page for each command
 should indicate the various exit codes and what they mean.
@@ -640,6 +714,10 @@
 If a command consists entirely of variable assignments then the
 exit status of the command is that of the last command substitution
 if any, otherwise 0.
+.Pp
+If redirections are present, and any fail to be correctly performed,
+any command present is not executed, and an exit status of 2
+is returned.
 .Ss Complex Commands
 Complex commands are combinations of simple commands with control
 operators or reserved words, together creating a larger complex command.
@@ -661,7 +739,11 @@
 simple command executed by the command.
 .Ss Pipelines
 A pipeline is a sequence of one or more commands separated
-by the control operator |.
+by the control operator
+.Sq \&| ,
+and optionally preceded by the
+.Dq \&!
+reserved word.
 The standard output of all but
 the last command is connected to the standard input
 of the next command.
@@ -676,7 +758,7 @@
 command2.
 The standard input, standard output, or both of a command is
 considered to be assigned by the pipeline before any redirection specified
-by redirection operators that are part of the command.
+by redirection operators that are part of the command are performed.
 .Pp
 If the pipeline is not in the background (discussed later), the shell
 waits for all commands to complete.
@@ -703,6 +785,12 @@
 terminator causes the preceding AND-OR-list (described
 next) to be executed sequentially; a \*[Am] causes asynchronous execution of
 the preceding AND-OR-list.
+The exit status of an asynchronous AND-OR-list is zero.
+The actual status of the commands,
+after they have completed,
+can be obtained using the
+.Ic wait
+built-in command described later.
 .Pp
 Note that unlike some other shells, each process in the pipeline is a
 child of the invoking shell (unless it is a shell built-in, in which case
@@ -726,13 +814,18 @@
 (see
 .Sx Special Parameters ) .
 .Ss Lists -- Generally Speaking
-A list is a sequence of zero or more commands separated by newlines,
+A list is a sequence of one or more commands separated by newlines,
 semicolons, or ampersands, and optionally terminated by one of these three
 characters.
 The commands in a list are executed in the order they are written.
 If command is followed by an ampersand, the shell starts the
 command and immediately proceeds to the next command; otherwise it waits
 for the command to terminate before proceeding to the next one.
+A newline is equivalent to a
+.Sq \&;
+when no other operator is present, and the command being input
+could syntactically correctly be terminated at the point where
+the newline is encountered, otherwise it is just whitespace.
 .Ss Short-Circuit List Operators
 .Dq \*[Am]\*[Am]
 and
@@ -755,7 +848,9 @@
 and nothing else.
 This is not the way it works in C.
 .Ss Flow-Control Constructs -- if, while, for, case
-The syntax of the if command is
+The syntax of the
+.Ic if
+command is
 .Bd -literal -offset indent
 if list
 then list
@@ -764,8 +859,23 @@
 [ else list ]
 fi
 .Ed
+The first list is executed, and if the exit status of that list is zero,
+the list following the
+.Ic then
+is executed.
+Otherwise the list after an
+.Ic elif
+(if any) is executed and the process repeats.
+When no more
+.Ic elif
+reserved words, and accompanying lists, appear,
+the list after the
+.Ic else
+reserved word, if any, is executed.
 .Pp
-The syntax of the while command is
+The syntax of the
+.Ic while
+command is
 .Bd -literal -offset indent
 while list
 do   list
@@ -774,11 +884,17 @@
 .Pp
 The two lists are executed repeatedly while the exit status of the
 first list is zero.
-The until command is similar, but has the word
-until in place of while, which causes it to
-repeat until the exit status of the first list is zero.
+The
+.Ic until
+command is similar, but has the word
+.Ic until
+in place of
+.Ic while ,
+which causes it to repeat until the exit status of the first list is zero.
 .Pp
-The syntax of the for command is
+The syntax of the
+.Ic for
+command is
 .Bd -literal -offset indent
 for variable [ in word ... ]
 do   list
@@ -788,23 +904,50 @@
 The words are expanded, or "$@" if no words are given,
 and then the list is executed repeatedly with the
 variable set to each word in turn.
-do and done may be replaced with
-.Dq {
+.Ic do
 and
-.Dq } ,
+.Ic done
+may be replaced with
+.Sq Ic \&{
+and
+.Sq Ic \&} ,
 but doing so is non-standard and not recommended.
 .Pp
-The syntax of the break and continue command is
+The syntax of the
+.Ic break
+and
+.Ic continue
+commands is
 .Bd -literal -offset indent
 break [ num ]
 continue [ num ]
 .Ed
 .Pp
-Break terminates the num innermost for or while loops.
-Continue continues with the next iteration of the innermost loop.
+.Ic break
+terminates the
+.Ar num
+innermost
+.Ic for , while ,
+or
+.Ic until
+loops.
+.Ic continue
+breaks execution of the
+.Ar num\-1
+innermost
+.Ic for , while ,
+or
+.Ic until
+loops, and then continues with the next iteration of the enclosing loop.
 These are implemented as built-in commands.
+The parameter
+.Ar num ,
+if given, must be an unsigned positive integer (greater than zero).
+If not given, 1 is used.
 .Pp
-The syntax of the case command is
+The syntax of the
+.Ic case
+command is
 .Bd -literal -offset indent
 case word in
 [(] pattern ) list ;&
@@ -833,8 +976,10 @@
 When a list terminated with
 .Dq \&;;
 has been executed, or when
-.Dv esac
-is reached execution of the case statement is complete.
+.Ic esac
+is reached execution of the
+.Ic case
+statement is complete.
 The exit status is that of the last command executed
 from the last list evaluated, if any, or zero otherwise.
 .Ss Grouping Commands Together
@@ -846,9 +991,16 @@
 .Pp
 .Dl { list; }
 .Pp
-The first of these executes the commands in a subshell.
+Note that while parentheses are operators, and do not require
+any extra syntax, braces are reserved words, so the opening brace
+must be followed by white space (or some other operator), and the
+closing brace must occur in a position where a new command word might
+otherwise appear.
+.Pp
+The first of these executes the commands in a sub-shell.
 Built-in commands grouped into a (list) will not affect the current shell.
-The second form does not fork another shell so is slightly more efficient.
+The second form does not fork another shell so is slightly more efficient,
+and allows for commands which do affect the current shell.
 Grouping commands together this way allows you to redirect
 their output as though they were one program:
 .Bd -literal -offset indent
@@ -872,7 +1024,7 @@
 and
 .Dq } .
 The standard syntax also allows the command to be any of the other
-compound commands, or a sub-shell, all of which are supported.
+compound commands, including a sub-shell, all of which are supported.
 As an extension, this shell also allows a simple command to be
 used, though users should be aware this is non-standard syntax.
 This means that
@@ -909,9 +1061,11 @@
 that input only to the cat command, not to any other commands
 that might appear in the function.
 .Pp
-Variables may be declared to be local to a function by using a local
+Variables may be declared to be local to a function by using a
+.Ic local
 command.
-This should appear as the first statement of a function, and the syntax is
+This should usually appear as the first statement of a function,
+its syntax is
 .Pp
 .Dl local [ variable | - ] ...
 .Pp
@@ -952,7 +1106,7 @@
 Note that $0 however retains the value it had outside the function,
 as do all the other special parameters.
 .Pp
-The only special parameter that can be made local is
+The only other special parameter that can be made local is
 .Dq - .
 Making
 .Dq -
@@ -984,7 +1138,7 @@
 The shell maintains a set of parameters.
 A parameter denoted by a name is called a variable.
 When starting up, the shell turns all the environment
-variables into shell variables.
+variables into shell variables, and exports them.
 New variables can be set using the form
 .Pp
 .Dl name=value
@@ -1056,14 +1210,14 @@
 Expands to the number of positional parameters.
 .It \&?
 Expands to the exit status of the most recent pipeline.
-.It - (Hyphen.)
+.It \- (Hyphen, or minus.)
 Expands to the current option flags (the single-letter
 option names concatenated into a string) as specified on
 invocation, by the set built-in command, or implicitly
 by the shell.
 .It $
 Expands to the process ID of the invoked shell.
-A subshell retains the same value of $ as its parent.
+A sub-shell retains the same value of $ as its parent.
 .It \&!
 Expands to the process ID of the most recent background
 command executed from the current shell.
@@ -1113,10 +1267,10 @@
 .Ss Tilde Expansion (substituting a user's home directory)
 A word beginning with an unquoted tilde character (~) is
 subjected to tilde expansion.
-All the characters up to
-a slash (/) or the end of the word are treated as a username
-and are replaced with the user's home directory.
-If the username is missing (as in
+All the following characters in the word up to
+a slash (/) or the end of the word are treated as a user name
+and are replaced with the named user's home directory.
+If the user name is missing (as in
 .Pa ~/foobar ) ,
 the tilde is replaced with the value of the
 .Va HOME
@@ -1141,8 +1295,9 @@
 .Pp
 The value, if any, of parameter is substituted.
 .Pp
-The parameter name or symbol can be enclosed in braces, which are
-optional except for positional parameters with more than one digit or
+The parameter name or symbol can be enclosed in braces,
+which are optional in this simple case,
+except for positional parameters with more than one digit or
 when parameter is followed by a character that could be interpreted as
 part of the name.
 If a parameter expansion occurs inside double quotes:
@@ -1154,12 +1309,12 @@
 expansion, with the exception of the special rules for @.
 .El
 .Pp
-In addition, a parameter expansion can be modified by using one of the
-following formats.
+In addition, a parameter expansion where braces are used,
+can be modified by using one of the following formats.
 If the
 .Dq Dv \&:
-is omitted in the following modifiers, then the expansion is applied only
-to unset parameters, not null ones.
+is omitted in the following modifiers, then the test in the expansion
+applies only to unset parameters, not null ones.
 .Bl -tag -width aaparameterwordaaaaa
 .It ${parameter:\(miword}
 Use Default Values.
@@ -1176,13 +1331,16 @@
 Indicate Error if Null or Unset.
 If parameter is unset or null, the
 expansion of word (or a message indicating it is unset if word is omitted)
-is written to standard error and the shell exits with a nonzero exit status.
-Otherwise, the value of parameter is substituted.
-An interactive shell need not exit.
+is written to standard error and a non-interactive shell exits with
+a nonzero exit status.
+An interactive shell will not exit, but any associated command(s) will
+not be executed.
+If the parameter is set, its value is substituted.
 .It ${parameter:+word}
 Use Alternative Value.
 If parameter is unset or null, null is
 substituted; otherwise, the expansion of word is substituted.
+The value of parameter is not used in this expansion.
 .It ${#parameter}
 String Length.
 The length in characters of the value of parameter.
@@ -1203,25 +1361,43 @@
 The word is expanded to produce a pattern.
 The parameter expansion then results in parameter, with the
 smallest portion of the suffix matched by the pattern deleted.
+If the word is to start with a
+.Sq \&%
+character, it must be quoted.
 .It ${parameter%%word}
 Remove Largest Suffix Pattern.
 The word is expanded to produce a pattern.
 The parameter expansion then results in parameter, with the largest
 portion of the suffix matched by the pattern deleted.
+The
+.Dq %%
+pattern operator only produces different results from the
+.Dq \&%
+operator when the pattern contains at least one unquoted
+.Sq \&* .
 .It ${parameter#word}
 Remove Smallest Prefix Pattern.
 The word is expanded to produce a pattern.
 The parameter expansion then results in parameter, with the
 smallest portion of the prefix matched by the pattern deleted.
+If the word is to start with a
+.Sq \&#
+character, it must be quoted.
 .It ${parameter##word}
 Remove Largest Prefix Pattern.
 The word is expanded to produce a pattern.
 The parameter expansion then results in parameter, with the largest
 portion of the prefix matched by the pattern deleted.
+This has the same relationship with the
+.Sq \&#
+pattern operator as
+.Dq %%
+has with
+.Dq \&% .
 .El
 .Ss Command Substitution
 Command substitution allows the output of a command to be substituted in
-place of the command name itself.
+place of the command (and surrounding syntax).
 Command substitution occurs when the command is enclosed as follows:
 .Pp
 .Dl $(command)
@@ -1235,7 +1411,7 @@
 .Dl `command`
 .Pp
 The shell expands the command substitution by executing command in a
-subshell environment and replacing the command substitution with the
+sub-shell environment and replacing the command substitution with the
 standard output of the command, removing sequences of one or more
 .Ao newline Ac Ns s
 at the end of the substitution.
@@ -1247,7 +1423,7 @@
 .Ao space Ac Ns s ,
 depending on the value of
 .Ev IFS
-and quoting that is in effect.)
+and any quoting that is in effect.)
 .Ss Arithmetic Expansion
 Arithmetic expansion provides a mechanism for evaluating an arithmetic
 expression and substituting its value.
@@ -1346,7 +1522,7 @@
 whitespace)
 can occur, leading and trailing
 .Ev IFS
-whitespace, and
+whitespace, and any
 .Ev IFS
 whitespace surrounding a non whitespace
 .Ev IFS
@@ -1355,7 +1531,7 @@
 .Ev IFS
 whitespace characters without a non-whitespace
 .Ev IFS
-delimiter acts as a field separator.
+delimiter acts as a single field separator.
 .Pp
 If
 .Ev IFS
@@ -1442,7 +1618,17 @@
 if any).
 To include a
 .Dq \(mi ,
-make it the first or last character listed.
+make it the first (after !) or last character listed.
+If both
+.Dq \&]
+and
+.Dq \(mi
+are to be included, the
+.Dq \&]
+must be first (after !)
+and the
+.Dq \(mi
+last, in the character class.
 .Ss Built-ins
 This section lists the built-in commands which are built-in because they
 need to perform some operation that can't be performed by a separate
@@ -1587,7 +1773,10 @@
 command are marked as permanent, so that they are not undone when the
 .Ic exec
 command finishes.
-File descriptors created via such redirections are marked close-on-exec
+When the
+.Ic posix
+option is not set,
+file descriptors created via such redirections are marked close-on-exec
 (see
 .Xr open 2
 .Dv O_CLOEXEC
@@ -1601,7 +1790,12 @@
 (except
 .Xr ksh 1 ) ,
 made those file descriptors available to exec'ed processes.
-To turn off the close-on-exec mark,
+This behavior is required by the
+.Tn POSIX
+standard, so when the
+.Ic posix
+option is set, this shell also acts that way.
+To be assured the close-on-exec setting is off,
 redirect the descriptor to (or from) itself,
 either when invoking a command for which the descriptor is wanted open,
 or by using
@@ -1611,15 +1805,20 @@
 as opened it, after the open)
 to leave the descriptor open in the shell
 and pass it to all commands invoked subsequently.
+Alternatively, see the
+.Ic fdflags
+command below, which can set, or clear, this, and other,
+file descriptor flags.
 .It exit Op Ar exitstatus
 Terminate the shell process.
 If
 .Ar exitstatus
 is given it is used as the exit status of the shell; otherwise the
-exit status of the preceding command is used.
+exit status of the preceding command (the current value of $?) is used.
 .It export Oo Fl npx Oc Ar name ...
 .It export Fl p Oo Fl x Oc
 With no options,
+but one or mode names,
 the specified names are exported so that they will appear in the
 environment of subsequent commands.
 With
@@ -1748,6 +1947,8 @@
 .El
 .It fg Op Ar job
 Move the specified job or the current job to the foreground.
+A foreground job can interact with the user via standard input,
+and receive signals from the terminal.
 .It fdflags Oo Fl v Oc Oo fd ... Oc
 .It fdflags Oo Fl v Oc Fl s Ar flags fd Oo ... Oc
 Get or set file descriptor flags.
@@ -1761,14 +1962,28 @@
 .Ar flags
 argument as a comma separated list of file descriptor flags, each preceded
 with a
-.Dq +
+.Dq \(pl
 or a
-.Dq -
+.Dq \(mi
 indicating to set or clear the respective flag.
 Valid flags are:
-append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec.
+.Cm append ,
+.Cm async ,
+.Cm sync ,
+.Cm nonblock ,
+.Cm fsync ,
+.Cm dsync ,
+.Cm rsync ,
+.Cm direct ,
+.Cm nosigpipe ,
+and
+.Cm cloexec .
+Unique abbreviations of these names, of at least 2 characters,
+may be used on input.
 See
 .Xr fcntl 2
+and
+.Xr open 2
 for more information.
 .It getopts Ar optstring var
 The
@@ -1862,7 +2077,7 @@
 	\e?)	echo $USAGE; exit 1;;
 	esac
 done
-shift $(expr $OPTIND - 1)
+shift $((OPTIND - 1))
 .Ed
 .Pp
 This code will accept any of the following as equivalent:
@@ -1927,12 +2142,12 @@
 .Fl L ,
 but note that the built-in
 .Ic cd
-command doesn't currently support the
+command doesn't support the
 .Fl L
 option and will cache (almost) the absolute path.
 If
 .Ic cd
-is changed,
+is changed (as unlikely as that is),
 .Ic pwd
 may be changed to default to
 .Ic pwd
@@ -1954,7 +2169,7 @@
 option is specified and the standard input is a terminal.
 Then a line is read from the standard input.
 The trailing newline is deleted from the
-line and the line is split as described in the
+line and the line is split as described in the field splitting section of the
 .Sx Word Expansions
 section above, and the pieces are assigned to the variables in order.
 If there are more pieces than variables, the remaining pieces
@@ -1977,7 +2192,7 @@
 If a backslash is followed by a newline, the backslash and the
 newline will be deleted.
 .It readonly Ar name ...
-.It readonly Fl p
+.It readonly Oo Fl p Oc
 The specified names are marked as read only, so that they cannot be
 subsequently modified or unset.
 The shell allows the value of a variable
@@ -2008,24 +2223,62 @@
 .It set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ...
 The
 .Ic set
-command performs three different functions.
+command performs four different functions.
 .Pp
 With no arguments, it lists the values of all shell variables.
 .Pp
+With a single option of either
+.Sq Fl o
+or
+.Sq Cm +o
+.Ic set
+outputs the current values of the options.
+In the
+.Fl o
+form, all options are listed, with their current values.
+In the
+.Cm +o
+form, the shell outputs a string that can later be used
+as a command to reset all options to their current values.
+.Pp
 If options are given, it sets the specified option
 flags, or clears them as described in the
 .Sx Argument List Processing
 section.
+In addition to the options listed there,
+when the
+.Dq "option name"
+given to
+.Ic set Fl o
+is
+.Cm default
+all of the options are reset to the values they had immediately
+after
+.Nm
+initialization, before any startup scripts, or other input, had been processed.
+While this may be of use to users or scripts, its primary purpose
+is for use in the output of
+.Dq Ic set Cm +o ,
+to avoid that command needing to list every available option.
+There is no
+.Cm +o default .
 .Pp
-The third use of the set command is to set the values of the shell's
+The fourth use of the set command is to set the values of the shell's
 positional parameters to the specified arguments.
 To change the positional
 parameters without changing any options, use
-.Dq --
+.Dq -\|-
 as the first argument to set.
-If no arguments are present, the set command
+If no following arguments are present, the set command
 will clear all the positional parameters (equivalent to executing
 .Dq shift $# . )
+Otherwise the following arguments become
+.Do \&$1 Dc Ns \&,
+.Do \&$2 Dc Ns \&,
+\&...,
+and
+.Dq \&$#
+is set to the number of arguments present.
 .It setvar Ar variable Ar value
 Assigns value to variable.
 (In general it is better to write
@@ -2094,7 +2347,7 @@
 .Sq - ,
 all signals are reset.
 .Pp
-When the shell forks off a subshell, it resets trapped (but not ignored)
+When the shell forks off a sub-shell, it resets trapped (but not ignored)
 signals to the default action.
 On non-interactive shells, the
 .Ic trap
@@ -2107,7 +2360,7 @@
 Issuing
 .Ic trap
 with option
-.Ar -l
+.Fl l
 will print a list of valid signal names.
 .Ic trap
 without any arguments causes it to write a list of signals and their
@@ -2115,7 +2368,7 @@
 that is suitable as an input to the shell that achieves the same
 trapping results.
 With the
-.Ar -p
+.Fl p
 flag, trap prints the same information for the signals specified,
 or if none are given, for all signals, including those where the
 action is the default.
@@ -2149,7 +2402,6 @@
 .Dl trap 1 2
 .Pp
 Reset the actions for signals 1 (HUP) and 2 (INT) to their defaults.
-.Pp
 .Bd -literal -offset indent
 traps=$(trap -p)
    # more commands ...
@@ -2164,7 +2416,7 @@
 .Fl p
 option is required in the first command here,
 or any signals that were previously
-untrapped (in their default states) 
+untrapped (in their default states)
 and which were altered during the intermediate code,
 would not be reset by the final
 .Dq eval .
@@ -2204,33 +2456,33 @@
 show all the current limits
 .It Fl b
 show or set the limit on the socket buffer size of a process (in bytes)
-.It Fl t
-show or set the limit on CPU time (in seconds)
-.It Fl f
-show or set the limit on the largest file that can be created
+.It Fl c
+show or set the limit on the largest core dump size that can be produced
 (in 512-byte blocks)
 .It Fl d
 show or set the limit on the data segment size of a process (in kilobytes)
-.It Fl s
-show or set the limit on the stack size of a process (in kilobytes)
-.It Fl c
-show or set the limit on the largest core dump size that can be produced
+.It Fl f
+show or set the limit on the largest file that can be created
 (in 512-byte blocks)
-.It Fl m
-show or set the limit on the total physical memory that can be
-in use by a process (in kilobytes)
 .It Fl l
 show or set the limit on how much memory a process can lock with
 .Xr mlock 2
 (in kilobytes)
+.It Fl m
+show or set the limit on the total physical memory that can be
+in use by a process (in kilobytes)
+.It Fl n
+show or set the limit on the number of files a process can have open at once
+.It Fl p
+show or set the limit on the number of processes this user can
+have at one time
 .It Fl r
 show or set the limit on the number of threads this user can
 have at one time
-.It Fl p
-show or set the limit on the number of processes this user can
-have at one time
-.It Fl n
-show or set the limit on the number of files a process can have open at once
+.It Fl s
+show or set the limit on the stack size of a process (in kilobytes)
+.It Fl t
+show or set the limit on CPU time (in seconds)
 .It Fl v
 show or set the limit on how large a process address space can be
 .El
@@ -2243,11 +2495,14 @@
 Limits of an arbitrary process can be displayed or set using the
 .Xr sysctl 8
 utility.
-.It umask Op Ar mask
+.It umask Oo Fl S Oc  Op Ar mask
 Set the value of umask (see
 .Xr umask 2 )
 to the specified octal value.
 If the argument is omitted, the umask value is printed.
+With
+.Fl S
+a symbolic form is used instead of an octal number.
 .It unalias Oo Fl a Oc Oo Ar name Oc
 If
 .Ar name
@@ -2398,12 +2653,15 @@
 .Xr nls 7 .
 .It Ev LINENO
 The current line number in the script or function.
+The value of this variable is automatically set by the
+shell, even if made readonly.
 .It Ev MAIL
 The name of a mail file, that will be checked for the arrival of new mail.
 Overridden by
 .Ev MAILPATH .
-The check occurs just before PS1 is written,
-immediately after reporting jobs which have changed status,
+The check occurs just before
+.Ev PS1
+is written, immediately after reporting jobs which have changed status,
 in interactive shells only.
 New mail is considered to have arrived if the monitored file
 has increased in size since the last check.
@@ -2428,6 +2686,11 @@
 See the
 .Sx Path Search
 section above.
+.It Ev PPID
+The process identified of the parent process of the
+current shell.
+This value is set at shell startup, ignoring
+any value in the environment, and then made readonly.
 .It Ev PS1
 The primary prompt string, which defaults to
 .Dq $ \  ,
@@ -2446,15 +2709,23 @@
 children of the shell, and is used in the history editing modes.
 .\" This is explicitly last, not in sort order - please leave!
 .It Ev NETBSD_SHELL
-Unlike the variables mentioned above,
+Unlike the variables previously mentioned,
 this variable is somewhat strange,
 in that it cannot be set,
 inherited from the environment,
 modified, or exported from the shell.
-If set, it indicates that the shell is the
+If set, by the shell, it indicates that the shell is the
 .Ic sh
 defined by this manual page, and gives its version information.
-It behaves like any other variable that has the read-only
+It can also give information in additional space separated words,
+after the version string.
+If the shell was built as part of a reproducible build,
+the relevant date that was used for that build will be included.
+Finally, any non-standard compilation options,
+which may affect features available,
+that were used when building the shell will be listed.
+.Ev NETBSD_SHELL
+behaves like any other variable that has the read-only
 and un-exportable attributes set.
 .El
 .Sh FILES
@@ -2503,7 +2774,11 @@
 Setuid shell scripts should be avoided at all costs, as they are a
 significant security risk.
 .Pp
-PS1, PS2, and PS4 should be subject to parameter expansion before
+.Ev PS1 ,
+.Ev PS2 ,
+and
+.Ev PS4
+should be subject to parameter expansion before
 being displayed.
 .Pp
 The characters generated by filename completion should probably be quoted
@@ -2511,14 +2786,13 @@
 processed.
 .Pp
 The
-.\" markup?
-trap
+.Ic trap
 command cannot usefully be used, yet, within a command substitution,
 to obtain the current trap values,
 as all command substitutions are currently executed within a
-subshell environment,
+sub-shell environment,
 and in sub-shells all non-ignored, non-default, traps are reset.
-As a workaround, it is possible to redirect ooutput from
+As a workaround, it is possible to redirect output from
 .Dq trap
 or
 .Dq trap -p
--- a/bin/sh/shell.h	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/shell.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: shell.h,v 1.20 2017/03/21 10:52:46 joerg Exp $	*/
+/*	$NetBSD: shell.h,v 1.20.2.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,6 @@
 /*
  * The follow should be set to reflect the type of system you have:
  *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
- *	SHORTNAMES -> 1 if your linker cannot handle long names.
  *	define BSD if you are running 4.2 BSD or later.
  *	define SYSV if you are running under System V.
  *	define DEBUG=1 to compile in debugging ('set -o debug' to turn on)
@@ -59,7 +58,7 @@
 #endif
 
 #ifndef DO_SHAREDVFORK
-#if __NetBSD_Version__ >= 104000000
+#if defined(__NetBSD_Version__) &&  __NetBSD_Version__ >= 104000000
 #define DO_SHAREDVFORK
 #endif
 #endif
@@ -77,13 +76,140 @@
 
 extern const char nullstr[1];		/* null string */
 
+#ifdef	SMALL
+#undef	DEBUG
+#endif
 
 #ifdef DEBUG
-#define TRACE(param)	trace param
-#define TRACEV(param)	tracev param
-#else
-#define TRACE(param)
-#define TRACEV(param)
-#endif
+
+extern	uint64_t	DFlags;
+extern	int		ShNest;
+
+/*
+ * This is selected as there are 26 letters in ascii - not that that
+ * matters for anything, just makes it easier to assign a different
+ * command letter to each debug option.  We currently use only 18
+ * so this could be reduced, but that is of no real benefit.  It can also
+ * be increased, but that both limits the maximum value tha can be
+ * used with DBG_EXTRAS(), and causes problems with verbose option naming.
+ */
+#define	DBG_VBOSE_SHIFT		26
+#define	DBG_EXTRAS(n)	((DBG_VBOSE_SHIFT * 2) + (n))
+
+/*
+ * Unconditional tracing for compatibility with old tracing setup.
+ */
+#define TRACE(param)		do {					\
+					trace param;			\
+				} while (/*CONSTCOND*/ 0)
+#define TRACEV(param)		do {					\
+					tracev param;			\
+				} while (/*CONSTCOND*/ 0)
+
+/*
+ * and the newer conditional tracing, so the mainainer can control
+ * just how much debug output is dumped to the trace file
+ * (once the rest of the shell is converted to use it).
+ *
+ * in the X forms, "xtra" can be any legal C statement(s) without (bare) commas
+ * executed if the relevant debug flag is enabled, after any tracing output.
+ */
+#define CTRACE(when, param)	do {					\
+				    if ((DFlags & (when)) != 0)		\
+					trace param;			\
+				} while (/*CONSTCOND*/ 0)
+
+#define CTRACEV(when, param)	do {					\
+				    if ((DFlags & (when)) != 0)		\
+					tracev param;			\
+				} while (/*CONSTCOND*/ 0)
+
+#define XTRACE(when, param, xtra) do {					\
+				    if ((DFlags & (when)) != 0) {	\
+					trace param;			\
+					xtra;				\
+				    }					\
+				} while (/*CONSTCOND*/ 0)
+
+#define VTRACE(when, param)	do {					\
+				    if ((DFlags &			\
+					(when)<<DBG_VBOSE_SHIFT) != 0)	\
+					    trace param;		\
+				} while (/*CONSTCOND*/ 0)
+
+#define VTRACEV(when, param)	do {					\
+				    if ((DFlags &			\
+					(when)<<DBG_VBOSE_SHIFT) != 0)	\
+					    tracev param;		\
+				} while (/*CONSTCOND*/ 0)
+
+#define VXTRACE(when, param, xtra) do {					\
+				    if ((DFlags &			\
+					(when)<<DBG_VBOSE_SHIFT) != 0) {\
+					    trace param;		\
+					    xtra;			\
+				    }					\
+				} while (/*CONSTCOND*/ 0)
+
+#define SHELL_FORKED()	ShNest++
+#define VFORK_BLOCK	{ const int _ShNest = ShNest;
+#define VFORK_END	}
+#define VFORK_UNDO()	ShNest = _ShNest
+
+#define	DBG_ALWAYS	(1LL << 0)
+#define	DBG_PARSE	(1LL << 1)		/* r (read commands) */
+#define	DBG_EVAL	(1LL << 2)		/* e */
+#define	DBG_EXPAND	(1LL << 3)		/* x */
+#define	DBG_JOBS	(1LL << 4)		/* j */
+#define	DBG_PROCS	(1LL << 5)		/* p */
+#define	DBG_REDIR	(1LL << 6)		/* f (fds) */
+#define	DBG_CMDS	(1LL << 7)		/* c */
+#define	DBG_ERRS	(1LL << 8)		/* z (?) */
+#define	DBG_WAIT	(1LL << 9)		/* w */
+#define	DBG_TRAP	(1LL << 10)		/* t */
+#define	DBG_VARS	(1LL << 11)		/* v */
+#define	DBG_INPUT	(1LL << 12)		/* i */
+#define	DBG_OUTPUT	(1LL << 13)		/* o */
+#define	DBG_MEM		(1LL << 14)		/* m */
+#define	DBG_ARITH	(1LL << 15)		/* a */
+#define	DBG_HISTORY	(1LL << 16)		/* h */
+#define	DBG_SIG		(1LL << 17)		/* s */
+
+/*
+ * reserved extras: b=builtins l=alias
+ * still free:  d g k n q s u y
+ */
+
+	/* use VTRACE(DBG_ALWAYS, (...)) to test this one */
+#define	DBG_VERBOSE	(1LL << DBG_VBOSE_SHIFT)
+
+	/* DBG_EXTRAS 0 .. 11 (max) only  - non-alpha options (no VTRACE !!) */
+#define	DBG_U0		(1LL << DBG_EXTRAS(0))	/* 0 - ad-hoc extra flags */
+#define	DBG_U1		(1LL << DBG_EXTRAS(1))	/* 1 - for short term */
+#define	DBG_U2		(1LL << DBG_EXTRAS(2))	/* 2 - extra tracing*/
+
+#define	DBG_PID		(1LL << DBG_EXTRAS(10))	/* $ ($$) */
+#define	DBG_NEST	(1LL << DBG_EXTRAS(11))	/* ^ */
+
+extern void set_debug(const char *, int);
+
+#else	/* DEBUG */
+
+#define TRACE(param)			/* historic normal trace */
+#define TRACEV(param)			/* historic varargs trace */
+
+#define CTRACE(when, param)		/* conditional normal trace */
+#define CTRACEV(when, param)		/* conditional varargs trace */
+#define XTRACE(when, param, extra)	/* conditional trace, plus more */
+#define VTRACE(when, param)		/* conditional verbose trace */
+#define VTRACEV(when, param)		/* conditional verbose varargs trace */
+#define VXTRACE(when, param, extra)	/* cond verbose trace, plus more */
+
+#define SHELL_FORKED()
+#define VFORK_BLOCK
+#define VFORK_END
+#define VFORK_UNDO()
+
+#endif	/* DEBUG */
 
 #endif /* SHELL_H */
--- a/bin/sh/show.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/show.c	Fri May 19 00:22:50 2017 +0000
@@ -1,9 +1,11 @@
-/*	$NetBSD: show.c,v 1.36.2.1 2017/05/11 02:58:28 pgoyette Exp $	*/
+/*	$NetBSD: show.c,v 1.36.2.2 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.  All rights reserved.
+ *
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
@@ -37,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)show.c	8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: show.c,v 1.36.2.1 2017/05/11 02:58:28 pgoyette Exp $");
+__RCSID("$NetBSD: show.c,v 1.36.2.2 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -45,6 +47,12 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <sys/types.h>
+#include <sys/uio.h>
 
 #include "shell.h"
 #include "parser.h"
@@ -52,402 +60,918 @@
 #include "mystring.h"
 #include "show.h"
 #include "options.h"
-#ifndef SMALL
-#define DEFINE_NODENAMES
-#include "nodenames.h"
+#include "redir.h"
+#include "error.h"
+#include "syntax.h"
+#include "output.h"
+#include "builtins.h"
+
+#if defined(DEBUG) && !defined(DBG_PID)
+/*
+ * If this is compiled, it means this is being compiled in a shell that still
+ * has an older shell.h (a simpler TRACE() mechanism than is coming soon.)
+ *
+ * Compensate for as much of that as is missing and is needed here
+ * to compile and operate at all.   After the other changes have appeared,
+ * this little block can (and should be) deleted (sometime).
+ *
+ * Try to avoid waiting 22 years...
+ */
+#define	DBG_PID		1
+#define	DBG_NEST	2
 #endif
 
-
-FILE *tracefile;
-
-#ifdef DEBUG
-static int shtree(union node *, int, int, char *, FILE*);
-static int shcmd(union node *, FILE *);
-static int shsubsh(union node *, FILE *);
-static int shredir(union node *, FILE *, int);
-static int sharg(union node *, FILE *);
-static int indent(int, char *, FILE *);
-static void trstring(char *);
-
-void
-showtree(union node *n)
-{
-	FILE *fp;
-
-	fp = tracefile ? tracefile : stdout;
-
-	trputs("showtree(");
-		if (n == NULL)
-			trputs("NULL");
-		else if (n == NEOF)
-			trputs("NEOF");
-	trputs(") called\n");
-	if (n != NULL && n != NEOF)
-		shtree(n, 1, 1, NULL, fp);
-}
-
+#define DEFINE_NODENAMES
+#include "nodenames.h"		/* does almost nothing if !defined(DEBUG) */
 
-static int
-shtree(union node *n, int ind, int nl, char *pfx, FILE *fp)
-{
-	struct nodelist *lp;
-	const char *s;
-	int len;
-
-	if (n == NULL) {
-		if (nl)
-			fputc('\n', fp);
-		return 0;
-	}
-
-	len = indent(ind, pfx, fp);
-	switch (n->type) {
-	case NSEMI:
-		s = "; ";
-		len += 2;
-		goto binop;
-	case NAND:
-		s = " && ";
-		len += 4;
-		goto binop;
-	case NOR:
-		s = " || ";
-		len += 4;
-binop:
-		len += shtree(n->nbinary.ch1, 0, 0, NULL, fp);
-		fputs(s, fp);
-		if (len >= 60) {
-			putc('\n', fp);
-			len = indent(ind < 0 ? 2 : ind + 1, pfx, fp);
-		}
-		len += shtree(n->nbinary.ch2, 0, nl, NULL, fp);
-		break;
-	case NCMD:
-		len += shcmd(n, fp);
-		if (nl && len > 0)
-			len = 0, putc('\n', fp);
-		break;
+#define	TR_STD_WIDTH	60	/* tend to fold lines wider than this */
+#define	TR_IOVECS	10	/* number of lines or trace (max) / write */
 
-	case NDNOT:
-		fputs("! ", fp);
-		len += 2;
-		/* FALLTHROUGH */
-	case NNOT:
-		fputs("! ", fp);
-		len += 2 + shtree(n->nnot.com, 0, 0, NULL, fp);
-		break;
+typedef struct traceinfo {
+	int	tfd;	/* file descriptor for open trace file */
+	int	nxtiov;	/* the buffer we should be writing to */
+	char	lastc;	/* the last non-white character output */
+	uint8_t	supr;	/* char classes to supress after \n */
+	pid_t	pid;	/* process id of process that opened that file */
+	size_t	llen;	/* number of chars in current output line */
+	size_t	blen;	/* chars used in current buffer being filled */
+	char *	tracefile;		/* name of the tracefile */
+	struct iovec lines[TR_IOVECS];	/* filled, flling, pending buffers */
+} TFILE;
 
-	case NPIPE:
-		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-			len += shtree(lp->n, 0, 0, NULL, fp);
-			if (lp->next) {
-				len += 3, fputs(" | ", fp);
-				if (len >= 60)  {
-					fputc('\n', fp);
-					len = indent(ind < 0 ? 2 : ind + 1,
-					    pfx, fp);
-				}
-			}
-		}
-		if (n->npipe.backgnd)
-			len += 2, fputs(" &", fp);
-		if (nl || len >= 60)
-			len = 0, fputc('\n', fp);
-		break;
-	case NSUBSHELL:
-		len += shsubsh(n, fp);
-		if (nl && len > 0)
-			len = 0, putc('\n', fp);
-		break;
-	default:
-#ifdef NODETYPENAME
-		len += fprintf(fp, "<node type %d [%s]>", n->type,
-		    NODETYPENAME(n->type));
-#else
-		len += fprintf(fp, "<node type %d>", n->type);
-#endif
-		if (nl)
-			len = 0, putc('\n', fp);
-		break;
-	}
-	return len;
-}
-
-
-
-static int
-shcmd(union node *cmd, FILE *fp)
-{
-	union node *np;
-	int first;
-	int len = 0;
-
-	first = 1;
-	for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
-		if (! first)
-			len++, fputc(' ', fp);
-		len += sharg(np, fp);
-		first = 0;
-	}
-	return len + shredir(cmd, fp, first);
-}
-
-static int
-shsubsh(union node *cmd, FILE *fp)
-{
-	int len = 6;
-
-	fputs(" ( ", fp);
-	len += shtree(cmd->nredir.n, -1, 0, NULL, fp);
-	fputs(" ) ", fp);
-	len += shredir(cmd, fp, 1);
-
-	return len;
-}
-
-static int
-shredir(union node *cmd, FILE *fp, int first)
-{
-	union node *np;
-	const char *s;
-	int dftfd;
-	int len = 0;
-	char buf[106];
+/* These are auto turned off when non white space is printed */
+#define	SUP_NL	0x01	/* don't print \n */
+#define	SUP_SP	0x03	/* supress spaces */
+#define	SUP_WSP	0x04	/* supress all white space */
 
-	for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
-		if (! first)
-			len++, fputc(' ', fp);
-		switch (np->nfile.type) {
-			case NTO:	s = ">";  dftfd = 1; len += 1; break;
-			case NCLOBBER:	s = ">|"; dftfd = 1; len += 2; break;
-			case NAPPEND:	s = ">>"; dftfd = 1; len += 2; break;
-			case NTOFD:	s = ">&"; dftfd = 1; len += 2; break;
-			case NFROM:	s = "<";  dftfd = 0; len += 1; break;
-			case NFROMFD:	s = "<&"; dftfd = 0; len += 2; break;
-			case NFROMTO:	s = "<>"; dftfd = 0; len += 2; break;
-			case NXHERE:	/* FALLTHROUGH */ 
-			case NHERE:	s = "<<"; dftfd = 0; len += 2; break;
-			default:   s = "*error*"; dftfd = 0; len += 7; break;
-		}
-		if (np->nfile.fd != dftfd)
-			len += fprintf(fp, "%d", np->nfile.fd);
-		fputs(s, fp);
-		if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) {
-			len += fprintf(fp, "%d", np->ndup.dupfd);
-		} else
-		    if (np->nfile.type == NHERE || np->nfile.type == NXHERE) {
-			if (np->nfile.type == NHERE)
-				fputc('\\', fp);
-			fputs("!!!\n", fp);
-			s = np->nhere.doc->narg.text;
-			if (strlen(s) > 100) {
-				memmove(buf, s, 100);
-				buf[100] = '\0';
-				strcat(buf, " ...");
-				s = buf;
-			}
-			fputs(s, fp);
-			fputs("!!!", fp);
-			len = 3;
-		} else {
-			len += sharg(np->nfile.fname, fp);
-		}
-		first = 0;
-	}
-	return len;
-}
+#ifdef DEBUG		/* from here to end of file ... */
 
-
-
-static int
-sharg(union node *arg, FILE *fp)
-{
-	char *p;
-	struct nodelist *bqlist;
-	int subtype;
-	int len = 0;
+TFILE tracedata, *tracetfile;
+FILE *tracefile;		/* just for histedit */
 
-	if (arg->type != NARG) {
-		fprintf(fp, "<node type %d>\n", arg->type);
-		abort();
-	}
-	bqlist = arg->narg.backquote;
-	for (p = arg->narg.text ; *p ; p++) {
-		switch (*p) {
-		case CTLESC:
-			putc(*++p, fp);
-			len++;
-			break;
-		case CTLVAR:
-			putc('$', fp);
-			putc('{', fp);
-			len += 2;
-			subtype = *++p;
-			if ((subtype & VSTYPE) == VSLENGTH)
-				len++, putc('#', fp);
-			if (subtype & VSLINENO)
-				len += 7, fputs("LINENO=", fp);
-
-			while (*++p != '=')
-				len++, putc(*p, fp);
-
-			if (subtype & VSNUL)
-				len++, putc(':', fp);
+uint64_t	DFlags;		/* currently enabled debug flags */
+int ShNest;			/* depth of shell (internal) nesting */
 
-			switch (subtype & VSTYPE) {
-			case VSNORMAL:
-				putc('}', fp);
-				len++;
-				break;
-			case VSMINUS:
-				putc('-', fp);
-				len++;
-				break;
-			case VSPLUS:
-				putc('+', fp);
-				len++;
-				break;
-			case VSQUESTION:
-				putc('?', fp);
-				len++;
-				break;
-			case VSASSIGN:
-				putc('=', fp);
-				len++;
-				break;
-			case VSTRIMLEFT:
-				putc('#', fp);
-				len++;
-				break;
-			case VSTRIMLEFTMAX:
-				putc('#', fp);
-				putc('#', fp);
-				len += 2;
-				break;
-			case VSTRIMRIGHT:
-				putc('%', fp);
-				len++;
-				break;
-			case VSTRIMRIGHTMAX:
-				putc('%', fp);
-				putc('%', fp);
-				len += 2;
-				break;
-			case VSLENGTH:
-				break;
-			default:
-				len += fprintf(fp, "<subtype %d>", subtype);
-			}
-			break;
-		case CTLENDVAR:
-		     putc('}', fp);
-		     len++;
-		     break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			putc('$', fp);
-			putc('(', fp);
-			len += shtree(bqlist->n, -1, 0, NULL, fp) + 3;
-			putc(')', fp);
-			break;
-		default:
-			putc(*p, fp);
-			len++;
-			break;
-		}
-	}
-	return len;
-}
+static void shtree(union node *, int, int, int, TFILE *);
+static void shcmd(union node *, TFILE *);
+static void shsubsh(union node *, TFILE *);
+static void shredir(union node *, TFILE *, int);
+static void sharg(union node *, TFILE *);
+static void indent(int, TFILE *);
+static void trstring(const char *);
+static void trace_putc(char, TFILE *);
+static void trace_puts(const char *, TFILE *);
+static void trace_flush(TFILE *, int);
+static char *trace_id(TFILE *);
+static void trace_fd_swap(int, int);
 
-
-static int
-indent(int amount, char *pfx, FILE *fp)
-{
-	int i;
-	int len = 0;
-
-	/*
-	 * in practice, pfx is **always** NULL
-	 * but here, we assume if it were not, at least strlen(pfx) < 8
-	 * if that is invalid, output will look messy
-	 */
-	for (i = 0 ; i < amount ; i++) {
-		if (pfx && i == amount - 1)
-			fputs(pfx, fp);
-		putc('\t', fp);
-		len |= 7;
-		len++;
-	}
-	return len;
-}
-#endif
-
+inline static int trlinelen(TFILE *);
 
 
 /*
- * Debugging stuff.
+ * These functions are the externally visible interface
+ *  (but only for a DEBUG shell.)
  */
 
+void
+opentrace(void)
+{
+	char *s;
+	int fd;
+	int i;
+	pid_t pid;
 
+	if (debug != 1) {
+		/* leave fd open because libedit might be using it */
+		if (tracefile)
+			fflush(tracefile);
+		if (tracetfile)
+			trace_flush(tracetfile, 1);
+		return;
+	}
+#if DBG_PID == 1		/* using old shell.h, old tracing method */
+	DFlags = DBG_PID;	/* just force DBG_PID on, and leave it ... */
+#endif
+	pid = getpid();
+	if (asprintf(&s, "trace.%jd", (intmax_t)pid) <= 0) {
+		debug = 0;
+		error("Cannot asprintf tracefilename");
+	};
 
+	fd = open(s, O_WRONLY|O_APPEND|O_CREAT, 0666);
+	if (fd == -1) {
+		debug = 0;
+		error("Can't open tracefile: %s (%s)\n", s, strerror(errno));
+	}
+	fd = to_upper_fd(fd);
+	if (fd <= 2) {
+		(void) close(fd);
+		debug = 0;
+		error("Attempt to use fd %d as tracefile thwarted\n", fd);
+	}
+	register_sh_fd(fd, trace_fd_swap);
 
-#ifdef DEBUG
-void
-trputc(int c)
-{
-	if (debug != 1 || !tracefile)
-		return;
-	putc(c, tracefile);
+	/*
+	 * This stuff is just so histedit has a FILE * to use
+	 */
+	if (tracefile)
+		(void) fclose(tracefile);	/* also closes tfd */
+	tracefile = fdopen(fd, "a");	/* don't care if it is NULL */
+	if (tracefile)			/* except here... */
+		setlinebuf(tracefile);
+
+	/*
+	 * Now the real tracing setup
+	 */
+	if (tracedata.tfd > 0 && tracedata.tfd != fd)
+		(void) close(tracedata.tfd);	/* usually done by fclose() */
+
+	tracedata.tfd = fd;
+	tracedata.pid = pid;
+	tracedata.nxtiov = 0;
+	tracedata.blen = 0;
+	tracedata.llen = 0;
+	tracedata.lastc = '\0';
+	tracedata.supr = SUP_NL | SUP_WSP;
+
+#define	replace(f, v) do {				\
+		if (tracedata.f != NULL)		\
+			free(tracedata.f);		\
+		tracedata.f = v;			\
+	} while (/*CONSTCOND*/ 0)
+
+	replace(tracefile, s);
+
+	for (i = 0; i < TR_IOVECS; i++) {
+		replace(lines[i].iov_base, NULL);
+		tracedata.lines[i].iov_len = 0;
+	}
+
+#undef replace
+
+	tracetfile = &tracedata;
+
+	trace_puts("\nTracing started.\n", tracetfile);
 }
-#endif
 
 void
 trace(const char *fmt, ...)
 {
-#ifdef DEBUG
 	va_list va;
+	char *s;
 
-	if (debug != 1 || !tracefile)
+	if (debug != 1 || !tracetfile)
 		return;
 	va_start(va, fmt);
-	(void) vfprintf(tracefile, fmt, va);
+	(void) vasprintf(&s, fmt, va);
 	va_end(va);
-#endif
+
+	trace_puts(s, tracetfile);
+	free(s);
+	if (tracetfile->llen == 0)
+		trace_flush(tracetfile, 0);
 }
 
 void
 tracev(const char *fmt, va_list va)
 {
-#ifdef DEBUG
 	va_list ap;
-	if (debug != 1 || !tracefile)
+	char *s;
+
+	if (debug != 1 || !tracetfile)
 		return;
 	va_copy(ap, va);
-	(void) vfprintf(tracefile, fmt, ap);
+	(void) vasprintf(&s, fmt, ap);
 	va_end(ap);
-#endif
+
+	trace_puts(s, tracetfile);
+	free(s);
+	if (tracetfile->llen == 0)
+		trace_flush(tracetfile, 0);
+}
+
+
+void
+trputs(const char *s)
+{
+	if (debug != 1 || !tracetfile)
+		return;
+	trace_puts(s, tracetfile);
+}
+
+void
+trputc(int c)
+{
+	if (debug != 1 || !tracetfile)
+		return;
+	trace_putc(c, tracetfile);
+}
+
+void
+showtree(union node *n)
+{
+	TFILE *fp;
+
+	if ((fp = tracetfile) == NULL)
+		return;
+
+	trace_puts("showtree(", fp);
+		if (n == NULL)
+			trace_puts("NULL", fp);
+		else if (n == NEOF)
+			trace_puts("NEOF", fp);
+		else
+			trace("%p", n);
+	trace_puts(") called\n", fp);
+	if (n != NULL && n != NEOF)
+		shtree(n, 1, 1, 1, fp);
+}
+
+void
+trargs(char **ap)
+{
+	if (debug != 1 || !tracetfile)
+		return;
+	while (*ap) {
+		trstring(*ap++);
+		if (*ap)
+			trace_putc(' ', tracetfile);
+		else
+			trace_putc('\n', tracetfile);
+	}
 }
 
 
-#ifdef DEBUG
-void
-trputs(const char *s)
+/*
+ * Beyond here we just have the implementation of all of that
+ */
+
+
+inline static int
+trlinelen(TFILE * fp)
+{
+	return fp->llen;
+}
+
+static void
+shtree(union node *n, int ind, int ilvl, int nl, TFILE *fp)
 {
-	if (debug != 1 || !tracefile)
+	struct nodelist *lp;
+	const char *s;
+
+	if (n == NULL) {
+		if (nl)
+			trace_putc('\n', fp);
 		return;
-	fputs(s, tracefile);
+	}
+
+	indent(ind, fp);
+	switch (n->type) {
+	case NSEMI:
+		s = NULL;
+		goto binop;
+	case NAND:
+		s = " && ";
+		goto binop;
+	case NOR:
+		s = " || ";
+binop:
+		shtree(n->nbinary.ch1, 0, ilvl, 0, fp);
+		if (s != NULL)
+			trace_puts(s, fp);
+		if (trlinelen(fp) >= TR_STD_WIDTH) {
+			trace_putc('\n', fp);
+			indent(ind < 0 ? 2 : ind + 1, fp);
+		} else if (s == NULL) {
+			if (fp->lastc != '&')
+				trace_puts("; ", fp);
+			else
+				trace_putc(' ', fp);
+		}
+		shtree(n->nbinary.ch2, 0, ilvl, nl, fp);
+		break;
+	case NCMD:
+		shcmd(n, fp);
+		if (n->ncmd.backgnd)
+			trace_puts(" &", fp);
+		if (nl && trlinelen(fp) > 0)
+			trace_putc('\n', fp);
+		break;
+	case NPIPE:
+		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+			shtree(lp->n, 0, ilvl, 0, fp);
+			if (lp->next) {
+				trace_puts(" |", fp);
+				if (trlinelen(fp) >= TR_STD_WIDTH)  {
+					trace_putc('\n', fp);
+					indent((ind < 0 ? ilvl : ind) + 1, fp);
+				} else
+					trace_putc(' ', fp);
+			}
+		}
+		if (n->npipe.backgnd)
+			trace_puts(" &", fp);
+		if (nl || trlinelen(fp) >= TR_STD_WIDTH)
+			trace_putc('\n', fp);
+		break;
+	case NBACKGND:
+	case NSUBSHELL:
+		shsubsh(n, fp);
+		if (n->type == NBACKGND)
+			trace_puts(" &", fp);
+		if (nl && trlinelen(fp) > 0)
+			trace_putc('\n', fp);
+		break;
+	case NDEFUN:
+		trace_puts(n->narg.text, fp);
+		trace_puts("() {\n", fp);
+		indent(ind, fp);
+		shtree(n->narg.next, (ind < 0 ? ilvl : ind) + 1, ilvl+1, 1, fp);
+		indent(ind, fp);
+		trace_puts("}\n", fp);
+		break;
+	case NDNOT:
+		trace_puts("! ", fp);
+		/* FALLTHROUGH */
+	case NNOT:
+		trace_puts("! ", fp);
+		shtree(n->nnot.com, -1, ilvl, nl, fp);
+		break;
+	case NREDIR:
+		shtree(n->nredir.n, -1, ilvl, 0, fp);
+		shredir(n->nredir.redirect, fp, n->nredir.n == NULL);
+		if (nl)
+			trace_putc('\n', fp);
+		break;
+
+	case NIF:
+	itsif:
+		trace_puts("if ", fp);
+		shtree(n->nif.test, -1, ilvl, 0, fp);
+		if (trlinelen(fp) > 0 && trlinelen(fp) < TR_STD_WIDTH) {
+			if (fp->lastc != '&')
+				trace_puts(" ;", fp);
+		} else
+			indent(ilvl, fp);
+		trace_puts(" then ", fp);
+		if (nl || trlinelen(fp) > TR_STD_WIDTH - 24)
+			indent(ilvl+1, fp);
+		shtree(n->nif.ifpart, -1, ilvl + 1, 0, fp);
+		if (trlinelen(fp) > 0 && trlinelen(fp) < TR_STD_WIDTH) {
+			if (fp->lastc != '&')
+				trace_puts(" ;", fp);
+		} else
+			indent(ilvl, fp);
+		if (n->nif.elsepart && n->nif.elsepart->type == NIF) {
+			if (nl || trlinelen(fp) > TR_STD_WIDTH - 24)
+				indent(ilvl, fp);
+			n = n->nif.elsepart;
+			trace_puts(" el", fp);
+			goto itsif;
+		}
+		if (n->nif.elsepart) {
+			if (nl || trlinelen(fp) > TR_STD_WIDTH - 24)
+				indent(ilvl+1, fp);
+			trace_puts(" else ", fp);
+			shtree(n->nif.elsepart, -1, ilvl + 1, 0, fp);
+			if (fp->lastc != '&')
+				trace_puts(" ;", fp);
+		}
+		trace_puts(" fi", fp);
+		if (nl)
+			trace_putc('\n', fp);
+		break;
+
+	case NWHILE:
+		trace_puts("while ", fp);
+		goto aloop;
+	case NUNTIL:
+		trace_puts("until ", fp);
+	aloop:
+		shtree(n->nbinary.ch1, -1, ilvl, 0, fp);
+		if (trlinelen(fp) > 0 && trlinelen(fp) < TR_STD_WIDTH) {
+			if (fp->lastc != '&')
+				trace_puts(" ;", fp);
+		} else
+			trace_putc('\n', fp);
+		trace_puts(" do ", fp);
+		shtree(n->nbinary.ch1, -1, ilvl + 1, 1, fp);
+		trace_puts(" done ", fp);
+		if (nl)
+			trace_putc('\n', fp);
+		break;
+
+	case NFOR:
+		trace_puts("for ", fp);
+		trace_puts(n->nfor.var, fp);
+		if (n->nfor.args) {
+			union node *argp;
+
+			trace_puts(" in ", fp);
+			for (argp = n->nfor.args; argp; argp=argp->narg.next) {
+				sharg(argp, fp);
+				trace_putc(' ', fp);
+			}
+			if (trlinelen(fp) > 0 && trlinelen(fp) < TR_STD_WIDTH) {
+				if (fp->lastc != '&')
+					trace_putc(';', fp);
+			} else
+				trace_putc('\n', fp);
+		}
+		trace_puts(" do ", fp);
+		shtree(n->nfor.body, -1, ilvl + 1, 0, fp);
+		if (fp->lastc != '&')
+			trace_putc(';', fp);
+		trace_puts(" done", fp);
+		if (nl)
+			trace_putc('\n', fp);
+		break;
+
+	case NCASE:
+		trace_puts("case ", fp);
+		sharg(n->ncase.expr, fp);
+		trace_puts(" in", fp);
+		if (nl)
+			trace_putc('\n', fp);
+		{
+			union node *cp;
+
+			for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
+				union node *patp;
+
+				if (nl || trlinelen(fp) > TR_STD_WIDTH - 16)
+					indent(ilvl, fp);
+				else
+					trace_putc(' ', fp);
+				trace_putc('(', fp);
+				patp = cp->nclist.pattern;
+				while (patp != NULL) {
+				    trace_putc(' ', fp);
+				    sharg(patp, fp);
+				    trace_putc(' ', fp);
+				    if ((patp = patp->narg.next) != NULL)
+					trace_putc('|', fp);
+				}
+				trace_putc(')', fp);
+				if (nl)
+					indent(ilvl + 1, fp);
+				else
+					trace_putc(' ', fp);
+				shtree(cp->nclist.body, -1, ilvl+2, 0, fp);
+				if (cp->type == NCLISTCONT)
+					trace_puts(" ;&", fp);
+				else
+					trace_puts(" ;;", fp);
+				if (nl)
+					trace_putc('\n', fp);
+			}
+		}
+		if (nl) {
+			trace_putc('\n', fp);
+			indent(ind, fp);
+		} else
+			trace_putc(' ', fp);
+		trace_puts("esac", fp);
+		if (nl)
+			trace_putc('\n', fp);
+		break;
+
+	default: {
+			char *str;
+
+			asprintf(&str, "<node type %d [%s]>", n->type,
+			    NODETYPENAME(n->type));
+			trace_puts(str, fp);
+			free(str);
+			if (nl)
+				trace_putc('\n', fp);
+		}
+		break;
+	}
 }
 
 
 static void
-trstring(char *s)
+shcmd(union node *cmd, TFILE *fp)
+{
+	union node *np;
+	int first;
+
+	first = 1;
+	for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
+		if (! first)
+			trace_putc(' ', fp);
+		sharg(np, fp);
+		first = 0;
+	}
+	shredir(cmd->ncmd.redirect, fp, first);
+}
+
+static void
+shsubsh(union node *cmd, TFILE *fp)
+{
+	trace_puts(" ( ", fp);
+	shtree(cmd->nredir.n, -1, 3, 0, fp);
+	trace_puts(" ) ", fp);
+	shredir(cmd->ncmd.redirect, fp, 1);
+}
+
+static void
+shredir(union node *np, TFILE *fp, int first)
+{
+	const char *s;
+	int dftfd;
+	char buf[106];
+
+	for ( ; np ; np = np->nfile.next) {
+		if (! first)
+			trace_putc(' ', fp);
+		switch (np->nfile.type) {
+			case NTO:	s = ">";  dftfd = 1; break;
+			case NCLOBBER:	s = ">|"; dftfd = 1; break;
+			case NAPPEND:	s = ">>"; dftfd = 1; break;
+			case NTOFD:	s = ">&"; dftfd = 1; break;
+			case NFROM:	s = "<";  dftfd = 0; break;
+			case NFROMFD:	s = "<&"; dftfd = 0; break;
+			case NFROMTO:	s = "<>"; dftfd = 0; break;
+			case NXHERE:	/* FALLTHROUGH */
+			case NHERE:	s = "<<"; dftfd = 0; break;
+			default:   s = "*error*"; dftfd = 0; break;
+		}
+		if (np->nfile.fd != dftfd) {
+			sprintf(buf, "%d", np->nfile.fd);
+			trace_puts(buf, fp);
+		}
+		trace_puts(s, fp);
+		if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) {
+			if (np->ndup.vname)
+				sharg(np->ndup.vname, fp);
+			else {
+				sprintf(buf, "%d", np->ndup.dupfd);
+				trace_puts(buf, fp);
+			}
+		} else
+		    if (np->nfile.type == NHERE || np->nfile.type == NXHERE) {
+			if (np->nfile.type == NHERE)
+				trace_putc('\\', fp);
+			trace_puts("!!!\n", fp);
+			s = np->nhere.doc->narg.text;
+			if (strlen(s) > 100) {
+				memmove(buf, s, 100);
+				buf[100] = '\0';
+				strcat(buf, " ...\n");
+				s = buf;
+			}
+			trace_puts(s, fp);
+			trace_puts("!!! ", fp);
+		} else {
+			sharg(np->nfile.fname, fp);
+		}
+		first = 0;
+	}
+}
+
+static void
+sharg(union node *arg, TFILE *fp)
+{
+	char *p, *s;
+	struct nodelist *bqlist;
+	int subtype = 0;
+	int quoted = 0;
+
+	if (arg->type != NARG) {
+		asprintf(&s, "<node type %d> ! NARG\n", arg->type);
+		trace_puts(s, fp);
+		abort();	/* no need to free s, better not to */
+	}
+
+	bqlist = arg->narg.backquote;
+	for (p = arg->narg.text ; *p ; p++) {
+		switch (*p) {
+		case CTLESC:
+			trace_putc('\\', fp);
+			trace_putc(*++p, fp);
+			break;
+
+		case CTLVAR:
+			subtype = *++p;
+			if (!quoted != !(subtype & VSQUOTE))
+				trace_putc('"', fp);
+			trace_putc('$', fp);
+			trace_putc('{', fp);
+			if ((subtype & VSTYPE) == VSLENGTH)
+				trace_putc('#', fp);
+			if (subtype & VSLINENO)
+				trace_puts("LINENO=", fp);
+
+			while (*++p != '=')
+				trace_putc(*p, fp);
+
+			if (subtype & VSNUL)
+				trace_putc(':', fp);
+
+			switch (subtype & VSTYPE) {
+			case VSNORMAL:
+				/* { */
+				trace_putc('}', fp);
+				if (!quoted != !(subtype & VSQUOTE))
+					trace_putc('"', fp);
+				break;
+			case VSMINUS:
+				trace_putc('-', fp);
+				break;
+			case VSPLUS:
+				trace_putc('+', fp);
+				break;
+			case VSQUESTION:
+				trace_putc('?', fp);
+				break;
+			case VSASSIGN:
+				trace_putc('=', fp);
+				break;
+			case VSTRIMLEFTMAX:
+				trace_putc('#', fp);
+				/* FALLTHROUGH */
+			case VSTRIMLEFT:
+				trace_putc('#', fp);
+				break;
+			case VSTRIMRIGHTMAX:
+				trace_putc('%', fp);
+				/* FALLTHROUGH */
+			case VSTRIMRIGHT:
+				trace_putc('%', fp);
+				break;
+			case VSLENGTH:
+				break;
+			default: {
+					char str[32];
+
+					snprintf(str, sizeof str,
+					    "<subtype %d>", subtype);
+					trace_puts(str, fp);
+				}
+				break;
+			}
+			break;
+		case CTLENDVAR:
+			/* { */
+			trace_putc('}', fp);
+			if (!quoted != !(subtype & VSQUOTE))
+				trace_putc('"', fp);
+			subtype = 0;
+			break;
+
+		case CTLBACKQ|CTLQUOTE:
+			if (!quoted)
+				trace_putc('"', fp);
+			/* FALLTHRU */
+		case CTLBACKQ:
+			trace_putc('$', fp);
+			trace_putc('(', fp);
+			if (bqlist) {
+				shtree(bqlist->n, -1, 3, 0, fp);
+				bqlist = bqlist->next;
+			} else
+				trace_puts("???", fp);
+			trace_putc(')', fp);
+			if (!quoted && *p == (CTLBACKQ|CTLQUOTE))
+				trace_putc('"', fp);
+			break;
+
+		case CTLQUOTEMARK:
+			if (subtype != 0 || !quoted) {
+				trace_putc('"', fp);
+				quoted++;
+			}
+			break;
+		case CTLQUOTEEND:
+			trace_putc('"', fp);
+			quoted--;
+			break;
+		case CTLARI:
+			trace_puts("$(( ", fp);
+			break;
+		case CTLENDARI:
+			trace_puts(" ))", fp);
+			break;
+
+		default:
+			if (*p == '$')
+				trace_putc('\\', fp);
+			trace_putc(*p, fp);
+			break;
+		}
+	}
+	if (quoted)
+		trace_putc('"', fp);
+}
+
+
+static void
+indent(int amount, TFILE *fp)
+{
+	int i;
+
+	if (amount <= 0)
+		return;
+
+	amount <<= 2;	/* indent slots -> chars */
+
+	i = trlinelen(fp);
+	fp->supr = SUP_NL;
+	if (i > amount) {
+		trace_putc('\n', fp);
+		i = 0;
+	}
+	fp->supr = 0;
+	for (; i < amount - 7 ; i++) {
+		trace_putc('\t', fp);
+		i |= 7;
+	}
+	while (i < amount) {
+		trace_putc(' ', fp);
+		i++;
+	}
+	fp->supr = SUP_WSP;
+}
+
+static void
+trace_putc(char c, TFILE *fp)
 {
 	char *p;
+
+	if (c == '\0')
+		return;
+	if (debug == 0 || fp == NULL)
+		return;
+
+	if (fp->llen == 0) {
+		if (fp->blen != 0)
+			abort();
+
+		if ((fp->supr & SUP_NL) && c == '\n')
+			return;
+		if ((fp->supr & (SUP_WSP|SUP_SP)) && c == ' ')
+			return;
+		if ((fp->supr & SUP_WSP) && c == '\t')
+			return;
+
+		if (fp->nxtiov >= TR_IOVECS - 1)	/* should be rare */
+			trace_flush(fp, 0);
+
+		p = trace_id(fp);
+		if (p != NULL) {
+			fp->lines[fp->nxtiov].iov_base = p;
+			fp->lines[fp->nxtiov].iov_len = strlen(p);
+			fp->nxtiov++;
+		}
+	} else if (fp->blen && fp->blen >= fp->lines[fp->nxtiov].iov_len) {
+		fp->blen = 0;
+		if (++fp->nxtiov >= TR_IOVECS)
+			trace_flush(fp, 0);
+	}
+
+	if (fp->lines[fp->nxtiov].iov_len == 0) {
+		p = (char *)malloc(2 * TR_STD_WIDTH);
+		if (p == NULL) {
+			trace_flush(fp, 1);
+			debug = 0;
+			return;
+		}
+		*p = '\0';
+		fp->lines[fp->nxtiov].iov_base = p;
+		fp->lines[fp->nxtiov].iov_len = 2 * TR_STD_WIDTH;
+		fp->blen = 0;
+	}
+
+	p = (char *)fp->lines[fp->nxtiov].iov_base + fp->blen++;
+	*p++ = c;
+	*p = 0;
+
+	if (c != ' ' && c != '\t' && c != '\n') {
+		fp->lastc = c;
+		fp->supr = 0;
+	}
+
+	if (c == '\n') {
+		fp->lines[fp->nxtiov++].iov_len = fp->blen;
+		fp->blen = 0;
+		fp->llen = 0;
+		fp->supr |= SUP_NL;
+		return;
+	}
+
+	if (c == '\t')
+		fp->llen |=  7;
+	fp->llen++;
+}
+
+void
+trace_flush(TFILE *fp, int all)
+{
+	int niov, i;
+	ssize_t written;
+
+	niov = fp->nxtiov;
+	if (all && fp->blen > 0) {
+		fp->lines[niov].iov_len = fp->blen;
+		fp->blen = 0;
+		fp->llen = 0;
+		niov++;
+	}
+	if (niov == 0)
+		return;
+	if (fp->blen > 0 && --niov == 0)
+		return;
+	written = writev(fp->tfd, fp->lines, niov);
+	for (i = 0; i < niov; i++) {
+		free(fp->lines[i].iov_base);
+		fp->lines[i].iov_base = NULL;
+		fp->lines[i].iov_len = 0;
+	}
+	if (written == -1) {
+		if (fp->blen > 0) {
+			free(fp->lines[niov].iov_base);
+			fp->lines[niov].iov_base = NULL;
+			fp->lines[niov].iov_len = 0;
+		}
+		debug = 0;
+		fp->blen = 0;
+		fp->llen = 0;
+		return;
+	}
+	if (fp->blen > 0) {
+		fp->lines[0].iov_base = fp->lines[niov].iov_base;
+		fp->lines[0].iov_len = fp->lines[niov].iov_len;
+		fp->lines[niov].iov_base = NULL;
+		fp->lines[niov].iov_len = 0;
+	}
+	fp->nxtiov = 0;
+}
+
+void
+trace_puts(const char *s, TFILE *fp)
+{
 	char c;
 
-	if (debug != 1 || !tracefile)
+	while ((c = *s++) != '\0')
+		trace_putc(c, fp);
+}
+
+inline static char *
+trace_id(TFILE *tf)
+{
+	int i;
+	char indent[16];
+	char *p;
+
+	if (DFlags & DBG_NEST) {
+		if ((unsigned)ShNest >= sizeof indent - 1) {
+			(void) snprintf(indent, sizeof indent,
+			    "### %*d ###", (int)(sizeof indent) - 9, ShNest);
+			p = strchr(indent, '\0');
+		} else {
+			p = indent;
+			for (i = 0; i < 6; i++)
+				*p++ = (i < ShNest) ? '#' : ' ';
+			while (i++ < ShNest && p < &indent[sizeof indent - 1])
+				*p++ = '#';
+			*p = '\0';
+		}
+	} else
+		indent[0] = '\0';
+
+	if (DFlags & DBG_PID) {
+		i = getpid();
+		(void) asprintf(&p, "%5d%c%s\t", i,
+		    i == tf->pid ? ':' : '=', indent);
+		return p;
+	} else if (DFlags & DBG_NEST) {
+		(void) asprintf(&p, "%s\t", indent);
+		return p;
+	}
+	return NULL;
+}
+
+/*
+ * Used only from trargs(), which itself is used only to print
+ * arg lists (argv[]) either that passed into this shell, or
+ * the arg list about to be given to some other command (incl
+ * builtin, and function) as their argv[].  If any of the CTL*
+ * chars seem to appear, they really should be just treated as data,
+ * not special...   But this is just debug, so, who cares!
+ */
+static void
+trstring(const char *s)
+{
+	const char *p;
+	char c;
+	TFILE *fp;
+
+	if (debug != 1 || !tracetfile)
 		return;
-	putc('"', tracefile);
+	fp = tracetfile;
+	trace_putc('"', fp);
 	for (p = s ; *p ; p++) {
 		switch (*p) {
 		case '\n':  c = 'n';  goto backslash;
@@ -460,78 +984,161 @@
 		case CTLVAR+CTLQUOTE:  c = 'V';  goto backslash;
 		case CTLBACKQ:  c = 'q';  goto backslash;
 		case CTLBACKQ+CTLQUOTE:  c = 'Q';  goto backslash;
-backslash:	  putc('\\', tracefile);
-			putc(c, tracefile);
+backslash:		trace_putc('\\', fp);
+			trace_putc(c, fp);
 			break;
 		default:
 			if (*p >= ' ' && *p <= '~')
-				putc(*p, tracefile);
+				trace_putc(*p, fp);
 			else {
-				putc('\\', tracefile);
-				putc(*p >> 6 & 03, tracefile);
-				putc(*p >> 3 & 07, tracefile);
-				putc(*p & 07, tracefile);
+				trace_putc('\\', fp);
+				trace_putc(*p >> 6 & 03, fp);
+				trace_putc(*p >> 3 & 07, fp);
+				trace_putc(*p & 07, fp);
 			}
 			break;
 		}
 	}
-	putc('"', tracefile);
+	trace_putc('"', fp);
 }
-#endif
 
-
-void
-trargs(char **ap)
+/*
+ * deal with the user "accidentally" picking our fd to use.
+ */
+static void
+trace_fd_swap(int from, int to)
 {
-#ifdef DEBUG
-	if (debug != 1 || !tracefile)
+	if (tracetfile == NULL || from == to)
 		return;
-	while (*ap) {
-		trstring(*ap++);
-		if (*ap)
-			putc(' ', tracefile);
-		else
-			putc('\n', tracefile);
-	}
-#endif
+
+	tracetfile->tfd = to;
+
+	/*
+	 * This is just so histedit has a stdio FILE* to use.
+	 */
+	if (tracefile)
+		fclose(tracefile);
+	tracefile = fdopen(to, "a");
+	if (tracefile)
+		setlinebuf(tracefile);
 }
 
 
-#ifdef DEBUG
-void
-opentrace(void)
-{
-	char s[100];
-#ifdef O_APPEND
-	int flags;
-#endif
+static struct debug_flag {
+	char		label;
+	uint64_t	flag;
+} debug_flags[] = {
+	{ 'a',	DBG_ARITH	},	/* arithmetic ( $(( )) ) */
+	{ 'c',	DBG_CMDS	},	/* command searching, ... */
+	{ 'e',	DBG_EVAL	},	/* evaluation of the parse tree */
+	{ 'f',	DBG_REDIR	},	/* file descriptors & redirections */
+	{ 'h',	DBG_HISTORY	},	/* history & cmd line editing */
+	{ 'i',	DBG_INPUT	},	/* shell input routines */
+	{ 'j',	DBG_JOBS	},	/* job control, structures */
+	{ 'm',	DBG_MEM		},	/* memory management */
+	{ 'o',	DBG_OUTPUT	},	/* output routines */
+	{ 'p',	DBG_PROCS	},	/* process management, fork, ... */
+	{ 'r',	DBG_PARSE	},	/* parser, lexer, ... tree building */
+	{ 's',	DBG_SIG		},	/* signals and everything related */
+	{ 't',	DBG_TRAP	},	/* traps & signals */
+	{ 'v',	DBG_VARS	},	/* variables and parameters */
+	{ 'w',	DBG_WAIT	},	/* waits for processes to finish */
+	{ 'x',	DBG_EXPAND	},	/* word expansion ${} $() $(( )) */
+	{ 'z',	DBG_ERRS	},	/* error control, jumps, cleanup */
+ 
+	{ '0',	DBG_U0		},	/* ad-hoc temp debug flag #0 */
+	{ '1',	DBG_U1		},	/* ad-hoc temp debug flag #1 */
+	{ '2',	DBG_U2		},	/* ad-hoc temp debug flag #2 */
+ 
+	{ '$',	DBG_PID		},	/* prefix trace lines with sh pid */
+	{ '^',	DBG_NEST	},	/* show shell nesting level */
+
+			/* alpha options only */
+	{ '_',	DBG_PARSE | DBG_EVAL | DBG_EXPAND | DBG_JOBS |
+		    DBG_PROCS | DBG_REDIR | DBG_CMDS | DBG_ERRS |
+		    DBG_WAIT | DBG_TRAP | DBG_VARS | DBG_MEM |
+		    DBG_INPUT | DBG_OUTPUT | DBG_ARITH | DBG_HISTORY },
+
+   /*   { '*',	DBG_ALLVERBOSE	}, 	   is handled in the code */
+
+	{ '#',	DBG_U0 | DBG_U1 | DBG_U2 },
 
-	if (debug != 1) {
-		if (tracefile)
-			fflush(tracefile);
-		/* leave open because libedit might be using it */
-		return;
-	}
-	snprintf(s, sizeof(s), "./trace.%d", (int)getpid());
-	if (tracefile) {
-		if (!freopen(s, "a", tracefile)) {
-			fprintf(stderr, "Can't re-open %s\n", s);
-			tracefile = NULL;
-			debug = 0;
-			return;
+	{ 0,	0		}
+};
+
+void
+set_debug(const char * flags, int on)
+{
+	char f;
+	struct debug_flag *df;
+	int verbose;
+
+	while ((f = *flags++) != '\0') {
+		verbose = 0;
+		if (is_upper(f)) {
+			verbose = 1;
+			f += 'a' - 'A';
 		}
-	} else {
-		if ((tracefile = fopen(s, "a")) == NULL) {
-			fprintf(stderr, "Can't open %s\n", s);
-			debug = 0;
-			return;
+		if (f == '*')
+			f = '_', verbose = 1;
+		if (f == '+') {
+			if (*flags == '+')
+				flags++, verbose=1;
+		}
+
+		/*
+		 * Note: turning on any debug option also enables DBG_ALWAYS
+		 * turning on any verbose option also enables DBG_VERBOSE
+		 * Once enabled, those flags cannot be disabled.
+		 * (tracing can still be turned off with "set +o debug")
+		 */
+		for (df = debug_flags; df->label != '\0'; df++) {
+			if (f == '+' || df->label == f) {
+				if (on) {
+					DFlags |= DBG_ALWAYS | df->flag;
+					if (verbose)
+					    DFlags |= DBG_VERBOSE |
+						(df->flag << DBG_VBOSE_SHIFT);
+				} else {
+					DFlags &= ~(df->flag<<DBG_VBOSE_SHIFT);
+					if (!verbose)
+						DFlags &= ~df->flag;
+				}
+			}
 		}
 	}
-#ifdef O_APPEND
-	if ((flags = fcntl(fileno(tracefile), F_GETFL, 0)) >= 0)
-		fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
-#endif
-	setlinebuf(tracefile);
-	fputs("\nTracing started.\n", tracefile);
 }
+
+
+int
+debugcmd(int argc, char **argv)
+{
+	if (argc == 1) {
+		struct debug_flag *df;
+
+		out1fmt("Debug: %sabled.  Flags: ", debug ? "en" : "dis");
+		for (df = debug_flags; df->label != '\0'; df++) {
+			if (df->flag & (df->flag - 1))
+				continue;
+			if (is_alpha(df->label) &&
+			    (df->flag << DBG_VBOSE_SHIFT) & DFlags)
+				out1c(df->label - ('a' - 'A'));
+			else if (df->flag & DFlags)
+				out1c(df->label);
+		}
+		out1c('\n');
+		return 0;
+	}
+
+	while (*++argv) {
+		if (**argv == '-')
+			set_debug(*argv + 1, 1);
+		else if (**argv == '+')
+			set_debug(*argv + 1, 0);
+		else
+			return 1;
+	}
+	return 0;
+}
+
 #endif /* DEBUG */
--- a/bin/sh/show.h	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/show.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.h,v 1.9 2017/03/16 13:21:59 kre Exp $	*/
+/*	$NetBSD: show.h,v 1.9.2.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1995
@@ -33,12 +33,12 @@
 
 #include <stdarg.h>
 
+#ifdef DEBUG
 union node;
 void showtree(union node *);
 void trace(const char *, ...);
 void tracev(const char *, va_list);
 void trargs(char **);
-#ifdef DEBUG
 void trputc(int);
 void trputs(const char *);
 void opentrace(void);
--- a/bin/sh/syntax.h	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/syntax.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: syntax.h,v 1.6 2016/03/16 19:02:26 christos Exp $	*/
+/*	$NetBSD: syntax.h,v 1.6.6.1 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -69,6 +69,8 @@
 /* These defines assume that the digits are contiguous (which is guaranteed) */
 #define	is_digit(c)	((unsigned)((c) - '0') <= 9)
 #define sh_ctype(c)	(is_type+SYNBASE)[(int)(c)]
+#define	is_upper(c)	(sh_ctype(c) & ISUPPER)
+#define	is_lower(c)	(sh_ctype(c) & ISLOWER)
 #define	is_alpha(c)	(sh_ctype(c) & (ISUPPER|ISLOWER))
 #define	is_name(c)	(sh_ctype(c) & (ISUPPER|ISLOWER|ISUNDER))
 #define	is_in_name(c)	(sh_ctype(c) & (ISUPPER|ISLOWER|ISUNDER|ISDIGIT))
--- a/bin/sh/var.c	Thu May 18 23:52:01 2017 +0000
+++ b/bin/sh/var.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.49.6.2 2017/05/11 02:58:28 pgoyette Exp $	*/
+/*	$NetBSD: var.c,v 1.49.6.3 2017/05/19 00:22:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: var.c,v 1.49.6.2 2017/05/11 02:58:28 pgoyette Exp $");
+__RCSID("$NetBSD: var.c,v 1.49.6.3 2017/05/19 00:22:51 pgoyette Exp $");
 #endif
 #endif /* not lint */
 
@@ -162,14 +162,45 @@
 	}
 
 	/*
+	 * Set variables which override anything read from environment.
+	 *
 	 * PPID is readonly
-	 *	set after processing environ to override anything there
-	 * Always default IFS, ignore any value from environment.
+	 * Always default IFS
+	 * NETBSD_SHELL is a constant (readonly), and is never exported
 	 */
 	snprintf(buf, sizeof(buf), "%d", (int)getppid());
 	setvar("PPID", buf, VREADONLY);
 	setvar("IFS", ifs_default, VTEXTFIXED);
-	setvar("NETBSD_SHELL", NETBSD_SHELL, VTEXTFIXED|VREADONLY|VNOEXPORT);
+
+	setvar("NETBSD_SHELL", NETBSD_SHELL
+#ifdef BUILD_DATE
+		" BUILD:" BUILD_DATE
+#endif
+#ifdef DEBUG
+		" DEBUG"
+#endif
+#if !defined(JOBS) || JOBS == 0
+		" -JOBS"
+#endif
+#ifndef DO_SHAREDVFORK
+		" -VFORK"
+#endif
+#ifdef SMALL
+		" SMALL"
+#endif
+#ifdef TINY
+		" TINY"
+#endif
+#ifdef OLD_TTY_DRIVER
+		" OLD_TTY"
+#endif
+#ifdef SYSV
+		" SYSV"
+#endif
+#ifndef BSD
+		" -BSD"
+#endif
+		    , VTEXTFIXED|VREADONLY|VNOEXPORT);
 }
 #endif
 
--- a/distrib/amd64/installimage/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/amd64/installimage/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.6 2016/01/24 15:30:05 christos Exp $
+#	$NetBSD: Makefile,v 1.6.6.1 2017/05/19 00:22:51 pgoyette Exp $
 
 .include <bsd.own.mk>
 
 INSTIMGBASE=	NetBSD-${DISTRIBVER}-amd64-install	# gives ${IMGBASE}.img
 
 BOOTDISK=	sd0			# for USB flash etc.
-INSTIMAGEMB?=	1200			# for all installation binaries
+INSTIMAGEMB?=	1300			# for all installation binaries
 
 PRIMARY_BOOT=		bootxx_ffsv1
 SECONDARY_BOOT=		boot
--- a/distrib/amd64/uefi-installimage/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/amd64/uefi-installimage/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.1 2017/01/24 11:16:50 nonaka Exp $
+#	$NetBSD: Makefile,v 1.1.6.1 2017/05/19 00:22:51 pgoyette Exp $
 
 .include <bsd.own.mk>
 
 INSTIMGBASE=	NetBSD-${DISTRIBVER}-amd64-uefi-install	# gives ${IMGBASE}.img
 
 BOOTDISK=	dk1			# unused (use GUID)
-INSTIMAGEMB?=	1280			# for all installation binaries
+INSTIMAGEMB?=	1380			# for all installation binaries
 
 PRIMARY_BOOT=		bootxx_ffsv1
 SECONDARY_BOOT=		boot
--- a/distrib/arc/ramdisk/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/arc/ramdisk/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.25 2017/01/24 18:04:01 christos Exp $
+#	$NetBSD: Makefile,v 1.25.2.1 2017/05/19 00:22:51 pgoyette Exp $
 
 .include <bsd.own.mk>
 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
 
 IMAGE=		ramdisk.fs
-IMAGESIZE=	2860k
+IMAGESIZE=	3060k
 MAKEFS_FLAGS+=	-f 15
 
 WARNS=		1
--- a/distrib/notes/common/main	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/notes/common/main	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: main,v 1.534 2017/03/10 04:13:43 salazar Exp $
+.\"	$NetBSD: main,v 1.534.2.1 2017/05/19 00:22:51 pgoyette Exp $
 .\"
 .\" Copyright (c) 1999-2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -1028,9 +1028,9 @@
 .br_ne 1i
 .It Em "The NetBSD core group:"
 .It Ta Ta
-.It Ta Alan Barrett Ta Mt apb@NetBSD.org
 .It Ta Alistair Crooks Ta Mt agc@NetBSD.org
 .It Ta Matthew Green Ta Mt mrg@NetBSD.org
+.It Ta Martin Husemann Ta Mt martin@NetBSD.org
 .It Ta Chuck Silvers Ta Mt chs@NetBSD.org
 .It Ta Matt Thomas Ta Mt matt@NetBSD.org
 .It Ta YAMAMOTO Takashi Ta Mt yamt@NetBSD.org
--- a/distrib/sets/lists/base/shl.mi	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/sets/lists/base/shl.mi	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.811.2.1 2017/05/11 02:58:28 pgoyette Exp $
+# $NetBSD: shl.mi,v 1.811.2.2 2017/05/19 00:22:51 pgoyette Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -54,7 +54,7 @@
 ./lib/liblzma.so.2.0				base-sys-shlib		dynamicroot
 ./lib/libm.so					base-sys-shlib		dynamicroot
 ./lib/libm.so.0					base-sys-shlib		dynamicroot
-./lib/libm.so.0.11				base-sys-shlib		dynamicroot
+./lib/libm.so.0.12				base-sys-shlib		dynamicroot
 ./lib/libnpf.so					base-npf-shlib		dynamicroot,npf
 ./lib/libnpf.so.0				base-npf-shlib		dynamicroot,npf
 ./lib/libnpf.so.0.1				base-npf-shlib		dynamicroot,npf
@@ -387,7 +387,7 @@
 ./usr/lib/liblzma.so.2.0			base-sys-shlib		compatfile
 ./usr/lib/libm.so				base-sys-shlib		compatfile
 ./usr/lib/libm.so.0				base-sys-shlib		compatfile
-./usr/lib/libm.so.0.11				base-sys-shlib		compatfile
+./usr/lib/libm.so.0.12				base-sys-shlib		compatfile
 ./usr/lib/libmagic.so				base-sys-shlib		compatfile
 ./usr/lib/libmagic.so.5				base-sys-shlib		compatfile
 ./usr/lib/libmagic.so.5.2			base-sys-shlib		compatfile
--- a/distrib/sets/lists/debug/shl.mi	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/sets/lists/debug/shl.mi	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.170.2.1 2017/05/11 02:58:29 pgoyette Exp $
+# $NetBSD: shl.mi,v 1.170.2.2 2017/05/19 00:22:51 pgoyette Exp $
 ./usr/lib/libbfd_g.a						comp-c-debuglib	debuglib,compatfile,binutils
 ./usr/libdata/debug/lib						base-sys-usr	debug,dynamicroot,compatdir
 ./usr/libdata/debug/lib/libblacklist.so.0.0.debug		comp-sys-debug	debug,dynamicroot
@@ -14,7 +14,7 @@
 ./usr/libdata/debug/lib/libkvm.so.6.0.debug			comp-sys-debug	debug,dynamicroot
 ./usr/libdata/debug/lib/liblzf.so.1.0.debug			comp-sys-debug	debug,dynamicroot
 ./usr/libdata/debug/lib/liblzma.so.2.0.debug			comp-sys-debug	debug,dynamicroot
-./usr/libdata/debug/lib/libm.so.0.11.debug			comp-sys-debug	debug,dynamicroot
+./usr/libdata/debug/lib/libm.so.0.12.debug			comp-sys-debug	debug,dynamicroot
 ./usr/libdata/debug/lib/libnpf.so.0.1.debug			comp-sys-debug	debug,dynamicroot
 ./usr/libdata/debug/lib/libpcap.so.6.0.debug			comp-sys-debug	debug,dynamicroot
 ./usr/libdata/debug/lib/libppath.so.0.0.debug			comp-sys-debug	debug,dynamicroot
@@ -134,7 +134,7 @@
 ./usr/libdata/debug/usr/lib/liblwres.so.8.4.debug		comp-bind-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/liblzf.so.1.0.debug			comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/liblzma.so.2.0.debug		comp-sys-debug	debug,compatfile
-./usr/libdata/debug/usr/lib/libm.so.0.11.debug			comp-sys-debug	debug,compatfile
+./usr/libdata/debug/usr/lib/libm.so.0.12.debug			comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libmagic.so.5.2.debug		comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libmenu.so.6.0.debug		comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libmj.so.1.0.debug			comp-crypto-debug	debug,compatfile,crypto
--- a/distrib/sets/lists/man/mi	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/sets/lists/man/mi	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1554 2017/04/19 00:17:30 riastradh Exp $
+# $NetBSD: mi,v 1.1554.2.1 2017/05/19 00:22:51 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1949,6 +1949,7 @@
 ./usr/share/man/cat4/vioif.0			man-sys-catman		.cat
 ./usr/share/man/cat4/viomb.0			man-sys-catman		.cat
 ./usr/share/man/cat4/viornd.0			man-sys-catman		.cat
+./usr/share/man/cat4/vioscsi.0			man-sys-catman		.cat
 ./usr/share/man/cat4/virt.0			man-sys-catman		.cat
 ./usr/share/man/cat4/virtio.0			man-sys-catman		.cat
 ./usr/share/man/cat4/vlan.0			man-sys-catman		.cat
@@ -4980,6 +4981,7 @@
 ./usr/share/man/html4/vioif.html		man-sys-htmlman		html
 ./usr/share/man/html4/viomb.html		man-sys-htmlman		html
 ./usr/share/man/html4/viornd.html		man-sys-htmlman		html
+./usr/share/man/html4/vioscsi.html		man-sys-htmlman		html
 ./usr/share/man/html4/virt.html			man-sys-htmlman		html
 ./usr/share/man/html4/virtio.html		man-sys-htmlman		html
 ./usr/share/man/html4/vlan.html			man-sys-htmlman		html
@@ -7943,6 +7945,7 @@
 ./usr/share/man/man4/vioif.4			man-sys-man		.man
 ./usr/share/man/man4/viomb.4			man-sys-man		.man
 ./usr/share/man/man4/viornd.4			man-sys-man		.man
+./usr/share/man/man4/vioscsi.4			man-sys-man		.man
 ./usr/share/man/man4/virt.4			man-sys-man		.man
 ./usr/share/man/man4/virtio.4			man-sys-man		.man
 ./usr/share/man/man4/vlan.4			man-sys-man		.man
--- a/distrib/sets/lists/tests/mi	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/sets/lists/tests/mi	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.735.2.2 2017/05/11 02:58:29 pgoyette Exp $
+# $NetBSD: mi,v 1.735.2.3 2017/05/19 00:22:51 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3300,12 +3300,13 @@
 ./usr/tests/net/ipsec/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/ipsec/t_ipsec_ah_keys		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_esp_keys		tests-net-tests		atf,rump
+./usr/tests/net/ipsec/t_ipsec_gif		tests-net-tests		atf,rump
+./usr/tests/net/ipsec/t_ipsec_l2tp		tests-net-tests		atf,rump
+./usr/tests/net/ipsec/t_ipsec_misc		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_sysctl		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_transport		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_tunnel		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_tunnel_odd	tests-net-tests		atf,rump
-./usr/tests/net/ipsec/t_ipsec_gif		tests-net-tests		atf,rump
-./usr/tests/net/ipsec/t_ipsec_l2tp		tests-net-tests		atf,rump
 ./usr/tests/net/mcast				tests-net-tests		compattestfile,atf
 ./usr/tests/net/mcast/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/mcast/Kyuafile			tests-net-tests		atf,rump,kyua
@@ -3584,6 +3585,12 @@
 ./usr/tests/usr.bin/bzip2/d_sample3.bz2		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/bzip2/d_sample3.ref		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/bzip2/t_bzip2		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/c++				tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/Atffile			tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/Kyuafile		tests-usr.bin-tests	compattestfile,atf,kyua,cxx
+./usr/tests/usr.bin/c++/t_cxxruntime		tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_hello			tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_static_destructor	tests-usr.bin-tests	compattestfile,atf,cxx
 ./usr/tests/usr.bin/cc				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/cc/Atffile			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/cc/Kyuafile			tests-usr.bin-tests	compattestfile,atf,kyua
--- a/distrib/utils/embedded/conf/evbarm.conf	Thu May 18 23:52:01 2017 +0000
+++ b/distrib/utils/embedded/conf/evbarm.conf	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: evbarm.conf,v 1.26 2017/04/12 23:32:11 jmcneill Exp $
+# $NetBSD: evbarm.conf,v 1.26.2.1 2017/05/19 00:22:52 pgoyette Exp $
 # evbarm shared config
 #
 image=$HOME/${board}.img
@@ -118,13 +118,14 @@
 }
 
 customize_evbarm() {
-	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
 	if $minwrites; then
 		mkdir ${mnt}/etc/postfix
 		(umask 022
 		sed -e 's/fifo/unix/' < ${release}/etc/postfix/master.cf > \
 		    ${mnt}/etc/postfix/master.cf)
 	fi
+	
+	cp ${release}/etc/rc.conf ${mnt}/etc/rc.conf
 	cat >> ${mnt}/etc/rc.conf << EOF
 rc_configured=YES
 hostname=${board}
--- a/doc/CHANGES	Thu May 18 23:52:01 2017 +0000
+++ b/doc/CHANGES	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2277.2.2 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2277.2.3 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -483,6 +483,8 @@
 	siginfo(2): Add new si_code values for SIGTRAP: TRAP_SCE and TRAP_SCX
 		[kamil 20170228]
 	zoneinfo: Import tzdata2017a.  [kre 20170301]
+	vioscsi(4): Allocate bus dma maps on attach, improves stability
+		and performance, adresses kern/52043 [jdolecek 20170307]
 	luna68k: Add a driver for LUNA's front panel LCD.  Ported from
 		OpenBSD/luna88k. [tsutsui 20170309]
 	sqlite3: Import 3.17.0. [christos 20170311]
@@ -492,6 +494,9 @@
 		adding support for all required operators, as well
 		as being smaller and faster.  [kre 20170320]
 	zoneinfo: Import tzdata2017b.  [kre 20170321]
+	virtio(4): Refactor child driver attach code for better modularization
+		[jdolecek 20170325]
+	vioscsi(4): Use MSI/MSI-X, reduce disk probe time [jdolecek 20170325]
 	dhcpcd(8): Import dhcpcd-7.0.0-beta2 [roy 20170402]
 	ptrace(2): Add operations to single step specified threads:
 		PT_SETSTEP and PT_CLEARSTEP [kamil 20170408]
@@ -507,3 +512,4 @@
 	acpi(4): Updated ACPICA to 20170303. [christos 20170430]
 	openpam(3): update to 20170430 (resedacea) [christos 20170506]
 	dhcpcd: Import dhcpcd 7.0.0-rc1 [roy 20170510]
+	vioscsi(4): Stability fixes [jdolecek 20170515]
--- a/etc/mtree/NetBSD.dist.tests	Thu May 18 23:52:01 2017 +0000
+++ b/etc/mtree/NetBSD.dist.tests	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.145 2017/04/14 02:56:48 ozaki-r Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.145.2.1 2017/05/19 00:22:52 pgoyette Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -376,6 +376,7 @@
 ./usr/tests/usr.bin/awk
 ./usr/tests/usr.bin/basename
 ./usr/tests/usr.bin/bzip2
+./usr/tests/usr.bin/c++
 ./usr/tests/usr.bin/cc
 ./usr/tests/usr.bin/cmp
 ./usr/tests/usr.bin/config
--- a/external/bsd/atf/dist/atf-sh/atf-sh-api.3	Thu May 18 23:52:01 2017 +0000
+++ b/external/bsd/atf/dist/atf-sh/atf-sh-api.3	Fri May 19 00:22:50 2017 +0000
@@ -26,7 +26,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 13, 2013
+.Dd May 15, 2017
 .Dt ATF-SH-API 3
 .Os
 .Sh NAME
@@ -51,25 +51,44 @@
 .Nm atf_test_case
 .Nd POSIX shell API to write ATF-based test programs
 .Sh SYNOPSIS
-.Fn atf_add_test_case "name"
-.Fn atf_check "command"
-.Fn atf_check_equal "expr1" "expr2"
-.Fn atf_config_get "var_name"
-.Fn atf_config_has "var_name"
-.Fn atf_expect_death "reason" "..."
-.Fn atf_expect_exit "exitcode" "reason" "..."
-.Fn atf_expect_fail "reason" "..."
-.Fn atf_expect_pass
-.Fn atf_expect_signal "signo" "reason" "..."
-.Fn atf_expect_timeout "reason" "..."
-.Fn atf_fail "reason"
-.Fn atf_get "var_name"
-.Fn atf_get_srcdir
-.Fn atf_pass
-.Fn atf_require_prog "prog_name"
-.Fn atf_set "var_name" "value"
-.Fn atf_skip "reason"
-.Fn atf_test_case "name" "cleanup"
+.Ic atf_add_test_case Dq name
+.br
+.Ic atf_check Dq command
+.br
+.Ic atf_check_equal Do expr1 Dc Dq expr2
+.br
+.Ic atf_config_get Dq var_name
+.br
+.Ic atf_config_has Dq var_name
+.br
+.Ic atf_expect_death Do reason Dc Dq \&...
+.br
+.Ic atf_expect_exit Do exitcode Dc Do reason Dc Dq \&...
+.br
+.Ic atf_expect_fail Do reason Dc Dq \&...
+.br
+.Ic atf_expect_pass
+.br
+.Ic atf_expect_signal Do signo Dc Do reason Dc Dq \&...
+.br
+.Ic atf_expect_timeout Do reason Dc Dq \&...
+.br
+.Ic atf_fail Dq reason
+.br
+.Ic atf_get Dq var_name
+.br
+.Ic atf_get_srcdir
+.br
+.Ic atf_pass
+.br
+.Ic atf_require_prog Dq prog_name
+.br
+.Ic atf_set Do var_name Dc Dq value
+.br
+.Ic atf_skip Dq reason
+.br
+.Ic atf_test_case Do name Dc Dq cleanup
+.br
 .Sh DESCRIPTION
 ATF
 provides a simple but powerful interface to easily write test programs in
@@ -114,13 +133,43 @@
     ... add additional test cases ...
 }
 .Ed
+.Pp
+All of these functions are required to return with an exit-status of
+zero, or ATF will determine that the test is faulty.
+In particular, this means that none may end with a conditional like:
+.Bd -literal -offset indent
+atf_sh_function() {
+    ... appropriate code here ...
+    condition-test && {
+	... more code here ...
+    }
+}
+.Ed
+.Pp
+as if condition-test fails
+the return code from atf_sh_function will not be 0.
+This can be corrected by adding
+.Bd -literal -offset indent
+    return 0
+.Ed
+.Pp
+before the end of the function, or by writing it as
+.Bd -literal -offset indent
+atf_sh_function() {
+    ... appropriate code here ...
+    if condition-test
+    then
+	... more code here ...
+    fi
+}
+.Ed
 .Ss Definition of test cases
 Test cases have an identifier and are composed of three different parts:
 the header, the body and an optional cleanup routine, all of which are
 described in
 .Xr atf-test-case 4 .
 To define test cases, one can use the
-.Fn atf_test_case
+.Ic atf_test_case
 function, which takes a first parameter specifiying the test case's
 name and instructs the library to set things up to accept it as a valid
 test case.
@@ -132,33 +181,34 @@
 .Em does not
 set the test case up for execution when the program is run.
 In order to do so, a later registration is needed through the
-.Fn atf_add_test_case
+.Ic atf_add_test_case
 function detailed in
 .Sx Program initialization .
 .Pp
 Later on, one must define the three parts of the body by providing two
 or three functions (remember that the cleanup routine is optional).
 These functions are named after the test case's identifier, and are
-.Fn <id>_head ,
-.Fn <id>_body
+.Ic <id>_head ,
+.Ic <id>_body
 and
-.Fn <id>_cleanup.
+.Ic <id>_cleanup.
 None of these take parameters when executed.
 .Ss Program initialization
 The test program must define an
-.Fn atf_init_test_cases
+.Ic atf_init_test_cases
 function, which is in charge of registering the test cases that will be
 executed at run time by using the
-.Fn atf_add_test_case
+.Ic atf_add_test_case
 function, which takes the name of a test case as its single parameter.
 This main function should not do anything else, except maybe sourcing
-auxiliary source files that define extra variables and functions.
+auxiliary source files that define extra variables and functions,
+or perhaps running simple tests to determine which test cases to add.
 .Ss Configuration variables
 The test case has read-only access to the current configuration variables
 through the
-.Fn atf_config_has
+.Ic atf_config_has
 and
-.Fn atf_config_get
+.Ic atf_config_get
 methods.
 The former takes a single parameter specifying a variable name and returns
 a boolean indicating whether the variable is defined or not.
@@ -170,17 +220,17 @@
 .Ss Access to the source directory
 It is possible to get the path to the test case's source directory from
 anywhere in the test program by using the
-.Fn atf_get_srcdir
+.Ic atf_get_srcdir
 function.
 It is interesting to note that this can be used inside
-.Fn atf_init_test_cases
+.Ic atf_init_test_cases
 to silently include additional helper files from the source directory.
 .Ss Requiring programs
 Aside from the
 .Va require.progs
 meta-data variable available in the header only, one can also check for
 additional programs in the test case's body by using the
-.Fn atf_require_prog
+.Ic atf_require_prog
 function, which takes the base name or full path of a single binary.
 Relative paths are forbidden.
 If it is not found, the test case will be automatically skipped.
@@ -189,10 +239,9 @@
 point the test is assumed to have
 .Em passed ,
 or at any explicit call to
-.Fn atf_pass ,
-.Fn atf_fail
-or
-.Fn atf_skip .
+.Ic atf_pass ,
+.Ic atf_fail
+.Ic atf_skip .
 These three functions terminate the execution of the test case immediately.
 The cleanup routine will be processed afterwards in a completely automated
 way, regardless of the test case's termination reason.
@@ -206,6 +255,7 @@
 was skipped, respectively.
 It is very important to provide a clear error message in both cases so that
 the user can quickly know why the test did not pass.
+This message must be a single line (no embedded newline characers.)
 .Ss Expectations
 Everything explained in the previous section changes when the test case
 expectations are redefined by the programmer.
@@ -215,20 +265,20 @@
 that describes what the test case expectations are at any point in time.
 The value of this property can change during execution by any of:
 .Bl -tag -width indent
-.It Fn atf_expect_death "reason" "..."
+.It Ic atf_expect_death Do reason Dc Dq \&...
 Expects the test case to exit prematurely regardless of the nature of the
 exit.
-.It Fn atf_expect_exit "exitcode" "reason" "..."
+.It Ic atf_expect_exit Do exitcode Dc Do reason Dc Dq \&...
 Expects the test case to exit cleanly.
 If
 .Va exitcode
 is not
-.Sq -1 ,
+.Sq \-1 ,
 .Xr atf-run 1
 will validate that the exit code of the test case matches the one provided
 in this call.
 Otherwise, the exact value will be ignored.
-.It Fn atf_expect_fail "reason"
+.It Ic atf_expect_fail Dq reason
 Any failure raised in this mode is recorded, but such failures do not report
 the test case as failed; instead, the test case finalizes cleanly and is
 reported as
@@ -245,28 +295,28 @@
 reporting a failure, signaling the developer that the test case must be
 adjusted to the new conditions.
 In this situation, it is useful, for example, to set
-.Fa reason
+.Va reason
 as the bug number for tracking purposes.
-.It Fn atf_expect_pass
+.It Ic atf_expect_pass
 This is the normal mode of execution.
 In this mode, any failure is reported as such to the user and the test case
 is marked as
 .Sq failed .
-.It Fn atf_expect_signal "signo" "reason" "..."
+.It Ic atf_expect_signal Do signo Dc Do reason Dc Dq \&...
 Expects the test case to terminate due to the reception of a signal.
 If
 .Va signo
 is not
-.Sq -1 ,
+.Sq \-1 ,
 .Xr atf-run 1
 will validate that the signal that terminated the test case matches the one
 provided in this call.
 Otherwise, the exact value will be ignored.
-.It Fn atf_expect_timeout "reason" "..."
+.It Ic atf_expect_timeout Do reason Dc Dq \&...
 Expects the test case to execute for longer than its timeout.
 .El
 .Ss Helper functions for common checks
-.Fn atf_check [options] command [args]
+.Ic atf_check Oo options Oc command Op args
 .Pp
 This function wraps the execution of the
 .Nm atf-check
@@ -275,7 +325,7 @@
 For more details on the parameters of this function, refer to
 .Xr atf-check 1 .
 .Pp
-.Fn atf_check_equal expr1 expr2
+.Ic atf_check_equal expr1 expr2
 .Pp
 This function takes two expressions, evaluates them and, if their
 results differ, aborts the test case with an appropriate failure message.
--- a/external/bsd/bind/lib/libdns/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/external/bsd/bind/lib/libdns/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2014/03/01 03:24:41 christos Exp $
+#	$NetBSD: Makefile,v 1.13.16.1 2017/05/19 00:22:52 pgoyette Exp $
 
 LIB=dns
 #USE_SHLIBDIR=   yes
@@ -24,9 +24,13 @@
 .endfor
 
 DNSSEC_SRCS=	dst_api.c dst_lib.c dst_parse.c dst_result.c \
-	gssapi_link.c gssapictx.c hmac_link.c key.c openssl_link.c \
+	gssapictx.c hmac_link.c key.c openssl_link.c \
 	openssldh_link.c openssldsa_link.c opensslrsa_link.c \
-	opensslecdsa_link.c opensslgost_link.c spnego.c
+	opensslecdsa_link.c opensslgost_link.c 
+.if ${MKKERBEROS} != "no"
+DNSSEC_SRCS+=	gssapi_link.c spnego.c
+.endif
+
 
 SRCS=	acl.c acache.c adb.c byaddr.c cache.c callbacks.c clientinfo.c \
 	compress.c client.c tsec.c ecdb.c \
--- a/external/cddl/osnet/dist/cmd/dtrace/dtrace.1	Thu May 18 23:52:01 2017 +0000
+++ b/external/cddl/osnet/dist/cmd/dtrace/dtrace.1	Fri May 19 00:22:50 2017 +0000
@@ -18,7 +18,7 @@
 .\"
 .\" CDDL HEADER END
 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
-.TH dtrace 1M "5 Sep 2006" "SunOS 5.11" "System Administration Commands"
+.TH dtrace 1 "5 Sep 2006" "SunOS 5.11" "System Administration Commands"
 .SH NAME
 dtrace \- DTrace dynamic tracing compiler and tracing utility
 .SH SYNOPSIS
@@ -88,7 +88,7 @@
 .SH OPTIONS
 .sp
 .LP
-The arguments accepted by the \fB-P\fR, \fB-m\fR, \fB-f\fR, \fB-n\fR, and \fB-i\fR options can include an optional D language \fIpredicate\fR enclosed in slashes \fB//\fR and optional D language \fIaction\fR statement list enclosed in braces \fB{}\fR. D program code specified on the command line must be appropriately quoted to avoid intepretation of meta-characters by the shell. 
+The arguments accepted by the \fB-P\fR, \fB-m\fR, \fB-f\fR, \fB-n\fR, and \fB-i\fR options can include an optional D language \fIpredicate\fR enclosed in slashes \fB//\fR and optional D language \fIaction\fR statement list enclosed in braces \fB{}\fR. D program code specified on the command line must be appropriately quoted to avoid interpretation of meta-characters by the shell. 
 .sp
 .LP
 The following options are supported:
--- a/external/gpl3/gcc/dist/gcc/auto-profile.c	Thu May 18 23:52:01 2017 +0000
+++ b/external/gpl3/gcc/dist/gcc/auto-profile.c	Fri May 19 00:22:50 2017 +0000
@@ -19,11 +19,11 @@
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
-#include "system.h"
 
 #include <string.h>
 #include <map>
 #include <set>
+#include "system.h"
 
 #include "coretypes.h"
 #include "hash-set.h"
--- a/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c	Thu May 18 23:52:01 2017 +0000
+++ b/external/gpl3/gcc/dist/gcc/graphite-isl-ast-to-gimple.c	Fri May 19 00:22:50 2017 +0000
@@ -38,6 +38,7 @@
 #endif
 #endif
 
+#include <map>
 #include "system.h"
 #include "coretypes.h"
 #include "hash-set.h"
@@ -75,7 +76,6 @@
 #include "tree-scalar-evolution.h"
 #include "gimple-ssa.h"
 #include "tree-into-ssa.h"
-#include <map>
 
 #ifdef HAVE_isl
 #include "graphite-poly.h"
--- a/external/gpl3/gcc/dist/gcc/system.h	Thu May 18 23:52:01 2017 +0000
+++ b/external/gpl3/gcc/dist/gcc/system.h	Fri May 19 00:22:50 2017 +0000
@@ -224,6 +224,7 @@
 #ifdef __cplusplus
 # include <algorithm>
 # include <cstring>
+# include <new>
 # include <utility>
 #endif
 #endif
--- a/lib/libc/gen/assert.c	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/gen/assert.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: assert.c,v 1.17 2012/06/25 22:32:43 abs Exp $	*/
+/*	$NetBSD: assert.c,v 1.17.22.1 2017/05/19 00:22:52 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)assert.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: assert.c,v 1.17 2012/06/25 22:32:43 abs Exp $");
+__RCSID("$NetBSD: assert.c,v 1.17.22.1 2017/05/19 00:22:52 pgoyette Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -44,19 +44,31 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <syslog.h>
+#include "extern.h"
+
+static int
+fmtassert(char *buf, size_t len, const char *file, int line,
+    const char *function, const char *failedexpr)
+{
+	return snprintf_ss(buf, len,
+	    "assertion \"%s\" failed: file \"%s\", line %d%s%s%s\n",
+	    failedexpr, file, line,
+	    function ? ", function \"" : "",
+	    function ? function : "",
+	    function ? "\"" : "");
+}
 
 void
 __assert13(const char *file, int line, const char *function,
     const char *failedexpr)
 {
-
-	(void)fprintf(stderr,
-	    "assertion \"%s\" failed: file \"%s\", line %d%s%s%s\n",
-	    failedexpr, file, line,
-	    function ? ", function \"" : "",
-	    function ? function : "",
-	    function ? "\"" : "");
+	char buf[1024];
+	int l = fmtassert(buf, sizeof(buf), file, line, function, failedexpr);
+	if (l < 0)
+		abort();
+	(void)write(STDERR_FILENO, buf, (size_t)l);
 	abort();
 	/* NOTREACHED */
 }
@@ -113,16 +125,19 @@
 		}
 	}
 
-	snprintf(buf, sizeof(buf),
-	    "assertion \"%s\" failed: file \"%s\", line %d%s%s%s",
-	    failedexpr, file, line,
-	    function ? ", function \"" : "",
-	    function ? function : "",
-	    function ? "\"" : "");
-	if (diagassert_flags & DIAGASSERT_STDERR)
-		(void)fprintf(stderr, "%s: %s\n", getprogname(), buf);
-	if (diagassert_flags & DIAGASSERT_SYSLOG)
-		syslog(LOG_DEBUG | LOG_USER, "%s", buf);
+	fmtassert(buf, sizeof(buf), file, line, function, failedexpr);
+	if (diagassert_flags & DIAGASSERT_STDERR) {
+		char ebuf[1024];
+		int l = snprintf_ss(ebuf, sizeof(ebuf), "%s: %s\n",
+		    getprogname(), buf);
+		if (l == -1)
+			abort();
+		(void)write(STDERR_FILENO, ebuf, (size_t)l);
+	}
+	if (diagassert_flags & DIAGASSERT_SYSLOG) {
+		struct syslog_data sdata = SYSLOG_DATA_INIT;
+		syslog_ss(LOG_DEBUG | LOG_USER, &sdata, "%s", buf);
+	}
 	if (diagassert_flags & DIAGASSERT_ABORT)
 		abort();
 }
--- a/lib/libc/gen/signalname.3	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/gen/signalname.3	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: signalname.3,v 1.1.2.2 2017/05/11 02:58:32 pgoyette Exp $
+.\" $NetBSD: signalname.3,v 1.1.2.3 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Available to all and sundry, without restriction on use, or other
 .\" limitations, and without fee.   Also without any warranty of fitness
@@ -20,8 +20,8 @@
 .Dt SIGNALNAME 3
 .Os
 .Sh NAME
-.Nm signalname
-.Nm signalnumber
+.Nm signalname ,
+.Nm signalnumber ,
 .Nm signalnext
 .Nd convert between signal numbers and names
 .Sh LIBRARY
@@ -43,16 +43,21 @@
 The name returned is locale independent,
 and can be the string representation of one of the
 signal names from
-.In signal.h 
-such as SIGHUP, SIGSTOP, SIGKILL,
+.In signal.h
+such as
+.Dv SIGHUP ,
+.Dv SIGSTOP ,
+.Dv SIGKILL ,
 or some similar name,
 but does not contain the leading
-.Dq SIG
+.Dq Dv SIG
 prefix.
 .Pp
 The return value of
 .Fn signalname
-is NULL if
+is
+.Dv NULL
+if
 .Fa sig
 does not represent a valid signal number,
 or if the signal number given has no name.
@@ -66,7 +71,7 @@
 .Fa name
 is handled in a case-insensitive manner.
 Any leading
-.Dq SIG
+.Dq Dv SIG
 prefix in
 .Fa name
 is ignored.
@@ -90,7 +95,7 @@
 .Fn signalnext
 function returns minus one (\-1) on error, if the given signal
 .Fa sig
-is neither a valid signal number, nor zero.
+is neither a valid signal number nor zero.
 It returns zero when the input signal number,
 .Fa sig ,
 is the biggest available signal number.
@@ -126,7 +131,7 @@
 .Sh HISTORY
 The
 .Fn signalname ,
-.Fn signalnext
+.Fn signalnext ,
 and
 .Fn signalnumber
 functions first appeared in
--- a/lib/libc/sys/execve.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/execve.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: execve.2,v 1.40 2010/05/31 12:16:20 njoly Exp $
+.\"	$NetBSD: execve.2,v 1.40.36.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -220,7 +220,7 @@
 Search permission is denied for a component of the path prefix,
 the new process file is not an ordinary file,
 its file mode denies execute permission, or
-it is on a filesystem mounted with execution
+it is on a file system mounted with execution
 disabled
 .Dv ( MNT_NOEXEC
 in
--- a/lib/libc/sys/getdents.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/getdents.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getdents.2,v 1.24 2016/01/23 08:17:18 dholland Exp $
+.\"	$NetBSD: getdents.2,v 1.24.6.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .Os
 .Sh NAME
 .Nm getdents
-.Nd "get directory entries in a filesystem independent format"
+.Nd "get directory entries in a file system independent format"
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
@@ -48,7 +48,7 @@
 .Fa fd
 into the buffer pointed to by
 .Fa buf ,
-in a filesystem independent format.
+in a file system independent format.
 Up to
 .Fa nbytes
 of data will be transferred.
@@ -57,7 +57,7 @@
 block size associated with the file,
 see
 .Xr stat 2 .
-Some filesystems may not support
+Some file systems may not support
 .Fn getdents
 with buffers smaller than this size.
 .Pp
--- a/lib/libc/sys/intro.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/intro.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: intro.2,v 1.58 2016/11/02 03:21:38 pgoyette Exp $
+.\"	$NetBSD: intro.2,v 1.58.4.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1983, 1986, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -419,7 +419,7 @@
 .It Er 70 ESTALE Em "Stale NFS file handle" .
 An attempt was made to access an open file (on an
 .Tn NFS
-filesystem)
+file system)
 which is now unavailable as referenced by the file descriptor.
 This may indicate the file was deleted on the
 .Tn NFS
@@ -458,11 +458,11 @@
 .It Er 80 EAUTH Em "Authentication error" .
 Attempted to use an invalid authentication ticket to mount an
 .Tn NFS
-filesystem.
+file system.
 .It Er 81 ENEEDAUTH Em "Need authenticator" .
 An authentication ticket must be obtained before the given
 .Tn NFS
-filesystem may be mounted.
+file system may be mounted.
 .It Er 82 EIDRM Em "Identifier removed" .
 An IPC identifier was removed while the current process was waiting on it.
 .It Er 83 ENOMSG Em "No message of the desired type" .
@@ -659,7 +659,7 @@
 .It Sy nfsio , nfskqpoll
 NFS handing daemons.
 .It Sy lfs_writer
-Log filesystem writer.
+Log file system writer.
 .It Sy pagedaemon
 The page daemon.
 .It Sy raidX , raidioX , raid_parity , raid_recon , raid_reconip , raid_copyback
--- a/lib/libc/sys/lfs_markv.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/lfs_markv.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: lfs_markv.2,v 1.11 2008/04/30 13:10:51 martin Exp $
+.\"	$NetBSD: lfs_markv.2,v 1.11.54.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -60,7 +60,7 @@
 .Pp
 The
 .Fa fsidp
-argument contains the id of the filesystem to which the inodes and
+argument contains the id of the file system to which the inodes and
 blocks belong.
 The
 .Fa bi_bp
@@ -103,7 +103,7 @@
 points outside the process's allocated address space.
 .It Bq Er EINVAL
 .Fa *fsidp
-does not specify a valid filesystem.
+does not specify a valid file system.
 .It Bq Er EBUSY
 One or more of the inodes whose blocks were to be written was locked,
 and its blocks were not rewritten.
--- a/lib/libc/sys/lfs_segclean.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/lfs_segclean.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: lfs_segclean.2,v 1.8 2008/04/30 13:10:51 martin Exp $
+.\"	$NetBSD: lfs_segclean.2,v 1.8.54.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -43,7 +43,7 @@
 .Fn lfs_segclean
 marks segment number
 .Fa segment
-in LFS filesystem
+in LFS file system
 .Fa *fsidp
 "clean" or available for writing.
 .Sh RETURN VALUES
@@ -59,7 +59,7 @@
 points outside the process's allocated address space.
 .It Bq Er EINVAL
 .Fa *fsidp
-does not specify a valid filesystem.
+does not specify a valid file system.
 .It Bq Er EBUSY
 .Fa segment
 is marked SU_ACTIVE, meaning that it does not yet belong to a valid checkpoint.
--- a/lib/libc/sys/lfs_segwait.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/lfs_segwait.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: lfs_segwait.2,v 1.8 2008/04/30 13:10:51 martin Exp $
+.\"	$NetBSD: lfs_segwait.2,v 1.8.54.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -41,12 +41,12 @@
 .Fn lfs_segwait "fsid_t *fsidp" "struct timeval *tv"
 .Sh DESCRIPTION
 .Fn lfs_segwait
-blocks until a new segment is acquired for writing by the filesystem
+blocks until a new segment is acquired for writing by the file system
 specified by
 .Fa *fsidp
 or if
 .Fa *fsidp
-is \-1, until a segment is acquired for writing by any LFS filesystem.
+is \-1, until a segment is acquired for writing by any LFS file system.
 .Pp
 If
 .Fa timeout
--- a/lib/libc/sys/mmap.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/mmap.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mmap.2,v 1.48.6.1 2017/05/11 02:58:33 pgoyette Exp $
+.\"	$NetBSD: mmap.2,v 1.48.6.2 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -87,7 +87,9 @@
 .It Dv PROT_NONE
 Placeholder when requesting no access permission.
 .El
-As a NetBSD extension,
+As a
+.Nx
+extension,
 .Dv PROT_MPROTECT
 can be used to request additional permissions for later use with
 .Fn mprotect 2 .
--- a/lib/libc/sys/mount.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/mount.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mount.2,v 1.49 2011/11/18 21:04:21 christos Exp $
+.\"	$NetBSD: mount.2,v 1.49.30.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1989, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -82,12 +82,12 @@
 The file system should be treated as read-only;
 even the super-user may not write on it.
 .It Dv MNT_UNION
-Union with underlying filesystem instead of obscuring it.
+Union with underlying file system instead of obscuring it.
 .It Dv MNT_HIDDEN
 Cause the
 .Xr df 1
 program, and perhaps others, to, by default,
-exclude this filesystem from its output.
+exclude this file system from its output.
 .It Dv MNT_NOEXEC
 Do not allow files to be executed from the file system.
 .It Dv MNT_NOSUID
@@ -109,22 +109,22 @@
 .It Dv MNT_SYNCHRONOUS
 All I/O to the file system should be done synchronously.
 This will slow I/O performance considerably, but
-enhances overall filesystem reliability.
+enhances overall file system reliability.
 .It Dv MNT_ASYNC
 All I/O to the file system should be done asynchronously.
 This vastly improves I/O throughput,
-but at a cost of making the filesystem likely to be
+but at a cost of making the file system likely to be
 completely unrecoverable should the system crash while
 unwritten data is pending in kernel buffers.
 .It Dv MNT_LOG
-Use a filesystem journal.
+Use a file system journal.
 .Dv MNT_LOG
 causes a journal (or log) to be created in the
-filesystem, creating a record of meta-data writes to be
+file system, creating a record of meta-data writes to be
 performed, allowing the actual writes to be deferred.
 This improves performance in most cases.
 .It MNT_EXTATTR
-Enable extended attributes, if the filesystem supports them and
+Enable extended attributes, if the file system supports them and
 does not enable them by default.
 Currently this is only the case for UFS1.
 .El
@@ -141,7 +141,7 @@
 flag allows the mount flags to be changed without requiring
 that the file system be unmounted and remounted.
 A conversion from read-write to read-only will fail if any files
-are currently open for writing on the filesystem, unless the
+are currently open for writing on the file system, unless the
 .Dv MNT_FORCE
 flag is also applied.
 Some file systems may not allow all flags to be changed.
@@ -149,16 +149,16 @@
 some file systems will not allow a change from read-write to read-only.
 The
 .Dv MNT_RELOAD
-flag causes kernel filesystem data to be reloaded from
-the filesystem device.
-It is only permitted on filesystems mounted read-only.
-Its purpose is to notify the system that the filesystem
+flag causes kernel file system data to be reloaded from
+the file system device.
+It is only permitted on file systems mounted read-only.
+Its purpose is to notify the system that the file system
 data has been modified by some external process.
 The
 .Dv MNT_GETARGS
-flag does not alter any of the mounted filesystem's properties,
-but returns the filesystem-specific arguments for the currently mounted
-filesystem.
+flag does not alter any of the mounted file system's properties,
+but returns the file system-specific arguments for the currently mounted
+file system.
 .Pp
 The
 .Fa type
@@ -172,7 +172,7 @@
 .\" .Bd -literal -offset indent
 vfs.generic.fstypes.
 .\" XXX from lite-2:
-.\" The types of filesystems known to the system can be obtained with
+.\" The types of file systems known to the system can be obtained with
 .\" .Xr sysctl 8
 .\" by using the command:
 .\" .Bd -literal -offset indent
@@ -227,13 +227,13 @@
 .Ed
 .\" XXX from lite-2:
 .\" The format for these argument structures is described in the
-.\" manual page for each filesystem.
-.\" By convention filesystem manual pages are named
-.\" by prefixing ``mount_'' to the name of the filesystem as returned by
+.\" manual page for each file system.
+.\" By convention file system manual pages are named
+.\" by prefixing ``mount_'' to the name of the file system as returned by
 .\" .Xr sysctl 8 .
 .\" Thus the
 .\" .Nm NFS
-.\" filesystem is described by the
+.\" file system is described by the
 .\" .Xr mount_nfs 8
 .\" manual page.
 .Pp
@@ -276,7 +276,7 @@
 Another process currently holds a reference to
 .Fa dir ,
 or for an update from read-write to read-only
-there are files on the filesystem open for writes.
+there are files on the file system open for writes.
 .It Bq Er EFAULT
 .Fa dir
 points outside the process's allocated address space.
@@ -428,7 +428,7 @@
 .Nx 4.0
 the
 .Nm
-call was used to export NFS filesystems.
+call was used to export NFS file systems.
 This is now done through
 .Fn nfssvc .
 .Pp
@@ -439,4 +439,4 @@
 .Sh BUGS
 Some of the error codes need translation to more obvious messages.
 .Pp
-Far more filesystems are supported than those those listed.
+Far more file systems are supported than those those listed.
--- a/lib/libc/sys/mprotect.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/mprotect.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mprotect.2,v 1.24.34.1 2017/05/11 02:58:33 pgoyette Exp $
+.\"	$NetBSD: mprotect.2,v 1.24.34.2 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -79,7 +79,7 @@
 .Pp
 The
 .Dv PROT_EXEC
-flag was attempted on pages which belong to a filesystem mounted with the
+flag was attempted on pages which belong to a file system mounted with the
 .Dv NOEXEC
 flag.
 .Pp
--- a/lib/libc/sys/open.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/open.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: open.2,v 1.56 2013/07/29 18:37:16 njoly Exp $
+.\"	$NetBSD: open.2,v 1.56.16.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -263,7 +263,7 @@
 If creating a file with
 .Dv O_CREAT ,
 the request for the lock will never fail
-(provided that the underlying filesystem supports locking).
+(provided that the underlying file system supports locking).
 .Pp
 If
 .Fn open
@@ -392,7 +392,7 @@
 .Dv O_SHLOCK
 or
 .Dv O_EXLOCK
-is specified but the underlying filesystem does not support locking; or
+is specified but the underlying file system does not support locking; or
 an attempt was made to open a socket (not currently implemented).
 .It Bq Er EPERM
 The file's flags (see
--- a/lib/libc/sys/statvfs.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/statvfs.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: statvfs.2,v 1.5 2010/05/31 12:16:20 njoly Exp $
+.\"	$NetBSD: statvfs.2,v 1.5.36.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -82,7 +82,7 @@
 When
 .Dv ST_NOWAIT
 is specified, then only cached statistics are returned.
-This can result in significant savings on non-local filesystems, where
+This can result in significant savings on non-local file systems, where
 gathering statistics involves a network communication.
 .Pp
 The
--- a/lib/libc/sys/sync.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/sync.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sync.2,v 1.17 2009/03/25 06:46:21 wiz Exp $
+.\"	$NetBSD: sync.2,v 1.17.36.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -55,7 +55,7 @@
 ensures that dirty buffers are synced to disk
 eventually.
 By default, a dirty buffer is synced after 30 seconds,
-but some filesystems exploit
+but some file systems exploit
 .Nm ioflush
 features to sync directory data and metadata faster
 (after 15 and 10 seconds, respectively).
--- a/lib/libc/sys/truncate.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/truncate.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: truncate.2,v 1.30 2014/07/25 08:44:54 wiz Exp $
+.\"	$NetBSD: truncate.2,v 1.30.14.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -85,7 +85,7 @@
 .It Bq Er EISDIR
 The named file is a directory.
 .It Bq Er ENOSPC
-There was no space in the filesystem to complete the operation.
+There was no space in the file system to complete the operation.
 .It Bq Er EROFS
 The named file resides on a read-only file system.
 .It Bq Er ETXTBSY
--- a/lib/libc/sys/undelete.2	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libc/sys/undelete.2	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: undelete.2,v 1.16 2014/11/11 08:10:02 njoly Exp $
+.\"	$NetBSD: undelete.2,v 1.16.6.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -76,7 +76,7 @@
 Currently
 .Nm
 works only when the named object
-is a whiteout in a union filesystem.
+is a whiteout in a union file system.
 The system call removes the whiteout causing
 any objects in a lower layer of the
 union stack to become visible once more.
--- a/lib/libcurses/curses.3	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libcurses/curses.3	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: curses.3,v 1.71 2017/01/25 12:42:05 roy Exp $
+.\"	$NetBSD: curses.3,v 1.71.2.1 2017/05/19 00:22:52 pgoyette Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -225,7 +225,7 @@
 .It resetty Ta Xr curses_tty 3
 .It resize_term Ta Xr curses_screen 3
 .It resizeterm Ta Xr curses_screen 3
-.It ripoffline Ta Xr curses_Screen 3
+.It ripoffline Ta Xr curses_screen 3
 .It savetty Ta Xr curses_tty 3
 .It scanw Ta Xr curses_scanw 3
 .It scrl Ta Xr curses_scroll 3
--- a/lib/libm/compat/compat_cabs.c	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libm/compat/compat_cabs.c	Fri May 19 00:22:50 2017 +0000
@@ -7,7 +7,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_cabs.c,v 1.2 2007/08/10 21:20:35 drochner Exp $");
+__RCSID("$NetBSD: compat_cabs.c,v 1.2.62.1 2017/05/19 00:22:53 pgoyette Exp $");
 #endif
 
 #include "../src/namespace.h"
@@ -19,7 +19,7 @@
 };
 
 double cabs(struct complex);
-__warn_references(cabs, "warning: reference to compatibility cabs()");
+__warn_references(cabs, "warning: reference to compatibility cabs()")
 
 double
 cabs(struct complex z)
--- a/lib/libm/compat/compat_cabsf.c	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libm/compat/compat_cabsf.c	Fri May 19 00:22:50 2017 +0000
@@ -7,7 +7,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_cabsf.c,v 1.2 2007/08/10 21:20:35 drochner Exp $");
+__RCSID("$NetBSD: compat_cabsf.c,v 1.2.62.1 2017/05/19 00:22:53 pgoyette Exp $");
 #endif
 
 #include "../src/namespace.h"
@@ -19,7 +19,7 @@
 };
 
 float cabsf __P((struct complex));
-__warn_references(cabsf, "warning: reference to compatibility cabsf()");
+__warn_references(cabsf, "warning: reference to compatibility cabsf()")
 
 float
 cabsf(struct complex z)
--- a/lib/libm/shlib_version	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libm/shlib_version	Fri May 19 00:22:50 2017 +0000
@@ -1,8 +1,8 @@
-#	$NetBSD: shlib_version,v 1.15 2017/01/20 22:10:38 maya Exp $
+#	$NetBSD: shlib_version,v 1.15.2.1 2017/05/19 00:22:53 pgoyette Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 # things we wish to do on next major version bump:
 # - remove compatibility cabs
 # - hide isinff
 major=0
-minor=11
+minor=12
--- a/lib/librumpclient/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/lib/librumpclient/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.11.6.1 2017/05/11 02:58:34 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.11.6.2 2017/05/19 00:22:53 pgoyette Exp $
 #
 
 .PATH:	${.CURDIR}/../../sys/rump/librump/rumpkern
@@ -17,7 +17,7 @@
 LIBDPLIBS+=	${lib} lib
 .endfor
 
-CPPFLAGS+=	-DRUMP_CLIENT -D_KERNTYPES
+CPPFLAGS+=	-DRUMP_CLIENT
 CPPFLAGS+=	-I${.OBJDIR} -I${.CURDIR}
 CPPFLAGS+=	-I${.CURDIR}/../librumpuser
 SRCS=		rumpclient.c
--- a/lib/librumpclient/rumpclient.h	Thu May 18 23:52:01 2017 +0000
+++ b/lib/librumpclient/rumpclient.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpclient.h,v 1.15 2013/01/20 15:23:21 pooka Exp $	*/
+/*	$NetBSD: rumpclient.h,v 1.15.20.1 2017/05/19 00:22:53 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -38,9 +38,12 @@
 #endif /* !__GNUC__ */
 #endif /* !__returns_twice */
 
-#if defined(__sun__) && !defined(RUMP_REGISTER_T)
-#define RUMP_REGISTER_T long
+#if !defined(RUMP_REGISTER_T)
+# define RUMP_REGISTER_T long
+# if !defined(_KERNEL) && !defined(_KMEMUSER) &&  \
+    !defined(_KERNTYPES) && !defined(_STANDALONE)
 typedef RUMP_REGISTER_T register_t;
+# endif
 #endif
 
 struct rumpclient_fork;
--- a/lib/librumphijack/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/lib/librumphijack/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.17.6.1 2017/05/11 02:58:34 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.17.6.2 2017/05/19 00:22:53 pgoyette Exp $
 #
 
 LIB=		rumphijack
@@ -10,7 +10,7 @@
 
 SRCS=		hijack.c hijackdlsym.c
 
-CPPFLAGS+=	-D_DIAGNOSTIC -D_REENTRANT -D_KERNTYPES
+CPPFLAGS+=	-D_DIAGNOSTIC -D_REENTRANT
 
 WARNS?=		5
 
--- a/lib/librumpuser/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/lib/librumpuser/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.24.6.1 2017/05/11 02:58:34 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.24.6.2 2017/05/19 00:22:53 pgoyette Exp $
 #
 
 .include <bsd.own.mk>
@@ -19,7 +19,7 @@
 LIBDO.${lib}=	_external
 LIBDPLIBS+=	${lib} lib
 .endfor
-CPPFLAGS+=	-DLIBRUMPUSER -D_KERNTYPES
+CPPFLAGS+=	-DLIBRUMPUSER
 #CPPFLAGS+=	-D_DIAGNOSTIC
 
 
--- a/lib/librumpuser/rumpuser_port.h	Thu May 18 23:52:01 2017 +0000
+++ b/lib/librumpuser/rumpuser_port.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser_port.h,v 1.48 2017/01/12 18:23:04 christos Exp $	*/
+/*	$NetBSD: rumpuser_port.h,v 1.48.4.1 2017/05/19 00:22:53 pgoyette Exp $	*/
 
 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
@@ -29,7 +29,6 @@
 #define HAVE_PATHS_H 1
 #define HAVE_POSIX_MEMALIGN 1
 #define HAVE_PTHREAD_SETNAME3 1
-#define HAVE_REGISTER_T 1
 #define HAVE_SETPROGNAME 1
 #define HAVE_STDINT_H 1
 #define HAVE_STDLIB_H 1
@@ -47,8 +46,8 @@
 #define HAVE_SYS_SYSCTL_H 1
 #define HAVE_SYS_TYPES_H 1
 #define HAVE_UNISTD_H 1
+#define HAVE_UTIMENSAT 1
 #define HAVE___QUOTACTL 1
-#define HAVE_UTIMENSAT 1
 #define PACKAGE_BUGREPORT "http://rumpkernel.org/"
 #define PACKAGE_NAME "rumpuser-posix"
 #define PACKAGE_STRING "rumpuser-posix 999"
@@ -301,6 +300,7 @@
 #if !defined(HAVE_REGISTER_T) && !defined(RUMP_REGISTER_T)
 #define RUMP_REGISTER_T long
 typedef RUMP_REGISTER_T register_t;
+#define	PRIxREGISTER	"lx"
 #endif
 
 #include <sys/time.h>
--- a/lib/libterminfo/term.c	Thu May 18 23:52:01 2017 +0000
+++ b/lib/libterminfo/term.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.21.2.1 2017/05/11 02:58:34 pgoyette Exp $ */
+/* $NetBSD: term.c,v 1.21.2.2 2017/05/19 00:22:53 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: term.c,v 1.21.2.1 2017/05/11 02:58:34 pgoyette Exp $");
+__RCSID("$NetBSD: term.c,v 1.21.2.2 2017/05/19 00:22:53 pgoyette Exp $");
 
 #include <sys/stat.h>
 
@@ -46,8 +46,7 @@
 
 #define _PATH_TERMINFO		"/usr/share/misc/terminfo"
 
-static char database[PATH_MAX];
-static char pathbuf[PATH_MAX];
+static char __ti_database[PATH_MAX];
 const char *_ti_database;
 
 /* Include a generated list of pre-compiled terminfo descriptions. */
@@ -244,63 +243,86 @@
 }
 
 static int
+_ti_checkname(const char *name, const char *termname, const char *termalias)
+{
+	const char *alias, *s;
+	size_t len, l;
+
+	/* Check terminal name matches. */
+	if (strcmp(termname, name) == 0)
+		return 1;
+
+	/* Check terminal aliases match. */
+	if (termalias == NULL)
+		return 0;
+
+	len = strlen(name);
+	alias = termalias;
+	while (*alias != '\0') {
+		s = strchr(alias, '|');
+		if (s == NULL)
+			l = strlen(alias);
+		else
+			l = (size_t)(s - alias);
+		if (len == l && memcmp(alias, name, l) == 0)
+			return 1;
+		if (s == NULL)
+			break;
+		alias = s + 1;
+	}
+
+	/* No match. */
+	return 0;
+}
+
+static int
 _ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags)
 {
 	struct cdbr *db;
 	const void *data;
-	char *db_name;
 	const uint8_t *data8;
 	size_t len, klen;
 	int r;
 
-	if (asprintf(&db_name, "%s.cdb", path) < 0)
+	if (snprintf(__ti_database, sizeof(__ti_database), "%s.cdb", path) < 0)
 		return -1;
-
-	db = cdbr_open(db_name, CDBR_DEFAULT);
-	free(db_name);
+	db = cdbr_open(__ti_database, CDBR_DEFAULT);
 	if (db == NULL)
 		return -1;
 
+	r = 0;
 	klen = strlen(name) + 1;
 	if (cdbr_find(db, name, klen, &data, &len) == -1)
-		goto fail;
+		goto out;
 	data8 = data;
 	if (len == 0)
-		goto fail;
-	/* Check for alias first, fall through to processing normal entries. */
+		goto out;
+
+	/* If the entry is an alias, load the indexed terminfo description. */
 	if (data8[0] == 2) {
-		if (klen + 7 > len || le16dec(data8 + 5) != klen)
-			goto fail;
-		if (memcmp(data8 + 7, name, klen))
-			goto fail;
 		if (cdbr_get(db, le32dec(data8 + 1), &data, &len))
-			goto fail;
+			goto out;
 		data8 = data;
-		if (data8[0] != 1)
-			goto fail;
-	} else if (data8[0] != 1)
-		goto fail;
-	else if (klen + 3 >= len || le16dec(data8 + 1) != klen)
-		goto fail;
-	else if (memcmp(data8 + 3, name, klen))
-		goto fail;
-
-	strlcpy(database, path, sizeof(database));
-	_ti_database = database;
+	}
 
 	r = _ti_readterm(term, data, len, flags);
+	/* Ensure that this is the right terminfo description. */
+        if (r == 1)
+                r = _ti_checkname(name, term->name, term->_alias);
+	/* Remember the database we read. */
+        if (r == 1)
+                _ti_database = __ti_database;
+
+out:
 	cdbr_close(db);
 	return r;
-
-fail:
-	cdbr_close(db);
-	return 0;
 }
 
 static int
 _ti_dbgettermp(TERMINAL *term, const char *path, const char *name, int flags)
 {
 	const char *p;
+	char pathbuf[PATH_MAX];
 	size_t l;
 	int r, e;
 
@@ -324,46 +346,14 @@
 }
 
 static int
-ticcmp(const TIC *tic, const char *name)
-{
-	char *alias, *s;
-	size_t len, l;
-
-	if (strcmp(tic->name, name) == 0)
-		return 0;
-	if (tic->alias == NULL)
-		return -1;
-
-	len = strlen(name);
-	alias = tic->alias;
-	while (*alias != '\0') {
-		s = strchr(alias, '|');
-		if (s == NULL)
-			l = strlen(alias);
-		else
-			l = (size_t)(s - alias);
-		if (len == l && memcmp(alias, name, l) == 0)
-			return 0;
-		if (s == NULL)
-			break;
-		alias = s + 1;
-	}
-	return 1;
-}
-
-static int
 _ti_findterm(TERMINAL *term, const char *name, int flags)
 {
 	int r;
-	char *c, *e, h[PATH_MAX];
-	TIC *tic;
-	uint8_t *f;
-	ssize_t len;
+	char *c, *e;
 
 	_DIAGASSERT(term != NULL);
 	_DIAGASSERT(name != NULL);
 
-	database[0] = '\0';
 	_ti_database = NULL;
 	r = 0;
 
@@ -384,6 +374,8 @@
 	}
 
 	if (e != NULL) {
+		TIC *tic;
+
 		if (c == NULL)
 			e = strdup(e); /* So we don't destroy env */
 		if (e == NULL)
@@ -393,7 +385,12 @@
 			    TIC_ALIAS | TIC_DESCRIPTION | TIC_EXTRA);
 			free(e);
 		}
-		if (tic != NULL && ticcmp(tic, name) == 0) {
+		if (tic != NULL &&
+		    _ti_checkname(name, tic->name, tic->alias) == 1)
+		{
+			uint8_t *f;
+			ssize_t len;
+
 			len = _ti_flatten(&f, tic);
 			if (len != -1) {
 				r = _ti_readterm(term, (char *)f, (size_t)len,
@@ -415,8 +412,10 @@
 		return _ti_dbgettermp(term, e, name, flags);
 
 	if ((e = getenv("HOME")) != NULL) {
-		snprintf(h, sizeof(h), "%s/.terminfo", e);
-		r = _ti_dbgetterm(term, h, name, flags);
+		char homepath[PATH_MAX];
+
+		if (snprintf(homepath, sizeof(homepath), "%s/.terminfo", e) > 0)
+			r = _ti_dbgetterm(term, homepath, name, flags);
 	}
 	if (r != 1)
 		r = _ti_dbgettermp(term, _PATH_TERMINFO, name, flags);
--- a/regress/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/regress/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,6 +1,5 @@
-#	$NetBSD: Makefile,v 1.19 2010/07/18 12:44:38 jmmv Exp $
+#	$NetBSD: Makefile,v 1.19.36.1 2017/05/19 00:22:53 pgoyette Exp $
 
-# missing: libexec sbin usr.sbin share
-SUBDIR+= lib libexec sys usr.bin
+SUBDIR+= lib libexec sys
 
 .include <bsd.subdir.mk>
--- a/regress/sys/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/regress/sys/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,17 +1,14 @@
-#	$NetBSD: Makefile,v 1.12 2005/12/14 23:56:45 rpaulo Exp $
+#	$NetBSD: Makefile,v 1.12.74.1 2017/05/19 00:22:53 pgoyette Exp $
 
 .include <bsd.own.mk>
 
-SUBDIR= kern fs uvm net
+SUBDIR= kern
 .if exists(arch/${MACHINE}/Makefile)
 SUBDIR+= arch/${MACHINE}
 .endif
 .if exists(arch/${MACHINE_ARCH}/Makefile)
 SUBDIR+= arch/${MACHINE_ARCH}
 .endif
-.if ${MKCRYPTO} != "no"
-SUBDIR+=	crypto
-.endif
 
 SUBDIR := ${SUBDIR:O:u}
 
--- a/regress/sys/crypto/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2002/02/27 02:21:08 itojun Exp $
-#	$KAME: Makefile,v 1.4 2000/11/01 14:55:39 itojun Exp $
-
-SUBDIR=	des blowfish cast128 rijndael
-.if ${MACHINE_ARCH} == "i386"
-SUBDIR+=	des_asm blowfish_asm
-.endif
-
-TARGETS+=	benchmark
-.PHONY:		benchmark
-
-.include <bsd.subdir.mk>
--- a/regress/sys/crypto/Makefile.inc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#	$NetBSD: Makefile.inc,v 1.8 2011/05/14 16:26:23 christos Exp $
-#	$KAME: Makefile.inc,v 1.3 2000/11/08 05:58:24 itojun Exp $
-
-.if !target(regress)
-.include <bsd.own.mk>
-
-SYSDIR=	${NETBSDSRCDIR}/sys
-WARNS?=	4
-
-regress:
-	@./${PROG}
-
-BENCHROUNDS?=	10000
-
-benchmark:
-	@time ./${PROG} ${BENCHROUNDS}
-.endif
-
-# do not install regression test programs
-proginstall::
--- a/regress/sys/crypto/blowfish/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#	$NetBSD: Makefile,v 1.5 2002/09/18 05:41:51 lukem Exp $
-#	$KAME: Makefile,v 1.5 2000/11/08 05:58:24 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		bftest
-SRCS=		bftest.c bf_enc.c bf_skey.c
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR}
-.PATH:		${SYSDIR}/crypto/blowfish
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/blowfish/bftest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,209 +0,0 @@
-/*	$NetBSD: bftest.c,v 1.6 2011/05/14 16:26:23 christos Exp $	*/
-/*	$KAME: bftest.c,v 1.3 2000/11/08 05:58:24 itojun Exp $	*/
-
-/*
- * Copyright (C) 2000 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <crypto/blowfish/blowfish.h>
-
-static const char *bf_key[2]={
-	"abcdefghijklmnopqrstuvwxyz",
-	"Who is John Galt?"
-};
-
-/* big endian */
-static const char *bf_plain[2] = {
-	"424c4f5746495348", "fedcba9876543210"
-};
-
-static const char *bf_cipher[2] = {
-	"324ed0fef413a203", "cc91732b8022f684"
-};
-
-static void hex2bin(u_int8_t *, const char *);
-static const char *pt(u_int8_t *);
-int main(int, char **);
-
-static void
-hex2bin(p, s)
-	u_int8_t *p;
-	const char *s;
-{
-	int i;
-	u_int v;
-
-	for (i = 0; i < 8; i++) {
-		sscanf(s, "%02x", &v);
-		*p++ = v & 0xff;
-		s += 2;
-	}
-}
-
-static const char *
-pt(p)
-	u_int8_t *p;
-{
-	static char bufs[10][20];
-	static int bnum = 0;
-	char *ret;
-	int i;
-
-	ret = bufs[bnum++];
-	bnum %= 10;
-	for (i = 0; i < 8; i++)
-		snprintf(&ret[i * 2], 3, "%02x", p[i]);
-	ret[8 * 2] = '\0';
-	return(ret);
-}
-
-int
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	int n, error = 0;
-	BF_KEY key;
-	BF_LONG data[2], plain[2], cipher[2]; 
-	int rounds;
-
-	if (argc > 1)
-		rounds = atoi(argv[1]);
-	else
-		rounds = 1;
-
-	printf("testing blowfish in raw ecb mode\n");
-again:
-	for (n = 0; n < 2; n++) {
-		BF_set_key(&key, strlen(bf_key[n]),
-		    (const unsigned char *)bf_key[n]);
-
-		hex2bin((u_int8_t *)plain, bf_plain[n]);
-		hex2bin((u_int8_t *)cipher, bf_cipher[n]);
-
-		memcpy(data, plain, 8);
-
-		data[0] = (BF_LONG)ntohl(data[0]);
-		data[1] = (BF_LONG)ntohl(data[1]);
-		BF_encrypt(data, &key);
-		data[0] = (BF_LONG)htonl(data[0]);
-		data[1] = (BF_LONG)htonl(data[1]);
-		if (memcmp(data, cipher, 8) != 0) {
-			printf("BF_encrypt error encrypting\n");
-			printf("got     : %s", pt((u_int8_t *)data));
-			printf("\n");
-			printf("expected: %s", pt((u_int8_t *)cipher));
-			error = 1;
-			printf("\n");
-		}
-
-		data[0] = (BF_LONG)ntohl(data[0]);
-		data[1] = (BF_LONG)ntohl(data[1]);
-		BF_decrypt(data, &key);
-		data[0] = (BF_LONG)htonl(data[0]);
-		data[1] = (BF_LONG)htonl(data[1]);
-		if (memcmp(data, plain, 8) != 0) {
-			printf("BF_encrypt error decrypting\n");
-			printf("got     : %s", pt((u_int8_t *)data));
-			printf("\n");
-			printf("expected: %s", pt((u_int8_t *)plain));
-			printf("\n");
-			error = 1;
-		}
-	}
-
-	if (--rounds > 0)
-		goto again;
-
-	exit(error);
-}
--- a/regress/sys/crypto/blowfish_asm/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2002/09/18 05:41:51 lukem Exp $
-#	$KAME: Makefile,v 1.5 2000/11/08 05:58:24 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		bftest
-SRCS=		bftest.c bf_enc.S bf_skey.c
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR} -I${SYSDIR}/arch
-.PATH:		${.CURDIR}/../blowfish ${SYSDIR}/crypto/blowfish \
-		${SYSDIR}/crypto/blowfish/arch/${MACHINE_ARCH}
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/cast128/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#	$NetBSD: Makefile,v 1.5 2002/09/18 05:41:51 lukem Exp $
-#	$KAME: Makefile,v 1.4 2000/11/08 05:58:25 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		casttest
-SRCS=		casttest.c cast128.c
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR}
-.PATH:		${SYSDIR}/crypto/cast128
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/cast128/casttest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,205 +0,0 @@
-/*	$NetBSD: casttest.c,v 1.6 2005/02/06 06:05:19 perry Exp $	*/
-/*	$KAME: casttest.c,v 1.5 2001/11/28 03:14:03 itojun Exp $	*/
-
-/*
- * Copyright (C) 2000 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <crypto/cast128/cast128.h>
-
-static unsigned char k[16]={
-	0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
-	0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
-};
-
-static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
-
-static int k_len[3]={16,10,5};
-static unsigned char c[3][8]={
-	{0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
-	{0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
-	{0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
-};
-static unsigned char out[80];
-
-#if 0
-static unsigned char in_a[16]={
-	0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
-	0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
-static unsigned char in_b[16]={
-	0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
-	0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
-
-static unsigned char c_a[16]={
-	0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
-	0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
-static unsigned char c_b[16]={
-	0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
-	0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
-#endif
-
-int main(int, char **);
-int test1(int);
-
-int
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	int error;
-	int rounds;
-
-	if (argc > 1)
-		rounds = atoi(argv[1]);
-	else
-		rounds = 1;
-	error = test1(rounds);
-	if (!error)
-		printf("ecb cast5 ok\n");
-	exit(error);
-}
-
-int
-test1(rounds)
-	int rounds;
-{
-	cast128_key subkey;
-	int i, z, error = 0;
-
-again:
-
-	for (z = 0; z < 3; z++) {
-#if 0
-		if (k_len[z] != 16)
-			continue;
-#endif
-
-		cast128_setkey(&subkey, k, k_len[z]);
-
-		subkey.rounds = (k_len[z] * 8 <= 80) ? 12 : 16;
-		cast128_encrypt(&subkey, in, out);
-
-		if (memcmp(out, c[z], 8) != 0) {
-			printf("ecb cast error encrypting for keysize %d\n",
-			    k_len[z] * 8);
-			printf("got     :");
-			for (i = 0; i < 8; i++)
-				printf("%02X ", out[i]);
-			printf("\n");
-			printf("expected:");
-			for (i = 0; i < 8; i++)
-				printf("%02X ", c[z][i]);
-			error = 20;
-			printf("\n");
-		}
-
-		cast128_decrypt(&subkey, out, out);
-		if (memcmp(out, in, 8) != 0) {
-			printf("ecb cast error decrypting for keysize %d\n",
-			    k_len[z] * 8);
-			printf("got     :");
-			for (i = 0; i < 8; i++)
-				printf("%02X ", out[i]);
-			printf("\n");
-			printf("expected:");
-			for (i = 0; i < 8; i++)
-				printf("%02X ", in[i]);
-			printf("\n");
-			error = 3;
-		}
-	}
-
-	if (--rounds > 0)
-		goto again;
-
-	return error;
-}
--- a/regress/sys/crypto/des/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#	$NetBSD: Makefile,v 1.6 2002/09/18 05:41:52 lukem Exp $
-#	$KAME: Makefile,v 1.5 2000/11/08 05:58:25 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		destest
-SRCS=		destest.c des_ecb.c des_enc.c des_setkey.c
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR}
-.PATH:		${SYSDIR}/crypto/des
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/des/destest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,273 +0,0 @@
-/*	$NetBSD: destest.c,v 1.3 2005/02/06 06:05:19 perry Exp $	*/
-/*	$KAME: destest.c,v 1.3 2000/11/08 05:58:25 itojun Exp $	*/
-
-/*
- * Copyright (C) 2000 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- * 
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to.  The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- * 
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- * 
- * 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 copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *    "This product includes cryptographic software written by
- *     Eric Young (eay@cryptsoft.com)"
- *    The word 'cryptographic' can be left out if the rouines from the library
- *    being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from 
- *    the apps directory (application code) you must include an acknowledgement:
- *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- * 
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
- * 
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed.  i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <crypto/des/des.h>
-
-#define NUM_TESTS 34
-static unsigned char key_data[NUM_TESTS][8]={
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
-	{0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
-	{0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
-	{0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
-	{0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
-	{0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
-	{0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
-	{0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
-	{0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
-	{0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
-	{0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
-	{0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
-	{0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
-	{0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
-	{0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
-	{0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
-	{0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
-	{0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
-	{0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
-	{0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
-	{0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
-	{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
-	{0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
-	{0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
-
-static unsigned char plain_data[NUM_TESTS][8]={
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
-	{0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
-	{0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
-	{0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
-	{0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
-	{0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
-	{0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
-	{0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
-	{0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
-	{0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
-	{0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
-	{0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
-	{0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
-	{0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
-	{0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
-	{0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
-	{0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
-	{0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
-	{0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
-	{0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
-	{0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
-	{0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
-	{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
-	{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
-
-static unsigned char cipher_data[NUM_TESTS][8]={
-	{0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
-	{0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
-	{0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
-	{0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
-	{0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
-	{0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
-	{0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
-	{0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
-	{0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
-	{0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
-	{0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
-	{0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
-	{0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
-	{0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
-	{0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
-	{0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
-	{0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
-	{0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
-	{0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
-	{0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
-	{0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
-	{0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
-	{0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
-	{0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
-	{0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
-	{0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
-	{0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
-	{0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
-	{0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
-	{0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
-	{0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
-	{0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
-	{0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
-	{0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
-
-
-static const char *pt(unsigned char *);
-int main(int, char **);
-
-static const char *
-pt(p)
-	unsigned char *p;
-{
-	static char bufs[10][20];
-	static int bnum = 0;
-	char *ret;
-	int i;
-
-	ret = bufs[bnum++];
-	bnum %= 10;
-	for (i = 0; i < 8; i++)
-		snprintf(&ret[i * 2], 3, "%02x", p[i]);
-	ret[8 * 2] = '\0';
-	return(ret);
-}
-
-int
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	des_key_schedule ks;
-	des_cblock in, out, outin;
-	int i;
-	int error = 0;
-	int rounds;
-
-	if (argc > 1)
-		rounds = atoi(argv[1]);
-	else
-		rounds = 1;
-
-	printf("Doing DES ecb\n");
-
-again:
-	for (i = 0; i < NUM_TESTS - 1; i++) {
-		des_set_key(&key_data[i], ks);
-		memcpy(in, plain_data[i],8);
-		memset(out, 0, 8);
-		memset(outin, 0, 8);
-		des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
-		des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);
-
-		if (memcmp(out, cipher_data[i], 8) != 0) {
-			printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n", 
-			    i + 1, pt(key_data[i]), pt(in), pt(cipher_data[i]), 
-			    pt(out));
-			error = 1;
-		}
-		if (memcmp(in, outin, 8) != 0) {
-			printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n", 
-			    i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
-			error = 1;
-		}
-	}
-
-	if (--rounds > 0)
-		goto again;
-
-	exit(error);
-}
--- a/regress/sys/crypto/des_asm/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#	$NetBSD: Makefile,v 1.4 2016/08/14 19:05:24 joerg Exp $
-#	$KAME: Makefile,v 1.5 2000/11/08 05:58:25 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		destest
-SRCS=		destest.c des_ecb.c des_enc.S des_setkey.c
-
-NOPIE=		yes
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR} -I${SYSDIR}/arch
-.PATH:		${.CURDIR}/../des ${SYSDIR}/crypto/des \
-		${SYSDIR}/crypto/des/arch/${MACHINE_ARCH}
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/rijndael/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-#	$NetBSD: Makefile,v 1.6 2002/09/18 05:41:52 lukem Exp $
-#	$KAME: Makefile,v 1.4 2000/11/08 05:58:26 itojun Exp $
-
-NOMAN=		# defined
-
-PROG=		rijndaeltest
-SRCS=		rijndaeltest.c rijndael-alg-fst.c rijndael-api-fst.c
-
-.include "../Makefile.inc"
-.include <bsd.own.mk>
-
-CPPFLAGS+=	-I${SYSDIR} "-Dpanic(x)=abort()"
-.PATH:		${SYSDIR}/crypto/rijndael
-
-BENCHROUNDS=	100
-
-.include <bsd.prog.mk>
--- a/regress/sys/crypto/rijndael/rijndaeltest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-/*	$NetBSD: rijndaeltest.c,v 1.8 2011/05/14 16:26:23 christos Exp $	*/
-/*	$KAME: rijndaeltest.c,v 1.7 2001/05/27 01:56:45 itojun Exp $	*/
-
-/*
- * Copyright (C) 2000 WIDE Project.
- * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <err.h>
-
-#include <crypto/rijndael/rijndael.h>
-#include <crypto/rijndael/rijndael-api-fst.h>
-
-/* decrypt test */
-struct {
-	const char *key;
-	const char *ct;
-	const char *pt;
-} dvector[] = {
-    {
-	"00000000000000000000000000000000",
-	"00000000000000000000000000000000",
-	"44416AC2D1F53C583303917E6BE9EBE0",
-    },
-    {
-	"DE11FF0A429E1CD3DE016DAC294F771187463793E21C29525A3B282CDCAD6270",
-	"E1268BA8A1473DEDE6CA64DDF2C8B805",
-	"4DE0C6DF7CB1697284604D60271BC59A",
-    },
-    {
-	NULL, NULL, NULL,
-    },
-};
-
-/* encrypt test */
-struct {
-	const char *key;
-	const char *pt;
-	const char *ct;
-} evector[] = {
-    {
-	"00000000000000000000000000000000",
-	"00000000000000000000000000000000",
-	"C34C052CC0DA8D73451AFE5F03BE297F",
-    },
-    {
-	"982D617A0F737342E99123A5A573D266F4961915B32DCA4118AD5CF1DCB6ED00",
-	"6F8606BBA6CC03A5D0A64FE21E277B60",
-	"1F6763DF807A7E70960D4CD3118E601A",
-    },
-    {
-	NULL, NULL, NULL,
-    },
-};
-
-static void hex2key(u_int8_t *, size_t, const char *);
-int main(int, char **);
-
-static void
-hex2key(p, l, s)
-	u_int8_t *p;
-	size_t l;
-	const char *s;
-{
-	size_t i;
-	u_int v;
-
-	for (i = 0; i < l && *s; i++) {
-		sscanf(s, "%02x", &v);
-		*p++ = v & 0xff;
-		s += 2;
-	}
-
-	if (*s) {
-		errx(1, "hex2key overrun");
-		/*NOTREACHED*/
-	}
-}
-
-int
-main(argc, argv)
-	int argc;
-	char **argv;
-{
-	int i, j;
-	keyInstance k;
-	cipherInstance c;
-	int error;
-	const char *test;
-	u_int8_t key[32], input[16], output[16], answer[16];
-	int nrounds, rounds;
-
-	if (argc > 1)
-		nrounds = atoi(argv[1]);
-	else
-		nrounds = 1;
-
-	error = 0;
-
-	rounds = nrounds;
-again1:
-	test = "decrypt test";
-	for (i = 0; dvector[i].key; i++) {
-		hex2key(key, sizeof(key), dvector[i].key);
-		hex2key(input, sizeof(input), dvector[i].ct);
-		memset(output, 0, sizeof(output));
-		hex2key(answer, sizeof(answer), dvector[i].pt);
-
-		/* LINTED const cast */
-		if (rijndael_makeKey(&k, DIR_DECRYPT,
-		    strlen(dvector[i].key) * 4, (char *)key) < 0) {
-			printf("makeKey failed for %s %d\n", test, i);
-			error++;
-			continue;
-		}
-		if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0) {
-			printf("cipherInit failed for %s %d\n", test, i);
-			error++;
-			continue;
-		}
-
-		for (j = 0; j < 10000; j++) {
-			if (rijndael_blockDecrypt(&c, &k, input,
-			    sizeof(input) * 8, output) < 0) {
-				printf("blockDecrypt failed for %s %d/%d\n",
-				    test, i, j);
-				error++;
-				goto next1;
-			}
-
-			memcpy(input, output, sizeof(input));
-		}
-
-		if (memcmp(output, answer, sizeof(output)) != 0) {
-			printf("result mismatch for %s %d\n", test, i);
-			error++;
-		}
-
-		if (nrounds == 1)
-			printf("%s %d successful\n", test, i);
-next1:;
-	}
-	if (--rounds)
-		goto again1;
-
-	rounds = nrounds;
-again2:
-	test = "encrypt test";
-	for (i = 0; evector[i].key; i++) {
-		hex2key(key, sizeof(key), evector[i].key);
-		hex2key(input, sizeof(input), evector[i].pt);
-		memset(output, 0, sizeof(output));
-		hex2key(answer, sizeof(answer), evector[i].ct);
-
-		/* LINTED const cast */
-		if (rijndael_makeKey(&k, DIR_ENCRYPT,
-		    strlen(evector[i].key) * 4, (char *)key) < 0) {
-			printf("makeKey failed for %s %d\n", test, i);
-			error++;
-			continue;
-		}
-		if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0) {
-			printf("cipherInit failed for %s %d\n", test, i);
-			error++;
-			continue;
-		}
-
-		for (j = 0; j < 10000; j++) {
-			if (rijndael_blockEncrypt(&c, &k, input,
-			    sizeof(input) * 8, output) < 0) {
-				printf("blockEncrypt failed for %s %d/%d\n",
-				    test, i, j);
-				error++;
-				goto next2;
-			}
-
-			memcpy(input, output, sizeof(input));
-		}
-
-		if (memcmp(output, answer, sizeof(output)) != 0) {
-			printf("result mismatch for %s %d\n", test, i);
-			error++;
-			continue;
-		}
-
-		if (nrounds == 1)
-			printf("%s %d successful\n", test, i);
-next2:;
-	}
-	if (--rounds)
-		goto again2;
-
-	exit(error);
-}
--- a/regress/sys/fs/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/regress/sys/fs/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,5 +1,5 @@
-#	$NetBSD: Makefile,v 1.8 2009/02/20 21:45:47 jmmv Exp $
+#	$NetBSD: Makefile,v 1.8.36.1 2017/05/19 00:22:54 pgoyette Exp $
 
-SUBDIR= getdents lseek
+SUBDIR= lseek
 
 .include <bsd.subdir.mk>
--- a/regress/sys/fs/getdents/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#	$NetBSD: Makefile,v 1.1 2004/10/03 12:35:15 yamt Exp $
-
-NOMAN=	# defined
-WARNS=	3
-
-PROG=	getdents
-
-TESTDIR= test
-
-clean:
-	rm -rf ${TESTDIR}
-
-regress: ${PROG}
-	@set -e;					\
-	test -d ${TESTDIR} || mkdir ${TESTDIR};		\
-	for x in $$(jot 1000); do			\
-		touch ${TESTDIR}/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX$$x; \
-	done;						\
-	if ./${PROG} ${TESTDIR} > /dev/null; then	\
-		echo PASSED; exit 0;			\
-	else						\
-		echo FAILED; exit 1;			\
-	fi
-
-.include <bsd.prog.mk>
--- a/regress/sys/fs/getdents/getdents.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,226 +0,0 @@
-/*	$Id: getdents.c,v 1.9 2006/12/30 23:19:11 yamt Exp $	*/
-
-/*-
- * Copyright (c)2004, 2006 YAMAMOTO Takashi,
- * 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.
- */
-
-#include <err.h>
-#include <errno.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-void print_dents(FILE *, const void *, int);
-int main(int, char *[]);
-
-void
-print_dents(FILE *fp, const void *vp, int sz)
-{
-	const char *cp = vp;
-	const char *ep = cp + sz;
-	const struct dirent *d;
-
-	while (cp < ep) {
-		d = (const void *)cp;
-		fprintf(fp, "fileno=%" PRIu64
-		    ", type=%d, reclen=%d, len=%d, %s\n",
-		    (uint64_t)d->d_fileno, (int)d->d_type, (int)d->d_reclen,
-		    (int)d->d_namlen, d->d_name);
-		cp += d->d_reclen;
-	}
-#if 1
-	{
-		int i;
-
-		for (cp = vp, i = 0; cp < ep; cp++, i++) {
-			if ((i % 16) == 0)
-				fprintf(fp, "%08tx:", cp - (const char *)vp);
-			fprintf(fp, "%02x ", (int)(unsigned char)*cp);
-			if ((i % 16) == 15)
-				fprintf(fp, "\n");
-		}
-	}
-#endif
-}
-
-struct ent {
-	off_t off;
-	int sz;
-	union {
-		struct dirent u_d;
-		char u_buf[DIRBLKSIZ];
-	} u;
-};
-
-int
-main(int argc, char *argv[])
-{
-	int fd;
-	off_t off;
-	int ret;
-	const char *path;
-	int nblks = 0;
-	struct ent *blks = NULL;
-	int i;
-	int count;
-
-	if (argc < 2)
-		errx(EXIT_FAILURE, "arg");
-	path = argv[1];
-	if (argc > 2)
-		off = strtoull(argv[2], 0, 0);
-	else
-		off = 0;
-
-	printf("dir=%s\n", path);
-	fd = open(path, O_RDONLY);
-	if (fd == -1)
-		err(EXIT_FAILURE, "open");
-	printf("seek: off=%" PRIx64 "(%" PRIu64 ")\n",
-	    (uint64_t)off, (uint64_t)off);
-	if (off != lseek(fd, off, SEEK_SET))
-		err(EXIT_FAILURE, "lseek");
-
-#if defined(DENSE_DIRECTORY)
-	printf("searching valid offsets..\n");
-	for (off = 0; ; off++) {
-		struct ent *p;
-		blks = realloc(blks, sizeof(*blks) * (nblks + 1));
-		if (blks == NULL)
-			err(EXIT_FAILURE, "realloc");
-		p = &blks[nblks];
-		memset(p, 0, sizeof(*p));
-		p->off = off = lseek(fd, off, SEEK_SET);
-		if (off == (off_t)-1)
-			err(EXIT_FAILURE, "lseek");
-		printf("off=%" PRIx64 "(%" PRIu64 ")\n",
-		    (uint64_t)off, (uint64_t)off);
-		p->sz = ret = getdents(fd, p->u.u_buf, DIRBLKSIZ);
-		printf("getdents: %d\n", ret);
-		if (ret == -1) {
-			if (errno == EINVAL) {
-				continue;
-			}
-			errx(EXIT_FAILURE, "getdents");
-		}
-		if (ret == 0) {
-			break;
-		}
-		nblks++;
-		print_dents(stdout, p->u.u_buf, ret);
-	}
-	printf("%d valid offsets found\n", nblks);
-#else /* defined(DENSE_DIRECTORY) */
-	printf("start reading..\n");
-	do {
-		struct ent *p;
-		blks = realloc(blks, sizeof(*blks) * (nblks + 1));
-		if (blks == NULL)
-			err(EXIT_FAILURE, "realloc");
-		p = &blks[nblks];
-		memset(p, 0, sizeof(*p));
-		p->off = off = lseek(fd, (off_t)0, SEEK_CUR);
-		if (off == (off_t)-1)
-			err(EXIT_FAILURE, "lseek");
-		printf("off=%" PRIx64 "(%" PRIu64 ")\n",
-		    (uint64_t)off, (uint64_t)off);
-		p->sz = ret = getdents(fd, p->u.u_buf, DIRBLKSIZ);
-		printf("getdents: %d\n", ret);
-		if (ret == -1)
-			err(EXIT_FAILURE, "getdents");
-		nblks++;
-		print_dents(stdout, p->u.u_buf, ret);
-	} while (ret > 0);
-	printf("%d blks read\n", nblks);
-#endif /* defined(DENSE_DIRECTORY) */
-
-#if 1
-	printf("re-open the file\n");
-	if (close(fd))
-		err(EXIT_FAILURE, "close");
-	fd = open(path, O_RDONLY);
-	if (fd == -1)
-		err(EXIT_FAILURE, "open");
-#endif
-
-	printf("starting random read...\n");
-	for (count = nblks * 4 + 10; count; count--) {
-		char buf[DIRBLKSIZ];
-		struct ent *p;
-		int differ = 0;
-
-		i = rand() % nblks;
-		p = &blks[i];
-		off = lseek(fd, p->off, SEEK_SET);
-		if (off == (off_t)-1)
-			err(1, "seek");
-		printf("off=%" PRIx64 "(%" PRIu64 ")\n",
-		    (uint64_t)off, (uint64_t)off);
-		ret = getdents(fd, buf, DIRBLKSIZ);
-		printf("getdents: %d\n", ret);
-		if (ret == -1)
-			err(EXIT_FAILURE, "getdents");
-		if (p->sz != ret) {
-			fflush(NULL);
-			fprintf(stderr, "off=%" PRIx64
-			    ": different sz %d != %d\n",
-			    (uint64_t)off, p->sz, ret);
-			differ = 1;
-		} else if (memcmp(p->u.u_buf, buf, (size_t)ret)) {
-			fflush(NULL);
-			fprintf(stderr, "off=%" PRIx64 ": different data\n",
-			    (uint64_t)off);
-			fprintf(stderr, "previous:\n");
-			print_dents(stderr, p->u.u_buf, p->sz);
-			fprintf(stderr, "now:\n");
-			print_dents(stderr, buf, ret);
-			differ = 1;
-		}
-		if (differ) {
-			const struct dirent *d1 = (void *)p->u.u_buf;
-			const struct dirent *d2 = (void *)buf;
-
-			if (p->sz == 0 || ret == 0 ||
-			    d1->d_fileno != d2->d_fileno ||
-#if defined(DT_UNKNOWN)
-			    (d1->d_type != DT_UNKNOWN &&
-			     d2->d_type != DT_UNKNOWN &&
-			     d1->d_type != d2->d_type) ||
-#endif /* defined(DT_UNKNOWN) */
-			    d1->d_namlen != d2->d_namlen ||
-			    memcmp(d1->d_name, d2->d_name, d1->d_namlen)) {
-				fprintf(stderr, "fatal difference\n");
-				exit(EXIT_FAILURE);
-			}
-		}
-	}
-
-	exit(EXIT_SUCCESS);
-	/* NOTREACHED */
-}
--- a/regress/sys/fs/lseek/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2006/09/21 17:33:08 reinoud Exp $
-
-NOMAN=	# defined
-
-PROG=	lseek
-
-clean:
-	rm -f test-file
-
-regress: ${PROG}
-	@set -e; \
-	dd if=/dev/zero of=test-file bs=2k count=1000 > /dev/null 2>&1; \
-	if ./${PROG} test-file > /dev/null; then \
-		echo PASSED; exit 0; \
-	else \
-		echo FAILED; exit 1; \
-	fi
-
-.include <bsd.prog.mk>
--- a/regress/sys/fs/lseek/lseek.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <err.h>
-#include <sys/stat.h>
-#include <sys/unistd.h>
-#include <sys/inttypes.h>
-
-int main(int argc, char **argv)
-{
-	int fd;
-	off_t cur;
-	struct stat st;
-	int error;
-
-	if (argc != 2)
-		errx(EXIT_FAILURE, "seektest filename");
-	fd = open(argv[1], 0, O_RDONLY);
-	if (fd <= 0)
-		err(EXIT_FAILURE, "can't open `%s'", argv[1]);
-
-	printf("Statting file\n");
-	error = fstat(fd, &st);
-	if (error)
-		err(EXIT_FAILURE, "can't stat file");
-	printf("fstat() returns %"PRIi64" as size\n", st.st_size);
-
-	error = stat(argv[1], &st);
-	if (error)
-		err(EXIT_FAILURE, "can't stat file");
-	printf("stat()  returns %"PRIi64" as size\n", st.st_size);
-
-	error = lstat(argv[1], &st);
-	if (error)
-		err(EXIT_FAILURE, "can't lstat file");
-	printf("lstat() returns %"PRIi64" as size\n", st.st_size);
-
-	printf("\nTesting normal seeking\n");
-	printf("get initial position\n");
-	cur = lseek(fd, 0, SEEK_CUR);
-	if (cur != 0)
-		err(EXIT_FAILURE, "seek initial position wrong");
-	printf("seek start %"PRIi64"\n", cur);
-
-	printf("seeking end (filesize = %"PRIi64")\n", st.st_size);
-	cur = lseek(fd, 0, SEEK_END);
-	if (cur != st.st_size)
-		err(EXIT_FAILURE, "seek to the end went wrong");
-	printf("seek now %"PRIi64"\n", cur);
-
-	printf("seeking backwards filesize - 150 steps\n");
-	cur = lseek(fd, -(st.st_size - 150), SEEK_CUR);
-	if (cur != 150)
-		err(EXIT_FAILURE, "relative seek from end to 150 failed");
-	printf("seek now %"PRIi64"\n", cur);
-
-	printf("seek set 1000\n");
-	cur = lseek(fd, 1000, SEEK_SET);
-	if (cur != 1000)
-		err(EXIT_FAILURE, "seek 1000 went wrong");
-	printf("seek now %"PRIi64"\n", cur);
-
-#if defined SEEK_DATA
-	printf("\nOne piece non sparse file checking:\n");
-	printf("seeking for sparse file data offset\n");
-	cur = lseek(fd, 0, SEEK_DATA);
-	if (cur != 0)
-		err(EXIT_FAILURE, "Not getting start of data segment at 0");
-
-	printf("if seek_data returns a 2nd part on a non-sparse file\n");
-	cur = lseek(fd, st.st_size, SEEK_DATA);
-	if (cur != -1)
-		errx(EXIT_FAILURE, "Seek data gave 2nd part at end of file");
-	if (errno != ENXIO)
-		errx(EXIT_FAILURE, "Seek data on the end of file didn't"
-			" raise ENXIO (%d)", errno);
-	printf( "if seek_data in the file's last block of a non-sparse file "
-		"returns the current position\n");
-	cur = lseek(fd, st.st_size-50, SEEK_DATA);
-	if (cur != st.st_size - 50) {
-		errx(EXIT_FAILURE, "Seek data didn't give passed seek position "
-		    "back %" PRIi64 " should be %" PRIi64, cur, st.st_size-50);
-		return EXIT_FAILURE;
-	}
-
-	printf("if seek_data in the middle of the of a non-sparse file "
-		"returns the current position\n");
-	cur = lseek(fd, st.st_size - 100 * 1024, SEEK_DATA);
-	if (cur != st.st_size - 100 * 1024)
-		errx(EXIT_FAILURE, "Seek data didn't give passed seek "
-		    "position back %" PRIi64 " should be %" PRIi64, cur,
-		    st.st_size - 100 * 1024);
-
-	printf("seeking for hole\n");
-	cur = lseek(fd, 0, SEEK_HOLE);
-	if (cur != st.st_size)
-		errx(EXIT_FAILURE, "Seek hole didn't return end of file");
-
-	printf("seeking if the end of the file is a hole\n");
-	cur = lseek(fd, st.st_size, SEEK_HOLE);
-	if (cur != st.st_size)
-		errx(EXIT_FAILURE, "At the end of the file, no virtual hole "
-		    "is returned");
-
-	printf("seeking if a 2nd hole is returned outside the file range\n");
-	cur = lseek(fd, st.st_size + 1, SEEK_HOLE);
-	if (cur != -1)
-		errx(EXIT_FAILURE, "Past the end of file, seek hole returned "
-		    "another hole instead of raising an error");
-	if (errno != ENXIO)
-		errx(EXIT_FAILURE, "Seek hole past the end of file didn't "
-		    "raise ENXIO (%d)", errno);
-#endif
-
-	return EXIT_SUCCESS;
-}
-
--- a/regress/sys/kern/callout1/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.1 2008/03/28 20:44:57 ad Exp $
-
-KMOD=   callout1_test
-
-NOMAN=
-
-.PATH:	${.CURDIR}/../lkmcommon
-
-SRCS=	lkminit_test.c test_callout1.c
-CPPFLAGS+=-DLKMENTRY=callout1_test_lkmentry
-
-.include <bsd.kmod.mk>
-.include <bsd.subdir.mk>
--- a/regress/sys/kern/callout1/test_callout1.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-/*	$NetBSD: test_callout1.c,v 1.3 2008/04/28 20:23:06 martin Exp $	*/
-
-/*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: test_callout1.c,v 1.3 2008/04/28 20:23:06 martin Exp $");
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/kthread.h>
-#include <sys/kernel.h>
-#include <sys/callout.h>
-
-int	testcall(struct lwp *, void *, register_t *);
-
-void	test_callout(void *);
-void	test_softint(void *);
-
-kmutex_t	test_mutex;
-kcondvar_t	test_cv;
-int		test_done;
-void		*test_sih;
-callout_t	test_ch;
-
-void
-test_callout(void *cookie)
-{
-	int s;
-	
-	/* Trigger soft interrupt. */
-	s = splhigh();
-	softint_schedule(test_sih);
-	splx(s);
-
-	mutex_enter(&test_mutex);
-	test_done = 1;
-	cv_broadcast(&test_cv);
-	mutex_exit(&test_mutex);
-}
-
-void
-test_softint(void *cookie)
-{
-
-	printf("l_ncsw = %d\n", (int)curlwp->l_ncsw);
-	callout_halt(&test_ch, NULL);
-	printf("l_ncsw = %d\n", (int)curlwp->l_ncsw);
-}
-
-int
-testcall(struct lwp *l, void *uap, register_t *retval)
-{
-
-	printf("test: initializing\n");
-
-	mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
-	cv_init(&test_cv, "testcv");
-	test_sih = softint_establish(SOFTINT_MPSAFE | SOFTINT_SERIAL,
-	    test_softint, NULL);
-	callout_init(&test_ch, CALLOUT_MPSAFE);
-	callout_setfunc(&test_ch, test_callout, NULL);
-
-	printf("test: firing\n");
-	callout_schedule(&test_ch, hz / 10);
-
-	printf("test: waiting\n");
-	mutex_enter(&test_mutex);
-	while (!test_done) {
-		cv_wait(&test_cv, &test_mutex);
-	}
-	mutex_exit(&test_mutex);
-
-	printf("test: finished\n");
-
-	callout_destroy(&test_ch);
-	softint_disestablish(test_sih);
-	mutex_destroy(&test_mutex);
-	cv_destroy(&test_cv);
-
-	return 0;
-}
--- a/regress/sys/kern/mutex1/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2007/02/24 15:25:23 yamt Exp $
-
-KMOD=   mutex1_test
-
-NOMAN=
-
-.PATH:	${.CURDIR}/../lkmcommon
-
-SRCS=	lkminit_test.c test_mutex1.c
-CPPFLAGS+=-DLKMENTRY=mutex1_test_lkmentry
-
-.include <bsd.kmod.mk>
-.include <bsd.subdir.mk>
--- a/regress/sys/kern/mutex1/test_mutex1.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-/*	$NetBSD: test_mutex1.c,v 1.5 2008/04/28 20:23:07 martin Exp $	*/
-
-/*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: test_mutex1.c,v 1.5 2008/04/28 20:23:07 martin Exp $");
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/kthread.h>
-#include <sys/kernel.h>
-
-#define	NTHREADS	9
-#define	SECONDS		60
-
-int	testcall(struct lwp *, void *, register_t *);
-void	thread1(void *);
-void	thread2(void *);
-void	thread3(void *);
-void	thread_exit(void);
-
-lwp_t		*test_threads[NTHREADS];
-kmutex_t	test_mutex;
-kcondvar_t	test_cv;
-int		test_count;
-int		test_exit;
-
-void
-thread_exit(void)
-{
-
-	mutex_enter(&test_mutex);
-	if (--test_count == 0)
-		cv_signal(&test_cv);
-	mutex_exit(&test_mutex);
-	kthread_exit(0);
-}
-
-/*
- * test_mutex -> kernel_lock
- */
-void
-thread1(void *cookie)
-{
-	int count;
-
-	for (count = 0; !test_exit; count++) {
-		mutex_enter(&test_mutex);
-		KERNEL_LOCK(1, curlwp);
-		if ((count % 11) == 0)
-			yield();
-		mutex_exit(&test_mutex);
-		KERNEL_UNLOCK_ONE(curlwp);
-		if ((count % 17) == 0)
-			yield();
-	}
-
-	thread_exit();
-}
-
-/*
- * kernel_lock -> test_mutex
- */
-void
-thread2(void *cookie)
-{
-	int count;
-
-	for (count = 0; !test_exit; count++) {
-		KERNEL_LOCK(1, curlwp);
-		mutex_enter(&test_mutex);
-		if ((count % 401) == 0)
-			yield();
-		KERNEL_UNLOCK_ONE(curlwp);
-		mutex_exit(&test_mutex);
-		if ((count % 19) == 0)
-			yield();
-	}
-
-	thread_exit();
-}
-
-/*
- * test_mutex without kernel_lock, to provide pressure
- */
-void
-thread3(void *cookie)
-{
-	int count;
-
-	for (count = 0; !test_exit; count++) {
-		mutex_enter(&test_mutex);
-		DELAY(10);
-		if ((count % 101) == 0)
-			yield();
-		mutex_exit(&test_mutex);
-		if ((count % 23) == 0)
-			yield();
-	}
-
-	thread_exit();
-}
-
-int
-testcall(struct lwp *l, void *uap, register_t *retval)
-{
-	void (*func)(void *);
-	int i;
-
-	mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
-	cv_init(&test_cv, "testcv");
-
-	printf("test: creating threads\n");
-
-	test_count = NTHREADS;
-	test_exit = 0;
-
-	for (i = 0; i < test_count; i++) {
-		switch (i % 3) {
-		case 0:
-			func = thread1;
-			break;
-		case 1:
-			func = thread2;
-			break;
-		case 2:
-			func = thread3;
-			break;
-		}
-		kthread_create(0, KTHREAD_MPSAFE, NULL, func, NULL,
-		    &test_threads[i], "thread%d", i);
-	}
-
-	printf("test: sleeping\n");
-
-	mutex_enter(&test_mutex);
-	while (test_count != 0) {
-		(void)cv_timedwait(&test_cv, &test_mutex, hz * SECONDS);
-		test_exit = NTHREADS;
-	}
-	mutex_exit(&test_mutex);
-
-	printf("test: finished\n");
-
-	cv_destroy(&test_cv);
-	mutex_destroy(&test_mutex);
-
-	return 0;
-}
--- a/regress/sys/kern/mutex2/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.2 2007/02/24 15:25:24 yamt Exp $
-
-KMOD=   mutex2_test
-
-NOMAN=
-
-.PATH:	${.CURDIR}/../lkmcommon
-
-SRCS=	lkminit_test.c test_mutex2.c
-CPPFLAGS+=-DLKMENTRY=mutex2_test_lkmentry
-
-.include <bsd.kmod.mk>
-.include <bsd.subdir.mk>
--- a/regress/sys/kern/mutex2/test_mutex2.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*	$NetBSD: test_mutex2.c,v 1.5 2008/04/28 20:23:07 martin Exp $	*/
-
-/*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: test_mutex2.c,v 1.5 2008/04/28 20:23:07 martin Exp $");
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/kthread.h>
-#include <sys/kernel.h>
-
-#define	NTHREADS	32
-#define	SECONDS		60
-
-int	testcall(struct lwp *, void *, register_t *);
-void	thread1(void *);
-void	thread_enter(void);
-
-lwp_t		*test_threads[NTHREADS];
-kmutex_t	test_mutex;
-kcondvar_t	test_cv;
-int		test_count;
-int		test_exit;
-
-static int primes[NTHREADS] = {
-	131, 137, 139, 149,
-	151, 157, 163, 167,
-	173, 179, 181, 191,
-	193, 197, 199, 211,
-	223, 227, 229, 233,
-	239, 241, 251, 257,
-	263, 269, 271, 277,
-	281, 283, 293, 307,
-};
-
-void
-thread_exit(void)
-{
-
-	mutex_enter(&test_mutex);
-	if (--test_count == 0)
-		cv_signal(&test_cv);
-	mutex_exit(&test_mutex);
-	kthread_exit(0);
-}
-
-void
-thread1(void *cookie)
-{
-	int count;
-
-	for (count = 0; !test_exit; count++) {
-		mutex_enter(&test_mutex);
-		if ((count % *(int *)cookie) == 0)
-			yield();
-		mutex_exit(&test_mutex);
-		if ((count % curproc->p_pid) == 0)
-			yield();
-	}
-}
-
-int
-testcall(struct lwp *l, void *uap, register_t *retval)
-{
-	int i;
-
-	mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
-	cv_init(&test_cv, "testcv");
-
-	printf("test: creating threads\n");
-
-	test_count = NTHREADS;
-	test_exit = 0;
-
-	for (i = 0; i < test_count; i++)
-		kthread_create(0, KTHREAD_MPSAFE, NULL, thread1, &primes[i],
-		    &test_threads[i], "thread%d", i);
-
-	printf("test: sleeping\n");
-
-	mutex_enter(&test_mutex);
-	while (test_count != 0) {
-		(void)cv_timedwait(&test_cv, &test_mutex, hz * SECONDS);
-		test_exit = 1;
-	}
-	mutex_exit(&test_mutex);
-
-	printf("test: finished\n");
-
-	cv_destroy(&test_cv);
-	mutex_destroy(&test_mutex);
-
-	return 0;
-}
--- a/regress/sys/kern/priority_inheritance1/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.1 2007/02/25 09:52:47 yamt Exp $
-
-KMOD=   priority_inheritance1_test
-
-NOMAN=
-
-.PATH:	${.CURDIR}/../lkmcommon
-
-SRCS=	lkminit_test.c test_priority_inheritance1.c
-CPPFLAGS+=-DLKMENTRY=priority_inheritance1_test_lkmentry
-
-.include <bsd.kmod.mk>
-.include <bsd.subdir.mk>
--- a/regress/sys/kern/priority_inheritance1/test_priority_inheritance1.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,228 +0,0 @@
-/*	$NetBSD: test_priority_inheritance1.c,v 1.2 2008/04/28 20:23:07 martin Exp $	*/
-
-/*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: test_priority_inheritance1.c,v 1.2 2008/04/28 20:23:07 martin Exp $");
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/kthread.h>
-#include <sys/kernel.h>
-
-#define	SECONDS		5
-
-int	testcall(struct lwp *, void *, register_t *);
-void	dummy(void *);
-void	lowprio(void *);
-void	highprio(void *);
-void	thread_exit(int, int);
-void	thread_enter(int *, int);
-
-kmutex_t	test_mutex;
-kcondvar_t	test_cv;
-bool		test_exit;
-
-int		started;
-kcondvar_t	start_cv;
-int		exited;
-kcondvar_t	exit_cv;
-
-void
-changepri(int prio)
-{
-	struct lwp *l = curlwp;
-
-	lwp_lock(l);
-	lwp_changepri(l, prio);
-	lwp_unlock(l);
-}
-
-void
-printpri(const char *msg)
-{
-	struct lwp *l = curlwp;
-
-#if 0
-	printf("%s: %s: eprio=%d l_priority=%d l_usrpri=%d\n",
-	    l->l_proc->p_comm, msg, lwp_eprio(l), l->l_priority, l->l_usrpri);
-#else
-	printf("%s: %s: l_priority=%d l_usrpri=%d\n",
-	    l->l_proc->p_comm, msg, l->l_priority, l->l_usrpri);
-#endif
-}
-
-void
-thread_enter(int *nlocks, int prio)
-{
-	struct lwp *l = curlwp;
-
-	KERNEL_UNLOCK_ALL(l, nlocks);
-	changepri(prio);
-	yield(); /* XXX */
-	printpri("enter");
-}
-
-void
-thread_exit(int nlocks, int prio)
-{
-	struct lwp *l = curlwp;
-
-	mutex_enter(&test_mutex);
-	exited++;
-	cv_signal(&exit_cv);
-	mutex_exit(&test_mutex);
-
-#if 0
-	if (lwp_eprio(l) != prio)
-#else
-	if (l->l_priority != prio || l->l_usrpri != prio)
-#endif
-		printpri("ERROR: priority changed");
-
-	printpri("exit");
-
-	KERNEL_LOCK(nlocks, curlwp);
-	kthread_exit(0);
-}
-
-void
-dummy(void *cookie)
-{
-	int count, nlocks;
-	int prio = (int)cookie;
-
-	thread_enter(&nlocks, prio);
-
-	mutex_enter(&test_mutex);
-	started++;
-	cv_signal(&start_cv);
-	mutex_exit(&test_mutex);
-	while (!test_exit)
-		yield();
-
-	thread_exit(nlocks, prio);
-}
-
-void
-lowprio(void *cookie)
-{
-	struct lwp *l = curlwp;
-	int count, nlocks;
-	int prio = (int)cookie;
-
-	thread_enter(&nlocks, prio);
-
-	mutex_enter(&test_mutex);
-	started++;
-	cv_signal(&start_cv);
-
-	changepri(PUSER-1);
-	kpause("test", false, hz, NULL);
-
-	printpri("have mutex");
-	mutex_exit(&test_mutex);
-	printpri("released mutex");
-
-	thread_exit(nlocks, PUSER-1);
-}
-
-void
-highprio(void *cookie)
-{
-	int count, nlocks;
-	int prio = (int)cookie;
-
-	thread_enter(&nlocks, prio);
-
-	printf("highprio start\n");
-	mutex_enter(&test_mutex);
-	while (started < ncpu + 1)
-		cv_wait(&start_cv, &test_mutex);
-	mutex_exit(&test_mutex);
-	printf("highprio done\n");
-
-	test_exit = true;
-
-	thread_exit(nlocks, prio);
-}
-
-int
-testcall(struct lwp *l, void *uap, register_t *retval)
-{
-	void (*func)(void *);
-	int i;
-
-	mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
-	cv_init(&start_cv, "startcv");
-	cv_init(&exit_cv, "exitcv");
-	cv_init(&test_cv, "testcv");
-
-	printf("test: creating threads\n");
-
-	test_exit = false;
-	started = exited = 0;
-
-	changepri(PUSER-30);
-
-	for (i = 0; i < ncpu; i++)
-		kthread_create1(dummy, (void *)(PUSER-10), NULL, "dummy-%d", i);
-	mutex_enter(&test_mutex);
-	while (started < ncpu)
-		cv_wait(&start_cv, &test_mutex);
-	mutex_exit(&test_mutex);
-
-	kthread_create1(lowprio, (void *)(PUSER-20), NULL, "lowprio");
-	i++;
-	kthread_create1(highprio, (void *)(PUSER-20), NULL, "highprio");
-	i++;
-
-	printf("test: sleeping\n");
-	kpause("test", false, hz * SECONDS, NULL);
-	printf("test: woken\n");
-
-	if (!test_exit)
-		printf("test: FAIL\n");
-	test_exit = true;
-	mutex_enter(&test_mutex);
-	while (exited != i) {
-		cv_wait(&exit_cv, &test_mutex);
-	}
-	mutex_exit(&test_mutex);
-
-	printf("test: finished\n");
-
-	cv_destroy(&test_cv);
-	mutex_destroy(&test_mutex);
-
-	return 0;
-}
--- a/regress/sys/kern/rwlock1/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.2 2007/02/24 15:25:24 yamt Exp $
-
-KMOD=   rwlock1_test
-
-NOMAN=
-
-.PATH:	${.CURDIR}/../lkmcommon
-
-SRCS=	lkminit_test.c test_rwlock1.c
-CPPFLAGS+=-DLKMENTRY=rwlock1_test_lkmentry
-
-.include <bsd.kmod.mk>
-.include <bsd.subdir.mk>
--- a/regress/sys/kern/rwlock1/test_rwlock1.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-/*	$NetBSD: test_rwlock1.c,v 1.6 2008/04/28 20:23:07 martin Exp $	*/
-
-/*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: test_rwlock1.c,v 1.6 2008/04/28 20:23:07 martin Exp $");
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/kthread.h>
-#include <sys/kernel.h>
-
-#define	NTHREADS	32
-#define	SECONDS		60
-
-int	testcall(struct lwp *, void *, register_t *);
-void	thread1(void *);
-void	thread_exit(void);
-
-lwp_t		*test_threads[NTHREADS];
-kmutex_t	test_mutex;
-krwlock_t	test_rwlock;
-kcondvar_t	test_cv;
-int		test_count;
-int		test_exit;
-
-static int primes[NTHREADS] = {
-	 17,  19,  23,  29,
-	 31,  37,  41,  43,
-	 47,  53,  59,  61,
-	 67,  71,  73,  79,
-	 83,  89,  97, 101,
-	103, 107, 109, 113,
-	127, 131, 137, 139,
-	149, 151, 157, 163,
-};
-
-void
-thread_exit(void)
-{
-
-	mutex_enter(&test_mutex);
-	if (--test_count == 0)
-		cv_signal(&test_cv);
-	mutex_exit(&test_mutex);
-	kthread_exit(0);
-}
-
-void
-thread1(void *cookie)
-{
-	int count;
-	krw_t op;
-
-	for (count = 0; !test_exit; count++) {
-		if (count % *(int *)cookie == 0)
-			op = RW_WRITER;
-		else
-			op = RW_READER;
-		rw_enter(&test_rwlock, op);
-		if ((arc4random() % 11) == 0)
-			yield();
-		rw_exit(&test_rwlock);
-		if ((arc4random() % 23) == 0)
-			yield();
-	}
-
-	thread_exit();
-}
-
-int
-testcall(struct lwp *l, void *uap, register_t *retval)
-{
-	int i;
-
-	mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
-	rw_init(&test_rwlock);
-	cv_init(&test_cv, "testcv");
-
-	printf("test: creating threads\n");
-
-	test_count = NTHREADS;
-	test_exit = 0;
-
-	for (i = 0; i < test_count; i++)
-		kthread_create(0, KTHREAD_MPSAFE, NULL, thread1, &primes[i],
-		    &test_threads[i], "thread%d", i);
-
-	printf("test: sleeping\n");
-
-	mutex_enter(&test_mutex);
-	while (test_count != 0) {
-		(void)cv_timedwait(&test_cv, &test_mutex, hz * SECONDS);
-		test_exit = 1;
-	}
-	mutex_exit(&test_mutex);
-
-	printf("test: finished\n");
-
-	cv_destroy(&test_cv);
-	rw_destroy(&test_rwlock);
-	mutex_destroy(&test_mutex);
-
-	return 0;
-}
--- a/regress/sys/net/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2011/11/01 23:07:34 pgoyette Exp $
-
-.include <bsd.own.mk>
-
-SUBDIR= bpf
-
-.include <bsd.subdir.mk>
--- a/regress/sys/net/bpf/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-#	$NetBSD: Makefile,v 1.3 2006/03/24 13:54:58 pavel Exp $
-
-.include <bsd.own.mk>
-
-SUBDIR= interface out-of-bounds
-
-.include <bsd.subdir.mk>
--- a/regress/sys/net/bpf/interface/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#	$NetBSD: Makefile,v 1.1 2005/12/25 22:07:01 rpaulo Exp $
-
-NOMAN=	# defined
-
-PROG=	interface
-WARNS=	3
-
-regress:
-	@if ./${PROG} ; then		\
-		echo "PASSED";		\
-	else				\
-		echo "FAILED";		\
-	fi
-
-.include <bsd.prog.mk>
--- a/regress/sys/net/bpf/interface/interface.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*	$NetBSD: interface.c,v 1.2 2008/04/28 20:23:07 martin Exp $	*/
-
-/*
- * Copyright (c) 2005 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Rui Paulo.
- *
- * 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 <errno.h>
-#include <string.h>
-#include <err.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-
-#include <net/bpf.h>
-#include <net/if.h>
-
-int
-main(int argc, char *argv[])
-{
-	int fd,i ;
-	u_int testint;
-	struct bpf_dltlist testdlt;
-	struct bpf_program testprog;
-	struct bpf_stat teststat;
-	struct bpf_version testversion;
-	struct ifreq testif;
-	struct timeval testtv;
-
-	struct ioctls_lists {
-		unsigned long req;
-		void *argumentp;
-	} ioctls[] = {
-		{ BIOCGBLEN, &testint },
-		{ BIOCGDLT, &testint },
-		{ BIOCGDLTLIST, &testdlt },
-		{ BIOCFLUSH, NULL },
-		{ BIOCPROMISC, NULL },
-		{ BIOCGETIF, &testif },
-		{ BIOCGRTIMEOUT, &testtv },
-		{ BIOCGSTATS, &teststat },
-		{ BIOCIMMEDIATE, &testint },
-		{ BIOCSETF, &testprog },
-		{ BIOCVERSION, &testversion },
-		{ BIOCGHDRCMPLT, &testint },
-		{ BIOCGSEESENT, &testint },
-		{ -1, NULL }
-	};
-	int nfailed;
-
-	fd = open("/dev/bpf", O_RDWR, 0);
-	if (fd < 0)
-		err(EXIT_FAILURE, "/dev/bpf");
-
-	strcpy(testif.ifr_name, "lo0");
-	nfailed = 0;
-
-	/* set no filter or remove the filter */
-	testprog.bf_len = 0;
-	testprog.bf_insns = NULL;
-
-	if (ioctl(fd, BIOCSETIF, &testif) < 0)
-		err(EXIT_FAILURE, "lo0");
-
-	for (i = 0; ioctls[i].req != -1; i++) 
-		if (ioctl(fd, ioctls[i].req, ioctls[i].argumentp) < 0) {
-		        fprintf(stderr, "0x%lx:\tFAILED (%s)\n",
-			    ioctls[i].req, strerror(errno));
-			switch (ioctls[i].req) {
-			case BIOCGDLTLIST:
-			case BIOCPROMISC:
-				/* both should fail on lo0 */
-				break;
-			default:
-				nfailed++;
-			}
-		} else
-			printf("0x%lx:\tOK\n", ioctls[i].req);
-
-	return nfailed;
-}
--- a/regress/sys/net/bpf/out-of-bounds/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#	$NetBSD: Makefile,v 1.1 2006/03/24 13:54:58 pavel Exp $
-
-.ifdef REGRESS_LOG
-regress:
-	@echo sys/net/bpf/out-of-bounds out-of-bounds \
-	`./out-of-bounds.sh` | tee ${REGRESS_LOG} ; true
-.else
-regress:
-	@echo sys/net/bpf/out-of-bounds out-of-bounds \
-	`./out-of-bounds.sh`; true 
-.endif
-
-.include <bsd.prog.mk>
--- a/regress/sys/net/bpf/out-of-bounds/out-of-bounds.sh	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#!/bin/sh
-
-# an out-of-bounds read in the BPF expression should exit the bpf program,
-# regardless of other expressions. Pass an expression to tcpdump which
-# performs an out-of-bound read and ping with a packet which would cause
-# the expression to succeed if the out-of-bounds read is not handled.
-
-# exit status: 0 - pass, 1 - fail, 2 - skip
-
-IFACE=${IFACE:-lo0}
-ADDR=${ADDR:-127.0.0.1}
-
-tcpdump -c1 -np -i $IFACE \( link[34000:2]=0 or icmp \) and ip[36:2]=0xcafe > /dev/null &
-TCPDUMP_PID=$!
-
-sleep 1
-if ! kill -0 $TCPDUMP_PID > /dev/null 2>&1 ; then
-	echo "SKIPPED tcpdump exited - are you root?"; exit 2;
-fi
-if ! ping -c1 -p cafe $ADDR > /dev/null 2>&1 ; then
-	echo "SKIPPED not able to ping localhost"; 
-	kill $TCPDUMP_PID > /dev/null 2>&1 ; exit 2;
-fi
-sleep 2
-if ! kill $TCPDUMP_PID > /dev/null 2>&1; then
-	echo "FAILED"; exit 1;
-fi
-wait $TCPDUMP_PID; echo "PASSED"; exit 0;
--- a/regress/sys/uvm/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#	$NetBSD: Makefile,v 1.10 2011/07/14 11:08:44 jruoho Exp $
-
-.include <bsd.own.mk>
-
-.if !empty(SUPPORTED_CC:Mgcc)
-SUBDIR+= stack_exec
-.endif
-
-#
-# Test for no-executable stack; applies only to architectures
-# where CPU and kernel support it.
-#
-STACKNOX_ARCHS= alpha i386 powerpc sparc sparc64 x86_64
-
-.if !empty(SUPPORTED_CC:Mgcc) && !empty(STACKNOX_ARCHS:M${MACHINE_ARCH})
-SUBDIR+= stack_noexec
-.endif
-
-.include <bsd.subdir.mk>
--- a/regress/sys/uvm/Makefile.inc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-#	$NetBSD: Makefile.inc,v 1.1 2000/03/19 02:47:19 simonb Exp $
-#
-# do not install regression test programs
-proginstall::
--- a/regress/sys/uvm/stack_exec/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# $NetBSD: Makefile,v 1.3 2011/05/20 13:36:12 joerg Exp $
-
-NOMAN=	#
-PROG=	tramptest
-LDADD=	-lpthread
-
-UNSUPPORTED_COMPILER.clang=
-UNSUPPORTED_COMPILER.pcc=
-
-regress: ${PROG}
-	@if ./tramptest; then \
-		echo "PASSED"; \
-	else \
-		echo "FAILED"; \
-	fi
-
-.include <bsd.prog.mk>
--- a/regress/sys/uvm/stack_exec/tramptest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/* $NetBSD: tramptest.c,v 1.1 2003/12/10 13:24:59 drochner Exp $ */
-
-#include <stdlib.h>
-#include <pthread.h>
-#include <signal.h>
-
-/*
- * This test checks whether processes/threads get execute permission
- * on the stack if needed, in particular for multiple threads.
- * It depends on the fact that gcc puts trampoline code for
- * nested functions on the stack and requests execution permission
- * for that address internally, at least on some architectures.
- * (On the other architectures, the test is just insignificant.)
- * Actually, it would be better if gcc wouldn't use stack trampolines,
- * at all, but for now it allows for an easy portable check whether the
- * kernel handles permissions correctly.
- */
-
-void
-buserr(int s)
-{
-
-	exit(1);
-}
-
-int
-main()
-{
-	pthread_t t1, t2;
-
-	void *mist(void *p)
-	{
-
-		return (0);
-	}
-
-	signal(SIGBUS, buserr);
-
-	pthread_create(&t1, 0, mist, 0);
-	pthread_create(&t2, 0, mist, 0);
-	pthread_join(t1, 0);
-	pthread_join(t2, 0);
-	exit(0);
-}
--- a/regress/sys/uvm/stack_noexec/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-# $NetBSD: Makefile,v 1.4 2011/05/20 13:36:12 joerg Exp $
-
-NOMAN=	#
-
-UNSUPPORTED_COMPILER.clang=
-UNSUPPORTED_COMPILER.pcc=
-
-.include <bsd.own.mk>
-#
-# tramptest.c relies on a trampoline generated by gcc,
-# which happens for the following architectures:
-#
-GCCTRAMP_ARCHS= alpha arm i386 m68k mips sparc sparc64 vax x86_64
-
-.if !empty(GCCTRAMP_ARCHS:M${MACHINE_GNU_ARCH})
-PROG=	tramptest
-regress: ${PROG}
-	@if ./tramptest; then \
-		echo "PASSED"; \
-	else \
-		echo "FAILED"; \
-	fi
-.else
-# XXX need another test program
-regress:
-.endif
-
-.include <bsd.prog.mk>
--- a/regress/sys/uvm/stack_noexec/tramptest.c	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/* $NetBSD: tramptest.c,v 1.2 2004/02/19 16:49:43 drochner Exp $ */
-
-#include <stdlib.h>
-#include <signal.h>
-
-/*
- * This test checks that the stack has no execute permission.
- * It depends on the fact that gcc puts trampoline code for
- * nested functions on the stack, at least on some architectures.
- * (On the other architectures, the test will fail, as on platforms
- * where execution permissions cannot be controlled.)
- * Actually, it would be better if gcc wouldn't use stack trampolines,
- * at all, but for now it allows for an easy portable check whether the
- * stack is executable.
- */
-
-void
-__enable_execute_stack()
-{
-	/* replace gcc's internal function by a noop */
-}
-
-void
-buserr(int s, siginfo_t *si, void *ctx)
-{
-
-	if (s != SIGSEGV || si->si_code != SEGV_ACCERR)
-		exit(2);
-
-	exit(0);
-}
-
-void (*f)(void);
-
-void do_f()
-{
-
-	(*f)();
-}
-
-int
-main()
-{
-	struct sigaction sa;
-
-	void mist()
-	{
-
-		return;
-	}
-
-	sa.sa_sigaction = buserr;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_SIGINFO;
-	sigaction(SIGSEGV, &sa, 0);
-
-	f = mist;
-	do_f();
-
-	exit(1);
-}
--- a/regress/usr.bin/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#	$NetBSD: Makefile,v 1.19 2010/08/01 16:44:31 jmmv Exp $
-
-.include <bsd.own.mk>
-
-.if ${MKCXX} != "no"
-SUBDIR+= c++
-.endif
-
-SUBDIR+= rtld
-
-.include <bsd.subdir.mk>
--- a/regress/usr.bin/c++/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-# $NetBSD: Makefile,v 1.1 2007/09/17 17:37:48 drochner Exp $
-
-SUBDIR=	static_destructor
-
-.include <bsd.subdir.mk>
--- a/regress/usr.bin/c++/static_destructor/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# $NetBSD: Makefile,v 1.1 2007/09/17 17:37:48 drochner Exp $
-
-PROG_CXX=	static_destructor
-NOMAN=		# defined
-
-regress:
-	./${PROG} > out && diff out ${.CURDIR}/expected
-
-CLEANFILES+=	out
-
-.include <bsd.prog.mk>
--- a/regress/usr.bin/c++/static_destructor/expected	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-constructor A
-constructor B
-destructor B : i = 1
-destructor A : i = 10
--- a/regress/usr.bin/c++/static_destructor/static_destructor.cc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/* $NetBSD: static_destructor.cc,v 1.1 2007/09/17 17:37:49 drochner Exp $ */
-
-/*
- * Tests proper order of destructor calls
- * (must be in reverse order of constructor completion).
- * from the gcc mailing list
- */
-
-#include <iostream>
-using namespace std;
-
-class A 
-{
-public:
-	int     i;
-	A(int j) : i(j) { cout << "constructor A" << endl; }
-	~A() { cout << "destructor A : i = " << i << endl; }
-};
-
-class B 
-{
-public:
-	A *n;
-	B() {
-		static A p(1);
-		n = &p;
-		cout << "constructor B" << endl;
-	}
-	~B() {
-		cout << "destructor B : i = " << n->i << endl;
-		n->i = 10;
-	}
-};
-
-class B x1;
-
-int main (void) { return 0; }
--- a/regress/usr.bin/rtld/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-# $NetBSD: Makefile,v 1.4 2010/12/14 06:02:21 skrll Exp $
-
-.include <bsd.own.mk>
-
-.if ${MKCXX} != "no"
-SUBDIR+= testlib
-.endif
-
-.include <bsd.subdir.mk>
--- a/regress/usr.bin/rtld/testlib/Makefile	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-# $NetBSD: Makefile,v 1.10 2012/08/10 16:04:28 joerg Exp $
-
-NOPROFILE=	yes
-
-SRCS=	ccexc.cc construct.cc virt.cc
-
-LIB=	test
-LIBISCXX=	yes
-TESTLIB=	testlib.so
-
-CLEANFILES+=	${TESTLIB}
-SHLIB_MAJOR=	1
-SHLIB_MINOR=	0
-#CXXFLAGS+= -fno-rtti
-
-.if ${MACHINE_ARCH} == "i386" && "${MKPIC}" != "no"
-all realall:	${TESTLIB}
-.else
-all realall:
-.endif
-
-${TESTLIB}: lib${LIB}.so.1.0
-	cp lib${LIB}.so.1.0 ${TESTLIB}
-
-regress:
-
-.include <bsd.lib.mk>
--- a/regress/usr.bin/rtld/testlib/ccexc.cc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-// $NetBSD: ccexc.cc,v 1.1 2000/12/08 19:21:28 drochner Exp $
-
-// generate references to exception handling runtime code
-
-extern "C" void ccexc(void);
-
-void
-ccexc(void)
-{
-	try {
-		throw "mist";
-	} catch (char *e) {
-	}
-}
--- a/regress/usr.bin/rtld/testlib/construct.cc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-// $NetBSD: construct.cc,v 1.2 2003/09/03 20:53:16 drochner Exp $
-
-// check constructor / destructor calls
-
-#include <iostream>
-
-using namespace std;
-
-class mist {
-public:
-	mist(void);
-	~mist();
-};
-
-mist::mist(void)
-{
-	cout << "constructor" << endl;
-}
-
-mist::~mist()
-{
-	cout << "destructor" << endl;
-}
-
-static mist construct;
--- a/regress/usr.bin/rtld/testlib/virt.cc	Thu May 18 23:52:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-// $NetBSD: virt.cc,v 1.1 2000/12/08 19:21:28 drochner Exp $
-
-// g++ generates a reference to "__pure_virtual" with this code
-
-class mist {
-public:
-	virtual void vv(void) = 0;
-};
-
-class mast: public mist {
-public:
-	void vv(void) {};
-};
-
-static mast virt;
--- a/share/man/man4/Makefile	Thu May 18 23:52:01 2017 +0000
+++ b/share/man/man4/Makefile	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.635 2017/04/19 00:17:31 riastradh Exp $
+#	$NetBSD: Makefile,v 1.635.2.1 2017/05/19 00:22:55 pgoyette Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 MAN=	aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -66,7 +66,7 @@
 	trm.4 tty.4 tun.4 tqphy.4 twa.4 twe.4 txp.4 \
 	uark.4 ubsec.4 udp.4 uep.4 ug.4 uha.4 uk.4 ukphy.4 unix.4 userconf.4 \
 	vald.4 valz.4 veriexec.4 vga.4 vge.4 viaide.4 video.4 vioif.4 viomb.4 \
-	viornd.4 virt.4 \
+	viornd.4 vioscsi.4 virt.4 \
 	virtio.4 vlan.4 vmmon.4 vmnet.4 vnd.4 voodoofb.4 vr.4 vte.4 \
 	wapbl.4 wb.4 wbsio.4 wd.4 wdc.4 wi.4 wm.4 wpi.4 \
 	wscons.4 wsdisplay.4 wsfont.4 wskbd.4 wsmouse.4 wsmux.4 \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/vioscsi.4	Fri May 19 00:22:50 2017 +0000
@@ -0,0 +1,66 @@
+.\" $NetBSD: vioscsi.4,v 1.2.2.2 2017/05/19 00:22:55 pgoyette Exp $
+.\"
+.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" 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.
+.\"
+.Dd May 17, 2017
+.Dt VIOSCSI 4
+.Os
+.Sh NAME
+.Nm vioscsi
+.Nd VirtIO SCSI adapter
+.Sh SYNOPSIS
+.Cd "vioscsi* at virtio?"
+.Cd "scsibus* at vioscsi?"
+.Sh DESCRIPTION
+.Nm
+driver provides support for
+.Xr virtio 4
+SCSI adapters.
+.Sh SEE ALSO
+.Xr scsi 4 ,
+.Xr sd 4 ,
+.Xr virtio 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 5.5 .
+It first appeared in
+.Nx 7.1 ,
+with further stabilization in
+.Nx 8.0 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Matthew Dempsky Aq Mt matthew@dempsky.org .
+.Nx
+port done by
+.An Christos Zoulas .
+Further stabilization done by
+.An Jaromir Dolecek Aq Mt jdolecek@NetBSD.org .
+.Sh CAVEATS
+.Nm
+driver limits probe to 1 channel, 16 targets, and 1024 LUNs to reduce boot time.
--- a/share/man/man4/virtio.4	Thu May 18 23:52:01 2017 +0000
+++ b/share/man/man4/virtio.4	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: virtio.4,v 1.7 2017/01/26 13:52:29 wiz Exp $
+.\"	$NetBSD: virtio.4,v 1.7.2.1 2017/05/19 00:22:55 pgoyette Exp $
 .\"
 .\" Copyright (c) 2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 26, 2017
+.Dd May 17, 2017
 .Dt VIRTIO 4
 .Os
 .Sh NAME
@@ -36,6 +36,7 @@
 .Cd "vioif* at virtio?"
 .Cd "viomb* at virtio?"
 .Cd "viornd* at virtio?"
+.Cd "vioscsi* at virtio?"
 .Sh DESCRIPTION
 .Nm
 defines an interface for efficient, standard and extensible I/O between the
@@ -57,13 +58,16 @@
 A pseudo-device to release memory back to the hypervisor.
 .It Xr viornd 4
 An entropy source.
+.It Xr vioscsi 4
+A SCSI adapter.
 .El
 .Sh SEE ALSO
 .Xr ld 4 ,
 .Xr pci 4 ,
 .Xr vioif 4 ,
 .Xr viomb 4 ,
-.Xr viornd 4
+.Xr viornd 4 ,
+.Xr vioscsi 4
 .Pp
 .Rs
 .%A Rusty Russell, IBM Corporation
--- a/share/man/man9/uvm_map.9	Thu May 18 23:52:01 2017 +0000
+++ b/share/man/man9/uvm_map.9	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-.\"	$NetBSD: uvm_map.9,v 1.6.6.1 2017/05/11 02:58:35 pgoyette Exp $
+.\"	$NetBSD: uvm_map.9,v 1.6.6.2 2017/05/19 00:22:56 pgoyette Exp $
 .\"
 .\" Copyright (c) 1998 Matthew R. Green
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 20, 2014
+.Dd May 6, 2017
 .Dt UVM_MAP 9
 .Os
 .Sh NAME
--- a/share/misc/acronyms.comp	Thu May 18 23:52:01 2017 +0000
+++ b/share/misc/acronyms.comp	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-$NetBSD: acronyms.comp,v 1.179.2.1 2017/05/11 02:58:35 pgoyette Exp $
+$NetBSD: acronyms.comp,v 1.179.2.2 2017/05/19 00:22:56 pgoyette Exp $
 3WHS	three-way handshake
 8VSB	8-state vestigial side band modulation
 AA	anti-aliasing
@@ -178,6 +178,7 @@
 CC	carbon coby
 CCD	charge coupled device
 CCI	co-channel interferer
+CCNUMA	cache-coherent non-uniform memory access
 CD	cache disable
 CD	compact disc
 CDDA	compact disc digital audio
@@ -961,6 +962,7 @@
 PICNIC	problem in chair, not in computer
 PID	process id
 PIE	position independent executable
+PIL	Priority Interrupt Level
 PIM	personal information manager
 PIM	platform-independent model
 PIO	programmed input/output
@@ -1081,6 +1083,7 @@
 RLO	right-to-left override
 RM	read miss
 RMI	remote method invocation
+RMO	Relaxed Memory Ordering
 RMPM	rapid memory power management
 RMS	root mean square
 RMW	read, modify, write
@@ -1216,6 +1219,8 @@
 SPDIF	Sony/Philips digital interface format
 SPI	serial peripheral interface
 SPI	stateful packet inspection
+SPL	system interrupt priority level
+SPL	spinlock
 SPMD	single process, multiple data
 SPR	special purpose register
 SPT	sectors per track
@@ -1311,6 +1316,7 @@
 TSD	time stamp disable
 TSL	test, set, lock
 TSO	time sharing option
+TSO	Total Store Ordering
 TSP	Time-Stamp Protocol
 TSP	Tunnel Setup Protocol
 TSP	time synchronization protocol
--- a/share/misc/airport	Thu May 18 23:52:01 2017 +0000
+++ b/share/misc/airport	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: airport,v 1.64 2017/04/06 19:53:36 mbalmer Exp $
+#	$NetBSD: airport,v 1.64.2.1 2017/05/19 00:22:56 pgoyette Exp $
 #	@(#)airport	8.1 (Berkeley) 6/8/93
 #
 # Some of this information is from http://www.mapping.com/airportcodes.html.
@@ -7601,7 +7601,7 @@
 THX:Turukhansk, Krasnoyarsk Krai, Russia
 THY:Thohoyandou, Venda, South Africa
 THZ:Tahoua, Niger
-TIA:Tirana, Albania
+TIA:Tirana International Airport, Albania
 TIB:Tibu, Colombia
 TIC:Tinak Airport, Marshall Islands
 TID:Tiaret (Bou Chekif), Algeria
--- a/sys/arch/amd64/conf/XEN3_DOMU	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/amd64/conf/XEN3_DOMU	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOMU,v 1.73 2017/02/26 12:41:50 rin Exp $
+# $NetBSD: XEN3_DOMU,v 1.73.4.1 2017/05/19 00:22:56 pgoyette Exp $
 
 include 	"arch/amd64/conf/std.xen"
 
@@ -215,8 +215,10 @@
 
 # network pseudo-devices
 pseudo-device	bpfilter		# Berkeley packet filter
+#pseudo-device	carp			# Common Address Redundancy Protocol
 pseudo-device	ipfilter		# IP filter (firewall) and NAT
 pseudo-device	loop			# network loopback
+#pseudo-device	mpls			# MPLS pseudo-interface
 pseudo-device	ppp			# Point-to-Point Protocol
 pseudo-device	pppoe			# PPP over Ethernet (RFC 2516)
 pseudo-device	sl			# Serial Line IP
--- a/sys/arch/arm/arm/ast.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/arm/arm/ast.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ast.c,v 1.28 2015/04/17 17:28:33 matt Exp $	*/
+/*	$NetBSD: ast.c,v 1.28.8.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1994,1995 Mark Brinicombe
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.28 2015/04/17 17:28:33 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.28.8.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "opt_ddb.h"
 
@@ -80,7 +80,9 @@
 #ifdef __HAVE_PREEMPTION
 	kpreempt_disable();
 #endif
-	KASSERT(curcpu()->ci_pmap_cur == l->l_proc->p_vmspace->vm_map.pmap);
+	KASSERTMSG(curcpu()->ci_pmap_cur == l->l_proc->p_vmspace->vm_map.pmap,
+	    "%p vs %p", curcpu()->ci_pmap_cur,
+	    l->l_proc->p_vmspace->vm_map.pmap);
 	if (__predict_false(armreg_ttbcr_read() & TTBCR_S_PD0)) {
 		pmap_activate(l);
 	}
--- a/sys/arch/evbmips/conf/LOONGSON	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/evbmips/conf/LOONGSON	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: LOONGSON,v 1.30 2017/02/19 07:47:00 rin Exp $
+# $NetBSD: LOONGSON,v 1.30.4.1 2017/05/19 00:22:56 pgoyette Exp $
 #
 # LOONGSON machine description file
 # 
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"LOONGSON-$Revision: 1.30 $"
+#ident 		"LOONGSON-$Revision: 1.30.4.1 $"
 
 maxusers	16
 
@@ -36,6 +36,7 @@
 #options 	PMAP_FAULTINFO
 #options 	LOCKDEBUG
 makeoptions	DEBUG="-g"
+makeoptions	COPY_SYMTAB=1		# size for embedded symbol table
 options 	KTRACE			# system call tracing support
 options 	MSGBUFSIZE=8192		# dmesg buffer size
 
--- a/sys/arch/mips/mips/cache.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/mips/mips/cache.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cache.c,v 1.55 2017/04/22 20:32:35 skrll Exp $	*/
+/*	$NetBSD: cache.c,v 1.55.2.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cache.c,v 1.55 2017/04/22 20:32:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cache.c,v 1.55.2.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "opt_cputype.h"
 #include "opt_mips_cache.h"
@@ -662,7 +662,7 @@
 		KASSERT(mci->mci_picache_ways != 0);
 		mci->mci_picache_way_size = mci->mci_picache_size / mci->mci_picache_ways;
 		mci->mci_picache_way_mask = mci->mci_picache_way_size - 1;
-#if (MIPS2 + MIPS3) > 0
+#if (MIPS2 + MIPS3 + MIPS4) > 0
 		if (mci->mci_icache_virtual_alias)
 			mci->mci_icache_alias_mask =
 			    mci->mci_picache_way_mask & -PAGE_SIZE;
@@ -672,13 +672,21 @@
 		KASSERT(mci->mci_pdcache_ways != 0);
 		mci->mci_pdcache_way_size = mci->mci_pdcache_size / mci->mci_pdcache_ways;
 		mci->mci_pdcache_way_mask = mci->mci_pdcache_way_size - 1;
-#if (MIPS2 + MIPS3) > 0
+#if (MIPS2 + MIPS3 + MIPS4) > 0
 		if (mci->mci_cache_virtual_alias)
 			mci->mci_cache_alias_mask =
-			    mci->mci_picache_way_mask & -PAGE_SIZE;
+			    mci->mci_pdcache_way_mask & -PAGE_SIZE;
 #endif
 	}
 
+#if (MIPS2 + MIPS3 + MIPS4) > 0
+	if (mci->mci_cache_virtual_alias) {
+		mci->mci_cache_prefer_mask = mci->mci_pdcache_way_mask;
+
+		uvmexp.ncolors = (mci->mci_cache_prefer_mask >> PAGE_SHIFT) + 1;
+	}
+#endif
+
 	mips_dcache_compute_align();
 
 	if (mci->mci_sdcache_line_size == 0)
@@ -987,14 +995,6 @@
 	mci->mci_pdcache_line_size = MIPS3_CONFIG_CACHE_L1_LSIZE(config,
 	    MIPS3_CONFIG_DB);
 
-	mci->mci_icache_alias_mask =
-	    (mci->mci_picache_size / mci->mci_picache_ways - 1) & -PAGE_SIZE;
-	mci->mci_cache_alias_mask =
-	    (mci->mci_pdcache_size / mci->mci_pdcache_ways - 1) & -PAGE_SIZE;
-	mci->mci_cache_prefer_mask =
-	    max(mci->mci_pdcache_size, mci->mci_picache_size) - 1;
-	uvmexp.ncolors = (mci->mci_cache_alias_mask >> PAGE_SHIFT) + 1;
-
 	switch(MIPS_PRID_IMPL(cpu_id)) {
 #ifndef ENABLE_MIPS_R3NKK
 	case MIPS_R5000:
--- a/sys/arch/mips/mips/mipsX_subr.S	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/mips/mips/mipsX_subr.S	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: mipsX_subr.S,v 1.96.6.1 2017/05/11 02:58:35 pgoyette Exp $	*/
+/*	$NetBSD: mipsX_subr.S,v 1.96.6.2 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -2576,7 +2576,7 @@
 	_MFC0	t0, MIPS_COP_0_TLB_HI		# get VA and ASID
 	MFC0_HAZARD
 	and	t0, t0, MIPS3_PG_ASID		# focus on ASID
-	bge	t0, a1, 4f			# >= ASID max? skip
+	bgt	t0, a1, 4f			# > ASID max? skip
 	 nop
 
 	srl	a2, t0, 3 + LONG_SCALESHIFT	# drop low 5 or 6 bits
--- a/sys/arch/mips/mips/pmap_machdep.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/mips/mips/pmap_machdep.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.c,v 1.12.6.1 2017/05/11 02:58:35 pgoyette Exp $	*/
+/*	$NetBSD: pmap_machdep.c,v 1.12.6.2 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.12.6.1 2017/05/11 02:58:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.12.6.2 2017/05/19 00:22:56 pgoyette Exp $");
 
 /*
  *	Manages physical address maps.
@@ -165,6 +165,10 @@
 PMAP_COUNTER(copied_pages, "pages copied");
 extern struct evcnt pmap_evcnt_page_cache_evictions;
 
+u_int pmap_page_cache_alias_mask;
+
+#define pmap_md_cache_indexof(x)	(((vaddr_t)(x)) & pmap_page_cache_alias_mask)
+
 static register_t
 pmap_md_map_ephemeral_page(struct vm_page *pg, bool locked_p, int prot,
     pt_entry_t *old_pte_p)
@@ -196,12 +200,20 @@
 		 */
 		kpreempt_disable(); // paired with the one in unmap
 		struct cpu_info * const ci = curcpu();
-		KASSERT(ci->ci_pmap_dstbase != 0);
+		if (MIPS_CACHE_VIRTUAL_ALIAS) {
+			KASSERT(ci->ci_pmap_dstbase != 0);
+			KASSERT(ci->ci_pmap_srcbase != 0);
 
+			const u_int __diagused mask = pmap_page_cache_alias_mask;
+			KASSERTMSG((ci->ci_pmap_dstbase & mask) == 0,
+			    "%#"PRIxVADDR, ci->ci_pmap_dstbase);
+			KASSERTMSG((ci->ci_pmap_srcbase & mask) == 0,
+			    "%#"PRIxVADDR, ci->ci_pmap_srcbase);
+		}
 		vaddr_t nva = (prot & VM_PROT_WRITE
 			? ci->ci_pmap_dstbase
 			: ci->ci_pmap_srcbase)
-		    + mips_cache_indexof(MIPS_CACHE_VIRTUAL_ALIAS
+		    + pmap_md_cache_indexof(MIPS_CACHE_VIRTUAL_ALIAS
 			? pv->pv_va
 			: pa);
 
@@ -330,8 +342,12 @@
 	size_t sysmap_size;
 	pt_entry_t *sysmap;
 
-	if (MIPS_CACHE_VIRTUAL_ALIAS && uvmexp.ncolors)
+	if (MIPS_CACHE_VIRTUAL_ALIAS && uvmexp.ncolors) {
 		pmap_page_colormask = (uvmexp.ncolors - 1) << PAGE_SHIFT;
+		pmap_page_cache_alias_mask = max(
+		    mips_cache_info.mci_cache_alias_mask,
+		    mips_cache_info.mci_icache_alias_mask);
+	}
 
 #ifdef MULTIPROCESSOR
 	pmap_t pm = pmap_kernel();
@@ -509,16 +525,23 @@
 #endif
 	    || MIPS_CACHE_VIRTUAL_ALIAS
 	    || MIPS_ICACHE_VIRTUAL_ALIAS) {
-		vsize_t size = uvmexp.ncolors * PAGE_SIZE;
-		if (MIPS_ICACHE_VIRTUAL_ALIAS
-		    && mci->mci_picache_way_size > size)
-			size = mci->mci_picache_way_size;
-		ci->ci_pmap_dstbase = uvm_km_alloc(kernel_map, size, 0,
-		    UVM_KMF_COLORMATCH | UVM_KMF_VAONLY);
+		vsize_t size = max(mci->mci_pdcache_way_size, mci->mci_picache_way_size);;
+		const u_int __diagused mask = pmap_page_cache_alias_mask;
+
+		ci->ci_pmap_dstbase = uvm_km_alloc(kernel_map, size, size,
+		    UVM_KMF_VAONLY);
+
 		KASSERT(ci->ci_pmap_dstbase);
-		ci->ci_pmap_srcbase = uvm_km_alloc(kernel_map, size, 0,
-		    UVM_KMF_COLORMATCH | UVM_KMF_VAONLY);
+		KASSERT(!pmap_md_direct_mapped_vaddr_p(ci->ci_pmap_dstbase));
+		KASSERTMSG((ci->ci_pmap_dstbase & mask) == 0, "%#"PRIxVADDR,
+		    ci->ci_pmap_dstbase);
+
+		ci->ci_pmap_srcbase = uvm_km_alloc(kernel_map, size, size,
+		    UVM_KMF_VAONLY);
 		KASSERT(ci->ci_pmap_srcbase);
+		KASSERT(!pmap_md_direct_mapped_vaddr_p(ci->ci_pmap_srcbase));
+		KASSERTMSG((ci->ci_pmap_srcbase & mask) == 0, "%#"PRIxVADDR,
+		    ci->ci_pmap_srcbase);
 	}
 }
 
@@ -596,6 +619,8 @@
 
 	struct vm_page * const dst_pg = PHYS_TO_VM_PAGE(dst_pa);
 
+	KASSERT(!VM_PAGEMD_EXECPAGE_P(VM_PAGE_TO_MD(dst_pg)));
+
 	const register_t dst_va = pmap_md_map_ephemeral_page(dst_pg, false,
 	    VM_PROT_READ|VM_PROT_WRITE, &dst_pte);
 
@@ -625,6 +650,7 @@
 	    VM_PROT_READ, &src_pte);
 
 	KASSERT(VM_PAGE_TO_MD(dst_pg)->mdpg_first.pv_pmap == NULL);
+	KASSERT(!VM_PAGEMD_EXECPAGE_P(VM_PAGE_TO_MD(dst_pg)));
 	const register_t dst_va = pmap_md_map_ephemeral_page(dst_pg, false,
 	    VM_PROT_READ|VM_PROT_WRITE, &dst_pte);
 
@@ -645,8 +671,6 @@
 		return;
 
 	struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
-	pv_entry_t pv = &mdpg->mdpg_first;
-	const register_t va = (intptr_t)trunc_page(pv->pv_va);
 
 	/*
 	 * If onproc is empty, we could do a
@@ -658,14 +682,23 @@
 	if (MIPS_HAS_R4K_MMU) {
 		if (VM_PAGEMD_CACHED_P(mdpg)) {
 			/* This was probably mapped cached by UBC so flush it */
-			mips_dcache_wbinv_range_index(va, PAGE_SIZE);
-			mips_icache_sync_range_index(va, PAGE_SIZE);
+			pt_entry_t pte;
+			const register_t tva = pmap_md_map_ephemeral_page(pg, false,
+			    VM_PROT_READ, &pte);
+
+			UVMHIST_LOG(pmaphist, "  va %#"PRIxVADDR, tva, 0, 0, 0);
+			mips_dcache_wbinv_range(tva, PAGE_SIZE);
+			mips_icache_sync_range(tva, PAGE_SIZE);
+
+			pmap_md_unmap_ephemeral_page(pg, false, tva, pte);
 		}
 	} else {
 		mips_icache_sync_range(MIPS_PHYS_TO_KSEG0(VM_PAGE_TO_PHYS(pg)),
 		    PAGE_SIZE);
 	}
 #ifdef MULTIPROCESSOR
+	pv_entry_t pv = &mdpg->mdpg_first;
+	const register_t va = (intptr_t)trunc_page(pv->pv_va);
 	pmap_tlb_syncicache(va, onproc);
 #endif
 }
@@ -698,7 +731,10 @@
 		pv_entry_t pv = &mdpg->mdpg_first;
 		vaddr_t last_va = trunc_page(pv->pv_va);
 
+		KASSERT(len == PAGE_SIZE || last_va == pa);
 		KASSERT(pv->pv_pmap == NULL);
+		KASSERT(pv->pv_next == NULL);
+		KASSERT(!VM_PAGEMD_EXECPAGE_P(mdpg));
 
 		/*
 		 * If this page was last mapped with an address that
@@ -722,22 +758,20 @@
 
 	const paddr_t pa = pmap_md_direct_mapped_vaddr_to_paddr(va);
 	struct vm_page * const pg = PHYS_TO_VM_PAGE(pa);
-	struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
 
 	KASSERT(pg);
+	struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
 
 	KASSERT(VM_PAGEMD_CACHED_P(mdpg));
-	mdpg->mdpg_first.pv_va = va;
-#if 0
-	if (MIPS_CACHE_VIRTUAL_ALIAS) {
-		/*
-		 * We've unmapped a poolpage.  Its contents are irrelevant.
-		 */
-		KASSERT((va & PAGE_MASK) == 0);
-		mips_dcache_inv_range(va, PAGE_SIZE);
-		mdpg->mdpg_first.pv_va = va;
-	}
-#endif
+	KASSERT(!VM_PAGEMD_EXECPAGE_P(mdpg));
+
+	pv_entry_t pv = &mdpg->mdpg_first;
+
+	/* Note last mapped address for future color check */
+	pv->pv_va = va;
+
+	KASSERT(pv->pv_pmap == NULL);
+	KASSERT(pv->pv_next == NULL);
 
 	return pa;
 }
@@ -908,11 +942,14 @@
 	if (__predict_true(!mips_cache_badalias(pv->pv_va, va))) {
 		return false;
 	}
+	KASSERT(pv->pv_pmap != NULL);
+	bool ret = false;
 	for (pv_entry_t npv = pv; npv && npv->pv_pmap;) {
 		if (npv->pv_va & PV_KENTER) {
 			npv = npv->pv_next;
 			continue;
 		}
+		ret = true;
 		vaddr_t nva = trunc_page(npv->pv_va);
 		pmap_t npm = npv->pv_pmap;
 		VM_PAGEMD_PVLIST_UNLOCK(mdpg);
@@ -922,7 +959,9 @@
 
 		npv = pv;
 	}
-	return true;
+	KASSERT(ret == true);
+
+	return ret;
 #else	/* !PMAP_NO_PV_UNCACHED */
 	if (VM_PAGEMD_CACHED_P(mdpg)) {
 		/*
--- a/sys/arch/mips/mips/vm_machdep.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/mips/mips/vm_machdep.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.153.6.1 2017/05/11 02:58:35 pgoyette Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.153.6.2 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.153.6.1 2017/05/11 02:58:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.153.6.2 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_coredump.h"
@@ -206,7 +206,7 @@
 	 */
 	const struct vm_page * const pg = TAILQ_FIRST(&pglist);
 	KASSERT(pg != NULL);
-	const paddr_t pa = VM_PAGE_TO_PHYS(pg);
+	const paddr_t __diagused pa = VM_PAGE_TO_PHYS(pg);
 	KASSERTMSG(pa >= pmap_limits.avail_start,
 	    "pa (%#"PRIxPADDR") < pmap_limits.avail_start (%#"PRIxPADDR")",
 	     pa, pmap_limits.avail_start);
--- a/sys/arch/pmax/ibus/dz_ibus.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/pmax/ibus/dz_ibus.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: dz_ibus.c,v 1.11 2011/07/09 17:32:29 matt Exp $	*/
+/*	$NetBSD: dz_ibus.c,v 1.11.44.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dz_ibus.c,v 1.11 2011/07/09 17:32:29 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dz_ibus.c,v 1.11.44.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "dzkbd.h"
 #include "dzms.h"
@@ -168,6 +168,7 @@
 	 * XXX - This is evil and ugly, but... due to the nature of how
 	 * bus_space_* works on pmax it will do for the time being.
 	 */
+	sc->sc_iot = normal_memt;
 	sc->sc_ioh = (bus_space_handle_t)MIPS_PHYS_TO_KSEG1(iba->ia_addr);
 
 	sc->sc_dr.dr_csr = 0;
--- a/sys/arch/pmax/pmax/bus.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/pmax/pmax/bus.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.c,v 1.1 2016/11/16 19:37:06 macallan Exp $	*/
+/*	$NetBSD: bus.c,v 1.1.10.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.1 2016/11/16 19:37:06 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.1.10.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "opt_cputype.h"
 
@@ -182,9 +182,9 @@
 		addr = map->dm_segs[i].ds_addr;
 
 #ifdef BUS_DMA_DEBUG
-		printf("bus_dmamap_sync_r3k: flushing segment %d "
-		    "(0x%lx..0x%lx) ...", i, addr + offset,
-		    addr + offset + minlen - 1);
+		printf("%s: flushing segment %d (%#jx..%#jx) ...", __func__, i,
+		    (intmax_t)addr + offset,
+		    (intmax_t)addr + offset + minlen - 1);
 #endif
 		mips_dcache_inv_range(
 		    MIPS_PHYS_TO_KSEG0(addr + offset), minlen);
@@ -294,9 +294,9 @@
 		addr = map->dm_segs[i]._ds_vaddr;
 
 #ifdef BUS_DMA_DEBUG
-		printf("bus_dmamap_sync: flushing segment %d "
-		    "(0x%lx..0x%lx) ...", i, addr + offset,
-		    addr + offset + minlen - 1);
+		printf("%s: flushing segment %d (%#jx..%#jx) ...",
+		    __func__, i, (intmax_t)addr + offset,
+		    (intmax_t)ddr + offset + minlen - 1);
 #endif
 
 		/*
--- a/sys/arch/pmax/pmax/bus_dma.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/pmax/pmax/bus_dma.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.58 2015/06/11 08:22:09 matt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.58.8.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.58 2015/06/11 08:22:09 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.58.8.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "opt_cputype.h"
 
@@ -493,9 +493,9 @@
 		addr = map->dm_segs[i].ds_addr;
 
 #ifdef BUS_DMA_DEBUG
-		printf("bus_dmamap_sync_r3k: flushing segment %d "
-		    "(0x%lx..0x%lx) ...", i, addr + offset,
-		    addr + offset + minlen - 1);
+		printf("%s: flushing segment %d (%#jx..%#jx) ...", __func__,
+		    i, (intmax_t)addr + offset,
+		    (intmax_t)addr + offset + minlen - 1);
 #endif
 		mips_dcache_inv_range(
 		    MIPS_PHYS_TO_KSEG0(addr + offset), minlen);
@@ -604,9 +604,9 @@
 		addr = map->dm_segs[i]._ds_vaddr;
 
 #ifdef BUS_DMA_DEBUG
-		printf("bus_dmamap_sync: flushing segment %d "
-		    "(0x%lx..0x%lx) ...", i, addr + offset,
-		    addr + offset + minlen - 1);
+		printf("%s: flushing segment %d (%#jx..%#jx) ...", __func__,
+		    i, (intmax_t)addr + offset,
+		    (intmax_t)addr + offset + minlen - 1);
 #endif
 
 		/*
--- a/sys/arch/x86/include/cpu.h	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/x86/include/cpu.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.69 2017/04/14 04:43:47 kamil Exp $	*/
+/*	$NetBSD: cpu.h,v 1.69.2.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -180,7 +180,7 @@
 	const struct cpu_functions *ci_func;  /* start/stop functions */
 	struct trapframe *ci_ddb_regs;
 
-	u_int ci_cflush_lsize;	/* CFLUSH insn line size */
+	u_int ci_cflush_lsize;	/* CLFLUSH insn line size */
 	struct x86_cache_info ci_cinfo[CAI_COUNT];
 
 	union descriptor *ci_gdt;
--- a/sys/arch/x86/include/specialreg.h	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/x86/include/specialreg.h	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: specialreg.h,v 1.97 2017/04/22 04:24:25 nonaka Exp $	*/
+/*	$NetBSD: specialreg.h,v 1.97.2.1 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -144,7 +144,7 @@
 #define CPUID_PAT	0x00010000	/* Page Attribute Table */
 #define CPUID_PSE36	0x00020000	/* 36-bit PSE */
 #define CPUID_PN	0x00040000	/* processor serial number */
-#define CPUID_CFLUSH	0x00080000	/* CFLUSH insn supported */
+#define CPUID_CFLUSH	0x00080000	/* CLFLUSH insn supported */
 #define CPUID_B20	0x00100000	/* reserved */
 #define CPUID_DS	0x00200000	/* Debug Store */
 #define CPUID_ACPI	0x00400000	/* ACPI performance modulation regs */
@@ -163,7 +163,7 @@
 	"\5" "TSC"	"\6" "MSR"	"\7" "PAE"	"\10" "MCE" \
 	"\11" "CX8"	"\12" "APIC"	"\13" "B10"	"\14" "SEP" \
 	"\15" "MTRR"	"\16" "PGE"	"\17" "MCA"	"\20" "CMOV" \
-	"\21" "PAT"	"\22" "PSE36"	"\23" "PN"	"\24" "CFLUSH" \
+	"\21" "PAT"	"\22" "PSE36"	"\23" "PN"	"\24" "CLFLUSH" \
 	"\25" "B20"	"\26" "DS"	"\27" "ACPI"	"\30" "MMX" \
 	"\31" "FXSR"	"\32" "SSE"	"\33" "SSE2"	"\34" "SS" \
 	"\35" "HTT"	"\36" "TM"	"\37" "IA64"	"\40" "SBF"
--- a/sys/arch/x86/x86/procfs_machdep.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/arch/x86/x86/procfs_machdep.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.14 2016/12/08 06:28:21 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.14.6.1 2017/05/19 00:22:56 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.14 2016/12/08 06:28:21 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.14.6.1 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -131,7 +131,7 @@
 	"clwb", NULL, "avx512pf", "avx512er",
 	"avx512cd", "sha_ni", "avx512bw", "avx512vl"},
 
-	{ /* (10) 0000000d eax */
+	{ /* (10) 0x0000000d eax */
 	"xsaveopt", "xsavec", "xgetbv1", "xsaves", NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -148,6 +148,38 @@
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+
+	{ /* (13) 0x80000008 ebx */
+	"clzero", "irperf", NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+
+	{ /* (14) 0x00000006 eax */
+	"dtherm", "ida", "arat", NULL, "pln", NULL, "pts", "hwp",
+	"hwp_notify", "hwp_act_window", "hwp_epp","hwp_pkg_req",
+	NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+
+	{ /* (15) 0x8000000a edx */
+	"npt", "lbrv", "svm_lock", "nrip_save",
+	"tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
+	NULL, NULL, "pausefilter", NULL, "pfthreshold", "avic", NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+
+	{ /* (16) 0x00000007:0 ecx */
+	NULL, "avx512vbmi", NULL, "pku", "ospke", NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, "avx512_vpopcntdq", NULL,
+	"la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+
+	{ /* (17) 0x80000007 ebx */
+	"overflow_recov", "succor", "smca", NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
 };
 
 static int	procfs_getonecpu(int, struct cpu_info *, char *, size_t *);
@@ -246,9 +278,18 @@
 	    left);
 	diff = last - *left;
 
-	/* (10) 0000000d eax */
+	/* (10) 0x0000000d eax */
 	/* (11) 0x0000000f(ecx=0) edx */
 	/* (12) 0x0000000f(ecx=1) edx */
+	/* (13) 0x80000008 ebx */
+	/* (14) 0x00000006 eax */
+	/* (15) 0x8000000a edx */
+
+	procfs_getonefeatreg(ci->ci_feat_val[6], x86_features[16], p + diff,
+	    left);
+	diff = last - *left;
+
+	/* (17) 0x80000007 ebx */
 
 	return 0; /* XXX */
 }
@@ -318,17 +359,36 @@
 		left = 0;
 
 	l = snprintf(p, left,
+	    "apicid\t\t: %d\n"
+	    "initial apicid\t: %d\n",
+	    ci->ci_acpiid,
+	    ci->ci_initapicid
+	);
+	size += l;
+	if (l < left) {
+		left -= l;
+		p += l;
+	} else
+		left = 0;
+
+	l = snprintf(p, left,
+#ifdef __i386__
 	    "fdiv_bug\t: %s\n"
+#endif
 	    "fpu\t\t: %s\n"
 	    "fpu_exception\t: yes\n"
 	    "cpuid level\t: %d\n"
 	    "wp\t\t: %s\n"
-	    "flags\t\t: %s\n",
+	    "flags\t\t: %s\n"
+	    "clflush size\t: %d\n",
+#ifdef __i386__
 	    i386_fpu_fdivbug ? "yes" : "no",	/* an old pentium */
+#endif
 	    i386_fpu_present ? "yes" : "no",	/* not a 486SX */
 	    cpuid_level,
 	    (rcr0() & CR0_WP) ? "yes" : "no",
-	    featurebuf
+	    featurebuf,
+	    ci->ci_cflush_lsize
 	);
 	size += l;
 
--- a/sys/dev/audio.c	Thu May 18 23:52:01 2017 +0000
+++ b/sys/dev/audio.c	Fri May 19 00:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.327.2.4 2017/05/11 02:58:38 pgoyette Exp $	*/
+/*	$NetBSD: audio.c,v 1.327.2.5 2017/05/19 00:22:56 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.327.2.4 2017/05/11 02:58:38 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.327.2.5 2017/05/19 00:22:56 pgoyette Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -188,6 +188,8 @@
 
 #include <machine/endian.h>
 
+#include <uvm/uvm.h>
+
 /* #define AUDIO_DEBUG	1 */
 #ifdef AUDIO_DEBUG
 #define DPRINTF(x)	if (audiodebug) printf x
@@ -871,9 +873,9 @@
 #ifdef AUDIO_PM_IDLE
 	callout_schedule(&sc->sc_idle_counter, audio_idle_timeout * hz);
 #endif
-	kthread_create(PRI_SOFTBIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
+	kthread_create(PRI_SOFTSERIAL, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
 	    audio_rec_thread, sc, &sc->sc_recthread, "audiorec");
-	kthread_create(PRI_SOFTBIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
+	kthread_create(PRI_SOFTSERIAL, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
 	    audio_play_thread, sc, &sc->sc_playthread, "audiomix");
 	audiorescan(self, "audio", NULL);
 }
@@ -1213,8 +1215,16 @@
 		/* Map it into the kernel virtual address space.  */
 		error = uvm_map(kernel_map, &vstart, vsize, r->uobj, 0, 0,
 		    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_NONE,
-			UVM_ADV_NORMAL, 0));
+			UVM_ADV_RANDOM, 0));
+		if (error)
+			goto bad_map;
+
+		error = uvm_map_pageable(kernel_map, vstart, vstart + vsize,
+		    false, 0);
+
 		if (error) {
+			uvm_unmap(kernel_map, vstart, vsize);
+bad_map:
 			uao_detach(r->uobj);	/* release reference */
 			r->uobj = NULL;		/* paranoia */
 			return error;
@@ -1249,13 +1259,10 @@
 		vstart = (vaddr_t)r->s.start;
 		vsize = roundup2(MAX(r->s.bufsize, PAGE_SIZE), PAGE_SIZE);
 
-		/*
-		 * Unmap the kernel mapping.  uvm_unmap releases the
-		 * reference to the uvm object, and this should be the
-		 * last virtual mapping of the uvm object, so no need
-		 * to explicitly release (`detach') the object.
-		 */
+		uvm_map_pageable(kernel_map, vstart, vstart + vsize,
+		    true, 0);
 		uvm_unmap(kernel_map, vstart, vsize);
+		uao_detach(r->uobj);	/* release reference */
 		r->uobj = NULL;		/* paranoia */
 	}
 
@@ -1696,18 +1703,17 @@
 
 static int
 audioread(struct file *fp, off_t *offp, struct uio *uio, kauth_cred_t cred,
-	  int flags)
+	  int ioflag)
 {
 	struct audio_softc *sc;
 	struct virtual_channel *vc;
-	int error, ioflag;
+	int error;
 	dev_t dev;
 
 	if (fp->f_audioctx == NULL)
 		return EIO;
 
 	dev = fp->f_audioctx->dev;
-	ioflag = 0;
 
 	if ((error = audio_enter(dev, RW_READER, &sc)) != 0)
 		return error;
@@ -1736,18 +1742,17 @@
 
 static int
 audiowrite(struct file *fp, off_t *offp, struct uio *uio, kauth_cred_t cred,
-	   int flags)
+	   int ioflag)
 {
 	struct audio_softc *sc;
 	struct virtual_channel *vc;
-	int error, ioflag;
+	int error;
 	dev_t dev;
 
 	if (fp->f_audioctx == NULL)
 		return EIO;
 
 	dev = fp->f_audioctx->dev;
-	ioflag = 0;
 
 	if ((error = audio_enter(dev, RW_READER, &sc)) != 0)
 		return error;
@@ -2675,24 +2680,27 @@
 		   struct virtual_channel *vc)
 {
 	const audio_params_t *parm;
-	struct audio_ringbuffer *rb;
+	struct audio_stream *rb;
+	int *blksize;
 
 	if (vc->sc_blkset)
 		return;
 
 	if (mode == AUMODE_PLAY) {
-		rb = &vc->sc_mpr;
-		parm = &rb->s.param;
+		rb = vc->sc_pustream;
+		parm = &rb->param;
+		blksize = &vc->sc_mpr.blksize;
 	} else {
-		rb = &vc->sc_mrr;
-		parm = &rb->s.param;
-	}
-
-	rb->blksize = parm->sample_rate * audio_blk_ms / 1000 *
+		rb = vc->sc_rustream;
+		parm = &rb->param;
+		blksize = &vc->sc_mrr.blksize;
+	}
+
+	*blksize = parm->sample_rate * audio_blk_ms / 1000 *
 	     parm->channels * parm->precision / NBBY;
 
 	DPRINTF(("audio_calc_blksize: %s blksize=%d\n",
-		 mode == AUMODE_PLAY ? "play" : "record", rb->blksize));
+		 mode == AUMODE_PLAY ? "play" : "record", *blksize));
 }
 
 void
@@ -3423,10 +3431,7 @@
 
 	if (*offp < 0)
 		return EINVAL;
-	if ((off_t)(*offp + len) < *offp) {
-		/* no offset wrapping */
-		return EOVERFLOW;
-	}
+
 #if 0
 /* XXX
  * The idea here was to use the protection to determine if
@@ -3451,7 +3456,7 @@
 	cb = &vc->sc_mpr;
 #endif
 
-	if ((u_int)*offp >= cb->s.bufsize)
+	if (len > cb->s.bufsize || *offp > cb->s.bufsize - len)
 		return EOVERFLOW;
 
 	if (!cb->mmapped) {
@@ -3475,7 +3480,7 @@
 	/* Acquire a reference for the mmap.  munmap will release.*/
 	uao_reference(*uobjp);
 	*maxprotp = prot;
-	*advicep = UVM_ADV_NORMAL;
+	*advicep = UVM_ADV_RANDOM;
 	*flagsp = MAP_SHARED;
 	return 0;
 }
@@ -3676,7 +3681,7 @@
 		DPRINTFN(3, ("HW RING - INSERT SILENCE\n"));
 		used = blksize;
 		while (used > 0) {
-			cc = sc->sc_pr.s.end - sc->sc_pr.s.inp;
+			cc = vc->sc_mpr.s.end - vc->sc_mpr.s.inp;
 			if (cc > used)
 				cc = used;
 			audio_fill_silence(&vc->sc_pparams, vc->sc_mpr.s.inp, cc);
@@ -3867,22 +3872,20 @@
 	cc = blksize - (inp - cb->s.start) % blksize;
 	if (sc->sc_writeme == false) {
 		DPRINTFN(3, ("MIX RING EMPTY - INSERT SILENCE\n"));
-		mutex_exit(sc->sc_intr_lock);
 		audio_fill_silence(&vc->sc_mpr.s.param, inp, cc);
-		mutex_enter(sc->sc_intr_lock);
 		sc->sc_pr.drops += cc;
 	} else
 		cc = blksize;
 	cb->s.inp = audio_stream_add_inp(&cb->s, cb->s.inp, cc);
 	cc = blksize;
 	cc1 = sc->sc_pr.s.end - sc->sc_pr.s.inp;
-	mutex_exit(sc->sc_intr_lock);
 	if (cc1 < cc) {
 		audio_fill_silence(&vc->sc_mpr.s.param, sc->sc_pr.s.inp, cc1);
 		cc -= cc1;
 		audio_fill_silence(&vc->sc_mpr.s.param, sc->sc_pr.s.start, cc);
 	} else
 		audio_fill_silence(&vc->sc_mpr.s.param, sc->sc_pr.s.inp, cc);
+	mutex_exit(sc->sc_intr_lock);
 
 	kpreempt_disable();
 	if (sc->schedule_wih == true)
@@ -3966,12 +3969,14 @@
 		cc = blksize;
 		if (cb->s.inp + blksize > cb->s.end)
 			cc = cb->s.end - cb->s.inp;
+		mutex_enter(sc->sc_intr_lock);
 		memcpy(cb->s.inp, sc->sc_rr.s.start, cc);
 		if (cc < blksize && cc != 0) {
 			cc1 = cc;
 			cc = blksize - cc;
 			memcpy(cb->s.start, sc->sc_rr.s.start + cc1, cc);
 		}
+		mutex_exit(sc->sc_intr_lock);
 
 		cc = blksize;
 		recswvol_func(sc, cb, blksize, vc);
@@ -4702,8 +4707,10 @@
 	/* Play params can affect the record params, so recalculate blksize. */
 	if (nr > 0 || np > 0 || reset) {
 		vc->sc_blkset = false;
-		audio_calc_blksize(sc, AUMODE_RECORD, vc);
-		audio_calc_blksize(sc, AUMODE_PLAY, vc);
+		if (nr > 0)
+			audio_calc_blksize(sc, AUMODE_RECORD, vc);
+		if (np > 0)
+			audio_calc_blksize(sc, AUMODE_PLAY, vc);
 	}
 #ifdef AUDIO_DEBUG
 	if (audiodebug > 1 && nr > 0) {
@@ -4796,8 +4803,10 @@
 			cleared = true;
 		}
 		vc->sc_blkset = false;
-		audio_calc_blksize(sc, AUMODE_RECORD, vc);
-		audio_calc_blksize(sc, AUMODE_PLAY, vc);
+		if (nr > 0)
+			audio_calc_blksize(sc, AUMODE_RECORD, vc);
+		if (np > 0)
+			audio_calc_blksize(sc, AUMODE_PLAY, vc);
 		sc->sc_pr.blksize = vc->sc_mpr.blksize;
 		sc->sc_rr.blksize = vc->sc_mrr.blksize;
 	} else {
@@ -5475,11 +5484,13 @@
 
 	if (sc->hw_if->trigger_input && sc->sc_rec_started == false) {
 		DPRINTF(("%s: call trigger_input\n", __func__));
+		sc->sc_rec_started = true;
 		error = sc->hw_if->trigger_input(sc->hw_hdl, vc->sc_mrr.s.start,
 		    vc->sc_mrr.s.end, blksize,
 		    audio_rint, (void *)sc, &vc->sc_mrr.s.param);
 	} else if (sc->hw_if->start_input) {
 		DPRINTF(("%s: call start_input\n", __func__));
+		sc->sc_rec_started = true;
 		error = sc->hw_if->start_input(sc->hw_hdl,
 		    vc->sc_mrr.s.inp, blksize,
 		    audio_rint, (void *)sc);
@@ -5488,8 +5499,8 @@
 		/* XXX does this really help? */
 		DPRINTF(("audio_upmix restart failed: %d\n", error));
 		audio_clear(sc, SIMPLEQ_FIRST(&sc->sc_audiochan)->vc);
-	}
-	sc->sc_rec_started = true;
+		sc->sc_rec_started = false;
+	}
 
 	inp = vc->sc_mrr.s.inp;
 	vc->sc_mrr.s.inp = audio_stream_add_inp(&vc->sc_mrr.s, inp, cc);
@@ -5536,6 +5547,9 @@
 	cc = blksize;
 	error = 0;
 
+	if (audio_stream_get_used(vc->sc_pustream) > blksize)
+		goto done;
+
 	tocopy = vc->sc_pustream->inp;
 	orig = __UNCONST(sc->sc_pr.s.outp);
 	used = blksize;
@@ -5566,6 +5580,7 @@
 	sc->sc_pr.s.outp = audio_stream_add_outp(&sc->sc_pr.s,