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