CVS commit: src/sys/arch/arm/arm

2021-02-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 17 06:54:23 UTC 2021

Modified Files:
src/sys/arch/arm/arm: idle_machdep.c

Log Message:
Trailing whitespace. *snigger*


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/arm/idle_machdep.c

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



CVS commit: src/sys/arch/arm/arm

2021-02-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 17 06:54:23 UTC 2021

Modified Files:
src/sys/arch/arm/arm: idle_machdep.c

Log Message:
Trailing whitespace. *snigger*


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/arm/idle_machdep.c

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

Modified files:

Index: src/sys/arch/arm/arm/idle_machdep.c
diff -u src/sys/arch/arm/arm/idle_machdep.c:1.5 src/sys/arch/arm/arm/idle_machdep.c:1.6
--- src/sys/arch/arm/arm/idle_machdep.c:1.5	Sun Aug 18 06:28:18 2013
+++ src/sys/arch/arm/arm/idle_machdep.c	Wed Feb 17 06:54:23 2021
@@ -1,11 +1,11 @@
-/*	$NetBSD: idle_machdep.c,v 1.5 2013/08/18 06:28:18 matt Exp $	*/
+/*	$NetBSD: idle_machdep.c,v 1.6 2021/02/17 06:54:23 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Nick Hudson 
+ * by Nick Hudson
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: idle_machdep.c,v 1.5 2013/08/18 06:28:18 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: idle_machdep.c,v 1.6 2021/02/17 06:54:23 skrll Exp $");
 
 #include 
 #include 



CVS commit: src/sys/arch/x86/x86

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb 17 06:33:48 UTC 2021

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
x86/tsc: fix double space in warning about TSC going backwards


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/tsc.c

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

Modified files:

Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.52 src/sys/arch/x86/x86/tsc.c:1.53
--- src/sys/arch/x86/x86/tsc.c:1.52	Mon Jun 15 20:27:30 2020
+++ src/sys/arch/x86/x86/tsc.c	Wed Feb 17 06:33:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.52 2020/06/15 20:27:30 riastradh Exp $	*/
+/*	$NetBSD: tsc.c,v 1.53 2021/02/17 06:33:47 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.52 2020/06/15 20:27:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.53 2021/02/17 06:33:47 rillig Exp $");
 
 #include 
 #include 
@@ -424,8 +424,9 @@ tsc_get_timecount(struct timecounter *tc
 		__cpu_simple_lock_try()) {
 			ticks = getticks();
 			if (ticks - lastwarn >= hz) {
-printf("WARNING: TSC time went backwards "
-" by %u\n", (unsigned)(prev - cur));
+printf(
+"WARNING: TSC time went backwards by %u\n",
+(unsigned)(prev - cur));
 lastwarn = ticks;
 			}
 			__cpu_simple_unlock();



CVS commit: src/sys/arch/x86/x86

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb 17 06:33:48 UTC 2021

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
x86/tsc: fix double space in warning about TSC going backwards


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/tsc.c

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



CVS commit: src/sys/dev/usb

2021-02-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Feb 17 06:30:57 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Expose more descriptor items as device properties.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/dev/usb/usb_subr.c

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

Modified files:

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.248 src/sys/dev/usb/usb_subr.c:1.249
--- src/sys/dev/usb/usb_subr.c:1.248	Thu Jun 11 02:39:30 2020
+++ src/sys/dev/usb/usb_subr.c	Wed Feb 17 06:30:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.248 2020/06/11 02:39:30 thorpej Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.249 2021/02/17 06:30:57 mlelstv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.248 2020/06/11 02:39:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.249 2021/02/17 06:30:57 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -862,10 +862,36 @@ usbd_attach_roothub(device_t parent, str
 }
 
 static void
-usbd_serialnumber(device_t dv, struct usbd_device *dev)
+usbd_properties(device_t dv, struct usbd_device *dev)
 {
+	usb_device_descriptor_t *dd = >ud_ddesc;
+	prop_dictionary_t dict = device_properties(dv);
+	int class, subclass, release, proto, vendor, product;
+
+	class = dd->bDeviceClass;
+	subclass = dd->bDeviceSubClass;
+	release = UGETW(dd->bcdDevice);
+	proto = dd->bDeviceProtocol;
+	vendor = UGETW(dd->idVendor);
+	product = UGETW(dd->idProduct);
+
+	prop_dictionary_set_uint16(dict, "class", class);
+	prop_dictionary_set_uint16(dict, "subclass", subclass);
+	prop_dictionary_set_uint16(dict, "release", release);
+	prop_dictionary_set_uint16(dict, "proto", proto);
+	prop_dictionary_set_uint16(dict, "vendor", vendor);
+	prop_dictionary_set_uint16(dict, "product", product);
+
+	if (dev->ud_vendor) {
+		prop_dictionary_set_string(dict,
+		"vendor-string", dev->ud_vendor);
+	}
+	if (dev->ud_product) {
+		prop_dictionary_set_string(dict,
+		"product-string", dev->ud_product);
+	}
 	if (dev->ud_serial) {
-		prop_dictionary_set_string(device_properties(dv),
+		prop_dictionary_set_string(dict,
 		"serialnumber", dev->ud_serial);
 	}
 }
@@ -907,7 +933,7 @@ usbd_attachwholedevice(device_t parent, 
 		dev->ud_subdevs[0] = dv;
 		dev->ud_subdevlen = 1;
 		dev->ud_nifaces_claimed = 1; /* XXX */
-		usbd_serialnumber(dv, dev);
+		usbd_properties(dv, dev);
 	}
 	config_pending_decr(parent);
 	return USBD_NORMAL_COMPLETION;
@@ -983,7 +1009,7 @@ usbd_attachinterfaces(device_t parent, s
 		if (!dv)
 			continue;
 
-		usbd_serialnumber(dv, dev);
+		usbd_properties(dv, dev);
 
 		/* claim */
 		ifaces[i] = NULL;



CVS commit: src/sys/dev/usb

2021-02-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Feb 17 06:30:57 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Expose more descriptor items as device properties.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/dev/usb/usb_subr.c

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



CVS commit: src/sys/kern

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb 17 06:25:11 UTC 2021

Modified Files:
src/sys/kern: makesyscalls.sh systrace_args.c

Log Message:
makesyscalls.sh: fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/kern/makesyscalls.sh
cvs rdiff -u -r1.44 -r1.45 src/sys/kern/systrace_args.c

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

Modified files:

Index: src/sys/kern/makesyscalls.sh
diff -u src/sys/kern/makesyscalls.sh:1.182 src/sys/kern/makesyscalls.sh:1.183
--- src/sys/kern/makesyscalls.sh:1.182	Tue Sep 29 02:58:53 2020
+++ src/sys/kern/makesyscalls.sh	Wed Feb 17 06:25:10 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: makesyscalls.sh,v 1.182 2020/09/29 02:58:53 msaitoh Exp $
+#	$NetBSD: makesyscalls.sh,v 1.183 2021/02/17 06:25:10 rillig Exp $
 #
 # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
 # All rights reserved.
@@ -274,7 +274,7 @@ BEGIN {
 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
 
 	printf "/* %s */\n\n", tag > systrace
-	printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
+	printf "/*\n * System call argument to DTrace register array conversion.\n *\n" > systrace
 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
 }
 NR == 1 {

Index: src/sys/kern/systrace_args.c
diff -u src/sys/kern/systrace_args.c:1.44 src/sys/kern/systrace_args.c:1.45
--- src/sys/kern/systrace_args.c:1.44	Mon Nov  2 18:56:16 2020
+++ src/sys/kern/systrace_args.c	Wed Feb 17 06:25:10 2021
@@ -1,7 +1,7 @@
-/* $NetBSD: systrace_args.c,v 1.44 2020/11/02 18:56:16 christos Exp $ */
+/* $NetBSD: systrace_args.c,v 1.45 2021/02/17 06:25:10 rillig Exp $ */
 
 /*
- * System call argument to DTrace register array converstion.
+ * System call argument to DTrace register array conversion.
  *
  * DO NOT EDIT-- this file is automatically generated.
  * This file is part of the DTrace syscall provider.



CVS commit: src/sys/kern

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb 17 06:25:11 UTC 2021

Modified Files:
src/sys/kern: makesyscalls.sh systrace_args.c

Log Message:
makesyscalls.sh: fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/kern/makesyscalls.sh
cvs rdiff -u -r1.44 -r1.45 src/sys/kern/systrace_args.c

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



CVS commit: src/external/mit/xorg/bin/xterm

2021-02-16 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Feb 17 03:06:07 UTC 2021

Modified Files:
src/external/mit/xorg/bin/xterm: Makefile

Log Message:
remove -DOPT_* from here (now in xtermcfg.h).

restore comment lost in rev 1.18.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/external/mit/xorg/bin/xterm/Makefile

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

Modified files:

Index: src/external/mit/xorg/bin/xterm/Makefile
diff -u src/external/mit/xorg/bin/xterm/Makefile:1.20 src/external/mit/xorg/bin/xterm/Makefile:1.21
--- src/external/mit/xorg/bin/xterm/Makefile:1.20	Thu Feb 11 12:30:08 2021
+++ src/external/mit/xorg/bin/xterm/Makefile	Wed Feb 17 03:06:07 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.20 2021/02/11 12:30:08 mrg Exp $
+#	$NetBSD: Makefile,v 1.21 2021/02/17 03:06:07 mrg Exp $
 
 .include 
 
@@ -10,6 +10,9 @@ SRCS=	button.c charproc.c charsets.c cur
 	charclass.c precompose.c wcwidth.c xutf8.c cachedGCs.c xtermcap.c \
 	svg.c html.c version.c
 
+# XXX
+# xterm.appdata.xml
+
 CPPFLAGS+=	-I. \
 		-I${X11SRCDIR.${PROG}} \
 		-I${X11SRCDIR.${PROG}}/../include \
@@ -17,8 +20,6 @@ CPPFLAGS+=	-I. \
 		-I${DESTDIR}${X11INCDIR}/freetype2/freetype \
 		-DPROJECTROOT=${X11ROOTDIR} \
 		-DHAVE_CONFIG_H \
-		-DOPT_GRAPHICS \
-		-DOPT_SIXEL_GRAPHICS \
 		-D_REENTRANT \
 		${X11FLAGS.VERSION}
 



CVS commit: src/external/mit/xorg/bin/xterm

2021-02-16 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Feb 17 03:06:07 UTC 2021

Modified Files:
src/external/mit/xorg/bin/xterm: Makefile

Log Message:
remove -DOPT_* from here (now in xtermcfg.h).

restore comment lost in rev 1.18.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/external/mit/xorg/bin/xterm/Makefile

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



CVS commit: xsrc/external/mit/xterm/include

2021-02-16 Thread matthew green
Module Name:xsrc
Committed By:   mrg
Date:   Wed Feb 17 03:03:28 UTC 2021

Modified Files:
xsrc/external/mit/xterm/include: xtermcfg.h

Log Message:
define OPT_SIXEL_GRAPHICS here like everything else, rather than
than Makefile.  (OPT_GRAPHICS is already defined here.)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 xsrc/external/mit/xterm/include/xtermcfg.h

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

Modified files:

Index: xsrc/external/mit/xterm/include/xtermcfg.h
diff -u xsrc/external/mit/xterm/include/xtermcfg.h:1.14 xsrc/external/mit/xterm/include/xtermcfg.h:1.15
--- xsrc/external/mit/xterm/include/xtermcfg.h:1.14	Thu Feb 11 12:24:39 2021
+++ xsrc/external/mit/xterm/include/xtermcfg.h	Wed Feb 17 03:03:27 2021
@@ -182,7 +182,7 @@
 /* #undef OPT_SELECTION_OPS */	/* CF_ARG_DISABLE(selection-ops) */
 #define OPT_SELECT_REGEX 1		/* CF_ARG_DISABLE(regex) */
 /* #undef OPT_SESSION_MGT */		/* CF_ARG_DISABLE(session-mgt) */
-/* #undef OPT_SIXEL_GRAPHICS */	/* CF_ARG_ENABLE(sixel-graphics) */
+#define OPT_SIXEL_GRAPHICS 1	/* CF_ARG_ENABLE(sixel-graphics) */
 /* #undef OPT_SUN_FUNC_KEYS */	/* CF_ARG_ENABLE(sun-fkeys) */
 #define OPT_TCAP_FKEYS 1		/* CF_ARG_ENABLE(tcap-fkeys) */
 #define OPT_TCAP_QUERY 1		/* CF_ARG_ENABLE(tcap-query) */



CVS commit: xsrc/external/mit/xterm/include

2021-02-16 Thread matthew green
Module Name:xsrc
Committed By:   mrg
Date:   Wed Feb 17 03:03:28 UTC 2021

Modified Files:
xsrc/external/mit/xterm/include: xtermcfg.h

Log Message:
define OPT_SIXEL_GRAPHICS here like everything else, rather than
than Makefile.  (OPT_GRAPHICS is already defined here.)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 xsrc/external/mit/xterm/include/xtermcfg.h

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



Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Valery Ushakov
On Tue, Feb 16, 2021 at 18:51:43 -0500, Christos Zoulas wrote:

> On Feb 17,  2:20am, u...@stderr.spb.ru (Valery Ushakov) wrote:
> -- Subject: Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)
> 
> | Well, it was you who did the definion of ALIGNED_POINTER centralized
> | and overridable :)
> | 
> |   revision 1.400
> |   date: 2012-01-25 00:03:36 +0400;  author: christos;  state: Exp;  lines: 
> +26 -1;
> |   Use and define ALIGN() ALIGN_POINTER() and STACK_ALIGN() consistently,
> |   and avoid definining them in 10 different places if not needed.
> 
> If you look a bit deeper into that change, it merged many MD copies
> of this macro into one, and I needed the override for the archs that
> were different.
> 
> | ALIGNED_POINTER is overriden on x86 to be always true.  Surprisingly
> | it is not overriden for m68k and vax that are __NO_STRICT_ALIGNMENT.
> | That is most likely an oversight, but that will probably require some
> | cvs archaeology to confirm.  Some uses of ALIGNED_POINTER are inside
> | an __NO_STRICT_ALIGNMENT #ifdef.
> 
> This is a mess as you can see. The problem is that in each case we
> need to determine if this macro is used to test alignment to determine
> access restrictions on certain architectures (most cases), or it
> is done for performance/protocol requirements.
> 
> I hope that nothing falls into the second category and then we can
> use a single macro that uses a combination of __NO_STRICT_ALIGNMENT
> and __alignof() which my guess is that it did not exist at the time
> the macro was invented, and thus it used sizeof() and limited it to
> integral types.
> 
> | We don't even seem to be sure about its semantics, as far as I can
> | tell (see bus space comments in my mail).
> | 
> | That's even more of a reason to stop doing aimless random changes
> | without getting some kind of understanding first.  The last thing we
> | need is ALIGNED_POINTER and POINTER_ALIGNED macros with slighly
> | different semantics both of which are counter-intuitive to begin with
> | (and riastradh@ even had to add a verbose comment for that).
> 
> This change was not aimless. I wanted to remove the multiple copies of
> the m_copyup/m_pullup code into one function. To do that I needed the
> alignment as a value, not a predicate macro (that was again copied in
> ~10 places). When I tried to centralize it, I wanted to do the minimal
> change so I would not screw it up (and I did end up screwing it up).
> 
> This is a good opportunity now to clean this up even more and provide
> sane alignment macros.

