The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/sysctl.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: a1a10b913101b0aa5d7357a5c3ef5614


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.