xref: /freebsd/sys/sys/sysctl.h (revision 8e6e287f8d1f4f58bb94cc71b3b46c543569f83f)
1 /*-
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Mike Karels at Berkeley Software Design, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
33  * $FreeBSD$
34  */
35 
36 #ifndef _SYS_SYSCTL_H_
37 #define	_SYS_SYSCTL_H_
38 
39 #include <sys/queue.h>
40 
41 struct thread;
42 /*
43  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
44  * for objects that can be examined or modified.  The name is expressed as
45  * a sequence of integers.  Like a file path name, the meaning of each
46  * component depends on its place in the hierarchy.  The top-level and kern
47  * identifiers are defined here, and other identifiers are defined in the
48  * respective subsystem header files.
49  */
50 
51 #define	CTL_MAXNAME	24	/* largest number of components supported */
52 
53 /*
54  * Each subsystem defined by sysctl defines a list of variables
55  * for that subsystem. Each name is either a node with further
56  * levels defined below it, or it is a leaf of some particular
57  * type given below. Each sysctl level defines a set of name/type
58  * pairs to be used by sysctl(8) in manipulating the subsystem.
59  */
60 struct ctlname {
61 	char	*ctl_name;	/* subsystem name */
62 	int	 ctl_type;	/* type of name */
63 };
64 
65 #define	CTLTYPE		0xf	/* mask for the type */
66 #define	CTLTYPE_NODE	1	/* name is a node */
67 #define	CTLTYPE_INT	2	/* name describes an integer */
68 #define	CTLTYPE_STRING	3	/* name describes a string */
69 #define	CTLTYPE_S64	4	/* name describes a signed 64-bit number */
70 #define	CTLTYPE_OPAQUE	5	/* name describes a structure */
71 #define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
72 #define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
73 #define	CTLTYPE_LONG	7	/* name describes a long */
74 #define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
75 #define	CTLTYPE_U64	9	/* name describes an unsigned 64-bit number */
76 #define	CTLTYPE_U8	0xa	/* name describes an unsigned 8-bit number */
77 #define	CTLTYPE_U16	0xb	/* name describes an unsigned 16-bit number */
78 #define	CTLTYPE_S8	0xc	/* name describes a signed 8-bit number */
79 #define	CTLTYPE_S16	0xd	/* name describes a signed 16-bit number */
80 #define	CTLTYPE_S32	0xe	/* name describes a signed 32-bit number */
81 #define	CTLTYPE_U32	0xf	/* name describes an unsigned 32-bit number */
82 
83 #define	CTLFLAG_RD	0x80000000	/* Allow reads of variable */
84 #define	CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
85 #define	CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
86 #define	CTLFLAG_DORMANT	0x20000000	/* This sysctl is not active yet */
87 #define	CTLFLAG_ANYBODY	0x10000000	/* All users can set this var */
88 #define	CTLFLAG_SECURE	0x08000000	/* Permit set only if securelevel<=0 */
89 #define	CTLFLAG_PRISON	0x04000000	/* Prisoned roots can fiddle */
90 #define	CTLFLAG_DYN	0x02000000	/* Dynamic oid - can be freed */
91 #define	CTLFLAG_SKIP	0x01000000	/* Skip this sysctl when listing */
92 #define	CTLMASK_SECURE	0x00F00000	/* Secure level */
93 #define	CTLFLAG_TUN	0x00080000	/* Default value is loaded from getenv() */
94 #define	CTLFLAG_RDTUN	(CTLFLAG_RD|CTLFLAG_TUN)
95 #define	CTLFLAG_RWTUN	(CTLFLAG_RW|CTLFLAG_TUN)
96 #define	CTLFLAG_MPSAFE	0x00040000	/* Handler is MP safe */
97 #define	CTLFLAG_VNET	0x00020000	/* Prisons with vnet can fiddle */
98 #define	CTLFLAG_DYING	0x00010000	/* Oid is being removed */
99 #define	CTLFLAG_CAPRD	0x00008000	/* Can be read in capability mode */
100 #define	CTLFLAG_CAPWR	0x00004000	/* Can be written in capability mode */
101 #define	CTLFLAG_STATS	0x00002000	/* Statistics, not a tuneable */
102 #define	CTLFLAG_NOFETCH	0x00001000	/* Don't fetch tunable from getenv() */
103 #define	CTLFLAG_CAPRW	(CTLFLAG_CAPRD|CTLFLAG_CAPWR)
104 
105 /*
106  * Secure level.   Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
107  *
108  * Secure when the securelevel is raised to at least N.
109  */
110 #define	CTLSHIFT_SECURE	20
111 #define	CTLFLAG_SECURE1	(CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
112 #define	CTLFLAG_SECURE2	(CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
113 #define	CTLFLAG_SECURE3	(CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
114 
115 /*
116  * USE THIS instead of a hardwired number from the categories below
117  * to get dynamically assigned sysctl entries using the linker-set
118  * technology. This is the way nearly all new sysctl variables should
119  * be implemented.
120  * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
121  */
122 #define	OID_AUTO	(-1)
123 
124 /*
125  * The starting number for dynamically-assigned entries.  WARNING!
126  * ALL static sysctl entries should have numbers LESS than this!
127  */
128 #define	CTL_AUTO_START	0x100
129 
130 #ifdef _KERNEL
131 #include <sys/linker_set.h>
132 
133 #ifdef KLD_MODULE
134 /* XXX allow overspecification of type in external kernel modules */
135 #define	SYSCTL_CT_ASSERT_MASK CTLTYPE
136 #else
137 #define	SYSCTL_CT_ASSERT_MASK 0
138 #endif
139 
140 #define	SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1,	\
141 	intmax_t arg2, struct sysctl_req *req
142 
143 /* definitions for sysctl_req 'lock' member */
144 #define	REQ_UNWIRED	1
145 #define	REQ_WIRED	2
146 
147 /* definitions for sysctl_req 'flags' member */
148 #if defined(__amd64__) || defined(__powerpc64__) ||\
149     (defined(__mips__) && defined(__mips_n64))
150 #define	SCTL_MASK32	1	/* 32 bit emulation */
151 #endif
152 
153 /*
154  * This describes the access space for a sysctl request.  This is needed
155  * so that we can use the interface from the kernel or from user-space.
156  */
157 struct sysctl_req {
158 	struct thread	*td;		/* used for access checking */
159 	int		 lock;		/* wiring state */
160 	void		*oldptr;
161 	size_t		 oldlen;
162 	size_t		 oldidx;
163 	int		(*oldfunc)(struct sysctl_req *, const void *, size_t);
164 	void		*newptr;
165 	size_t		 newlen;
166 	size_t		 newidx;
167 	int		(*newfunc)(struct sysctl_req *, void *, size_t);
168 	size_t		 validlen;
169 	int		 flags;
170 };
171 
172 SLIST_HEAD(sysctl_oid_list, sysctl_oid);
173 
174 /*
175  * This describes one "oid" in the MIB tree.  Potentially more nodes can
176  * be hidden behind it, expanded by the handler.
177  */
178 struct sysctl_oid {
179 	struct sysctl_oid_list oid_children;
180 	struct sysctl_oid_list *oid_parent;
181 	SLIST_ENTRY(sysctl_oid) oid_link;
182 	int		 oid_number;
183 	u_int		 oid_kind;
184 	void		*oid_arg1;
185 	intmax_t	 oid_arg2;
186 	const char	*oid_name;
187 	int		(*oid_handler)(SYSCTL_HANDLER_ARGS);
188 	const char	*oid_fmt;
189 	int		 oid_refcnt;
190 	u_int		 oid_running;
191 	const char	*oid_descr;
192 	const char	*oid_label;
193 };
194 
195 #define	SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
196 #define	SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
197 #define	SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
198 
199 int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
200 int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
201 int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
202 int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
203 int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
204 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
205 int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
206 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
207 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
208 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
209 int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
210 int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
211 
212 int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
213 int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
214 
215 int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
216 int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
217 int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
218 
219 /*
220  * These functions are used to add/remove an oid from the mib.
221  */
222 void sysctl_register_oid(struct sysctl_oid *oidp);
223 void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
224 void sysctl_enable_oid(struct sysctl_oid *oidp);
225 void sysctl_unregister_oid(struct sysctl_oid *oidp);
226 
227 /* Declare a static oid to allow child oids to be added to it. */
228 #define	SYSCTL_DECL(name)			\
229 	extern struct sysctl_oid sysctl__##name
230 
231 /* Hide these in macros. */
232 #define	SYSCTL_CHILDREN(oid_ptr)		(&(oid_ptr)->oid_children)
233 #define	SYSCTL_PARENT(oid_ptr)					\
234     (((oid_ptr)->oid_parent != &sysctl__children) ?		\
235 	__containerof((oid_ptr)->oid_parent, struct sysctl_oid,	\
236 	oid_children) : (struct sysctl_oid *)NULL)
237 #define	SYSCTL_STATIC_CHILDREN(oid_name)	(&sysctl__##oid_name.oid_children)
238 
239 /* === Structs and macros related to context handling. === */
240 
241 /* All dynamically created sysctls can be tracked in a context list. */
242 struct sysctl_ctx_entry {
243 	struct sysctl_oid *entry;
244 	TAILQ_ENTRY(sysctl_ctx_entry) link;
245 };
246 
247 TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
248 
249 #define	SYSCTL_NODE_CHILDREN(parent, name) \
250 	sysctl__##parent##_##name.oid_children
251 
252 #ifndef NO_SYSCTL_DESCR
253 #define	__DESCR(d) d
254 #else
255 #define	__DESCR(d) ""
256 #endif
257 
258 /* This macro is only for internal use */
259 #define	SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
260 	struct sysctl_oid id = {					\
261 		.oid_parent = (parent_child_head),			\
262 		.oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
263 		.oid_number = (nbr),					\
264 		.oid_kind = (kind),					\
265 		.oid_arg1 = (a1),					\
266 		.oid_arg2 = (a2),					\
267 		.oid_name = (name),					\
268 		.oid_handler = (handler),				\
269 		.oid_fmt = (fmt),					\
270 		.oid_descr = __DESCR(descr),				\
271 		.oid_label = (label),					\
272 	};								\
273 	DATA_SET(sysctl_set, id)
274 
275 /* This constructs a static "raw" MIB oid. */
276 #define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
277 	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2,		\
278 	    handler, fmt, descr, NULL)
279 
280 #define	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
281     static SYSCTL_OID_RAW(sysctl__##parent##_##name,			\
282 	SYSCTL_CHILDREN(&sysctl__##parent),				\
283 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
284 
285 /* This constructs a global "raw" MIB oid. */
286 #define	SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
287     SYSCTL_OID_RAW(sysctl__##parent##_##name, \
288 	SYSCTL_CHILDREN(&sysctl__##parent),	\
289 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
290 
291 #define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
292 	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr), NULL)
293 
294 /* This constructs a root node from which other nodes can hang. */
295 #define	SYSCTL_ROOT_NODE(nbr, name, access, handler, descr)	\
296 	SYSCTL_OID_RAW(sysctl___##name, &sysctl__children,	\
297 	    nbr, #name, CTLTYPE_NODE|(access), NULL, 0,		\
298 	    handler, "N", descr, NULL);				\
299 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
300 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
301 
302 /* This constructs a node from which other oids can hang. */
303 #define	SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
304 	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL)
305 
306 #define	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \
307 	SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access),	\
308 	    NULL, 0, handler, "N", descr, label);			\
309 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
310 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
311 
312 #define	SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
313 	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \
314 	    handler, descr, NULL)
315 
316 #define	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \
317 ({									\
318 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
319 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
320 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
321 	    NULL, 0, handler, "N", __DESCR(descr), label);		\
322 })
323 
324 #define	SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr)	\
325 ({									\
326 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
327 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
328 	sysctl_add_oid(ctx, &sysctl__children, nbr, name,		\
329 	    CTLTYPE_NODE|(access),					\
330 	    NULL, 0, handler, "N", __DESCR(descr), NULL);		\
331 })
332 
333 /* Oid for a string.  len can be 0 to indicate '\0' termination. */
334 #define	SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
335 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
336 	    arg, len, sysctl_handle_string, "A", descr);		\
337 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
338 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
339 
340 #define	SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
341 ({									\
342 	char *__arg = (arg);						\
343 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
344 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
345 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
346 	    __arg, len, sysctl_handle_string, "A", __DESCR(descr),	\
347 	    NULL); \
348 })
349 
350 /* Oid for a bool.  If ptr is NULL, val is returned. */
351 #define	SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
352 #define	SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr)	\
353 	SYSCTL_OID(parent, nbr, name,				\
354 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
355 	    ptr, val, sysctl_handle_bool, "CU", descr);		\
356 	CTASSERT(((access) & CTLTYPE) == 0 &&			\
357 	    sizeof(bool) == sizeof(*(ptr)))
358 
359 #define	SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
360 ({									\
361 	bool *__ptr = (ptr);						\
362 	CTASSERT(((access) & CTLTYPE) == 0);				\
363 	sysctl_add_oid(ctx, parent, nbr, name,				\
364 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
365 	    __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr),	\
366 	    NULL);							\
367 })
368 
369 /* Oid for a signed 8-bit int.  If ptr is NULL, val is returned. */
370 #define	SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
371 #define	SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
372 	SYSCTL_OID(parent, nbr, name,				\
373 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),		\
374 	    ptr, val, sysctl_handle_8, "C", descr);		\
375 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
376 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
377 	    sizeof(int8_t) == sizeof(*(ptr)))
378 
379 #define	SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr)	\
380 ({									\
381 	int8_t *__ptr = (ptr);						\
382 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
383 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8);		\
384 	sysctl_add_oid(ctx, parent, nbr, name,				\
385 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),			\
386 	    __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL);	\
387 })
388 
389 /* Oid for an unsigned 8-bit int.  If ptr is NULL, val is returned. */
390 #define	SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
391 #define	SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
392 	SYSCTL_OID(parent, nbr, name,				\
393 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
394 	    ptr, val, sysctl_handle_8, "CU", descr);		\
395 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
396 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
397 	    sizeof(uint8_t) == sizeof(*(ptr)))
398 
399 #define	SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr)	\
400 ({									\
401 	uint8_t *__ptr = (ptr);						\
402 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
403 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8);		\
404 	sysctl_add_oid(ctx, parent, nbr, name,				\
405 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
406 	    __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL);	\
407 })
408 
409 /* Oid for a signed 16-bit int.  If ptr is NULL, val is returned. */
410 #define	SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
411 #define	SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
412 	SYSCTL_OID(parent, nbr, name,				\
413 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),		\
414 	    ptr, val, sysctl_handle_16, "S", descr);		\
415 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
416 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
417 	    sizeof(int16_t) == sizeof(*(ptr)))
418 
419 #define	SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr)	\
420 ({									\
421 	int16_t *__ptr = (ptr);						\
422 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
423 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16);		\
424 	sysctl_add_oid(ctx, parent, nbr, name,				\
425 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),			\
426 	    __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL);	\
427 })
428 
429 /* Oid for an unsigned 16-bit int.  If ptr is NULL, val is returned. */
430 #define	SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
431 #define	SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
432 	SYSCTL_OID(parent, nbr, name,				\
433 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),		\
434 	    ptr, val, sysctl_handle_16, "SU", descr);		\
435 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
436 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
437 	    sizeof(uint16_t) == sizeof(*(ptr)))
438 
439 #define	SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr)	\
440 ({									\
441 	uint16_t *__ptr = (ptr);					\
442 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
443 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16);		\
444 	sysctl_add_oid(ctx, parent, nbr, name,				\
445 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),			\
446 	    __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL);	\
447 })
448 
449 /* Oid for a signed 32-bit int.  If ptr is NULL, val is returned. */
450 #define	SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
451 #define	SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
452 	SYSCTL_OID(parent, nbr, name,				\
453 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),		\
454 	    ptr, val, sysctl_handle_32, "I", descr);		\
455 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
456 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
457 	    sizeof(int32_t) == sizeof(*(ptr)))
458 
459 #define	SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr)	\
460 ({									\
461 	int32_t *__ptr = (ptr);						\
462 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
463 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32);		\
464 	sysctl_add_oid(ctx, parent, nbr, name,				\
465 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),			\
466 	    __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL);	\
467 })
468 
469 /* Oid for an unsigned 32-bit int.  If ptr is NULL, val is returned. */
470 #define	SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
471 #define	SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
472 	SYSCTL_OID(parent, nbr, name,				\
473 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),		\
474 	    ptr, val, sysctl_handle_32, "IU", descr);		\
475 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
476 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
477 	    sizeof(uint32_t) == sizeof(*(ptr)))
478 
479 #define	SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr)	\
480 ({									\
481 	uint32_t *__ptr = (ptr);					\
482 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
483 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32);		\
484 	sysctl_add_oid(ctx, parent, nbr, name,				\
485 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),			\
486 	    __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL);	\
487 })
488 
489 /* Oid for a signed 64-bit int.  If ptr is NULL, val is returned. */
490 #define	SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
491 #define	SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
492 	SYSCTL_OID(parent, nbr, name,				\
493 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
494 	    ptr, val, sysctl_handle_64, "Q", descr);		\
495 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
496 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
497 	    sizeof(int64_t) == sizeof(*(ptr)))
498 
499 #define	SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr)	\
500 ({									\
501 	int64_t *__ptr = (ptr);						\
502 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
503 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
504 	sysctl_add_oid(ctx, parent, nbr, name,				\
505 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
506 	    __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
507 })
508 
509 /* Oid for an unsigned 64-bit int.  If ptr is NULL, val is returned. */
510 #define	SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
511 #define	SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
512 	SYSCTL_OID(parent, nbr, name,				\
513 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
514 	    ptr, val, sysctl_handle_64, "QU", descr);		\
515 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
516 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
517 	    sizeof(uint64_t) == sizeof(*(ptr)))
518 
519 #define	SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr)	\
520 ({									\
521 	uint64_t *__ptr = (ptr);					\
522 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
523 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
524 	sysctl_add_oid(ctx, parent, nbr, name,				\
525 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
526 	    __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
527 })
528 
529 /* Oid for an int.  If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
530 #define	SYSCTL_NULL_INT_PTR ((int *)NULL)
531 #define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
532 	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL)
533 
534 #define	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \
535 	SYSCTL_OID_WITH_LABEL(parent, nbr, name,			\
536 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
537 	    ptr, val, sysctl_handle_int, "I", descr, label);		\
538 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
539 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
540 	    sizeof(int) == sizeof(*(ptr)))
541 
542 #define	SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
543 ({									\
544 	int *__ptr = (ptr);						\
545 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
546 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
547 	sysctl_add_oid(ctx, parent, nbr, name,				\
548 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
549 	    __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL);	\
550 })
551 
552 /* Oid for an unsigned int.  If ptr is NULL, val is returned. */
553 #define	SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
554 #define	SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)	\
555 	SYSCTL_OID(parent, nbr, name,				\
556 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
557 	    ptr, val, sysctl_handle_int, "IU", descr);		\
558 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
559 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
560 	    sizeof(unsigned) == sizeof(*(ptr)))
561 
562 #define	SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
563 ({									\
564 	unsigned *__ptr = (ptr);					\
565 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
566 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT);	\
567 	sysctl_add_oid(ctx, parent, nbr, name,				\
568 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),			\
569 	    __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL);	\
570 })
571 
572 /* Oid for a long.  The pointer must be non NULL. */
573 #define	SYSCTL_NULL_LONG_PTR ((long *)NULL)
574 #define	SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)	\
575 	SYSCTL_OID(parent, nbr, name,				\
576 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),		\
577 	    ptr, val, sysctl_handle_long, "L", descr);		\
578 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
579 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
580 	    sizeof(long) == sizeof(*(ptr)))
581 
582 #define	SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
583 ({									\
584 	long *__ptr = (ptr);						\
585 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
586 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG);	\
587 	sysctl_add_oid(ctx, parent, nbr, name,				\
588 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),			\
589 	    __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL);	\
590 })
591 
592 /* Oid for an unsigned long.  The pointer must be non NULL. */
593 #define	SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
594 #define	SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
595 	SYSCTL_OID(parent, nbr, name,					\
596 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
597 	    ptr, val, sysctl_handle_long, "LU", descr);			\
598 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
599 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) &&	\
600 	    sizeof(unsigned long) == sizeof(*(ptr)))
601 
602 #define	SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
603 ({									\
604 	unsigned long *__ptr = (ptr);					\
605 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
606 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG);	\
607 	sysctl_add_oid(ctx, parent, nbr, name,				\
608 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
609 	    __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL);	\
610 })
611 
612 /* Oid for a quad.  The pointer must be non NULL. */
613 #define	SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
614 #define	SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)	\
615 	SYSCTL_OID(parent, nbr, name,				\
616 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
617 	    ptr, val, sysctl_handle_64, "Q", descr);		\
618 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
619 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
620 	    sizeof(int64_t) == sizeof(*(ptr)))
621 
622 #define	SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	\
623 ({									\
624 	int64_t *__ptr = (ptr);						\
625 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
626 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
627 	sysctl_add_oid(ctx, parent, nbr, name,				\
628 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
629 	    __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
630 })
631 
632 #define	SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
633 #define	SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
634 	SYSCTL_OID(parent, nbr, name,					\
635 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
636 	     ptr, val, sysctl_handle_64, "QU", descr);			\
637 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
638 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
639 	    sizeof(uint64_t) == sizeof(*(ptr)))
640 
641 #define	SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	\
642 ({									\
643 	uint64_t *__ptr = (ptr);					\
644 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
645 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
646 	sysctl_add_oid(ctx, parent, nbr, name,				\
647 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
648 	    __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
649 })
650 
651 /* Oid for a CPU dependent variable */
652 #define	SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr)	\
653 ({									\
654 	struct sysctl_oid *__ret;					\
655 	CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) ||			\
656 	    sizeof(unsigned) == sizeof(*(ptr))) &&			\
657 	    ((access) & CTLTYPE) == 0);					\
658 	if (sizeof(uint64_t) == sizeof(*(ptr))) {			\
659 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
660 		    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
661 		    (ptr), 0, sysctl_handle_64, "QU",			\
662 		    __DESCR(descr), NULL);				\
663 	} else {							\
664 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
665 		    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
666 		    (ptr), 0, sysctl_handle_int, "IU",			\
667 		    __DESCR(descr), NULL);				\
668 	}								\
669 	__ret;								\
670 })
671 
672 /* Oid for a 64-bit unsigned counter(9).  The pointer must be non NULL. */
673 #define	SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr)	\
674 	SYSCTL_OID(parent, nbr, name,					\
675 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
676 	    (ptr), 0, sysctl_handle_counter_u64, "QU", descr);		\
677 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
678 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
679 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
680 	    sizeof(uint64_t) == sizeof(**(ptr)))
681 
682 #define	SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
683 ({									\
684 	counter_u64_t *__ptr = (ptr);					\
685 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
686 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
687 	sysctl_add_oid(ctx, parent, nbr, name,				\
688 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
689 	    __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr),	\
690 	    NULL);							\
691 })
692 
693 /* Oid for an array of counter(9)s.  The pointer and length must be non zero. */
694 #define	SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
695 	SYSCTL_OID(parent, nbr, name,					\
696 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
697 	    (ptr), (len), sysctl_handle_counter_u64_array, "S", descr);	\
698 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
699 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&	\
700 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
701 	    sizeof(uint64_t) == sizeof(**(ptr)))
702 
703 #define	SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,	\
704     ptr, len, descr)							\
705 ({									\
706 	counter_u64_t *__ptr = (ptr);					\
707 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
708 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
709 	sysctl_add_oid(ctx, parent, nbr, name,				\
710 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
711 	    __ptr, len, sysctl_handle_counter_u64_array, "S",		\
712 	    __DESCR(descr), NULL);					\
713 })
714 
715 /* Oid for an opaque object.  Specified by a pointer and a length. */
716 #define	SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
717 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
718 	    ptr, len, sysctl_handle_opaque, fmt, descr);		\
719 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
720 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
721 
722 #define	SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)	\
723 ({									\
724 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
725 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
726 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
727 	    ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL);	\
728 })
729 
730 /* Oid for a struct.  Specified by a pointer and a type. */
731 #define	SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
732 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
733 	    ptr, sizeof(struct type), sysctl_handle_opaque,		\
734 	    "S," #type, descr);						\
735 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
736 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
737 
738 #define	SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
739 ({									\
740 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
741 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
742 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
743 	    (ptr), sizeof(struct type),					\
744 	    sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL);	\
745 })
746 
747 /* Oid for a procedure.  Specified by a pointer and an arg. */
748 #define	SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
749 	SYSCTL_OID(parent, nbr, name, (access),				\
750 	    ptr, arg, handler, fmt, descr);				\
751 	CTASSERT(((access) & CTLTYPE) != 0)
752 
753 #define	SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
754 ({									\
755 	CTASSERT(((access) & CTLTYPE) != 0);				\
756 	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
757 	    (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL);	\
758 })
759 
760 /* Oid to handle limits on uma(9) zone specified by pointer. */
761 #define	SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr)	\
762 	SYSCTL_OID(parent, nbr, name,				\
763 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
764 	    (ptr), 0, sysctl_handle_uma_zone_max, "I", descr);	\
765 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
766 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
767 
768 #define	SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)	\
769 ({									\
770 	uma_zone_t __ptr = (ptr);					\
771 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
772 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
773 	sysctl_add_oid(ctx, parent, nbr, name,				\
774 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
775 	    __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr),	\
776 	    NULL);							\
777 })
778 
779 /* Oid to obtain current use of uma(9) zone specified by pointer. */
780 #define	SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr)		\
781 	SYSCTL_OID(parent, nbr, name,					\
782 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
783 	    (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr);		\
784 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
785 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
786 
787 #define	SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr)	\
788 ({									\
789 	uma_zone_t __ptr = (ptr);					\
790 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
791 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
792 	sysctl_add_oid(ctx, parent, nbr, name,				\
793 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
794 	    __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr),	\
795 	    NULL);							\
796 })
797 
798 /*
799  * A macro to generate a read-only sysctl to indicate the presence of optional
800  * kernel features.
801  */
802 #define	FEATURE(name, desc)						\
803 	SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name,		\
804 	    CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature")
805 
806 #endif /* _KERNEL */
807 
808 /*
809  * Top-level identifiers
810  */
811 #define	CTL_UNSPEC	0		/* unused */
812 #define	CTL_KERN	1		/* "high kernel": proc, limits */
813 #define	CTL_VM		2		/* virtual memory */
814 #define	CTL_VFS		3		/* filesystem, mount type is next */
815 #define	CTL_NET		4		/* network, see socket.h */
816 #define	CTL_DEBUG	5		/* debugging parameters */
817 #define	CTL_HW		6		/* generic cpu/io */
818 #define	CTL_MACHDEP	7		/* machine dependent */
819 #define	CTL_USER	8		/* user-level */
820 #define	CTL_P1003_1B	9		/* POSIX 1003.1B */
821 
822 /*
823  * CTL_KERN identifiers
824  */
825 #define	KERN_OSTYPE		 1	/* string: system version */
826 #define	KERN_OSRELEASE		 2	/* string: system release */
827 #define	KERN_OSREV		 3	/* int: system revision */
828 #define	KERN_VERSION		 4	/* string: compile time info */
829 #define	KERN_MAXVNODES		 5	/* int: max vnodes */
830 #define	KERN_MAXPROC		 6	/* int: max processes */
831 #define	KERN_MAXFILES		 7	/* int: max open files */
832 #define	KERN_ARGMAX		 8	/* int: max arguments to exec */
833 #define	KERN_SECURELVL		 9	/* int: system security level */
834 #define	KERN_HOSTNAME		10	/* string: hostname */
835 #define	KERN_HOSTID		11	/* int: host identifier */
836 #define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
837 #define	KERN_VNODE		13	/* struct: vnode structures */
838 #define	KERN_PROC		14	/* struct: process entries */
839 #define	KERN_FILE		15	/* struct: file entries */
840 #define	KERN_PROF		16	/* node: kernel profiling info */
841 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
842 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
843 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
844 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
845 #define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
846 #define	KERN_NISDOMAINNAME	22	/* string: YP domain name */
847 #define	KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
848 #define	KERN_OSRELDATE		24	/* int: kernel release date */
849 #define	KERN_NTP_PLL		25	/* node: NTP PLL control */
850 #define	KERN_BOOTFILE		26	/* string: name of booted kernel */
851 #define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
852 #define	KERN_MAXPROCPERUID	28	/* int: max processes per uid */
853 #define	KERN_DUMPDEV		29	/* struct cdev *: device to dump on */
854 #define	KERN_IPC		30	/* node: anything related to IPC */
855 #define	KERN_DUMMY		31	/* unused */
856 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
857 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
858 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
859 #define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
860 #define	KERN_HOSTUUID		36	/* string: host UUID identifier */
861 #define	KERN_ARND		37	/* int: from arc4rand() */
862 #define	KERN_MAXPHYS		38	/* int: MAXPHYS value */
863 /*
864  * KERN_PROC subtypes
865  */
866 #define	KERN_PROC_ALL		0	/* everything */
867 #define	KERN_PROC_PID		1	/* by process id */
868 #define	KERN_PROC_PGRP		2	/* by process group id */
869 #define	KERN_PROC_SESSION	3	/* by session of pid */
870 #define	KERN_PROC_TTY		4	/* by controlling tty */
871 #define	KERN_PROC_UID		5	/* by effective uid */
872 #define	KERN_PROC_RUID		6	/* by real uid */
873 #define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
874 #define	KERN_PROC_PROC		8	/* only return procs */
875 #define	KERN_PROC_SV_NAME	9	/* get syscall vector name */
876 #define	KERN_PROC_RGID		10	/* by real group id */
877 #define	KERN_PROC_GID		11	/* by effective group id */
878 #define	KERN_PROC_PATHNAME	12	/* path to executable */
879 #define	KERN_PROC_OVMMAP	13	/* Old VM map entries for process */
880 #define	KERN_PROC_OFILEDESC	14	/* Old file descriptors for process */
881 #define	KERN_PROC_KSTACK	15	/* Kernel stacks for process */
882 #define	KERN_PROC_INC_THREAD	0x10	/*
883 					 * modifier for pid, pgrp, tty,
884 					 * uid, ruid, gid, rgid and proc
885 					 * This effectively uses 16-31
886 					 */
887 #define	KERN_PROC_VMMAP		32	/* VM map entries for process */
888 #define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
889 #define	KERN_PROC_GROUPS	34	/* process groups */
890 #define	KERN_PROC_ENV		35	/* get environment */
891 #define	KERN_PROC_AUXV		36	/* get ELF auxiliary vector */
892 #define	KERN_PROC_RLIMIT	37	/* process resource limits */
893 #define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
894 #define	KERN_PROC_UMASK		39	/* process umask */
895 #define	KERN_PROC_OSREL		40	/* osreldate for process binary */
896 #define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
897 #define	KERN_PROC_CWD		42	/* process current working directory */
898 #define	KERN_PROC_NFDS		43	/* number of open file descriptors */
899 
900 /*
901  * KERN_IPC identifiers
902  */
903 #define	KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
904 #define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
905 #define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
906 #define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
907 #define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
908 #define	KIPC_MAX_HDR		6	/* int: max total length of headers */
909 #define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
910 
911 /*
912  * CTL_HW identifiers
913  */
914 #define	HW_MACHINE	 1		/* string: machine class */
915 #define	HW_MODEL	 2		/* string: specific machine model */
916 #define	HW_NCPU		 3		/* int: number of cpus */
917 #define	HW_BYTEORDER	 4		/* int: machine byte order */
918 #define	HW_PHYSMEM	 5		/* int: total memory */
919 #define	HW_USERMEM	 6		/* int: non-kernel memory */
920 #define	HW_PAGESIZE	 7		/* int: software page size */
921 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
922 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
923 #define	HW_FLOATINGPT	10		/* int: has HW floating point? */
924 #define	HW_MACHINE_ARCH	11		/* string: machine architecture */
925 #define	HW_REALMEM	12		/* int: 'real' memory */
926 
927 /*
928  * CTL_USER definitions
929  */
930 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
931 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
932 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
933 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
934 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
935 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
936 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
937 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
938 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
939 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
940 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
941 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
942 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
943 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
944 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
945 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
946 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
947 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
948 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
949 #define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
950 
951 #define	CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
952 #define	CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
953 #define	CTL_P1003_1B_MEMLOCK			3	/* boolean */
954 #define	CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
955 #define	CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
956 #define	CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
957 #define	CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
958 #define	CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
959 #define	CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
960 #define	CTL_P1003_1B_SEMAPHORES			10	/* boolean */
961 #define	CTL_P1003_1B_FSYNC			11	/* boolean */
962 #define	CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
963 #define	CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
964 #define	CTL_P1003_1B_TIMERS			14	/* boolean */
965 #define	CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
966 #define	CTL_P1003_1B_AIO_MAX			16	/* int */
967 #define	CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
968 #define	CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
969 #define	CTL_P1003_1B_MQ_OPEN_MAX		19	/* int */
970 #define	CTL_P1003_1B_PAGESIZE			20	/* int */
971 #define	CTL_P1003_1B_RTSIG_MAX			21	/* int */
972 #define	CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
973 #define	CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
974 #define	CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
975 #define	CTL_P1003_1B_TIMER_MAX			25	/* int */
976 
977 #define	CTL_P1003_1B_MAXID		26
978 
979 #ifdef _KERNEL
980 
981 /*
982  * Declare some common oids.
983  */
984 extern struct sysctl_oid_list sysctl__children;
985 SYSCTL_DECL(_kern);
986 SYSCTL_DECL(_kern_features);
987 SYSCTL_DECL(_kern_ipc);
988 SYSCTL_DECL(_kern_proc);
989 SYSCTL_DECL(_kern_sched);
990 SYSCTL_DECL(_kern_sched_stats);
991 SYSCTL_DECL(_sysctl);
992 SYSCTL_DECL(_vm);
993 SYSCTL_DECL(_vm_stats);
994 SYSCTL_DECL(_vm_stats_misc);
995 SYSCTL_DECL(_vfs);
996 SYSCTL_DECL(_net);
997 SYSCTL_DECL(_debug);
998 SYSCTL_DECL(_debug_sizeof);
999 SYSCTL_DECL(_dev);
1000 SYSCTL_DECL(_hw);
1001 SYSCTL_DECL(_hw_bus);
1002 SYSCTL_DECL(_hw_bus_devices);
1003 SYSCTL_DECL(_hw_bus_info);
1004 SYSCTL_DECL(_machdep);
1005 SYSCTL_DECL(_user);
1006 SYSCTL_DECL(_compat);
1007 SYSCTL_DECL(_regression);
1008 SYSCTL_DECL(_security);
1009 SYSCTL_DECL(_security_bsd);
1010 #ifdef EXT_RESOURCES
1011 SYSCTL_DECL(_clock);
1012 #endif
1013 
1014 extern char	machine[];
1015 extern char	osrelease[];
1016 extern char	ostype[];
1017 extern char	kern_ident[];
1018 
1019 /* Dynamic oid handling */
1020 struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
1021 	    struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
1022 	    void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
1023 	    const char *fmt, const char *descr, const char *label);
1024 int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
1025 	    int recurse);
1026 void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
1027 int	sysctl_move_oid(struct sysctl_oid *oidp,
1028 	    struct sysctl_oid_list *parent);
1029 int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
1030 int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
1031 int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
1032 struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
1033 	    struct sysctl_oid *oidp);
1034 struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
1035 	    struct sysctl_oid *oidp);
1036 int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
1037 	    struct sysctl_oid *oidp);
1038 
1039 int	kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1040 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1041 	    int flags);
1042 int	kernel_sysctlbyname(struct thread *td, char *name, void *old,
1043 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1044 	    int flags);
1045 int	userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1046 	    size_t *oldlenp, int inkernel, void *new, size_t newlen,
1047 	    size_t *retval, int flags);
1048 int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
1049 	    int *nindx, struct sysctl_req *req);
1050 void	sysctl_wlock(void);
1051 void	sysctl_wunlock(void);
1052 int	sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
1053 
1054 struct sbuf;
1055 struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
1056 	    struct sysctl_req *);
1057 #else	/* !_KERNEL */
1058 #include <sys/cdefs.h>
1059 
1060 __BEGIN_DECLS
1061 int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1062 int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1063 int	sysctlnametomib(const char *, int *, size_t *);
1064 __END_DECLS
1065 #endif	/* _KERNEL */
1066 
1067 #endif	/* !_SYS_SYSCTL_H_ */
1068