We should start by at least separating the concerns.  The test for
"aligned at power of two boundary" and the actual intent/purpose of
that test ("stuff needs to be aligned for us to safely do $FOO").
Then we can test the alignment check without jumping through
ridiculous hoops.  That should have been done earlier for the
ALIGNED_POINTER change, but yeah, I can see how in the heat of the
moment that change was just "preserve the status quo" and that's
absolutely fine.  But doing the same thing now with the alignment test
and the purpose of that alignment test conflacted once again under a
different but confusignly similar name is negligent (if anything we
will run out of half way decent names for the just-the-alignment-test
macro, b/c all of them will be loaded with some additional accidental
semantic).


-uwe


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Valery Ushakov
On Wed, Feb 17, 2021 at 00:51:03 +0100, Roland Illig wrote:

> 17.02.2021 00:25:10 Valery Ushakov :
> > On Tue, Feb 16, 2021 at 23:54:46 +0100, Roland Illig wrote:
> >> Yes, it does.  That's what the "#undef __NO_STRICT_ALIGNMENT" in the
> >> test is for.
> >>
> >> I intentionally placed it between  (which defines that
> >> macro on x86 and some other platforms) and  (which uses the
> >> macro to switch between the boring "everything is correctly aligned" and
> >> the more interesting formula suggested here.
> >
> > This is wrong on so many levels.  What is even the point of a test
> > that doesn't test the thing as it is actually defined and used in the
> > code?
> 
> The point of the test is to verify that the "complicated" formula
> produces correct results.  That's what several commits tried to
> fix.  If this test had been there from the beginning, none of the
> wrong formulas would have passed it.  That's the whole point.
> 
> The point of the test was intentionally not to test the actual
> behavior on each platform but to test the same formula, independent
> from the platform, and to do this, I somehow needed access to that
> formula.  Testing the actually used formula per platform could be
> added as another test.  I just wanted to avoid the obviously wrong
> formulas to go unnoticed in the code.  That's the point of the test,
> and that's exactly what it achieves.  Therefore I don't see anything
> wrong with it.

The very fact that you need to undefine an unspecified macro at an
unspecified time to get to the "formula" points to a problem.  We
shouldn't be pretending that it's not, and provide the false decorum
of "oh, but it's covered with a test, so it's ok".

-uwe


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Christos Zoulas
On Feb 17,  2:20am, u...@stderr.spb.ru (Valery Ushakov) wrote:
-- Subject: Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

| Well, it was you who did the definion of ALIGNED_POINTER centralized
| and overridable :)
| 
|   revision 1.400
|   date: 2012-01-25 00:03:36 +0400;  author: christos;  state: Exp;  lines: 
+26 -1;
|   Use and define ALIGN() ALIGN_POINTER() and STACK_ALIGN() consistently,
|   and avoid definining them in 10 different places if not needed.

If you look a bit deeper into that change, it merged many MD copies
of this macro into one, and I needed the override for the archs that
were different.

| ALIGNED_POINTER is overriden on x86 to be always true.  Surprisingly
| it is not overriden for m68k and vax that are __NO_STRICT_ALIGNMENT.
| That is most likely an oversight, but that will probably require some
| cvs archaeology to confirm.  Some uses of ALIGNED_POINTER are inside
| an __NO_STRICT_ALIGNMENT #ifdef.

This is a mess as you can see. The problem is that in each case we
need to determine if this macro is used to test alignment to determine
access restrictions on certain architectures (most cases), or it
is done for performance/protocol requirements.

I hope that nothing falls into the second category and then we can
use a single macro that uses a combination of __NO_STRICT_ALIGNMENT
and __alignof() which my guess is that it did not exist at the time
the macro was invented, and thus it used sizeof() and limited it to
integral types.

| We don't even seem to be sure about its semantics, as far as I can
| tell (see bus space comments in my mail).
| 
| That's even more of a reason to stop doing aimless random changes
| without getting some kind of understanding first.  The last thing we
| need is ALIGNED_POINTER and POINTER_ALIGNED macros with slighly
| different semantics both of which are counter-intuitive to begin with
| (and riastradh@ even had to add a verbose comment for that).

This change was not aimless. I wanted to remove the multiple copies of
the m_copyup/m_pullup code into one function. To do that I needed the
alignment as a value, not a predicate macro (that was again copied in
~10 places). When I tried to centralize it, I wanted to do the minimal
change so I would not screw it up (and I did end up screwing it up).

This is a good opportunity now to clean this up even more and provide
sane alignment macros.

christos


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Roland Illig
17.02.2021 00:25:10 Valery Ushakov :
> On Tue, Feb 16, 2021 at 23:54:46 +0100, Roland Illig wrote:
>> Yes, it does.  That's what the "#undef __NO_STRICT_ALIGNMENT" in the
>> test is for.
>>
>> I intentionally placed it between  (which defines that
>> macro on x86 and some other platforms) and  (which uses the
>> macro to switch between the boring "everything is correctly aligned" and
>> the more interesting formula suggested here.
>
> This is wrong on so many levels.  What is even the point of a test
> that doesn't test the thing as it is actually defined and used in the
> code?

The point of the test is to verify that the "complicated" formula produces 
correct results.  That's what several commits tried to fix.  If this test had 
been there from the beginning, none of the wrong formulas would have passed it. 
 That's the whole point.

The point of the test was intentionally not to test the actual behavior on each 
platform but to test the same formula, independent from the platform, and to do 
this, I somehow needed access to that formula.  Testing the actually used 
formula per platform could be added as another test.  I just wanted to avoid 
the obviously wrong formulas to go unnoticed in the code.  That's the point of 
the test, and that's exactly what it achieves.  Therefore I don't see anything 
wrong with it.

Roland


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Roland Illig

On 16.02.2021 23:32, Jason Thorpe wrote:



On Feb 16, 2021, at 1:56 PM, Roland Illig  wrote:

A downside of this test is that the macro from  gets only
evaluated at compile time of the test.  The test therefore cannot cover
future updates to  without being reinstalled itself.  But
at least for the release builds, it ensures a correct definition.


You can make this get evaluated at run-time by passing in a non-constant 
argument.


I wanted to make the test even more flexible: react to the then-current
installed version of the macro in .  To do that, the test
would need to be compiled at runtime, requiring a C compiler on the
target machine, and I'm not sure that's a valid assumption.

And maybe that's something that shouldn't be done at all, updating the
system header without the corresponding test suite.  So it's probably
fine as it is now, notwithstanding the discussion about whether the
macro is needed at all in this prominent place.

It surprised me though that neither Google nor GitHub found the macro
name POINTER_ALIGNED_P anywhere outside the NetBSD repository.  I would
have expected this name to be already used by some projects, given that
it is so straight-forward.

Roland


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Valery Ushakov
On Tue, Feb 16, 2021 at 17:53:09 -0500, Christos Zoulas wrote:

> In this case "type" is a struct and we have __alignof() to handle
> it, but does this give the right answer?
> 
> Also ALIGNED_POINTER is not conditional to __NO_STRICT_ALIGNMENT and
> can be overriden (the opposite goes for POINTER_ALIGNED_P) I am all
> for having one macro, but how can we satisfy all the different
> semantics?

Well, it was you who did the definion of ALIGNED_POINTER centralized
and overridable :)

  revision 1.400
  date: 2012-01-25 00:03:36 +0400;  author: christos;  state: Exp;  lines: +26 
-1;
  Use and define ALIGN() ALIGN_POINTER() and STACK_ALIGN() consistently,
  and avoid definining them in 10 different places if not needed.

ALIGNED_POINTER is overriden on x86 to be always true.  Surprisingly
it is not overriden for m68k and vax that are __NO_STRICT_ALIGNMENT.
That is most likely an oversight, but that will probably require some
cvs archaeology to confirm.  Some uses of ALIGNED_POINTER are inside
an __NO_STRICT_ALIGNMENT #ifdef.

We don't even seem to be sure about its semantics, as far as I can
tell (see bus space comments in my mail).

That's even more of a reason to stop doing aimless random changes
without getting some kind of understanding first.  The last thing we
need is ALIGNED_POINTER and POINTER_ALIGNED macros with slighly
different semantics both of which are counter-intuitive to begin with
(and riastradh@ even had to add a verbose comment for that).


-uwe


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Valery Ushakov
On Tue, Feb 16, 2021 at 23:54:46 +0100, Roland Illig wrote:

