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