]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/sysctl.h
xnu-7195.60.75.tar.gz
[apple/xnu.git] / bsd / sys / sysctl.h
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
a39ff7e2 5 *
2d21ac55
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
a39ff7e2 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
a39ff7e2 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
a39ff7e2 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * This code is derived from software contributed to Berkeley by
34 * Mike Karels at Berkeley Software Design, Inc.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)sysctl.h 8.1 (Berkeley) 6/2/93
65 */
2d21ac55
A
66/*
67 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
68 * support for mandatory and extensible security protections. This notice
69 * is included in support of clause 2.2 (b) of the Apple Public License,
70 * Version 2.0.
71 */
1c79356b
A
72
73#ifndef _SYS_SYSCTL_H_
0a7de745 74#define _SYS_SYSCTL_H_
1c79356b
A
75
76/*
77 * These are for the eproc structure defined below.
78 */
91447636
A
79#include <sys/cdefs.h>
80
9bccf70c 81#include <sys/appleapiopts.h>
1c79356b
A
82#ifndef KERNEL
83#include <sys/time.h>
84#include <sys/ucred.h>
91447636 85#else
fe8ab488 86#ifndef XNU_KERNEL_PRIVATE
91447636 87#include <libkern/sysctl.h>
f427ee49 88#include <os/base.h>
1c79356b 89#endif
5ba3f43e 90
fe8ab488 91#endif
1c79356b 92#include <sys/proc.h>
91447636
A
93#include <sys/vm.h>
94
2d21ac55 95#ifdef XNU_KERNEL_PRIVATE
1c79356b 96#include <sys/linker_set.h>
91447636 97#endif
1c79356b
A
98
99/*
100 * Definitions for sysctl call. The sysctl call uses a hierarchical name
101 * for objects that can be examined or modified. The name is expressed as
102 * a sequence of integers. Like a file path name, the meaning of each
103 * component depends on its place in the hierarchy. The top-level and kern
104 * identifiers are defined here, and other identifiers are defined in the
105 * respective subsystem header files.
106 */
107
0a7de745 108#define CTL_MAXNAME 12 /* largest number of components supported */
1c79356b
A
109
110/*
111 * Each subsystem defined by sysctl defines a list of variables
a39ff7e2 112 * for that subsystem. Each name is either a node with further
1c79356b
A
113 * levels defined below it, or it is a leaf of some particular
114 * type given below. Each sysctl level defines a set of name/type
115 * pairs to be used by sysctl(1) in manipulating the subsystem.
2d21ac55 116 *
fe8ab488 117 * When declaring new sysctl names, use the CTLFLAG_LOCKED flag in the
6d2010ae
A
118 * type to indicate that all necessary locking will be handled
119 * within the sysctl.
120 *
121 * Any sysctl defined without CTLFLAG_LOCKED is considered legacy
fe8ab488 122 * and will be protected by a global mutex.
6d2010ae
A
123 *
124 * Note: This is not optimal, so it is best to handle locking
125 * yourself, if you are able to do so. A simple design
126 * pattern for use to avoid in a single function known
127 * to potentially be in the paging path ot doing a DMA
128 * to physical memory in a user space process is:
129 *
130 * lock
131 * perform operation vs. local buffer
132 * unlock
133 * SYSCTL_OUT(rey, local buffer, length)
134 *
135 * ...this assumes you are not using a deep call graph
136 * or are unable to pass a local buffer address as a
137 * parameter into your deep call graph.
138 *
139 * Note that very large user buffers can fail the wire
140 * if to do so would require more physical pages than
141 * are available (the caller will get an ENOMEM error,
142 * see sysctl_mem_hold() for details).
1c79356b
A
143 */
144struct ctlname {
0a7de745
A
145 char *ctl_name; /* subsystem name */
146 int ctl_type; /* type of name */
1c79356b
A
147};
148
0a7de745
A
149#define CTLTYPE 0xf /* Mask for the type */
150#define CTLTYPE_NODE 1 /* name is a node */
151#define CTLTYPE_INT 2 /* name describes an integer */
152#define CTLTYPE_STRING 3 /* name describes a string */
153#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
154#define CTLTYPE_OPAQUE 5 /* name describes a structure */
155#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
156
157#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
158#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
159#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
160#define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
161#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
162#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
163#define CTLFLAG_MASKED 0x04000000 /* deprecated variable, do not display */
164#define CTLFLAG_NOAUTO 0x02000000 /* do not auto-register */
165#define CTLFLAG_KERN 0x01000000 /* valid inside the kernel */
166#define CTLFLAG_LOCKED 0x00800000 /* node will handle locking itself */
167#define CTLFLAG_OID2 0x00400000 /* struct sysctl_oid has version info */
1c79356b
A
168
169/*
170 * USE THIS instead of a hardwired number from the categories below
171 * to get dynamically assigned sysctl entries using the linker-set
172 * technology. This is the way nearly all new sysctl variables should
173 * be implemented.
2d21ac55 174 *
1c79356b 175 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
2d21ac55
A
176 *
177 * Note that linker set technology will automatically register all nodes
178 * declared like this on kernel initialization, UNLESS they are defined
179 * in I/O-Kit. In this case, you have to call sysctl_register_oid()
180 * manually - just like in a KEXT.
181 */
0a7de745 182#define OID_AUTO (-1)
2d21ac55 183#define OID_AUTO_START 100 /* conventional */
1c79356b
A
184
185#ifdef KERNEL
186#define SYSCTL_HANDLER_ARGS (struct sysctl_oid *oidp, void *arg1, int arg2, \
187 struct sysctl_req *req)
188
2d21ac55 189
1c79356b
A
190/*
191 * This describes the access space for a sysctl request. This is needed
192 * so that we can use the interface from the kernel or from user-space.
193 */
194struct sysctl_req {
0a7de745
A
195 struct proc *p;
196 int lock;
197 user_addr_t oldptr; /* pointer to user supplied buffer */
198 size_t oldlen; /* user buffer length (also returned) */
199 size_t oldidx; /* total data iteratively copied out */
200 int (*oldfunc)(struct sysctl_req *, const void *, size_t);
201 user_addr_t newptr; /* buffer containing new value */
202 size_t newlen; /* length of new value */
203 size_t newidx; /* total data iteratively copied in */
204 int (*newfunc)(struct sysctl_req *, void *, size_t);
1c79356b
A
205};
206
207SLIST_HEAD(sysctl_oid_list, sysctl_oid);
208
0a7de745 209#define SYSCTL_OID_VERSION 1 /* current OID structure version */
6d2010ae 210
1c79356b
A
211/*
212 * This describes one "oid" in the MIB tree. Potentially more nodes can
213 * be hidden behind it, expanded by the handler.
6d2010ae
A
214 *
215 * NOTES: We implement binary comparibility between CTLFLAG_OID2 and
216 * pre-CTLFLAG_OID2 structure in sysctl_register_oid() and in
217 * sysctl_unregister_oid() using the fact that the fields up
218 * to oid_fmt are unchanged, and that the field immediately
219 * following is on an alignment boundary following a pointer
220 * type and is also a pointer. This lets us get the previous
221 * size of the structure, and the copy-cut-off point, using
222 * the offsetof() language primitive, and these values are
223 * used in conjunction with the fact that earlier and future
224 * statically compiled sysctl_oid structures are declared via
225 * macros. This lets us overload the macros so that the addition
226 * of the CTLFLAG_OID2 in newly compiled code containing sysctl
227 * node declarations, subsequently allowing us to to avoid
228 * changing the KPI used for non-static (un)registration in
229 * KEXTs.
230 *
f427ee49
A
231 * Non CTLFLAG_OID2 based sysctls are deprecated and unavailable
232 * to non Intel platforms.
233 *
6d2010ae
A
234 * This depends on the fact that people declare SYSCTLs,
235 * rather than declaring sysctl_oid structures. All new code
236 * should avoid declaring struct sysctl_oid's directly without
237 * the macros; the current risk for this is limited to losing
238 * your description field and ending up with a malloc'ed copy,
239 * as if it were a legacy binary static declaration via SYSCTL;
240 * in the future, we may deprecate access to a named structure
241 * type in third party code. Use the macros, or our code will
242 * end up with compile errors when that happens.
243 *
244 * Please try to include a long description of the field in any
245 * new sysctl declarations (all the macros support this). This
246 * field may be the only human readable documentation your users
247 * get for your sysctl.
1c79356b
A
248 */
249struct sysctl_oid {
f427ee49 250 struct sysctl_oid_list * OS_PTRAUTH_SIGNED_PTR("sysctl_oid.oid_parent") oid_parent;
1c79356b 251 SLIST_ENTRY(sysctl_oid) oid_link;
0a7de745
A
252 int oid_number;
253 int oid_kind;
254 void *oid_arg1;
255 int oid_arg2;
256 const char *oid_name;
257 int (*oid_handler)SYSCTL_HANDLER_ARGS;
258 const char *oid_fmt;
259 const char *oid_descr; /* offsetof() field / long description */
260 int oid_version;
261 int oid_refcnt;
1c79356b
A
262};
263
264#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
265#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
266
2d21ac55
A
267typedef int (* sysctl_handler_t) SYSCTL_HANDLER_ARGS;
268
91447636
A
269__BEGIN_DECLS
270
2d21ac55 271/* old interface */
1c79356b
A
272int sysctl_handle_int SYSCTL_HANDLER_ARGS;
273int sysctl_handle_long SYSCTL_HANDLER_ARGS;
43866e37
A
274int sysctl_handle_quad SYSCTL_HANDLER_ARGS;
275int sysctl_handle_int2quad SYSCTL_HANDLER_ARGS;
1c79356b
A
276int sysctl_handle_string SYSCTL_HANDLER_ARGS;
277int sysctl_handle_opaque SYSCTL_HANDLER_ARGS;
2d21ac55
A
278/* new interface */
279int sysctl_io_number(struct sysctl_req *req, long long bigValue, size_t valueSize, void *pValue, int *changed);
280int sysctl_io_string(struct sysctl_req *req, char *pValue, size_t valueSize, int trunc, int *changed);
281int sysctl_io_opaque(struct sysctl_req *req, void *pValue, size_t valueSize, int *changed);
1c79356b
A
282
283/*
284 * These functions are used to add/remove an oid from the mib.
285 */
286void sysctl_register_oid(struct sysctl_oid *oidp);
287void sysctl_unregister_oid(struct sysctl_oid *oidp);
288
cb323159 289void sysctl_load_devicetree_entries(void);
f427ee49
A
290#define nvram_osenvironment "osenvironment"
291void sysctl_set_osenvironment(unsigned int size, const void* value);
292void sysctl_unblock_osenvironment(void);
cb323159 293
39037602
A
294/* Deprecated */
295void sysctl_register_fixed(void) __deprecated;
2d21ac55 296
91447636
A
297__END_DECLS
298
1c79356b 299/* Declare an oid to allow child oids to be added to it. */
0a7de745 300#define SYSCTL_DECL(name) \
1c79356b
A
301 extern struct sysctl_oid_list sysctl_##name##_children
302
2d21ac55
A
303#ifdef XNU_KERNEL_PRIVATE
304#define SYSCTL_LINKER_SET_ENTRY LINKER_SET_ENTRY
305#else
306#define SYSCTL_LINKER_SET_ENTRY(a, b)
307#endif
fe8ab488 308/*
a39ff7e2 309 * Macros to define sysctl entries. Which to use? Pure data that are
fe8ab488
A
310 * returned without modification, SYSCTL_<data type> is for you, like
311 * SYSCTL_QUAD for a 64-bit value. When you want to run a handler of your
a39ff7e2 312 * own, SYSCTL_PROC.
fe8ab488
A
313 *
314 * parent: parent in name hierarchy (e.g. _kern for "kern")
315 * nbr: ID. Almost certainly OID_AUTO ("pick one for me") for you.
316 * name: name for this particular item (e.g. "thesysctl" for "kern.thesysctl")
317 * kind/access: Control flags (CTLFLAG_*). Some notable options include:
0a7de745
A
318 * CTLFLAG_ANYBODY: non-root users allowed
319 * CTLFLAG_MASKED: don't show in sysctl listing in userland
320 * CTLFLAG_LOCKED: does own locking (no additional protection needed)
321 * CTLFLAG_KERN: valid inside kernel (best avoided generally)
322 * CTLFLAG_WR: "new" value accepted
fe8ab488
A
323 * a1, a2: entry-data, passed to handler (see specific macros)
324 * Format String: Tells "sysctl" tool how to print data from this entry.
0a7de745
A
325 * "A" - string
326 * "I" - list of integers. "IU" - list of unsigned integers. space-separated.
327 * "-" - do not print
328 * "L" - longs, as ints with I
fe8ab488 329 * "P" - pointer
0a7de745
A
330 * "Q" - quads
331 * "S","T" - clock info, see sysctl.c in system_cmds (you probably don't need this)
fe8ab488
A
332 * Description: unused
333 */
334
335
1c79356b 336/* This constructs a "raw" MIB oid. */
fe8ab488 337#define SYSCTL_STRUCT_INIT(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
0a7de745 338 { \
cb323159 339 &sysctl_##parent##_children, { NULL }, \
0a7de745 340 nbr, (int)(kind|CTLFLAG_OID2), a1, (int)(a2), #name, handler, fmt, descr, SYSCTL_OID_VERSION, 0 \
fe8ab488
A
341 }
342
1c79356b 343#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
fe8ab488 344 struct sysctl_oid sysctl_##parent##_##name = SYSCTL_STRUCT_INIT(parent, nbr, name, kind, a1, a2, handler, fmt, descr); \
2d21ac55 345 SYSCTL_LINKER_SET_ENTRY(__sysctl_set, sysctl_##parent##_##name)
1c79356b
A
346
347/* This constructs a node from which other oids can hang. */
0a7de745
A
348#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
349 struct sysctl_oid_list sysctl_##parent##_##name##_children; \
350 SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access, \
351 (void*)&sysctl_##parent##_##name##_children, 0, handler, \
cb323159 352 "N", descr)
1c79356b
A
353
354/* Oid for a string. len can be 0 to indicate '\0' termination. */
355#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
356 SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|access, \
0a7de745 357 arg, len, sysctl_handle_string, "A", descr)
1c79356b 358
b0d623f7
A
359#define SYSCTL_COMPAT_INT(parent, nbr, name, access, ptr, val, descr) \
360 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 361 ptr, val, sysctl_handle_int, "I", descr)
b0d623f7
A
362
363#define SYSCTL_COMPAT_UINT(parent, nbr, name, access, ptr, val, descr) \
364 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 365 ptr, val, sysctl_handle_int, "IU", descr)
b0d623f7 366
1c79356b
A
367/* Oid for an int. If ptr is NULL, val is returned. */
368#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
369 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 370 ptr, val, sysctl_handle_int, "I", descr); \
cb323159 371 typedef char _sysctl_##parent##_##name##_size_check[(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(int)) ? 0 : -1]
1c79356b 372
55e303ae
A
373/* Oid for an unsigned int. If ptr is NULL, val is returned. */
374#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \
375 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 376 ptr, val, sysctl_handle_int, "IU", descr); \
cb323159 377 typedef char _sysctl_##parent##_##name##_size_check[(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(unsigned int)) ? 0 : -1]
55e303ae 378
1c79356b
A
379/* Oid for a long. The pointer must be non NULL. */
380#define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \
381 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 382 ptr, 0, sysctl_handle_long, "L", descr); \
cb323159 383 typedef char _sysctl_##parent##_##name##_size_check[(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(long)) ? 0 : -1]
1c79356b 384
5ba3f43e
A
385/* Oid for a unsigned long. The pointer must be non NULL. */
386#define SYSCTL_ULONG(parent, nbr, name, access, ptr, descr) \
387 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
0a7de745 388 ptr, 0, sysctl_handle_long, "LU", descr); \
cb323159 389 typedef char _sysctl_##parent##_##name##_size_check[(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(unsigned long)) ? 0 : -1]
5ba3f43e 390
43866e37
A
391/* Oid for a quad. The pointer must be non NULL. */
392#define SYSCTL_QUAD(parent, nbr, name, access, ptr, descr) \
393 SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
0a7de745 394 ptr, 0, sysctl_handle_quad, "Q", descr); \
cb323159 395 typedef char _sysctl_##parent##_##name##_size_check[(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(long long)) ? 0 : -1]
43866e37 396
1c79356b
A
397/* Oid for an opaque object. Specified by a pointer and a length. */
398#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
399 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
0a7de745 400 ptr, len, sysctl_handle_opaque, fmt, descr)
1c79356b
A
401
402/* Oid for a struct. Specified by a pointer and a type. */
403#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
404 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
0a7de745
A
405 ptr, sizeof(struct type), sysctl_handle_opaque, \
406 "S," #type, descr)
1c79356b 407
a39ff7e2 408/*
fe8ab488
A
409 * Oid for a procedure. Specified by a pointer and an arg.
410 * CTLTYPE_* macros can determine how the "sysctl" tool deals with
411 * input (e.g. converting to int).
412 */
1c79356b
A
413#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
414 SYSCTL_OID(parent, nbr, name, access, \
0a7de745 415 ptr, arg, handler, fmt, descr)
a39ff7e2
A
416
417
91447636
A
418extern struct sysctl_oid_list sysctl__children;
419SYSCTL_DECL(_kern);
420SYSCTL_DECL(_sysctl);
421SYSCTL_DECL(_vm);
422SYSCTL_DECL(_vfs);
423SYSCTL_DECL(_net);
424SYSCTL_DECL(_debug);
425SYSCTL_DECL(_hw);
426SYSCTL_DECL(_machdep);
427SYSCTL_DECL(_user);
428
39037602 429#ifdef PRIVATE
a39ff7e2 430SYSCTL_DECL(_kern_bridge);
39037602
A
431SYSCTL_DECL(_hw_features);
432#endif
433
5ba3f43e
A
434
435#ifndef SYSCTL_SKMEM_UPDATE_FIELD
436
0a7de745
A
437#define SYSCTL_SKMEM 0
438#define SYSCTL_SKMEM_UPDATE_FIELD(field, value)
439#define SYSCTL_SKMEM_UPDATE_AT_OFFSET(offset, value)
440#define SYSCTL_SKMEM_INT(parent, oid, sysctl_name, access, ptr, offset, descr) \
5ba3f43e
A
441 SYSCTL_INT(parent, oid, sysctl_name, access, ptr, 0, descr)
442
0a7de745
A
443#define SYSCTL_SKMEM_TCP_INT(oid, sysctl_name, access, variable_type, \
444 variable_name, initial_value, descr) \
445 variable_type variable_name = initial_value; \
446 SYSCTL_SKMEM_INT(_net_inet_tcp, oid, sysctl_name, access, \
447 &variable_name, 0, descr)
5ba3f43e
A
448
449#else /* SYSCTL_SKMEM_UPDATE_FIELD */
0a7de745 450#define SYSCTL_SKMEM 1
5ba3f43e
A
451#endif /* SYSCTL_SKMEM_UPDATE_FIELD */
452
453
454
1c79356b
A
455#endif /* KERNEL */
456
91447636
A
457#ifdef XNU_KERNEL_PRIVATE
458#define SYSCTL_DEF_ENABLED
459#else
460#ifndef KERNEL
461#define SYSCTL_DEF_ENABLED
462#endif
463#endif
464
465#ifdef SYSCTL_DEF_ENABLED
1c79356b
A
466/*
467 * Top-level identifiers
468 */
0a7de745
A
469#define CTL_UNSPEC 0 /* unused */
470#define CTL_KERN 1 /* "high kernel": proc, limits */
471#define CTL_VM 2 /* virtual memory */
472#define CTL_VFS 3 /* file system, mount type is next */
473#define CTL_NET 4 /* network, see socket.h */
474#define CTL_DEBUG 5 /* debugging parameters */
475#define CTL_HW 6 /* generic cpu/io */
476#define CTL_MACHDEP 7 /* machine dependent */
477#define CTL_USER 8 /* user-level */
478#define CTL_MAXID 9 /* number of valid top-level ids */
1c79356b
A
479
480#define CTL_NAMES { \
481 { 0, 0 }, \
482 { "kern", CTLTYPE_NODE }, \
483 { "vm", CTLTYPE_NODE }, \
484 { "vfs", CTLTYPE_NODE }, \
485 { "net", CTLTYPE_NODE }, \
486 { "debug", CTLTYPE_NODE }, \
487 { "hw", CTLTYPE_NODE }, \
488 { "machdep", CTLTYPE_NODE }, \
489 { "user", CTLTYPE_NODE }, \
490}
491
492/*
493 * CTL_KERN identifiers
494 */
0a7de745
A
495#define KERN_OSTYPE 1 /* string: system version */
496#define KERN_OSRELEASE 2 /* string: system release */
497#define KERN_OSREV 3 /* int: system revision */
498#define KERN_VERSION 4 /* string: compile time info */
499#define KERN_MAXVNODES 5 /* int: max vnodes */
500#define KERN_MAXPROC 6 /* int: max processes */
501#define KERN_MAXFILES 7 /* int: max open files */
502#define KERN_ARGMAX 8 /* int: max arguments to exec */
503#define KERN_SECURELVL 9 /* int: system security level */
504#define KERN_HOSTNAME 10 /* string: hostname */
505#define KERN_HOSTID 11 /* int: host identifier */
506#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
507#define KERN_VNODE 13 /* struct: vnode structures */
508#define KERN_PROC 14 /* struct: process entries */
509#define KERN_FILE 15 /* struct: file entries */
510#define KERN_PROF 16 /* node: kernel profiling info */
511#define KERN_POSIX1 17 /* int: POSIX.1 version */
512#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
513#define KERN_JOB_CONTROL 19 /* int: is job control available */
514#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
515#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
516#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
517#define KERN_DOMAINNAME KERN_NISDOMAINNAME
518#define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */
519#define KERN_KDEBUG 24 /* int: kernel trace points */
520#define KERN_UPDATEINTERVAL 25 /* int: update process sleep time */
521#define KERN_OSRELDATE 26 /* int: OS release date */
522#define KERN_NTP_PLL 27 /* node: NTP PLL control */
523#define KERN_BOOTFILE 28 /* string: name of booted kernel */
524#define KERN_MAXFILESPERPROC 29 /* int: max open files per proc */
525#define KERN_MAXPROCPERUID 30 /* int: max processes per uid */
526#define KERN_DUMPDEV 31 /* dev_t: device to dump on */
527#define KERN_IPC 32 /* node: anything related to IPC */
528#define KERN_DUMMY 33 /* unused */
529#define KERN_PS_STRINGS 34 /* int: address of PS_STRINGS */
530#define KERN_USRSTACK32 35 /* int: address of USRSTACK */
531#define KERN_LOGSIGEXIT 36 /* int: do we log sigexit procs? */
532#define KERN_SYMFILE 37 /* string: kernel symbol filename */
533#define KERN_PROCARGS 38
cb323159 534/* 39 was KERN_PCSAMPLES... now obsolete */
0a7de745
A
535#define KERN_NETBOOT 40 /* int: are we netbooted? 1=yes,0=no */
536/* 41 was KERN_PANICINFO : panic UI information (deprecated) */
537#define KERN_SYSV 42 /* node: System V IPC information */
538#define KERN_AFFINITY 43 /* xxx */
539#define KERN_TRANSLATE 44 /* xxx */
540#define KERN_CLASSIC KERN_TRANSLATE /* XXX backwards compat */
541#define KERN_EXEC 45 /* xxx */
542#define KERN_CLASSICHANDLER KERN_EXEC /* XXX backwards compatibility */
543#define KERN_AIOMAX 46 /* int: max aio requests */
544#define KERN_AIOPROCMAX 47 /* int: max aio requests per process */
545#define KERN_AIOTHREADS 48 /* int: max aio worker threads */
55e303ae 546#ifdef __APPLE_API_UNSTABLE
0a7de745 547#define KERN_PROCARGS2 49
55e303ae 548#endif /* __APPLE_API_UNSTABLE */
0a7de745
A
549#define KERN_COREFILE 50 /* string: corefile format string */
550#define KERN_COREDUMP 51 /* int: whether to coredump at all */
551#define KERN_SUGID_COREDUMP 52 /* int: whether to dump SUGID cores */
552#define KERN_PROCDELAYTERM 53 /* int: set/reset current proc for delayed termination during shutdown */
553#define KERN_SHREG_PRIVATIZABLE 54 /* int: can shared regions be privatized ? */
554/* 55 was KERN_PROC_LOW_PRI_IO... now deprecated */
555#define KERN_LOW_PRI_WINDOW 56 /* int: set/reset throttle window - milliseconds */
556#define KERN_LOW_PRI_DELAY 57 /* int: set/reset throttle delay - milliseconds */
557#define KERN_POSIX 58 /* node: posix tunables */
558#define KERN_USRSTACK64 59 /* LP64 user stack query */
559#define KERN_NX_PROTECTION 60 /* int: whether no-execute protection is enabled */
560#define KERN_TFP 61 /* Task for pid settings */
561#define KERN_PROCNAME 62 /* setup process program name(2*MAXCOMLEN) */
562#define KERN_THALTSTACK 63 /* for compat with older x86 and does nothing */
563#define KERN_SPECULATIVE_READS 64 /* int: whether speculative reads are disabled */
564#define KERN_OSVERSION 65 /* for build number i.e. 9A127 */
565#define KERN_SAFEBOOT 66 /* are we booted safe? */
566/* 67 was KERN_LCTX (login context) */
567#define KERN_RAGEVNODE 68
568#define KERN_TTY 69 /* node: tty settings */
2d21ac55 569#define KERN_CHECKOPENEVT 70 /* spi: check the VOPENEVT flag on vnodes at open time */
0a7de745
A
570#define KERN_THREADNAME 71 /* set/get thread name */
571#define KERN_MAXID 72 /* number of valid kern ids */
2d21ac55
A
572/*
573 * Don't add any more sysctls like this. Instead, use the SYSCTL_*() macros
574 * and OID_AUTO. This will have the added benefit of not having to recompile
575 * sysctl(8) to pick up your changes.
576 */
577
a39ff7e2 578#if COUNT_SYSCALLS && defined(KERNEL)
0a7de745 579#define KERN_COUNT_SYSCALLS (KERN_OSTYPE + 1000) /* keep called count for each bsd syscall */
2d21ac55 580#endif
91447636
A
581
582#if defined(__LP64__)
0a7de745 583#define KERN_USRSTACK KERN_USRSTACK64
91447636 584#else
0a7de745 585#define KERN_USRSTACK KERN_USRSTACK32
91447636 586#endif
1c79356b 587
2d21ac55
A
588
589/* KERN_RAGEVNODE types */
0a7de745
A
590#define KERN_RAGE_PROC 1
591#define KERN_RAGE_THREAD 2
592#define KERN_UNRAGE_PROC 3
593#define KERN_UNRAGE_THREAD 4
2d21ac55
A
594
595/* KERN_OPENEVT types */
596#define KERN_OPENEVT_PROC 1
597#define KERN_UNOPENEVT_PROC 2
598
0c530ab8 599/* KERN_TFP types */
0a7de745 600#define KERN_TFP_POLICY 1
0c530ab8
A
601
602/* KERN_TFP_POLICY values . All policies allow task port for self */
0a7de745
A
603#define KERN_TFP_POLICY_DENY 0 /* Deny Mode: None allowed except privileged */
604#define KERN_TFP_POLICY_DEFAULT 2 /* Default Mode: related ones allowed and upcall authentication */
0c530ab8 605
1c79356b 606/* KERN_KDEBUG types */
39037602
A
607#define KERN_KDEFLAGS 1
608#define KERN_KDDFLAGS 2
609#define KERN_KDENABLE 3
610#define KERN_KDSETBUF 4
611#define KERN_KDGETBUF 5
612#define KERN_KDSETUP 6
613#define KERN_KDREMOVE 7
614#define KERN_KDSETREG 8
615#define KERN_KDGETREG 9
616#define KERN_KDREADTR 10
617#define KERN_KDPIDTR 11
618#define KERN_KDTHRMAP 12
1c79356b 619/* Don't use 13 as it is overloaded with KERN_VNODE */
39037602
A
620#define KERN_KDPIDEX 14
621#define KERN_KDSETRTCDEC 15 /* obsolete */
622#define KERN_KDGETENTROPY 16 /* obsolete */
623#define KERN_KDWRITETR 17
624#define KERN_KDWRITEMAP 18
625#define KERN_KDTEST 19
626/* 20 unused */
627#define KERN_KDREADCURTHRMAP 21
628#define KERN_KDSET_TYPEFILTER 22
629#define KERN_KDBUFWAIT 23
630#define KERN_KDCPUMAP 24
631/* 25 - 26 unused */
632#define KERN_KDWRITEMAP_V3 27
633#define KERN_KDWRITETR_V3 28
9bccf70c 634
1c79356b
A
635#define CTL_KERN_NAMES { \
636 { 0, 0 }, \
637 { "ostype", CTLTYPE_STRING }, \
638 { "osrelease", CTLTYPE_STRING }, \
639 { "osrevision", CTLTYPE_INT }, \
640 { "version", CTLTYPE_STRING }, \
641 { "maxvnodes", CTLTYPE_INT }, \
642 { "maxproc", CTLTYPE_INT }, \
643 { "maxfiles", CTLTYPE_INT }, \
644 { "argmax", CTLTYPE_INT }, \
645 { "securelevel", CTLTYPE_INT }, \
646 { "hostname", CTLTYPE_STRING }, \
647 { "hostid", CTLTYPE_INT }, \
648 { "clockrate", CTLTYPE_STRUCT }, \
649 { "vnode", CTLTYPE_STRUCT }, \
650 { "proc", CTLTYPE_STRUCT }, \
651 { "file", CTLTYPE_STRUCT }, \
652 { "profiling", CTLTYPE_NODE }, \
653 { "posix1version", CTLTYPE_INT }, \
654 { "ngroups", CTLTYPE_INT }, \
655 { "job_control", CTLTYPE_INT }, \
656 { "saved_ids", CTLTYPE_INT }, \
657 { "boottime", CTLTYPE_STRUCT }, \
658 { "nisdomainname", CTLTYPE_STRING }, \
659 { "maxpartitions", CTLTYPE_INT }, \
660 { "kdebug", CTLTYPE_INT }, \
661 { "update", CTLTYPE_INT }, \
662 { "osreldate", CTLTYPE_INT }, \
9bccf70c 663 { "ntp_pll", CTLTYPE_NODE }, \
1c79356b
A
664 { "bootfile", CTLTYPE_STRING }, \
665 { "maxfilesperproc", CTLTYPE_INT }, \
666 { "maxprocperuid", CTLTYPE_INT }, \
667 { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
668 { "ipc", CTLTYPE_NODE }, \
669 { "dummy", CTLTYPE_INT }, \
91447636 670 { "dummy", CTLTYPE_INT }, \
1c79356b
A
671 { "usrstack", CTLTYPE_INT }, \
672 { "logsigexit", CTLTYPE_INT }, \
9bccf70c
A
673 { "symfile",CTLTYPE_STRING },\
674 { "procargs",CTLTYPE_STRUCT },\
0a7de745 675 { "dummy", CTLTYPE_INT }, /* deprecated pcsamples */ \
9bccf70c 676 { "netboot", CTLTYPE_INT }, \
0a7de745 677 { "dummy", CTLTYPE_INT }, /* deprecated: panicinfo */ \
55e303ae
A
678 { "sysv", CTLTYPE_NODE }, \
679 { "dummy", CTLTYPE_INT }, \
680 { "dummy", CTLTYPE_INT }, \
0c530ab8 681 { "exec", CTLTYPE_NODE }, \
55e303ae
A
682 { "aiomax", CTLTYPE_INT }, \
683 { "aioprocmax", CTLTYPE_INT }, \
684 { "aiothreads", CTLTYPE_INT }, \
e5568f75
A
685 { "procargs2",CTLTYPE_STRUCT }, \
686 { "corefile",CTLTYPE_STRING }, \
687 { "coredump", CTLTYPE_INT }, \
91447636
A
688 { "sugid_coredump", CTLTYPE_INT }, \
689 { "delayterm", CTLTYPE_INT }, \
690 { "shreg_private", CTLTYPE_INT }, \
691 { "proc_low_pri_io", CTLTYPE_INT }, \
692 { "low_pri_window", CTLTYPE_INT }, \
693 { "low_pri_delay", CTLTYPE_INT }, \
0c530ab8
A
694 { "posix", CTLTYPE_NODE }, \
695 { "usrstack64", CTLTYPE_QUAD }, \
696 { "nx", CTLTYPE_INT }, \
697 { "tfp", CTLTYPE_NODE }, \
698 { "procname", CTLTYPE_STRING }, \
2d21ac55
A
699 { "threadsigaltstack", CTLTYPE_INT }, \
700 { "speculative_reads_disabled", CTLTYPE_INT }, \
701 { "osversion", CTLTYPE_STRING }, \
702 { "safeboot", CTLTYPE_INT }, \
0a7de745 703 { "dummy", CTLTYPE_INT }, /* deprecated: lctx */ \
2d21ac55 704 { "rage_vnode", CTLTYPE_INT }, \
0a7de745 705 { "tty", CTLTYPE_NODE }, \
b0d623f7
A
706 { "check_openevt", CTLTYPE_INT }, \
707 { "thread_name", CTLTYPE_STRING } \
1c79356b
A
708}
709
710/*
711 * CTL_VFS identifiers
712 */
713#define CTL_VFS_NAMES { \
9bccf70c 714 { "vfsconf", CTLTYPE_STRUCT } \
1c79356b
A
715}
716
a39ff7e2 717/*
1c79356b
A
718 * KERN_PROC subtypes
719 */
0a7de745
A
720#define KERN_PROC_ALL 0 /* everything */
721#define KERN_PROC_PID 1 /* by process id */
722#define KERN_PROC_PGRP 2 /* by process group id */
723#define KERN_PROC_SESSION 3 /* by session of pid */
724#define KERN_PROC_TTY 4 /* by controlling tty */
725#define KERN_PROC_UID 5 /* by effective uid */
726#define KERN_PROC_RUID 6 /* by real uid */
727#define KERN_PROC_LCID 7 /* by login context id */
2d21ac55 728
cb323159
A
729/*
730 * KERN_VFSNSPACE subtypes
731 */
732#define KERN_VFSNSPACE_HANDLE_PROC 1
733#define KERN_VFSNSPACE_UNHANDLE_PROC 2
734
a39ff7e2
A
735#if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL)
736/*
1c79356b
A
737 * KERN_PROC subtype ops return arrays of augmented proc structures:
738 */
91447636
A
739
740struct _pcred {
0a7de745
A
741 char pc_lock[72]; /* opaque content */
742 struct ucred *pc_ucred; /* Current credentials. */
743 uid_t p_ruid; /* Real user id. */
744 uid_t p_svuid; /* Saved effective user id. */
745 gid_t p_rgid; /* Real group id. */
746 gid_t p_svgid; /* Saved effective group id. */
747 int p_refcnt; /* Number of references. */
91447636
A
748};
749
750struct _ucred {
0a7de745
A
751 int32_t cr_ref; /* reference count */
752 uid_t cr_uid; /* effective user id */
753 short cr_ngroups; /* number of groups */
754 gid_t cr_groups[NGROUPS]; /* groups */
91447636
A
755};
756
1c79356b 757struct kinfo_proc {
0a7de745
A
758 struct extern_proc kp_proc; /* proc structure */
759 struct eproc {
760 struct proc *e_paddr; /* address of proc */
761 struct session *e_sess; /* session pointer */
762 struct _pcred e_pcred; /* process credentials */
763 struct _ucred e_ucred; /* current credentials */
764 struct vmspace e_vm; /* address space */
765 pid_t e_ppid; /* parent process id */
766 pid_t e_pgid; /* process group id */
767 short e_jobc; /* job control counter */
768 dev_t e_tdev; /* controlling tty dev */
769 pid_t e_tpgid; /* tty process group id */
770 struct session *e_tsess; /* tty session pointer */
771#define WMESGLEN 7
772 char e_wmesg[WMESGLEN + 1]; /* wchan message */
773 segsz_t e_xsize; /* text size */
774 short e_xrssize; /* text rss */
775 short e_xccount; /* text references */
776 short e_xswrss;
777 int32_t e_flag;
778#define EPROC_CTTY 0x01 /* controlling tty vnode active */
779#define EPROC_SLEADER 0x02 /* session leader */
780#define COMAPT_MAXLOGNAME 12
781 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
782 int32_t e_spare[4];
1c79356b
A
783 } kp_eproc;
784};
91447636 785
b0d623f7
A
786#endif /* defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) */
787
91447636
A
788#ifdef BSD_KERNEL_PRIVATE
789#include <sys/proc_internal.h>
790
a39ff7e2 791/* LP64 version of _pcred. all pointers
91447636
A
792 * grow when we're dealing with a 64-bit process.
793 * WARNING - keep in sync with _pcred
794 */
795
b0d623f7 796struct user32_pcred {
f427ee49
A
797 char pc_lock[72]; /* opaque content */
798 user32_addr_t pc_ucred; /* Current credentials. */
799 uid_t p_ruid; /* Real user id. */
800 uid_t p_svuid; /* Saved effective user id. */
801 gid_t p_rgid; /* Real group id. */
802 gid_t p_svgid; /* Saved effective group id. */
803 int p_refcnt; /* Number of references. */
b0d623f7
A
804};
805struct user64_pcred {
f427ee49
A
806 char pc_lock[72]; /* opaque content */
807 user64_addr_t pc_ucred; /* Current credentials. */
808 uid_t p_ruid; /* Real user id. */
809 uid_t p_svuid; /* Saved effective user id. */
810 gid_t p_rgid; /* Real group id. */
811 gid_t p_svgid; /* Saved effective group id. */
812 int p_refcnt; /* Number of references. */
91447636
A
813};
814
a39ff7e2 815/* LP64 version of kinfo_proc. all pointers
91447636
A
816 * grow when we're dealing with a 64-bit process.
817 * WARNING - keep in sync with kinfo_proc
818 */
b0d623f7 819struct user32_kinfo_proc {
0a7de745
A
820 struct user32_extern_proc kp_proc; /* proc structure */
821 struct user32_eproc {
822 user32_addr_t e_paddr; /* address of proc */
823 user32_addr_t e_sess; /* session pointer */
824 struct user32_pcred e_pcred; /* process credentials */
825 struct _ucred e_ucred; /* current credentials */
826 struct user32_vmspace e_vm; /* address space */
827 pid_t e_ppid; /* parent process id */
828 pid_t e_pgid; /* process group id */
f427ee49 829 int e_jobc; /* job control counter */
0a7de745
A
830 dev_t e_tdev; /* controlling tty dev */
831 pid_t e_tpgid; /* tty process group id */
832 user32_addr_t e_tsess; /* tty session pointer */
833 char e_wmesg[WMESGLEN + 1]; /* wchan message */
834 segsz_t e_xsize; /* text size */
835 short e_xrssize; /* text rss */
836 short e_xccount; /* text references */
837 short e_xswrss;
838 int32_t e_flag;
839 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
840 int32_t e_spare[4];
b0d623f7
A
841 } kp_eproc;
842};
843struct user64_kinfo_proc {
0a7de745
A
844 struct user64_extern_proc kp_proc; /* proc structure */
845 struct user64_eproc {
846 user_addr_t e_paddr; /* address of proc */
847 user_addr_t e_sess; /* session pointer */
848 struct user64_pcred e_pcred; /* process credentials */
849 struct _ucred e_ucred; /* current credentials */
850 struct user_vmspace e_vm; /* address space */
851 pid_t e_ppid; /* parent process id */
852 pid_t e_pgid; /* process group id */
f427ee49 853 int e_jobc; /* job control counter */
0a7de745
A
854 dev_t e_tdev; /* controlling tty dev */
855 pid_t e_tpgid; /* tty process group id */
856 user64_addr_t e_tsess __attribute((aligned(8))); /* tty session pointer */
857 char e_wmesg[WMESGLEN + 1]; /* wchan message */
858 segsz_t e_xsize; /* text size */
859 short e_xrssize; /* text rss */
860 short e_xccount; /* text references */
861 short e_xswrss;
862 int32_t e_flag;
863 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
864 int32_t e_spare[4];
91447636
A
865 } kp_eproc;
866};
867
0a7de745 868#endif /* BSD_KERNEL_PRIVATE */
91447636 869
1c79356b
A
870/*
871 * KERN_IPC identifiers
872 */
0a7de745
A
873#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
874#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
875#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
876#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
877#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
878#define KIPC_MAX_HDR 6 /* int: max total length of headers */
879#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
880#define KIPC_MBSTAT 8 /* struct: mbuf usage statistics */
881#define KIPC_NMBCLUSTERS 9 /* int: maximum mbuf clusters */
882#define KIPC_SOQLIMITCOMPAT 10 /* int: socket queue limit */
1c79356b
A
883
884/*
885 * CTL_VM identifiers
886 */
0a7de745
A
887#define VM_METER 1 /* struct vmmeter */
888#define VM_LOADAVG 2 /* struct loadavg */
91447636
A
889/*
890 * Note: "3" was skipped sometime ago and should probably remain unused
891 * to avoid any new entry from being accepted by older kernels...
a39ff7e2 892 */
0a7de745
A
893#define VM_MACHFACTOR 4 /* struct loadavg with mach factor*/
894#define VM_SWAPUSAGE 5 /* total swap usage */
895#define VM_MAXID 6 /* number of valid vm ids */
1c79356b 896
0a7de745 897#define CTL_VM_NAMES { \
1c79356b
A
898 { 0, 0 }, \
899 { "vmmeter", CTLTYPE_STRUCT }, \
91447636
A
900 { "loadavg", CTLTYPE_STRUCT }, \
901 { 0, 0 }, /* placeholder for "3" (see comment above) */ \
2d21ac55 902 { "dummy", CTLTYPE_INT }, \
91447636 903 { "swapusage", CTLTYPE_STRUCT } \
1c79356b
A
904}
905
91447636 906struct xsw_usage {
0a7de745
A
907 u_int64_t xsu_total;
908 u_int64_t xsu_avail;
909 u_int64_t xsu_used;
910 u_int32_t xsu_pagesize;
911 boolean_t xsu_encrypted;
91447636
A
912};
913
914#ifdef __APPLE_API_PRIVATE
915/* Load average structure. Use of fixpt_t assume <sys/types.h> in scope. */
916/* XXX perhaps we should protect fixpt_t, and define it here (or discard it) */
917struct loadavg {
0a7de745
A
918 fixpt_t ldavg[3];
919 long fscale;
91447636
A
920};
921extern struct loadavg averunnable;
0a7de745 922#define LSCALE 1000 /* scaling for "fixed point" arithmetic */
91447636 923
91447636
A
924#ifdef BSD_KERNEL_PRIVATE
925
b0d623f7 926struct user32_loadavg {
0a7de745
A
927 fixpt_t ldavg[3];
928 user32_long_t fscale;
b0d623f7
A
929};
930
931struct user64_loadavg {
0a7de745
A
932 fixpt_t ldavg[3];
933 user64_long_t fscale;
91447636
A
934};
935
0a7de745 936#endif /* BSD_KERNEL_PRIVATE */
91447636
A
937#endif /* __APPLE_API_PRIVATE */
938
939
1c79356b
A
940/*
941 * CTL_HW identifiers
942 */
f427ee49
A
943#define HW_MACHINE 1 /* string: machine class (deprecated: use HW_PRODUCT) */
944#define HW_MODEL 2 /* string: specific machine model (deprecated: use HW_TARGET) */
0a7de745
A
945#define HW_NCPU 3 /* int: number of cpus */
946#define HW_BYTEORDER 4 /* int: machine byte order */
947#define HW_PHYSMEM 5 /* int: total memory */
948#define HW_USERMEM 6 /* int: non-kernel memory */
949#define HW_PAGESIZE 7 /* int: software page size */
950#define HW_DISKNAMES 8 /* strings: disk drive names */
951#define HW_DISKSTATS 9 /* struct: diskstats[] */
952#define HW_EPOCH 10 /* int: 0 for Legacy, else NewWorld */
953#define HW_FLOATINGPT 11 /* int: has HW floating point? */
954#define HW_MACHINE_ARCH 12 /* string: machine architecture */
955#define HW_VECTORUNIT 13 /* int: has HW vector unit? */
956#define HW_BUS_FREQ 14 /* int: Bus Frequency */
957#define HW_CPU_FREQ 15 /* int: CPU Frequency */
958#define HW_CACHELINE 16 /* int: Cache Line Size in Bytes */
959#define HW_L1ICACHESIZE 17 /* int: L1 I Cache Size in Bytes */
960#define HW_L1DCACHESIZE 18 /* int: L1 D Cache Size in Bytes */
961#define HW_L2SETTINGS 19 /* int: L2 Cache Settings */
962#define HW_L2CACHESIZE 20 /* int: L2 Cache Size in Bytes */
963#define HW_L3SETTINGS 21 /* int: L3 Cache Settings */
964#define HW_L3CACHESIZE 22 /* int: L3 Cache Size in Bytes */
965#define HW_TB_FREQ 23 /* int: Bus Frequency */
966#define HW_MEMSIZE 24 /* uint64_t: physical ram size */
967#define HW_AVAILCPU 25 /* int: number of available CPUs */
f427ee49
A
968#define HW_TARGET 26 /* string: model identifier */
969#define HW_PRODUCT 27 /* string: product identifier */
970#define HW_MAXID 28 /* number of valid hw ids */
1c79356b
A
971
972#define CTL_HW_NAMES { \
973 { 0, 0 }, \
f427ee49
A
974 { "machine", CTLTYPE_STRING }, /* Deprecated: use hw.product */ \
975 { "model", CTLTYPE_STRING }, /* Deprecated: use hw.target */ \
1c79356b
A
976 { "ncpu", CTLTYPE_INT }, \
977 { "byteorder", CTLTYPE_INT }, \
978 { "physmem", CTLTYPE_INT }, \
979 { "usermem", CTLTYPE_INT }, \
980 { "pagesize", CTLTYPE_INT }, \
981 { "disknames", CTLTYPE_STRUCT }, \
982 { "diskstats", CTLTYPE_STRUCT }, \
983 { "epoch", CTLTYPE_INT }, \
984 { "floatingpoint", CTLTYPE_INT }, \
985 { "machinearch", CTLTYPE_STRING }, \
986 { "vectorunit", CTLTYPE_INT }, \
987 { "busfrequency", CTLTYPE_INT }, \
988 { "cpufrequency", CTLTYPE_INT }, \
989 { "cachelinesize", CTLTYPE_INT }, \
990 { "l1icachesize", CTLTYPE_INT }, \
991 { "l1dcachesize", CTLTYPE_INT }, \
992 { "l2settings", CTLTYPE_INT }, \
993 { "l2cachesize", CTLTYPE_INT }, \
994 { "l3settings", CTLTYPE_INT }, \
90556fb8 995 { "l3cachesize", CTLTYPE_INT }, \
43866e37
A
996 { "tbfrequency", CTLTYPE_INT }, \
997 { "memsize", CTLTYPE_QUAD }, \
f427ee49
A
998 { "availcpu", CTLTYPE_INT }, \
999 { "target", CTLTYPE_STRING }, \
1000 { "product", CTLTYPE_STRING }, \
1c79356b
A
1001}
1002
43866e37 1003/*
2d21ac55
A
1004 * XXX This information should be moved to the man page.
1005 *
91447636 1006 * These are the support HW selectors for sysctlbyname. Parameters that are byte counts or frequencies are 64 bit numbers.
43866e37
A
1007 * All other parameters are 32 bit numbers.
1008 *
1009 * hw.memsize - The number of bytes of physical memory in the system.
1010 *
91447636 1011 * hw.ncpu - The maximum number of processors that could be available this boot.
43866e37
A
1012 * Use this value for sizing of static per processor arrays; i.e. processor load statistics.
1013 *
91447636 1014 * hw.activecpu - The number of processors currently available for executing threads.
43866e37
A
1015 * Use this number to determine the number threads to create in SMP aware applications.
1016 * This number can change when power management modes are changed.
91447636
A
1017 *
1018 * hw.physicalcpu - The number of physical processors available in the current power management mode.
1019 * hw.physicalcpu_max - The maximum number of physical processors that could be available this boot
1020 *
1021 * hw.logicalcpu - The number of logical processors available in the current power management mode.
1022 * hw.logicalcpu_max - The maximum number of logical processors that could be available this boot
1023 *
43866e37
A
1024 * hw.tbfrequency - This gives the time base frequency used by the OS and is the basis of all timing services.
1025 * In general is is better to use mach's or higher level timing services, but this value
1026 * is needed to convert the PPC Time Base registers to real time.
1027 *
1028 * hw.cpufrequency - These values provide the current, min and max cpu frequency. The min and max are for
1029 * hw.cpufrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
1030 * hw.cpufrequency_min - All frequencies are in Hz.
1031 *
1032 * hw.busfrequency - These values provide the current, min and max bus frequency. The min and max are for
1033 * hw.busfrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
1034 * hw.busfrequency_min - All frequencies are in Hz.
1035 *
1036 * hw.cputype - These values provide the mach-o cpu type and subtype. A complete list is in <mach/machine.h>
1037 * hw.cpusubtype - These values should be used to determine what processor family the running cpu is from so that
1038 * the best binary can be chosen, or the best dynamic code generated. They should not be used
1039 * to determine if a given processor feature is available.
91447636
A
1040 * hw.cputhreadtype - This value will be present if the processor supports threads. Like hw.cpusubtype this selector
1041 * should not be used to infer features, and only used to name the processors thread architecture.
1042 * The values are defined in <mach/machine.h>
43866e37
A
1043 *
1044 * hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little.
1045 *
1046 * hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system.
1047 *
1048 * hw.cachelinesize - Gives the size in bytes of the processor's cache lines.
1049 * This value should be use to control the strides of loops that use cache control instructions
1050 * like dcbz, dcbt or dcbst.
1051 *
1052 * hw.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present
1053 * hw.l1icachesize - then the selector will return and error.
1054 * hw.l2cachesize -
1055 * hw.l3cachesize -
1056 *
2d21ac55 1057 * hw.packages - Gives the number of processor packages.
43866e37 1058 *
a39ff7e2 1059 * These are the selectors for optional processor features for specific processors. Selectors that return errors are not support
0c530ab8
A
1060 * on the system. Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help .
1061 * performance. Future versions of these selectors may return larger values as necessary so it is best to test for non zero.
1062 *
1063 * For PowerPC:
43866e37
A
1064 *
1065 * hw.optional.floatingpoint - Floating Point Instructions
1066 * hw.optional.altivec - AltiVec Instructions
1067 * hw.optional.graphicsops - Graphics Operations
1068 * hw.optional.64bitops - 64-bit Instructions
1069 * hw.optional.fsqrt - HW Floating Point Square Root Instruction
1070 * hw.optional.stfiwx - Store Floating Point as Integer Word Indexed Instructions
1071 * hw.optional.dcba - Data Cache Block Allocate Instruction
1072 * hw.optional.datastreams - Data Streams Instructions
1073 * hw.optional.dcbtstreams - Data Cache Block Touch Steams Instruction Form
1074 *
0c530ab8 1075 * For x86 Architecture:
a39ff7e2 1076 *
2d21ac55
A
1077 * hw.optional.floatingpoint - Floating Point Instructions
1078 * hw.optional.mmx - Original MMX vector instructions
1079 * hw.optional.sse - Streaming SIMD Extensions
1080 * hw.optional.sse2 - Streaming SIMD Extensions 2
1081 * hw.optional.sse3 - Streaming SIMD Extensions 3
1082 * hw.optional.supplementalsse3 - Supplemental Streaming SIMD Extensions 3
1083 * hw.optional.x86_64 - 64-bit support
43866e37
A
1084 */
1085
1086
1c79356b
A
1087/*
1088 * CTL_USER definitions
1089 */
0a7de745
A
1090#define USER_CS_PATH 1 /* string: _CS_PATH */
1091#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
1092#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
1093#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
1094#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
1095#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
1096#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
1097#define USER_LINE_MAX 8 /* int: LINE_MAX */
1098#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
1099#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
1100#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
1101#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
1102#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
1103#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
1104#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
1105#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
1106#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
1107#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
1108#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
1109#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
1110#define USER_MAXID 21 /* number of valid user ids */
1111
1112#define CTL_USER_NAMES { \
1c79356b
A
1113 { 0, 0 }, \
1114 { "cs_path", CTLTYPE_STRING }, \
1115 { "bc_base_max", CTLTYPE_INT }, \
1116 { "bc_dim_max", CTLTYPE_INT }, \
1117 { "bc_scale_max", CTLTYPE_INT }, \
1118 { "bc_string_max", CTLTYPE_INT }, \
1119 { "coll_weights_max", CTLTYPE_INT }, \
1120 { "expr_nest_max", CTLTYPE_INT }, \
1121 { "line_max", CTLTYPE_INT }, \
1122 { "re_dup_max", CTLTYPE_INT }, \
1123 { "posix2_version", CTLTYPE_INT }, \
1124 { "posix2_c_bind", CTLTYPE_INT }, \
1125 { "posix2_c_dev", CTLTYPE_INT }, \
1126 { "posix2_char_term", CTLTYPE_INT }, \
1127 { "posix2_fort_dev", CTLTYPE_INT }, \
1128 { "posix2_fort_run", CTLTYPE_INT }, \
1129 { "posix2_localedef", CTLTYPE_INT }, \
1130 { "posix2_sw_dev", CTLTYPE_INT }, \
1131 { "posix2_upe", CTLTYPE_INT }, \
1132 { "stream_max", CTLTYPE_INT }, \
9bccf70c 1133 { "tzname_max", CTLTYPE_INT } \
1c79356b
A
1134}
1135
1136
1137
1138/*
1139 * CTL_DEBUG definitions
1140 *
1141 * Second level identifier specifies which debug variable.
1142 * Third level identifier specifies which stucture component.
1143 */
0a7de745
A
1144#define CTL_DEBUG_NAME 0 /* string: variable name */
1145#define CTL_DEBUG_VALUE 1 /* int: variable value */
1146#define CTL_DEBUG_MAXID 20
1c79356b 1147
2d21ac55 1148
f427ee49 1149#if (CTL_MAXID != 9) || (KERN_MAXID != 72) || (VM_MAXID != 6) || (HW_MAXID != 28) || (USER_MAXID != 21) || (CTL_DEBUG_MAXID != 20)
2d21ac55
A
1150#error Use the SYSCTL_*() macros and OID_AUTO instead!
1151#endif
1152
1153
0a7de745 1154#ifdef KERNEL
1c79356b 1155
91447636 1156#ifdef BSD_KERNEL_PRIVATE
0a7de745
A
1157extern char machine[];
1158extern char osrelease[];
1159extern char ostype[];
1160extern char osversion[];
1161extern char osproductversion[];
1162extern char osbuild_config[];
1163#if defined(XNU_TARGET_OS_BRIDGE)
1164/*
1165 * 15 characters at maximum so both the productversion
1166 * and the build version can fit in the panic header
1167 * osversion field with the formatting requirements.
1168 */
1169#define MACOS_VERS_LEN 15
1170
1171extern char macosproductversion[];
1172extern char macosversion[];
1173#endif
1c79356b
A
1174
1175struct linker_set;
1176
0a7de745
A
1177void sysctl_register_set(const char *set);
1178void sysctl_unregister_set(const char *set);
1179void sysctl_mib_init(void);
91447636
A
1180
1181int sysctl_int(user_addr_t, size_t *, user_addr_t, size_t, int *);
91447636 1182int sysctl_quad(user_addr_t, size_t *, user_addr_t, size_t, quad_t *);
2d21ac55 1183
39037602 1184void sysctl_early_init(void);
2d21ac55 1185
91447636 1186#endif /* BSD_KERNEL_PRIVATE */
0a7de745 1187#else /* !KERNEL */
1c79356b
A
1188
1189__BEGIN_DECLS
0a7de745
A
1190int sysctl(int *, u_int, void *, size_t *, void *, size_t);
1191int sysctlbyname(const char *, void *, size_t *, void *, size_t);
1192int sysctlnametomib(const char *, int *, size_t *);
1c79356b 1193__END_DECLS
91447636 1194
0a7de745 1195#endif /* KERNEL */
91447636
A
1196
1197
1198#endif /* SYSCTL_DEF_ENABLED */
1199
1200
0a7de745 1201#endif /* !_SYS_SYSCTL_H_ */