> On 16.02.2021 23:40, Valery Ushakov wrote:
> > On Tue, Feb 16, 2021 at 22:56:19 +0100, Roland Illig wrote:
> > 
> > > On 16.02.2021 19:46, Roy Marples wrote:
> > > > I suggest we change POINTER_ALIGNED_P to accept the alignment value we
> > > > want rather than the bitwise test we supply, like so:
> > > > 
> > > > #define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)))
> > > 
> > > To make sure that this macro doesn't get broken again, I have written
> > > the attached tests.  I will commit them after making sure I got the
> > > changes to distrib/sets/lists/tests/mi correct.  All the rest I already
> > > tested successfully.
> > 
> > I don't see any proposal to change the meaning of this macro to
> > actually require the alignment even for arches without strict
> > alignment.  Does the attached test really passes on e.g. x86 where the
> > macro is always true?  E.g. this one:
> > 
> > > + if (POINTER_ALIGNED_P(p + 1, 2))
> > > + atf_tc_fail("p + 1 must not be aligned to 2");
> 
> Yes, it does.  That's what the "#undef __NO_STRICT_ALIGNMENT" in the
> test is for.
> 
> I intentionally placed it between  (which defines that
> macro on x86 and some other platforms) and  (which uses the
> macro to switch between the boring "everything is correctly aligned" and
> the more interesting formula suggested here.

This is wrong on so many levels.  What is even the point of a test
that doesn't test the thing as it is actually defined and used in the
code?

-uwe


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Roland Illig

On 16.02.2021 23:40, Valery Ushakov wrote:

On Tue, Feb 16, 2021 at 22:56:19 +0100, Roland Illig wrote:


On 16.02.2021 19:46, Roy Marples wrote:

I suggest we change POINTER_ALIGNED_P to accept the alignment value we
want rather than the bitwise test we supply, like so:

#define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)))


To make sure that this macro doesn't get broken again, I have written
the attached tests.  I will commit them after making sure I got the
changes to distrib/sets/lists/tests/mi correct.  All the rest I already
tested successfully.


I don't see any proposal to change the meaning of this macro to
actually require the alignment even for arches without strict
alignment.  Does the attached test really passes on e.g. x86 where the
macro is always true?  E.g. this one:


+   if (POINTER_ALIGNED_P(p + 1, 2))
+   atf_tc_fail("p + 1 must not be aligned to 2");


Yes, it does.  That's what the "#undef __NO_STRICT_ALIGNMENT" in the
test is for.

I intentionally placed it between  (which defines that
macro on x86 and some other platforms) and  (which uses the
macro to switch between the boring "everything is correctly aligned" and
the more interesting formula suggested here.


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Christos Zoulas
In this case "type" is a struct and we have __alignof() to handle it, but does 
this give the
right answer? Also ALIGNED_POINTER is not conditional to __NO_STRICT_ALIGNMENT
and can be overriden (the opposite goes for POINTER_ALIGNED_P)  I am all for 
having one
macro, but how can we satisfy all the different semantics?

christos


signature.asc
Description: Message signed with OpenPGP


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Valery Ushakov
On Tue, Feb 16, 2021 at 22:56:19 +0100, Roland Illig wrote:

> On 16.02.2021 19:46, Roy Marples wrote:
> > I suggest we change POINTER_ALIGNED_P to accept the alignment value we
> > want rather than the bitwise test we supply, like so:
> > 
> > #define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)))
> 
> That's a good definition, clear, simple, obvious, without any surprises.

Now, replace the value "a" with the type "t" and change (a) to
sizeof(t) and you will get ALIGNED_POINTER from just above.


> To make sure that this macro doesn't get broken again, I have written
> the attached tests.  I will commit them after making sure I got the
> changes to distrib/sets/lists/tests/mi correct.  All the rest I already
> tested successfully.

I don't see any proposal to change the meaning of this macro to
actually require the alignment even for arches without strict
alignment.  Does the attached test really passes on e.g. x86 where the
macro is always true?  E.g. this one:

> + if (POINTER_ALIGNED_P(p + 1, 2))
> + atf_tc_fail("p + 1 must not be aligned to 2");


> Is my assumption correct that on each platform supported by NetBSD, a
> variable of type double gets aligned to a multiple of 8, even on the
> stack?

No.  E.g. on sh3 doubles are 8 bytes but are 4 bytes aligned.  I'm
almost sure some other ABI has that kind less strict alignment too,
but I don't remember.


> I wanted to keep the test as simple as possible, therefore I
> didn't want to call malloc just to get an aligned pointer.

You can use an ordinary array that is large enough and manually
find/construct a suitably aligned pointer value inside that array.


BUT, can we, PLEASE, stop making random breaking changes and at least
articulate first what is that that we want here?

POINTER_ALIGNED_P should have never been brought into existence in the
first place.

ALIGNED_POINTER seems to be used to define BUS_SPACE_ALIGNED_POINTER -
the real fun here is sys/arch/x86/include/bus_defs.h that defines
BUS_SPACE_ALIGNED_POINTER to be "really" aligned for BUS_SPACE_DEBUG,
which seems kinda suspicious to me.  BTW, can we really conclude from
the CPU's alignment requirements to some bus alignment requirements?

But to get back to my main point, PLEASE, can we stop making random
aimless changes without prior discussion?

To quote Vonnegut, "If I had of been a observer, I would of said we
was comical."


-uwe


Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Jason Thorpe


> On Feb 16, 2021, at 1:56 PM, Roland Illig  wrote:
> 
> A downside of this test is that the macro from  gets only
> evaluated at compile time of the test.  The test therefore cannot cover
> future updates to  without being reinstalled itself.  But
> at least for the release builds, it ensures a correct definition.

You can make this get evaluated at run-time by passing in a non-constant 
argument.

-- thorpej



CVS commit: src/sys/arch/arm/pic

2021-02-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb 16 22:12:50 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c pic_splfuncs.c

Log Message:
pic: avoid pic_do_pending_ints if pic_mark_pending_* has never been called


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/pic/pic_splfuncs.c

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



CVS commit: src/sys/arch/arm/pic

2021-02-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb 16 22:12:50 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c pic_splfuncs.c

Log Message:
pic: avoid pic_do_pending_ints if pic_mark_pending_* has never been called


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/pic/pic_splfuncs.c

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

Modified files:

Index: src/sys/arch/arm/pic/pic.c
diff -u src/sys/arch/arm/pic/pic.c:1.64 src/sys/arch/arm/pic/pic.c:1.65
--- src/sys/arch/arm/pic/pic.c:1.64	Mon Feb 15 16:32:07 2021
+++ src/sys/arch/arm/pic/pic.c	Tue Feb 16 22:12:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.c,v 1.64 2021/02/15 16:32:07 jmcneill Exp $	*/
+/*	$NetBSD: pic.c,v 1.65 2021/02/16 22:12:49 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.64 2021/02/15 16:32:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.65 2021/02/16 22:12:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -59,6 +59,9 @@ __KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.64
 #include 
 
 #if defined(__HAVE_PIC_PENDING_INTRS)
+
+bool pic_pending_used __read_mostly = false;
+
 /*
  * This implementation of pending interrupts on a MULTIPROCESSOR system makes
  * the assumption that a PIC (pic_softc) shall only have all its interrupts
@@ -279,6 +282,9 @@ pic_mark_pending_source(struct pic_softc
 {
 	const uint32_t ipl_mask = __BIT(is->is_ipl);
 
+	if (!pic_pending_used)
+		pic_pending_used = true;
+
 	atomic_or_32(>pic_pending_irqs[is->is_irq >> 5],
 	__BIT(is->is_irq & 0x1f));
 
@@ -309,6 +315,9 @@ pic_mark_pending_sources(struct pic_soft
 	volatile uint32_t *ipending = >pic_pending_irqs[irq_base >> 5];
 	uint32_t ipl_mask = 0;
 
+	if (!pic_pending_used)
+		pic_pending_used = true;
+
 	if (pending == 0)
 		return ipl_mask;
 

Index: src/sys/arch/arm/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.12 src/sys/arch/arm/pic/pic_splfuncs.c:1.13
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.12	Mon Feb 15 16:32:07 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Tue Feb 16 22:12:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.12 2021/02/15 16:32:07 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.13 2021/02/16 22:12:50 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.12 2021/02/15 16:32:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.13 2021/02/16 22:12:50 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -46,6 +46,11 @@ __KERNEL_RCSID(0, "$NetBSD: pic_splfuncs
 
 #include 
 
+#if defined(__HAVE_PIC_PENDING_INTRS)
+extern bool pic_pending_used;
+#else
+#define pic_pending_used	false
+#endif
 
 int
 _splraise(int newipl)
@@ -65,12 +70,16 @@ _spllower(int newipl)
 	const int oldipl = ci->ci_cpl;
 	KASSERT(panicstr || newipl <= ci->ci_cpl);
 	if (newipl < ci->ci_cpl) {
-		register_t psw = cpsid(I32_bit);
-		ci->ci_intr_depth++;
-		pic_do_pending_ints(psw, newipl, NULL);
-		ci->ci_intr_depth--;
-		if ((psw & I32_bit) == 0 || newipl == IPL_NONE)
-			cpsie(I32_bit);
+		if (__predict_false(pic_pending_used)) {
+			register_t psw = cpsid(I32_bit);
+			ci->ci_intr_depth++;
+			pic_do_pending_ints(psw, newipl, NULL);
+			ci->ci_intr_depth--;
+			if ((psw & I32_bit) == 0 || newipl == IPL_NONE)
+cpsie(I32_bit);
+		} else {
+			pic_set_priority(ci, newipl);
+		}
 		cpu_dosoftints();
 	}
 	return oldipl;
@@ -86,21 +95,26 @@ splx(int savedipl)
 		return;
 	}
 
-	register_t psw = cpsid(I32_bit);
-	KASSERTMSG(panicstr != NULL || savedipl < ci->ci_cpl,
-	"splx(%d) to a higher ipl than %d", savedipl, ci->ci_cpl);
-
-	if ((psw & I32_bit) == 0) {
-		ci->ci_intr_depth++;
-		pic_do_pending_ints(psw, savedipl, NULL);
-		ci->ci_intr_depth--;
-		KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
-		ci->ci_cpl, savedipl);
+	if (__predict_false(pic_pending_used)) {
+		register_t psw = cpsid(I32_bit);
+		KASSERTMSG(panicstr != NULL || savedipl < ci->ci_cpl,
+		"splx(%d) to a higher ipl than %d", savedipl, ci->ci_cpl);
 
-		cpsie(I32_bit);
-		cpu_dosoftints();
+		if ((psw & I32_bit) == 0) {
+			ci->ci_intr_depth++;
+			pic_do_pending_ints(psw, savedipl, NULL);
+			ci->ci_intr_depth--;
+			KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
+			ci->ci_cpl, savedipl);
+
+			cpsie(I32_bit);
+			cpu_dosoftints();
+		} else {
+			pic_set_priority_psw(ci, psw, savedipl);
+		}
 	} else {
-		pic_set_priority_psw(ci, psw, savedipl);
+		pic_set_priority(ci, savedipl);
+		cpu_dosoftints();
 	}
 
 	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",



Re: POINTER_ALIGNED_P (was: Re: CVS commit: src/sys)

2021-02-16 Thread Roland Illig

On 16.02.2021 19:46, Roy Marples wrote:

I suggest we change POINTER_ALIGNED_P to accept the alignment value we
want rather than the bitwise test we supply, like so:

#define    POINTER_ALIGNED_P(p, a)    (((uintptr_t)(p) & ((a) - 1))


That's a good definition, clear, simple, obvious, without any surprises.

To make sure that this macro doesn't get broken again, I have written
the attached tests.  I will commit them after making sure I got the
changes to distrib/sets/lists/tests/mi correct.  All the rest I already
tested successfully.

Is my assumption correct that on each platform supported by NetBSD, a
variable of type double gets aligned to a multiple of 8, even on the
stack?  I wanted to keep the test as simple as possible, therefore I
didn't want to call malloc just to get an aligned pointer.

A downside of this test is that the macro from  gets only
evaluated at compile time of the test.  The test therefore cannot cover
future updates to  without being reinstalled itself.  But
at least for the release builds, it ensures a correct definition.

Roland
Index: distrib/sets/lists/tests/mi
===
RCS file: /cvsroot/src/distrib/sets/lists/tests/mi,v
retrieving revision 1.1019
diff -u -p -r1.1019 mi
--- distrib/sets/lists/tests/mi 16 Feb 2021 09:46:24 -  1.1019
+++ distrib/sets/lists/tests/mi 16 Feb 2021 21:45:40 -
@@ -4396,6 +4396,10 @@
 ./usr/tests/sys/rc/h_args  tests-sys-tests 
compattestfile,atf
 ./usr/tests/sys/rc/h_simpletests-sys-tests 
compattestfile,atf
 ./usr/tests/sys/rc/t_rc_d_cli  tests-sys-tests 
compattestfile,atf
+./usr/tests/sys/systests-sys-tests 
compattestfile,atf
+./usr/tests/sys/sys/Atffiletests-sys-tests 
compattestfile,atf
+./usr/tests/sys/sys/Kyuafile   tests-sys-tests 
compattestfile,atf,kyua
+./usr/tests/sys/sys/t_pointer_aligned_ptests-sys-tests 
compattestfile,atf
 ./usr/tests/sys/x86tests-sys-tests 
compattestfile,atf
 ./usr/tests/syscalltests-obsolete  
obsolete
 ./usr/tests/syscall/Atffiletests-obsolete  
obsolete
Index: tests/sys/Makefile
===
RCS file: /cvsroot/src/tests/sys/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- tests/sys/Makefile  15 Oct 2020 17:44:44 -  1.5
+++ tests/sys/Makefile  16 Feb 2021 21:45:40 -
@@ -10,6 +10,7 @@ TESTS_SUBDIRS+=   netatalk
 TESTS_SUBDIRS+=netinet
 TESTS_SUBDIRS+=netinet6
 TESTS_SUBDIRS+=rc
+TESTS_SUBDIRS+=sys
 .if ${MACHINE} == amd64 || ${MACHINE} == i386
 TESTS_SUBDIRS+=x86
 .endif
Index: tests/sys/sys/Makefile
===
RCS file: tests/sys/sys/Makefile
diff -N tests/sys/sys/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ tests/sys/sys/Makefile  16 Feb 2021 21:45:40 -
@@ -0,0 +1,11 @@
+# $NetBSD$
+
+TESTSDIR=  ${TESTSBASE}/sys/sys
+WARNS= 6
+
+TESTS_C=   t_pointer_aligned_p
+
+.PATH: ${NETBSDSRCDIR}/sys
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys
+
+.include 
Index: tests/sys/sys/t_pointer_aligned_p.c
===
RCS file: tests/sys/sys/t_pointer_aligned_p.c
diff -N tests/sys/sys/t_pointer_aligned_p.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ tests/sys/sys/t_pointer_aligned_p.c 16 Feb 2021 21:45:40 -
@@ -0,0 +1,77 @@
+/* $NetBSD$*/
+
+/*-
+ * Copyright (c) 2021 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 

CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:46:15 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: clean up VarAdd, Var_Delete, Var_ReexportVars

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.830 -r1.831 src/usr.bin/make/var.c

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.830 src/usr.bin/make/var.c:1.831
--- src/usr.bin/make/var.c:1.830	Tue Feb 16 17:41:23 2021
+++ src/usr.bin/make/var.c	Tue Feb 16 19:46:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.830 2021/02/16 17:41:23 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.831 2021/02/16 19:46:15 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.830 2021/02/16 17:41:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.831 2021/02/16 19:46:15 rillig Exp $");
 
 typedef enum VarFlags {
 	VFL_NONE	= 0,
@@ -486,18 +486,15 @@ VarFreeEnv(Var *v, Boolean freeValue)
 	return TRUE;
 }
 
-/*
- * Add a new variable of the given name and value to the given scope.
- * The name and val arguments are duplicated so they may safely be freed.
- */
+/* Add a new variable of the given name and value to the given scope. */
 static void
-VarAdd(const char *name, const char *val, GNode *scope, VarSetFlags flags)
+VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags)
 {
 	HashEntry *he = HashTable_CreateEntry(>vars, name, NULL);
-	Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), val,
+	Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), value,
 	flags & VAR_SET_READONLY ? VFL_READONLY : VFL_NONE);
 	HashEntry_Set(he, v);
-	DEBUG3(VAR, "%s:%s = %s\n", scope->name, name, val);
+	DEBUG3(VAR, "%s:%s = %s\n", scope->name, name, value);
 }
 
 /*
@@ -516,7 +513,7 @@ Var_Delete(GNode *scope, const char *var
 	}
 
 	DEBUG2(VAR, "%s:delete %s\n", scope->name, varname);
-	v = HashEntry_Get(he);
+	v = he->value;
 	if (v->flags & VFL_EXPORTED)
 		unsetenv(v->name.str);
 	if (strcmp(v->name.str, MAKE_EXPORTED) == 0)
@@ -717,7 +714,7 @@ Var_ReexportVars(void)
 	 * We allow the makefiles to update MAKELEVEL and ensure
 	 * children see a correctly incremented value.
 	 */
-	char tmp[BUFSIZ];
+	char tmp[21];
 	snprintf(tmp, sizeof tmp, "%d", makelevel + 1);
 	setenv(MAKE_LEVEL_ENV, tmp, 1);
 
