Convert hw_sysctl to sysctl_bounded_args

2020-11-07 Thread Greg Steuck
This one is surprisingly a minor loss if one were to simply add bytes
on amd64:
   .text+.data+.bss+.rodata
before 0x64b0+0x40+0x14+0x338 = 0x683c
after  0x6440+0x48+0x14+0x3b8 = 0x6854

OK?

>From f93b64d701aed8a72256a7bc0bd343fcc16a2aa8 Mon Sep 17 00:00:00 2001
From: Greg Steuck 
Date: Sat, 7 Nov 2020 17:00:12 -0800
Subject: [PATCH] Convert hw_sysctl to sysctl_bounded_args

---
 sys/kern/kern_sysctl.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c
index 9201a443b5e..afcb93d32dd 100644
--- sys/kern/kern_sysctl.c
+++ sys/kern/kern_sysctl.c
@@ -666,6 +666,18 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
 char *hw_vendor, *hw_prod, *hw_uuid, *hw_serial, *hw_ver;
 int allowpowerdown = 1;
 
+/* morally const values reported by sysctl_bounded_arr */
+static int byte_order = BYTE_ORDER;
+static int page_size = PAGE_SIZE;
+
+const struct sysctl_bounded_args hw_vars[] = {
+   {HW_NCPU, &ncpus, 1, 0},
+   {HW_NCPUFOUND, &ncpusfound, 1, 0},
+   {HW_BYTEORDER, &byte_order, 1, 0},
+   {HW_PAGESIZE, &page_size, 1, 0},
+   {HW_DISKCOUNT, &disk_count, 1, 0},
+};
+
 int
 hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
 size_t newlen, struct proc *p)
@@ -682,22 +694,14 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
return (sysctl_rdstring(oldp, oldlenp, newp, machine));
case HW_MODEL:
return (sysctl_rdstring(oldp, oldlenp, newp, cpu_model));
-   case HW_NCPU:
-   return (sysctl_rdint(oldp, oldlenp, newp, ncpus));
-   case HW_NCPUFOUND:
-   return (sysctl_rdint(oldp, oldlenp, newp, ncpusfound));
case HW_NCPUONLINE:
return (sysctl_rdint(oldp, oldlenp, newp,
sysctl_hwncpuonline()));
-   case HW_BYTEORDER:
-   return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER));
case HW_PHYSMEM:
return (sysctl_rdint(oldp, oldlenp, newp, ptoa(physmem)));
case HW_USERMEM:
return (sysctl_rdint(oldp, oldlenp, newp,
ptoa(physmem - uvmexp.wired)));
-   case HW_PAGESIZE:
-   return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE));
case HW_DISKNAMES:
err = sysctl_diskinit(0, p);
if (err)
@@ -713,8 +717,6 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
return err;
return (sysctl_rdstruct(oldp, oldlenp, newp, diskstats,
disk_count * sizeof(struct diskstats)));
-   case HW_DISKCOUNT:
-   return (sysctl_rdint(oldp, oldlenp, newp, disk_count));
case HW_CPUSPEED:
if (!cpu_cpuspeed)
return (EOPNOTSUPP);
@@ -775,7 +777,8 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
return (sysctl_hwsmt(oldp, oldlenp, newp, newlen));
 #endif
default:
-   return (EOPNOTSUPP);
+   return sysctl_bounded_arr(hw_vars, nitems(hw_vars), name,
+   namelen, oldp, oldlenp, newp, newlen);
}
/* NOTREACHED */
 }
-- 
2.29.2



Convert kern_sysctl to sysctl_bounded_args

2020-11-07 Thread Greg Steuck
This one is a tiny bit different in its using separate static ints to
store some constants previously in .text immediate operands.

Tested by diff'ing sysctl kern outputs and probing to write the
sysctl_int's.

OK?

>From fe000c108d1695b48c4651dddf586d224be66fe8 Mon Sep 17 00:00:00 2001
From: Greg Steuck 
Date: Sat, 7 Nov 2020 12:23:05 -0800
Subject: [PATCH] Convert kern_sysctl to sysctl_bounded_args

objdump -h changes in size of kern_sysctl.o on amd64
before  after
.text 7140   64b0
.data   24 40
.bss10 14
.rodata 50338
---
 sys/kern/kern_sysctl.c | 175 +
 1 file changed, 73 insertions(+), 102 deletions(-)

