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 /*      $NetBSD: sysctl.h,v 1.116.2.8 2004/05/23 10:45:52 tron Exp $    */
    2 
    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  */
   36 
   37 #ifndef _SYS_SYSCTL_H_
   38 #define _SYS_SYSCTL_H_
   39 
   40 /*
   41  * These are for the eproc structure defined below.
   42  */
   43 #include <sys/time.h>
   44 #include <sys/ucred.h>
   45 #include <sys/ucontext.h>
   46 #include <sys/proc.h>
   47 #include <uvm/uvm_extern.h>
   48 
   49 /* For offsetof() */
   50 #if defined(_KERNEL) || defined(_STANDALONE)
   51 #include <sys/systm.h>
   52 #else
   53 #include <stddef.h>
   54 #endif
   55 
   56 /*
   57  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
   58  * for objects that can be examined or modified.  The name is expressed as
   59  * a sequence of integers.  Like a file path name, the meaning of each
   60  * component depends on its place in the hierarchy.  The top-level and kern
   61  * identifiers are defined here, and other identifiers are defined in the
   62  * respective subsystem header files.
   63  */
   64 
   65 #define CTL_MAXNAME     12      /* largest number of components supported */
   66 #define SYSCTL_NAMELEN  32      /* longest name allowed for a node */
   67 
   68 #define CREATE_BASE     (1024)  /* start of dynamic mib allocation */
   69 #define SYSCTL_DEFSIZE  8       /* initial size of a child set */
   70 
   71 /*
   72  * Each subsystem defined by sysctl defines a list of variables
   73  * for that subsystem. Each name is either a node with further
   74  * levels defined below it, or it is a leaf of some particular
   75  * type given below. Each sysctl level defines a set of name/type
   76  * pairs to be used by sysctl(1) in manipulating the subsystem.
   77  */
   78 struct ctlname {
   79         const char *ctl_name;   /* subsystem name */
   80         int     ctl_type;       /* type of name */
   81 };
   82 #define CTLTYPE_NODE    1       /* name is a node */
   83 #define CTLTYPE_INT     2       /* name describes an integer */
   84 #define CTLTYPE_STRING  3       /* name describes a string */
   85 #define CTLTYPE_QUAD    4       /* name describes a 64-bit number */
   86 #define CTLTYPE_STRUCT  5       /* name describes a structure */
   87 
   88 /*
   89  * Flags that apply to each node, governing access and other features
   90  */
   91 #define CTLFLAG_READONLY        0x00000000
   92 #define CTLFLAG_READONLY1       0x00000010
   93 #define CTLFLAG_READONLY2       0x00000020
   94 /* #define CTLFLAG_READ*        0x00000040 */
   95 #define CTLFLAG_READWRITE       0x00000070
   96 #define CTLFLAG_ANYWRITE        0x00000080
   97 #define CTLFLAG_PRIVATE         0x00000100
   98 #define CTLFLAG_PERMANENT       0x00000200
   99 #define CTLFLAG_OWNDATA         0x00000400
  100 #define CTLFLAG_IMMEDIATE       0x00000800
  101 #define CTLFLAG_HEX             0x00001000
  102 #define CTLFLAG_ROOT            0x00002000
  103 #define CTLFLAG_ANYNUMBER       0x00004000
  104 #define CTLFLAG_HIDDEN          0x00008000
  105 #define CTLFLAG_ALIAS           0x00010000
  106 #define CTLFLAG_MMAP            0x00020000
  107 #define CTLFLAG_OWNDESC         0x00040000
  108 
  109 /*
  110  * sysctl API version
  111  */
  112 #define SYSCTL_VERS_MASK        0xff000000
  113 #define SYSCTL_VERS_0           0x00000000
  114 #define SYSCTL_VERS_1           0x01000000
  115 #define SYSCTL_VERSION          SYSCTL_VERS_1
  116 #define SYSCTL_VERS(f)          ((f) & SYSCTL_VERS_MASK)
  117 
  118 /*
  119  * Flags that can be set by a create request from user-space
  120  */
  121 #define SYSCTL_USERFLAGS        (CTLFLAG_READWRITE|\
  122                                 CTLFLAG_ANYWRITE|\
  123                                 CTLFLAG_PRIVATE|\
  124                                 CTLFLAG_OWNDATA|\
  125                                 CTLFLAG_IMMEDIATE|\
  126                                 CTLFLAG_HEX|\
  127                                 CTLFLAG_HIDDEN)
  128 
  129 /*
  130  * Accessor macros
  131  */
  132 #define SYSCTL_TYPEMASK         0x0000000f
  133 #define SYSCTL_TYPE(x)          ((x) & SYSCTL_TYPEMASK)
  134 #define SYSCTL_FLAGMASK         0x00fffff0
  135 #define SYSCTL_FLAGS(x)         ((x) & SYSCTL_FLAGMASK)
  136 
  137 /*
  138  * Meta-identifiers
  139  */
  140 #define CTL_EOL         -1              /* end of createv/destroyv list */
  141 #define CTL_QUERY       -2              /* enumerates children of a node */
  142 #define CTL_CREATE      -3              /* node create request */
  143 #define CTL_CREATESYM   -4              /* node create request with symbol */
  144 #define CTL_DESTROY     -5              /* node destroy request */
  145 #define CTL_MMAP        -6              /* mmap request */
  146 #define CTL_DESCRIBE    -7              /* get node descriptions */
  147 
  148 /*
  149  * Top-level identifiers
  150  */
  151 #define CTL_UNSPEC      0               /* unused */
  152 #define CTL_KERN        1               /* "high kernel": proc, limits */
  153 #define CTL_VM          2               /* virtual memory */
  154 #define CTL_VFS         3               /* file system, mount type is next */
  155 #define CTL_NET         4               /* network, see socket.h */
  156 #define CTL_DEBUG       5               /* debugging parameters */
  157 #define CTL_HW          6               /* generic CPU/io */
  158 #define CTL_MACHDEP     7               /* machine dependent */
  159 #define CTL_USER        8               /* user-level */
  160 #define CTL_DDB         9               /* in-kernel debugger */
  161 #define CTL_PROC        10              /* per-proc attr */
  162 #define CTL_VENDOR      11              /* vendor-specific data */
  163 #define CTL_EMUL        12              /* emulation-specific data */
  164 #define CTL_MAXID       13              /* number of valid top-level ids */
  165 
  166 #define CTL_NAMES { \
  167         { 0, 0 }, \
  168         { "kern", CTLTYPE_NODE }, \
  169         { "vm", CTLTYPE_NODE }, \
  170         { "vfs", CTLTYPE_NODE }, \
  171         { "net", CTLTYPE_NODE }, \
  172         { "debug", CTLTYPE_NODE }, \
  173         { "hw", CTLTYPE_NODE }, \
  174         { "machdep", CTLTYPE_NODE }, \
  175         { "user", CTLTYPE_NODE }, \
  176         { "ddb", CTLTYPE_NODE }, \
  177         { "proc", CTLTYPE_NODE }, \
  178         { "vendor", CTLTYPE_NODE }, \
  179         { "emul", CTLTYPE_NODE }, \
  180 }
  181 
  182 /*
  183  * The "vendor" toplevel name is to be used by vendors who wish to
  184  * have their own private MIB tree. If you do that, please use
  185  * vendor.<yourname>.*
  186  */
  187 
  188 /*
  189  * CTL_KERN identifiers
  190  */
  191 #define KERN_OSTYPE              1      /* string: system version */
  192 #define KERN_OSRELEASE           2      /* string: system release */
  193 #define KERN_OSREV               3      /* int: system revision */
  194 #define KERN_VERSION             4      /* string: compile time info */
  195 #define KERN_MAXVNODES           5      /* int: max vnodes */
  196 #define KERN_MAXPROC             6      /* int: max processes */
  197 #define KERN_MAXFILES            7      /* int: max open files */
  198 #define KERN_ARGMAX              8      /* int: max arguments to exec */
  199 #define KERN_SECURELVL           9      /* int: system security level */
  200 #define KERN_HOSTNAME           10      /* string: hostname */
  201 #define KERN_HOSTID             11      /* int: host identifier */
  202 #define KERN_CLOCKRATE          12      /* struct: struct clockrate */
  203 #define KERN_VNODE              13      /* struct: vnode structures */
  204 #define KERN_PROC               14      /* struct: process entries */
  205 #define KERN_FILE               15      /* struct: file entries */
  206 #define KERN_PROF               16      /* node: kernel profiling info */
  207 #define KERN_POSIX1             17      /* int: POSIX.1 version */
  208 #define KERN_NGROUPS            18      /* int: # of supplemental group ids */
  209 #define KERN_JOB_CONTROL        19      /* int: is job control available */
  210 #define KERN_SAVED_IDS          20      /* int: saved set-user/group-ID */
  211 #define KERN_BOOTTIME           21      /* struct: time kernel was booted */
  212 #define KERN_DOMAINNAME         22      /* string: (YP) domainname */
  213 #define KERN_MAXPARTITIONS      23      /* int: number of partitions/disk */
  214 #define KERN_RAWPARTITION       24      /* int: raw partition number */
  215 #define KERN_NTPTIME            25      /* struct: extended-precision time */
  216 #define KERN_TIMEX              26      /* struct: ntp timekeeping state */
  217 #define KERN_AUTONICETIME       27      /* int: proc time before autonice */
  218 #define KERN_AUTONICEVAL        28      /* int: auto nice value */
  219 #define KERN_RTC_OFFSET         29      /* int: offset of rtc from gmt */
  220 #define KERN_ROOT_DEVICE        30      /* string: root device */
  221 #define KERN_MSGBUFSIZE         31      /* int: max # of chars in msg buffer */
  222 #define KERN_FSYNC              32      /* int: file synchronization support */
  223 #define KERN_SYSVMSG            33      /* int: SysV message queue suppoprt */
  224 #define KERN_SYSVSEM            34      /* int: SysV semaphore support */
  225 #define KERN_SYSVSHM            35      /* int: SysV shared memory support */
  226 #define KERN_OLDSHORTCORENAME   36      /* old, unimplemented */
  227 #define KERN_SYNCHRONIZED_IO    37      /* int: POSIX synchronized I/O */
  228 #define KERN_IOV_MAX            38      /* int: max iovec's for readv(2) etc. */
  229 #define KERN_MBUF               39      /* node: mbuf parameters */
  230 #define KERN_MAPPED_FILES       40      /* int: POSIX memory mapped files */
  231 #define KERN_MEMLOCK            41      /* int: POSIX memory locking */
  232 #define KERN_MEMLOCK_RANGE      42      /* int: POSIX memory range locking */
  233 #define KERN_MEMORY_PROTECTION  43      /* int: POSIX memory protections */
  234 #define KERN_LOGIN_NAME_MAX     44      /* int: max length login name + NUL */
  235 #define KERN_DEFCORENAME        45      /* old: sort core name format */
  236 #define KERN_LOGSIGEXIT         46      /* int: log signalled processes */
  237 #define KERN_PROC2              47      /* struct: process entries */
  238 #define KERN_PROC_ARGS          48      /* struct: process argv/env */
  239 #define KERN_FSCALE             49      /* int: fixpt FSCALE */
  240 #define KERN_CCPU               50      /* int: fixpt ccpu */
  241 #define KERN_CP_TIME            51      /* struct: CPU time counters */
  242 #define KERN_SYSVIPC_INFO       52      /* number of valid kern ids */
  243 #define KERN_MSGBUF             53      /* kernel message buffer */
  244 #define KERN_CONSDEV            54      /* dev_t: console terminal device */
  245 #define KERN_MAXPTYS            55      /* int: maximum number of ptys */
  246 #define KERN_PIPE               56      /* node: pipe limits */
  247 #define KERN_MAXPHYS            57      /* int: kernel value of MAXPHYS */
  248 #define KERN_SBMAX              58      /* int: max socket buffer size */
  249 #define KERN_TKSTAT             59      /* tty in/out counters */
  250 #define KERN_MONOTONIC_CLOCK    60      /* int: POSIX monotonic clock */
  251 #define KERN_URND               61      /* int: random integer from urandom */
  252 #ifndef _KERNEL
  253 #define KERN_ARND               KERN_URND       /* compat w/ openbsd */
  254 #endif
  255 #define KERN_LABELSECTOR        62      /* int: disklabel sector */
  256 #define KERN_LABELOFFSET        63      /* int: offset of label within sector */
  257 #define KERN_LWP                64      /* struct: lwp entries */
  258 #define KERN_FORKFSLEEP         65      /* int: sleep length on failed fork */
  259 #define KERN_POSIX_THREADS      66      /* int: POSIX Threads option */
  260 #define KERN_POSIX_SEMAPHORES   67      /* int: POSIX Semaphores option */
  261 #define KERN_POSIX_BARRIERS     68      /* int: POSIX Barriers option */
  262 #define KERN_POSIX_TIMERS       69      /* int: POSIX Timers option */
  263 #define KERN_POSIX_SPIN_LOCKS   70      /* int: POSIX Spin Locks option */
  264 #define KERN_POSIX_READER_WRITER_LOCKS 71 /* int: POSIX R/W Locks option */
  265 #define KERN_DUMP_ON_PANIC      72      /* int: dump on panic */
  266 #define KERN_SOMAXKVA           73      /* int: max socket kernel virtual mem */
  267 #define KERN_ROOT_PARTITION     74      /* int: root partition */
  268 #define KERN_DRIVERS            75      /* struct: driver names and majors #s */
  269 #define KERN_BUF                76      /* struct: buffers */
  270 #define KERN_MAXID              77      /* number of valid kern ids */
  271 
  272 
  273 #define CTL_KERN_NAMES { \
  274         { 0, 0 }, \
  275         { "ostype", CTLTYPE_STRING }, \
  276         { "osrelease", CTLTYPE_STRING }, \
  277         { "osrevision", CTLTYPE_INT }, \
  278         { "version", CTLTYPE_STRING }, \
  279         { "maxvnodes", CTLTYPE_INT }, \
  280         { "maxproc", CTLTYPE_INT }, \
  281         { "maxfiles", CTLTYPE_INT }, \
  282         { "argmax", CTLTYPE_INT }, \
  283         { "securelevel", CTLTYPE_INT }, \
  284         { "hostname", CTLTYPE_STRING }, \
  285         { "hostid", CTLTYPE_INT }, \
  286         { "clockrate", CTLTYPE_STRUCT }, \
  287         { "vnode", CTLTYPE_STRUCT }, \
  288         { "proc", CTLTYPE_STRUCT }, \
  289         { "file", CTLTYPE_STRUCT }, \
  290         { "profiling", CTLTYPE_NODE }, \
  291         { "posix1version", CTLTYPE_INT }, \
  292         { "ngroups", CTLTYPE_INT }, \
  293         { "job_control", CTLTYPE_INT }, \
  294         { "saved_ids", CTLTYPE_INT }, \
  295         { "boottime", CTLTYPE_STRUCT }, \
  296         { "domainname", CTLTYPE_STRING }, \
  297         { "maxpartitions", CTLTYPE_INT }, \
  298         { "rawpartition", CTLTYPE_INT }, \
  299         { "ntptime", CTLTYPE_STRUCT }, \
  300         { "timex", CTLTYPE_STRUCT }, \
  301         { "autonicetime", CTLTYPE_INT }, \
  302         { "autoniceval", CTLTYPE_INT }, \
  303         { "rtc_offset", CTLTYPE_INT }, \
  304         { "root_device", CTLTYPE_STRING }, \
  305         { "msgbufsize", CTLTYPE_INT }, \
  306         { "fsync", CTLTYPE_INT }, \
  307         { "sysvmsg", CTLTYPE_INT }, \
  308         { "sysvsem", CTLTYPE_INT }, \
  309         { "sysvshm", CTLTYPE_INT }, \
  310         { 0, 0 }, \
  311         { "synchronized_io", CTLTYPE_INT }, \
  312         { "iov_max", CTLTYPE_INT }, \
  313         { "mbuf", CTLTYPE_NODE }, \
  314         { "mapped_files", CTLTYPE_INT }, \
  315         { "memlock", CTLTYPE_INT }, \
  316         { "memlock_range", CTLTYPE_INT }, \
  317         { "memory_protection", CTLTYPE_INT }, \
  318         { "login_name_max", CTLTYPE_INT }, \
  319         { "defcorename", CTLTYPE_STRING }, \
  320         { "logsigexit", CTLTYPE_INT }, \
  321         { "proc2", CTLTYPE_STRUCT }, \
  322         { "proc_args", CTLTYPE_STRING }, \
  323         { "fscale", CTLTYPE_INT }, \
  324         { "ccpu", CTLTYPE_INT }, \
  325         { "cp_time", CTLTYPE_STRUCT }, \
  326         { "sysvipc_info", CTLTYPE_STRUCT }, \
  327         { "msgbuf", CTLTYPE_STRUCT }, \
  328         { "consdev", CTLTYPE_STRUCT }, \
  329         { "maxptys", CTLTYPE_INT }, \
  330         { "pipe", CTLTYPE_NODE }, \
  331         { "maxphys", CTLTYPE_INT }, \
  332         { "sbmax", CTLTYPE_INT }, \
  333         { "tkstat", CTLTYPE_NODE }, \
  334         { "monotonic_clock", CTLTYPE_INT }, \
  335         { "urandom", CTLTYPE_INT }, \
  336         { "labelsector", CTLTYPE_INT }, \
  337         { "labeloffset", CTLTYPE_INT }, \
  338         { "lwp", CTLTYPE_STRUCT }, \
  339         { "forkfsleep", CTLTYPE_INT }, \
  340         { "posix_threads", CTLTYPE_INT }, \
  341         { "posix_semaphores", CTLTYPE_INT }, \
  342         { "posix_barriers", CTLTYPE_INT }, \
  343         { "posix_timers", CTLTYPE_INT }, \
  344         { "posix_spin_locks", CTLTYPE_INT }, \
  345         { "posix_reader_writer_locks", CTLTYPE_INT }, \
  346         { "dump_on_panic", CTLTYPE_INT}, \
  347         { "somaxkva", CTLTYPE_INT}, \
  348         { "root_partition", CTLTYPE_INT}, \
  349         { "drivers", CTLTYPE_STRUCT }, \
  350 }
  351 
  352 /*
  353  * KERN_PROC subtypes
  354  */
  355 #define KERN_PROC_ALL            0      /* everything */
  356 #define KERN_PROC_PID            1      /* by process id */
  357 #define KERN_PROC_PGRP           2      /* by process group id */
  358 #define KERN_PROC_SESSION        3      /* by session of pid */
  359 #define KERN_PROC_TTY            4      /* by controlling tty */
  360 #define KERN_PROC_UID            5      /* by effective uid */
  361 #define KERN_PROC_RUID           6      /* by real uid */
  362 #define KERN_PROC_GID            7      /* by effective gid */
  363 #define KERN_PROC_RGID           8      /* by real gid */
  364 
  365 /*
  366  * KERN_PROC_TTY sub-subtypes
  367  */
  368 #define KERN_PROC_TTY_NODEV     NODEV           /* no controlling tty */
  369 #define KERN_PROC_TTY_REVOKE    ((dev_t)-2)     /* revoked tty */
  370 
  371 /*
  372  * KERN_PROC subtype ops return arrays of augmented proc structures:
  373  */
  374 struct kinfo_proc {
  375         struct  proc kp_proc;                   /* proc structure */
  376         struct  eproc {
  377                 struct  proc *e_paddr;          /* address of proc */
  378                 struct  session *e_sess;        /* session pointer */
  379                 struct  pcred e_pcred;          /* process credentials */
  380                 struct  ucred e_ucred;          /* current credentials */
  381                 struct  vmspace e_vm;           /* address space */
  382                 pid_t   e_ppid;                 /* parent process id */
  383                 pid_t   e_pgid;                 /* process group id */
  384                 short   e_jobc;                 /* job control counter */
  385                 dev_t   e_tdev;                 /* controlling tty dev */
  386                 pid_t   e_tpgid;                /* tty process group id */
  387                 struct  session *e_tsess;       /* tty session pointer */
  388 #define WMESGLEN        8
  389                 char    e_wmesg[WMESGLEN];      /* wchan message */
  390                 segsz_t e_xsize;                /* text size */
  391                 short   e_xrssize;              /* text rss */
  392                 short   e_xccount;              /* text references */
  393                 short   e_xswrss;
  394                 long    e_flag;
  395 #define EPROC_CTTY      0x01    /* controlling tty vnode active */
  396 #define EPROC_SLEADER   0x02    /* session leader */
  397                 char    e_login[MAXLOGNAME];    /* setlogin() name */
  398                 pid_t   e_sid;                  /* session id */
  399                 long    e_spare[3];
  400         } kp_eproc;
  401 };
  402 
  403 /*
  404  * Convert pointer to 64 bit unsigned integer for struct
  405  * kinfo_proc2, etc.
  406  */
  407 #define PTRTOUINT64(p) ((u_int64_t)(uintptr_t)(p))
  408 #define UINT64TOPTR(u) ((void *)(uintptr_t)(u))
  409 
  410 /*
  411  * KERN_PROC2 subtype ops return arrays of relatively fixed size
  412  * structures of process info.   Use 8 byte alignment, and new
  413  * elements should only be added to the end of this structure so
  414  * binary compatibility can be preserved.
  415  */
  416 #define KI_NGROUPS      16
  417 #define KI_MAXCOMLEN    24      /* extra for 8 byte alignment */
  418 #define KI_WMESGLEN     8
  419 #define KI_MAXLOGNAME   24      /* extra for 8 byte alignment */
  420 
  421 #define KI_NOCPU        (~(u_int64_t)0)
  422 
  423 typedef struct {
  424         u_int32_t       __bits[4];
  425 } ki_sigset_t;
  426 
  427 struct kinfo_proc2 {
  428         u_int64_t p_forw;               /* PTR: linked run/sleep queue. */
  429         u_int64_t p_back;
  430         u_int64_t p_paddr;              /* PTR: address of proc */
  431 
  432         u_int64_t p_addr;               /* PTR: Kernel virtual addr of u-area */
  433         u_int64_t p_fd;                 /* PTR: Ptr to open files structure. */
  434         u_int64_t p_cwdi;               /* PTR: cdir/rdir/cmask info */
  435         u_int64_t p_stats;              /* PTR: Accounting/statistics */
  436         u_int64_t p_limit;              /* PTR: Process limits. */
  437         u_int64_t p_vmspace;            /* PTR: Address space. */
  438         u_int64_t p_sigacts;            /* PTR: Signal actions, state */
  439         u_int64_t p_sess;               /* PTR: session pointer */
  440         u_int64_t p_tsess;              /* PTR: tty session pointer */
  441         u_int64_t p_ru;                 /* PTR: Exit information. XXX */
  442 
  443         int32_t p_eflag;                /* LONG: extra kinfo_proc2 flags */
  444         int32_t p_exitsig;              /* INT: signal to sent to parent on exit */
  445         int32_t p_flag;                 /* INT: P_* flags. */
  446 
  447         int32_t p_pid;                  /* PID_T: Process identifier. */
  448         int32_t p_ppid;                 /* PID_T: Parent process id */
  449         int32_t p_sid;                  /* PID_T: session id */
  450         int32_t p__pgid;                /* PID_T: process group id */
  451                                         /* XXX: <sys/proc.h> hijacks p_pgid */
  452         int32_t p_tpgid;                /* PID_T: tty process group id */
  453 
  454         u_int32_t p_uid;                /* UID_T: effective user id */
  455         u_int32_t p_ruid;               /* UID_T: real user id */
  456         u_int32_t p_gid;                /* GID_T: effective group id */
  457         u_int32_t p_rgid;               /* GID_T: real group id */
  458 
  459         u_int32_t p_groups[KI_NGROUPS]; /* GID_T: groups */
  460         int16_t p_ngroups;              /* SHORT: number of groups */
  461 
  462         int16_t p_jobc;                 /* SHORT: job control counter */
  463         u_int32_t p_tdev;               /* DEV_T: controlling tty dev */
  464 
  465         u_int32_t p_estcpu;             /* U_INT: Time averaged value of p_cpticks. */
  466         u_int32_t p_rtime_sec;          /* STRUCT TIMEVAL: Real time. */
  467         u_int32_t p_rtime_usec;         /* STRUCT TIMEVAL: Real time. */
  468         int32_t p_cpticks;              /* INT: Ticks of CPU time. */
  469         u_int32_t p_pctcpu;             /* FIXPT_T: %cpu for this process during p_swtime */
  470         u_int32_t p_swtime;             /* U_INT: Time swapped in or out. */
  471         u_int32_t p_slptime;            /* U_INT: Time since last blocked. */
  472         int32_t p_schedflags;           /* INT: PSCHED_* flags */
  473 
  474         u_int64_t p_uticks;             /* U_QUAD_T: Statclock hits in user mode. */
  475         u_int64_t p_sticks;             /* U_QUAD_T: Statclock hits in system mode. */
  476         u_int64_t p_iticks;             /* U_QUAD_T: Statclock hits processing intr. */
  477 
  478         u_int64_t p_tracep;             /* PTR: Trace to vnode or file */
  479         int32_t p_traceflag;            /* INT: Kernel trace points. */
  480 
  481         int32_t p_holdcnt;              /* INT: If non-zero, don't swap. */
  482 
  483         ki_sigset_t p_siglist;          /* SIGSET_T: Signals arrived but not delivered. */
  484         ki_sigset_t p_sigmask;          /* SIGSET_T: Current signal mask. */
  485         ki_sigset_t p_sigignore;        /* SIGSET_T: Signals being ignored. */
  486         ki_sigset_t p_sigcatch;         /* SIGSET_T: Signals being caught by user. */
  487 
  488         int8_t  p_stat;                 /* CHAR: S* process status (from LWP). */
  489         u_int8_t p_priority;            /* U_CHAR: Process priority. */
  490         u_int8_t p_usrpri;              /* U_CHAR: User-priority based on p_cpu and p_nice. */
  491         u_int8_t p_nice;                /* U_CHAR: Process "nice" value. */
  492 
  493         u_int16_t p_xstat;              /* U_SHORT: Exit status for wait; also stop signal. */
  494         u_int16_t p_acflag;             /* U_SHORT: Accounting flags. */
  495 
  496         char    p_comm[KI_MAXCOMLEN];
  497 
  498         char    p_wmesg[KI_WMESGLEN];   /* wchan message */
  499         u_int64_t p_wchan;              /* PTR: sleep address. */
  500 
  501         char    p_login[KI_MAXLOGNAME]; /* setlogin() name */
  502 
  503         int32_t p_vm_rssize;            /* SEGSZ_T: current resident set size in pages */
  504         int32_t p_vm_tsize;             /* SEGSZ_T: text size (pages) */
  505         int32_t p_vm_dsize;             /* SEGSZ_T: data size (pages) */
  506         int32_t p_vm_ssize;             /* SEGSZ_T: stack size (pages) */
  507 
  508         int64_t p_uvalid;               /* CHAR: following p_u* members from struct user are valid */
  509                                         /* XXX 64 bits for alignment */
  510         u_int32_t p_ustart_sec;         /* STRUCT TIMEVAL: starting time. */
  511         u_int32_t p_ustart_usec;        /* STRUCT TIMEVAL: starting time. */
  512 
  513         u_int32_t p_uutime_sec;         /* STRUCT TIMEVAL: user time. */
  514         u_int32_t p_uutime_usec;        /* STRUCT TIMEVAL: user time. */
  515         u_int32_t p_ustime_sec;         /* STRUCT TIMEVAL: system time. */
  516         u_int32_t p_ustime_usec;        /* STRUCT TIMEVAL: system time. */
  517 
  518         u_int64_t p_uru_maxrss;         /* LONG: max resident set size. */
  519         u_int64_t p_uru_ixrss;          /* LONG: integral shared memory size. */
  520         u_int64_t p_uru_idrss;          /* LONG: integral unshared data ". */
  521         u_int64_t p_uru_isrss;          /* LONG: integral unshared stack ". */
  522         u_int64_t p_uru_minflt;         /* LONG: page reclaims. */
  523         u_int64_t p_uru_majflt;         /* LONG: page faults. */
  524         u_int64_t p_uru_nswap;          /* LONG: swaps. */
  525         u_int64_t p_uru_inblock;        /* LONG: block input operations. */
  526         u_int64_t p_uru_oublock;        /* LONG: block output operations. */
  527         u_int64_t p_uru_msgsnd;         /* LONG: messages sent. */
  528         u_int64_t p_uru_msgrcv;         /* LONG: messages received. */
  529         u_int64_t p_uru_nsignals;       /* LONG: signals received. */
  530         u_int64_t p_uru_nvcsw;          /* LONG: voluntary context switches. */
  531         u_int64_t p_uru_nivcsw;         /* LONG: involuntary ". */
  532 
  533         u_int32_t p_uctime_sec;         /* STRUCT TIMEVAL: child u+s time. */
  534         u_int32_t p_uctime_usec;        /* STRUCT TIMEVAL: child u+s time. */
  535         u_int64_t p_cpuid;              /* LONG: CPU id */
  536         u_int64_t p_realflag;           /* INT: P_* flags (not including LWPs). */
  537         u_int64_t p_nlwps;              /* LONG: Number of LWPs */
  538         u_int64_t p_nrlwps;             /* LONG: Number of running LWPs */
  539         u_int64_t p_realstat;           /* LONG: non-LWP process status */
  540         u_int32_t p_svuid;              /* UID_T: saved user id */
  541         u_int32_t p_svgid;              /* GID_T: saved group id */
  542 };
  543 
  544 /*
  545  * KERN_LWP structure. See notes on KERN_PROC2 about adding elements.
  546  */
  547 struct kinfo_lwp {
  548         u_int64_t l_forw;               /* PTR: linked run/sleep queue. */
  549         u_int64_t l_back;
  550         u_int64_t l_laddr;              /* PTR: Address of LWP */
  551         u_int64_t l_addr;               /* PTR: Kernel virtual addr of u-area */
  552         int32_t l_lid;                  /* LWPID_T: LWP identifier */
  553         int32_t l_flag;                 /* INT: L_* flags. */
  554         u_int32_t l_swtime;             /* U_INT: Time swapped in or out. */
  555         u_int32_t l_slptime;            /* U_INT: Time since last blocked. */
  556         int32_t l_schedflags;           /* INT: PSCHED_* flags */
  557         int32_t l_holdcnt;              /* INT: If non-zero, don't swap. */
  558         u_int8_t l_priority;            /* U_CHAR: Process priority. */
  559         u_int8_t l_usrpri;              /* U_CHAR: User-priority based on l_cpu and p_nice. */
  560         int8_t  l_stat;                 /* CHAR: S* process status. */
  561         int8_t  l_pad1;                 /* fill out to 4-byte boundary */
  562         int32_t l_pad2;                 /* .. and then to an 8-byte boundary */
  563         char    l_wmesg[KI_WMESGLEN];   /* wchan message */
  564         u_int64_t l_wchan;              /* PTR: sleep address. */
  565         u_int64_t l_cpuid;              /* LONG: CPU id */
  566 };
  567 
  568 /*
  569  * KERN_PROC_ARGS subtypes
  570  */
  571 #define KERN_PROC_ARGV          1       /* argv */
  572 #define KERN_PROC_NARGV         2       /* number of strings in above */
  573 #define KERN_PROC_ENV           3       /* environ */
  574 #define KERN_PROC_NENV          4       /* number of strings in above */
  575 
  576 /*
  577  * KERN_SYSVIPC_INFO subtypes
  578  */
  579 #define KERN_SYSVIPC_MSG_INFO           1       /* msginfo and msqid_ds */
  580 #define KERN_SYSVIPC_SEM_INFO           2       /* seminfo and semid_ds */
  581 #define KERN_SYSVIPC_SHM_INFO           3       /* shminfo and shmid_ds */
  582 
  583 /*
  584  * tty counter sysctl variables
  585  */
  586 #define KERN_TKSTAT_NIN                 1       /* total input character */
  587 #define KERN_TKSTAT_NOUT                2       /* total output character */
  588 #define KERN_TKSTAT_CANCC               3       /* canonical input character */
  589 #define KERN_TKSTAT_RAWCC               4       /* raw input character */
  590 #define KERN_TKSTAT_MAXID               5       /* number of valid TKSTAT ids */
  591 
  592 #define KERN_TKSTAT_NAMES { \
  593         { 0, 0 }, \
  594         { "nin", CTLTYPE_QUAD }, \
  595         { "nout", CTLTYPE_QUAD }, \
  596         { "cancc", CTLTYPE_QUAD }, \
  597         { "rawcc", CTLTYPE_QUAD }, \
  598 }
  599 
  600 /*
  601  * kern.drivers returns an array of these.
  602  */
  603 
  604 struct kinfo_drivers {
  605         int32_t         d_cmajor;
  606         int32_t         d_bmajor;
  607         char            d_name[24];
  608 };
  609 
  610 /*
  611  * KERN_BUF subtypes, like KERN_PROC2, where the four following mib
  612  * entries specify "which type of buf", "which particular buf",
  613  * "sizeof buf", and "how many".  Currently, only "all buf" is
  614  * defined.
  615  */
  616 #define KERN_BUF_ALL    0               /* all buffers */
  617 
  618 /*
  619  * kern.buf returns an array of these structures, which are designed
  620  * both to be immune to 32/64 bit emulation issues and to provide
  621  * backwards compatibility.  Note that the order here differs slightly
  622  * from the real struct buf in order to achieve proper 64 bit
  623  * alignment.
  624  */
  625 struct buf_sysctl {
  626         uint32_t b_flags;       /* LONG: B_* flags */
  627         int32_t  b_error;       /* INT: Errno value */
  628         int32_t  b_prio;        /* INT: Hint for buffer queue discipline */
  629         uint32_t b_dev;         /* DEV_T: Device associated with buffer */
  630         uint64_t b_bufsize;     /* LONG: Allocated buffer size */
  631         uint64_t b_bcount;      /* LONG: Valid bytes in buffer */
  632         uint64_t b_resid;       /* LONG: Remaining I/O */
  633         uint64_t b_addr;        /* CADDR_T: Memory, superblocks, indirect... */
  634         uint64_t b_blkno;       /* DADDR_T: Underlying physical block number */
  635         uint64_t b_rawblkno;    /* DADDR_T: Raw underlying physical block */
  636         uint64_t b_iodone;      /* PTR: Function called upon completion */
  637         uint64_t b_proc;        /* PTR: Associated proc if B_PHYS set */
  638         uint64_t b_vp;          /* PTR: File vnode */
  639         uint64_t b_saveaddr;    /* PTR: Original b_addr for physio */
  640         uint64_t b_lblkno;      /* DADDR_T: Logical block number */
  641 };
  642 
  643 /*
  644  * CTL_HW identifiers
  645  */
  646 #define HW_MACHINE       1              /* string: machine class */
  647 #define HW_MODEL         2              /* string: specific machine model */
  648 #define HW_NCPU          3              /* int: number of cpus */
  649 #define HW_BYTEORDER     4              /* int: machine byte order */
  650 #define HW_PHYSMEM       5              /* int: total memory (bytes) */
  651 #define HW_USERMEM       6              /* int: non-kernel memory (bytes) */
  652 #define HW_PAGESIZE      7              /* int: software page size */
  653 #define HW_DISKNAMES     8              /* string: disk drive names */
  654 #define HW_DISKSTATS     9              /* struct: diskstats[] */
  655 #define HW_MACHINE_ARCH 10              /* string: machine architecture */
  656 #define HW_ALIGNBYTES   11              /* int: ALIGNBYTES for the kernel */
  657 #define HW_CNMAGIC      12              /* string: console magic sequence(s) */
  658 #define HW_PHYSMEM64    13              /* quad: total memory (bytes) */
  659 #define HW_USERMEM64    14              /* quad: non-kernel memory (bytes) */
  660 #define HW_MAXID        15              /* number of valid hw ids */
  661 
  662 #define CTL_HW_NAMES { \
  663         { 0, 0 }, \
  664         { "machine", CTLTYPE_STRING }, \
  665         { "model", CTLTYPE_STRING }, \
  666         { "ncpu", CTLTYPE_INT }, \
  667         { "byteorder", CTLTYPE_INT }, \
  668         { "physmem", CTLTYPE_INT }, \
  669         { "usermem", CTLTYPE_INT }, \
  670         { "pagesize", CTLTYPE_INT }, \
  671         { "disknames", CTLTYPE_STRING }, \
  672         { "diskstats", CTLTYPE_STRUCT }, \
  673         { "machine_arch", CTLTYPE_STRING }, \
  674         { "alignbytes", CTLTYPE_INT }, \
  675         { "cnmagic", CTLTYPE_STRING }, \
  676         { "physmem64", CTLTYPE_QUAD }, \
  677         { "usermem64", CTLTYPE_QUAD }, \
  678 }
  679 
  680 /*
  681  * CTL_USER definitions
  682  */
  683 #define USER_CS_PATH             1      /* string: _CS_PATH */
  684 #define USER_BC_BASE_MAX         2      /* int: BC_BASE_MAX */
  685 #define USER_BC_DIM_MAX          3      /* int: BC_DIM_MAX */
  686 #define USER_BC_SCALE_MAX        4      /* int: BC_SCALE_MAX */
  687 #define USER_BC_STRING_MAX       5      /* int: BC_STRING_MAX */
  688 #define USER_COLL_WEIGHTS_MAX    6      /* int: COLL_WEIGHTS_MAX */
  689 #define USER_EXPR_NEST_MAX       7      /* int: EXPR_NEST_MAX */
  690 #define USER_LINE_MAX            8      /* int: LINE_MAX */
  691 #define USER_RE_DUP_MAX          9      /* int: RE_DUP_MAX */
  692 #define USER_POSIX2_VERSION     10      /* int: POSIX2_VERSION */
  693 #define USER_POSIX2_C_BIND      11      /* int: POSIX2_C_BIND */
  694 #define USER_POSIX2_C_DEV       12      /* int: POSIX2_C_DEV */
  695 #define USER_POSIX2_CHAR_TERM   13      /* int: POSIX2_CHAR_TERM */
  696 #define USER_POSIX2_FORT_DEV    14      /* int: POSIX2_FORT_DEV */
  697 #define USER_POSIX2_FORT_RUN    15      /* int: POSIX2_FORT_RUN */
  698 #define USER_POSIX2_LOCALEDEF   16      /* int: POSIX2_LOCALEDEF */
  699 #define USER_POSIX2_SW_DEV      17      /* int: POSIX2_SW_DEV */
  700 #define USER_POSIX2_UPE         18      /* int: POSIX2_UPE */
  701 #define USER_STREAM_MAX         19      /* int: POSIX2_STREAM_MAX */
  702 #define USER_TZNAME_MAX         20      /* int: POSIX2_TZNAME_MAX */
  703 #define USER_ATEXIT_MAX         21      /* int: {ATEXIT_MAX} */
  704 #define USER_MAXID              22      /* number of valid user ids */
  705 
  706 #define CTL_USER_NAMES { \
  707         { 0, 0 }, \
  708         { "cs_path", CTLTYPE_STRING }, \
  709         { "bc_base_max", CTLTYPE_INT }, \
  710         { "bc_dim_max", CTLTYPE_INT }, \
  711         { "bc_scale_max", CTLTYPE_INT }, \
  712         { "bc_string_max", CTLTYPE_INT }, \
  713         { "coll_weights_max", CTLTYPE_INT }, \
  714         { "expr_nest_max", CTLTYPE_INT }, \
  715         { "line_max", CTLTYPE_INT }, \
  716         { "re_dup_max", CTLTYPE_INT }, \
  717         { "posix2_version", CTLTYPE_INT }, \
  718         { "posix2_c_bind", CTLTYPE_INT }, \
  719         { "posix2_c_dev", CTLTYPE_INT }, \
  720         { "posix2_char_term", CTLTYPE_INT }, \
  721         { "posix2_fort_dev", CTLTYPE_INT }, \
  722         { "posix2_fort_run", CTLTYPE_INT }, \
  723         { "posix2_localedef", CTLTYPE_INT }, \
  724         { "posix2_sw_dev", CTLTYPE_INT }, \
  725         { "posix2_upe", CTLTYPE_INT }, \
  726         { "stream_max", CTLTYPE_INT }, \
  727         { "tzname_max", CTLTYPE_INT }, \
  728         { "atexit_max", CTLTYPE_INT }, \
  729 }
  730 
  731 /*
  732  * CTL_DDB definitions
  733  */
  734 #define DDBCTL_RADIX            1       /* int: Input and output radix */
  735 #define DDBCTL_MAXOFF           2       /* int: max symbol offset */
  736 #define DDBCTL_MAXWIDTH         3       /* int: width of the display line */
  737 #define DDBCTL_LINES            4       /* int: number of display lines */
  738 #define DDBCTL_TABSTOPS         5       /* int: tab width */
  739 #define DDBCTL_ONPANIC          6       /* int: DDB on panic if non-zero */
  740 #define DDBCTL_FROMCONSOLE      7       /* int: DDB via console if non-zero */
  741 #define DDBCTL_MAXID            8       /* number of valid DDB ids */
  742 
  743 #define CTL_DDB_NAMES { \
  744         { 0, 0 }, \
  745         { "radix", CTLTYPE_INT }, \
  746         { "maxoff", CTLTYPE_INT }, \
  747         { "maxwidth", CTLTYPE_INT }, \
  748         { "lines", CTLTYPE_INT }, \
  749         { "tabstops", CTLTYPE_INT }, \
  750         { "onpanic", CTLTYPE_INT }, \
  751         { "fromconsole", CTLTYPE_INT }, \
  752 }
  753 
  754 /*
  755  * CTL_DEBUG definitions
  756  *
  757  * Second level identifier specifies which debug variable.
  758  * Third level identifier specifies which stucture component.
  759  */
  760 #define CTL_DEBUG_NAME          0       /* string: variable name */
  761 #define CTL_DEBUG_VALUE         1       /* int: variable value */
  762 #define CTL_DEBUG_MAXID         20
  763 
  764 /*
  765  * CTL_PROC subtype. Either a PID, or a magic value for the current proc.
  766  */
  767 
  768 #define PROC_CURPROC    (~((u_int)1 << 31))
  769 
  770 /*
  771  * CTL_PROC tree: either corename (string), or a limit
  772  * (rlimit.<type>.{hard,soft}, int).
  773  */
  774 #define PROC_PID_CORENAME       1
  775 #define PROC_PID_LIMIT          2
  776 #define PROC_PID_STOPFORK       3
  777 #define PROC_PID_STOPEXEC       4
  778 #define PROC_PID_STOPEXIT       5
  779 #define PROC_PID_MAXID          6
  780 
  781 #define PROC_PID_NAMES { \
  782         { 0, 0 }, \
  783         { "corename", CTLTYPE_STRING }, \
  784         { "rlimit", CTLTYPE_NODE }, \
  785         { "stopfork", CTLTYPE_INT }, \
  786         { "stopexec", CTLTYPE_INT }, \
  787         { "stopexit", CTLTYPE_INT }, \
  788 }
  789 
  790 /* Limit types from <sys/resources.h> */
  791 #define PROC_PID_LIMIT_CPU      (RLIMIT_CPU+1)
  792 #define PROC_PID_LIMIT_FSIZE    (RLIMIT_FSIZE+1)
  793 #define PROC_PID_LIMIT_DATA     (RLIMIT_DATA+1)
  794 #define PROC_PID_LIMIT_STACK    (RLIMIT_STACK+1)
  795 #define PROC_PID_LIMIT_CORE     (RLIMIT_CORE+1)
  796 #define PROC_PID_LIMIT_RSS      (RLIMIT_RSS+1)
  797 #define PROC_PID_LIMIT_MEMLOCK  (RLIMIT_MEMLOCK+1)
  798 #define PROC_PID_LIMIT_NPROC    (RLIMIT_NPROC+1)
  799 #define PROC_PID_LIMIT_NOFILE   (RLIMIT_NOFILE+1)
  800 #define PROC_PID_LIMIT_MAXID    10
  801 
  802 #define PROC_PID_LIMIT_NAMES { \
  803         { 0, 0 }, \
  804         { "cputime", CTLTYPE_NODE }, \
  805         { "filesize", CTLTYPE_NODE }, \
  806         { "datasize", CTLTYPE_NODE }, \
  807         { "stacksize", CTLTYPE_NODE }, \
  808         { "coredumpsize", CTLTYPE_NODE }, \
  809         { "memoryuse", CTLTYPE_NODE }, \
  810         { "memorylocked", CTLTYPE_NODE }, \
  811         { "maxproc", CTLTYPE_NODE }, \
  812         { "descriptors", CTLTYPE_NODE }, \
  813 }
  814 /* for each type, either hard or soft value */
  815 #define PROC_PID_LIMIT_TYPE_SOFT        1
  816 #define PROC_PID_LIMIT_TYPE_HARD        2
  817 #define PROC_PID_LIMIT_TYPE_MAXID       3
  818 
  819 #define PROC_PID_LIMIT_TYPE_NAMES { \
  820         {0, 0}, \
  821         { "soft", CTLTYPE_QUAD }, \
  822         { "hard", CTLTYPE_QUAD }, \
  823 }
  824 
  825 /*
  826  * CTL_EMUL definitions
  827  *
  828  * Second level identifier specifies which emulation variable.
  829  * Subsequent levels are specified in the emulations themselves.
  830  */
  831 #define EMUL_LINUX      1
  832 #define EMUL_IRIX       2
  833 #define EMUL_DARWIN     3
  834 
  835 #define EMUL_MAXID      4
  836 #define CTL_EMUL_NAMES { \
  837         { 0, 0 }, \
  838         { "linux", CTLTYPE_NODE }, \
  839         { "irix", CTLTYPE_NODE }, \
  840         { "darwin", CTLTYPE_NODE }, \
  841 }
  842 
  843 #ifdef _KERNEL
  844 
  845 #if defined(_KERNEL_OPT)
  846 #include "opt_sysctl.h"
  847 #endif
  848 
  849 /*
  850  * A log of nodes created by a setup function or set of setup
  851  * functions so that they can be torn down in one "transaction"
  852  * when no longer needed.
  853  *
  854  * Users of the log merely pass a pointer to a pointer, and the sysctl
  855  * infrastructure takes care of the rest.
  856  */
  857 struct sysctllog;
  858 
  859 /*
  860  * CTL_DEBUG variables.
  861  *
  862  * These are declared as separate variables so that they can be
  863  * individually initialized at the location of their associated
  864  * variable. The loader prevents multiple use by issuing errors
  865  * if a variable is initialized in more than one place. They are
  866  * aggregated into an array in debug_sysctl(), so that it can
  867  * conveniently locate them when querried. If more debugging
  868  * variables are added, they must also be declared here and also
  869  * entered into the array.
  870  *
  871  * Note that the debug subtree is largely obsolescent in terms of
  872  * functionality now that we have dynamic sysctl, but the
  873  * infrastructure is retained for backwards compatibility.
  874  */
  875 struct ctldebug {
  876         char    *debugname;     /* name of debugging variable */
  877         int     *debugvar;      /* pointer to debugging variable */
  878 };
  879 #ifdef  DEBUG
  880 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
  881 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
  882 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
  883 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
  884 #endif  /* DEBUG */
  885 
  886 #define SYSCTLFN_PROTO const int *, u_int, void *, \
  887         size_t *, const void *, size_t, \
  888         const int *, struct lwp *, const struct sysctlnode *
  889 #define SYSCTLFN_ARGS const int *name, u_int namelen, void *oldp, \
  890         size_t *oldlenp, const void *newp, size_t newlen, \
  891         const int *oname, struct lwp *l, const struct sysctlnode *rnode
  892 #define SYSCTLFN_RWPROTO const int *, u_int, void *, \
  893         size_t *, const void *, size_t, \
  894         const int *, struct lwp *, struct sysctlnode *
  895 #define SYSCTLFN_RWARGS const int *name, u_int namelen, void *oldp, \
  896         size_t *oldlenp, const void *newp, size_t newlen, \
  897         const int *oname, struct lwp *l, struct sysctlnode *rnode
  898 #define SYSCTLFN_CALL(node) name, namelen, oldp, \
  899         oldlenp, newp, newlen, \
  900         oname, l, (struct sysctlnode *)node
  901 
  902 #ifdef _LKM
  903 
  904 #define SYSCTL_SETUP_PROTO(name)                                \
  905         void name(struct sysctllog **)
  906 #ifdef SYSCTL_DEBUG_SETUP
  907 #define SYSCTL_SETUP(name, desc)                                \
  908         static void __CONCAT(___,name)(struct sysctllog **);    \
  909         void name(struct sysctllog **clog) {                    \
  910                 printf("%s\n", desc);                           \
  911                 __CONCAT(___,name)(clog); }                     \
  912         __link_set_add_text(sysctl_funcs, name);                \
  913         static void __CONCAT(___,name)(struct sysctllog **clog)
  914 #else /* SYSCTL_DEBUG_SETUP */
  915 #define SYSCTL_SETUP(name, desc)                                \
  916         __link_set_add_text(sysctl_funcs, name);                \
  917         void name(struct sysctllog **clog)
  918 #endif /* SYSCTL_DEBUG_SETUP */
  919 
  920 #else /* _LKM */
  921 
  922 #define SYSCTL_SETUP_PROTO(name)
  923 #ifdef SYSCTL_DEBUG_SETUP
  924 #define SYSCTL_SETUP(name, desc)                                \
  925         static void __CONCAT(___,name)(struct sysctllog **);    \
  926         static void name(struct sysctllog **clog) {             \
  927                 printf("%s\n", desc);                           \
  928                 __CONCAT(___,name)(clog); }                     \
  929         __link_set_add_text(sysctl_funcs, name);                \
  930         static void __CONCAT(___,name)(struct sysctllog **clog)
  931 #else /* SYSCTL_DEBUG_SETUP */
  932 #define SYSCTL_SETUP(name, desc)                                \
  933         static void name(struct sysctllog **);                  \
  934         __link_set_add_text(sysctl_funcs, name);                \
  935         static void name(struct sysctllog **clog)
  936 #endif /* SYSCTL_DEBUG_SETUP */
  937 typedef void (*sysctl_setup_func)(struct sysctllog **);
  938 
  939 #endif /* _LKM */
  940 
  941 /*
  942  * Internal sysctl function calling convention:
  943  *
  944  *      (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen,
  945  *                  origname, lwp, node);
  946  *
  947  * The name parameter points at the next component of the name to be
  948  * interpreted.  The namelen parameter is the number of integers in
  949  * the name.  The origname parameter points to the start of the name
  950  * being parsed.  The node parameter points to the node on which the
  951  * current operation is to be performed.
  952  */
  953 typedef int (*sysctlfn)(SYSCTLFN_PROTO);
  954 
  955 /*
  956  * used in more than just sysctl
  957  */
  958 void    fill_eproc(struct proc *, struct eproc *);
  959 
  960 /*
  961  * subsystem setup
  962  */
  963 void    sysctl_init(void);
  964 
  965 /*
  966  * typical syscall call order
  967  */
  968 int     sysctl_lock(struct lwp *, void *, size_t);
  969 int     sysctl_dispatch(SYSCTLFN_RWPROTO);
  970 void    sysctl_unlock(struct lwp *);
  971 
  972 /*
  973  * tree navigation primitives (must obtain lock before using these)
  974  */
  975 int     sysctl_locate(struct lwp *, const int *, u_int, struct sysctlnode **,
  976                       int *);
  977 int     sysctl_query(SYSCTLFN_PROTO);
  978 #ifdef SYSCTL_DEBUG_CREATE
  979 #define sysctl_create _sysctl_create
  980 #endif /* SYSCTL_DEBUG_CREATE */
  981 int     sysctl_create(SYSCTLFN_RWPROTO);
  982 int     sysctl_destroy(SYSCTLFN_RWPROTO);
  983 int     sysctl_lookup(SYSCTLFN_RWPROTO);
  984 int     sysctl_describe(SYSCTLFN_PROTO);
  985 
  986 /*
  987  * simple variadic interface for adding/removing nodes
  988  */
  989 int     sysctl_createv(struct sysctllog **, int,
  990                        struct sysctlnode **, struct sysctlnode **,
  991                        int, int, const char *, const char *,
  992                        sysctlfn, u_quad_t, void *, size_t, ...);
  993 int     sysctl_destroyv(struct sysctlnode *, ...);
  994 
  995 /*
  996  * miscellany
  997  */
  998 void    sysctl_dump(const struct sysctlnode *);
  999 void    sysctl_free(struct sysctlnode *);
 1000 void    sysctl_teardown(struct sysctllog **);
 1001 
 1002 #if SYSCTL_INCLUDE_DESCR
 1003 #define SYSCTL_DESCR(s) s
 1004 #else /* SYSCTL_INCLUDE_DESCR */
 1005 #define SYSCTL_DESCR(s) NULL
 1006 #endif /* SYSCTL_INCLUDE_DESCR */
 1007 
 1008 /*
 1009  * simple interface similar to old interface for in-kernel consumption
 1010  */
 1011 int     old_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct lwp *);
 1012 
 1013 /*
 1014  * these helpers are in other files (XXX so should the nodes be) or
 1015  * are used by more than one node
 1016  */
 1017 int     sysctl_hw_disknames(SYSCTLFN_PROTO);
 1018 int     sysctl_hw_diskstats(SYSCTLFN_PROTO);
 1019 int     sysctl_kern_vnode(SYSCTLFN_PROTO);
 1020 int     sysctl_net_inet_ip_ports(SYSCTLFN_PROTO);
 1021 int     sysctl_consdev(SYSCTLFN_PROTO);
 1022 int     sysctl_root_device(SYSCTLFN_PROTO);
 1023 
 1024 /*
 1025  * primitive helper stubs
 1026  */
 1027 int     sysctl_needfunc(SYSCTLFN_PROTO);
 1028 int     sysctl_notavail(SYSCTLFN_PROTO);
 1029 int     sysctl_null(SYSCTLFN_PROTO);
 1030 
 1031 MALLOC_DECLARE(M_SYSCTLNODE);
 1032 MALLOC_DECLARE(M_SYSCTLDATA);
 1033 
 1034 #else   /* !_KERNEL */
 1035 #include <sys/cdefs.h>
 1036 
 1037 typedef void *sysctlfn;
 1038 
 1039 __BEGIN_DECLS
 1040 int     sysctl __P((int *, u_int, void *, size_t *, const void *, size_t));
 1041 int     sysctlbyname __P((const char *, void *, size_t *, void *, size_t));
 1042 int     sysctlgetmibinfo __P((const char *, int *, u_int *,
 1043                               char *, size_t *, struct sysctlnode **, int));
 1044 int     sysctlnametomib __P((const char *, int *, size_t *));
 1045 __END_DECLS
 1046 
 1047 #endif  /* !_KERNEL */
 1048 
 1049 #ifdef __COMPAT_SYSCTL
 1050 /*
 1051  * old node definitions go here
 1052  */
 1053 #endif /* __COMPAT_SYSCTL */
 1054 
 1055 /*
 1056  * padding makes alignment magically "work" for 32/64 compatibility at
 1057  * the expense of making things bigger on 32 bit platforms.
 1058  */
 1059 #if defined(_LP64) || (BYTE_ORDER == LITTLE_ENDIAN)
 1060 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
 1061         struct { type __sysc_sdatum; } __sysc_ustr; }
 1062 #else
 1063 #define __sysc_pad(type) union { uint64_t __sysc_upad; \
 1064         struct { uint32_t __sysc_spad; type __sysc_sdatum; } __sysc_ustr; }
 1065 #endif
 1066 #define __sysc_unpad(x) x.__sysc_ustr.__sysc_sdatum
 1067 
 1068 /*
 1069  * The following is for gcc2, which doesn't handle __sysc_unpad().
 1070  * The code gets a little less ugly this way.
 1071  */
 1072 #define sysc_init_field(field, value)   \
 1073         .field = { .__sysc_ustr = { .__sysc_sdatum = (value), }, }
 1074 
 1075 struct sysctlnode {
 1076         uint32_t sysctl_flags;          /* flags and type */
 1077         int32_t sysctl_num;             /* mib number */
 1078         char sysctl_name[SYSCTL_NAMELEN]; /* node name */
 1079         uint32_t sysctl_ver;            /* node's version vs. rest of tree */
 1080         uint32_t __rsvd;
 1081         union {
 1082                 struct {
 1083                         uint32_t suc_csize;     /* size of child node array */
 1084                         uint32_t suc_clen;      /* number of valid children */
 1085                         __sysc_pad(struct sysctlnode*) _suc_child; /* array of child nodes */
 1086                 } scu_child;
 1087                 struct {
 1088                         __sysc_pad(void*) _sud_data; /* pointer to external data */
 1089                         __sysc_pad(size_t) _sud_offset; /* offset to data */
 1090                 } scu_data;
 1091                 int32_t scu_alias;              /* node this node refers to */
 1092                 int32_t scu_idata;              /* immediate "int" data */
 1093                 u_quad_t scu_qdata;             /* immediate "u_quad_t" data */
 1094         } sysctl_un;
 1095         __sysc_pad(size_t) _sysctl_size;        /* size of instrumented data */
 1096         __sysc_pad(sysctlfn) _sysctl_func;      /* access helper function */
 1097         __sysc_pad(struct sysctlnode*) _sysctl_parent; /* parent of this node */
 1098         __sysc_pad(const char *) _sysctl_desc;  /* description of node */
 1099 };
 1100 
 1101 /*
 1102  * padded data
 1103  */
 1104 #define suc_child       __sysc_unpad(_suc_child)
 1105 #define sud_data        __sysc_unpad(_sud_data)
 1106 #define sud_offset      __sysc_unpad(_sud_offset)
 1107 #define sysctl_size     __sysc_unpad(_sysctl_size)
 1108 #define sysctl_func     __sysc_unpad(_sysctl_func)
 1109 #define sysctl_parent   __sysc_unpad(_sysctl_parent)
 1110 #define sysctl_desc     __sysc_unpad(_sysctl_desc)
 1111 
 1112 /*
 1113  * nested data (may also be padded)
 1114  */
 1115 #define sysctl_csize    sysctl_un.scu_child.suc_csize
 1116 #define sysctl_clen     sysctl_un.scu_child.suc_clen
 1117 #define sysctl_child    sysctl_un.scu_child.suc_child
 1118 #define sysctl_data     sysctl_un.scu_data.sud_data
 1119 #define sysctl_offset   sysctl_un.scu_data.sud_offset
 1120 #define sysctl_alias    sysctl_un.scu_alias
 1121 #define sysctl_idata    sysctl_un.scu_idata
 1122 #define sysctl_qdata    sysctl_un.scu_qdata
 1123 
 1124 /*
 1125  * when requesting a description of a node (a set of nodes, actually),
 1126  * you get back an "array" of these, where the actual length of the
 1127  * descr_str is noted in descr_len (which includes the trailing nul
 1128  * byte), rounded up to the nearest four (sizeof(int32_t) actually).
 1129  *
 1130  * NEXT_DESCR() will take a pointer to a description and advance it to
 1131  * the next description.
 1132  */
 1133 struct sysctldesc {
 1134         int32_t         descr_num;      /* mib number of node */
 1135         uint32_t        descr_ver;      /* version of node */
 1136         uint32_t        descr_len;      /* length of description string */
 1137         char            descr_str[1];   /* not really 1...see above */
 1138 };
 1139 
 1140 #define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
 1141 #define __sysc_desc_adv(d, l) \
 1142         (/*LINTED ptr cast*/(struct sysctldesc *) \
 1143         (((const char*)(d)) + offsetof(struct sysctldesc, descr_str) + \
 1144                 __sysc_desc_roundup(l)))
 1145 #define NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
 1146 
 1147 static __inline struct sysctlnode *
 1148 sysctl_rootof(struct sysctlnode *n)
 1149 {
 1150         while (n->sysctl_parent != NULL)
 1151                 n = n->sysctl_parent;
 1152         return (n);
 1153 }
 1154 
 1155 #endif  /* !_SYS_SYSCTL_H_ */

Cache object: bd1f37e4e53022939f5f2bba692a355e


[ 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.