@@ -727,7 +724,7 @@ Var_ReexportVars(void)
 	if (var_exportedVars == VAR_EXPORTED_ALL) {
 		HashIter hi;
 
-		/* Ouch! Exporting all variables at once is crazy... */
+		/* Ouch! Exporting all variables at once is crazy. */
 		HashIter_Init(, _GLOBAL->vars);
 		while (HashIter_Next() != NULL) {
 			Var *var = hi.entry->value;
@@ -752,6 +749,7 @@ Var_ReexportVars(void)
 
 static void
 ExportVars(const char *varnames, Boolean isExport, VarExportMode mode)
+/* TODO: try to combine the parameters 'isExport' and 'mode'. */
 {
 	Words words = Str_Words(varnames, FALSE);
 	size_t i;



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:46:15 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: clean up VarAdd, Var_Delete, Var_ReexportVars

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.830 -r1.831 src/usr.bin/make/var.c

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



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:43:09 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: varcmd.mk

Log Message:
make: document the bad state in which the test varcmd.mk is


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varcmd.mk

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



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:43:09 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: varcmd.mk

Log Message:
make: document the bad state in which the test varcmd.mk is


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varcmd.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/varcmd.mk
diff -u src/usr.bin/make/unit-tests/varcmd.mk:1.5 src/usr.bin/make/unit-tests/varcmd.mk:1.6
--- src/usr.bin/make/unit-tests/varcmd.mk:1.5	Sat Oct 24 08:50:17 2020
+++ src/usr.bin/make/unit-tests/varcmd.mk	Tue Feb 16 19:43:09 2021
@@ -1,6 +1,17 @@
-# $NetBSD: varcmd.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: varcmd.mk,v 1.6 2021/02/16 19:43:09 rillig Exp $
 #
 # Test behaviour of recursive make and vars set on command line.
+#
+# FIXME: The purpose of this test is unclear.  The test uses six levels of
+# sub-makes, which makes it incredibly hard to understand.  There must be at
+# least an introductory explanation about what _should_ happen here.
+# The variable names are terrible, as well as their values.
+#
+# This test produces different results if the large block with the condition
+# "scope == SCOPE_GLOBAL" in Var_SetWithFlags is removed.  This test should
+# be rewritten to make it clear why there is a difference and why this is
+# actually intended.  Removing that large block of code makes only this test
+# and vardebug.mk fail, which is not enough.
 
 FU=	fu
 FOO?=	foo
@@ -57,4 +68,3 @@ five:	show show-v
 
 six:	show-v
 	@${.MAKE} -f ${MAKEFILE} V=override show-v
-



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:01:18 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-export.mk

Log Message:
make: test exporting a variable that itself depends on a subprocess

When the point that "isn't going to end well" is reached, the stacktrace
is quite long but still reasonable:

main
main_ReadFiles
ReadAllMakefiles
ReadMakefiledirective-export.mk
Parse_File
ParseLine   # line 3 has: _!= :;:
ParseVarassign
Parse_DoVar
VarAssign_Eval
VarAssign_EvalShell # because of the '!='
Cmd_Exec:;:
Var_ReexportVars# before starting the subprocess
ExportVar   EMPTY_SHELL
ExportVarEnv# was only marked for export
Var_Subst   ${EMPTY_SHELL}  # to get the value to export
VarSubstExpr${EMPTY_SHELL}
Var_Parse   ${EMPTY_SHELL}
Var_Subst   ${:sh}  # since EMPTY_SHELL= ${:sh}
VarSubstExpr${:sh}
Var_Parse   ${:sh}
ApplyModifiers
ApplySingleModifier :sh
ApplyModifier
ApplyModifier_SunShell  :sh
Cmd_Exec""  # empty command
Var_ReexportVars
ExportVar   EMPTY_SHELL
ExportVarEnv# skipping this edge case


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/directive-export.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/directive-export.mk
diff -u src/usr.bin/make/unit-tests/directive-export.mk:1.7 src/usr.bin/make/unit-tests/directive-export.mk:1.8
--- src/usr.bin/make/unit-tests/directive-export.mk:1.7	Tue Feb 16 18:12:46 2021
+++ src/usr.bin/make/unit-tests/directive-export.mk	Tue Feb 16 19:01:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export.mk,v 1.7 2021/02/16 18:12:46 rillig Exp $
+# $NetBSD: directive-export.mk,v 1.8 2021/02/16 19:01:18 rillig Exp $
 #
 # Tests for the .export directive.
 #
@@ -34,5 +34,11 @@ VAR=		value $$ ${INDIRECT}
 # An empty argument means no additional variables to export.
 .export ${:U}
 
+
+# Trigger the "This isn't going to end well" in ExportVarEnv.
+EMPTY_SHELL=	${:sh}
+.export EMPTY_SHELL	# only marked for export at this point
+_!=		:;:	# Force the variable to be actually exported.
+
+
 all:
-	@:;



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 19:01:18 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-export.mk

Log Message:
make: test exporting a variable that itself depends on a subprocess

When the point that "isn't going to end well" is reached, the stacktrace
is quite long but still reasonable:

main
main_ReadFiles
ReadAllMakefiles
ReadMakefiledirective-export.mk
Parse_File
ParseLine   # line 3 has: _!= :;:
ParseVarassign
Parse_DoVar
VarAssign_Eval
VarAssign_EvalShell # because of the '!='
Cmd_Exec:;:
Var_ReexportVars# before starting the subprocess
ExportVar   EMPTY_SHELL
ExportVarEnv# was only marked for export
Var_Subst   ${EMPTY_SHELL}  # to get the value to export
VarSubstExpr${EMPTY_SHELL}
Var_Parse   ${EMPTY_SHELL}
Var_Subst   ${:sh}  # since EMPTY_SHELL= ${:sh}
VarSubstExpr${:sh}
Var_Parse   ${:sh}
ApplyModifiers
ApplySingleModifier :sh
ApplyModifier
ApplyModifier_SunShell  :sh
Cmd_Exec""  # empty command
Var_ReexportVars
ExportVar   EMPTY_SHELL
ExportVarEnv# skipping this edge case


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/directive-export.mk

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



Re: CVS commit: src/sys

2021-02-16 Thread Christos Zoulas
Yes, I agree. I am going to change that.

christos

> On Feb 16, 2021, at 1:46 PM, Roy Marples  wrote:
> 
> Hi Christos
> 
> On 14/02/2021 20:58, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Sun Feb 14 20:58:35 UTC 2021
>> Modified Files:
>>  src/sys/net: if_arp.h if_bridge.c
>>  src/sys/netinet: icmp_private.h if_arp.c igmp_var.h in_l2tp.c ip_flow.c
>>  ip_input.c ip_private.h tcp_input.c tcp_private.h udp_private.h
>>  udp_usrreq.c
>>  src/sys/netinet6: icmp6.c in6_l2tp.c ip6_flow.c ip6_input.c
>>  ip6_private.h udp6_usrreq.c
>>  src/sys/sys: mbuf.h param.h
>> Log Message:
>> - centralize header align and pullup into a single inline function
>> - use a single macro to align pointers and expose the alignment, instead
>>   of hard-coding 3 in 1/2 the macros.
>> - fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling
>>   for ipv6.
> 
> -#ifdef __NO_STRICT_ALIGNMENT
> -#define  IP_HDR_ALIGNED_P(ip)1
> -#else
> -#define  IP_HDR_ALIGNED_P(ip)vaddr_t) (ip)) & 3) == 0)
> -#endif
> +#define  IP_HDR_ALIGNMENT3
> #endif /* _KERNEL */
> 
> While this is a like for like change, I feel that the meaning of 
> IP_HDR_ALIGNMENT is no longer clear as 3 without context makes no sense at 
> all.
> We know it should be aligned to 4 bytes.
> 
> I suggest we change POINTER_ALIGNED_P to accept the alignment value we want 
> rather than the bitwise test we supply, like so:
> 
> #define   POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)) 
> == 0)
> 
> Roy



signature.asc
Description: Message signed with OpenPGP


Re: CVS commit: src/sys

2021-02-16 Thread Roy Marples

Hi Christos

On 14/02/2021 20:58, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Sun Feb 14 20:58:35 UTC 2021

Modified Files:
src/sys/net: if_arp.h if_bridge.c
src/sys/netinet: icmp_private.h if_arp.c igmp_var.h in_l2tp.c ip_flow.c
ip_input.c ip_private.h tcp_input.c tcp_private.h udp_private.h
udp_usrreq.c
src/sys/netinet6: icmp6.c in6_l2tp.c ip6_flow.c ip6_input.c
ip6_private.h udp6_usrreq.c
src/sys/sys: mbuf.h param.h

Log Message:
- centralize header align and pullup into a single inline function
- use a single macro to align pointers and expose the alignment, instead
   of hard-coding 3 in 1/2 the macros.
- fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling
   for ipv6.


-#ifdef __NO_STRICT_ALIGNMENT
-#defineIP_HDR_ALIGNED_P(ip)1
-#else
-#defineIP_HDR_ALIGNED_P(ip)vaddr_t) (ip)) & 3) == 0)
-#endif
+#defineIP_HDR_ALIGNMENT3
 #endif /* _KERNEL */

While this is a like for like change, I feel that the meaning of 
IP_HDR_ALIGNMENT is no longer clear as 3 without context makes no sense at all.

We know it should be aligned to 4 bytes.

I suggest we change POINTER_ALIGNED_P to accept the alignment value we want 
rather than the bitwise test we supply, like so:


#define POINTER_ALIGNED_P(p, a) (((uintptr_t)(p) & ((a) - 1)) == 0)

Roy


CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 18:12:46 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-export.mk

Log Message:
make: clarify what .export ${:U} means


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-export.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/directive-export.mk
diff -u src/usr.bin/make/unit-tests/directive-export.mk:1.6 src/usr.bin/make/unit-tests/directive-export.mk:1.7
--- src/usr.bin/make/unit-tests/directive-export.mk:1.6	Sun Dec 13 01:07:54 2020
+++ src/usr.bin/make/unit-tests/directive-export.mk	Tue Feb 16 18:12:46 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export.mk,v 1.6 2020/12/13 01:07:54 rillig Exp $
+# $NetBSD: directive-export.mk,v 1.7 2021/02/16 18:12:46 rillig Exp $
 #
 # Tests for the .export directive.
 #
@@ -28,8 +28,11 @@ VAR=		value $$ ${INDIRECT}
 .  error
 .endif
 
-# No argument means to export all variables.
+# No syntactical argument means to export all variables.
 .export
 
+# An empty argument means no additional variables to export.
+.export ${:U}
+
 all:
 	@:;



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 18:12:46 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-export.mk

Log Message:
make: clarify what .export ${:U} means


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-export.mk

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



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 18:02:19 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-undef.exp directive-undef.mk

Log Message:
make: demonstrate inconsistency in .undef of an exported variable


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-undef.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/directive-undef.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/directive-undef.exp
diff -u src/usr.bin/make/unit-tests/directive-undef.exp:1.5 src/usr.bin/make/unit-tests/directive-undef.exp:1.6
--- src/usr.bin/make/unit-tests/directive-undef.exp:1.5	Tue Dec 22 20:10:21 2020
+++ src/usr.bin/make/unit-tests/directive-undef.exp	Tue Feb 16 18:02:19 2021
@@ -1,5 +1,6 @@
 make: "directive-undef.mk" line 29: The .undef directive requires an argument
 make: "directive-undef.mk" line 86: Unknown modifier 'Z'
+make: "directive-undef.mk" line 103: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/directive-undef.mk
diff -u src/usr.bin/make/unit-tests/directive-undef.mk:1.9 src/usr.bin/make/unit-tests/directive-undef.mk:1.10
--- src/usr.bin/make/unit-tests/directive-undef.mk:1.9	Tue Dec 22 20:10:21 2020
+++ src/usr.bin/make/unit-tests/directive-undef.mk	Tue Feb 16 18:02:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-undef.mk,v 1.9 2020/12/22 20:10:21 rillig Exp $
+# $NetBSD: directive-undef.mk,v 1.10 2021/02/16 18:02:19 rillig Exp $
 #
 # Tests for the .undef directive.
 #
@@ -86,5 +86,22 @@ ${DOLLAR}=	dollar
 .undef ${VARNAMES:L:Z}
 
 
+UT_EXPORTED=	exported-value
+.export UT_EXPORTED
+.if ${:!echo "\${UT_EXPORTED:-not-exported}"!} != "exported-value"
+.  error
+.endif
+.if !${.MAKE.EXPORTED:MUT_EXPORTED}
+.  error
+.endif
+.undef UT_EXPORTED		# XXX: does not update .MAKE.EXPORTED
+.if ${:!echo "\${UT_EXPORTED:-not-exported}"!} != "not-exported"
+.  error
+.endif
+.if ${.MAKE.EXPORTED:MUT_EXPORTED}
+.  warning UT_EXPORTED is still listed in .MAKE.EXPORTED even though $\
+	   it is not exported anymore.
+.endif
+
+
 all:
-	@:;



CVS commit: src/usr.bin/make/unit-tests

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 18:02:19 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-undef.exp directive-undef.mk

Log Message:
make: demonstrate inconsistency in .undef of an exported variable


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-undef.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/directive-undef.mk

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



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 17:41:23 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: clean up and update comments in var.c

During the refactorings of the last months, several comments have become
outdated, some are now redundant since the code is as clear as the
comment, and some code benefits from a bit of explanation.


To generate a diff of this commit:
cvs rdiff -u -r1.829 -r1.830 src/usr.bin/make/var.c

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



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 17:41:23 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: clean up and update comments in var.c

During the refactorings of the last months, several comments have become
outdated, some are now redundant since the code is as clear as the
comment, and some code benefits from a bit of explanation.


To generate a diff of this commit:
cvs rdiff -u -r1.829 -r1.830 src/usr.bin/make/var.c

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.829 src/usr.bin/make/var.c:1.830
--- src/usr.bin/make/var.c:1.829	Tue Feb 16 16:33:40 2021
+++ src/usr.bin/make/var.c	Tue Feb 16 17:41:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.829 2021/02/16 16:33:40 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.830 2021/02/16 17:41:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.829 2021/02/16 16:33:40 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.830 2021/02/16 17:41:23 rillig Exp $");
 
 typedef enum VarFlags {
 	VFL_NONE	= 0,
@@ -179,6 +179,8 @@ typedef enum VarFlags {
 	 * The variable value cannot be changed anymore, and the variable
 	 * cannot be deleted.  Any attempts to do so are silently ignored,
 	 * they are logged with -dv though.
+	 *
+	 * See VAR_SET_READONLY.
 	 */
 	VFL_READONLY	= 1 << 5
 } VarFlags;
@@ -217,7 +219,11 @@ typedef struct Var {
 } Var;
 
 /*
- * Exporting vars is expensive so skip it if we can
+ * Exporting variables is expensive and may leak memory, so skip it if we
+ * can.
+ *
+ * To avoid this, it might be worth encapsulating the environment variables
+ * in a separate data structure called EnvVars.
  */
 typedef enum VarExportedMode {
 	VAR_EXPORTED_NONE,
@@ -226,8 +232,17 @@ typedef enum VarExportedMode {
 } VarExportedMode;
 
 typedef enum UnexportWhat {
+	/* Unexport the variables given by name. */
 	UNEXPORT_NAMED,
+	/*
+	 * Unexport all globals previously exported, but keep the environment
+	 * inherited from the parent.
+	 */
 	UNEXPORT_ALL,
+	/*
+	 * Unexport all globals previously exported and clear the environment
+	 * inherited from the parent.
+	 */
 	UNEXPORT_ENV
 } UnexportWhat;
 
@@ -244,7 +259,7 @@ typedef struct VarPatternFlags {
 	Boolean anchorEnd: 1;
 } VarPatternFlags;
 
-/* SepBuf is a string being built from words, interleaved with separators. */
+/* SepBuf builds a string from words interleaved with separators. */
 typedef struct SepBuf {
 	Buffer buf;
 	Boolean needSep;
@@ -275,6 +290,8 @@ char var_Error[] = "";
  * a case where VARE_UNDEFERR is not set.  This undefined variable is
  * typically a dynamic variable such as ${.TARGET}, whose expansion needs to
  * be deferred until it is defined in an actual target.
+ *
+ * See VARE_KEEP_UNDEF.
  */
 static char varUndefined[] = "";
 
@@ -403,24 +420,14 @@ VarFind(const char *name, GNode *scope, 
 	Var *var;
 	unsigned int nameHash;
 
-	/*
-	 * If the variable name begins with a '.', it could very well be
-	 * one of the local ones.  We check the name against all the local
-	 * variables and substitute the short version in for 'name' if it
-	 * matches one of them.
-	 */
+	/* Replace '.TARGET' with '@', likewise for other local variables. */
 	name = CanonicalVarname(name);
 	nameHash = Hash_Hash(name);
 
-	/* First look for the variable in the given scope. */
 	var = GNode_FindVar(scope, name, nameHash);
 	if (!elsewhere)
 		return var;
 
-	/*
-	 * The variable was not found in the given scope.
-	 * Now look for it in the other scopes as well.
-	 */
 	if (var == NULL && scope != SCOPE_CMDLINE)
 		var = GNode_FindVar(SCOPE_CMDLINE, name, nameHash);
 
@@ -652,6 +659,7 @@ ExportVarPlain(Var *v)
 	 * Flag the variable as something we need to re-export.
 	 * No point actually exporting it now though,
 	 * the child process can do it at the last minute.
+	 * Avoid calling setenv more often than necessary since it can leak.
 	 */
 	v->flags |= VFL_EXPORTED | VFL_REEXPORT;
 	return TRUE;
@@ -670,12 +678,9 @@ ExportVarLiteral(Var *v)
 }
 
 /*
- * Export a single variable.
+ * Mark a single variable to be exported later for subprocesses.
  *
- * We ignore make internal variables (those which start with '.').
- * Also we jump through some hoops to avoid calling setenv
- * more than necessary since it can leak.
- * We only manipulate flags of vars if 'parent' is set.
+ * Internal variables (those starting with '.') are not exported.
  */
 static Boolean
 ExportVar(const char *name, VarExportMode mode)
@@ -838,6 +843,7 @@ GetVarnamesToUnexport(Boolean isEnv, con
 			Parse_Error(PARSE_FATAL,
 			"The directive .unexport-env does not take "
 			"arguments");
+			/* continue anyway */
 		}
 		what = UNEXPORT_ENV;
 
@@ -953,7 +959,7 @@ Var_SetWithFlags(GNode *scope, const 

CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:33:40 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: use bit-shift expressions for VarFlags constants

These are easier to read than hex constants.

There was no need to skip bits 2 and 3 (there were no constants for 0x04
and 0x08).  Close this gap, to avoid confusing future readers.  Keep the
relative order of the flags since that affects the debug output of -dv.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.828 -r1.829 src/usr.bin/make/var.c

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.828 src/usr.bin/make/var.c:1.829
--- src/usr.bin/make/var.c:1.828	Tue Feb 16 16:28:41 2021
+++ src/usr.bin/make/var.c	Tue Feb 16 16:33:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.828 2021/02/16 16:28:41 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.829 2021/02/16 16:33:40 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.828 2021/02/16 16:28:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.829 2021/02/16 16:33:40 rillig Exp $");
 
 typedef enum VarFlags {
 	VFL_NONE	= 0,
@@ -149,20 +149,20 @@ typedef enum VarFlags {
 	 * The variable's value is currently being used by Var_Parse or
 	 * Var_Subst.  This marker is used to avoid endless recursion.
 	 */
-	VFL_IN_USE = 0x01,
+	VFL_IN_USE	= 1 << 0,
 
 	/*
 	 * The variable comes from the environment.
 	 * These variables are not registered in any GNode, therefore they
 	 * must be freed as soon as they are not used anymore.
 	 */
-	VFL_FROM_ENV = 0x02,
+	VFL_FROM_ENV	= 1 << 1,
 
 	/*
 	 * The variable is exported to the environment, to be used by child
 	 * processes.
 	 */
-	VFL_EXPORTED = 0x10,
+	VFL_EXPORTED	= 1 << 2,
 
 	/*
 	 * At the point where this variable was exported, it contained an
@@ -170,17 +170,17 @@ typedef enum VarFlags {
 	 * process is started, it needs to be exported again, in the hope
 	 * that the referenced variable can then be resolved.
 	 */
-	VFL_REEXPORT = 0x20,
+	VFL_REEXPORT	= 1 << 3,
 
 	/* The variable came from the command line. */
-	VFL_FROM_CMD = 0x40,
+	VFL_FROM_CMD	= 1 << 4,
 
 	/*
 	 * The variable value cannot be changed anymore, and the variable
 	 * cannot be deleted.  Any attempts to do so are silently ignored,
 	 * they are logged with -dv though.
 	 */
-	VFL_READONLY = 0x80
+	VFL_READONLY	= 1 << 5
 } VarFlags;
 
 /*



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:33:40 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: use bit-shift expressions for VarFlags constants

These are easier to read than hex constants.

There was no need to skip bits 2 and 3 (there were no constants for 0x04
and 0x08).  Close this gap, to avoid confusing future readers.  Keep the
relative order of the flags since that affects the debug output of -dv.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.828 -r1.829 src/usr.bin/make/var.c

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



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:28:41 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: directive-export-impl.exp
directive-export-impl.mk

Log Message:
make: rename constants for VarFlags

The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.


To generate a diff of this commit:
cvs rdiff -u -r1.827 -r1.828 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 \
src/usr.bin/make/unit-tests/directive-export-impl.exp
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-export-impl.mk

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.827 src/usr.bin/make/var.c:1.828
--- src/usr.bin/make/var.c:1.827	Tue Feb 16 16:14:27 2021
+++ src/usr.bin/make/var.c	Tue Feb 16 16:28:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.827 2021/02/16 16:14:27 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.828 2021/02/16 16:28:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,29 +140,29 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.827 2021/02/16 16:14:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.828 2021/02/16 16:28:41 rillig Exp $");
 
 typedef enum VarFlags {
-	VAR_NONE	= 0,
+	VFL_NONE	= 0,
 
 	/*
 	 * The variable's value is currently being used by Var_Parse or
 	 * Var_Subst.  This marker is used to avoid endless recursion.
 	 */
-	VAR_IN_USE = 0x01,
+	VFL_IN_USE = 0x01,
 
 	/*
 	 * The variable comes from the environment.
 	 * These variables are not registered in any GNode, therefore they
 	 * must be freed as soon as they are not used anymore.
 	 */
-	VAR_FROM_ENV = 0x02,
+	VFL_FROM_ENV = 0x02,
 
 	/*
 	 * The variable is exported to the environment, to be used by child
 	 * processes.
 	 */
-	VAR_EXPORTED = 0x10,
+	VFL_EXPORTED = 0x10,
 
 	/*
 	 * At the point where this variable was exported, it contained an
@@ -170,17 +170,17 @@ typedef enum VarFlags {
 	 * process is started, it needs to be exported again, in the hope
 	 * that the referenced variable can then be resolved.
 	 */
-	VAR_REEXPORT = 0x20,
+	VFL_REEXPORT = 0x20,
 
 	/* The variable came from the command line. */
-	VAR_FROM_CMD = 0x40,
+	VFL_FROM_CMD = 0x40,
 
 	/*
 	 * The variable value cannot be changed anymore, and the variable
 	 * cannot be deleted.  Any attempts to do so are silently ignored,
 	 * they are logged with -dv though.
 	 */
-	VAR_READONLY = 0x80
+	VFL_READONLY = 0x80
 } VarFlags;
 
 /*
@@ -315,8 +315,8 @@ GNode *SCOPE_GLOBAL;
 GNode *SCOPE_INTERNAL;
 
 ENUM_FLAGS_RTTI_6(VarFlags,
-		  VAR_IN_USE, VAR_FROM_ENV,
-		  VAR_EXPORTED, VAR_REEXPORT, VAR_FROM_CMD, VAR_READONLY);
+		  VFL_IN_USE, VFL_FROM_ENV,
+		  VFL_EXPORTED, VFL_REEXPORT, VFL_FROM_CMD, VFL_READONLY);
 
 static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE;
 
@@ -437,7 +437,7 @@ VarFind(const char *name, GNode *scope, 
 
 		if ((env = getenv(name)) != NULL) {
 			char *varname = bmake_strdup(name);
-			return VarNew(FStr_InitOwn(varname), env, VAR_FROM_ENV);
+			return VarNew(FStr_InitOwn(varname), env, VFL_FROM_ENV);
 		}
 
 		if (opts.checkEnvFirst && scope != SCOPE_GLOBAL) {
@@ -467,7 +467,7 @@ VarFind(const char *name, GNode *scope, 
 static Boolean
 VarFreeEnv(Var *v, Boolean freeValue)
 {
-	if (!(v->flags & VAR_FROM_ENV))
+	if (!(v->flags & VFL_FROM_ENV))
 		return FALSE;
 
 	FStr_Done(>name);
@@ -488,7 +488,7 @@ VarAdd(const char *name, const char *val
 {
 	HashEntry *he = HashTable_CreateEntry(>vars, name, NULL);
 	Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), val,
-	flags & VAR_SET_READONLY ? VAR_READONLY : VAR_NONE);
+	flags & VAR_SET_READONLY ? VFL_READONLY : VFL_NONE);
 	HashEntry_Set(he, v);
 	DEBUG3(VAR, "%s:%s = %s\n", scope->name, name, val);
 }
@@ -510,7 +510,7 @@ Var_Delete(GNode *scope, const char *var
 
 	DEBUG2(VAR, "%s:delete %s\n", scope->name, varname);
 	v = HashEntry_Get(he);
-	if (v->flags & VAR_EXPORTED)
+	if (v->flags & VFL_EXPORTED)
 		unsetenv(v->name.str);
 	if (strcmp(v->name.str, MAKE_EXPORTED) == 0)
 		var_exportedVars = VAR_EXPORTED_NONE;
@@ -611,16 +611,16 @@ ExportVarEnv(Var *v)
 	char *val = v->val.data;
 	char *expr;
 
-	if ((v->flags & VAR_EXPORTED) && !(v->flags & VAR_REEXPORT))
+	if ((v->flags & VFL_EXPORTED) && !(v->flags & VFL_REEXPORT))
 		return FALSE;	/* nothing to do */
 
 	if (strchr(val, '$') == NULL) {
-		if (!(v->flags & VAR_EXPORTED))
+		if (!(v->flags & VFL_EXPORTED))
 			setenv(name, val, 1);
 		return TRUE;
 	}
 
-	if (v->flags & VAR_IN_USE) {
+	if (v->flags & VFL_IN_USE) {
 		/*
 		 * We recursed while exporting in a child.
 		 * This isn't going to end well, just skip it.
@@ -643,8 +643,8 @@ ExportVarPlain(Var *v)
 {
 	if (strchr(v->val.data, '$') == NULL) {
 		setenv(v->name.str, v->val.data, 1);
-		v->flags |= 

CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:28:41 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: directive-export-impl.exp
directive-export-impl.mk

Log Message:
make: rename constants for VarFlags

The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.


To generate a diff of this commit:
cvs rdiff -u -r1.827 -r1.828 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 \
src/usr.bin/make/unit-tests/directive-export-impl.exp
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-export-impl.mk

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



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:14:27 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: sync comment about duplicated code with reality

There are only very few places in var.c that contain really duplicate
code anymore.

There is still lots of _almost_ duplicate, for example the code for
parsing variable modifiers.  It differs subtly in behavior:

*   The modifiers ':M' and ':N' use '$$' to escape a '$' sign, while
almost all other modifiers use '\$' for this purpose.

*   The modifiers ':M', ':N', ':S', ':@' and several others parse
balanced parentheses and braces, allowing '(' to '}' to match.
The modifiers ':D' and ':U' only treat the end character special but
not the other 3 of '(){}'.

*   When parsing the modifier ':S' but not evaluating it, the code for
nested variable expressions is parsed differently from when it is in
evaluation mode (VARE_WANTRES).  This applies to an outer ':S'
modifier and an inner ':D' or ':M' modifier.

Since these inconsistencies affect the behavior in edge cases and some
users of make might depend on it, they cannot be fixed by
behavior-preserving refactorings.


To generate a diff of this commit:
cvs rdiff -u -r1.826 -r1.827 src/usr.bin/make/var.c

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



CVS commit: src/usr.bin/make

2021-02-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb 16 16:14:27 UTC 2021

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: sync comment about duplicated code with reality

There are only very few places in var.c that contain really duplicate
code anymore.

There is still lots of _almost_ duplicate, for example the code for
parsing variable modifiers.  It differs subtly in behavior:

*   The modifiers ':M' and ':N' use '$$' to escape a '$' sign, while
almost all other modifiers use '\$' for this purpose.

*   The modifiers ':M', ':N', ':S', ':@' and several others parse
balanced parentheses and braces, allowing '(' to '}' to match.
The modifiers ':D' and ':U' only treat the end character special but
not the other 3 of '(){}'.

*   When parsing the modifier ':S' but not evaluating it, the code for
nested variable expressions is parsed differently from when it is in
evaluation mode (VARE_WANTRES).  This applies to an outer ':S'
modifier and an inner ':D' or ':M' modifier.

Since these inconsistencies affect the behavior in edge cases and some
users of make might depend on it, they cannot be fixed by
behavior-preserving refactorings.


To generate a diff of this commit:
cvs rdiff -u -r1.826 -r1.827 src/usr.bin/make/var.c

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.826 src/usr.bin/make/var.c:1.827
--- src/usr.bin/make/var.c:1.826	Mon Feb 15 18:23:32 2021
+++ src/usr.bin/make/var.c	Tue Feb 16 16:14:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.826 2021/02/15 18:23:32 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.827 2021/02/16 16:14:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -120,7 +120,8 @@
  *
  *	Var_Dump	Print out all variables defined in the given scope.
  *
- * XXX: There's a lot of duplication in these functions.
+ * XXX: There's a lot of almost duplicate code in these functions that only
+ *  differs in subtle details that are not mentioned in the manual page.
  */
 
 #include 
@@ -139,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.826 2021/02/15 18:23:32 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.827 2021/02/16 16:14:27 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,



CVS commit: src/bin/sh

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 15:30:26 UTC 2021

Modified Files:
src/bin/sh: input.c

Log Message:
PR bin/55979

Correctly handle (ie: ignore completely) \0 chars (nuls) in the
shell command input stream (script, dot file, or stdin).

Previously nul chars were ignored correctly in the line in which
they occurred, but would cause trailing chars of that line to reappear
as the start of the following line.   If there was just one \0 skipped,
this would generally result in an extra \n in the sh input, which in
most cases has no effect.   With multiple \0's in a single line, more
of the end of that line was duplicated into the following one.  This
usually manifested as a weird "command not found" error.

Note that any \0 chars in the sh input make the script non-conforming,
so fixing this is not crucial (no \0's should really ever be seen) but
it was an obvious bug in the code, which was attempting to ignore nul
chars (as do many other shells), so let it be fixed.

XXX pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/bin/sh/input.c

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



CVS commit: src/bin/sh

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 15:30:26 UTC 2021

Modified Files:
src/bin/sh: input.c

Log Message:
PR bin/55979

Correctly handle (ie: ignore completely) \0 chars (nuls) in the
shell command input stream (script, dot file, or stdin).

Previously nul chars were ignored correctly in the line in which
they occurred, but would cause trailing chars of that line to reappear
as the start of the following line.   If there was just one \0 skipped,
this would generally result in an extra \n in the sh input, which in
most cases has no effect.   With multiple \0's in a single line, more
of the end of that line was duplicated into the following one.  This
usually manifested as a weird "command not found" error.

Note that any \0 chars in the sh input make the script non-conforming,
so fixing this is not crucial (no \0's should really ever be seen) but
it was an obvious bug in the code, which was attempting to ignore nul
chars (as do many other shells), so let it be fixed.

XXX pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/bin/sh/input.c

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

Modified files:

Index: src/bin/sh/input.c
diff -u src/bin/sh/input.c:1.71 src/bin/sh/input.c:1.72
--- src/bin/sh/input.c:1.71	Sat Feb  9 09:20:47 2019
+++ src/bin/sh/input.c	Tue Feb 16 15:30:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: input.c,v 1.71 2019/02/09 09:20:47 kre Exp $	*/
+/*	$NetBSD: input.c,v 1.72 2021/02/16 15:30:26 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c	8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.71 2019/02/09 09:20:47 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.72 2021/02/16 15:30:26 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -90,6 +90,7 @@ struct parsefile {
 	int fd;			/* file descriptor (or -1 if string) */
 	int nleft;		/* number of chars left in this line */
 	int lleft;		/* number of chars left in this buffer */
+	int nskip;		/* number of \0's dropped in previous line */
 	const char *nextc;	/* next char in buffer */
 	char *buf;		/* input buffer */
 	struct strpush *strpush; /* for pushing strings at this level */
@@ -274,8 +275,13 @@ preadbuffer(void)
 			parselleft = parsenleft = EOF_NLEFT;
 			return PEOF;
 		}
+		parsefile->nskip = 0;
 	}
 
+		/* jump over slots for any \0 chars that were dropped */
+	parsenextc += parsefile->nskip;
+	parsefile->nskip = 0;
+
 		/* p = (not const char *)parsenextc; */
 	p = parsefile->buf + (parsenextc - parsefile->buf);
 	q = p;
@@ -288,6 +294,7 @@ preadbuffer(void)
 		switch (*p) {
 		case '\0':
 			p++;	/* Skip nul */
+			parsefile->nskip++;
 			goto check;
 
 		case '\t':
@@ -306,7 +313,11 @@ preadbuffer(void)
 			break;
 		}
 
-		*q++ = *p++;
+		if (parsefile->nskip)
+			*q++ = *p++;
+		else
+			q = ++p;
+
  check:
 		if (--parselleft <= 0) {
 			parsenleft = q - parsenextc - 1;



CVS commit: src/bin/sh

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 15:30:12 UTC 2021

Modified Files:
src/bin/sh: exec.c

Log Message:
PR bin/55979

This fixes the MSAN detected reference to an unitialised variable
(an unitialised field in a struct) which happens when a command is
not found after a PATH search.

Aside from skipping some known to be going to fail exec*() calls
in some cases, the setting of the relevant field is irrelevant,
so this problem makes no practical difference to the shell, or any
shell script.

XXX (maybe) pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/bin/sh/exec.c

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

Modified files:

Index: src/bin/sh/exec.c
diff -u src/bin/sh/exec.c:1.54 src/bin/sh/exec.c:1.55
--- src/bin/sh/exec.c:1.54	Sat Aug  1 17:51:18 2020
+++ src/bin/sh/exec.c	Tue Feb 16 15:30:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.c,v 1.54 2020/08/01 17:51:18 kre Exp $	*/
+/*	$NetBSD: exec.c,v 1.55 2021/02/16 15:30:12 kre 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.54 2020/08/01 17:51:18 kre Exp $");
+__RCSID("$NetBSD: exec.c,v 1.55 2021/02/16 15:30:12 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -683,6 +683,7 @@ loop:
 	if (act & DO_ERR)
 		outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
 	entry->cmdtype = CMDUNKNOWN;
+	entry->u.index = idx + 1;
 	return;
 
 builtin_success:
@@ -704,8 +705,10 @@ success:
 		entry->lineno = cmdp->lineno;
 		entry->lno_frel = cmdp->fn_ln1;
 		entry->u = cmdp->param;
-	} else
+	} else {
 		entry->cmdtype = CMDUNKNOWN;
+		entry->u.index = -1;
+	}
 }
 
 



CVS commit: src/bin/sh

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 15:30:12 UTC 2021

Modified Files:
src/bin/sh: exec.c

Log Message:
PR bin/55979

This fixes the MSAN detected reference to an unitialised variable
(an unitialised field in a struct) which happens when a command is
not found after a PATH search.

Aside from skipping some known to be going to fail exec*() calls
in some cases, the setting of the relevant field is irrelevant,
so this problem makes no practical difference to the shell, or any
shell script.

XXX (maybe) pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/bin/sh/exec.c

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



CVS commit: src/sys/arch/evbmips/mipssim

2021-02-16 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Feb 16 15:06:30 UTC 2021

Modified Files:
src/sys/arch/evbmips/mipssim: mipssimreg.h

Log Message:
Whitespace nit.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/mipssim/mipssimreg.h

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

Modified files:

Index: src/sys/arch/evbmips/mipssim/mipssimreg.h
diff -u src/sys/arch/evbmips/mipssim/mipssimreg.h:1.2 src/sys/arch/evbmips/mipssim/mipssimreg.h:1.3
--- src/sys/arch/evbmips/mipssim/mipssimreg.h:1.2	Mon Feb 15 22:39:46 2021
+++ src/sys/arch/evbmips/mipssim/mipssimreg.h	Tue Feb 16 15:06:30 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mipssimreg.h,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
+/* $NetBSD: mipssimreg.h,v 1.3 2021/02/16 15:06:30 simonb Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -58,4 +58,3 @@
 
 #define VIRTIO_NUM_TRANSPORTS	32
 #define VIRTIO_STRIDE		512
-



CVS commit: src/sys/arch/evbmips/mipssim

2021-02-16 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Feb 16 15:06:30 UTC 2021

Modified Files:
src/sys/arch/evbmips/mipssim: mipssimreg.h

Log Message:
Whitespace nit.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/mipssim/mipssimreg.h

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



CVS commit: src/sys/compat/netbsd32

2021-02-16 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Feb 16 14:47:20 UTC 2021

Modified Files:
src/sys/compat/netbsd32: netbsd32_fs.c

Log Message:
In netbsd32___mount50() zero out the native fs_args union before use so
we don't pass stack garbage to the lower layers in the MNT_GETARGS case.

Fixes random errors like "Bad address" from "mount -vv" with nfs mounts.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/compat/netbsd32/netbsd32_fs.c

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

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_fs.c
diff -u src/sys/compat/netbsd32/netbsd32_fs.c:1.92 src/sys/compat/netbsd32/netbsd32_fs.c:1.93
--- src/sys/compat/netbsd32/netbsd32_fs.c:1.92	Tue Jan 19 03:41:22 2021
+++ src/sys/compat/netbsd32/netbsd32_fs.c	Tue Feb 16 14:47:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_fs.c,v 1.92 2021/01/19 03:41:22 simonb Exp $	*/
+/*	$NetBSD: netbsd32_fs.c,v 1.93 2021/02/16 14:47:20 simonb Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.92 2021/01/19 03:41:22 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.93 2021/02/16 14:47:20 simonb Exp $");
 
 #include 
 #include 
@@ -825,6 +825,7 @@ netbsd32___mount50(struct lwp *l, const 
  
 	udata = data = SCARG_P32(uap, data);
 	memset(_args32, 0, sizeof(fs_args32));
+	memset(_args, 0, sizeof(fs_args));
 
 	error = copyinstr(type, mtype, sizeof(mtype), );
 	if (error)



CVS commit: src/sys/compat/netbsd32

2021-02-16 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Feb 16 14:47:20 UTC 2021

Modified Files:
src/sys/compat/netbsd32: netbsd32_fs.c

Log Message:
In netbsd32___mount50() zero out the native fs_args union before use so
we don't pass stack garbage to the lower layers in the MNT_GETARGS case.

Fixes random errors like "Bad address" from "mount -vv" with nfs mounts.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/compat/netbsd32/netbsd32_fs.c

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



CVS commit: src/lib/libc

2021-02-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 16 14:44:26 UTC 2021

Modified Files:
src/lib/libc/stdio: printf.3 wprintf.3
src/lib/libc/stdlib: rand48.3

Log Message:
Correct floating-point terminology.

Might want to harmonize the printf(3) and wprintf(3) descriptions of
`%a'.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libc/stdio/printf.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdio/wprintf.3
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdlib/rand48.3

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

Modified files:

Index: src/lib/libc/stdio/printf.3
diff -u src/lib/libc/stdio/printf.3:1.68 src/lib/libc/stdio/printf.3:1.69
--- src/lib/libc/stdio/printf.3:1.68	Sun Dec 31 07:22:55 2017
+++ src/lib/libc/stdio/printf.3	Tue Feb 16 14:44:25 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: printf.3,v 1.68 2017/12/31 07:22:55 dholland Exp $
+.\"	$NetBSD: printf.3,v 1.69 2021/02/16 14:44:25 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -619,7 +619,7 @@ to represent the hex digits, and the let
 .Ql P
 (rather than
 .Ql p )
-to separate the mantissa and exponent.
+to separate the significand and exponent.
 .Pp
 Note that there may be multiple valid ways to represent floating-point
 numbers in this hexadecimal format.
@@ -630,8 +630,8 @@ and
 are all equivalent.
 The format chosen depends on the internal representation of the
 number, but the implementation guarantees that the length of the
-mantissa will be minimized.
-Zeroes are always represented with a mantissa of 0 (preceded by a
+significand will be minimized.
+Zeroes are always represented with a significand of 0 (preceded by a
 .Ql -
 if appropriate) and an exponent of
 .Li +0 .

Index: src/lib/libc/stdio/wprintf.3
diff -u src/lib/libc/stdio/wprintf.3:1.8 src/lib/libc/stdio/wprintf.3:1.9
--- src/lib/libc/stdio/wprintf.3:1.8	Thu Dec 16 17:42:27 2010
+++ src/lib/libc/stdio/wprintf.3	Tue Feb 16 14:44:25 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: wprintf.3,v 1.8 2010/12/16 17:42:27 wiz Exp $
+.\" $NetBSD: wprintf.3,v 1.9 2021/02/16 14:44:25 riastradh Exp $
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -459,13 +459,13 @@ is equal to the precision specification.
 If the precision is missing, it is taken as enough to exactly
 represent the floating-point number; if the precision is
 explicitly zero, no hexadecimal-point character appears.
-This is an exact conversion of the mantissa+exponent internal
+This is an exact conversion of the significand+exponent internal
 floating point representation; the
 .Sm off
 .Oo \- Oc Li 0x Ar h Li \&. Ar hhh
 .Sm on
-portion represents exactly the mantissa; only denormalized
-mantissas have a zero value to the left of the hexadecimal
+portion represents exactly the significand; only in subnormal numbers do
+significands have a zero value to the left of the hexadecimal
 point.
 The
 .Cm p
@@ -488,7 +488,7 @@ to represent the hex digits, and the let
 .Ql P
 (rather than
 .Ql p )
-to separate the mantissa and exponent.
+to separate the significand and exponent.
 .It Cm C
 Treated as
 .Cm c

Index: src/lib/libc/stdlib/rand48.3
diff -u src/lib/libc/stdlib/rand48.3:1.13 src/lib/libc/stdlib/rand48.3:1.14
--- src/lib/libc/stdlib/rand48.3:1.13	Sat Feb 22 13:20:21 2020
+++ src/lib/libc/stdlib/rand48.3	Tue Feb 16 14:44:25 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rand48.3,v 1.13 2020/02/22 13:20:21 kamil Exp $
+.\"	$NetBSD: rand48.3,v 1.14 2021/02/16 14:44:25 riastradh Exp $
 .\"
 .\" Copyright (c) 1993 Martin Birgmeier
 .\" All rights reserved.
@@ -67,7 +67,7 @@ computational step is to perform a singl
 and
 .Fn erand48
 return values of type double.
-The full 48 bits of r(n+1) are loaded into the mantissa of the
+The full 48 bits of r(n+1) are loaded into the significand of the
 returned value, with the exponent set such that the values produced
 lie in the interval [0.0, 1.0).
 .Pp



CVS commit: src/lib/libc

2021-02-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 16 14:44:26 UTC 2021

Modified Files:
src/lib/libc/stdio: printf.3 wprintf.3
src/lib/libc/stdlib: rand48.3

Log Message:
Correct floating-point terminology.

Might want to harmonize the printf(3) and wprintf(3) descriptions of
`%a'.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libc/stdio/printf.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdio/wprintf.3
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdlib/rand48.3

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



CVS commit: src/sys/arch/evbmips/conf

2021-02-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Feb 16 10:58:33 UTC 2021

Modified Files:
src/sys/arch/evbmips/conf: MIPSSIM files.mipssim

Log Message:
I forgot to add the needed conf files for the mipssim virtio addition


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/conf/MIPSSIM
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/conf/files.mipssim

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

Modified files:

Index: src/sys/arch/evbmips/conf/MIPSSIM
diff -u src/sys/arch/evbmips/conf/MIPSSIM:1.2 src/sys/arch/evbmips/conf/MIPSSIM:1.3
--- src/sys/arch/evbmips/conf/MIPSSIM:1.2	Mon Feb  8 00:47:53 2021
+++ src/sys/arch/evbmips/conf/MIPSSIM	Tue Feb 16 10:58:32 2021
@@ -1,10 +1,14 @@
-# $NetBSD: MIPSSIM,v 1.2 2021/02/08 00:47:53 simonb Exp $
+# $NetBSD: MIPSSIM,v 1.3 2021/02/16 10:58:32 reinoud Exp $
 #
 # Kernel config for the QEMU MIPS "mipssim" simulator
+#
+# The QEMU virtio support is experimental and subject to change
+# and will likely be removed when qemu gains a MIPS "virt" target.
+#
 
 include 	"arch/evbmips/conf/std.mipssim"
 
-#ident 		"GENERIC-$Revision: 1.2 $"
+#ident 		"GENERIC-$Revision: 1.3 $"
 
 maxusers	32
 
@@ -63,8 +67,8 @@ file-system	PTYFS		# /dev/pts/N support
 #options 	NFSSERVER	# Sun NFS-compatible filesystem server
 #options 	QUOTA		# legacy UFS quotas
 #options 	QUOTA2		# new, in-filesystem UFS quotas
-#options 	DISKLABEL_EI	# disklabel Endian Independent support
-#options 	FFS_EI		# FFS Endian Independent support
+options 	DISKLABEL_EI	# disklabel Endian Independent support
+options 	FFS_EI		# FFS Endian Independent support
 #options 	WAPBL		# File system journaling support
 #options 	EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and
 # immutable) behave as system flags.
@@ -105,6 +109,29 @@ com*		at mainbus?
 # mipsnet*	at mainbus?
 # options 	MIPSSIM_ETH_MACADDR="ba:bb:1e:01:23:45"
 
+
+# Virtio devices
+virtio*		at mainbus?		# Virtio PCI device
+#viomb*		at virtio?		# Virtio memory balloon device
+ld*		at virtio?		# Virtio disk device
+vioif*		at virtio?		# Virtio network device
+viornd*		at virtio?		# Virtio entropy device
+vioscsi*	at virtio?		# Virtio SCSI device
+#vio9p*		at virtio?		# Virtio 9P device
+
+# SCSI bus support
+scsibus* at scsi?
+
+# SCSI devices
+sd*	at scsibus? target ? lun ?	# SCSI disk drives
+#st*	at scsibus? target ? lun ?	# SCSI tape drives
+cd*	at scsibus? target ? lun ?	# SCSI CD-ROM drives
+#ch*	at scsibus? target ? lun ?	# SCSI autochangers
+#ses*	at scsibus? target ? lun ?	# SCSI Enclosure Services devices
+#ss*	at scsibus? target ? lun ?	# SCSI scanners
+#uk*	at scsibus? target ? lun ?	# SCSI unknown
+
+
 # Network pseudo-devices
 pseudo-device	bpfilter			# Berkeley packet filter
 #pseudo-device 	carp# Common Address Redundancy Protocol

Index: src/sys/arch/evbmips/conf/files.mipssim
diff -u src/sys/arch/evbmips/conf/files.mipssim:1.1 src/sys/arch/evbmips/conf/files.mipssim:1.2
--- src/sys/arch/evbmips/conf/files.mipssim:1.1	Wed Jan 27 05:24:16 2021
+++ src/sys/arch/evbmips/conf/files.mipssim	Tue Feb 16 10:58:33 2021
@@ -1,15 +1,19 @@
-# $NetBSD: files.mipssim,v 1.1 2021/01/27 05:24:16 simonb Exp $
+# $NetBSD: files.mipssim,v 1.2 2021/02/16 10:58:33 reinoud Exp $
 
 file	arch/evbmips/mipssim/autoconf.c
 file	arch/evbmips/mipssim/machdep.c
 file	arch/evbmips/mipssim/mipssim_intr.c
+file	arch/evbmips/mipssim/mipssim_dma.c
 file	arch/evbmips/mipssim/mipssim_bus_io.c
 
 file	arch/evbmips/evbmips/interrupt.c
 
+file	arch/mips/mips/bus_dma.c
 file	arch/mips/mips/mips3_clock.c
 file	arch/mips/mips/mips3_clockintr.c
 
+file	kern/subr_disk_mbr.c			disk
+
 # System bus
 device	mainbus {}
 attach	mainbus at root
@@ -27,5 +31,12 @@ attach	mipsnet at mainbus
 file	arch/evbmips/mipssim/if_mipsnet.c	mipsnet
 defparam opt_mipsnet.hMIPSSIM_ETH_MACADDR
 
+attach	virtio at mainbus with virtio_mainbus:	virtio_mmio
+file	arch/evbmips/mipssim/virtio_mainbus.c	virtio_mainbus
+
 # Memory Disk
 file	dev/md_root.cmemory_disk_hooks
+
+# SCSI support
+include "dev/scsipi/files.scsipi"
+



CVS commit: src/sys/arch/evbmips/conf

2021-02-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Tue Feb 16 10:58:33 UTC 2021

Modified Files:
src/sys/arch/evbmips/conf: MIPSSIM files.mipssim

Log Message:
I forgot to add the needed conf files for the mipssim virtio addition


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/conf/MIPSSIM
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/conf/files.mipssim

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



Re: CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
On Tue, Feb 16, 2021 at 09:29:15AM +, Roy Marples wrote:
> In my testing on aarch64 and octeon (both of which I think are strict
> alignment) neither need pullups nor copyups as the mbuf already has enough
> and arphrd is aligned correctly already.

Ah, we asserted too much alignment - indeed, this variant works and I commited
it after testing on 32bit arm and sparc64.

Martin


CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 16 10:22:52 UTC 2021

Modified Files:
src/sys/netinet: if_arp.c

Log Message:
One more time: backout arp header alignment, now that the alignment
asserted has been aligned to reality.
Also remove unused ARP_HDR_ALIGNED_P macro. Pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/netinet/if_arp.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.305 src/sys/netinet/if_arp.c:1.306
--- src/sys/netinet/if_arp.c:1.305	Tue Feb 16 05:44:13 2021
+++ src/sys/netinet/if_arp.c	Tue Feb 16 10:22:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -133,12 +133,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ARP_HDR_ALIGNED_P(ar)	1
-#else
-#define	ARP_HDR_ALIGNED_P(ar)	vaddr_t) (ar)) & 1) == 0)
-#endif
-
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;
@@ -707,9 +701,10 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		if (m_get_aligned_hdr(, ARP_HDR_ALIGNMENT, sizeof(*ar),
-		false) != 0)
-			goto badlen;
+		if (__predict_false(m->m_len < sizeof(*ar))) {
+			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
+goto badlen;
+		}
 		ar = mtod(m, struct arphdr *);
 		KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 



CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 16 10:22:52 UTC 2021

Modified Files:
src/sys/netinet: if_arp.c

Log Message:
One more time: backout arp header alignment, now that the alignment
asserted has been aligned to reality.
Also remove unused ARP_HDR_ALIGNED_P macro. Pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/netinet/if_arp.c

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



CVS commit: src/sys/net

2021-02-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 16 10:20:56 UTC 2021

Modified Files:
src/sys/net: if_arp.h

Log Message:
ARP headers only need 2 byte alignment - pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/if_arp.h

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

Modified files:

Index: src/sys/net/if_arp.h
diff -u src/sys/net/if_arp.h:1.40 src/sys/net/if_arp.h:1.41
--- src/sys/net/if_arp.h:1.40	Sun Feb 14 20:58:34 2021
+++ src/sys/net/if_arp.h	Tue Feb 16 10:20:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.40 2021/02/14 20:58:34 christos Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.41 2021/02/16 10:20:56 martin Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,7 +72,7 @@ struct	arphdr {
 	uint8_t  ar_tpa[];	/* target protocol address */
 #endif
 };
-#define	ARP_HDR_ALIGNMENT	3
+#define	ARP_HDR_ALIGNMENT	1
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)



CVS commit: src/sys/net

2021-02-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 16 10:20:56 UTC 2021

Modified Files:
src/sys/net: if_arp.h

Log Message:
ARP headers only need 2 byte alignment - pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/if_arp.h

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



CVS commit: src/etc/rc.d

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:02:42 UTC 2021

Modified Files:
src/etc/rc.d: mountall mountd

Log Message:
Enable "/etc/zfs/exports" from "zfs share" in rc.d/mountd and rc.d/mountall.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/etc/rc.d/mountall src/etc/rc.d/mountd

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

Modified files:

Index: src/etc/rc.d/mountall
diff -u src/etc/rc.d/mountall:1.13 src/etc/rc.d/mountall:1.14
--- src/etc/rc.d/mountall:1.13	Sun Mar  1 15:22:55 2020
+++ src/etc/rc.d/mountall	Tue Feb 16 10:02:42 2021
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: mountall,v 1.13 2020/03/01 15:22:55 roy Exp $
+# $NetBSD: mountall,v 1.14 2021/02/16 10:02:42 hannken Exp $
 #
 
 # REQUIRE: mountcritremote named ypbind
@@ -20,6 +20,7 @@ mountall_start()
 	# may try and null mount paths on ZFS.
 	if checkyesno zfs; then
 		zfs mount -a
+		zfs share -a
 	fi
 
 	# Mount file systems noted in fstab.
@@ -34,6 +35,7 @@ mountall_stop()
 
 	# Unmount ZFS file systems.
 	if checkyesno zfs; then
+		zfs unshare -a
 		zfs unmount -a
 	fi
 }
Index: src/etc/rc.d/mountd
diff -u src/etc/rc.d/mountd:1.13 src/etc/rc.d/mountd:1.14
--- src/etc/rc.d/mountd:1.13	Wed Nov 12 12:35:52 2008
+++ src/etc/rc.d/mountd	Tue Feb 16 10:02:42 2021
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: mountd,v 1.13 2008/11/12 12:35:52 ad Exp $
+# $NetBSD: mountd,v 1.14 2021/02/16 10:02:42 hannken Exp $
 #
 
 # PROVIDE: mountd
@@ -19,6 +19,12 @@ mountd_precmd()
 {
 	rm -f /var/db/mountdtab
 	( umask 022 ; > /var/db/mountdtab )
+	if checkyesno zfs; then
+		if [ ! -r /etc/zfs/exports ]; then
+			touch /etc/zfs/exports
+		fi
+		rc_flags="${rc_flags} /etc/exports /etc/zfs/exports"
+	fi
 	return 0
 }
 



CVS commit: src/etc/rc.d

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:02:42 UTC 2021

Modified Files:
src/etc/rc.d: mountall mountd

Log Message:
Enable "/etc/zfs/exports" from "zfs share" in rc.d/mountd and rc.d/mountall.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/etc/rc.d/mountall src/etc/rc.d/mountd

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



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Feb 16 10:01:55 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.8

Log Message:
Reword slightly.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/mountd/mountd.8

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

Modified files:

Index: src/usr.sbin/mountd/mountd.8
diff -u src/usr.sbin/mountd/mountd.8:1.39 src/usr.sbin/mountd/mountd.8:1.40
--- src/usr.sbin/mountd/mountd.8:1.39	Tue Feb 16 10:00:27 2021
+++ src/usr.sbin/mountd/mountd.8	Tue Feb 16 10:01:55 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mountd.8,v 1.39 2021/02/16 10:00:27 hannken Exp $
+.\"	$NetBSD: mountd.8,v 1.40 2021/02/16 10:01:55 wiz Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -101,7 +101,7 @@ The
 .Ar exportsfile
 argument specifies an alternative location
 for the exports file.
-There can many exports files.
+Multiple exports files can be defined.
 .El
 .Pp
 When



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Feb 16 10:01:55 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.8

Log Message:
Reword slightly.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/mountd/mountd.8

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



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:00:27 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.8 mountd.c

Log Message:
Add support for multiple exports files. This will be useful for example for
ZFS, where we have an automatically generated /etc/zfs/exports file, which
should not be edited directly.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/mountd/mountd.8
cvs rdiff -u -r1.133 -r1.134 src/usr.sbin/mountd/mountd.c

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



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 10:00:27 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.8 mountd.c

Log Message:
Add support for multiple exports files. This will be useful for example for
ZFS, where we have an automatically generated /etc/zfs/exports file, which
should not be edited directly.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/mountd/mountd.8
cvs rdiff -u -r1.133 -r1.134 src/usr.sbin/mountd/mountd.c

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

Modified files:

Index: src/usr.sbin/mountd/mountd.8
diff -u src/usr.sbin/mountd/mountd.8:1.38 src/usr.sbin/mountd/mountd.8:1.39
--- src/usr.sbin/mountd/mountd.8:1.38	Sat Dec 24 08:26:57 2016
+++ src/usr.sbin/mountd/mountd.8	Tue Feb 16 10:00:27 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mountd.8,v 1.38 2016/12/24 08:26:57 abhinav Exp $
+.\"	$NetBSD: mountd.8,v 1.39 2021/02/16 10:00:27 hannken Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)mountd.8	8.4 (Berkeley) 4/28/95
 .\"
-.Dd November 2, 2011
+.Dd February 16, 2021
 .Dt MOUNTD 8
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@ mount requests
 .Op Fl dN
 .Op Fl P Ar policy
 .Op Fl p Ar port
-.Op Ar exportsfile
+.Op Ar exportsfile ...
 .Sh DESCRIPTION
 .Nm
 is the server for
@@ -101,6 +101,7 @@ The
 .Ar exportsfile
 argument specifies an alternative location
 for the exports file.
+There can many exports files.
 .El
 .Pp
 When

Index: src/usr.sbin/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.133 src/usr.sbin/mountd/mountd.c:1.134
--- src/usr.sbin/mountd/mountd.c:1.133	Tue Feb 16 09:58:35 2021
+++ src/usr.sbin/mountd/mountd.c	Tue Feb 16 10:00:27 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.134 2021/02/16 10:00:27 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -226,7 +226,8 @@ __dead static void no_nfs(int);
 static struct exportlist *exphead;
 static struct mountlist *mlhead;
 static struct grouplist *grphead;
-static const char *exname;
+static char *const exnames_default[] = { __UNCONST(_PATH_EXPORTS), NULL };
+static char *const *exnames;
 static struct uucred def_anon = {
 	1,
 	(uid_t) -2,
@@ -384,15 +385,15 @@ main(int argc, char **argv)
 #ifdef IPSEC
 			" [-P policy]"
 #endif
-			" [-p port] [exportsfile]\n", getprogname());
+			" [-p port] [exportsfile ...]\n", getprogname());
 			exit(1);
 		};
 	argc -= optind;
 	argv += optind;
-	if (argc == 1)
-		exname = *argv;
+	if (argc > 0)
+		exnames = argv;
 	else
-		exname = _PATH_EXPORTS;
+		exnames = exnames_default;
 
 	s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
 	if (s < 0)
@@ -408,7 +409,7 @@ main(int argc, char **argv)
 
 	sem_init(, 0, 0);
 	pthread_create(, NULL, exportlist_thread, NULL);
-	exname = _PATH_EXPORTS;
+	exnames = exnames_default;
 	have_v6 = 0;
 	(void)signal(SIGHUP, signal_get_exportlist);
 #endif
@@ -1261,20 +1262,22 @@ get_exportlist(int n)
 	 * Read in the exports file and build the list, calling
 	 * mount() as we go along to push the export rules into the kernel.
 	 */
-	if ((exp_file = fopen(exname, "r")) == NULL) {
-		/*
-		 * Don't exit here; we can still reload the config
-		 * after a SIGHUP.
-		 */
-		if (mountd_debug)
-			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
-			strerror(errno));
-		return;
-	}
+	for (i = 0; exnames[i] != NULL; i++) {
+		if ((exp_file = fopen(exnames[i], "r")) == NULL) {
+			/*
+			 * Don't exit here; we can still reload the config
+			 * after a SIGHUP.
+			 */
+			if (mountd_debug)
+(void)fprintf(stderr, "Can't open %s: %s\n",
+exnames[i], strerror(errno));
+			continue;
+		}
 
-	get_exportlist_one(exp_file);
+		get_exportlist_one(exp_file);
 
-	(void)fclose(exp_file);
+		(void)fclose(exp_file);
+	}
 }
 
 /*



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:58:35 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.c

Log Message:
Split get_exportlist() into get_exportlist() and get_exportlist_one()
in preparation to support multiple input files.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.sbin/mountd/mountd.c

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

Modified files:

Index: src/usr.sbin/mountd/mountd.c
diff -u src/usr.sbin/mountd/mountd.c:1.132 src/usr.sbin/mountd/mountd.c:1.133
--- src/usr.sbin/mountd/mountd.c:1.132	Wed Jun 17 00:16:21 2020
+++ src/usr.sbin/mountd/mountd.c	Tue Feb 16 09:58:35 2021
@@ -1,4 +1,4 @@
-/* 	$NetBSD: mountd.c,v 1.132 2020/06/17 00:16:21 kamil Exp $	 */
+/* 	$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $	 */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.132 2020/06/17 00:16:21 kamil Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.133 2021/02/16 09:58:35 hannken Exp $");
 #endif
 #endif/* not lint */
 
@@ -1009,81 +1009,22 @@ parse_directory(const char *line, size_t
 }
 
 
-/*
- * Get the export list
- */
-/* ARGSUSED */
-void
-get_exportlist(int n)
+static void
+get_exportlist_one(FILE *exp_file)
 {
 	struct exportlist *ep, *ep2;
 	struct grouplist *grp, *tgrp;
 	struct exportlist **epp;
 	struct dirlist *dirhead;
-	struct statvfs fsb, *fsp;
+	struct statvfs fsb;
 	struct addrinfo *ai;
 	struct uucred anon;
 	char *cp, *endcp, *dirp, savedc;
-	int has_host, exflags, got_nondir, dirplen, num, i;
-	FILE *exp_file;
+	int has_host, exflags, got_nondir, dirplen;
 	char *line;
 	size_t lineno = 0, len;
 
-
-	/*
-	 * First, get rid of the old list
-	 */
-	ep = exphead;
-	while (ep) {
-		ep2 = ep;
-		ep = ep->ex_next;
-		free_exp(ep2);
-	}
-	exphead = NULL;
-
 	dirp = NULL;
-	dirplen = 0;
-	grp = grphead;
-	while (grp) {
-		tgrp = grp;
-		grp = grp->gr_next;
-		free_grp(tgrp);
-	}
-	grphead = NULL;
-
-	/*
-	 * And delete exports that are in the kernel for all local
-	 * file systems.
-	 */
-	num = getmntinfo(, MNT_NOWAIT);
-	for (i = 0; i < num; i++) {
-		struct mountd_exports_list mel;
-
-		/* Delete all entries from the export list. */
-		mel.mel_path = fsp->f_mntonname;
-		mel.mel_nexports = 0;
-		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) == -1 &&
-		errno != EOPNOTSUPP)
-			syslog(LOG_ERR, "Can't delete exports for %s (%m)",
-			fsp->f_mntonname);
-
-		fsp++;
-	}
-
-	/*
-	 * Read in the exports file and build the list, calling
-	 * mount() as we go along to push the export rules into the kernel.
-	 */
-	if ((exp_file = fopen(exname, "r")) == NULL) {
-		/*
-		 * Don't exit here; we can still reload the config
-		 * after a SIGHUP.
-		 */
-		if (mountd_debug)
-			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
-			strerror(errno));
-		return;
-	}
 	dirhead = NULL;
 	while ((line = fparseln(exp_file, , , NULL, 0)) != NULL) {
 		if (mountd_debug)
@@ -1262,6 +1203,77 @@ nextline:
 		}
 		free(line);
 	}
