xref: /xnu-11215/bsd/sys/sysctl.h (revision 8d741a5d)
1 /*
2  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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  */
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  */
72 
73 #ifndef _SYS_SYSCTL_H_
74 #define _SYS_SYSCTL_H_
75 
76 /*
77  * These are for the eproc structure defined below.
78  */
79 #include <sys/cdefs.h>
80 
81 #include <sys/appleapiopts.h>
82 #ifndef KERNEL
83 #include <sys/time.h>
84 #include <sys/ucred.h>
85 #else
86 #ifdef XNU_KERNEL_PRIVATE
87 #include <kern/startup.h>
88 #include <libkern/section_keywords.h>
89 #include <string.h>
90 #else
91 #include <libkern/sysctl.h>
92 #include <os/base.h>
93 #endif /* XNU_KERNEL_PRIVATE */
94 #endif /* KERNEL */
95 
96 #include <sys/proc.h>
97 #include <sys/vm.h>
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 
108 #define CTL_MAXNAME     12      /* largest number of components supported */
109 
110 /*
111  * Each subsystem defined by sysctl defines a list of variables
112  * for that subsystem. Each name is either a node with further
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.
116  *
117  * When declaring new sysctl names, use the CTLFLAG_LOCKED flag in the
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
122  * and will be protected by a global mutex.
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).
143  */
144 struct ctlname {
145 	char    *ctl_name;      /* subsystem name */
146 	int     ctl_type;       /* type of name */
147 };
148 
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 */
168 #if XNU_KERNEL_PRIVATE
169 #define CTLFLAG_PERMANENT   0x00200000      /* permanent sysctl_oid */
170 #endif
171 #define CTLFLAG_EXPERIMENT 0x00100000 /* Allows writing w/ the trial experiment entitlement. */
172 
173 /*
174  * USE THIS instead of a hardwired number from the categories below
175  * to get dynamically assigned sysctl entries using the linker-set
176  * technology. This is the way nearly all new sysctl variables should
177  * be implemented.
178  *
179  * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
180  *
181  * Note that linker set technology will automatically register all nodes
182  * declared like this on kernel initialization, UNLESS they are defined
183  * in I/O-Kit. In this case, you have to call sysctl_register_oid()
184  * manually - just like in a KEXT.
185  */
186 #define OID_AUTO              (-1)
187 #if XNU_KERNEL_PRIVATE
188 /*
189  * Used to allow for most of the core kernel sysctl OIDs to be in immutable
190  * memory. The nodes that can be extensible have a fake first node with this
191  * particular oid_number which hangs a second mutable list from this node.
192  *
193  * This node is always first when it is used
194  */
195 #define OID_MUTABLE_ANCHOR    (INT_MIN)
196 #endif
197 #define OID_AUTO_START        100 /* conventional */
198 
199 #ifdef KERNEL
200 #define SYSCTL_HANDLER_ARGS \
201 	(struct sysctl_oid *oidp __unused, void *arg1 __unused, int arg2 __unused, \
202 	struct sysctl_req *req)
203 
204 
205 /*
206  * This describes the access space for a sysctl request.  This is needed
207  * so that we can use the interface from the kernel or from user-space.
208  */
209 struct sysctl_req {
210 	struct proc     *p;
211 	int             lock;
212 	user_addr_t     oldptr;         /* pointer to user supplied buffer */
213 	size_t          oldlen;         /* user buffer length (also returned) */
214 	size_t          oldidx;         /* total data iteratively copied out */
215 	int             (*oldfunc)(struct sysctl_req *, const void *, size_t);
216 	user_addr_t     newptr;         /* buffer containing new value */
217 	size_t          newlen;         /* length of new value */
218 	size_t          newidx;         /* total data iteratively copied in */
219 	int             (*newfunc)(struct sysctl_req *, void *, size_t);
220 };
221 
222 SLIST_HEAD(sysctl_oid_list, sysctl_oid);
223 
224 #define SYSCTL_OID_VERSION      1       /* current OID structure version */
225 
226 /*
227  * This describes one "oid" in the MIB tree.  Potentially more nodes can
228  * be hidden behind it, expanded by the handler.
229  *
230  * NOTES:	We implement binary comparibility between CTLFLAG_OID2 and
231  *		pre-CTLFLAG_OID2 structure in sysctl_register_oid() and in
232  *		sysctl_unregister_oid() using the fact that the fields up
233  *		to oid_fmt are unchanged, and that the field immediately
234  *		following is on an alignment boundary following a pointer
235  *		type and is also a pointer.  This lets us get the previous
236  *		size of the structure, and the copy-cut-off point, using
237  *		the offsetof() language primitive, and these values  are
238  *		used in conjunction with the fact that earlier and future
239  *		statically compiled sysctl_oid structures are declared via
240  *		macros.  This lets us overload the macros so that the addition
241  *		of the CTLFLAG_OID2 in newly compiled code containing sysctl
242  *		node declarations, subsequently allowing us to to avoid
243  *		changing the KPI used for non-static (un)registration in
244  *		KEXTs.
245  *
246  *		Non CTLFLAG_OID2 based sysctls are deprecated and unavailable
247  *		to non Intel platforms.
248  *
249  *		This depends on the fact that people declare SYSCTLs,
250  *		rather than declaring sysctl_oid structures.  All new code
251  *		should avoid declaring struct sysctl_oid's directly without
252  *		the macros; the current risk for this is limited to losing
253  *		your description field and ending up with a malloc'ed copy,
254  *		as if it were a legacy binary static declaration via SYSCTL;
255  *		in the future, we may deprecate access to a named structure
256  *		type in third party code.  Use the macros, or our code will
257  *		end up with compile errors when that happens.
258  *
259  *		Please try to include a long description of the field in any
260  *		new sysctl declarations (all the macros support this).  This
261  *		field may be the only human readable documentation your users
262  *		get for your sysctl.
263  */
264 struct sysctl_oid {
265 	struct sysctl_oid_list * OS_PTRAUTH_SIGNED_PTR("sysctl_oid.oid_parent") oid_parent;
266 	SLIST_ENTRY(sysctl_oid) oid_link;
267 	int             oid_number;
268 	int             oid_kind;
269 	void            *oid_arg1;
270 	int             oid_arg2;
271 	const char      *oid_name;
272 	int             (*oid_handler)SYSCTL_HANDLER_ARGS;
273 	const char      *oid_fmt;
274 	const char      *oid_descr; /* offsetof() field / long description */
275 	int             oid_version;
276 	int             oid_refcnt;
277 };
278 
279 #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
280 #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
281 
282 typedef int (* sysctl_handler_t) SYSCTL_HANDLER_ARGS;
283 
284 __BEGIN_DECLS
285 
286 /* old interface */
287 int sysctl_handle_int SYSCTL_HANDLER_ARGS;
288 int sysctl_handle_long SYSCTL_HANDLER_ARGS;
289 int sysctl_handle_quad SYSCTL_HANDLER_ARGS;
290 int sysctl_handle_int2quad SYSCTL_HANDLER_ARGS;
291 int sysctl_handle_string SYSCTL_HANDLER_ARGS;
292 int sysctl_handle_opaque SYSCTL_HANDLER_ARGS;
293 /* new interface */
294 int sysctl_io_number(struct sysctl_req *req, long long bigValue, size_t valueSize, void *pValue, int *changed);
295 int sysctl_io_string(struct sysctl_req *req, char *pValue, size_t valueSize, int trunc, int *changed);
296 int sysctl_io_opaque(struct sysctl_req *req, void *pValue, size_t valueSize, int *changed);
297 
298 /*
299  * These functions are used to add/remove an oid from the mib.
300  */
301 void sysctl_register_oid(struct sysctl_oid *oidp);
302 void sysctl_unregister_oid(struct sysctl_oid *oidp);
303 
304 #define nvram_osenvironment "osenvironment"
305 void sysctl_set_osenvironment(unsigned int size, const void* value);
306 void sysctl_unblock_osenvironment(void);
307 
308 /* Deprecated */
309 void sysctl_register_fixed(void) __deprecated;
310 
311 __END_DECLS
312 
313 /* Declare an oid to allow child oids to be added to it. */
314 #define SYSCTL_DECL(name)                                       \
315 	extern struct sysctl_oid_list sysctl_##name##_children
316 
317 /*
318  * Macros to define sysctl entries.  Which to use?  Pure data that are
319  * returned without modification, SYSCTL_<data type> is for you, like
320  * SYSCTL_QUAD for a 64-bit value.  When you want to run a handler of your
321  * own, SYSCTL_PROC.
322  *
323  * parent:	parent in name hierarchy (e.g. _kern for "kern")
324  * nbr:		ID.  Almost certainly OID_AUTO ("pick one for me") for you.
325  * name:	name for this particular item (e.g. "thesysctl" for "kern.thesysctl")
326  * kind/access: Control flags (CTLFLAG_*).  Some notable options include:
327  *                      CTLFLAG_ANYBODY:        non-root users allowed
328  *                      CTLFLAG_MASKED:	        don't show in sysctl listing in userland
329  *                      CTLFLAG_LOCKED:		does own locking (no additional protection needed)
330  *                      CTLFLAG_KERN:		valid inside kernel (best avoided generally)
331  *                      CTLFLAG_WR:		"new" value accepted
332  * a1, a2:	entry-data, passed to handler (see specific macros)
333  * Format String: Tells "sysctl" tool how to print data from this entry.
334  *	                "A" - string
335  *	                "I" - list of integers. "IU" - list of unsigned integers. space-separated.
336  *	                "-" - do not print
337  *	                "L" - longs, as ints with I
338  *			"P" - pointer
339  *                      "Q" - quads
340  *                      "S","T" - clock info, see sysctl.c in system_cmds (you probably don't need this)
341  * Description: unused
342  */
343 
344 
345 /* This constructs a "raw" MIB oid. */
346 #define SYSCTL_STRUCT_INIT(parent, nbr, name, kind, a1, a2, fn, fmt, desc) {    \
347 	    .oid_parent     = &sysctl_##parent##_children,                      \
348 	    .oid_number     = nbr,                                              \
349 	    .oid_kind       = (int)(kind | CTLFLAG_OID2),                       \
350 	    .oid_arg1       = a1,                                               \
351 	    .oid_arg2       = (int)(a2),                                        \
352 	    .oid_name       = #name,                                            \
353 	    .oid_handler    = fn,                                               \
354 	    .oid_fmt        = fmt,                                              \
355 	    .oid_descr      = desc,                                             \
356 	    .oid_version    = SYSCTL_OID_VERSION,                               \
357 	}
358 
359 #define __SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
360 	struct sysctl_oid sysctl_##parent##_##name = SYSCTL_STRUCT_INIT(\
361 	    parent, nbr, name, kind, a1, a2, handler, fmt, descr)
362 
363 #if XNU_KERNEL_PRIVATE
364 
365 /*
366  * Core kernel registers sysctls before lockdown and protects those entries
367  * in immutable memory.
368  *
369  * When a node needs to support dynamic extension after lockdown, it needs to be
370  * declared with SYSCTL_EXTENSIBLE_NODE() to insert a dummy "OID_MUTABLE_ANCHOR"
371  * node in this node chain which will allow extensibility.
372  *
373  * OIDs that are to be inserted dynamically based on system properties that
374  * aren't known at compile time, have three options, in increasing order of
375  * unsafety:
376  *
377  * - The OID can use the CTLFLAG_NOAUTO flag. Such entries aren't inserted to
378  *   the sysctl tree automatically but will be made read-only at lock down.
379  *
380  *   Such entries must be inserted in the STARTUP_SUB_SYSCTL "Middle" phase
381  *   using sysctl_register_oid_early().
382  *
383  * - The OID can be always registered and test whether it is ready to operate.
384  *   When it is not, it must return ENOENT which simulates an absent entry.
385  *
386  *   This however has the downside that the entry is still resolvable as an MIB
387  *   or listed in `sysctl -a` when it isn't masked.
388  *
389  *   This is acceptable for sysctls that will become valid quickly during boot
390  *   (but after lockdown).
391  *
392  * - SYSCTL_OID_MANUAL / SYSCTL_NODE_MANUAL can be used for completely
393  *   dynamic/manual oid registration. Such nodes must be registered with
394  *   sysctl_register_oid() after lockdown.
395  *
396  *   This is the least preferred solution.
397  */
398 
399 __BEGIN_DECLS
400 void sysctl_register_oid_early(struct sysctl_oid *oidp);
401 __END_DECLS
402 
403 #define SYSCTL_OID_MANUAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
404 	__XNU_PRIVATE_EXTERN                                                    \
405 	__SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)
406 
407 #define SYSCTL_NODE_MANUAL(parent, nbr, name, access, handler, descr)           \
408 	struct sysctl_oid_list sysctl_##parent##_##name##_children;             \
409 	__XNU_PRIVATE_EXTERN                                                    \
410 	__SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access,                    \
411 	    &sysctl_##parent##_##name##_children, 0, handler, "N", descr);
412 
413 #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)        \
414 	__security_const_late __XNU_PRIVATE_EXTERN                              \
415 	__SYSCTL_OID(parent, nbr, name, CTLFLAG_PERMANENT|kind,                 \
416 	    a1, a2, handler, fmt, descr);                                       \
417 	__STARTUP_ARG(sysctl_##parent, _##name,                                 \
418 	    SYSCTL, STARTUP_RANK_SECOND, sysctl_register_oid_early,             \
419 	    &sysctl_##parent##_##name)
420 
421 #define __SYSCTL_NODE(parent, nbr, name, access, handler, descr)                \
422 	__security_const_late                                                   \
423 	struct sysctl_oid_list sysctl_##parent##_##name##_children;             \
424 	__security_const_late __XNU_PRIVATE_EXTERN                              \
425 	__SYSCTL_OID(parent, nbr, name, CTLFLAG_PERMANENT|CTLTYPE_NODE|access,  \
426 	    &sysctl_##parent##_##name##_children, 0, handler, "N", descr);      \
427 	__STARTUP_ARG(sysctl_##parent, _##name,                                 \
428 	    SYSCTL, STARTUP_RANK_FIRST, sysctl_register_oid_early,              \
429 	    &sysctl_##parent##_##name)
430 
431 #define __SYSCTL_EXTENSION_NODE(name)                                           \
432 	static __security_read_write                                            \
433 	struct sysctl_oid_list sysctl_##name##_children_mutable;                \
434 	static __security_const_late                                            \
435 	struct sysctl_oid sysctl_##name##_wranchor = {                          \
436 	    .oid_parent     = &sysctl_##name##_children,                        \
437 	    .oid_number     = OID_MUTABLE_ANCHOR,                               \
438 	    .oid_kind       = CTLFLAG_OID2 | CTLFLAG_PERMANENT,                 \
439 	    .oid_arg1       = &sysctl_##name##_children_mutable,                \
440 	    .oid_name       = "__anchor__(" #name ")",                          \
441 	    .oid_version    = SYSCTL_OID_VERSION,                               \
442 	};                                                                      \
443 	__STARTUP_ARG(sysctl_##name, _wranchor,                                 \
444 	    SYSCTL, STARTUP_RANK_LAST, sysctl_register_oid_early,               \
445 	    &sysctl_##name##_wranchor)
446 
447 #define SYSCTL_NODE(parent, nbr, name, access, handler, descr)                  \
448 	__XNU_PRIVATE_EXTERN                                                    \
449 	__SYSCTL_NODE(parent, nbr, name, access, handler, descr)
450 
451 #define SYSCTL_EXTENSIBLE_NODE(parent, nbr, name, access, handler, descr)       \
452 	__SYSCTL_NODE(parent, nbr, name, access, handler, descr);               \
453 	__SYSCTL_EXTENSION_NODE(parent##_##name)
454 #else
455 #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
456 	__SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)
457 
458 /* This constructs a node from which other oids can hang. */
459 #define SYSCTL_NODE(parent, nbr, name, access, handler, descr)                  \
460 	struct sysctl_oid_list sysctl_##parent##_##name##_children;             \
461 	SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access,                      \
462 	    &sysctl_##parent##_##name##_children, 0, handler, "N", descr)
463 #endif /* XNU_KERNEL_PRIVATE */
464 
465 /* Oid for a string.  len can be 0 to indicate '\0' termination. */
466 #define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
467 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|access, \
468 	    arg, len, sysctl_handle_string, "A", descr)
469 
470 #define SYSCTL_COMPAT_INT(parent, nbr, name, access, ptr, val, descr) \
471 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
472 	    ptr, val, sysctl_handle_int, "I", descr)
473 
474 #define SYSCTL_COMPAT_UINT(parent, nbr, name, access, ptr, val, descr) \
475 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
476 	    ptr, val, sysctl_handle_int, "IU", descr)
477 
478 /* Oid for an int.  If ptr is NULL, val is returned. */
479 #define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
480 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
481 	    ptr, val, sysctl_handle_int, "I", descr); \
482 	_Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(int), \
483 	    "must be integer sized");
484 
485 /* Oid for an unsigned int.  If ptr is NULL, val is returned. */
486 #define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \
487 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
488 	    ptr, val, sysctl_handle_int, "IU", descr); \
489 	_Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(unsigned int), \
490 	    "must be integer sized");
491 
492 /* Oid for a long.  The pointer must be non NULL. */
493 #define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \
494 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
495 	    ptr, 0, sysctl_handle_long, "L", descr); \
496 	_Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(long), \
497 	    "must be long sized");
498 
499 /* Oid for a unsigned long.  The pointer must be non NULL. */
500 #define SYSCTL_ULONG(parent, nbr, name, access, ptr, descr) \
501 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
502 	    ptr, 0, sysctl_handle_long, "LU", descr); \
503 	_Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(unsigned long), \
504 	    "must be long sized");
505 
506 /* Oid for a quad.  The pointer must be non NULL. */
507 #define SYSCTL_QUAD(parent, nbr, name, access, ptr, descr) \
508 	SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
509 	    ptr, 0, sysctl_handle_quad, "Q", descr); \
510 	_Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(long long), \
511 	    "must be long long sized");
512 
513 /* Oid for an opaque object.  Specified by a pointer and a length. */
514 #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
515 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
516 	        ptr, len, sysctl_handle_opaque, fmt, descr)
517 
518 /* Oid for a struct.  Specified by a pointer and a type. */
519 #define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
520 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
521 	    ptr, sizeof(struct type), sysctl_handle_opaque, \
522 	    "S," #type, descr)
523 
524 /*
525  * Oid for a procedure.  Specified by a pointer and an arg.
526  * CTLTYPE_* macros can determine how the "sysctl" tool deals with
527  * input (e.g. converting to int).
528  */
529 #define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
530 	SYSCTL_OID(parent, nbr, name, access, \
531 	    ptr, arg, handler, fmt, descr)
532 
533 /*
534  * The EXPERIMENT macros below expose values for on-device experimentation (A/B testing) via Trial.
535  * These values will be set shortly after boot by the KRExperiments framework based on any
536  * active experiments on the device.
537  * Values exposed via these macros are still normal sysctls and can be set by the superuser in the
538  * development or debug kernel. However, on the release kernel they can ONLY be set by processes
539  * with the com.apple.private.write-kr-experiment-factors entitlement.
540  * In addition, for numeric types, special macros are provided that enforce a valid range for the value (inclusive)
541  * to ensure that an errant experiment can't set a totally unexpected value. These macros also track which
542  * values have been modified via sycstl(3) so that they can be inspected with the showexperiments lldb macro.
543  */
544 
545 struct experiment_spec {
546 	void *ptr; /* ptr to numeric experiment factor. */
547 	uint64_t min_value; /* Min value that can be set via sysctl(3) (inclusive). */
548 	uint64_t max_value; /* Max value that can be set via sysctl(3) (inclusive). */
549 	uint64_t original_value; /* First value that was overwritten via sysctl(3). */
550 	_Atomic bool modified; /* Has this value ever been overwritten via sysctl(3)? */
551 };
552 
553 /*
554  * The handlers for the numeric types can be easily parameterized by type.
555  * So they're defined via an X macro.
556  */
557 #define experiment_factor_numeric_types \
558     X(uint, unsigned int) \
559     X(int, int) \
560     X(ulong, unsigned long) \
561     X(long, long) \
562     X(uint64, uint64_t) \
563     X(int64, int64_t)
564 
565 #define X(experiment_factor_typename, _) \
566 int experiment_factor_##experiment_factor_typename##_handler SYSCTL_HANDLER_ARGS;
567 
568 experiment_factor_numeric_types
569 #undef X
570 
571 #define __EXPERIMENT_FACTOR_SPEC(parent, name, p, min, max) \
572 	struct experiment_spec experiment_##parent##_##name = { \
573 	        .ptr = p, \
574 	        .min_value = min, \
575 	        .max_value = max, \
576 	        .original_value = 0, \
577 	        .modified = false \
578 	}
579 
580 #define EXPERIMENT_FACTOR_UINT(parent, name, ptr, min, max, descr) \
581 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
582 	_Static_assert(sizeof(*(ptr)) == sizeof(unsigned int), "must be integer sized"); \
583 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_uint_handler, "IU", descr);
584 
585 #define EXPERIMENT_FACTOR_INT(parent, name, ptr, min, max, descr) \
586 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
587 	_Static_assert(sizeof(*(ptr)) == sizeof(int), "must be integer sized"); \
588 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_int_handler, "I", descr);
589 
590 #define EXPERIMENT_FACTOR_ULONG(parent, name, ptr, min, max, descr) \
591 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
592 	_Static_assert(sizeof(*(ptr)) == sizeof(unsigned long), "must be long sized"); \
593 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_ulong_handler, "LU", descr);
594 
595 #define EXPERIMENT_FACTOR_LONG(parent, name, ptr, min, max, descr) \
596 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
597 	_Static_assert(sizeof(*(ptr)) == sizeof(long), "must be long sized"); \
598 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_long_handler, "L", descr);
599 
600 #define EXPERIMENT_FACTOR_UINT64(parent, name, ptr, min, max, descr) \
601 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
602 	_Static_assert(sizeof(*(ptr)) == sizeof(uint64_t), "must be 8 bytes"); \
603 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_uint64_handler, "QU", descr);
604 
605 #define EXPERIMENT_FACTOR_INT64(parent, name, ptr, min, max, descr) \
606 	__EXPERIMENT_FACTOR_SPEC(parent, name, ptr, min, max); \
607 	_Static_assert(sizeof(*(ptr)) == sizeof(int64_t), "must be 8 bytes"); \
608 	SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, &experiment_##parent##_##name, 1, &experiment_factor_int64_handler, "Q", descr);
609 
610 /*
611  * Calls an user provided handler to read / write this factor.
612  * Entitlement checking will still be done by sysctl, but it's the callers responsibility to validate any new values.
613  * This factor will not be printed out via the showexperiments lldb macro.
614  */
615 #define EXPERIMENT_FACTOR_PROC(parent, name, access, ptr, arg, handler, fmt, descr) \
616 	_Static_assert(arg != 1, "arg can not be 1"); \
617 	SYSCTL_PROC(parent, OID_AUTO, name, access | CTLFLAG_ANYBODY | CTLFLAG_EXPERIMENT, ptr, arg, handler, fmt, descr);
618 
619 #ifdef XNU_KERNEL_PRIVATE
620 /*
621  * Sysctl handler for reading a simple counter.
622  * Using this directly is not recommended. Use the SYSCTL_SCALABLE_COUNTER macro
623  */
624 int scalable_counter_sysctl_handler SYSCTL_HANDLER_ARGS;
625 
626 /*!
627  * @macro SYSCTL_SCALABLE_COUNTER
628  *
629  * @abstract
630  * Provides a sysctl for reading the value of a percpu counter.
631  */
632 #define SYSCTL_SCALABLE_COUNTER(parent, name, counter, descr) \
633 SYSCTL_PROC(parent, OID_AUTO, name, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED, \
634     (void *)(&counter), 0, &scalable_counter_sysctl_handler, "Q", descr);
635 #endif /* XNU_KERNEL_PRIVATE */
636 
637 extern struct sysctl_oid_list sysctl__children;
638 SYSCTL_DECL(_kern);
639 SYSCTL_DECL(_sysctl);
640 SYSCTL_DECL(_vm);
641 SYSCTL_DECL(_vfs);
642 SYSCTL_DECL(_net);
643 SYSCTL_DECL(_debug);
644 SYSCTL_DECL(_hw);
645 SYSCTL_DECL(_machdep);
646 SYSCTL_DECL(_user);
647 #if DEVELOPMENT || DEBUG
648 SYSCTL_DECL(_debug_test);
649 #endif /* DEVELOPMENT || DEBUG */
650 
651 #ifdef PRIVATE
652 SYSCTL_DECL(_kern_bridge);
653 SYSCTL_DECL(_hw_features);
654 #endif
655 
656 #if defined(BSD_KERNEL_PRIVATE) && SKYWALK
657 #include <skywalk/os_sysctls_private.h>
658 #endif  /* defined(BSD_KERNEL_PRIVATE) && SKYWALK */
659 
660 #ifndef SYSCTL_SKMEM_UPDATE_FIELD
661 
662 #define SYSCTL_SKMEM 0
663 #define SYSCTL_SKMEM_UPDATE_FIELD(field, value)
664 #define SYSCTL_SKMEM_UPDATE_AT_OFFSET(offset, value)
665 #define SYSCTL_SKMEM_INT(parent, oid, sysctl_name, access, ptr, offset, descr) \
666 	SYSCTL_INT(parent, oid, sysctl_name, access, ptr, 0, descr)
667 
668 #define SYSCTL_SKMEM_TCP_INT(oid, sysctl_name, access, variable_type,   \
669 	    variable_name, initial_value, descr)           \
670 	variable_type variable_name = initial_value;                                            \
671 	SYSCTL_SKMEM_INT(_net_inet_tcp, oid, sysctl_name, access,                       \
672 	                                 &variable_name, 0, descr)
673 
674 #else /* SYSCTL_SKMEM_UPDATE_FIELD */
675 #define SYSCTL_SKMEM 1
676 #endif /* SYSCTL_SKMEM_UPDATE_FIELD */
677 
678 
679 
680 #endif /* KERNEL */
681 
682 #ifdef XNU_KERNEL_PRIVATE
683 #define SYSCTL_DEF_ENABLED
684 #else
685 #ifndef KERNEL
686 #define SYSCTL_DEF_ENABLED
687 #endif
688 #endif
689 
690 #ifdef SYSCTL_DEF_ENABLED
691 /*
692  * Top-level identifiers
693  */
694 #define CTL_UNSPEC      0               /* unused */
695 #define CTL_KERN        1               /* "high kernel": proc, limits */
696 #define CTL_VM          2               /* virtual memory */
697 #define CTL_VFS         3               /* file system, mount type is next */
698 #define CTL_NET         4               /* network, see socket.h */
699 #define CTL_DEBUG       5               /* debugging parameters */
700 #define CTL_HW          6               /* generic cpu/io */
701 #define CTL_MACHDEP     7               /* machine dependent */
702 #define CTL_USER        8               /* user-level */
703 #define CTL_MAXID       9               /* number of valid top-level ids */
704 
705 #define CTL_NAMES { \
706 	{ 0, 0 }, \
707 	{ "kern", CTLTYPE_NODE }, \
708 	{ "vm", CTLTYPE_NODE }, \
709 	{ "vfs", CTLTYPE_NODE }, \
710 	{ "net", CTLTYPE_NODE }, \
711 	{ "debug", CTLTYPE_NODE }, \
712 	{ "hw", CTLTYPE_NODE }, \
713 	{ "machdep", CTLTYPE_NODE }, \
714 	{ "user", CTLTYPE_NODE }, \
715 }
716 
717 /*
718  * CTL_KERN identifiers
719  */
720 #define KERN_OSTYPE              1      /* string: system version */
721 #define KERN_OSRELEASE           2      /* string: system release */
722 #define KERN_OSREV               3      /* int: system revision */
723 #define KERN_VERSION             4      /* string: compile time info */
724 #define KERN_MAXVNODES           5      /* int: max vnodes */
725 #define KERN_MAXPROC             6      /* int: max processes */
726 #define KERN_MAXFILES            7      /* int: max open files */
727 #define KERN_ARGMAX              8      /* int: max arguments to exec */
728 #define KERN_SECURELVL           9      /* int: system security level */
729 #define KERN_HOSTNAME           10      /* string: hostname */
730 #define KERN_HOSTID             11      /* int: host identifier */
731 #define KERN_CLOCKRATE          12      /* struct: struct clockrate */
732 #define KERN_VNODE              13      /* struct: vnode structures */
733 #define KERN_PROC               14      /* struct: process entries */
734 #define KERN_FILE               15      /* struct: file entries */
735 #define KERN_PROF               16      /* node: kernel profiling info */
736 #define KERN_POSIX1             17      /* int: POSIX.1 version */
737 #define KERN_NGROUPS            18      /* int: # of supplemental group ids */
738 #define KERN_JOB_CONTROL        19      /* int: is job control available */
739 #define KERN_SAVED_IDS          20      /* int: saved set-user/group-ID */
740 #define KERN_BOOTTIME           21      /* struct: time kernel was booted */
741 #define KERN_NISDOMAINNAME      22      /* string: YP domain name */
742 #define KERN_DOMAINNAME         KERN_NISDOMAINNAME
743 #define KERN_MAXPARTITIONS      23      /* int: number of partitions/disk */
744 #define KERN_KDEBUG             24      /* int: kernel trace points */
745 #define KERN_UPDATEINTERVAL     25      /* int: update process sleep time */
746 #define KERN_OSRELDATE          26      /* int: OS release date */
747 #define KERN_NTP_PLL            27      /* node: NTP PLL control */
748 #define KERN_BOOTFILE           28      /* string: name of booted kernel */
749 #define KERN_MAXFILESPERPROC    29      /* int: max open files per proc */
750 #define KERN_MAXPROCPERUID      30      /* int: max processes per uid */
751 #define KERN_DUMPDEV            31      /* dev_t: device to dump on */
752 #define KERN_IPC                32      /* node: anything related to IPC */
753 #define KERN_DUMMY              33      /* unused */
754 #define KERN_PS_STRINGS 34      /* int: address of PS_STRINGS */
755 #define KERN_USRSTACK32 35      /* int: address of USRSTACK */
756 #define KERN_LOGSIGEXIT 36      /* int: do we log sigexit procs? */
757 #define KERN_SYMFILE            37      /* string: kernel symbol filename */
758 #define KERN_PROCARGS           38
759 /* 39 was KERN_PCSAMPLES... now obsolete */
760 #define KERN_NETBOOT            40      /* int: are we netbooted? 1=yes,0=no */
761 /* 41 was KERN_PANICINFO : panic UI information (deprecated) */
762 #define KERN_SYSV               42      /* node: System V IPC information */
763 #define KERN_AFFINITY           43      /* xxx */
764 #define KERN_TRANSLATE          44      /* xxx */
765 #define KERN_CLASSIC            KERN_TRANSLATE  /* XXX backwards compat */
766 #define KERN_EXEC               45      /* xxx */
767 #define KERN_CLASSICHANDLER     KERN_EXEC /* XXX backwards compatibility */
768 #define KERN_AIOMAX             46      /* int: max aio requests */
769 #define KERN_AIOPROCMAX         47      /* int: max aio requests per process */
770 #define KERN_AIOTHREADS         48      /* int: max aio worker threads */
771 #ifdef __APPLE_API_UNSTABLE
772 #define KERN_PROCARGS2          49
773 #endif /* __APPLE_API_UNSTABLE */
774 #define KERN_COREFILE           50      /* string: corefile format string */
775 #define KERN_COREDUMP           51      /* int: whether to coredump at all */
776 #define KERN_SUGID_COREDUMP     52      /* int: whether to dump SUGID cores */
777 #define KERN_PROCDELAYTERM      53      /* int: set/reset current proc for delayed termination during shutdown */
778 #define KERN_SHREG_PRIVATIZABLE 54      /* int: can shared regions be privatized ? */
779 /* 55 was KERN_PROC_LOW_PRI_IO... now deprecated */
780 #define KERN_LOW_PRI_WINDOW     56      /* int: set/reset throttle window - milliseconds */
781 #define KERN_LOW_PRI_DELAY      57      /* int: set/reset throttle delay - milliseconds */
782 #define KERN_POSIX              58      /* node: posix tunables */
783 #define KERN_USRSTACK64         59      /* LP64 user stack query */
784 #define KERN_NX_PROTECTION      60      /* int: whether no-execute protection is enabled */
785 #define KERN_TFP                61      /* Task for pid settings */
786 #define KERN_PROCNAME           62      /* setup process program  name(2*MAXCOMLEN) */
787 #define KERN_THALTSTACK         63      /* for compat with older x86 and does nothing */
788 #define KERN_SPECULATIVE_READS  64      /* int: whether speculative reads are disabled */
789 #define KERN_OSVERSION          65      /* for build number i.e. 9A127 */
790 #define KERN_SAFEBOOT           66      /* are we booted safe? */
791 /*	67 was KERN_LCTX (login context) */
792 #define KERN_RAGEVNODE          68
793 #define KERN_TTY                69      /* node: tty settings */
794 #define KERN_CHECKOPENEVT       70      /* spi: check the VOPENEVT flag on vnodes at open time */
795 #define KERN_THREADNAME         71      /* set/get thread name */
796 #define KERN_MAXID              72      /* number of valid kern ids */
797 /*
798  * Don't add any more sysctls like this.  Instead, use the SYSCTL_*() macros
799  * and OID_AUTO. This will have the added benefit of not having to recompile
800  * sysctl(8) to pick up your changes.
801  */
802 
803 #if COUNT_SYSCALLS && defined(KERNEL)
804 #define KERN_COUNT_SYSCALLS (KERN_OSTYPE + 1000)        /* keep called count for each bsd syscall */
805 #endif
806 
807 #if defined(__LP64__)
808 #define KERN_USRSTACK KERN_USRSTACK64
809 #else
810 #define KERN_USRSTACK KERN_USRSTACK32
811 #endif
812 
813 
814 /* KERN_RAGEVNODE types */
815 #define KERN_RAGE_PROC          1
816 #define KERN_RAGE_THREAD        2
817 #define KERN_UNRAGE_PROC        3
818 #define KERN_UNRAGE_THREAD      4
819 
820 /* KERN_OPENEVT types */
821 #define KERN_OPENEVT_PROC     1
822 #define KERN_UNOPENEVT_PROC   2
823 
824 /* KERN_TFP types */
825 #define KERN_TFP_POLICY                 1
826 
827 /* KERN_TFP_POLICY values . All policies allow task port for self */
828 #define KERN_TFP_POLICY_DENY            0       /* Deny Mode: None allowed except privileged */
829 #define KERN_TFP_POLICY_DEFAULT         2       /* Default  Mode: related ones allowed and upcall authentication */
830 
831 /* KERN_KDEBUG types */
832 #define KERN_KDEFLAGS         1
833 #define KERN_KDDFLAGS         2
834 #define KERN_KDENABLE         3
835 #define KERN_KDSETBUF         4
836 #define KERN_KDGETBUF         5
837 #define KERN_KDSETUP          6
838 #define KERN_KDREMOVE         7
839 #define KERN_KDSETREG         8
840 #define KERN_KDGETREG         9
841 #define KERN_KDREADTR         10
842 #define KERN_KDPIDTR          11
843 #define KERN_KDTHRMAP         12
844 /* Don't use 13 as it is overloaded with KERN_VNODE */
845 #define KERN_KDPIDEX          14
846 #define KERN_KDSETRTCDEC      15 /* obsolete */
847 #define KERN_KDGETENTROPY     16 /* obsolete */
848 #define KERN_KDWRITETR        17
849 #define KERN_KDWRITEMAP       18
850 #define KERN_KDTEST           19
851 /* 20 unused */
852 #define KERN_KDREADCURTHRMAP  21
853 #define KERN_KDSET_TYPEFILTER 22
854 #define KERN_KDBUFWAIT        23
855 #define KERN_KDCPUMAP         24
856 #define KERN_KDCPUMAP_EXT     25
857 #define KERN_KDSET_EDM        26
858 #define KERN_KDGET_EDM        27
859 #define KERN_KDWRITETR_V3     28
860 
861 #define CTL_KERN_NAMES { \
862 	{ 0, 0 }, \
863 	{ "ostype", CTLTYPE_STRING }, \
864 	{ "osrelease", CTLTYPE_STRING }, \
865 	{ "osrevision", CTLTYPE_INT }, \
866 	{ "version", CTLTYPE_STRING }, \
867 	{ "maxvnodes", CTLTYPE_INT }, \
868 	{ "maxproc", CTLTYPE_INT }, \
869 	{ "maxfiles", CTLTYPE_INT }, \
870 	{ "argmax", CTLTYPE_INT }, \
871 	{ "securelevel", CTLTYPE_INT }, \
872 	{ "hostname", CTLTYPE_STRING }, \
873 	{ "hostid", CTLTYPE_INT }, \
874 	{ "clockrate", CTLTYPE_STRUCT }, \
875 	{ "vnode", CTLTYPE_STRUCT }, \
876 	{ "proc", CTLTYPE_STRUCT }, \
877 	{ "file", CTLTYPE_STRUCT }, \
878 	{ "profiling", CTLTYPE_NODE }, \
879 	{ "posix1version", CTLTYPE_INT }, \
880 	{ "ngroups", CTLTYPE_INT }, \
881 	{ "job_control", CTLTYPE_INT }, \
882 	{ "saved_ids", CTLTYPE_INT }, \
883 	{ "boottime", CTLTYPE_STRUCT }, \
884 	{ "nisdomainname", CTLTYPE_STRING }, \
885 	{ "maxpartitions", CTLTYPE_INT }, \
886 	{ "kdebug", CTLTYPE_INT }, \
887 	{ "update", CTLTYPE_INT }, \
888 	{ "osreldate", CTLTYPE_INT }, \
889 	{ "ntp_pll", CTLTYPE_NODE }, \
890 	{ "bootfile", CTLTYPE_STRING }, \
891 	{ "maxfilesperproc", CTLTYPE_INT }, \
892 	{ "maxprocperuid", CTLTYPE_INT }, \
893 	{ "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
894 	{ "ipc", CTLTYPE_NODE }, \
895 	{ "dummy", CTLTYPE_INT }, \
896 	{ "dummy", CTLTYPE_INT }, \
897 	{ "usrstack", CTLTYPE_INT }, \
898 	{ "logsigexit", CTLTYPE_INT }, \
899 	{ "symfile",CTLTYPE_STRING },\
900 	{ "procargs",CTLTYPE_STRUCT },\
901 	{ "dummy", CTLTYPE_INT },               /* deprecated pcsamples */ \
902 	{ "netboot", CTLTYPE_INT }, \
903 	{ "dummy", CTLTYPE_INT },               /* deprecated: panicinfo */ \
904 	{ "sysv", CTLTYPE_NODE }, \
905 	{ "dummy", CTLTYPE_INT }, \
906 	{ "dummy", CTLTYPE_INT }, \
907 	{ "exec", CTLTYPE_NODE }, \
908 	{ "aiomax", CTLTYPE_INT }, \
909 	{ "aioprocmax", CTLTYPE_INT }, \
910 	{ "aiothreads", CTLTYPE_INT }, \
911 	{ "procargs2",CTLTYPE_STRUCT }, \
912 	{ "corefile",CTLTYPE_STRING }, \
913 	{ "coredump", CTLTYPE_INT }, \
914 	{ "sugid_coredump", CTLTYPE_INT }, \
915 	{ "delayterm", CTLTYPE_INT }, \
916 	{ "shreg_private", CTLTYPE_INT }, \
917 	{ "proc_low_pri_io", CTLTYPE_INT }, \
918 	{ "low_pri_window", CTLTYPE_INT }, \
919 	{ "low_pri_delay", CTLTYPE_INT }, \
920 	{ "posix", CTLTYPE_NODE }, \
921 	{ "usrstack64", CTLTYPE_QUAD }, \
922 	{ "nx", CTLTYPE_INT }, \
923 	{ "tfp", CTLTYPE_NODE }, \
924 	{ "procname", CTLTYPE_STRING }, \
925 	{ "threadsigaltstack", CTLTYPE_INT }, \
926 	{ "speculative_reads_disabled", CTLTYPE_INT }, \
927 	{ "osversion", CTLTYPE_STRING }, \
928 	{ "safeboot", CTLTYPE_INT }, \
929 	{ "dummy", CTLTYPE_INT },               /* deprecated: lctx */ \
930 	{ "rage_vnode", CTLTYPE_INT }, \
931 	{ "tty", CTLTYPE_NODE },        \
932 	{ "check_openevt", CTLTYPE_INT }, \
933 	{ "thread_name", CTLTYPE_STRING } \
934 }
935 
936 /*
937  * CTL_VFS identifiers
938  */
939 #define CTL_VFS_NAMES { \
940 	{ "vfsconf", CTLTYPE_STRUCT } \
941 }
942 
943 /*
944  * KERN_PROC subtypes
945  */
946 #define KERN_PROC_ALL           0       /* everything */
947 #define KERN_PROC_PID           1       /* by process id */
948 #define KERN_PROC_PGRP          2       /* by process group id */
949 #define KERN_PROC_SESSION       3       /* by session of pid */
950 #define KERN_PROC_TTY           4       /* by controlling tty */
951 #define KERN_PROC_UID           5       /* by effective uid */
952 #define KERN_PROC_RUID          6       /* by real uid */
953 #define KERN_PROC_LCID          7       /* by login context id */
954 
955 /*
956  * KERN_VFSNSPACE subtypes
957  */
958 #define KERN_VFSNSPACE_HANDLE_PROC              1
959 #define KERN_VFSNSPACE_UNHANDLE_PROC    2
960 
961 #if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL)
962 /*
963  * KERN_PROC subtype ops return arrays of augmented proc structures:
964  */
965 
966 struct _pcred {
967 	char    pc_lock[72];            /* opaque content */
968 	struct  ucred *pc_ucred;        /* Current credentials. */
969 	uid_t   p_ruid;                 /* Real user id. */
970 	uid_t   p_svuid;                /* Saved effective user id. */
971 	gid_t   p_rgid;                 /* Real group id. */
972 	gid_t   p_svgid;                /* Saved effective group id. */
973 	int     p_refcnt;               /* Number of references. */
974 };
975 
976 struct _ucred {
977 	int32_t cr_ref;                 /* reference count */
978 	uid_t   cr_uid;                 /* effective user id */
979 	short   cr_ngroups;             /* number of groups */
980 	gid_t   cr_groups[NGROUPS];     /* groups */
981 };
982 
983 struct kinfo_proc {
984 	struct  extern_proc kp_proc;                    /* proc structure */
985 	struct  eproc {
986 		struct  proc *e_paddr;          /* address of proc */
987 		struct  session *e_sess;        /* session pointer */
988 		struct  _pcred e_pcred;         /* process credentials */
989 		struct  _ucred e_ucred;         /* current credentials */
990 		struct   vmspace e_vm;          /* address space */
991 		pid_t   e_ppid;                 /* parent process id */
992 		pid_t   e_pgid;                 /* process group id */
993 		short   e_jobc;                 /* job control counter */
994 		dev_t   e_tdev;                 /* controlling tty dev */
995 		pid_t   e_tpgid;                /* tty process group id */
996 		struct  session *e_tsess;       /* tty session pointer */
997 #define WMESGLEN        7
998 		char    e_wmesg[WMESGLEN + 1];    /* wchan message */
999 		segsz_t e_xsize;                /* text size */
1000 		short   e_xrssize;              /* text rss */
1001 		short   e_xccount;              /* text references */
1002 		short   e_xswrss;
1003 		int32_t e_flag;
1004 #define EPROC_CTTY      0x01    /* controlling tty vnode active */
1005 #define EPROC_SLEADER   0x02    /* session leader */
1006 #define COMAPT_MAXLOGNAME       12
1007 		char    e_login[COMAPT_MAXLOGNAME];     /* short setlogin() name */
1008 		int32_t e_spare[4];
1009 	} kp_eproc;
1010 };
1011 
1012 #endif /* defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) */
1013 
1014 #ifdef BSD_KERNEL_PRIVATE
1015 #include <sys/proc_internal.h>
1016 
1017 /* LP64 version of _pcred.  all pointers
1018  * grow when we're dealing with a 64-bit process.
1019  * WARNING - keep in sync with _pcred
1020  */
1021 
1022 struct user32_pcred {
1023 	char          pc_lock[72];    /* opaque content */
1024 	user32_addr_t pc_ucred;       /* Current credentials. */
1025 	uid_t         p_ruid;         /* Real user id. */
1026 	uid_t         p_svuid;        /* Saved effective user id. */
1027 	gid_t         p_rgid;         /* Real group id. */
1028 	gid_t         p_svgid;        /* Saved effective group id. */
1029 	int           p_refcnt;       /* Number of references. */
1030 };
1031 struct user64_pcred {
1032 	char          pc_lock[72];      /* opaque content */
1033 	user64_addr_t pc_ucred;         /* Current credentials. */
1034 	uid_t         p_ruid;           /* Real user id. */
1035 	uid_t         p_svuid;          /* Saved effective user id. */
1036 	gid_t         p_rgid;           /* Real group id. */
1037 	gid_t         p_svgid;          /* Saved effective group id. */
1038 	int           p_refcnt;         /* Number of references. */
1039 };
1040 
1041 /* LP64 version of kinfo_proc.  all pointers
1042  * grow when we're dealing with a 64-bit process.
1043  * WARNING - keep in sync with kinfo_proc
1044  */
1045 struct user32_kinfo_proc {
1046 	struct  user32_extern_proc kp_proc;     /* proc structure */
1047 	struct  user32_eproc {
1048 		user32_addr_t e_paddr;          /* address of proc */
1049 		user32_addr_t e_sess;                   /* session pointer */
1050 		struct  user32_pcred e_pcred;           /* process credentials */
1051 		struct  _ucred e_ucred;         /* current credentials */
1052 		struct  user32_vmspace e_vm; /* address space */
1053 		pid_t   e_ppid;                 /* parent process id */
1054 		pid_t   e_pgid;                 /* process group id */
1055 		int     e_jobc;                 /* job control counter */
1056 		dev_t   e_tdev;                 /* controlling tty dev */
1057 		pid_t   e_tpgid;                /* tty process group id */
1058 		user32_addr_t   e_tsess;        /* tty session pointer */
1059 		char    e_wmesg[WMESGLEN + 1];    /* wchan message */
1060 		segsz_t e_xsize;                /* text size */
1061 		short   e_xrssize;              /* text rss */
1062 		short   e_xccount;              /* text references */
1063 		short   e_xswrss;
1064 		int32_t e_flag;
1065 		char    e_login[COMAPT_MAXLOGNAME];     /* short setlogin() name */
1066 		int32_t e_spare[4];
1067 	} kp_eproc;
1068 };
1069 struct user64_kinfo_proc {
1070 	struct  user64_extern_proc kp_proc;     /* proc structure */
1071 	struct  user64_eproc {
1072 		user_addr_t e_paddr;            /* address of proc */
1073 		user_addr_t e_sess;                     /* session pointer */
1074 		struct  user64_pcred e_pcred;           /* process credentials */
1075 		struct  _ucred e_ucred;         /* current credentials */
1076 		struct   user_vmspace e_vm; /* address space */
1077 		pid_t   e_ppid;                 /* parent process id */
1078 		pid_t   e_pgid;                 /* process group id */
1079 		int     e_jobc;                 /* job control counter */
1080 		dev_t   e_tdev;                 /* controlling tty dev */
1081 		pid_t   e_tpgid;                /* tty process group id */
1082 		user64_addr_t   e_tsess __attribute((aligned(8)));      /* tty session pointer */
1083 		char    e_wmesg[WMESGLEN + 1];    /* wchan message */
1084 		segsz_t e_xsize;                /* text size */
1085 		short   e_xrssize;              /* text rss */
1086 		short   e_xccount;              /* text references */
1087 		short   e_xswrss;
1088 		int32_t e_flag;
1089 		char    e_login[COMAPT_MAXLOGNAME];     /* short setlogin() name */
1090 		int32_t e_spare[4];
1091 	} kp_eproc;
1092 };
1093 
1094 #endif  /* BSD_KERNEL_PRIVATE */
1095 
1096 /*
1097  * KERN_IPC identifiers
1098  */
1099 #define KIPC_MAXSOCKBUF         1       /* int: max size of a socket buffer */
1100 #define KIPC_SOCKBUF_WASTE      2       /* int: wastage factor in sockbuf */
1101 #define KIPC_SOMAXCONN          3       /* int: max length of connection q */
1102 #define KIPC_MAX_LINKHDR        4       /* int: max length of link header */
1103 #define KIPC_MAX_PROTOHDR       5       /* int: max length of network header */
1104 #define KIPC_MAX_HDR            6       /* int: max total length of headers */
1105 #define KIPC_MAX_DATALEN        7       /* int: max length of data? */
1106 #define KIPC_MBSTAT             8       /* struct: mbuf usage statistics */
1107 #define KIPC_NMBCLUSTERS        9       /* int: maximum mbuf clusters */
1108 #define KIPC_SOQLIMITCOMPAT     10      /* int: socket queue limit */
1109 
1110 /*
1111  * CTL_VM identifiers
1112  */
1113 #define VM_METER        1               /* struct vmmeter */
1114 #define VM_LOADAVG      2               /* struct loadavg */
1115 /*
1116  * Note: "3" was skipped sometime ago and should probably remain unused
1117  * to avoid any new entry from being accepted by older kernels...
1118  */
1119 #define VM_MACHFACTOR   4               /* struct loadavg with mach factor*/
1120 #define VM_SWAPUSAGE    5               /* total swap usage */
1121 #define VM_MAXID        6               /* number of valid vm ids */
1122 
1123 #define CTL_VM_NAMES { \
1124 	{ 0, 0 }, \
1125 	{ "vmmeter", CTLTYPE_STRUCT }, \
1126 	{ "loadavg", CTLTYPE_STRUCT }, \
1127 	{ 0, 0 }, /* placeholder for "3" (see comment above) */ \
1128 	{ "dummy", CTLTYPE_INT }, \
1129 	{ "swapusage", CTLTYPE_STRUCT } \
1130 }
1131 
1132 struct xsw_usage {
1133 	u_int64_t       xsu_total;
1134 	u_int64_t       xsu_avail;
1135 	u_int64_t       xsu_used;
1136 	u_int32_t       xsu_pagesize;
1137 	boolean_t       xsu_encrypted;
1138 };
1139 
1140 #ifdef __APPLE_API_PRIVATE
1141 /* Load average structure.  Use of fixpt_t assume <sys/types.h> in scope. */
1142 /* XXX perhaps we should protect fixpt_t, and define it here (or discard it) */
1143 struct loadavg {
1144 	fixpt_t ldavg[3];
1145 	long    fscale;
1146 };
1147 extern struct loadavg averunnable;
1148 #define LSCALE  1000            /* scaling for "fixed point" arithmetic */
1149 
1150 #ifdef BSD_KERNEL_PRIVATE
1151 
1152 struct user32_loadavg {
1153 	fixpt_t ldavg[3];
1154 	user32_long_t       fscale;
1155 };
1156 
1157 struct user64_loadavg {
1158 	fixpt_t ldavg[3];
1159 	user64_long_t       fscale;
1160 };
1161 
1162 #endif  /* BSD_KERNEL_PRIVATE */
1163 #endif /* __APPLE_API_PRIVATE */
1164 
1165 
1166 /*
1167  * CTL_HW identifiers
1168  */
1169 #define HW_MACHINE       1              /* string: machine class (deprecated: use HW_PRODUCT) */
1170 #define HW_MODEL         2              /* string: specific machine model (deprecated: use HW_TARGET) */
1171 #define HW_NCPU          3              /* int: number of cpus */
1172 #define HW_BYTEORDER     4              /* int: machine byte order */
1173 #define HW_PHYSMEM       5              /* int: total memory */
1174 #define HW_USERMEM       6              /* int: non-kernel memory */
1175 #define HW_PAGESIZE      7              /* int: software page size */
1176 #define HW_DISKNAMES     8              /* strings: disk drive names */
1177 #define HW_DISKSTATS     9              /* struct: diskstats[] */
1178 #define HW_EPOCH        10              /* int: 0 for Legacy, else NewWorld */
1179 #define HW_FLOATINGPT   11              /* int: has HW floating point? */
1180 #define HW_MACHINE_ARCH 12              /* string: machine architecture */
1181 #define HW_VECTORUNIT   13              /* int: has HW vector unit? */
1182 #define HW_BUS_FREQ     14              /* int: Bus Frequency */
1183 #define HW_CPU_FREQ     15              /* int: CPU Frequency */
1184 #define HW_CACHELINE    16              /* int: Cache Line Size in Bytes */
1185 #define HW_L1ICACHESIZE 17              /* int: L1 I Cache Size in Bytes */
1186 #define HW_L1DCACHESIZE 18              /* int: L1 D Cache Size in Bytes */
1187 #define HW_L2SETTINGS   19              /* int: L2 Cache Settings */
1188 #define HW_L2CACHESIZE  20              /* int: L2 Cache Size in Bytes */
1189 #define HW_L3SETTINGS   21              /* int: L3 Cache Settings */
1190 #define HW_L3CACHESIZE  22              /* int: L3 Cache Size in Bytes */
1191 #define HW_TB_FREQ      23              /* int: Bus Frequency */
1192 #define HW_MEMSIZE      24              /* uint64_t: physical ram size */
1193 #define HW_AVAILCPU     25              /* int: number of available CPUs */
1194 #define HW_TARGET       26              /* string: model identifier */
1195 #define HW_PRODUCT      27              /* string: product identifier */
1196 #define HW_MAXID        28              /* number of valid hw ids */
1197 
1198 #define CTL_HW_NAMES { \
1199 	{ 0, 0 }, \
1200 	{ "machine", CTLTYPE_STRING },          /* Deprecated: use hw.product */ \
1201 	{ "model", CTLTYPE_STRING },            /* Deprecated: use hw.target */ \
1202 	{ "ncpu", CTLTYPE_INT }, \
1203 	{ "byteorder", CTLTYPE_INT }, \
1204 	{ "physmem", CTLTYPE_INT }, \
1205 	{ "usermem", CTLTYPE_INT }, \
1206 	{ "pagesize", CTLTYPE_INT }, \
1207 	{ "disknames", CTLTYPE_STRUCT }, \
1208 	{ "diskstats", CTLTYPE_STRUCT }, \
1209 	{ "epoch", CTLTYPE_INT }, \
1210 	{ "floatingpoint", CTLTYPE_INT }, \
1211 	{ "machinearch", CTLTYPE_STRING }, \
1212 	{ "vectorunit", CTLTYPE_INT }, \
1213 	{ "busfrequency", CTLTYPE_INT }, \
1214 	{ "cpufrequency", CTLTYPE_INT }, \
1215 	{ "cachelinesize", CTLTYPE_INT }, \
1216 	{ "l1icachesize", CTLTYPE_INT }, \
1217 	{ "l1dcachesize", CTLTYPE_INT }, \
1218 	{ "l2settings", CTLTYPE_INT }, \
1219 	{ "l2cachesize", CTLTYPE_INT }, \
1220 	{ "l3settings", CTLTYPE_INT }, \
1221 	{ "l3cachesize", CTLTYPE_INT }, \
1222 	{ "tbfrequency", CTLTYPE_INT }, \
1223 	{ "memsize", CTLTYPE_QUAD }, \
1224 	{ "availcpu", CTLTYPE_INT }, \
1225 	{ "target", CTLTYPE_STRING }, \
1226 	{ "product", CTLTYPE_STRING }, \
1227 }
1228 
1229 /*
1230  * XXX This information should be moved to the man page.
1231  *
1232  * These are the support HW selectors for sysctlbyname.  Parameters that are byte counts or frequencies are 64 bit numbers.
1233  * All other parameters are 32 bit numbers.
1234  *
1235  *   hw.memsize                - The number of bytes of physical memory in the system.
1236  *
1237  *   hw.ncpu                   - The maximum number of processors that could be available this boot.
1238  *                               Use this value for sizing of static per processor arrays; i.e. processor load statistics.
1239  *
1240  *   hw.activecpu              - The number of processors currently available for executing threads.
1241  *                               Use this number to determine the number threads to create in SMP aware applications.
1242  *                               This number can change when power management modes are changed.
1243  *
1244  *   hw.physicalcpu            - The number of physical processors available in the current power management mode.
1245  *   hw.physicalcpu_max        - The maximum number of physical processors that could be available this boot
1246  *
1247  *   hw.logicalcpu             - The number of logical processors available in the current power management mode.
1248  *   hw.logicalcpu_max         - The maximum number of logical processors that could be available this boot
1249  *
1250  *   hw.tbfrequency            - This gives the time base frequency used by the OS and is the basis of all timing services.
1251  *                               In general is is better to use mach's or higher level timing services, but this value
1252  *                               is needed to convert the PPC Time Base registers to real time.
1253  *
1254  *   hw.cpufrequency, hw.busfrequency and their min/max versions are deprecated because frequency isn't consistent.
1255  *
1256  *   hw.cpufrequency           - (deprecated) These values provide the current, min and max cpu frequency.  The min and max are for
1257  *   hw.cpufrequency_max       - (deprecated) all power management modes.  The current frequency is the max frequency in the current mode.
1258  *   hw.cpufrequency_min       - (deprecated) All frequencies are in Hz.
1259  *
1260  *   hw.busfrequency           - (deprecated) These values provide the current, min and max bus frequency.  The min and max are for
1261  *   hw.busfrequency_max       - (deprecated) all power management modes.  The current frequency is the max frequency in the current mode.
1262  *   hw.busfrequency_min       - (deprecated) All frequencies are in Hz.
1263  *
1264  *   hw.cputype                - These values provide the mach-o cpu type and subtype.  A complete list is in <mach/machine.h>
1265  *   hw.cpusubtype             - These values should be used to determine what processor family the running cpu is from so that
1266  *                               the best binary can be chosen, or the best dynamic code generated.  They should not be used
1267  *                               to determine if a given processor feature is available.
1268  *   hw.cputhreadtype          - This value will be present if the processor supports threads.  Like hw.cpusubtype this selector
1269  *                               should not be used to infer features, and only used to name the processors thread architecture.
1270  *                               The values are defined in <mach/machine.h>
1271  *
1272  *   hw.byteorder              - Gives the byte order of the processor.  4321 for big endian, 1234 for little.
1273  *
1274  *   hw.pagesize               - Gives the size in bytes of the pages used by the processor and VM system.
1275  *
1276  *   hw.cachelinesize          - Gives the size in bytes of the processor's cache lines.
1277  *                               This value should be use to control the strides of loops that use cache control instructions
1278  *                               like dcbz, dcbt or dcbst.
1279  *
1280  *   hw.l1dcachesize           - These values provide the size in bytes of the L1, L2 and L3 caches.  If a cache is not present
1281  *   hw.l1icachesize           - then the selector will return and error.
1282  *   hw.l2cachesize            -
1283  *   hw.l3cachesize            -
1284  *
1285  *   hw.nperflevels            - Number of core types in the system. See the parameters below, which can be used to get
1286  *                             - information associated with a specific perf level.
1287  *
1288  *   The following parameters apply to perflevel N, where N is a number between 0 and the number of core types in the system minus one.
1289  *   perflevel 0 always refers to the highest performance core type in the system.
1290  *
1291  *   hw.perflevelN.physicalcpu      - The number of physical processors available in the current power management mode.
1292  *   hw.perflevelN.physicalcpumax   - The maximum number of physical processors that could be available this boot.
1293  *   hw.perflevelN.logicalcpu       - The number of logical processors available in the current power management mode.
1294  *   hw.perflevelN.logicalcpumax    - The maximum number of logical processors that could be available this boot.
1295  *
1296  *   hw.perflevelN.l1dcachesize     - These values provide the size in bytes of the L1, L2 and L3 caches.  If a cache is not present
1297  *   hw.perflevelN.l1icachesize     - then the selector will return and error.
1298  *   hw.perflevelN.l2cachesize      -
1299  *   hw.perflevelN.l3cachesize      -
1300  *
1301  *   hw.perflevelN.cpusperl2        - These values provide the number of CPUs of the same type that share L2 and L3 caches.
1302  *   hw.perflevelN.cpusperl3        - If a cache is not present then the selector will return and error.
1303  *
1304  *   hw.perflevelN.l2perflevels     - These values provide a bitmap, where bit  number of CPUs of the same type that share L2 and L3 caches.
1305  *   hw.perflevelN.l3perflevels     - If a cache is not present then the selector will return and error.
1306  *
1307  *   hw.packages               - Gives the number of processor packages.
1308  *
1309  * These are the selectors for optional processor features for specific processors.  Selectors that return errors are not support
1310  * on the system.  Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help .
1311  * performance.  Future versions of these selectors may return larger values as necessary so it is best to test for non zero.
1312  *
1313  * For PowerPC:
1314  *
1315  *   hw.optional.floatingpoint - Floating Point Instructions
1316  *   hw.optional.altivec       - AltiVec Instructions
1317  *   hw.optional.graphicsops   - Graphics Operations
1318  *   hw.optional.64bitops      - 64-bit Instructions
1319  *   hw.optional.fsqrt         - HW Floating Point Square Root Instruction
1320  *   hw.optional.stfiwx        - Store Floating Point as Integer Word Indexed Instructions
1321  *   hw.optional.dcba          - Data Cache Block Allocate Instruction
1322  *   hw.optional.datastreams   - Data Streams Instructions
1323  *   hw.optional.dcbtstreams   - Data Cache Block Touch Steams Instruction Form
1324  *
1325  * For x86 Architecture:
1326  *
1327  *   hw.optional.floatingpoint     - Floating Point Instructions
1328  *   hw.optional.mmx               - Original MMX vector instructions
1329  *   hw.optional.sse               - Streaming SIMD Extensions
1330  *   hw.optional.sse2              - Streaming SIMD Extensions 2
1331  *   hw.optional.sse3              - Streaming SIMD Extensions 3
1332  *   hw.optional.supplementalsse3  - Supplemental Streaming SIMD Extensions 3
1333  *   hw.optional.x86_64            - 64-bit support
1334  */
1335 
1336 
1337 /*
1338  * CTL_USER definitions
1339  */
1340 #define USER_CS_PATH             1      /* string: _CS_PATH */
1341 #define USER_BC_BASE_MAX         2      /* int: BC_BASE_MAX */
1342 #define USER_BC_DIM_MAX          3      /* int: BC_DIM_MAX */
1343 #define USER_BC_SCALE_MAX        4      /* int: BC_SCALE_MAX */
1344 #define USER_BC_STRING_MAX       5      /* int: BC_STRING_MAX */
1345 #define USER_COLL_WEIGHTS_MAX    6      /* int: COLL_WEIGHTS_MAX */
1346 #define USER_EXPR_NEST_MAX       7      /* int: EXPR_NEST_MAX */
1347 #define USER_LINE_MAX            8      /* int: LINE_MAX */
1348 #define USER_RE_DUP_MAX          9      /* int: RE_DUP_MAX */
1349 #define USER_POSIX2_VERSION     10      /* int: POSIX2_VERSION */
1350 #define USER_POSIX2_C_BIND      11      /* int: POSIX2_C_BIND */
1351 #define USER_POSIX2_C_DEV       12      /* int: POSIX2_C_DEV */
1352 #define USER_POSIX2_CHAR_TERM   13      /* int: POSIX2_CHAR_TERM */
1353 #define USER_POSIX2_FORT_DEV    14      /* int: POSIX2_FORT_DEV */
1354 #define USER_POSIX2_FORT_RUN    15      /* int: POSIX2_FORT_RUN */
1355 #define USER_POSIX2_LOCALEDEF   16      /* int: POSIX2_LOCALEDEF */
1356 #define USER_POSIX2_SW_DEV      17      /* int: POSIX2_SW_DEV */
1357 #define USER_POSIX2_UPE         18      /* int: POSIX2_UPE */
1358 #define USER_STREAM_MAX         19      /* int: POSIX2_STREAM_MAX */
1359 #define USER_TZNAME_MAX         20      /* int: POSIX2_TZNAME_MAX */
1360 #define USER_MAXID              21      /* number of valid user ids */
1361 
1362 #define CTL_USER_NAMES { \
1363 	{ 0, 0 }, \
1364 	{ "cs_path", CTLTYPE_STRING }, \
1365 	{ "bc_base_max", CTLTYPE_INT }, \
1366 	{ "bc_dim_max", CTLTYPE_INT }, \
1367 	{ "bc_scale_max", CTLTYPE_INT }, \
1368 	{ "bc_string_max", CTLTYPE_INT }, \
1369 	{ "coll_weights_max", CTLTYPE_INT }, \
1370 	{ "expr_nest_max", CTLTYPE_INT }, \
1371 	{ "line_max", CTLTYPE_INT }, \
1372 	{ "re_dup_max", CTLTYPE_INT }, \
1373 	{ "posix2_version", CTLTYPE_INT }, \
1374 	{ "posix2_c_bind", CTLTYPE_INT }, \
1375 	{ "posix2_c_dev", CTLTYPE_INT }, \
1376 	{ "posix2_char_term", CTLTYPE_INT }, \
1377 	{ "posix2_fort_dev", CTLTYPE_INT }, \
1378 	{ "posix2_fort_run", CTLTYPE_INT }, \
1379 	{ "posix2_localedef", CTLTYPE_INT }, \
1380 	{ "posix2_sw_dev", CTLTYPE_INT }, \
1381 	{ "posix2_upe", CTLTYPE_INT }, \
1382 	{ "stream_max", CTLTYPE_INT }, \
1383 	{ "tzname_max", CTLTYPE_INT } \
1384 }
1385 
1386 
1387 
1388 /*
1389  * CTL_DEBUG definitions
1390  *
1391  * Second level identifier specifies which debug variable.
1392  * Third level identifier specifies which stucture component.
1393  */
1394 #define CTL_DEBUG_NAME          0       /* string: variable name */
1395 #define CTL_DEBUG_VALUE         1       /* int: variable value */
1396 #define CTL_DEBUG_MAXID         20
1397 
1398 
1399 #if (CTL_MAXID != 9) || (KERN_MAXID != 72) || (VM_MAXID != 6) || (HW_MAXID != 28) || (USER_MAXID != 21) || (CTL_DEBUG_MAXID != 20)
1400 #error Use the SYSCTL_*() macros and OID_AUTO instead!
1401 #endif
1402 
1403 
1404 #ifdef  KERNEL
1405 
1406 #ifdef BSD_KERNEL_PRIVATE
1407 extern char     machine[];
1408 extern char     osrelease[];
1409 #define OSRELEASETYPE_SIZE 48
1410 extern char     osreleasetype[OSRELEASETYPE_SIZE];
1411 extern char     ostype[];
1412 extern char     osversion[];
1413 extern char     osproductversion[];
1414 extern char     osbuild_config[];
1415 
1416 /*
1417  * Tries to match variants inside osreleasetype such as matching "Darwin" in
1418  * "Darwin Internal".
1419  */
1420 static inline bool
kern_osreleasetype_matches(const char * variant)1421 kern_osreleasetype_matches(const char *variant)
1422 {
1423 	const size_t len = sizeof(osreleasetype);
1424 
1425 	return strnstr(__unsafe_null_terminated_from_indexable(osreleasetype, &osreleasetype[len - 1]),
1426 	           variant, len);
1427 }
1428 
1429 #if defined(XNU_TARGET_OS_BRIDGE)
1430 /*
1431  * 15 characters at maximum so both the productversion
1432  * and the build version can fit in the panic header
1433  * osversion field with the formatting requirements.
1434  */
1435 #define MACOS_VERS_LEN 15
1436 
1437 extern char     macosproductversion[];
1438 extern char     macosversion[];
1439 #endif
1440 
1441 void    sysctl_mib_init(void);
1442 
1443 #endif /* BSD_KERNEL_PRIVATE */
1444 #else   /* !KERNEL */
1445 
1446 __BEGIN_DECLS
1447 int     sysctl(int *, u_int, void *__sized_by(*oldlenp), size_t *oldlenp,
1448     void *__sized_by(newlen), size_t newlen);
1449 int     sysctlbyname(const char *, void *__sized_by(*oldlenp), size_t *oldlenp,
1450     void *__sized_by(newlen), size_t newlen);
1451 int     sysctlnametomib(const char *, int *__counted_by(*sizep), size_t *sizep);
1452 __END_DECLS
1453 
1454 #endif  /* KERNEL */
1455 
1456 
1457 #endif /* SYSCTL_DEF_ENABLED */
1458 
1459 
1460 #endif  /* !_SYS_SYSCTL_H_ */
1461