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