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