1 /* $NetBSD: sysctl.h,v 1.237 2023/04/07 03:01:21 simonb 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
279 /*
280 * KERN_CLOCKRATE structure
281 */
282 struct clockinfo {
283 int hz; /* clock frequency */
284 int tick; /* micro-seconds per hz tick */
285 int tickadj; /* clock skew rate for adjtime() */
286 int stathz; /* statistics clock frequency */
287 int profhz; /* profiling clock frequency */
288 };
289
290 /*
291 * KERN_PROC subtypes
292 */
293 #define KERN_PROC_ALL 0 /* everything */
294 #define KERN_PROC_PID 1 /* by process id */
295 #define KERN_PROC_PGRP 2 /* by process group id */
296 #define KERN_PROC_SESSION 3 /* by session of pid */
297 #define KERN_PROC_TTY 4 /* by controlling tty */
298 #define KERN_PROC_UID 5 /* by effective uid */
299 #define KERN_PROC_RUID 6 /* by real uid */
300 #define KERN_PROC_GID 7 /* by effective gid */
301 #define KERN_PROC_RGID 8 /* by real gid */
302
303 /*
304 * KERN_PROC_TTY sub-subtypes
305 */
306 #define KERN_PROC_TTY_NODEV NODEV /* no controlling tty */
307 #define KERN_PROC_TTY_REVOKE ((dev_t)-2) /* revoked tty */
308
309 struct ki_pcred {
310 void *p_pad;
311 uid_t p_ruid; /* Real user id */
312 uid_t p_svuid; /* Saved effective user id */
313 gid_t p_rgid; /* Real group id */
314 gid_t p_svgid; /* Saved effective group id */
315 int p_refcnt; /* Number of references */
316 };
317
318 struct ki_ucred {
319 uint32_t cr_ref; /* reference count */
320 uid_t cr_uid; /* effective user id */
321 gid_t cr_gid; /* effective group id */
322 uint32_t cr_ngroups; /* number of groups */
323 gid_t cr_groups[NGROUPS]; /* groups */
324 };
325
326 #if defined(_KERNEL) || defined(_KMEMUSER)
327
328 struct eproc {
329 struct proc *e_paddr; /* address of proc */
330 struct session *e_sess; /* session pointer */
331 struct ki_pcred e_pcred; /* process credentials */
332 struct ki_ucred e_ucred; /* current credentials */
333 struct vmspace e_vm; /* address space */
334 pid_t e_ppid; /* parent process id */
335 pid_t e_pgid; /* process group id */
336 short e_jobc; /* job control counter */
337 uint32_t e_tdev; /* XXX: controlling tty dev */
338 pid_t e_tpgid; /* tty process group id */
339 struct session *e_tsess; /* tty session pointer */
340 #define WMESGLEN 8
341 char e_wmesg[WMESGLEN]; /* wchan message */
342 segsz_t e_xsize; /* text size */
343 short e_xrssize; /* text rss */
344 short e_xccount; /* text references */
345 short e_xswrss;
346 long e_flag; /* see p_eflag below */
347 char e_login[MAXLOGNAME]; /* setlogin() name */
348 pid_t e_sid; /* session id */
349 long e_spare[3];
350 };
351
352 /*
353 * KERN_PROC subtype ops return arrays of augmented proc structures:
354 */
355 struct kinfo_proc {
356 struct proc kp_proc; /* proc structure */
357 struct eproc kp_eproc; /* eproc structure */
358 };
359 #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
360
361 /*
362 * Convert pointer to 64 bit unsigned integer for struct
363 * kinfo_proc2, etc.
364 */
365 #define PTRTOUINT64(p) ((uint64_t)(uintptr_t)(p))
366 #define UINT64TOPTR(u) ((void *)(uintptr_t)(u))
367
368 /*
369 * KERN_PROC2 subtype ops return arrays of relatively fixed size
370 * structures of process info. Use 8 byte alignment, and new
371 * elements should only be added to the end of this structure so
372 * binary compatibility can be preserved.
373 */
374 #define KI_NGROUPS 16
375 #define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */
376 #define KI_WMESGLEN 8
377 #define KI_MAXLOGNAME 24 /* extra for 8 byte alignment */
378 #define KI_MAXEMULLEN 16
379 #define KI_LNAMELEN 20 /* extra 4 for alignment */
380
381 #define KI_NOCPU (~(uint64_t)0)
382
383 typedef struct {
384 uint32_t __bits[4];
385 } ki_sigset_t;
386
387 struct kinfo_proc2 {
388 uint64_t p_forw; /* PTR: linked run/sleep queue. */
389 uint64_t p_back;
390 uint64_t p_paddr; /* PTR: address of proc */
391
392 uint64_t p_addr; /* PTR: Kernel virtual addr of u-area */
393 uint64_t p_fd; /* PTR: Ptr to open files structure. */
394 uint64_t p_cwdi; /* PTR: cdir/rdir/cmask info */
395 uint64_t p_stats; /* PTR: Accounting/statistics */
396 uint64_t p_limit; /* PTR: Process limits. */
397 uint64_t p_vmspace; /* PTR: Address space. */
398 uint64_t p_sigacts; /* PTR: Signal actions, state */
399 uint64_t p_sess; /* PTR: session pointer */
400 uint64_t p_tsess; /* PTR: tty session pointer */
401 uint64_t p_ru; /* PTR: Exit information. XXX */
402
403 int32_t p_eflag; /* LONG: extra kinfo_proc2 flags */
404 #define EPROC_CTTY 0x01 /* controlling tty vnode active */
405 #define EPROC_SLEADER 0x02 /* session leader */
406 int32_t p_exitsig; /* INT: signal to sent to parent on exit */
407 int32_t p_flag; /* INT: P_* flags. */
408
409 int32_t p_pid; /* PID_T: Process identifier. */
410 int32_t p_ppid; /* PID_T: Parent process id */
411 int32_t p_sid; /* PID_T: session id */
412 int32_t p__pgid; /* PID_T: process group id */
413 /* XXX: <sys/proc.h> hijacks p_pgid */
414 int32_t p_tpgid; /* PID_T: tty process group id */
415
416 uint32_t p_uid; /* UID_T: effective user id */
417 uint32_t p_ruid; /* UID_T: real user id */
418 uint32_t p_gid; /* GID_T: effective group id */
419 uint32_t p_rgid; /* GID_T: real group id */
420
421 uint32_t p_groups[KI_NGROUPS]; /* GID_T: groups */
422 int16_t p_ngroups; /* SHORT: number of groups */
423
424 int16_t p_jobc; /* SHORT: job control counter */
425 uint32_t p_tdev; /* XXX: DEV_T: controlling tty dev */
426
427 uint32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */
428 uint32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */
429 uint32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */
430 int32_t p_cpticks; /* INT: Ticks of CPU time. */
431 uint32_t p_pctcpu; /* FIXPT_T: %cpu for this process during p_swtime */
432 uint32_t p_swtime; /* U_INT: Time swapped in or out. */
433 uint32_t p_slptime; /* U_INT: Time since last blocked. */
434 int32_t p_schedflags; /* INT: PSCHED_* flags */
435
436 uint64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */
437 uint64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */
438 uint64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */
439
440 uint64_t p_tracep; /* PTR: Trace to vnode or file */
441 int32_t p_traceflag; /* INT: Kernel trace points. */
442
443 int32_t p_holdcnt; /* INT: If non-zero, don't swap. */
444
445 ki_sigset_t p_siglist; /* SIGSET_T: Signals arrived but not delivered. */
446 ki_sigset_t p_sigmask; /* SIGSET_T: Current signal mask. */
447 ki_sigset_t p_sigignore; /* SIGSET_T: Signals being ignored. */
448 ki_sigset_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */
449
450 int8_t p_stat; /* CHAR: S* process status (from LWP). */
451 uint8_t p_priority; /* U_CHAR: Process priority. */
452 uint8_t p_usrpri; /* U_CHAR: User-priority based on p_cpu and p_nice. */
453 uint8_t p_nice; /* U_CHAR: Process "nice" value. */
454
455 uint16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */
456 uint16_t p_acflag; /* U_SHORT: Accounting flags. */
457
458 char p_comm[KI_MAXCOMLEN];
459
460 char p_wmesg[KI_WMESGLEN]; /* wchan message */
461 uint64_t p_wchan; /* PTR: sleep address. */
462
463 char p_login[KI_MAXLOGNAME]; /* setlogin() name */
464
465 int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */
466 int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */
467 int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */
468 int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */
469
470 int64_t p_uvalid; /* CHAR: following p_u* parameters are valid */
471 /* XXX 64 bits for alignment */
472 uint32_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */
473 uint32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */
474
475 uint32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */
476 uint32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */
477 uint32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */
478 uint32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */
479
480 uint64_t p_uru_maxrss; /* LONG: max resident set size. */
481 uint64_t p_uru_ixrss; /* LONG: integral shared memory size. */
482 uint64_t p_uru_idrss; /* LONG: integral unshared data ". */
483 uint64_t p_uru_isrss; /* LONG: integral unshared stack ". */
484 uint64_t p_uru_minflt; /* LONG: page reclaims. */
485 uint64_t p_uru_majflt; /* LONG: page faults. */
486 uint64_t p_uru_nswap; /* LONG: swaps. */
487 uint64_t p_uru_inblock; /* LONG: block input operations. */
488 uint64_t p_uru_oublock; /* LONG: block output operations. */
489 uint64_t p_uru_msgsnd; /* LONG: messages sent. */
490 uint64_t p_uru_msgrcv; /* LONG: messages received. */
491 uint64_t p_uru_nsignals; /* LONG: signals received. */
492 uint64_t p_uru_nvcsw; /* LONG: voluntary context switches. */
493 uint64_t p_uru_nivcsw; /* LONG: involuntary ". */
494
495 uint32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */
496 uint32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */
497 uint64_t p_cpuid; /* LONG: CPU id */
498 uint64_t p_realflag; /* INT: P_* flags (not including LWPs). */
499 uint64_t p_nlwps; /* LONG: Number of LWPs */
500 uint64_t p_nrlwps; /* LONG: Number of running LWPs */
501 uint64_t p_realstat; /* LONG: non-LWP process status */
502 uint32_t p_svuid; /* UID_T: saved user id */
503 uint32_t p_svgid; /* GID_T: saved group id */
504 char p_ename[KI_MAXEMULLEN]; /* emulation name */
505 int64_t p_vm_vsize; /* SEGSZ_T: total map size (pages) */
506 int64_t p_vm_msize; /* SEGSZ_T: stack-adjusted map size (pages) */
507 };
508
509 /*
510 * Compat flags for kinfo_proc, kinfo_proc2. Not guaranteed to be stable.
511 * Some of them used to be shared with LWP flags.
512 * XXXAD Trim to the minimum necessary...
513 */
514
515 #define P_ADVLOCK 0x00000001
516 #define P_CONTROLT 0x00000002
517 #define L_INMEM 0x00000004
518 #define P_INMEM /* 0x00000004 */ L_INMEM
519 #define P_NOCLDSTOP 0x00000008
520 #define P_PPWAIT 0x00000010
521 #define P_PROFIL 0x00000020
522 #define L_SELECT 0x00000040
523 #define P_SELECT /* 0x00000040 */ L_SELECT
524 #define L_SINTR 0x00000080
525 #define P_SINTR /* 0x00000080 */ L_SINTR
526 #define P_SUGID 0x00000100
527 #define L_SYSTEM 0x00000200
528 #define P_SYSTEM /* 0x00000200 */ L_SYSTEM
529 #define L_SA 0x00000400
530 #define P_SA /* 0x00000400 */ L_SA
531 #define P_TRACED 0x00000800
532 #define P_WAITED 0x00001000
533 #define P_WEXIT 0x00002000
534 #define P_EXEC 0x00004000
535 #define P_OWEUPC 0x00008000
536 #define P_NOCLDWAIT 0x00020000
537 #define P_32 0x00040000
538 #define P_CLDSIGIGN 0x00080000
539 #define P_SYSTRACE 0x00200000
540 #define P_CHTRACED 0x00400000
541 #define P_STOPFORK 0x00800000
542 #define P_STOPEXEC 0x01000000
543 #define P_STOPEXIT 0x02000000
544 #define P_SYSCALL 0x04000000
545
546 /*
547 * LWP compat flags.
548 */
549 #define L_DETACHED 0x00800000
550
551 #define __SYSCTL_PROC_FLAG_BITS \
552 "\20" \
553 "\1ADVLOCK" \
554 "\2CONTROLT" \
555 "\3INMEM" \
556 "\4NOCLDSTOP" \
557 "\5PPWAIT" \
558 "\6PROFIL" \
559 "\7SELECT" \
560 "\10SINTR" \
561 "\11SUGID" \
562 "\12SYSTEM" \
563 "\13SA" \
564 "\14TRACED" \
565 "\15WAITED" \
566 "\16WEXIT" \
567 "\17EXEC" \
568 "\20OWEUPC" \
569 "\22NOCLDWAIT" \
570 "\23P32" \
571 "\24CLDSIGIGN" \
572 "\26SYSTRACE" \
573 "\27CHTRACED" \
574 "\30STOPFORK" \
575 "\31STOPEXEC" \
576 "\32STOPEXIT" \
577 "\33SYSCALL"
578
579 /*
580 * KERN_LWP structure. See notes on KERN_PROC2 about adding elements.
581 */
582 struct kinfo_lwp {
583 uint64_t l_forw; /* PTR: linked run/sleep queue. */
584 uint64_t l_back;
585 uint64_t l_laddr; /* PTR: Address of LWP */
586 uint64_t l_addr; /* PTR: Kernel virtual addr of u-area */
587 int32_t l_lid; /* LWPID_T: LWP identifier */
588 int32_t l_flag; /* INT: L_* flags. */
589 uint32_t l_swtime; /* U_INT: Time swapped in or out. */
590 uint32_t l_slptime; /* U_INT: Time since last blocked. */
591 int32_t l_schedflags; /* INT: PSCHED_* flags */
592 int32_t l_holdcnt; /* INT: If non-zero, don't swap. */
593 uint8_t l_priority; /* U_CHAR: Process priority. */
594 uint8_t l_usrpri; /* U_CHAR: User-priority based on l_cpu and p_nice. */
595 int8_t l_stat; /* CHAR: S* process status. */
596 int8_t l_pad1; /* fill out to 4-byte boundary */
597 int32_t l_pad2; /* .. and then to an 8-byte boundary */
598 char l_wmesg[KI_WMESGLEN]; /* wchan message */
599 uint64_t l_wchan; /* PTR: sleep address. */
600 uint64_t l_cpuid; /* LONG: CPU id */
601 uint32_t l_rtime_sec; /* STRUCT TIMEVAL: Real time. */
602 uint32_t l_rtime_usec; /* STRUCT TIMEVAL: Real time. */
603 uint32_t l_cpticks; /* INT: ticks during l_swtime */
604 uint32_t l_pctcpu; /* FIXPT_T: cpu usage for ps */
605 uint32_t l_pid; /* PID_T: process identifier */
606 char l_name[KI_LNAMELEN]; /* CHAR[]: name, may be empty */
607 };
608
609 /*
610 * KERN_PROC_ARGS subtypes
611 */
612 #define KERN_PROC_ARGV 1 /* argv */
613 #define KERN_PROC_NARGV 2 /* number of strings in above */
614 #define KERN_PROC_ENV 3 /* environ */
615 #define KERN_PROC_NENV 4 /* number of strings in above */
616 #define KERN_PROC_PATHNAME 5 /* path to executable */
617 #define KERN_PROC_CWD 6 /* current working dir */
618
619 /*
620 * KERN_SYSVIPC subtypes
621 */
622 #define KERN_SYSVIPC_INFO 1 /* struct: number of valid kern ids */
623 #define KERN_SYSVIPC_MSG 2 /* int: SysV message queue support */
624 #define KERN_SYSVIPC_SEM 3 /* int: SysV semaphore support */
625 #define KERN_SYSVIPC_SHM 4 /* int: SysV shared memory support */
626 #define KERN_SYSVIPC_SHMMAX 5 /* int: max shared memory segment size (bytes) */
627 #define KERN_SYSVIPC_SHMMNI 6 /* int: max number of shared memory identifiers */
628 #define KERN_SYSVIPC_SHMSEG 7 /* int: max shared memory segments per process */
629 #define KERN_SYSVIPC_SHMMAXPGS 8 /* int: max amount of shared memory (pages) */
630 #define KERN_SYSVIPC_SHMUSEPHYS 9 /* int: physical memory usage */
631
632 /*
633 * KERN_SYSVIPC_INFO subtypes
634 */
635 /* KERN_SYSVIPC_OMSG_INFO 1 */
636 /* KERN_SYSVIPC_OSEM_INFO 2 */
637 /* KERN_SYSVIPC_OSHM_INFO 3 */
638 #define KERN_SYSVIPC_MSG_INFO 4 /* msginfo and msgid_ds */
639 #define KERN_SYSVIPC_SEM_INFO 5 /* seminfo and semid_ds */
640 #define KERN_SYSVIPC_SHM_INFO 6 /* shminfo and shmid_ds */
641
642 /*
643 * tty counter sysctl variables
644 */
645 #define KERN_TKSTAT_NIN 1 /* total input character */
646 #define KERN_TKSTAT_NOUT 2 /* total output character */
647 #define KERN_TKSTAT_CANCC 3 /* canonical input character */
648 #define KERN_TKSTAT_RAWCC 4 /* raw input character */
649
650 /*
651 * kern.drivers returns an array of these.
652 */
653
654 struct kinfo_drivers {
655 devmajor_t d_cmajor;
656 devmajor_t d_bmajor;
657 char d_name[24];
658 };
659
660 /*
661 * KERN_BUF subtypes, like KERN_PROC2, where the four following mib
662 * entries specify "which type of buf", "which particular buf",
663 * "sizeof buf", and "how many". Currently, only "all buf" is
664 * defined.
665 */
666 #define KERN_BUF_ALL 0 /* all buffers */
667
668 /*
669 * kern.buf returns an array of these structures, which are designed
670 * both to be immune to 32/64 bit emulation issues and to provide
671 * backwards compatibility. Note that the order here differs slightly
672 * from the real struct buf in order to achieve proper 64 bit
673 * alignment.
674 */
675 struct buf_sysctl {
676 uint32_t b_flags; /* LONG: B_* flags */
677 int32_t b_error; /* INT: Errno value */
678 int32_t b_prio; /* INT: Hint for buffer queue discipline */
679 uint32_t b_dev; /* DEV_T: Device associated with buffer */
680 uint64_t b_bufsize; /* LONG: Allocated buffer size */
681 uint64_t b_bcount; /* LONG: Valid bytes in buffer */
682 uint64_t b_resid; /* LONG: Remaining I/O */
683 uint64_t b_addr; /* CADDR_T: Memory, superblocks, indirect... */
684 uint64_t b_blkno; /* DADDR_T: Underlying physical block number */
685 uint64_t b_rawblkno; /* DADDR_T: Raw underlying physical block */
686 uint64_t b_iodone; /* PTR: Function called upon completion */
687 uint64_t b_proc; /* PTR: Associated proc if B_PHYS set */
688 uint64_t b_vp; /* PTR: File vnode */
689 uint64_t b_saveaddr; /* PTR: Original b_addr for physio */
690 uint64_t b_lblkno; /* DADDR_T: Logical block number */
691 };
692
693 #define KERN_BUFSLOP 20
694
695 /*
696 * kern.file2 returns an array of these structures, which are designed
697 * both to be immune to 32/64 bit emulation issues and to
698 * provide backwards compatibility. The order differs slightly from
699 * that of the real struct file, and some fields are taken from other
700 * structures (struct vnode, struct proc) in order to make the file
701 * information more useful.
702 */
703 struct kinfo_file {
704 uint64_t ki_fileaddr; /* PTR: address of struct file */
705 uint32_t ki_flag; /* INT: flags (see fcntl.h) */
706 uint32_t ki_iflags; /* INT: internal flags */
707 uint32_t ki_ftype; /* INT: descriptor type */
708 uint32_t ki_count; /* UINT: reference count */
709 uint32_t ki_msgcount; /* UINT: references from msg queue */
710 uint32_t ki_usecount; /* INT: number active users */
711 uint64_t ki_fucred; /* PTR: creds for descriptor */
712 uint32_t ki_fuid; /* UID_T: descriptor credentials */
713 uint32_t ki_fgid; /* GID_T: descriptor credentials */
714 uint64_t ki_fops; /* PTR: address of fileops */
715 uint64_t ki_foffset; /* OFF_T: offset */
716 uint64_t ki_fdata; /* PTR: descriptor data */
717
718 /* vnode information to glue this file to something */
719 uint64_t ki_vun; /* PTR: socket, specinfo, etc */
720 uint64_t ki_vsize; /* OFF_T: size of file */
721 uint32_t ki_vtype; /* ENUM: vnode type */
722 uint32_t ki_vtag; /* ENUM: type of underlying data */
723 uint64_t ki_vdata; /* PTR: private data for fs */
724
725 /* process information when retrieved via KERN_FILE_BYPID */
726 uint32_t ki_pid; /* PID_T: process id */
727 int32_t ki_fd; /* INT: descriptor number */
728 uint32_t ki_ofileflags; /* CHAR: open file flags */
729 uint32_t _ki_padto64bits;
730 };
731
732 #define KERN_FILE_BYFILE 1
733 #define KERN_FILE_BYPID 2
734 #define KERN_FILESLOP 10
735
736 /*
737 * kern.evcnt returns an array of these structures, which are designed both to
738 * be immune to 32/64 bit emulation issues. Note that the struct here differs
739 * from the real struct evcnt but contains the same information in order to
740 * accommodate sysctl.
741 */
742 struct evcnt_sysctl {
743 uint64_t ev_count; /* current count */
744 uint64_t ev_addr; /* kernel address of evcnt */
745 uint64_t ev_parent; /* kernel address of parent */
746 uint8_t ev_type; /* EVCNT_TRAP_* */
747 uint8_t ev_grouplen; /* length of group with NUL */
748 uint8_t ev_namelen; /* length of name with NUL */
749 uint8_t ev_len; /* multiply by 8 */
750 /*
751 * Now the group and name strings follow (both include the trailing
752 * NUL). ev_name start at &ev_strings[ev_grouplen+1]
753 */
754 char ev_strings[];
755 };
756
757 #define KERN_EVCNT_COUNT_ANY 0
758 #define KERN_EVCNT_COUNT_NONZERO 1
759
760
761 /*
762 * kern.hashstat returns an array of these structures, which are designed
763 * to be immune to 32/64 bit emulation issues.
764 *
765 * Hash users can register a filler function to fill the hashstat_sysctl
766 * which can then be exposed via vmstat(1).
767 *
768 * See comments for hashstat_sysctl() in kern/subr_hash.c for details
769 * on sysctl(3) usage.
770 */
771 struct hashstat_sysctl {
772 char hash_name[SYSCTL_NAMELEN];
773 char hash_desc[SYSCTL_NAMELEN];
774 uint64_t hash_size;
775 uint64_t hash_used;
776 uint64_t hash_items;
777 uint64_t hash_maxchain;
778 };
779 typedef int (*hashstat_func_t)(struct hashstat_sysctl *, bool);
780 void hashstat_register(const char *, hashstat_func_t);
781
782 /*
783 * CTL_VM identifiers in <uvm/uvm_param.h>
784 */
785
786 /*
787 * The vm.proc.map sysctl allows a process to dump the VM layout of
788 * another process as a series of entries.
789 */
790 #define KVME_TYPE_NONE 0
791 #define KVME_TYPE_OBJECT 1
792 #define KVME_TYPE_VNODE 2
793 #define KVME_TYPE_KERN 3
794 #define KVME_TYPE_DEVICE 4
795 #define KVME_TYPE_ANON 5
796 #define KVME_TYPE_SUBMAP 6
797 #define KVME_TYPE_UNKNOWN 255
798
799 #define KVME_PROT_READ 0x00000001
800 #define KVME_PROT_WRITE 0x00000002
801 #define KVME_PROT_EXEC 0x00000004
802
803 #define KVME_FLAG_COW 0x00000001
804 #define KVME_FLAG_NEEDS_COPY 0x00000002
805 #define KVME_FLAG_NOCOREDUMP 0x00000004
806 #define KVME_FLAG_PAGEABLE 0x00000008
807 #define KVME_FLAG_GROWS_UP 0x00000010
808 #define KVME_FLAG_GROWS_DOWN 0x00000020
809
810 struct kinfo_vmentry {
811 uint64_t kve_start; /* Starting address. */
812 uint64_t kve_end; /* Finishing address. */
813 uint64_t kve_offset; /* Mapping offset in object */
814
815 uint32_t kve_type; /* Type of map entry. */
816 uint32_t kve_flags; /* Flags on map entry. */
817
818 uint32_t kve_count; /* Number of pages/entries */
819 uint32_t kve_wired_count; /* Number of wired pages */
820
821 uint32_t kve_advice; /* Advice */
822 uint32_t kve_attributes; /* Map attribute */
823
824 uint32_t kve_protection; /* Protection bitmask. */
825 uint32_t kve_max_protection; /* Max protection bitmask */
826
827 uint32_t kve_ref_count; /* VM obj ref count. */
828 uint32_t kve_inheritance; /* Inheritance */
829
830 uint64_t kve_vn_fileid; /* inode number if vnode */
831 uint64_t kve_vn_size; /* File size. */
832 uint64_t kve_vn_fsid; /* dev_t of vnode location */
833 uint64_t kve_vn_rdev; /* Device id if device. */
834
835 uint32_t kve_vn_type; /* Vnode type. */
836 uint32_t kve_vn_mode; /* File mode. */
837
838 char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
839 };
840
841 /*
842 * CTL_HW identifiers
843 */
844 #define HW_MACHINE 1 /* string: machine class */
845 #define HW_MODEL 2 /* string: specific machine model */
846 #define HW_NCPU 3 /* int: number of cpus */
847 #define HW_BYTEORDER 4 /* int: machine byte order */
848 #define HW_PHYSMEM 5 /* int: total memory (bytes) */
849 #define HW_USERMEM 6 /* int: non-kernel memory (bytes) */
850 #define HW_PAGESIZE 7 /* int: software page size */
851 #define HW_DISKNAMES 8 /* string: disk drive names */
852 #define HW_IOSTATS 9 /* struct: iostats[] */
853 #define HW_MACHINE_ARCH 10 /* string: machine architecture */
854 #define HW_ALIGNBYTES 11 /* int: ALIGNBYTES for the kernel */
855 #define HW_CNMAGIC 12 /* string: console magic sequence(s) */
856 #define HW_PHYSMEM64 13 /* quad: total memory (bytes) */
857 #define HW_USERMEM64 14 /* quad: non-kernel memory (bytes) */
858 #define HW_IOSTATNAMES 15 /* string: iostat names */
859 #define HW_NCPUONLINE 16 /* number CPUs online */
860
861 /*
862 * CTL_USER definitions
863 */
864 #define USER_CS_PATH 1 /* string: _CS_PATH */
865 #define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
866 #define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
867 #define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
868 #define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
869 #define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
870 #define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
871 #define USER_LINE_MAX 8 /* int: LINE_MAX */
872 #define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
873 #define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
874 #define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
875 #define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
876 #define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
877 #define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
878 #define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
879 #define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
880 #define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
881 #define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
882 #define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
883 #define USER_TZNAME_MAX 20 /* int: _POSIX_TZNAME_MAX */
884 #define USER_ATEXIT_MAX 21 /* int: {ATEXIT_MAX} */
885
886 /*
887 * CTL_DDB definitions
888 */
889 #define DDBCTL_RADIX 1 /* int: Input and output radix */
890 #define DDBCTL_MAXOFF 2 /* int: max symbol offset */
891 #define DDBCTL_MAXWIDTH 3 /* int: width of the display line */
892 #define DDBCTL_LINES 4 /* int: number of display lines */
893 #define DDBCTL_TABSTOPS 5 /* int: tab width */
894 #define DDBCTL_ONPANIC 6 /* int: DDB on panic if non-zero */
895 #define DDBCTL_FROMCONSOLE 7 /* int: DDB via console if non-zero */
896
897 /*
898 * CTL_DEBUG definitions
899 *
900 * Second level identifier specifies which debug variable.
901 * Third level identifier specifies which structure component.
902 */
903 #define CTL_DEBUG_NAME 0 /* string: variable name */
904 #define CTL_DEBUG_VALUE 1 /* int: variable value */
905
906 /*
907 * CTL_PROC subtype. Either a PID, or a magic value for the current proc.
908 */
909
910 #define PROC_CURPROC (~((u_int)1 << 31))
911
912 /*
913 * CTL_PROC tree: either corename (string), a limit
914 * (rlimit.<type>.{hard,soft}, int), a process stop
915 * condition, or paxflags.
916 */
917 #define PROC_PID_CORENAME 1
918 #define PROC_PID_LIMIT 2
919 #define PROC_PID_STOPFORK 3
920 #define PROC_PID_STOPEXEC 4
921 #define PROC_PID_STOPEXIT 5
922 #define PROC_PID_PAXFLAGS 6
923
924 /* Limit types from <sys/resources.h> */
925 #define PROC_PID_LIMIT_CPU (RLIMIT_CPU+1)
926 #define PROC_PID_LIMIT_FSIZE (RLIMIT_FSIZE+1)
927 #define PROC_PID_LIMIT_DATA (RLIMIT_DATA+1)
928 #define PROC_PID_LIMIT_STACK (RLIMIT_STACK+1)
929 #define PROC_PID_LIMIT_CORE (RLIMIT_CORE+1)
930 #define PROC_PID_LIMIT_RSS (RLIMIT_RSS+1)
931 #define PROC_PID_LIMIT_MEMLOCK (RLIMIT_MEMLOCK+1)
932 #define PROC_PID_LIMIT_NPROC (RLIMIT_NPROC+1)
933 #define PROC_PID_LIMIT_NOFILE (RLIMIT_NOFILE+1)
934 #define PROC_PID_LIMIT_SBSIZE (RLIMIT_SBSIZE+1)
935 #define PROC_PID_LIMIT_AS (RLIMIT_AS+1)
936 #define PROC_PID_LIMIT_NTHR (RLIMIT_NTHR+1)
937
938 /* for each type, either hard or soft value */
939 #define PROC_PID_LIMIT_TYPE_SOFT 1
940 #define PROC_PID_LIMIT_TYPE_HARD 2
941
942 /*
943 * Export PAX flag definitions to userland.
944 *
945 * XXX These are duplicated from sys/pax.h but that header is not
946 * XXX installed.
947 */
948 #define CTL_PROC_PAXFLAGS_ASLR 0x01
949 #define CTL_PROC_PAXFLAGS_MPROTECT 0x02
950 #define CTL_PROC_PAXFLAGS_GUARD 0x04
951
952 /*
953 * CTL_EMUL definitions
954 *
955 * Second level identifier specifies which emulation variable.
956 * Subsequent levels are specified in the emulations themselves.
957 */
958 #define EMUL_LINUX 1
959 #define EMUL_LINUX32 5
960
961 #ifdef _KERNEL
962
963 #if defined(_KERNEL_OPT)
964 #include "opt_sysctl.h"
965 #endif
966
967 /* Root node of the kernel sysctl tree */
968 extern struct sysctlnode sysctl_root;
969
970 /*
971 * A log of nodes created by a setup function or set of setup
972 * functions so that they can be torn down in one "transaction"
973 * when no longer needed.
974 *
975 * Users of the log merely pass a pointer to a pointer, and the sysctl
976 * infrastructure takes care of the rest.
977 */
978 struct sysctllog;
979
980 /*
981 * CTL_DEBUG variables.
982 *
983 * These are declared as separate variables so that they can be
984 * individually initialized at the location of their associated
985 * variable. The loader prevents multiple use by issuing errors
986 * if a variable is initialized in more than one place. They are
987 * aggregated into an array in debug_sysctl(), so that it can
988 * conveniently locate them when queried. If more debugging
989 * variables are added, they must also be declared here and also
990 * entered into the array.
991 *
992 * Note that the debug subtree is largely obsolescent in terms of
993 * functionality now that we have dynamic sysctl, but the
994 * infrastructure is retained for backwards compatibility.
995 */
996 struct ctldebug {
997 const char *debugname; /* name of debugging variable */
998 int *debugvar; /* pointer to debugging variable */
999 };
1000 #ifdef DEBUG
1001 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
1002 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
1003 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
1004 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
1005 #endif /* DEBUG */
1006
1007 #define SYSCTLFN_PROTO const int *, u_int, void *, \
1008 size_t *, const void *, size_t, \
1009 const int *, struct lwp *, const struct sysctlnode *
1010 #define SYSCTLFN_ARGS const int *name, u_int namelen, \
1011 void *oldp, size_t *oldlenp, \
1012 const void *newp, size_t newlen, \
1013 const int *oname, struct lwp *l, \
1014 const struct sysctlnode *rnode
1015 #define SYSCTLFN_CALL(node) name, namelen, oldp, \
1016 oldlenp, newp, newlen, \
1017 oname, l, node
1018
1019 #ifdef RUMP_USE_CTOR
1020 #include <sys/kernel.h>
1021
1022 struct sysctl_setup_chain {
1023 void (*ssc_func)(struct sysctllog **);
1024 LIST_ENTRY(sysctl_setup_chain) ssc_entries;
1025 };
1026 LIST_HEAD(sysctl_boot_chain, sysctl_setup_chain);
1027 #define _SYSCTL_REGISTER(name) \
1028 static struct sysctl_setup_chain __CONCAT(ssc,name) = { \
1029 .ssc_func = name, \
1030 }; \
1031 static void sysctlctor_##name(void) __attribute__((constructor)); \
1032 static void sysctlctor_##name(void) \
1033 { \
1034 struct sysctl_setup_chain *ssc = &__CONCAT(ssc,name); \
1035 extern struct sysctl_boot_chain sysctl_boot_chain; \
1036 if (cold) { \
1037 LIST_INSERT_HEAD(&sysctl_boot_chain, ssc, ssc_entries); \
1038 } \
1039 } \
1040 static void sysctldtor_##name(void) __attribute__((destructor)); \
1041 static void sysctldtor_##name(void) \
1042 { \
1043 struct sysctl_setup_chain *ssc = &__CONCAT(ssc,name); \
1044 if (cold) { \
1045 LIST_REMOVE(ssc, ssc_entries); \
1046 } \
1047 }
1048
1049 #else /* RUMP_USE_CTOR */
1050
1051 #define _SYSCTL_REGISTER(name) __link_set_add_text(sysctl_funcs, name);
1052
1053 #endif /* RUMP_USE_CTOR */
1054
1055 #ifdef _MODULE
1056
1057 #define SYSCTL_SETUP_PROTO(name) \
1058 void name(struct sysctllog **)
1059 #ifdef SYSCTL_DEBUG_SETUP
1060 #define SYSCTL_SETUP(name, desc) \
1061 SYSCTL_SETUP_PROTO(name); \
1062 static void __CONCAT(___,name)(struct sysctllog **); \
1063 void name(struct sysctllog **clog) { \
1064 printf("%s\n", desc); \
1065 __CONCAT(___,name)(clog); } \
1066 _SYSCTL_REGISTER(name); \
1067 static void __CONCAT(___,name)(struct sysctllog **clog)
1068 #else /* !SYSCTL_DEBUG_SETUP */
1069 #define SYSCTL_SETUP(name, desc) \
1070 SYSCTL_SETUP_PROTO(name); \
1071 _SYSCTL_REGISTER(name); \
1072 void name(struct sysctllog **clog)
1073 #endif /* !SYSCTL_DEBUG_SETUP */
1074
1075 #else /* !_MODULE */
1076
1077 #define SYSCTL_SETUP_PROTO(name)
1078 #ifdef SYSCTL_DEBUG_SETUP
1079 #define SYSCTL_SETUP(name, desc) \
1080 static void __CONCAT(___,name)(struct sysctllog **); \
1081 static void name(struct sysctllog **clog) { \
1082 printf("%s\n", desc); \
1083 __CONCAT(___,name)(clog); } \
1084 _SYSCTL_REGISTER(name); \
1085 static void __CONCAT(___,name)(struct sysctllog **clog)
1086 #else /* !SYSCTL_DEBUG_SETUP */
1087 #define SYSCTL_SETUP(name, desc) \
1088 static void name(struct sysctllog **); \
1089 _SYSCTL_REGISTER(name); \
1090 static void name(struct sysctllog **clog)
1091 #endif /* !SYSCTL_DEBUG_SETUP */
1092
1093 #endif /* !_MODULE */
1094
1095 /*
1096 * Internal sysctl function calling convention:
1097 *
1098 * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen,
1099 * origname, lwp, node);
1100 *
1101 * The name parameter points at the next component of the name to be
1102 * interpreted. The namelen parameter is the number of integers in
1103 * the name. The origname parameter points to the start of the name
1104 * being parsed. The node parameter points to the node on which the
1105 * current operation is to be performed.
1106 */
1107 typedef int (*sysctlfn)(SYSCTLFN_PROTO);
1108
1109 /*
1110 * used in more than just sysctl
1111 */
1112 void fill_eproc(struct proc *, struct eproc *, bool, bool);
1113 void fill_kproc2(struct proc *, struct kinfo_proc2 *, bool, bool);
1114
1115 /*
1116 * subsystem setup
1117 */
1118 void sysctl_init(void);
1119 void sysctl_basenode_init(void);
1120 void sysctl_finalize(void);
1121
1122 /*
1123 * typical syscall call order
1124 */
1125 void sysctl_lock(bool);
1126 int sysctl_dispatch(SYSCTLFN_PROTO);
1127 void sysctl_unlock(void);
1128 void sysctl_relock(void);
1129
1130 /*
1131 * tree navigation primitives (must obtain lock before using these)
1132 */
1133 int sysctl_locate(struct lwp *, const int *, u_int,
1134 const struct sysctlnode **, int *);
1135 int sysctl_query(SYSCTLFN_PROTO);
1136 int sysctl_create(SYSCTLFN_PROTO);
1137 int sysctl_destroy(SYSCTLFN_PROTO);
1138 int sysctl_lookup(SYSCTLFN_PROTO);
1139 int sysctl_describe(SYSCTLFN_PROTO);
1140
1141 /*
1142 * simple variadic interface for adding/removing nodes
1143 */
1144 int sysctl_createv(struct sysctllog **, int,
1145 const struct sysctlnode **, const struct sysctlnode **,
1146 int, int, const char *, const char *,
1147 sysctlfn, u_quad_t, void *, size_t, ...);
1148 int sysctl_destroyv(struct sysctlnode *, ...);
1149
1150 #define VERIFY_FN(ctl_type, c_type) \
1151 __always_inline static __inline void * \
1152 __sysctl_verify_##ctl_type##_arg(c_type *arg) \
1153 { \
1154 return arg; \
1155 }
1156
1157 VERIFY_FN(CTLTYPE_NODE, struct sysctlnode);
1158 VERIFY_FN(CTLTYPE_INT, int);
1159 VERIFY_FN(CTLTYPE_STRING, char);
1160 VERIFY_FN(CTLTYPE_QUAD, int64_t);
1161 VERIFY_FN(CTLTYPE_STRUCT, void);
1162 VERIFY_FN(CTLTYPE_BOOL, bool);
1163 VERIFY_FN(CTLTYPE_LONG, long);
1164 #undef VERIFY_FN
1165
1166 #define sysctl_createv(lg, cfl, rn, cn, fl, type, nm, desc, fn, qv, newp, ...) \
1167 sysctl_createv(lg, cfl, rn, cn, fl, type, nm, desc, fn, qv, \
1168 __sysctl_verify_##type##_arg(newp), __VA_ARGS__)
1169
1170 /*
1171 * miscellany
1172 */
1173 void sysctl_dump(const struct sysctlnode *);
1174 void sysctl_free(struct sysctlnode *);
1175 void sysctl_teardown(struct sysctllog **);
1176 void sysctl_log_print(const struct sysctllog *);
1177
1178 #ifdef SYSCTL_INCLUDE_DESCR
1179 #define SYSCTL_DESCR(s) s
1180 #else /* SYSCTL_INCLUDE_DESCR */
1181 #define SYSCTL_DESCR(s) NULL
1182 #endif /* SYSCTL_INCLUDE_DESCR */
1183
1184 /*
1185 * simple interface similar to old interface for in-kernel consumption
1186 */
1187 int old_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct lwp *);
1188
1189 /*
1190 * these helpers are in other files (XXX so should the nodes be) or
1191 * are used by more than one node
1192 */
1193 int sysctl_hw_tapenames(SYSCTLFN_PROTO);
1194 int sysctl_hw_tapestats(SYSCTLFN_PROTO);
1195 int sysctl_kern_vnode(SYSCTLFN_PROTO);
1196 int sysctl_net_inet_ip_ports(SYSCTLFN_PROTO);
1197 int sysctl_consdev(SYSCTLFN_PROTO);
1198 int sysctl_root_device(SYSCTLFN_PROTO);
1199 int sysctl_vfs_generic_fstypes(SYSCTLFN_PROTO);
1200
1201 /*
1202 * primitive helper stubs
1203 */
1204 int sysctl_needfunc(SYSCTLFN_PROTO);
1205 int sysctl_notavail(SYSCTLFN_PROTO);
1206 int sysctl_null(SYSCTLFN_PROTO);
1207
1208 int sysctl_copyin(struct lwp *, const void *, void *, size_t);
1209 int sysctl_copyout(struct lwp *, const void *, void *, size_t);
1210 int sysctl_copyinstr(struct lwp *, const void *, void *, size_t, size_t *);
1211
1212 u_int sysctl_map_flags(const u_int *, u_int);
1213
1214 MALLOC_DECLARE(M_SYSCTLNODE);
1215 MALLOC_DECLARE(M_SYSCTLDATA);
1216
1217 extern const u_int sysctl_lwpflagmap[];
1218
1219 #else /* !_KERNEL */
1220 #include <sys/cdefs.h>
1221
1222 typedef void *sysctlfn;
1223
1224 __BEGIN_DECLS
1225 int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1226 int sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1227 int sysctlgetmibinfo(const char *, int *, u_int *,
1228 char *, size_t *, struct sysctlnode **, int);
1229 int sysctlnametomib(const char *, int *, size_t *);
1230 int proc_compare(const struct kinfo_proc2 *, const struct kinfo_lwp *,
1231 const struct kinfo_proc2 *, const struct kinfo_lwp *);
1232 void *asysctl(const int *, size_t, size_t *);
1233 void *asysctlbyname(const char *, size_t *);
1234 __END_DECLS
1235
1236 #endif /* !_KERNEL */
1237
1238 #ifdef __COMPAT_SYSCTL
1239 /*
1240 * old node definitions go here
1241 */
1242 #endif /* __COMPAT_SYSCTL */
1243
1244 /*
1245 * padding makes alignment magically "work" for 32/64 compatibility at
1246 * the expense of making things bigger on 32 bit platforms.
1247 */
1248 #if defined(_LP64) || (BYTE_ORDER == LITTLE_ENDIAN)
1249 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1250 struct { type __sysc_sdatum; } __sysc_ustr; }
1251 #else
1252 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1253 struct { uint32_t __sysc_spad; type __sysc_sdatum; } __sysc_ustr; }
1254 #endif
1255 #define __sysc_unpad(x) x.__sysc_ustr.__sysc_sdatum
1256
1257 /*
1258 * The following is for gcc2, which doesn't handle __sysc_unpad().
1259 * The code gets a little less ugly this way.
1260 */
1261 #define sysc_init_field(field, value) \
1262 .field = { .__sysc_ustr = { .__sysc_sdatum = (value), }, }
1263
1264 struct sysctlnode {
1265 uint32_t sysctl_flags; /* flags and type */
1266 int32_t sysctl_num; /* mib number */
1267 char sysctl_name[SYSCTL_NAMELEN]; /* node name */
1268 uint32_t sysctl_ver; /* node's version vs. rest of tree */
1269 uint32_t __rsvd;
1270 union {
1271 struct {
1272 uint32_t suc_csize; /* size of child node array */
1273 uint32_t suc_clen; /* number of valid children */
1274 __sysc_pad(struct sysctlnode*) _suc_child; /* array of child nodes */
1275 } scu_child;
1276 struct {
1277 __sysc_pad(void*) _sud_data; /* pointer to external data */
1278 __sysc_pad(size_t) _sud_offset; /* offset to data */
1279 } scu_data;
1280 int32_t scu_alias; /* node this node refers to */
1281 int32_t scu_idata; /* immediate "int" data */
1282 u_quad_t scu_qdata; /* immediate "u_quad_t" data */
1283 bool scu_bdata; /* immediate bool data */
1284 } sysctl_un;
1285 __sysc_pad(size_t) _sysctl_size; /* size of instrumented data */
1286 __sysc_pad(sysctlfn) _sysctl_func; /* access helper function */
1287 __sysc_pad(struct sysctlnode*) _sysctl_parent; /* parent of this node */
1288 __sysc_pad(const char *) _sysctl_desc; /* description of node */
1289 };
1290
1291 /*
1292 * padded data
1293 */
1294 #define suc_child __sysc_unpad(_suc_child)
1295 #define sud_data __sysc_unpad(_sud_data)
1296 #define sud_offset __sysc_unpad(_sud_offset)
1297 #define sysctl_size __sysc_unpad(_sysctl_size)
1298 #define sysctl_func __sysc_unpad(_sysctl_func)
1299 #define sysctl_parent __sysc_unpad(_sysctl_parent)
1300 #define sysctl_desc __sysc_unpad(_sysctl_desc)
1301
1302 /*
1303 * nested data (may also be padded)
1304 */
1305 #define sysctl_csize sysctl_un.scu_child.suc_csize
1306 #define sysctl_clen sysctl_un.scu_child.suc_clen
1307 #define sysctl_child sysctl_un.scu_child.suc_child
1308 #define sysctl_data sysctl_un.scu_data.sud_data
1309 #define sysctl_offset sysctl_un.scu_data.sud_offset
1310 #define sysctl_alias sysctl_un.scu_alias
1311 #define sysctl_idata sysctl_un.scu_idata
1312 #define sysctl_qdata sysctl_un.scu_qdata
1313 #define sysctl_bdata sysctl_un.scu_bdata
1314
1315 /*
1316 * when requesting a description of a node (a set of nodes, actually),
1317 * you get back an "array" of these, where the actual length of the
1318 * descr_str is noted in descr_len (which includes the trailing nul
1319 * byte), rounded up to the nearest four (sizeof(int32_t) actually).
1320 *
1321 * NEXT_DESCR() will take a pointer to a description and advance it to
1322 * the next description.
1323 */
1324 struct sysctldesc {
1325 int32_t descr_num; /* mib number of node */
1326 uint32_t descr_ver; /* version of node */
1327 uint32_t descr_len; /* length of description string */
1328 char descr_str[1]; /* not really 1...see above */
1329 };
1330
1331 #define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
1332 #define __sysc_desc_len(l) (offsetof(struct sysctldesc, descr_str) +\
1333 __sysc_desc_roundup(l))
1334 #define __sysc_desc_adv(d, l) \
1335 (/*XXXUNCONST ptr cast*/(struct sysctldesc *) \
1336 __UNCONST(((const char*)(d)) + __sysc_desc_len(l)))
1337 #define NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
1338
1339 static __inline const struct sysctlnode *
sysctl_rootof(const struct sysctlnode * n)1340 sysctl_rootof(const struct sysctlnode *n)
1341 {
1342 while (n->sysctl_parent != NULL)
1343 n = n->sysctl_parent;
1344 return (n);
1345 }
1346
1347 #endif /* !_SYS_SYSCTL_H_ */
1348