xref: /openbsd/sys/sys/sysctl.h (revision b3802834)
1 /*	$OpenBSD: sysctl.h,v 1.240 2024/11/04 11:49:19 jsg Exp $	*/
2 /*	$NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Mike Karels at Berkeley Software Design, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)sysctl.h	8.2 (Berkeley) 3/30/95
36  */
37 
38 #ifndef _SYS_SYSCTL_H_
39 #define	_SYS_SYSCTL_H_
40 
41 #include <sys/syslimits.h>
42 #include <uvm/uvmexp.h>
43 
44 /*
45  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
46  * for objects that can be examined or modified.  The name is expressed as
47  * a sequence of integers.  Like a file path name, the meaning of each
48  * component depends on its place in the hierarchy.  The top-level and kern
49  * identifiers are defined here, and other identifiers are defined in the
50  * respective subsystem header files.
51  */
52 
53 #define	CTL_MAXNAME	12	/* largest number of components supported */
54 
55 /*
56  * Each subsystem defined by sysctl defines a list of variables
57  * for that subsystem. Each name is either a node with further
58  * levels defined below it, or it is a leaf of some particular
59  * type given below. Each sysctl level defines a set of name/type
60  * pairs to be used by sysctl(1) in manipulating the subsystem.
61  */
62 struct ctlname {
63 	char	*ctl_name;	/* subsystem name */
64 	int	ctl_type;	/* type of name */
65 };
66 #define	CTLTYPE_NODE	1	/* name is a node */
67 #define	CTLTYPE_INT	2	/* name describes an integer */
68 #define	CTLTYPE_STRING	3	/* name describes a string */
69 #define	CTLTYPE_QUAD	4	/* name describes a 64-bit number */
70 #define	CTLTYPE_STRUCT	5	/* name describes a structure */
71 
72 /*
73  * Top-level identifiers
74  */
75 #define	CTL_UNSPEC	0		/* unused */
76 #define	CTL_KERN	1		/* "high kernel": proc, limits */
77 #define	CTL_VM		2		/* virtual memory */
78 #define	CTL_FS		3		/* file system, mount type is next */
79 #define	CTL_NET		4		/* network, see socket.h */
80 #define	CTL_DEBUG	5		/* debugging parameters */
81 #define	CTL_HW		6		/* generic cpu/io */
82 #define	CTL_MACHDEP	7		/* machine dependent */
83 /*define gap		8		   was CTL_USER: removed 2013-04 */
84 #define	CTL_DDB		9		/* DDB user interface, see db_var.h */
85 #define	CTL_VFS		10		/* VFS sysctl's */
86 #define	CTL_MAXID	11		/* number of valid top-level ids */
87 
88 #define	CTL_NAMES { \
89 	{ 0, 0 }, \
90 	{ "kern", CTLTYPE_NODE }, \
91 	{ "vm", CTLTYPE_NODE }, \
92 	{ "fs", CTLTYPE_NODE }, \
93 	{ "net", CTLTYPE_NODE }, \
94 	{ "debug", CTLTYPE_NODE }, \
95 	{ "hw", CTLTYPE_NODE }, \
96 	{ "machdep", CTLTYPE_NODE }, \
97 	{ "gap", 0 }, \
98 	{ "ddb", CTLTYPE_NODE }, \
99 	{ "vfs", CTLTYPE_NODE }, \
100 }
101 
102 /*
103  * CTL_KERN identifiers
104  */
105 #define	KERN_OSTYPE	 	 1	/* string: system version */
106 #define	KERN_OSRELEASE	 	 2	/* string: system release */
107 #define	KERN_OSREV	 	 3	/* int: system revision */
108 #define	KERN_VERSION	 	 4	/* string: compile time info */
109 #define	KERN_MAXVNODES	 	 5	/* int: max vnodes */
110 #define	KERN_MAXPROC	 	 6	/* int: max processes */
111 #define	KERN_MAXFILES	 	 7	/* int: max open files */
112 #define	KERN_ARGMAX	 	 8	/* int: max arguments to exec */
113 #define	KERN_SECURELVL	 	 9	/* int: system security level */
114 #define	KERN_HOSTNAME		10	/* string: hostname */
115 #define	KERN_HOSTID		11	/* int: host identifier */
116 #define	KERN_CLOCKRATE		12	/* struct: struct clockinfo */
117 /* was KERN_DNSJACKPORT		13	*/
118 /* was KERN_PROC		14	*/
119 /* was KERN_FILE		15	*/
120 #define	KERN_PROF		16	/* node: kernel profiling info */
121 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
122 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
123 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
124 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
125 #define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
126 #define	KERN_DOMAINNAME		22	/* string: (YP) domainname */
127 #define	KERN_MAXPARTITIONS	23	/* int: number of partitions/disk */
128 #define	KERN_RAWPARTITION	24	/* int: raw partition number */
129 #define	KERN_MAXTHREAD	 	25	/* int: max threads */
130 #define	KERN_NTHREADS		26	/* int: number of threads */
131 #define	KERN_OSVERSION		27	/* string: kernel build version */
132 #define	KERN_SOMAXCONN		28	/* int: listen queue maximum */
133 #define	KERN_SOMINCONN		29	/* int: half-open controllable param */
134 /* was KERN_USERMOUNT		30	*/
135 /* was KERN_RND	31			*/
136 #define	KERN_NOSUIDCOREDUMP	32	/* int: no setuid coredumps ever */
137 #define	KERN_FSYNC		33	/* int: file synchronization support */
138 #define	KERN_SYSVMSG		34	/* int: SysV message queue support */
139 #define	KERN_SYSVSEM		35	/* int: SysV semaphore support */
140 #define	KERN_SYSVSHM		36	/* int: SysV shared memory support */
141 /* was KERN_ARND		37	*/
142 #define	KERN_MSGBUFSIZE		38	/* int: size of message buffer */
143 #define KERN_MALLOCSTATS	39	/* node: malloc statistics */
144 #define KERN_CPTIME		40	/* array: cp_time */
145 #define KERN_NCHSTATS		41	/* struct: vfs cache statistics */
146 #define KERN_FORKSTAT		42	/* struct: fork statistics */
147 /* was KERN_NSELCOLL		43	*/
148 #define KERN_TTY		44	/* node: tty information */
149 #define	KERN_CCPU		45	/* int: ccpu */
150 #define	KERN_FSCALE		46	/* int: fscale */
151 #define	KERN_NPROCS		47	/* int: number of processes */
152 #define	KERN_MSGBUF		48	/* message buffer, KERN_MSGBUFSIZE */
153 #define	KERN_POOL		49	/* struct: pool information */
154 #define	KERN_STACKGAPRANDOM	50	/* int: stackgap_random */
155 #define	KERN_SYSVIPC_INFO	51	/* struct: SysV sem/shm/msg info */
156 #define KERN_ALLOWKMEM		52	/* int: allowkmem */
157 #define KERN_WITNESSWATCH	53	/* int: witnesswatch */
158 #define KERN_SPLASSERT		54	/* int: splassert */
159 #define KERN_PROC_ARGS		55	/* node: proc args and env */
160 #define	KERN_NFILES		56	/* int: number of open files */
161 #define	KERN_TTYCOUNT		57	/* int: number of tty devices */
162 #define KERN_NUMVNODES		58	/* int: number of vnodes in use */
163 #define	KERN_MBSTAT		59	/* struct: mbuf statistics */
164 #define	KERN_WITNESS		60	/* node: witness */
165 #define	KERN_SEMINFO		61	/* struct: SysV struct seminfo */
166 #define	KERN_SHMINFO		62	/* struct: SysV struct shminfo */
167 #define KERN_INTRCNT		63	/* node: interrupt counters */
168 #define	KERN_WATCHDOG		64	/* node: watchdog */
169 #define	KERN_ALLOWDT		65	/* int: allowdt */
170 #define	KERN_PROC		66	/* struct: process entries */
171 #define	KERN_MAXCLUSTERS	67	/* number of mclusters */
172 #define KERN_EVCOUNT		68	/* node: event counters */
173 #define	KERN_TIMECOUNTER	69	/* node: timecounter */
174 #define	KERN_MAXLOCKSPERUID	70	/* int: locks per uid */
175 #define	KERN_CPTIME2		71	/* array: cp_time2 */
176 #define	KERN_CACHEPCT		72	/* buffer cache % of physmem */
177 #define	KERN_FILE		73	/* struct: file entries */
178 #define	KERN_WXABORT		74	/* int: w^x sigabrt & core */
179 #define	KERN_CONSDEV		75	/* dev_t: console terminal device */
180 #define	KERN_NETLIVELOCKS	76	/* int: number of network livelocks */
181 #define	KERN_POOL_DEBUG		77	/* int: enable pool_debug */
182 #define	KERN_PROC_CWD		78      /* node: proc cwd */
183 #define	KERN_PROC_NOBROADCASTKILL 79	/* node: proc no broadcast kill */
184 #define	KERN_PROC_VMMAP		80      /* node: proc vmmap */
185 #define	KERN_GLOBAL_PTRACE	81	/* allow ptrace globally */
186 #define	KERN_CONSBUFSIZE	82	/* int: console message buffer size */
187 #define	KERN_CONSBUF		83	/* console message buffer */
188 #define	KERN_AUDIO		84	/* struct: audio properties */
189 #define	KERN_CPUSTATS		85	/* struct: cpu statistics */
190 #define	KERN_PFSTATUS		86	/* struct: pf status and stats */
191 #define	KERN_TIMEOUT_STATS	87	/* struct: timeout status and stats */
192 #define	KERN_UTC_OFFSET		88	/* int: adjust RTC time to UTC */
193 #define	KERN_VIDEO		89	/* struct: video properties */
194 #define	KERN_CLOCKINTR		90	/* node: clockintr */
195 #define	KERN_AUTOCONF_SERIAL	91	/* int: kernel device tree state serial */
196 #define	KERN_MAXID		92	/* number of valid kern ids */
197 
198 #define	CTL_KERN_NAMES { \
199 	{ 0, 0 }, \
200 	{ "ostype", CTLTYPE_STRING }, \
201 	{ "osrelease", CTLTYPE_STRING }, \
202 	{ "osrevision", CTLTYPE_INT }, \
203 	{ "version", CTLTYPE_STRING }, \
204 	{ "maxvnodes", CTLTYPE_INT }, \
205 	{ "maxproc", CTLTYPE_INT }, \
206 	{ "maxfiles", CTLTYPE_INT }, \
207 	{ "argmax", CTLTYPE_INT }, \
208 	{ "securelevel", CTLTYPE_INT }, \
209 	{ "hostname", CTLTYPE_STRING }, \
210 	{ "hostid", CTLTYPE_INT }, \
211 	{ "clockrate", CTLTYPE_STRUCT }, \
212 	{ "gap", 0 }, \
213 	{ "gap", 0 }, \
214 	{ "gap", 0 }, \
215 	{ "profiling", CTLTYPE_NODE }, \
216 	{ "posix1version", CTLTYPE_INT }, \
217 	{ "ngroups", CTLTYPE_INT }, \
218 	{ "job_control", CTLTYPE_INT }, \
219 	{ "saved_ids", CTLTYPE_INT }, \
220 	{ "boottime", CTLTYPE_STRUCT }, \
221 	{ "domainname", CTLTYPE_STRING }, \
222 	{ "maxpartitions", CTLTYPE_INT }, \
223 	{ "rawpartition", CTLTYPE_INT }, \
224 	{ "maxthread", CTLTYPE_INT }, \
225 	{ "nthreads", CTLTYPE_INT }, \
226 	{ "osversion", CTLTYPE_STRING }, \
227 	{ "somaxconn", CTLTYPE_INT }, \
228 	{ "sominconn", CTLTYPE_INT }, \
229 	{ "gap", 0 }, \
230 	{ "gap", 0 }, \
231 	{ "nosuidcoredump", CTLTYPE_INT }, \
232 	{ "fsync", CTLTYPE_INT }, \
233 	{ "sysvmsg", CTLTYPE_INT }, \
234 	{ "sysvsem", CTLTYPE_INT }, \
235 	{ "sysvshm", CTLTYPE_INT }, \
236 	{ "gap", 0 }, \
237 	{ "msgbufsize", CTLTYPE_INT }, \
238 	{ "malloc", CTLTYPE_NODE }, \
239 	{ "cp_time", CTLTYPE_STRUCT }, \
240 	{ "nchstats", CTLTYPE_STRUCT }, \
241 	{ "forkstat", CTLTYPE_STRUCT }, \
242 	{ "gap", 0 }, \
243 	{ "tty", CTLTYPE_NODE }, \
244 	{ "ccpu", CTLTYPE_INT }, \
245 	{ "fscale", CTLTYPE_INT }, \
246 	{ "nprocs", CTLTYPE_INT }, \
247 	{ "msgbuf", CTLTYPE_STRUCT }, \
248 	{ "pool", CTLTYPE_NODE }, \
249 	{ "stackgap_random", CTLTYPE_INT }, \
250 	{ "sysvipc_info", CTLTYPE_INT }, \
251 	{ "allowkmem", CTLTYPE_INT }, \
252 	{ "witnesswatch", CTLTYPE_INT }, \
253 	{ "splassert", CTLTYPE_INT }, \
254 	{ "procargs", CTLTYPE_NODE }, \
255 	{ "nfiles", CTLTYPE_INT }, \
256 	{ "ttycount", CTLTYPE_INT }, \
257 	{ "numvnodes", CTLTYPE_INT }, \
258 	{ "mbstat", CTLTYPE_STRUCT }, \
259 	{ "witness", CTLTYPE_NODE }, \
260 	{ "seminfo", CTLTYPE_STRUCT }, \
261 	{ "shminfo", CTLTYPE_STRUCT }, \
262 	{ "intrcnt", CTLTYPE_NODE }, \
263  	{ "watchdog", CTLTYPE_NODE }, \
264  	{ "allowdt", CTLTYPE_INT }, \
265  	{ "proc", CTLTYPE_STRUCT }, \
266  	{ "maxclusters", CTLTYPE_INT }, \
267 	{ "evcount", CTLTYPE_NODE }, \
268  	{ "timecounter", CTLTYPE_NODE }, \
269  	{ "maxlocksperuid", CTLTYPE_INT }, \
270  	{ "cp_time2", CTLTYPE_STRUCT }, \
271 	{ "bufcachepercent", CTLTYPE_INT }, \
272 	{ "file", CTLTYPE_STRUCT }, \
273 	{ "wxabort", CTLTYPE_INT }, \
274 	{ "consdev", CTLTYPE_STRUCT }, \
275 	{ "netlivelocks", CTLTYPE_INT }, \
276 	{ "pool_debug", CTLTYPE_INT }, \
277 	{ "proc_cwd", CTLTYPE_NODE }, \
278 	{ "proc_nobroadcastkill", CTLTYPE_NODE }, \
279 	{ "proc_vmmap", CTLTYPE_NODE }, \
280 	{ "global_ptrace", CTLTYPE_INT }, \
281 	{ "consbufsize", CTLTYPE_INT }, \
282 	{ "consbuf", CTLTYPE_STRUCT }, \
283 	{ "audio", CTLTYPE_STRUCT }, \
284 	{ "cpustats", CTLTYPE_STRUCT }, \
285 	{ "pfstatus", CTLTYPE_STRUCT }, \
286 	{ "timeout_stats", CTLTYPE_STRUCT }, \
287 	{ "utc_offset", CTLTYPE_INT }, \
288 	{ "video", CTLTYPE_STRUCT }, \
289  	{ "clockintr", CTLTYPE_NODE }, \
290 	{ "autoconf_serial", CTLTYPE_INT }, \
291 }
292 
293 /*
294  * KERN_PROC subtypes
295  */
296 #define	KERN_PROC_ALL		0	/* everything but kernel threads */
297 #define	KERN_PROC_PID		1	/* by process id */
298 #define	KERN_PROC_PGRP		2	/* by process group id */
299 #define	KERN_PROC_SESSION	3	/* by session of pid */
300 #define	KERN_PROC_TTY		4	/* by controlling tty */
301 #define	KERN_PROC_UID		5	/* by effective uid */
302 #define	KERN_PROC_RUID		6	/* by real uid */
303 #define	KERN_PROC_KTHREAD	7	/* also return kernel threads */
304 #define	KERN_PROC_SHOW_THREADS	0x40000000/* also return normal threads */
305 
306 /*
307  * KERN_SYSVIPC_INFO subtypes
308  */
309 #define KERN_SYSVIPC_MSG_INFO	1	/* msginfo and msqid_ds */
310 #define KERN_SYSVIPC_SEM_INFO	2	/* seminfo and semid_ds */
311 #define KERN_SYSVIPC_SHM_INFO	3	/* shminfo and shmid_ds */
312 
313 /*
314  * KERN_PROC_ARGS subtypes
315  */
316 #define KERN_PROC_ARGV		1
317 #define KERN_PROC_NARGV		2
318 #define KERN_PROC_ENV		3
319 #define KERN_PROC_NENV		4
320 
321 /*
322  * KERN_AUDIO
323  */
324 #define KERN_AUDIO_RECORD	1
325 #define KERN_AUDIO_MAXID	2
326 
327 #define CTL_KERN_AUDIO_NAMES { \
328 	{ 0, 0 }, \
329 	{ "record", CTLTYPE_INT }, \
330 }
331 
332 /*
333  * KERN_VIDEO
334  */
335 #define KERN_VIDEO_RECORD	1
336 #define KERN_VIDEO_MAXID	2
337 
338 #define CTL_KERN_VIDEO_NAMES { \
339 	{ 0, 0 }, \
340 	{ "record", CTLTYPE_INT }, \
341 }
342 
343 /*
344  * KERN_WITNESS
345  */
346 #define	KERN_WITNESS_WATCH	1	/* int: operating mode */
347 #define	KERN_WITNESS_LOCKTRACE	2	/* int: stack trace saving mode */
348 #define	KERN_WITNESS_MAXID	3
349 
350 #define	CTL_KERN_WITNESS_NAMES { \
351 	{ 0, 0 }, \
352 	{ "watch", CTLTYPE_INT }, \
353 	{ "locktrace", CTLTYPE_INT }, \
354 }
355 
356 /*
357  * KERN_PROC subtype ops return arrays of relatively fixed size
358  * structures of process info.   Use 8 byte alignment, and new
359  * elements should only be added to the end of this structure so
360  * binary compatibility can be preserved.
361  */
362 #define	KI_NGROUPS	16
363 #define	KI_MAXCOMLEN	_MAXCOMLEN	/* includes NUL */
364 #define	KI_WMESGLEN	8
365 #define	KI_MAXLOGNAME	32
366 #define	KI_EMULNAMELEN	8
367 
368 #define KI_NOCPU	(~(u_int64_t)0)
369 
370 struct kinfo_proc {
371 	u_int64_t p_forw;		/* PTR: linked run/sleep queue. */
372 	u_int64_t p_back;
373 	u_int64_t p_paddr;		/* PTR: address of proc */
374 
375 	u_int64_t p_addr;		/* PTR: Kernel virtual addr of u-area */
376 	u_int64_t p_fd;			/* PTR: Ptr to open files structure. */
377 	u_int64_t p_stats;		/* unused, always zero. */
378 	u_int64_t p_limit;		/* PTR: Process limits. */
379 	u_int64_t p_vmspace;		/* PTR: Address space. */
380 	u_int64_t p_sigacts;		/* PTR: Signal actions, state */
381 	u_int64_t p_sess;		/* PTR: session pointer */
382 	u_int64_t p_tsess;		/* PTR: tty session pointer */
383 	u_int64_t p_ru;			/* PTR: Exit information. XXX */
384 
385 	int32_t	p_eflag;		/* LONG: extra kinfo_proc flags */
386 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
387 #define	EPROC_SLEADER	0x02	/* session leader */
388 #define	EPROC_UNVEIL	0x04	/* has unveil settings */
389 #define	EPROC_LKUNVEIL	0x08	/* unveil is locked */
390 	int32_t	p_exitsig;		/* unused, always zero. */
391 	int32_t	p_flag;			/* INT: P_* flags. */
392 
393 	int32_t	p_pid;			/* PID_T: Process identifier. */
394 	int32_t	p_ppid;			/* PID_T: Parent process id */
395 	int32_t	p_sid;			/* PID_T: session id */
396 	int32_t	p__pgid;		/* PID_T: process group id */
397 					/* XXX: <sys/proc.h> hijacks p_pgid */
398 	int32_t	p_tpgid;		/* PID_T: tty process group id */
399 
400 	u_int32_t p_uid;		/* UID_T: effective user id */
401 	u_int32_t p_ruid;		/* UID_T: real user id */
402 	u_int32_t p_gid;		/* GID_T: effective group id */
403 	u_int32_t p_rgid;		/* GID_T: real group id */
404 
405 	u_int32_t p_groups[KI_NGROUPS];	/* GID_T: groups */
406 	int16_t	p_ngroups;		/* SHORT: number of groups */
407 
408 	int16_t	p_jobc;			/* SHORT: job control counter */
409 	u_int32_t p_tdev;		/* DEV_T: controlling tty dev */
410 
411 	u_int32_t p_estcpu;		/* U_INT: Time averaged value of p_cpticks. */
412 	u_int32_t p_rtime_sec;		/* STRUCT TIMEVAL: Real time. */
413 	u_int32_t p_rtime_usec;		/* STRUCT TIMEVAL: Real time. */
414 	int32_t	p_cpticks;		/* INT: Ticks of cpu time. */
415 	u_int32_t p_pctcpu;		/* FIXPT_T: %cpu for this process */
416 	u_int32_t p_swtime;		/* unused, always zero */
417 	u_int32_t p_slptime;		/* U_INT: Time since last blocked. */
418 	int32_t	p_schedflags;		/* INT: PSCHED_* flags */
419 
420 	u_int64_t p_uticks;		/* U_QUAD_T: Statclock hits in user mode. */
421 	u_int64_t p_sticks;		/* U_QUAD_T: Statclock hits in system mode. */
422 	u_int64_t p_iticks;		/* U_QUAD_T: Statclock hits processing intr. */
423 
424 	u_int64_t p_tracep;		/* PTR: Trace to vnode or file */
425 	int32_t	p_traceflag;		/* INT: Kernel trace points. */
426 
427 	int32_t p_holdcnt;		/* INT: If non-zero, don't swap. */
428 
429 	int32_t p_siglist;		/* INT: Signals arrived but not delivered. */
430 	u_int32_t p_sigmask;		/* SIGSET_T: Current signal mask. */
431 	u_int32_t p_sigignore;		/* SIGSET_T: Signals being ignored. */
432 	u_int32_t p_sigcatch;		/* SIGSET_T: Signals being caught by user. */
433 
434 	int8_t	p_stat;			/* CHAR: S* process status (from LWP). */
435 	u_int8_t p_priority;		/* U_CHAR: Process priority. */
436 	u_int8_t p_usrpri;		/* U_CHAR: User-priority based on p_estcpu and ps_nice. */
437 	u_int8_t p_nice;		/* U_CHAR: Process "nice" value. */
438 
439 	u_int16_t p_xstat;		/* U_SHORT: Exit status for wait; also stop signal. */
440 	u_int16_t p_spare;		/* U_SHORT: unused */
441 
442 	char	p_comm[KI_MAXCOMLEN];
443 
444 	char	p_wmesg[KI_WMESGLEN];	/* wchan message */
445 	u_int64_t p_wchan;		/* PTR: sleep address. */
446 
447 	char	p_login[KI_MAXLOGNAME];	/* setlogin() name */
448 
449 	int32_t	p_vm_rssize;		/* SEGSZ_T: current resident set size in pages */
450 	int32_t	p_vm_tsize;		/* SEGSZ_T: text size (pages) */
451 	int32_t	p_vm_dsize;		/* SEGSZ_T: data size (pages) */
452 	int32_t	p_vm_ssize;		/* SEGSZ_T: stack size (pages) */
453 
454 	int64_t	p_uvalid;		/* CHAR: following p_u* members from struct user are valid */
455 					/* XXX 64 bits for alignment */
456 	u_int64_t p_ustart_sec;		/* STRUCT TIMEVAL: starting time. */
457 	u_int32_t p_ustart_usec;	/* STRUCT TIMEVAL: starting time. */
458 
459 	u_int32_t p_uutime_sec;		/* STRUCT TIMEVAL: user time. */
460 	u_int32_t p_uutime_usec;	/* STRUCT TIMEVAL: user time. */
461 	u_int32_t p_ustime_sec;		/* STRUCT TIMEVAL: system time. */
462 	u_int32_t p_ustime_usec;	/* STRUCT TIMEVAL: system time. */
463 
464 	u_int64_t p_uru_maxrss;		/* LONG: max resident set size. */
465 	u_int64_t p_uru_ixrss;		/* LONG: integral shared memory size. */
466 	u_int64_t p_uru_idrss;		/* LONG: integral unshared data ". */
467 	u_int64_t p_uru_isrss;		/* LONG: integral unshared stack ". */
468 	u_int64_t p_uru_minflt;		/* LONG: page reclaims. */
469 	u_int64_t p_uru_majflt;		/* LONG: page faults. */
470 	u_int64_t p_uru_nswap;		/* LONG: swaps. */
471 	u_int64_t p_uru_inblock;	/* LONG: block input operations. */
472 	u_int64_t p_uru_oublock;	/* LONG: block output operations. */
473 	u_int64_t p_uru_msgsnd;		/* LONG: messages sent. */
474 	u_int64_t p_uru_msgrcv;		/* LONG: messages received. */
475 	u_int64_t p_uru_nsignals;	/* LONG: signals received. */
476 	u_int64_t p_uru_nvcsw;		/* LONG: voluntary context switches. */
477 	u_int64_t p_uru_nivcsw;		/* LONG: involuntary ". */
478 
479 	u_int32_t p_uctime_sec;		/* STRUCT TIMEVAL: child u+s time. */
480 	u_int32_t p_uctime_usec;	/* STRUCT TIMEVAL: child u+s time. */
481 	u_int32_t p_psflags;		/* UINT: PS_* flags on the process. */
482 	u_int32_t p_acflag;		/* UINT: Accounting flags. */
483 	u_int32_t p_svuid;		/* UID_T: saved user id */
484 	u_int32_t p_svgid;		/* GID_T: saved group id */
485 	char    p_emul[KI_EMULNAMELEN];	/* syscall emulation name */
486 	u_int64_t p_rlim_rss_cur;	/* RLIM_T: soft limit for rss */
487 	u_int64_t p_cpuid;		/* LONG: CPU id */
488 	u_int64_t p_vm_map_size;	/* VSIZE_T: virtual size */
489 	int32_t   p_tid;		/* PID_T: Thread identifier. */
490 	u_int32_t p_rtableid;		/* U_INT: Routing table identifier. */
491 
492 	u_int64_t p_pledge;		/* U_INT64_T: Pledge flags. */
493 	char	p_name[KI_MAXCOMLEN];	/* thread name */
494 };
495 
496 /*
497  * VM address range entry, matching struct vm_map_entry.  Useful for
498  * debuggers to know process's addresses.
499  *
500  * To iterate entries, set the last kve_end as the base address into
501  * kve_start.
502  */
503 struct kinfo_vmentry {
504 	u_long kve_start;		/* vaddr_t */
505 	u_long kve_end;			/* vaddr_t */
506 	u_long kve_guard;		/* vsize_t */
507 	u_long kve_fspace;		/* vsize_t */
508 	u_long kve_fspace_augment;	/* vsize_t */
509 	u_int64_t kve_offset;		/* voff_t */
510 	int kve_wired_count;
511 	int kve_etype;
512 	int kve_protection;
513 	int kve_max_protection;
514 	int kve_advice;
515 	int kve_inheritance;
516 	u_int8_t kve_flags;		/* u_int8_t */
517 };
518 
519 /* keep in sync with UVM_ET_* */
520 #define KVE_ET_OBJ		0x00000001
521 #define KVE_ET_SUBMAP		0x00000002
522 #define KVE_ET_COPYONWRITE 	0x00000004
523 #define KVE_ET_NEEDSCOPY	0x00000008
524 #define KVE_ET_HOLE		0x00000010
525 #define KVE_ET_NOFAULT		0x00000020
526 #define KVE_ET_STACK		0x00000040
527 #define KVE_ET_WC		0x00000080
528 #define KVE_ET_CONCEAL		0x00000100
529 #define KVE_ET_SYSCALL		0x00000200
530 #define KVE_ET_FREEMAPPED	0x00000800
531 
532 #define KVE_PROT_NONE		0x00000000
533 #define KVE_PROT_READ		0x00000001
534 #define KVE_PROT_WRITE		0x00000002
535 #define KVE_PROT_EXEC		0x00000004
536 
537 #define KVE_ADV_NORMAL		0x00000000
538 #define KVE_ADV_RANDOM		0x00000001
539 #define KVE_ADV_SEQUENTIAL	0x00000002
540 
541 #define KVE_INH_SHARE		0x00000000
542 #define KVE_INH_COPY		0x00000010
543 #define KVE_INH_NONE		0x00000020
544 #define KVE_INH_ZERO		0x00000030
545 
546 #define KVE_F_STATIC		0x01
547 #define KVE_F_KMEM		0x02
548 
549 #if defined(_KERNEL) || defined(_LIBKVM)
550 
551 /*
552  * Macros for filling in the bulk of a kinfo_proc structure, used
553  * in the kernel to implement the KERN_PROC sysctl and in userland
554  * in libkvm to implement reading from kernel crashes.  The macro
555  * arguments are all pointers; by name they are:
556  *	kp - target kinfo_proc structure
557  *	copy_str - a function or macro invoked as copy_str(dst,src,maxlen)
558  *	    that has strlcpy or memcpy semantics; the destination is
559  *	    pre-filled with zeros; for libkvm, src is a kvm address
560  *	p - source struct proc
561  *	pr - source struct process
562  *	uc - source struct ucreds
563  *	pg - source struct pgrp
564  *	paddr - kernel address of the source struct proc
565  *	praddr - kernel address of the source struct process
566  *	sess - source struct session
567  *	vm - source struct vmspace
568  *	lim - source struct plimits
569  *	sa - source struct sigacts
570  * There are some members that are not handled by these macros
571  * because they're too painful to generalize: p_sid, p_tdev,
572  * p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid
573  */
574 
575 #if defined(_KERNEL)
576 #define PR_LOCK(pr)	mtx_enter(&(pr)->ps_mtx)
577 #define PR_UNLOCK(pr)	mtx_leave(&(pr)->ps_mtx)
578 #else
579 #define PR_LOCK(pr)	/* nothing */
580 #define PR_UNLOCK(pr)	/* nothing */
581 #endif
582 
583 #define _getcompatprio(_p)						\
584 	((_p)->p_stat == SRUN ? (_p)->p_runpri : 			\
585 	    ((_p)->p_stat == SSLEEP) ? (_p)->p_slppri : (_p)->p_usrpri)
586 
587 #define PTRTOINT64(_x)	((u_int64_t)(u_long)(_x))
588 
589 #define	_FILL_KPROC_MIN(a,b) (((a)<(b))?(a):(b))
590 
591 #define FILL_KPROC(kp, copy_str, p, pr, uc, pg, paddr, \
592     praddr, sess, vm, lim, sa, tu, isthread, show_addresses) \
593 do {									\
594 	memset((kp), 0, sizeof(*(kp)));					\
595 									\
596 	if (show_addresses) {						\
597 		(kp)->p_paddr = PTRTOINT64(paddr);			\
598 		(kp)->p_fd = PTRTOINT64((pr)->ps_fd);			\
599 		(kp)->p_limit = PTRTOINT64((pr)->ps_limit);		\
600 		(kp)->p_vmspace = PTRTOINT64((pr)->ps_vmspace);		\
601 		(kp)->p_sigacts = PTRTOINT64((pr)->ps_sigacts);		\
602 		(kp)->p_sess = PTRTOINT64((pg)->pg_session);		\
603 		(kp)->p_ru = PTRTOINT64((pr)->ps_ru);			\
604 	}								\
605 	(kp)->p_stats = 0;						\
606 	(kp)->p_exitsig = 0;						\
607 	(kp)->p_flag = (p)->p_flag;					\
608 	(kp)->p_pid = (pr)->ps_pid;					\
609 	(kp)->p_psflags = (pr)->ps_flags;				\
610 									\
611 	(kp)->p__pgid = (pg)->pg_id;					\
612 									\
613 	(kp)->p_uid = (uc)->cr_uid;					\
614 	(kp)->p_ruid = (uc)->cr_ruid;					\
615 	(kp)->p_gid = (uc)->cr_gid;					\
616 	(kp)->p_rgid = (uc)->cr_rgid;					\
617 	(kp)->p_svuid = (uc)->cr_svuid;					\
618 	(kp)->p_svgid = (uc)->cr_svgid;					\
619 									\
620 	memcpy((kp)->p_groups, (uc)->cr_groups,				\
621 	    _FILL_KPROC_MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \
622 	(kp)->p_ngroups = (uc)->cr_ngroups;				\
623 									\
624 	(kp)->p_jobc = (pg)->pg_jobc;					\
625 									\
626 	(kp)->p_estcpu = (p)->p_estcpu;					\
627 	if (isthread) {							\
628 		(kp)->p_tid = (p)->p_tid + THREAD_PID_OFFSET;		\
629 		strlcpy((kp)->p_name, (p)->p_name, sizeof((kp)->p_name)); \
630 	} else {							\
631 		(kp)->p_tid = -1;					\
632 	}								\
633 	(kp)->p_rtime_sec = (tu)->tu_runtime.tv_sec;			\
634 	(kp)->p_rtime_usec = (tu)->tu_runtime.tv_nsec/1000;		\
635 	(kp)->p_uticks = (tu)->tu_uticks;				\
636 	(kp)->p_sticks = (tu)->tu_sticks;				\
637 	(kp)->p_iticks = (tu)->tu_iticks;				\
638 	(kp)->p_cpticks = (p)->p_cpticks;				\
639 									\
640 	if (show_addresses)						\
641 		(kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp);		\
642 	(kp)->p_traceflag = (pr)->ps_traceflag;				\
643 									\
644 	(kp)->p_siglist = (p)->p_siglist | (pr)->ps_siglist;		\
645 	(kp)->p_sigmask = (p)->p_sigmask;				\
646 									\
647 	PR_LOCK(pr);							\
648 	(kp)->p_ppid = (pr)->ps_ppid;					\
649 	(kp)->p_sigignore = (sa) ? (sa)->ps_sigignore : 0;		\
650 	(kp)->p_sigcatch = (sa) ? (sa)->ps_sigcatch : 0;		\
651 									\
652 	if (lim)							\
653 		(kp)->p_rlim_rss_cur =					\
654 		    (lim)->pl_rlimit[RLIMIT_RSS].rlim_cur;		\
655 	PR_UNLOCK(pr);							\
656 									\
657 	(kp)->p_stat = (p)->p_stat;					\
658 	(kp)->p_nice = (pr)->ps_nice;					\
659 									\
660 	(kp)->p_xstat = W_EXITCODE((pr)->ps_xexit, (pr)->ps_xsig);	\
661 	(kp)->p_acflag = (pr)->ps_acflag;				\
662 	(kp)->p_pledge = (pr)->ps_pledge;				\
663 									\
664 	strlcpy((kp)->p_emul, "native", sizeof((kp)->p_emul));		\
665 	strlcpy((kp)->p_comm, (pr)->ps_comm, sizeof((kp)->p_comm));	\
666 	strlcpy((kp)->p_login, (sess)->s_login,				\
667 	    _FILL_KPROC_MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \
668 									\
669 	if ((sess)->s_ttyvp)						\
670 		(kp)->p_eflag |= EPROC_CTTY;				\
671 	if ((pr)->ps_uvpaths)						\
672 		(kp)->p_eflag |= EPROC_UNVEIL;				\
673 	if ((pr)->ps_uvdone ||						\
674 	    (((pr)->ps_flags & PS_PLEDGE) &&				\
675 	     ((pr)->ps_pledge & PLEDGE_UNVEIL) == 0))			\
676 		(kp)->p_eflag |= EPROC_LKUNVEIL;			\
677 									\
678 	if (((pr)->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0) {		\
679 		if ((vm) != NULL) {					\
680 			(kp)->p_vm_rssize = (vm)->vm_rssize;		\
681 			(kp)->p_vm_tsize = (vm)->vm_tsize;		\
682 			(kp)->p_vm_dsize = (vm)->vm_dused;		\
683 			(kp)->p_vm_ssize = (vm)->vm_ssize;		\
684 		}							\
685 		(kp)->p_addr = PTRTOINT64((p)->p_addr);			\
686 		(kp)->p_stat = (p)->p_stat;				\
687 		(kp)->p_slptime = (p)->p_slptime;			\
688 		(kp)->p_holdcnt = 1;					\
689 		(kp)->p_priority = _getcompatprio(p);			\
690 		(kp)->p_usrpri = (p)->p_usrpri;				\
691 		if ((p)->p_wchan && (p)->p_wmesg)			\
692 			copy_str((kp)->p_wmesg, (p)->p_wmesg,		\
693 			    sizeof((kp)->p_wmesg));			\
694 		if (show_addresses)					\
695 			(kp)->p_wchan = PTRTOINT64((p)->p_wchan);	\
696 	}								\
697 									\
698 	if (((pr)->ps_flags & PS_ZOMBIE) == 0) {			\
699 		struct timeval __tv;					\
700 									\
701 		(kp)->p_uvalid = 1;					\
702 									\
703 		(kp)->p_uru_maxrss = (p)->p_ru.ru_maxrss;		\
704 		(kp)->p_uru_ixrss = (p)->p_ru.ru_ixrss;			\
705 		(kp)->p_uru_idrss = (p)->p_ru.ru_idrss;			\
706 		(kp)->p_uru_isrss = (p)->p_ru.ru_isrss;			\
707 		(kp)->p_uru_minflt = (p)->p_ru.ru_minflt;		\
708 		(kp)->p_uru_majflt = (p)->p_ru.ru_majflt;		\
709 		(kp)->p_uru_nswap = (p)->p_ru.ru_nswap;			\
710 		(kp)->p_uru_inblock = (p)->p_ru.ru_inblock;		\
711 		(kp)->p_uru_oublock = (p)->p_ru.ru_oublock;		\
712 		(kp)->p_uru_msgsnd = (p)->p_ru.ru_msgsnd;		\
713 		(kp)->p_uru_msgrcv = (p)->p_ru.ru_msgrcv;		\
714 		(kp)->p_uru_nsignals = (p)->p_ru.ru_nsignals;		\
715 		(kp)->p_uru_nvcsw = (p)->p_ru.ru_nvcsw;			\
716 		(kp)->p_uru_nivcsw = (p)->p_ru.ru_nivcsw;		\
717 									\
718 		timeradd(&(pr)->ps_cru.ru_utime,			\
719 			 &(pr)->ps_cru.ru_stime, &__tv);		\
720 		(kp)->p_uctime_sec = __tv.tv_sec;			\
721 		(kp)->p_uctime_usec = __tv.tv_usec;			\
722 	}								\
723 									\
724 	(kp)->p_cpuid = KI_NOCPU;					\
725 	(kp)->p_rtableid = (pr)->ps_rtableid;				\
726 } while (0)
727 
728 #endif /* defined(_KERNEL) || defined(_LIBKVM) */
729 
730 
731 /*
732  * kern.file returns an array of these structures, which are designed
733  * both to be immune to 32/64 bit emulation issues and to
734  * provide backwards compatibility.  The order differs slightly from
735  * that of the real struct file, and some fields are taken from other
736  * structures (struct vnode, struct proc) in order to make the file
737  * information more useful.
738  */
739 #define	KERN_FILE_BYFILE	1
740 #define	KERN_FILE_BYPID		2
741 #define	KERN_FILE_BYUID		3
742 #define	KERN_FILESLOP		10
743 
744 #define KERN_FILE_TEXT		-1
745 #define KERN_FILE_CDIR		-2
746 #define KERN_FILE_RDIR		-3
747 #define KERN_FILE_TRACE		-4
748 
749 #define KI_MNAMELEN		96	/* rounded up from 90 */
750 #define KI_UNPPATHLEN		104
751 
752 struct kinfo_file {
753 	uint64_t	f_fileaddr;	/* PTR: address of struct file */
754 	uint32_t	f_flag;		/* UINT: flags (see fcntl.h) */
755 	uint32_t	f_iflags;	/* UINT: internal flags */
756 	uint32_t	f_type;		/* INT: descriptor type */
757 	uint32_t	f_count;	/* UINT: reference count */
758 	uint32_t	f_msgcount;	/* UINT: references from msg queue */
759 	uint32_t	f_usecount;	/* INT: number active users */
760 	uint64_t	f_ucred;	/* PTR: creds for descriptor */
761 	uint32_t	f_uid;		/* UID_T: descriptor credentials */
762 	uint32_t	f_gid;		/* GID_T: descriptor credentials */
763 	uint64_t	f_ops;		/* PTR: address of fileops */
764 	uint64_t	f_offset;	/* OFF_T: offset */
765 	uint64_t	f_data;		/* PTR: descriptor data */
766 	uint64_t	f_rxfer;	/* UINT64: number of read xfers */
767 	uint64_t	f_rwfer;	/* UINT64: number of write xfers */
768 	uint64_t	f_seek;		/* UINT64: number of seek operations */
769 	uint64_t	f_rbytes;	/* UINT64: total bytes read */
770 	uint64_t	f_wbytes;	/* UINT64: total bytes written */
771 
772 	/* information about the vnode associated with this file */
773 	uint64_t	v_un;		/* PTR: socket, specinfo, etc */
774 	uint32_t	v_type;		/* ENUM: vnode type */
775 	uint32_t	v_tag;		/* ENUM: type of underlying data */
776 	uint32_t	v_flag;		/* UINT: vnode flags */
777 	uint32_t	va_rdev;	/* DEV_T: raw device */
778 	uint64_t	v_data;		/* PTR: private data for fs */
779 	uint64_t	v_mount;	/* PTR: mount info for fs */
780 	uint64_t	va_fileid;	/* LONG: file id */
781 	uint64_t	va_size;	/* UINT64_T: file size in bytes */
782 	uint32_t	va_mode;	/* MODE_T: file access mode and type */
783 	uint32_t	va_fsid;	/* DEV_T: filesystem device */
784 	char		f_mntonname[KI_MNAMELEN];
785 
786 	/* socket information */
787 	uint32_t	so_type;	/* SHORT: socket type */
788 	uint32_t	so_state;	/* SHORT: socket state */
789 	uint64_t	so_pcb;		/* PTR: socket pcb */
790 					/* for non-root: -1 if not NULL */
791 	uint32_t	so_protocol;	/* SHORT: socket protocol type */
792 	uint32_t	so_family;	/* INT: socket domain family */
793 	uint64_t	inp_ppcb;	/* PTR: pointer to per-protocol pcb */
794 	uint32_t	inp_lport;	/* SHORT: local inet port */
795 	uint32_t	inp_laddru[4];	/* STRUCT: local inet addr */
796 	uint32_t	inp_fport;	/* SHORT: foreign inet port */
797 	uint32_t	inp_faddru[4];	/* STRUCT: foreign inet addr */
798 	uint64_t	unp_conn;	/* PTR: connected socket cntrl block */
799 
800 	/* pipe information */
801 	uint64_t	pipe_peer;	/* PTR: link with other direction */
802 	uint32_t	pipe_state;	/* UINT: pipe status info */
803 
804 	/* kqueue information */
805 	uint32_t	kq_count;	/* INT: number of pending events */
806 	uint32_t	kq_state;	/* INT: kqueue status information */
807 
808 	uint32_t	__unused1;	/* INT: unused */
809 
810 	/* process information when retrieved via KERN_FILE_BY[PU]ID */
811 	uint32_t	p_pid;		/* PID_T: process id */
812 	int32_t		fd_fd;		/* INT: descriptor number */
813 	uint32_t	fd_ofileflags;	/* CHAR: open file flags */
814 	uint32_t	p_uid;		/* UID_T: process credentials */
815 	uint32_t	p_gid;		/* GID_T: process credentials */
816 	uint32_t	p_tid;		/* PID_T: thread id */
817 	char		p_comm[KI_MAXCOMLEN];
818 
819 	/* more socket information */
820 	uint32_t	inp_rtableid;	/* UINT: Routing table identifier. */
821 	uint64_t	so_splice;	/* PTR: f_data of spliced socket */
822 	int64_t		so_splicelen;	/* OFF_T: already spliced count or */
823 					/* -1 if this is target of splice */
824 	uint64_t	so_rcv_cc;	/* LONG: chars in receive buf */
825 	uint64_t	so_snd_cc;	/* LONG: chars in send buf */
826 	uint64_t	unp_refs;	/* PTR: connected sockets */
827 	uint64_t	unp_nextref;	/* PTR: link to next connected socket */
828 	uint64_t	unp_addr;	/* PTR: address of the socket address */
829 	char		unp_path[KI_UNPPATHLEN];
830 	uint32_t	inp_proto;	/* CHAR: raw protocol id */
831 	uint32_t	t_state;	/* SHORT: tcp state */
832 	uint64_t	t_rcv_wnd;	/* ULONG: tcp receive window */
833 	uint64_t	t_snd_wnd;	/* ULONG: tcp send window */
834 	uint64_t	t_snd_cwnd;	/* ULONG: congestion-controlled win */
835 
836 	uint32_t	va_nlink;	/* NLINK_T: number of references to file */
837 };
838 
839 /*
840  * KERN_INTRCNT
841  */
842 #define KERN_INTRCNT_NUM	1	/* int: # intrcnt */
843 #define KERN_INTRCNT_CNT	2	/* node: intrcnt */
844 #define KERN_INTRCNT_NAME	3	/* node: names */
845 #define KERN_INTRCNT_VECTOR	4	/* node: interrupt vector # */
846 #define KERN_INTRCNT_MAXID	5
847 
848 #define CTL_KERN_INTRCNT_NAMES { \
849 	{ 0, 0 }, \
850 	{ "nintrcnt", CTLTYPE_INT }, \
851 	{ "intrcnt", CTLTYPE_NODE }, \
852 	{ "intrname", CTLTYPE_NODE }, \
853 }
854 
855 /*
856  * KERN_WATCHDOG
857  */
858 #define KERN_WATCHDOG_PERIOD	1	/* int: watchdog period */
859 #define KERN_WATCHDOG_AUTO	2	/* int: automatic tickle */
860 #define KERN_WATCHDOG_MAXID	3
861 
862 #define CTL_KERN_WATCHDOG_NAMES { \
863 	{ 0, 0 }, \
864 	{ "period", CTLTYPE_INT }, \
865 	{ "auto", CTLTYPE_INT }, \
866 }
867 
868 /*
869  * KERN_TIMECOUNTER
870  */
871 #define KERN_TIMECOUNTER_TICK		1	/* int: number of revolutions */
872 #define KERN_TIMECOUNTER_TIMESTEPWARNINGS 2	/* int: log a warning when time changes */
873 #define KERN_TIMECOUNTER_HARDWARE	3	/* string: tick hardware used */
874 #define KERN_TIMECOUNTER_CHOICE		4	/* string: tick hardware used */
875 #define KERN_TIMECOUNTER_MAXID		5
876 
877 #define CTL_KERN_TIMECOUNTER_NAMES { \
878 	{ 0, 0 }, \
879 	{ "tick", CTLTYPE_INT }, \
880 	{ "timestepwarnings", CTLTYPE_INT }, \
881 	{ "hardware", CTLTYPE_STRING }, \
882 	{ "choice", CTLTYPE_STRING }, \
883 }
884 
885 /*
886  * KERN_CLOCKINTR
887  */
888 #define KERN_CLOCKINTR_STATS		1	/* struct: stats */
889 #define KERN_CLOCKINTR_MAXID		2
890 
891 #define CTL_KERN_CLOCKINTR_NAMES { \
892 	{ 0, 0 }, \
893 	{ "stats", CTLTYPE_STRUCT }, \
894 }
895 
896 /*
897  * CTL_FS identifiers
898  */
899 #define	FS_POSIX	1		/* POSIX flags */
900 #define	FS_MAXID	2
901 
902 #define	CTL_FS_NAMES { \
903 	{ 0, 0 }, \
904 	{ "posix", CTLTYPE_NODE }, \
905 }
906 
907 /*
908  * CTL_FS identifiers
909  */
910 #define	FS_POSIX_SETUID	1		/* int: always clear SGID/SUID bit when owner change */
911 #define	FS_POSIX_MAXID	2
912 
913 #define	CTL_FS_POSIX_NAMES { \
914 	{ 0, 0 }, \
915 	{ "setuid", CTLTYPE_INT }, \
916 }
917 
918 /*
919  * CTL_HW identifiers
920  */
921 #define	HW_MACHINE		 1	/* string: machine class */
922 #define	HW_MODEL		 2	/* string: specific machine model */
923 #define	HW_NCPU			 3	/* int: number of configured cpus */
924 #define	HW_BYTEORDER		 4	/* int: machine byte order */
925 #define	HW_PHYSMEM		 5	/* int: total memory */
926 #define	HW_USERMEM		 6	/* int: non-kernel memory */
927 #define	HW_PAGESIZE		 7	/* int: software page size */
928 #define	HW_DISKNAMES		 8	/* strings: disk drive names */
929 #define	HW_DISKSTATS		 9	/* struct: diskstats[] */
930 #define	HW_DISKCOUNT		10	/* int: number of disks */
931 #define	HW_SENSORS		11	/* node: hardware monitors */
932 #define	HW_CPUSPEED		12	/* get CPU frequency */
933 #define	HW_SETPERF		13	/* set CPU performance % */
934 #define	HW_VENDOR		14	/* string: vendor name */
935 #define	HW_PRODUCT		15	/* string: product name */
936 #define	HW_VERSION		16	/* string: hardware version */
937 #define	HW_SERIALNO		17	/* string: hardware serial number */
938 #define	HW_UUID			18	/* string: universal unique id */
939 #define	HW_PHYSMEM64		19	/* quad: total memory */
940 #define	HW_USERMEM64		20	/* quad: non-kernel memory */
941 #define	HW_NCPUFOUND		21	/* int: number of cpus found */
942 #define	HW_ALLOWPOWERDOWN	22	/* allow power button shutdown */
943 #define	HW_PERFPOLICY		23	/* set performance policy */
944 #define	HW_SMT			24	/* int: enable SMT/HT/CMT */
945 #define	HW_NCPUONLINE		25	/* int: number of cpus being used */
946 #define	HW_POWER		26	/* int: machine has wall-power */
947 #define	HW_BATTERY		27	/* node: battery */
948 #define	HW_UCOMNAMES		28	/* strings: ucom names */
949 #define	HW_MAXID		29	/* number of valid hw ids */
950 
951 #define	CTL_HW_NAMES { \
952 	{ 0, 0 }, \
953 	{ "machine", CTLTYPE_STRING }, \
954 	{ "model", CTLTYPE_STRING }, \
955 	{ "ncpu", CTLTYPE_INT }, \
956 	{ "byteorder", CTLTYPE_INT }, \
957 	{ "gap", 0 }, \
958 	{ "gap", 0 }, \
959 	{ "pagesize", CTLTYPE_INT }, \
960 	{ "disknames", CTLTYPE_STRING }, \
961 	{ "diskstats", CTLTYPE_STRUCT }, \
962 	{ "diskcount", CTLTYPE_INT }, \
963 	{ "sensors", CTLTYPE_NODE}, \
964 	{ "cpuspeed", CTLTYPE_INT }, \
965 	{ "setperf", CTLTYPE_INT }, \
966 	{ "vendor", CTLTYPE_STRING }, \
967 	{ "product", CTLTYPE_STRING }, \
968 	{ "version", CTLTYPE_STRING }, \
969 	{ "serialno", CTLTYPE_STRING }, \
970 	{ "uuid", CTLTYPE_STRING }, \
971 	{ "physmem", CTLTYPE_QUAD }, \
972 	{ "usermem", CTLTYPE_QUAD }, \
973 	{ "ncpufound", CTLTYPE_INT }, \
974 	{ "allowpowerdown", CTLTYPE_INT }, \
975 	{ "perfpolicy", CTLTYPE_STRING }, \
976 	{ "smt", CTLTYPE_INT }, \
977 	{ "ncpuonline", CTLTYPE_INT }, \
978 	{ "power", CTLTYPE_INT }, \
979 	{ "battery", CTLTYPE_NODE }, \
980 	{ "ucomnames", CTLTYPE_STRING }, \
981 }
982 
983 /*
984  * HW_BATTERY
985  */
986 #define	HW_BATTERY_CHARGEMODE	1	/* int: battery charging mode */
987 #define	HW_BATTERY_CHARGESTART	2	/* int: battery start charge percent */
988 #define	HW_BATTERY_CHARGESTOP	3	/* int: battery stop charge percent */
989 #define	HW_BATTERY_MAXID	4
990 
991 #define CTL_HW_BATTERY_NAMES { \
992 	{ 0, 0 }, \
993 	{ "chargemode", CTLTYPE_INT }, \
994 	{ "chargestart", CTLTYPE_INT }, \
995 	{ "chargestop", CTLTYPE_INT }, \
996 }
997 
998 /*
999  * CTL_DEBUG definitions
1000  *
1001  * Second level identifier specifies which debug variable.
1002  * Third level identifier specifies which structure component.
1003  */
1004 #define	CTL_DEBUG_NAME		0	/* string: variable name */
1005 #define	CTL_DEBUG_VALUE		1	/* int: variable value */
1006 #define	CTL_DEBUG_MAXID		20
1007 
1008 #ifdef	_KERNEL
1009 #ifdef DEBUG_SYSCTL
1010 /*
1011  * CTL_DEBUG variables.
1012  *
1013  * These are declared as separate variables so that they can be
1014  * individually initialized at the location of their associated
1015  * variable. The loader prevents multiple use by issuing errors
1016  * if a variable is initialized in more than one place. They are
1017  * aggregated into an array in debug_sysctl(), so that it can
1018  * conveniently locate them when queried. If more debugging
1019  * variables are added, they must also be declared here and also
1020  * entered into the array.
1021  */
1022 struct ctldebug {
1023 	char	*debugname;	/* name of debugging variable */
1024 	int	*debugvar;	/* pointer to debugging variable */
1025 };
1026 #endif	/* DEBUG_SYSCTL */
1027 
1028 /*
1029  * Exported sysctl variable with valid bounds. Both bounds are inclusive to
1030  * allow full range of values.
1031  */
1032 struct sysctl_bounded_args {
1033 	int mib;     /* identifier shared with userspace as a CTL_ #define */
1034 	int *var;    /* never NULL */
1035 	int minimum; /* checking is disabled if minimum == maximum  */
1036 	int maximum; /* read-only variable if minimum > maximum */
1037 };
1038 
1039 /* Special case minimum,maximum marker for sysctl_bounded_args. */
1040 #define SYSCTL_INT_READONLY	1,0
1041 
1042 /*
1043  * Internal sysctl function calling convention:
1044  *
1045  *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
1046  *
1047  * The name parameter points at the next component of the name to be
1048  * interpreted.  The namelen parameter is the number of integers in
1049  * the name.
1050  */
1051 typedef int (sysctlfn)(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
1052 
1053 int sysctl_vslock(void *, size_t);
1054 void sysctl_vsunlock(void *, size_t);
1055 
1056 int sysctl_int_lower(void *, size_t *, void *, size_t, int *);
1057 int sysctl_int(void *, size_t *, void *, size_t, int *);
1058 int sysctl_rdint(void *, size_t *, void *, int);
1059 int sysctl_securelevel_int(void *, size_t *, void *, size_t, int *);
1060 int sysctl_int_bounded(void *, size_t *, void *, size_t, int *, int, int);
1061 int sysctl_bounded_arr(const struct sysctl_bounded_args *, u_int,
1062     int *, u_int, void *, size_t *, void *, size_t);
1063 int sysctl_quad(void *, size_t *, void *, size_t, int64_t *);
1064 int sysctl_rdquad(void *, size_t *, void *, int64_t);
1065 int sysctl_string(void *, size_t *, void *, size_t, char *, size_t);
1066 int sysctl_tstring(void *, size_t *, void *, size_t, char *, size_t);
1067 int sysctl__string(void *, size_t *, void *, size_t, char *, size_t, int);
1068 int sysctl_rdstring(void *, size_t *, void *, const char *);
1069 int sysctl_rdstruct(void *, size_t *, void *, const void *, size_t);
1070 int sysctl_struct(void *, size_t *, void *, size_t, void *, size_t);
1071 int sysctl_file(int *, u_int, char *, size_t *, struct proc *);
1072 int sysctl_doproc(int *, u_int, char *, size_t *);
1073 struct mbuf_queue;
1074 int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t,
1075     struct mbuf_queue *);
1076 struct rtentry;
1077 int sysctl_dumpentry(struct rtentry *, void *, unsigned int);
1078 int sysctl_rtable(int *, u_int, void *, size_t *, void *, size_t);
1079 int sysctl_clockrate(char *, size_t *, void *);
1080 #if defined(GPROF) || defined(DDBPROF)
1081 int sysctl_doprof(int *, u_int, void *, size_t *, void *, size_t);
1082 #endif
1083 int sysctl_dopool(int *, u_int, char *, size_t *);
1084 
1085 int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1086 		     struct proc *);
1087 int hw_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1088 		   struct proc *);
1089 #ifdef DEBUG_SYSCTL
1090 int debug_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1091 		      struct proc *);
1092 #endif
1093 int fs_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1094 		   struct proc *);
1095 int fs_posix_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1096 			 struct proc *);
1097 int net_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1098 		    struct proc *);
1099 int cpu_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1100 		    struct proc *);
1101 int vfs_sysctl(int *, u_int, void *, size_t *, void *, size_t,
1102 		    struct proc *);
1103 int sysctl_sysvipc(int *, u_int, void *, size_t *);
1104 int sysctl_wdog(int *, u_int, void *, size_t *, void *, size_t);
1105 
1106 extern int (*cpu_cpuspeed)(int *);
1107 extern void (*cpu_setperf)(int);
1108 
1109 int net_ifiq_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1110 int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1111 int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1112 int pipex_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1113 int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1114 int pf_sysctl(void *, size_t *, void *, size_t);
1115 int uipc_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1116 
1117 #else	/* !_KERNEL */
1118 
1119 __BEGIN_DECLS
1120 int	sysctl(const int *, u_int, void *, size_t *, void *, size_t);
1121 __END_DECLS
1122 #endif	/* _KERNEL */
1123 #endif	/* !_SYS_SYSCTL_H_ */
1124