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