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