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

Cache object: 8fbe25a991035f79e4c9de5c8fa4971a


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