+}
+
+/*
+ * Get the export list
+ */
+/* ARGSUSED */
+void
+get_exportlist(int n)
+{
+	struct exportlist *ep, *ep2;
+	struct grouplist *grp, *tgrp;
+	struct statvfs *fsp;
+	int num, i;
+	FILE *exp_file;
+
+
+	/*
+	 * First, get rid of the old list
+	 */
+	ep = exphead;
+	while (ep) {
+		ep2 = ep;
+		ep = ep->ex_next;
+		free_exp(ep2);
+	}
+	exphead = NULL;
+
+	grp = grphead;
+	while (grp) {
+		tgrp = grp;
+		grp = grp->gr_next;
+		free_grp(tgrp);
+	}
+	grphead = NULL;
+
+	/*
+	 * And delete exports that are in the kernel for all local
+	 * file systems.
+	 */
+	num = getmntinfo(, MNT_NOWAIT);
+	for (i = 0; i < num; i++) {
+		struct mountd_exports_list mel;
+
+		/* Delete all entries from the export list. */
+		mel.mel_path = fsp->f_mntonname;
+		mel.mel_nexports = 0;
+		if (nfssvc(NFSSVC_SETEXPORTSLIST, ) == -1 &&
+		errno != EOPNOTSUPP)
+			syslog(LOG_ERR, "Can't delete exports for %s (%m)",
+			fsp->f_mntonname);
+
+		fsp++;
+	}
+
+	/*
+	 * Read in the exports file and build the list, calling
+	 * mount() as we go along to push the export rules into the kernel.
+	 */
+	if ((exp_file = fopen(exname, "r")) == NULL) {
+		/*
+		 * Don't exit here; we can still reload the config
+		 * after a SIGHUP.
+		 */
+		if (mountd_debug)
+			(void)fprintf(stderr, "Can't open %s: %s\n", exname,
+			strerror(errno));
+		return;
+	}
+
+	get_exportlist_one(exp_file);
+
 	(void)fclose(exp_file);
 }
 



