1 | /* |
2 | * Copyright (c) 2000-2021 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License |
8 | * Version 2.0 (the 'License'). You may not use this file except in |
9 | * compliance with the License. The rights granted to you under the License |
10 | * may not be used to create, or enable the creation or redistribution of, |
11 | * unlawful or unlicensed copies of an Apple operating system, or to |
12 | * circumvent, violate, or enable the circumvention or violation of, any |
13 | * terms of an Apple operating system software license agreement. |
14 | * |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
17 | * |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and |
24 | * limitations under the License. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ |
29 | /* |
30 | * Copyright (c) 1989, 1993 |
31 | * The Regents of the University of California. All rights reserved. |
32 | * |
33 | * This code is derived from software contributed to Berkeley by |
34 | * Mike Karels at Berkeley Software Design, Inc. |
35 | * |
36 | * Redistribution and use in source and binary forms, with or without |
37 | * modification, are permitted provided that the following conditions |
38 | * are met: |
39 | * 1. Redistributions of source code must retain the above copyright |
40 | * notice, this list of conditions and the following disclaimer. |
41 | * 2. Redistributions in binary form must reproduce the above copyright |
42 | * notice, this list of conditions and the following disclaimer in the |
43 | * documentation and/or other materials provided with the distribution. |
44 | * 3. All advertising materials mentioning features or use of this software |
45 | * must display the following acknowledgement: |
46 | * This product includes software developed by the University of |
47 | * California, Berkeley and its contributors. |
48 | * 4. Neither the name of the University nor the names of its contributors |
49 | * may be used to endorse or promote products derived from this software |
50 | * without specific prior written permission. |
51 | * |
52 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
53 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
55 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
58 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
62 | * SUCH DAMAGE. |
63 | * |
64 | * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 |
65 | */ |
66 | /* |
67 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce |
68 | * support for mandatory and extensible security protections. This notice |
69 | * is included in support of clause 2.2 (b) of the Apple Public License, |
70 | * Version 2.0. |
71 | */ |
72 | |
73 | #ifndef _SYS_SYSCTL_H_ |
74 | #define _SYS_SYSCTL_H_ |
75 | |
76 | /* |
77 | * These are for the eproc structure defined below. |
78 | */ |
79 | #include <sys/cdefs.h> |
80 | |
81 | #include <sys/appleapiopts.h> |
82 | #ifndef KERNEL |
83 | #include <sys/time.h> |
84 | #include <sys/ucred.h> |
85 | #else |
86 | #ifdef XNU_KERNEL_PRIVATE |
87 | #include <kern/startup.h> |
88 | #include <libkern/section_keywords.h> |
89 | #else |
90 | #include <libkern/sysctl.h> |
91 | #include <os/base.h> |
92 | #endif /* XNU_KERNEL_PRIVATE */ |
93 | #endif /* KERNEL */ |
94 | |
95 | #include <sys/proc.h> |
96 | #include <sys/vm.h> |
97 | |
98 | /* |
99 | * Definitions for sysctl call. The sysctl call uses a hierarchical name |
100 | * for objects that can be examined or modified. The name is expressed as |
101 | * a sequence of integers. Like a file path name, the meaning of each |
102 | * component depends on its place in the hierarchy. The top-level and kern |
103 | * identifiers are defined here, and other identifiers are defined in the |
104 | * respective subsystem header files. |
105 | */ |
106 | |
107 | #define CTL_MAXNAME 12 /* largest number of components supported */ |
108 | |
109 | /* |
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. |
115 | * |
116 | * When declaring new sysctl names, use the CTLFLAG_LOCKED flag in the |
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 |
121 | * and will be protected by a global mutex. |
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). |
142 | */ |
143 | struct ctlname { |
144 | char *ctl_name; /* subsystem name */ |
145 | int ctl_type; /* type of name */ |
146 | }; |
147 | |
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. */ |
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. |
177 | * |
178 | * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); |
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 | */ |
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 */ |
197 | |
198 | #ifdef KERNEL |
199 | #define SYSCTL_HANDLER_ARGS \ |
200 | (struct sysctl_oid *oidp __unused, void *arg1 __unused, int arg2 __unused, \ |
201 | struct sysctl_req *req) |
202 | |
203 | |
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 { |
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); |
219 | }; |
220 | |
221 | SLIST_HEAD(sysctl_oid_list, sysctl_oid); |
222 | |
223 | #define SYSCTL_OID_VERSION 1 /* current OID structure version */ |
224 | |
225 | /* |
226 | * This describes one "oid" in the MIB tree. Potentially more nodes can |
227 | * be hidden behind it, expanded by the handler. |
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 | * |
245 | * Non CTLFLAG_OID2 based sysctls are deprecated and unavailable |
246 | * to non Intel platforms. |
247 | * |
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. |
262 | */ |
263 | struct sysctl_oid { |
264 | struct sysctl_oid_list * OS_PTRAUTH_SIGNED_PTR("sysctl_oid.oid_parent" ) oid_parent; |
265 | SLIST_ENTRY(sysctl_oid) oid_link; |
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; |
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 | |
281 | typedef int (* sysctl_handler_t) SYSCTL_HANDLER_ARGS; |
282 | |
283 | __BEGIN_DECLS |
284 | |
285 | /* old interface */ |
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; |
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); |
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 | |
303 | #define nvram_osenvironment "osenvironment" |
304 | void sysctl_set_osenvironment(unsigned int size, const void* value); |
305 | void sysctl_unblock_osenvironment(void); |
306 | |
307 | /* Deprecated */ |
308 | void sysctl_register_fixed(void) __deprecated; |
309 | |
310 | __END_DECLS |
311 | |
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 |
315 | |
316 | /* |
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 |
320 | * own, SYSCTL_PROC. |
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: |
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. |
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 |
337 | * "P" - pointer |
338 | * "Q" - quads |
339 | * "S","T" - clock info, see sysctl.c in system_cmds (you probably don't need this) |
340 | * Description: unused |
341 | */ |
342 | |
343 | |
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, \ |
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, \ |
356 | } |
357 | |
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 |
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) |
456 | |
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 */ |
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, \ |
467 | arg, len, sysctl_handle_string, "A", descr) |
468 | |
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) |
472 | |
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) |
476 | |
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"); |
483 | |
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"); |
490 | |
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"); |
497 | |
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"); |
504 | |
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"); |
511 | |
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) |
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, \ |
520 | ptr, sizeof(struct type), sysctl_handle_opaque, \ |
521 | "S," #type, descr) |
522 | |
523 | /* |
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 | */ |
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) |
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); |
593 | |
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 */ |
635 | |
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 | #if DEVELOPMENT || DEBUG |
647 | SYSCTL_DECL(_debug_test); |
648 | #endif /* DEVELOPMENT || DEBUG */ |
649 | |
650 | #ifdef PRIVATE |
651 | SYSCTL_DECL(_kern_bridge); |
652 | SYSCTL_DECL(_hw_features); |
653 | #endif |
654 | |
655 | #if defined(BSD_KERNEL_PRIVATE) && SKYWALK |
656 | #include <skywalk/os_sysctls_private.h> |
657 | #endif /* defined(BSD_KERNEL_PRIVATE) && SKYWALK */ |
658 | |
659 | #ifndef SYSCTL_SKMEM_UPDATE_FIELD |
660 | |
661 | #define SYSCTL_SKMEM 0 |
662 | #define SYSCTL_SKMEM_UPDATE_FIELD(field, value) |
663 | #define SYSCTL_SKMEM_UPDATE_AT_OFFSET(offset, value) |
664 | #define SYSCTL_SKMEM_INT(parent, oid, sysctl_name, access, ptr, offset, descr) \ |
665 | SYSCTL_INT(parent, oid, sysctl_name, access, ptr, 0, descr) |
666 | |
667 | #define SYSCTL_SKMEM_TCP_INT(oid, sysctl_name, access, variable_type, \ |
668 | variable_name, initial_value, descr) \ |
669 | variable_type variable_name = initial_value; \ |
670 | SYSCTL_SKMEM_INT(_net_inet_tcp, oid, sysctl_name, access, \ |
671 | &variable_name, 0, descr) |
672 | |
673 | #else /* SYSCTL_SKMEM_UPDATE_FIELD */ |
674 | #define SYSCTL_SKMEM 1 |
675 | #endif /* SYSCTL_SKMEM_UPDATE_FIELD */ |
676 | |
677 | |
678 | |
679 | #endif /* KERNEL */ |
680 | |
681 | #ifdef XNU_KERNEL_PRIVATE |
682 | #define SYSCTL_DEF_ENABLED |
683 | #else |
684 | #ifndef KERNEL |
685 | #define SYSCTL_DEF_ENABLED |
686 | #endif |
687 | #endif |
688 | |
689 | #ifdef SYSCTL_DEF_ENABLED |
690 | /* |
691 | * Top-level identifiers |
692 | */ |
693 | #define CTL_UNSPEC 0 /* unused */ |
694 | #define CTL_KERN 1 /* "high kernel": proc, limits */ |
695 | #define CTL_VM 2 /* virtual memory */ |
696 | #define CTL_VFS 3 /* file system, mount type is next */ |
697 | #define CTL_NET 4 /* network, see socket.h */ |
698 | #define CTL_DEBUG 5 /* debugging parameters */ |
699 | #define CTL_HW 6 /* generic cpu/io */ |
700 | #define CTL_MACHDEP 7 /* machine dependent */ |
701 | #define CTL_USER 8 /* user-level */ |
702 | #define CTL_MAXID 9 /* number of valid top-level ids */ |
703 | |
704 | #define CTL_NAMES { \ |
705 | { 0, 0 }, \ |
706 | { "kern", CTLTYPE_NODE }, \ |
707 | { "vm", CTLTYPE_NODE }, \ |
708 | { "vfs", CTLTYPE_NODE }, \ |
709 | { "net", CTLTYPE_NODE }, \ |
710 | { "debug", CTLTYPE_NODE }, \ |
711 | { "hw", CTLTYPE_NODE }, \ |
712 | { "machdep", CTLTYPE_NODE }, \ |
713 | { "user", CTLTYPE_NODE }, \ |
714 | } |
715 | |
716 | /* |
717 | * CTL_KERN identifiers |
718 | */ |
719 | #define KERN_OSTYPE 1 /* string: system version */ |
720 | #define KERN_OSRELEASE 2 /* string: system release */ |
721 | #define KERN_OSREV 3 /* int: system revision */ |
722 | #define KERN_VERSION 4 /* string: compile time info */ |
723 | #define KERN_MAXVNODES 5 /* int: max vnodes */ |
724 | #define KERN_MAXPROC 6 /* int: max processes */ |
725 | #define KERN_MAXFILES 7 /* int: max open files */ |
726 | #define KERN_ARGMAX 8 /* int: max arguments to exec */ |
727 | #define KERN_SECURELVL 9 /* int: system security level */ |
728 | #define KERN_HOSTNAME 10 /* string: hostname */ |
729 | #define KERN_HOSTID 11 /* int: host identifier */ |
730 | #define KERN_CLOCKRATE 12 /* struct: struct clockrate */ |
731 | #define KERN_VNODE 13 /* struct: vnode structures */ |
732 | #define KERN_PROC 14 /* struct: process entries */ |
733 | #define KERN_FILE 15 /* struct: file entries */ |
734 | #define KERN_PROF 16 /* node: kernel profiling info */ |
735 | #define KERN_POSIX1 17 /* int: POSIX.1 version */ |
736 | #define KERN_NGROUPS 18 /* int: # of supplemental group ids */ |
737 | #define KERN_JOB_CONTROL 19 /* int: is job control available */ |
738 | #define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ |
739 | #define KERN_BOOTTIME 21 /* struct: time kernel was booted */ |
740 | #define KERN_NISDOMAINNAME 22 /* string: YP domain name */ |
741 | #define KERN_DOMAINNAME KERN_NISDOMAINNAME |
742 | #define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */ |
743 | #define KERN_KDEBUG 24 /* int: kernel trace points */ |
744 | #define KERN_UPDATEINTERVAL 25 /* int: update process sleep time */ |
745 | #define KERN_OSRELDATE 26 /* int: OS release date */ |
746 | #define KERN_NTP_PLL 27 /* node: NTP PLL control */ |
747 | #define KERN_BOOTFILE 28 /* string: name of booted kernel */ |
748 | #define KERN_MAXFILESPERPROC 29 /* int: max open files per proc */ |
749 | #define KERN_MAXPROCPERUID 30 /* int: max processes per uid */ |
750 | #define KERN_DUMPDEV 31 /* dev_t: device to dump on */ |
751 | #define KERN_IPC 32 /* node: anything related to IPC */ |
752 | #define KERN_DUMMY 33 /* unused */ |
753 | #define KERN_PS_STRINGS 34 /* int: address of PS_STRINGS */ |
754 | #define KERN_USRSTACK32 35 /* int: address of USRSTACK */ |
755 | #define KERN_LOGSIGEXIT 36 /* int: do we log sigexit procs? */ |
756 | #define KERN_SYMFILE 37 /* string: kernel symbol filename */ |
757 | #define KERN_PROCARGS 38 |
758 | /* 39 was KERN_PCSAMPLES... now obsolete */ |
759 | #define KERN_NETBOOT 40 /* int: are we netbooted? 1=yes,0=no */ |
760 | /* 41 was KERN_PANICINFO : panic UI information (deprecated) */ |
761 | #define KERN_SYSV 42 /* node: System V IPC information */ |
762 | #define KERN_AFFINITY 43 /* xxx */ |
763 | #define KERN_TRANSLATE 44 /* xxx */ |
764 | #define KERN_CLASSIC KERN_TRANSLATE /* XXX backwards compat */ |
765 | #define KERN_EXEC 45 /* xxx */ |
766 | #define KERN_CLASSICHANDLER KERN_EXEC /* XXX backwards compatibility */ |
767 | #define KERN_AIOMAX 46 /* int: max aio requests */ |
768 | #define KERN_AIOPROCMAX 47 /* int: max aio requests per process */ |
769 | #define KERN_AIOTHREADS 48 /* int: max aio worker threads */ |
770 | #ifdef __APPLE_API_UNSTABLE |
771 | #define KERN_PROCARGS2 49 |
772 | #endif /* __APPLE_API_UNSTABLE */ |
773 | #define KERN_COREFILE 50 /* string: corefile format string */ |
774 | #define KERN_COREDUMP 51 /* int: whether to coredump at all */ |
775 | #define KERN_SUGID_COREDUMP 52 /* int: whether to dump SUGID cores */ |
776 | #define KERN_PROCDELAYTERM 53 /* int: set/reset current proc for delayed termination during shutdown */ |
777 | #define KERN_SHREG_PRIVATIZABLE 54 /* int: can shared regions be privatized ? */ |
778 | /* 55 was KERN_PROC_LOW_PRI_IO... now deprecated */ |
779 | #define KERN_LOW_PRI_WINDOW 56 /* int: set/reset throttle window - milliseconds */ |
780 | #define KERN_LOW_PRI_DELAY 57 /* int: set/reset throttle delay - milliseconds */ |
781 | #define KERN_POSIX 58 /* node: posix tunables */ |
782 | #define KERN_USRSTACK64 59 /* LP64 user stack query */ |
783 | #define KERN_NX_PROTECTION 60 /* int: whether no-execute protection is enabled */ |
784 | #define KERN_TFP 61 /* Task for pid settings */ |
785 | #define KERN_PROCNAME 62 /* setup process program name(2*MAXCOMLEN) */ |
786 | #define KERN_THALTSTACK 63 /* for compat with older x86 and does nothing */ |
787 | #define KERN_SPECULATIVE_READS 64 /* int: whether speculative reads are disabled */ |
788 | #define KERN_OSVERSION 65 /* for build number i.e. 9A127 */ |
789 | #define KERN_SAFEBOOT 66 /* are we booted safe? */ |
790 | /* 67 was KERN_LCTX (login context) */ |
791 | #define KERN_RAGEVNODE 68 |
792 | #define KERN_TTY 69 /* node: tty settings */ |
793 | #define KERN_CHECKOPENEVT 70 /* spi: check the VOPENEVT flag on vnodes at open time */ |
794 | #define KERN_THREADNAME 71 /* set/get thread name */ |
795 | #define KERN_MAXID 72 /* number of valid kern ids */ |
796 | /* |
797 | * Don't add any more sysctls like this. Instead, use the SYSCTL_*() macros |
798 | * and OID_AUTO. This will have the added benefit of not having to recompile |
799 | * sysctl(8) to pick up your changes. |
800 | */ |
801 | |
802 | #if COUNT_SYSCALLS && defined(KERNEL) |
803 | #define KERN_COUNT_SYSCALLS (KERN_OSTYPE + 1000) /* keep called count for each bsd syscall */ |
804 | #endif |
805 | |
806 | #if defined(__LP64__) |
807 | #define KERN_USRSTACK KERN_USRSTACK64 |
808 | #else |
809 | #define KERN_USRSTACK KERN_USRSTACK32 |
810 | #endif |
811 | |
812 | |
813 | /* KERN_RAGEVNODE types */ |
814 | #define KERN_RAGE_PROC 1 |
815 | #define KERN_RAGE_THREAD 2 |
816 | #define KERN_UNRAGE_PROC 3 |
817 | #define KERN_UNRAGE_THREAD 4 |
818 | |
819 | /* KERN_OPENEVT types */ |
820 | #define KERN_OPENEVT_PROC 1 |
821 | #define KERN_UNOPENEVT_PROC 2 |
822 | |
823 | /* KERN_TFP types */ |
824 | #define KERN_TFP_POLICY 1 |
825 | |
826 | /* KERN_TFP_POLICY values . All policies allow task port for self */ |
827 | #define KERN_TFP_POLICY_DENY 0 /* Deny Mode: None allowed except privileged */ |
828 | #define KERN_TFP_POLICY_DEFAULT 2 /* Default Mode: related ones allowed and upcall authentication */ |
829 | |
830 | /* KERN_KDEBUG types */ |
831 | #define KERN_KDEFLAGS 1 |
832 | #define KERN_KDDFLAGS 2 |
833 | #define KERN_KDENABLE 3 |
834 | #define KERN_KDSETBUF 4 |
835 | #define KERN_KDGETBUF 5 |
836 | #define KERN_KDSETUP 6 |
837 | #define KERN_KDREMOVE 7 |
838 | #define KERN_KDSETREG 8 |
839 | #define KERN_KDGETREG 9 |
840 | #define KERN_KDREADTR 10 |
841 | #define KERN_KDPIDTR 11 |
842 | #define KERN_KDTHRMAP 12 |
843 | /* Don't use 13 as it is overloaded with KERN_VNODE */ |
844 | #define KERN_KDPIDEX 14 |
845 | #define KERN_KDSETRTCDEC 15 /* obsolete */ |
846 | #define KERN_KDGETENTROPY 16 /* obsolete */ |
847 | #define KERN_KDWRITETR 17 |
848 | #define KERN_KDWRITEMAP 18 |
849 | #define KERN_KDTEST 19 |
850 | /* 20 unused */ |
851 | #define KERN_KDREADCURTHRMAP 21 |
852 | #define KERN_KDSET_TYPEFILTER 22 |
853 | #define KERN_KDBUFWAIT 23 |
854 | #define KERN_KDCPUMAP 24 |
855 | #define KERN_KDCPUMAP_EXT 25 |
856 | #define KERN_KDSET_EDM 26 |
857 | #define KERN_KDGET_EDM 27 |
858 | #define KERN_KDWRITETR_V3 28 |
859 | |
860 | #define CTL_KERN_NAMES { \ |
861 | { 0, 0 }, \ |
862 | { "ostype", CTLTYPE_STRING }, \ |
863 | { "osrelease", CTLTYPE_STRING }, \ |
864 | { "osrevision", CTLTYPE_INT }, \ |
865 | { "version", CTLTYPE_STRING }, \ |
866 | { "maxvnodes", CTLTYPE_INT }, \ |
867 | { "maxproc", CTLTYPE_INT }, \ |
868 | { "maxfiles", CTLTYPE_INT }, \ |
869 | { "argmax", CTLTYPE_INT }, \ |
870 | { "securelevel", CTLTYPE_INT }, \ |
871 | { "hostname", CTLTYPE_STRING }, \ |
872 | { "hostid", CTLTYPE_INT }, \ |
873 | { "clockrate", CTLTYPE_STRUCT }, \ |
874 | { "vnode", CTLTYPE_STRUCT }, \ |
875 | { "proc", CTLTYPE_STRUCT }, \ |
876 | { "file", CTLTYPE_STRUCT }, \ |
877 | { "profiling", CTLTYPE_NODE }, \ |
878 | { "posix1version", CTLTYPE_INT }, \ |
879 | { "ngroups", CTLTYPE_INT }, \ |
880 | { "job_control", CTLTYPE_INT }, \ |
881 | { "saved_ids", CTLTYPE_INT }, \ |
882 | { "boottime", CTLTYPE_STRUCT }, \ |
883 | { "nisdomainname", CTLTYPE_STRING }, \ |
884 | { "maxpartitions", CTLTYPE_INT }, \ |
885 | { "kdebug", CTLTYPE_INT }, \ |
886 | { "update", CTLTYPE_INT }, \ |
887 | { "osreldate", CTLTYPE_INT }, \ |
888 | { "ntp_pll", CTLTYPE_NODE }, \ |
889 | { "bootfile", CTLTYPE_STRING }, \ |
890 | { "maxfilesperproc", CTLTYPE_INT }, \ |
891 | { "maxprocperuid", CTLTYPE_INT }, \ |
892 | { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \ |
893 | { "ipc", CTLTYPE_NODE }, \ |
894 | { "dummy", CTLTYPE_INT }, \ |
895 | { "dummy", CTLTYPE_INT }, \ |
896 | { "usrstack", CTLTYPE_INT }, \ |
897 | { "logsigexit", CTLTYPE_INT }, \ |
898 | { "symfile",CTLTYPE_STRING },\ |
899 | { "procargs",CTLTYPE_STRUCT },\ |
900 | { "dummy", CTLTYPE_INT }, /* deprecated pcsamples */ \ |
901 | { "netboot", CTLTYPE_INT }, \ |
902 | { "dummy", CTLTYPE_INT }, /* deprecated: panicinfo */ \ |
903 | { "sysv", CTLTYPE_NODE }, \ |
904 | { "dummy", CTLTYPE_INT }, \ |
905 | { "dummy", CTLTYPE_INT }, \ |
906 | { "exec", CTLTYPE_NODE }, \ |
907 | { "aiomax", CTLTYPE_INT }, \ |
908 | { "aioprocmax", CTLTYPE_INT }, \ |
909 | { "aiothreads", CTLTYPE_INT }, \ |
910 | { "procargs2",CTLTYPE_STRUCT }, \ |
911 | { "corefile",CTLTYPE_STRING }, \ |
912 | { "coredump", CTLTYPE_INT }, \ |
913 | { "sugid_coredump", CTLTYPE_INT }, \ |
914 | { "delayterm", CTLTYPE_INT }, \ |
915 | { "shreg_private", CTLTYPE_INT }, \ |
916 | { "proc_low_pri_io", CTLTYPE_INT }, \ |
917 | { "low_pri_window", CTLTYPE_INT }, \ |
918 | { "low_pri_delay", CTLTYPE_INT }, \ |
919 | { "posix", CTLTYPE_NODE }, \ |
920 | { "usrstack64", CTLTYPE_QUAD }, \ |
921 | { "nx", CTLTYPE_INT }, \ |
922 | { "tfp", CTLTYPE_NODE }, \ |
923 | { "procname", CTLTYPE_STRING }, \ |
924 | { "threadsigaltstack", CTLTYPE_INT }, \ |
925 | { "speculative_reads_disabled", CTLTYPE_INT }, \ |
926 | { "osversion", CTLTYPE_STRING }, \ |
927 | { "safeboot", CTLTYPE_INT }, \ |
928 | { "dummy", CTLTYPE_INT }, /* deprecated: lctx */ \ |
929 | { "rage_vnode", CTLTYPE_INT }, \ |
930 | { "tty", CTLTYPE_NODE }, \ |
931 | { "check_openevt", CTLTYPE_INT }, \ |
932 | { "thread_name", CTLTYPE_STRING } \ |
933 | } |
934 | |
935 | /* |
936 | * CTL_VFS identifiers |
937 | */ |
938 | #define CTL_VFS_NAMES { \ |
939 | { "vfsconf", CTLTYPE_STRUCT } \ |
940 | } |
941 | |
942 | /* |
943 | * KERN_PROC subtypes |
944 | */ |
945 | #define KERN_PROC_ALL 0 /* everything */ |
946 | #define KERN_PROC_PID 1 /* by process id */ |
947 | #define KERN_PROC_PGRP 2 /* by process group id */ |
948 | #define KERN_PROC_SESSION 3 /* by session of pid */ |
949 | #define KERN_PROC_TTY 4 /* by controlling tty */ |
950 | #define KERN_PROC_UID 5 /* by effective uid */ |
951 | #define KERN_PROC_RUID 6 /* by real uid */ |
952 | #define KERN_PROC_LCID 7 /* by login context id */ |
953 | |
954 | /* |
955 | * KERN_VFSNSPACE subtypes |
956 | */ |
957 | #define KERN_VFSNSPACE_HANDLE_PROC 1 |
958 | #define KERN_VFSNSPACE_UNHANDLE_PROC 2 |
959 | |
960 | #if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) |
961 | /* |
962 | * KERN_PROC subtype ops return arrays of augmented proc structures: |
963 | */ |
964 | |
965 | struct _pcred { |
966 | char pc_lock[72]; /* opaque content */ |
967 | struct ucred *pc_ucred; /* Current credentials. */ |
968 | uid_t p_ruid; /* Real user id. */ |
969 | uid_t p_svuid; /* Saved effective user id. */ |
970 | gid_t p_rgid; /* Real group id. */ |
971 | gid_t p_svgid; /* Saved effective group id. */ |
972 | int p_refcnt; /* Number of references. */ |
973 | }; |
974 | |
975 | struct _ucred { |
976 | int32_t cr_ref; /* reference count */ |
977 | uid_t cr_uid; /* effective user id */ |
978 | short cr_ngroups; /* number of groups */ |
979 | gid_t cr_groups[NGROUPS]; /* groups */ |
980 | }; |
981 | |
982 | struct kinfo_proc { |
983 | struct extern_proc kp_proc; /* proc structure */ |
984 | struct eproc { |
985 | struct proc *e_paddr; /* address of proc */ |
986 | struct session *e_sess; /* session pointer */ |
987 | struct _pcred e_pcred; /* process credentials */ |
988 | struct _ucred e_ucred; /* current credentials */ |
989 | struct vmspace e_vm; /* address space */ |
990 | pid_t e_ppid; /* parent process id */ |
991 | pid_t e_pgid; /* process group id */ |
992 | short e_jobc; /* job control counter */ |
993 | dev_t e_tdev; /* controlling tty dev */ |
994 | pid_t e_tpgid; /* tty process group id */ |
995 | struct session *e_tsess; /* tty session pointer */ |
996 | #define WMESGLEN 7 |
997 | char e_wmesg[WMESGLEN + 1]; /* wchan message */ |
998 | segsz_t e_xsize; /* text size */ |
999 | short ; /* text rss */ |
1000 | short e_xccount; /* text references */ |
1001 | short ; |
1002 | int32_t e_flag; |
1003 | #define EPROC_CTTY 0x01 /* controlling tty vnode active */ |
1004 | #define EPROC_SLEADER 0x02 /* session leader */ |
1005 | #define COMAPT_MAXLOGNAME 12 |
1006 | char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */ |
1007 | int32_t e_spare[4]; |
1008 | } kp_eproc; |
1009 | }; |
1010 | |
1011 | #endif /* defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL) */ |
1012 | |
1013 | #ifdef BSD_KERNEL_PRIVATE |
1014 | #include <sys/proc_internal.h> |
1015 | |
1016 | /* LP64 version of _pcred. all pointers |
1017 | * grow when we're dealing with a 64-bit process. |
1018 | * WARNING - keep in sync with _pcred |
1019 | */ |
1020 | |
1021 | struct user32_pcred { |
1022 | char pc_lock[72]; /* opaque content */ |
1023 | user32_addr_t pc_ucred; /* Current credentials. */ |
1024 | uid_t p_ruid; /* Real user id. */ |
1025 | uid_t p_svuid; /* Saved effective user id. */ |
1026 | gid_t p_rgid; /* Real group id. */ |
1027 | gid_t p_svgid; /* Saved effective group id. */ |
1028 | int p_refcnt; /* Number of references. */ |
1029 | }; |
1030 | struct user64_pcred { |
1031 | char pc_lock[72]; /* opaque content */ |
1032 | user64_addr_t pc_ucred; /* Current credentials. */ |
1033 | uid_t p_ruid; /* Real user id. */ |
1034 | uid_t p_svuid; /* Saved effective user id. */ |
1035 | gid_t p_rgid; /* Real group id. */ |
1036 | gid_t p_svgid; /* Saved effective group id. */ |
1037 | int p_refcnt; /* Number of references. */ |
1038 | }; |
1039 | |
1040 | /* LP64 version of kinfo_proc. all pointers |
1041 | * grow when we're dealing with a 64-bit process. |
1042 | * WARNING - keep in sync with kinfo_proc |
1043 | */ |
1044 | struct user32_kinfo_proc { |
1045 | struct user32_extern_proc kp_proc; /* proc structure */ |
1046 | struct user32_eproc { |
1047 | user32_addr_t e_paddr; /* address of proc */ |
1048 | user32_addr_t e_sess; /* session pointer */ |
1049 | struct user32_pcred e_pcred; /* process credentials */ |
1050 | struct _ucred e_ucred; /* current credentials */ |
1051 | struct user32_vmspace e_vm; /* address space */ |
1052 | pid_t e_ppid; /* parent process id */ |
1053 | pid_t e_pgid; /* process group id */ |
1054 | int e_jobc; /* job control counter */ |
1055 | dev_t e_tdev; /* controlling tty dev */ |
1056 | pid_t e_tpgid; /* tty process group id */ |
1057 | user32_addr_t e_tsess; /* tty session pointer */ |
1058 | char e_wmesg[WMESGLEN + 1]; /* wchan message */ |
1059 | segsz_t e_xsize; /* text size */ |
1060 | short e_xrssize; /* text rss */ |
1061 | short e_xccount; /* text references */ |
1062 | short e_xswrss; |
1063 | int32_t e_flag; |
1064 | char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */ |
1065 | int32_t e_spare[4]; |
1066 | } kp_eproc; |
1067 | }; |
1068 | struct user64_kinfo_proc { |
1069 | struct user64_extern_proc kp_proc; /* proc structure */ |
1070 | struct user64_eproc { |
1071 | user_addr_t e_paddr; /* address of proc */ |
1072 | user_addr_t e_sess; /* session pointer */ |
1073 | struct user64_pcred e_pcred; /* process credentials */ |
1074 | struct _ucred e_ucred; /* current credentials */ |
1075 | struct user_vmspace e_vm; /* address space */ |
1076 | pid_t e_ppid; /* parent process id */ |
1077 | pid_t e_pgid; /* process group id */ |
1078 | int e_jobc; /* job control counter */ |
1079 | dev_t e_tdev; /* controlling tty dev */ |
1080 | pid_t e_tpgid; /* tty process group id */ |
1081 | user64_addr_t e_tsess __attribute((aligned(8))); /* tty session pointer */ |
1082 | char e_wmesg[WMESGLEN + 1]; /* wchan message */ |
1083 | segsz_t e_xsize; /* text size */ |
1084 | short e_xrssize; /* text rss */ |
1085 | short e_xccount; /* text references */ |
1086 | short e_xswrss; |
1087 | int32_t e_flag; |
1088 | char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */ |
1089 | int32_t e_spare[4]; |
1090 | } kp_eproc; |
1091 | }; |
1092 | |
1093 | #endif /* BSD_KERNEL_PRIVATE */ |
1094 | |
1095 | /* |
1096 | * KERN_IPC identifiers |
1097 | */ |
1098 | #define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */ |
1099 | #define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */ |
1100 | #define KIPC_SOMAXCONN 3 /* int: max length of connection q */ |
1101 | #define KIPC_MAX_LINKHDR 4 /* int: max length of link header */ |
1102 | #define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */ |
1103 | #define KIPC_MAX_HDR 6 /* int: max total length of headers */ |
1104 | #define KIPC_MAX_DATALEN 7 /* int: max length of data? */ |
1105 | #define KIPC_MBSTAT 8 /* struct: mbuf usage statistics */ |
1106 | #define KIPC_NMBCLUSTERS 9 /* int: maximum mbuf clusters */ |
1107 | #define KIPC_SOQLIMITCOMPAT 10 /* int: socket queue limit */ |
1108 | |
1109 | /* |
1110 | * CTL_VM identifiers |
1111 | */ |
1112 | #define VM_METER 1 /* struct vmmeter */ |
1113 | #define VM_LOADAVG 2 /* struct loadavg */ |
1114 | /* |
1115 | * Note: "3" was skipped sometime ago and should probably remain unused |
1116 | * to avoid any new entry from being accepted by older kernels... |
1117 | */ |
1118 | #define VM_MACHFACTOR 4 /* struct loadavg with mach factor*/ |
1119 | #define VM_SWAPUSAGE 5 /* total swap usage */ |
1120 | #define VM_MAXID 6 /* number of valid vm ids */ |
1121 | |
1122 | #define CTL_VM_NAMES { \ |
1123 | { 0, 0 }, \ |
1124 | { "vmmeter", CTLTYPE_STRUCT }, \ |
1125 | { "loadavg", CTLTYPE_STRUCT }, \ |
1126 | { 0, 0 }, /* placeholder for "3" (see comment above) */ \ |
1127 | { "dummy", CTLTYPE_INT }, \ |
1128 | { "swapusage", CTLTYPE_STRUCT } \ |
1129 | } |
1130 | |
1131 | struct xsw_usage { |
1132 | u_int64_t xsu_total; |
1133 | u_int64_t xsu_avail; |
1134 | u_int64_t xsu_used; |
1135 | u_int32_t xsu_pagesize; |
1136 | boolean_t xsu_encrypted; |
1137 | }; |
1138 | |
1139 | #ifdef __APPLE_API_PRIVATE |
1140 | /* Load average structure. Use of fixpt_t assume <sys/types.h> in scope. */ |
1141 | /* XXX perhaps we should protect fixpt_t, and define it here (or discard it) */ |
1142 | struct loadavg { |
1143 | fixpt_t ldavg[3]; |
1144 | long fscale; |
1145 | }; |
1146 | extern struct loadavg averunnable; |
1147 | #define LSCALE 1000 /* scaling for "fixed point" arithmetic */ |
1148 | |
1149 | #ifdef BSD_KERNEL_PRIVATE |
1150 | |
1151 | struct user32_loadavg { |
1152 | fixpt_t ldavg[3]; |
1153 | user32_long_t fscale; |
1154 | }; |
1155 | |
1156 | struct user64_loadavg { |
1157 | fixpt_t ldavg[3]; |
1158 | user64_long_t fscale; |
1159 | }; |
1160 | |
1161 | #endif /* BSD_KERNEL_PRIVATE */ |
1162 | #endif /* __APPLE_API_PRIVATE */ |
1163 | |
1164 | |
1165 | /* |
1166 | * CTL_HW identifiers |
1167 | */ |
1168 | #define HW_MACHINE 1 /* string: machine class (deprecated: use HW_PRODUCT) */ |
1169 | #define HW_MODEL 2 /* string: specific machine model (deprecated: use HW_TARGET) */ |
1170 | #define HW_NCPU 3 /* int: number of cpus */ |
1171 | #define HW_BYTEORDER 4 /* int: machine byte order */ |
1172 | #define HW_PHYSMEM 5 /* int: total memory */ |
1173 | #define HW_USERMEM 6 /* int: non-kernel memory */ |
1174 | #define HW_PAGESIZE 7 /* int: software page size */ |
1175 | #define HW_DISKNAMES 8 /* strings: disk drive names */ |
1176 | #define HW_DISKSTATS 9 /* struct: diskstats[] */ |
1177 | #define HW_EPOCH 10 /* int: 0 for Legacy, else NewWorld */ |
1178 | #define HW_FLOATINGPT 11 /* int: has HW floating point? */ |
1179 | #define HW_MACHINE_ARCH 12 /* string: machine architecture */ |
1180 | #define HW_VECTORUNIT 13 /* int: has HW vector unit? */ |
1181 | #define HW_BUS_FREQ 14 /* int: Bus Frequency */ |
1182 | #define HW_CPU_FREQ 15 /* int: CPU Frequency */ |
1183 | #define HW_CACHELINE 16 /* int: Cache Line Size in Bytes */ |
1184 | #define HW_L1ICACHESIZE 17 /* int: L1 I Cache Size in Bytes */ |
1185 | #define HW_L1DCACHESIZE 18 /* int: L1 D Cache Size in Bytes */ |
1186 | #define HW_L2SETTINGS 19 /* int: L2 Cache Settings */ |
1187 | #define HW_L2CACHESIZE 20 /* int: L2 Cache Size in Bytes */ |
1188 | #define HW_L3SETTINGS 21 /* int: L3 Cache Settings */ |
1189 | #define HW_L3CACHESIZE 22 /* int: L3 Cache Size in Bytes */ |
1190 | #define HW_TB_FREQ 23 /* int: Bus Frequency */ |
1191 | #define HW_MEMSIZE 24 /* uint64_t: physical ram size */ |
1192 | #define HW_AVAILCPU 25 /* int: number of available CPUs */ |
1193 | #define HW_TARGET 26 /* string: model identifier */ |
1194 | #define HW_PRODUCT 27 /* string: product identifier */ |
1195 | #define HW_MAXID 28 /* number of valid hw ids */ |
1196 | |
1197 | #define CTL_HW_NAMES { \ |
1198 | { 0, 0 }, \ |
1199 | { "machine", CTLTYPE_STRING }, /* Deprecated: use hw.product */ \ |
1200 | { "model", CTLTYPE_STRING }, /* Deprecated: use hw.target */ \ |
1201 | { "ncpu", CTLTYPE_INT }, \ |
1202 | { "byteorder", CTLTYPE_INT }, \ |
1203 | { "physmem", CTLTYPE_INT }, \ |
1204 | { "usermem", CTLTYPE_INT }, \ |
1205 | { "pagesize", CTLTYPE_INT }, \ |
1206 | { "disknames", CTLTYPE_STRUCT }, \ |
1207 | { "diskstats", CTLTYPE_STRUCT }, \ |
1208 | { "epoch", CTLTYPE_INT }, \ |
1209 | { "floatingpoint", CTLTYPE_INT }, \ |
1210 | { "machinearch", CTLTYPE_STRING }, \ |
1211 | { "vectorunit", CTLTYPE_INT }, \ |
1212 | { "busfrequency", CTLTYPE_INT }, \ |
1213 | { "cpufrequency", CTLTYPE_INT }, \ |
1214 | { "cachelinesize", CTLTYPE_INT }, \ |
1215 | { "l1icachesize", CTLTYPE_INT }, \ |
1216 | { "l1dcachesize", CTLTYPE_INT }, \ |
1217 | { "l2settings", CTLTYPE_INT }, \ |
1218 | { "l2cachesize", CTLTYPE_INT }, \ |
1219 | { "l3settings", CTLTYPE_INT }, \ |
1220 | { "l3cachesize", CTLTYPE_INT }, \ |
1221 | { "tbfrequency", CTLTYPE_INT }, \ |
1222 | { "memsize", CTLTYPE_QUAD }, \ |
1223 | { "availcpu", CTLTYPE_INT }, \ |
1224 | { "target", CTLTYPE_STRING }, \ |
1225 | { "product", CTLTYPE_STRING }, \ |
1226 | } |
1227 | |
1228 | /* |
1229 | * XXX This information should be moved to the man page. |
1230 | * |
1231 | * These are the support HW selectors for sysctlbyname. Parameters that are byte counts or frequencies are 64 bit numbers. |
1232 | * All other parameters are 32 bit numbers. |
1233 | * |
1234 | * hw.memsize - The number of bytes of physical memory in the system. |
1235 | * |
1236 | * hw.ncpu - The maximum number of processors that could be available this boot. |
1237 | * Use this value for sizing of static per processor arrays; i.e. processor load statistics. |
1238 | * |
1239 | * hw.activecpu - The number of processors currently available for executing threads. |
1240 | * Use this number to determine the number threads to create in SMP aware applications. |
1241 | * This number can change when power management modes are changed. |
1242 | * |
1243 | * hw.physicalcpu - The number of physical processors available in the current power management mode. |
1244 | * hw.physicalcpu_max - The maximum number of physical processors that could be available this boot |
1245 | * |
1246 | * hw.logicalcpu - The number of logical processors available in the current power management mode. |
1247 | * hw.logicalcpu_max - The maximum number of logical processors that could be available this boot |
1248 | * |
1249 | * hw.tbfrequency - This gives the time base frequency used by the OS and is the basis of all timing services. |
1250 | * In general is is better to use mach's or higher level timing services, but this value |
1251 | * is needed to convert the PPC Time Base registers to real time. |
1252 | * |
1253 | * hw.cpufrequency - These values provide the current, min and max cpu frequency. The min and max are for |
1254 | * hw.cpufrequency_max - all power management modes. The current frequency is the max frequency in the current mode. |
1255 | * hw.cpufrequency_min - All frequencies are in Hz. |
1256 | * |
1257 | * hw.busfrequency - These values provide the current, min and max bus frequency. The min and max are for |
1258 | * hw.busfrequency_max - all power management modes. The current frequency is the max frequency in the current mode. |
1259 | * hw.busfrequency_min - All frequencies are in Hz. |
1260 | * |
1261 | * hw.cputype - These values provide the mach-o cpu type and subtype. A complete list is in <mach/machine.h> |
1262 | * hw.cpusubtype - These values should be used to determine what processor family the running cpu is from so that |
1263 | * the best binary can be chosen, or the best dynamic code generated. They should not be used |
1264 | * to determine if a given processor feature is available. |
1265 | * hw.cputhreadtype - This value will be present if the processor supports threads. Like hw.cpusubtype this selector |
1266 | * should not be used to infer features, and only used to name the processors thread architecture. |
1267 | * The values are defined in <mach/machine.h> |
1268 | * |
1269 | * hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little. |
1270 | * |
1271 | * hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system. |
1272 | * |
1273 | * hw.cachelinesize - Gives the size in bytes of the processor's cache lines. |
1274 | * This value should be use to control the strides of loops that use cache control instructions |
1275 | * like dcbz, dcbt or dcbst. |
1276 | * |
1277 | * hw.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present |
1278 | * hw.l1icachesize - then the selector will return and error. |
1279 | * hw.l2cachesize - |
1280 | * hw.l3cachesize - |
1281 | * |
1282 | * hw.nperflevels - Number of core types in the system. See the parameters below, which can be used to get |
1283 | * - information associated with a specific perf level. |
1284 | * |
1285 | * The following parameters apply to perflevel N, where N is a number between 0 and the number of core types in the system minus one. |
1286 | * perflevel 0 always refers to the highest performance core type in the system. |
1287 | * |
1288 | * hw.perflevelN.physicalcpu - The number of physical processors available in the current power management mode. |
1289 | * hw.perflevelN.physicalcpumax - The maximum number of physical processors that could be available this boot. |
1290 | * hw.perflevelN.logicalcpu - The number of logical processors available in the current power management mode. |
1291 | * hw.perflevelN.logicalcpumax - The maximum number of logical processors that could be available this boot. |
1292 | * |
1293 | * hw.perflevelN.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present |
1294 | * hw.perflevelN.l1icachesize - then the selector will return and error. |
1295 | * hw.perflevelN.l2cachesize - |
1296 | * hw.perflevelN.l3cachesize - |
1297 | * |
1298 | * hw.perflevelN.cpusperl2 - These values provide the number of CPUs of the same type that share L2 and L3 caches. |
1299 | * hw.perflevelN.cpusperl3 - If a cache is not present then the selector will return and error. |
1300 | * |
1301 | * hw.perflevelN.l2perflevels - These values provide a bitmap, where bit number of CPUs of the same type that share L2 and L3 caches. |
1302 | * hw.perflevelN.l3perflevels - If a cache is not present then the selector will return and error. |
1303 | * |
1304 | * hw.packages - Gives the number of processor packages. |
1305 | * |
1306 | * These are the selectors for optional processor features for specific processors. Selectors that return errors are not support |
1307 | * on the system. Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help . |
1308 | * performance. Future versions of these selectors may return larger values as necessary so it is best to test for non zero. |
1309 | * |
1310 | * For PowerPC: |
1311 | * |
1312 | * hw.optional.floatingpoint - Floating Point Instructions |
1313 | * hw.optional.altivec - AltiVec Instructions |
1314 | * hw.optional.graphicsops - Graphics Operations |
1315 | * hw.optional.64bitops - 64-bit Instructions |
1316 | * hw.optional.fsqrt - HW Floating Point Square Root Instruction |
1317 | * hw.optional.stfiwx - Store Floating Point as Integer Word Indexed Instructions |
1318 | * hw.optional.dcba - Data Cache Block Allocate Instruction |
1319 | * hw.optional.datastreams - Data Streams Instructions |
1320 | * hw.optional.dcbtstreams - Data Cache Block Touch Steams Instruction Form |
1321 | * |
1322 | * For x86 Architecture: |
1323 | * |
1324 | * hw.optional.floatingpoint - Floating Point Instructions |
1325 | * hw.optional.mmx - Original MMX vector instructions |
1326 | * hw.optional.sse - Streaming SIMD Extensions |
1327 | * hw.optional.sse2 - Streaming SIMD Extensions 2 |
1328 | * hw.optional.sse3 - Streaming SIMD Extensions 3 |
1329 | * hw.optional.supplementalsse3 - Supplemental Streaming SIMD Extensions 3 |
1330 | * hw.optional.x86_64 - 64-bit support |
1331 | */ |
1332 | |
1333 | |
1334 | /* |
1335 | * CTL_USER definitions |
1336 | */ |
1337 | #define USER_CS_PATH 1 /* string: _CS_PATH */ |
1338 | #define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ |
1339 | #define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ |
1340 | #define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ |
1341 | #define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ |
1342 | #define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ |
1343 | #define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ |
1344 | #define USER_LINE_MAX 8 /* int: LINE_MAX */ |
1345 | #define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ |
1346 | #define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ |
1347 | #define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ |
1348 | #define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ |
1349 | #define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ |
1350 | #define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ |
1351 | #define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ |
1352 | #define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ |
1353 | #define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ |
1354 | #define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ |
1355 | #define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ |
1356 | #define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ |
1357 | #define USER_MAXID 21 /* number of valid user ids */ |
1358 | |
1359 | #define CTL_USER_NAMES { \ |
1360 | { 0, 0 }, \ |
1361 | { "cs_path", CTLTYPE_STRING }, \ |
1362 | { "bc_base_max", CTLTYPE_INT }, \ |
1363 | { "bc_dim_max", CTLTYPE_INT }, \ |
1364 | { "bc_scale_max", CTLTYPE_INT }, \ |
1365 | { "bc_string_max", CTLTYPE_INT }, \ |
1366 | { "coll_weights_max", CTLTYPE_INT }, \ |
1367 | { "expr_nest_max", CTLTYPE_INT }, \ |
1368 | { "line_max", CTLTYPE_INT }, \ |
1369 | { "re_dup_max", CTLTYPE_INT }, \ |
1370 | { "posix2_version", CTLTYPE_INT }, \ |
1371 | { "posix2_c_bind", CTLTYPE_INT }, \ |
1372 | { "posix2_c_dev", CTLTYPE_INT }, \ |
1373 | { "posix2_char_term", CTLTYPE_INT }, \ |
1374 | { "posix2_fort_dev", CTLTYPE_INT }, \ |
1375 | { "posix2_fort_run", CTLTYPE_INT }, \ |
1376 | { "posix2_localedef", CTLTYPE_INT }, \ |
1377 | { "posix2_sw_dev", CTLTYPE_INT }, \ |
1378 | { "posix2_upe", CTLTYPE_INT }, \ |
1379 | { "stream_max", CTLTYPE_INT }, \ |
1380 | { "tzname_max", CTLTYPE_INT } \ |
1381 | } |
1382 | |
1383 | |
1384 | |
1385 | /* |
1386 | * CTL_DEBUG definitions |
1387 | * |
1388 | * Second level identifier specifies which debug variable. |
1389 | * Third level identifier specifies which stucture component. |
1390 | */ |
1391 | #define CTL_DEBUG_NAME 0 /* string: variable name */ |
1392 | #define CTL_DEBUG_VALUE 1 /* int: variable value */ |
1393 | #define CTL_DEBUG_MAXID 20 |
1394 | |
1395 | |
1396 | #if (CTL_MAXID != 9) || (KERN_MAXID != 72) || (VM_MAXID != 6) || (HW_MAXID != 28) || (USER_MAXID != 21) || (CTL_DEBUG_MAXID != 20) |
1397 | #error Use the SYSCTL_*() macros and OID_AUTO instead! |
1398 | #endif |
1399 | |
1400 | |
1401 | #ifdef KERNEL |
1402 | |
1403 | #ifdef BSD_KERNEL_PRIVATE |
1404 | extern char machine[]; |
1405 | extern char osrelease[]; |
1406 | extern char ostype[]; |
1407 | extern char osversion[]; |
1408 | extern char osproductversion[]; |
1409 | extern char osbuild_config[]; |
1410 | #if defined(XNU_TARGET_OS_BRIDGE) |
1411 | /* |
1412 | * 15 characters at maximum so both the productversion |
1413 | * and the build version can fit in the panic header |
1414 | * osversion field with the formatting requirements. |
1415 | */ |
1416 | #define MACOS_VERS_LEN 15 |
1417 | |
1418 | extern char macosproductversion[]; |
1419 | extern char macosversion[]; |
1420 | #endif |
1421 | |
1422 | void sysctl_mib_init(void); |
1423 | |
1424 | #endif /* BSD_KERNEL_PRIVATE */ |
1425 | #else /* !KERNEL */ |
1426 | |
1427 | __BEGIN_DECLS |
1428 | int sysctl(int *, u_int, void *, size_t *, void *, size_t); |
1429 | int sysctlbyname(const char *, void *, size_t *, void *, size_t); |
1430 | int sysctlnametomib(const char *, int *, size_t *); |
1431 | __END_DECLS |
1432 | |
1433 | #endif /* KERNEL */ |
1434 | |
1435 | |
1436 | #endif /* SYSCTL_DEF_ENABLED */ |
1437 | |
1438 | |
1439 | #endif /* !_SYS_SYSCTL_H_ */ |
1440 | |