init_sysctl.c revision 1.105.2.2 1 1.105.2.2 matt /* $NetBSD: init_sysctl.c,v 1.105.2.2 2008/01/09 01:55:57 matt Exp $ */
2 1.1 atatat
3 1.1 atatat /*-
4 1.105.2.2 matt * Copyright (c) 2003, 2007, 2008 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.105.2.2 matt * 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 * 3. All advertising materials mentioning features or use of this software
19 1.1 atatat * must display the following acknowledgement:
20 1.105.2.1 matt * This product includes software developed by the NetBSD
21 1.105.2.1 matt * Foundation, Inc. and its contributors.
22 1.1 atatat * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 atatat * contributors may be used to endorse or promote products derived
24 1.1 atatat * from this software without specific prior written permission.
25 1.1 atatat *
26 1.1 atatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 atatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 atatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 atatat * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 atatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 atatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 atatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 atatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 atatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 atatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 atatat * POSSIBILITY OF SUCH DAMAGE.
37 1.1 atatat */
38 1.1 atatat
39 1.16 atatat #include <sys/cdefs.h>
40 1.105.2.2 matt __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.105.2.2 2008/01/09 01:55:57 matt Exp $");
41 1.16 atatat
42 1.1 atatat #include "opt_sysv.h"
43 1.4 fvdl #include "opt_posix.h"
44 1.82 manu #include "opt_compat_netbsd32.h"
45 1.1 atatat #include "pty.h"
46 1.1 atatat #include "rnd.h"
47 1.1 atatat
48 1.1 atatat #include <sys/types.h>
49 1.1 atatat #include <sys/param.h>
50 1.1 atatat #include <sys/sysctl.h>
51 1.104 yamt #include <sys/cpu.h>
52 1.1 atatat #include <sys/errno.h>
53 1.1 atatat #include <sys/systm.h>
54 1.1 atatat #include <sys/kernel.h>
55 1.1 atatat #include <sys/unistd.h>
56 1.1 atatat #include <sys/disklabel.h>
57 1.1 atatat #include <sys/rnd.h>
58 1.1 atatat #include <sys/vnode.h>
59 1.1 atatat #include <sys/mount.h>
60 1.1 atatat #include <sys/namei.h>
61 1.1 atatat #include <sys/msgbuf.h>
62 1.1 atatat #include <dev/cons.h>
63 1.1 atatat #include <sys/socketvar.h>
64 1.1 atatat #include <sys/file.h>
65 1.34 atatat #include <sys/filedesc.h>
66 1.1 atatat #include <sys/tty.h>
67 1.1 atatat #include <sys/malloc.h>
68 1.1 atatat #include <sys/resource.h>
69 1.1 atatat #include <sys/resourcevar.h>
70 1.1 atatat #include <sys/exec.h>
71 1.1 atatat #include <sys/conf.h>
72 1.1 atatat #include <sys/device.h>
73 1.61 elad #include <sys/stat.h>
74 1.68 elad #include <sys/kauth.h>
75 1.86 manu #include <sys/ktrace.h>
76 1.1 atatat
77 1.82 manu #ifdef COMPAT_NETBSD32
78 1.82 manu #include <compat/netbsd32/netbsd32.h>
79 1.82 manu #endif
80 1.82 manu
81 1.105.2.1 matt #include <sys/cpu.h>
82 1.1 atatat
83 1.54 elad /* XXX this should not be here */
84 1.61 elad int security_setidcore_dump;
85 1.61 elad char security_setidcore_path[MAXPATHLEN] = "/var/crash/%n.core";
86 1.61 elad uid_t security_setidcore_owner = 0;
87 1.61 elad gid_t security_setidcore_group = 0;
88 1.61 elad mode_t security_setidcore_mode = (S_IRUSR|S_IWUSR);
89 1.54 elad
90 1.95 ad static const u_int sysctl_flagmap[] = {
91 1.97 pavel PK_ADVLOCK, P_ADVLOCK,
92 1.97 pavel PK_EXEC, P_EXEC,
93 1.97 pavel PK_NOCLDWAIT, P_NOCLDWAIT,
94 1.97 pavel PK_32, P_32,
95 1.97 pavel PK_CLDSIGIGN, P_CLDSIGIGN,
96 1.97 pavel PK_SUGID, P_SUGID,
97 1.95 ad 0
98 1.95 ad };
99 1.95 ad
100 1.95 ad static const u_int sysctl_sflagmap[] = {
101 1.97 pavel PS_NOCLDSTOP, P_NOCLDSTOP,
102 1.97 pavel PS_PPWAIT, P_PPWAIT,
103 1.97 pavel PS_WEXIT, P_WEXIT,
104 1.97 pavel PS_STOPFORK, P_STOPFORK,
105 1.97 pavel PS_STOPEXEC, P_STOPEXEC,
106 1.97 pavel PS_STOPEXIT, P_STOPEXIT,
107 1.95 ad 0
108 1.95 ad };
109 1.95 ad
110 1.95 ad static const u_int sysctl_slflagmap[] = {
111 1.97 pavel PSL_TRACED, P_TRACED,
112 1.97 pavel PSL_FSTRACE, P_FSTRACE,
113 1.97 pavel PSL_CHTRACED, P_CHTRACED,
114 1.97 pavel PSL_SYSCALL, P_SYSCALL,
115 1.95 ad 0
116 1.95 ad };
117 1.95 ad
118 1.95 ad static const u_int sysctl_lflagmap[] = {
119 1.97 pavel PL_CONTROLT, P_CONTROLT,
120 1.95 ad 0
121 1.95 ad };
122 1.95 ad
123 1.95 ad static const u_int sysctl_stflagmap[] = {
124 1.97 pavel PST_PROFIL, P_PROFIL,
125 1.95 ad 0
126 1.95 ad
127 1.95 ad };
128 1.95 ad
129 1.95 ad static const u_int sysctl_lwpflagmap[] = {
130 1.97 pavel LW_INMEM, P_INMEM,
131 1.97 pavel LW_SINTR, P_SINTR,
132 1.97 pavel LW_SYSTEM, P_SYSTEM,
133 1.95 ad 0
134 1.95 ad };
135 1.95 ad
136 1.95 ad static const u_int sysctl_lwpprflagmap[] = {
137 1.97 pavel LPR_DETACHED, L_DETACHED,
138 1.95 ad 0
139 1.95 ad };
140 1.95 ad
141 1.1 atatat /*
142 1.1 atatat * try over estimating by 5 procs/lwps
143 1.1 atatat */
144 1.1 atatat #define KERN_PROCSLOP (5 * sizeof(struct kinfo_proc))
145 1.1 atatat #define KERN_LWPSLOP (5 * sizeof(struct kinfo_lwp))
146 1.1 atatat
147 1.105 ad static int dcopyout(struct lwp *, const void *, void *, size_t);
148 1.86 manu
149 1.105 ad static int
150 1.86 manu dcopyout(l, kaddr, uaddr, len)
151 1.86 manu struct lwp *l;
152 1.86 manu const void *kaddr;
153 1.86 manu void *uaddr;
154 1.86 manu size_t len;
155 1.86 manu {
156 1.86 manu int error;
157 1.86 manu
158 1.86 manu error = copyout(kaddr, uaddr, len);
159 1.105 ad ktrmibio(-1, UIO_READ, uaddr, len, error);
160 1.86 manu
161 1.86 manu return error;
162 1.86 manu }
163 1.96 ad
164 1.64 erh #ifdef DIAGNOSTIC
165 1.64 erh static int sysctl_kern_trigger_panic(SYSCTLFN_PROTO);
166 1.64 erh #endif
167 1.1 atatat static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
168 1.14 martin static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
169 1.1 atatat static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
170 1.1 atatat static int sysctl_kern_hostid(SYSCTLFN_PROTO);
171 1.17 atatat static int sysctl_setlen(SYSCTLFN_PROTO);
172 1.1 atatat static int sysctl_kern_clockrate(SYSCTLFN_PROTO);
173 1.1 atatat static int sysctl_kern_file(SYSCTLFN_PROTO);
174 1.1 atatat static int sysctl_msgbuf(SYSCTLFN_PROTO);
175 1.1 atatat static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
176 1.1 atatat static int sysctl_kern_cptime(SYSCTLFN_PROTO);
177 1.6 he #if NPTY > 0
178 1.1 atatat static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
179 1.6 he #endif /* NPTY > 0 */
180 1.1 atatat static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
181 1.1 atatat static int sysctl_kern_urnd(SYSCTLFN_PROTO);
182 1.91 christos static int sysctl_kern_arnd(SYSCTLFN_PROTO);
183 1.1 atatat static int sysctl_kern_lwp(SYSCTLFN_PROTO);
184 1.1 atatat static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
185 1.1 atatat static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
186 1.1 atatat static int sysctl_kern_drivers(SYSCTLFN_PROTO);
187 1.34 atatat static int sysctl_kern_file2(SYSCTLFN_PROTO);
188 1.61 elad static int sysctl_security_setidcore(SYSCTLFN_PROTO);
189 1.61 elad static int sysctl_security_setidcorename(SYSCTLFN_PROTO);
190 1.45 christos static int sysctl_kern_cpid(SYSCTLFN_PROTO);
191 1.1 atatat static int sysctl_doeproc(SYSCTLFN_PROTO);
192 1.1 atatat static int sysctl_kern_proc_args(SYSCTLFN_PROTO);
193 1.1 atatat static int sysctl_hw_usermem(SYSCTLFN_PROTO);
194 1.1 atatat static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
195 1.1 atatat
196 1.95 ad static u_int sysctl_map_flags(const u_int *, u_int);
197 1.1 atatat static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
198 1.1 atatat static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
199 1.34 atatat static void fill_file(struct kinfo_file *, const struct file *, struct proc *,
200 1.34 atatat int);
201 1.1 atatat
202 1.1 atatat /*
203 1.1 atatat * ********************************************************************
204 1.1 atatat * section 1: setup routines
205 1.1 atatat * ********************************************************************
206 1.105.2.1 matt * These functions are stuffed into a link set for sysctl setup
207 1.105.2.1 matt * functions. They're never called or referenced from anywhere else.
208 1.1 atatat * ********************************************************************
209 1.1 atatat */
210 1.1 atatat
211 1.1 atatat /*
212 1.1 atatat * sets up the base nodes...
213 1.1 atatat */
214 1.1 atatat SYSCTL_SETUP(sysctl_root_setup, "sysctl base setup")
215 1.1 atatat {
216 1.1 atatat
217 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
218 1.24 atatat CTLFLAG_PERMANENT,
219 1.26 atatat CTLTYPE_NODE, "kern",
220 1.26 atatat SYSCTL_DESCR("High kernel"),
221 1.1 atatat NULL, 0, NULL, 0,
222 1.1 atatat CTL_KERN, CTL_EOL);
223 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
224 1.24 atatat CTLFLAG_PERMANENT,
225 1.26 atatat CTLTYPE_NODE, "vm",
226 1.26 atatat SYSCTL_DESCR("Virtual memory"),
227 1.1 atatat NULL, 0, NULL, 0,
228 1.1 atatat CTL_VM, CTL_EOL);
229 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
230 1.24 atatat CTLFLAG_PERMANENT,
231 1.26 atatat CTLTYPE_NODE, "vfs",
232 1.26 atatat SYSCTL_DESCR("Filesystem"),
233 1.1 atatat NULL, 0, NULL, 0,
234 1.1 atatat CTL_VFS, CTL_EOL);
235 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
236 1.24 atatat CTLFLAG_PERMANENT,
237 1.26 atatat CTLTYPE_NODE, "net",
238 1.26 atatat SYSCTL_DESCR("Networking"),
239 1.1 atatat NULL, 0, NULL, 0,
240 1.1 atatat CTL_NET, CTL_EOL);
241 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
242 1.24 atatat CTLFLAG_PERMANENT,
243 1.26 atatat CTLTYPE_NODE, "debug",
244 1.26 atatat SYSCTL_DESCR("Debugging"),
245 1.1 atatat NULL, 0, NULL, 0,
246 1.1 atatat CTL_DEBUG, CTL_EOL);
247 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
248 1.24 atatat CTLFLAG_PERMANENT,
249 1.26 atatat CTLTYPE_NODE, "hw",
250 1.26 atatat SYSCTL_DESCR("Generic CPU, I/O"),
251 1.1 atatat NULL, 0, NULL, 0,
252 1.1 atatat CTL_HW, CTL_EOL);
253 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
254 1.24 atatat CTLFLAG_PERMANENT,
255 1.26 atatat CTLTYPE_NODE, "machdep",
256 1.26 atatat SYSCTL_DESCR("Machine dependent"),
257 1.1 atatat NULL, 0, NULL, 0,
258 1.1 atatat CTL_MACHDEP, CTL_EOL);
259 1.1 atatat /*
260 1.1 atatat * this node is inserted so that the sysctl nodes in libc can
261 1.1 atatat * operate.
262 1.1 atatat */
263 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
264 1.24 atatat CTLFLAG_PERMANENT,
265 1.26 atatat CTLTYPE_NODE, "user",
266 1.26 atatat SYSCTL_DESCR("User-level"),
267 1.1 atatat NULL, 0, NULL, 0,
268 1.1 atatat CTL_USER, CTL_EOL);
269 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
270 1.24 atatat CTLFLAG_PERMANENT,
271 1.26 atatat CTLTYPE_NODE, "ddb",
272 1.26 atatat SYSCTL_DESCR("In-kernel debugger"),
273 1.1 atatat NULL, 0, NULL, 0,
274 1.1 atatat CTL_DDB, CTL_EOL);
275 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
276 1.24 atatat CTLFLAG_PERMANENT,
277 1.26 atatat CTLTYPE_NODE, "proc",
278 1.26 atatat SYSCTL_DESCR("Per-process"),
279 1.1 atatat NULL, 0, NULL, 0,
280 1.1 atatat CTL_PROC, CTL_EOL);
281 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
282 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
283 1.26 atatat CTLTYPE_NODE, "vendor",
284 1.26 atatat SYSCTL_DESCR("Vendor specific"),
285 1.1 atatat NULL, 0, NULL, 0,
286 1.1 atatat CTL_VENDOR, CTL_EOL);
287 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
288 1.24 atatat CTLFLAG_PERMANENT,
289 1.26 atatat CTLTYPE_NODE, "emul",
290 1.26 atatat SYSCTL_DESCR("Emulation settings"),
291 1.1 atatat NULL, 0, NULL, 0,
292 1.1 atatat CTL_EMUL, CTL_EOL);
293 1.54 elad sysctl_createv(clog, 0, NULL, NULL,
294 1.54 elad CTLFLAG_PERMANENT,
295 1.54 elad CTLTYPE_NODE, "security",
296 1.54 elad SYSCTL_DESCR("Security"),
297 1.54 elad NULL, 0, NULL, 0,
298 1.54 elad CTL_SECURITY, CTL_EOL);
299 1.1 atatat }
300 1.1 atatat
301 1.1 atatat /*
302 1.1 atatat * this setup routine is a replacement for kern_sysctl()
303 1.1 atatat */
304 1.1 atatat SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
305 1.1 atatat {
306 1.1 atatat extern int kern_logsigexit; /* defined in kern/kern_sig.c */
307 1.1 atatat extern fixpt_t ccpu; /* defined in kern/kern_synch.c */
308 1.1 atatat extern int dumponpanic; /* defined in kern/subr_prf.c */
309 1.75 elad const struct sysctlnode *rnode;
310 1.1 atatat
311 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
312 1.24 atatat CTLFLAG_PERMANENT,
313 1.1 atatat CTLTYPE_NODE, "kern", NULL,
314 1.1 atatat NULL, 0, NULL, 0,
315 1.1 atatat CTL_KERN, CTL_EOL);
316 1.1 atatat
317 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
318 1.24 atatat CTLFLAG_PERMANENT,
319 1.26 atatat CTLTYPE_STRING, "ostype",
320 1.26 atatat SYSCTL_DESCR("Operating system type"),
321 1.1 atatat NULL, 0, &ostype, 0,
322 1.1 atatat CTL_KERN, KERN_OSTYPE, CTL_EOL);
323 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
324 1.24 atatat CTLFLAG_PERMANENT,
325 1.26 atatat CTLTYPE_STRING, "osrelease",
326 1.26 atatat SYSCTL_DESCR("Operating system release"),
327 1.1 atatat NULL, 0, &osrelease, 0,
328 1.1 atatat CTL_KERN, KERN_OSRELEASE, CTL_EOL);
329 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
330 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
331 1.26 atatat CTLTYPE_INT, "osrevision",
332 1.26 atatat SYSCTL_DESCR("Operating system revision"),
333 1.1 atatat NULL, __NetBSD_Version__, NULL, 0,
334 1.1 atatat CTL_KERN, KERN_OSREV, CTL_EOL);
335 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
336 1.24 atatat CTLFLAG_PERMANENT,
337 1.26 atatat CTLTYPE_STRING, "version",
338 1.26 atatat SYSCTL_DESCR("Kernel version"),
339 1.1 atatat NULL, 0, &version, 0,
340 1.1 atatat CTL_KERN, KERN_VERSION, CTL_EOL);
341 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
342 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
343 1.26 atatat CTLTYPE_INT, "maxvnodes",
344 1.26 atatat SYSCTL_DESCR("Maximum number of vnodes"),
345 1.1 atatat sysctl_kern_maxvnodes, 0, NULL, 0,
346 1.1 atatat CTL_KERN, KERN_MAXVNODES, CTL_EOL);
347 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
348 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
349 1.26 atatat CTLTYPE_INT, "maxproc",
350 1.26 atatat SYSCTL_DESCR("Maximum number of simultaneous processes"),
351 1.1 atatat sysctl_kern_maxproc, 0, NULL, 0,
352 1.1 atatat CTL_KERN, KERN_MAXPROC, CTL_EOL);
353 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
354 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
355 1.26 atatat CTLTYPE_INT, "maxfiles",
356 1.26 atatat SYSCTL_DESCR("Maximum number of open files"),
357 1.1 atatat NULL, 0, &maxfiles, 0,
358 1.1 atatat CTL_KERN, KERN_MAXFILES, 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, "argmax",
362 1.26 atatat SYSCTL_DESCR("Maximum number of bytes of arguments to "
363 1.26 atatat "execve(2)"),
364 1.1 atatat NULL, ARG_MAX, NULL, 0,
365 1.1 atatat CTL_KERN, KERN_ARGMAX, CTL_EOL);
366 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
367 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
368 1.26 atatat CTLTYPE_STRING, "hostname",
369 1.26 atatat SYSCTL_DESCR("System hostname"),
370 1.17 atatat sysctl_setlen, 0, &hostname, MAXHOSTNAMELEN,
371 1.1 atatat CTL_KERN, KERN_HOSTNAME, CTL_EOL);
372 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
373 1.27 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
374 1.26 atatat CTLTYPE_INT, "hostid",
375 1.26 atatat SYSCTL_DESCR("System host ID number"),
376 1.1 atatat sysctl_kern_hostid, 0, NULL, 0,
377 1.1 atatat CTL_KERN, KERN_HOSTID, CTL_EOL);
378 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
379 1.24 atatat CTLFLAG_PERMANENT,
380 1.26 atatat CTLTYPE_STRUCT, "clockrate",
381 1.26 atatat SYSCTL_DESCR("Kernel clock rates"),
382 1.1 atatat sysctl_kern_clockrate, 0, NULL,
383 1.1 atatat sizeof(struct clockinfo),
384 1.1 atatat CTL_KERN, KERN_CLOCKRATE, CTL_EOL);
385 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
386 1.24 atatat CTLFLAG_PERMANENT,
387 1.53 rpaulo CTLTYPE_INT, "hardclock_ticks",
388 1.53 rpaulo SYSCTL_DESCR("Number of hardclock ticks"),
389 1.53 rpaulo NULL, 0, &hardclock_ticks, sizeof(hardclock_ticks),
390 1.53 rpaulo CTL_KERN, KERN_HARDCLOCK_TICKS, CTL_EOL);
391 1.53 rpaulo sysctl_createv(clog, 0, NULL, NULL,
392 1.53 rpaulo CTLFLAG_PERMANENT,
393 1.26 atatat CTLTYPE_STRUCT, "vnode",
394 1.26 atatat SYSCTL_DESCR("System vnode table"),
395 1.1 atatat sysctl_kern_vnode, 0, NULL, 0,
396 1.1 atatat CTL_KERN, KERN_VNODE, CTL_EOL);
397 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
398 1.24 atatat CTLFLAG_PERMANENT,
399 1.26 atatat CTLTYPE_STRUCT, "file",
400 1.26 atatat SYSCTL_DESCR("System open file table"),
401 1.1 atatat sysctl_kern_file, 0, NULL, 0,
402 1.1 atatat CTL_KERN, KERN_FILE, CTL_EOL);
403 1.1 atatat #ifndef GPROF
404 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
405 1.24 atatat CTLFLAG_PERMANENT,
406 1.26 atatat CTLTYPE_NODE, "profiling",
407 1.26 atatat SYSCTL_DESCR("Profiling information (not available)"),
408 1.1 atatat sysctl_notavail, 0, NULL, 0,
409 1.1 atatat CTL_KERN, KERN_PROF, CTL_EOL);
410 1.1 atatat #endif
411 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
412 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
413 1.26 atatat CTLTYPE_INT, "posix1version",
414 1.26 atatat SYSCTL_DESCR("Version of ISO/IEC 9945 (POSIX 1003.1) "
415 1.26 atatat "with which the operating system attempts "
416 1.26 atatat "to comply"),
417 1.1 atatat NULL, _POSIX_VERSION, NULL, 0,
418 1.1 atatat CTL_KERN, KERN_POSIX1, CTL_EOL);
419 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
420 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
421 1.26 atatat CTLTYPE_INT, "ngroups",
422 1.26 atatat SYSCTL_DESCR("Maximum number of supplemental groups"),
423 1.1 atatat NULL, NGROUPS_MAX, NULL, 0,
424 1.1 atatat CTL_KERN, KERN_NGROUPS, CTL_EOL);
425 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
426 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
427 1.26 atatat CTLTYPE_INT, "job_control",
428 1.26 atatat SYSCTL_DESCR("Whether job control is available"),
429 1.1 atatat NULL, 1, NULL, 0,
430 1.1 atatat CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
431 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
432 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
433 1.26 atatat CTLTYPE_INT, "saved_ids",
434 1.37 mrg SYSCTL_DESCR("Whether POSIX saved set-group/user ID is "
435 1.26 atatat "available"), NULL,
436 1.1 atatat #ifdef _POSIX_SAVED_IDS
437 1.1 atatat 1,
438 1.1 atatat #else /* _POSIX_SAVED_IDS */
439 1.1 atatat 0,
440 1.1 atatat #endif /* _POSIX_SAVED_IDS */
441 1.1 atatat NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
442 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
443 1.24 atatat CTLFLAG_PERMANENT,
444 1.26 atatat CTLTYPE_STRUCT, "boottime",
445 1.26 atatat SYSCTL_DESCR("System boot time"),
446 1.1 atatat NULL, 0, &boottime, sizeof(boottime),
447 1.1 atatat CTL_KERN, KERN_BOOTTIME, CTL_EOL);
448 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
449 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
450 1.26 atatat CTLTYPE_STRING, "domainname",
451 1.26 atatat SYSCTL_DESCR("YP domain name"),
452 1.17 atatat sysctl_setlen, 0, &domainname, MAXHOSTNAMELEN,
453 1.1 atatat CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
454 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
455 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
456 1.26 atatat CTLTYPE_INT, "maxpartitions",
457 1.26 atatat SYSCTL_DESCR("Maximum number of partitions allowed per "
458 1.26 atatat "disk"),
459 1.1 atatat NULL, MAXPARTITIONS, NULL, 0,
460 1.1 atatat CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
461 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
462 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
463 1.26 atatat CTLTYPE_INT, "rawpartition",
464 1.26 atatat SYSCTL_DESCR("Raw partition of a disk"),
465 1.1 atatat NULL, RAW_PART, NULL, 0,
466 1.1 atatat CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
467 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
468 1.24 atatat CTLFLAG_PERMANENT,
469 1.1 atatat CTLTYPE_STRUCT, "timex", NULL,
470 1.1 atatat sysctl_notavail, 0, NULL, 0,
471 1.1 atatat CTL_KERN, KERN_TIMEX, CTL_EOL);
472 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
473 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
474 1.26 atatat CTLTYPE_INT, "rtc_offset",
475 1.26 atatat SYSCTL_DESCR("Offset of real time clock from UTC in "
476 1.26 atatat "minutes"),
477 1.14 martin sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
478 1.1 atatat CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
479 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
480 1.24 atatat CTLFLAG_PERMANENT,
481 1.26 atatat CTLTYPE_STRING, "root_device",
482 1.26 atatat SYSCTL_DESCR("Name of the root device"),
483 1.1 atatat sysctl_root_device, 0, NULL, 0,
484 1.1 atatat CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
485 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
486 1.24 atatat CTLFLAG_PERMANENT,
487 1.26 atatat CTLTYPE_INT, "msgbufsize",
488 1.26 atatat SYSCTL_DESCR("Size of the kernel message buffer"),
489 1.31 atatat sysctl_msgbuf, 0, NULL, 0,
490 1.1 atatat CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
491 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
492 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
493 1.26 atatat CTLTYPE_INT, "fsync",
494 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b File "
495 1.26 atatat "Synchronization Option is available on "
496 1.26 atatat "this system"),
497 1.1 atatat NULL, 1, NULL, 0,
498 1.1 atatat CTL_KERN, KERN_FSYNC, CTL_EOL);
499 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
500 1.92 christos CTLFLAG_PERMANENT,
501 1.92 christos CTLTYPE_NODE, "ipc",
502 1.92 christos SYSCTL_DESCR("SysV IPC options"),
503 1.92 christos NULL, 0, NULL, 0,
504 1.92 christos CTL_KERN, KERN_SYSVIPC, CTL_EOL);
505 1.92 christos sysctl_createv(clog, 0, NULL, NULL,
506 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
507 1.26 atatat CTLTYPE_INT, "sysvmsg",
508 1.26 atatat SYSCTL_DESCR("System V style message support available"),
509 1.26 atatat NULL,
510 1.1 atatat #ifdef SYSVMSG
511 1.1 atatat 1,
512 1.1 atatat #else /* SYSVMSG */
513 1.1 atatat 0,
514 1.1 atatat #endif /* SYSVMSG */
515 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, 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, "sysvsem",
519 1.26 atatat SYSCTL_DESCR("System V style semaphore support "
520 1.26 atatat "available"), NULL,
521 1.1 atatat #ifdef SYSVSEM
522 1.1 atatat 1,
523 1.1 atatat #else /* SYSVSEM */
524 1.1 atatat 0,
525 1.1 atatat #endif /* SYSVSEM */
526 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
527 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
528 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
529 1.26 atatat CTLTYPE_INT, "sysvshm",
530 1.26 atatat SYSCTL_DESCR("System V style shared memory support "
531 1.26 atatat "available"), NULL,
532 1.1 atatat #ifdef SYSVSHM
533 1.1 atatat 1,
534 1.1 atatat #else /* SYSVSHM */
535 1.1 atatat 0,
536 1.1 atatat #endif /* SYSVSHM */
537 1.92 christos NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
538 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
539 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
540 1.26 atatat CTLTYPE_INT, "synchronized_io",
541 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Synchronized "
542 1.26 atatat "I/O Option is available on this system"),
543 1.1 atatat NULL, 1, NULL, 0,
544 1.1 atatat CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
545 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
546 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
547 1.26 atatat CTLTYPE_INT, "iov_max",
548 1.26 atatat SYSCTL_DESCR("Maximum number of iovec structures per "
549 1.26 atatat "process"),
550 1.1 atatat NULL, IOV_MAX, NULL, 0,
551 1.1 atatat CTL_KERN, KERN_IOV_MAX, CTL_EOL);
552 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
553 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
554 1.26 atatat CTLTYPE_INT, "mapped_files",
555 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Memory Mapped "
556 1.26 atatat "Files Option is available on this system"),
557 1.1 atatat NULL, 1, NULL, 0,
558 1.1 atatat CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
559 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
560 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
561 1.26 atatat CTLTYPE_INT, "memlock",
562 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Process Memory "
563 1.26 atatat "Locking Option is available on this "
564 1.26 atatat "system"),
565 1.1 atatat NULL, 1, NULL, 0,
566 1.1 atatat CTL_KERN, KERN_MEMLOCK, CTL_EOL);
567 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
568 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
569 1.26 atatat CTLTYPE_INT, "memlock_range",
570 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Range Memory "
571 1.26 atatat "Locking Option is available on this "
572 1.26 atatat "system"),
573 1.1 atatat NULL, 1, NULL, 0,
574 1.1 atatat CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
575 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
576 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
577 1.26 atatat CTLTYPE_INT, "memory_protection",
578 1.26 atatat SYSCTL_DESCR("Whether the POSIX 1003.1b Memory "
579 1.26 atatat "Protection Option is available on this "
580 1.26 atatat "system"),
581 1.1 atatat NULL, 1, NULL, 0,
582 1.1 atatat CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
583 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
584 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
585 1.26 atatat CTLTYPE_INT, "login_name_max",
586 1.26 atatat SYSCTL_DESCR("Maximum login name length"),
587 1.1 atatat NULL, LOGIN_NAME_MAX, NULL, 0,
588 1.1 atatat CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
589 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
590 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
591 1.26 atatat CTLTYPE_STRING, "defcorename",
592 1.26 atatat SYSCTL_DESCR("Default core file name"),
593 1.1 atatat sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
594 1.1 atatat CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
595 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
596 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
597 1.26 atatat CTLTYPE_INT, "logsigexit",
598 1.26 atatat SYSCTL_DESCR("Log process exit when caused by signals"),
599 1.1 atatat NULL, 0, &kern_logsigexit, 0,
600 1.1 atatat CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
601 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
602 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
603 1.26 atatat CTLTYPE_INT, "fscale",
604 1.26 atatat SYSCTL_DESCR("Kernel fixed-point scale factor"),
605 1.1 atatat NULL, FSCALE, NULL, 0,
606 1.1 atatat CTL_KERN, KERN_FSCALE, CTL_EOL);
607 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
608 1.24 atatat CTLFLAG_PERMANENT,
609 1.26 atatat CTLTYPE_INT, "ccpu",
610 1.26 atatat SYSCTL_DESCR("Scheduler exponential decay value"),
611 1.1 atatat NULL, 0, &ccpu, 0,
612 1.1 atatat CTL_KERN, KERN_CCPU, CTL_EOL);
613 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
614 1.24 atatat CTLFLAG_PERMANENT,
615 1.26 atatat CTLTYPE_STRUCT, "cp_time",
616 1.26 atatat SYSCTL_DESCR("Clock ticks spent in different CPU states"),
617 1.1 atatat sysctl_kern_cptime, 0, NULL, 0,
618 1.1 atatat CTL_KERN, KERN_CP_TIME, CTL_EOL);
619 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
620 1.24 atatat CTLFLAG_PERMANENT,
621 1.26 atatat CTLTYPE_INT, "msgbuf",
622 1.26 atatat SYSCTL_DESCR("Kernel message buffer"),
623 1.1 atatat sysctl_msgbuf, 0, NULL, 0,
624 1.1 atatat CTL_KERN, KERN_MSGBUF, CTL_EOL);
625 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
626 1.24 atatat CTLFLAG_PERMANENT,
627 1.26 atatat CTLTYPE_STRUCT, "consdev",
628 1.26 atatat SYSCTL_DESCR("Console device"),
629 1.1 atatat sysctl_consdev, 0, NULL, sizeof(dev_t),
630 1.1 atatat CTL_KERN, KERN_CONSDEV, CTL_EOL);
631 1.1 atatat #if NPTY > 0
632 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
633 1.24 atatat CTLFLAG_PERMANENT,
634 1.26 atatat CTLTYPE_INT, "maxptys",
635 1.26 atatat SYSCTL_DESCR("Maximum number of pseudo-ttys"),
636 1.1 atatat sysctl_kern_maxptys, 0, NULL, 0,
637 1.1 atatat CTL_KERN, KERN_MAXPTYS, CTL_EOL);
638 1.1 atatat #endif /* NPTY > 0 */
639 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
640 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
641 1.26 atatat CTLTYPE_INT, "maxphys",
642 1.26 atatat SYSCTL_DESCR("Maximum raw I/O transfer size"),
643 1.1 atatat NULL, MAXPHYS, NULL, 0,
644 1.1 atatat CTL_KERN, KERN_MAXPHYS, CTL_EOL);
645 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
646 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
647 1.26 atatat CTLTYPE_INT, "sbmax",
648 1.26 atatat SYSCTL_DESCR("Maximum socket buffer size"),
649 1.1 atatat sysctl_kern_sbmax, 0, NULL, 0,
650 1.1 atatat CTL_KERN, KERN_SBMAX, CTL_EOL);
651 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
652 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
653 1.26 atatat CTLTYPE_INT, "monotonic_clock",
654 1.26 atatat SYSCTL_DESCR("Implementation version of the POSIX "
655 1.26 atatat "1003.1b Monotonic Clock Option"),
656 1.1 atatat /* XXX _POSIX_VERSION */
657 1.1 atatat NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
658 1.1 atatat CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
659 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
660 1.24 atatat CTLFLAG_PERMANENT,
661 1.26 atatat CTLTYPE_INT, "urandom",
662 1.26 atatat SYSCTL_DESCR("Random integer value"),
663 1.1 atatat sysctl_kern_urnd, 0, NULL, 0,
664 1.1 atatat CTL_KERN, KERN_URND, CTL_EOL);
665 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
666 1.91 christos CTLFLAG_PERMANENT,
667 1.91 christos CTLTYPE_INT, "arandom",
668 1.91 christos SYSCTL_DESCR("n bytes of random data"),
669 1.91 christos sysctl_kern_arnd, 0, NULL, 0,
670 1.91 christos CTL_KERN, KERN_ARND, CTL_EOL);
671 1.91 christos sysctl_createv(clog, 0, NULL, NULL,
672 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
673 1.26 atatat CTLTYPE_INT, "labelsector",
674 1.26 atatat SYSCTL_DESCR("Sector number containing the disklabel"),
675 1.1 atatat NULL, LABELSECTOR, NULL, 0,
676 1.1 atatat CTL_KERN, KERN_LABELSECTOR, 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, "labeloffset",
680 1.26 atatat SYSCTL_DESCR("Offset of the disklabel within the "
681 1.26 atatat "sector"),
682 1.1 atatat NULL, LABELOFFSET, NULL, 0,
683 1.1 atatat CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
684 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
685 1.24 atatat CTLFLAG_PERMANENT,
686 1.26 atatat CTLTYPE_NODE, "lwp",
687 1.26 atatat SYSCTL_DESCR("System-wide LWP information"),
688 1.1 atatat sysctl_kern_lwp, 0, NULL, 0,
689 1.1 atatat CTL_KERN, KERN_LWP, CTL_EOL);
690 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
691 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
692 1.26 atatat CTLTYPE_INT, "forkfsleep",
693 1.26 atatat SYSCTL_DESCR("Milliseconds to sleep on fork failure due "
694 1.26 atatat "to process limits"),
695 1.1 atatat sysctl_kern_forkfsleep, 0, NULL, 0,
696 1.1 atatat CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
697 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
698 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
699 1.26 atatat CTLTYPE_INT, "posix_threads",
700 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
701 1.26 atatat "Threads option to which the system "
702 1.26 atatat "attempts to conform"),
703 1.1 atatat /* XXX _POSIX_VERSION */
704 1.1 atatat NULL, _POSIX_THREADS, NULL, 0,
705 1.1 atatat CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
706 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
707 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
708 1.26 atatat CTLTYPE_INT, "posix_semaphores",
709 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
710 1.26 atatat "Semaphores option to which the system "
711 1.26 atatat "attempts to conform"), NULL,
712 1.1 atatat #ifdef P1003_1B_SEMAPHORE
713 1.1 atatat 200112,
714 1.1 atatat #else /* P1003_1B_SEMAPHORE */
715 1.1 atatat 0,
716 1.1 atatat #endif /* P1003_1B_SEMAPHORE */
717 1.1 atatat NULL, 0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
718 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
719 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
720 1.26 atatat CTLTYPE_INT, "posix_barriers",
721 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
722 1.26 atatat "Barriers option to which the system "
723 1.26 atatat "attempts to conform"),
724 1.1 atatat /* XXX _POSIX_VERSION */
725 1.1 atatat NULL, _POSIX_BARRIERS, NULL, 0,
726 1.1 atatat CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
727 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
728 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
729 1.26 atatat CTLTYPE_INT, "posix_timers",
730 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
731 1.26 atatat "Timers option to which the system "
732 1.26 atatat "attempts to conform"),
733 1.1 atatat /* XXX _POSIX_VERSION */
734 1.1 atatat NULL, _POSIX_TIMERS, NULL, 0,
735 1.1 atatat CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
736 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
737 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
738 1.26 atatat CTLTYPE_INT, "posix_spin_locks",
739 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
740 1.26 atatat "Locks option to which the system attempts "
741 1.26 atatat "to conform"),
742 1.1 atatat /* XXX _POSIX_VERSION */
743 1.1 atatat NULL, _POSIX_SPIN_LOCKS, NULL, 0,
744 1.1 atatat CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
745 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
746 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
747 1.26 atatat CTLTYPE_INT, "posix_reader_writer_locks",
748 1.26 atatat SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
749 1.26 atatat "Read-Write Locks option to which the "
750 1.26 atatat "system attempts to conform"),
751 1.1 atatat /* XXX _POSIX_VERSION */
752 1.1 atatat NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
753 1.1 atatat CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
754 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
755 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
756 1.26 atatat CTLTYPE_INT, "dump_on_panic",
757 1.26 atatat SYSCTL_DESCR("Perform a crash dump on system panic"),
758 1.1 atatat NULL, 0, &dumponpanic, 0,
759 1.1 atatat CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
760 1.64 erh #ifdef DIAGNOSTIC
761 1.64 erh sysctl_createv(clog, 0, NULL, NULL,
762 1.64 erh CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
763 1.64 erh CTLTYPE_INT, "panic_now",
764 1.64 erh SYSCTL_DESCR("Trigger a panic"),
765 1.64 erh sysctl_kern_trigger_panic, 0, NULL, 0,
766 1.64 erh CTL_KERN, CTL_CREATE, CTL_EOL);
767 1.64 erh #endif
768 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
769 1.24 atatat CTLFLAG_PERMANENT,
770 1.26 atatat CTLTYPE_INT, "root_partition",
771 1.26 atatat SYSCTL_DESCR("Root partition on the root device"),
772 1.1 atatat sysctl_kern_root_partition, 0, NULL, 0,
773 1.1 atatat CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
774 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
775 1.24 atatat CTLFLAG_PERMANENT,
776 1.26 atatat CTLTYPE_STRUCT, "drivers",
777 1.26 atatat SYSCTL_DESCR("List of all drivers with block and "
778 1.26 atatat "character device numbers"),
779 1.1 atatat sysctl_kern_drivers, 0, NULL, 0,
780 1.1 atatat CTL_KERN, KERN_DRIVERS, CTL_EOL);
781 1.34 atatat sysctl_createv(clog, 0, NULL, NULL,
782 1.34 atatat CTLFLAG_PERMANENT,
783 1.36 atatat CTLTYPE_STRUCT, "file2",
784 1.34 atatat SYSCTL_DESCR("System open file table"),
785 1.34 atatat sysctl_kern_file2, 0, NULL, 0,
786 1.34 atatat CTL_KERN, KERN_FILE2, CTL_EOL);
787 1.45 christos sysctl_createv(clog, 0, NULL, NULL,
788 1.45 christos CTLFLAG_PERMANENT,
789 1.45 christos CTLTYPE_STRUCT, "cp_id",
790 1.45 christos SYSCTL_DESCR("Mapping of CPU number to CPU id"),
791 1.45 christos sysctl_kern_cpid, 0, NULL, 0,
792 1.45 christos CTL_KERN, KERN_CP_ID, CTL_EOL);
793 1.75 elad sysctl_createv(clog, 0, NULL, &rnode,
794 1.75 elad CTLFLAG_PERMANENT,
795 1.75 elad CTLTYPE_NODE, "coredump",
796 1.75 elad SYSCTL_DESCR("Coredump settings."),
797 1.75 elad NULL, 0, NULL, 0,
798 1.75 elad CTL_KERN, CTL_CREATE, CTL_EOL);
799 1.75 elad sysctl_createv(clog, 0, &rnode, &rnode,
800 1.75 elad CTLFLAG_PERMANENT,
801 1.75 elad CTLTYPE_NODE, "setid",
802 1.75 elad SYSCTL_DESCR("Set-id processes' coredump settings."),
803 1.75 elad NULL, 0, NULL, 0,
804 1.75 elad CTL_CREATE, CTL_EOL);
805 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
806 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
807 1.75 elad CTLTYPE_INT, "dump",
808 1.75 elad SYSCTL_DESCR("Allow set-id processes to dump core."),
809 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_dump,
810 1.75 elad sizeof(security_setidcore_dump),
811 1.75 elad CTL_CREATE, CTL_EOL);
812 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
813 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
814 1.75 elad CTLTYPE_STRING, "path",
815 1.75 elad SYSCTL_DESCR("Path pattern for set-id coredumps."),
816 1.75 elad sysctl_security_setidcorename, 0,
817 1.75 elad &security_setidcore_path,
818 1.75 elad sizeof(security_setidcore_path),
819 1.75 elad CTL_CREATE, CTL_EOL);
820 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
821 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
822 1.75 elad CTLTYPE_INT, "owner",
823 1.75 elad SYSCTL_DESCR("Owner id for set-id processes' cores."),
824 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_owner,
825 1.75 elad 0,
826 1.75 elad CTL_CREATE, CTL_EOL);
827 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
828 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
829 1.75 elad CTLTYPE_INT, "group",
830 1.75 elad SYSCTL_DESCR("Group id for set-id processes' cores."),
831 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_group,
832 1.75 elad 0,
833 1.75 elad CTL_CREATE, CTL_EOL);
834 1.75 elad sysctl_createv(clog, 0, &rnode, NULL,
835 1.75 elad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
836 1.75 elad CTLTYPE_INT, "mode",
837 1.75 elad SYSCTL_DESCR("Mode for set-id processes' cores."),
838 1.75 elad sysctl_security_setidcore, 0, &security_setidcore_mode,
839 1.75 elad 0,
840 1.75 elad CTL_CREATE, CTL_EOL);
841 1.105.2.1 matt sysctl_createv(clog, 0, NULL, NULL,
842 1.105.2.1 matt CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
843 1.105.2.1 matt CTLTYPE_INT, "no_sa_support",
844 1.105.2.1 matt SYSCTL_DESCR("0 if the kernel supports SA, otherwise it doesn't"),
845 1.105.2.1 matt NULL, 1, NULL, 0,
846 1.105.2.1 matt CTL_KERN, CTL_CREATE, CTL_EOL);
847 1.1 atatat }
848 1.1 atatat
849 1.1 atatat SYSCTL_SETUP(sysctl_kern_proc_setup,
850 1.1 atatat "sysctl kern.proc/proc2/proc_args subtree setup")
851 1.1 atatat {
852 1.1 atatat
853 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
854 1.24 atatat CTLFLAG_PERMANENT,
855 1.1 atatat CTLTYPE_NODE, "kern", NULL,
856 1.1 atatat NULL, 0, NULL, 0,
857 1.1 atatat CTL_KERN, CTL_EOL);
858 1.1 atatat
859 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
860 1.24 atatat CTLFLAG_PERMANENT,
861 1.26 atatat CTLTYPE_NODE, "proc",
862 1.26 atatat SYSCTL_DESCR("System-wide process information"),
863 1.1 atatat sysctl_doeproc, 0, NULL, 0,
864 1.1 atatat CTL_KERN, KERN_PROC, CTL_EOL);
865 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
866 1.24 atatat CTLFLAG_PERMANENT,
867 1.26 atatat CTLTYPE_NODE, "proc2",
868 1.26 atatat SYSCTL_DESCR("Machine-independent process information"),
869 1.1 atatat sysctl_doeproc, 0, NULL, 0,
870 1.1 atatat CTL_KERN, KERN_PROC2, CTL_EOL);
871 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
872 1.24 atatat CTLFLAG_PERMANENT,
873 1.26 atatat CTLTYPE_NODE, "proc_args",
874 1.26 atatat SYSCTL_DESCR("Process argument information"),
875 1.1 atatat sysctl_kern_proc_args, 0, NULL, 0,
876 1.1 atatat CTL_KERN, KERN_PROC_ARGS, CTL_EOL);
877 1.1 atatat
878 1.1 atatat /*
879 1.1 atatat "nodes" under these:
880 1.1 atatat
881 1.1 atatat KERN_PROC_ALL
882 1.1 atatat KERN_PROC_PID pid
883 1.1 atatat KERN_PROC_PGRP pgrp
884 1.1 atatat KERN_PROC_SESSION sess
885 1.1 atatat KERN_PROC_TTY tty
886 1.1 atatat KERN_PROC_UID uid
887 1.1 atatat KERN_PROC_RUID uid
888 1.1 atatat KERN_PROC_GID gid
889 1.1 atatat KERN_PROC_RGID gid
890 1.1 atatat
891 1.1 atatat all in all, probably not worth the effort...
892 1.1 atatat */
893 1.1 atatat }
894 1.1 atatat
895 1.1 atatat SYSCTL_SETUP(sysctl_hw_setup, "sysctl hw subtree setup")
896 1.1 atatat {
897 1.1 atatat u_int u;
898 1.1 atatat u_quad_t q;
899 1.1 atatat
900 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
901 1.24 atatat CTLFLAG_PERMANENT,
902 1.1 atatat CTLTYPE_NODE, "hw", NULL,
903 1.1 atatat NULL, 0, NULL, 0,
904 1.1 atatat CTL_HW, CTL_EOL);
905 1.1 atatat
906 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
907 1.24 atatat CTLFLAG_PERMANENT,
908 1.26 atatat CTLTYPE_STRING, "machine",
909 1.26 atatat SYSCTL_DESCR("Machine class"),
910 1.1 atatat NULL, 0, machine, 0,
911 1.1 atatat CTL_HW, HW_MACHINE, CTL_EOL);
912 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
913 1.24 atatat CTLFLAG_PERMANENT,
914 1.26 atatat CTLTYPE_STRING, "model",
915 1.26 atatat SYSCTL_DESCR("Machine model"),
916 1.1 atatat NULL, 0, cpu_model, 0,
917 1.1 atatat CTL_HW, HW_MODEL, CTL_EOL);
918 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
919 1.24 atatat CTLFLAG_PERMANENT,
920 1.26 atatat CTLTYPE_INT, "ncpu",
921 1.105.2.1 matt SYSCTL_DESCR("Number of CPUs configured"),
922 1.105.2.1 matt NULL, 0, &ncpu, 0,
923 1.1 atatat CTL_HW, HW_NCPU, CTL_EOL);
924 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
925 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
926 1.26 atatat CTLTYPE_INT, "byteorder",
927 1.26 atatat SYSCTL_DESCR("System byte order"),
928 1.1 atatat NULL, BYTE_ORDER, NULL, 0,
929 1.1 atatat CTL_HW, HW_BYTEORDER, CTL_EOL);
930 1.1 atatat u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
931 1.1 atatat UINT_MAX : physmem * PAGE_SIZE;
932 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
933 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
934 1.26 atatat CTLTYPE_INT, "physmem",
935 1.26 atatat SYSCTL_DESCR("Bytes of physical memory"),
936 1.1 atatat NULL, u, NULL, 0,
937 1.1 atatat CTL_HW, HW_PHYSMEM, CTL_EOL);
938 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
939 1.24 atatat CTLFLAG_PERMANENT,
940 1.26 atatat CTLTYPE_INT, "usermem",
941 1.26 atatat SYSCTL_DESCR("Bytes of non-kernel memory"),
942 1.1 atatat sysctl_hw_usermem, 0, NULL, 0,
943 1.1 atatat CTL_HW, HW_USERMEM, CTL_EOL);
944 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
945 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
946 1.26 atatat CTLTYPE_INT, "pagesize",
947 1.26 atatat SYSCTL_DESCR("Software page size"),
948 1.1 atatat NULL, PAGE_SIZE, NULL, 0,
949 1.1 atatat CTL_HW, HW_PAGESIZE, CTL_EOL);
950 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
951 1.24 atatat CTLFLAG_PERMANENT,
952 1.26 atatat CTLTYPE_STRING, "machine_arch",
953 1.26 atatat SYSCTL_DESCR("Machine CPU class"),
954 1.1 atatat NULL, 0, machine_arch, 0,
955 1.1 atatat CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
956 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
957 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
958 1.26 atatat CTLTYPE_INT, "alignbytes",
959 1.26 atatat SYSCTL_DESCR("Alignment constraint for all possible "
960 1.26 atatat "data types"),
961 1.1 atatat NULL, ALIGNBYTES, NULL, 0,
962 1.1 atatat CTL_HW, HW_ALIGNBYTES, CTL_EOL);
963 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
964 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
965 1.26 atatat CTLTYPE_STRING, "cnmagic",
966 1.26 atatat SYSCTL_DESCR("Console magic key sequence"),
967 1.1 atatat sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
968 1.1 atatat CTL_HW, HW_CNMAGIC, CTL_EOL);
969 1.1 atatat q = (u_quad_t)physmem * PAGE_SIZE;
970 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
971 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
972 1.26 atatat CTLTYPE_QUAD, "physmem64",
973 1.26 atatat SYSCTL_DESCR("Bytes of physical memory"),
974 1.1 atatat NULL, q, NULL, 0,
975 1.1 atatat CTL_HW, HW_PHYSMEM64, CTL_EOL);
976 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
977 1.24 atatat CTLFLAG_PERMANENT,
978 1.26 atatat CTLTYPE_QUAD, "usermem64",
979 1.26 atatat SYSCTL_DESCR("Bytes of non-kernel memory"),
980 1.1 atatat sysctl_hw_usermem, 0, NULL, 0,
981 1.1 atatat CTL_HW, HW_USERMEM64, CTL_EOL);
982 1.105.2.1 matt sysctl_createv(clog, 0, NULL, NULL,
983 1.105.2.1 matt CTLFLAG_PERMANENT,
984 1.105.2.1 matt CTLTYPE_INT, "ncpuonline",
985 1.105.2.1 matt SYSCTL_DESCR("Number of CPUs online"),
986 1.105.2.1 matt NULL, 0, &ncpuonline, 0,
987 1.105.2.1 matt CTL_HW, HW_NCPUONLINE, CTL_EOL);
988 1.1 atatat }
989 1.1 atatat
990 1.1 atatat #ifdef DEBUG
991 1.1 atatat /*
992 1.1 atatat * Debugging related system variables.
993 1.1 atatat */
994 1.1 atatat struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
995 1.1 atatat struct ctldebug debug5, debug6, debug7, debug8, debug9;
996 1.1 atatat struct ctldebug debug10, debug11, debug12, debug13, debug14;
997 1.1 atatat struct ctldebug debug15, debug16, debug17, debug18, debug19;
998 1.1 atatat static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
999 1.1 atatat &debug0, &debug1, &debug2, &debug3, &debug4,
1000 1.1 atatat &debug5, &debug6, &debug7, &debug8, &debug9,
1001 1.1 atatat &debug10, &debug11, &debug12, &debug13, &debug14,
1002 1.1 atatat &debug15, &debug16, &debug17, &debug18, &debug19,
1003 1.1 atatat };
1004 1.1 atatat
1005 1.1 atatat /*
1006 1.1 atatat * this setup routine is a replacement for debug_sysctl()
1007 1.1 atatat *
1008 1.1 atatat * note that it creates several nodes per defined debug variable
1009 1.1 atatat */
1010 1.1 atatat SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
1011 1.1 atatat {
1012 1.1 atatat struct ctldebug *cdp;
1013 1.1 atatat char nodename[20];
1014 1.1 atatat int i;
1015 1.1 atatat
1016 1.1 atatat /*
1017 1.1 atatat * two ways here:
1018 1.1 atatat *
1019 1.1 atatat * the "old" way (debug.name -> value) which was emulated by
1020 1.1 atatat * the sysctl(8) binary
1021 1.1 atatat *
1022 1.1 atatat * the new way, which the sysctl(8) binary was actually using
1023 1.1 atatat
1024 1.1 atatat node debug
1025 1.1 atatat node debug.0
1026 1.105.2.1 matt string debug.0.name
1027 1.1 atatat int debug.0.value
1028 1.1 atatat int debug.name
1029 1.1 atatat
1030 1.1 atatat */
1031 1.1 atatat
1032 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
1033 1.24 atatat CTLFLAG_PERMANENT,
1034 1.1 atatat CTLTYPE_NODE, "debug", NULL,
1035 1.1 atatat NULL, 0, NULL, 0,
1036 1.1 atatat CTL_DEBUG, CTL_EOL);
1037 1.1 atatat
1038 1.1 atatat for (i = 0; i < CTL_DEBUG_MAXID; i++) {
1039 1.1 atatat cdp = debugvars[i];
1040 1.1 atatat if (cdp->debugname == NULL || cdp->debugvar == NULL)
1041 1.1 atatat continue;
1042 1.1 atatat
1043 1.1 atatat snprintf(nodename, sizeof(nodename), "debug%d", i);
1044 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
1045 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1046 1.1 atatat CTLTYPE_NODE, nodename, NULL,
1047 1.1 atatat NULL, 0, NULL, 0,
1048 1.1 atatat CTL_DEBUG, i, CTL_EOL);
1049 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
1050 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1051 1.1 atatat CTLTYPE_STRING, "name", NULL,
1052 1.40 christos /*XXXUNCONST*/
1053 1.40 christos NULL, 0, __UNCONST(cdp->debugname), 0,
1054 1.1 atatat CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
1055 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
1056 1.24 atatat CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1057 1.1 atatat CTLTYPE_INT, "value", NULL,
1058 1.1 atatat NULL, 0, cdp->debugvar, 0,
1059 1.1 atatat CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
1060 1.24 atatat sysctl_createv(clog, 0, NULL, NULL,
1061 1.24 atatat CTLFLAG_PERMANENT,
1062 1.1 atatat CTLTYPE_INT, cdp->debugname, NULL,
1063 1.1 atatat NULL, 0, cdp->debugvar, 0,
1064 1.1 atatat CTL_DEBUG, CTL_CREATE, CTL_EOL);
1065 1.1 atatat }
1066 1.1 atatat }
1067 1.1 atatat #endif /* DEBUG */
1068 1.1 atatat
1069 1.1 atatat /*
1070 1.1 atatat * ********************************************************************
1071 1.1 atatat * section 2: private node-specific helper routines.
1072 1.1 atatat * ********************************************************************
1073 1.1 atatat */
1074 1.1 atatat
1075 1.64 erh #ifdef DIAGNOSTIC
1076 1.64 erh static int
1077 1.64 erh sysctl_kern_trigger_panic(SYSCTLFN_ARGS)
1078 1.64 erh {
1079 1.64 erh int newtrig, error;
1080 1.64 erh struct sysctlnode node;
1081 1.64 erh
1082 1.64 erh newtrig = 0;
1083 1.64 erh node = *rnode;
1084 1.64 erh node.sysctl_data = &newtrig;
1085 1.64 erh error = sysctl_lookup(SYSCTLFN_CALL(&node));
1086 1.64 erh if (error || newp == NULL)
1087 1.64 erh return (error);
1088 1.64 erh
1089 1.64 erh if (newtrig != 0)
1090 1.64 erh panic("Panic triggered");
1091 1.64 erh
1092 1.64 erh return (error);
1093 1.64 erh }
1094 1.64 erh #endif
1095 1.64 erh
1096 1.1 atatat /*
1097 1.105.2.1 matt * sysctl helper routine for kern.maxvnodes. Drain vnodes if
1098 1.13 yamt * new value is lower than desiredvnodes and then calls reinit
1099 1.1 atatat * routines that needs to adjust to the new value.
1100 1.1 atatat */
1101 1.1 atatat static int
1102 1.1 atatat sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
1103 1.1 atatat {
1104 1.12 yamt int error, new_vnodes, old_vnodes;
1105 1.1 atatat struct sysctlnode node;
1106 1.1 atatat
1107 1.1 atatat new_vnodes = desiredvnodes;
1108 1.1 atatat node = *rnode;
1109 1.1 atatat node.sysctl_data = &new_vnodes;
1110 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1111 1.1 atatat if (error || newp == NULL)
1112 1.1 atatat return (error);
1113 1.1 atatat
1114 1.12 yamt old_vnodes = desiredvnodes;
1115 1.1 atatat desiredvnodes = new_vnodes;
1116 1.12 yamt if (new_vnodes < old_vnodes) {
1117 1.58 christos error = vfs_drainvnodes(new_vnodes, l);
1118 1.12 yamt if (error) {
1119 1.12 yamt desiredvnodes = old_vnodes;
1120 1.12 yamt return (error);
1121 1.12 yamt }
1122 1.12 yamt }
1123 1.1 atatat vfs_reinit();
1124 1.1 atatat nchreinit();
1125 1.1 atatat
1126 1.1 atatat return (0);
1127 1.1 atatat }
1128 1.1 atatat
1129 1.1 atatat /*
1130 1.14 martin * sysctl helper routine for rtc_offset - set time after changes
1131 1.14 martin */
1132 1.14 martin static int
1133 1.14 martin sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
1134 1.14 martin {
1135 1.57 christos struct timespec ts, delta;
1136 1.57 christos int error, new_rtc_offset;
1137 1.14 martin struct sysctlnode node;
1138 1.14 martin
1139 1.14 martin new_rtc_offset = rtc_offset;
1140 1.14 martin node = *rnode;
1141 1.14 martin node.sysctl_data = &new_rtc_offset;
1142 1.14 martin error = sysctl_lookup(SYSCTLFN_CALL(&node));
1143 1.14 martin if (error || newp == NULL)
1144 1.14 martin return (error);
1145 1.14 martin
1146 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
1147 1.83 elad KAUTH_REQ_SYSTEM_TIME_RTCOFFSET,
1148 1.105.2.2 matt KAUTH_ARG(new_rtc_offset), NULL, NULL))
1149 1.14 martin return (EPERM);
1150 1.14 martin if (rtc_offset == new_rtc_offset)
1151 1.14 martin return (0);
1152 1.14 martin
1153 1.14 martin /* if we change the offset, adjust the time */
1154 1.57 christos nanotime(&ts);
1155 1.57 christos delta.tv_sec = 60 * (new_rtc_offset - rtc_offset);
1156 1.57 christos delta.tv_nsec = 0;
1157 1.57 christos timespecadd(&ts, &delta, &ts);
1158 1.14 martin rtc_offset = new_rtc_offset;
1159 1.105.2.2 matt return (settime(l->l_proc, &ts));
1160 1.14 martin }
1161 1.14 martin
1162 1.14 martin /*
1163 1.105.2.1 matt * sysctl helper routine for kern.maxproc. Ensures that the new
1164 1.1 atatat * values are not too low or too high.
1165 1.1 atatat */
1166 1.1 atatat static int
1167 1.1 atatat sysctl_kern_maxproc(SYSCTLFN_ARGS)
1168 1.1 atatat {
1169 1.1 atatat int error, nmaxproc;
1170 1.1 atatat struct sysctlnode node;
1171 1.1 atatat
1172 1.1 atatat nmaxproc = maxproc;
1173 1.1 atatat node = *rnode;
1174 1.1 atatat node.sysctl_data = &nmaxproc;
1175 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1176 1.1 atatat if (error || newp == NULL)
1177 1.1 atatat return (error);
1178 1.1 atatat
1179 1.1 atatat if (nmaxproc < 0 || nmaxproc >= PID_MAX)
1180 1.1 atatat return (EINVAL);
1181 1.1 atatat #ifdef __HAVE_CPU_MAXPROC
1182 1.1 atatat if (nmaxproc > cpu_maxproc())
1183 1.1 atatat return (EINVAL);
1184 1.1 atatat #endif
1185 1.1 atatat maxproc = nmaxproc;
1186 1.1 atatat
1187 1.1 atatat return (0);
1188 1.1 atatat }
1189 1.1 atatat
1190 1.1 atatat /*
1191 1.105.2.1 matt * sysctl helper function for kern.hostid. The hostid is a long, but
1192 1.1 atatat * we export it as an int, so we need to give it a little help.
1193 1.1 atatat */
1194 1.1 atatat static int
1195 1.1 atatat sysctl_kern_hostid(SYSCTLFN_ARGS)
1196 1.1 atatat {
1197 1.1 atatat int error, inthostid;
1198 1.1 atatat struct sysctlnode node;
1199 1.1 atatat
1200 1.29 martin inthostid = hostid; /* XXX assumes sizeof int <= sizeof long */
1201 1.1 atatat node = *rnode;
1202 1.1 atatat node.sysctl_data = &inthostid;
1203 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1204 1.1 atatat if (error || newp == NULL)
1205 1.1 atatat return (error);
1206 1.1 atatat
1207 1.27 atatat hostid = (unsigned)inthostid;
1208 1.1 atatat
1209 1.1 atatat return (0);
1210 1.1 atatat }
1211 1.1 atatat
1212 1.1 atatat /*
1213 1.17 atatat * sysctl helper function for kern.hostname and kern.domainnname.
1214 1.17 atatat * resets the relevant recorded length when the underlying name is
1215 1.17 atatat * changed.
1216 1.15 martin */
1217 1.15 martin static int
1218 1.17 atatat sysctl_setlen(SYSCTLFN_ARGS)
1219 1.15 martin {
1220 1.15 martin int error;
1221 1.15 martin
1222 1.43 atatat error = sysctl_lookup(SYSCTLFN_CALL(rnode));
1223 1.15 martin if (error || newp == NULL)
1224 1.15 martin return (error);
1225 1.15 martin
1226 1.17 atatat switch (rnode->sysctl_num) {
1227 1.17 atatat case KERN_HOSTNAME:
1228 1.17 atatat hostnamelen = strlen((const char*)rnode->sysctl_data);
1229 1.17 atatat break;
1230 1.17 atatat case KERN_DOMAINNAME:
1231 1.17 atatat domainnamelen = strlen((const char*)rnode->sysctl_data);
1232 1.17 atatat break;
1233 1.17 atatat }
1234 1.17 atatat
1235 1.15 martin return (0);
1236 1.15 martin }
1237 1.15 martin
1238 1.15 martin /*
1239 1.105.2.1 matt * sysctl helper routine for kern.clockrate. Assembles a struct on
1240 1.1 atatat * the fly to be returned to the caller.
1241 1.1 atatat */
1242 1.1 atatat static int
1243 1.1 atatat sysctl_kern_clockrate(SYSCTLFN_ARGS)
1244 1.1 atatat {
1245 1.1 atatat struct clockinfo clkinfo;
1246 1.1 atatat struct sysctlnode node;
1247 1.1 atatat
1248 1.1 atatat clkinfo.tick = tick;
1249 1.1 atatat clkinfo.tickadj = tickadj;
1250 1.1 atatat clkinfo.hz = hz;
1251 1.1 atatat clkinfo.profhz = profhz;
1252 1.1 atatat clkinfo.stathz = stathz ? stathz : hz;
1253 1.1 atatat
1254 1.1 atatat node = *rnode;
1255 1.1 atatat node.sysctl_data = &clkinfo;
1256 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1257 1.1 atatat }
1258 1.1 atatat
1259 1.1 atatat
1260 1.1 atatat /*
1261 1.1 atatat * sysctl helper routine for kern.file pseudo-subtree.
1262 1.1 atatat */
1263 1.1 atatat static int
1264 1.1 atatat sysctl_kern_file(SYSCTLFN_ARGS)
1265 1.1 atatat {
1266 1.1 atatat int error;
1267 1.1 atatat size_t buflen;
1268 1.105.2.2 matt struct file *fp, *dp, *np, fbuf;
1269 1.1 atatat char *start, *where;
1270 1.1 atatat
1271 1.1 atatat start = where = oldp;
1272 1.1 atatat buflen = *oldlenp;
1273 1.105.2.2 matt dp = NULL;
1274 1.105.2.2 matt
1275 1.1 atatat if (where == NULL) {
1276 1.1 atatat /*
1277 1.1 atatat * overestimate by 10 files
1278 1.1 atatat */
1279 1.105.2.2 matt *oldlenp = sizeof(filehead) + (nfiles + 10) *
1280 1.105.2.2 matt sizeof(struct file);
1281 1.1 atatat return (0);
1282 1.1 atatat }
1283 1.1 atatat
1284 1.1 atatat /*
1285 1.86 manu * first dcopyout filehead
1286 1.1 atatat */
1287 1.1 atatat if (buflen < sizeof(filehead)) {
1288 1.1 atatat *oldlenp = 0;
1289 1.1 atatat return (0);
1290 1.1 atatat }
1291 1.105.2.2 matt sysctl_unlock();
1292 1.86 manu error = dcopyout(l, &filehead, where, sizeof(filehead));
1293 1.105.2.2 matt if (error) {
1294 1.105.2.2 matt sysctl_relock();
1295 1.105.2.2 matt return error;
1296 1.105.2.2 matt }
1297 1.1 atatat buflen -= sizeof(filehead);
1298 1.1 atatat where += sizeof(filehead);
1299 1.1 atatat
1300 1.1 atatat /*
1301 1.105.2.2 matt * allocate dummy file descriptor to make position in list
1302 1.105.2.2 matt */
1303 1.105.2.2 matt if ((dp = fgetdummy()) == NULL) {
1304 1.105.2.2 matt sysctl_relock();
1305 1.105.2.2 matt return ENOMEM;
1306 1.105.2.2 matt }
1307 1.105.2.2 matt
1308 1.105.2.2 matt /*
1309 1.1 atatat * followed by an array of file structures
1310 1.1 atatat */
1311 1.105.2.2 matt mutex_enter(&filelist_lock);
1312 1.105.2.2 matt for (fp = LIST_FIRST(&filehead); fp != NULL; fp = np) {
1313 1.78 ad if (kauth_authorize_generic(l->l_cred,
1314 1.105.2.2 matt KAUTH_GENERIC_CANSEE, fp->f_cred) != 0) {
1315 1.105.2.2 matt np = LIST_NEXT(fp, f_list);
1316 1.55 elad continue;
1317 1.105.2.2 matt }
1318 1.1 atatat if (buflen < sizeof(struct file)) {
1319 1.1 atatat *oldlenp = where - start;
1320 1.105.2.2 matt mutex_exit(&filelist_lock);
1321 1.105.2.2 matt error = ENOMEM;
1322 1.105.2.2 matt break;
1323 1.105.2.2 matt }
1324 1.105.2.2 matt memcpy(&fbuf, fp, sizeof(fbuf));
1325 1.105.2.2 matt LIST_INSERT_AFTER(fp, dp, f_list);
1326 1.105.2.2 matt mutex_exit(&filelist_lock);
1327 1.105.2.2 matt error = dcopyout(l, &fbuf, where, sizeof(fbuf));
1328 1.105.2.2 matt if (error) {
1329 1.105.2.2 matt mutex_enter(&filelist_lock);
1330 1.105.2.2 matt LIST_REMOVE(dp, f_list);
1331 1.105.2.2 matt break;
1332 1.1 atatat }
1333 1.1 atatat buflen -= sizeof(struct file);
1334 1.1 atatat where += sizeof(struct file);
1335 1.105.2.2 matt mutex_enter(&filelist_lock);
1336 1.105.2.2 matt np = LIST_NEXT(dp, f_list);
1337 1.105.2.2 matt LIST_REMOVE(dp, f_list);
1338 1.1 atatat }
1339 1.105.2.2 matt mutex_exit(&filelist_lock);
1340 1.1 atatat *oldlenp = where - start;
1341 1.105.2.2 matt if (dp != NULL)
1342 1.105.2.2 matt fputdummy(dp);
1343 1.105.2.2 matt sysctl_relock();
1344 1.105.2.2 matt return (error);
1345 1.1 atatat }
1346 1.1 atatat
1347 1.1 atatat /*
1348 1.105.2.1 matt * sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
1349 1.105.2.1 matt * former it merely checks the message buffer is set up. For the latter,
1350 1.28 simonb * it also copies out the data if necessary.
1351 1.1 atatat */
1352 1.1 atatat static int
1353 1.1 atatat sysctl_msgbuf(SYSCTLFN_ARGS)
1354 1.1 atatat {
1355 1.1 atatat char *where = oldp;
1356 1.1 atatat size_t len, maxlen;
1357 1.1 atatat long beg, end;
1358 1.105.2.2 matt extern kmutex_t log_lock;
1359 1.1 atatat int error;
1360 1.1 atatat
1361 1.1 atatat if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
1362 1.1 atatat msgbufenabled = 0;
1363 1.1 atatat return (ENXIO);
1364 1.1 atatat }
1365 1.1 atatat
1366 1.1 atatat switch (rnode->sysctl_num) {
1367 1.31 atatat case KERN_MSGBUFSIZE: {
1368 1.31 atatat struct sysctlnode node = *rnode;
1369 1.31 atatat int msg_bufs = (int)msgbufp->msg_bufs;
1370 1.31 atatat node.sysctl_data = &msg_bufs;
1371 1.31 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1372 1.31 atatat }
1373 1.1 atatat case KERN_MSGBUF:
1374 1.1 atatat break;
1375 1.1 atatat default:
1376 1.1 atatat return (EOPNOTSUPP);
1377 1.1 atatat }
1378 1.1 atatat
1379 1.1 atatat if (newp != NULL)
1380 1.1 atatat return (EPERM);
1381 1.1 atatat
1382 1.105.2.1 matt if (oldp == NULL) {
1383 1.1 atatat /* always return full buffer size */
1384 1.1 atatat *oldlenp = msgbufp->msg_bufs;
1385 1.1 atatat return (0);
1386 1.105.2.1 matt }
1387 1.1 atatat
1388 1.105.2.2 matt sysctl_unlock();
1389 1.1 atatat
1390 1.1 atatat /*
1391 1.1 atatat * First, copy from the write pointer to the end of
1392 1.1 atatat * message buffer.
1393 1.1 atatat */
1394 1.105.2.2 matt error = 0;
1395 1.105.2.2 matt mutex_spin_enter(&log_lock);
1396 1.105.2.2 matt maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
1397 1.1 atatat beg = msgbufp->msg_bufx;
1398 1.1 atatat end = msgbufp->msg_bufs;
1399 1.105.2.2 matt mutex_spin_exit(&log_lock);
1400 1.105.2.2 matt
1401 1.1 atatat while (maxlen > 0) {
1402 1.1 atatat len = MIN(end - beg, maxlen);
1403 1.1 atatat if (len == 0)
1404 1.1 atatat break;
1405 1.105.2.2 matt /* XXX unlocked, but hardly matters. */
1406 1.86 manu error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
1407 1.1 atatat if (error)
1408 1.1 atatat break;
1409 1.1 atatat where += len;
1410 1.1 atatat maxlen -= len;
1411 1.1 atatat
1412 1.1 atatat /*
1413 1.1 atatat * ... then, copy from the beginning of message buffer to
1414 1.1 atatat * the write pointer.
1415 1.1 atatat */
1416 1.1 atatat beg = 0;
1417 1.1 atatat end = msgbufp->msg_bufx;
1418 1.1 atatat }
1419 1.1 atatat
1420 1.105.2.2 matt sysctl_relock();
1421 1.1 atatat return (error);
1422 1.1 atatat }
1423 1.1 atatat
1424 1.1 atatat /*
1425 1.105.2.1 matt * sysctl helper routine for kern.defcorename. In the case of a new
1426 1.1 atatat * string being assigned, check that it's not a zero-length string.
1427 1.1 atatat * (XXX the check in -current doesn't work, but do we really care?)
1428 1.1 atatat */
1429 1.1 atatat static int
1430 1.1 atatat sysctl_kern_defcorename(SYSCTLFN_ARGS)
1431 1.1 atatat {
1432 1.1 atatat int error;
1433 1.62 yamt char *newcorename;
1434 1.1 atatat struct sysctlnode node;
1435 1.1 atatat
1436 1.62 yamt newcorename = PNBUF_GET();
1437 1.1 atatat node = *rnode;
1438 1.1 atatat node.sysctl_data = &newcorename[0];
1439 1.1 atatat memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
1440 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1441 1.62 yamt if (error || newp == NULL) {
1442 1.62 yamt goto done;
1443 1.62 yamt }
1444 1.1 atatat
1445 1.1 atatat /*
1446 1.1 atatat * when sysctl_lookup() deals with a string, it's guaranteed
1447 1.105.2.1 matt * to come back nul terminated. So there. :)
1448 1.1 atatat */
1449 1.62 yamt if (strlen(newcorename) == 0) {
1450 1.62 yamt error = EINVAL;
1451 1.62 yamt } else {
1452 1.62 yamt memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
1453 1.62 yamt error = 0;
1454 1.62 yamt }
1455 1.62 yamt done:
1456 1.62 yamt PNBUF_PUT(newcorename);
1457 1.62 yamt return error;
1458 1.1 atatat }
1459 1.1 atatat
1460 1.1 atatat /*
1461 1.105.2.1 matt * sysctl helper routine for kern.cp_time node. Adds up cpu time
1462 1.1 atatat * across all cpus.
1463 1.1 atatat */
1464 1.1 atatat static int
1465 1.1 atatat sysctl_kern_cptime(SYSCTLFN_ARGS)
1466 1.1 atatat {
1467 1.1 atatat struct sysctlnode node = *rnode;
1468 1.59 perry uint64_t *cp_time = NULL;
1469 1.96 ad int error, n = ncpu, i;
1470 1.1 atatat struct cpu_info *ci;
1471 1.1 atatat CPU_INFO_ITERATOR cii;
1472 1.1 atatat
1473 1.1 atatat /*
1474 1.1 atatat * if you specifically pass a buffer that is the size of the
1475 1.1 atatat * sum, or if you are probing for the size, you get the "sum"
1476 1.1 atatat * of cp_time (and the size thereof) across all processors.
1477 1.1 atatat *
1478 1.1 atatat * alternately, you can pass an additional mib number and get
1479 1.1 atatat * cp_time for that particular processor.
1480 1.1 atatat */
1481 1.1 atatat switch (namelen) {
1482 1.1 atatat case 0:
1483 1.105.2.1 matt if (*oldlenp == sizeof(uint64_t) * CPUSTATES || oldp == NULL) {
1484 1.59 perry node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1485 1.1 atatat n = -1; /* SUM */
1486 1.1 atatat }
1487 1.1 atatat else {
1488 1.59 perry node.sysctl_size = n * sizeof(uint64_t) * CPUSTATES;
1489 1.1 atatat n = -2; /* ALL */
1490 1.1 atatat }
1491 1.1 atatat break;
1492 1.1 atatat case 1:
1493 1.1 atatat if (name[0] < 0 || name[0] >= n)
1494 1.18 atatat return (ENOENT); /* ENOSUCHPROCESSOR */
1495 1.59 perry node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1496 1.1 atatat n = name[0];
1497 1.1 atatat /*
1498 1.1 atatat * adjust these so that sysctl_lookup() will be happy
1499 1.1 atatat */
1500 1.1 atatat name++;
1501 1.1 atatat namelen--;
1502 1.7 martin break;
1503 1.1 atatat default:
1504 1.1 atatat return (EINVAL);
1505 1.1 atatat }
1506 1.1 atatat
1507 1.105.2.2 matt cp_time = kmem_alloc(node.sysctl_size, KM_SLEEP);
1508 1.1 atatat if (cp_time == NULL)
1509 1.1 atatat return (ENOMEM);
1510 1.1 atatat node.sysctl_data = cp_time;
1511 1.1 atatat memset(cp_time, 0, node.sysctl_size);
1512 1.1 atatat
1513 1.1 atatat for (CPU_INFO_FOREACH(cii, ci)) {
1514 1.105.2.2 matt if (n <= 0) {
1515 1.105.2.2 matt for (i = 0; i < CPUSTATES; i++) {
1516 1.1 atatat cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
1517 1.105.2.2 matt }
1518 1.105.2.2 matt }
1519 1.1 atatat /*
1520 1.1 atatat * if a specific processor was requested and we just
1521 1.1 atatat * did it, we're done here
1522 1.1 atatat */
1523 1.1 atatat if (n == 0)
1524 1.1 atatat break;
1525 1.1 atatat /*
1526 1.1 atatat * if doing "all", skip to next cp_time set for next processor
1527 1.1 atatat */
1528 1.1 atatat if (n == -2)
1529 1.1 atatat cp_time += CPUSTATES;
1530 1.1 atatat /*
1531 1.1 atatat * if we're doing a specific processor, we're one
1532 1.1 atatat * processor closer
1533 1.1 atatat */
1534 1.1 atatat if (n > 0)
1535 1.1 atatat n--;
1536 1.1 atatat }
1537 1.1 atatat
1538 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1539 1.105.2.2 matt kmem_free(node.sysctl_data, node.sysctl_size);
1540 1.5 martin return (error);
1541 1.1 atatat }
1542 1.1 atatat
1543 1.1 atatat #if NPTY > 0
1544 1.1 atatat /*
1545 1.105.2.1 matt * sysctl helper routine for kern.maxptys. Ensures that any new value
1546 1.1 atatat * is acceptable to the pty subsystem.
1547 1.1 atatat */
1548 1.1 atatat static int
1549 1.1 atatat sysctl_kern_maxptys(SYSCTLFN_ARGS)
1550 1.1 atatat {
1551 1.1 atatat int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
1552 1.40 christos int error, xmax;
1553 1.1 atatat struct sysctlnode node;
1554 1.1 atatat
1555 1.1 atatat /* get current value of maxptys */
1556 1.40 christos xmax = pty_maxptys(0, 0);
1557 1.1 atatat
1558 1.1 atatat node = *rnode;
1559 1.40 christos node.sysctl_data = &xmax;
1560 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1561 1.1 atatat if (error || newp == NULL)
1562 1.1 atatat return (error);
1563 1.33 perry
1564 1.40 christos if (xmax != pty_maxptys(xmax, 1))
1565 1.1 atatat return (EINVAL);
1566 1.1 atatat
1567 1.1 atatat return (0);
1568 1.1 atatat }
1569 1.1 atatat #endif /* NPTY > 0 */
1570 1.1 atatat
1571 1.1 atatat /*
1572 1.105.2.1 matt * sysctl helper routine for kern.sbmax. Basically just ensures that
1573 1.1 atatat * any new value is not too small.
1574 1.1 atatat */
1575 1.1 atatat static int
1576 1.1 atatat sysctl_kern_sbmax(SYSCTLFN_ARGS)
1577 1.1 atatat {
1578 1.1 atatat int error, new_sbmax;
1579 1.1 atatat struct sysctlnode node;
1580 1.1 atatat
1581 1.1 atatat new_sbmax = sb_max;
1582 1.1 atatat node = *rnode;
1583 1.1 atatat node.sysctl_data = &new_sbmax;
1584 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1585 1.1 atatat if (error || newp == NULL)
1586 1.1 atatat return (error);
1587 1.1 atatat
1588 1.105.2.2 matt KERNEL_LOCK(1, NULL);
1589 1.1 atatat error = sb_max_set(new_sbmax);
1590 1.105.2.2 matt KERNEL_UNLOCK_ONE(NULL);
1591 1.1 atatat
1592 1.1 atatat return (error);
1593 1.1 atatat }
1594 1.1 atatat
1595 1.1 atatat /*
1596 1.105.2.1 matt * sysctl helper routine for kern.urandom node. Picks a random number
1597 1.1 atatat * for you.
1598 1.1 atatat */
1599 1.1 atatat static int
1600 1.1 atatat sysctl_kern_urnd(SYSCTLFN_ARGS)
1601 1.1 atatat {
1602 1.1 atatat #if NRND > 0
1603 1.105.2.2 matt int v, rv;
1604 1.1 atatat
1605 1.105.2.2 matt KERNEL_LOCK(1, NULL);
1606 1.105.2.2 matt rv = rnd_extract_data(&v, sizeof(v), RND_EXTRACT_ANY);
1607 1.105.2.2 matt KERNEL_UNLOCK_ONE(NULL);
1608 1.105.2.2 matt if (rv == sizeof(v)) {
1609 1.1 atatat struct sysctlnode node = *rnode;
1610 1.1 atatat node.sysctl_data = &v;
1611 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1612 1.1 atatat }
1613 1.1 atatat else
1614 1.1 atatat return (EIO); /*XXX*/
1615 1.1 atatat #else
1616 1.1 atatat return (EOPNOTSUPP);
1617 1.1 atatat #endif
1618 1.1 atatat }
1619 1.1 atatat
1620 1.1 atatat /*
1621 1.105.2.1 matt * sysctl helper routine for kern.arandom node. Picks a random number
1622 1.91 christos * for you.
1623 1.91 christos */
1624 1.91 christos static int
1625 1.91 christos sysctl_kern_arnd(SYSCTLFN_ARGS)
1626 1.91 christos {
1627 1.91 christos #if NRND > 0
1628 1.91 christos int error;
1629 1.91 christos void *v;
1630 1.91 christos struct sysctlnode node = *rnode;
1631 1.91 christos
1632 1.91 christos if (*oldlenp == 0)
1633 1.91 christos return 0;
1634 1.91 christos if (*oldlenp > 8192)
1635 1.91 christos return E2BIG;
1636 1.91 christos
1637 1.105.2.2 matt v = kmem_alloc(*oldlenp, KM_SLEEP);
1638 1.91 christos arc4randbytes(v, *oldlenp);
1639 1.91 christos node.sysctl_data = v;
1640 1.91 christos node.sysctl_size = *oldlenp;
1641 1.91 christos error = sysctl_lookup(SYSCTLFN_CALL(&node));
1642 1.105.2.2 matt kmem_free(v, *oldlenp);
1643 1.91 christos return error;
1644 1.91 christos #else
1645 1.91 christos return (EOPNOTSUPP);
1646 1.91 christos #endif
1647 1.91 christos }
1648 1.91 christos /*
1649 1.1 atatat * sysctl helper routine to do kern.lwp.* work.
1650 1.1 atatat */
1651 1.1 atatat static int
1652 1.1 atatat sysctl_kern_lwp(SYSCTLFN_ARGS)
1653 1.1 atatat {
1654 1.1 atatat struct kinfo_lwp klwp;
1655 1.1 atatat struct proc *p;
1656 1.105.2.2 matt struct lwp *l2, *l3;
1657 1.1 atatat char *where, *dp;
1658 1.1 atatat int pid, elem_size, elem_count;
1659 1.1 atatat int buflen, needed, error;
1660 1.105.2.2 matt bool gotit;
1661 1.1 atatat
1662 1.19 atatat if (namelen == 1 && name[0] == CTL_QUERY)
1663 1.43 atatat return (sysctl_query(SYSCTLFN_CALL(rnode)));
1664 1.19 atatat
1665 1.1 atatat dp = where = oldp;
1666 1.1 atatat buflen = where != NULL ? *oldlenp : 0;
1667 1.1 atatat error = needed = 0;
1668 1.1 atatat
1669 1.11 simonb if (newp != NULL || namelen != 3)
1670 1.1 atatat return (EINVAL);
1671 1.11 simonb pid = name[0];
1672 1.11 simonb elem_size = name[1];
1673 1.11 simonb elem_count = name[2];
1674 1.1 atatat
1675 1.105.2.2 matt sysctl_unlock();
1676 1.101 yamt if (pid == -1) {
1677 1.105.2.2 matt mutex_enter(&proclist_lock);
1678 1.105.2.2 matt LIST_FOREACH(p, &allproc, p_list) {
1679 1.105.2.2 matt /* Grab a hold on the process. */
1680 1.105.2.2 matt if (!rw_tryenter(&p->p_reflock, RW_READER)) {
1681 1.105.2.2 matt continue;
1682 1.105.2.2 matt }
1683 1.105.2.2 matt mutex_exit(&proclist_lock);
1684 1.101 yamt
1685 1.105.2.2 matt mutex_enter(&p->p_smutex);
1686 1.105.2.2 matt LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1687 1.105.2.2 matt if (buflen >= elem_size && elem_count > 0) {
1688 1.105.2.2 matt lwp_lock(l2);
1689 1.105.2.2 matt fill_lwp(l2, &klwp);
1690 1.105.2.2 matt lwp_unlock(l2);
1691 1.105.2.2 matt mutex_exit(&p->p_smutex);
1692 1.105.2.2 matt
1693 1.105.2.2 matt /*
1694 1.105.2.2 matt * Copy out elem_size, but not
1695 1.105.2.2 matt * larger than the size of a
1696 1.105.2.2 matt * struct kinfo_proc2.
1697 1.105.2.2 matt */
1698 1.105.2.2 matt error = dcopyout(l, &klwp, dp,
1699 1.105.2.2 matt min(sizeof(klwp), elem_size));
1700 1.105.2.2 matt if (error) {
1701 1.105.2.2 matt rw_exit(&p->p_reflock);
1702 1.105.2.2 matt goto cleanup;
1703 1.105.2.2 matt }
1704 1.105.2.2 matt mutex_enter(&p->p_smutex);
1705 1.105.2.2 matt LIST_FOREACH(l3, &p->p_lwps,
1706 1.105.2.2 matt l_sibling) {
1707 1.105.2.2 matt if (l2 == l3)
1708 1.105.2.2 matt break;
1709 1.105.2.2 matt }
1710 1.105.2.2 matt if (l3 == NULL) {
1711 1.105.2.2 matt mutex_exit(&p->p_smutex);
1712 1.105.2.2 matt rw_exit(&p->p_reflock);
1713 1.105.2.2 matt error = EAGAIN;
1714 1.105.2.2 matt goto cleanup;
1715 1.105.2.2 matt }
1716 1.105.2.2 matt dp += elem_size;
1717 1.105.2.2 matt buflen -= elem_size;
1718 1.105.2.2 matt elem_count--;
1719 1.105.2.2 matt }
1720 1.105.2.2 matt needed += elem_size;
1721 1.101 yamt }
1722 1.105.2.2 matt mutex_exit(&p->p_smutex);
1723 1.105.2.2 matt
1724 1.105.2.2 matt /* Drop reference to process. */
1725 1.105.2.2 matt mutex_enter(&proclist_lock);
1726 1.105.2.2 matt rw_exit(&p->p_reflock);
1727 1.101 yamt }
1728 1.105.2.2 matt mutex_exit(&proclist_lock);
1729 1.101 yamt } else {
1730 1.105.2.2 matt mutex_enter(&proclist_lock);
1731 1.101 yamt p = p_find(pid, PFIND_LOCKED);
1732 1.101 yamt if (p == NULL) {
1733 1.105.2.2 matt error = ESRCH;
1734 1.101 yamt mutex_exit(&proclist_lock);
1735 1.105.2.2 matt goto cleanup;
1736 1.105.2.2 matt }
1737 1.105.2.2 matt /* Grab a hold on the process. */
1738 1.105.2.2 matt gotit = rw_tryenter(&p->p_reflock, RW_READER);
1739 1.105.2.2 matt mutex_exit(&proclist_lock);
1740 1.105.2.2 matt if (!gotit) {
1741 1.105.2.2 matt error = ESRCH;
1742 1.105.2.2 matt goto cleanup;
1743 1.101 yamt }
1744 1.105.2.2 matt
1745 1.105.2.1 matt mutex_enter(&p->p_smutex);
1746 1.101 yamt LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1747 1.101 yamt if (buflen >= elem_size && elem_count > 0) {
1748 1.101 yamt lwp_lock(l2);
1749 1.101 yamt fill_lwp(l2, &klwp);
1750 1.101 yamt lwp_unlock(l2);
1751 1.105.2.1 matt mutex_exit(&p->p_smutex);
1752 1.101 yamt /*
1753 1.101 yamt * Copy out elem_size, but not larger than
1754 1.101 yamt * the size of a struct kinfo_proc2.
1755 1.101 yamt */
1756 1.101 yamt error = dcopyout(l, &klwp, dp,
1757 1.101 yamt min(sizeof(klwp), elem_size));
1758 1.105.2.1 matt if (error) {
1759 1.105.2.2 matt rw_exit(&p->p_reflock);
1760 1.101 yamt goto cleanup;
1761 1.105.2.1 matt }
1762 1.105.2.1 matt mutex_enter(&p->p_smutex);
1763 1.105.2.1 matt LIST_FOREACH(l3, &p->p_lwps, l_sibling) {
1764 1.105.2.1 matt if (l2 == l3)
1765 1.105.2.1 matt break;
1766 1.105.2.1 matt }
1767 1.105.2.1 matt if (l3 == NULL) {
1768 1.105.2.1 matt mutex_exit(&p->p_smutex);
1769 1.105.2.2 matt rw_exit(&p->p_reflock);
1770 1.105.2.1 matt error = EAGAIN;
1771 1.105.2.1 matt goto cleanup;
1772 1.105.2.1 matt }
1773 1.101 yamt dp += elem_size;
1774 1.101 yamt buflen -= elem_size;
1775 1.101 yamt elem_count--;
1776 1.101 yamt }
1777 1.101 yamt needed += elem_size;
1778 1.1 atatat }
1779 1.101 yamt mutex_exit(&p->p_smutex);
1780 1.105.2.2 matt
1781 1.105.2.2 matt /* Drop reference to process. */
1782 1.105.2.2 matt rw_exit(&p->p_reflock);
1783 1.1 atatat }
1784 1.1 atatat
1785 1.1 atatat if (where != NULL) {
1786 1.1 atatat *oldlenp = dp - where;
1787 1.105.2.2 matt if (needed > *oldlenp) {
1788 1.105.2.2 matt sysctl_relock();
1789 1.1 atatat return (ENOMEM);
1790 1.105.2.2 matt }
1791 1.1 atatat } else {
1792 1.22 atatat needed += KERN_LWPSLOP;
1793 1.1 atatat *oldlenp = needed;
1794 1.1 atatat }
1795 1.105.2.2 matt error = 0;
1796 1.1 atatat cleanup:
1797 1.105.2.2 matt sysctl_relock();
1798 1.1 atatat return (error);
1799 1.1 atatat }
1800 1.1 atatat
1801 1.1 atatat /*
1802 1.105.2.1 matt * sysctl helper routine for kern.forkfsleep node. Ensures that the
1803 1.1 atatat * given value is not too large or two small, and is at least one
1804 1.1 atatat * timer tick if not zero.
1805 1.1 atatat */
1806 1.1 atatat static int
1807 1.1 atatat sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
1808 1.1 atatat {
1809 1.1 atatat /* userland sees value in ms, internally is in ticks */
1810 1.1 atatat extern int forkfsleep; /* defined in kern/kern_fork.c */
1811 1.1 atatat int error, timo, lsleep;
1812 1.1 atatat struct sysctlnode node;
1813 1.1 atatat
1814 1.1 atatat lsleep = forkfsleep * 1000 / hz;
1815 1.1 atatat node = *rnode;
1816 1.1 atatat node.sysctl_data = &lsleep;
1817 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
1818 1.1 atatat if (error || newp == NULL)
1819 1.1 atatat return (error);
1820 1.1 atatat
1821 1.1 atatat /* refuse negative values, and overly 'long time' */
1822 1.1 atatat if (lsleep < 0 || lsleep > MAXSLP * 1000)
1823 1.1 atatat return (EINVAL);
1824 1.1 atatat
1825 1.1 atatat timo = mstohz(lsleep);
1826 1.1 atatat
1827 1.1 atatat /* if the interval is >0 ms && <1 tick, use 1 tick */
1828 1.1 atatat if (lsleep != 0 && timo == 0)
1829 1.1 atatat forkfsleep = 1;
1830 1.1 atatat else
1831 1.1 atatat forkfsleep = timo;
1832 1.1 atatat
1833 1.1 atatat return (0);
1834 1.1 atatat }
1835 1.1 atatat
1836 1.1 atatat /*
1837 1.1 atatat * sysctl helper routine for kern.root_partition
1838 1.1 atatat */
1839 1.1 atatat static int
1840 1.1 atatat sysctl_kern_root_partition(SYSCTLFN_ARGS)
1841 1.1 atatat {
1842 1.1 atatat int rootpart = DISKPART(rootdev);
1843 1.1 atatat struct sysctlnode node = *rnode;
1844 1.1 atatat
1845 1.1 atatat node.sysctl_data = &rootpart;
1846 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1847 1.1 atatat }
1848 1.1 atatat
1849 1.1 atatat /*
1850 1.1 atatat * sysctl helper function for kern.drivers
1851 1.1 atatat */
1852 1.1 atatat static int
1853 1.1 atatat sysctl_kern_drivers(SYSCTLFN_ARGS)
1854 1.1 atatat {
1855 1.1 atatat int error;
1856 1.1 atatat size_t buflen;
1857 1.1 atatat struct kinfo_drivers kd;
1858 1.1 atatat char *start, *where;
1859 1.1 atatat const char *dname;
1860 1.1 atatat int i;
1861 1.1 atatat extern struct devsw_conv *devsw_conv;
1862 1.1 atatat extern int max_devsw_convs;
1863 1.105.2.2 matt extern kmutex_t devsw_lock;
1864 1.1 atatat
1865 1.1 atatat if (newp != NULL || namelen != 0)
1866 1.1 atatat return (EINVAL);
1867 1.1 atatat
1868 1.1 atatat start = where = oldp;
1869 1.1 atatat buflen = *oldlenp;
1870 1.1 atatat if (where == NULL) {
1871 1.1 atatat *oldlenp = max_devsw_convs * sizeof kd;
1872 1.1 atatat return 0;
1873 1.1 atatat }
1874 1.1 atatat
1875 1.1 atatat /*
1876 1.1 atatat * An array of kinfo_drivers structures
1877 1.1 atatat */
1878 1.1 atatat error = 0;
1879 1.105.2.2 matt sysctl_unlock();
1880 1.105.2.2 matt mutex_enter(&devsw_lock);
1881 1.1 atatat for (i = 0; i < max_devsw_convs; i++) {
1882 1.1 atatat dname = devsw_conv[i].d_name;
1883 1.1 atatat if (dname == NULL)
1884 1.1 atatat continue;
1885 1.1 atatat if (buflen < sizeof kd) {
1886 1.1 atatat error = ENOMEM;
1887 1.1 atatat break;
1888 1.1 atatat }
1889 1.25 atatat memset(&kd, 0, sizeof(kd));
1890 1.1 atatat kd.d_bmajor = devsw_conv[i].d_bmajor;
1891 1.1 atatat kd.d_cmajor = devsw_conv[i].d_cmajor;
1892 1.1 atatat strlcpy(kd.d_name, dname, sizeof kd.d_name);
1893 1.105.2.2 matt mutex_exit(&devsw_lock);
1894 1.86 manu error = dcopyout(l, &kd, where, sizeof kd);
1895 1.105.2.2 matt mutex_enter(&devsw_lock);
1896 1.1 atatat if (error != 0)
1897 1.1 atatat break;
1898 1.1 atatat buflen -= sizeof kd;
1899 1.1 atatat where += sizeof kd;
1900 1.1 atatat }
1901 1.105.2.2 matt mutex_exit(&devsw_lock);
1902 1.105.2.2 matt sysctl_relock();
1903 1.1 atatat *oldlenp = where - start;
1904 1.1 atatat return error;
1905 1.1 atatat }
1906 1.1 atatat
1907 1.34 atatat /*
1908 1.34 atatat * sysctl helper function for kern.file2
1909 1.34 atatat */
1910 1.34 atatat static int
1911 1.34 atatat sysctl_kern_file2(SYSCTLFN_ARGS)
1912 1.34 atatat {
1913 1.34 atatat struct proc *p;
1914 1.34 atatat struct file *fp;
1915 1.34 atatat struct filedesc *fd;
1916 1.34 atatat struct kinfo_file kf;
1917 1.34 atatat char *dp;
1918 1.34 atatat u_int i, op;
1919 1.34 atatat size_t len, needed, elem_size, out_size;
1920 1.34 atatat int error, arg, elem_count;
1921 1.34 atatat
1922 1.34 atatat if (namelen == 1 && name[0] == CTL_QUERY)
1923 1.43 atatat return (sysctl_query(SYSCTLFN_CALL(rnode)));
1924 1.34 atatat
1925 1.34 atatat if (namelen != 4)
1926 1.34 atatat return (EINVAL);
1927 1.34 atatat
1928 1.34 atatat error = 0;
1929 1.34 atatat dp = oldp;
1930 1.34 atatat len = (oldp != NULL) ? *oldlenp : 0;
1931 1.34 atatat op = name[0];
1932 1.34 atatat arg = name[1];
1933 1.34 atatat elem_size = name[2];
1934 1.34 atatat elem_count = name[3];
1935 1.34 atatat out_size = MIN(sizeof(kf), elem_size);
1936 1.34 atatat needed = 0;
1937 1.34 atatat
1938 1.34 atatat if (elem_size < 1 || elem_count < 0)
1939 1.34 atatat return (EINVAL);
1940 1.34 atatat
1941 1.34 atatat switch (op) {
1942 1.34 atatat case KERN_FILE_BYFILE:
1943 1.34 atatat /*
1944 1.34 atatat * doesn't use arg so it must be zero
1945 1.34 atatat */
1946 1.34 atatat if (arg != 0)
1947 1.34 atatat return (EINVAL);
1948 1.105.2.2 matt sysctl_unlock();
1949 1.105.2.2 matt mutex_enter(&filelist_lock);
1950 1.34 atatat LIST_FOREACH(fp, &filehead, f_list) {
1951 1.78 ad if (kauth_authorize_generic(l->l_cred,
1952 1.76 elad KAUTH_GENERIC_CANSEE, fp->f_cred) != 0)
1953 1.55 elad continue;
1954 1.105.2.2 matt mutex_enter(&fp->f_lock);
1955 1.105.2.2 matt if (fp->f_count == 0) {
1956 1.105.2.2 matt mutex_exit(&fp->f_lock);
1957 1.105.2.2 matt continue;
1958 1.105.2.2 matt }
1959 1.105.2.2 matt FILE_USE(fp);
1960 1.34 atatat if (len >= elem_size && elem_count > 0) {
1961 1.34 atatat fill_file(&kf, fp, NULL, 0);
1962 1.86 manu error = dcopyout(l, &kf, dp, out_size);
1963 1.105.2.2 matt if (error) {
1964 1.105.2.2 matt mutex_enter(&filelist_lock);
1965 1.105.2.2 matt FILE_UNUSE(fp, NULL);
1966 1.34 atatat break;
1967 1.105.2.2 matt }
1968 1.34 atatat dp += elem_size;
1969 1.34 atatat len -= elem_size;
1970 1.34 atatat }
1971 1.34 atatat if (elem_count > 0) {
1972 1.34 atatat needed += elem_size;
1973 1.34 atatat if (elem_count != INT_MAX)
1974 1.34 atatat elem_count--;
1975 1.34 atatat }
1976 1.105.2.2 matt /* XXXAD can't work?? */
1977 1.105.2.2 matt mutex_enter(&filelist_lock);
1978 1.105.2.2 matt FILE_UNUSE(fp, NULL);
1979 1.34 atatat }
1980 1.105.2.2 matt mutex_exit(&filelist_lock);
1981 1.105.2.2 matt sysctl_relock();
1982 1.34 atatat break;
1983 1.69 yamt case KERN_FILE_BYPID:
1984 1.34 atatat if (arg < -1)
1985 1.34 atatat /* -1 means all processes */
1986 1.34 atatat return (EINVAL);
1987 1.105.2.2 matt sysctl_unlock();
1988 1.98 ad mutex_enter(&proclist_lock);
1989 1.105.2.2 matt LIST_FOREACH(p, &allproc, p_list) {
1990 1.105.2.2 matt if (p->p_stat == SIDL) {
1991 1.34 atatat /* skip embryonic processes */
1992 1.34 atatat continue;
1993 1.105.2.2 matt }
1994 1.105.2.2 matt if (arg > 0 && p->p_pid != arg) {
1995 1.34 atatat /* pick only the one we want */
1996 1.34 atatat /* XXX want 0 to mean "kernel files" */
1997 1.34 atatat continue;
1998 1.105.2.2 matt }
1999 1.105.2.2 matt mutex_enter(&p->p_mutex);
2000 1.105.2.2 matt error = kauth_authorize_process(l->l_cred,
2001 1.105.2.2 matt KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL);
2002 1.105.2.2 matt mutex_exit(&p->p_mutex);
2003 1.105.2.2 matt if (error != 0) {
2004 1.105.2.2 matt continue;
2005 1.105.2.2 matt }
2006 1.105.2.2 matt
2007 1.105.2.2 matt /*
2008 1.105.2.2 matt * Grab a hold on the process.
2009 1.105.2.2 matt */
2010 1.105.2.2 matt if (!rw_tryenter(&p->p_reflock, RW_READER)) {
2011 1.105.2.2 matt continue;
2012 1.105.2.2 matt }
2013 1.105.2.2 matt mutex_exit(&proclist_lock);
2014 1.105.2.2 matt
2015 1.34 atatat fd = p->p_fd;
2016 1.105.2.2 matt rw_enter(&fd->fd_lock, RW_READER);
2017 1.34 atatat for (i = 0; i < fd->fd_nfiles; i++) {
2018 1.34 atatat fp = fd->fd_ofiles[i];
2019 1.105.2.2 matt if (fp == NULL) {
2020 1.34 atatat continue;
2021 1.105.2.2 matt }
2022 1.105.2.2 matt mutex_enter(&fp->f_lock);
2023 1.105.2.2 matt if (!FILE_IS_USABLE(fp)) {
2024 1.105.2.2 matt mutex_exit(&fp->f_lock);
2025 1.105.2.2 matt continue;
2026 1.105.2.2 matt }
2027 1.34 atatat if (len >= elem_size && elem_count > 0) {
2028 1.105.2.2 matt fill_file(&kf, fd->fd_ofiles[i], p, i);
2029 1.105.2.2 matt mutex_exit(&fp->f_lock);
2030 1.105.2.2 matt rw_exit(&fd->fd_lock);
2031 1.86 manu error = dcopyout(l, &kf, dp, out_size);
2032 1.105.2.2 matt rw_enter(&fd->fd_lock, RW_READER);
2033 1.34 atatat if (error)
2034 1.34 atatat break;
2035 1.34 atatat dp += elem_size;
2036 1.34 atatat len -= elem_size;
2037 1.105.2.2 matt } else {
2038 1.105.2.2 matt mutex_exit(&fp->f_lock);
2039 1.34 atatat }
2040 1.34 atatat if (elem_count > 0) {
2041 1.34 atatat needed += elem_size;
2042 1.34 atatat if (elem_count != INT_MAX)
2043 1.34 atatat elem_count--;
2044 1.34 atatat }
2045 1.34 atatat }
2046 1.105.2.2 matt rw_exit(&fd->fd_lock);
2047 1.105.2.2 matt
2048 1.105.2.2 matt /*
2049 1.105.2.2 matt * Release reference to process.
2050 1.105.2.2 matt */
2051 1.105.2.2 matt mutex_enter(&proclist_lock);
2052 1.105.2.2 matt rw_exit(&p->p_reflock);
2053 1.34 atatat }
2054 1.98 ad mutex_exit(&proclist_lock);
2055 1.105.2.2 matt sysctl_relock();
2056 1.34 atatat break;
2057 1.34 atatat default:
2058 1.34 atatat return (EINVAL);
2059 1.34 atatat }
2060 1.34 atatat
2061 1.34 atatat if (oldp == NULL)
2062 1.34 atatat needed += KERN_FILESLOP * elem_size;
2063 1.34 atatat *oldlenp = needed;
2064 1.34 atatat
2065 1.34 atatat return (error);
2066 1.34 atatat }
2067 1.34 atatat
2068 1.34 atatat static void
2069 1.34 atatat fill_file(struct kinfo_file *kp, const struct file *fp, struct proc *p, int i)
2070 1.34 atatat {
2071 1.34 atatat
2072 1.34 atatat memset(kp, 0, sizeof(*kp));
2073 1.34 atatat
2074 1.34 atatat kp->ki_fileaddr = PTRTOUINT64(fp);
2075 1.34 atatat kp->ki_flag = fp->f_flag;
2076 1.34 atatat kp->ki_iflags = fp->f_iflags;
2077 1.34 atatat kp->ki_ftype = fp->f_type;
2078 1.34 atatat kp->ki_count = fp->f_count;
2079 1.34 atatat kp->ki_msgcount = fp->f_msgcount;
2080 1.34 atatat kp->ki_usecount = fp->f_usecount;
2081 1.34 atatat kp->ki_fucred = PTRTOUINT64(fp->f_cred);
2082 1.68 elad kp->ki_fuid = kauth_cred_geteuid(fp->f_cred);
2083 1.68 elad kp->ki_fgid = kauth_cred_getegid(fp->f_cred);
2084 1.34 atatat kp->ki_fops = PTRTOUINT64(fp->f_ops);
2085 1.34 atatat kp->ki_foffset = fp->f_offset;
2086 1.34 atatat kp->ki_fdata = PTRTOUINT64(fp->f_data);
2087 1.34 atatat
2088 1.34 atatat /* vnode information to glue this file to something */
2089 1.34 atatat if (fp->f_type == DTYPE_VNODE) {
2090 1.34 atatat struct vnode *vp = (struct vnode *)fp->f_data;
2091 1.34 atatat
2092 1.34 atatat kp->ki_vun = PTRTOUINT64(vp->v_un.vu_socket);
2093 1.34 atatat kp->ki_vsize = vp->v_size;
2094 1.34 atatat kp->ki_vtype = vp->v_type;
2095 1.34 atatat kp->ki_vtag = vp->v_tag;
2096 1.34 atatat kp->ki_vdata = PTRTOUINT64(vp->v_data);
2097 1.34 atatat }
2098 1.34 atatat
2099 1.105.2.1 matt /* process information when retrieved via KERN_FILE_BYPID */
2100 1.34 atatat if (p) {
2101 1.105.2.2 matt KASSERT(rw_lock_held(&p->p_fd->fd_lock));
2102 1.105.2.2 matt
2103 1.34 atatat kp->ki_pid = p->p_pid;
2104 1.34 atatat kp->ki_fd = i;
2105 1.34 atatat kp->ki_ofileflags = p->p_fd->fd_ofileflags[i];
2106 1.34 atatat }
2107 1.34 atatat }
2108 1.34 atatat
2109 1.1 atatat static int
2110 1.1 atatat sysctl_doeproc(SYSCTLFN_ARGS)
2111 1.1 atatat {
2112 1.73 christos struct eproc *eproc;
2113 1.73 christos struct kinfo_proc2 *kproc2;
2114 1.1 atatat struct kinfo_proc *dp;
2115 1.1 atatat struct proc *p;
2116 1.1 atatat char *where, *dp2;
2117 1.1 atatat int type, op, arg;
2118 1.1 atatat u_int elem_size, elem_count;
2119 1.1 atatat size_t buflen, needed;
2120 1.105.2.2 matt bool match;
2121 1.1 atatat int error;
2122 1.1 atatat
2123 1.19 atatat if (namelen == 1 && name[0] == CTL_QUERY)
2124 1.43 atatat return (sysctl_query(SYSCTLFN_CALL(rnode)));
2125 1.19 atatat
2126 1.1 atatat dp = oldp;
2127 1.1 atatat dp2 = where = oldp;
2128 1.1 atatat buflen = where != NULL ? *oldlenp : 0;
2129 1.1 atatat error = 0;
2130 1.1 atatat needed = 0;
2131 1.1 atatat type = rnode->sysctl_num;
2132 1.1 atatat
2133 1.1 atatat if (type == KERN_PROC) {
2134 1.1 atatat if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
2135 1.1 atatat return (EINVAL);
2136 1.1 atatat op = name[0];
2137 1.1 atatat if (op != KERN_PROC_ALL)
2138 1.1 atatat arg = name[1];
2139 1.1 atatat else
2140 1.1 atatat arg = 0; /* Quell compiler warning */
2141 1.1 atatat elem_size = elem_count = 0; /* Ditto */
2142 1.1 atatat } else {
2143 1.1 atatat if (namelen != 4)
2144 1.1 atatat return (EINVAL);
2145 1.1 atatat op = name[0];
2146 1.1 atatat arg = name[1];
2147 1.1 atatat elem_size = name[2];
2148 1.1 atatat elem_count = name[3];
2149 1.1 atatat }
2150 1.1 atatat
2151 1.105.2.2 matt sysctl_unlock();
2152 1.105.2.2 matt
2153 1.74 christos if (type == KERN_PROC) {
2154 1.105.2.2 matt eproc = kmem_alloc(sizeof(*eproc), KM_SLEEP);
2155 1.74 christos kproc2 = NULL;
2156 1.74 christos } else {
2157 1.74 christos eproc = NULL;
2158 1.105.2.2 matt kproc2 = kmem_alloc(sizeof(*kproc2), KM_SLEEP);
2159 1.74 christos }
2160 1.1 atatat
2161 1.105.2.2 matt mutex_enter(&proclist_lock);
2162 1.105.2.2 matt LIST_FOREACH(p, &allproc, p_list) {
2163 1.1 atatat /*
2164 1.1 atatat * Skip embryonic processes.
2165 1.1 atatat */
2166 1.1 atatat if (p->p_stat == SIDL)
2167 1.1 atatat continue;
2168 1.55 elad
2169 1.105.2.2 matt mutex_enter(&p->p_mutex);
2170 1.105.2.2 matt error = kauth_authorize_process(l->l_cred,
2171 1.105.2.2 matt KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL);
2172 1.105.2.2 matt if (error != 0) {
2173 1.105.2.2 matt mutex_exit(&p->p_mutex);
2174 1.55 elad continue;
2175 1.105.2.2 matt }
2176 1.55 elad
2177 1.1 atatat /*
2178 1.1 atatat * TODO - make more efficient (see notes below).
2179 1.1 atatat * do by session.
2180 1.1 atatat */
2181 1.1 atatat switch (op) {
2182 1.1 atatat case KERN_PROC_PID:
2183 1.1 atatat /* could do this with just a lookup */
2184 1.105.2.2 matt match = (p->p_pid == (pid_t)arg);
2185 1.1 atatat break;
2186 1.1 atatat
2187 1.1 atatat case KERN_PROC_PGRP:
2188 1.1 atatat /* could do this by traversing pgrp */
2189 1.105.2.2 matt match = (p->p_pgrp->pg_id == (pid_t)arg);
2190 1.1 atatat break;
2191 1.1 atatat
2192 1.1 atatat case KERN_PROC_SESSION:
2193 1.105.2.2 matt match = (p->p_session->s_sid == (pid_t)arg);
2194 1.1 atatat break;
2195 1.1 atatat
2196 1.1 atatat case KERN_PROC_TTY:
2197 1.105.2.2 matt match = true;
2198 1.1 atatat if (arg == (int) KERN_PROC_TTY_REVOKE) {
2199 1.95 ad if ((p->p_lflag & PL_CONTROLT) == 0 ||
2200 1.1 atatat p->p_session->s_ttyp == NULL ||
2201 1.105.2.2 matt p->p_session->s_ttyvp != NULL) {
2202 1.105.2.2 matt match = false;
2203 1.105.2.2 matt }
2204 1.95 ad } else if ((p->p_lflag & PL_CONTROLT) == 0 ||
2205 1.1 atatat p->p_session->s_ttyp == NULL) {
2206 1.105.2.2 matt if ((dev_t)arg != KERN_PROC_TTY_NODEV) {
2207 1.105.2.2 matt match = false;
2208 1.105.2.2 matt }
2209 1.105.2.2 matt } else if (p->p_session->s_ttyp->t_dev != (dev_t)arg) {
2210 1.105.2.2 matt match = false;
2211 1.105.2.2 matt }
2212 1.1 atatat break;
2213 1.1 atatat
2214 1.1 atatat case KERN_PROC_UID:
2215 1.105.2.2 matt match = (kauth_cred_geteuid(p->p_cred) == (uid_t)arg);
2216 1.1 atatat break;
2217 1.1 atatat
2218 1.1 atatat case KERN_PROC_RUID:
2219 1.105.2.2 matt match = (kauth_cred_getuid(p->p_cred) == (uid_t)arg);
2220 1.1 atatat break;
2221 1.1 atatat
2222 1.1 atatat case KERN_PROC_GID:
2223 1.105.2.2 matt match = (kauth_cred_getegid(p->p_cred) == (uid_t)arg);
2224 1.1 atatat break;
2225 1.1 atatat
2226 1.1 atatat case KERN_PROC_RGID:
2227 1.105.2.2 matt match = (kauth_cred_getgid(p->p_cred) == (uid_t)arg);
2228 1.1 atatat break;
2229 1.1 atatat
2230 1.1 atatat case KERN_PROC_ALL:
2231 1.105.2.2 matt match = true;
2232 1.1 atatat /* allow everything */
2233 1.1 atatat break;
2234 1.1 atatat
2235 1.1 atatat default:
2236 1.1 atatat error = EINVAL;
2237 1.105.2.2 matt mutex_exit(&p->p_mutex);
2238 1.1 atatat goto cleanup;
2239 1.1 atatat }
2240 1.105.2.2 matt if (!match) {
2241 1.105.2.2 matt mutex_exit(&p->p_mutex);
2242 1.105.2.2 matt continue;
2243 1.105.2.2 matt }
2244 1.105.2.2 matt
2245 1.105.2.2 matt /*
2246 1.105.2.2 matt * Grab a hold on the process.
2247 1.105.2.2 matt */
2248 1.105.2.2 matt if (!rw_tryenter(&p->p_reflock, RW_READER)) {
2249 1.105.2.2 matt mutex_exit(&p->p_mutex);
2250 1.105.2.2 matt continue;
2251 1.105.2.2 matt }
2252 1.105.2.2 matt
2253 1.1 atatat if (type == KERN_PROC) {
2254 1.1 atatat if (buflen >= sizeof(struct kinfo_proc)) {
2255 1.73 christos fill_eproc(p, eproc);
2256 1.105.2.2 matt mutex_exit(&p->p_mutex);
2257 1.105.2.2 matt mutex_exit(&proclist_lock);
2258 1.86 manu error = dcopyout(l, p, &dp->kp_proc,
2259 1.1 atatat sizeof(struct proc));
2260 1.105.2.2 matt mutex_enter(&proclist_lock);
2261 1.1 atatat if (error)
2262 1.1 atatat goto cleanup;
2263 1.86 manu error = dcopyout(l, eproc, &dp->kp_eproc,
2264 1.73 christos sizeof(*eproc));
2265 1.1 atatat if (error)
2266 1.1 atatat goto cleanup;
2267 1.1 atatat dp++;
2268 1.1 atatat buflen -= sizeof(struct kinfo_proc);
2269 1.105.2.2 matt } else {
2270 1.105.2.2 matt mutex_exit(&p->p_mutex);
2271 1.1 atatat }
2272 1.1 atatat needed += sizeof(struct kinfo_proc);
2273 1.1 atatat } else { /* KERN_PROC2 */
2274 1.1 atatat if (buflen >= elem_size && elem_count > 0) {
2275 1.73 christos fill_kproc2(p, kproc2);
2276 1.105.2.2 matt mutex_exit(&p->p_mutex);
2277 1.105.2.2 matt mutex_exit(&proclist_lock);
2278 1.1 atatat /*
2279 1.1 atatat * Copy out elem_size, but not larger than
2280 1.1 atatat * the size of a struct kinfo_proc2.
2281 1.1 atatat */
2282 1.86 manu error = dcopyout(l, kproc2, dp2,
2283 1.73 christos min(sizeof(*kproc2), elem_size));
2284 1.105.2.2 matt mutex_enter(&proclist_lock);
2285 1.1 atatat if (error)
2286 1.1 atatat goto cleanup;
2287 1.1 atatat dp2 += elem_size;
2288 1.1 atatat buflen -= elem_size;
2289 1.1 atatat elem_count--;
2290 1.105.2.2 matt } else {
2291 1.105.2.2 matt mutex_exit(&p->p_mutex);
2292 1.1 atatat }
2293 1.1 atatat needed += elem_size;
2294 1.1 atatat }
2295 1.105.2.2 matt
2296 1.105.2.2 matt /*
2297 1.105.2.2 matt * Release reference to process.
2298 1.105.2.2 matt */
2299 1.105.2.2 matt rw_exit(&p->p_reflock);
2300 1.1 atatat }
2301 1.98 ad mutex_exit(&proclist_lock);
2302 1.1 atatat
2303 1.1 atatat if (where != NULL) {
2304 1.1 atatat if (type == KERN_PROC)
2305 1.1 atatat *oldlenp = (char *)dp - where;
2306 1.1 atatat else
2307 1.1 atatat *oldlenp = dp2 - where;
2308 1.73 christos if (needed > *oldlenp) {
2309 1.73 christos error = ENOMEM;
2310 1.73 christos goto out;
2311 1.73 christos }
2312 1.1 atatat } else {
2313 1.22 atatat needed += KERN_PROCSLOP;
2314 1.1 atatat *oldlenp = needed;
2315 1.1 atatat }
2316 1.74 christos if (kproc2)
2317 1.105.2.2 matt kmem_free(kproc2, sizeof(*kproc2));
2318 1.74 christos if (eproc)
2319 1.105.2.2 matt kmem_free(eproc, sizeof(*eproc));
2320 1.105.2.2 matt sysctl_relock();
2321 1.74 christos return 0;
2322 1.1 atatat cleanup:
2323 1.98 ad mutex_exit(&proclist_lock);
2324 1.73 christos out:
2325 1.74 christos if (kproc2)
2326 1.105.2.2 matt kmem_free(kproc2, sizeof(*kproc2));
2327 1.74 christos if (eproc)
2328 1.105.2.2 matt kmem_free(eproc, sizeof(*eproc));
2329 1.105.2.2 matt sysctl_relock();
2330 1.74 christos return error;
2331 1.1 atatat }
2332 1.1 atatat
2333 1.1 atatat /*
2334 1.1 atatat * sysctl helper routine for kern.proc_args pseudo-subtree.
2335 1.1 atatat */
2336 1.1 atatat static int
2337 1.1 atatat sysctl_kern_proc_args(SYSCTLFN_ARGS)
2338 1.1 atatat {
2339 1.1 atatat struct ps_strings pss;
2340 1.78 ad struct proc *p;
2341 1.84 manu size_t len, i;
2342 1.1 atatat struct uio auio;
2343 1.1 atatat struct iovec aiov;
2344 1.1 atatat pid_t pid;
2345 1.105.2.2 matt int nargv, type, error, argvlen;
2346 1.1 atatat char *arg;
2347 1.84 manu char **argv = NULL;
2348 1.1 atatat char *tmp;
2349 1.56 yamt struct vmspace *vmspace;
2350 1.56 yamt vaddr_t psstr_addr;
2351 1.56 yamt vaddr_t offsetn;
2352 1.56 yamt vaddr_t offsetv;
2353 1.1 atatat
2354 1.19 atatat if (namelen == 1 && name[0] == CTL_QUERY)
2355 1.43 atatat return (sysctl_query(SYSCTLFN_CALL(rnode)));
2356 1.19 atatat
2357 1.1 atatat if (newp != NULL || namelen != 2)
2358 1.1 atatat return (EINVAL);
2359 1.1 atatat pid = name[0];
2360 1.1 atatat type = name[1];
2361 1.105.2.2 matt argv = NULL;
2362 1.105.2.2 matt argvlen = 0;
2363 1.1 atatat
2364 1.1 atatat switch (type) {
2365 1.1 atatat case KERN_PROC_ARGV:
2366 1.1 atatat case KERN_PROC_NARGV:
2367 1.1 atatat case KERN_PROC_ENV:
2368 1.1 atatat case KERN_PROC_NENV:
2369 1.1 atatat /* ok */
2370 1.1 atatat break;
2371 1.1 atatat default:
2372 1.1 atatat return (EINVAL);
2373 1.1 atatat }
2374 1.1 atatat
2375 1.105.2.2 matt sysctl_unlock();
2376 1.56 yamt
2377 1.1 atatat /* check pid */
2378 1.105.2.2 matt mutex_enter(&proclist_lock);
2379 1.56 yamt if ((p = p_find(pid, PFIND_LOCKED)) == NULL) {
2380 1.56 yamt error = EINVAL;
2381 1.56 yamt goto out_locked;
2382 1.56 yamt }
2383 1.105.2.2 matt mutex_enter(&p->p_mutex);
2384 1.78 ad error = kauth_authorize_process(l->l_cred,
2385 1.71 yamt KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL);
2386 1.71 yamt if (error) {
2387 1.105.2.2 matt mutex_exit(&p->p_mutex);
2388 1.56 yamt goto out_locked;
2389 1.56 yamt }
2390 1.55 elad
2391 1.1 atatat /* only root or same user change look at the environment */
2392 1.1 atatat if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
2393 1.94 elad if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
2394 1.94 elad NULL) != 0) {
2395 1.94 elad if (kauth_cred_getuid(l->l_cred) !=
2396 1.94 elad kauth_cred_getuid(p->p_cred) ||
2397 1.94 elad kauth_cred_getuid(l->l_cred) !=
2398 1.94 elad kauth_cred_getsvuid(p->p_cred)) {
2399 1.56 yamt error = EPERM;
2400 1.105.2.2 matt mutex_exit(&p->p_mutex);
2401 1.56 yamt goto out_locked;
2402 1.94 elad }
2403 1.1 atatat }
2404 1.1 atatat }
2405 1.1 atatat
2406 1.1 atatat if (oldp == NULL) {
2407 1.1 atatat if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
2408 1.1 atatat *oldlenp = sizeof (int);
2409 1.1 atatat else
2410 1.1 atatat *oldlenp = ARG_MAX; /* XXX XXX XXX */
2411 1.56 yamt error = 0;
2412 1.105.2.2 matt mutex_exit(&p->p_mutex);
2413 1.56 yamt goto out_locked;
2414 1.1 atatat }
2415 1.1 atatat
2416 1.1 atatat /*
2417 1.1 atatat * Zombies don't have a stack, so we can't read their psstrings.
2418 1.1 atatat * System processes also don't have a user stack.
2419 1.1 atatat */
2420 1.97 pavel if (P_ZOMBIE(p) || (p->p_flag & PK_SYSTEM) != 0) {
2421 1.56 yamt error = EINVAL;
2422 1.105.2.2 matt mutex_exit(&p->p_mutex);
2423 1.56 yamt goto out_locked;
2424 1.56 yamt }
2425 1.1 atatat
2426 1.1 atatat /*
2427 1.1 atatat * Lock the process down in memory.
2428 1.1 atatat */
2429 1.56 yamt psstr_addr = (vaddr_t)p->p_psstr;
2430 1.56 yamt if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV) {
2431 1.56 yamt offsetn = p->p_psnargv;
2432 1.56 yamt offsetv = p->p_psargv;
2433 1.56 yamt } else {
2434 1.56 yamt offsetn = p->p_psnenv;
2435 1.56 yamt offsetv = p->p_psenv;
2436 1.56 yamt }
2437 1.56 yamt vmspace = p->p_vmspace;
2438 1.105.2.2 matt uvmspace_addref(vmspace);
2439 1.105.2.2 matt mutex_exit(&p->p_mutex);
2440 1.98 ad mutex_exit(&proclist_lock);
2441 1.1 atatat
2442 1.1 atatat /*
2443 1.1 atatat * Allocate a temporary buffer to hold the arguments.
2444 1.1 atatat */
2445 1.105.2.2 matt arg = kmem_alloc(PAGE_SIZE, KM_SLEEP);
2446 1.1 atatat
2447 1.1 atatat /*
2448 1.1 atatat * Read in the ps_strings structure.
2449 1.1 atatat */
2450 1.1 atatat aiov.iov_base = &pss;
2451 1.1 atatat aiov.iov_len = sizeof(pss);
2452 1.1 atatat auio.uio_iov = &aiov;
2453 1.1 atatat auio.uio_iovcnt = 1;
2454 1.56 yamt auio.uio_offset = psstr_addr;
2455 1.1 atatat auio.uio_resid = sizeof(pss);
2456 1.1 atatat auio.uio_rw = UIO_READ;
2457 1.63 yamt UIO_SETUP_SYSSPACE(&auio);
2458 1.56 yamt error = uvm_io(&vmspace->vm_map, &auio);
2459 1.1 atatat if (error)
2460 1.1 atatat goto done;
2461 1.1 atatat
2462 1.56 yamt memcpy(&nargv, (char *)&pss + offsetn, sizeof(nargv));
2463 1.1 atatat if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
2464 1.86 manu error = dcopyout(l, &nargv, oldp, sizeof(nargv));
2465 1.1 atatat *oldlenp = sizeof(nargv);
2466 1.1 atatat goto done;
2467 1.1 atatat }
2468 1.1 atatat /*
2469 1.1 atatat * Now read the address of the argument vector.
2470 1.1 atatat */
2471 1.1 atatat switch (type) {
2472 1.1 atatat case KERN_PROC_ARGV:
2473 1.56 yamt /* FALLTHROUGH */
2474 1.1 atatat case KERN_PROC_ENV:
2475 1.56 yamt memcpy(&tmp, (char *)&pss + offsetv, sizeof(tmp));
2476 1.1 atatat break;
2477 1.1 atatat default:
2478 1.105.2.2 matt error = EINVAL;
2479 1.105.2.2 matt goto done;
2480 1.1 atatat }
2481 1.82 manu
2482 1.84 manu #ifdef COMPAT_NETBSD32
2483 1.97 pavel if (p->p_flag & PK_32)
2484 1.84 manu len = sizeof(netbsd32_charp) * nargv;
2485 1.84 manu else
2486 1.84 manu #endif
2487 1.84 manu len = sizeof(char *) * nargv;
2488 1.84 manu
2489 1.105.2.2 matt argv = kmem_alloc(len, KM_SLEEP);
2490 1.105.2.2 matt argvlen = len;
2491 1.84 manu
2492 1.84 manu aiov.iov_base = argv;
2493 1.84 manu aiov.iov_len = len;
2494 1.1 atatat auio.uio_iov = &aiov;
2495 1.1 atatat auio.uio_iovcnt = 1;
2496 1.84 manu auio.uio_offset = (off_t)(unsigned long)tmp;
2497 1.84 manu auio.uio_resid = len;
2498 1.1 atatat auio.uio_rw = UIO_READ;
2499 1.63 yamt UIO_SETUP_SYSSPACE(&auio);
2500 1.56 yamt error = uvm_io(&vmspace->vm_map, &auio);
2501 1.1 atatat if (error)
2502 1.1 atatat goto done;
2503 1.1 atatat
2504 1.105.2.1 matt /*
2505 1.84 manu * Now copy each string.
2506 1.84 manu */
2507 1.84 manu len = 0; /* bytes written to user buffer */
2508 1.84 manu for (i = 0; i < nargv; i++) {
2509 1.84 manu int finished = 0;
2510 1.84 manu vaddr_t base;
2511 1.84 manu size_t xlen;
2512 1.84 manu int j;
2513 1.84 manu
2514 1.82 manu #ifdef COMPAT_NETBSD32
2515 1.97 pavel if (p->p_flag & PK_32) {
2516 1.84 manu netbsd32_charp *argv32;
2517 1.84 manu
2518 1.84 manu argv32 = (netbsd32_charp *)argv;
2519 1.84 manu
2520 1.84 manu base = (vaddr_t)NETBSD32PTR64(argv32[i]);
2521 1.84 manu } else
2522 1.82 manu #endif
2523 1.84 manu base = (vaddr_t)argv[i];
2524 1.82 manu
2525 1.105.2.1 matt /*
2526 1.105.2.1 matt * The program has messed around with its arguments,
2527 1.105.2.1 matt * possibly deleting some, and replacing them with
2528 1.105.2.1 matt * NULL's. Treat this as the last argument and not
2529 1.105.2.1 matt * a failure.
2530 1.105.2.1 matt */
2531 1.105.2.1 matt if (base == 0)
2532 1.105.2.1 matt break;
2533 1.105.2.1 matt
2534 1.84 manu while (!finished) {
2535 1.84 manu xlen = PAGE_SIZE - (base & PAGE_MASK);
2536 1.1 atatat
2537 1.84 manu aiov.iov_base = arg;
2538 1.84 manu aiov.iov_len = PAGE_SIZE;
2539 1.84 manu auio.uio_iov = &aiov;
2540 1.84 manu auio.uio_iovcnt = 1;
2541 1.84 manu auio.uio_offset = base;
2542 1.84 manu auio.uio_resid = xlen;
2543 1.84 manu auio.uio_rw = UIO_READ;
2544 1.84 manu UIO_SETUP_SYSSPACE(&auio);
2545 1.84 manu error = uvm_io(&vmspace->vm_map, &auio);
2546 1.84 manu if (error)
2547 1.84 manu goto done;
2548 1.1 atatat
2549 1.84 manu /* Look for the end of the string */
2550 1.84 manu for (j = 0; j < xlen; j++) {
2551 1.84 manu if (arg[j] == '\0') {
2552 1.84 manu xlen = j + 1;
2553 1.84 manu finished = 1;
2554 1.84 manu break;
2555 1.84 manu }
2556 1.84 manu }
2557 1.1 atatat
2558 1.84 manu /* Check for user buffer overflow */
2559 1.84 manu if (len + xlen > *oldlenp) {
2560 1.84 manu finished = 1;
2561 1.105.2.1 matt if (len > *oldlenp)
2562 1.84 manu xlen = 0;
2563 1.84 manu else
2564 1.84 manu xlen = *oldlenp - len;
2565 1.84 manu }
2566 1.105.2.1 matt
2567 1.84 manu /* Copyout the page */
2568 1.86 manu error = dcopyout(l, arg, (char *)oldp + len, xlen);
2569 1.84 manu if (error)
2570 1.84 manu goto done;
2571 1.1 atatat
2572 1.84 manu len += xlen;
2573 1.84 manu base += xlen;
2574 1.1 atatat }
2575 1.1 atatat }
2576 1.1 atatat *oldlenp = len;
2577 1.1 atatat
2578 1.1 atatat done:
2579 1.84 manu if (argv != NULL)
2580 1.105.2.2 matt kmem_free(argv, argvlen);
2581 1.56 yamt uvmspace_free(vmspace);
2582 1.105.2.2 matt kmem_free(arg, PAGE_SIZE);
2583 1.105.2.2 matt sysctl_relock();
2584 1.56 yamt return error;
2585 1.56 yamt
2586 1.56 yamt out_locked:
2587 1.98 ad mutex_exit(&proclist_lock);
2588 1.105.2.2 matt sysctl_relock();
2589 1.56 yamt return error;
2590 1.1 atatat }
2591 1.1 atatat
2592 1.61 elad static int
2593 1.61 elad sysctl_security_setidcore(SYSCTLFN_ARGS)
2594 1.61 elad {
2595 1.61 elad int newsize, error;
2596 1.61 elad struct sysctlnode node;
2597 1.61 elad
2598 1.61 elad node = *rnode;
2599 1.61 elad node.sysctl_data = &newsize;
2600 1.61 elad newsize = *(int *)rnode->sysctl_data;
2601 1.61 elad error = sysctl_lookup(SYSCTLFN_CALL(&node));
2602 1.61 elad if (error || newp == NULL)
2603 1.61 elad return error;
2604 1.61 elad
2605 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
2606 1.85 elad 0, NULL, NULL, NULL))
2607 1.61 elad return (EPERM);
2608 1.61 elad
2609 1.61 elad *(int *)rnode->sysctl_data = newsize;
2610 1.61 elad
2611 1.61 elad return 0;
2612 1.61 elad }
2613 1.61 elad
2614 1.61 elad static int
2615 1.61 elad sysctl_security_setidcorename(SYSCTLFN_ARGS)
2616 1.61 elad {
2617 1.61 elad int error;
2618 1.72 yamt char *newsetidcorename;
2619 1.61 elad struct sysctlnode node;
2620 1.61 elad
2621 1.72 yamt newsetidcorename = PNBUF_GET();
2622 1.61 elad node = *rnode;
2623 1.72 yamt node.sysctl_data = newsetidcorename;
2624 1.61 elad memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
2625 1.61 elad error = sysctl_lookup(SYSCTLFN_CALL(&node));
2626 1.72 yamt if (error || newp == NULL) {
2627 1.72 yamt goto out;
2628 1.72 yamt }
2629 1.83 elad if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
2630 1.85 elad 0, NULL, NULL, NULL)) {
2631 1.72 yamt error = EPERM;
2632 1.72 yamt goto out;
2633 1.72 yamt }
2634 1.72 yamt if (strlen(newsetidcorename) == 0) {
2635 1.72 yamt error = EINVAL;
2636 1.72 yamt goto out;
2637 1.72 yamt }
2638 1.61 elad memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
2639 1.72 yamt out:
2640 1.72 yamt PNBUF_PUT(newsetidcorename);
2641 1.72 yamt return error;
2642 1.61 elad }
2643 1.61 elad
2644 1.38 elad /*
2645 1.105.2.1 matt * sysctl helper routine for kern.cp_id node. Maps cpus to their
2646 1.45 christos * cpuids.
2647 1.45 christos */
2648 1.45 christos static int
2649 1.45 christos sysctl_kern_cpid(SYSCTLFN_ARGS)
2650 1.45 christos {
2651 1.45 christos struct sysctlnode node = *rnode;
2652 1.59 perry uint64_t *cp_id = NULL;
2653 1.96 ad int error, n = ncpu;
2654 1.45 christos struct cpu_info *ci;
2655 1.45 christos CPU_INFO_ITERATOR cii;
2656 1.45 christos
2657 1.45 christos /*
2658 1.105.2.1 matt * Here you may either retrieve a single cpu id or the whole
2659 1.105.2.1 matt * set. The size you get back when probing depends on what
2660 1.46 atatat * you ask for.
2661 1.45 christos */
2662 1.45 christos switch (namelen) {
2663 1.45 christos case 0:
2664 1.59 perry node.sysctl_size = n * sizeof(uint64_t);
2665 1.45 christos n = -2; /* ALL */
2666 1.45 christos break;
2667 1.45 christos case 1:
2668 1.45 christos if (name[0] < 0 || name[0] >= n)
2669 1.45 christos return (ENOENT); /* ENOSUCHPROCESSOR */
2670 1.59 perry node.sysctl_size = sizeof(uint64_t);
2671 1.45 christos n = name[0];
2672 1.45 christos /*
2673 1.45 christos * adjust these so that sysctl_lookup() will be happy
2674 1.45 christos */
2675 1.45 christos name++;
2676 1.45 christos namelen--;
2677 1.45 christos break;
2678 1.45 christos default:
2679 1.45 christos return (EINVAL);
2680 1.45 christos }
2681 1.45 christos
2682 1.105.2.2 matt cp_id = kmem_alloc(node.sysctl_size, KM_SLEEP);
2683 1.45 christos if (cp_id == NULL)
2684 1.45 christos return (ENOMEM);
2685 1.45 christos node.sysctl_data = cp_id;
2686 1.45 christos memset(cp_id, 0, node.sysctl_size);
2687 1.45 christos
2688 1.45 christos for (CPU_INFO_FOREACH(cii, ci)) {
2689 1.45 christos if (n <= 0)
2690 1.45 christos cp_id[0] = ci->ci_cpuid;
2691 1.45 christos /*
2692 1.45 christos * if a specific processor was requested and we just
2693 1.45 christos * did it, we're done here
2694 1.45 christos */
2695 1.45 christos if (n == 0)
2696 1.45 christos break;
2697 1.45 christos /*
2698 1.45 christos * if doing "all", skip to next cp_id slot for next processor
2699 1.45 christos */
2700 1.45 christos if (n == -2)
2701 1.45 christos cp_id++;
2702 1.45 christos /*
2703 1.45 christos * if we're doing a specific processor, we're one
2704 1.45 christos * processor closer
2705 1.45 christos */
2706 1.45 christos if (n > 0)
2707 1.45 christos n--;
2708 1.45 christos }
2709 1.45 christos
2710 1.45 christos error = sysctl_lookup(SYSCTLFN_CALL(&node));
2711 1.105.2.2 matt kmem_free(node.sysctl_data, node.sysctl_size);
2712 1.45 christos return (error);
2713 1.45 christos }
2714 1.45 christos
2715 1.45 christos /*
2716 1.105.2.1 matt * sysctl helper routine for hw.usermem and hw.usermem64. Values are
2717 1.1 atatat * calculate on the fly taking into account integer overflow and the
2718 1.1 atatat * current wired count.
2719 1.1 atatat */
2720 1.1 atatat static int
2721 1.1 atatat sysctl_hw_usermem(SYSCTLFN_ARGS)
2722 1.1 atatat {
2723 1.1 atatat u_int ui;
2724 1.1 atatat u_quad_t uq;
2725 1.1 atatat struct sysctlnode node;
2726 1.1 atatat
2727 1.1 atatat node = *rnode;
2728 1.1 atatat switch (rnode->sysctl_num) {
2729 1.1 atatat case HW_USERMEM:
2730 1.1 atatat if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
2731 1.1 atatat ui = UINT_MAX;
2732 1.1 atatat else
2733 1.1 atatat ui *= PAGE_SIZE;
2734 1.1 atatat node.sysctl_data = &ui;
2735 1.1 atatat break;
2736 1.1 atatat case HW_USERMEM64:
2737 1.1 atatat uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
2738 1.1 atatat node.sysctl_data = &uq;
2739 1.1 atatat break;
2740 1.1 atatat default:
2741 1.1 atatat return (EINVAL);
2742 1.1 atatat }
2743 1.1 atatat
2744 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2745 1.1 atatat }
2746 1.1 atatat
2747 1.1 atatat /*
2748 1.105.2.1 matt * sysctl helper routine for kern.cnmagic node. Pulls the old value
2749 1.1 atatat * out, encoded, and stuffs the new value in for decoding.
2750 1.1 atatat */
2751 1.1 atatat static int
2752 1.1 atatat sysctl_hw_cnmagic(SYSCTLFN_ARGS)
2753 1.1 atatat {
2754 1.1 atatat char magic[CNS_LEN];
2755 1.1 atatat int error;
2756 1.1 atatat struct sysctlnode node;
2757 1.1 atatat
2758 1.1 atatat if (oldp)
2759 1.1 atatat cn_get_magic(magic, CNS_LEN);
2760 1.1 atatat node = *rnode;
2761 1.1 atatat node.sysctl_data = &magic[0];
2762 1.1 atatat error = sysctl_lookup(SYSCTLFN_CALL(&node));
2763 1.1 atatat if (error || newp == NULL)
2764 1.1 atatat return (error);
2765 1.33 perry
2766 1.1 atatat return (cn_set_magic(magic));
2767 1.1 atatat }
2768 1.3 martin
2769 1.1 atatat /*
2770 1.1 atatat * ********************************************************************
2771 1.1 atatat * section 3: public helper routines that are used for more than one
2772 1.1 atatat * node
2773 1.1 atatat * ********************************************************************
2774 1.1 atatat */
2775 1.1 atatat
2776 1.1 atatat /*
2777 1.1 atatat * sysctl helper routine for the kern.root_device node and some ports'
2778 1.1 atatat * machdep.root_device nodes.
2779 1.1 atatat */
2780 1.1 atatat int
2781 1.1 atatat sysctl_root_device(SYSCTLFN_ARGS)
2782 1.1 atatat {
2783 1.1 atatat struct sysctlnode node;
2784 1.1 atatat
2785 1.1 atatat node = *rnode;
2786 1.1 atatat node.sysctl_data = root_device->dv_xname;
2787 1.1 atatat node.sysctl_size = strlen(root_device->dv_xname) + 1;
2788 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2789 1.1 atatat }
2790 1.1 atatat
2791 1.1 atatat /*
2792 1.1 atatat * sysctl helper routine for kern.consdev, dependent on the current
2793 1.105.2.1 matt * state of the console. Also used for machdep.console_device on some
2794 1.1 atatat * ports.
2795 1.1 atatat */
2796 1.1 atatat int
2797 1.1 atatat sysctl_consdev(SYSCTLFN_ARGS)
2798 1.1 atatat {
2799 1.1 atatat dev_t consdev;
2800 1.1 atatat struct sysctlnode node;
2801 1.1 atatat
2802 1.1 atatat if (cn_tab != NULL)
2803 1.1 atatat consdev = cn_tab->cn_dev;
2804 1.1 atatat else
2805 1.1 atatat consdev = NODEV;
2806 1.1 atatat node = *rnode;
2807 1.1 atatat node.sysctl_data = &consdev;
2808 1.1 atatat node.sysctl_size = sizeof(consdev);
2809 1.1 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2810 1.1 atatat }
2811 1.1 atatat
2812 1.1 atatat /*
2813 1.1 atatat * ********************************************************************
2814 1.1 atatat * section 4: support for some helpers
2815 1.1 atatat * ********************************************************************
2816 1.1 atatat */
2817 1.1 atatat
2818 1.1 atatat /*
2819 1.1 atatat * Fill in a kinfo_proc2 structure for the specified process.
2820 1.1 atatat */
2821 1.1 atatat static void
2822 1.1 atatat fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
2823 1.1 atatat {
2824 1.1 atatat struct tty *tp;
2825 1.95 ad struct lwp *l, *l2;
2826 1.95 ad struct timeval ut, st, rt;
2827 1.95 ad sigset_t ss1, ss2;
2828 1.1 atatat
2829 1.105.2.2 matt KASSERT(mutex_owned(&proclist_lock));
2830 1.105.2.2 matt KASSERT(mutex_owned(&p->p_mutex));
2831 1.105.2.2 matt
2832 1.1 atatat memset(ki, 0, sizeof(*ki));
2833 1.1 atatat
2834 1.21 atatat ki->p_paddr = PTRTOUINT64(p);
2835 1.21 atatat ki->p_fd = PTRTOUINT64(p->p_fd);
2836 1.21 atatat ki->p_cwdi = PTRTOUINT64(p->p_cwdi);
2837 1.21 atatat ki->p_stats = PTRTOUINT64(p->p_stats);
2838 1.21 atatat ki->p_limit = PTRTOUINT64(p->p_limit);
2839 1.21 atatat ki->p_vmspace = PTRTOUINT64(p->p_vmspace);
2840 1.21 atatat ki->p_sigacts = PTRTOUINT64(p->p_sigacts);
2841 1.21 atatat ki->p_sess = PTRTOUINT64(p->p_session);
2842 1.1 atatat ki->p_tsess = 0; /* may be changed if controlling tty below */
2843 1.100 dsl ki->p_ru = PTRTOUINT64(&p->p_stats->p_ru);
2844 1.1 atatat
2845 1.1 atatat ki->p_eflag = 0;
2846 1.1 atatat ki->p_exitsig = p->p_exitsig;
2847 1.95 ad
2848 1.95 ad ki->p_flag = sysctl_map_flags(sysctl_flagmap, p->p_flag);
2849 1.95 ad ki->p_flag |= sysctl_map_flags(sysctl_sflagmap, p->p_sflag);
2850 1.95 ad ki->p_flag |= sysctl_map_flags(sysctl_slflagmap, p->p_slflag);
2851 1.95 ad ki->p_flag |= sysctl_map_flags(sysctl_lflagmap, p->p_lflag);
2852 1.95 ad ki->p_flag |= sysctl_map_flags(sysctl_stflagmap, p->p_stflag);
2853 1.1 atatat
2854 1.1 atatat ki->p_pid = p->p_pid;
2855 1.1 atatat if (p->p_pptr)
2856 1.1 atatat ki->p_ppid = p->p_pptr->p_pid;
2857 1.1 atatat else
2858 1.1 atatat ki->p_ppid = 0;
2859 1.1 atatat ki->p_sid = p->p_session->s_sid;
2860 1.1 atatat ki->p__pgid = p->p_pgrp->pg_id;
2861 1.1 atatat
2862 1.1 atatat ki->p_tpgid = NO_PGID; /* may be changed if controlling tty below */
2863 1.1 atatat
2864 1.68 elad ki->p_uid = kauth_cred_geteuid(p->p_cred);
2865 1.68 elad ki->p_ruid = kauth_cred_getuid(p->p_cred);
2866 1.68 elad ki->p_gid = kauth_cred_getegid(p->p_cred);
2867 1.68 elad ki->p_rgid = kauth_cred_getgid(p->p_cred);
2868 1.68 elad ki->p_svuid = kauth_cred_getsvuid(p->p_cred);
2869 1.68 elad ki->p_svgid = kauth_cred_getsvgid(p->p_cred);
2870 1.68 elad
2871 1.68 elad ki->p_ngroups = kauth_cred_ngroups(p->p_cred);
2872 1.68 elad kauth_cred_getgroups(p->p_cred, ki->p_groups,
2873 1.102 dsl min(ki->p_ngroups, sizeof(ki->p_groups) / sizeof(ki->p_groups[0])),
2874 1.102 dsl UIO_SYSSPACE);
2875 1.1 atatat
2876 1.1 atatat ki->p_jobc = p->p_pgrp->pg_jobc;
2877 1.95 ad if ((p->p_lflag & PL_CONTROLT) && (tp = p->p_session->s_ttyp)) {
2878 1.1 atatat ki->p_tdev = tp->t_dev;
2879 1.1 atatat ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
2880 1.21 atatat ki->p_tsess = PTRTOUINT64(tp->t_session);
2881 1.1 atatat } else {
2882 1.1 atatat ki->p_tdev = NODEV;
2883 1.1 atatat }
2884 1.1 atatat
2885 1.101 yamt mutex_enter(&p->p_smutex);
2886 1.1 atatat
2887 1.1 atatat ki->p_uticks = p->p_uticks;
2888 1.1 atatat ki->p_sticks = p->p_sticks;
2889 1.1 atatat ki->p_iticks = p->p_iticks;
2890 1.1 atatat
2891 1.21 atatat ki->p_tracep = PTRTOUINT64(p->p_tracep);
2892 1.1 atatat ki->p_traceflag = p->p_traceflag;
2893 1.1 atatat
2894 1.1 atatat memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
2895 1.1 atatat memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
2896 1.1 atatat
2897 1.101 yamt ki->p_cpticks = 0;
2898 1.101 yamt ki->p_pctcpu = p->p_pctcpu;
2899 1.105.2.1 matt ki->p_estcpu = 0;
2900 1.95 ad ss1 = p->p_sigpend.sp_set;
2901 1.95 ad LIST_FOREACH(l, &p->p_lwps, l_sibling) {
2902 1.95 ad /* This is hardly correct, but... */
2903 1.95 ad sigplusset(&l->l_sigpend.sp_set, &ss1);
2904 1.95 ad sigplusset(&l->l_sigmask, &ss2);
2905 1.101 yamt ki->p_cpticks += l->l_cpticks;
2906 1.101 yamt ki->p_pctcpu += l->l_pctcpu;
2907 1.105.2.1 matt ki->p_estcpu += l->l_estcpu;
2908 1.95 ad }
2909 1.95 ad memcpy(&ki->p_siglist, &ss1, sizeof(ki_sigset_t));
2910 1.95 ad memcpy(&ki->p_sigmask, &ss2, sizeof(ki_sigset_t));
2911 1.95 ad
2912 1.1 atatat ki->p_stat = p->p_stat; /* Will likely be overridden by LWP status */
2913 1.1 atatat ki->p_realstat = p->p_stat;
2914 1.1 atatat ki->p_nice = p->p_nice;
2915 1.1 atatat
2916 1.1 atatat ki->p_xstat = p->p_xstat;
2917 1.1 atatat ki->p_acflag = p->p_acflag;
2918 1.1 atatat
2919 1.1 atatat strncpy(ki->p_comm, p->p_comm,
2920 1.1 atatat min(sizeof(ki->p_comm), sizeof(p->p_comm)));
2921 1.1 atatat
2922 1.1 atatat strncpy(ki->p_login, p->p_session->s_login,
2923 1.1 atatat min(sizeof ki->p_login - 1, sizeof p->p_session->s_login));
2924 1.1 atatat
2925 1.1 atatat ki->p_nlwps = p->p_nlwps;
2926 1.95 ad ki->p_realflag = ki->p_flag;
2927 1.1 atatat
2928 1.1 atatat if (p->p_stat == SIDL || P_ZOMBIE(p)) {
2929 1.1 atatat ki->p_vm_rssize = 0;
2930 1.1 atatat ki->p_vm_tsize = 0;
2931 1.1 atatat ki->p_vm_dsize = 0;
2932 1.1 atatat ki->p_vm_ssize = 0;
2933 1.95 ad ki->p_nrlwps = 0;
2934 1.1 atatat l = NULL;
2935 1.1 atatat } else {
2936 1.1 atatat struct vmspace *vm = p->p_vmspace;
2937 1.95 ad int tmp;
2938 1.1 atatat
2939 1.1 atatat ki->p_vm_rssize = vm_resident_count(vm);
2940 1.1 atatat ki->p_vm_tsize = vm->vm_tsize;
2941 1.1 atatat ki->p_vm_dsize = vm->vm_dsize;
2942 1.1 atatat ki->p_vm_ssize = vm->vm_ssize;
2943 1.1 atatat
2944 1.1 atatat /* Pick a "representative" LWP */
2945 1.95 ad l = proc_representative_lwp(p, &tmp, 1);
2946 1.95 ad lwp_lock(l);
2947 1.95 ad ki->p_nrlwps = tmp;
2948 1.101 yamt ki->p_forw = 0;
2949 1.101 yamt ki->p_back = 0;
2950 1.21 atatat ki->p_addr = PTRTOUINT64(l->l_addr);
2951 1.1 atatat ki->p_stat = l->l_stat;
2952 1.95 ad ki->p_flag |= sysctl_map_flags(sysctl_lwpflagmap, l->l_flag);
2953 1.1 atatat ki->p_swtime = l->l_swtime;
2954 1.1 atatat ki->p_slptime = l->l_slptime;
2955 1.95 ad if (l->l_stat == LSONPROC)
2956 1.1 atatat ki->p_schedflags = l->l_cpu->ci_schedstate.spc_flags;
2957 1.95 ad else
2958 1.1 atatat ki->p_schedflags = 0;
2959 1.1 atatat ki->p_holdcnt = l->l_holdcnt;
2960 1.105.2.1 matt ki->p_priority = lwp_eprio(l);
2961 1.105.2.1 matt ki->p_usrpri = l->l_priority;
2962 1.1 atatat if (l->l_wmesg)
2963 1.1 atatat strncpy(ki->p_wmesg, l->l_wmesg, sizeof(ki->p_wmesg));
2964 1.21 atatat ki->p_wchan = PTRTOUINT64(l->l_wchan);
2965 1.95 ad lwp_unlock(l);
2966 1.1 atatat }
2967 1.1 atatat if (p->p_session->s_ttyvp)
2968 1.1 atatat ki->p_eflag |= EPROC_CTTY;
2969 1.1 atatat if (SESS_LEADER(p))
2970 1.1 atatat ki->p_eflag |= EPROC_SLEADER;
2971 1.1 atatat
2972 1.1 atatat /* XXX Is this double check necessary? */
2973 1.1 atatat if (P_ZOMBIE(p)) {
2974 1.1 atatat ki->p_uvalid = 0;
2975 1.95 ad ki->p_rtime_sec = 0;
2976 1.95 ad ki->p_rtime_usec = 0;
2977 1.1 atatat } else {
2978 1.1 atatat ki->p_uvalid = 1;
2979 1.1 atatat
2980 1.1 atatat ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
2981 1.1 atatat ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
2982 1.1 atatat
2983 1.95 ad calcru(p, &ut, &st, NULL, &rt);
2984 1.95 ad ki->p_rtime_sec = rt.tv_sec;
2985 1.95 ad ki->p_rtime_usec = rt.tv_usec;
2986 1.1 atatat ki->p_uutime_sec = ut.tv_sec;
2987 1.1 atatat ki->p_uutime_usec = ut.tv_usec;
2988 1.1 atatat ki->p_ustime_sec = st.tv_sec;
2989 1.1 atatat ki->p_ustime_usec = st.tv_usec;
2990 1.1 atatat
2991 1.1 atatat ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
2992 1.1 atatat ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
2993 1.1 atatat ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
2994 1.1 atatat ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
2995 1.1 atatat ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
2996 1.1 atatat ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
2997 1.1 atatat ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
2998 1.1 atatat ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
2999 1.1 atatat ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
3000 1.1 atatat ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
3001 1.1 atatat ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
3002 1.1 atatat ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
3003 1.95 ad
3004 1.95 ad ki->p_uru_nvcsw = 0;
3005 1.95 ad ki->p_uru_nivcsw = 0;
3006 1.95 ad LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
3007 1.101 yamt ki->p_uru_nvcsw += (l->l_ncsw - l->l_nivcsw);
3008 1.95 ad ki->p_uru_nivcsw += l->l_nivcsw;
3009 1.95 ad }
3010 1.1 atatat
3011 1.1 atatat timeradd(&p->p_stats->p_cru.ru_utime,
3012 1.1 atatat &p->p_stats->p_cru.ru_stime, &ut);
3013 1.1 atatat ki->p_uctime_sec = ut.tv_sec;
3014 1.1 atatat ki->p_uctime_usec = ut.tv_usec;
3015 1.1 atatat }
3016 1.95 ad if (l != NULL)
3017 1.1 atatat ki->p_cpuid = l->l_cpu->ci_cpuid;
3018 1.95 ad
3019 1.95 ad mutex_exit(&p->p_smutex);
3020 1.1 atatat }
3021 1.1 atatat
3022 1.1 atatat /*
3023 1.1 atatat * Fill in a kinfo_lwp structure for the specified lwp.
3024 1.1 atatat */
3025 1.1 atatat static void
3026 1.1 atatat fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
3027 1.1 atatat {
3028 1.101 yamt struct proc *p = l->l_proc;
3029 1.105.2.2 matt struct timeval tv;
3030 1.1 atatat
3031 1.101 yamt kl->l_forw = 0;
3032 1.101 yamt kl->l_back = 0;
3033 1.21 atatat kl->l_laddr = PTRTOUINT64(l);
3034 1.21 atatat kl->l_addr = PTRTOUINT64(l->l_addr);
3035 1.1 atatat kl->l_stat = l->l_stat;
3036 1.1 atatat kl->l_lid = l->l_lid;
3037 1.95 ad kl->l_flag = sysctl_map_flags(sysctl_lwpprflagmap, l->l_prflag);
3038 1.1 atatat
3039 1.1 atatat kl->l_swtime = l->l_swtime;
3040 1.1 atatat kl->l_slptime = l->l_slptime;
3041 1.95 ad if (l->l_stat == LSONPROC)
3042 1.1 atatat kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
3043 1.95 ad else
3044 1.1 atatat kl->l_schedflags = 0;
3045 1.1 atatat kl->l_holdcnt = l->l_holdcnt;
3046 1.105.2.1 matt kl->l_priority = lwp_eprio(l);
3047 1.105.2.1 matt kl->l_usrpri = l->l_priority;
3048 1.1 atatat if (l->l_wmesg)
3049 1.1 atatat strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
3050 1.21 atatat kl->l_wchan = PTRTOUINT64(l->l_wchan);
3051 1.95 ad kl->l_cpuid = l->l_cpu->ci_cpuid;
3052 1.105.2.2 matt bintime2timeval(&l->l_rtime, &tv);
3053 1.105.2.2 matt kl->l_rtime_sec = tv.tv_sec;
3054 1.105.2.2 matt kl->l_rtime_usec = tv.tv_usec;
3055 1.101 yamt kl->l_cpticks = l->l_cpticks;
3056 1.101 yamt kl->l_pctcpu = l->l_pctcpu;
3057 1.101 yamt kl->l_pid = p->p_pid;
3058 1.101 yamt if (l->l_name == NULL)
3059 1.101 yamt kl->l_name[0] = '\0';
3060 1.101 yamt else
3061 1.101 yamt strlcpy(kl->l_name, l->l_name, sizeof(kl->l_name));
3062 1.1 atatat }
3063 1.1 atatat
3064 1.1 atatat /*
3065 1.1 atatat * Fill in an eproc structure for the specified process.
3066 1.1 atatat */
3067 1.1 atatat void
3068 1.1 atatat fill_eproc(struct proc *p, struct eproc *ep)
3069 1.1 atatat {
3070 1.1 atatat struct tty *tp;
3071 1.1 atatat struct lwp *l;
3072 1.1 atatat
3073 1.105.2.2 matt KASSERT(mutex_owned(&proclist_lock));
3074 1.105.2.2 matt KASSERT(mutex_owned(&p->p_mutex));
3075 1.105.2.2 matt
3076 1.1 atatat ep->e_paddr = p;
3077 1.1 atatat ep->e_sess = p->p_session;
3078 1.77 ad kauth_cred_topcred(p->p_cred, &ep->e_pcred);
3079 1.77 ad kauth_cred_toucred(p->p_cred, &ep->e_ucred);
3080 1.1 atatat if (p->p_stat == SIDL || P_ZOMBIE(p)) {
3081 1.1 atatat ep->e_vm.vm_rssize = 0;
3082 1.1 atatat ep->e_vm.vm_tsize = 0;
3083 1.1 atatat ep->e_vm.vm_dsize = 0;
3084 1.1 atatat ep->e_vm.vm_ssize = 0;
3085 1.1 atatat /* ep->e_vm.vm_pmap = XXX; */
3086 1.1 atatat } else {
3087 1.1 atatat struct vmspace *vm = p->p_vmspace;
3088 1.1 atatat
3089 1.1 atatat ep->e_vm.vm_rssize = vm_resident_count(vm);
3090 1.1 atatat ep->e_vm.vm_tsize = vm->vm_tsize;
3091 1.1 atatat ep->e_vm.vm_dsize = vm->vm_dsize;
3092 1.1 atatat ep->e_vm.vm_ssize = vm->vm_ssize;
3093 1.1 atatat
3094 1.1 atatat /* Pick a "representative" LWP */
3095 1.95 ad mutex_enter(&p->p_smutex);
3096 1.95 ad l = proc_representative_lwp(p, NULL, 1);
3097 1.95 ad lwp_lock(l);
3098 1.1 atatat if (l->l_wmesg)
3099 1.1 atatat strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN);
3100 1.95 ad lwp_unlock(l);
3101 1.95 ad mutex_exit(&p->p_smutex);
3102 1.1 atatat }
3103 1.1 atatat if (p->p_pptr)
3104 1.1 atatat ep->e_ppid = p->p_pptr->p_pid;
3105 1.1 atatat else
3106 1.1 atatat ep->e_ppid = 0;
3107 1.1 atatat ep->e_pgid = p->p_pgrp->pg_id;
3108 1.1 atatat ep->e_sid = ep->e_sess->s_sid;
3109 1.1 atatat ep->e_jobc = p->p_pgrp->pg_jobc;
3110 1.95 ad if ((p->p_lflag & PL_CONTROLT) &&
3111 1.1 atatat (tp = ep->e_sess->s_ttyp)) {
3112 1.1 atatat ep->e_tdev = tp->t_dev;
3113 1.1 atatat ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
3114 1.1 atatat ep->e_tsess = tp->t_session;
3115 1.1 atatat } else
3116 1.1 atatat ep->e_tdev = NODEV;
3117 1.1 atatat
3118 1.1 atatat ep->e_xsize = ep->e_xrssize = 0;
3119 1.1 atatat ep->e_xccount = ep->e_xswrss = 0;
3120 1.1 atatat ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
3121 1.1 atatat if (SESS_LEADER(p))
3122 1.1 atatat ep->e_flag |= EPROC_SLEADER;
3123 1.1 atatat strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
3124 1.1 atatat }
3125 1.95 ad
3126 1.95 ad u_int
3127 1.95 ad sysctl_map_flags(const u_int *map, u_int word)
3128 1.95 ad {
3129 1.95 ad u_int rv;
3130 1.95 ad
3131 1.95 ad for (rv = 0; *map != 0; map += 2)
3132 1.95 ad if ((word & map[0]) != 0)
3133 1.95 ad rv |= map[1];
3134 1.95 ad
3135 1.95 ad return rv;
3136 1.95 ad }
3137