CVS commit: src/usr.sbin/mountd

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:58:35 UTC 2021

Modified Files:
src/usr.sbin/mountd: mountd.c

Log Message:
Split get_exportlist() into get_exportlist() and get_exportlist_one()
in preparation to support multiple input files.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.sbin/mountd/mountd.c

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



CVS commit: src/sys

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:56:32 UTC 2021

Modified Files:
src/sys/kern: vfs_mount.c
src/sys/uvm: uvm_swap.c

Log Message:
Reorganize uvm_swap_shutdown() a bit, make sure the vnode gets
locked and referenced across the call to swap_off() and finally
use it from vfs_unmountall1() to remove swap after unmounting
the last file system.

Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.200 -r1.201 src/sys/uvm/uvm_swap.c

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

Modified files:

Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.85 src/sys/kern/vfs_mount.c:1.86
--- src/sys/kern/vfs_mount.c:1.85	Thu Nov 19 10:47:47 2020
+++ src/sys/kern/vfs_mount.c	Tue Feb 16 09:56:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.86 2021/02/16 09:56:32 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.85 2020/11/19 10:47:47 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.86 2021/02/16 09:56:32 hannken Exp $");
 
 #include 
 #include 
@@ -94,6 +94,8 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,
 #include 
 #include 
 
+#include 
+
 enum mountlist_type {
 	ME_MOUNT,
 	ME_MARKER
@@ -1022,6 +1024,7 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
+	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1056,6 +1059,13 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
+	/* If the mountlist is empty it is time to remove swap. */
+	mountlist_iterator_init();
+	if (mountlist_iterator_next(iter) == NULL) {
+		uvm_swap_shutdown(l);
+	}
+	mountlist_iterator_destroy(iter);
+
 	return progress;
 }
 

