]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
cb323159 | 2 | * Copyright (c) 2000-2019 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
a39ff7e2 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
a39ff7e2 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
a39ff7e2 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
a39ff7e2 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1989, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * This code is derived from software contributed to Berkeley by | |
34 | * Mike Karels at Berkeley Software Design, Inc. | |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * 1. Redistributions of source code must retain the above copyright | |
40 | * notice, this list of conditions and the following disclaimer. | |
41 | * 2. Redistributions in binary form must reproduce the above copyright | |
42 | * notice, this list of conditions and the following disclaimer in the | |
43 | * documentation and/or other materials provided with the distribution. | |
44 | * 3. All advertising materials mentioning features or use of this software | |
45 | * must display the following acknowledgement: | |
46 | * This product includes software developed by the University of | |
47 | * California, Berkeley and its contributors. | |
48 | * 4. Neither the name of the University nor the names of its contributors | |
49 | * may be used to endorse or promote products derived from this software | |
50 | * without specific prior written permission. | |
51 | * | |
52 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
53 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
55 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
58 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
62 | * SUCH DAMAGE. | |
63 | * | |
64 | * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 | |
65 | */ | |
2d21ac55 A |
66 | /* |
67 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
68 | * support for mandatory and extensible security protections. This notice | |
69 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
70 | * Version 2.0. | |
71 | */ | |
1c79356b A |
72 | |
73 | #ifndef _SYS_SYSCTL_H_ | |
0a7de745 | 74 | #define _SYS_SYSCTL_H_ |
1c79356b A |
75 | |
76 | /* | |
77 | * These are for the eproc structure defined below. | |
78 | */ | |
91447636 A |
79 | #include <sys/cdefs.h> |
80 | ||
9bccf70c | 81 | #include <sys/appleapiopts.h> |
1c79356b A |
82 | #ifndef KERNEL |
83 | #include <sys/time.h> | |
84 | #include <sys/ucred.h> | |
91447636 | 85 | #else |
c3c9b80d A |
86 | #ifdef XNU_KERNEL_PRIVATE |
87 | #include <kern/startup.h> | |
88 | #include <libkern/section_keywords.h> | |
89 | #else | |
91447636 | 90 | #include <libkern/sysctl.h> |
f427ee49 | 91 | #include <os/base.h> |
c3c9b80d A |
92 | #endif /* XNU_KERNEL_PRIVATE */ |
93 | #endif /* KERNEL */ | |
5ba3f43e | 94 | |
1c79356b | 95 | #include <sys/proc.h> |
91447636 A |
96 | #include <sys/vm.h> |
97 | ||
1c79356b A |
98 | /* |
99 | * Definitions for sysctl call. The sysctl call uses a hierarchical name | |
100 | * for objects that can be examined or modified. The name is expressed as | |
101 | * a sequence of integers. Like a file path name, the meaning of each | |
102 | * component depends on its place in the hierarchy. The top-level and kern | |
103 | * identifiers are defined here, and other identifiers are defined in the | |
104 | * respective subsystem header files. | |
105 | */ | |
106 | ||
0a7de745 | 107 | #define CTL_MAXNAME 12 /* largest number of components supported */ |
1c79356b A |
108 | |
109 | /* | |
110 | * Each subsystem defined by sysctl defines a list of variables | |
a39ff7e2 | 111 | * for that subsystem. Each name is either a node with further |
1c79356b A |
112 | * levels defined below it, or it is a leaf of some particular |
113 | * type given below. Each sysctl level defines a set of name/type | |
114 | * pairs to be used by sysctl(1) in manipulating the subsystem. | |
2d21ac55 | 115 | * |
fe8ab488 | 116 | * When declaring new sysctl names, use the CTLFLAG_LOCKED flag in the |
6d2010ae A |
117 | * type to indicate that all necessary locking will be handled |
118 | * within the sysctl. | |
119 | * | |
120 | * Any sysctl defined without CTLFLAG_LOCKED is considered legacy | |
fe8ab488 | 121 | * and will be protected by a global mutex. |
6d2010ae A |
122 | * |
123 | * Note: This is not optimal, so it is best to handle locking | |
124 | * yourself, if you are able to do so. A simple design | |
125 | * pattern for use to avoid in a single function known | |
126 | * to potentially be in the paging path ot doing a DMA | |
127 | * to physical memory in a user space process is: | |
128 | * | |
129 | * lock | |
130 | * perform operation vs. local buffer | |
131 | * unlock | |
132 | * SYSCTL_OUT(rey, local buffer, length) | |
133 | * | |
134 | * ...this assumes you are not using a deep call graph | |
135 | * or are unable to pass a local buffer address as a | |
136 | * parameter into your deep call graph. | |
137 | * | |
138 | * Note that very large user buffers can fail the wire | |
139 | * if to do so would require more physical pages than | |
140 | * are available (the caller will get an ENOMEM error, | |
141 | * see sysctl_mem_hold() for details). | |
1c79356b A |
142 | */ |
143 | struct ctlname { | |
0a7de745 A |
144 | char *ctl_name; /* subsystem name */ |
145 | int ctl_type; /* type of name */ | |
1c79356b A |
146 | }; |
147 | ||
c3c9b80d A |
148 | #define CTLTYPE 0xf /* Mask for the type */ |
149 | #define CTLTYPE_NODE 1 /* name is a node */ | |
150 | #define CTLTYPE_INT 2 /* name describes an integer */ | |
151 | #define CTLTYPE_STRING 3 /* name describes a string */ | |
152 | #define CTLTYPE_QUAD 4 /* name describes a 64-bit number */ | |
153 | #define CTLTYPE_OPAQUE 5 /* name describes a structure */ | |
154 | #define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */ | |
155 | ||
156 | #define CTLFLAG_RD 0x80000000 /* Allow reads of variable */ | |
157 | #define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */ | |
158 | #define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR) | |
159 | #define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */ | |
160 | #define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */ | |
161 | #define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */ | |
162 | #define CTLFLAG_MASKED 0x04000000 /* deprecated variable, do not display */ | |
163 | #define CTLFLAG_NOAUTO 0x02000000 /* do not auto-register */ | |
164 | #define CTLFLAG_KERN 0x01000000 /* valid inside the kernel */ | |
165 | #define CTLFLAG_LOCKED 0x00800000 /* node will handle locking itself */ | |
166 | #define CTLFLAG_OID2 0x00400000 /* struct sysctl_oid has version info */ | |
167 | #if XNU_KERNEL_PRIVATE | |
168 | #define CTLFLAG_PERMANENT 0x00200000 /* permanent sysctl_oid */ | |
169 | #endif | |
170 | #define CTLFLAG_EXPERIMENT 0x00100000 /* Allows writing w/ the trial experiment entitlement. */ | |
1c79356b A |
171 | |
172 | /* | |
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 | |
176 | * be implemented. | |
2d21ac55 | 177 | * |
1c79356b | 178 | * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); |
2d21ac55 A |
179 | * |
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. | |
184 | */ | |
c3c9b80d A |
185 | #define OID_AUTO (-1) |
186 | #if XNU_KERNEL_PRIVATE | |
187 | /* | |
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. | |
191 | * | |
192 | * This node is always first when it is used | |
193 | */ | |
194 | #define OID_MUTABLE_ANCHOR (INT_MIN) | |
195 | #endif | |
196 | #define OID_AUTO_START 100 /* conventional */ | |
1c79356b A |
197 | |
198 | #ifdef KERNEL | |
c3c9b80d A |
199 | #define SYSCTL_HANDLER_ARGS \ |
200 | (struct sysctl_oid *oidp __unused, void *arg1 __unused, int arg2 __unused, \ | |
1c79356b A |
201 | struct sysctl_req *req) |
202 | ||
2d21ac55 | 203 | |
1c79356b A |
204 | /* |
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. | |
207 | */ | |
208 | struct sysctl_req { | |
0a7de745 A |
209 | struct proc *p; |
210 | int lock; | |
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); | |
1c79356b A |
219 | }; |
220 | ||
221 | SLIST_HEAD(sysctl_oid_list, sysctl_oid); | |
222 | ||
0a7de745 | 223 | #define SYSCTL_OID_VERSION 1 /* current OID structure version */ |
6d2010ae | 224 | |
1c79356b A |
225 | /* |
226 | * This describes one "oid" in the MIB tree. Potentially more nodes can | |
227 | * be hidden behind it, expanded by the handler. | |
6d2010ae A |
228 | * |
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 | |
243 | * KEXTs. | |
244 | * | |
f427ee49 A |
245 | * Non CTLFLAG_OID2 based sysctls are deprecated and unavailable |
246 | * to non Intel platforms. | |
247 | * | |
6d2010ae A |
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. | |
257 | * | |
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. | |
1c79356b A |
262 | */ |
263 | struct sysctl_oid { | |
f427ee49 | 264 | struct sysctl_oid_list * OS_PTRAUTH_SIGNED_PTR("sysctl_oid.oid_parent") oid_parent; |
1c79356b | 265 | SLIST_ENTRY(sysctl_oid) oid_link; |
0a7de745 A |
266 | int oid_number; |
267 | int oid_kind; | |
268 | void *oid_arg1; | |
269 | int oid_arg2; | |
270 | const char *oid_name; | |
271 | int (*oid_handler)SYSCTL_HANDLER_ARGS; | |
272 | const char *oid_fmt; | |
273 | const char *oid_descr; /* offsetof() field / long description */ | |
274 | int oid_version; | |
275 | int oid_refcnt; | |
1c79356b A |
276 | }; |
277 | ||
278 | #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) | |
279 | #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l) | |
280 | ||
2d21ac55 A |
281 | typedef int (* sysctl_handler_t) SYSCTL_HANDLER_ARGS; |
282 | ||
91447636 A |
283 | __BEGIN_DECLS |
284 | ||
2d21ac55 | 285 | /* old interface */ |
1c79356b A |
286 | int sysctl_handle_int SYSCTL_HANDLER_ARGS; |
287 | int sysctl_handle_long SYSCTL_HANDLER_ARGS; | |
43866e37 A |
288 | int sysctl_handle_quad SYSCTL_HANDLER_ARGS; |
289 | int sysctl_handle_int2quad SYSCTL_HANDLER_ARGS; | |
1c79356b A |
290 | int sysctl_handle_string SYSCTL_HANDLER_ARGS; |
291 | int sysctl_handle_opaque SYSCTL_HANDLER_ARGS; | |
2d21ac55 A |
292 | /* new interface */ |
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); | |
1c79356b A |
296 | |
297 | /* | |
298 | * These functions are used to add/remove an oid from the mib. | |
299 | */ | |
300 | void sysctl_register_oid(struct sysctl_oid *oidp); | |
301 | void sysctl_unregister_oid(struct sysctl_oid *oidp); | |
302 | ||
f427ee49 A |
303 | #define nvram_osenvironment "osenvironment" |
304 | void sysctl_set_osenvironment(unsigned int size, const void* value); | |
305 | void sysctl_unblock_osenvironment(void); | |
cb323159 | 306 | |
39037602 A |
307 | /* Deprecated */ |
308 | void sysctl_register_fixed(void) __deprecated; | |
2d21ac55 | 309 | |
91447636 A |
310 | __END_DECLS |
311 | ||
1c79356b | 312 | /* Declare an oid to allow child oids to be added to it. */ |
0a7de745 | 313 | #define SYSCTL_DECL(name) \ |
1c79356b A |
314 | extern struct sysctl_oid_list sysctl_##name##_children |
315 | ||
fe8ab488 | 316 | /* |
a39ff7e2 | 317 | * Macros to define sysctl entries. Which to use? Pure data that are |
fe8ab488 A |
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 | |
a39ff7e2 | 320 | * own, SYSCTL_PROC. |
fe8ab488 A |
321 | * |
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: | |
0a7de745 A |
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 | |
fe8ab488 A |
331 | * a1, a2: entry-data, passed to handler (see specific macros) |
332 | * Format String: Tells "sysctl" tool how to print data from this entry. | |
0a7de745 A |
333 | * "A" - string |
334 | * "I" - list of integers. "IU" - list of unsigned integers. space-separated. | |
335 | * "-" - do not print | |
336 | * "L" - longs, as ints with I | |
fe8ab488 | 337 | * "P" - pointer |
0a7de745 A |
338 | * "Q" - quads |
339 | * "S","T" - clock info, see sysctl.c in system_cmds (you probably don't need this) | |
fe8ab488 A |
340 | * Description: unused |
341 | */ | |
342 | ||
343 | ||
1c79356b | 344 | /* This constructs a "raw" MIB oid. */ |
c3c9b80d A |
345 | #define SYSCTL_STRUCT_INIT(parent, nbr, name, kind, a1, a2, fn, fmt, desc) { \ |
346 | .oid_parent = &sysctl_##parent##_children, \ | |
347 | .oid_number = nbr, \ | |
348 | .oid_kind = (int)(kind | CTLFLAG_OID2), \ | |
349 | .oid_arg1 = a1, \ | |
350 | .oid_arg2 = (int)(a2), \ | |
351 | .oid_name = #name, \ | |
352 | .oid_handler = fn, \ | |
353 | .oid_fmt = fmt, \ | |
354 | .oid_descr = desc, \ | |
355 | .oid_version = SYSCTL_OID_VERSION, \ | |
fe8ab488 A |
356 | } |
357 | ||
c3c9b80d A |
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) | |
361 | ||
362 | #if XNU_KERNEL_PRIVATE | |
363 | ||
364 | /* | |
365 | * Core kernel registers sysctls before lockdown and protects those entries | |
366 | * in immutable memory. | |
367 | * | |
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. | |
371 | * | |
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 | |
374 | * unsafety: | |
375 | * | |
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. | |
378 | * | |
379 | * Such entries must be inserted in the STARTUP_SUB_SYSCTL "Middle" phase | |
380 | * using sysctl_register_oid_early(). | |
381 | * | |
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. | |
384 | * | |
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. | |
387 | * | |
388 | * This is acceptable for sysctls that will become valid quickly during boot | |
389 | * (but after lockdown). | |
390 | * | |
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. | |
394 | * | |
395 | * This is the least preferred solution. | |
396 | */ | |
397 | ||
398 | __BEGIN_DECLS | |
399 | void sysctl_register_oid_early(struct sysctl_oid *oidp); | |
400 | __END_DECLS | |
401 | ||
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) | |
405 | ||
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); | |
411 | ||
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) | |
419 | ||
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) | |
429 | ||
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, \ | |
441 | }; \ | |
442 | __STARTUP_ARG(sysctl_##name, _wranchor, \ | |
443 | SYSCTL, STARTUP_RANK_LAST, sysctl_register_oid_early, \ | |
444 | &sysctl_##name##_wranchor) | |
445 | ||
446 | #define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ | |
447 | __XNU_PRIVATE_EXTERN \ | |
448 | __SYSCTL_NODE(parent, nbr, name, access, handler, descr) | |
449 | ||
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) | |
453 | #else | |
1c79356b | 454 | #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ |
c3c9b80d | 455 | __SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) |
1c79356b A |
456 | |
457 | /* This constructs a node from which other oids can hang. */ | |
c3c9b80d A |
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 */ | |
1c79356b A |
463 | |
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, \ | |
c3c9b80d | 467 | arg, len, sysctl_handle_string, "A", descr) |
1c79356b | 468 | |
b0d623f7 A |
469 | #define SYSCTL_COMPAT_INT(parent, nbr, name, access, ptr, val, descr) \ |
470 | SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ | |
c3c9b80d | 471 | ptr, val, sysctl_handle_int, "I", descr) |
b0d623f7 A |
472 | |
473 | #define SYSCTL_COMPAT_UINT(parent, nbr, name, access, ptr, val, descr) \ | |
474 | SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ | |
c3c9b80d | 475 | ptr, val, sysctl_handle_int, "IU", descr) |
b0d623f7 | 476 | |
1c79356b A |
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, \ | |
c3c9b80d A |
480 | ptr, val, sysctl_handle_int, "I", descr); \ |
481 | _Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(int), \ | |
482 | "must be integer sized"); | |
1c79356b | 483 | |
55e303ae A |
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, \ | |
c3c9b80d A |
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"); | |
55e303ae | 490 | |
1c79356b A |
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, \ | |
c3c9b80d A |
494 | ptr, 0, sysctl_handle_long, "L", descr); \ |
495 | _Static_assert(__builtin_constant_p(ptr) || sizeof(*(ptr)) == sizeof(long), \ | |
496 | "must be long sized"); | |
1c79356b | 497 | |
5ba3f43e A |
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, \ | |
c3c9b80d A |
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"); | |
5ba3f43e | 504 | |
43866e37 A |
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, \ | |
c3c9b80d A |
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"); | |
43866e37 | 511 | |
1c79356b A |
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, \ | |
0a7de745 | 515 | ptr, len, sysctl_handle_opaque, fmt, descr) |
1c79356b A |
516 | |
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, \ | |
c3c9b80d A |
520 | ptr, sizeof(struct type), sysctl_handle_opaque, \ |
521 | "S," #type, descr) | |
1c79356b | 522 | |
a39ff7e2 | 523 | /* |
fe8ab488 A |
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). | |
527 | */ | |
1c79356b A |
528 | #define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ |
529 | SYSCTL_OID(parent, nbr, name, access, \ | |
c3c9b80d A |
530 | ptr, arg, handler, fmt, descr) |
531 | ||
532 | /* | |
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. | |
542 | */ | |
543 | ||
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)? */ | |
550 | }; | |
551 | ||
552 | /* | |
553 | * The handlers for the numeric types can be easily parameterized by type. | |
554 | * So they're defined via an X macro. | |
555 | */ | |
556 | #define experiment_factor_numeric_types \ | |
557 | X(uint, unsigned int) \ | |
558 | X(int, int) \ | |
559 | X(ulong, unsigned long) \ | |
560 | X(long, long) \ | |
561 | X(uint64, uint64_t) \ | |
562 | X(int64, int64_t) | |
563 | ||
564 | #define X(experiment_factor_typename, _) \ | |
565 | int experiment_factor_##experiment_factor_typename##_handler SYSCTL_HANDLER_ARGS; | |
566 | ||
567 | experiment_factor_numeric_types | |
568 | #undef X | |
569 | ||
570 | #define __EXPERIMENT_FACTOR_SPEC(parent, name, p, min, max) \ | |
571 | struct experiment_spec experiment_##parent##_##name = { \ | |
572 | .ptr = p, \ | |
573 | .min_value = min, \ | |
574 | .max_value = max, \ | |
575 | .original_value = 0, \ | |
576 | .modified = false \ | |
577 | } | |
578 | ||
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); | |
583 | ||
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); | |
588 | ||
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); | |
a39ff7e2 | 593 | |
c3c9b80d A |
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); | |
598 | ||
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); | |
603 | ||
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); | |
608 | ||
609 | /* | |
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. | |
613 | */ | |
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); | |
617 | ||
618 | #ifdef XNU_KERNEL_PRIVATE | |
619 | /* | |
620 | * Sysctl handler for reading a simple counter. | |
621 | * Using this directly is not recommended. Use the SYSCTL_SCALABLE_COUNTER macro | |
622 | */ | |
623 | int scalable_counter_sysctl_handler SYSCTL_HANDLER_ARGS; | |
624 | ||
625 | /*! | |
626 | * @macro SYSCTL_SCALABLE_COUNTER | |
627 | * | |
628 | * @abstract | |
629 | * Provides a sysctl for reading the value of a percpu counter. | |
630 | */ | |
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 */ | |
a39ff7e2 | 635 | |
91447636 A |
636 | extern struct sysctl_oid_list sysctl__children; |
637 | SYSCTL_DECL(_kern); | |
638 | SYSCTL_DECL(_sysctl); | |
639 | SYSCTL_DECL(_vm); | |
640 | SYSCTL_DECL(_vfs); | |
641 | SYSCTL_DECL(_net); | |
642 | SYSCTL_DECL(_debug); | |
643 | SYSCTL_DECL(_hw); | |
644 | SYSCTL_DECL(_machdep); | |
645 | SYSCTL_DECL(_user); | |
646 | ||
39037602 | 647 | #ifdef PRIVATE |
a39ff7e2 | 648 | SYSCTL_DECL(_kern_bridge); |
39037602 A |
649 | SYSCTL_DECL(_hw_features); |
650 | #endif | |
651 | ||
5ba3f43e A |
652 | |
653 | #ifndef SYSCTL_SKMEM_UPDATE_FIELD | |
654 | ||
0a7de745 A |
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) \ | |
5ba3f43e A |
659 | SYSCTL_INT(parent, oid, sysctl_name, access, ptr, 0, descr) |
660 | ||
0a7de745 A |
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) | |
5ba3f43e A |
666 | |
667 | #else /* SYSCTL_SKMEM_UPDATE_FIELD */ | |
0a7de745 | 668 | #define SYSCTL_SKMEM 1 |
5ba3f43e A |
669 | #endif /* SYSCTL_SKMEM_UPDATE_FIELD */ |
670 | ||
671 | ||
672 | ||
1c79356b A |
673 | #endif /* KERNEL */ |
674 | ||
91447636 A |
675 | #ifdef XNU_KERNEL_PRIVATE |
676 | #define SYSCTL_DEF_ENABLED | |
677 | #else | |
678 | #ifndef KERNEL | |
679 | #define SYSCTL_DEF_ENABLED | |
680 | #endif | |
681 | #endif | |
682 | ||
683 | #ifdef SYSCTL_DEF_ENABLED | |
1c79356b A |
684 | /* |
685 | * Top-level identifiers | |
686 | */ | |
0a7de745 A |
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 */ | |
1c79356b A |
697 | |
698 | #define CTL_NAMES { \ | |
699 | { 0, 0 }, \ | |
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 }, \ | |
708 | } | |
709 | ||
710 | /* | |
711 | * CTL_KERN identifiers | |
712 | */ | |
0a7de745 A |
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 | |
cb323159 | 752 | /* 39 was KERN_PCSAMPLES... now obsolete */ |
0a7de745 A |
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 */ | |
55e303ae | 764 | #ifdef __APPLE_API_UNSTABLE |
0a7de745 | 765 | #define KERN_PROCARGS2 49 |
55e303ae | 766 | #endif /* __APPLE_API_UNSTABLE */ |
0a7de745 A |
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 */ | |
2d21ac55 | 787 | #define KERN_CHECKOPENEVT 70 /* spi: check the VOPENEVT flag on vnodes at open time */ |
0a7de745 A |
788 | #define KERN_THREADNAME 71 /* set/get thread name */ |
789 | #define KERN_MAXID 72 /* number of valid kern ids */ | |
2d21ac55 A |
790 | /* |
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. | |
794 | */ | |
795 | ||
a39ff7e2 | 796 | #if COUNT_SYSCALLS && defined(KERNEL) |
0a7de745 | 797 | #define KERN_COUNT_SYSCALLS (KERN_OSTYPE + 1000) /* keep called count for each bsd syscall */ |
2d21ac55 | 798 | #endif |
91447636 A |
799 | |
800 | #if defined(__LP64__) | |
0a7de745 | 801 | #define KERN_USRSTACK KERN_USRSTACK64 |
91447636 | 802 | #else |
0a7de745 | 803 | #define KERN_USRSTACK KERN_USRSTACK32 |
91447636 | 804 | #endif |
1c79356b | 805 | |
2d21ac55 A |
806 | |
807 | /* KERN_RAGEVNODE types */ | |
0a7de745 A |
808 | #define KERN_RAGE_PROC 1 |
809 | #define KERN_RAGE_THREAD 2 | |
810 | #define KERN_UNRAGE_PROC 3 | |
811 | #define KERN_UNRAGE_THREAD 4 | |
2d21ac55 A |
812 | |
813 | /* KERN_OPENEVT types */ | |
814 | #define KERN_OPENEVT_PROC 1 | |
815 | #define KERN_UNOPENEVT_PROC 2 | |
816 | ||
0c530ab8 | 817 | /* KERN_TFP types */ |
0a7de745 | 818 | #define KERN_TFP_POLICY 1 |
0c530ab8 A |
819 | |
820 | /* KERN_TFP_POLICY values . All policies allow task port for self */ | |
0a7de745 A |
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 */ | |
0c530ab8 | 823 | |
1c79356b | 824 | /* KERN_KDEBUG types */ |
39037602 A |
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 | |
1c79356b | 837 | /* Don't use 13 as it is overloaded with KERN_VNODE */ |
39037602 A |
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 | |
844 | /* 20 unused */ | |
845 | #define KERN_KDREADCURTHRMAP 21 | |
846 | #define KERN_KDSET_TYPEFILTER 22 | |
847 | #define KERN_KDBUFWAIT 23 | |
848 | #define KERN_KDCPUMAP 24 | |
849 | /* 25 - 26 unused */ | |
850 | #define KERN_KDWRITEMAP_V3 27 | |
851 | #define KERN_KDWRITETR_V3 28 | |
9bccf70c | 852 | |
1c79356b A |
853 | #define CTL_KERN_NAMES { \ |
854 | { 0, 0 }, \ | |
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 }, \ | |
9bccf70c | 881 | { "ntp_pll", CTLTYPE_NODE }, \ |
1c79356b A |
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 }, \ | |
91447636 | 888 | { "dummy", CTLTYPE_INT }, \ |
1c79356b A |
889 | { "usrstack", CTLTYPE_INT }, \ |
890 | { "logsigexit", CTLTYPE_INT }, \ | |
9bccf70c A |
891 | { "symfile",CTLTYPE_STRING },\ |
892 | { "procargs",CTLTYPE_STRUCT },\ | |
0a7de745 | 893 | { "dummy", CTLTYPE_INT }, /* deprecated pcsamples */ \ |
9bccf70c | 894 | { "netboot", CTLTYPE_INT }, \ |
0a7de745 | 895 | { "dummy", CTLTYPE_INT }, /* deprecated: panicinfo */ \ |
55e303ae A |
896 | { "sysv", CTLTYPE_NODE }, \ |
897 | { "dummy", CTLTYPE_INT }, \ | |
898 | { "dummy", CTLTYPE_INT }, \ | |
0c530ab8 | 899 | { "exec", CTLTYPE_NODE }, \ |
55e303ae A |
900 | { "aiomax", CTLTYPE_INT }, \ |
901 | { "aioprocmax", CTLTYPE_INT }, \ | |
902 | { "aiothreads", CTLTYPE_INT }, \ | |
e5568f75 A |
903 | { "procargs2",CTLTYPE_STRUCT }, \ |
904 | { "corefile",CTLTYPE_STRING }, \ | |
905 | { "coredump", CTLTYPE_INT }, \ | |
91447636 A |
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 }, \ | |
0c530ab8 A |
912 | { "posix", CTLTYPE_NODE }, \ |
913 | { "usrstack64", CTLTYPE_QUAD }, \ | |
914 | { "nx", CTLTYPE_INT }, \ | |
915 | { "tfp", CTLTYPE_NODE }, \ | |
916 | { "procname", CTLTYPE_STRING }, \ | |
2d21ac55 A |
917 | { "threadsigaltstack", CTLTYPE_INT }, \ |
918 | { "speculative_reads_disabled", CTLTYPE_INT }, \ | |
919 | { "osversion", CTLTYPE_STRING }, \ | |
920 | { "safeboot", CTLTYPE_INT }, \ | |
0a7de745 | 921 | { "dummy", CTLTYPE_INT }, /* deprecated: lctx */ \ |
2d21ac55 | 922 | { "rage_vnode", CTLTYPE_INT }, \ |
0a7de745 | 923 | { "tty", CTLTYPE_NODE }, \ |
b0d623f7 A |
924 | { "check_openevt", CTLTYPE_INT }, \ |
925 | { "thread_name", CTLTYPE_STRING } \ | |
1c79356b A |
926 | } |
927 | ||
928 | /* | |
929 | * CTL_VFS identifiers | |
930 | */ | |
931 | #define CTL_VFS_NAMES { \ | |
9bccf70c | 932 | { "vfsconf", CTLTYPE_STRUCT } \ |
1c79356b A |
933 | } |
934 | ||
a39ff7e2 | 935 | /* |
1c79356b A |
936 | * KERN_PROC subtypes |
937 | */ | |
0a7de745 A |
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 */ | |
2d21ac55 | 946 | |
cb323159 A |
947 | /* |
948 | * KERN_VFSNSPACE subtypes | |
949 | */ | |
950 | #define KERN_VFSNSPACE_HANDLE_PROC 1 | |
951 | #define KERN_VFSNSPACE_UNHANDLE_PROC 2 | |
952 | ||
a39ff7e2 A |
953 | #if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) |
954 | /* | |
1c79356b A |
955 | * KERN_PROC subtype ops return arrays of augmented proc structures: |
956 | */ | |
91447636 A |
957 | |
958 | struct _pcred { | |
0a7de745 A |
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. */ | |
91447636 A |
966 | }; |
967 | ||
968 | struct _ucred { | |
0a7de745 A |
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 */ | |
91447636 A |
973 | }; |
974 | ||
1c79356b | 975 | struct kinfo_proc { |
0a7de745 A |
976 | struct extern_proc kp_proc; /* proc structure */ |
977 | struct eproc { | |
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 */ | |
989 | #define WMESGLEN 7 | |
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 */ | |
994 | short e_xswrss; | |
995 | int32_t e_flag; | |
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 */ | |
1000 | int32_t e_spare[4]; | |
1c79356b A |
1001 | } kp_eproc; |
1002 | }; | |
91447636 | 1003 | |
b0d623f7 A |
1004 | #endif /* defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) */ |
1005 | ||
91447636 A |
1006 | #ifdef BSD_KERNEL_PRIVATE |
1007 | #include <sys/proc_internal.h> | |
1008 | ||
a39ff7e2 | 1009 | /* LP64 version of _pcred. all pointers |
91447636 A |
1010 | * grow when we're dealing with a 64-bit process. |
1011 | * WARNING - keep in sync with _pcred | |
1012 | */ | |
1013 | ||
b0d623f7 | 1014 | struct user32_pcred { |
f427ee49 A |
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. */ | |
b0d623f7 A |
1022 | }; |
1023 | struct user64_pcred { | |
f427ee49 A |
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. */ | |
91447636 A |
1031 | }; |
1032 | ||
a39ff7e2 | 1033 | /* LP64 version of kinfo_proc. all pointers |
91447636 A |
1034 | * grow when we're dealing with a 64-bit process. |
1035 | * WARNING - keep in sync with kinfo_proc | |
1036 | */ | |
b0d623f7 | 1037 | struct user32_kinfo_proc { |
0a7de745 A |
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 */ | |
f427ee49 | 1047 | int e_jobc; /* job control counter */ |
0a7de745 A |
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 */ | |
1055 | short e_xswrss; | |
1056 | int32_t e_flag; | |
1057 | char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */ | |
1058 | int32_t e_spare[4]; | |
b0d623f7 A |
1059 | } kp_eproc; |
1060 | }; | |
1061 | struct user64_kinfo_proc { | |
0a7de745 A |
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 */ | |
f427ee49 | 1071 | int e_jobc; /* job control counter */ |
0a7de745 A |
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 */ | |
1079 | short e_xswrss; | |
1080 | int32_t e_flag; | |
1081 | char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */ | |
1082 | int32_t e_spare[4]; | |
91447636 A |
1083 | } kp_eproc; |
1084 | }; | |
1085 | ||
0a7de745 | 1086 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 | 1087 | |
1c79356b A |
1088 | /* |
1089 | * KERN_IPC identifiers | |
1090 | */ | |
0a7de745 A |
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 */ | |
1c79356b A |
1101 | |
1102 | /* | |
1103 | * CTL_VM identifiers | |
1104 | */ | |
0a7de745 A |
1105 | #define VM_METER 1 /* struct vmmeter */ |
1106 | #define VM_LOADAVG 2 /* struct loadavg */ | |
91447636 A |
1107 | /* |
1108 | * Note: "3" was skipped sometime ago and should probably remain unused | |
1109 | * to avoid any new entry from being accepted by older kernels... | |
a39ff7e2 | 1110 | */ |
0a7de745 A |
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 */ | |
1c79356b | 1114 | |
0a7de745 | 1115 | #define CTL_VM_NAMES { \ |
1c79356b A |
1116 | { 0, 0 }, \ |
1117 | { "vmmeter", CTLTYPE_STRUCT }, \ | |
91447636 A |
1118 | { "loadavg", CTLTYPE_STRUCT }, \ |
1119 | { 0, 0 }, /* placeholder for "3" (see comment above) */ \ | |
2d21ac55 | 1120 | { "dummy", CTLTYPE_INT }, \ |
91447636 | 1121 | { "swapusage", CTLTYPE_STRUCT } \ |
1c79356b A |
1122 | } |
1123 | ||
91447636 | 1124 | struct xsw_usage { |
0a7de745 A |
1125 | u_int64_t xsu_total; |
1126 | u_int64_t xsu_avail; | |
1127 | u_int64_t xsu_used; | |
1128 | u_int32_t xsu_pagesize; | |
1129 | boolean_t xsu_encrypted; | |
91447636 A |
1130 | }; |
1131 | ||
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) */ | |
1135 | struct loadavg { | |
0a7de745 A |
1136 | fixpt_t ldavg[3]; |
1137 | long fscale; | |
91447636 A |
1138 | }; |
1139 | extern struct loadavg averunnable; | |
0a7de745 | 1140 | #define LSCALE 1000 /* scaling for "fixed point" arithmetic */ |
91447636 | 1141 | |
91447636 A |
1142 | #ifdef BSD_KERNEL_PRIVATE |
1143 | ||
b0d623f7 | 1144 | struct user32_loadavg { |
0a7de745 A |
1145 | fixpt_t ldavg[3]; |
1146 | user32_long_t fscale; | |
b0d623f7 A |
1147 | }; |
1148 | ||
1149 | struct user64_loadavg { | |
0a7de745 A |
1150 | fixpt_t ldavg[3]; |
1151 | user64_long_t fscale; | |
91447636 A |
1152 | }; |
1153 | ||
0a7de745 | 1154 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 A |
1155 | #endif /* __APPLE_API_PRIVATE */ |
1156 | ||
1157 | ||
1c79356b A |
1158 | /* |
1159 | * CTL_HW identifiers | |
1160 | */ | |
f427ee49 A |
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) */ | |
0a7de745 A |
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 */ | |
f427ee49 A |
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 */ | |
1c79356b A |
1189 | |
1190 | #define CTL_HW_NAMES { \ | |
1191 | { 0, 0 }, \ | |
f427ee49 A |
1192 | { "machine", CTLTYPE_STRING }, /* Deprecated: use hw.product */ \ |
1193 | { "model", CTLTYPE_STRING }, /* Deprecated: use hw.target */ \ | |
1c79356b A |
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 }, \ | |
90556fb8 | 1213 | { "l3cachesize", CTLTYPE_INT }, \ |
43866e37 A |
1214 | { "tbfrequency", CTLTYPE_INT }, \ |
1215 | { "memsize", CTLTYPE_QUAD }, \ | |
f427ee49 A |
1216 | { "availcpu", CTLTYPE_INT }, \ |
1217 | { "target", CTLTYPE_STRING }, \ | |
1218 | { "product", CTLTYPE_STRING }, \ | |
1c79356b A |
1219 | } |
1220 | ||
43866e37 | 1221 | /* |
2d21ac55 A |
1222 | * XXX This information should be moved to the man page. |
1223 | * | |
91447636 | 1224 | * These are the support HW selectors for sysctlbyname. Parameters that are byte counts or frequencies are 64 bit numbers. |
43866e37 A |
1225 | * All other parameters are 32 bit numbers. |
1226 | * | |
1227 | * hw.memsize - The number of bytes of physical memory in the system. | |
1228 | * | |
91447636 | 1229 | * hw.ncpu - The maximum number of processors that could be available this boot. |
43866e37 A |
1230 | * Use this value for sizing of static per processor arrays; i.e. processor load statistics. |
1231 | * | |
91447636 | 1232 | * hw.activecpu - The number of processors currently available for executing threads. |
43866e37 A |
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. | |
91447636 A |
1235 | * |
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 | |
1238 | * | |
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 | |
1241 | * | |
43866e37 A |
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. | |
1245 | * | |
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. | |
1249 | * | |
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. | |
1253 | * | |
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. | |
91447636 A |
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> | |
43866e37 A |
1261 | * |
1262 | * hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little. | |
1263 | * | |
1264 | * hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system. | |
1265 | * | |
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. | |
1269 | * | |
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. | |
1272 | * hw.l2cachesize - | |
1273 | * hw.l3cachesize - | |
1274 | * | |
2d21ac55 | 1275 | * hw.packages - Gives the number of processor packages. |
43866e37 | 1276 | * |
a39ff7e2 | 1277 | * These are the selectors for optional processor features for specific processors. Selectors that return errors are not support |
0c530ab8 A |
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. | |
1280 | * | |
1281 | * For PowerPC: | |
43866e37 A |
1282 | * |
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 | |
1292 | * | |
0c530ab8 | 1293 | * For x86 Architecture: |
a39ff7e2 | 1294 | * |
2d21ac55 A |
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 | |
43866e37 A |
1302 | */ |
1303 | ||
1304 | ||
1c79356b A |
1305 | /* |
1306 | * CTL_USER definitions | |
1307 | */ | |
0a7de745 A |
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 */ | |
1329 | ||
1330 | #define CTL_USER_NAMES { \ | |
1c79356b A |
1331 | { 0, 0 }, \ |
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 }, \ | |
9bccf70c | 1351 | { "tzname_max", CTLTYPE_INT } \ |
1c79356b A |
1352 | } |
1353 | ||
1354 | ||
1355 | ||
1356 | /* | |
1357 | * CTL_DEBUG definitions | |
1358 | * | |
1359 | * Second level identifier specifies which debug variable. | |
1360 | * Third level identifier specifies which stucture component. | |
1361 | */ | |
0a7de745 A |
1362 | #define CTL_DEBUG_NAME 0 /* string: variable name */ |
1363 | #define CTL_DEBUG_VALUE 1 /* int: variable value */ | |
1364 | #define CTL_DEBUG_MAXID 20 | |
1c79356b | 1365 | |
2d21ac55 | 1366 | |
f427ee49 | 1367 | #if (CTL_MAXID != 9) || (KERN_MAXID != 72) || (VM_MAXID != 6) || (HW_MAXID != 28) || (USER_MAXID != 21) || (CTL_DEBUG_MAXID != 20) |
2d21ac55 A |
1368 | #error Use the SYSCTL_*() macros and OID_AUTO instead! |
1369 | #endif | |
1370 | ||
1371 | ||
0a7de745 | 1372 | #ifdef KERNEL |
1c79356b | 1373 | |
91447636 | 1374 | #ifdef BSD_KERNEL_PRIVATE |
0a7de745 A |
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) | |
1382 | /* | |
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. | |
1386 | */ | |
1387 | #define MACOS_VERS_LEN 15 | |
1388 | ||
1389 | extern char macosproductversion[]; | |
1390 | extern char macosversion[]; | |
1391 | #endif | |
1c79356b | 1392 | |
0a7de745 | 1393 | void sysctl_mib_init(void); |
c3c9b80d | 1394 | void hvg_bsd_init(void); |
2d21ac55 | 1395 | |
91447636 | 1396 | #endif /* BSD_KERNEL_PRIVATE */ |
0a7de745 | 1397 | #else /* !KERNEL */ |
1c79356b A |
1398 | |
1399 | __BEGIN_DECLS | |
0a7de745 A |
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 *); | |
1c79356b | 1403 | __END_DECLS |
91447636 | 1404 | |
0a7de745 | 1405 | #endif /* KERNEL */ |
91447636 A |
1406 | |
1407 | ||
1408 | #endif /* SYSCTL_DEF_ENABLED */ | |
1409 | ||
1410 | ||
0a7de745 | 1411 | #endif /* !_SYS_SYSCTL_H_ */ |