FreeBSD/Linux Kernel Cross Reference
sys/sys/sysctl.h
1 /* $NetBSD: sysctl.h,v 1.133.2.1 2005/06/10 15:10:51 tron 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 /*
41 * These are for the eproc structure defined below.
42 */
43 #include <sys/time.h>
44 #include <sys/ucred.h>
45 #include <sys/ucontext.h>
46 #include <sys/proc.h>
47 #include <uvm/uvm_extern.h>
48
49 /* For offsetof() */
50 #if defined(_KERNEL) || defined(_STANDALONE)
51 #include <sys/systm.h>
52 #else
53 #include <stddef.h>
54 #endif
55
56 /*
57 * Definitions for sysctl call. The sysctl call uses a hierarchical name
58 * for objects that can be examined or modified. The name is expressed as
59 * a sequence of integers. Like a file path name, the meaning of each
60 * component depends on its place in the hierarchy. The top-level and kern
61 * identifiers are defined here, and other identifiers are defined in the
62 * respective subsystem header files.
63 */
64
65 #define CTL_MAXNAME 12 /* largest number of components supported */
66 #define SYSCTL_NAMELEN 32 /* longest name allowed for a node */
67
68 #define CREATE_BASE (1024) /* start of dynamic mib allocation */
69 #define SYSCTL_DEFSIZE 8 /* initial size of a child set */
70
71 /*
72 * Each subsystem defined by sysctl defines a list of variables
73 * for that subsystem. Each name is either a node with further
74 * levels defined below it, or it is a leaf of some particular
75 * type given below. Each sysctl level defines a set of name/type
76 * pairs to be used by sysctl(1) in manipulating the subsystem.
77 */
78 struct ctlname {
79 const char *ctl_name; /* subsystem name */
80 int ctl_type; /* type of name */
81 };
82 #define CTLTYPE_NODE 1 /* name is a node */
83 #define CTLTYPE_INT 2 /* name describes an integer */
84 #define CTLTYPE_STRING 3 /* name describes a string */
85 #define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
86 #define CTLTYPE_STRUCT 5 /* name describes a structure */
87
88 /*
89 * Flags that apply to each node, governing access and other features
90 */
91 #define CTLFLAG_READONLY 0x00000000
92 #define CTLFLAG_READONLY1 0x00000010
93 #define CTLFLAG_READONLY2 0x00000020
94 /* #define CTLFLAG_READ* 0x00000040 */
95 #define CTLFLAG_READWRITE 0x00000070
96 #define CTLFLAG_ANYWRITE 0x00000080
97 #define CTLFLAG_PRIVATE 0x00000100
98 #define CTLFLAG_PERMANENT 0x00000200
99 #define CTLFLAG_OWNDATA 0x00000400
100 #define CTLFLAG_IMMEDIATE 0x00000800
101 #define CTLFLAG_HEX 0x00001000
102 #define CTLFLAG_ROOT 0x00002000
103 #define CTLFLAG_ANYNUMBER 0x00004000
104 #define CTLFLAG_HIDDEN 0x00008000
105 #define CTLFLAG_ALIAS 0x00010000
106 #define CTLFLAG_MMAP 0x00020000
107 #define CTLFLAG_OWNDESC 0x00040000
108
109 /*
110 * sysctl API version
111 */
112 #define SYSCTL_VERS_MASK 0xff000000
113 #define SYSCTL_VERS_0 0x00000000
114 #define SYSCTL_VERS_1 0x01000000
115 #define SYSCTL_VERSION SYSCTL_VERS_1
116 #define SYSCTL_VERS(f) ((f) & SYSCTL_VERS_MASK)
117
118 /*
119 * Flags that can be set by a create request from user-space
120 */
121 #define SYSCTL_USERFLAGS (CTLFLAG_READWRITE|\
122 CTLFLAG_ANYWRITE|\
123 CTLFLAG_PRIVATE|\
124 CTLFLAG_OWNDATA|\
125 CTLFLAG_IMMEDIATE|\
126 CTLFLAG_HEX|\
127 CTLFLAG_HIDDEN)
128
129 /*
130 * Accessor macros
131 */
132 #define SYSCTL_TYPEMASK 0x0000000f
133 #define SYSCTL_TYPE(x) ((x) & SYSCTL_TYPEMASK)
134 #define SYSCTL_FLAGMASK 0x00fffff0
135 #define SYSCTL_FLAGS(x) ((x) & SYSCTL_FLAGMASK)
136
137 /*
138 * Meta-identifiers
139 */
140 #define CTL_EOL -1 /* end of createv/destroyv list */
141 #define CTL_QUERY -2 /* enumerates children of a node */
142 #define CTL_CREATE -3 /* node create request */
143 #define CTL_CREATESYM -4 /* node create request with symbol */
144 #define CTL_DESTROY -5 /* node destroy request */
145 #define CTL_MMAP -6 /* mmap request */
146 #define CTL_DESCRIBE -7 /* get node descriptions */
147
148 /*
149 * Top-level identifiers
150 */
151 #define CTL_UNSPEC 0 /* unused */
152 #define CTL_KERN 1 /* "high kernel": proc, limits */
153 #define CTL_VM 2 /* virtual memory */
154 #define CTL_VFS 3 /* file system, mount type is next */
155 #define CTL_NET 4 /* network, see socket.h */
156 #define CTL_DEBUG 5 /* debugging parameters */
157 #define CTL_HW 6 /* generic CPU/io */
158 #define CTL_MACHDEP 7 /* machine dependent */
159 #define CTL_USER 8 /* user-level */
160 #define CTL_DDB 9 /* in-kernel debugger */
161 #define CTL_PROC 10 /* per-proc attr */
162 #define CTL_VENDOR 11 /* vendor-specific data */
163 #define CTL_EMUL 12 /* emulation-specific data */
164 #define CTL_MAXID 13 /* number of valid top-level ids */
165
166 #define CTL_NAMES { \
167 { 0, 0 }, \
168 { "kern", CTLTYPE_NODE }, \
169 { "vm", CTLTYPE_NODE }, \
170 { "vfs", CTLTYPE_NODE }, \
171 { "net", CTLTYPE_NODE }, \
172 { "debug", CTLTYPE_NODE }, \
173 { "hw", CTLTYPE_NODE }, \
174 { "machdep", CTLTYPE_NODE }, \
175 { "user", CTLTYPE_NODE }, \
176 { "ddb", CTLTYPE_NODE }, \
177 { "proc", CTLTYPE_NODE }, \
178 { "vendor", CTLTYPE_NODE }, \
179 { "emul", CTLTYPE_NODE }, \
180 }
181
182 /*
183 * The "vendor" toplevel name is to be used by vendors who wish to
184 * have their own private MIB tree. If you do that, please use
185 * vendor.<yourname>.*
186 */
187
188 /*
189 * CTL_KERN identifiers
190 */
191 #define KERN_OSTYPE 1 /* string: system version */
192 #define KERN_OSRELEASE 2 /* string: system release */
193 #define KERN_OSREV 3 /* int: system revision */
194 #define KERN_VERSION 4 /* string: compile time info */
195 #define KERN_MAXVNODES 5 /* int: max vnodes */
196 #define KERN_MAXPROC 6 /* int: max processes */
197 #define KERN_MAXFILES 7 /* int: max open files */
198 #define KERN_ARGMAX 8 /* int: max arguments to exec */
199 #define KERN_SECURELVL 9 /* int: system security level */
200 #define KERN_HOSTNAME 10 /* string: hostname */
201 #define KERN_HOSTID 11 /* int: host identifier */
202 #define KERN_CLOCKRATE 12 /* struct: struct clockrate */
203 #define KERN_VNODE 13 /* struct: vnode structures */
204 #define KERN_PROC 14 /* struct: process entries */
205 #define KERN_FILE 15 /* struct: file entries */
206 #define KERN_PROF 16 /* node: kernel profiling info */
207 #define KERN_POSIX1 17 /* int: POSIX.1 version */
208 #define KERN_NGROUPS 18 /* int: # of supplemental group ids */
209 #define KERN_JOB_CONTROL 19 /* int: is job control available */
210 #define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
211 #define KERN_BOOTTIME 21 /* struct: time kernel was booted */
212 #define KERN_DOMAINNAME 22 /* string: (YP) domainname */
213 #define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */
214 #define KERN_RAWPARTITION 24 /* int: raw partition number */
215 #define KERN_NTPTIME 25 /* struct: extended-precision time */
216 #define KERN_TIMEX 26 /* struct: ntp timekeeping state */
217 #define KERN_AUTONICETIME 27 /* int: proc time before autonice */
218 #define KERN_AUTONICEVAL 28 /* int: auto nice value */
219 #define KERN_RTC_OFFSET 29 /* int: offset of rtc from gmt */
220 #define KERN_ROOT_DEVICE 30 /* string: root device */
221 #define KERN_MSGBUFSIZE 31 /* int: max # of chars in msg buffer */
222 #define KERN_FSYNC 32 /* int: file synchronization support */
223 #define KERN_SYSVMSG 33 /* int: SysV message queue suppoprt */
224 #define KERN_SYSVSEM 34 /* int: SysV semaphore support */
225 #define KERN_SYSVSHM 35 /* int: SysV shared memory support */
226 #define KERN_OLDSHORTCORENAME 36 /* old, unimplemented */
227 #define KERN_SYNCHRONIZED_IO 37 /* int: POSIX synchronized I/O */
228 #define KERN_IOV_MAX 38 /* int: max iovec's for readv(2) etc. */
229 #define KERN_MBUF 39 /* node: mbuf parameters */
230 #define KERN_MAPPED_FILES 40 /* int: POSIX memory mapped files */
231 #define KERN_MEMLOCK 41 /* int: POSIX memory locking */
232 #define KERN_MEMLOCK_RANGE 42 /* int: POSIX memory range locking */
233 #define KERN_MEMORY_PROTECTION 43 /* int: POSIX memory protections */
234 #define KERN_LOGIN_NAME_MAX 44 /* int: max length login name + NUL */
235 #define KERN_DEFCORENAME 45 /* old: sort core name format */
236 #define KERN_LOGSIGEXIT 46 /* int: log signalled processes */
237 #define KERN_PROC2 47 /* struct: process entries */
238 #define KERN_PROC_ARGS 48 /* struct: process argv/env */
239 #define KERN_FSCALE 49 /* int: fixpt FSCALE */
240 #define KERN_CCPU 50 /* int: fixpt ccpu */
241 #define KERN_CP_TIME 51 /* struct: CPU time counters */
242 #define KERN_SYSVIPC_INFO 52 /* number of valid kern ids */
243 #define KERN_MSGBUF 53 /* kernel message buffer */
244 #define KERN_CONSDEV 54 /* dev_t: console terminal device */
245 #define KERN_MAXPTYS 55 /* int: maximum number of ptys */
246 #define KERN_PIPE 56 /* node: pipe limits */
247 #define KERN_MAXPHYS 57 /* int: kernel value of MAXPHYS */
248 #define KERN_SBMAX 58 /* int: max socket buffer size */
249 #define KERN_TKSTAT 59 /* tty in/out counters */
250 #define KERN_MONOTONIC_CLOCK 60 /* int: POSIX monotonic clock */
251 #define KERN_URND 61 /* int: random integer from urandom */
252 #ifndef _KERNEL
253 #define KERN_ARND KERN_URND /* compat w/ openbsd */
254 #endif
255 #define KERN_LABELSECTOR 62 /* int: disklabel sector */
256 #define KERN_LABELOFFSET 63 /* int: offset of label within sector */
257 #define KERN_LWP 64 /* struct: lwp entries */
258 #define KERN_FORKFSLEEP 65 /* int: sleep length on failed fork */
259 #define KERN_POSIX_THREADS 66 /* int: POSIX Threads option */
260 #define KERN_POSIX_SEMAPHORES 67 /* int: POSIX Semaphores option */
261 #define KERN_POSIX_BARRIERS 68 /* int: POSIX Barriers option */
262 #define KERN_POSIX_TIMERS 69 /* int: POSIX Timers option */
263 #define KERN_POSIX_SPIN_LOCKS 70 /* int: POSIX Spin Locks option */
264 #define KERN_POSIX_READER_WRITER_LOCKS 71 /* int: POSIX R/W Locks option */
265 #define KERN_DUMP_ON_PANIC 72 /* int: dump on panic */
266 #define KERN_SOMAXKVA 73 /* int: max socket kernel virtual mem */
267 #define KERN_ROOT_PARTITION 74 /* int: root partition */
268 #define KERN_DRIVERS 75 /* struct: driver names and majors #s */
269 #define KERN_BUF 76 /* struct: buffers */
270 #define KERN_FILE2 77 /* struct: file entries */
271 #define KERN_VERIEXEC 78 /* node: verified exec */
272 #define KERN_MAXID 79 /* number of valid kern ids */
273
274
275 #define CTL_KERN_NAMES { \
276 { 0, 0 }, \
277 { "ostype", CTLTYPE_STRING }, \
278 { "osrelease", CTLTYPE_STRING }, \
279 { "osrevision", CTLTYPE_INT }, \
280 { "version", CTLTYPE_STRING }, \
281 { "maxvnodes", CTLTYPE_INT }, \
282 { "maxproc", CTLTYPE_INT }, \
283 { "maxfiles", CTLTYPE_INT }, \
284 { "argmax", CTLTYPE_INT }, \
285 { "securelevel", CTLTYPE_INT }, \
286 { "hostname", CTLTYPE_STRING }, \
287 { "hostid", CTLTYPE_INT }, \
288 { "clockrate", CTLTYPE_STRUCT }, \
289 { "vnode", CTLTYPE_STRUCT }, \
290 { "proc", CTLTYPE_STRUCT }, \
291 { "file", CTLTYPE_STRUCT }, \
292 { "profiling", CTLTYPE_NODE }, \
293 { "posix1version", CTLTYPE_INT }, \
294 { "ngroups", CTLTYPE_INT }, \
295 { "job_control", CTLTYPE_INT }, \
296 { "saved_ids", CTLTYPE_INT }, \
297 { "boottime", CTLTYPE_STRUCT }, \
298 { "domainname", CTLTYPE_STRING }, \
299 { "maxpartitions", CTLTYPE_INT }, \
300 { "rawpartition", CTLTYPE_INT }, \
301 { "ntptime", CTLTYPE_STRUCT }, \
302 { "timex", CTLTYPE_STRUCT }, \
303 { "autonicetime", CTLTYPE_INT }, \
304 { "autoniceval", CTLTYPE_INT }, \
305 { "rtc_offset", CTLTYPE_INT }, \
306 { "root_device", CTLTYPE_STRING }, \
307 { "msgbufsize", CTLTYPE_INT }, \
308 { "fsync", CTLTYPE_INT }, \
309 { "sysvmsg", CTLTYPE_INT }, \
310 { "sysvsem", CTLTYPE_INT }, \
311 { "sysvshm", CTLTYPE_INT }, \
312 { 0, 0 }, \
313 { "synchronized_io", CTLTYPE_INT }, \
314 { "iov_max", CTLTYPE_INT }, \
315 { "mbuf", CTLTYPE_NODE }, \
316 { "mapped_files", CTLTYPE_INT }, \
317 { "memlock", CTLTYPE_INT }, \
318 { "memlock_range", CTLTYPE_INT }, \
319 { "memory_protection", CTLTYPE_INT }, \
320 { "login_name_max", CTLTYPE_INT }, \
321 { "defcorename", CTLTYPE_STRING }, \
322 { "logsigexit", CTLTYPE_INT }, \
323 { "proc2", CTLTYPE_STRUCT }, \
324 { "proc_args", CTLTYPE_STRING }, \
325 { "fscale", CTLTYPE_INT }, \
326 { "ccpu", CTLTYPE_INT }, \
327 { "cp_time", CTLTYPE_STRUCT }, \
328 { "sysvipc_info", CTLTYPE_STRUCT }, \
329 { "msgbuf", CTLTYPE_STRUCT }, \
330 { "consdev", CTLTYPE_STRUCT }, \
331 { "maxptys", CTLTYPE_INT }, \
332 { "pipe", CTLTYPE_NODE }, \
333 { "maxphys", CTLTYPE_INT }, \
334 { "sbmax", CTLTYPE_INT }, \
335 { "tkstat", CTLTYPE_NODE }, \
336 { "monotonic_clock", CTLTYPE_INT }, \
337 { "urandom", CTLTYPE_INT }, \
338 { "labelsector", CTLTYPE_INT }, \
339 { "labeloffset", CTLTYPE_INT }, \
340 { "lwp", CTLTYPE_STRUCT }, \
341 { "forkfsleep", CTLTYPE_INT }, \
342 { "posix_threads", CTLTYPE_INT }, \
343 { "posix_semaphores", CTLTYPE_INT }, \
344 { "posix_barriers", CTLTYPE_INT }, \
345 { "posix_timers", CTLTYPE_INT }, \
346 { "posix_spin_locks", CTLTYPE_INT }, \
347 { "posix_reader_writer_locks", CTLTYPE_INT }, \
348 { "dump_on_panic", CTLTYPE_INT}, \
349 { "somaxkva", CTLTYPE_INT}, \
350 { "root_partition", CTLTYPE_INT}, \
351 { "drivers", CTLTYPE_STRUCT }, \
352 { "buf", CTLTYPE_NODE }, \
353 { "file2", CTLTYPE_STRUCT }, \
354 { "veriexec", CTLTYPE_NODE }, \
355 }
356
357 /*
358 * KERN_PROC subtypes
359 */
360 #define KERN_PROC_ALL 0 /* everything */
361 #define KERN_PROC_PID 1 /* by process id */
362 #define KERN_PROC_PGRP 2 /* by process group id */
363 #define KERN_PROC_SESSION 3 /* by session of pid */
364 #define KERN_PROC_TTY 4 /* by controlling tty */
365 #define KERN_PROC_UID 5 /* by effective uid */
366 #define KERN_PROC_RUID 6 /* by real uid */
367 #define KERN_PROC_GID 7 /* by effective gid */
368 #define KERN_PROC_RGID 8 /* by real gid */
369
370 /*
371 * KERN_PROC_TTY sub-subtypes
372 */
373 #define KERN_PROC_TTY_NODEV NODEV /* no controlling tty */
374 #define KERN_PROC_TTY_REVOKE ((dev_t)-2) /* revoked tty */
375
376 /*
377 * KERN_PROC subtype ops return arrays of augmented proc structures:
378 */
379 struct kinfo_proc {
380 struct proc kp_proc; /* proc structure */
381 struct eproc {
382 struct proc *e_paddr; /* address of proc */
383 struct session *e_sess; /* session pointer */
384 struct pcred e_pcred; /* process credentials */
385 struct ucred e_ucred; /* current credentials */
386 struct vmspace e_vm; /* address space */
387 pid_t e_ppid; /* parent process id */
388 pid_t e_pgid; /* process group id */
389 short e_jobc; /* job control counter */
390 dev_t e_tdev; /* controlling tty dev */
391 pid_t e_tpgid; /* tty process group id */
392 struct session *e_tsess; /* tty session pointer */
393 #define WMESGLEN 8
394 char e_wmesg[WMESGLEN]; /* wchan message */
395 segsz_t e_xsize; /* text size */
396 short e_xrssize; /* text rss */
397 short e_xccount; /* text references */
398 short e_xswrss;
399 long e_flag;
400 #define EPROC_CTTY 0x01 /* controlling tty vnode active */
401 #define EPROC_SLEADER 0x02 /* session leader */
402 char e_login[MAXLOGNAME]; /* setlogin() name */
403 pid_t e_sid; /* session id */
404 long e_spare[3];
405 } kp_eproc;
406 };
407
408 /*
409 * Convert pointer to 64 bit unsigned integer for struct
410 * kinfo_proc2, etc.
411 */
412 #define PTRTOUINT64(p) ((u_int64_t)(uintptr_t)(p))
413 #define UINT64TOPTR(u) ((void *)(uintptr_t)(u))
414
415 /*
416 * KERN_PROC2 subtype ops return arrays of relatively fixed size
417 * structures of process info. Use 8 byte alignment, and new
418 * elements should only be added to the end of this structure so
419 * binary compatibility can be preserved.
420 */
421 #define KI_NGROUPS 16
422 #define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */
423 #define KI_WMESGLEN 8
424 #define KI_MAXLOGNAME 24 /* extra for 8 byte alignment */
425
426 #define KI_NOCPU (~(u_int64_t)0)
427
428 typedef struct {
429 u_int32_t __bits[4];
430 } ki_sigset_t;
431
432 struct kinfo_proc2 {
433 u_int64_t p_forw; /* PTR: linked run/sleep queue. */
434 u_int64_t p_back;
435 u_int64_t p_paddr; /* PTR: address of proc */
436
437 u_int64_t p_addr; /* PTR: Kernel virtual addr of u-area */
438 u_int64_t p_fd; /* PTR: Ptr to open files structure. */
439 u_int64_t p_cwdi; /* PTR: cdir/rdir/cmask info */
440 u_int64_t p_stats; /* PTR: Accounting/statistics */
441 u_int64_t p_limit; /* PTR: Process limits. */
442 u_int64_t p_vmspace; /* PTR: Address space. */
443 u_int64_t p_sigacts; /* PTR: Signal actions, state */
444 u_int64_t p_sess; /* PTR: session pointer */
445 u_int64_t p_tsess; /* PTR: tty session pointer */
446 u_int64_t p_ru; /* PTR: Exit information. XXX */
447
448 int32_t p_eflag; /* LONG: extra kinfo_proc2 flags */
449 int32_t p_exitsig; /* INT: signal to sent to parent on exit */
450 int32_t p_flag; /* INT: P_* flags. */
451
452 int32_t p_pid; /* PID_T: Process identifier. */
453 int32_t p_ppid; /* PID_T: Parent process id */
454 int32_t p_sid; /* PID_T: session id */
455 int32_t p__pgid; /* PID_T: process group id */
456 /* XXX: <sys/proc.h> hijacks p_pgid */
457 int32_t p_tpgid; /* PID_T: tty process group id */
458
459 u_int32_t p_uid; /* UID_T: effective user id */
460 u_int32_t p_ruid; /* UID_T: real user id */
461 u_int32_t p_gid; /* GID_T: effective group id */
462 u_int32_t p_rgid; /* GID_T: real group id */
463
464 u_int32_t p_groups[KI_NGROUPS]; /* GID_T: groups */
465 int16_t p_ngroups; /* SHORT: number of groups */
466
467 int16_t p_jobc; /* SHORT: job control counter */
468 u_int32_t p_tdev; /* DEV_T: controlling tty dev */
469
470 u_int32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */
471 u_int32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */
472 u_int32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */
473 int32_t p_cpticks; /* INT: Ticks of CPU time. */
474 u_int32_t p_pctcpu; /* FIXPT_T: %cpu for this process during p_swtime */
475 u_int32_t p_swtime; /* U_INT: Time swapped in or out. */
476 u_int32_t p_slptime; /* U_INT: Time since last blocked. */
477 int32_t p_schedflags; /* INT: PSCHED_* flags */
478
479 u_int64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */
480 u_int64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */
481 u_int64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */
482
483 u_int64_t p_tracep; /* PTR: Trace to vnode or file */
484 int32_t p_traceflag; /* INT: Kernel trace points. */
485
486 int32_t p_holdcnt; /* INT: If non-zero, don't swap. */
487
488 ki_sigset_t p_siglist; /* SIGSET_T: Signals arrived but not delivered. */
489 ki_sigset_t p_sigmask; /* SIGSET_T: Current signal mask. */
490 ki_sigset_t p_sigignore; /* SIGSET_T: Signals being ignored. */
491 ki_sigset_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */
492
493 int8_t p_stat; /* CHAR: S* process status (from LWP). */
494 u_int8_t p_priority; /* U_CHAR: Process priority. */
495 u_int8_t p_usrpri; /* U_CHAR: User-priority based on p_cpu and p_nice. */
496 u_int8_t p_nice; /* U_CHAR: Process "nice" value. */
497
498 u_int16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */
499 u_int16_t p_acflag; /* U_SHORT: Accounting flags. */
500
501 char p_comm[KI_MAXCOMLEN];
502
503 char p_wmesg[KI_WMESGLEN]; /* wchan message */
504 u_int64_t p_wchan; /* PTR: sleep address. */
505
506 char p_login[KI_MAXLOGNAME]; /* setlogin() name */
507
508 int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */
509 int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */
510 int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */
511 int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */
512
513 int64_t p_uvalid; /* CHAR: following p_u* members from struct user are valid */
514 /* XXX 64 bits for alignment */
515 u_int32_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */
516 u_int32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */
517
518 u_int32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */
519 u_int32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */
520 u_int32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */
521 u_int32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */
522
523 u_int64_t p_uru_maxrss; /* LONG: max resident set size. */
524 u_int64_t p_uru_ixrss; /* LONG: integral shared memory size. */
525 u_int64_t p_uru_idrss; /* LONG: integral unshared data ". */
526 u_int64_t p_uru_isrss; /* LONG: integral unshared stack ". */
527 u_int64_t p_uru_minflt; /* LONG: page reclaims. */
528 u_int64_t p_uru_majflt; /* LONG: page faults. */
529 u_int64_t p_uru_nswap; /* LONG: swaps. */
530 u_int64_t p_uru_inblock; /* LONG: block input operations. */
531 u_int64_t p_uru_oublock; /* LONG: block output operations. */
532 u_int64_t p_uru_msgsnd; /* LONG: messages sent. */
533 u_int64_t p_uru_msgrcv; /* LONG: messages received. */
534 u_int64_t p_uru_nsignals; /* LONG: signals received. */
535 u_int64_t p_uru_nvcsw; /* LONG: voluntary context switches. */
536 u_int64_t p_uru_nivcsw; /* LONG: involuntary ". */
537
538 u_int32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */
539 u_int32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */
540 u_int64_t p_cpuid; /* LONG: CPU id */
541 u_int64_t p_realflag; /* INT: P_* flags (not including LWPs). */
542 u_int64_t p_nlwps; /* LONG: Number of LWPs */
543 u_int64_t p_nrlwps; /* LONG: Number of running LWPs */
544 u_int64_t p_realstat; /* LONG: non-LWP process status */
545 u_int32_t p_svuid; /* UID_T: saved user id */
546 u_int32_t p_svgid; /* GID_T: saved group id */
547 };
548
549 /*
550 * KERN_LWP structure. See notes on KERN_PROC2 about adding elements.
551 */
552 struct kinfo_lwp {
553 u_int64_t l_forw; /* PTR: linked run/sleep queue. */
554 u_int64_t l_back;
555 u_int64_t l_laddr; /* PTR: Address of LWP */
556 u_int64_t l_addr; /* PTR: Kernel virtual addr of u-area */
557 int32_t l_lid; /* LWPID_T: LWP identifier */
558 int32_t l_flag; /* INT: L_* flags. */
559 u_int32_t l_swtime; /* U_INT: Time swapped in or out. */
560 u_int32_t l_slptime; /* U_INT: Time since last blocked. */
561 int32_t l_schedflags; /* INT: PSCHED_* flags */
562 int32_t l_holdcnt; /* INT: If non-zero, don't swap. */
563 u_int8_t l_priority; /* U_CHAR: Process priority. */
564 u_int8_t l_usrpri; /* U_CHAR: User-priority based on l_cpu and p_nice. */
565 int8_t l_stat; /* CHAR: S* process status. */
566 int8_t l_pad1; /* fill out to 4-byte boundary */
567 int32_t l_pad2; /* .. and then to an 8-byte boundary */
568 char l_wmesg[KI_WMESGLEN]; /* wchan message */
569 u_int64_t l_wchan; /* PTR: sleep address. */
570 u_int64_t l_cpuid; /* LONG: CPU id */
571 };
572
573 /*
574 * KERN_PROC_ARGS subtypes
575 */
576 #define KERN_PROC_ARGV 1 /* argv */
577 #define KERN_PROC_NARGV 2 /* number of strings in above */
578 #define KERN_PROC_ENV 3 /* environ */
579 #define KERN_PROC_NENV 4 /* number of strings in above */
580
581 /*
582 * KERN_SYSVIPC_INFO subtypes
583 */
584 #define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */
585 #define KERN_SYSVIPC_SEM_INFO 2 /* seminfo and semid_ds */
586 #define KERN_SYSVIPC_SHM_INFO 3 /* shminfo and shmid_ds */
587
588 /*
589 * tty counter sysctl variables
590 */
591 #define KERN_TKSTAT_NIN 1 /* total input character */
592 #define KERN_TKSTAT_NOUT 2 /* total output character */
593 #define KERN_TKSTAT_CANCC 3 /* canonical input character */
594 #define KERN_TKSTAT_RAWCC 4 /* raw input character */
595 #define KERN_TKSTAT_MAXID 5 /* number of valid TKSTAT ids */
596
597 #define KERN_TKSTAT_NAMES { \
598 { 0, 0 }, \
599 { "nin", CTLTYPE_QUAD }, \
600 { "nout", CTLTYPE_QUAD }, \
601 { "cancc", CTLTYPE_QUAD }, \
602 { "rawcc", CTLTYPE_QUAD }, \
603 }
604
605 /*
606 * kern.drivers returns an array of these.
607 */
608
609 struct kinfo_drivers {
610 int32_t d_cmajor;
611 int32_t d_bmajor;
612 char d_name[24];
613 };
614
615 /*
616 * KERN_BUF subtypes, like KERN_PROC2, where the four following mib
617 * entries specify "which type of buf", "which particular buf",
618 * "sizeof buf", and "how many". Currently, only "all buf" is
619 * defined.
620 */
621 #define KERN_BUF_ALL 0 /* all buffers */
622
623 /*
624 * kern.buf returns an array of these structures, which are designed
625 * both to be immune to 32/64 bit emulation issues and to provide
626 * backwards compatibility. Note that the order here differs slightly
627 * from the real struct buf in order to achieve proper 64 bit
628 * alignment.
629 */
630 struct buf_sysctl {
631 uint32_t b_flags; /* LONG: B_* flags */
632 int32_t b_error; /* INT: Errno value */
633 int32_t b_prio; /* INT: Hint for buffer queue discipline */
634 uint32_t b_dev; /* DEV_T: Device associated with buffer */
635 uint64_t b_bufsize; /* LONG: Allocated buffer size */
636 uint64_t b_bcount; /* LONG: Valid bytes in buffer */
637 uint64_t b_resid; /* LONG: Remaining I/O */
638 uint64_t b_addr; /* CADDR_T: Memory, superblocks, indirect... */
639 uint64_t b_blkno; /* DADDR_T: Underlying physical block number */
640 uint64_t b_rawblkno; /* DADDR_T: Raw underlying physical block */
641 uint64_t b_iodone; /* PTR: Function called upon completion */
642 uint64_t b_proc; /* PTR: Associated proc if B_PHYS set */
643 uint64_t b_vp; /* PTR: File vnode */
644 uint64_t b_saveaddr; /* PTR: Original b_addr for physio */
645 uint64_t b_lblkno; /* DADDR_T: Logical block number */
646 };
647
648 /*
649 * kern.file2 returns an array of these structures, which are designed
650 * both to be immune to be immune to 32/64 bit emulation issues and to
651 * provide backwards compatibility. The order differs slightly from
652 * that of the real struct file, and some fields are taken from other
653 * structures (struct vnode, struct proc) in order to make the file
654 * information more useful.
655 */
656 struct kinfo_file {
657 uint64_t ki_fileaddr; /* PTR: address of struct file */
658 uint32_t ki_flag; /* INT: flags (see fcntl.h) */
659 uint32_t ki_iflags; /* INT: internal flags */
660 uint32_t ki_ftype; /* INT: descriptor type */
661 uint32_t ki_count; /* UINT: reference count */
662 uint32_t ki_msgcount; /* UINT: references from msg queue */
663 uint32_t ki_usecount; /* INT: number active users */
664 uint64_t ki_fucred; /* PTR: creds for descriptor */
665 uint32_t ki_fuid; /* UID_T: descriptor credentials */
666 uint32_t ki_fgid; /* GID_T: descriptor credentials */
667 uint64_t ki_fops; /* PTR: address of fileops */
668 uint64_t ki_foffset; /* OFF_T: offset */
669 uint64_t ki_fdata; /* PTR: descriptor data */
670
671 /* vnode information to glue this file to something */
672 uint64_t ki_vun; /* PTR: socket, specinfo, etc */
673 uint64_t ki_vsize; /* OFF_T: size of file */
674 uint32_t ki_vtype; /* ENUM: vnode type */
675 uint32_t ki_vtag; /* ENUM: type of underlying data */
676 uint64_t ki_vdata; /* PTR: private data for fs */
677
678 /* process information when retrieved via KERN_FILE_BYPID */
679 uint32_t ki_pid; /* PID_T: process id */
680 int32_t ki_fd; /* INT: descriptor number */
681 uint32_t ki_ofileflags; /* CHAR: open file flags */
682 uint32_t _ki_padto64bits;
683 };
684
685 #define KERN_FILE_BYFILE 1
686 #define KERN_FILE_BYPID 2
687 #define KERN_FILESLOP 10
688
689 /*
690 * CTL_HW identifiers
691 */
692 #define HW_MACHINE 1 /* string: machine class */
693 #define HW_MODEL 2 /* string: specific machine model */
694 #define HW_NCPU 3 /* int: number of cpus */
695 #define HW_BYTEORDER 4 /* int: machine byte order */
696 #define HW_PHYSMEM 5 /* int: total memory (bytes) */
697 #define HW_USERMEM 6 /* int: non-kernel memory (bytes) */
698 #define HW_PAGESIZE 7 /* int: software page size */
699 #define HW_DISKNAMES 8 /* string: disk drive names */
700 #define HW_DISKSTATS 9 /* struct: diskstats[] */
701 #define HW_MACHINE_ARCH 10 /* string: machine architecture */
702 #define HW_ALIGNBYTES 11 /* int: ALIGNBYTES for the kernel */
703 #define HW_CNMAGIC 12 /* string: console magic sequence(s) */
704 #define HW_PHYSMEM64 13 /* quad: total memory (bytes) */
705 #define HW_USERMEM64 14 /* quad: non-kernel memory (bytes) */
706 #define HW_MAXID 15 /* number of valid hw ids */
707
708 #define CTL_HW_NAMES { \
709 { 0, 0 }, \
710 { "machine", CTLTYPE_STRING }, \
711 { "model", CTLTYPE_STRING }, \
712 { "ncpu", CTLTYPE_INT }, \
713 { "byteorder", CTLTYPE_INT }, \
714 { "physmem", CTLTYPE_INT }, \
715 { "usermem", CTLTYPE_INT }, \
716 { "pagesize", CTLTYPE_INT }, \
717 { "disknames", CTLTYPE_STRING }, \
718 { "diskstats", CTLTYPE_STRUCT }, \
719 { "machine_arch", CTLTYPE_STRING }, \
720 { "alignbytes", CTLTYPE_INT }, \
721 { "cnmagic", CTLTYPE_STRING }, \
722 { "physmem64", CTLTYPE_QUAD }, \
723 { "usermem64", CTLTYPE_QUAD }, \
724 }
725
726 /*
727 * CTL_USER definitions
728 */
729 #define USER_CS_PATH 1 /* string: _CS_PATH */
730 #define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
731 #define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
732 #define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
733 #define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
734 #define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
735 #define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
736 #define USER_LINE_MAX 8 /* int: LINE_MAX */
737 #define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
738 #define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
739 #define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
740 #define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
741 #define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
742 #define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
743 #define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
744 #define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
745 #define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
746 #define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
747 #define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
748 #define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
749 #define USER_ATEXIT_MAX 21 /* int: {ATEXIT_MAX} */
750 #define USER_MAXID 22 /* number of valid user ids */
751
752 #define CTL_USER_NAMES { \
753 { 0, 0 }, \
754 { "cs_path", CTLTYPE_STRING }, \
755 { "bc_base_max", CTLTYPE_INT }, \
756 { "bc_dim_max", CTLTYPE_INT }, \
757 { "bc_scale_max", CTLTYPE_INT }, \
758 { "bc_string_max", CTLTYPE_INT }, \
759 { "coll_weights_max", CTLTYPE_INT }, \
760 { "expr_nest_max", CTLTYPE_INT }, \
761 { "line_max", CTLTYPE_INT }, \
762 { "re_dup_max", CTLTYPE_INT }, \
763 { "posix2_version", CTLTYPE_INT }, \
764 { "posix2_c_bind", CTLTYPE_INT }, \
765 { "posix2_c_dev", CTLTYPE_INT }, \
766 { "posix2_char_term", CTLTYPE_INT }, \
767 { "posix2_fort_dev", CTLTYPE_INT }, \
768 { "posix2_fort_run", CTLTYPE_INT }, \
769 { "posix2_localedef", CTLTYPE_INT }, \
770 { "posix2_sw_dev", CTLTYPE_INT }, \
771 { "posix2_upe", CTLTYPE_INT }, \
772 { "stream_max", CTLTYPE_INT }, \
773 { "tzname_max", CTLTYPE_INT }, \
774 { "atexit_max", CTLTYPE_INT }, \
775 }
776
777 /*
778 * CTL_DDB definitions
779 */
780 #define DDBCTL_RADIX 1 /* int: Input and output radix */
781 #define DDBCTL_MAXOFF 2 /* int: max symbol offset */
782 #define DDBCTL_MAXWIDTH 3 /* int: width of the display line */
783 #define DDBCTL_LINES 4 /* int: number of display lines */
784 #define DDBCTL_TABSTOPS 5 /* int: tab width */
785 #define DDBCTL_ONPANIC 6 /* int: DDB on panic if non-zero */
786 #define DDBCTL_FROMCONSOLE 7 /* int: DDB via console if non-zero */
787 #define DDBCTL_MAXID 8 /* number of valid DDB ids */
788
789 #define CTL_DDB_NAMES { \
790 { 0, 0 }, \
791 { "radix", CTLTYPE_INT }, \
792 { "maxoff", CTLTYPE_INT }, \
793 { "maxwidth", CTLTYPE_INT }, \
794 { "lines", CTLTYPE_INT }, \
795 { "tabstops", CTLTYPE_INT }, \
796 { "onpanic", CTLTYPE_INT }, \
797 { "fromconsole", CTLTYPE_INT }, \
798 }
799
800 /*
801 * CTL_DEBUG definitions
802 *
803 * Second level identifier specifies which debug variable.
804 * Third level identifier specifies which stucture component.
805 */
806 #define CTL_DEBUG_NAME 0 /* string: variable name */
807 #define CTL_DEBUG_VALUE 1 /* int: variable value */
808 #define CTL_DEBUG_MAXID 20
809
810 /*
811 * CTL_PROC subtype. Either a PID, or a magic value for the current proc.
812 */
813
814 #define PROC_CURPROC (~((u_int)1 << 31))
815
816 /*
817 * CTL_PROC tree: either corename (string), or a limit
818 * (rlimit.<type>.{hard,soft}, int).
819 */
820 #define PROC_PID_CORENAME 1
821 #define PROC_PID_LIMIT 2
822 #define PROC_PID_STOPFORK 3
823 #define PROC_PID_STOPEXEC 4
824 #define PROC_PID_STOPEXIT 5
825 #define PROC_PID_MAXID 6
826
827 #define PROC_PID_NAMES { \
828 { 0, 0 }, \
829 { "corename", CTLTYPE_STRING }, \
830 { "rlimit", CTLTYPE_NODE }, \
831 { "stopfork", CTLTYPE_INT }, \
832 { "stopexec", CTLTYPE_INT }, \
833 { "stopexit", CTLTYPE_INT }, \
834 }
835
836 /* Limit types from <sys/resources.h> */
837 #define PROC_PID_LIMIT_CPU (RLIMIT_CPU+1)
838 #define PROC_PID_LIMIT_FSIZE (RLIMIT_FSIZE+1)
839 #define PROC_PID_LIMIT_DATA (RLIMIT_DATA+1)
840 #define PROC_PID_LIMIT_STACK (RLIMIT_STACK+1)
841 #define PROC_PID_LIMIT_CORE (RLIMIT_CORE+1)
842 #define PROC_PID_LIMIT_RSS (RLIMIT_RSS+1)
843 #define PROC_PID_LIMIT_MEMLOCK (RLIMIT_MEMLOCK+1)
844 #define PROC_PID_LIMIT_NPROC (RLIMIT_NPROC+1)
845 #define PROC_PID_LIMIT_NOFILE (RLIMIT_NOFILE+1)
846 #define PROC_PID_LIMIT_SBSIZE (RLIMIT_SBSIZE+1)
847 #define PROC_PID_LIMIT_MAXID (RLIM_NLIMITS+1)
848
849 #define PROC_PID_LIMIT_NAMES { \
850 { 0, 0 }, \
851 { "cputime", CTLTYPE_NODE }, \
852 { "filesize", CTLTYPE_NODE }, \
853 { "datasize", CTLTYPE_NODE }, \
854 { "stacksize", CTLTYPE_NODE }, \
855 { "coredumpsize", CTLTYPE_NODE }, \
856 { "memoryuse", CTLTYPE_NODE }, \
857 { "memorylocked", CTLTYPE_NODE }, \
858 { "maxproc", CTLTYPE_NODE }, \
859 { "descriptors", CTLTYPE_NODE }, \
860 { "sbsize", CTLTYPE_NODE }, \
861 }
862 /* for each type, either hard or soft value */
863 #define PROC_PID_LIMIT_TYPE_SOFT 1
864 #define PROC_PID_LIMIT_TYPE_HARD 2
865 #define PROC_PID_LIMIT_TYPE_MAXID 3
866
867 #define PROC_PID_LIMIT_TYPE_NAMES { \
868 {0, 0}, \
869 { "soft", CTLTYPE_QUAD }, \
870 { "hard", CTLTYPE_QUAD }, \
871 }
872
873 /*
874 * CTL_EMUL definitions
875 *
876 * Second level identifier specifies which emulation variable.
877 * Subsequent levels are specified in the emulations themselves.
878 */
879 #define EMUL_LINUX 1
880 #define EMUL_IRIX 2
881 #define EMUL_DARWIN 3
882 #define EMUL_MACH 4
883
884 #define EMUL_MAXID 5
885 #define CTL_EMUL_NAMES { \
886 { 0, 0 }, \
887 { "linux", CTLTYPE_NODE }, \
888 { "irix", CTLTYPE_NODE }, \
889 { "darwin", CTLTYPE_NODE }, \
890 { "mach", CTLTYPE_NODE }, \
891 }
892
893 #ifdef _KERNEL
894
895 #if defined(_KERNEL_OPT)
896 #include "opt_sysctl.h"
897 #endif
898
899 /* Root node of the kernel sysctl tree */
900 extern struct sysctlnode sysctl_root;
901
902 /*
903 * A log of nodes created by a setup function or set of setup
904 * functions so that they can be torn down in one "transaction"
905 * when no longer needed.
906 *
907 * Users of the log merely pass a pointer to a pointer, and the sysctl
908 * infrastructure takes care of the rest.
909 */
910 struct sysctllog;
911
912 /*
913 * CTL_DEBUG variables.
914 *
915 * These are declared as separate variables so that they can be
916 * individually initialized at the location of their associated
917 * variable. The loader prevents multiple use by issuing errors
918 * if a variable is initialized in more than one place. They are
919 * aggregated into an array in debug_sysctl(), so that it can
920 * conveniently locate them when querried. If more debugging
921 * variables are added, they must also be declared here and also
922 * entered into the array.
923 *
924 * Note that the debug subtree is largely obsolescent in terms of
925 * functionality now that we have dynamic sysctl, but the
926 * infrastructure is retained for backwards compatibility.
927 */
928 struct ctldebug {
929 char *debugname; /* name of debugging variable */
930 int *debugvar; /* pointer to debugging variable */
931 };
932 #ifdef DEBUG
933 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
934 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
935 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
936 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
937 #endif /* DEBUG */
938
939 #define SYSCTLFN_PROTO const int *, u_int, void *, \
940 size_t *, const void *, size_t, \
941 const int *, struct lwp *, const struct sysctlnode *
942 #define SYSCTLFN_ARGS const int *name, u_int namelen, void *oldp, \
943 size_t *oldlenp, const void *newp, size_t newlen, \
944 const int *oname, struct lwp *l, const struct sysctlnode *rnode
945 #define SYSCTLFN_RWPROTO const int *, u_int, void *, \
946 size_t *, const void *, size_t, \
947 const int *, struct lwp *, struct sysctlnode *
948 #define SYSCTLFN_RWARGS const int *name, u_int namelen, void *oldp, \
949 size_t *oldlenp, const void *newp, size_t newlen, \
950 const int *oname, struct lwp *l, struct sysctlnode *rnode
951 #define SYSCTLFN_CALL(node) name, namelen, oldp, \
952 oldlenp, newp, newlen, \
953 oname, l, (struct sysctlnode *)node
954
955 #ifdef _LKM
956
957 #define SYSCTL_SETUP_PROTO(name) \
958 void name(struct sysctllog **)
959 #ifdef SYSCTL_DEBUG_SETUP
960 #define SYSCTL_SETUP(name, desc) \
961 static void __CONCAT(___,name)(struct sysctllog **); \
962 void name(struct sysctllog **clog) { \
963 printf("%s\n", desc); \
964 __CONCAT(___,name)(clog); } \
965 __link_set_add_text(sysctl_funcs, name); \
966 static void __CONCAT(___,name)(struct sysctllog **clog)
967 #else /* SYSCTL_DEBUG_SETUP */
968 #define SYSCTL_SETUP(name, desc) \
969 __link_set_add_text(sysctl_funcs, name); \
970 void name(struct sysctllog **clog)
971 #endif /* SYSCTL_DEBUG_SETUP */
972
973 #else /* _LKM */
974
975 #define SYSCTL_SETUP_PROTO(name)
976 #ifdef SYSCTL_DEBUG_SETUP
977 #define SYSCTL_SETUP(name, desc) \
978 static void __CONCAT(___,name)(struct sysctllog **); \
979 static void name(struct sysctllog **clog) { \
980 printf("%s\n", desc); \
981 __CONCAT(___,name)(clog); } \
982 __link_set_add_text(sysctl_funcs, name); \
983 static void __CONCAT(___,name)(struct sysctllog **clog)
984 #else /* SYSCTL_DEBUG_SETUP */
985 #define SYSCTL_SETUP(name, desc) \
986 static void name(struct sysctllog **); \
987 __link_set_add_text(sysctl_funcs, name); \
988 static void name(struct sysctllog **clog)
989 #endif /* SYSCTL_DEBUG_SETUP */
990 typedef void (*sysctl_setup_func)(struct sysctllog **);
991
992 #endif /* _LKM */
993
994 /*
995 * Internal sysctl function calling convention:
996 *
997 * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen,
998 * origname, lwp, node);
999 *
1000 * The name parameter points at the next component of the name to be
1001 * interpreted. The namelen parameter is the number of integers in
1002 * the name. The origname parameter points to the start of the name
1003 * being parsed. The node parameter points to the node on which the
1004 * current operation is to be performed.
1005 */
1006 typedef int (*sysctlfn)(SYSCTLFN_PROTO);
1007
1008 /*
1009 * used in more than just sysctl
1010 */
1011 void fill_eproc(struct proc *, struct eproc *);
1012
1013 /*
1014 * subsystem setup
1015 */
1016 void sysctl_init(void);
1017
1018 /*
1019 * typical syscall call order
1020 */
1021 int sysctl_lock(struct lwp *, void *, size_t);
1022 int sysctl_dispatch(SYSCTLFN_RWPROTO);
1023 void sysctl_unlock(struct lwp *);
1024
1025 /*
1026 * tree navigation primitives (must obtain lock before using these)
1027 */
1028 int sysctl_locate(struct lwp *, const int *, u_int, struct sysctlnode **,
1029 int *);
1030 int sysctl_query(SYSCTLFN_PROTO);
1031 #ifdef SYSCTL_DEBUG_CREATE
1032 #define sysctl_create _sysctl_create
1033 #endif /* SYSCTL_DEBUG_CREATE */
1034 int sysctl_create(SYSCTLFN_RWPROTO);
1035 int sysctl_destroy(SYSCTLFN_RWPROTO);
1036 int sysctl_lookup(SYSCTLFN_RWPROTO);
1037 int sysctl_describe(SYSCTLFN_PROTO);
1038
1039 /*
1040 * simple variadic interface for adding/removing nodes
1041 */
1042 int sysctl_createv(struct sysctllog **, int,
1043 struct sysctlnode **, struct sysctlnode **,
1044 int, int, const char *, const char *,
1045 sysctlfn, u_quad_t, void *, size_t, ...);
1046 int sysctl_destroyv(struct sysctlnode *, ...);
1047
1048 /*
1049 * miscellany
1050 */
1051 void sysctl_dump(const struct sysctlnode *);
1052 void sysctl_free(struct sysctlnode *);
1053 void sysctl_teardown(struct sysctllog **);
1054
1055 #ifdef SYSCTL_INCLUDE_DESCR
1056 #define SYSCTL_DESCR(s) s
1057 #else /* SYSCTL_INCLUDE_DESCR */
1058 #define SYSCTL_DESCR(s) NULL
1059 #endif /* SYSCTL_INCLUDE_DESCR */
1060
1061 /*
1062 * simple interface similar to old interface for in-kernel consumption
1063 */
1064 int old_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct lwp *);
1065
1066 /*
1067 * these helpers are in other files (XXX so should the nodes be) or
1068 * are used by more than one node
1069 */
1070 int sysctl_hw_disknames(SYSCTLFN_PROTO);
1071 int sysctl_hw_diskstats(SYSCTLFN_PROTO);
1072 int sysctl_kern_vnode(SYSCTLFN_PROTO);
1073 int sysctl_net_inet_ip_ports(SYSCTLFN_PROTO);
1074 int sysctl_consdev(SYSCTLFN_PROTO);
1075 int sysctl_root_device(SYSCTLFN_PROTO);
1076
1077 /*
1078 * primitive helper stubs
1079 */
1080 int sysctl_needfunc(SYSCTLFN_PROTO);
1081 int sysctl_notavail(SYSCTLFN_PROTO);
1082 int sysctl_null(SYSCTLFN_PROTO);
1083
1084 MALLOC_DECLARE(M_SYSCTLNODE);
1085 MALLOC_DECLARE(M_SYSCTLDATA);
1086
1087 #else /* !_KERNEL */
1088 #include <sys/cdefs.h>
1089
1090 typedef void *sysctlfn;
1091
1092 __BEGIN_DECLS
1093 int sysctl(int *, u_int, void *, size_t *, const void *, size_t);
1094 int sysctlbyname(const char *, void *, size_t *, void *, size_t);
1095 int sysctlgetmibinfo(const char *, int *, u_int *,
1096 char *, size_t *, struct sysctlnode **, int);
1097 int sysctlnametomib(const char *, int *, size_t *);
1098 __END_DECLS
1099
1100 #endif /* !_KERNEL */
1101
1102 #ifdef __COMPAT_SYSCTL
1103 /*
1104 * old node definitions go here
1105 */
1106 #endif /* __COMPAT_SYSCTL */
1107
1108 /*
1109 * padding makes alignment magically "work" for 32/64 compatibility at
1110 * the expense of making things bigger on 32 bit platforms.
1111 */
1112 #if defined(_LP64) || (BYTE_ORDER == LITTLE_ENDIAN)
1113 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1114 struct { type __sysc_sdatum; } __sysc_ustr; }
1115 #else
1116 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1117 struct { uint32_t __sysc_spad; type __sysc_sdatum; } __sysc_ustr; }
1118 #endif
1119 #define __sysc_unpad(x) x.__sysc_ustr.__sysc_sdatum
1120
1121 /*
1122 * The following is for gcc2, which doesn't handle __sysc_unpad().
1123 * The code gets a little less ugly this way.
1124 */
1125 #define sysc_init_field(field, value) \
1126 .field = { .__sysc_ustr = { .__sysc_sdatum = (value), }, }
1127
1128 struct sysctlnode {
1129 uint32_t sysctl_flags; /* flags and type */
1130 int32_t sysctl_num; /* mib number */
1131 char sysctl_name[SYSCTL_NAMELEN]; /* node name */
1132 uint32_t sysctl_ver; /* node's version vs. rest of tree */
1133 uint32_t __rsvd;
1134 union {
1135 struct {
1136 uint32_t suc_csize; /* size of child node array */
1137 uint32_t suc_clen; /* number of valid children */
1138 __sysc_pad(struct sysctlnode*) _suc_child; /* array of child nodes */
1139 } scu_child;
1140 struct {
1141 __sysc_pad(void*) _sud_data; /* pointer to external data */
1142 __sysc_pad(size_t) _sud_offset; /* offset to data */
1143 } scu_data;
1144 int32_t scu_alias; /* node this node refers to */
1145 int32_t scu_idata; /* immediate "int" data */
1146 u_quad_t scu_qdata; /* immediate "u_quad_t" data */
1147 } sysctl_un;
1148 __sysc_pad(size_t) _sysctl_size; /* size of instrumented data */
1149 __sysc_pad(sysctlfn) _sysctl_func; /* access helper function */
1150 __sysc_pad(struct sysctlnode*) _sysctl_parent; /* parent of this node */
1151 __sysc_pad(const char *) _sysctl_desc; /* description of node */
1152 };
1153
1154 /*
1155 * padded data
1156 */
1157 #define suc_child __sysc_unpad(_suc_child)
1158 #define sud_data __sysc_unpad(_sud_data)
1159 #define sud_offset __sysc_unpad(_sud_offset)
1160 #define sysctl_size __sysc_unpad(_sysctl_size)
1161 #define sysctl_func __sysc_unpad(_sysctl_func)
1162 #define sysctl_parent __sysc_unpad(_sysctl_parent)
1163 #define sysctl_desc __sysc_unpad(_sysctl_desc)
1164
1165 /*
1166 * nested data (may also be padded)
1167 */
1168 #define sysctl_csize sysctl_un.scu_child.suc_csize
1169 #define sysctl_clen sysctl_un.scu_child.suc_clen
1170 #define sysctl_child sysctl_un.scu_child.suc_child
1171 #define sysctl_data sysctl_un.scu_data.sud_data
1172 #define sysctl_offset sysctl_un.scu_data.sud_offset
1173 #define sysctl_alias sysctl_un.scu_alias
1174 #define sysctl_idata sysctl_un.scu_idata
1175 #define sysctl_qdata sysctl_un.scu_qdata
1176
1177 /*
1178 * when requesting a description of a node (a set of nodes, actually),
1179 * you get back an "array" of these, where the actual length of the
1180 * descr_str is noted in descr_len (which includes the trailing nul
1181 * byte), rounded up to the nearest four (sizeof(int32_t) actually).
1182 *
1183 * NEXT_DESCR() will take a pointer to a description and advance it to
1184 * the next description.
1185 */
1186 struct sysctldesc {
1187 int32_t descr_num; /* mib number of node */
1188 uint32_t descr_ver; /* version of node */
1189 uint32_t descr_len; /* length of description string */
1190 char descr_str[1]; /* not really 1...see above */
1191 };
1192
1193 #define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
1194 #define __sysc_desc_adv(d, l) \
1195 (/*LINTED ptr cast*/(struct sysctldesc *) \
1196 (((const char*)(d)) + offsetof(struct sysctldesc, descr_str) + \
1197 __sysc_desc_roundup(l)))
1198 #define NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
1199
1200 static __inline struct sysctlnode *
1201 sysctl_rootof(struct sysctlnode *n)
1202 {
1203 while (n->sysctl_parent != NULL)
1204 n = n->sysctl_parent;
1205 return (n);
1206 }
1207
1208 #endif /* !_SYS_SYSCTL_H_ */
Cache object: b2e786f17949dbb27f1030d1965c7009
|