145ec3b38SPoul-Henning Kamp /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 445ec3b38SPoul-Henning Kamp * Copyright (c) 1982, 1986, 1989, 1993 545ec3b38SPoul-Henning Kamp * The Regents of the University of California. All rights reserved. 645ec3b38SPoul-Henning Kamp * 745ec3b38SPoul-Henning Kamp * This code is derived from software contributed to Berkeley by 845ec3b38SPoul-Henning Kamp * Mike Karels at Berkeley Software Design, Inc. 945ec3b38SPoul-Henning Kamp * 1045ec3b38SPoul-Henning Kamp * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD 1145ec3b38SPoul-Henning Kamp * project, to make these variables more userfriendly. 1245ec3b38SPoul-Henning Kamp * 1345ec3b38SPoul-Henning Kamp * Redistribution and use in source and binary forms, with or without 1445ec3b38SPoul-Henning Kamp * modification, are permitted provided that the following conditions 1545ec3b38SPoul-Henning Kamp * are met: 1645ec3b38SPoul-Henning Kamp * 1. Redistributions of source code must retain the above copyright 1745ec3b38SPoul-Henning Kamp * notice, this list of conditions and the following disclaimer. 1845ec3b38SPoul-Henning Kamp * 2. Redistributions in binary form must reproduce the above copyright 1945ec3b38SPoul-Henning Kamp * notice, this list of conditions and the following disclaimer in the 2045ec3b38SPoul-Henning Kamp * documentation and/or other materials provided with the distribution. 2169a28758SEd Maste * 3. Neither the name of the University nor the names of its contributors 2245ec3b38SPoul-Henning Kamp * may be used to endorse or promote products derived from this software 2345ec3b38SPoul-Henning Kamp * without specific prior written permission. 2445ec3b38SPoul-Henning Kamp * 2545ec3b38SPoul-Henning Kamp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2645ec3b38SPoul-Henning Kamp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2745ec3b38SPoul-Henning Kamp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2845ec3b38SPoul-Henning Kamp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2945ec3b38SPoul-Henning Kamp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3045ec3b38SPoul-Henning Kamp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3145ec3b38SPoul-Henning Kamp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3245ec3b38SPoul-Henning Kamp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3345ec3b38SPoul-Henning Kamp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3445ec3b38SPoul-Henning Kamp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3545ec3b38SPoul-Henning Kamp * SUCH DAMAGE. 3645ec3b38SPoul-Henning Kamp * 3745ec3b38SPoul-Henning Kamp * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 3845ec3b38SPoul-Henning Kamp */ 3945ec3b38SPoul-Henning Kamp 40677b542eSDavid E. O'Brien #include <sys/cdefs.h> 41677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 42677b542eSDavid E. O'Brien 43eacb362fSRobert Watson #include "opt_posix.h" 445f9974aeSWojciech A. Koszek #include "opt_config.h" 45c175d222SRobert Watson 4645ec3b38SPoul-Henning Kamp #include <sys/param.h> 47af9727f6SWarner Losh #include <sys/boot.h> 4861bbe53cSJohn Baldwin #include <sys/elf.h> 49d1b06863SMark Murray #include <sys/jail.h> 5045ec3b38SPoul-Henning Kamp #include <sys/kernel.h> 517a6322e1SKonstantin Belousov #include <sys/limits.h> 5201137630SRobert Watson #include <sys/lock.h> 5301137630SRobert Watson #include <sys/mutex.h> 54d1b06863SMark Murray #include <sys/proc.h> 55d1b06863SMark Murray #include <sys/random.h> 56d1b06863SMark Murray #include <sys/sbuf.h> 576caa8a15SJohn Baldwin #include <sys/smp.h> 580304c731SJamie Gritton #include <sys/sx.h> 593da4d19bSJohn Baldwin #include <sys/sysent.h> 609ed01c32SGleb Smirnoff #include <sys/vmmeter.h> 61d1b06863SMark Murray #include <sys/sysctl.h> 62d1b06863SMark Murray #include <sys/systm.h> 63eeea998cSMike Barcroft #include <sys/unistd.h> 64662f9a69SKATO Takenori 657029da5cSPawel Biernacki SYSCTL_ROOT_NODE(0, sysctl, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 6645ec3b38SPoul-Henning Kamp "Sysctl internal magic"); 677029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_KERN, kern, CTLFLAG_RW | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, 0, 6845ec3b38SPoul-Henning Kamp "High kernel, proc, limits &c"); 697029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_VM, vm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 7045ec3b38SPoul-Henning Kamp "Virtual memory"); 717029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_VFS, vfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 7245ec3b38SPoul-Henning Kamp "File system"); 737029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_NET, net, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 7445ec3b38SPoul-Henning Kamp "Network, (see socket.h)"); 757029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_DEBUG, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 7645ec3b38SPoul-Henning Kamp "Debugging"); 777029da5cSPawel Biernacki SYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 786f13bfc2SPoul-Henning Kamp "Sizeof various things"); 797029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_HW, hw, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 8045ec3b38SPoul-Henning Kamp "hardware"); 817029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_MACHDEP, machdep, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 8245ec3b38SPoul-Henning Kamp "machine dependent"); 837029da5cSPawel Biernacki SYSCTL_NODE(_machdep, OID_AUTO, mitigations, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 84de890ea4SScott Long "Machine dependent platform mitigations."); 857029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_USER, user, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 8645ec3b38SPoul-Henning Kamp "user-level"); 877029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_P1003_1B, p1003_1b, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 888a6472b7SPeter Dufault "p1003_1b, (see p1003_1b.h)"); 89644d85f4SPeter Dufault 907029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, compat, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 91c6dfea0eSMarcel Moolenaar "Compatibility code"); 927029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, security, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 93d0615c64SAndrew R. Reiter "Security"); 94eacb362fSRobert Watson #ifdef REGRESSION 957029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, regression, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 96eacb362fSRobert Watson "Regression test MIB"); 97eacb362fSRobert Watson #endif 98c6dfea0eSMarcel Moolenaar 99f3b86a5fSEd Schouten SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD|CTLFLAG_MPSAFE, 100c02d7621SJuli Mallett kern_ident, 0, "Kernel identifier"); 101da1186f2SJuli Mallett 102ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD, 103f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, BSD, "Operating system revision"); 10445ec3b38SPoul-Henning Kamp 105f3b86a5fSEd Schouten SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD|CTLFLAG_MPSAFE, 1063d177f46SBill Fumerola version, 0, "Kernel version"); 10745ec3b38SPoul-Henning Kamp 1088eede5c4SAndriy Gapon SYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD|CTLFLAG_MPSAFE, 109bfdcb3bcSAndriy Gapon compiler_version, 0, "Version of compiler used to compile kernel"); 110bfdcb3bcSAndriy Gapon 111ff66f6a4SRobert Watson SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE| 112ff66f6a4SRobert Watson CTLFLAG_CAPRD, ostype, 0, "Operating system type"); 11345ec3b38SPoul-Henning Kamp 114af3b2549SHans Petter Selasky SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, 1153d177f46SBill Fumerola &maxproc, 0, "Maximum number of processes"); 11645ec3b38SPoul-Henning Kamp 1173d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW, 1183d177f46SBill Fumerola &maxprocperuid, 0, "Maximum processes allowed per userid"); 11945ec3b38SPoul-Henning Kamp 120af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, 121ee342e1bSPeter Wemm &maxusers, 0, "Hint for kernel tuning"); 122ee342e1bSPeter Wemm 123ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD, 124f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, ARG_MAX, "Maximum bytes of argument to execve(2)"); 12545ec3b38SPoul-Henning Kamp 126ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD, 127f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, _POSIX_VERSION, "Version of POSIX attempting to comply to"); 12845ec3b38SPoul-Henning Kamp 129af3b2549SHans Petter Selasky SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN | 130af3b2549SHans Petter Selasky CTLFLAG_NOFETCH | CTLFLAG_CAPRD, &ngroups_max, 0, 1315feedc25SBrooks Davis "Maximum number of supplemental groups a user can belong to"); 13245ec3b38SPoul-Henning Kamp 133ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD, 134f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 1, "Whether job control is available"); 13545ec3b38SPoul-Henning Kamp 13645ec3b38SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS 137ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD, 138f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 1, "Whether saved set-group/user ID is available"); 13945ec3b38SPoul-Henning Kamp #else 140ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD, 141f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether saved set-group/user ID is available"); 14245ec3b38SPoul-Henning Kamp #endif 14345ec3b38SPoul-Henning Kamp 144ec9abc18SWarner Losh char kernelname[MAXPATHLEN] = PATH_KERNEL; /* XXX bloat */ 14545ec3b38SPoul-Henning Kamp 14653dc58f2SMateusz Guzik SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW | CTLFLAG_MPSAFE, 1473d177f46SBill Fumerola kernelname, sizeof kernelname, "Name of kernel file booted"); 14845ec3b38SPoul-Henning Kamp 1497ed6b78bSGleb Smirnoff SYSCTL_INT(_kern, KERN_MAXPHYS, maxphys, CTLFLAG_RD | CTLFLAG_CAPRD, 1507ed6b78bSGleb Smirnoff SYSCTL_NULL_INT_PTR, MAXPHYS, "Maximum block I/O access size"); 1517ed6b78bSGleb Smirnoff 152ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD, 1533d177f46SBill Fumerola &mp_ncpus, 0, "Number of active CPUs"); 15445ec3b38SPoul-Henning Kamp 155ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD, 156f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, BYTE_ORDER, "System byte order"); 15745ec3b38SPoul-Henning Kamp 158ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD, 159f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, PAGE_SIZE, "System memory page size"); 16045ec3b38SPoul-Henning Kamp 1610fca57b8SThomas Moestl static int 162ee9f4661SAlexander Kabaev sysctl_kern_arnd(SYSCTL_HANDLER_ARGS) 163ee9f4661SAlexander Kabaev { 164370f990dSAntoine Brodin char buf[256]; 165370f990dSAntoine Brodin size_t len; 166ee9f4661SAlexander Kabaev 16713774e82SConrad Meyer len = MIN(req->oldlen, sizeof(buf)); 16813774e82SConrad Meyer read_random(buf, len); 169370f990dSAntoine Brodin return (SYSCTL_OUT(req, buf, len)); 170ee9f4661SAlexander Kabaev } 171ee9f4661SAlexander Kabaev 172f3b86a5fSEd Schouten SYSCTL_PROC(_kern, KERN_ARND, arandom, 173ff66f6a4SRobert Watson CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0, 174f3b86a5fSEd Schouten sysctl_kern_arnd, "", "arc4rand"); 175ee9f4661SAlexander Kabaev 176ee9f4661SAlexander Kabaev static int 1770fca57b8SThomas Moestl sysctl_hw_physmem(SYSCTL_HANDLER_ARGS) 1780fca57b8SThomas Moestl { 1797a6322e1SKonstantin Belousov u_long val, p; 1800fca57b8SThomas Moestl 1817a6322e1SKonstantin Belousov p = SIZE_T_MAX >> PAGE_SHIFT; 1827a6322e1SKonstantin Belousov if (physmem < p) 1837a6322e1SKonstantin Belousov p = physmem; 1847a6322e1SKonstantin Belousov val = ctob(p); 1850fca57b8SThomas Moestl return (sysctl_handle_long(oidp, &val, 0, req)); 1860fca57b8SThomas Moestl } 1877029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, 1887029da5cSPawel Biernacki CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0, 1897029da5cSPawel Biernacki sysctl_hw_physmem, "LU", 190557e162fSRavi Pokala "Amount of physical memory (in bytes)"); 1910fca57b8SThomas Moestl 1920fca57b8SThomas Moestl static int 193a0915044SWes Peters sysctl_hw_realmem(SYSCTL_HANDLER_ARGS) 194a0915044SWes Peters { 1957a6322e1SKonstantin Belousov u_long val, p; 1967a6322e1SKonstantin Belousov 1977a6322e1SKonstantin Belousov p = SIZE_T_MAX >> PAGE_SHIFT; 1987a6322e1SKonstantin Belousov if (realmem < p) 1997a6322e1SKonstantin Belousov p = realmem; 2007a6322e1SKonstantin Belousov val = ctob(p); 201a0915044SWes Peters return (sysctl_handle_long(oidp, &val, 0, req)); 202a0915044SWes Peters } 2037029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_REALMEM, realmem, 2047029da5cSPawel Biernacki CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0, 2057029da5cSPawel Biernacki sysctl_hw_realmem, "LU", 206557e162fSRavi Pokala "Amount of memory (in bytes) reported by the firmware"); 2077a6322e1SKonstantin Belousov 208a0915044SWes Peters static int 2090fca57b8SThomas Moestl sysctl_hw_usermem(SYSCTL_HANDLER_ARGS) 2100fca57b8SThomas Moestl { 2117a6322e1SKonstantin Belousov u_long val, p, p1; 2120fca57b8SThomas Moestl 2137a6322e1SKonstantin Belousov p1 = physmem - vm_wire_count(); 2147a6322e1SKonstantin Belousov p = SIZE_T_MAX >> PAGE_SHIFT; 2157a6322e1SKonstantin Belousov if (p1 < p) 2167a6322e1SKonstantin Belousov p = p1; 2177a6322e1SKonstantin Belousov val = ctob(p); 2180fca57b8SThomas Moestl return (sysctl_handle_long(oidp, &val, 0, req)); 2190fca57b8SThomas Moestl } 2207029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_USERMEM, usermem, 2217029da5cSPawel Biernacki CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0, 2227029da5cSPawel Biernacki sysctl_hw_usermem, "LU", 223557e162fSRavi Pokala "Amount of memory (in bytes) which is not wired"); 2240fca57b8SThomas Moestl 225557e162fSRavi Pokala SYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, 226557e162fSRavi Pokala "Amount of physical memory (in pages)"); 2270fca57b8SThomas Moestl 228fe105d45SAlan Cox u_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE }; 229fe105d45SAlan Cox 230fe105d45SAlan Cox static int 231fe105d45SAlan Cox sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS) 232fe105d45SAlan Cox { 233fe105d45SAlan Cox int error; 234697503c4SKonstantin Belousov size_t len; 235fe105d45SAlan Cox #ifdef SCTL_MASK32 236fe105d45SAlan Cox int i; 237fe105d45SAlan Cox uint32_t pagesizes32[MAXPAGESIZES]; 238fe105d45SAlan Cox 239fe105d45SAlan Cox if (req->flags & SCTL_MASK32) { 240fe105d45SAlan Cox /* 241a2b127aeSKonstantin Belousov * Recreate the "pagesizes" array with 32-bit elements. 242a2b127aeSKonstantin Belousov * Truncate any page size greater than UINT32_MAX to zero, 243a2b127aeSKonstantin Belousov * which assumes that page sizes are powers of two. 244fe105d45SAlan Cox */ 245fe105d45SAlan Cox for (i = 0; i < MAXPAGESIZES; i++) 246fe105d45SAlan Cox pagesizes32[i] = (uint32_t)pagesizes[i]; 247fe105d45SAlan Cox 248697503c4SKonstantin Belousov len = sizeof(pagesizes32); 249*a0efcf64SMark Johnston if (len > req->oldlen && req->oldptr != NULL) 250697503c4SKonstantin Belousov len = req->oldlen; 251697503c4SKonstantin Belousov error = SYSCTL_OUT(req, pagesizes32, len); 252fe105d45SAlan Cox } else 253fe105d45SAlan Cox #endif 254697503c4SKonstantin Belousov { 255697503c4SKonstantin Belousov len = sizeof(pagesizes); 256*a0efcf64SMark Johnston if (len > req->oldlen && req->oldptr != NULL) 257697503c4SKonstantin Belousov len = req->oldlen; 258697503c4SKonstantin Belousov error = SYSCTL_OUT(req, pagesizes, len); 259697503c4SKonstantin Belousov } 260fe105d45SAlan Cox return (error); 261fe105d45SAlan Cox } 2627029da5cSPawel Biernacki SYSCTL_PROC(_hw, OID_AUTO, pagesizes, 263*a0efcf64SMark Johnston CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, 264*a0efcf64SMark Johnston sysctl_hw_pagesizes, "S,pagesizes", 2657029da5cSPawel Biernacki "Supported page sizes"); 266fe105d45SAlan Cox 26787d45a03SKonstantin Belousov int adaptive_machine_arch = 1; 26887d45a03SKonstantin Belousov SYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW, 26987d45a03SKonstantin Belousov &adaptive_machine_arch, 1, 27087d45a03SKonstantin Belousov "Adapt reported machine architecture to the ABI of the binary"); 2713da4d19bSJohn Baldwin 2723da4d19bSJohn Baldwin static const char * 2733da4d19bSJohn Baldwin proc_machine_arch(struct proc *p) 2743da4d19bSJohn Baldwin { 2753da4d19bSJohn Baldwin 2763da4d19bSJohn Baldwin if (p->p_sysent->sv_machine_arch != NULL) 2773da4d19bSJohn Baldwin return (p->p_sysent->sv_machine_arch(p)); 2783da4d19bSJohn Baldwin #ifdef COMPAT_FREEBSD32 2793da4d19bSJohn Baldwin if (SV_PROC_FLAG(p, SV_ILP32)) 2803da4d19bSJohn Baldwin return (MACHINE_ARCH32); 28187d45a03SKonstantin Belousov #endif 2823da4d19bSJohn Baldwin return (MACHINE_ARCH); 2833da4d19bSJohn Baldwin } 28487d45a03SKonstantin Belousov 28587d45a03SKonstantin Belousov static int 28687d45a03SKonstantin Belousov sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS) 28787d45a03SKonstantin Belousov { 2883da4d19bSJohn Baldwin const char *machine_arch; 28987d45a03SKonstantin Belousov 2903da4d19bSJohn Baldwin if (adaptive_machine_arch) 2913da4d19bSJohn Baldwin machine_arch = proc_machine_arch(curproc); 29287d45a03SKonstantin Belousov else 2933da4d19bSJohn Baldwin machine_arch = MACHINE_ARCH; 2943da4d19bSJohn Baldwin return (SYSCTL_OUT(req, machine_arch, strlen(machine_arch) + 1)); 29587d45a03SKonstantin Belousov } 29653dc58f2SMateusz Guzik SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD | 29753dc58f2SMateusz Guzik CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine_arch, "A", 29853dc58f2SMateusz Guzik "System architecture"); 299664f8517SKATO Takenori 3003da4d19bSJohn Baldwin #ifndef MACHINE_ARCHES 3013cb6654dSNathan Whitehorn #ifdef COMPAT_FREEBSD32 3023da4d19bSJohn Baldwin #define MACHINE_ARCHES MACHINE_ARCH " " MACHINE_ARCH32 3033cb6654dSNathan Whitehorn #else 3043da4d19bSJohn Baldwin #define MACHINE_ARCHES MACHINE_ARCH 3053cb6654dSNathan Whitehorn #endif 3063da4d19bSJohn Baldwin #endif 3073da4d19bSJohn Baldwin 3083da4d19bSJohn Baldwin SYSCTL_STRING(_kern, OID_AUTO, supported_archs, CTLFLAG_RD | CTLFLAG_MPSAFE, 3093da4d19bSJohn Baldwin MACHINE_ARCHES, 0, "Supported architectures for binaries"); 3103cb6654dSNathan Whitehorn 31175c13541SPoul-Henning Kamp static int 31282d9ae4eSPoul-Henning Kamp sysctl_hostname(SYSCTL_HANDLER_ARGS) 31375c13541SPoul-Henning Kamp { 31476ca6f88SJamie Gritton struct prison *pr, *cpr; 31576ca6f88SJamie Gritton size_t pr_offset; 31676ca6f88SJamie Gritton char tmpname[MAXHOSTNAMELEN]; 31776ca6f88SJamie Gritton int descend, error, len; 31876ca6f88SJamie Gritton 31976ca6f88SJamie Gritton /* 32076ca6f88SJamie Gritton * This function can set: hostname domainname hostuuid. 32176ca6f88SJamie Gritton * Keep that in mind when comments say "hostname". 32276ca6f88SJamie Gritton */ 32376ca6f88SJamie Gritton pr_offset = (size_t)arg1; 32476ca6f88SJamie Gritton len = arg2; 32576ca6f88SJamie Gritton KASSERT(len <= sizeof(tmpname), 32676ca6f88SJamie Gritton ("length %d too long for %s", len, __func__)); 32775c13541SPoul-Henning Kamp 328a854ed98SJohn Baldwin pr = req->td->td_ucred->cr_prison; 3290304c731SJamie Gritton if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 3306c144e75SRobert Watson return (EPERM); 33101137630SRobert Watson /* 33276ca6f88SJamie Gritton * Make a local copy of hostname to get/set so we don't have to hold 33376ca6f88SJamie Gritton * the jail mutex during the sysctl copyin/copyout activities. 33401137630SRobert Watson */ 33501137630SRobert Watson mtx_lock(&pr->pr_mtx); 33676ca6f88SJamie Gritton bcopy((char *)pr + pr_offset, tmpname, len); 33701137630SRobert Watson mtx_unlock(&pr->pr_mtx); 33801137630SRobert Watson 33976ca6f88SJamie Gritton error = sysctl_handle_string(oidp, tmpname, len, req); 34001137630SRobert Watson 34101137630SRobert Watson if (req->newptr != NULL && error == 0) { 34201137630SRobert Watson /* 34376ca6f88SJamie Gritton * Copy the locally set hostname to all jails that share 34476ca6f88SJamie Gritton * this host info. 34501137630SRobert Watson */ 34676ca6f88SJamie Gritton sx_slock(&allprison_lock); 34776ca6f88SJamie Gritton while (!(pr->pr_flags & PR_HOST)) 34876ca6f88SJamie Gritton pr = pr->pr_parent; 34901137630SRobert Watson mtx_lock(&pr->pr_mtx); 35076ca6f88SJamie Gritton bcopy(tmpname, (char *)pr + pr_offset, len); 35176ca6f88SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 35276ca6f88SJamie Gritton if (cpr->pr_flags & PR_HOST) 35376ca6f88SJamie Gritton descend = 0; 35476ca6f88SJamie Gritton else 35576ca6f88SJamie Gritton bcopy(tmpname, (char *)cpr + pr_offset, len); 35601137630SRobert Watson mtx_unlock(&pr->pr_mtx); 35776ca6f88SJamie Gritton sx_sunlock(&allprison_lock); 3584f7d1876SRobert Watson } 35975c13541SPoul-Henning Kamp return (error); 36075c13541SPoul-Henning Kamp } 36175c13541SPoul-Henning Kamp 36275c13541SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, 3630176ca2eSAllan Jude CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, 364c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN, 36576ca6f88SJamie Gritton sysctl_hostname, "A", "Hostname"); 36676ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname, 3670176ca2eSAllan Jude CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, 368c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN, 36976ca6f88SJamie Gritton sysctl_hostname, "A", "Name of the current YP/NIS domain"); 37076ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid, 3710176ca2eSAllan Jude CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, 372c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN, 37376ca6f88SJamie Gritton sysctl_hostname, "A", "Host UUID"); 37445ec3b38SPoul-Henning Kamp 375eacb362fSRobert Watson static int regression_securelevel_nonmonotonic = 0; 376c175d222SRobert Watson 3771e4b531bSRobert Watson #ifdef REGRESSION 378c175d222SRobert Watson SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW, 379c175d222SRobert Watson ®ression_securelevel_nonmonotonic, 0, "securelevel may be lowered"); 380eacb362fSRobert Watson #endif 381c175d222SRobert Watson 38245ec3b38SPoul-Henning Kamp static int 38382d9ae4eSPoul-Henning Kamp sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) 38445ec3b38SPoul-Henning Kamp { 3850304c731SJamie Gritton struct prison *pr, *cpr; 3860304c731SJamie Gritton int descend, error, level; 38745ec3b38SPoul-Henning Kamp 388a854ed98SJohn Baldwin pr = req->td->td_ucred->cr_prison; 389d3c9fa04SRobert Watson 3908a528812SRobert Watson /* 3910304c731SJamie Gritton * Reading the securelevel is easy, since the current jail's level 3920304c731SJamie Gritton * is known to be at least as secure as any higher levels. Perform 3930304c731SJamie Gritton * a lockless read since the securelevel is an integer. 3948a528812SRobert Watson */ 3950304c731SJamie Gritton level = pr->pr_securelevel; 39645ec3b38SPoul-Henning Kamp error = sysctl_handle_int(oidp, &level, 0, req); 39745ec3b38SPoul-Henning Kamp if (error || !req->newptr) 39845ec3b38SPoul-Henning Kamp return (error); 3990304c731SJamie Gritton /* Permit update only if the new securelevel exceeds the old. */ 4000304c731SJamie Gritton sx_slock(&allprison_lock); 40101137630SRobert Watson mtx_lock(&pr->pr_mtx); 4021e4b531bSRobert Watson if (!regression_securelevel_nonmonotonic && 4030304c731SJamie Gritton level < pr->pr_securelevel) { 40401137630SRobert Watson mtx_unlock(&pr->pr_mtx); 4050304c731SJamie Gritton sx_sunlock(&allprison_lock); 4068a528812SRobert Watson return (EPERM); 40701137630SRobert Watson } 408d3c9fa04SRobert Watson pr->pr_securelevel = level; 4090304c731SJamie Gritton /* 4100304c731SJamie Gritton * Set all child jails to be at least this level, but do not lower 4110304c731SJamie Gritton * them (even if regression_securelevel_nonmonotonic). 4120304c731SJamie Gritton */ 4130304c731SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) { 4140304c731SJamie Gritton if (cpr->pr_securelevel < level) 4150304c731SJamie Gritton cpr->pr_securelevel = level; 4160304c731SJamie Gritton } 41701137630SRobert Watson mtx_unlock(&pr->pr_mtx); 4180304c731SJamie Gritton sx_sunlock(&allprison_lock); 41945ec3b38SPoul-Henning Kamp return (error); 42045ec3b38SPoul-Henning Kamp } 42145ec3b38SPoul-Henning Kamp 4228a528812SRobert Watson SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, 4237029da5cSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 0, 0, 4247029da5cSPawel Biernacki sysctl_kern_securelvl, "I", 4257029da5cSPawel Biernacki "Current secure level"); 426e812e491SRobert Watson 4275f9974aeSWojciech A. Koszek #ifdef INCLUDE_CONFIG_FILE 428744b947eSWojciech A. Koszek /* Actual kernel configuration options. */ 429744b947eSWojciech A. Koszek extern char kernconfstring[]; 430744b947eSWojciech A. Koszek 43153dc58f2SMateusz Guzik SYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD | CTLFLAG_MPSAFE, 43253dc58f2SMateusz Guzik kernconfstring, 0, "Kernel configuration file"); 4333627f737SWarner Losh #endif 434744b947eSWojciech A. Koszek 4354f7d1876SRobert Watson static int 43676ca6f88SJamie Gritton sysctl_hostid(SYSCTL_HANDLER_ARGS) 4374f7d1876SRobert Watson { 43876ca6f88SJamie Gritton struct prison *pr, *cpr; 43976ca6f88SJamie Gritton u_long tmpid; 44076ca6f88SJamie Gritton int descend, error; 4414f7d1876SRobert Watson 44276ca6f88SJamie Gritton /* 44376ca6f88SJamie Gritton * Like sysctl_hostname, except it operates on a u_long 44476ca6f88SJamie Gritton * instead of a string, and is used only for hostid. 44576ca6f88SJamie Gritton */ 44676ca6f88SJamie Gritton pr = req->td->td_ucred->cr_prison; 44776ca6f88SJamie Gritton if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 44876ca6f88SJamie Gritton return (EPERM); 44976ca6f88SJamie Gritton tmpid = pr->pr_hostid; 45076ca6f88SJamie Gritton error = sysctl_handle_long(oidp, &tmpid, 0, req); 45176ca6f88SJamie Gritton 4524f7d1876SRobert Watson if (req->newptr != NULL && error == 0) { 45376ca6f88SJamie Gritton sx_slock(&allprison_lock); 45476ca6f88SJamie Gritton while (!(pr->pr_flags & PR_HOST)) 45576ca6f88SJamie Gritton pr = pr->pr_parent; 45676ca6f88SJamie Gritton mtx_lock(&pr->pr_mtx); 45776ca6f88SJamie Gritton pr->pr_hostid = tmpid; 45876ca6f88SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 45976ca6f88SJamie Gritton if (cpr->pr_flags & PR_HOST) 46076ca6f88SJamie Gritton descend = 0; 46176ca6f88SJamie Gritton else 46276ca6f88SJamie Gritton cpr->pr_hostid = tmpid; 46376ca6f88SJamie Gritton mtx_unlock(&pr->pr_mtx); 46476ca6f88SJamie Gritton sx_sunlock(&allprison_lock); 4654f7d1876SRobert Watson } 4664f7d1876SRobert Watson return (error); 4674f7d1876SRobert Watson } 4684f7d1876SRobert Watson 46976ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTID, hostid, 470200241b5SBryan Drewery CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, 47176ca6f88SJamie Gritton NULL, 0, sysctl_hostid, "LU", "Host ID"); 47245ec3b38SPoul-Henning Kamp 47334086d5bSConrad Meyer static struct mtx bootid_lk; 47434086d5bSConrad Meyer MTX_SYSINIT(bootid_lock, &bootid_lk, "bootid generator lock", MTX_DEF); 47534086d5bSConrad Meyer 47634086d5bSConrad Meyer static int 47734086d5bSConrad Meyer sysctl_bootid(SYSCTL_HANDLER_ARGS) 47834086d5bSConrad Meyer { 47934086d5bSConrad Meyer static uint8_t boot_id[16]; 48034086d5bSConrad Meyer static bool initialized = false; 48134086d5bSConrad Meyer 48234086d5bSConrad Meyer mtx_lock(&bootid_lk); 48334086d5bSConrad Meyer if (!initialized) { 48434086d5bSConrad Meyer if (!is_random_seeded()) { 48534086d5bSConrad Meyer mtx_unlock(&bootid_lk); 48634086d5bSConrad Meyer return (ENXIO); 48734086d5bSConrad Meyer } 48834086d5bSConrad Meyer arc4random_buf(boot_id, sizeof(boot_id)); 48934086d5bSConrad Meyer initialized = true; 49034086d5bSConrad Meyer } 49134086d5bSConrad Meyer mtx_unlock(&bootid_lk); 49234086d5bSConrad Meyer 49334086d5bSConrad Meyer return (SYSCTL_OUT(req, boot_id, sizeof(boot_id))); 49434086d5bSConrad Meyer } 49534086d5bSConrad Meyer SYSCTL_PROC(_kern, OID_AUTO, boot_id, 49634086d5bSConrad Meyer CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, 49734086d5bSConrad Meyer NULL, 0, sysctl_bootid, "", "Random boot ID"); 49834086d5bSConrad Meyer 499b96bd95bSIan Lepore /* 500b96bd95bSIan Lepore * The osrelease string is copied from the global (osrelease in vers.c) into 501b96bd95bSIan Lepore * prison0 by a sysinit and is inherited by child jails if not changed at jail 502b96bd95bSIan Lepore * creation, so we always return the copy from the current prison data. 503b96bd95bSIan Lepore */ 504b96bd95bSIan Lepore static int 505b96bd95bSIan Lepore sysctl_osrelease(SYSCTL_HANDLER_ARGS) 506b96bd95bSIan Lepore { 507b96bd95bSIan Lepore struct prison *pr; 508b96bd95bSIan Lepore 509b96bd95bSIan Lepore pr = req->td->td_ucred->cr_prison; 510b96bd95bSIan Lepore return (SYSCTL_OUT(req, pr->pr_osrelease, strlen(pr->pr_osrelease) + 1)); 511b96bd95bSIan Lepore 512b96bd95bSIan Lepore } 513b96bd95bSIan Lepore 514b96bd95bSIan Lepore SYSCTL_PROC(_kern, KERN_OSRELEASE, osrelease, 515b96bd95bSIan Lepore CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, 516b96bd95bSIan Lepore NULL, 0, sysctl_osrelease, "A", "Operating system release"); 517b96bd95bSIan Lepore 518b96bd95bSIan Lepore /* 519b96bd95bSIan Lepore * The osreldate number is copied from the global (osreldate in vers.c) into 520b96bd95bSIan Lepore * prison0 by a sysinit and is inherited by child jails if not changed at jail 521b96bd95bSIan Lepore * creation, so we always return the value from the current prison data. 522b96bd95bSIan Lepore */ 523b96bd95bSIan Lepore static int 524b96bd95bSIan Lepore sysctl_osreldate(SYSCTL_HANDLER_ARGS) 525b96bd95bSIan Lepore { 526b96bd95bSIan Lepore struct prison *pr; 527b96bd95bSIan Lepore 528b96bd95bSIan Lepore pr = req->td->td_ucred->cr_prison; 529b96bd95bSIan Lepore return (SYSCTL_OUT(req, &pr->pr_osreldate, sizeof(pr->pr_osreldate))); 530b96bd95bSIan Lepore 531b96bd95bSIan Lepore } 532b96bd95bSIan Lepore 533b96bd95bSIan Lepore /* 534b96bd95bSIan Lepore * NOTICE: The *userland* release date is available in 535b96bd95bSIan Lepore * /usr/include/osreldate.h 536b96bd95bSIan Lepore */ 537b96bd95bSIan Lepore SYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate, 538b96bd95bSIan Lepore CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, 539b96bd95bSIan Lepore NULL, 0, sysctl_osreldate, "I", "Kernel release date"); 540b96bd95bSIan Lepore 54174cd06b4SEd Maste /* 54274cd06b4SEd Maste * The build-id is copied from the ELF section .note.gnu.build-id. The linker 54374cd06b4SEd Maste * script defines two variables to expose the beginning and end. LLVM 54474cd06b4SEd Maste * currently uses a SHA-1 hash, but other formats can be supported by checking 54574cd06b4SEd Maste * the length of the section. 54674cd06b4SEd Maste */ 54774cd06b4SEd Maste 54874cd06b4SEd Maste extern char __build_id_start[]; 54974cd06b4SEd Maste extern char __build_id_end[]; 55074cd06b4SEd Maste 55174cd06b4SEd Maste #define BUILD_ID_HEADER_LEN 0x10 55274cd06b4SEd Maste #define BUILD_ID_HASH_MAXLEN 0x14 55374cd06b4SEd Maste 55474cd06b4SEd Maste static int 55574cd06b4SEd Maste sysctl_build_id(SYSCTL_HANDLER_ARGS) 55674cd06b4SEd Maste { 55774cd06b4SEd Maste uintptr_t sectionlen = (uintptr_t)(__build_id_end - __build_id_start); 55874cd06b4SEd Maste int hashlen; 55974cd06b4SEd Maste char buf[2*BUILD_ID_HASH_MAXLEN+1]; 56074cd06b4SEd Maste 56174cd06b4SEd Maste /* 56274cd06b4SEd Maste * The ELF note section has a four byte length for the vendor name, 56374cd06b4SEd Maste * four byte length for the value, and a four byte vendor specific 56474cd06b4SEd Maste * type. The name for the build id is "GNU\0". We skip the first 16 56574cd06b4SEd Maste * bytes to read the build hash. We will return the remaining bytes up 56674cd06b4SEd Maste * to 20 (SHA-1) hash size. If the hash happens to be a custom number 56774cd06b4SEd Maste * of bytes we will pad the value with zeros, as the section should be 56874cd06b4SEd Maste * four byte aligned. 56974cd06b4SEd Maste */ 57074cd06b4SEd Maste if (sectionlen <= BUILD_ID_HEADER_LEN || 57174cd06b4SEd Maste sectionlen > (BUILD_ID_HEADER_LEN + BUILD_ID_HASH_MAXLEN)) { 57274cd06b4SEd Maste return (ENOENT); 57374cd06b4SEd Maste } 57474cd06b4SEd Maste 57574cd06b4SEd Maste hashlen = sectionlen - BUILD_ID_HEADER_LEN; 57674cd06b4SEd Maste for (int i = 0; i < hashlen; i++) { 57774cd06b4SEd Maste uint8_t c = __build_id_start[i+BUILD_ID_HEADER_LEN]; 57874cd06b4SEd Maste snprintf(&buf[2*i], 3, "%02x", c); 57974cd06b4SEd Maste } 58074cd06b4SEd Maste 58174cd06b4SEd Maste return (SYSCTL_OUT(req, buf, strlen(buf) + 1)); 58274cd06b4SEd Maste } 58374cd06b4SEd Maste 58474cd06b4SEd Maste SYSCTL_PROC(_kern, OID_AUTO, build_id, 58574cd06b4SEd Maste CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, 58674cd06b4SEd Maste NULL, 0, sysctl_build_id, "A", "Operating system build-id"); 58774cd06b4SEd Maste 5887029da5cSPawel Biernacki SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 5897029da5cSPawel Biernacki "Kernel Features"); 5900deabe7eSJohn Baldwin 5912c179010SJohn Baldwin #ifdef COMPAT_FREEBSD4 5922c179010SJohn Baldwin FEATURE(compat_freebsd4, "Compatible with FreeBSD 4"); 5932c179010SJohn Baldwin #endif 5942c179010SJohn Baldwin 5952c179010SJohn Baldwin #ifdef COMPAT_FREEBSD5 5962c179010SJohn Baldwin FEATURE(compat_freebsd5, "Compatible with FreeBSD 5"); 5972c179010SJohn Baldwin #endif 5982c179010SJohn Baldwin 5992c179010SJohn Baldwin #ifdef COMPAT_FREEBSD6 6002c179010SJohn Baldwin FEATURE(compat_freebsd6, "Compatible with FreeBSD 6"); 6012c179010SJohn Baldwin #endif 6022c179010SJohn Baldwin 6032c179010SJohn Baldwin #ifdef COMPAT_FREEBSD7 6042c179010SJohn Baldwin FEATURE(compat_freebsd7, "Compatible with FreeBSD 7"); 6052c179010SJohn Baldwin #endif 6062c179010SJohn Baldwin 60745ec3b38SPoul-Henning Kamp /* 60845ec3b38SPoul-Henning Kamp * This is really cheating. These actually live in the libc, something 60945ec3b38SPoul-Henning Kamp * which I'm not quite sure is a good idea anyway, but in order for 61045ec3b38SPoul-Henning Kamp * getnext and friends to actually work, we define dummies here. 611ff66f6a4SRobert Watson * 612ff66f6a4SRobert Watson * XXXRW: These probably should be CTLFLAG_CAPRD. 61345ec3b38SPoul-Henning Kamp */ 6143d177f46SBill Fumerola SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, 6153d177f46SBill Fumerola "", 0, "PATH that finds all the standard utilities"); 6163d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 617f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Max ibase/obase values in bc(1)"); 6183d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 619f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Max array size in bc(1)"); 6203d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 621f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Max scale value in bc(1)"); 6223d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 623f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Max string length in bc(1)"); 6243d177f46SBill Fumerola SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 625f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry"); 626f0188618SHans Petter Selasky SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 627f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, ""); 6283d177f46SBill Fumerola SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 629f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Max length (bytes) of a text-processing utility's input line"); 6303d177f46SBill Fumerola SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 631f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Maximum number of repeats of a regexp permitted"); 6323d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 633f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, 6343d177f46SBill Fumerola "The version of POSIX 1003.2 with which the system attempts to comply"); 6353d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 636f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether C development supports the C bindings option"); 6373d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 638f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports the C development utilities option"); 6393d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 640f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, ""); 6413d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 642f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN development utilities"); 6433d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 644f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN runtime utilities"); 6453d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 646f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports creation of locales"); 6473d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 648f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports software development utilities"); 6493d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 650f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports the user portability utilities"); 6513d177f46SBill Fumerola SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 652f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time"); 6533d177f46SBill Fumerola SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 654f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names"); 6556f13bfc2SPoul-Henning Kamp 6566f13bfc2SPoul-Henning Kamp #include <sys/vnode.h> 6576f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD, 658f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, sizeof(struct vnode), "sizeof(struct vnode)"); 6596f13bfc2SPoul-Henning Kamp 6606f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD, 661f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, sizeof(struct proc), "sizeof(struct proc)"); 662d7bf417dSPoul-Henning Kamp 66302c6fc21SKonstantin Belousov static int 66402c6fc21SKonstantin Belousov sysctl_kern_pid_max(SYSCTL_HANDLER_ARGS) 66502c6fc21SKonstantin Belousov { 66602c6fc21SKonstantin Belousov int error, pm; 66702c6fc21SKonstantin Belousov 66802c6fc21SKonstantin Belousov pm = pid_max; 66902c6fc21SKonstantin Belousov error = sysctl_handle_int(oidp, &pm, 0, req); 67002c6fc21SKonstantin Belousov if (error || !req->newptr) 67102c6fc21SKonstantin Belousov return (error); 67202c6fc21SKonstantin Belousov sx_xlock(&proctree_lock); 67302c6fc21SKonstantin Belousov sx_xlock(&allproc_lock); 6743fa615bcSKonstantin Belousov 6753fa615bcSKonstantin Belousov /* 6763fa615bcSKonstantin Belousov * Only permit the values less then PID_MAX. 6773fa615bcSKonstantin Belousov * As a safety measure, do not allow to limit the pid_max too much. 6783fa615bcSKonstantin Belousov */ 6793fa615bcSKonstantin Belousov if (pm < 300 || pm > PID_MAX) 68002c6fc21SKonstantin Belousov error = EINVAL; 68102c6fc21SKonstantin Belousov else 68202c6fc21SKonstantin Belousov pid_max = pm; 68302c6fc21SKonstantin Belousov sx_xunlock(&allproc_lock); 68402c6fc21SKonstantin Belousov sx_xunlock(&proctree_lock); 68502c6fc21SKonstantin Belousov return (error); 68602c6fc21SKonstantin Belousov } 687af3b2549SHans Petter Selasky SYSCTL_PROC(_kern, OID_AUTO, pid_max, CTLTYPE_INT | 688af3b2549SHans Petter Selasky CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, 689af3b2549SHans Petter Selasky 0, 0, sysctl_kern_pid_max, "I", "Maximum allowed pid"); 69002c6fc21SKonstantin Belousov 6919626b608SPoul-Henning Kamp #include <sys/bio.h> 6928c125869SPoul-Henning Kamp #include <sys/buf.h> 6938c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, 694f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, sizeof(struct bio), "sizeof(struct bio)"); 6958c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD, 696f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, sizeof(struct buf), "sizeof(struct buf)"); 697d5a08a60SJake Burkholder 698d5a08a60SJake Burkholder #include <sys/user.h> 699d5a08a60SJake Burkholder SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, 700f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); 701a360a43dSJake Burkholder 702645743eaSJohn Baldwin /* Used by kernel debuggers. */ 703645743eaSJohn Baldwin const int pcb_size = sizeof(struct pcb); 704645743eaSJohn Baldwin SYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD, 705645743eaSJohn Baldwin SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)"); 706645743eaSJohn Baldwin 707e548a1d4SJake Burkholder /* XXX compatibility, remove for 6.0 */ 708e548a1d4SJake Burkholder #include <sys/imgact.h> 709e548a1d4SJake Burkholder #include <sys/imgact_elf.h> 710e548a1d4SJake Burkholder SYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW, 711e548a1d4SJake Burkholder &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)), 712e548a1d4SJake Burkholder "compatibility for kern.fallback_elf_brand"); 713