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