diff --git sys/kern/kern_sysctl.c sys/kern/kern_sysctl.c
index 78d5b309787..9201a443b5e 100644
--- sys/kern/kern_sysctl.c
+++ sys/kern/kern_sysctl.c
@@ -275,6 +275,76 @@ struct diskstats *diskstats = NULL;
 size_t diskstatslen;
 int securelevel;
 
+/* morally const values reported by sysctl_bounded_arr */
+static int arg_max = ARG_MAX;
+static int openbsd = OpenBSD;
+static int posix_version = _POSIX_VERSION;
+static int ngroups_max = NGROUPS_MAX;
+static int int_zero = 0;
+static int int_one = 1;
+static int maxpartitions = MAXPARTITIONS;
+static int raw_part = RAW_PART;
+
+extern int somaxconn, sominconn;
+extern int nosuidcoredump;
+extern int maxlocksperuid;
+extern int uvm_wxabort;
+extern int global_ptrace;
+
+const struct sysctl_bounded_args kern_vars[] = {
+   {KERN_OSREV, &openbsd, 1, 0},
+   {KERN_MAXVNODES, &maxvnodes, 0, INT_MAX},
+   {KERN_MAXPROC, &maxprocess, 0, INT_MAX},
+   {KERN_MAXFILES, &maxfiles, 0, INT_MAX},
+   {KERN_NFILES, &numfiles, 1, 0},
+   {KERN_TTYCOUNT, &tty_count, 1, 0},
+   {KERN_ARGMAX, &arg_max, 1, 0},
+   {KERN_NSELCOLL, &nselcoll, 1, 0},
+   {KERN_POSIX1, &posix_version, 1, 0},
+   {KERN_NGROUPS, &ngroups_max, 1, 0},
+   {KERN_JOB_CONTROL, &int_one, 1, 0},
+   {KERN_SAVED_IDS, &int_one, 1, 0},
+   {KERN_MAXPARTITIONS, &maxpartitions, 1, 0},
+   {KERN_RAWPARTITION, &raw_part, 1, 0},
+   {KERN_MAXTHREAD, &maxthread, 0, INT_MAX},
+   {KERN_NTHREADS, &nthreads, 1, 0},
+   {KERN_SOMAXCONN, &somaxconn, 0, SHRT_MAX},
+   {KERN_SOMINCONN, &sominconn, 0, SHRT_MAX},
+   {KERN_NOSUIDCOREDUMP, &nosuidcoredump, 0, 3},
+   {KERN_FSYNC, &int_one, 1, 0},
+   {KERN_SYSVMSG,
+#ifdef SYSVMSG
+&int_one,
+#else
+&int_zero,
+#endif
+1, 0},
+   {KERN_SYSVSEM,
+#ifdef SYSVSEM
+&int_one,
+#else
+&int_zero,
+#endif
+1, 0},
+   {KERN_SYSVSHM,
+#ifdef SYSVSHM
+&int_one,
+#else
+&int_zero,
+#endif
+1, 0},
+   {KERN_FSCALE, &fscale, 1, 0},
+   {KERN_CCPU, &ccpu, 1, 0},
+   {KERN_NPROCS, &nprocesses, 1, 0},
+   {KERN_SPLASSERT, &splassert_ctl, 0, 3},
+   {KERN_MAXLOCKSPERUID, &maxlocksperuid, 0, INT_MAX},
+   {KERN_WXABORT, &uvm_wxabort, 0, 1},
+   {KERN_NETLIVELOCKS, &int_zero, 1, 0},
+#ifdef PTRACE
+   {KERN_GLOBAL_PTRACE, &global_ptrace, 0, 1},
+#endif
+};
+
 /*
  * kernel related system variables.
  */
