]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/sysctl.h
xnu-792.6.22.tar.gz
[apple/xnu.git] / bsd / sys / sysctl.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23/*
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * This code is derived from software contributed to Berkeley by
28 * Mike Karels at Berkeley Software Design, Inc.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)sysctl.h 8.1 (Berkeley) 6/2/93
59 */
60
61#ifndef _SYS_SYSCTL_H_
62#define _SYS_SYSCTL_H_
63
64/*
65 * These are for the eproc structure defined below.
66 */
67#include <sys/cdefs.h>
68
69#include <sys/appleapiopts.h>
70#ifndef KERNEL
71#include <sys/time.h>
72#include <sys/ucred.h>
73#else
74#include <libkern/sysctl.h>
75#endif
76#include <sys/proc.h>
77#include <sys/vm.h>
78
79#ifdef BSD_KERNEL_PRIVATE
80#include <sys/linker_set.h>
81#endif
82
83/*
84 * Definitions for sysctl call. The sysctl call uses a hierarchical name
85 * for objects that can be examined or modified. The name is expressed as
86 * a sequence of integers. Like a file path name, the meaning of each
87 * component depends on its place in the hierarchy. The top-level and kern
88 * identifiers are defined here, and other identifiers are defined in the
89 * respective subsystem header files.
90 */
91
92#define CTL_MAXNAME 12 /* largest number of components supported */
93
94/*
95 * Each subsystem defined by sysctl defines a list of variables
96 * for that subsystem. Each name is either a node with further
97 * levels defined below it, or it is a leaf of some particular
98 * type given below. Each sysctl level defines a set of name/type
99 * pairs to be used by sysctl(1) in manipulating the subsystem.
100 */
101struct ctlname {
102 char *ctl_name; /* subsystem name */
103 int ctl_type; /* type of name */
104};
105
106#define CTLTYPE 0xf /* Mask for the type */
107#define CTLTYPE_NODE 1 /* name is a node */
108#define CTLTYPE_INT 2 /* name describes an integer */
109#define CTLTYPE_STRING 3 /* name describes a string */
110#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
111#define CTLTYPE_OPAQUE 5 /* name describes a structure */
112#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
113
114#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
115#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
116#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
117#define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */
118#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
119#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
120#define CTLFLAG_MASKED 0x04000000 /* deprecated variable, do not display */
121#define CTLFLAG_NOAUTO 0x02000000 /* do not auto-register */
122#define CTLFLAG_KERN 0x01000000 /* valid inside the kernel */
123
124/*
125 * USE THIS instead of a hardwired number from the categories below
126 * to get dynamically assigned sysctl entries using the linker-set
127 * technology. This is the way nearly all new sysctl variables should
128 * be implemented.
129 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
130 */
131#define OID_AUTO (-1)
132
133#ifdef KERNEL
134#define SYSCTL_HANDLER_ARGS (struct sysctl_oid *oidp, void *arg1, int arg2, \
135 struct sysctl_req *req)
136
137/*
138 * This describes the access space for a sysctl request. This is needed
139 * so that we can use the interface from the kernel or from user-space.
140 */
141struct sysctl_req {
142 struct proc *p;
143 int lock;
144 user_addr_t oldptr;
145 size_t oldlen;
146 size_t oldidx;
147 int (*oldfunc)(struct sysctl_req *, const void *, size_t);
148 user_addr_t newptr;
149 size_t newlen;
150 size_t newidx;
151 int (*newfunc)(struct sysctl_req *, void *, size_t);
152};
153
154SLIST_HEAD(sysctl_oid_list, sysctl_oid);
155
156/*
157 * This describes one "oid" in the MIB tree. Potentially more nodes can
158 * be hidden behind it, expanded by the handler.
159 */
160struct sysctl_oid {
161 struct sysctl_oid_list *oid_parent;
162 SLIST_ENTRY(sysctl_oid) oid_link;
163 int oid_number;
164 int oid_kind;
165 void *oid_arg1;
166 int oid_arg2;
167 const char *oid_name;
168 int (*oid_handler) SYSCTL_HANDLER_ARGS;
169 const char *oid_fmt;
170};
171
172#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
173#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
174
175__BEGIN_DECLS
176
177int sysctl_handle_int SYSCTL_HANDLER_ARGS;
178int sysctl_handle_long SYSCTL_HANDLER_ARGS;
179int sysctl_handle_quad SYSCTL_HANDLER_ARGS;
180int sysctl_handle_int2quad SYSCTL_HANDLER_ARGS;
181/*int sysctl_handle_intptr SYSCTL_HANDLER_ARGS; XXX not implemented */
182int sysctl_handle_string SYSCTL_HANDLER_ARGS;
183int sysctl_handle_opaque SYSCTL_HANDLER_ARGS;
184
185/*
186 * These functions are used to add/remove an oid from the mib.
187 */
188void sysctl_register_oid(struct sysctl_oid *oidp);
189void sysctl_unregister_oid(struct sysctl_oid *oidp);
190
191__END_DECLS
192
193/* Declare an oid to allow child oids to be added to it. */
194#define SYSCTL_DECL(name) \
195 extern struct sysctl_oid_list sysctl_##name##_children
196
197/* This constructs a "raw" MIB oid. */
198#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
199 struct sysctl_oid sysctl_##parent##_##name = { \
200 &sysctl_##parent##_children, { 0 }, \
201 nbr, kind, a1, a2, #name, handler, fmt };
202
203
204/* This constructs a node from which other oids can hang. */
205#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
206 struct sysctl_oid_list sysctl_##parent##_##name##_children; \
207 SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|access, \
208 (void*)&sysctl_##parent##_##name##_children, 0, handler, \
209 "N", descr);
210
211/* Oid for a string. len can be 0 to indicate '\0' termination. */
212#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \
213 SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|access, \
214 arg, len, sysctl_handle_string, "A", descr)
215
216/* Oid for an int. If ptr is NULL, val is returned. */
217#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
218 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
219 ptr, val, sysctl_handle_int, "I", descr)
220
221/* Oid for an unsigned int. If ptr is NULL, val is returned. */
222#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \
223 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
224 ptr, val, sysctl_handle_int, "IU", descr)
225
226/* Oid for a long. The pointer must be non NULL. */
227#define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \
228 SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \
229 ptr, 0, sysctl_handle_long, "L", descr)
230
231/* Oid for a quad. The pointer must be non NULL. */
232#define SYSCTL_QUAD(parent, nbr, name, access, ptr, descr) \
233 SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
234 ptr, 0, sysctl_handle_quad, "Q", descr)
235
236/* Oid for a int returned as quad. The pointer must be non NULL. */
237#define SYSCTL_INT2QUAD(parent, nbr, name, access, ptr, descr) \
238 SYSCTL_OID(parent, nbr, name, CTLTYPE_QUAD|access, \
239 ptr, 0, sysctl_handle_int2quad, "Q", descr)
240
241/* Oid for an opaque object. Specified by a pointer and a length. */
242#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
243 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
244 ptr, len, sysctl_handle_opaque, fmt, descr)
245
246/* Oid for a struct. Specified by a pointer and a type. */
247#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \
248 SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|access, \
249 ptr, sizeof(struct type), sysctl_handle_opaque, \
250 "S," #type, descr)
251
252/* Oid for a procedure. Specified by a pointer and an arg. */
253#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
254 SYSCTL_OID(parent, nbr, name, access, \
255 ptr, arg, handler, fmt, descr)
256
257
258extern struct sysctl_oid_list sysctl__children;
259SYSCTL_DECL(_kern);
260SYSCTL_DECL(_sysctl);
261SYSCTL_DECL(_vm);
262SYSCTL_DECL(_vfs);
263SYSCTL_DECL(_net);
264SYSCTL_DECL(_debug);
265SYSCTL_DECL(_hw);
266SYSCTL_DECL(_machdep);
267SYSCTL_DECL(_user);
268
269#endif /* KERNEL */
270
271#ifdef XNU_KERNEL_PRIVATE
272#define SYSCTL_DEF_ENABLED
273#else
274#ifndef KERNEL
275#define SYSCTL_DEF_ENABLED
276#endif
277#endif
278
279#ifdef SYSCTL_DEF_ENABLED
280/*
281 * Top-level identifiers
282 */
283#define CTL_UNSPEC 0 /* unused */
284#define CTL_KERN 1 /* "high kernel": proc, limits */
285#define CTL_VM 2 /* virtual memory */
286#define CTL_VFS 3 /* file system, mount type is next */
287#define CTL_NET 4 /* network, see socket.h */
288#define CTL_DEBUG 5 /* debugging parameters */
289#define CTL_HW 6 /* generic cpu/io */
290#define CTL_MACHDEP 7 /* machine dependent */
291#define CTL_USER 8 /* user-level */
292#define CTL_MAXID 9 /* number of valid top-level ids */
293
294#define CTL_NAMES { \
295 { 0, 0 }, \
296 { "kern", CTLTYPE_NODE }, \
297 { "vm", CTLTYPE_NODE }, \
298 { "vfs", CTLTYPE_NODE }, \
299 { "net", CTLTYPE_NODE }, \
300 { "debug", CTLTYPE_NODE }, \
301 { "hw", CTLTYPE_NODE }, \
302 { "machdep", CTLTYPE_NODE }, \
303 { "user", CTLTYPE_NODE }, \
304}
305
306/*
307 * CTL_KERN identifiers
308 */
309#define KERN_OSTYPE 1 /* string: system version */
310#define KERN_OSRELEASE 2 /* string: system release */
311#define KERN_OSREV 3 /* int: system revision */
312#define KERN_VERSION 4 /* string: compile time info */
313#define KERN_MAXVNODES 5 /* int: max vnodes */
314#define KERN_MAXPROC 6 /* int: max processes */
315#define KERN_MAXFILES 7 /* int: max open files */
316#define KERN_ARGMAX 8 /* int: max arguments to exec */
317#define KERN_SECURELVL 9 /* int: system security level */
318#define KERN_HOSTNAME 10 /* string: hostname */
319#define KERN_HOSTID 11 /* int: host identifier */
320#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
321#define KERN_VNODE 13 /* struct: vnode structures */
322#define KERN_PROC 14 /* struct: process entries */
323#define KERN_FILE 15 /* struct: file entries */
324#define KERN_PROF 16 /* node: kernel profiling info */
325#define KERN_POSIX1 17 /* int: POSIX.1 version */
326#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
327#define KERN_JOB_CONTROL 19 /* int: is job control available */
328#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
329#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
330#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
331#define KERN_DOMAINNAME KERN_NISDOMAINNAME
332#define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */
333#define KERN_KDEBUG 24 /* int: kernel trace points */
334#define KERN_UPDATEINTERVAL 25 /* int: update process sleep time */
335#define KERN_OSRELDATE 26 /* int: OS release date */
336#define KERN_NTP_PLL 27 /* node: NTP PLL control */
337#define KERN_BOOTFILE 28 /* string: name of booted kernel */
338#define KERN_MAXFILESPERPROC 29 /* int: max open files per proc */
339#define KERN_MAXPROCPERUID 30 /* int: max processes per uid */
340#define KERN_DUMPDEV 31 /* dev_t: device to dump on */
341#define KERN_IPC 32 /* node: anything related to IPC */
342#define KERN_DUMMY 33 /* unused */
343#define KERN_PS_STRINGS 34 /* int: address of PS_STRINGS */
344#define KERN_USRSTACK32 35 /* int: address of USRSTACK */
345#define KERN_LOGSIGEXIT 36 /* int: do we log sigexit procs? */
346#define KERN_SYMFILE 37 /* string: kernel symbol filename */
347#define KERN_PROCARGS 38
348#define KERN_PCSAMPLES 39 /* node: pc sampling */
349#define KERN_NETBOOT 40 /* int: are we netbooted? 1=yes,0=no */
350#define KERN_PANICINFO 41 /* node: panic UI information */
351#define KERN_SYSV 42 /* node: System V IPC information */
352#define KERN_AFFINITY 43 /* xxx */
353#define KERN_CLASSIC 44 /* xxx */
354#define KERN_CLASSICHANDLER 45 /* xxx */
355#define KERN_AIOMAX 46 /* int: max aio requests */
356#define KERN_AIOPROCMAX 47 /* int: max aio requests per process */
357#define KERN_AIOTHREADS 48 /* int: max aio worker threads */
358#ifdef __APPLE_API_UNSTABLE
359#define KERN_PROCARGS2 49
360#endif /* __APPLE_API_UNSTABLE */
361#define KERN_COREFILE 50 /* string: corefile format string */
362#define KERN_COREDUMP 51 /* int: whether to coredump at all */
363#define KERN_SUGID_COREDUMP 52 /* int: whether to dump SUGID cores */
364#define KERN_PROCDELAYTERM 53 /* int: set/reset current proc for delayed termination during shutdown */
365#define KERN_SHREG_PRIVATIZABLE 54 /* int: can shared regions be privatized ? */
366#define KERN_PROC_LOW_PRI_IO 55 /* int: set/reset current proc for low priority I/O */
367#define KERN_LOW_PRI_WINDOW 56 /* int: set/reset throttle window - milliseconds */
368#define KERN_LOW_PRI_DELAY 57 /* int: set/reset throttle delay - milliseconds */
369#define KERN_POSIX 58 /* node: posix tunables */
370#define KERN_USRSTACK64 59 /* LP64 user stack query */
371#define KERN_MAXID 60 /* number of valid kern ids */
372
373#if defined(__LP64__)
374#define KERN_USRSTACK KERN_USRSTACK64
375#else
376#define KERN_USRSTACK KERN_USRSTACK32
377#endif
378
379/* KERN_KDEBUG types */
380#define KERN_KDEFLAGS 1
381#define KERN_KDDFLAGS 2
382#define KERN_KDENABLE 3
383#define KERN_KDSETBUF 4
384#define KERN_KDGETBUF 5
385#define KERN_KDSETUP 6
386#define KERN_KDREMOVE 7
387#define KERN_KDSETREG 8
388#define KERN_KDGETREG 9
389#define KERN_KDREADTR 10
390#define KERN_KDPIDTR 11
391#define KERN_KDTHRMAP 12
392/* Don't use 13 as it is overloaded with KERN_VNODE */
393#define KERN_KDPIDEX 14
394#define KERN_KDSETRTCDEC 15
395#define KERN_KDGETENTROPY 16
396
397/* KERN_PCSAMPLES types */
398#define KERN_PCDISABLE 1
399#define KERN_PCSETBUF 2
400#define KERN_PCGETBUF 3
401#define KERN_PCSETUP 4
402#define KERN_PCREMOVE 5
403#define KERN_PCREADBUF 6
404#define KERN_PCSETREG 7
405#define KERN_PCCOMM 8
406
407/* KERN_PANICINFO types */
408#define KERN_PANICINFO_MAXSIZE 1 /* quad: panic UI image size limit */
409#define KERN_PANICINFO_IMAGE 2 /* panic UI in 8-bit kraw format */
410
411/*
412 * KERN_SYSV identifiers
413 */
414#define KSYSV_SHMMAX 1 /* int: max shared memory segment size (bytes) */
415#define KSYSV_SHMMIN 2 /* int: min shared memory segment size (bytes) */
416#define KSYSV_SHMMNI 3 /* int: max number of shared memory identifiers */
417#define KSYSV_SHMSEG 4 /* int: max shared memory segments per process */
418#define KSYSV_SHMALL 5 /* int: max amount of shared memory (pages) */
419#define KSYSV_SEMMNI 6 /* int: max num of semaphore identifiers */
420#define KSYSV_SEMMNS 7 /* int: max num of semaphores in system */
421#define KSYSV_SEMMNU 8 /* int: max num of undo structures in system */
422#define KSYSV_SEMMSL 9 /* int: max num of semaphores per id */
423#define KSYSV_SEMUNE 10 /* int: max num of undo entries per process */
424
425
426#define CTL_KERN_NAMES { \
427 { 0, 0 }, \
428 { "ostype", CTLTYPE_STRING }, \
429 { "osrelease", CTLTYPE_STRING }, \
430 { "osrevision", CTLTYPE_INT }, \
431 { "version", CTLTYPE_STRING }, \
432 { "maxvnodes", CTLTYPE_INT }, \
433 { "maxproc", CTLTYPE_INT }, \
434 { "maxfiles", CTLTYPE_INT }, \
435 { "argmax", CTLTYPE_INT }, \
436 { "securelevel", CTLTYPE_INT }, \
437 { "hostname", CTLTYPE_STRING }, \
438 { "hostid", CTLTYPE_INT }, \
439 { "clockrate", CTLTYPE_STRUCT }, \
440 { "vnode", CTLTYPE_STRUCT }, \
441 { "proc", CTLTYPE_STRUCT }, \
442 { "file", CTLTYPE_STRUCT }, \
443 { "profiling", CTLTYPE_NODE }, \
444 { "posix1version", CTLTYPE_INT }, \
445 { "ngroups", CTLTYPE_INT }, \
446 { "job_control", CTLTYPE_INT }, \
447 { "saved_ids", CTLTYPE_INT }, \
448 { "boottime", CTLTYPE_STRUCT }, \
449 { "nisdomainname", CTLTYPE_STRING }, \
450 { "maxpartitions", CTLTYPE_INT }, \
451 { "kdebug", CTLTYPE_INT }, \
452 { "update", CTLTYPE_INT }, \
453 { "osreldate", CTLTYPE_INT }, \
454 { "ntp_pll", CTLTYPE_NODE }, \
455 { "bootfile", CTLTYPE_STRING }, \
456 { "maxfilesperproc", CTLTYPE_INT }, \
457 { "maxprocperuid", CTLTYPE_INT }, \
458 { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
459 { "ipc", CTLTYPE_NODE }, \
460 { "dummy", CTLTYPE_INT }, \
461 { "dummy", CTLTYPE_INT }, \
462 { "usrstack", CTLTYPE_INT }, \
463 { "logsigexit", CTLTYPE_INT }, \
464 { "symfile",CTLTYPE_STRING },\
465 { "procargs",CTLTYPE_STRUCT },\
466 { "pcsamples",CTLTYPE_STRUCT },\
467 { "netboot", CTLTYPE_INT }, \
468 { "panicinfo", CTLTYPE_NODE }, \
469 { "sysv", CTLTYPE_NODE }, \
470 { "dummy", CTLTYPE_INT }, \
471 { "dummy", CTLTYPE_INT }, \
472 { "dummy", CTLTYPE_INT }, \
473 { "aiomax", CTLTYPE_INT }, \
474 { "aioprocmax", CTLTYPE_INT }, \
475 { "aiothreads", CTLTYPE_INT }, \
476 { "procargs2",CTLTYPE_STRUCT }, \
477 { "corefile",CTLTYPE_STRING }, \
478 { "coredump", CTLTYPE_INT }, \
479 { "sugid_coredump", CTLTYPE_INT }, \
480 { "delayterm", CTLTYPE_INT }, \
481 { "shreg_private", CTLTYPE_INT }, \
482 { "proc_low_pri_io", CTLTYPE_INT }, \
483 { "low_pri_window", CTLTYPE_INT }, \
484 { "low_pri_delay", CTLTYPE_INT }, \
485 { "posix", CTLTYPE_NODE } \
486}
487
488/*
489 * CTL_VFS identifiers
490 */
491#define CTL_VFS_NAMES { \
492 { "vfsconf", CTLTYPE_STRUCT } \
493}
494
495/*
496 * KERN_PROC subtypes
497 */
498#define KERN_PROC_ALL 0 /* everything */
499#define KERN_PROC_PID 1 /* by process id */
500#define KERN_PROC_PGRP 2 /* by process group id */
501#define KERN_PROC_SESSION 3 /* by session of pid */
502#define KERN_PROC_TTY 4 /* by controlling tty */
503#define KERN_PROC_UID 5 /* by effective uid */
504#define KERN_PROC_RUID 6 /* by real uid */
505
506/*
507 * KERN_PROC subtype ops return arrays of augmented proc structures:
508 */
509#ifdef __APPLE_API_UNSTABLE
510
511struct _pcred {
512 char pc_lock[72]; /* opaque content */
513 struct ucred *pc_ucred; /* Current credentials. */
514 uid_t p_ruid; /* Real user id. */
515 uid_t p_svuid; /* Saved effective user id. */
516 gid_t p_rgid; /* Real group id. */
517 gid_t p_svgid; /* Saved effective group id. */
518 int p_refcnt; /* Number of references. */
519};
520
521struct _ucred {
522 int32_t cr_ref; /* reference count */
523 uid_t cr_uid; /* effective user id */
524 short cr_ngroups; /* number of groups */
525 gid_t cr_groups[NGROUPS]; /* groups */
526};
527
528struct kinfo_proc {
529 struct extern_proc kp_proc; /* proc structure */
530 struct eproc {
531 struct proc *e_paddr; /* address of proc */
532 struct session *e_sess; /* session pointer */
533 struct _pcred e_pcred; /* process credentials */
534 struct _ucred e_ucred; /* current credentials */
535 struct vmspace e_vm; /* address space */
536 pid_t e_ppid; /* parent process id */
537 pid_t e_pgid; /* process group id */
538 short e_jobc; /* job control counter */
539 dev_t e_tdev; /* controlling tty dev */
540 pid_t e_tpgid; /* tty process group id */
541 struct session *e_tsess; /* tty session pointer */
542#define WMESGLEN 7
543 char e_wmesg[WMESGLEN+1]; /* wchan message */
544 segsz_t e_xsize; /* text size */
545 short e_xrssize; /* text rss */
546 short e_xccount; /* text references */
547 short e_xswrss;
548 int32_t e_flag;
549#define EPROC_CTTY 0x01 /* controlling tty vnode active */
550#define EPROC_SLEADER 0x02 /* session leader */
551#define COMAPT_MAXLOGNAME 12
552 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
553 int32_t e_spare[4];
554 } kp_eproc;
555};
556
557#ifdef BSD_KERNEL_PRIVATE
558#include <sys/proc_internal.h>
559
560// LP64todo - should this move?
561
562/* LP64 version of _pcred. all pointers
563 * grow when we're dealing with a 64-bit process.
564 * WARNING - keep in sync with _pcred
565 */
566
567#if __DARWIN_ALIGN_NATURAL
568#pragma options align=natural
569#endif
570
571struct user_pcred {
572 char pc_lock[72]; /* opaque content */
573 user_addr_t pc_ucred; /* Current credentials. */
574 uid_t p_ruid; /* Real user id. */
575 uid_t p_svuid; /* Saved effective user id. */
576 gid_t p_rgid; /* Real group id. */
577 gid_t p_svgid; /* Saved effective group id. */
578 int p_refcnt; /* Number of references. */
579};
580
581/* LP64 version of kinfo_proc. all pointers
582 * grow when we're dealing with a 64-bit process.
583 * WARNING - keep in sync with kinfo_proc
584 */
585struct user_kinfo_proc {
586 struct user_extern_proc kp_proc; /* proc structure */
587 struct user_eproc {
588 user_addr_t e_paddr; /* address of proc */
589 user_addr_t e_sess; /* session pointer */
590 struct user_pcred e_pcred; /* process credentials */
591 struct _ucred e_ucred; /* current credentials */
592 struct user_vmspace e_vm; /* address space */
593 pid_t e_ppid; /* parent process id */
594 pid_t e_pgid; /* process group id */
595 short e_jobc; /* job control counter */
596 dev_t e_tdev; /* controlling tty dev */
597 pid_t e_tpgid; /* tty process group id */
598 user_addr_t e_tsess; /* tty session pointer */
599 char e_wmesg[WMESGLEN+1]; /* wchan message */
600 segsz_t e_xsize; /* text size */
601 short e_xrssize; /* text rss */
602 short e_xccount; /* text references */
603 short e_xswrss;
604 int32_t e_flag;
605 char e_login[COMAPT_MAXLOGNAME]; /* short setlogin() name */
606 int32_t e_spare[4];
607 } kp_eproc;
608};
609
610#if __DARWIN_ALIGN_NATURAL
611#pragma options align=reset
612#endif
613
614#endif /* BSD_KERNEL_PRIVATE */
615
616#endif /* __APPLE_API_UNSTABLE */
617
618/*
619 * KERN_IPC identifiers
620 */
621#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
622#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
623#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
624#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
625#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
626#define KIPC_MAX_HDR 6 /* int: max total length of headers */
627#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
628#define KIPC_MBSTAT 8 /* struct: mbuf usage statistics */
629#define KIPC_NMBCLUSTERS 9 /* int: maximum mbuf clusters */
630
631/*
632 * CTL_VM identifiers
633 */
634#define VM_METER 1 /* struct vmmeter */
635#define VM_LOADAVG 2 /* struct loadavg */
636/*
637 * Note: "3" was skipped sometime ago and should probably remain unused
638 * to avoid any new entry from being accepted by older kernels...
639 */
640#define VM_MACHFACTOR 4 /* struct loadavg with mach factor*/
641#define VM_SWAPUSAGE 5 /* total swap usage */
642#define VM_MAXID 6 /* number of valid vm ids */
643
644#define CTL_VM_NAMES { \
645 { 0, 0 }, \
646 { "vmmeter", CTLTYPE_STRUCT }, \
647 { "loadavg", CTLTYPE_STRUCT }, \
648 { 0, 0 }, /* placeholder for "3" (see comment above) */ \
649 { "machfactor", CTLTYPE_STRUCT }, \
650 { "swapusage", CTLTYPE_STRUCT } \
651}
652
653struct xsw_usage {
654 u_int64_t xsu_total;
655 u_int64_t xsu_avail;
656 u_int64_t xsu_used;
657 u_int32_t xsu_pagesize;
658 boolean_t xsu_encrypted;
659};
660
661#ifdef __APPLE_API_PRIVATE
662/* Load average structure. Use of fixpt_t assume <sys/types.h> in scope. */
663/* XXX perhaps we should protect fixpt_t, and define it here (or discard it) */
664struct loadavg {
665 fixpt_t ldavg[3];
666 long fscale;
667};
668extern struct loadavg averunnable;
669#define LSCALE 1000 /* scaling for "fixed point" arithmetic */
670
671// LP64todo - should this move?
672#ifdef BSD_KERNEL_PRIVATE
673
674#if __DARWIN_ALIGN_NATURAL
675#pragma options align=natural
676#endif
677struct user_loadavg {
678 fixpt_t ldavg[3];
679 user_long_t fscale;
680};
681
682#if __DARWIN_ALIGN_NATURAL
683#pragma options align=reset
684#endif
685
686#endif /* BSD_KERNEL_PRIVATE */
687#endif /* __APPLE_API_PRIVATE */
688
689
690/*
691 * CTL_HW identifiers
692 */
693#define HW_MACHINE 1 /* string: machine class */
694#define HW_MODEL 2 /* string: specific machine model */
695#define HW_NCPU 3 /* int: number of cpus */
696#define HW_BYTEORDER 4 /* int: machine byte order */
697#define HW_PHYSMEM 5 /* int: total memory */
698#define HW_USERMEM 6 /* int: non-kernel memory */
699#define HW_PAGESIZE 7 /* int: software page size */
700#define HW_DISKNAMES 8 /* strings: disk drive names */
701#define HW_DISKSTATS 9 /* struct: diskstats[] */
702#define HW_EPOCH 10 /* int: 0 for Legacy, else NewWorld */
703#define HW_FLOATINGPT 11 /* int: has HW floating point? */
704#define HW_MACHINE_ARCH 12 /* string: machine architecture */
705#define HW_VECTORUNIT 13 /* int: has HW vector unit? */
706#define HW_BUS_FREQ 14 /* int: Bus Frequency */
707#define HW_CPU_FREQ 15 /* int: CPU Frequency */
708#define HW_CACHELINE 16 /* int: Cache Line Size in Bytes */
709#define HW_L1ICACHESIZE 17 /* int: L1 I Cache Size in Bytes */
710#define HW_L1DCACHESIZE 18 /* int: L1 D Cache Size in Bytes */
711#define HW_L2SETTINGS 19 /* int: L2 Cache Settings */
712#define HW_L2CACHESIZE 20 /* int: L2 Cache Size in Bytes */
713#define HW_L3SETTINGS 21 /* int: L3 Cache Settings */
714#define HW_L3CACHESIZE 22 /* int: L3 Cache Size in Bytes */
715#define HW_TB_FREQ 23 /* int: Bus Frequency */
716#define HW_MEMSIZE 24 /* uint64_t: physical ram size */
717#define HW_AVAILCPU 25 /* int: number of available CPUs */
718#define HW_MAXID 26 /* number of valid hw ids */
719
720#define CTL_HW_NAMES { \
721 { 0, 0 }, \
722 { "machine", CTLTYPE_STRING }, \
723 { "model", CTLTYPE_STRING }, \
724 { "ncpu", CTLTYPE_INT }, \
725 { "byteorder", CTLTYPE_INT }, \
726 { "physmem", CTLTYPE_INT }, \
727 { "usermem", CTLTYPE_INT }, \
728 { "pagesize", CTLTYPE_INT }, \
729 { "disknames", CTLTYPE_STRUCT }, \
730 { "diskstats", CTLTYPE_STRUCT }, \
731 { "epoch", CTLTYPE_INT }, \
732 { "floatingpoint", CTLTYPE_INT }, \
733 { "machinearch", CTLTYPE_STRING }, \
734 { "vectorunit", CTLTYPE_INT }, \
735 { "busfrequency", CTLTYPE_INT }, \
736 { "cpufrequency", CTLTYPE_INT }, \
737 { "cachelinesize", CTLTYPE_INT }, \
738 { "l1icachesize", CTLTYPE_INT }, \
739 { "l1dcachesize", CTLTYPE_INT }, \
740 { "l2settings", CTLTYPE_INT }, \
741 { "l2cachesize", CTLTYPE_INT }, \
742 { "l3settings", CTLTYPE_INT }, \
743 { "l3cachesize", CTLTYPE_INT }, \
744 { "tbfrequency", CTLTYPE_INT }, \
745 { "memsize", CTLTYPE_QUAD }, \
746 { "availcpu", CTLTYPE_INT } \
747}
748
749/*
750 * These are the support HW selectors for sysctlbyname. Parameters that are byte counts or frequencies are 64 bit numbers.
751 * All other parameters are 32 bit numbers.
752 *
753 * hw.memsize - The number of bytes of physical memory in the system.
754 *
755 * hw.ncpu - The maximum number of processors that could be available this boot.
756 * Use this value for sizing of static per processor arrays; i.e. processor load statistics.
757 *
758 * hw.activecpu - The number of processors currently available for executing threads.
759 * Use this number to determine the number threads to create in SMP aware applications.
760 * This number can change when power management modes are changed.
761 *
762 * hw.physicalcpu - The number of physical processors available in the current power management mode.
763 * hw.physicalcpu_max - The maximum number of physical processors that could be available this boot
764 *
765 * hw.logicalcpu - The number of logical processors available in the current power management mode.
766 * hw.logicalcpu_max - The maximum number of logical processors that could be available this boot
767 *
768 * hw.tbfrequency - This gives the time base frequency used by the OS and is the basis of all timing services.
769 * In general is is better to use mach's or higher level timing services, but this value
770 * is needed to convert the PPC Time Base registers to real time.
771 *
772 * hw.cpufrequency - These values provide the current, min and max cpu frequency. The min and max are for
773 * hw.cpufrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
774 * hw.cpufrequency_min - All frequencies are in Hz.
775 *
776 * hw.busfrequency - These values provide the current, min and max bus frequency. The min and max are for
777 * hw.busfrequency_max - all power management modes. The current frequency is the max frequency in the current mode.
778 * hw.busfrequency_min - All frequencies are in Hz.
779 *
780 * hw.cputype - These values provide the mach-o cpu type and subtype. A complete list is in <mach/machine.h>
781 * hw.cpusubtype - These values should be used to determine what processor family the running cpu is from so that
782 * the best binary can be chosen, or the best dynamic code generated. They should not be used
783 * to determine if a given processor feature is available.
784 * hw.cputhreadtype - This value will be present if the processor supports threads. Like hw.cpusubtype this selector
785 * should not be used to infer features, and only used to name the processors thread architecture.
786 * The values are defined in <mach/machine.h>
787 *
788 * hw.byteorder - Gives the byte order of the processor. 4321 for big endian, 1234 for little.
789 *
790 * hw.pagesize - Gives the size in bytes of the pages used by the processor and VM system.
791 *
792 * hw.cachelinesize - Gives the size in bytes of the processor's cache lines.
793 * This value should be use to control the strides of loops that use cache control instructions
794 * like dcbz, dcbt or dcbst.
795 *
796 * hw.l1dcachesize - These values provide the size in bytes of the L1, L2 and L3 caches. If a cache is not present
797 * hw.l1icachesize - then the selector will return and error.
798 * hw.l2cachesize -
799 * hw.l3cachesize -
800 *
801 *
802 * These are the selectors for optional processor features. Selectors that return errors are not support on the system.
803 * Supported features will return 1 if they are recommended or 0 if they are supported but are not expected to help performance.
804 * Future versions of these selectors may return larger values as necessary so it is best to test for non zero.
805 *
806 * hw.optional.floatingpoint - Floating Point Instructions
807 * hw.optional.altivec - AltiVec Instructions
808 * hw.optional.graphicsops - Graphics Operations
809 * hw.optional.64bitops - 64-bit Instructions
810 * hw.optional.fsqrt - HW Floating Point Square Root Instruction
811 * hw.optional.stfiwx - Store Floating Point as Integer Word Indexed Instructions
812 * hw.optional.dcba - Data Cache Block Allocate Instruction
813 * hw.optional.datastreams - Data Streams Instructions
814 * hw.optional.dcbtstreams - Data Cache Block Touch Steams Instruction Form
815 *
816 */
817
818
819/*
820 * CTL_USER definitions
821 */
822#define USER_CS_PATH 1 /* string: _CS_PATH */
823#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
824#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
825#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
826#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
827#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
828#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
829#define USER_LINE_MAX 8 /* int: LINE_MAX */
830#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
831#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
832#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
833#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
834#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
835#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
836#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
837#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
838#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
839#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
840#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
841#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
842#define USER_MAXID 21 /* number of valid user ids */
843
844#define CTL_USER_NAMES { \
845 { 0, 0 }, \
846 { "cs_path", CTLTYPE_STRING }, \
847 { "bc_base_max", CTLTYPE_INT }, \
848 { "bc_dim_max", CTLTYPE_INT }, \
849 { "bc_scale_max", CTLTYPE_INT }, \
850 { "bc_string_max", CTLTYPE_INT }, \
851 { "coll_weights_max", CTLTYPE_INT }, \
852 { "expr_nest_max", CTLTYPE_INT }, \
853 { "line_max", CTLTYPE_INT }, \
854 { "re_dup_max", CTLTYPE_INT }, \
855 { "posix2_version", CTLTYPE_INT }, \
856 { "posix2_c_bind", CTLTYPE_INT }, \
857 { "posix2_c_dev", CTLTYPE_INT }, \
858 { "posix2_char_term", CTLTYPE_INT }, \
859 { "posix2_fort_dev", CTLTYPE_INT }, \
860 { "posix2_fort_run", CTLTYPE_INT }, \
861 { "posix2_localedef", CTLTYPE_INT }, \
862 { "posix2_sw_dev", CTLTYPE_INT }, \
863 { "posix2_upe", CTLTYPE_INT }, \
864 { "stream_max", CTLTYPE_INT }, \
865 { "tzname_max", CTLTYPE_INT } \
866}
867
868
869
870/*
871 * CTL_DEBUG definitions
872 *
873 * Second level identifier specifies which debug variable.
874 * Third level identifier specifies which stucture component.
875 */
876#define CTL_DEBUG_NAME 0 /* string: variable name */
877#define CTL_DEBUG_VALUE 1 /* int: variable value */
878#define CTL_DEBUG_MAXID 20
879
880#ifdef KERNEL
881#ifdef DEBUG
882/*
883 * CTL_DEBUG variables.
884 *
885 * These are declared as separate variables so that they can be
886 * individually initialized at the location of their associated
887 * variable. The loader prevents multiple use by issuing errors
888 * if a variable is initialized in more than one place. They are
889 * aggregated into an array in debug_sysctl(), so that it can
890 * conveniently locate them when querried. If more debugging
891 * variables are added, they must also be declared here and also
892 * entered into the array.
893 */
894struct ctldebug {
895 char *debugname; /* name of debugging variable */
896 int *debugvar; /* pointer to debugging variable */
897};
898extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
899extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
900extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
901extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
902#endif /* DEBUG */
903
904#ifdef BSD_KERNEL_PRIVATE
905extern char machine[];
906extern char osrelease[];
907extern char ostype[];
908
909struct linker_set;
910
911void sysctl_register_set(struct linker_set *lsp);
912void sysctl_unregister_set(struct linker_set *lsp);
913void sysctl_mib_init(void);
914int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
915 size_t *oldlenp, void *newp, size_t newlen);
916int userland_sysctl(struct proc *p, int *name, u_int namelen, user_addr_t old,
917 size_t *oldlenp, int inkernel, user_addr_t newp, size_t newlen,
918 size_t *retval);
919
920/*
921 * Internal sysctl function calling convention:
922 *
923 * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
924 *
925 * The name parameter points at the next component of the name to be
926 * interpreted. The namelen parameter is the number of integers in
927 * the name.
928 */
929typedef int (sysctlfn)
930 (int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, struct proc *);
931
932int sysctl_int(user_addr_t, size_t *, user_addr_t, size_t, int *);
933int sysctl_rdint(user_addr_t, size_t *, user_addr_t, int);
934int sysctl_quad(user_addr_t, size_t *, user_addr_t, size_t, quad_t *);
935int sysctl_rdquad(void *, size_t *, void *, quad_t);
936int sysctl_string(user_addr_t, size_t *, user_addr_t, size_t, char *, int);
937int sysctl_trstring(user_addr_t, size_t *, user_addr_t, size_t, char *, int);
938int sysctl_rdstring(user_addr_t, size_t *, user_addr_t, char *);
939int sysctl_rdstruct(user_addr_t, size_t *, user_addr_t, void *, int);
940
941#endif /* BSD_KERNEL_PRIVATE */
942#else /* !KERNEL */
943
944__BEGIN_DECLS
945int sysctl(int *, u_int, void *, size_t *, void *, size_t);
946int sysctlbyname(const char *, void *, size_t *, void *, size_t);
947int sysctlnametomib(const char *, int *, size_t *);
948__END_DECLS
949
950#endif /* KERNEL */
951
952
953#endif /* SYSCTL_DEF_ENABLED */
954
955
956#endif /* !_SYS_SYSCTL_H_ */