]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sysctl.h
8af90d6ed9a7e835f3954fa1fa334a45714e501b
[apple/xnu.git] / bsd / sys / sysctl.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1989, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * This code is derived from software contributed to Berkeley by
31 * Mike Karels at Berkeley Software Design, Inc.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)sysctl.h 8.1 (Berkeley) 6/2/93
62 */
63
64 #ifndef _SYS_SYSCTL_H_
65 #define _SYS_SYSCTL_H_
66
67 /*
68 * These are for the eproc structure defined below.
69 */
70 #include <sys/appleapiopts.h>
71 #ifndef KERNEL
72 #include <sys/time.h>
73 #include <sys/ucred.h>
74 #endif
75
76 #include <sys/vm.h>
77 #include <sys/proc.h>
78 #include <sys/linker_set.h>
79
80 /*
81 * Definitions for sysctl call. The sysctl call uses a hierarchical name
82 * for objects that can be examined or modified. The name is expressed as
83 * a sequence of integers. Like a file path name, the meaning of each
84 * component depends on its place in the hierarchy. The top-level and kern
85 * identifiers are defined here, and other identifiers are defined in the
86 * respective subsystem header files.
87 */
88
89 #define CTL_MAXNAME 12 /* largest number of components supported */
90
91 /*
92 * Each subsystem defined by sysctl defines a list of variables
93 * for that subsystem. Each name is either a node with further
94 * levels defined below it, or it is a leaf of some particular
95 * type given below. Each sysctl level defines a set of name/type
96 * pairs to be used by sysctl(1) in manipulating the subsystem.
97 */
98 struct ctlname {
99 char *ctl_name; /* subsystem name */
100 int ctl_type; /* type of name */
101 };
102
103 #define CTLTYPE 0xf /* Mask for the type */
104 #define CTLTYPE_NODE 1 /* name is a node */
105 #define CTLTYPE_INT 2 /* name describes an integer */
106 #define CTLTYPE_STRING 3 /* name describes a string */
107 #define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
108 #define CTLTYPE_OPAQUE 5 /* name describes a structure */
109 #define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
110
111 #define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
112 #define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
113 #define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
114 #define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
115 #define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
116 #define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
117 #define CTLFLAG_MASKED 0x04000000 /* deprecated variable, do not display */
118 #define CTLFLAG_NOAUTO 0x02000000 /* do not auto-register */
119 #define CTLFLAG_KERN 0x01000000 /* valid inside the kernel */
120
121 /*
122 * USE THIS instead of a hardwired number from the categories below
123 * to get dynamically assigned sysctl entries using the linker-set
124 * technology. This is the way nearly all new sysctl variables should
125 * be implemented.
126 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
127 */
128 #define OID_AUTO (-1)
129
130 #ifdef KERNEL
131 #ifdef __APPLE_API_UNSTABLE
132 #define SYSCTL_HANDLER_ARGS (struct sysctl_oid *oidp, void *arg1, int arg2, \
133 struct sysctl_req *req)
134
135 /*
136 * This describes the access space for a sysctl request. This is needed
137 * so that we can use the interface from the kernel or from user-space.
138 */
139 struct sysctl_req {
140 struct proc *p;
141 int lock;
142 void *oldptr;
143 size_t oldlen;
144 size_t oldidx;
145 int (*oldfunc)(struct sysctl_req *, const void *, size_t);
146 void *newptr;
147 size_t newlen;
148 size_t newidx;
149 int (*newfunc)(struct sysctl_req *, void *, size_t);
150 };
151
152 SLIST_HEAD(sysctl_oid_list, sysctl_oid);
153
154 /*
155 * This describes one "oid" in the MIB tree. Potentially more nodes can
156 * be hidden behind it, expanded by the handler.
157 */
158 struct sysctl_oid {
159 struct sysctl_oid_list *oid_parent;
160 SLIST_ENTRY(sysctl_oid) oid_link;
161 int oid_number;
162 int oid_kind;
163 void *oid_arg1;
164 int oid_arg2;
165 const char *oid_name;
166 int (*oid_handler) SYSCTL_HANDLER_ARGS;
167 const char *oid_fmt;
168 };
169
170 #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
171 #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
172
173 int sysctl_handle_int SYSCTL_HANDLER_ARGS;
174 int sysctl_handle_long SYSCTL_HANDLER_ARGS;
175 int sysctl_handle_quad SYSCTL_HANDLER_ARGS;
176 int sysctl_handle_int2quad SYSCTL_HANDLER_ARGS;
177 /*int sysctl_handle_intptr SYSCTL_HANDLER_ARGS; XXX not implemented */
178 int sysctl_handle_string SYSCTL_HANDLER_ARGS;
179 int sysctl_handle_opaque SYSCTL_HANDLER_ARGS;
180
181 /*
182 * These functions are used to add/remove an oid from the mib.
183 */
184 void sysctl_register_oid(struct sysctl_oid *oidp);
185 void sysctl_unregister_oid(struct sysctl_oid *oidp);
186
187 /* Declare an oid to allow child oids to be added to it. */
188 #define SYSCTL_DECL(name) \
189 extern struct sysctl_oid_list sysctl_##name##_children
190
191 /* This constructs a "raw" MIB oid. */
192 #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
193 struct sysctl_oid sysctl_##parent##_##name = { \
194 &sysctl_##parent##_children, { 0 }, \
195 nbr, kind, a1, a2, #name, handler, fmt };
196
197
198 /* This constructs a node from which other oids can hang. */
199 #define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
200 struct sysctl_oid_list sysctl_##parent##_##name##_children; \
201 SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access, \
202 (void*)&sysctl_##parent##_##name##_children, 0, handler, \
203 "N", descr);
204
205 /* Oid for a string. len can be 0 to indicate '\0' termination. */
206 #define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
207 SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|access, \
208 arg, len, sysctl_handle_string, "A", descr)
209
210 /* Oid for an int. If ptr is NULL, val is returned. */
211 #define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
212 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
213 ptr, val, sysctl_handle_int, "I", descr)
214
215 /* Oid for a long. The pointer must be non NULL. */
216 #define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \
217 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
218 ptr, 0, sysctl_handle_long, "L", descr)
219
220 /* Oid for a quad. The pointer must be non NULL. */
221 #define SYSCTL_QUAD(parent, nbr, name, access, ptr, descr) \
222 SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
223 ptr, 0, sysctl_handle_quad, "Q", descr)
224
225 /* Oid for a int returned as quad. The pointer must be non NULL. */
226 #define SYSCTL_INT2QUAD(parent, nbr, name, access, ptr, descr) \
227 SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
228 ptr, 0, sysctl_handle_int2quad, "Q", descr)
229
230 /* Oid for an opaque object. Specified by a pointer and a length. */
231 #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
232 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
233 ptr, len, sysctl_handle_opaque, fmt, descr)
234
235 /* Oid for a struct. Specified by a pointer and a type. */
236 #define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
237 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
238 ptr, sizeof(struct type), sysctl_handle_opaque, \
239 "S," #type, descr)
240
241 /* Oid for a procedure. Specified by a pointer and an arg. */
242 #define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
243 SYSCTL_OID(parent, nbr, name, access, \
244 ptr, arg, handler, fmt, descr)
245 #endif /* __APPLE_API_UNSTABLE */
246 #endif /* KERNEL */
247
248 /*
249 * Top-level identifiers
250 */
251 #define CTL_UNSPEC 0 /* unused */
252 #define CTL_KERN 1 /* "high kernel": proc, limits */
253 #define CTL_VM 2 /* virtual memory */
254 #define CTL_VFS 3 /* file system, mount type is next */
255 #define CTL_NET 4 /* network, see socket.h */
256 #define CTL_DEBUG 5 /* debugging parameters */
257 #define CTL_HW 6 /* generic cpu/io */
258 #define CTL_MACHDEP 7 /* machine dependent */
259 #define CTL_USER 8 /* user-level */
260 #define CTL_MAXID 9 /* number of valid top-level ids */
261
262 #define CTL_NAMES { \
263 { 0, 0 }, \
264 { "kern", CTLTYPE_NODE }, \
265 { "vm", CTLTYPE_NODE }, \
266 { "vfs", CTLTYPE_NODE }, \
267 { "net", CTLTYPE_NODE }, \
268 { "debug", CTLTYPE_NODE }, \
269 { "hw", CTLTYPE_NODE }, \
270 { "machdep", CTLTYPE_NODE }, \
271 { "user", CTLTYPE_NODE }, \
272 }
273
274 /*
275 * CTL_KERN identifiers
276 */
277 #define KERN_OSTYPE 1 /* string: system version */
278 #define KERN_OSRELEASE 2 /* string: system release */
279 #define KERN_OSREV 3 /* int: system revision */
280 #define KERN_VERSION 4 /* string: compile time info */
281 #define KERN_MAXVNODES 5 /* int: max vnodes */
282 #define KERN_MAXPROC 6 /* int: max processes */
283 #define KERN_MAXFILES 7 /* int: max open files */
284 #define KERN_ARGMAX 8 /* int: max arguments to exec */
285 #define KERN_SECURELVL 9 /* int: system security level */
286 #define KERN_HOSTNAME 10 /* string: hostname */
287 #define KERN_HOSTID 11 /* int: host identifier */
288 #define KERN_CLOCKRATE 12 /* struct: struct clockrate */
289 #define KERN_VNODE 13 /* struct: vnode structures */
290 #define KERN_PROC 14 /* struct: process entries */
291 #define KERN_FILE 15 /* struct: file entries */
292 #define KERN_PROF 16 /* node: kernel profiling info */
293 #define KERN_POSIX1 17 /* int: POSIX.1 version */
294 #define KERN_NGROUPS 18 /* int: # of supplemental group ids */
295 #define KERN_JOB_CONTROL 19 /* int: is job control available */
296 #define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
297 #define KERN_BOOTTIME 21 /* struct: time kernel was booted */
298 #define KERN_NISDOMAINNAME 22 /* string: YP domain name */
299 #define KERN_DOMAINNAME KERN_NISDOMAINNAME
300 #define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */
301 #define KERN_KDEBUG 24 /* int: kernel trace points */
302 #define KERN_UPDATEINTERVAL 25 /* int: update process sleep time */
303 #define KERN_OSRELDATE 26 /* int: OS release date */
304 #define KERN_NTP_PLL 27 /* node: NTP PLL control */
305 #define KERN_BOOTFILE 28 /* string: name of booted kernel */
306 #define KERN_MAXFILESPERPROC 29 /* int: max open files per proc */
307 #define KERN_MAXPROCPERUID 30 /* int: max processes per uid */
308 #define KERN_DUMPDEV 31 /* dev_t: device to dump on */
309 #define KERN_IPC 32 /* node: anything related to IPC */
310 #define KERN_DUMMY 33 /* unused */
311 #define KERN_PS_STRINGS 34 /* int: address of PS_STRINGS */
312 #define KERN_USRSTACK 35 /* int: address of USRSTACK */
313 #define KERN_LOGSIGEXIT 36 /* int: do we log sigexit procs? */
314 #define KERN_SYMFILE 37 /* string: kernel symbol filename */
315 #define KERN_PROCARGS 38
316 #define KERN_PCSAMPLES 39 /* node: pc sampling */
317 #define KERN_NETBOOT 40 /* int: are we netbooted? 1=yes,0=no */
318 #define KERN_PANICINFO 41 /* node: panic UI information */
319 #define KERN_SYSV 42 /* node: panic UI information */
320 #define KERN_MAXID 43 /* number of valid kern ids */
321
322
323 /* KERN_KDEBUG types */
324 #define KERN_KDEFLAGS 1
325 #define KERN_KDDFLAGS 2
326 #define KERN_KDENABLE 3
327 #define KERN_KDSETBUF 4
328 #define KERN_KDGETBUF 5
329 #define KERN_KDSETUP 6
330 #define KERN_KDREMOVE 7
331 #define KERN_KDSETREG 8
332 #define KERN_KDGETREG 9
333 #define KERN_KDREADTR 10
334 #define KERN_KDPIDTR 11
335 #define KERN_KDTHRMAP 12
336 /* Don't use 13 as it is overloaded with KERN_VNODE */
337 #define KERN_KDPIDEX 14
338 #define KERN_KDSETRTCDEC 15
339 #define KERN_KDGETENTROPY 16
340
341 /* KERN_PCSAMPLES types */
342 #define KERN_PCDISABLE 1
343 #define KERN_PCSETBUF 2
344 #define KERN_PCGETBUF 3
345 #define KERN_PCSETUP 4
346 #define KERN_PCREMOVE 5
347 #define KERN_PCREADBUF 6
348 #define KERN_PCSETREG 7
349 #define KERN_PCCOMM 8
350
351 /* KERN_PANICINFO types */
352 #define KERN_PANICINFO_MAXSIZE 1 /* quad: panic UI image size limit */
353 #define KERN_PANICINFO_IMAGE16 2 /* string: path to the panic UI (16 bit) */
354 #define KERN_PANICINFO_IMAGE32 3 /* string: path to the panic UI (32 bit) */
355
356 /*
357 * KERN_SYSV identifiers
358 */
359 #define KSYSV_SHMMAX 1 /* int: max shared memory segment size (bytes) */
360 #define KSYSV_SHMMIN 2 /* int: min shared memory segment size (bytes) */
361 #define KSYSV_SHMMNI 3 /* int: max number of shared memory identifiers */
362 #define KSYSV_SHMSEG 4 /* int: max shared memory segments per process */
363 #define KSYSV_SHMALL 5 /* int: max amount of shared memory (pages) */
364
365
366 #define CTL_KERN_NAMES { \
367 { 0, 0 }, \
368 { "ostype", CTLTYPE_STRING }, \
369 { "osrelease", CTLTYPE_STRING }, \
370 { "osrevision", CTLTYPE_INT }, \
371 { "version", CTLTYPE_STRING }, \
372 { "maxvnodes", CTLTYPE_INT }, \
373 { "maxproc", CTLTYPE_INT }, \
374 { "maxfiles", CTLTYPE_INT }, \
375 { "argmax", CTLTYPE_INT }, \
376 { "securelevel", CTLTYPE_INT }, \
377 { "hostname", CTLTYPE_STRING }, \
378 { "hostid", CTLTYPE_INT }, \
379 { "clockrate", CTLTYPE_STRUCT }, \
380 { "vnode", CTLTYPE_STRUCT }, \
381 { "proc", CTLTYPE_STRUCT }, \
382 { "file", CTLTYPE_STRUCT }, \
383 { "profiling", CTLTYPE_NODE }, \
384 { "posix1version", CTLTYPE_INT }, \
385 { "ngroups", CTLTYPE_INT }, \
386 { "job_control", CTLTYPE_INT }, \
387 { "saved_ids", CTLTYPE_INT }, \
388 { "boottime", CTLTYPE_STRUCT }, \
389 { "nisdomainname", CTLTYPE_STRING }, \
390 { "maxpartitions", CTLTYPE_INT }, \
391 { "kdebug", CTLTYPE_INT }, \
392 { "update", CTLTYPE_INT }, \
393 { "osreldate", CTLTYPE_INT }, \
394 { "ntp_pll", CTLTYPE_NODE }, \
395 { "bootfile", CTLTYPE_STRING }, \
396 { "maxfilesperproc", CTLTYPE_INT }, \
397 { "maxprocperuid", CTLTYPE_INT }, \
398 { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
399 { "ipc", CTLTYPE_NODE }, \
400 { "dummy", CTLTYPE_INT }, \
401 { "ps_strings", CTLTYPE_INT }, \
402 { "usrstack", CTLTYPE_INT }, \
403 { "logsigexit", CTLTYPE_INT }, \
404 { "symfile",CTLTYPE_STRING },\
405 { "procargs",CTLTYPE_STRUCT },\
406 { "pcsamples",CTLTYPE_STRUCT },\
407 { "netboot", CTLTYPE_INT }, \
408 { "panicinfo", CTLTYPE_NODE }, \
409 { "sysv", CTLTYPE_NODE } \
410 }
411
412 /*
413 * CTL_VFS identifiers
414 */
415 #define CTL_VFS_NAMES { \
416 { "vfsconf", CTLTYPE_STRUCT } \
417 }
418
419 /*
420 * KERN_PROC subtypes
421 */
422 #define KERN_PROC_ALL 0 /* everything */
423 #define KERN_PROC_PID 1 /* by process id */
424 #define KERN_PROC_PGRP 2 /* by process group id */
425 #define KERN_PROC_SESSION 3 /* by session of pid */
426 #define KERN_PROC_TTY 4 /* by controlling tty */
427 #define KERN_PROC_UID 5 /* by effective uid */
428 #define KERN_PROC_RUID 6 /* by real uid */
429
430 /*
431 * KERN_PROC subtype ops return arrays of augmented proc structures:
432 */
433 #ifdef __APPLE_API_UNSTABLE
434 struct kinfo_proc {
435 struct extern_proc kp_proc; /* proc structure */
436 struct eproc {
437 struct proc *e_paddr; /* address of proc */
438 struct session *e_sess; /* session pointer */
439 struct pcred e_pcred; /* process credentials */
440 struct ucred e_ucred; /* current credentials */
441 struct vmspace e_vm; /* address space */
442 pid_t e_ppid; /* parent process id */
443 pid_t e_pgid; /* process group id */
444 short e_jobc; /* job control counter */
445 dev_t e_tdev; /* controlling tty dev */
446 pid_t e_tpgid; /* tty process group id */
447 struct session *e_tsess; /* tty session pointer */
448 #define WMESGLEN 7
449 char e_wmesg[WMESGLEN+1]; /* wchan message */
450 segsz_t e_xsize; /* text size */
451 short e_xrssize; /* text rss */
452 short e_xccount; /* text references */
453 short e_xswrss;
454 long e_flag;
455 #define EPROC_CTTY 0x01 /* controlling tty vnode active */
456 #define EPROC_SLEADER 0x02 /* session leader */
457 #define COMAPT_MAXLOGNAME 12
458 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
459 long e_spare[4];
460 } kp_eproc;
461 };
462 #endif /* __APPLE_API_UNSTABLE */
463
464 /*
465 * KERN_IPC identifiers
466 */
467 #define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
468 #define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
469 #define KIPC_SOMAXCONN 3 /* int: max length of connection q */
470 #define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
471 #define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
472 #define KIPC_MAX_HDR 6 /* int: max total length of headers */
473 #define KIPC_MAX_DATALEN 7 /* int: max length of data? */
474 #define KIPC_MBSTAT 8 /* struct: mbuf usage statistics */
475 #define KIPC_NMBCLUSTERS 9 /* int: maximum mbuf clusters */
476
477 /*
478 * CTL_VM identifiers
479 */
480 #define VM_METER 1 /* struct vmmeter */
481 #define VM_LOADAVG 2 /* struct loadavg */
482 #define VM_MAXID 3 /* number of valid vm ids */
483 #define VM_MACHFACTOR 4 /* struct loadavg with mach factor*/
484
485 #define CTL_VM_NAMES { \
486 { 0, 0 }, \
487 { "vmmeter", CTLTYPE_STRUCT }, \
488 { "loadavg", CTLTYPE_STRUCT } \
489 }
490
491 /*
492 * CTL_HW identifiers
493 */
494 #define HW_MACHINE 1 /* string: machine class */
495 #define HW_MODEL 2 /* string: specific machine model */
496 #define HW_NCPU 3 /* int: number of cpus */
497 #define HW_BYTEORDER 4 /* int: machine byte order */
498 #define HW_PHYSMEM 5 /* int: total memory */
499 #define HW_USERMEM 6 /* int: non-kernel memory */
500 #define HW_PAGESIZE 7 /* int: software page size */
501 #define HW_DISKNAMES 8 /* strings: disk drive names */
502 #define HW_DISKSTATS 9 /* struct: diskstats[] */
503 #define HW_EPOCH 10 /* int: 0 for Legacy, else NewWorld */
504 #define HW_FLOATINGPT 11 /* int: has HW floating point? */
505 #define HW_MACHINE_ARCH 12 /* string: machine architecture */
506 #define HW_VECTORUNIT 13 /* int: has HW vector unit? */
507 #define HW_BUS_FREQ 14 /* int: Bus Frequency */
508 #define HW_CPU_FREQ 15 /* int: CPU Frequency */
509 #define HW_CACHELINE 16 /* int: Cache Line Size in Bytes */
510 #define HW_L1ICACHESIZE 17 /* int: L1 I Cache Size in Bytes */
511 #define HW_L1DCACHESIZE 18 /* int: L1 D Cache Size in Bytes */
512 #define HW_L2SETTINGS 19 /* int: L2 Cache Settings */
513 #define HW_L2CACHESIZE 20 /* int: L2 Cache Size in Bytes */
514 #define HW_L3SETTINGS 21 /* int: L3 Cache Settings */
515 #define HW_L3CACHESIZE 22 /* int: L3 Cache Size in Bytes */
516 #define HW_TB_FREQ 23 /* int: Bus Frequency */
517 #define HW_MEMSIZE 24 /* uint64_t: physical ram size */
518 #define HW_AVAILCPU 25 /* int: number of available CPUs */
519 #define HW_MAXID 26 /* number of valid hw ids */
520
521 #define CTL_HW_NAMES { \
522 { 0, 0 }, \
523 { "machine", CTLTYPE_STRING }, \
524 { "model", CTLTYPE_STRING }, \
525 { "ncpu", CTLTYPE_INT }, \
526 { "byteorder", CTLTYPE_INT }, \
527 { "physmem", CTLTYPE_INT }, \
528 { "usermem", CTLTYPE_INT }, \
529 { "pagesize", CTLTYPE_INT }, \
530 { "disknames", CTLTYPE_STRUCT }, \
531 { "diskstats", CTLTYPE_STRUCT }, \
532 { "epoch", CTLTYPE_INT }, \
533 { "floatingpoint", CTLTYPE_INT }, \
534 { "machinearch", CTLTYPE_STRING }, \
535 { "vectorunit", CTLTYPE_INT }, \
536 { "busfrequency", CTLTYPE_INT }, \
537 { "cpufrequency", CTLTYPE_INT }, \
538 { "cachelinesize", CTLTYPE_INT }, \
539 { "l1icachesize", CTLTYPE_INT }, \
540 { "l1dcachesize", CTLTYPE_INT }, \
541 { "l2settings", CTLTYPE_INT }, \
542 { "l2cachesize", CTLTYPE_INT }, \
543 { "l3settings", CTLTYPE_INT }, \
544 { "l3cachesize", CTLTYPE_INT }, \
545 { "tbfrequency", CTLTYPE_INT }, \
546 { "memsize", CTLTYPE_QUAD }, \
547 { "availcpu", CTLTYPE_INT } \
548 }
549
550 /*
551 * These are the support HW selectors for sysctlbyname. Parameters that are byte count or frequencies are 64 bit numbers.
552 * All other parameters are 32 bit numbers.
553 *
554 * hw.memsize - The number of bytes of physical memory in the system.
555 *
556 * hw.ncpu - The number maximum number of processor that could be available this boot.
557 * Use this value for sizing of static per processor arrays; i.e. processor load statistics.
558 *
559 * hw.activecpu - The number of cpus currently available for executing threads.
560 * Use this number to determine the number threads to create in SMP aware applications.
561 * This number can change when power management modes are changed.
562 *
563 * hw.tbfrequency - This gives the time base frequency used by the OS and is the basis of all timing services.
564 * In general is is better to use mach's or higher level timing services, but this value
565 * is needed to convert the PPC Time Base registers to real time.
566 *
567 * hw.cpufrequency - These values provide the current, min and max cpu frequency. The min and max are for
568 * hw.cpufrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
569 * hw.cpufrequency_min - All frequencies are in Hz.
570 *
571 * hw.busfrequency - These values provide the current, min and max bus frequency. The min and max are for
572 * hw.busfrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
573 * hw.busfrequency_min - All frequencies are in Hz.
574 *
575 * hw.cputype - These values provide the mach-o cpu type and subtype. A complete list is in <mach/machine.h>
576 * hw.cpusubtype - These values should be used to determine what processor family the running cpu is from so that
577 * the best binary can be chosen, or the best dynamic code generated. They should not be used
578 * to determine if a given processor feature is available.
579 *
580 * hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little.
581 *
582 * hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system.
583 *
584 * hw.cachelinesize - Gives the size in bytes of the processor's cache lines.
585 * This value should be use to control the strides of loops that use cache control instructions
586 * like dcbz, dcbt or dcbst.
587 *
588 * hw.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present
589 * hw.l1icachesize - then the selector will return and error.
590 * hw.l2cachesize -
591 * hw.l3cachesize -
592 *
593 *
594 * These are the selectors for optional processor features. Selectors that return errors are not support on the system.
595 * Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help performance.
596 * Future versions of these selectors may return larger values as necessary so it is best to test for non zero.
597 *
598 * hw.optional.floatingpoint - Floating Point Instructions
599 * hw.optional.altivec - AltiVec Instructions
600 * hw.optional.graphicsops - Graphics Operations
601 * hw.optional.64bitops - 64-bit Instructions
602 * hw.optional.fsqrt - HW Floating Point Square Root Instruction
603 * hw.optional.stfiwx - Store Floating Point as Integer Word Indexed Instructions
604 * hw.optional.dcba - Data Cache Block Allocate Instruction
605 * hw.optional.datastreams - Data Streams Instructions
606 * hw.optional.dcbtstreams - Data Cache Block Touch Steams Instruction Form
607 *
608 */
609
610
611 /*
612 * CTL_USER definitions
613 */
614 #define USER_CS_PATH 1 /* string: _CS_PATH */
615 #define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
616 #define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
617 #define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
618 #define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
619 #define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
620 #define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
621 #define USER_LINE_MAX 8 /* int: LINE_MAX */
622 #define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
623 #define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
624 #define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
625 #define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
626 #define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
627 #define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
628 #define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
629 #define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
630 #define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
631 #define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
632 #define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
633 #define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
634 #define USER_MAXID 21 /* number of valid user ids */
635
636 #define CTL_USER_NAMES { \
637 { 0, 0 }, \
638 { "cs_path", CTLTYPE_STRING }, \
639 { "bc_base_max", CTLTYPE_INT }, \
640 { "bc_dim_max", CTLTYPE_INT }, \
641 { "bc_scale_max", CTLTYPE_INT }, \
642 { "bc_string_max", CTLTYPE_INT }, \
643 { "coll_weights_max", CTLTYPE_INT }, \
644 { "expr_nest_max", CTLTYPE_INT }, \
645 { "line_max", CTLTYPE_INT }, \
646 { "re_dup_max", CTLTYPE_INT }, \
647 { "posix2_version", CTLTYPE_INT }, \
648 { "posix2_c_bind", CTLTYPE_INT }, \
649 { "posix2_c_dev", CTLTYPE_INT }, \
650 { "posix2_char_term", CTLTYPE_INT }, \
651 { "posix2_fort_dev", CTLTYPE_INT }, \
652 { "posix2_fort_run", CTLTYPE_INT }, \
653 { "posix2_localedef", CTLTYPE_INT }, \
654 { "posix2_sw_dev", CTLTYPE_INT }, \
655 { "posix2_upe", CTLTYPE_INT }, \
656 { "stream_max", CTLTYPE_INT }, \
657 { "tzname_max", CTLTYPE_INT } \
658 }
659
660
661
662 /*
663 * CTL_DEBUG definitions
664 *
665 * Second level identifier specifies which debug variable.
666 * Third level identifier specifies which stucture component.
667 */
668 #define CTL_DEBUG_NAME 0 /* string: variable name */
669 #define CTL_DEBUG_VALUE 1 /* int: variable value */
670 #define CTL_DEBUG_MAXID 20
671
672 #ifdef KERNEL
673 #ifdef __APPLE_API_UNSTABLE
674
675 extern struct sysctl_oid_list sysctl__children;
676 SYSCTL_DECL(_kern);
677 SYSCTL_DECL(_sysctl);
678 SYSCTL_DECL(_vm);
679 SYSCTL_DECL(_vfs);
680 SYSCTL_DECL(_net);
681 SYSCTL_DECL(_debug);
682 SYSCTL_DECL(_hw);
683 SYSCTL_DECL(_machdep);
684 SYSCTL_DECL(_user);
685
686
687 #ifdef DEBUG
688 /*
689 * CTL_DEBUG variables.
690 *
691 * These are declared as separate variables so that they can be
692 * individually initialized at the location of their associated
693 * variable. The loader prevents multiple use by issuing errors
694 * if a variable is initialized in more than one place. They are
695 * aggregated into an array in debug_sysctl(), so that it can
696 * conveniently locate them when querried. If more debugging
697 * variables are added, they must also be declared here and also
698 * entered into the array.
699 */
700 struct ctldebug {
701 char *debugname; /* name of debugging variable */
702 int *debugvar; /* pointer to debugging variable */
703 };
704 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
705 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
706 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
707 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
708 #endif /* DEBUG */
709
710 extern char machine[];
711 extern char osrelease[];
712 extern char ostype[];
713
714 struct linker_set;
715
716 void sysctl_register_set(struct linker_set *lsp);
717 void sysctl_unregister_set(struct linker_set *lsp);
718 void sysctl_mib_init(void);
719 int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
720 size_t *oldlenp, void *newp, size_t newlen);
721 int userland_sysctl(struct proc *p, int *name, u_int namelen, void *old,
722 size_t *oldlenp, int inkernel, void *newp, size_t newlen,
723 size_t *retval);
724
725 /*
726 * Sysctl handling within the kernel.
727 *
728 * May be called with either or no funnel held; will take and
729 * switch funnels as required.
730 */
731 int sysctlbyname __P((const char *, void *, size_t *, void *, size_t));
732
733 /*
734 * Internal sysctl function calling convention:
735 *
736 * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
737 *
738 * The name parameter points at the next component of the name to be
739 * interpreted. The namelen parameter is the number of integers in
740 * the name.
741 */
742 typedef int (sysctlfn)
743 __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *));
744
745 int sysctl_int __P((void *, size_t *, void *, size_t, int *));
746 int sysctl_rdint __P((void *, size_t *, void *, int));
747 int sysctl_quad __P((void *, size_t *, void *, size_t, quad_t *));
748 int sysctl_rdquad __P((void *, size_t *, void *, quad_t));
749 int sysctl_string __P((void *, size_t *, void *, size_t, char *, int));
750 int sysctl_rdstring __P((void *, size_t *, void *, char *));
751 int sysctl_rdstruct __P((void *, size_t *, void *, void *, int));
752 void fill_eproc __P((struct proc *, struct eproc *));
753
754 #endif /* __APPLE_API_UNSTABLE */
755 #else /* !KERNEL */
756 #include <sys/cdefs.h>
757
758 __BEGIN_DECLS
759 int sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
760 int sysctlbyname __P((const char *, void *, size_t *, void *, size_t));
761 __END_DECLS
762 #endif /* KERNEL */
763 #endif /* !_SYS_SYSCTL_H_ */