@@ -284,11 +354,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
 {
int error, level, inthostid, stackgap;
dev_t dev;
-   extern int somaxconn, sominconn;
-   extern int nosuidcoredump;
-   extern int maxlocksperuid;
extern int pool_debug;
-   extern int uvm_wxabort;
 
/* all sysctl names at this level are terminal except a ton of them */
if (namelen != 1) {
@@ -325,28 +391,12 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
return (sysctl_rdstring(oldp, oldlenp, newp, ostype));
case KERN_OSRELEASE:
return (sysctl_rdstring(oldp, oldlenp, newp, osrelease));
-   case KERN_OSREV:
-   return (sysctl_rdint(oldp, oldlenp, newp, OpenBSD));
case KERN_OSVERSION:
return (sysctl_rdstring(oldp, oldlenp, newp, osversion));
case KERN_VERSION:
return (sysctl_rdstring(oldp, oldlenp, newp, version));
-   case KERN_MAXVNODES:
-   return(sysctl_int(oldp, oldlenp, newp, newlen, &maxvnodes));
-   case KERN_MAXPROC:
-   return (sysctl_int(oldp, oldlenp, newp, newlen, &maxprocess));
-   case KERN_MAXFILES:
-   return (sysctl_int(oldp, oldlenp, newp, newlen, &maxfiles));
-   case KERN_NFILES:
-   return (sysctl_rdint(oldp, oldlenp, newp, numfiles));
-   case KERN_TTYCOUNT:
-   return (sysctl_rdint(oldp, oldlenp, newp, tty_count));
-   case KERN_NUMVNODES:
+   case KERN_NUMVNODES:  /* XXX numvnodes is a long */
return (sysctl_rdint(oldp, oldlenp, newp, numvnodes));
-   case KERN_ARGMAX:
-   return (sysctl_rdint(oldp, oldlenp, newp, ARG_MAX));
-   case KERN_NSELCOLL:
-   return (sysctl_rd

unbound.conf.5.in: remove reference to default pidfile

2020-11-07 Thread Martin Vahlensieck
Hi

Unbound on OpenBSD does not have a pidfile, so remove the reference in
the manual. As the variable is empty, it also incorrectly formats the
description as italic.

Best,

Martin

Index: unbound.conf.5.in
===
RCS file: /cvs/src/usr.sbin/unbound/doc/unbound.conf.5.in,v
retrieving revision 1.34
diff -u -p -r1.34 unbound.conf.5.in
--- unbound.conf.5.in   28 Oct 2020 11:31:07 -  1.34
+++ unbound.conf.5.in   7 Nov 2020 11:45:38 -
@@ -2360,9 +2360,6 @@ location.
 .I @ub_conf_file@
 unbound configuration file.
 .TP
-.I @UNBOUND_PIDFILE@
-default unbound pidfile with process ID of the running daemon.
-.TP
 .I unbound.log
 unbound log file. default is to log to
 \fIsyslog\fR(3).



dhcpd: Put return type on its own line

2020-11-07 Thread Martin Vahlensieck
Hi

Put the return type on its own line. Found while checking dhcpd.h.

Best,

Martin

Index: memory.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/memory.c,v
retrieving revision 1.29
diff -u -p -r1.29 memory.c
--- memory.c6 Apr 2020 17:05:40 -   1.29
+++ memory.c7 Nov 2020 09:37:53 -
@@ -687,7 +687,8 @@ find_lease_by_ip_addr(struct iaddr addr)
addr.iabuf, addr.len);
 }
 
-struct lease *find_lease_by_uid(unsigned char *uid, int len)
+struct lease *
+find_lease_by_uid(unsigned char *uid, int len)
 {
return (struct lease *)hash_lookup(lease_uid_hash, uid, len);
 }
Index: hash.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/hash.c,v
retrieving revision 1.8
diff -u -p -r1.8 hash.c
--- hash.c  13 Feb 2017 19:13:14 -  1.8
+++ hash.c  7 Nov 2020 09:37:53 -
@@ -89,7 +89,8 @@ do_hash(unsigned char *name, int len, in
return (accum % size);
 }
 
-void add_hash(struct hash_table *table, unsigned char *name, int len,
+void
+add_hash(struct hash_table *table, unsigned char *name, int len,
 unsigned char *pointer)
 {
int hashno;



base64.c: Remove trailing whitespace

2020-11-07 Thread Martin Vahlensieck
Hi

Remove trailing whitespace.

Best,

Martin

Index: base64.c
===
RCS file: /cvs/src/lib/libc/net/base64.c,v
retrieving revision 1.8
diff -u -p -r1.8 base64.c
--- base64.c16 Jan 2015 16:48:51 -  1.8
+++ base64.c7 Nov 2020 09:30:43 -
@@ -107,9 +107,9 @@ static const char Pad64 = '=';
end of the data is performed using the '=' character.
 
Since all base64 input is an integral number of octets, only the
- - 
  
+ -
following cases can arise:
-   
+
(1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded
   output will be an integral multiple of 4 characters
@@ -152,14 +152,14 @@ b64_ntop(src, srclength, target, targsiz
target[datalength++] = Base64[output[2]];
target[datalength++] = Base64[output[3]];
}
-
+
/* Now we worry about padding. */
if (0 != srclength) {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
for (i = 0; i < srclength; i++)
input[i] = *src++;
-   
+
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);



dhcpd: Remove prototypes without implementation

2020-11-07 Thread Martin Vahlensieck
Hi

pretty_print_option: Removed in options.c in revision 1.4
parse_timestamp: Removed in confpars.c in revision 1.13
tree_host_lookup: Removed in tree.c in revision 1.11
enter_dns_host: Removed in tree.c in revision 1.11
getLong: Removed in convert.c in revision 1.4
getShort: Removes in convert.c in revision 1.4

So I think they can be removed in dhcpd.h as well. No warnings when
compiling.

Best,

Martin

Index: dhcpd.h
===
RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.h,v
retrieving revision 1.67
diff -u -p -r1.67 dhcpd.h
--- dhcpd.h 8 May 2019 22:00:55 -   1.67
+++ dhcpd.h 7 Nov 2020 09:07:18 -
@@ -311,7 +311,6 @@ void parse_options(struct packet *);
 voidparse_option_buffer(struct packet *, unsigned char *, int);
 int cons_options(struct packet *, struct dhcp_packet *, int,
struct tree_cache **, int, int, int, u_int8_t *, int);
-char   *pretty_print_option(unsigned int, unsigned char *, int, int, int);
 voiddo_packet(struct interface_info *, struct dhcp_packet *, int,
unsigned int, struct iaddr, struct hardware *);
 
@@ -364,7 +363,6 @@ char*parse_string(FILE *);
 struct tree*parse_ip_addr_or_hostname(FILE *, int);
 struct tree_cache  *parse_fixed_addr_param(FILE *);
 voidparse_option_param(FILE *, struct group *);
-time_t  parse_timestamp(FILE *);
 struct lease   *parse_lease_declaration(FILE *);
 voidparse_address_range(FILE *, struct subnet *);
 time_t  parse_date(FILE *);
@@ -376,8 +374,6 @@ struct tree *parse_domain_and_comp(FILE
 /* tree.c */
 paircons(caddr_t, pair);
 struct tree_cache  *tree_cache(struct tree *);
-struct tree*tree_host_lookup(char *);
-struct dns_host_entry  *enter_dns_host(char *);
 struct tree*tree_const(unsigned char *, int);
 struct tree*tree_concat(struct tree *, struct tree *);
 struct tree*tree_limit(struct tree *, int);
@@ -476,9 +472,7 @@ void initialize_universes(void);
 
 /* convert.c */
 u_int32_t getULong(unsigned char *);
-int32_t getLong(unsigned char *);
 u_int16_t getUShort(unsigned char *);
-int16_t getShort(unsigned char *);
 void putULong(unsigned char *, u_int32_t);
 void putLong(unsigned char *, int32_t);
 void putUShort(unsigned char *, unsigned int);



Re: Fix ilogb(3)

2020-11-07 Thread Philip Guenther
On Fri, Nov 6, 2020 at 4:51 PM George Koehler  wrote:

> Your ilogb fix is ok gkoehler@
>

It's annoying that C and/or ieee754 and the original hardware
implementation in the x87 instructions diverged in their definitions, but
the former is what matters and libm needs to follow that.  ok guenther@



> On Sat, 31 Oct 2020 16:09:07 +0100 (CET)
> Mark Kettenis  wrote:
>
> > - Dropping the amd64 and i386 versions.  Fixing the corner cases in
> >   assembly is hard, and the C implementation should be fast enough for
> >   regular floating-point values.
>
> The amd64 and i386 assembly uses the x87 fxtract instruction.  I feel
> that x87 instructions are obsolete on amd64.  <...>


Umm, no?  The amd64 ABI defines "long double" as matching the format used
by the x87 instructions; a function returning that type returns it in the
x87 %st(0) register and a review of libm finds many of the functions are
naturally implemented by the native x87 instructions.

I believe the main issue in this case is that the standard evolved away
from what Kahan originally did as a consultant with Intel.  For a note on
how the ieee754 standard originated in (large) part from what Kahan did
with Intel, see
  https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html

I'm not nearly enough of a numerical analyst to judge the decision of the
standard.


Philip Guenther