xref: /freebsd/sys/kern/kern_mib.c (revision 5862c891bb7c588aa00538d85eb26ffe77d3f709)
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 
38677b542eSDavid E. O'Brien #include <sys/cdefs.h>
39eacb362fSRobert Watson #include "opt_posix.h"
405f9974aeSWojciech A. Koszek #include "opt_config.h"
41c175d222SRobert Watson 
4245ec3b38SPoul-Henning Kamp #include <sys/param.h>
43af9727f6SWarner Losh #include <sys/boot.h>
4461bbe53cSJohn Baldwin #include <sys/elf.h>
45d1b06863SMark Murray #include <sys/jail.h>
4645ec3b38SPoul-Henning Kamp #include <sys/kernel.h>
477a6322e1SKonstantin Belousov #include <sys/limits.h>
4801137630SRobert Watson #include <sys/lock.h>
4901137630SRobert Watson #include <sys/mutex.h>
50d1b06863SMark Murray #include <sys/proc.h>
51d1b06863SMark Murray #include <sys/random.h>
52d1b06863SMark Murray #include <sys/sbuf.h>
536caa8a15SJohn Baldwin #include <sys/smp.h>
540304c731SJamie Gritton #include <sys/sx.h>
553da4d19bSJohn Baldwin #include <sys/sysent.h>
569ed01c32SGleb Smirnoff #include <sys/vmmeter.h>
57d1b06863SMark Murray #include <sys/sysctl.h>
58d1b06863SMark Murray #include <sys/systm.h>
59eeea998cSMike Barcroft #include <sys/unistd.h>
60662f9a69SKATO Takenori 
613e00c11aSAlan Cox #include <vm/vm_param.h>
623e00c11aSAlan Cox 
637029da5cSPawel Biernacki SYSCTL_ROOT_NODE(0, sysctl, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
6445ec3b38SPoul-Henning Kamp     "Sysctl internal magic");
657029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_KERN, kern, CTLFLAG_RW | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, 0,
6645ec3b38SPoul-Henning Kamp     "High kernel, proc, limits &c");
677029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_VM, vm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
6845ec3b38SPoul-Henning Kamp     "Virtual memory");
697029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_VFS, vfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
7045ec3b38SPoul-Henning Kamp     "File system");
717029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_NET, net, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
7245ec3b38SPoul-Henning Kamp     "Network, (see socket.h)");
737029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_DEBUG, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
7445ec3b38SPoul-Henning Kamp     "Debugging");
757029da5cSPawel Biernacki SYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
766f13bfc2SPoul-Henning Kamp     "Sizeof various things");
777029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_HW, hw, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
7845ec3b38SPoul-Henning Kamp     "hardware");
797029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_MACHDEP, machdep, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
8045ec3b38SPoul-Henning Kamp     "machine dependent");
817029da5cSPawel Biernacki SYSCTL_NODE(_machdep, OID_AUTO, mitigations, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
82de890ea4SScott Long     "Machine dependent platform mitigations.");
837029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_USER, user, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
8445ec3b38SPoul-Henning Kamp     "user-level");
857029da5cSPawel Biernacki SYSCTL_ROOT_NODE(CTL_P1003_1B, p1003_1b, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
868a6472b7SPeter Dufault     "p1003_1b, (see p1003_1b.h)");
87644d85f4SPeter Dufault 
887029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, compat, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
89c6dfea0eSMarcel Moolenaar     "Compatibility code");
907029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, security, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
91d0615c64SAndrew R. Reiter     "Security");
92eacb362fSRobert Watson #ifdef REGRESSION
937029da5cSPawel Biernacki SYSCTL_ROOT_NODE(OID_AUTO, regression, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
94eacb362fSRobert Watson     "Regression test MIB");
95eacb362fSRobert Watson #endif
96c6dfea0eSMarcel Moolenaar 
97969fc091SMark Johnston SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
98c02d7621SJuli Mallett     kern_ident, 0, "Kernel identifier");
99da1186f2SJuli Mallett 
100ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD | CTLFLAG_CAPRD,
101f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, BSD, "Operating system revision");
10245ec3b38SPoul-Henning Kamp 
103969fc091SMark Johnston SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
1043d177f46SBill Fumerola     version, 0, "Kernel version");
10545ec3b38SPoul-Henning Kamp 
106969fc091SMark Johnston SYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD,
107bfdcb3bcSAndriy Gapon     compiler_version, 0, "Version of compiler used to compile kernel");
108bfdcb3bcSAndriy Gapon 
109969fc091SMark Johnston SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD | CTLFLAG_CAPRD,
110969fc091SMark Johnston     ostype, 0, "Operating system type");
11145ec3b38SPoul-Henning Kamp 
112af3b2549SHans Petter Selasky SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
1133d177f46SBill Fumerola     &maxproc, 0, "Maximum number of processes");
11445ec3b38SPoul-Henning Kamp 
1153d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
1163d177f46SBill Fumerola     &maxprocperuid, 0, "Maximum processes allowed per userid");
11745ec3b38SPoul-Henning Kamp 
118af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
119ee342e1bSPeter Wemm     &maxusers, 0, "Hint for kernel tuning");
120ee342e1bSPeter Wemm 
121ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD,
122f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, ARG_MAX, "Maximum bytes of argument to execve(2)");
12345ec3b38SPoul-Henning Kamp 
124ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD,
125f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, _POSIX_VERSION, "Version of POSIX attempting to comply to");
12645ec3b38SPoul-Henning Kamp 
127af3b2549SHans Petter Selasky SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN |
128af3b2549SHans Petter Selasky     CTLFLAG_NOFETCH | CTLFLAG_CAPRD, &ngroups_max, 0,
1295feedc25SBrooks Davis     "Maximum number of supplemental groups a user can belong to");
13045ec3b38SPoul-Henning Kamp 
131ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD,
132f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 1, "Whether job control is available");
13345ec3b38SPoul-Henning Kamp 
13445ec3b38SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS
135ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
136f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 1, "Whether saved set-group/user ID is available");
13745ec3b38SPoul-Henning Kamp #else
138ff66f6a4SRobert Watson SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
139f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether saved set-group/user ID is available");
14045ec3b38SPoul-Henning Kamp #endif
14145ec3b38SPoul-Henning Kamp 
142ec9abc18SWarner Losh char kernelname[MAXPATHLEN] = PATH_KERNEL;	/* XXX bloat */
14345ec3b38SPoul-Henning Kamp 
144969fc091SMark Johnston SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
1453d177f46SBill Fumerola     kernelname, sizeof kernelname, "Name of kernel file booted");
14645ec3b38SPoul-Henning Kamp 
147cd853791SKonstantin Belousov #ifdef COMPAT_FREEBSD12
148cd853791SKonstantin Belousov static int
149cd853791SKonstantin Belousov sysctl_maxphys(SYSCTL_HANDLER_ARGS)
150cd853791SKonstantin Belousov {
151cd853791SKonstantin Belousov 	u_long lvalue;
152cd853791SKonstantin Belousov 	int ivalue;
153cd853791SKonstantin Belousov 
154cd853791SKonstantin Belousov 	lvalue = maxphys;
155cd853791SKonstantin Belousov 	if (sizeof(int) == sizeof(u_long) || req->oldlen >= sizeof(u_long))
156cd853791SKonstantin Belousov 		return (sysctl_handle_long(oidp, &lvalue, 0, req));
157cd853791SKonstantin Belousov 	if (lvalue > INT_MAX)
158cd853791SKonstantin Belousov 		return (sysctl_handle_long(oidp, &lvalue, 0, req));
159cd853791SKonstantin Belousov 	ivalue = lvalue;
160cd853791SKonstantin Belousov 	return (sysctl_handle_int(oidp, &ivalue, 0, req));
161cd853791SKonstantin Belousov }
162cd853791SKonstantin Belousov SYSCTL_PROC(_kern, KERN_MAXPHYS, maxphys, CTLTYPE_LONG | CTLFLAG_RDTUN |
163cd853791SKonstantin Belousov     CTLFLAG_NOFETCH | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
164cd853791SKonstantin Belousov     NULL, 0, sysctl_maxphys, "UL", "Maximum block I/O access size");
165cd853791SKonstantin Belousov #else
166cd853791SKonstantin Belousov SYSCTL_ULONG(_kern, KERN_MAXPHYS, maxphys,
167cd853791SKonstantin Belousov     CTLFLAG_RDTUN | CTLFLAG_NOFETCH | CTLFLAG_CAPRD,
168cd853791SKonstantin Belousov     &maxphys, 0, "Maximum block I/O access size");
169cd853791SKonstantin Belousov #endif
1707ed6b78bSGleb Smirnoff 
171ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD,
1723d177f46SBill Fumerola     &mp_ncpus, 0, "Number of active CPUs");
17345ec3b38SPoul-Henning Kamp 
174ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD,
175f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, BYTE_ORDER, "System byte order");
17645ec3b38SPoul-Henning Kamp 
177ff66f6a4SRobert Watson SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD,
178f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, PAGE_SIZE, "System memory page size");
17945ec3b38SPoul-Henning Kamp 
1800fca57b8SThomas Moestl static int
181ee9f4661SAlexander Kabaev sysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
182ee9f4661SAlexander Kabaev {
183370f990dSAntoine Brodin 	char buf[256];
184370f990dSAntoine Brodin 	size_t len;
185*5862c891SKyle Evans 	int error;
186ee9f4661SAlexander Kabaev 
18713774e82SConrad Meyer 	len = MIN(req->oldlen, sizeof(buf));
18813774e82SConrad Meyer 	read_random(buf, len);
189*5862c891SKyle Evans 
190*5862c891SKyle Evans 	error = SYSCTL_OUT(req, buf, len);
191*5862c891SKyle Evans 	explicit_bzero(buf, len);
192*5862c891SKyle Evans 	return (error);
193ee9f4661SAlexander Kabaev }
194ee9f4661SAlexander Kabaev 
195f3b86a5fSEd Schouten SYSCTL_PROC(_kern, KERN_ARND, arandom,
196ff66f6a4SRobert Watson     CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0,
197f3b86a5fSEd Schouten     sysctl_kern_arnd, "", "arc4rand");
198ee9f4661SAlexander Kabaev 
199ee9f4661SAlexander Kabaev static int
2000fca57b8SThomas Moestl sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
2010fca57b8SThomas Moestl {
2027a6322e1SKonstantin Belousov 	u_long val, p;
2030fca57b8SThomas Moestl 
2047a6322e1SKonstantin Belousov 	p = SIZE_T_MAX >> PAGE_SHIFT;
2057a6322e1SKonstantin Belousov 	if (physmem < p)
2067a6322e1SKonstantin Belousov 		p = physmem;
2077a6322e1SKonstantin Belousov 	val = ctob(p);
2080fca57b8SThomas Moestl 	return (sysctl_handle_long(oidp, &val, 0, req));
2090fca57b8SThomas Moestl }
2107029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_PHYSMEM, physmem,
2117029da5cSPawel Biernacki     CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
2127029da5cSPawel Biernacki     sysctl_hw_physmem, "LU",
213557e162fSRavi Pokala     "Amount of physical memory (in bytes)");
2140fca57b8SThomas Moestl 
2150fca57b8SThomas Moestl static int
216a0915044SWes Peters sysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
217a0915044SWes Peters {
2187a6322e1SKonstantin Belousov 	u_long val, p;
2197a6322e1SKonstantin Belousov 
2207a6322e1SKonstantin Belousov 	p = SIZE_T_MAX >> PAGE_SHIFT;
2217a6322e1SKonstantin Belousov 	if (realmem < p)
2227a6322e1SKonstantin Belousov 		p = realmem;
2237a6322e1SKonstantin Belousov 	val = ctob(p);
224a0915044SWes Peters 	return (sysctl_handle_long(oidp, &val, 0, req));
225a0915044SWes Peters }
2267029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_REALMEM, realmem,
2277029da5cSPawel Biernacki     CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
2287029da5cSPawel Biernacki     sysctl_hw_realmem, "LU",
229557e162fSRavi Pokala     "Amount of memory (in bytes) reported by the firmware");
2307a6322e1SKonstantin Belousov 
231a0915044SWes Peters static int
2320fca57b8SThomas Moestl sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
2330fca57b8SThomas Moestl {
2347a6322e1SKonstantin Belousov 	u_long val, p, p1;
2350fca57b8SThomas Moestl 
2367a6322e1SKonstantin Belousov 	p1 = physmem - vm_wire_count();
2377a6322e1SKonstantin Belousov 	p = SIZE_T_MAX >> PAGE_SHIFT;
2387a6322e1SKonstantin Belousov 	if (p1 < p)
2397a6322e1SKonstantin Belousov 		p = p1;
2407a6322e1SKonstantin Belousov 	val = ctob(p);
2410fca57b8SThomas Moestl 	return (sysctl_handle_long(oidp, &val, 0, req));
2420fca57b8SThomas Moestl }
2437029da5cSPawel Biernacki SYSCTL_PROC(_hw, HW_USERMEM, usermem,
2447029da5cSPawel Biernacki     CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
2457029da5cSPawel Biernacki     sysctl_hw_usermem, "LU",
246557e162fSRavi Pokala     "Amount of memory (in bytes) which is not wired");
2470fca57b8SThomas Moestl 
248557e162fSRavi Pokala SYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0,
249557e162fSRavi Pokala     "Amount of physical memory (in pages)");
2500fca57b8SThomas Moestl 
2513e00c11aSAlan Cox #if VM_NRESERVLEVEL > 0
2523e00c11aSAlan Cox _Static_assert(MAXPAGESIZES > VM_NRESERVLEVEL, "MAXPAGESIZES is too small");
2533e00c11aSAlan Cox #endif
2543e00c11aSAlan Cox 
2553e00c11aSAlan Cox u_long __read_mostly pagesizes[MAXPAGESIZES] = { PAGE_SIZE };
256fe105d45SAlan Cox 
257fe105d45SAlan Cox static int
258fe105d45SAlan Cox sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
259fe105d45SAlan Cox {
260fe105d45SAlan Cox 	int error;
261697503c4SKonstantin Belousov 	size_t len;
262fe105d45SAlan Cox #ifdef SCTL_MASK32
263fe105d45SAlan Cox 	int i;
264fe105d45SAlan Cox 	uint32_t pagesizes32[MAXPAGESIZES];
265fe105d45SAlan Cox 
266fe105d45SAlan Cox 	if (req->flags & SCTL_MASK32) {
267fe105d45SAlan Cox 		/*
268a2b127aeSKonstantin Belousov 		 * Recreate the "pagesizes" array with 32-bit elements.
269a2b127aeSKonstantin Belousov 		 * Truncate any page size greater than UINT32_MAX to zero,
270a2b127aeSKonstantin Belousov 		 * which assumes that page sizes are powers of two.
271fe105d45SAlan Cox 		 */
272fe105d45SAlan Cox 		for (i = 0; i < MAXPAGESIZES; i++)
273fe105d45SAlan Cox 			pagesizes32[i] = (uint32_t)pagesizes[i];
274fe105d45SAlan Cox 
275697503c4SKonstantin Belousov 		len = sizeof(pagesizes32);
276a0efcf64SMark Johnston 		if (len > req->oldlen && req->oldptr != NULL)
277697503c4SKonstantin Belousov 			len = req->oldlen;
278697503c4SKonstantin Belousov 		error = SYSCTL_OUT(req, pagesizes32, len);
279fe105d45SAlan Cox 	} else
280fe105d45SAlan Cox #endif
281697503c4SKonstantin Belousov 	{
282697503c4SKonstantin Belousov 		len = sizeof(pagesizes);
283a0efcf64SMark Johnston 		if (len > req->oldlen && req->oldptr != NULL)
284697503c4SKonstantin Belousov 			len = req->oldlen;
285697503c4SKonstantin Belousov 		error = SYSCTL_OUT(req, pagesizes, len);
286697503c4SKonstantin Belousov 	}
287fe105d45SAlan Cox 	return (error);
288fe105d45SAlan Cox }
2897029da5cSPawel Biernacki SYSCTL_PROC(_hw, OID_AUTO, pagesizes,
290a0efcf64SMark Johnston     CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
291a0efcf64SMark Johnston     sysctl_hw_pagesizes, "S,pagesizes",
2927029da5cSPawel Biernacki     "Supported page sizes");
293fe105d45SAlan Cox 
29487d45a03SKonstantin Belousov int adaptive_machine_arch = 1;
29587d45a03SKonstantin Belousov SYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW,
29687d45a03SKonstantin Belousov     &adaptive_machine_arch, 1,
29787d45a03SKonstantin Belousov     "Adapt reported machine architecture to the ABI of the binary");
2983da4d19bSJohn Baldwin 
2993da4d19bSJohn Baldwin static const char *
3003da4d19bSJohn Baldwin proc_machine_arch(struct proc *p)
3013da4d19bSJohn Baldwin {
3023da4d19bSJohn Baldwin 
3033da4d19bSJohn Baldwin 	if (p->p_sysent->sv_machine_arch != NULL)
3043da4d19bSJohn Baldwin 		return (p->p_sysent->sv_machine_arch(p));
3053da4d19bSJohn Baldwin #ifdef COMPAT_FREEBSD32
3063da4d19bSJohn Baldwin 	if (SV_PROC_FLAG(p, SV_ILP32))
3073da4d19bSJohn Baldwin 		return (MACHINE_ARCH32);
30887d45a03SKonstantin Belousov #endif
3093da4d19bSJohn Baldwin 	return (MACHINE_ARCH);
3103da4d19bSJohn Baldwin }
31187d45a03SKonstantin Belousov 
31287d45a03SKonstantin Belousov static int
31387d45a03SKonstantin Belousov sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
31487d45a03SKonstantin Belousov {
3153da4d19bSJohn Baldwin 	const char *machine_arch;
31687d45a03SKonstantin Belousov 
3173da4d19bSJohn Baldwin 	if (adaptive_machine_arch)
3183da4d19bSJohn Baldwin 		machine_arch = proc_machine_arch(curproc);
31987d45a03SKonstantin Belousov 	else
3203da4d19bSJohn Baldwin 		machine_arch = MACHINE_ARCH;
3213da4d19bSJohn Baldwin 	return (SYSCTL_OUT(req, machine_arch, strlen(machine_arch) + 1));
32287d45a03SKonstantin Belousov }
32353dc58f2SMateusz Guzik SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD |
3244a1c4de2SVal Packett     CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine_arch, "A",
32553dc58f2SMateusz Guzik     "System architecture");
326664f8517SKATO Takenori 
3273cb6654dSNathan Whitehorn #ifdef COMPAT_FREEBSD32
32826b36a64SKonstantin Belousov #include <compat/freebsd32/freebsd32_util.h>
3293da4d19bSJohn Baldwin #endif
3303da4d19bSJohn Baldwin 
33126b36a64SKonstantin Belousov static int
33226b36a64SKonstantin Belousov sysctl_kern_supported_archs(SYSCTL_HANDLER_ARGS)
33326b36a64SKonstantin Belousov {
33426b36a64SKonstantin Belousov 	const char *supported_archs;
33526b36a64SKonstantin Belousov 
33626b36a64SKonstantin Belousov 	supported_archs =
33726b36a64SKonstantin Belousov #ifdef COMPAT_FREEBSD32
33826b36a64SKonstantin Belousov 	    compat_freebsd_32bit ? MACHINE_ARCH " " MACHINE_ARCH32 :
33926b36a64SKonstantin Belousov #endif
34026b36a64SKonstantin Belousov 	    MACHINE_ARCH;
34126b36a64SKonstantin Belousov 	return (SYSCTL_OUT(req, supported_archs, strlen(supported_archs) + 1));
34226b36a64SKonstantin Belousov }
34326b36a64SKonstantin Belousov SYSCTL_PROC(_kern, OID_AUTO, supported_archs, CTLFLAG_RD | CTLFLAG_MPSAFE |
34426b36a64SKonstantin Belousov     CTLFLAG_CAPRD | CTLTYPE_STRING, NULL, 0, sysctl_kern_supported_archs, "A",
34526b36a64SKonstantin Belousov     "Supported architectures for binaries");
3463cb6654dSNathan Whitehorn 
34775c13541SPoul-Henning Kamp static int
34882d9ae4eSPoul-Henning Kamp sysctl_hostname(SYSCTL_HANDLER_ARGS)
34975c13541SPoul-Henning Kamp {
35076ca6f88SJamie Gritton 	struct prison *pr, *cpr;
35176ca6f88SJamie Gritton 	size_t pr_offset;
35276ca6f88SJamie Gritton 	char tmpname[MAXHOSTNAMELEN];
35376ca6f88SJamie Gritton 	int descend, error, len;
35476ca6f88SJamie Gritton 
35576ca6f88SJamie Gritton 	/*
35676ca6f88SJamie Gritton 	 * This function can set: hostname domainname hostuuid.
35776ca6f88SJamie Gritton 	 * Keep that in mind when comments say "hostname".
35876ca6f88SJamie Gritton 	 */
35976ca6f88SJamie Gritton 	pr_offset = (size_t)arg1;
36076ca6f88SJamie Gritton 	len = arg2;
36176ca6f88SJamie Gritton 	KASSERT(len <= sizeof(tmpname),
36276ca6f88SJamie Gritton 	    ("length %d too long for %s", len, __func__));
36375c13541SPoul-Henning Kamp 
36401137630SRobert Watson 	/*
36576ca6f88SJamie Gritton 	 * Make a local copy of hostname to get/set so we don't have to hold
36676ca6f88SJamie Gritton 	 * the jail mutex during the sysctl copyin/copyout activities.
36701137630SRobert Watson 	 */
3680fe74ae6SJamie Gritton 	pr = req->td->td_ucred->cr_prison;
36901137630SRobert Watson 	mtx_lock(&pr->pr_mtx);
37076ca6f88SJamie Gritton 	bcopy((char *)pr + pr_offset, tmpname, len);
37101137630SRobert Watson 	mtx_unlock(&pr->pr_mtx);
37201137630SRobert Watson 
37376ca6f88SJamie Gritton 	error = sysctl_handle_string(oidp, tmpname, len, req);
3740fe74ae6SJamie Gritton 	if (error != 0 || req->newptr == NULL)
3750fe74ae6SJamie Gritton 		return (error);
37601137630SRobert Watson 
37701137630SRobert Watson 	/*
37876ca6f88SJamie Gritton 	 * Copy the locally set hostname to all jails that share
37976ca6f88SJamie Gritton 	 * this host info.
38001137630SRobert Watson 	 */
38176ca6f88SJamie Gritton 	sx_slock(&allprison_lock);
3820fe74ae6SJamie Gritton 	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME))
3830fe74ae6SJamie Gritton 		error = EPERM;
3840fe74ae6SJamie Gritton 	else {
38576ca6f88SJamie Gritton 		while (!(pr->pr_flags & PR_HOST))
38676ca6f88SJamie Gritton 			pr = pr->pr_parent;
38701137630SRobert Watson 		mtx_lock(&pr->pr_mtx);
38876ca6f88SJamie Gritton 		bcopy(tmpname, (char *)pr + pr_offset, len);
38976ca6f88SJamie Gritton 		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
39076ca6f88SJamie Gritton 			if (cpr->pr_flags & PR_HOST)
39176ca6f88SJamie Gritton 				descend = 0;
39276ca6f88SJamie Gritton 			else
39376ca6f88SJamie Gritton 				bcopy(tmpname, (char *)cpr + pr_offset, len);
39401137630SRobert Watson 		mtx_unlock(&pr->pr_mtx);
3954f7d1876SRobert Watson 	}
3960fe74ae6SJamie Gritton 	sx_sunlock(&allprison_lock);
39775c13541SPoul-Henning Kamp 	return (error);
39875c13541SPoul-Henning Kamp }
39975c13541SPoul-Henning Kamp 
40075c13541SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
4010176ca2eSAllan Jude     CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
402c1f19219SJamie Gritton     (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN,
40376ca6f88SJamie Gritton     sysctl_hostname, "A", "Hostname");
40476ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname,
4050176ca2eSAllan Jude     CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
406c1f19219SJamie Gritton     (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN,
40776ca6f88SJamie Gritton     sysctl_hostname, "A", "Name of the current YP/NIS domain");
40876ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid,
4090176ca2eSAllan Jude     CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
410c1f19219SJamie Gritton     (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN,
41176ca6f88SJamie Gritton     sysctl_hostname, "A", "Host UUID");
41245ec3b38SPoul-Henning Kamp 
413eacb362fSRobert Watson static int	regression_securelevel_nonmonotonic = 0;
414c175d222SRobert Watson 
4151e4b531bSRobert Watson #ifdef REGRESSION
416c175d222SRobert Watson SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
417c175d222SRobert Watson     &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
418eacb362fSRobert Watson #endif
419c175d222SRobert Watson 
42045ec3b38SPoul-Henning Kamp static int
42182d9ae4eSPoul-Henning Kamp sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
42245ec3b38SPoul-Henning Kamp {
4230304c731SJamie Gritton 	struct prison *pr, *cpr;
4240304c731SJamie Gritton 	int descend, error, level;
42545ec3b38SPoul-Henning Kamp 
426a854ed98SJohn Baldwin 	pr = req->td->td_ucred->cr_prison;
427d3c9fa04SRobert Watson 
4288a528812SRobert Watson 	/*
4290304c731SJamie Gritton 	 * Reading the securelevel is easy, since the current jail's level
4300304c731SJamie Gritton 	 * is known to be at least as secure as any higher levels.  Perform
4310304c731SJamie Gritton 	 * a lockless read since the securelevel is an integer.
4328a528812SRobert Watson 	 */
4330304c731SJamie Gritton 	level = pr->pr_securelevel;
43445ec3b38SPoul-Henning Kamp 	error = sysctl_handle_int(oidp, &level, 0, req);
43545ec3b38SPoul-Henning Kamp 	if (error || !req->newptr)
43645ec3b38SPoul-Henning Kamp 		return (error);
4370304c731SJamie Gritton 	/* Permit update only if the new securelevel exceeds the old. */
4380304c731SJamie Gritton 	sx_slock(&allprison_lock);
43901137630SRobert Watson 	mtx_lock(&pr->pr_mtx);
4401e4b531bSRobert Watson 	if (!regression_securelevel_nonmonotonic &&
4410304c731SJamie Gritton 	    level < pr->pr_securelevel) {
44201137630SRobert Watson 		mtx_unlock(&pr->pr_mtx);
4430304c731SJamie Gritton 		sx_sunlock(&allprison_lock);
4448a528812SRobert Watson 		return (EPERM);
44501137630SRobert Watson 	}
446d3c9fa04SRobert Watson 	pr->pr_securelevel = level;
4470304c731SJamie Gritton 	/*
4480304c731SJamie Gritton 	 * Set all child jails to be at least this level, but do not lower
4490304c731SJamie Gritton 	 * them (even if regression_securelevel_nonmonotonic).
4500304c731SJamie Gritton 	 */
4510304c731SJamie Gritton 	FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
4520304c731SJamie Gritton 		if (cpr->pr_securelevel < level)
4530304c731SJamie Gritton 			cpr->pr_securelevel = level;
4540304c731SJamie Gritton 	}
45501137630SRobert Watson 	mtx_unlock(&pr->pr_mtx);
4560304c731SJamie Gritton 	sx_sunlock(&allprison_lock);
45745ec3b38SPoul-Henning Kamp 	return (error);
45845ec3b38SPoul-Henning Kamp }
45945ec3b38SPoul-Henning Kamp 
4608a528812SRobert Watson SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
4617029da5cSPawel Biernacki     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 0, 0,
4627029da5cSPawel Biernacki     sysctl_kern_securelvl, "I",
4637029da5cSPawel Biernacki     "Current secure level");
464e812e491SRobert Watson 
4655f9974aeSWojciech A. Koszek #ifdef INCLUDE_CONFIG_FILE
466744b947eSWojciech A. Koszek /* Actual kernel configuration options. */
467744b947eSWojciech A. Koszek extern char kernconfstring[];
468744b947eSWojciech A. Koszek 
469969fc091SMark Johnston SYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD,
47053dc58f2SMateusz Guzik     kernconfstring, 0, "Kernel configuration file");
4713627f737SWarner Losh #endif
472744b947eSWojciech A. Koszek 
4734f7d1876SRobert Watson static int
47476ca6f88SJamie Gritton sysctl_hostid(SYSCTL_HANDLER_ARGS)
4754f7d1876SRobert Watson {
47676ca6f88SJamie Gritton 	struct prison *pr, *cpr;
47776ca6f88SJamie Gritton 	u_long tmpid;
47876ca6f88SJamie Gritton 	int descend, error;
4794f7d1876SRobert Watson 
48076ca6f88SJamie Gritton 	/*
48176ca6f88SJamie Gritton 	 * Like sysctl_hostname, except it operates on a u_long
48276ca6f88SJamie Gritton 	 * instead of a string, and is used only for hostid.
48376ca6f88SJamie Gritton 	 */
48476ca6f88SJamie Gritton 	pr = req->td->td_ucred->cr_prison;
4850fe74ae6SJamie Gritton 	mtx_lock(&pr->pr_mtx);
48676ca6f88SJamie Gritton 	tmpid = pr->pr_hostid;
4870fe74ae6SJamie Gritton 	mtx_unlock(&pr->pr_mtx);
48876ca6f88SJamie Gritton 
4890fe74ae6SJamie Gritton 	error = sysctl_handle_long(oidp, &tmpid, 0, req);
4900fe74ae6SJamie Gritton 	if (error != 0 || req->newptr == NULL)
4910fe74ae6SJamie Gritton 		return (error);
4920fe74ae6SJamie Gritton 
49376ca6f88SJamie Gritton 	sx_slock(&allprison_lock);
4940fe74ae6SJamie Gritton 	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME))
4950fe74ae6SJamie Gritton 		error = EPERM;
4960fe74ae6SJamie Gritton 	else {
49776ca6f88SJamie Gritton 		while (!(pr->pr_flags & PR_HOST))
49876ca6f88SJamie Gritton 			pr = pr->pr_parent;
49976ca6f88SJamie Gritton 		mtx_lock(&pr->pr_mtx);
50076ca6f88SJamie Gritton 		pr->pr_hostid = tmpid;
50176ca6f88SJamie Gritton 		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
50276ca6f88SJamie Gritton 			if (cpr->pr_flags & PR_HOST)
50376ca6f88SJamie Gritton 				descend = 0;
50476ca6f88SJamie Gritton 			else
50576ca6f88SJamie Gritton 				cpr->pr_hostid = tmpid;
50676ca6f88SJamie Gritton 		mtx_unlock(&pr->pr_mtx);
5074f7d1876SRobert Watson 	}
5080fe74ae6SJamie Gritton 	sx_sunlock(&allprison_lock);
5094f7d1876SRobert Watson 	return (error);
5104f7d1876SRobert Watson }
5114f7d1876SRobert Watson 
51276ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTID, hostid,
513200241b5SBryan Drewery     CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE | CTLFLAG_CAPRD,
51476ca6f88SJamie Gritton     NULL, 0, sysctl_hostid, "LU", "Host ID");
51545ec3b38SPoul-Henning Kamp 
51634086d5bSConrad Meyer static struct mtx bootid_lk;
51734086d5bSConrad Meyer MTX_SYSINIT(bootid_lock, &bootid_lk, "bootid generator lock", MTX_DEF);
51834086d5bSConrad Meyer 
51934086d5bSConrad Meyer static int
52034086d5bSConrad Meyer sysctl_bootid(SYSCTL_HANDLER_ARGS)
52134086d5bSConrad Meyer {
52234086d5bSConrad Meyer 	static uint8_t boot_id[16];
52334086d5bSConrad Meyer 	static bool initialized = false;
52434086d5bSConrad Meyer 
52534086d5bSConrad Meyer 	mtx_lock(&bootid_lk);
52634086d5bSConrad Meyer 	if (!initialized) {
52734086d5bSConrad Meyer 		if (!is_random_seeded()) {
52834086d5bSConrad Meyer 			mtx_unlock(&bootid_lk);
52934086d5bSConrad Meyer 			return (ENXIO);
53034086d5bSConrad Meyer 		}
53134086d5bSConrad Meyer 		arc4random_buf(boot_id, sizeof(boot_id));
53234086d5bSConrad Meyer 		initialized = true;
53334086d5bSConrad Meyer 	}
53434086d5bSConrad Meyer 	mtx_unlock(&bootid_lk);
53534086d5bSConrad Meyer 
53634086d5bSConrad Meyer 	return (SYSCTL_OUT(req, boot_id, sizeof(boot_id)));
53734086d5bSConrad Meyer }
53834086d5bSConrad Meyer SYSCTL_PROC(_kern, OID_AUTO, boot_id,
53934086d5bSConrad Meyer     CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD,
54034086d5bSConrad Meyer     NULL, 0, sysctl_bootid, "", "Random boot ID");
54134086d5bSConrad Meyer 
542b96bd95bSIan Lepore /*
543b96bd95bSIan Lepore  * The osrelease string is copied from the global (osrelease in vers.c) into
544b96bd95bSIan Lepore  * prison0 by a sysinit and is inherited by child jails if not changed at jail
545b96bd95bSIan Lepore  * creation, so we always return the copy from the current prison data.
546b96bd95bSIan Lepore  */
547b96bd95bSIan Lepore static int
548b96bd95bSIan Lepore sysctl_osrelease(SYSCTL_HANDLER_ARGS)
549b96bd95bSIan Lepore {
550b96bd95bSIan Lepore 	struct prison *pr;
551b96bd95bSIan Lepore 
552b96bd95bSIan Lepore 	pr = req->td->td_ucred->cr_prison;
553b96bd95bSIan Lepore 	return (SYSCTL_OUT(req, pr->pr_osrelease, strlen(pr->pr_osrelease) + 1));
554b96bd95bSIan Lepore 
555b96bd95bSIan Lepore }
556b96bd95bSIan Lepore 
557b96bd95bSIan Lepore SYSCTL_PROC(_kern, KERN_OSRELEASE, osrelease,
558b96bd95bSIan Lepore     CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
559b96bd95bSIan Lepore     NULL, 0, sysctl_osrelease, "A", "Operating system release");
560b96bd95bSIan Lepore 
561b96bd95bSIan Lepore /*
562b96bd95bSIan Lepore  * The osreldate number is copied from the global (osreldate in vers.c) into
563b96bd95bSIan Lepore  * prison0 by a sysinit and is inherited by child jails if not changed at jail
564b96bd95bSIan Lepore  * creation, so we always return the value from the current prison data.
565b96bd95bSIan Lepore  */
566b96bd95bSIan Lepore static int
567b96bd95bSIan Lepore sysctl_osreldate(SYSCTL_HANDLER_ARGS)
568b96bd95bSIan Lepore {
569b96bd95bSIan Lepore 	struct prison *pr;
570b96bd95bSIan Lepore 
571b96bd95bSIan Lepore 	pr = req->td->td_ucred->cr_prison;
572b96bd95bSIan Lepore 	return (SYSCTL_OUT(req, &pr->pr_osreldate, sizeof(pr->pr_osreldate)));
573b96bd95bSIan Lepore 
574b96bd95bSIan Lepore }
575b96bd95bSIan Lepore 
576b96bd95bSIan Lepore /*
577b96bd95bSIan Lepore  * NOTICE: The *userland* release date is available in
578b96bd95bSIan Lepore  * /usr/include/osreldate.h
579b96bd95bSIan Lepore  */
580b96bd95bSIan Lepore SYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate,
581b96bd95bSIan Lepore     CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
582b96bd95bSIan Lepore     NULL, 0, sysctl_osreldate, "I", "Kernel release date");
583b96bd95bSIan Lepore 
58474cd06b4SEd Maste /*
58574cd06b4SEd Maste  * The build-id is copied from the ELF section .note.gnu.build-id.  The linker
58674cd06b4SEd Maste  * script defines two variables to expose the beginning and end.  LLVM
58774cd06b4SEd Maste  * currently uses a SHA-1 hash, but other formats can be supported by checking
58874cd06b4SEd Maste  * the length of the section.
58974cd06b4SEd Maste  */
59074cd06b4SEd Maste 
59174cd06b4SEd Maste extern char __build_id_start[];
59274cd06b4SEd Maste extern char __build_id_end[];
59374cd06b4SEd Maste 
59474cd06b4SEd Maste #define	BUILD_ID_HEADER_LEN	0x10
59574cd06b4SEd Maste #define	BUILD_ID_HASH_MAXLEN	0x14
59674cd06b4SEd Maste 
59774cd06b4SEd Maste static int
59874cd06b4SEd Maste sysctl_build_id(SYSCTL_HANDLER_ARGS)
59974cd06b4SEd Maste {
60074cd06b4SEd Maste 	uintptr_t sectionlen = (uintptr_t)(__build_id_end - __build_id_start);
60174cd06b4SEd Maste 	int hashlen;
60274cd06b4SEd Maste 	char buf[2*BUILD_ID_HASH_MAXLEN+1];
60374cd06b4SEd Maste 
60474cd06b4SEd Maste 	/*
60574cd06b4SEd Maste 	 * The ELF note section has a four byte length for the vendor name,
60674cd06b4SEd Maste 	 * four byte length for the value, and a four byte vendor specific
60774cd06b4SEd Maste 	 * type.  The name for the build id is "GNU\0".  We skip the first 16
60874cd06b4SEd Maste 	 * bytes to read the build hash.  We will return the remaining bytes up
60974cd06b4SEd Maste 	 * to 20 (SHA-1) hash size.  If the hash happens to be a custom number
61074cd06b4SEd Maste 	 * of bytes we will pad the value with zeros, as the section should be
61174cd06b4SEd Maste 	 * four byte aligned.
61274cd06b4SEd Maste 	 */
61374cd06b4SEd Maste 	if (sectionlen <= BUILD_ID_HEADER_LEN ||
61474cd06b4SEd Maste 	    sectionlen > (BUILD_ID_HEADER_LEN + BUILD_ID_HASH_MAXLEN)) {
61574cd06b4SEd Maste 		return (ENOENT);
61674cd06b4SEd Maste 	}
61774cd06b4SEd Maste 
61874cd06b4SEd Maste 	hashlen = sectionlen - BUILD_ID_HEADER_LEN;
61974cd06b4SEd Maste 	for (int i = 0; i < hashlen; i++) {
62074cd06b4SEd Maste 		uint8_t c = __build_id_start[i+BUILD_ID_HEADER_LEN];
62174cd06b4SEd Maste 		snprintf(&buf[2*i], 3, "%02x", c);
62274cd06b4SEd Maste 	}
62374cd06b4SEd Maste 
62474cd06b4SEd Maste 	return (SYSCTL_OUT(req, buf, strlen(buf) + 1));
62574cd06b4SEd Maste }
62674cd06b4SEd Maste 
62774cd06b4SEd Maste SYSCTL_PROC(_kern, OID_AUTO, build_id,
62874cd06b4SEd Maste     CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
62974cd06b4SEd Maste     NULL, 0, sysctl_build_id, "A", "Operating system build-id");
63074cd06b4SEd Maste 
6317029da5cSPawel Biernacki SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
6327029da5cSPawel Biernacki     "Kernel Features");
6330deabe7eSJohn Baldwin 
6342c179010SJohn Baldwin #ifdef COMPAT_FREEBSD4
6352c179010SJohn Baldwin FEATURE(compat_freebsd4, "Compatible with FreeBSD 4");
6362c179010SJohn Baldwin #endif
6372c179010SJohn Baldwin 
6382c179010SJohn Baldwin #ifdef COMPAT_FREEBSD5
6392c179010SJohn Baldwin FEATURE(compat_freebsd5, "Compatible with FreeBSD 5");
6402c179010SJohn Baldwin #endif
6412c179010SJohn Baldwin 
6422c179010SJohn Baldwin #ifdef COMPAT_FREEBSD6
6432c179010SJohn Baldwin FEATURE(compat_freebsd6, "Compatible with FreeBSD 6");
6442c179010SJohn Baldwin #endif
6452c179010SJohn Baldwin 
6462c179010SJohn Baldwin #ifdef COMPAT_FREEBSD7
6472c179010SJohn Baldwin FEATURE(compat_freebsd7, "Compatible with FreeBSD 7");
6482c179010SJohn Baldwin #endif
6492c179010SJohn Baldwin 
650e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD8
651e256f713SKonstantin Belousov FEATURE(compat_freebsd8, "Compatible with FreeBSD 8");
652e256f713SKonstantin Belousov #endif
653e256f713SKonstantin Belousov 
654e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD9
655e256f713SKonstantin Belousov FEATURE(compat_freebsd9, "Compatible with FreeBSD 9");
656e256f713SKonstantin Belousov #endif
657e256f713SKonstantin Belousov 
658e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD10
659e256f713SKonstantin Belousov FEATURE(compat_freebsd10, "Compatible with FreeBSD 10");
660e256f713SKonstantin Belousov #endif
661e256f713SKonstantin Belousov 
662e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD11
663e256f713SKonstantin Belousov FEATURE(compat_freebsd11, "Compatible with FreeBSD 11");
664e256f713SKonstantin Belousov #endif
665e256f713SKonstantin Belousov 
666e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD12
667e256f713SKonstantin Belousov FEATURE(compat_freebsd12, "Compatible with FreeBSD 12");
668e256f713SKonstantin Belousov #endif
669e256f713SKonstantin Belousov 
670e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD13
671e256f713SKonstantin Belousov FEATURE(compat_freebsd13, "Compatible with FreeBSD 13");
672e256f713SKonstantin Belousov #endif
673e256f713SKonstantin Belousov 
674e256f713SKonstantin Belousov #ifdef COMPAT_FREEBSD14
675e256f713SKonstantin Belousov FEATURE(compat_freebsd14, "Compatible with FreeBSD 14");
676e256f713SKonstantin Belousov #endif
677e256f713SKonstantin Belousov 
67845ec3b38SPoul-Henning Kamp /*
67945ec3b38SPoul-Henning Kamp  * This is really cheating.  These actually live in the libc, something
68045ec3b38SPoul-Henning Kamp  * which I'm not quite sure is a good idea anyway, but in order for
68145ec3b38SPoul-Henning Kamp  * getnext and friends to actually work, we define dummies here.
682ff66f6a4SRobert Watson  *
683ff66f6a4SRobert Watson  * XXXRW: These probably should be CTLFLAG_CAPRD.
68445ec3b38SPoul-Henning Kamp  */
6853d177f46SBill Fumerola SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
6863d177f46SBill Fumerola     "", 0, "PATH that finds all the standard utilities");
6873d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
688f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Max ibase/obase values in bc(1)");
6893d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
690f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Max array size in bc(1)");
6913d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
692f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Max scale value in bc(1)");
6933d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
694f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Max string length in bc(1)");
6953d177f46SBill Fumerola SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
696f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
697f0188618SHans Petter Selasky SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD,
698f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "");
6993d177f46SBill Fumerola SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
700f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Max length (bytes) of a text-processing utility's input line");
7013d177f46SBill Fumerola SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
702f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Maximum number of repeats of a regexp permitted");
7033d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
704f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0,
7053d177f46SBill Fumerola     "The version of POSIX 1003.2 with which the system attempts to comply");
7063d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
707f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether C development supports the C bindings option");
7083d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
709f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports the C development utilities option");
7103d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
711f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "");
7123d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
713f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN development utilities");
7143d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
715f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN runtime utilities");
7163d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
717f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports creation of locales");
7183d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
719f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports software development utilities");
7203d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
721f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Whether system supports the user portability utilities");
7223d177f46SBill Fumerola SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
723f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time");
7243d177f46SBill Fumerola SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
725f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names");
7261ebef477SStefan Eßer 
7271ebef477SStefan Eßer static char localbase[MAXPATHLEN] = "";
7281ebef477SStefan Eßer 
7291ebef477SStefan Eßer SYSCTL_STRING(_user, USER_LOCALBASE, localbase, CTLFLAG_RWTUN,
7301ebef477SStefan Eßer     localbase, sizeof(localbase), "Prefix used to install and locate add-on packages");
7316f13bfc2SPoul-Henning Kamp 
7326f13bfc2SPoul-Henning Kamp #include <sys/vnode.h>
7336f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
734f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, sizeof(struct vnode), "sizeof(struct vnode)");
7356f13bfc2SPoul-Henning Kamp 
7366f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
737f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, sizeof(struct proc), "sizeof(struct proc)");
738d7bf417dSPoul-Henning Kamp 
73902c6fc21SKonstantin Belousov static int
74002c6fc21SKonstantin Belousov sysctl_kern_pid_max(SYSCTL_HANDLER_ARGS)
74102c6fc21SKonstantin Belousov {
74202c6fc21SKonstantin Belousov 	int error, pm;
74302c6fc21SKonstantin Belousov 
74402c6fc21SKonstantin Belousov 	pm = pid_max;
74502c6fc21SKonstantin Belousov 	error = sysctl_handle_int(oidp, &pm, 0, req);
74602c6fc21SKonstantin Belousov 	if (error || !req->newptr)
74702c6fc21SKonstantin Belousov 		return (error);
74802c6fc21SKonstantin Belousov 	sx_xlock(&proctree_lock);
74902c6fc21SKonstantin Belousov 	sx_xlock(&allproc_lock);
7503fa615bcSKonstantin Belousov 
7513fa615bcSKonstantin Belousov 	/*
7523fa615bcSKonstantin Belousov 	 * Only permit the values less then PID_MAX.
7533fa615bcSKonstantin Belousov 	 * As a safety measure, do not allow to limit the pid_max too much.
7543fa615bcSKonstantin Belousov 	 */
7553fa615bcSKonstantin Belousov 	if (pm < 300 || pm > PID_MAX)
75602c6fc21SKonstantin Belousov 		error = EINVAL;
75702c6fc21SKonstantin Belousov 	else
75802c6fc21SKonstantin Belousov 		pid_max = pm;
75902c6fc21SKonstantin Belousov 	sx_xunlock(&allproc_lock);
76002c6fc21SKonstantin Belousov 	sx_xunlock(&proctree_lock);
76102c6fc21SKonstantin Belousov 	return (error);
76202c6fc21SKonstantin Belousov }
763af3b2549SHans Petter Selasky SYSCTL_PROC(_kern, OID_AUTO, pid_max, CTLTYPE_INT |
764af3b2549SHans Petter Selasky     CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE,
765af3b2549SHans Petter Selasky     0, 0, sysctl_kern_pid_max, "I", "Maximum allowed pid");
76602c6fc21SKonstantin Belousov 
7671b8d70b2SPawel Jakub Dawidek SYSCTL_INT(_kern, OID_AUTO, pid_max_limit, CTLFLAG_RD,
7681b8d70b2SPawel Jakub Dawidek     SYSCTL_NULL_INT_PTR, PID_MAX,
7691b8d70b2SPawel Jakub Dawidek     "Maximum allowed pid (kern.pid_max) top limit");
7701b8d70b2SPawel Jakub Dawidek 
7719626b608SPoul-Henning Kamp #include <sys/bio.h>
7728c125869SPoul-Henning Kamp #include <sys/buf.h>
7738c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
774f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, sizeof(struct bio), "sizeof(struct bio)");
7758c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
776f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, sizeof(struct buf), "sizeof(struct buf)");
777d5a08a60SJake Burkholder 
778d5a08a60SJake Burkholder #include <sys/user.h>
779d5a08a60SJake Burkholder SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
780f0188618SHans Petter Selasky     SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
781a360a43dSJake Burkholder 
782645743eaSJohn Baldwin /* Used by kernel debuggers. */
783645743eaSJohn Baldwin const int pcb_size = sizeof(struct pcb);
784645743eaSJohn Baldwin SYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD,
785645743eaSJohn Baldwin     SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)");
786645743eaSJohn Baldwin 
787e548a1d4SJake Burkholder /* XXX compatibility, remove for 6.0 */
788e548a1d4SJake Burkholder #include <sys/imgact.h>
789e548a1d4SJake Burkholder #include <sys/imgact_elf.h>
790e548a1d4SJake Burkholder SYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW,
791e548a1d4SJake Burkholder     &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)),
792e548a1d4SJake Burkholder     "compatibility for kern.fallback_elf_brand");
793