FreeBSD/Linux Kernel Cross Reference
sys/sys/sysctl.h
1 /* $NetBSD: sysctl.h,v 1.165 2006/11/25 21:40:06 christos 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_UNUSED1 0x00000010 */
93 /* #define CTLFLAG_UNUSED2 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_SECURITY 13 /* security */
165 #define CTL_MAXID 14 /* number of valid top-level ids */
166
167 #define CTL_NAMES { \
168 { 0, 0 }, \
169 { "kern", CTLTYPE_NODE }, \
170 { "vm", CTLTYPE_NODE }, \
171 { "vfs", CTLTYPE_NODE }, \
172 { "net", CTLTYPE_NODE }, \
173 { "debug", CTLTYPE_NODE }, \
174 { "hw", CTLTYPE_NODE }, \
175 { "machdep", CTLTYPE_NODE }, \
176 { "user", CTLTYPE_NODE }, \
177 { "ddb", CTLTYPE_NODE }, \
178 { "proc", CTLTYPE_NODE }, \
179 { "vendor", CTLTYPE_NODE }, \
180 { "emul", CTLTYPE_NODE }, \
181 { "security", CTLTYPE_NODE }, \
182 }
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_BOOTTIME 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 suppoprt */
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 signalled 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 /* int: 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_MAXID 83 /* number of valid kern ids */
276
277
278 #define CTL_KERN_NAMES { \
279 { 0, 0 }, \
280 { "ostype", CTLTYPE_STRING }, \
281 { "osrelease", CTLTYPE_STRING }, \
282 { "osrevision", CTLTYPE_INT }, \
283 { "version", CTLTYPE_STRING }, \
284 { "maxvnodes", CTLTYPE_INT }, \
285 { "maxproc", CTLTYPE_INT }, \
286 { "maxfiles", CTLTYPE_INT }, \
287 { "argmax", CTLTYPE_INT }, \
288 { "securelevel", CTLTYPE_INT }, \
289 { "hostname", CTLTYPE_STRING }, \
290 { "hostid", CTLTYPE_INT }, \
291 { "clockrate", CTLTYPE_STRUCT }, \
292 { "vnode", CTLTYPE_STRUCT }, \
293 { "proc", CTLTYPE_STRUCT }, \
294 { "file", CTLTYPE_STRUCT }, \
295 { "profiling", CTLTYPE_NODE }, \
296 { "posix1version", CTLTYPE_INT }, \
297 { "ngroups", CTLTYPE_INT }, \
298 { "job_control", CTLTYPE_INT }, \
299 { "saved_ids", CTLTYPE_INT }, \
300 { "boottime", CTLTYPE_STRUCT }, \
301 { "domainname", CTLTYPE_STRING }, \
302 { "maxpartitions", CTLTYPE_INT }, \
303 { "rawpartition", CTLTYPE_INT }, \
304 { "ntptime", CTLTYPE_STRUCT }, \
305 { "timex", CTLTYPE_STRUCT }, \
306 { "autonicetime", CTLTYPE_INT }, \
307 { "autoniceval", CTLTYPE_INT }, \
308 { "rtc_offset", CTLTYPE_INT }, \
309 { "root_device", CTLTYPE_STRING }, \
310 { "msgbufsize", CTLTYPE_INT }, \
311 { "fsync", CTLTYPE_INT }, \
312 { 0, 0 }, \
313 { 0, 0 }, \
314 { 0, 0 }, \
315 { 0, 0 }, \
316 { "synchronized_io", CTLTYPE_INT }, \
317 { "iov_max", CTLTYPE_INT }, \
318 { "mbuf", CTLTYPE_NODE }, \
319 { "mapped_files", CTLTYPE_INT }, \
320 { "memlock", CTLTYPE_INT }, \
321 { "memlock_range", CTLTYPE_INT }, \
322 { "memory_protection", CTLTYPE_INT }, \
323 { "login_name_max", CTLTYPE_INT }, \
324 { "defcorename", CTLTYPE_STRING }, \
325 { "logsigexit", CTLTYPE_INT }, \
326 { "proc2", CTLTYPE_STRUCT }, \
327 { "proc_args", CTLTYPE_STRING }, \
328 { "fscale", CTLTYPE_INT }, \
329 { "ccpu", CTLTYPE_INT }, \
330 { "cp_time", CTLTYPE_STRUCT }, \
331 { 0, 0 }, \
332 { "msgbuf", CTLTYPE_STRUCT }, \
333 { "consdev", CTLTYPE_STRUCT }, \
334 { "maxptys", CTLTYPE_INT }, \
335 { "pipe", CTLTYPE_NODE }, \
336 { "maxphys", CTLTYPE_INT }, \
337 { "sbmax", CTLTYPE_INT }, \
338 { "tkstat", CTLTYPE_NODE }, \
339 { "monotonic_clock", CTLTYPE_INT }, \
340 { "urandom", CTLTYPE_INT }, \
341 { "labelsector", CTLTYPE_INT }, \
342 { "labeloffset", CTLTYPE_INT }, \
343 { "lwp", CTLTYPE_STRUCT }, \
344 { "forkfsleep", CTLTYPE_INT }, \
345 { "posix_threads", CTLTYPE_INT }, \
346 { "posix_semaphores", CTLTYPE_INT }, \
347 { "posix_barriers", CTLTYPE_INT }, \
348 { "posix_timers", CTLTYPE_INT }, \
349 { "posix_spin_locks", CTLTYPE_INT }, \
350 { "posix_reader_writer_locks", CTLTYPE_INT }, \
351 { "dump_on_panic", CTLTYPE_INT}, \
352 { "somaxkva", CTLTYPE_INT}, \
353 { "root_partition", CTLTYPE_INT}, \
354 { "drivers", CTLTYPE_STRUCT }, \
355 { "buf", CTLTYPE_NODE }, \
356 { "file2", CTLTYPE_STRUCT }, \
357 { "veriexec", CTLTYPE_NODE }, \
358 { "cp_id", CTLTYPE_STRUCT }, \
359 { "hardclock_ticks", CTLTYPE_INT }, \
360 { "arandom", CTLTYPE_STRUCT }, \
361 { "sysvipc", CTLTYPE_STRUCT }, \
362 }
363
364 /*
365 * KERN_CLOCKRATE structure
366 */
367 struct clockinfo {
368 int hz; /* clock frequency */
369 int tick; /* micro-seconds per hz tick */
370 int tickadj; /* clock skew rate for adjtime() */
371 int stathz; /* statistics clock frequency */
372 int profhz; /* profiling clock frequency */
373 };
374
375 /*
376 * KERN_PROC subtypes
377 */
378 #define KERN_PROC_ALL 0 /* everything */
379 #define KERN_PROC_PID 1 /* by process id */
380 #define KERN_PROC_PGRP 2 /* by process group id */
381 #define KERN_PROC_SESSION 3 /* by session of pid */
382 #define KERN_PROC_TTY 4 /* by controlling tty */
383 #define KERN_PROC_UID 5 /* by effective uid */
384 #define KERN_PROC_RUID 6 /* by real uid */
385 #define KERN_PROC_GID 7 /* by effective gid */
386 #define KERN_PROC_RGID 8 /* by real gid */
387
388 /*
389 * KERN_PROC_TTY sub-subtypes
390 */
391 #define KERN_PROC_TTY_NODEV NODEV /* no controlling tty */
392 #define KERN_PROC_TTY_REVOKE ((dev_t)-2) /* revoked tty */
393
394 /*
395 * KERN_PROC subtype ops return arrays of augmented proc structures:
396 */
397 struct kinfo_proc {
398 struct proc kp_proc; /* proc structure */
399 struct eproc {
400 struct proc *e_paddr; /* address of proc */
401 struct session *e_sess; /* session pointer */
402 struct pcred e_pcred; /* process credentials */
403 struct ucred e_ucred; /* current credentials */
404 struct vmspace e_vm; /* address space */
405 pid_t e_ppid; /* parent process id */
406 pid_t e_pgid; /* process group id */
407 short e_jobc; /* job control counter */
408 dev_t e_tdev; /* controlling tty dev */
409 pid_t e_tpgid; /* tty process group id */
410 struct session *e_tsess; /* tty session pointer */
411 #define WMESGLEN 8
412 char e_wmesg[WMESGLEN]; /* wchan message */
413 segsz_t e_xsize; /* text size */
414 short e_xrssize; /* text rss */
415 short e_xccount; /* text references */
416 short e_xswrss;
417 long e_flag;
418 #define EPROC_CTTY 0x01 /* controlling tty vnode active */
419 #define EPROC_SLEADER 0x02 /* session leader */
420 char e_login[MAXLOGNAME]; /* setlogin() name */
421 pid_t e_sid; /* session id */
422 long e_spare[3];
423 } kp_eproc;
424 };
425
426 /*
427 * Convert pointer to 64 bit unsigned integer for struct
428 * kinfo_proc2, etc.
429 */
430 #define PTRTOUINT64(p) ((uint64_t)(uintptr_t)(p))
431 #define UINT64TOPTR(u) ((void *)(uintptr_t)(u))
432
433 /*
434 * KERN_PROC2 subtype ops return arrays of relatively fixed size
435 * structures of process info. Use 8 byte alignment, and new
436 * elements should only be added to the end of this structure so
437 * binary compatibility can be preserved.
438 */
439 #define KI_NGROUPS 16
440 #define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */
441 #define KI_WMESGLEN 8
442 #define KI_MAXLOGNAME 24 /* extra for 8 byte alignment */
443 #define KI_MAXEMULLEN 16
444
445 #define KI_NOCPU (~(uint64_t)0)
446
447 typedef struct {
448 uint32_t __bits[4];
449 } ki_sigset_t;
450
451 struct kinfo_proc2 {
452 uint64_t p_forw; /* PTR: linked run/sleep queue. */
453 uint64_t p_back;
454 uint64_t p_paddr; /* PTR: address of proc */
455
456 uint64_t p_addr; /* PTR: Kernel virtual addr of u-area */
457 uint64_t p_fd; /* PTR: Ptr to open files structure. */
458 uint64_t p_cwdi; /* PTR: cdir/rdir/cmask info */
459 uint64_t p_stats; /* PTR: Accounting/statistics */
460 uint64_t p_limit; /* PTR: Process limits. */
461 uint64_t p_vmspace; /* PTR: Address space. */
462 uint64_t p_sigacts; /* PTR: Signal actions, state */
463 uint64_t p_sess; /* PTR: session pointer */
464 uint64_t p_tsess; /* PTR: tty session pointer */
465 uint64_t p_ru; /* PTR: Exit information. XXX */
466
467 int32_t p_eflag; /* LONG: extra kinfo_proc2 flags */
468 int32_t p_exitsig; /* INT: signal to sent to parent on exit */
469 int32_t p_flag; /* INT: P_* flags. */
470
471 int32_t p_pid; /* PID_T: Process identifier. */
472 int32_t p_ppid; /* PID_T: Parent process id */
473 int32_t p_sid; /* PID_T: session id */
474 int32_t p__pgid; /* PID_T: process group id */
475 /* XXX: <sys/proc.h> hijacks p_pgid */
476 int32_t p_tpgid; /* PID_T: tty process group id */
477
478 uint32_t p_uid; /* UID_T: effective user id */
479 uint32_t p_ruid; /* UID_T: real user id */
480 uint32_t p_gid; /* GID_T: effective group id */
481 uint32_t p_rgid; /* GID_T: real group id */
482
483 uint32_t p_groups[KI_NGROUPS]; /* GID_T: groups */
484 int16_t p_ngroups; /* SHORT: number of groups */
485
486 int16_t p_jobc; /* SHORT: job control counter */
487 uint32_t p_tdev; /* DEV_T: controlling tty dev */
488
489 uint32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */
490 uint32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */
491 uint32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */
492 int32_t p_cpticks; /* INT: Ticks of CPU time. */
493 uint32_t p_pctcpu; /* FIXPT_T: %cpu for this process during p_swtime */
494 uint32_t p_swtime; /* U_INT: Time swapped in or out. */
495 uint32_t p_slptime; /* U_INT: Time since last blocked. */
496 int32_t p_schedflags; /* INT: PSCHED_* flags */
497
498 uint64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */
499 uint64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */
500 uint64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */
501
502 uint64_t p_tracep; /* PTR: Trace to vnode or file */
503 int32_t p_traceflag; /* INT: Kernel trace points. */
504
505 int32_t p_holdcnt; /* INT: If non-zero, don't swap. */
506
507 ki_sigset_t p_siglist; /* SIGSET_T: Signals arrived but not delivered. */
508 ki_sigset_t p_sigmask; /* SIGSET_T: Current signal mask. */
509 ki_sigset_t p_sigignore; /* SIGSET_T: Signals being ignored. */
510 ki_sigset_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */
511
512 int8_t p_stat; /* CHAR: S* process status (from LWP). */
513 uint8_t p_priority; /* U_CHAR: Process priority. */
514 uint8_t p_usrpri; /* U_CHAR: User-priority based on p_cpu and p_nice. */
515 uint8_t p_nice; /* U_CHAR: Process "nice" value. */
516
517 uint16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */
518 uint16_t p_acflag; /* U_SHORT: Accounting flags. */
519
520 char p_comm[KI_MAXCOMLEN];
521
522 char p_wmesg[KI_WMESGLEN]; /* wchan message */
523 uint64_t p_wchan; /* PTR: sleep address. */
524
525 char p_login[KI_MAXLOGNAME]; /* setlogin() name */
526
527 int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */
528 int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */
529 int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */
530 int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */
531
532 int64_t p_uvalid; /* CHAR: following p_u* members from struct user are valid */
533 /* XXX 64 bits for alignment */
534 uint32_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */
535 uint32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */
536
537 uint32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */
538 uint32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */
539 uint32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */
540 uint32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */
541
542 uint64_t p_uru_maxrss; /* LONG: max resident set size. */
543 uint64_t p_uru_ixrss; /* LONG: integral shared memory size. */
544 uint64_t p_uru_idrss; /* LONG: integral unshared data ". */
545 uint64_t p_uru_isrss; /* LONG: integral unshared stack ". */
546 uint64_t p_uru_minflt; /* LONG: page reclaims. */
547 uint64_t p_uru_majflt; /* LONG: page faults. */
548 uint64_t p_uru_nswap; /* LONG: swaps. */
549 uint64_t p_uru_inblock; /* LONG: block input operations. */
550 uint64_t p_uru_oublock; /* LONG: block output operations. */
551 uint64_t p_uru_msgsnd; /* LONG: messages sent. */
552 uint64_t p_uru_msgrcv; /* LONG: messages received. */
553 uint64_t p_uru_nsignals; /* LONG: signals received. */
554 uint64_t p_uru_nvcsw; /* LONG: voluntary context switches. */
555 uint64_t p_uru_nivcsw; /* LONG: involuntary ". */
556
557 uint32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */
558 uint32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */
559 uint64_t p_cpuid; /* LONG: CPU id */
560 uint64_t p_realflag; /* INT: P_* flags (not including LWPs). */
561 uint64_t p_nlwps; /* LONG: Number of LWPs */
562 uint64_t p_nrlwps; /* LONG: Number of running LWPs */
563 uint64_t p_realstat; /* LONG: non-LWP process status */
564 uint32_t p_svuid; /* UID_T: saved user id */
565 uint32_t p_svgid; /* GID_T: saved group id */
566 char p_ename[KI_MAXEMULLEN]; /* emulation name */
567 };
568
569 /*
570 * KERN_LWP structure. See notes on KERN_PROC2 about adding elements.
571 */
572 struct kinfo_lwp {
573 uint64_t l_forw; /* PTR: linked run/sleep queue. */
574 uint64_t l_back;
575 uint64_t l_laddr; /* PTR: Address of LWP */
576 uint64_t l_addr; /* PTR: Kernel virtual addr of u-area */
577 int32_t l_lid; /* LWPID_T: LWP identifier */
578 int32_t l_flag; /* INT: L_* flags. */
579 uint32_t l_swtime; /* U_INT: Time swapped in or out. */
580 uint32_t l_slptime; /* U_INT: Time since last blocked. */
581 int32_t l_schedflags; /* INT: PSCHED_* flags */
582 int32_t l_holdcnt; /* INT: If non-zero, don't swap. */
583 uint8_t l_priority; /* U_CHAR: Process priority. */
584 uint8_t l_usrpri; /* U_CHAR: User-priority based on l_cpu and p_nice. */
585 int8_t l_stat; /* CHAR: S* process status. */
586 int8_t l_pad1; /* fill out to 4-byte boundary */
587 int32_t l_pad2; /* .. and then to an 8-byte boundary */
588 char l_wmesg[KI_WMESGLEN]; /* wchan message */
589 uint64_t l_wchan; /* PTR: sleep address. */
590 uint64_t l_cpuid; /* LONG: CPU id */
591 };
592
593 /*
594 * KERN_PROC_ARGS subtypes
595 */
596 #define KERN_PROC_ARGV 1 /* argv */
597 #define KERN_PROC_NARGV 2 /* number of strings in above */
598 #define KERN_PROC_ENV 3 /* environ */
599 #define KERN_PROC_NENV 4 /* number of strings in above */
600
601 /*
602 * KERN_SYSVIPC subtypes
603 */
604 #define KERN_SYSVIPC_INFO 1 /* struct: number of valid kern ids */
605 #define KERN_SYSVIPC_MSG 2 /* int: SysV message queue suppoprt */
606 #define KERN_SYSVIPC_SEM 3 /* int: SysV semaphore support */
607 #define KERN_SYSVIPC_SHM 4 /* int: SysV shared memory support */
608 #define KERN_SYSVIPC_SHMMAX 5 /* int: max shared memory segment size (bytes) */
609 #define KERN_SYSVIPC_SHMMNI 6 /* int: max number of shared memory identifiers */
610 #define KERN_SYSVIPC_SHMSEG 7 /* int: max shared memory segments per process */
611 #define KERN_SYSVIPC_SHMMAXPGS 8 /* int: max amount of shared memory (pages) */
612 #define KERN_SYSVIPC_SHMUSEPHYS 9 /* int: physical memory usage */
613
614 /*
615 * KERN_SYSVIPC_INFO subtypes
616 */
617 #define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */
618 #define KERN_SYSVIPC_SEM_INFO 2 /* seminfo and semid_ds */
619 #define KERN_SYSVIPC_SHM_INFO 3 /* shminfo and shmid_ds */
620
621 /*
622 * tty counter sysctl variables
623 */
624 #define KERN_TKSTAT_NIN 1 /* total input character */
625 #define KERN_TKSTAT_NOUT 2 /* total output character */
626 #define KERN_TKSTAT_CANCC 3 /* canonical input character */
627 #define KERN_TKSTAT_RAWCC 4 /* raw input character */
628 #define KERN_TKSTAT_MAXID 5 /* number of valid TKSTAT ids */
629
630 #define KERN_TKSTAT_NAMES { \
631 { 0, 0 }, \
632 { "nin", CTLTYPE_QUAD }, \
633 { "nout", CTLTYPE_QUAD }, \
634 { "cancc", CTLTYPE_QUAD }, \
635 { "rawcc", CTLTYPE_QUAD }, \
636 }
637
638 /*
639 * kern.drivers returns an array of these.
640 */
641
642 struct kinfo_drivers {
643 int32_t d_cmajor;
644 int32_t d_bmajor;
645 char d_name[24];
646 };
647
648 /*
649 * KERN_BUF subtypes, like KERN_PROC2, where the four following mib
650 * entries specify "which type of buf", "which particular buf",
651 * "sizeof buf", and "how many". Currently, only "all buf" is
652 * defined.
653 */
654 #define KERN_BUF_ALL 0 /* all buffers */
655
656 /*
657 * kern.buf returns an array of these structures, which are designed
658 * both to be immune to 32/64 bit emulation issues and to provide
659 * backwards compatibility. Note that the order here differs slightly
660 * from the real struct buf in order to achieve proper 64 bit
661 * alignment.
662 */
663 struct buf_sysctl {
664 uint32_t b_flags; /* LONG: B_* flags */
665 int32_t b_error; /* INT: Errno value */
666 int32_t b_prio; /* INT: Hint for buffer queue discipline */
667 uint32_t b_dev; /* DEV_T: Device associated with buffer */
668 uint64_t b_bufsize; /* LONG: Allocated buffer size */
669 uint64_t b_bcount; /* LONG: Valid bytes in buffer */
670 uint64_t b_resid; /* LONG: Remaining I/O */
671 uint64_t b_addr; /* CADDR_T: Memory, superblocks, indirect... */
672 uint64_t b_blkno; /* DADDR_T: Underlying physical block number */
673 uint64_t b_rawblkno; /* DADDR_T: Raw underlying physical block */
674 uint64_t b_iodone; /* PTR: Function called upon completion */
675 uint64_t b_proc; /* PTR: Associated proc if B_PHYS set */
676 uint64_t b_vp; /* PTR: File vnode */
677 uint64_t b_saveaddr; /* PTR: Original b_addr for physio */
678 uint64_t b_lblkno; /* DADDR_T: Logical block number */
679 };
680
681 /*
682 * kern.file2 returns an array of these structures, which are designed
683 * both to be immune to be immune to 32/64 bit emulation issues and to
684 * provide backwards compatibility. The order differs slightly from
685 * that of the real struct file, and some fields are taken from other
686 * structures (struct vnode, struct proc) in order to make the file
687 * information more useful.
688 */
689 struct kinfo_file {
690 uint64_t ki_fileaddr; /* PTR: address of struct file */
691 uint32_t ki_flag; /* INT: flags (see fcntl.h) */
692 uint32_t ki_iflags; /* INT: internal flags */
693 uint32_t ki_ftype; /* INT: descriptor type */
694 uint32_t ki_count; /* UINT: reference count */
695 uint32_t ki_msgcount; /* UINT: references from msg queue */
696 uint32_t ki_usecount; /* INT: number active users */
697 uint64_t ki_fucred; /* PTR: creds for descriptor */
698 uint32_t ki_fuid; /* UID_T: descriptor credentials */
699 uint32_t ki_fgid; /* GID_T: descriptor credentials */
700 uint64_t ki_fops; /* PTR: address of fileops */
701 uint64_t ki_foffset; /* OFF_T: offset */
702 uint64_t ki_fdata; /* PTR: descriptor data */
703
704 /* vnode information to glue this file to something */
705 uint64_t ki_vun; /* PTR: socket, specinfo, etc */
706 uint64_t ki_vsize; /* OFF_T: size of file */
707 uint32_t ki_vtype; /* ENUM: vnode type */
708 uint32_t ki_vtag; /* ENUM: type of underlying data */
709 uint64_t ki_vdata; /* PTR: private data for fs */
710
711 /* process information when retrieved via KERN_FILE_BYPID */
712 uint32_t ki_pid; /* PID_T: process id */
713 int32_t ki_fd; /* INT: descriptor number */
714 uint32_t ki_ofileflags; /* CHAR: open file flags */
715 uint32_t _ki_padto64bits;
716 };
717
718 #define KERN_FILE_BYFILE 1
719 #define KERN_FILE_BYPID 2
720 #define KERN_FILESLOP 10
721
722 /*
723 * CTL_HW identifiers
724 */
725 #define HW_MACHINE 1 /* string: machine class */
726 #define HW_MODEL 2 /* string: specific machine model */
727 #define HW_NCPU 3 /* int: number of cpus */
728 #define HW_BYTEORDER 4 /* int: machine byte order */
729 #define HW_PHYSMEM 5 /* int: total memory (bytes) */
730 #define HW_USERMEM 6 /* int: non-kernel memory (bytes) */
731 #define HW_PAGESIZE 7 /* int: software page size */
732 #define HW_DISKNAMES 8 /* string: disk drive names */
733 #define HW_IOSTATS 9 /* struct: iostats[] */
734 #define HW_MACHINE_ARCH 10 /* string: machine architecture */
735 #define HW_ALIGNBYTES 11 /* int: ALIGNBYTES for the kernel */
736 #define HW_CNMAGIC 12 /* string: console magic sequence(s) */
737 #define HW_PHYSMEM64 13 /* quad: total memory (bytes) */
738 #define HW_USERMEM64 14 /* quad: non-kernel memory (bytes) */
739 #define HW_IOSTATNAMES 15 /* string: iostat names */
740 #define HW_MAXID 15 /* number of valid hw ids */
741
742 #define CTL_HW_NAMES { \
743 { 0, 0 }, \
744 { "machine", CTLTYPE_STRING }, \
745 { "model", CTLTYPE_STRING }, \
746 { "ncpu", CTLTYPE_INT }, \
747 { "byteorder", CTLTYPE_INT }, \
748 { "physmem", CTLTYPE_INT }, \
749 { "usermem", CTLTYPE_INT }, \
750 { "pagesize", CTLTYPE_INT }, \
751 { "drivenames", CTLTYPE_STRING }, \
752 { "drivestats", CTLTYPE_STRUCT }, \
753 { "machine_arch", CTLTYPE_STRING }, \
754 { "alignbytes", CTLTYPE_INT }, \
755 { "cnmagic", CTLTYPE_STRING }, \
756 { "physmem64", CTLTYPE_QUAD }, \
757 { "usermem64", CTLTYPE_QUAD }, \
758 }
759
760 /*
761 * CTL_USER definitions
762 */
763 #define USER_CS_PATH 1 /* string: _CS_PATH */
764 #define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
765 #define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
766 #define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
767 #define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
768 #define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
769 #define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
770 #define USER_LINE_MAX 8 /* int: LINE_MAX */
771 #define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
772 #define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
773 #define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
774 #define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
775 #define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
776 #define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
777 #define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
778 #define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
779 #define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
780 #define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
781 #define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
782 #define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
783 #define USER_ATEXIT_MAX 21 /* int: {ATEXIT_MAX} */
784 #define USER_MAXID 22 /* number of valid user ids */
785
786 #define CTL_USER_NAMES { \
787 { 0, 0 }, \
788 { "cs_path", CTLTYPE_STRING }, \
789 { "bc_base_max", CTLTYPE_INT }, \
790 { "bc_dim_max", CTLTYPE_INT }, \
791 { "bc_scale_max", CTLTYPE_INT }, \
792 { "bc_string_max", CTLTYPE_INT }, \
793 { "coll_weights_max", CTLTYPE_INT }, \
794 { "expr_nest_max", CTLTYPE_INT }, \
795 { "line_max", CTLTYPE_INT }, \
796 { "re_dup_max", CTLTYPE_INT }, \
797 { "posix2_version", CTLTYPE_INT }, \
798 { "posix2_c_bind", CTLTYPE_INT }, \
799 { "posix2_c_dev", CTLTYPE_INT }, \
800 { "posix2_char_term", CTLTYPE_INT }, \
801 { "posix2_fort_dev", CTLTYPE_INT }, \
802 { "posix2_fort_run", CTLTYPE_INT }, \
803 { "posix2_localedef", CTLTYPE_INT }, \
804 { "posix2_sw_dev", CTLTYPE_INT }, \
805 { "posix2_upe", CTLTYPE_INT }, \
806 { "stream_max", CTLTYPE_INT }, \
807 { "tzname_max", CTLTYPE_INT }, \
808 { "atexit_max", CTLTYPE_INT }, \
809 }
810
811 /*
812 * CTL_DDB definitions
813 */
814 #define DDBCTL_RADIX 1 /* int: Input and output radix */
815 #define DDBCTL_MAXOFF 2 /* int: max symbol offset */
816 #define DDBCTL_MAXWIDTH 3 /* int: width of the display line */
817 #define DDBCTL_LINES 4 /* int: number of display lines */
818 #define DDBCTL_TABSTOPS 5 /* int: tab width */
819 #define DDBCTL_ONPANIC 6 /* int: DDB on panic if non-zero */
820 #define DDBCTL_FROMCONSOLE 7 /* int: DDB via console if non-zero */
821 #define DDBCTL_MAXID 8 /* number of valid DDB ids */
822
823 #define CTL_DDB_NAMES { \
824 { 0, 0 }, \
825 { "radix", CTLTYPE_INT }, \
826 { "maxoff", CTLTYPE_INT }, \
827 { "maxwidth", CTLTYPE_INT }, \
828 { "lines", CTLTYPE_INT }, \
829 { "tabstops", CTLTYPE_INT }, \
830 { "onpanic", CTLTYPE_INT }, \
831 { "fromconsole", CTLTYPE_INT }, \
832 }
833
834 /*
835 * CTL_DEBUG definitions
836 *
837 * Second level identifier specifies which debug variable.
838 * Third level identifier specifies which structure component.
839 */
840 #define CTL_DEBUG_NAME 0 /* string: variable name */
841 #define CTL_DEBUG_VALUE 1 /* int: variable value */
842 #define CTL_DEBUG_MAXID 20
843
844 /*
845 * CTL_PROC subtype. Either a PID, or a magic value for the current proc.
846 */
847
848 #define PROC_CURPROC (~((u_int)1 << 31))
849
850 /*
851 * CTL_PROC tree: either corename (string), or a limit
852 * (rlimit.<type>.{hard,soft}, int).
853 */
854 #define PROC_PID_CORENAME 1
855 #define PROC_PID_LIMIT 2
856 #define PROC_PID_STOPFORK 3
857 #define PROC_PID_STOPEXEC 4
858 #define PROC_PID_STOPEXIT 5
859 #define PROC_PID_MAXID 6
860
861 #define PROC_PID_NAMES { \
862 { 0, 0 }, \
863 { "corename", CTLTYPE_STRING }, \
864 { "rlimit", CTLTYPE_NODE }, \
865 { "stopfork", CTLTYPE_INT }, \
866 { "stopexec", CTLTYPE_INT }, \
867 { "stopexit", CTLTYPE_INT }, \
868 }
869
870 /* Limit types from <sys/resources.h> */
871 #define PROC_PID_LIMIT_CPU (RLIMIT_CPU+1)
872 #define PROC_PID_LIMIT_FSIZE (RLIMIT_FSIZE+1)
873 #define PROC_PID_LIMIT_DATA (RLIMIT_DATA+1)
874 #define PROC_PID_LIMIT_STACK (RLIMIT_STACK+1)
875 #define PROC_PID_LIMIT_CORE (RLIMIT_CORE+1)
876 #define PROC_PID_LIMIT_RSS (RLIMIT_RSS+1)
877 #define PROC_PID_LIMIT_MEMLOCK (RLIMIT_MEMLOCK+1)
878 #define PROC_PID_LIMIT_NPROC (RLIMIT_NPROC+1)
879 #define PROC_PID_LIMIT_NOFILE (RLIMIT_NOFILE+1)
880 #define PROC_PID_LIMIT_SBSIZE (RLIMIT_SBSIZE+1)
881 #define PROC_PID_LIMIT_MAXID (RLIM_NLIMITS+1)
882
883 #define PROC_PID_LIMIT_NAMES { \
884 { 0, 0 }, \
885 { "cputime", CTLTYPE_NODE }, \
886 { "filesize", CTLTYPE_NODE }, \
887 { "datasize", CTLTYPE_NODE }, \
888 { "stacksize", CTLTYPE_NODE }, \
889 { "coredumpsize", CTLTYPE_NODE }, \
890 { "memoryuse", CTLTYPE_NODE }, \
891 { "memorylocked", CTLTYPE_NODE }, \
892 { "maxproc", CTLTYPE_NODE }, \
893 { "descriptors", CTLTYPE_NODE }, \
894 { "sbsize", CTLTYPE_NODE }, \
895 }
896 /* for each type, either hard or soft value */
897 #define PROC_PID_LIMIT_TYPE_SOFT 1
898 #define PROC_PID_LIMIT_TYPE_HARD 2
899 #define PROC_PID_LIMIT_TYPE_MAXID 3
900
901 #define PROC_PID_LIMIT_TYPE_NAMES { \
902 {0, 0}, \
903 { "soft", CTLTYPE_QUAD }, \
904 { "hard", CTLTYPE_QUAD }, \
905 }
906
907 /*
908 * CTL_EMUL definitions
909 *
910 * Second level identifier specifies which emulation variable.
911 * Subsequent levels are specified in the emulations themselves.
912 */
913 #define EMUL_LINUX 1
914 #define EMUL_IRIX 2
915 #define EMUL_DARWIN 3
916 #define EMUL_MACH 4
917 #define EMUL_LINUX32 5
918
919 #define EMUL_MAXID 6
920 #define CTL_EMUL_NAMES { \
921 { 0, 0 }, \
922 { "linux", CTLTYPE_NODE }, \
923 { "irix", CTLTYPE_NODE }, \
924 { "darwin", CTLTYPE_NODE }, \
925 { "mach", CTLTYPE_NODE }, \
926 { "linux32", CTLTYPE_NODE }, \
927 }
928
929 #ifdef _KERNEL
930
931 #if defined(_KERNEL_OPT)
932 #include "opt_sysctl.h"
933 #endif
934
935 /* Root node of the kernel sysctl tree */
936 extern struct sysctlnode sysctl_root;
937
938 /*
939 * A log of nodes created by a setup function or set of setup
940 * functions so that they can be torn down in one "transaction"
941 * when no longer needed.
942 *
943 * Users of the log merely pass a pointer to a pointer, and the sysctl
944 * infrastructure takes care of the rest.
945 */
946 struct sysctllog;
947
948 /*
949 * CTL_DEBUG variables.
950 *
951 * These are declared as separate variables so that they can be
952 * individually initialized at the location of their associated
953 * variable. The loader prevents multiple use by issuing errors
954 * if a variable is initialized in more than one place. They are
955 * aggregated into an array in debug_sysctl(), so that it can
956 * conveniently locate them when querried. If more debugging
957 * variables are added, they must also be declared here and also
958 * entered into the array.
959 *
960 * Note that the debug subtree is largely obsolescent in terms of
961 * functionality now that we have dynamic sysctl, but the
962 * infrastructure is retained for backwards compatibility.
963 */
964 struct ctldebug {
965 const char *debugname; /* name of debugging variable */
966 int *debugvar; /* pointer to debugging variable */
967 };
968 #ifdef DEBUG
969 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
970 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
971 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
972 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
973 #endif /* DEBUG */
974
975 #define SYSCTLFN_PROTO const int *, u_int, void *, \
976 size_t *, const void *, size_t, \
977 const int *, struct lwp *, const struct sysctlnode *
978 #define SYSCTLFN_ARGS const int *name, u_int namelen, \
979 void *oldp, size_t *oldlenp, \
980 const void *newp, size_t newlen, \
981 const int *oname, struct lwp *l, \
982 const struct sysctlnode *rnode
983 #define SYSCTLFN_CALL(node) name, namelen, oldp, \
984 oldlenp, newp, newlen, \
985 oname, l, node
986
987 #ifdef _LKM
988
989 #define SYSCTL_SETUP_PROTO(name) \
990 void name(struct sysctllog **)
991 #ifdef SYSCTL_DEBUG_SETUP
992 #define SYSCTL_SETUP(name, desc) \
993 static void __CONCAT(___,name)(struct sysctllog **); \
994 void name(struct sysctllog **clog) { \
995 printf("%s\n", desc); \
996 __CONCAT(___,name)(clog); } \
997 __link_set_add_text(sysctl_funcs, name); \
998 static void __CONCAT(___,name)(struct sysctllog **clog)
999 #else /* !SYSCTL_DEBUG_SETUP */
1000 #define SYSCTL_SETUP(name, desc) \
1001 __link_set_add_text(sysctl_funcs, name); \
1002 void name(struct sysctllog **clog)
1003 #endif /* !SYSCTL_DEBUG_SETUP */
1004
1005 #else /* !_LKM */
1006
1007 #define SYSCTL_SETUP_PROTO(name)
1008 #ifdef SYSCTL_DEBUG_SETUP
1009 #define SYSCTL_SETUP(name, desc) \
1010 static void __CONCAT(___,name)(struct sysctllog **); \
1011 static void name(struct sysctllog **clog) { \
1012 printf("%s\n", desc); \
1013 __CONCAT(___,name)(clog); } \
1014 __link_set_add_text(sysctl_funcs, name); \
1015 static void __CONCAT(___,name)(struct sysctllog **clog)
1016 #else /* !SYSCTL_DEBUG_SETUP */
1017 #define SYSCTL_SETUP(name, desc) \
1018 static void name(struct sysctllog **); \
1019 __link_set_add_text(sysctl_funcs, name); \
1020 static void name(struct sysctllog **clog)
1021 #endif /* !SYSCTL_DEBUG_SETUP */
1022 typedef void (*sysctl_setup_func)(struct sysctllog **);
1023
1024 #endif /* !_LKM */
1025
1026 /*
1027 * Internal sysctl function calling convention:
1028 *
1029 * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen,
1030 * origname, lwp, node);
1031 *
1032 * The name parameter points at the next component of the name to be
1033 * interpreted. The namelen parameter is the number of integers in
1034 * the name. The origname parameter points to the start of the name
1035 * being parsed. The node parameter points to the node on which the
1036 * current operation is to be performed.
1037 */
1038 typedef int (*sysctlfn)(SYSCTLFN_PROTO);
1039
1040 /*
1041 * used in more than just sysctl
1042 */
1043 void fill_eproc(struct proc *, struct eproc *);
1044
1045 /*
1046 * subsystem setup
1047 */
1048 void sysctl_init(void);
1049
1050 /*
1051 * typical syscall call order
1052 */
1053 int sysctl_lock(struct lwp *, void *, size_t);
1054 int sysctl_dispatch(SYSCTLFN_PROTO);
1055 void sysctl_unlock(struct lwp *);
1056
1057 /*
1058 * tree navigation primitives (must obtain lock before using these)
1059 */
1060 int sysctl_locate(struct lwp *, const int *, u_int,
1061 const struct sysctlnode **, int *);
1062 int sysctl_query(SYSCTLFN_PROTO);
1063 int sysctl_create(SYSCTLFN_PROTO);
1064 int sysctl_destroy(SYSCTLFN_PROTO);
1065 int sysctl_lookup(SYSCTLFN_PROTO);
1066 int sysctl_describe(SYSCTLFN_PROTO);
1067
1068 /*
1069 * simple variadic interface for adding/removing nodes
1070 */
1071 int sysctl_createv(struct sysctllog **, int,
1072 const struct sysctlnode **, const struct sysctlnode **,
1073 int, int, const char *, const char *,
1074 sysctlfn, u_quad_t, void *, size_t, ...);
1075 int sysctl_destroyv(struct sysctlnode *, ...);
1076
1077 /*
1078 * miscellany
1079 */
1080 void sysctl_dump(const struct sysctlnode *);
1081 void sysctl_free(struct sysctlnode *);
1082 void sysctl_teardown(struct sysctllog **);
1083
1084 #ifdef SYSCTL_INCLUDE_DESCR
1085 #define SYSCTL_DESCR(s) s
1086 #else /* SYSCTL_INCLUDE_DESCR */
1087 #define SYSCTL_DESCR(s) NULL
1088 #endif /* SYSCTL_INCLUDE_DESCR */
1089
1090 /*
1091 * simple interface similar to old interface for in-kernel consumption
1092 */
1093 int old_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct lwp *);
1094
1095 /*
1096 * these helpers are in other files (XXX so should the nodes be) or
1097 * are used by more than one node
1098 */
1099 int sysctl_hw_tapenames(SYSCTLFN_PROTO);
1100 int sysctl_hw_tapestats(SYSCTLFN_PROTO);
1101 int sysctl_kern_vnode(SYSCTLFN_PROTO);
1102 int sysctl_net_inet_ip_ports(SYSCTLFN_PROTO);
1103 int sysctl_consdev(SYSCTLFN_PROTO);
1104 int sysctl_root_device(SYSCTLFN_PROTO);
1105
1106 /*
1107 * primitive helper stubs
1108 */
1109 int sysctl_needfunc(SYSCTLFN_PROTO);
1110 int sysctl_notavail(SYSCTLFN_PROTO);
1111 int sysctl_null(SYSCTLFN_PROTO);
1112
1113 MALLOC_DECLARE(M_SYSCTLNODE);
1114 MALLOC_DECLARE(M_SYSCTLDATA);
1115
1116 #else /* !_KERNEL */
1117 #include <sys/cdefs.h>
1118
1119 typedef void *sysctlfn;
1120
1121 __BEGIN_DECLS
1122 int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1123 int sysctlbyname(const char *, void *, size_t *, void *, size_t);
1124 int sysctlgetmibinfo(const char *, int *, u_int *,
1125 char *, size_t *, struct sysctlnode **, int);
1126 int sysctlnametomib(const char *, int *, size_t *);
1127 __END_DECLS
1128
1129 #endif /* !_KERNEL */
1130
1131 #ifdef __COMPAT_SYSCTL
1132 /*
1133 * old node definitions go here
1134 */
1135 #endif /* __COMPAT_SYSCTL */
1136
1137 /*
1138 * padding makes alignment magically "work" for 32/64 compatibility at
1139 * the expense of making things bigger on 32 bit platforms.
1140 */
1141 #if defined(_LP64) || (BYTE_ORDER == LITTLE_ENDIAN)
1142 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1143 struct { type __sysc_sdatum; } __sysc_ustr; }
1144 #else
1145 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
1146 struct { uint32_t __sysc_spad; type __sysc_sdatum; } __sysc_ustr; }
1147 #endif
1148 #define __sysc_unpad(x) x.__sysc_ustr.__sysc_sdatum
1149
1150 /*
1151 * The following is for gcc2, which doesn't handle __sysc_unpad().
1152 * The code gets a little less ugly this way.
1153 */
1154 #define sysc_init_field(field, value) \
1155 .field = { .__sysc_ustr = { .__sysc_sdatum = (value), }, }
1156
1157 struct sysctlnode {
1158 uint32_t sysctl_flags; /* flags and type */
1159 int32_t sysctl_num; /* mib number */
1160 char sysctl_name[SYSCTL_NAMELEN]; /* node name */
1161 uint32_t sysctl_ver; /* node's version vs. rest of tree */
1162 uint32_t __rsvd;
1163 union {
1164 struct {
1165 uint32_t suc_csize; /* size of child node array */
1166 uint32_t suc_clen; /* number of valid children */
1167 __sysc_pad(struct sysctlnode*) _suc_child; /* array of child nodes */
1168 } scu_child;
1169 struct {
1170 __sysc_pad(void*) _sud_data; /* pointer to external data */
1171 __sysc_pad(size_t) _sud_offset; /* offset to data */
1172 } scu_data;
1173 int32_t scu_alias; /* node this node refers to */
1174 int32_t scu_idata; /* immediate "int" data */
1175 u_quad_t scu_qdata; /* immediate "u_quad_t" data */
1176 } sysctl_un;
1177 __sysc_pad(size_t) _sysctl_size; /* size of instrumented data */
1178 __sysc_pad(sysctlfn) _sysctl_func; /* access helper function */
1179 __sysc_pad(struct sysctlnode*) _sysctl_parent; /* parent of this node */
1180 __sysc_pad(const char *) _sysctl_desc; /* description of node */
1181 };
1182
1183 /*
1184 * padded data
1185 */
1186 #define suc_child __sysc_unpad(_suc_child)
1187 #define sud_data __sysc_unpad(_sud_data)
1188 #define sud_offset __sysc_unpad(_sud_offset)
1189 #define sysctl_size __sysc_unpad(_sysctl_size)
1190 #define sysctl_func __sysc_unpad(_sysctl_func)
1191 #define sysctl_parent __sysc_unpad(_sysctl_parent)
1192 #define sysctl_desc __sysc_unpad(_sysctl_desc)
1193
1194 /*
1195 * nested data (may also be padded)
1196 */
1197 #define sysctl_csize sysctl_un.scu_child.suc_csize
1198 #define sysctl_clen sysctl_un.scu_child.suc_clen
1199 #define sysctl_child sysctl_un.scu_child.suc_child
1200 #define sysctl_data sysctl_un.scu_data.sud_data
1201 #define sysctl_offset sysctl_un.scu_data.sud_offset
1202 #define sysctl_alias sysctl_un.scu_alias
1203 #define sysctl_idata sysctl_un.scu_idata
1204 #define sysctl_qdata sysctl_un.scu_qdata
1205
1206 /*
1207 * when requesting a description of a node (a set of nodes, actually),
1208 * you get back an "array" of these, where the actual length of the
1209 * descr_str is noted in descr_len (which includes the trailing nul
1210 * byte), rounded up to the nearest four (sizeof(int32_t) actually).
1211 *
1212 * NEXT_DESCR() will take a pointer to a description and advance it to
1213 * the next description.
1214 */
1215 struct sysctldesc {
1216 int32_t descr_num; /* mib number of node */
1217 uint32_t descr_ver; /* version of node */
1218 uint32_t descr_len; /* length of description string */
1219 char descr_str[1]; /* not really 1...see above */
1220 };
1221
1222 #define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
1223 #define __sysc_desc_adv(d, l) \
1224 (/*XXXUNCONST ptr cast*/(struct sysctldesc *) \
1225 __UNCONST(((const char*)(d)) + offsetof(struct sysctldesc, descr_str) +\
1226 __sysc_desc_roundup(l)))
1227 #define NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
1228
1229 static __inline const struct sysctlnode *
1230 sysctl_rootof(const struct sysctlnode *n)
1231 {
1232 while (n->sysctl_parent != NULL)
1233 n = n->sysctl_parent;
1234 return (n);
1235 }
1236
1237 #endif /* !_SYS_SYSCTL_H_ */
Cache object: 1acdbe47898cbbd5e089e176a2a6efe3
|