Sun Mar 15 20:20:03 2009 UTC ()
Pull up following revision(s) (requested by mrg in ticket #565):
	sys/kern/init_sysctl.c: revision 1.158
always calculate "needed" for KERN_FILE2 calls.  this allows a caller
to get an estimate of the needed space, like the intention is.


(snj)
diff -r1.149.4.1 -r1.149.4.2 src/sys/kern/init_sysctl.c

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

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