Mon May 4 14:52:33 2009 UTC ()
sysctl_doeproc: fix a bug in rev.1.135.
don't forget to mark our marker process PK_MARKER.
this fixes crashes in sched_pstats, etc.


(yamt)
diff -r1.160 -r1.161 src/sys/kern/init_sysctl.c

cvs diff -r1.160 -r1.161 src/sys/kern/init_sysctl.c (switch to unified diff)

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