init_sysctl.c revision 1.185 1 1.185 tls /* $NetBSD: init_sysctl.c,v 1.185 2011/11/20 01:09:14 tls Exp $ */
2 1.1 atatat
3 1.1 atatat /*-
4 1.164 ad * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 1.1 atatat * All rights reserved.
6 1.1 atatat *
7 1.1 atatat * This code is derived from software contributed to The NetBSD Foundation
8 1.118 ad * by Andrew Brown, and by Andrew Doran.
9 1.1 atatat *
10 1.1 atatat * Redistribution and use in source and binary forms, with or without
11 1.1 atatat * modification, are permitted provided that the following conditions
12 1.1 atatat * are met:
13 1.1 atatat * 1. Redistributions of source code must retain the above copyright
14 1.1 atatat * notice, this list of conditions and the following disclaimer.
15 1.1 atatat * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 atatat * notice, this list of conditions and the following disclaimer in the
17 1.1 atatat * documentation and/or other materials provided with the distribution.
18 1.1 atatat *
19 1.1 atatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 atatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 atatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 atatat * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 atatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 atatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 atatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 atatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 atatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 atatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 atatat * POSSIBILITY OF SUCH DAMAGE.
30 1.1 atatat */
31 1.1 atatat
32 1.16 atatat #include <sys/cdefs.h>
33 1.185 tls __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.185 2011/11/20 01:09:14 tls Exp $");
34 1.16 atatat
35 1.1 atatat #include "opt_sysv.h"
36 1.153 christos #include "opt_compat_netbsd.h"
37 1.156 apb #include "opt_modular.h"
38 1.145 wrstuden #include "opt_sa.h"
39 1.150 ad #include "opt_posix.h"
40 1.1 atatat #include "pty.h"
41 1.1 atatat
42 1.1 atatat #include <sys/types.h>
43 1.1 atatat #include <sys/param.h>
44 1.1 atatat #include <sys/sysctl.h>
45 1.104 yamt #include <sys/cpu.h>
46 1.1 atatat #include <sys/errno.h>
47 1.1 atatat #include <sys/systm.h>
48 1.1 atatat #include <sys/kernel.h>
49 1.1 atatat #include <sys/unistd.h>
50 1.1 atatat #include <sys/disklabel.h>
51 1.184 tls #include <sys/cprng.h>
52 1.1 atatat #include <sys/vnode.h>
53 1.1 atatat #include <sys/mount.h>
54 1.1 atatat #include <sys/namei.h>
55 1.1 atatat #include <sys/msgbuf.h>
56 1.1 atatat #include <dev/cons.h>
57 1.1 atatat #include <sys/socketvar.h>
58 1.1 atatat #include <sys/file.h>
59 1.34 atatat #include <sys/filedesc.h>
60 1.1 atatat #include <sys/tty.h>
61 1.154 yamt #include <sys/kmem.h>
62 1.1 atatat #include <sys/resource.h>
63 1.1 atatat #include <sys/resourcevar.h>
64 1.1 atatat #include <sys/exec.h>
65 1.1 atatat #include <sys/conf.h>
66 1.1 atatat #include <sys/device.h>
67 1.61 elad #include <sys/stat.h>
68 1.68 elad #include <sys/kauth.h>
69 1.86 manu #include <sys/ktrace.h>
70 1.149 ad #include <sys/ksem.h>
71 1.1 atatat
72 1.153 christos #ifdef COMPAT_50
73 1.153 christos #include <compat/sys/time.h>
74 1.153 christos #endif
75 1.82 manu
76 1.145 wrstuden #ifdef KERN_SA
77 1.145 wrstuden #include <sys/sa.h>
78 1.145 wrstuden #endif
79 1.145 wrstuden
80 1.112 ad #include <sys/cpu.h>
81 1.1 atatat
82 1.150 ad #if defined(MODULAR) || defined(P1003_1B_SEMAPHORE)
83 1.150 ad int posix_semaphores = 200112;
84 1.150 ad #else
85 1.148 ad int posix_semaphores;
86 1.150 ad #endif
87 1.150 ad
88 1.61 elad int security_setidcore_dump;
89 1.61 elad char security_setidcore_path[MAXPATHLEN] = "/var/crash/%n.core";
90 1.61 elad uid_t security_setidcore_owner = 0;
91 1.61 elad gid_t security_setidcore_group = 0;
92 1.61 elad mode_t security_setidcore_mode = (S_IRUSR|S_IWUSR);
93 1.54 elad
94 1.95 ad static const u_int sysctl_flagmap[] = {
95 1.97 pavel PK_ADVLOCK, P_ADVLOCK,
96 1.97 pavel PK_EXEC, P_EXEC,
97 1.97 pavel PK_NOCLDWAIT, P_NOCLDWAIT,
98 1.97 pavel PK_32, P_32,
99 1.97 pavel PK_CLDSIGIGN, P_CLDSIGIGN,
100 1.97 pavel PK_SUGID, P_SUGID,
101 1.95 ad 0
102 1.95 ad };
103 1.95 ad
104 1.95 ad static const u_int sysctl_sflagmap[] = {
105 1.97 pavel PS_NOCLDSTOP, P_NOCLDSTOP,
106 1.97 pavel PS_WEXIT, P_WEXIT,
107 1.97 pavel PS_STOPFORK, P_STOPFORK,
108 1.97 pavel PS_STOPEXEC, P_STOPEXEC,
109 1.97 pavel PS_STOPEXIT, P_STOPEXIT,
110 1.95 ad 0
111 1.95 ad };
112 1.95 ad
113 1.95 ad static const u_int sysctl_slflagmap[] = {
114 1.97 pavel PSL_TRACED, P_TRACED,
115 1.97 pavel PSL_FSTRACE, P_FSTRACE,
116 1.97 pavel PSL_CHTRACED, P_CHTRACED,
117 1.97 pavel PSL_SYSCALL, P_SYSCALL,
118 1.95 ad 0
119 1.95 ad };
120 1.95 ad
121 1.95 ad static const u_int sysctl_lflagmap[] = {
122 1.97 pavel PL_CONTROLT, P_CONTROLT,
123 1.141 ad PL_PPWAIT, P_PPWAIT,
124 1.95 ad 0
125 1.95 ad };
126 1.95 ad
127 1.95 ad static const u_int sysctl_stflagmap[] = {
128 1.97 pavel PST_PROFIL, P_PROFIL,
129 1.95 ad 0
130 1.95 ad
131 1.95 ad };
132 1.95 ad
133 1.95 ad static const u_int sysctl_lwpprflagmap[] = {
134 1.97 pavel LPR_DETACHED, L_DETACHED,
135 1.95 ad 0
136 1.95 ad };
137 1.95 ad
138 1.1 atatat /*
139 1.1 atatat * try over estimating by 5 procs/lwps
140 1.1 atatat */
141 1.1 atatat #define KERN_LWPSLOP (5 * sizeof(struct kinfo_lwp))
142 1.1 atatat
143 1.105 ad static int dcopyout(struct lwp *, const void *, void *, size_t);
144 1.86 manu
145 1.105 ad static int
146 1.123 matt dcopyout(struct lwp *l, const void *kaddr, void *uaddr, size_t len)
147 1.86 manu {
148 1.86 manu int error;
149 1.86 manu
150 1.86 manu error = copyout(kaddr, uaddr, len);
151 1.105 ad ktrmibio(-1, UIO_READ, uaddr, len, error);
152 1.86 manu
153 1.86 manu return error;
154 1.86 manu }
155 1.96 ad
156 1.64 erh #ifdef DIAGNOSTIC
157 1.64 erh static int sysctl_kern_trigger_panic(SYSCTLFN_PROTO);
158 1.64 erh #endif
159 1.1 atatat static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
160 1.14 martin static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
161 1.1 atatat static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
162 1.1 atatat static int sysctl_kern_hostid(SYSCTLFN_PROTO);
163 1.17 atatat static int sysctl_setlen(SYSCTLFN_PROTO);
164 1.1 atatat static int sysctl_kern_clockrate(SYSCTLFN_PROTO);
165 1.1 atatat static int sysctl_msgbuf(SYSCTLFN_PROTO);
166 1.1 atatat static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
167 1.1 atatat static int sysctl_kern_cptime(SYSCTLFN_PROTO);
168 1.6 he #if NPTY > 0
169 1.1 atatat static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
170 1.6 he #endif /* NPTY > 0 */
171 1.1 atatat static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
172 1.1 atatat static int sysctl_kern_urnd(SYSCTLFN_PROTO);
173 1.91 christos static int sysctl_kern_arnd(SYSCTLFN_PROTO);
174 1.1 atatat static int sysctl_kern_lwp(SYSCTLFN_PROTO);
175 1.1 atatat static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
176 1.1 atatat static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
177 1.1 atatat static int sysctl_kern_drivers(SYSCTLFN_PROTO);
178 1.61 elad static int sysctl_security_setidcore(SYSCTLFN_PROTO);
179 1.61 elad static int sysctl_security_setidcorename(SYSCTLFN_PROTO);
180 1.45 christos static int sysctl_kern_cpid(SYSCTLFN_PROTO);
181 1.1 atatat static int sysctl_hw_usermem(SYSCTLFN_PROTO);
182 1.1 atatat static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
183 1.1 atatat
184 1.1 atatat static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
185 1.1 atatat
186 1.1 atatat /*
187 1.1 atatat * ********************************************************************
188 1.1 atatat * section 1: setup routines
189 1.1 atatat * ********************************************************************
190 1.110 christos * These functions are stuffed into a link set for sysctl setup
191 1.110 christos * functions. They're never called or referenced from anywhere else.
192 1.1 atatat * ********************************************************************
193 1.1 atatat */
194 1.1 atatat
195 1.1 atatat /*
196 1.1 atatat * this setup routine is a replacement for kern_sysctl()
197 1.1 atatat */
198 1.1 atatat SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
199 1.1 atatat {
200 1.1 atatat extern int kern_logsigexit; /* defined in kern/kern_sig.c */
201 1.1 atatat extern fixpt_t ccpu; /* defined in kern/kern_synch.c */
202 1.1 atatat extern int dumponpanic; /* defined in kern/subr_prf.c */
203 1.75 elad const struct sysctlnode *rnode;
204 1.1 atatat
205 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
206 1.24 atatat CTLFLAG_PERMANENT,
207 1.1 atatat CTLTYPE_NODE, "kern", NULL,
208 1.1 atatat NULL, 0, NULL, 0,
209 1.1 atatat CTL_KERN, CTL_EOL);
210 1.1 atatat
211 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
212 1.24 atatat CTLFLAG_PERMANENT,
213 1.26 atatat CTLTYPE_STRING, "ostype",
214 1.26 atatat SYSCTL_DESCR("Operating system type"),
215 1.181 joerg NULL, 0, __UNCONST(&ostype), 0,
216 1.1 atatat CTL_KERN, KERN_OSTYPE, CTL_EOL);
217 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
218 1.24 atatat CTLFLAG_PERMANENT,
219 1.26 atatat CTLTYPE_STRING, "osrelease",
220 1.26 atatat SYSCTL_DESCR("Operating system release"),
221 1.181 joerg NULL, 0, __UNCONST(&osrelease), 0,
222 1.1 atatat CTL_KERN, KERN_OSRELEASE, CTL_EOL);
223 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
224 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
225 1.26 atatat CTLTYPE_INT, "osrevision",
226 1.26 atatat SYSCTL_DESCR("Operating system revision"),
227 1.1 atatat NULL, __NetBSD_Version__, NULL, 0,
228 1.1 atatat CTL_KERN, KERN_OSREV, CTL_EOL);
229 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
230 1.24 atatat CTLFLAG_PERMANENT,
231 1.26 atatat CTLTYPE_STRING, "version",
232 1.26 atatat SYSCTL_DESCR("Kernel version"),
233 1.181 joerg NULL, 0, __UNCONST(&version), 0,
234 1.1 atatat CTL_KERN, KERN_VERSION, CTL_EOL);
235 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
236 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
237 1.26 atatat CTLTYPE_INT, "maxvnodes",
238 1.26 atatat SYSCTL_DESCR("Maximum number of vnodes"),
239 1.1 atatat sysctl_kern_maxvnodes, 0, NULL, 0,
240 1.1 atatat CTL_KERN, KERN_MAXVNODES, CTL_EOL);
241 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
242 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
243 1.26 atatat CTLTYPE_INT, "maxproc",
244 1.26 atatat SYSCTL_DESCR("Maximum number of simultaneous processes"),
245 1.1 atatat sysctl_kern_maxproc, 0, NULL, 0,
246 1.1 atatat CTL_KERN, KERN_MAXPROC, CTL_EOL);
247 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
248 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
249 1.26 atatat CTLTYPE_INT, "maxfiles",
250 1.26 atatat SYSCTL_DESCR("Maximum number of open files"),
251 1.1 atatat NULL, 0, &maxfiles, 0,
252 1.1 atatat CTL_KERN, KERN_MAXFILES, CTL_EOL);
253 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
254 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
255 1.26 atatat CTLTYPE_INT, "argmax",
256 1.26 atatat SYSCTL_DESCR("Maximum number of bytes of arguments to "
257 1.26 atatat "execve(2)"),
258 1.1 atatat NULL, ARG_MAX, NULL, 0,
259 1.1 atatat CTL_KERN, KERN_ARGMAX, CTL_EOL);
260 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
261 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
262 1.26 atatat CTLTYPE_STRING, "hostname",
263 1.26 atatat SYSCTL_DESCR("System hostname"),
264 1.17 atatat sysctl_setlen, 0, &hostname, MAXHOSTNAMELEN,
265 1.1 atatat CTL_KERN, KERN_HOSTNAME, CTL_EOL);
266 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
267 1.27 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
268 1.26 atatat CTLTYPE_INT, "hostid",
269 1.26 atatat SYSCTL_DESCR("System host ID number"),
270 1.1 atatat sysctl_kern_hostid, 0, NULL, 0,
271 1.1 atatat CTL_KERN, KERN_HOSTID, CTL_EOL);
272 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
273 1.24 atatat CTLFLAG_PERMANENT,
274 1.26 atatat CTLTYPE_STRUCT, "clockrate",
275 1.26 atatat SYSCTL_DESCR("Kernel clock rates"),
276 1.1 atatat sysctl_kern_clockrate, 0, NULL,
277 1.1 atatat sizeof(struct clockinfo),
278 1.1 atatat CTL_KERN, KERN_CLOCKRATE, CTL_EOL);
279 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
280 1.24 atatat CTLFLAG_PERMANENT,
281 1.53 rpaulo CTLTYPE_INT, "hardclock_ticks",
282 1.53 rpaulo SYSCTL_DESCR("Number of hardclock ticks"),
283 1.53 rpaulo NULL, 0, &hardclock_ticks, sizeof(hardclock_ticks),
284 1.53 rpaulo CTL_KERN, KERN_HARDCLOCK_TICKS, CTL_EOL);
285 1.53 rpaulo sysctl_createv(clog, 0, NULL, NULL,
286 1.53 rpaulo CTLFLAG_PERMANENT,
287 1.26 atatat CTLTYPE_STRUCT, "vnode",
288 1.26 atatat SYSCTL_DESCR("System vnode table"),
289 1.1 atatat sysctl_kern_vnode, 0, NULL, 0,
290 1.1 atatat CTL_KERN, KERN_VNODE, CTL_EOL);
291 1.1 atatat #ifndef GPROF
292 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
293 1.24 atatat CTLFLAG_PERMANENT,
294 1.26 atatat CTLTYPE_NODE, "profiling",
295 1.26 atatat SYSCTL_DESCR("Profiling information (not available)"),
296 1.1 atatat sysctl_notavail, 0, NULL, 0,
297 1.1 atatat CTL_KERN, KERN_PROF, CTL_EOL);
298 1.1 atatat #endif
299 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
300 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
301 1.26 atatat CTLTYPE_INT, "posix1version",
302 1.26 atatat SYSCTL_DESCR("Version of ISO/IEC 9945 (POSIX 1003.1) "
303 1.26 atatat "with which the operating system attempts "
304 1.26 atatat "to comply"),
305 1.1 atatat NULL, _POSIX_VERSION, NULL, 0,
306 1.1 atatat CTL_KERN, KERN_POSIX1, CTL_EOL);
307 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
308 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
309 1.26 atatat CTLTYPE_INT, "ngroups",
310 1.26 atatat SYSCTL_DESCR("Maximum number of supplemental groups"),
311 1.1 atatat NULL, NGROUPS_MAX, NULL, 0,
312 1.1 atatat CTL_KERN, KERN_NGROUPS, CTL_EOL);
313 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
314 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
315 1.26 atatat CTLTYPE_INT, "job_control",
316 1.26 atatat SYSCTL_DESCR("Whether job control is available"),
317 1.1 atatat NULL, 1, NULL, 0,
318 1.1 atatat CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
319 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
320 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
321 1.26 atatat CTLTYPE_INT, "saved_ids",
322 1.37 mrg SYSCTL_DESCR("Whether POSIX saved set-group/user ID is "
323 1.26 atatat "available"), NULL,
324 1.1 atatat #ifdef _POSIX_SAVED_IDS
325 1.1 atatat 1,
326 1.1 atatat #else /* _POSIX_SAVED_IDS */
327 1.1 atatat 0,
328 1.1 atatat #endif /* _POSIX_SAVED_IDS */
329 1.1 atatat NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
330 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
331 1.166 apb CTLFLAG_PERMANENT|CTLFLAG_HEX,
332 1.166 apb CTLTYPE_INT, "boothowto",
333 1.166 apb SYSCTL_DESCR("Flags from boot loader"),
334 1.166 apb NULL, 0, &boothowto, sizeof(boothowto),
335 1.166 apb CTL_KERN, CTL_CREATE, CTL_EOL);
336 1.166 apb sysctl_createv(clog, 0, NULL, NULL,
337 1.24 atatat CTLFLAG_PERMANENT,
338 1.26 atatat CTLTYPE_STRUCT, "boottime",
339 1.26 atatat SYSCTL_DESCR("System boot time"),
340 1.1 atatat NULL, 0, &boottime, sizeof(boottime),
341 1.1 atatat CTL_KERN, KERN_BOOTTIME, CTL_EOL);
342 1.153 christos #ifdef COMPAT_50
343 1.153 christos {
344 1.153 christos extern struct timeval50 boottime50;
345 1.153 christos sysctl_createv(clog, 0, NULL, NULL,
346 1.153 christos CTLFLAG_PERMANENT,
347 1.153 christos CTLTYPE_STRUCT, "oboottime",
348 1.153 christos SYSCTL_DESCR("System boot time"),
349 1.153 christos NULL, 0, &boottime50, sizeof(boottime50),
350 1.153 christos CTL_KERN, KERN_OBOOTTIME, CTL_EOL);
351 1.153 christos }
352 1.153 christos #endif
353 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
354 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
355 1.26 atatat CTLTYPE_STRING, "domainname",
356 1.26 atatat SYSCTL_DESCR("YP domain name"),
357 1.17 atatat sysctl_setlen, 0, &domainname, MAXHOSTNAMELEN,
358 1.1 atatat CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
359 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
360 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
361 1.26 atatat CTLTYPE_INT, "maxpartitions",
362 1.26 atatat SYSCTL_DESCR("Maximum number of partitions allowed per "
363 1.26 atatat "disk"),
364 1.1 atatat NULL, MAXPARTITIONS, NULL, 0,
365 1.1 atatat CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
366 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
367 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
368 1.26 atatat CTLTYPE_INT, "rawpartition",
369 1.26 atatat SYSCTL_DESCR("Raw partition of a disk"),
370 1.1 atatat NULL, RAW_PART, NULL, 0,
371 1.1 atatat CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
372 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
373 1.24 atatat CTLFLAG_PERMANENT,
374 1.1 atatat CTLTYPE_STRUCT, "timex", NULL,
375 1.1 atatat sysctl_notavail, 0, NULL, 0,
376 1.1 atatat CTL_KERN, KERN_TIMEX, CTL_EOL);
377 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
378 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
379 1.26 atatat CTLTYPE_INT, "rtc_offset",
380 1.26 atatat SYSCTL_DESCR("Offset of real time clock from UTC in "
381 1.26 atatat "minutes"),
382 1.14 martin sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
383 1.1 atatat CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
384 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
385 1.24 atatat CTLFLAG_PERMANENT,
386 1.26 atatat CTLTYPE_STRING, "root_device",
387 1.26 atatat SYSCTL_DESCR("Name of the root device"),
388 1.1 atatat sysctl_root_device, 0, NULL, 0,
389 1.1 atatat CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
390 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
391 1.24 atatat CTLFLAG_PERMANENT,
392 1.26 atatat CTLTYPE_INT, "msgbufsize",
393 1.26 atatat SYSCTL_DESCR("Size of the kernel message buffer"),
394 1.31 atatat sysctl_msgbuf, 0, NULL, 0,
395 1.1 atatat CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
396 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
397 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
398 1.26 atatat CTLTYPE_INT, "fsync",
399 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b File "
400 1.26 atatat "Synchronization Option is available on "
401 1.26 atatat "this system"),
402 1.1 atatat NULL, 1, NULL, 0,
403 1.1 atatat CTL_KERN, KERN_FSYNC, CTL_EOL);
404 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
405 1.92 christos CTLFLAG_PERMANENT,
406 1.92 christos CTLTYPE_NODE, "ipc",
407 1.92 christos SYSCTL_DESCR("SysV IPC options"),
408 1.92 christos NULL, 0, NULL, 0,
409 1.92 christos CTL_KERN, KERN_SYSVIPC, CTL_EOL);
410 1.92 christos sysctl_createv(clog, 0, NULL, NULL,
411 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
412 1.26 atatat CTLTYPE_INT, "sysvmsg",
413 1.26 atatat SYSCTL_DESCR("System V style message support available"),
414 1.26 atatat NULL,
415 1.1 atatat #ifdef SYSVMSG
416 1.1 atatat 1,
417 1.1 atatat #else /* SYSVMSG */
418 1.1 atatat 0,
419 1.1 atatat #endif /* SYSVMSG */
420 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, CTL_EOL);
421 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
422 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
423 1.26 atatat CTLTYPE_INT, "sysvsem",
424 1.26 atatat SYSCTL_DESCR("System V style semaphore support "
425 1.26 atatat "available"), NULL,
426 1.1 atatat #ifdef SYSVSEM
427 1.1 atatat 1,
428 1.1 atatat #else /* SYSVSEM */
429 1.1 atatat 0,
430 1.1 atatat #endif /* SYSVSEM */
431 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
432 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
433 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
434 1.26 atatat CTLTYPE_INT, "sysvshm",
435 1.26 atatat SYSCTL_DESCR("System V style shared memory support "
436 1.26 atatat "available"), NULL,
437 1.1 atatat #ifdef SYSVSHM
438 1.1 atatat 1,
439 1.1 atatat #else /* SYSVSHM */
440 1.1 atatat 0,
441 1.1 atatat #endif /* SYSVSHM */
442 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
443 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
444 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
445 1.26 atatat CTLTYPE_INT, "synchronized_io",
446 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Synchronized "
447 1.26 atatat "I/O Option is available on this system"),
448 1.1 atatat NULL, 1, NULL, 0,
449 1.1 atatat CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
450 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
451 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
452 1.26 atatat CTLTYPE_INT, "iov_max",
453 1.26 atatat SYSCTL_DESCR("Maximum number of iovec structures per "
454 1.26 atatat "process"),
455 1.1 atatat NULL, IOV_MAX, NULL, 0,
456 1.1 atatat CTL_KERN, KERN_IOV_MAX, CTL_EOL);
457 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
458 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
459 1.26 atatat CTLTYPE_INT, "mapped_files",
460 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Memory Mapped "
461 1.26 atatat "Files Option is available on this system"),
462 1.1 atatat NULL, 1, NULL, 0,
463 1.1 atatat CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
464 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
465 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
466 1.26 atatat CTLTYPE_INT, "memlock",
467 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Process Memory "
468 1.26 atatat "Locking Option is available on this "
469 1.26 atatat "system"),
470 1.1 atatat NULL, 1, NULL, 0,
471 1.1 atatat CTL_KERN, KERN_MEMLOCK, CTL_EOL);
472 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
473 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
474 1.26 atatat CTLTYPE_INT, "memlock_range",
475 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Range Memory "
476 1.26 atatat "Locking Option is available on this "
477 1.26 atatat "system"),
478 1.1 atatat NULL, 1, NULL, 0,
479 1.1 atatat CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
480 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
481 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
482 1.26 atatat CTLTYPE_INT, "memory_protection",
483 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Memory "
484 1.26 atatat "Protection Option is available on this "
485 1.26 atatat "system"),
486 1.1 atatat NULL, 1, NULL, 0,
487 1.1 atatat CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
488 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
489 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
490 1.26 atatat CTLTYPE_INT, "login_name_max",
491 1.26 atatat SYSCTL_DESCR("Maximum login name length"),
492 1.1 atatat NULL, LOGIN_NAME_MAX, NULL, 0,
493 1.1 atatat CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
494 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
495 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
496 1.26 atatat CTLTYPE_STRING, "defcorename",
497 1.26 atatat SYSCTL_DESCR("Default core file name"),
498 1.1 atatat sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
499 1.1 atatat CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
500 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
501 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
502 1.26 atatat CTLTYPE_INT, "logsigexit",
503 1.26 atatat SYSCTL_DESCR("Log process exit when caused by signals"),
504 1.1 atatat NULL, 0, &kern_logsigexit, 0,
505 1.1 atatat CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
506 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
507 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
508 1.26 atatat CTLTYPE_INT, "fscale",
509 1.26 atatat SYSCTL_DESCR("Kernel fixed-point scale factor"),
510 1.1 atatat NULL, FSCALE, NULL, 0,
511 1.1 atatat CTL_KERN, KERN_FSCALE, CTL_EOL);
512 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
513 1.24 atatat CTLFLAG_PERMANENT,
514 1.26 atatat CTLTYPE_INT, "ccpu",
515 1.26 atatat SYSCTL_DESCR("Scheduler exponential decay value"),
516 1.1 atatat NULL, 0, &ccpu, 0,
517 1.1 atatat CTL_KERN, KERN_CCPU, CTL_EOL);
518 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
519 1.24 atatat CTLFLAG_PERMANENT,
520 1.26 atatat CTLTYPE_STRUCT, "cp_time",
521 1.26 atatat SYSCTL_DESCR("Clock ticks spent in different CPU states"),
522 1.1 atatat sysctl_kern_cptime, 0, NULL, 0,
523 1.1 atatat CTL_KERN, KERN_CP_TIME, CTL_EOL);
524 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
525 1.24 atatat CTLFLAG_PERMANENT,
526 1.26 atatat CTLTYPE_INT, "msgbuf",
527 1.26 atatat SYSCTL_DESCR("Kernel message buffer"),
528 1.1 atatat sysctl_msgbuf, 0, NULL, 0,
529 1.1 atatat CTL_KERN, KERN_MSGBUF, CTL_EOL);
530 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
531 1.24 atatat CTLFLAG_PERMANENT,
532 1.26 atatat CTLTYPE_STRUCT, "consdev",
533 1.26 atatat SYSCTL_DESCR("Console device"),
534 1.1 atatat sysctl_consdev, 0, NULL, sizeof(dev_t),
535 1.1 atatat CTL_KERN, KERN_CONSDEV, CTL_EOL);
536 1.1 atatat #if NPTY > 0
537 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
538 1.24 atatat CTLFLAG_PERMANENT,
539 1.26 atatat CTLTYPE_INT, "maxptys",
540 1.26 atatat SYSCTL_DESCR("Maximum number of pseudo-ttys"),
541 1.1 atatat sysctl_kern_maxptys, 0, NULL, 0,
542 1.1 atatat CTL_KERN, KERN_MAXPTYS, CTL_EOL);
543 1.1 atatat #endif /* NPTY > 0 */
544 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
545 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
546 1.26 atatat CTLTYPE_INT, "maxphys",
547 1.26 atatat SYSCTL_DESCR("Maximum raw I/O transfer size"),
548 1.1 atatat NULL, MAXPHYS, NULL, 0,
549 1.1 atatat CTL_KERN, KERN_MAXPHYS, CTL_EOL);
550 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
551 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
552 1.26 atatat CTLTYPE_INT, "sbmax",
553 1.26 atatat SYSCTL_DESCR("Maximum socket buffer size"),
554 1.1 atatat sysctl_kern_sbmax, 0, NULL, 0,
555 1.1 atatat CTL_KERN, KERN_SBMAX, CTL_EOL);
556 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
557 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
558 1.26 atatat CTLTYPE_INT, "monotonic_clock",
559 1.26 atatat SYSCTL_DESCR("Implementation version of the POSIX "
560 1.26 atatat "1003.1b Monotonic Clock Option"),
561 1.1 atatat /* XXX _POSIX_VERSION */
562 1.1 atatat NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
563 1.1 atatat CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
564 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
565 1.24 atatat CTLFLAG_PERMANENT,
566 1.26 atatat CTLTYPE_INT, "urandom",
567 1.26 atatat SYSCTL_DESCR("Random integer value"),
568 1.1 atatat sysctl_kern_urnd, 0, NULL, 0,
569 1.1 atatat CTL_KERN, KERN_URND, CTL_EOL);
570 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
571 1.91 christos CTLFLAG_PERMANENT,
572 1.91 christos CTLTYPE_INT, "arandom",
573 1.91 christos SYSCTL_DESCR("n bytes of random data"),
574 1.91 christos sysctl_kern_arnd, 0, NULL, 0,
575 1.91 christos CTL_KERN, KERN_ARND, CTL_EOL);
576 1.91 christos sysctl_createv(clog, 0, NULL, NULL,
577 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
578 1.26 atatat CTLTYPE_INT, "labelsector",
579 1.26 atatat SYSCTL_DESCR("Sector number containing the disklabel"),
580 1.1 atatat NULL, LABELSECTOR, NULL, 0,
581 1.1 atatat CTL_KERN, KERN_LABELSECTOR, CTL_EOL);
582 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
583 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
584 1.26 atatat CTLTYPE_INT, "labeloffset",
585 1.26 atatat SYSCTL_DESCR("Offset of the disklabel within the "
586 1.26 atatat "sector"),
587 1.1 atatat NULL, LABELOFFSET, NULL, 0,
588 1.1 atatat CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
589 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
590 1.183 bouyer CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
591 1.183 bouyer CTLTYPE_INT, "labelusesmbr",
592 1.183 bouyer SYSCTL_DESCR("disklabel is inside MBR partition"),
593 1.183 bouyer NULL, LABELUSESMBR, NULL, 0,
594 1.183 bouyer CTL_KERN, CTL_CREATE, CTL_EOL);
595 1.183 bouyer sysctl_createv(clog, 0, NULL, NULL,
596 1.24 atatat CTLFLAG_PERMANENT,
597 1.26 atatat CTLTYPE_NODE, "lwp",
598 1.26 atatat SYSCTL_DESCR("System-wide LWP information"),
599 1.1 atatat sysctl_kern_lwp, 0, NULL, 0,
600 1.1 atatat CTL_KERN, KERN_LWP, CTL_EOL);
601 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
602 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
603 1.26 atatat CTLTYPE_INT, "forkfsleep",
604 1.26 atatat SYSCTL_DESCR("Milliseconds to sleep on fork failure due "
605 1.26 atatat "to process limits"),
606 1.1 atatat sysctl_kern_forkfsleep, 0, NULL, 0,
607 1.1 atatat CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
608 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
609 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
610 1.26 atatat CTLTYPE_INT, "posix_threads",
611 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
612 1.26 atatat "Threads option to which the system "
613 1.26 atatat "attempts to conform"),
614 1.1 atatat /* XXX _POSIX_VERSION */
615 1.1 atatat NULL, _POSIX_THREADS, NULL, 0,
616 1.1 atatat CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
617 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
618 1.148 ad CTLFLAG_PERMANENT,
619 1.26 atatat CTLTYPE_INT, "posix_semaphores",
620 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
621 1.26 atatat "Semaphores option to which the system "
622 1.26 atatat "attempts to conform"), NULL,
623 1.148 ad 0, &posix_semaphores,
624 1.148 ad 0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
625 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
626 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
627 1.26 atatat CTLTYPE_INT, "posix_barriers",
628 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
629 1.26 atatat "Barriers option to which the system "
630 1.26 atatat "attempts to conform"),
631 1.1 atatat /* XXX _POSIX_VERSION */
632 1.1 atatat NULL, _POSIX_BARRIERS, NULL, 0,
633 1.1 atatat CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
634 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
635 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
636 1.26 atatat CTLTYPE_INT, "posix_timers",
637 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
638 1.26 atatat "Timers option to which the system "
639 1.26 atatat "attempts to conform"),
640 1.1 atatat /* XXX _POSIX_VERSION */
641 1.1 atatat NULL, _POSIX_TIMERS, NULL, 0,
642 1.1 atatat CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
643 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
644 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
645 1.26 atatat CTLTYPE_INT, "posix_spin_locks",
646 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
647 1.26 atatat "Locks option to which the system attempts "
648 1.26 atatat "to conform"),
649 1.1 atatat /* XXX _POSIX_VERSION */
650 1.1 atatat NULL, _POSIX_SPIN_LOCKS, NULL, 0,
651 1.1 atatat CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
652 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
653 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
654 1.26 atatat CTLTYPE_INT, "posix_reader_writer_locks",
655 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
656 1.26 atatat "Read-Write Locks option to which the "
657 1.26 atatat "system attempts to conform"),
658 1.1 atatat /* XXX _POSIX_VERSION */
659 1.1 atatat NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
660 1.1 atatat CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
661 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
662 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
663 1.26 atatat CTLTYPE_INT, "dump_on_panic",
664 1.26 atatat SYSCTL_DESCR("Perform a crash dump on system panic"),
665 1.1 atatat NULL, 0, &dumponpanic, 0,
666 1.1 atatat CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
667 1.64 erh #ifdef DIAGNOSTIC
668 1.64 erh sysctl_createv(clog, 0, NULL, NULL,
669 1.64 erh CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
670 1.64 erh CTLTYPE_INT, "panic_now",
671 1.64 erh SYSCTL_DESCR("Trigger a panic"),
672 1.64 erh sysctl_kern_trigger_panic, 0, NULL, 0,
673 1.64 erh CTL_KERN, CTL_CREATE, CTL_EOL);
674 1.64 erh #endif
675 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
676 1.24 atatat CTLFLAG_PERMANENT,
677 1.26 atatat CTLTYPE_INT, "root_partition",
678 1.26 atatat SYSCTL_DESCR("Root partition on the root device"),
679 1.1 atatat sysctl_kern_root_partition, 0, NULL, 0,
680 1.1 atatat CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
681 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
682 1.24 atatat CTLFLAG_PERMANENT,
683 1.26 atatat CTLTYPE_STRUCT, "drivers",
684 1.26 atatat SYSCTL_DESCR("List of all drivers with block and "
685 1.26 atatat "character device numbers"),
686 1.1 atatat sysctl_kern_drivers, 0, NULL, 0,
687 1.1 atatat CTL_KERN, KERN_DRIVERS, CTL_EOL);
688 1.34 atatat sysctl_createv(clog, 0, NULL, NULL,
689 1.34 atatat CTLFLAG_PERMANENT,
690 1.45 christos CTLTYPE_STRUCT, "cp_id",
691 1.45 christos SYSCTL_DESCR("Mapping of CPU number to CPU id"),
692 1.45 christos sysctl_kern_cpid, 0, NULL, 0,
693 1.45 christos CTL_KERN, KERN_CP_ID, CTL_EOL);
694 1.75 elad sysctl_createv(clog, 0, NULL, &rnode,
695 1.75 elad CTLFLAG_PERMANENT,
696 1.75 elad CTLTYPE_NODE, "coredump",
697 1.75 elad SYSCTL_DESCR("Coredump settings."),
698 1.75 elad NULL, 0, NULL, 0,
699 1.75 elad CTL_KERN, CTL_CREATE, CTL_EOL);
700 1.75 elad sysctl_createv(clog, 0, &rnode, &rnode,
701 1.75 elad CTLFLAG_PERMANENT,
702 1.75 elad CTLTYPE_NODE, "setid",
703 1.75 elad SYSCTL_DESCR("Set-id processes' coredump settings."),
704 1.75 elad NULL, 0, NULL, 0,
705 1.75 elad CTL_CREATE, CTL_EOL);
706 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
707 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
708 1.75 elad CTLTYPE_INT, "dump",
709 1.75 elad SYSCTL_DESCR("Allow set-id processes to dump core."),
710 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_dump,
711 1.75 elad sizeof(security_setidcore_dump),
712 1.75 elad CTL_CREATE, CTL_EOL);
713 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
714 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
715 1.75 elad CTLTYPE_STRING, "path",
716 1.75 elad SYSCTL_DESCR("Path pattern for set-id coredumps."),
717 1.75 elad sysctl_security_setidcorename, 0,
718 1.75 elad &security_setidcore_path,
719 1.75 elad sizeof(security_setidcore_path),
720 1.75 elad CTL_CREATE, CTL_EOL);
721 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
722 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
723 1.75 elad CTLTYPE_INT, "owner",
724 1.75 elad SYSCTL_DESCR("Owner id for set-id processes' cores."),
725 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_owner,
726 1.75 elad 0,
727 1.75 elad CTL_CREATE, CTL_EOL);
728 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
729 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
730 1.75 elad CTLTYPE_INT, "group",
731 1.75 elad SYSCTL_DESCR("Group id for set-id processes' cores."),
732 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_group,
733 1.75 elad 0,
734 1.75 elad CTL_CREATE, CTL_EOL);
735 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
736 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
737 1.75 elad CTLTYPE_INT, "mode",
738 1.75 elad SYSCTL_DESCR("Mode for set-id processes' cores."),
739 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_mode,
740 1.75 elad 0,
741 1.75 elad CTL_CREATE, CTL_EOL);
742 1.145 wrstuden sysctl_createv(clog, 0, NULL, NULL,
743 1.182 jym #ifndef KERN_SA
744 1.182 jym CTLFLAG_IMMEDIATE|
745 1.182 jym #endif
746 1.145 wrstuden CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
747 1.145 wrstuden CTLTYPE_INT, "no_sa_support",
748 1.179 christos SYSCTL_DESCR("0 if the kernel supports SA, otherwise "
749 1.179 christos "it doesn't"),
750 1.179 christos NULL,
751 1.182 jym #ifndef KERN_SA
752 1.182 jym 1, NULL,
753 1.182 jym #else
754 1.179 christos 0, &sa_system_disabled,
755 1.179 christos #endif
756 1.179 christos 0,
757 1.106 joerg CTL_KERN, CTL_CREATE, CTL_EOL);
758 1.150 ad /* kern.posix. */
759 1.150 ad sysctl_createv(clog, 0, NULL, &rnode,
760 1.150 ad CTLFLAG_PERMANENT,
761 1.150 ad CTLTYPE_NODE, "posix",
762 1.150 ad SYSCTL_DESCR("POSIX options"),
763 1.150 ad NULL, 0, NULL, 0,
764 1.150 ad CTL_KERN, CTL_CREATE, CTL_EOL);
765 1.150 ad sysctl_createv(clog, 0, &rnode, NULL,
766 1.150 ad CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
767 1.150 ad CTLTYPE_INT, "semmax",
768 1.150 ad SYSCTL_DESCR("Maximal number of semaphores"),
769 1.150 ad NULL, 0, &ksem_max, 0,
770 1.150 ad CTL_CREATE, CTL_EOL);
771 1.1 atatat }
772 1.1 atatat
773 1.1 atatat SYSCTL_SETUP(sysctl_hw_setup, "sysctl hw subtree setup")
774 1.1 atatat {
775 1.1 atatat u_int u;
776 1.1 atatat u_quad_t q;
777 1.1 atatat
778 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
779 1.24 atatat CTLFLAG_PERMANENT,
780 1.1 atatat CTLTYPE_NODE, "hw", NULL,
781 1.1 atatat NULL, 0, NULL, 0,
782 1.1 atatat CTL_HW, CTL_EOL);
783 1.1 atatat
784 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
785 1.24 atatat CTLFLAG_PERMANENT,
786 1.26 atatat CTLTYPE_STRING, "machine",
787 1.26 atatat SYSCTL_DESCR("Machine class"),
788 1.1 atatat NULL, 0, machine, 0,
789 1.1 atatat CTL_HW, HW_MACHINE, CTL_EOL);
790 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
791 1.24 atatat CTLFLAG_PERMANENT,
792 1.26 atatat CTLTYPE_STRING, "model",
793 1.26 atatat SYSCTL_DESCR("Machine model"),
794 1.1 atatat NULL, 0, cpu_model, 0,
795 1.1 atatat CTL_HW, HW_MODEL, CTL_EOL);
796 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
797 1.24 atatat CTLFLAG_PERMANENT,
798 1.26 atatat CTLTYPE_INT, "ncpu",
799 1.109 ad SYSCTL_DESCR("Number of CPUs configured"),
800 1.109 ad NULL, 0, &ncpu, 0,
801 1.1 atatat CTL_HW, HW_NCPU, CTL_EOL);
802 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
803 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
804 1.26 atatat CTLTYPE_INT, "byteorder",
805 1.26 atatat SYSCTL_DESCR("System byte order"),
806 1.1 atatat NULL, BYTE_ORDER, NULL, 0,
807 1.1 atatat CTL_HW, HW_BYTEORDER, CTL_EOL);
808 1.1 atatat u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
809 1.1 atatat UINT_MAX : physmem * PAGE_SIZE;
810 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
811 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
812 1.26 atatat CTLTYPE_INT, "physmem",
813 1.26 atatat SYSCTL_DESCR("Bytes of physical memory"),
814 1.1 atatat NULL, u, NULL, 0,
815 1.1 atatat CTL_HW, HW_PHYSMEM, CTL_EOL);
816 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
817 1.24 atatat CTLFLAG_PERMANENT,
818 1.26 atatat CTLTYPE_INT, "usermem",
819 1.26 atatat SYSCTL_DESCR("Bytes of non-kernel memory"),
820 1.1 atatat sysctl_hw_usermem, 0, NULL, 0,
821 1.1 atatat CTL_HW, HW_USERMEM, CTL_EOL);
822 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
823 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
824 1.26 atatat CTLTYPE_INT, "pagesize",
825 1.26 atatat SYSCTL_DESCR("Software page size"),
826 1.1 atatat NULL, PAGE_SIZE, NULL, 0,
827 1.1 atatat CTL_HW, HW_PAGESIZE, CTL_EOL);
828 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
829 1.24 atatat CTLFLAG_PERMANENT,
830 1.26 atatat CTLTYPE_STRING, "machine_arch",
831 1.26 atatat SYSCTL_DESCR("Machine CPU class"),
832 1.1 atatat NULL, 0, machine_arch, 0,
833 1.1 atatat CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
834 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
835 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
836 1.26 atatat CTLTYPE_INT, "alignbytes",
837 1.26 atatat SYSCTL_DESCR("Alignment constraint for all possible "
838 1.26 atatat "data types"),
839 1.1 atatat NULL, ALIGNBYTES, NULL, 0,
840 1.1 atatat CTL_HW, HW_ALIGNBYTES, CTL_EOL);
841 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
842 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
843 1.26 atatat CTLTYPE_STRING, "cnmagic",
844 1.26 atatat SYSCTL_DESCR("Console magic key sequence"),
845 1.1 atatat sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
846 1.1 atatat CTL_HW, HW_CNMAGIC, CTL_EOL);
847 1.1 atatat q = (u_quad_t)physmem * PAGE_SIZE;
848 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
849 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
850 1.26 atatat CTLTYPE_QUAD, "physmem64",
851 1.26 atatat SYSCTL_DESCR("Bytes of physical memory"),
852 1.1 atatat NULL, q, NULL, 0,
853 1.1 atatat CTL_HW, HW_PHYSMEM64, CTL_EOL);
854 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
855 1.24 atatat CTLFLAG_PERMANENT,
856 1.26 atatat CTLTYPE_QUAD, "usermem64",
857 1.26 atatat SYSCTL_DESCR("Bytes of non-kernel memory"),
858 1.1 atatat sysctl_hw_usermem, 0, NULL, 0,
859 1.1 atatat CTL_HW, HW_USERMEM64, CTL_EOL);
860 1.109 ad sysctl_createv(clog, 0, NULL, NULL,
861 1.109 ad CTLFLAG_PERMANENT,
862 1.109 ad CTLTYPE_INT, "ncpuonline",
863 1.109 ad SYSCTL_DESCR("Number of CPUs online"),
864 1.109 ad NULL, 0, &ncpuonline, 0,
865 1.109 ad CTL_HW, HW_NCPUONLINE, CTL_EOL);
866 1.1 atatat }
867 1.1 atatat
868 1.1 atatat #ifdef DEBUG
869 1.1 atatat /*
870 1.1 atatat * Debugging related system variables.
871 1.1 atatat */
872 1.1 atatat struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
873 1.1 atatat struct ctldebug debug5, debug6, debug7, debug8, debug9;
874 1.1 atatat struct ctldebug debug10, debug11, debug12, debug13, debug14;
875 1.1 atatat struct ctldebug debug15, debug16, debug17, debug18, debug19;
876 1.1 atatat static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
877 1.1 atatat &debug0, &debug1, &debug2, &debug3, &debug4,
878 1.1 atatat &debug5, &debug6, &debug7, &debug8, &debug9,
879 1.1 atatat &debug10, &debug11, &debug12, &debug13, &debug14,
880 1.1 atatat &debug15, &debug16, &debug17, &debug18, &debug19,
881 1.1 atatat };
882 1.1 atatat
883 1.1 atatat /*
884 1.1 atatat * this setup routine is a replacement for debug_sysctl()
885 1.1 atatat *
886 1.1 atatat * note that it creates several nodes per defined debug variable
887 1.1 atatat */
888 1.1 atatat SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
889 1.1 atatat {
890 1.1 atatat struct ctldebug *cdp;
891 1.1 atatat char nodename[20];
892 1.1 atatat int i;
893 1.1 atatat
894 1.1 atatat /*
895 1.1 atatat * two ways here:
896 1.1 atatat *
897 1.1 atatat * the "old" way (debug.name -> value) which was emulated by
898 1.1 atatat * the sysctl(8) binary
899 1.1 atatat *
900 1.1 atatat * the new way, which the sysctl(8) binary was actually using
901 1.1 atatat
902 1.1 atatat node debug
903 1.1 atatat node debug.0
904 1.110 christos string debug.0.name
905 1.1 atatat int debug.0.value
906 1.1 atatat int debug.name
907 1.1 atatat
908 1.1 atatat */
909 1.1 atatat
910 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
911 1.24 atatat CTLFLAG_PERMANENT,
912 1.1 atatat CTLTYPE_NODE, "debug", NULL,
913 1.1 atatat NULL, 0, NULL, 0,
914 1.1 atatat CTL_DEBUG, CTL_EOL);
915 1.1 atatat
916 1.1 atatat for (i = 0; i < CTL_DEBUG_MAXID; i++) {
917 1.1 atatat cdp = debugvars[i];
918 1.1 atatat if (cdp->debugname == NULL || cdp->debugvar == NULL)
919 1.1 atatat continue;
920 1.1 atatat
921 1.1 atatat snprintf(nodename, sizeof(nodename), "debug%d", i);
922 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
923 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
924 1.1 atatat CTLTYPE_NODE, nodename, NULL,
925 1.1 atatat NULL, 0, NULL, 0,
926 1.1 atatat CTL_DEBUG, i, CTL_EOL);
927 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
928 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
929 1.1 atatat CTLTYPE_STRING, "name", NULL,
930 1.40 christos /*XXXUNCONST*/
931 1.40 christos NULL, 0, __UNCONST(cdp->debugname), 0,
932 1.1 atatat CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
933 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
934 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
935 1.1 atatat CTLTYPE_INT, "value", NULL,
936 1.1 atatat NULL, 0, cdp->debugvar, 0,
937 1.1 atatat CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
938 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
939 1.24 atatat CTLFLAG_PERMANENT,
940 1.1 atatat CTLTYPE_INT, cdp->debugname, NULL,
941 1.1 atatat NULL, 0, cdp->debugvar, 0,
942 1.1 atatat CTL_DEBUG, CTL_CREATE, CTL_EOL);
943 1.1 atatat }
944 1.1 atatat }
945 1.1 atatat #endif /* DEBUG */
946 1.1 atatat
947 1.1 atatat /*
948 1.1 atatat * ********************************************************************
949 1.1 atatat * section 2: private node-specific helper routines.
950 1.1 atatat * ********************************************************************
951 1.1 atatat */
952 1.1 atatat
953 1.64 erh #ifdef DIAGNOSTIC
954 1.64 erh static int
955 1.64 erh sysctl_kern_trigger_panic(SYSCTLFN_ARGS)
956 1.64 erh {
957 1.64 erh int newtrig, error;
958 1.64 erh struct sysctlnode node;
959 1.64 erh
960 1.64 erh newtrig = 0;
961 1.64 erh node = *rnode;
962 1.64 erh node.sysctl_data = &newtrig;
963 1.64 erh error = sysctl_lookup(SYSCTLFN_CALL(&node));
964 1.64 erh if (error || newp == NULL)
965 1.64 erh return (error);
966 1.64 erh
967 1.64 erh if (newtrig != 0)
968 1.64 erh panic("Panic triggered");
969 1.64 erh
970 1.64 erh return (error);
971 1.64 erh }
972 1.64 erh #endif
973 1.64 erh
974 1.1 atatat /*
975 1.110 christos * sysctl helper routine for kern.maxvnodes. Drain vnodes if
976 1.13 yamt * new value is lower than desiredvnodes and then calls reinit
977 1.1 atatat * routines that needs to adjust to the new value.
978 1.1 atatat */
979 1.1 atatat static int
980 1.1 atatat sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
981 1.1 atatat {
982 1.142 ad int error, new_vnodes, old_vnodes, new_max;
983 1.1 atatat struct sysctlnode node;
984 1.1 atatat
985 1.1 atatat new_vnodes = desiredvnodes;
986 1.1 atatat node = *rnode;
987 1.1 atatat node.sysctl_data = &new_vnodes;
988 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
989 1.1 atatat if (error || newp == NULL)
990 1.1 atatat return (error);
991 1.1 atatat
992 1.142 ad /* Limits: 75% of KVA and physical memory. */
993 1.142 ad new_max = calc_cache_size(kernel_map, 75, 75) / VNODE_COST;
994 1.142 ad if (new_vnodes > new_max)
995 1.142 ad new_vnodes = new_max;
996 1.142 ad
997 1.12 yamt old_vnodes = desiredvnodes;
998 1.1 atatat desiredvnodes = new_vnodes;
999 1.12 yamt if (new_vnodes < old_vnodes) {
1000 1.180 rmind error = vfs_drainvnodes(new_vnodes);
1001 1.12 yamt if (error) {
1002 1.12 yamt desiredvnodes = old_vnodes;
1003 1.12 yamt return (error);
1004 1.12 yamt }
1005 1.12 yamt }
1006 1.1 atatat vfs_reinit();
1007 1.1 atatat nchreinit();
1008 1.1 atatat
1009 1.1 atatat return (0);
1010 1.1 atatat }
1011 1.1 atatat
1012 1.1 atatat /*
1013 1.14 martin * sysctl helper routine for rtc_offset - set time after changes
1014 1.14 martin */
1015 1.14 martin static int
1016 1.14 martin sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
1017 1.14 martin {
1018 1.57 christos struct timespec ts, delta;
1019 1.57 christos int error, new_rtc_offset;
1020 1.14 martin struct sysctlnode node;
1021 1.14 martin
1022 1.14 martin new_rtc_offset = rtc_offset;
1023 1.14 martin node = *rnode;
1024 1.14 martin node.sysctl_data = &new_rtc_offset;
1025 1.14 martin error = sysctl_lookup(SYSCTLFN_CALL(&node));
1026 1.14 martin if (error || newp == NULL)
1027 1.14 martin return (error);
1028 1.14 martin
1029 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
1030 1.83 elad KAUTH_REQ_SYSTEM_TIME_RTCOFFSET,
1031 1.114 elad KAUTH_ARG(new_rtc_offset), NULL, NULL))
1032 1.14 martin return (EPERM);
1033 1.14 martin if (rtc_offset == new_rtc_offset)
1034 1.14 martin return (0);
1035 1.14 martin
1036 1.14 martin /* if we change the offset, adjust the time */
1037 1.57 christos nanotime(&ts);
1038 1.57 christos delta.tv_sec = 60 * (new_rtc_offset - rtc_offset);
1039 1.57 christos delta.tv_nsec = 0;
1040 1.57 christos timespecadd(&ts, &delta, &ts);
1041 1.14 martin rtc_offset = new_rtc_offset;
1042 1.114 elad return (settime(l->l_proc, &ts));
1043 1.14 martin }
1044 1.14 martin
1045 1.14 martin /*
1046 1.110 christos * sysctl helper routine for kern.maxproc. Ensures that the new
1047 1.1 atatat * values are not too low or too high.
1048 1.1 atatat */
1049 1.1 atatat static int
1050 1.1 atatat sysctl_kern_maxproc(SYSCTLFN_ARGS)
1051 1.1 atatat {
1052 1.1 atatat int error, nmaxproc;
1053 1.1 atatat struct sysctlnode node;
1054 1.1 atatat
1055 1.1 atatat nmaxproc = maxproc;
1056 1.1 atatat node = *rnode;
1057 1.1 atatat node.sysctl_data = &nmaxproc;
1058 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1059 1.1 atatat if (error || newp == NULL)
1060 1.1 atatat return (error);
1061 1.1 atatat
1062 1.1 atatat if (nmaxproc < 0 || nmaxproc >= PID_MAX)
1063 1.1 atatat return (EINVAL);
1064 1.1 atatat #ifdef __HAVE_CPU_MAXPROC
1065 1.1 atatat if (nmaxproc > cpu_maxproc())
1066 1.1 atatat return (EINVAL);
1067 1.1 atatat #endif
1068 1.1 atatat maxproc = nmaxproc;
1069 1.1 atatat
1070 1.1 atatat return (0);
1071 1.1 atatat }
1072 1.1 atatat
1073 1.1 atatat /*
1074 1.110 christos * sysctl helper function for kern.hostid. The hostid is a long, but
1075 1.1 atatat * we export it as an int, so we need to give it a little help.
1076 1.1 atatat */
1077 1.1 atatat static int
1078 1.1 atatat sysctl_kern_hostid(SYSCTLFN_ARGS)
1079 1.1 atatat {
1080 1.1 atatat int error, inthostid;
1081 1.1 atatat struct sysctlnode node;
1082 1.1 atatat
1083 1.29 martin inthostid = hostid; /* XXX assumes sizeof int <= sizeof long */
1084 1.1 atatat node = *rnode;
1085 1.1 atatat node.sysctl_data = &inthostid;
1086 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1087 1.1 atatat if (error || newp == NULL)
1088 1.1 atatat return (error);
1089 1.1 atatat
1090 1.27 atatat hostid = (unsigned)inthostid;
1091 1.1 atatat
1092 1.1 atatat return (0);
1093 1.1 atatat }
1094 1.1 atatat
1095 1.1 atatat /*
1096 1.17 atatat * sysctl helper function for kern.hostname and kern.domainnname.
1097 1.17 atatat * resets the relevant recorded length when the underlying name is
1098 1.17 atatat * changed.
1099 1.15 martin */
1100 1.15 martin static int
1101 1.17 atatat sysctl_setlen(SYSCTLFN_ARGS)
1102 1.15 martin {
1103 1.15 martin int error;
1104 1.15 martin
1105 1.43 atatat error = sysctl_lookup(SYSCTLFN_CALL(rnode));
1106 1.15 martin if (error || newp == NULL)
1107 1.15 martin return (error);
1108 1.15 martin
1109 1.17 atatat switch (rnode->sysctl_num) {
1110 1.17 atatat case KERN_HOSTNAME:
1111 1.17 atatat hostnamelen = strlen((const char*)rnode->sysctl_data);
1112 1.17 atatat break;
1113 1.17 atatat case KERN_DOMAINNAME:
1114 1.17 atatat domainnamelen = strlen((const char*)rnode->sysctl_data);
1115 1.17 atatat break;
1116 1.17 atatat }
1117 1.17 atatat
1118 1.15 martin return (0);
1119 1.15 martin }
1120 1.15 martin
1121 1.15 martin /*
1122 1.110 christos * sysctl helper routine for kern.clockrate. Assembles a struct on
1123 1.1 atatat * the fly to be returned to the caller.
1124 1.1 atatat */
1125 1.1 atatat static int
1126 1.1 atatat sysctl_kern_clockrate(SYSCTLFN_ARGS)
1127 1.1 atatat {
1128 1.1 atatat struct clockinfo clkinfo;
1129 1.1 atatat struct sysctlnode node;
1130 1.1 atatat
1131 1.1 atatat clkinfo.tick = tick;
1132 1.1 atatat clkinfo.tickadj = tickadj;
1133 1.1 atatat clkinfo.hz = hz;
1134 1.1 atatat clkinfo.profhz = profhz;
1135 1.1 atatat clkinfo.stathz = stathz ? stathz : hz;
1136 1.1 atatat
1137 1.1 atatat node = *rnode;
1138 1.1 atatat node.sysctl_data = &clkinfo;
1139 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1140 1.1 atatat }
1141 1.1 atatat
1142 1.171 elad /*
1143 1.110 christos * sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
1144 1.110 christos * former it merely checks the message buffer is set up. For the latter,
1145 1.28 simonb * it also copies out the data if necessary.
1146 1.1 atatat */
1147 1.1 atatat static int
1148 1.1 atatat sysctl_msgbuf(SYSCTLFN_ARGS)
1149 1.1 atatat {
1150 1.1 atatat char *where = oldp;
1151 1.1 atatat size_t len, maxlen;
1152 1.1 atatat long beg, end;
1153 1.118 ad extern kmutex_t log_lock;
1154 1.1 atatat int error;
1155 1.1 atatat
1156 1.1 atatat if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
1157 1.1 atatat msgbufenabled = 0;
1158 1.1 atatat return (ENXIO);
1159 1.1 atatat }
1160 1.1 atatat
1161 1.1 atatat switch (rnode->sysctl_num) {
1162 1.31 atatat case KERN_MSGBUFSIZE: {
1163 1.31 atatat struct sysctlnode node = *rnode;
1164 1.31 atatat int msg_bufs = (int)msgbufp->msg_bufs;
1165 1.31 atatat node.sysctl_data = &msg_bufs;
1166 1.31 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1167 1.31 atatat }
1168 1.1 atatat case KERN_MSGBUF:
1169 1.1 atatat break;
1170 1.1 atatat default:
1171 1.1 atatat return (EOPNOTSUPP);
1172 1.1 atatat }
1173 1.1 atatat
1174 1.1 atatat if (newp != NULL)
1175 1.1 atatat return (EPERM);
1176 1.1 atatat
1177 1.110 christos if (oldp == NULL) {
1178 1.1 atatat /* always return full buffer size */
1179 1.1 atatat *oldlenp = msgbufp->msg_bufs;
1180 1.1 atatat return (0);
1181 1.110 christos }
1182 1.1 atatat
1183 1.118 ad sysctl_unlock();
1184 1.1 atatat
1185 1.1 atatat /*
1186 1.1 atatat * First, copy from the write pointer to the end of
1187 1.1 atatat * message buffer.
1188 1.1 atatat */
1189 1.118 ad error = 0;
1190 1.118 ad mutex_spin_enter(&log_lock);
1191 1.118 ad maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
1192 1.1 atatat beg = msgbufp->msg_bufx;
1193 1.1 atatat end = msgbufp->msg_bufs;
1194 1.118 ad mutex_spin_exit(&log_lock);
1195 1.118 ad
1196 1.1 atatat while (maxlen > 0) {
1197 1.1 atatat len = MIN(end - beg, maxlen);
1198 1.1 atatat if (len == 0)
1199 1.1 atatat break;
1200 1.118 ad /* XXX unlocked, but hardly matters. */
1201 1.86 manu error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
1202 1.1 atatat if (error)
1203 1.1 atatat break;
1204 1.1 atatat where += len;
1205 1.1 atatat maxlen -= len;
1206 1.1 atatat
1207 1.1 atatat /*
1208 1.1 atatat * ... then, copy from the beginning of message buffer to
1209 1.1 atatat * the write pointer.
1210 1.1 atatat */
1211 1.1 atatat beg = 0;
1212 1.1 atatat end = msgbufp->msg_bufx;
1213 1.1 atatat }
1214 1.1 atatat
1215 1.118 ad sysctl_relock();
1216 1.1 atatat return (error);
1217 1.1 atatat }
1218 1.1 atatat
1219 1.1 atatat /*
1220 1.110 christos * sysctl helper routine for kern.defcorename. In the case of a new
1221 1.1 atatat * string being assigned, check that it's not a zero-length string.
1222 1.1 atatat * (XXX the check in -current doesn't work, but do we really care?)
1223 1.1 atatat */
1224 1.1 atatat static int
1225 1.1 atatat sysctl_kern_defcorename(SYSCTLFN_ARGS)
1226 1.1 atatat {
1227 1.1 atatat int error;
1228 1.62 yamt char *newcorename;
1229 1.1 atatat struct sysctlnode node;
1230 1.1 atatat
1231 1.62 yamt newcorename = PNBUF_GET();
1232 1.1 atatat node = *rnode;
1233 1.1 atatat node.sysctl_data = &newcorename[0];
1234 1.1 atatat memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
1235 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1236 1.62 yamt if (error || newp == NULL) {
1237 1.62 yamt goto done;
1238 1.62 yamt }
1239 1.1 atatat
1240 1.1 atatat /*
1241 1.1 atatat * when sysctl_lookup() deals with a string, it's guaranteed
1242 1.110 christos * to come back nul terminated. So there. :)
1243 1.1 atatat */
1244 1.62 yamt if (strlen(newcorename) == 0) {
1245 1.62 yamt error = EINVAL;
1246 1.62 yamt } else {
1247 1.62 yamt memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
1248 1.62 yamt error = 0;
1249 1.62 yamt }
1250 1.62 yamt done:
1251 1.62 yamt PNBUF_PUT(newcorename);
1252 1.62 yamt return error;
1253 1.1 atatat }
1254 1.1 atatat
1255 1.1 atatat /*
1256 1.110 christos * sysctl helper routine for kern.cp_time node. Adds up cpu time
1257 1.1 atatat * across all cpus.
1258 1.1 atatat */
1259 1.1 atatat static int
1260 1.1 atatat sysctl_kern_cptime(SYSCTLFN_ARGS)
1261 1.1 atatat {
1262 1.1 atatat struct sysctlnode node = *rnode;
1263 1.59 perry uint64_t *cp_time = NULL;
1264 1.96 ad int error, n = ncpu, i;
1265 1.1 atatat struct cpu_info *ci;
1266 1.1 atatat CPU_INFO_ITERATOR cii;
1267 1.1 atatat
1268 1.1 atatat /*
1269 1.1 atatat * if you specifically pass a buffer that is the size of the
1270 1.1 atatat * sum, or if you are probing for the size, you get the "sum"
1271 1.1 atatat * of cp_time (and the size thereof) across all processors.
1272 1.1 atatat *
1273 1.1 atatat * alternately, you can pass an additional mib number and get
1274 1.1 atatat * cp_time for that particular processor.
1275 1.1 atatat */
1276 1.1 atatat switch (namelen) {
1277 1.1 atatat case 0:
1278 1.110 christos if (*oldlenp == sizeof(uint64_t) * CPUSTATES || oldp == NULL) {
1279 1.59 perry node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1280 1.1 atatat n = -1; /* SUM */
1281 1.1 atatat }
1282 1.1 atatat else {
1283 1.59 perry node.sysctl_size = n * sizeof(uint64_t) * CPUSTATES;
1284 1.1 atatat n = -2; /* ALL */
1285 1.1 atatat }
1286 1.1 atatat break;
1287 1.1 atatat case 1:
1288 1.1 atatat if (name[0] < 0 || name[0] >= n)
1289 1.18 atatat return (ENOENT); /* ENOSUCHPROCESSOR */
1290 1.59 perry node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1291 1.1 atatat n = name[0];
1292 1.1 atatat /*
1293 1.1 atatat * adjust these so that sysctl_lookup() will be happy
1294 1.1 atatat */
1295 1.1 atatat name++;
1296 1.1 atatat namelen--;
1297 1.7 martin break;
1298 1.1 atatat default:
1299 1.1 atatat return (EINVAL);
1300 1.1 atatat }
1301 1.1 atatat
1302 1.118 ad cp_time = kmem_alloc(node.sysctl_size, KM_SLEEP);
1303 1.1 atatat if (cp_time == NULL)
1304 1.1 atatat return (ENOMEM);
1305 1.1 atatat node.sysctl_data = cp_time;
1306 1.1 atatat memset(cp_time, 0, node.sysctl_size);
1307 1.1 atatat
1308 1.1 atatat for (CPU_INFO_FOREACH(cii, ci)) {
1309 1.118 ad if (n <= 0) {
1310 1.118 ad for (i = 0; i < CPUSTATES; i++) {
1311 1.1 atatat cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
1312 1.118 ad }
1313 1.118 ad }
1314 1.1 atatat /*
1315 1.1 atatat * if a specific processor was requested and we just
1316 1.1 atatat * did it, we're done here
1317 1.1 atatat */
1318 1.1 atatat if (n == 0)
1319 1.1 atatat break;
1320 1.1 atatat /*
1321 1.1 atatat * if doing "all", skip to next cp_time set for next processor
1322 1.1 atatat */
1323 1.1 atatat if (n == -2)
1324 1.1 atatat cp_time += CPUSTATES;
1325 1.1 atatat /*
1326 1.1 atatat * if we're doing a specific processor, we're one
1327 1.1 atatat * processor closer
1328 1.1 atatat */
1329 1.1 atatat if (n > 0)
1330 1.1 atatat n--;
1331 1.1 atatat }
1332 1.1 atatat
1333 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1334 1.118 ad kmem_free(node.sysctl_data, node.sysctl_size);
1335 1.5 martin return (error);
1336 1.1 atatat }
1337 1.1 atatat
1338 1.1 atatat #if NPTY > 0
1339 1.1 atatat /*
1340 1.110 christos * sysctl helper routine for kern.maxptys. Ensures that any new value
1341 1.1 atatat * is acceptable to the pty subsystem.
1342 1.1 atatat */
1343 1.1 atatat static int
1344 1.1 atatat sysctl_kern_maxptys(SYSCTLFN_ARGS)
1345 1.1 atatat {
1346 1.1 atatat int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
1347 1.40 christos int error, xmax;
1348 1.1 atatat struct sysctlnode node;
1349 1.1 atatat
1350 1.1 atatat /* get current value of maxptys */
1351 1.40 christos xmax = pty_maxptys(0, 0);
1352 1.1 atatat
1353 1.1 atatat node = *rnode;
1354 1.40 christos node.sysctl_data = &xmax;
1355 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1356 1.1 atatat if (error || newp == NULL)
1357 1.1 atatat return (error);
1358 1.33 perry
1359 1.40 christos if (xmax != pty_maxptys(xmax, 1))
1360 1.1 atatat return (EINVAL);
1361 1.1 atatat
1362 1.1 atatat return (0);
1363 1.1 atatat }
1364 1.1 atatat #endif /* NPTY > 0 */
1365 1.1 atatat
1366 1.1 atatat /*
1367 1.110 christos * sysctl helper routine for kern.sbmax. Basically just ensures that
1368 1.1 atatat * any new value is not too small.
1369 1.1 atatat */
1370 1.1 atatat static int
1371 1.1 atatat sysctl_kern_sbmax(SYSCTLFN_ARGS)
1372 1.1 atatat {
1373 1.1 atatat int error, new_sbmax;
1374 1.1 atatat struct sysctlnode node;
1375 1.1 atatat
1376 1.1 atatat new_sbmax = sb_max;
1377 1.1 atatat node = *rnode;
1378 1.1 atatat node.sysctl_data = &new_sbmax;
1379 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1380 1.1 atatat if (error || newp == NULL)
1381 1.1 atatat return (error);
1382 1.1 atatat
1383 1.118 ad KERNEL_LOCK(1, NULL);
1384 1.1 atatat error = sb_max_set(new_sbmax);
1385 1.118 ad KERNEL_UNLOCK_ONE(NULL);
1386 1.1 atatat
1387 1.1 atatat return (error);
1388 1.1 atatat }
1389 1.1 atatat
1390 1.1 atatat /*
1391 1.110 christos * sysctl helper routine for kern.urandom node. Picks a random number
1392 1.1 atatat * for you.
1393 1.1 atatat */
1394 1.1 atatat static int
1395 1.1 atatat sysctl_kern_urnd(SYSCTLFN_ARGS)
1396 1.1 atatat {
1397 1.118 ad int v, rv;
1398 1.1 atatat
1399 1.184 tls rv = cprng_strong(sysctl_prng, &v, sizeof(v));
1400 1.118 ad if (rv == sizeof(v)) {
1401 1.1 atatat struct sysctlnode node = *rnode;
1402 1.1 atatat node.sysctl_data = &v;
1403 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1404 1.1 atatat }
1405 1.1 atatat else
1406 1.1 atatat return (EIO); /*XXX*/
1407 1.1 atatat }
1408 1.1 atatat
1409 1.1 atatat /*
1410 1.110 christos * sysctl helper routine for kern.arandom node. Picks a random number
1411 1.91 christos * for you.
1412 1.91 christos */
1413 1.91 christos static int
1414 1.91 christos sysctl_kern_arnd(SYSCTLFN_ARGS)
1415 1.91 christos {
1416 1.91 christos int error;
1417 1.91 christos void *v;
1418 1.91 christos struct sysctlnode node = *rnode;
1419 1.91 christos
1420 1.91 christos if (*oldlenp == 0)
1421 1.91 christos return 0;
1422 1.185 tls /*
1423 1.185 tls * This code used to allow sucking 8192 bytes at a time out
1424 1.185 tls * of the kernel arc4random generator. Evidently there is some
1425 1.185 tls * very old OpenBSD application code that may try to do this.
1426 1.185 tls *
1427 1.185 tls * Note that this node is documented as type "INT" -- 4 or 8
1428 1.185 tls * bytes, not 8192.
1429 1.185 tls *
1430 1.185 tls * We continue to support this abuse of the "len" pointer here
1431 1.185 tls * but only 256 bytes at a time, as, anecdotally, the actual
1432 1.185 tls * application use here was to generate RC4 keys in userspace.
1433 1.185 tls *
1434 1.185 tls * Support for such large requests will probably be removed
1435 1.185 tls * entirely in the future.
1436 1.185 tls */
1437 1.185 tls if (*oldlenp > 256)
1438 1.91 christos return E2BIG;
1439 1.91 christos
1440 1.118 ad v = kmem_alloc(*oldlenp, KM_SLEEP);
1441 1.184 tls cprng_fast(v, *oldlenp);
1442 1.91 christos node.sysctl_data = v;
1443 1.91 christos node.sysctl_size = *oldlenp;
1444 1.91 christos error = sysctl_lookup(SYSCTLFN_CALL(&node));
1445 1.118 ad kmem_free(v, *oldlenp);
1446 1.91 christos return error;
1447 1.91 christos }
1448 1.91 christos /*
1449 1.1 atatat * sysctl helper routine to do kern.lwp.* work.
1450 1.1 atatat */
1451 1.1 atatat static int
1452 1.1 atatat sysctl_kern_lwp(SYSCTLFN_ARGS)
1453 1.1 atatat {
1454 1.1 atatat struct kinfo_lwp klwp;
1455 1.1 atatat struct proc *p;
1456 1.118 ad struct lwp *l2, *l3;
1457 1.1 atatat char *where, *dp;
1458 1.1 atatat int pid, elem_size, elem_count;
1459 1.1 atatat int buflen, needed, error;
1460 1.118 ad bool gotit;
1461 1.1 atatat
1462 1.19 atatat if (namelen == 1 && name[0] == CTL_QUERY)
1463 1.43 atatat return (sysctl_query(SYSCTLFN_CALL(rnode)));
1464 1.19 atatat
1465 1.1 atatat dp = where = oldp;
1466 1.1 atatat buflen = where != NULL ? *oldlenp : 0;
1467 1.1 atatat error = needed = 0;
1468 1.1 atatat
1469 1.11 simonb if (newp != NULL || namelen != 3)
1470 1.1 atatat return (EINVAL);
1471 1.11 simonb pid = name[0];
1472 1.11 simonb elem_size = name[1];
1473 1.11 simonb elem_count = name[2];
1474 1.1 atatat
1475 1.118 ad sysctl_unlock();
1476 1.101 yamt if (pid == -1) {
1477 1.132 ad mutex_enter(proc_lock);
1478 1.162 yamt PROCLIST_FOREACH(p, &allproc) {
1479 1.118 ad /* Grab a hold on the process. */
1480 1.118 ad if (!rw_tryenter(&p->p_reflock, RW_READER)) {
1481 1.118 ad continue;
1482 1.118 ad }
1483 1.132 ad mutex_exit(proc_lock);
1484 1.118 ad
1485 1.133 ad mutex_enter(p->p_lock);
1486 1.118 ad LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1487 1.118 ad if (buflen >= elem_size && elem_count > 0) {
1488 1.118 ad lwp_lock(l2);
1489 1.118 ad fill_lwp(l2, &klwp);
1490 1.118 ad lwp_unlock(l2);
1491 1.133 ad mutex_exit(p->p_lock);
1492 1.101 yamt
1493 1.118 ad /*
1494 1.118 ad * Copy out elem_size, but not
1495 1.118 ad * larger than the size of a
1496 1.118 ad * struct kinfo_proc2.
1497 1.118 ad */
1498 1.118 ad error = dcopyout(l, &klwp, dp,
1499 1.118 ad min(sizeof(klwp), elem_size));
1500 1.118 ad if (error) {
1501 1.118 ad rw_exit(&p->p_reflock);
1502 1.118 ad goto cleanup;
1503 1.118 ad }
1504 1.133 ad mutex_enter(p->p_lock);
1505 1.118 ad LIST_FOREACH(l3, &p->p_lwps,
1506 1.118 ad l_sibling) {
1507 1.118 ad if (l2 == l3)
1508 1.118 ad break;
1509 1.118 ad }
1510 1.118 ad if (l3 == NULL) {
1511 1.133 ad mutex_exit(p->p_lock);
1512 1.118 ad rw_exit(&p->p_reflock);
1513 1.118 ad error = EAGAIN;
1514 1.118 ad goto cleanup;
1515 1.118 ad }
1516 1.118 ad dp += elem_size;
1517 1.118 ad buflen -= elem_size;
1518 1.118 ad elem_count--;
1519 1.118 ad }
1520 1.118 ad needed += elem_size;
1521 1.101 yamt }
1522 1.133 ad mutex_exit(p->p_lock);
1523 1.118 ad
1524 1.118 ad /* Drop reference to process. */
1525 1.132 ad mutex_enter(proc_lock);
1526 1.118 ad rw_exit(&p->p_reflock);
1527 1.101 yamt }
1528 1.132 ad mutex_exit(proc_lock);
1529 1.101 yamt } else {
1530 1.132 ad mutex_enter(proc_lock);
1531 1.175 rmind p = proc_find(pid);
1532 1.101 yamt if (p == NULL) {
1533 1.118 ad error = ESRCH;
1534 1.132 ad mutex_exit(proc_lock);
1535 1.118 ad goto cleanup;
1536 1.118 ad }
1537 1.118 ad /* Grab a hold on the process. */
1538 1.118 ad gotit = rw_tryenter(&p->p_reflock, RW_READER);
1539 1.132 ad mutex_exit(proc_lock);
1540 1.118 ad if (!gotit) {
1541 1.118 ad error = ESRCH;
1542 1.118 ad goto cleanup;
1543 1.101 yamt }
1544 1.118 ad
1545 1.133 ad mutex_enter(p->p_lock);
1546 1.101 yamt LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1547 1.101 yamt if (buflen >= elem_size && elem_count > 0) {
1548 1.101 yamt lwp_lock(l2);
1549 1.101 yamt fill_lwp(l2, &klwp);
1550 1.101 yamt lwp_unlock(l2);
1551 1.133 ad mutex_exit(p->p_lock);
1552 1.101 yamt /*
1553 1.101 yamt * Copy out elem_size, but not larger than
1554 1.101 yamt * the size of a struct kinfo_proc2.
1555 1.101 yamt */
1556 1.101 yamt error = dcopyout(l, &klwp, dp,
1557 1.101 yamt min(sizeof(klwp), elem_size));
1558 1.107 ad if (error) {
1559 1.118 ad rw_exit(&p->p_reflock);
1560 1.107 ad goto cleanup;
1561 1.107 ad }
1562 1.133 ad mutex_enter(p->p_lock);
1563 1.107 ad LIST_FOREACH(l3, &p->p_lwps, l_sibling) {
1564 1.107 ad if (l2 == l3)
1565 1.107 ad break;
1566 1.107 ad }
1567 1.108 rmind if (l3 == NULL) {
1568 1.133 ad mutex_exit(p->p_lock);
1569 1.118 ad rw_exit(&p->p_reflock);
1570 1.107 ad error = EAGAIN;
1571 1.101 yamt goto cleanup;
1572 1.107 ad }
1573 1.101 yamt dp += elem_size;
1574 1.101 yamt buflen -= elem_size;
1575 1.101 yamt elem_count--;
1576 1.101 yamt }
1577 1.101 yamt needed += elem_size;
1578 1.1 atatat }
1579 1.133 ad mutex_exit(p->p_lock);
1580 1.118 ad
1581 1.118 ad /* Drop reference to process. */
1582 1.118 ad rw_exit(&p->p_reflock);
1583 1.1 atatat }
1584 1.1 atatat
1585 1.1 atatat if (where != NULL) {
1586 1.1 atatat *oldlenp = dp - where;
1587 1.118 ad if (needed > *oldlenp) {
1588 1.118 ad sysctl_relock();
1589 1.1 atatat return (ENOMEM);
1590 1.118 ad }
1591 1.1 atatat } else {
1592 1.22 atatat needed += KERN_LWPSLOP;
1593 1.1 atatat *oldlenp = needed;
1594 1.1 atatat }
1595 1.118 ad error = 0;
1596 1.1 atatat cleanup:
1597 1.118 ad sysctl_relock();
1598 1.1 atatat return (error);
1599 1.1 atatat }
1600 1.1 atatat
1601 1.1 atatat /*
1602 1.110 christos * sysctl helper routine for kern.forkfsleep node. Ensures that the
1603 1.1 atatat * given value is not too large or two small, and is at least one
1604 1.1 atatat * timer tick if not zero.
1605 1.1 atatat */
1606 1.1 atatat static int
1607 1.1 atatat sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
1608 1.1 atatat {
1609 1.1 atatat /* userland sees value in ms, internally is in ticks */
1610 1.1 atatat extern int forkfsleep; /* defined in kern/kern_fork.c */
1611 1.1 atatat int error, timo, lsleep;
1612 1.1 atatat struct sysctlnode node;
1613 1.1 atatat
1614 1.1 atatat lsleep = forkfsleep * 1000 / hz;
1615 1.1 atatat node = *rnode;
1616 1.1 atatat node.sysctl_data = &lsleep;
1617 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1618 1.1 atatat if (error || newp == NULL)
1619 1.1 atatat return (error);
1620 1.1 atatat
1621 1.1 atatat /* refuse negative values, and overly 'long time' */
1622 1.1 atatat if (lsleep < 0 || lsleep > MAXSLP * 1000)
1623 1.1 atatat return (EINVAL);
1624 1.1 atatat
1625 1.1 atatat timo = mstohz(lsleep);
1626 1.1 atatat
1627 1.1 atatat /* if the interval is >0 ms && <1 tick, use 1 tick */
1628 1.1 atatat if (lsleep != 0 && timo == 0)
1629 1.1 atatat forkfsleep = 1;
1630 1.1 atatat else
1631 1.1 atatat forkfsleep = timo;
1632 1.1 atatat
1633 1.1 atatat return (0);
1634 1.1 atatat }
1635 1.1 atatat
1636 1.1 atatat /*
1637 1.1 atatat * sysctl helper routine for kern.root_partition
1638 1.1 atatat */
1639 1.1 atatat static int
1640 1.1 atatat sysctl_kern_root_partition(SYSCTLFN_ARGS)
1641 1.1 atatat {
1642 1.1 atatat int rootpart = DISKPART(rootdev);
1643 1.1 atatat struct sysctlnode node = *rnode;
1644 1.1 atatat
1645 1.1 atatat node.sysctl_data = &rootpart;
1646 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1647 1.1 atatat }
1648 1.1 atatat
1649 1.1 atatat /*
1650 1.1 atatat * sysctl helper function for kern.drivers
1651 1.1 atatat */
1652 1.1 atatat static int
1653 1.1 atatat sysctl_kern_drivers(SYSCTLFN_ARGS)
1654 1.1 atatat {
1655 1.1 atatat int error;
1656 1.1 atatat size_t buflen;
1657 1.1 atatat struct kinfo_drivers kd;
1658 1.1 atatat char *start, *where;
1659 1.1 atatat const char *dname;
1660 1.1 atatat int i;
1661 1.1 atatat extern struct devsw_conv *devsw_conv;
1662 1.1 atatat extern int max_devsw_convs;
1663 1.1 atatat
1664 1.1 atatat if (newp != NULL || namelen != 0)
1665 1.1 atatat return (EINVAL);
1666 1.1 atatat
1667 1.1 atatat start = where = oldp;
1668 1.1 atatat buflen = *oldlenp;
1669 1.1 atatat if (where == NULL) {
1670 1.1 atatat *oldlenp = max_devsw_convs * sizeof kd;
1671 1.1 atatat return 0;
1672 1.1 atatat }
1673 1.1 atatat
1674 1.1 atatat /*
1675 1.1 atatat * An array of kinfo_drivers structures
1676 1.1 atatat */
1677 1.1 atatat error = 0;
1678 1.118 ad sysctl_unlock();
1679 1.152 pooka mutex_enter(&device_lock);
1680 1.1 atatat for (i = 0; i < max_devsw_convs; i++) {
1681 1.1 atatat dname = devsw_conv[i].d_name;
1682 1.1 atatat if (dname == NULL)
1683 1.1 atatat continue;
1684 1.1 atatat if (buflen < sizeof kd) {
1685 1.1 atatat error = ENOMEM;
1686 1.1 atatat break;
1687 1.1 atatat }
1688 1.25 atatat memset(&kd, 0, sizeof(kd));
1689 1.1 atatat kd.d_bmajor = devsw_conv[i].d_bmajor;
1690 1.1 atatat kd.d_cmajor = devsw_conv[i].d_cmajor;
1691 1.1 atatat strlcpy(kd.d_name, dname, sizeof kd.d_name);
1692 1.152 pooka mutex_exit(&device_lock);
1693 1.86 manu error = dcopyout(l, &kd, where, sizeof kd);
1694 1.152 pooka mutex_enter(&device_lock);
1695 1.1 atatat if (error != 0)
1696 1.1 atatat break;
1697 1.1 atatat buflen -= sizeof kd;
1698 1.1 atatat where += sizeof kd;
1699 1.1 atatat }
1700 1.152 pooka mutex_exit(&device_lock);
1701 1.118 ad sysctl_relock();
1702 1.1 atatat *oldlenp = where - start;
1703 1.1 atatat return error;
1704 1.1 atatat }
1705 1.1 atatat
1706 1.61 elad static int
1707 1.61 elad sysctl_security_setidcore(SYSCTLFN_ARGS)
1708 1.61 elad {
1709 1.61 elad int newsize, error;
1710 1.61 elad struct sysctlnode node;
1711 1.61 elad
1712 1.61 elad node = *rnode;
1713 1.61 elad node.sysctl_data = &newsize;
1714 1.61 elad newsize = *(int *)rnode->sysctl_data;
1715 1.61 elad error = sysctl_lookup(SYSCTLFN_CALL(&node));
1716 1.61 elad if (error || newp == NULL)
1717 1.61 elad return error;
1718 1.61 elad
1719 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
1720 1.85 elad 0, NULL, NULL, NULL))
1721 1.61 elad return (EPERM);
1722 1.61 elad
1723 1.61 elad *(int *)rnode->sysctl_data = newsize;
1724 1.61 elad
1725 1.61 elad return 0;
1726 1.61 elad }
1727 1.61 elad
1728 1.61 elad static int
1729 1.61 elad sysctl_security_setidcorename(SYSCTLFN_ARGS)
1730 1.61 elad {
1731 1.61 elad int error;
1732 1.72 yamt char *newsetidcorename;
1733 1.61 elad struct sysctlnode node;
1734 1.61 elad
1735 1.72 yamt newsetidcorename = PNBUF_GET();
1736 1.61 elad node = *rnode;
1737 1.72 yamt node.sysctl_data = newsetidcorename;
1738 1.61 elad memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
1739 1.61 elad error = sysctl_lookup(SYSCTLFN_CALL(&node));
1740 1.72 yamt if (error || newp == NULL) {
1741 1.72 yamt goto out;
1742 1.72 yamt }
1743 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
1744 1.85 elad 0, NULL, NULL, NULL)) {
1745 1.72 yamt error = EPERM;
1746 1.72 yamt goto out;
1747 1.72 yamt }
1748 1.72 yamt if (strlen(newsetidcorename) == 0) {
1749 1.72 yamt error = EINVAL;
1750 1.72 yamt goto out;
1751 1.72 yamt }
1752 1.61 elad memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
1753 1.72 yamt out:
1754 1.72 yamt PNBUF_PUT(newsetidcorename);
1755 1.72 yamt return error;
1756 1.61 elad }
1757 1.61 elad
1758 1.38 elad /*
1759 1.110 christos * sysctl helper routine for kern.cp_id node. Maps cpus to their
1760 1.45 christos * cpuids.
1761 1.45 christos */
1762 1.45 christos static int
1763 1.45 christos sysctl_kern_cpid(SYSCTLFN_ARGS)
1764 1.45 christos {
1765 1.45 christos struct sysctlnode node = *rnode;
1766 1.59 perry uint64_t *cp_id = NULL;
1767 1.96 ad int error, n = ncpu;
1768 1.45 christos struct cpu_info *ci;
1769 1.45 christos CPU_INFO_ITERATOR cii;
1770 1.45 christos
1771 1.45 christos /*
1772 1.110 christos * Here you may either retrieve a single cpu id or the whole
1773 1.110 christos * set. The size you get back when probing depends on what
1774 1.46 atatat * you ask for.
1775 1.45 christos */
1776 1.45 christos switch (namelen) {
1777 1.45 christos case 0:
1778 1.59 perry node.sysctl_size = n * sizeof(uint64_t);
1779 1.45 christos n = -2; /* ALL */
1780 1.45 christos break;
1781 1.45 christos case 1:
1782 1.45 christos if (name[0] < 0 || name[0] >= n)
1783 1.45 christos return (ENOENT); /* ENOSUCHPROCESSOR */
1784 1.59 perry node.sysctl_size = sizeof(uint64_t);
1785 1.45 christos n = name[0];
1786 1.45 christos /*
1787 1.45 christos * adjust these so that sysctl_lookup() will be happy
1788 1.45 christos */
1789 1.45 christos name++;
1790 1.45 christos namelen--;
1791 1.45 christos break;
1792 1.45 christos default:
1793 1.45 christos return (EINVAL);
1794 1.45 christos }
1795 1.45 christos
1796 1.118 ad cp_id = kmem_alloc(node.sysctl_size, KM_SLEEP);
1797 1.45 christos if (cp_id == NULL)
1798 1.45 christos return (ENOMEM);
1799 1.45 christos node.sysctl_data = cp_id;
1800 1.45 christos memset(cp_id, 0, node.sysctl_size);
1801 1.45 christos
1802 1.45 christos for (CPU_INFO_FOREACH(cii, ci)) {
1803 1.45 christos if (n <= 0)
1804 1.138 ad cp_id[0] = cpu_index(ci);
1805 1.45 christos /*
1806 1.45 christos * if a specific processor was requested and we just
1807 1.45 christos * did it, we're done here
1808 1.45 christos */
1809 1.45 christos if (n == 0)
1810 1.45 christos break;
1811 1.45 christos /*
1812 1.45 christos * if doing "all", skip to next cp_id slot for next processor
1813 1.45 christos */
1814 1.45 christos if (n == -2)
1815 1.45 christos cp_id++;
1816 1.45 christos /*
1817 1.45 christos * if we're doing a specific processor, we're one
1818 1.45 christos * processor closer
1819 1.45 christos */
1820 1.45 christos if (n > 0)
1821 1.45 christos n--;
1822 1.45 christos }
1823 1.45 christos
1824 1.45 christos error = sysctl_lookup(SYSCTLFN_CALL(&node));
1825 1.118 ad kmem_free(node.sysctl_data, node.sysctl_size);
1826 1.45 christos return (error);
1827 1.45 christos }
1828 1.45 christos
1829 1.45 christos /*
1830 1.110 christos * sysctl helper routine for hw.usermem and hw.usermem64. Values are
1831 1.1 atatat * calculate on the fly taking into account integer overflow and the
1832 1.1 atatat * current wired count.
1833 1.1 atatat */
1834 1.1 atatat static int
1835 1.1 atatat sysctl_hw_usermem(SYSCTLFN_ARGS)
1836 1.1 atatat {
1837 1.1 atatat u_int ui;
1838 1.1 atatat u_quad_t uq;
1839 1.1 atatat struct sysctlnode node;
1840 1.1 atatat
1841 1.1 atatat node = *rnode;
1842 1.1 atatat switch (rnode->sysctl_num) {
1843 1.155 cegger case HW_USERMEM:
1844 1.1 atatat if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
1845 1.1 atatat ui = UINT_MAX;
1846 1.1 atatat else
1847 1.1 atatat ui *= PAGE_SIZE;
1848 1.1 atatat node.sysctl_data = &ui;
1849 1.1 atatat break;
1850 1.1 atatat case HW_USERMEM64:
1851 1.1 atatat uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
1852 1.1 atatat node.sysctl_data = &uq;
1853 1.1 atatat break;
1854 1.1 atatat default:
1855 1.1 atatat return (EINVAL);
1856 1.1 atatat }
1857 1.1 atatat
1858 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1859 1.1 atatat }
1860 1.1 atatat
1861 1.1 atatat /*
1862 1.110 christos * sysctl helper routine for kern.cnmagic node. Pulls the old value
1863 1.1 atatat * out, encoded, and stuffs the new value in for decoding.
1864 1.1 atatat */
1865 1.1 atatat static int
1866 1.1 atatat sysctl_hw_cnmagic(SYSCTLFN_ARGS)
1867 1.1 atatat {
1868 1.1 atatat char magic[CNS_LEN];
1869 1.1 atatat int error;
1870 1.1 atatat struct sysctlnode node;
1871 1.1 atatat
1872 1.1 atatat if (oldp)
1873 1.1 atatat cn_get_magic(magic, CNS_LEN);
1874 1.1 atatat node = *rnode;
1875 1.1 atatat node.sysctl_data = &magic[0];
1876 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1877 1.1 atatat if (error || newp == NULL)
1878 1.1 atatat return (error);
1879 1.33 perry
1880 1.1 atatat return (cn_set_magic(magic));
1881 1.1 atatat }
1882 1.3 martin
1883 1.1 atatat /*
1884 1.1 atatat * ********************************************************************
1885 1.1 atatat * section 3: public helper routines that are used for more than one
1886 1.1 atatat * node
1887 1.1 atatat * ********************************************************************
1888 1.1 atatat */
1889 1.1 atatat
1890 1.1 atatat /*
1891 1.1 atatat * sysctl helper routine for the kern.root_device node and some ports'
1892 1.1 atatat * machdep.root_device nodes.
1893 1.1 atatat */
1894 1.1 atatat int
1895 1.1 atatat sysctl_root_device(SYSCTLFN_ARGS)
1896 1.1 atatat {
1897 1.1 atatat struct sysctlnode node;
1898 1.1 atatat
1899 1.1 atatat node = *rnode;
1900 1.1 atatat node.sysctl_data = root_device->dv_xname;
1901 1.130 cegger node.sysctl_size = strlen(device_xname(root_device)) + 1;
1902 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1903 1.1 atatat }
1904 1.1 atatat
1905 1.1 atatat /*
1906 1.1 atatat * sysctl helper routine for kern.consdev, dependent on the current
1907 1.110 christos * state of the console. Also used for machdep.console_device on some
1908 1.1 atatat * ports.
1909 1.1 atatat */
1910 1.1 atatat int
1911 1.1 atatat sysctl_consdev(SYSCTLFN_ARGS)
1912 1.1 atatat {
1913 1.1 atatat dev_t consdev;
1914 1.165 christos uint32_t oconsdev;
1915 1.1 atatat struct sysctlnode node;
1916 1.1 atatat
1917 1.1 atatat if (cn_tab != NULL)
1918 1.1 atatat consdev = cn_tab->cn_dev;
1919 1.1 atatat else
1920 1.1 atatat consdev = NODEV;
1921 1.1 atatat node = *rnode;
1922 1.165 christos switch (*oldlenp) {
1923 1.165 christos case sizeof(consdev):
1924 1.165 christos node.sysctl_data = &consdev;
1925 1.165 christos node.sysctl_size = sizeof(consdev);
1926 1.165 christos break;
1927 1.165 christos case sizeof(oconsdev):
1928 1.165 christos oconsdev = (uint32_t)consdev;
1929 1.165 christos node.sysctl_data = &oconsdev;
1930 1.165 christos node.sysctl_size = sizeof(oconsdev);
1931 1.165 christos break;
1932 1.165 christos default:
1933 1.165 christos return EINVAL;
1934 1.165 christos }
1935 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1936 1.1 atatat }
1937 1.1 atatat
1938 1.1 atatat /*
1939 1.1 atatat * ********************************************************************
1940 1.1 atatat * section 4: support for some helpers
1941 1.1 atatat * ********************************************************************
1942 1.1 atatat */
1943 1.146 christos
1944 1.1 atatat
1945 1.1 atatat /*
1946 1.1 atatat * Fill in a kinfo_lwp structure for the specified lwp.
1947 1.1 atatat */
1948 1.1 atatat static void
1949 1.1 atatat fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
1950 1.1 atatat {
1951 1.101 yamt struct proc *p = l->l_proc;
1952 1.115 yamt struct timeval tv;
1953 1.1 atatat
1954 1.131 yamt KASSERT(lwp_locked(l, NULL));
1955 1.131 yamt
1956 1.174 pooka memset(kl, 0, sizeof(*kl));
1957 1.174 pooka
1958 1.101 yamt kl->l_forw = 0;
1959 1.101 yamt kl->l_back = 0;
1960 1.21 atatat kl->l_laddr = PTRTOUINT64(l);
1961 1.21 atatat kl->l_addr = PTRTOUINT64(l->l_addr);
1962 1.1 atatat kl->l_stat = l->l_stat;
1963 1.1 atatat kl->l_lid = l->l_lid;
1964 1.170 dsl kl->l_flag = L_INMEM;
1965 1.170 dsl kl->l_flag |= sysctl_map_flags(sysctl_lwpprflagmap, l->l_prflag);
1966 1.144 christos kl->l_flag |= sysctl_map_flags(sysctl_lwpflagmap, l->l_flag);
1967 1.1 atatat
1968 1.1 atatat kl->l_swtime = l->l_swtime;
1969 1.1 atatat kl->l_slptime = l->l_slptime;
1970 1.95 ad if (l->l_stat == LSONPROC)
1971 1.1 atatat kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
1972 1.95 ad else
1973 1.1 atatat kl->l_schedflags = 0;
1974 1.113 ad kl->l_priority = lwp_eprio(l);
1975 1.113 ad kl->l_usrpri = l->l_priority;
1976 1.131 yamt if (l->l_wchan)
1977 1.129 xtraeme strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
1978 1.21 atatat kl->l_wchan = PTRTOUINT64(l->l_wchan);
1979 1.138 ad kl->l_cpuid = cpu_index(l->l_cpu);
1980 1.115 yamt bintime2timeval(&l->l_rtime, &tv);
1981 1.115 yamt kl->l_rtime_sec = tv.tv_sec;
1982 1.115 yamt kl->l_rtime_usec = tv.tv_usec;
1983 1.101 yamt kl->l_cpticks = l->l_cpticks;
1984 1.101 yamt kl->l_pctcpu = l->l_pctcpu;
1985 1.101 yamt kl->l_pid = p->p_pid;
1986 1.101 yamt if (l->l_name == NULL)
1987 1.101 yamt kl->l_name[0] = '\0';
1988 1.128 xtraeme else
1989 1.129 xtraeme strlcpy(kl->l_name, l->l_name, sizeof(kl->l_name));
1990 1.1 atatat }
1991