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 <[email protected]>
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

Reply via email to