Index: src/sys/uvm/uvm_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.200 src/sys/uvm/uvm_swap.c:1.201
--- src/sys/uvm/uvm_swap.c:1.200	Wed Oct  7 17:51:50 2020
+++ src/sys/uvm/uvm_swap.c	Tue Feb 16 09:56:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.c,v 1.200 2020/10/07 17:51:50 chs Exp $	*/
+/*	$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.200 2020/10/07 17:51:50 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.201 2021/02/16 09:56:32 hannken Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1152,27 +1152,23 @@ again:
 			if ((sdp->swd_flags & (SWF_INUSE|SWF_ENABLE)) == 0)
 continue;
 #ifdef DEBUG
-			printf("\nturning off swap on %s...",
-			sdp->swd_path);
+			printf("\nturning off swap on %s...", sdp->swd_path);
 #endif
+			/* Have to lock and reference vnode for swap_off(). */
 			if (vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE)) {
 error = EBUSY;
-vp = NULL;
-			} else
-error = 0;
-			if (!error) {
+			} else {
+vref(vp);
 error = swap_off(l, sdp);
+vput(vp);
 mutex_enter(_swap_data_lock);
 			}
 			if (error) {
 printf("stopping swap on %s failed "
 "with error %d\n", sdp->swd_path, error);
-TAILQ_REMOVE(>spi_swapdev, sdp,
-swd_next);
+TAILQ_REMOVE(>spi_swapdev, sdp, swd_next);
 uvmexp.nswapdev--;
 swaplist_trim();
-if (vp)
-	vput(vp);
 			}
 			goto again;
 		}



