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