Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: sysctl.h,v 1.242 2026/07/10 03:27:57 kre Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Mike Karels at Berkeley Software Design, Inc.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
     35  */
     36 
     37 #ifndef _SYS_SYSCTL_H_
     38 #define	_SYS_SYSCTL_H_
     39 
     40 #include <sys/param.h> /* precautionary upon removal from ucred.h */
     41 #include <sys/proc.h>  /* Needed for things like P_ZOMBIE() and LW_SINTR */
     42 #include <uvm/uvm_param.h>
     43 
     44 #if defined(_KERNEL) || defined(_KMEMUSER)
     45 /*
     46  * These are for the eproc structure defined below.
     47  */
     48 #include <sys/time.h>
     49 #include <sys/ucred.h>
     50 #include <sys/ucontext.h>
     51 #include <sys/mallocvar.h>
     52 #include <uvm/uvm_extern.h>
     53 #endif
     54 
     55 
     56 /* For offsetof() */
     57 #if defined(_KERNEL) || defined(_STANDALONE)
     58 #include <sys/systm.h>
     59 #else
     60 #include <stddef.h>
     61 #include <stdbool.h>
     62 #endif
     63 
     64 /*
     65  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
     66  * for objects that can be examined or modified.  The name is expressed as
     67  * a sequence of integers.  Like a file path name, the meaning of each
     68  * component depends on its place in the hierarchy.  The top-level and kern
     69  * identifiers are defined here, and other identifiers are defined in the
     70  * respective subsystem header files.
     71  */
     72 
     73 struct sysctlnode;
     74 
     75 #define	CTL_MAXNAME	12	/* largest number of components supported */
     76 #define	SYSCTL_NAMELEN	32	/* longest name allowed for a node */
     77 
     78 #define	CREATE_BASE	(1024)	/* start of dynamic mib allocation */
     79 #define	SYSCTL_DEFSIZE	8	/* initial size of a child set */
     80 
     81 /*
     82  * Each subsystem defined by sysctl defines a list of variables
     83  * for that subsystem. Each name is either a node with further
     84  * levels defined below it, or it is a leaf of some particular
     85  * type given below. Each sysctl level defines a set of name/type
     86  * pairs to be used by sysctl(1) in manipulating the subsystem.
     87  */
     88 struct ctlname {
     89 	const char *ctl_name;	/* subsystem name */
     90 	int	ctl_type;	/* type of name */
     91 };
     92 #define	CTLTYPE_NODE	1	/* name is a node */
     93 #define	CTLTYPE_INT	2	/* name describes an integer */
     94 #define	CTLTYPE_STRING	3	/* name describes a string */
     95 #define	CTLTYPE_QUAD	4	/* name describes a 64-bit number */
     96 #define	CTLTYPE_STRUCT	5	/* name describes a structure */
     97 #define	CTLTYPE_BOOL	6	/* name describes a bool */
     98 
     99 #ifdef _LP64
    100 #define	CTLTYPE_LONG	CTLTYPE_QUAD
    101 #else
    102 #define	CTLTYPE_LONG	CTLTYPE_INT
    103 #endif
    104 
    105 /*
    106  * Flags that apply to each node, governing access and other features
    107  */
    108 #define	CTLFLAG_READONLY	0x00000000
    109 /* #define CTLFLAG_UNUSED1		0x00000010 */
    110 /* #define CTLFLAG_UNUSED2		0x00000020 */
    111 /* #define CTLFLAG_READ*	0x00000040 */
    112 #define	CTLFLAG_READWRITE	0x00000070
    113 #define	CTLFLAG_ANYWRITE	0x00000080
    114 #define	CTLFLAG_PRIVATE		0x00000100
    115 #define	CTLFLAG_PERMANENT	0x00000200
    116 #define	CTLFLAG_OWNDATA		0x00000400
    117 #define	CTLFLAG_IMMEDIATE	0x00000800
    118 #define	CTLFLAG_HEX		0x00001000
    119 #define	CTLFLAG_ROOT		0x00002000
    120 #define	CTLFLAG_ANYNUMBER	0x00004000
    121 #define	CTLFLAG_HIDDEN		0x00008000
    122 #define	CTLFLAG_ALIAS		0x00010000
    123 #define	CTLFLAG_MMAP		0x00020000
    124 #define	CTLFLAG_OWNDESC		0x00040000
    125 #define	CTLFLAG_UNSIGNED	0x00080000
    126 
    127 /*
    128  * sysctl API version
    129  */
    130 #define	SYSCTL_VERS_MASK	0xff000000
    131 #define	SYSCTL_VERS_0		0x00000000
    132 #define	SYSCTL_VERS_1		0x01000000
    133 #define	SYSCTL_VERSION		SYSCTL_VERS_1
    134 #define	SYSCTL_VERS(f)		((f) & SYSCTL_VERS_MASK)
    135 
    136 /*
    137  * Flags that can be set by a create request from user-space
    138  */
    139 #define	SYSCTL_USERFLAGS	(CTLFLAG_READWRITE|\
    140 				CTLFLAG_ANYWRITE|\
    141 				CTLFLAG_PRIVATE|\
    142 				CTLFLAG_OWNDATA|\
    143 				CTLFLAG_IMMEDIATE|\
    144 				CTLFLAG_HEX|\
    145 				CTLFLAG_HIDDEN)
    146 
    147 /*
    148  * Accessor macros
    149  */
    150 #define	SYSCTL_TYPEMASK		0x0000000f
    151 #define	SYSCTL_TYPE(x)		((x) & SYSCTL_TYPEMASK)
    152 #define	SYSCTL_FLAGMASK		0x00fffff0
    153 #define	SYSCTL_FLAGS(x)		((x) & SYSCTL_FLAGMASK)
    154 
    155 /*
    156  * Meta-identifiers
    157  */
    158 #define	CTL_EOL		(-1)		/* end of createv/destroyv list */
    159 #define	CTL_QUERY	(-2)		/* enumerates children of a node */
    160 #define	CTL_CREATE	(-3)		/* node create request */
    161 #define	CTL_CREATESYM	(-4)		/* node create request with symbol */
    162 #define	CTL_DESTROY	(-5)		/* node destroy request */
    163 #define	CTL_MMAP	(-6)		/* mmap request */
    164 #define	CTL_DESCRIBE	(-7)		/* get node descriptions */
    165 
    166 /*
    167  * Top-level identifiers
    168  */
    169 #define	CTL_UNSPEC	0		/* unused */
    170 #define	CTL_KERN	1		/* "high kernel": proc, limits */
    171 #define	CTL_VM		2		/* virtual memory */
    172 #define	CTL_VFS		3		/* file system, mount type is next */
    173 #define	CTL_NET		4		/* network, see socket.h */
    174 #define	CTL_DEBUG	5		/* debugging parameters */
    175 #define	CTL_HW		6		/* generic CPU/io */
    176 #define	CTL_MACHDEP	7		/* machine dependent */
    177 #define	CTL_USER	8		/* user-level */
    178 #define	CTL_DDB		9		/* in-kernel debugger */
    179 #define	CTL_PROC	10		/* per-proc attr */
    180 #define	CTL_VENDOR	11		/* vendor-specific data */
    181 #define	CTL_EMUL	12		/* emulation-specific data */
    182 #define	CTL_SECURITY	13		/* security */
    183 
    184 /*
    185  * The "vendor" toplevel name is to be used by vendors who wish to
    186  * have their own private MIB tree. If you do that, please use
    187  * vendor.<yourname>.*
    188  */
    189 
    190 /*
    191  * CTL_KERN identifiers
    192  */
    193 #define	KERN_OSTYPE	 	 1	/* string: system version */
    194 #define	KERN_OSRELEASE	 	 2	/* string: system release */
    195 #define	KERN_OSREV	 	 3	/* int: system revision */
    196 #define	KERN_VERSION	 	 4	/* string: compile time info */
    197 #define	KERN_MAXVNODES	 	 5	/* int: max vnodes */
    198 #define	KERN_MAXPROC	 	 6	/* int: max processes */
    199 #define	KERN_MAXFILES	 	 7	/* int: max open files */
    200 #define	KERN_ARGMAX	 	 8	/* int: max arguments to exec */
    201 #define	KERN_SECURELVL	 	 9	/* int: system security level */
    202 #define	KERN_HOSTNAME		10	/* string: hostname */
    203 #define	KERN_HOSTID		11	/* int: host identifier */
    204 #define	KERN_CLOCKRATE		12	/* struct: struct clockinfo */
    205 #define	KERN_VNODE		13	/* struct: vnode structures */
    206 #define	KERN_PROC		14	/* struct: process entries */
    207 #define	KERN_FILE		15	/* struct: file entries */
    208 #define	KERN_PROF		16	/* node: kernel profiling info */
    209 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
    210 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
    211 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
    212 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
    213 #define	KERN_OBOOTTIME		21	/* struct: time kernel was booted */
    214 #define	KERN_DOMAINNAME		22	/* string: (YP) domainname */
    215 #define	KERN_MAXPARTITIONS	23	/* int: number of partitions/disk */
    216 #define	KERN_RAWPARTITION	24	/* int: raw partition number */
    217 #define	KERN_NTPTIME		25	/* struct: extended-precision time */
    218 #define	KERN_TIMEX		26	/* struct: ntp timekeeping state */
    219 #define	KERN_AUTONICETIME	27	/* int: proc time before autonice */
    220 #define	KERN_AUTONICEVAL	28	/* int: auto nice value */
    221 #define	KERN_RTC_OFFSET		29	/* int: offset of rtc from gmt */
    222 #define	KERN_ROOT_DEVICE	30	/* string: root device */
    223 #define	KERN_MSGBUFSIZE		31	/* int: max # of chars in msg buffer */
    224 #define	KERN_FSYNC		32	/* int: file synchronization support */
    225 #define	KERN_OLDSYSVMSG		33	/* old: SysV message queue support */
    226 #define	KERN_OLDSYSVSEM		34	/* old: SysV semaphore support */
    227 #define	KERN_OLDSYSVSHM		35	/* old: SysV shared memory support */
    228 #define	KERN_OLDSHORTCORENAME	36	/* old, unimplemented */
    229 #define	KERN_SYNCHRONIZED_IO	37	/* int: POSIX synchronized I/O */
    230 #define	KERN_IOV_MAX		38	/* int: max iovec's for readv(2) etc. */
    231 #define	KERN_MBUF		39	/* node: mbuf parameters */
    232 #define	KERN_MAPPED_FILES	40	/* int: POSIX memory mapped files */
    233 #define	KERN_MEMLOCK		41	/* int: POSIX memory locking */
    234 #define	KERN_MEMLOCK_RANGE	42	/* int: POSIX memory range locking */
    235 #define	KERN_MEMORY_PROTECTION	43	/* int: POSIX memory protections */
    236 #define	KERN_LOGIN_NAME_MAX	44	/* int: max length login name + NUL */
    237 #define	KERN_DEFCORENAME	45	/* old: sort core name format */
    238 #define	KERN_LOGSIGEXIT		46	/* int: log signaled processes */
    239 #define	KERN_PROC2		47	/* struct: process entries */
    240 #define	KERN_PROC_ARGS		48	/* struct: process argv/env */
    241 #define	KERN_FSCALE		49	/* int: fixpt FSCALE */
    242 #define	KERN_CCPU		50	/* old: fixpt ccpu */
    243 #define	KERN_CP_TIME		51	/* struct: CPU time counters */
    244 #define	KERN_OLDSYSVIPC_INFO	52	/* old: number of valid kern ids */
    245 #define	KERN_MSGBUF		53	/* kernel message buffer */
    246 #define	KERN_CONSDEV		54	/* dev_t: console terminal device */
    247 #define	KERN_MAXPTYS		55	/* int: maximum number of ptys */
    248 #define	KERN_PIPE		56	/* node: pipe limits */
    249 #define	KERN_MAXPHYS		57	/* int: kernel value of MAXPHYS */
    250 #define	KERN_SBMAX		58	/* int: max socket buffer size */
    251 #define	KERN_TKSTAT		59	/* tty in/out counters */
    252 #define	KERN_MONOTONIC_CLOCK	60	/* int: POSIX monotonic clock */
    253 #define	KERN_URND		61	/* int: random integer from urandom */
    254 #define	KERN_LABELSECTOR	62	/* int: disklabel sector */
    255 #define	KERN_LABELOFFSET	63	/* int: offset of label within sector */
    256 #define	KERN_LWP		64	/* struct: lwp entries */
    257 #define	KERN_FORKFSLEEP		65	/* int: sleep length on failed fork */
    258 #define	KERN_POSIX_THREADS	66	/* int: POSIX Threads option */
    259 #define	KERN_POSIX_SEMAPHORES	67	/* int: POSIX Semaphores option */
    260 #define	KERN_POSIX_BARRIERS	68	/* int: POSIX Barriers option */
    261 #define	KERN_POSIX_TIMERS	69	/* int: POSIX Timers option */
    262 #define	KERN_POSIX_SPIN_LOCKS	70	/* int: POSIX Spin Locks option */
    263 #define	KERN_POSIX_READER_WRITER_LOCKS 71 /* int: POSIX R/W Locks option */
    264 #define	KERN_DUMP_ON_PANIC	72	/* int: dump on panic */
    265 #define	KERN_SOMAXKVA		73	/* int: max socket kernel virtual mem */
    266 #define	KERN_ROOT_PARTITION	74	/* int: root partition */
    267 #define	KERN_DRIVERS		75	/* struct: driver names and majors #s */
    268 #define	KERN_BUF		76	/* struct: buffers */
    269 #define	KERN_FILE2		77	/* struct: file entries */
    270 #define	KERN_VERIEXEC		78	/* node: verified exec */
    271 #define	KERN_CP_ID		79	/* struct: cpu id numbers */
    272 #define	KERN_HARDCLOCK_TICKS	80	/* int: number of hardclock ticks */
    273 #define	KERN_ARND		81	/* void *buf, size_t siz random */
    274 #define	KERN_SYSVIPC		82	/* node: SysV IPC parameters */
    275 #define	KERN_BOOTTIME		83	/* struct: time kernel was booted */
    276 #define	KERN_EVCNT		84	/* struct: evcnts */
    277 #define	KERN_SOFIXEDBUF		85	/* bool: fixed socket buffer sizes */
    278 #define	KERN_ENTROPY		86	/* node: entropy(9) subsystem */
    279 
    280 /*
    281  *  KERN_CLOCKRATE structure
    282  */
    283 struct clockinfo {
    284 	int	hz;		/* clock frequency */
    285 	int	tick;		/* micro-seconds per hz tick */
    286 	int	tickadj;	/* clock skew rate for adjtime() */
    287 	int	stathz;		/* statistics clock frequency */
    288 	int	profhz;		/* profiling clock frequency */
    289 };
    290 
    291 /*
    292  * KERN_PROC subtypes
    293  */
    294 #define	KERN_PROC_ALL		 0	/* everything */
    295 #define	KERN_PROC_PID		 1	/* by process id */
    296 #define	KERN_PROC_PGRP		 2	/* by process group id */
    297 #define	KERN_PROC_SESSION	 3	/* by session of pid */
    298 #define	KERN_PROC_TTY		 4	/* by controlling tty */
    299 #define	KERN_PROC_UID		 5	/* by effective uid */
    300 #define	KERN_PROC_RUID		 6	/* by real uid */
    301 #define	KERN_PROC_GID		 7	/* by effective gid */
    302 #define	KERN_PROC_RGID		 8	/* by real gid */
    303 
    304 /*
    305  * KERN_PROC_TTY sub-subtypes
    306  */
    307 #define	KERN_PROC_TTY_NODEV	NODEV		/* no controlling tty */
    308 #define	KERN_PROC_TTY_REVOKE	((dev_t)-2)	/* revoked tty */
    309 
    310 struct ki_pcred {
    311 	void		*p_pad;
    312 	uid_t		p_ruid;		/* Real user id */
    313 	uid_t		p_svuid;	/* Saved effective user id */
    314 	gid_t		p_rgid;		/* Real group id */
    315 	gid_t		p_svgid;	/* Saved effective group id */
    316 	int		p_refcnt;	/* Number of references */
    317 };
    318 
    319 struct ki_ucred {
    320 	uint32_t	cr_ref;			/* reference count */
    321 	uid_t		cr_uid;			/* effective user id */
    322 	gid_t		cr_gid;			/* effective group id */
    323 	uint32_t	cr_ngroups;		/* number of groups */
    324 	gid_t		cr_groups[NGROUPS];	/* groups */
    325 };
    326 
    327 #if defined(_KERNEL) || defined(_KMEMUSER)
    328 
    329 struct	eproc {
    330 	struct	proc *e_paddr;		/* address of proc */
    331 	struct	session *e_sess;	/* session pointer */
    332 	struct	ki_pcred e_pcred;	/* process credentials */
    333 	struct	ki_ucred e_ucred;	/* current credentials */
    334 	struct	vmspace e_vm;		/* address space */
    335 	pid_t	e_ppid;			/* parent process id */
    336 	pid_t	e_pgid;			/* process group id */
    337 	short	e_jobc;			/* job control counter */
    338 	uint32_t e_tdev;		/* XXX: controlling tty dev */
    339 	pid_t	e_tpgid;		/* tty process group id */
    340 	struct	session *e_tsess;	/* tty session pointer */
    341 #define	WMESGLEN	8
    342 	char	e_wmesg[WMESGLEN];	/* wchan message */
    343 	segsz_t e_xsize;		/* text size */
    344 	short	e_xrssize;		/* text rss */
    345 	short	e_xccount;		/* text references */
    346 	short	e_xswrss;
    347 	long	e_flag;			/* see p_eflag  below */
    348 	char	e_login[MAXLOGNAME];	/* setlogin() name */
    349 	pid_t	e_sid;			/* session id */
    350 	long	e_spare[3];
    351 };
    352 
    353 /*
    354  * KERN_PROC subtype ops return arrays of augmented proc structures:
    355  */
    356 struct kinfo_proc {
    357 	struct	proc kp_proc;			/* proc structure */
    358 	struct	eproc kp_eproc;			/* eproc structure */
    359 };
    360 #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
    361 
    362 /*
    363  * Convert pointer to 64 bit unsigned integer for struct
    364  * kinfo_proc2, etc.
    365  */
    366 #define	PTRTOUINT64(p) ((uint64_t)(uintptr_t)(p))
    367 #define	UINT64TOPTR(u) ((void *)(uintptr_t)(u))
    368 
    369 /*
    370  * KERN_PROC2 subtype ops return arrays of relatively fixed size
    371  * structures of process info.   Use 8 byte alignment, and new
    372  * elements should only be added to the end of this structure so
    373  * binary compatibility can be preserved.
    374  */
    375 #define	KI_NGROUPS	16
    376 #define	KI_MAXCOMLEN	24	/* extra for 8 byte alignment */
    377 #define	KI_WMESGLEN	8
    378 #define	KI_MAXLOGNAME	24	/* extra for 8 byte alignment */
    379 #define	KI_MAXEMULLEN	16
    380 #define	KI_LNAMELEN	20	/* extra 4 for alignment */
    381 
    382 #define	KI_NOCPU	(~(uint64_t)0)
    383 
    384 typedef struct {
    385 	uint32_t	__bits[4];
    386 } ki_sigset_t;
    387 
    388 struct kinfo_proc2 {
    389 	uint64_t p_forw;		/* PTR: linked run/sleep queue. */
    390 	uint64_t p_back;
    391 	uint64_t p_paddr;		/* PTR: address of proc */
    392 
    393 	uint64_t p_addr;		/* PTR: Kernel virtual addr of u-area */
    394 	uint64_t p_fd;			/* PTR: Ptr to open files structure. */
    395 	uint64_t p_cwdi;		/* PTR: cdir/rdir/cmask info */
    396 	uint64_t p_stats;		/* PTR: Accounting/statistics */
    397 	uint64_t p_limit;		/* PTR: Process limits. */
    398 	uint64_t p_vmspace;		/* PTR: Address space. */
    399 	uint64_t p_sigacts;		/* PTR: Signal actions, state */
    400 	uint64_t p_sess;		/* PTR: session pointer */
    401 	uint64_t p_tsess;		/* PTR: tty session pointer */
    402 	uint64_t p_ru;			/* PTR: Exit information. XXX */
    403 
    404 	int32_t	p_eflag;		/* LONG: extra kinfo_proc2 flags */
    405 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
    406 #define	EPROC_SLEADER	0x02	/* session leader */
    407 	int32_t	p_exitsig;		/* INT: signal to sent to parent on exit */
    408 	int32_t	p_flag;			/* INT: P_* flags. */
    409 
    410 	int32_t	p_pid;			/* PID_T: Process identifier. */
    411 	int32_t	p_ppid;			/* PID_T: Parent process id */
    412 	int32_t	p_sid;			/* PID_T: session id */
    413 	int32_t	p__pgid;		/* PID_T: process group id */
    414 					/* XXX: <sys/proc.h> hijacks p_pgid */
    415 	int32_t	p_tpgid;		/* PID_T: tty process group id */
    416 
    417 	uint32_t p_uid;			/* UID_T: effective user id */
    418 	uint32_t p_ruid;		/* UID_T: real user id */
    419 	uint32_t p_gid;			/* GID_T: effective group id */
    420 	uint32_t p_rgid;		/* GID_T: real group id */
    421 
    422 	uint32_t p_groups[KI_NGROUPS];	/* GID_T: groups */
    423 	int16_t	p_ngroups;		/* SHORT: number of groups */
    424 
    425 	int16_t	p_jobc;			/* SHORT: job control counter */
    426 	uint32_t p_tdev;		/* XXX: DEV_T: controlling tty dev */
    427 
    428 	uint32_t p_estcpu;		/* U_INT: Time averaged value of p_cpticks. */
    429 	uint32_t p_rtime_sec;		/* STRUCT TIMEVAL: Real time. */
    430 	uint32_t p_rtime_usec;		/* STRUCT TIMEVAL: Real time. */
    431 	int32_t	p_cpticks;		/* INT: Ticks of CPU time. */
    432 	uint32_t p_pctcpu;		/* FIXPT_T: %cpu for this process during p_swtime */
    433 	uint32_t p_swtime;		/* U_INT: Time swapped in or out. */
    434 	uint32_t p_slptime;		/* U_INT: Time since last blocked. */
    435 	int32_t	p_schedflags;		/* INT: PSCHED_* flags */
    436 
    437 	uint64_t p_uticks;		/* U_QUAD_T: Statclock hits in user mode. */
    438 	uint64_t p_sticks;		/* U_QUAD_T: Statclock hits in system mode. */
    439 	uint64_t p_iticks;		/* U_QUAD_T: Statclock hits processing intr. */
    440 
    441 	uint64_t p_tracep;		/* PTR: Trace to vnode or file */
    442 	int32_t	p_traceflag;		/* INT: Kernel trace points. */
    443 
    444 	int32_t	p_holdcnt;              /* INT: If non-zero, don't swap. */
    445 
    446 	ki_sigset_t p_siglist;		/* SIGSET_T: Signals arrived but not delivered. */
    447 	ki_sigset_t p_sigmask;		/* SIGSET_T: Current signal mask. */
    448 	ki_sigset_t p_sigignore;	/* SIGSET_T: Signals being ignored. */
    449 	ki_sigset_t p_sigcatch;		/* SIGSET_T: Signals being caught by user. */
    450 
    451 	int8_t	p_stat;			/* CHAR: S* process status (from LWP). */
    452 	uint8_t p_priority;		/* U_CHAR: Process priority. */
    453 	uint8_t p_usrpri;		/* U_CHAR: User-priority based on p_cpu and p_nice. */
    454 	uint8_t p_nice;			/* U_CHAR: Process "nice" value. */
    455 
    456 	uint16_t p_xstat;		/* U_SHORT: Exit status for wait; also stop signal. */
    457 	uint16_t p_acflag;		/* U_SHORT: Accounting flags. */
    458 
    459 	char	p_comm[KI_MAXCOMLEN];
    460 
    461 	char	p_wmesg[KI_WMESGLEN];	/* wchan message */
    462 	uint64_t p_wchan;		/* PTR: sleep address. */
    463 
    464 	char	p_login[KI_MAXLOGNAME];	/* setlogin() name */
    465 
    466 	int32_t	p_vm_rssize;		/* SEGSZ_T: current resident set size in pages */
    467 	int32_t	p_vm_tsize;		/* SEGSZ_T: text size (pages) */
    468 	int32_t	p_vm_dsize;		/* SEGSZ_T: data size (pages) */
    469 	int32_t	p_vm_ssize;		/* SEGSZ_T: stack size (pages) */
    470 
    471 	int64_t	p_uvalid;		/* CHAR: following p_u* parameters are valid */
    472 					/* XXX 64 bits for alignment */
    473 	uint32_t p_ustart_sec;		/* STRUCT TIMEVAL: starting time. */
    474 	uint32_t p_ustart_usec;		/* STRUCT TIMEVAL: starting time. */
    475 
    476 	uint32_t p_uutime_sec;		/* STRUCT TIMEVAL: user time. */
    477 	uint32_t p_uutime_usec;		/* STRUCT TIMEVAL: user time. */
    478 	uint32_t p_ustime_sec;		/* STRUCT TIMEVAL: system time. */
    479 	uint32_t p_ustime_usec;		/* STRUCT TIMEVAL: system time. */
    480 
    481 	uint64_t p_uru_maxrss;		/* LONG: max resident set size. */
    482 	uint64_t p_uru_ixrss;		/* LONG: integral shared memory size. */
    483 	uint64_t p_uru_idrss;		/* LONG: integral unshared data ". */
    484 	uint64_t p_uru_isrss;		/* LONG: integral unshared stack ". */
    485 	uint64_t p_uru_minflt;		/* LONG: page reclaims. */
    486 	uint64_t p_uru_majflt;		/* LONG: page faults. */
    487 	uint64_t p_uru_nswap;		/* LONG: swaps. */
    488 	uint64_t p_uru_inblock;		/* LONG: block input operations. */
    489 	uint64_t p_uru_oublock;		/* LONG: block output operations. */
    490 	uint64_t p_uru_msgsnd;		/* LONG: messages sent. */
    491 	uint64_t p_uru_msgrcv;		/* LONG: messages received. */
    492 	uint64_t p_uru_nsignals;	/* LONG: signals received. */
    493 	uint64_t p_uru_nvcsw;		/* LONG: voluntary context switches. */
    494 	uint64_t p_uru_nivcsw;		/* LONG: involuntary ". */
    495 
    496 	uint32_t p_uctime_sec;		/* STRUCT TIMEVAL: child u+s time. */
    497 	uint32_t p_uctime_usec;		/* STRUCT TIMEVAL: child u+s time. */
    498 	uint64_t p_cpuid;		/* LONG: CPU id */
    499 	uint64_t p_realflag;	       	/* INT: P_* flags (not including LWPs). */
    500 	uint64_t p_nlwps;		/* LONG: Number of LWPs */
    501 	uint64_t p_nrlwps;		/* LONG: Number of running LWPs */
    502 	uint64_t p_realstat;		/* LONG: non-LWP process status */
    503 	uint32_t p_svuid;		/* UID_T: saved user id */
    504 	uint32_t p_svgid;		/* GID_T: saved group id */
    505 	char p_ename[KI_MAXEMULLEN];	/* emulation name */
    506 	int64_t	p_vm_vsize;		/* SEGSZ_T: total map size (pages) */
    507 	int64_t	p_vm_msize;		/* SEGSZ_T: stack-adjusted map size (pages) */
    508 };
    509 
    510 /*
    511  * Compat flags for kinfo_proc, kinfo_proc2.  Not guaranteed to be stable.
    512  * Some of them used to be shared with LWP flags.
    513  * XXXAD Trim to the minimum necessary...
    514  */
    515 
    516 #define	P_ADVLOCK		0x00000001
    517 #define	P_CONTROLT		0x00000002
    518 #define	L_INMEM			0x00000004
    519 #define	P_INMEM		     /* 0x00000004 */	L_INMEM
    520 #define	P_NOCLDSTOP		0x00000008
    521 #define	P_PPWAIT		0x00000010
    522 #define	P_PROFIL		0x00000020
    523 #define	L_SELECT		0x00000040
    524 #define	P_SELECT	     /* 0x00000040 */	L_SELECT
    525 #define	L_SINTR			0x00000080
    526 #define	P_SINTR		     /* 0x00000080 */	L_SINTR
    527 #define	P_SUGID			0x00000100
    528 #define	L_SYSTEM	     	0x00000200
    529 #define	P_SYSTEM	     /*	0x00000200 */	L_SYSTEM
    530 #define	L_SA			0x00000400
    531 #define	P_SA		     /* 0x00000400 */	L_SA
    532 #define	P_TRACED		0x00000800
    533 #define	P_WAITED		0x00001000
    534 #define	P_WEXIT			0x00002000
    535 #define	P_EXEC			0x00004000
    536 #define	P_OWEUPC		0x00008000
    537 #define	P_NOCLDWAIT		0x00020000
    538 #define	P_32			0x00040000
    539 #define	P_CLDSIGIGN		0x00080000
    540 #define	P_SYSTRACE		0x00200000
    541 #define	P_CHTRACED		0x00400000
    542 #define	P_STOPFORK		0x00800000
    543 #define	P_STOPEXEC		0x01000000
    544 #define	P_STOPEXIT		0x02000000
    545 #define	P_SYSCALL		0x04000000
    546 
    547 /*
    548  * LWP compat flags.
    549  */
    550 #define	L_DETACHED		0x00800000
    551 
    552 #define	__SYSCTL_PROC_FLAG_BITS \
    553 	"\20" \
    554 	"\1ADVLOCK" \
    555 	"\2CONTROLT" \
    556 	"\3INMEM" \
    557 	"\4NOCLDSTOP" \
    558 	"\5PPWAIT" \
    559 	"\6PROFIL" \
    560 	"\7SELECT" \
    561 	"\10SINTR" \
    562 	"\11SUGID" \
    563 	"\12SYSTEM" \
    564 	"\13SA" \
    565 	"\14TRACED" \
    566 	"\15WAITED" \
    567 	"\16WEXIT" \
    568 	"\17EXEC" \
    569 	"\20OWEUPC" \
    570 	"\22NOCLDWAIT" \
    571 	"\23P32" \
    572 	"\24CLDSIGIGN" \
    573 	"\26SYSTRACE" \
    574 	"\27CHTRACED" \
    575 	"\30STOPFORK" \
    576 	"\31STOPEXEC" \
    577 	"\32STOPEXIT" \
    578 	"\33SYSCALL"
    579 
    580 /*
    581  * KERN_LWP structure. See notes on KERN_PROC2 about adding elements.
    582  */
    583 struct kinfo_lwp {
    584 	uint64_t l_forw;		/* PTR: linked run/sleep queue. */
    585 	uint64_t l_back;
    586 	uint64_t l_laddr;		/* PTR: Address of LWP */
    587 	uint64_t l_addr;		/* PTR: Kernel virtual addr of u-area */
    588 	int32_t	l_lid;			/* LWPID_T: LWP identifier */
    589 	int32_t	l_flag;			/* INT: L_* flags. */
    590 	uint32_t l_swtime;		/* U_INT: Time swapped in or out. */
    591 	uint32_t l_slptime;		/* U_INT: Time since last blocked. */
    592 	int32_t	l_schedflags;		/* INT: PSCHED_* flags */
    593 	int32_t	l_holdcnt;              /* INT: If non-zero, don't swap. */
    594 	uint8_t l_priority;		/* U_CHAR: Process priority. */
    595 	uint8_t l_usrpri;		/* U_CHAR: User-priority based on l_cpu and p_nice. */
    596 	int8_t	l_stat;			/* CHAR: S* process status. */
    597 	int8_t	l_pad1;			/* fill out to 4-byte boundary */
    598 	int32_t	l_pad2;			/* .. and then to an 8-byte boundary */
    599 	char	l_wmesg[KI_WMESGLEN];	/* wchan message */
    600 	uint64_t l_wchan;		/* PTR: sleep address. */
    601 	uint64_t l_cpuid;		/* LONG: CPU id */
    602 	uint32_t l_rtime_sec;		/* STRUCT TIMEVAL: Real time. */
    603 	uint32_t l_rtime_usec;		/* STRUCT TIMEVAL: Real time. */
    604 	uint32_t l_cpticks;		/* INT: ticks during l_swtime */
    605 	uint32_t l_pctcpu;		/* FIXPT_T: cpu usage for ps */
    606 	uint32_t l_pid;			/* PID_T: process identifier */
    607 	char	l_name[KI_LNAMELEN];	/* CHAR[]: name, may be empty */
    608 };
    609 
    610 /*
    611  * KERN_PROC_ARGS subtypes
    612  */
    613 #define	KERN_PROC_ARGV		1	/* argv */
    614 #define	KERN_PROC_NARGV		2	/* number of strings in above */
    615 #define	KERN_PROC_ENV		3	/* environ */
    616 #define	KERN_PROC_NENV		4	/* number of strings in above */
    617 #define	KERN_PROC_PATHNAME 	5	/* path to executable */
    618 #define	KERN_PROC_CWD 		6	/* current working dir */
    619 
    620 /*
    621  * KERN_SYSVIPC subtypes
    622  */
    623 #define	KERN_SYSVIPC_INFO	1	/* struct: number of valid kern ids */
    624 #define	KERN_SYSVIPC_MSG	2	/* int: SysV message queue support */
    625 #define	KERN_SYSVIPC_SEM	3	/* int: SysV semaphore support */
    626 #define	KERN_SYSVIPC_SHM	4	/* int: SysV shared memory support */
    627 #define	KERN_SYSVIPC_SHMMAX	5	/* int: max shared memory segment size (bytes) */
    628 #define	KERN_SYSVIPC_SHMMNI	6	/* int: max number of shared memory identifiers */
    629 #define	KERN_SYSVIPC_SHMSEG	7	/* int: max shared memory segments per process */
    630 #define	KERN_SYSVIPC_SHMMAXPGS	8	/* int: max amount of shared memory (pages) */
    631 #define	KERN_SYSVIPC_SHMUSEPHYS	9	/* int: physical memory usage */
    632 
    633 /*
    634  * KERN_SYSVIPC_INFO subtypes
    635  */
    636 /* KERN_SYSVIPC_OMSG_INFO		1	*/
    637 /* KERN_SYSVIPC_OSEM_INFO		2	*/
    638 /* KERN_SYSVIPC_OSHM_INFO		3	*/
    639 #define	KERN_SYSVIPC_MSG_INFO		4	/* msginfo and msgid_ds */
    640 #define	KERN_SYSVIPC_SEM_INFO		5	/* seminfo and semid_ds */
    641 #define	KERN_SYSVIPC_SHM_INFO		6	/* shminfo and shmid_ds */
    642 
    643 /*
    644  * tty counter sysctl variables
    645  */
    646 #define	KERN_TKSTAT_NIN			1	/* total input character */
    647 #define	KERN_TKSTAT_NOUT		2	/* total output character */
    648 #define	KERN_TKSTAT_CANCC		3	/* canonical input character */
    649 #define	KERN_TKSTAT_RAWCC		4	/* raw input character */
    650 
    651 /*
    652  * kern.drivers returns an array of these.
    653  */
    654 
    655 struct kinfo_drivers {
    656 	devmajor_t	d_cmajor;
    657 	devmajor_t	d_bmajor;
    658 	char		d_name[24];
    659 };
    660 
    661 /*
    662  * KERN_BUF subtypes, like KERN_PROC2, where the four following mib
    663  * entries specify "which type of buf", "which particular buf",
    664  * "sizeof buf", and "how many".  Currently, only "all buf" is
    665  * defined.
    666  */
    667 #define	KERN_BUF_ALL	0		/* all buffers */
    668 
    669 /*
    670  * kern.buf returns an array of these structures, which are designed
    671  * both to be immune to 32/64 bit emulation issues and to provide
    672  * backwards compatibility.  Note that the order here differs slightly
    673  * from the real struct buf in order to achieve proper 64 bit
    674  * alignment.
    675  */
    676 struct buf_sysctl {
    677 	uint32_t b_flags;	/* LONG: B_* flags */
    678 	int32_t  b_error;	/* INT: Errno value */
    679 	int32_t  b_prio;	/* INT: Hint for buffer queue discipline */
    680 	uint32_t b_dev;		/* DEV_T: Device associated with buffer */
    681 	uint64_t b_bufsize;	/* LONG: Allocated buffer size */
    682 	uint64_t b_bcount;	/* LONG: Valid bytes in buffer */
    683 	uint64_t b_resid;	/* LONG: Remaining I/O */
    684 	uint64_t b_addr;	/* CADDR_T: Memory, superblocks, indirect... */
    685 	uint64_t b_blkno;	/* DADDR_T: Underlying physical block number */
    686 	uint64_t b_rawblkno;	/* DADDR_T: Raw underlying physical block */
    687 	uint64_t b_iodone;	/* PTR: Function called upon completion */
    688 	uint64_t b_proc;	/* PTR: Associated proc if B_PHYS set */
    689 	uint64_t b_vp;		/* PTR: File vnode */
    690 	uint64_t b_saveaddr;	/* PTR: Original b_addr for physio */
    691 	uint64_t b_lblkno;	/* DADDR_T: Logical block number */
    692 };
    693 
    694 #define	KERN_BUFSLOP	20
    695 
    696 /*
    697  * kern.file2 returns an array of these structures, which are designed
    698  * both to be immune to 32/64 bit emulation issues and to
    699  * provide backwards compatibility.  The order differs slightly from
    700  * that of the real struct file, and some fields are taken from other
    701  * structures (struct vnode, struct proc) in order to make the file
    702  * information more useful.
    703  */
    704 struct kinfo_file {
    705 	uint64_t	ki_fileaddr;	/* PTR: address of struct file */
    706 	uint32_t	ki_flag;	/* INT: flags (see fcntl.h) */
    707 	uint32_t	ki_iflags;	/* INT: internal flags */
    708 	uint32_t	ki_ftype;	/* INT: descriptor type */
    709 	uint32_t	ki_count;	/* UINT: reference count */
    710 	uint32_t	ki_msgcount;	/* UINT: references from msg queue */
    711 	uint32_t	ki_usecount;	/* INT: number active users */
    712 	uint64_t	ki_fucred;	/* PTR: creds for descriptor */
    713 	uint32_t	ki_fuid;	/* UID_T: descriptor credentials */
    714 	uint32_t	ki_fgid;	/* GID_T: descriptor credentials */
    715 	uint64_t	ki_fops;	/* PTR: address of fileops */
    716 	uint64_t	ki_foffset;	/* OFF_T: offset */
    717 	uint64_t	ki_fdata;	/* PTR: descriptor data */
    718 
    719 	/* vnode information to glue this file to something */
    720 	uint64_t	ki_vun;		/* PTR: socket, specinfo, etc */
    721 	uint64_t	ki_vsize;	/* OFF_T: size of file */
    722 	uint32_t	ki_vtype;	/* ENUM: vnode type */
    723 	uint32_t	ki_vtag;	/* ENUM: type of underlying data */
    724 	uint64_t	ki_vdata;	/* PTR: private data for fs */
    725 
    726 	/* process information when retrieved via KERN_FILE_BYPID */
    727 	uint32_t	ki_pid;		/* PID_T: process id */
    728 	int32_t		ki_fd;		/* INT: descriptor number */
    729 	uint32_t	ki_ofileflags;	/* CHAR: open file flags */
    730 	uint32_t	_ki_padto64bits;
    731 };
    732 
    733 #define	KERN_FILE_BYFILE	1
    734 #define	KERN_FILE_BYPID		2
    735 #define	KERN_FILESLOP		10
    736 
    737 /*
    738  * kern.evcnt returns an array of these structures, which are designed both to
    739  * be immune to 32/64 bit emulation issues.  Note that the struct here differs
    740  * from the real struct evcnt but contains the same information in order to
    741  * accommodate sysctl.
    742  */
    743 struct evcnt_sysctl {
    744 	uint64_t	ev_count;		/* current count */
    745 	uint64_t	ev_addr;		/* kernel address of evcnt */
    746 	uint64_t	ev_parent;		/* kernel address of parent */
    747 	uint8_t		ev_type;		/* EVCNT_TRAP_* */
    748 	uint8_t		ev_grouplen;		/* length of group with NUL */
    749 	uint8_t		ev_namelen;		/* length of name with NUL */
    750 	uint8_t		ev_len;			/* multiply by 8 */
    751 	/*
    752 	 * Now the group and name strings follow (both include the trailing
    753 	 * NUL).  ev_name start at &ev_strings[ev_grouplen+1]
    754 	 */
    755 	char		ev_strings[];
    756 };
    757 
    758 #define	KERN_EVCNT_COUNT_ANY		0
    759 #define	KERN_EVCNT_COUNT_NONZERO	1
    760 
    761 
    762 /*
    763  * kern.hashstat returns an array of these structures, which are designed
    764  * to be immune to 32/64 bit emulation issues.
    765  *
    766  * Hash users can register a filler function to fill the hashstat_sysctl
    767  * which can then be exposed via vmstat(1).
    768  *
    769  * See comments for hashstat_sysctl() in kern/subr_hash.c for details
    770  * on sysctl(3) usage.
    771  */
    772 struct hashstat_sysctl {
    773 	char		hash_name[SYSCTL_NAMELEN];
    774 	char		hash_desc[SYSCTL_NAMELEN];
    775 	uint64_t	hash_size;
    776 	uint64_t	hash_used;
    777 	uint64_t	hash_items;
    778 	uint64_t	hash_maxchain;
    779 };
    780 typedef int	(*hashstat_func_t)(struct hashstat_sysctl *, bool);
    781 void		hashstat_register(const char *, hashstat_func_t);
    782 
    783 /*
    784  * kern.entropy.* variables
    785  */
    786 
    787 #define	KERN_ENTROPY_EPOCH	1	/* int: PRNG reseed epoch */
    788 
    789 /*
    790  * CTL_VM identifiers in <uvm/uvm_param.h>
    791  */
    792 
    793 /*
    794  * The vm.proc.map sysctl allows a process to dump the VM layout of
    795  * another process as a series of entries.
    796  */
    797 #define	KVME_TYPE_NONE		0
    798 #define	KVME_TYPE_OBJECT	1
    799 #define	KVME_TYPE_VNODE		2
    800 #define	KVME_TYPE_KERN		3
    801 #define	KVME_TYPE_DEVICE	4
    802 #define	KVME_TYPE_ANON		5
    803 #define	KVME_TYPE_SUBMAP	6
    804 #define	KVME_TYPE_UNKNOWN	255
    805 
    806 #define	KVME_PROT_READ		0x00000001
    807 #define	KVME_PROT_WRITE		0x00000002
    808 #define	KVME_PROT_EXEC		0x00000004
    809 
    810 #define	KVME_FLAG_COW		0x00000001
    811 #define	KVME_FLAG_NEEDS_COPY	0x00000002
    812 #define	KVME_FLAG_NOCOREDUMP	0x00000004
    813 #define	KVME_FLAG_PAGEABLE	0x00000008
    814 #define	KVME_FLAG_GROWS_UP	0x00000010
    815 #define	KVME_FLAG_GROWS_DOWN	0x00000020
    816 
    817 struct kinfo_vmentry {
    818 	uint64_t kve_start;			/* Starting address. */
    819 	uint64_t kve_end;			/* Finishing address. */
    820 	uint64_t kve_offset;			/* Mapping offset in object */
    821 
    822 	uint32_t kve_type;			/* Type of map entry. */
    823 	uint32_t kve_flags;			/* Flags on map entry. */
    824 
    825 	uint32_t kve_count;			/* Number of pages/entries */
    826 	uint32_t kve_wired_count;		/* Number of wired pages */
    827 
    828 	uint32_t kve_advice;			/* Advice */
    829 	uint32_t kve_attributes;		/* Map attribute */
    830 
    831 	uint32_t kve_protection;		/* Protection bitmask. */
    832 	uint32_t kve_max_protection;		/* Max protection bitmask */
    833 
    834 	uint32_t kve_ref_count;			/* VM obj ref count. */
    835 	uint32_t kve_inheritance;		/* Inheritance */
    836 
    837 	uint64_t kve_vn_fileid;			/* inode number if vnode */
    838 	uint64_t kve_vn_size;			/* File size. */
    839 	uint64_t kve_vn_fsid;			/* dev_t of vnode location */
    840 	uint64_t kve_vn_rdev;			/* Device id if device. */
    841 
    842 	uint32_t kve_vn_type;			/* Vnode type. */
    843 	uint32_t kve_vn_mode;			/* File mode. */
    844 
    845 	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
    846 };
    847 
    848 /*
    849  * CTL_HW identifiers
    850  */
    851 #define	HW_MACHINE	 1		/* string: machine class */
    852 #define	HW_MODEL	 2		/* string: specific machine model */
    853 #define	HW_NCPU		 3		/* int: number of cpus */
    854 #define	HW_BYTEORDER	 4		/* int: machine byte order */
    855 #define	HW_PHYSMEM	 5		/* int: total memory (bytes) */
    856 #define	HW_USERMEM	 6		/* int: non-kernel memory (bytes) */
    857 #define	HW_PAGESIZE	 7		/* int: software page size */
    858 #define	HW_DISKNAMES	 8		/* string: disk drive names */
    859 #define	HW_IOSTATS	 9		/* struct: iostats[] */
    860 #define	HW_MACHINE_ARCH	10		/* string: machine architecture */
    861 #define	HW_ALIGNBYTES	11		/* int: ALIGNBYTES for the kernel */
    862 #define	HW_CNMAGIC	12		/* string: console magic sequence(s) */
    863 #define	HW_PHYSMEM64	13		/* quad: total memory (bytes) */
    864 #define	HW_USERMEM64	14		/* quad: non-kernel memory (bytes) */
    865 #define	HW_IOSTATNAMES	15		/* string: iostat names */
    866 #define	HW_NCPUONLINE	16		/* number CPUs online */
    867 
    868 /*
    869  * CTL_USER definitions
    870  */
    871 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
    872 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
    873 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
    874 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
    875 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
    876 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
    877 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
    878 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
    879 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
    880 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
    881 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
    882 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
    883 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
    884 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
    885 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
    886 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
    887 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
    888 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
    889 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
    890 #define	USER_TZNAME_MAX		20	/* int: _POSIX_TZNAME_MAX */
    891 #define	USER_ATEXIT_MAX		21	/* int: {ATEXIT_MAX} */
    892 #define	USER_OSTYPE		22	/* str: "NetBSD" */
    893 #define	USER_OSREVISION		23	/* int: __NetBSD_Version__ */
    894 #define	USER_OSRELEASE		24	/* str: "11.0_RC6" (or whatever) */
    895 #define	USER_BUILDTIME		25	/* str: YYYY-MM-DD hh:mm:ss UTC [!] */
    896 
    897 /*
    898  * CTL_DDB definitions
    899  */
    900 #define	DDBCTL_RADIX		1	/* int: Input and output radix */
    901 #define	DDBCTL_MAXOFF		2	/* int: max symbol offset */
    902 #define	DDBCTL_MAXWIDTH		3	/* int: width of the display line */
    903 #define	DDBCTL_LINES		4	/* int: number of display lines */
    904 #define	DDBCTL_TABSTOPS		5	/* int: tab width */
    905 #define	DDBCTL_ONPANIC		6	/* int: DDB on panic if non-zero */
    906 #define	DDBCTL_FROMCONSOLE	7	/* int: DDB via console if non-zero */
    907 
    908 /*
    909  * CTL_DEBUG definitions
    910  *
    911  * Second level identifier specifies which debug variable.
    912  * Third level identifier specifies which structure component.
    913  */
    914 #define	CTL_DEBUG_NAME		0	/* string: variable name */
    915 #define	CTL_DEBUG_VALUE		1	/* int: variable value */
    916 
    917 /*
    918  * CTL_PROC subtype. Either a PID, or a magic value for the current proc.
    919  */
    920 
    921 #define	PROC_CURPROC	(~((u_int)1 << 31))
    922 
    923 /*
    924  * CTL_PROC tree: either corename (string), a limit
    925  * (rlimit.<type>.{hard,soft}, int), a process stop
    926  * condition, or paxflags.
    927  */
    928 #define	PROC_PID_CORENAME	1
    929 #define	PROC_PID_LIMIT		2
    930 #define	PROC_PID_STOPFORK	3
    931 #define	PROC_PID_STOPEXEC	4
    932 #define	PROC_PID_STOPEXIT	5
    933 #define	PROC_PID_PAXFLAGS	6
    934 
    935 /* Limit types from <sys/resources.h> */
    936 #define	PROC_PID_LIMIT_CPU	(RLIMIT_CPU+1)
    937 #define	PROC_PID_LIMIT_FSIZE	(RLIMIT_FSIZE+1)
    938 #define	PROC_PID_LIMIT_DATA	(RLIMIT_DATA+1)
    939 #define	PROC_PID_LIMIT_STACK	(RLIMIT_STACK+1)
    940 #define	PROC_PID_LIMIT_CORE	(RLIMIT_CORE+1)
    941 #define	PROC_PID_LIMIT_RSS	(RLIMIT_RSS+1)
    942 #define	PROC_PID_LIMIT_MEMLOCK	(RLIMIT_MEMLOCK+1)
    943 #define	PROC_PID_LIMIT_NPROC	(RLIMIT_NPROC+1)
    944 #define	PROC_PID_LIMIT_NOFILE	(RLIMIT_NOFILE+1)
    945 #define	PROC_PID_LIMIT_SBSIZE	(RLIMIT_SBSIZE+1)
    946 #define	PROC_PID_LIMIT_AS	(RLIMIT_AS+1)
    947 #define	PROC_PID_LIMIT_NTHR	(RLIMIT_NTHR+1)
    948 
    949 /* for each type, either hard or soft value */
    950 #define	PROC_PID_LIMIT_TYPE_SOFT	1
    951 #define	PROC_PID_LIMIT_TYPE_HARD	2
    952 
    953 /*
    954  * Export PAX flag definitions to userland.
    955  *
    956  * XXX These are duplicated from sys/pax.h but that header is not
    957  * XXX installed.
    958  */
    959 #define	CTL_PROC_PAXFLAGS_ASLR		0x01
    960 #define	CTL_PROC_PAXFLAGS_MPROTECT	0x02
    961 #define	CTL_PROC_PAXFLAGS_GUARD		0x04
    962 
    963 /*
    964  * CTL_EMUL definitions
    965  *
    966  * Second level identifier specifies which emulation variable.
    967  * Subsequent levels are specified in the emulations themselves.
    968  */
    969 #define	EMUL_LINUX	1
    970 #define	EMUL_LINUX32	5
    971 
    972 #ifdef _KERNEL
    973 
    974 #if defined(_KERNEL_OPT)
    975 #include "opt_sysctl.h"
    976 #endif
    977 
    978 /* Root node of the kernel sysctl tree */
    979 extern struct sysctlnode sysctl_root;
    980 
    981 /*
    982  * A log of nodes created by a setup function or set of setup
    983  * functions so that they can be torn down in one "transaction"
    984  * when no longer needed.
    985  *
    986  * Users of the log merely pass a pointer to a pointer, and the sysctl
    987  * infrastructure takes care of the rest.
    988  */
    989 struct sysctllog;
    990 
    991 /*
    992  * CTL_DEBUG variables.
    993  *
    994  * These are declared as separate variables so that they can be
    995  * individually initialized at the location of their associated
    996  * variable. The loader prevents multiple use by issuing errors
    997  * if a variable is initialized in more than one place. They are
    998  * aggregated into an array in debug_sysctl(), so that it can
    999  * conveniently locate them when queried. If more debugging
   1000  * variables are added, they must also be declared here and also
   1001  * entered into the array.
   1002  *
   1003  * Note that the debug subtree is largely obsolescent in terms of
   1004  * functionality now that we have dynamic sysctl, but the
   1005  * infrastructure is retained for backwards compatibility.
   1006  */
   1007 struct ctldebug {
   1008 	const char *debugname;	/* name of debugging variable */
   1009 	int	*debugvar;	/* pointer to debugging variable */
   1010 };
   1011 #ifdef	DEBUG
   1012 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
   1013 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
   1014 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
   1015 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
   1016 #endif	/* DEBUG */
   1017 
   1018 #define	SYSCTLFN_PROTO const int *, u_int, void *, \
   1019 	size_t *, const void *, size_t, \
   1020 	const int *, struct lwp *, const struct sysctlnode *
   1021 #define	SYSCTLFN_ARGS const int *name, u_int namelen, \
   1022 	void *oldp, size_t *oldlenp, \
   1023 	const void *newp, size_t newlen, \
   1024 	const int *oname, struct lwp *l, \
   1025 	const struct sysctlnode *rnode
   1026 #define	SYSCTLFN_CALL(node) name, namelen, oldp, \
   1027 	oldlenp, newp, newlen, \
   1028 	oname, l, node
   1029 
   1030 #ifdef RUMP_USE_CTOR
   1031 #include <sys/kernel.h>
   1032 
   1033 struct sysctl_setup_chain {
   1034 	void (*ssc_func)(struct sysctllog **);
   1035 	LIST_ENTRY(sysctl_setup_chain) ssc_entries;
   1036 };
   1037 LIST_HEAD(sysctl_boot_chain, sysctl_setup_chain);
   1038 #define	_SYSCTL_REGISTER(name)						\
   1039 static struct sysctl_setup_chain __CONCAT(ssc,name) = {			\
   1040 	.ssc_func = name,						\
   1041 };									\
   1042 static void sysctlctor_##name(void) __attribute__((constructor));	\
   1043 static void sysctlctor_##name(void)					\
   1044 {									\
   1045 	struct sysctl_setup_chain *ssc = &__CONCAT(ssc,name);		\
   1046 	extern struct sysctl_boot_chain sysctl_boot_chain;		\
   1047 	if (cold) {							\
   1048 		LIST_INSERT_HEAD(&sysctl_boot_chain, ssc, ssc_entries);	\
   1049 	}								\
   1050 }									\
   1051 static void sysctldtor_##name(void) __attribute__((destructor));	\
   1052 static void sysctldtor_##name(void)					\
   1053 {									\
   1054 	struct sysctl_setup_chain *ssc = &__CONCAT(ssc,name);		\
   1055 	if (cold) {							\
   1056 		LIST_REMOVE(ssc, ssc_entries);				\
   1057 	}								\
   1058 }
   1059 
   1060 #else /* RUMP_USE_CTOR */
   1061 
   1062 #define	_SYSCTL_REGISTER(name) __link_set_add_text(sysctl_funcs, name);
   1063 
   1064 #endif /* RUMP_USE_CTOR */
   1065 
   1066 #ifdef _MODULE
   1067 
   1068 #define	SYSCTL_SETUP_PROTO(name)				\
   1069 	void name(struct sysctllog **)
   1070 #ifdef SYSCTL_DEBUG_SETUP
   1071 #define	SYSCTL_SETUP(name, desc)				\
   1072 	SYSCTL_SETUP_PROTO(name);				\
   1073 	static void __CONCAT(___,name)(struct sysctllog **);	\
   1074 	void name(struct sysctllog **clog) {			\
   1075 		printf("%s\n", desc);				\
   1076 		__CONCAT(___,name)(clog); }			\
   1077 	_SYSCTL_REGISTER(name);					\
   1078 	static void __CONCAT(___,name)(struct sysctllog **clog)
   1079 #else  /* !SYSCTL_DEBUG_SETUP */
   1080 #define	SYSCTL_SETUP(name, desc)				\
   1081 	SYSCTL_SETUP_PROTO(name);				\
   1082 	_SYSCTL_REGISTER(name);					\
   1083 	void name(struct sysctllog **clog)
   1084 #endif /* !SYSCTL_DEBUG_SETUP */
   1085 
   1086 #else /* !_MODULE */
   1087 
   1088 #define	SYSCTL_SETUP_PROTO(name)
   1089 #ifdef SYSCTL_DEBUG_SETUP
   1090 #define	SYSCTL_SETUP(name, desc)				\
   1091 	static void __CONCAT(___,name)(struct sysctllog **);	\
   1092 	static void name(struct sysctllog **clog) {		\
   1093 		printf("%s\n", desc);				\
   1094 		__CONCAT(___,name)(clog); }			\
   1095 	_SYSCTL_REGISTER(name);					\
   1096 	static void __CONCAT(___,name)(struct sysctllog **clog)
   1097 #else  /* !SYSCTL_DEBUG_SETUP */
   1098 #define	SYSCTL_SETUP(name, desc)				\
   1099 	static void name(struct sysctllog **);			\
   1100 	_SYSCTL_REGISTER(name);					\
   1101 	static void name(struct sysctllog **clog)
   1102 #endif /* !SYSCTL_DEBUG_SETUP */
   1103 
   1104 #endif /* !_MODULE */
   1105 
   1106 /*
   1107  * Internal sysctl function calling convention:
   1108  *
   1109  *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen,
   1110  *		    origname, lwp, node);
   1111  *
   1112  * The name parameter points at the next component of the name to be
   1113  * interpreted.  The namelen parameter is the number of integers in
   1114  * the name.  The origname parameter points to the start of the name
   1115  * being parsed.  The node parameter points to the node on which the
   1116  * current operation is to be performed.
   1117  */
   1118 typedef int (*sysctlfn)(SYSCTLFN_PROTO);
   1119 
   1120 /*
   1121  * used in more than just sysctl
   1122  */
   1123 void	fill_eproc(struct proc *, struct eproc *, bool, bool);
   1124 void	fill_kproc2(struct proc *, struct kinfo_proc2 *, bool, bool);
   1125 
   1126 /*
   1127  * subsystem setup
   1128  */
   1129 void	sysctl_init(void);
   1130 void	sysctl_basenode_init(void);
   1131 void	sysctl_finalize(void);
   1132 
   1133 /*
   1134  * typical syscall call order
   1135  */
   1136 void	sysctl_lock(bool);
   1137 int	sysctl_dispatch(SYSCTLFN_PROTO);
   1138 void	sysctl_unlock(void);
   1139 void	sysctl_relock(void);
   1140 
   1141 /*
   1142  * tree navigation primitives (must obtain lock before using these)
   1143  */
   1144 int	sysctl_locate(struct lwp *, const int *, u_int,
   1145 		      const struct sysctlnode **, int *);
   1146 int	sysctl_query(SYSCTLFN_PROTO);
   1147 int	sysctl_create(SYSCTLFN_PROTO);
   1148 int	sysctl_destroy(SYSCTLFN_PROTO);
   1149 int	sysctl_lookup(SYSCTLFN_PROTO);
   1150 int	sysctl_describe(SYSCTLFN_PROTO);
   1151 
   1152 /*
   1153  * simple variadic interface for adding/removing nodes
   1154  */
   1155 int	sysctl_createv(struct sysctllog **, int,
   1156 		       const struct sysctlnode **, const struct sysctlnode **,
   1157 		       int, int, const char *, const char *,
   1158 		       sysctlfn, u_quad_t, void *, size_t, ...);
   1159 int	sysctl_destroyv(struct sysctlnode *, ...);
   1160 
   1161 #define	VERIFY_FN(ctl_type, c_type) \
   1162 __always_inline static __inline void * \
   1163 __sysctl_verify_##ctl_type##_arg(c_type *arg) \
   1164 { \
   1165     return arg; \
   1166 }
   1167 
   1168 VERIFY_FN(CTLTYPE_NODE, struct sysctlnode)
   1169 VERIFY_FN(CTLTYPE_INT, int)
   1170 VERIFY_FN(CTLTYPE_STRING, char)
   1171 VERIFY_FN(CTLTYPE_QUAD, int64_t)
   1172 VERIFY_FN(CTLTYPE_STRUCT, void)
   1173 VERIFY_FN(CTLTYPE_BOOL, bool)
   1174 VERIFY_FN(CTLTYPE_LONG, long)
   1175 #undef VERIFY_FN
   1176 
   1177 #define	sysctl_createv(lg, cfl, rn, cn, fl, type, nm, desc, fn, qv, newp, ...) \
   1178     sysctl_createv(lg, cfl, rn, cn, fl, type, nm, desc, fn, qv, \
   1179 	    __sysctl_verify_##type##_arg(newp), __VA_ARGS__)
   1180 
   1181 /*
   1182  * miscellany
   1183  */
   1184 void	sysctl_dump(const struct sysctlnode *);
   1185 void	sysctl_free(struct sysctlnode *);
   1186 void	sysctl_teardown(struct sysctllog **);
   1187 void	sysctl_log_print(const struct sysctllog *);
   1188 
   1189 #ifdef SYSCTL_INCLUDE_DESCR
   1190 #define	SYSCTL_DESCR(s) s
   1191 #else /* SYSCTL_INCLUDE_DESCR */
   1192 #define	SYSCTL_DESCR(s) NULL
   1193 #endif /* SYSCTL_INCLUDE_DESCR */
   1194 
   1195 /*
   1196  * simple interface similar to old interface for in-kernel consumption
   1197  */
   1198 int	old_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct lwp *);
   1199 
   1200 /*
   1201  * these helpers are in other files (XXX so should the nodes be) or
   1202  * are used by more than one node
   1203  */
   1204 int	sysctl_hw_tapenames(SYSCTLFN_PROTO);
   1205 int	sysctl_hw_tapestats(SYSCTLFN_PROTO);
   1206 int	sysctl_kern_vnode(SYSCTLFN_PROTO);
   1207 int	sysctl_net_inet_ip_ports(SYSCTLFN_PROTO);
   1208 int	sysctl_consdev(SYSCTLFN_PROTO);
   1209 int	sysctl_root_device(SYSCTLFN_PROTO);
   1210 int	sysctl_vfs_generic_fstypes(SYSCTLFN_PROTO);
   1211 
   1212 /*
   1213  * primitive helper stubs
   1214  */
   1215 int	sysctl_needfunc(SYSCTLFN_PROTO);
   1216 int	sysctl_notavail(SYSCTLFN_PROTO);
   1217 int	sysctl_null(SYSCTLFN_PROTO);
   1218 
   1219 int	sysctl_copyin(struct lwp *, const void *, void *, size_t);
   1220 int	sysctl_copyout(struct lwp *, const void *, void *, size_t);
   1221 int	sysctl_copyinstr(struct lwp *, const void *, void *, size_t, size_t *);
   1222 
   1223 u_int	sysctl_map_flags(const u_int *, u_int);
   1224 
   1225 MALLOC_DECLARE(M_SYSCTLNODE);
   1226 MALLOC_DECLARE(M_SYSCTLDATA);
   1227 
   1228 extern const u_int sysctl_lwpflagmap[];
   1229 
   1230 #else	/* !_KERNEL */
   1231 #include <sys/cdefs.h>
   1232 
   1233 typedef void *sysctlfn;
   1234 
   1235 __BEGIN_DECLS
   1236 int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
   1237 int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
   1238 int	sysctlgetmibinfo(const char *, int *, u_int *,
   1239 			 char *, size_t *, struct sysctlnode **, int);
   1240 int	sysctlnametomib(const char *, int *, size_t *);
   1241 int	proc_compare(const struct kinfo_proc2 *, const struct kinfo_lwp *,
   1242     const struct kinfo_proc2 *, const struct kinfo_lwp *);
   1243 void	*asysctl(const int *, size_t, size_t *);
   1244 void	*asysctlbyname(const char *, size_t *);
   1245 int	__learn_tree(int *, u_int, struct sysctlnode *);
   1246 __END_DECLS
   1247 
   1248 #endif	/* !_KERNEL */
   1249 
   1250 #ifdef __COMPAT_SYSCTL
   1251 /*
   1252  * old node definitions go here
   1253  */
   1254 #endif /* __COMPAT_SYSCTL */
   1255 
   1256 /*
   1257  * padding makes alignment magically "work" for 32/64 compatibility at
   1258  * the expense of making things bigger on 32 bit platforms.
   1259  */
   1260 #if defined(_LP64) || (BYTE_ORDER == LITTLE_ENDIAN)
   1261 #define	__sysc_pad(type) union { uint64_t __sysc_upad; \
   1262 	struct { type __sysc_sdatum; } __sysc_ustr; }
   1263 #else
   1264 #define	__sysc_pad(type) union { uint64_t __sysc_upad; \
   1265 	struct { uint32_t __sysc_spad; type __sysc_sdatum; } __sysc_ustr; }
   1266 #endif
   1267 #define	__sysc_unpad(x) x.__sysc_ustr.__sysc_sdatum
   1268 
   1269 /*
   1270  * The following is for gcc2, which doesn't handle __sysc_unpad().
   1271  * The code gets a little less ugly this way.
   1272  */
   1273 #define	sysc_init_field(field, value) 	\
   1274 	.field = { .__sysc_ustr = { .__sysc_sdatum = (value), }, }
   1275 
   1276 struct sysctlnode {
   1277 	uint32_t sysctl_flags;		/* flags and type */
   1278 	int32_t sysctl_num;		/* mib number */
   1279 	char sysctl_name[SYSCTL_NAMELEN]; /* node name */
   1280 	uint32_t sysctl_ver;		/* node's version vs. rest of tree */
   1281 	uint32_t __rsvd;
   1282 	union {
   1283 		struct {
   1284 			uint32_t suc_csize;	/* size of child node array */
   1285 			uint32_t suc_clen;	/* number of valid children */
   1286 			__sysc_pad(struct sysctlnode*) _suc_child; /* array of child nodes */
   1287 		} scu_child;
   1288 		struct {
   1289 			__sysc_pad(void*) _sud_data; /* pointer to external data */
   1290 			__sysc_pad(size_t) _sud_offset; /* offset to data */
   1291 		} scu_data;
   1292 		int32_t scu_alias;		/* node this node refers to */
   1293 		int32_t scu_idata;		/* immediate "int" data */
   1294 		u_quad_t scu_qdata;		/* immediate "u_quad_t" data */
   1295 		bool scu_bdata;			/* immediate bool data */
   1296 	} sysctl_un;
   1297 	__sysc_pad(size_t) _sysctl_size;	/* size of instrumented data */
   1298 	__sysc_pad(sysctlfn) _sysctl_func;	/* access helper function */
   1299 	__sysc_pad(struct sysctlnode*) _sysctl_parent; /* parent of this node */
   1300 	__sysc_pad(const char *) _sysctl_desc;	/* description of node */
   1301 };
   1302 
   1303 /*
   1304  * padded data
   1305  */
   1306 #define	suc_child	__sysc_unpad(_suc_child)
   1307 #define	sud_data	__sysc_unpad(_sud_data)
   1308 #define	sud_offset	__sysc_unpad(_sud_offset)
   1309 #define	sysctl_size	__sysc_unpad(_sysctl_size)
   1310 #define	sysctl_func	__sysc_unpad(_sysctl_func)
   1311 #define	sysctl_parent	__sysc_unpad(_sysctl_parent)
   1312 #define	sysctl_desc	__sysc_unpad(_sysctl_desc)
   1313 
   1314 /*
   1315  * nested data (may also be padded)
   1316  */
   1317 #define	sysctl_csize	sysctl_un.scu_child.suc_csize
   1318 #define	sysctl_clen	sysctl_un.scu_child.suc_clen
   1319 #define	sysctl_child	sysctl_un.scu_child.suc_child
   1320 #define	sysctl_data	sysctl_un.scu_data.sud_data
   1321 #define	sysctl_offset	sysctl_un.scu_data.sud_offset
   1322 #define	sysctl_alias	sysctl_un.scu_alias
   1323 #define	sysctl_idata	sysctl_un.scu_idata
   1324 #define	sysctl_qdata	sysctl_un.scu_qdata
   1325 #define	sysctl_bdata	sysctl_un.scu_bdata
   1326 
   1327 /*
   1328  * when requesting a description of a node (a set of nodes, actually),
   1329  * you get back an "array" of these, where the actual length of the
   1330  * descr_str is noted in descr_len (which includes the trailing nul
   1331  * byte), rounded up to the nearest four (sizeof(int32_t) actually).
   1332  *
   1333  * NEXT_DESCR() will take a pointer to a description and advance it to
   1334  * the next description.
   1335  */
   1336 struct sysctldesc {
   1337 	int32_t		descr_num;	/* mib number of node */
   1338 	uint32_t	descr_ver;	/* version of node */
   1339 	uint32_t	descr_len;	/* length of description string */
   1340 	char		descr_str[1];	/* not really 1...see above */
   1341 };
   1342 
   1343 #define	__sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
   1344 #define	__sysc_desc_len(l) (offsetof(struct sysctldesc, descr_str) +\
   1345 		__sysc_desc_roundup(l))
   1346 #define	__sysc_desc_adv(d, l) \
   1347 	(/*XXXUNCONST ptr cast*/(struct sysctldesc *) \
   1348 	__UNCONST(((const char*)(d)) + __sysc_desc_len(l)))
   1349 #define	NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
   1350 
   1351 static __inline const struct sysctlnode *
   1352 sysctl_rootof(const struct sysctlnode *n)
   1353 {
   1354 	while (n->sysctl_parent != NULL)
   1355 		n = n->sysctl_parent;
   1356 	return (n);
   1357 }
   1358 
   1359 #endif	/* !_SYS_SYSCTL_H_ */
   1360