CVS commit: src/sys

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:56:32 UTC 2021

Modified Files:
src/sys/kern: vfs_mount.c
src/sys/uvm: uvm_swap.c

Log Message:
Reorganize uvm_swap_shutdown() a bit, make sure the vnode gets
locked and referenced across the call to swap_off() and finally
use it from vfs_unmountall1() to remove swap after unmounting
the last file system.

Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.200 -r1.201 src/sys/uvm/uvm_swap.c

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



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs/sys

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:54:17 UTC 2021

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys: zfs_context.h

Log Message:
Use the right uid / gid for nobody:nobody like FreeBSD does.

Prevents null pointer dereferences when ZFS replaces this
illegal (according to IS_EPHEMERAL()) id with another
illegal id in operation zfs_fuid_create_cred() and
finally zfs_log_create() dereferences fuidp being NULL.

Adresses PR misc/55042 (Panic when creating a directory on a NFS served ZFS)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h

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

Modified files:

Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h
diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.2 src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.3
--- src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h:1.2	Sat Jun 22 09:48:39 2019
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h	Tue Feb 16 09:54:17 2021
@@ -157,13 +157,13 @@ extern "C" {
 #define fm_panic			panic
 #define getffd_getfile
 #define getminor(a)			minor(a)
-#define GID_NOBODY			(-2)
+#define GID_NOBODY			(39)
 #define issig(x)			(sigispending(curlwp, 0))
 #define kmem_debugging()		0
 #define releasef			fd_putfile
 #define strfree(str)			kmem_free((str), strlen(str)+1)
 #define td_rul_ru
-#define UID_NOBODY			(-2)
+#define UID_NOBODY			(32767)
 #define vnode_pager_setsize(vp, size)	zfs_netbsd_setsize(vp, size)
 #define zone_get_hostid(a)		0
 



CVS commit: src/external/cddl/osnet/dist/uts/common/fs/zfs/sys

2021-02-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue Feb 16 09:54:17 UTC 2021

Modified Files:
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys: zfs_context.h

Log Message:
Use the right uid / gid for nobody:nobody like FreeBSD does.

Prevents null pointer dereferences when ZFS replaces this
illegal (according to IS_EPHEMERAL()) id with another
illegal id in operation zfs_fuid_create_cred() and
finally zfs_log_create() dereferences fuidp being NULL.

Adresses PR misc/55042 (Panic when creating a directory on a NFS served ZFS)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_context.h

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



CVS commit: src

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 09:46:24 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_input.sh

Log Message:
PR bin/55979

Add a sh ATF test to demonstrate a bug in the way that \0 characters
are dropped from scripts.   This test will eventually be extended to
test other potential sh script input related issues.

When initially committed, this test should fail.  It should succeed
when the fix for the PR is committed (soon).

Nb: this tests only the \0 related issues from the PR, the MSAN
detected uninitialised variable (struct field) can only be detected
by MSAN, as it has no visible impact on the operation of the shell
when running on any real (or even emulated) hardware.
(It will, however, also be fixed).


To generate a diff of this commit:
cvs rdiff -u -r1.1018 -r1.1019 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.14 -r1.15 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_input.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1018 src/distrib/sets/lists/tests/mi:1.1019
--- src/distrib/sets/lists/tests/mi:1.1018	Sun Feb 14 20:16:17 2021
+++ src/distrib/sets/lists/tests/mi	Tue Feb 16 09:46:24 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1018 2021/02/14 20:16:17 rillig Exp $
+# $NetBSD: mi,v 1.1019 2021/02/16 09:46:24 kre Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1296,6 +1296,7 @@
 ./usr/tests/bin/sh/t_expandtests-bin-tests		compattestfile,atf
 ./usr/tests/bin/sh/t_fsplittests-bin-tests		compattestfile,atf
 ./usr/tests/bin/sh/t_heretests-bin-tests		compattestfile,atf
+./usr/tests/bin/sh/t_inputtests-bin-tests		compattestfile,atf
 ./usr/tests/bin/sh/t_optiontests-bin-tests		compattestfile,atf
 ./usr/tests/bin/sh/t_patternstests-bin-tests		compattestfile,atf
 ./usr/tests/bin/sh/t_redirtests-bin-tests		compattestfile,atf

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.14 src/tests/bin/sh/Makefile:1.15
--- src/tests/bin/sh/Makefile:1.14	Wed Dec  5 02:45:06 2018
+++ src/tests/bin/sh/Makefile	Tue Feb 16 09:46:24 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2018/12/05 02:45:06 kre Exp $
+# $NetBSD: Makefile,v 1.15 2021/02/16 09:46:24 kre Exp $
 #
 
 .include 
@@ -15,6 +15,7 @@ TESTS_SH+=	t_exit
 TESTS_SH+=	t_expand
 TESTS_SH+=	t_fsplit
 TESTS_SH+=	t_here
+TESTS_SH+=	t_input
 TESTS_SH+=	t_option
 TESTS_SH+=	t_patterns
 TESTS_SH+=	t_redir

Added files:

Index: src/tests/bin/sh/t_input.sh
diff -u /dev/null src/tests/bin/sh/t_input.sh:1.1
--- /dev/null	Tue Feb 16 09:46:25 2021
+++ src/tests/bin/sh/t_input.sh	Tue Feb 16 09:46:24 2021
@@ -0,0 +1,178 @@
+# $NetBSD: t_input.sh,v 1.1 2021/02/16 09:46:24 kre Exp $
+#
+# Copyright (c) 2021 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.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+# This set of tests checks the low level shell (script) input
+# systrem (reading script files, nested files, fines read while
+# reading strings, ..) and correctly dropping nul bytes from file data
+
+# other shell input (the read builtin for example) is not covered here.
+
+atf_test_case nul_elimination
+
+nul_elimination_head() {
+	atf_set "descr" "verifies that \0 chars in input are properly ignored"
+}
+
+nul_elimination_body() {
+	atf_require_prog printf
+	atf_require_prog stat
+
+	# these really should always be present, but...
+	atf_require_prog dd
+	atf_require_prog 

CVS commit: src

2021-02-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Feb 16 09:46:24 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_input.sh

Log Message:
PR bin/55979

Add a sh ATF test to demonstrate a bug in the way that \0 characters
are dropped from scripts.   This test will eventually be extended to
test other potential sh script input related issues.

When initially committed, this test should fail.  It should succeed
when the fix for the PR is committed (soon).

Nb: this tests only the \0 related issues from the PR, the MSAN
detected uninitialised variable (struct field) can only be detected
by MSAN, as it has no visible impact on the operation of the shell
when running on any real (or even emulated) hardware.
(It will, however, also be fixed).


To generate a diff of this commit:
cvs rdiff -u -r1.1018 -r1.1019 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.14 -r1.15 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_input.sh

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



Re: CVS commit: src/sys/netinet

2021-02-16 Thread Roy Marples

On 16/02/2021 09:20, Martin Husemann wrote:

On Tue, Feb 16, 2021 at 08:26:40AM +, Roy Marples wrote:

Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?


The KASSERT a few lines below triggerd, we need to be consistent.


For the purposes of using just the header we define I'm pretty sure we can
use 2 byte alignment and set ARP_HDR_ALIGNMENT to 1.


I can test (I have an alignment critical machine with non-ETHER_ALIGN'ing
network driver). Send me a patch, I lost track in the ongoing overhaul.


ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.


Not sure I understand what you mean here.



Index: net/if_arp.h
===
RCS file: /cvsroot/src/sys/net/if_arp.h,v
retrieving revision 1.40
diff -u -p -r1.40 if_arp.h
--- net/if_arp.h14 Feb 2021 20:58:34 -  1.40
+++ net/if_arp.h16 Feb 2021 09:26:23 -
@@ -72,7 +72,7 @@ structarphdr {
uint8_t  ar_tpa[];  /* target protocol address */
 #endif
 };
-#defineARP_HDR_ALIGNMENT   3
+#defineARP_HDR_ALIGNMENT   1

 static __inline uint8_t *
 ar_data(struct arphdr *ap)
Index: netinet/if_arp.c
===
RCS file: /cvsroot/src/sys/netinet/if_arp.c,v
retrieving revision 1.305
diff -u -p -r1.305 if_arp.c
--- netinet/if_arp.c16 Feb 2021 05:44:13 -  1.305
+++ netinet/if_arp.c16 Feb 2021 09:26:23 -
@@ -133,12 +133,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL

-#ifdef __NO_STRICT_ALIGNMENT
-#defineARP_HDR_ALIGNED_P(ar)   1
-#else
-#defineARP_HDR_ALIGNED_P(ar)   vaddr_t) (ar)) & 1) == 0)
-#endif
-
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;


In my testing on aarch64 and octeon (both of which I think are strict alignment) 
neither need pullups nor copyups as the mbuf already has enough and arphrd is 
aligned correctly already.


Roy


Re: CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
On Tue, Feb 16, 2021 at 08:26:40AM +, Roy Marples wrote:
> Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?

The KASSERT a few lines below triggerd, we need to be consistent.

> For the purposes of using just the header we define I'm pretty sure we can
> use 2 byte alignment and set ARP_HDR_ALIGNMENT to 1.

I can test (I have an alignment critical machine with non-ETHER_ALIGN'ing
network driver). Send me a patch, I lost track in the ongoing overhaul.

> ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.

Not sure I understand what you mean here.

Martin


Re: CVS commit: src/sys/netinet

2021-02-16 Thread Roy Marples

On 16/02/2021 05:44, Martin Husemann wrote:

Module Name:src
Committed By:   martin
Date:   Tue Feb 16 05:44:14 UTC 2021

Modified Files:
src/sys/netinet: if_arp.c

Log Message:
Undo previous backout: alignment is needed here.
The reason for the previous backout was a misunderstanding (POINTER_ALIGNED_P
was broken, but the assertion fired even after it got fixed).


Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?
For the purposes of using just the header we define I'm pretty sure we can use 2 
byte alignment and set ARP_HDR_ALIGNMENT to 1.


ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.

Roy