Home | History | Annotate | Line # | Download | only in kern
      1  1.228  christos /*	$NetBSD: init_sysctl.c,v 1.228 2023/09/09 16:01:09 christos Exp $ */
      2    1.1    atatat 
      3    1.1    atatat /*-
      4  1.164        ad  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
      5    1.1    atatat  * All rights reserved.
      6    1.1    atatat  *
      7    1.1    atatat  * This code is derived from software contributed to The NetBSD Foundation
      8  1.118        ad  * by Andrew Brown, and by Andrew Doran.
      9    1.1    atatat  *
     10    1.1    atatat  * Redistribution and use in source and binary forms, with or without
     11    1.1    atatat  * modification, are permitted provided that the following conditions
     12    1.1    atatat  * are met:
     13    1.1    atatat  * 1. Redistributions of source code must retain the above copyright
     14    1.1    atatat  *    notice, this list of conditions and the following disclaimer.
     15    1.1    atatat  * 2. Redistributions in binary form must reproduce the above copyright
     16    1.1    atatat  *    notice, this list of conditions and the following disclaimer in the
     17    1.1    atatat  *    documentation and/or other materials provided with the distribution.
     18    1.1    atatat  *
     19    1.1    atatat  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20    1.1    atatat  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21    1.1    atatat  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22    1.1    atatat  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23    1.1    atatat  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24    1.1    atatat  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25    1.1    atatat  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26    1.1    atatat  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27    1.1    atatat  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28    1.1    atatat  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29    1.1    atatat  * POSSIBILITY OF SUCH DAMAGE.
     30    1.1    atatat  */
     31    1.1    atatat 
     32   1.16    atatat #include <sys/cdefs.h>
     33  1.228  christos __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.228 2023/09/09 16:01:09 christos Exp $");
     34   1.16    atatat 
     35    1.1    atatat #include "opt_sysv.h"
     36  1.153  christos #include "opt_compat_netbsd.h"
     37  1.156       apb #include "opt_modular.h"
     38  1.214      maxv #include "opt_gprof.h"
     39    1.1    atatat #include "pty.h"
     40    1.1    atatat 
     41  1.227     skrll #include <sys/param.h>
     42    1.1    atatat #include <sys/types.h>
     43  1.227     skrll 
     44  1.227     skrll #include <dev/cons.h>
     45  1.227     skrll #include <sys/conf.h>
     46  1.227     skrll #include <sys/cprng.h>
     47  1.104      yamt #include <sys/cpu.h>
     48  1.227     skrll #include <sys/device.h>
     49  1.227     skrll #include <sys/disklabel.h>
     50    1.1    atatat #include <sys/errno.h>
     51  1.227     skrll #include <sys/exec.h>
     52  1.227     skrll #include <sys/filedesc.h>
     53  1.227     skrll #include <sys/file.h>
     54  1.227     skrll #include <sys/kauth.h>
     55    1.1    atatat #include <sys/kernel.h>
     56  1.227     skrll #include <sys/kmem.h>
     57  1.227     skrll #include <sys/ktrace.h>
     58    1.1    atatat #include <sys/mount.h>
     59    1.1    atatat #include <sys/namei.h>
     60  1.211  pgoyette #include <sys/reboot.h>
     61    1.1    atatat #include <sys/resource.h>
     62    1.1    atatat #include <sys/resourcevar.h>
     63  1.227     skrll #include <sys/socketvar.h>
     64   1.61      elad #include <sys/stat.h>
     65  1.227     skrll #include <sys/sysctl.h>
     66  1.227     skrll #include <sys/systm.h>
     67  1.227     skrll #include <sys/tty.h>
     68  1.227     skrll #include <sys/unistd.h>
     69  1.227     skrll #include <sys/vnode_impl.h>     /* For vfs_drainvnodes(). */
     70    1.1    atatat 
     71   1.61      elad int security_setidcore_dump;
     72   1.61      elad char security_setidcore_path[MAXPATHLEN] = "/var/crash/%n.core";
     73   1.61      elad uid_t security_setidcore_owner = 0;
     74   1.61      elad gid_t security_setidcore_group = 0;
     75   1.61      elad mode_t security_setidcore_mode = (S_IRUSR|S_IWUSR);
     76   1.54      elad 
     77  1.206  pgoyette /*
     78  1.206  pgoyette  * Current status of SysV IPC capability.  Initially, these are
     79  1.206  pgoyette  * 0 if the capability is not built-in to the kernel, but can
     80  1.206  pgoyette  * be updated if the appropriate kernel module is (auto)loaded.
     81  1.206  pgoyette  */
     82  1.206  pgoyette 
     83  1.206  pgoyette int kern_has_sysvmsg = 0;
     84  1.206  pgoyette int kern_has_sysvshm = 0;
     85  1.206  pgoyette int kern_has_sysvsem = 0;
     86  1.206  pgoyette 
     87   1.95        ad static const u_int sysctl_lwpprflagmap[] = {
     88   1.97     pavel 	LPR_DETACHED, L_DETACHED,
     89   1.95        ad 	0
     90   1.95        ad };
     91   1.95        ad 
     92    1.1    atatat /*
     93    1.1    atatat  * try over estimating by 5 procs/lwps
     94    1.1    atatat  */
     95    1.1    atatat #define KERN_LWPSLOP	(5 * sizeof(struct kinfo_lwp))
     96    1.1    atatat 
     97  1.105        ad static int dcopyout(struct lwp *, const void *, void *, size_t);
     98   1.86      manu 
     99  1.105        ad static int
    100  1.123      matt dcopyout(struct lwp *l, const void *kaddr, void *uaddr, size_t len)
    101   1.86      manu {
    102   1.86      manu 	int error;
    103   1.86      manu 
    104   1.86      manu 	error = copyout(kaddr, uaddr, len);
    105  1.105        ad 	ktrmibio(-1, UIO_READ, uaddr, len, error);
    106   1.86      manu 
    107   1.86      manu 	return error;
    108   1.86      manu }
    109   1.96        ad 
    110    1.1    atatat static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
    111  1.211  pgoyette static int sysctl_kern_messages(SYSCTLFN_PROTO);
    112  1.223   thorpej static int sysctl_kern_boottime(SYSCTLFN_PROTO);
    113   1.14    martin static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
    114    1.1    atatat static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
    115    1.1    atatat static int sysctl_kern_hostid(SYSCTLFN_PROTO);
    116    1.1    atatat static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
    117    1.1    atatat static int sysctl_kern_cptime(SYSCTLFN_PROTO);
    118    1.6        he #if NPTY > 0
    119    1.1    atatat static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
    120    1.6        he #endif /* NPTY > 0 */
    121    1.1    atatat static int sysctl_kern_lwp(SYSCTLFN_PROTO);
    122    1.1    atatat static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
    123    1.1    atatat static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
    124    1.1    atatat static int sysctl_kern_drivers(SYSCTLFN_PROTO);
    125   1.61      elad static int sysctl_security_setidcore(SYSCTLFN_PROTO);
    126   1.61      elad static int sysctl_security_setidcorename(SYSCTLFN_PROTO);
    127   1.45  christos static int sysctl_kern_cpid(SYSCTLFN_PROTO);
    128    1.1    atatat static int sysctl_hw_usermem(SYSCTLFN_PROTO);
    129    1.1    atatat static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
    130    1.1    atatat 
    131    1.1    atatat static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
    132    1.1    atatat 
    133    1.1    atatat /*
    134    1.1    atatat  * ********************************************************************
    135    1.1    atatat  * section 1: setup routines
    136    1.1    atatat  * ********************************************************************
    137  1.110  christos  * These functions are stuffed into a link set for sysctl setup
    138  1.110  christos  * functions. They're never called or referenced from anywhere else.
    139    1.1    atatat  * ********************************************************************
    140    1.1    atatat  */
    141    1.1    atatat 
    142    1.1    atatat /*
    143    1.1    atatat  * this setup routine is a replacement for kern_sysctl()
    144    1.1    atatat  */
    145    1.1    atatat SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
    146    1.1    atatat {
    147    1.1    atatat 	extern int kern_logsigexit;	/* defined in kern/kern_sig.c */
    148    1.1    atatat 	extern fixpt_t ccpu;		/* defined in kern/kern_synch.c */
    149    1.1    atatat 	extern int dumponpanic;		/* defined in kern/subr_prf.c */
    150   1.75      elad 	const struct sysctlnode *rnode;
    151    1.1    atatat 
    152   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    153   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    154   1.26    atatat 		       CTLTYPE_INT, "maxvnodes",
    155   1.26    atatat 		       SYSCTL_DESCR("Maximum number of vnodes"),
    156    1.1    atatat 		       sysctl_kern_maxvnodes, 0, NULL, 0,
    157    1.1    atatat 		       CTL_KERN, KERN_MAXVNODES, CTL_EOL);
    158   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    159   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    160   1.26    atatat 		       CTLTYPE_INT, "maxproc",
    161   1.26    atatat 		       SYSCTL_DESCR("Maximum number of simultaneous processes"),
    162    1.1    atatat 		       sysctl_kern_maxproc, 0, NULL, 0,
    163    1.1    atatat 		       CTL_KERN, KERN_MAXPROC, CTL_EOL);
    164   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    165   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    166   1.26    atatat 		       CTLTYPE_INT, "maxfiles",
    167   1.26    atatat 		       SYSCTL_DESCR("Maximum number of open files"),
    168    1.1    atatat 		       NULL, 0, &maxfiles, 0,
    169    1.1    atatat 		       CTL_KERN, KERN_MAXFILES, CTL_EOL);
    170   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    171   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    172   1.26    atatat 		       CTLTYPE_INT, "argmax",
    173   1.26    atatat 		       SYSCTL_DESCR("Maximum number of bytes of arguments to "
    174   1.26    atatat 				    "execve(2)"),
    175    1.1    atatat 		       NULL, ARG_MAX, NULL, 0,
    176    1.1    atatat 		       CTL_KERN, KERN_ARGMAX, CTL_EOL);
    177   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    178   1.27    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
    179   1.26    atatat 		       CTLTYPE_INT, "hostid",
    180   1.26    atatat 		       SYSCTL_DESCR("System host ID number"),
    181    1.1    atatat 		       sysctl_kern_hostid, 0, NULL, 0,
    182    1.1    atatat 		       CTL_KERN, KERN_HOSTID, CTL_EOL);
    183   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    184   1.24    atatat 		       CTLFLAG_PERMANENT,
    185   1.26    atatat 		       CTLTYPE_STRUCT, "vnode",
    186   1.26    atatat 		       SYSCTL_DESCR("System vnode table"),
    187    1.1    atatat 		       sysctl_kern_vnode, 0, NULL, 0,
    188    1.1    atatat 		       CTL_KERN, KERN_VNODE, CTL_EOL);
    189    1.1    atatat #ifndef GPROF
    190   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    191   1.24    atatat 		       CTLFLAG_PERMANENT,
    192   1.26    atatat 		       CTLTYPE_NODE, "profiling",
    193   1.26    atatat 		       SYSCTL_DESCR("Profiling information (not available)"),
    194    1.1    atatat 		       sysctl_notavail, 0, NULL, 0,
    195    1.1    atatat 		       CTL_KERN, KERN_PROF, CTL_EOL);
    196    1.1    atatat #endif
    197   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    198   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    199   1.26    atatat 		       CTLTYPE_INT, "posix1version",
    200   1.26    atatat 		       SYSCTL_DESCR("Version of ISO/IEC 9945 (POSIX 1003.1) "
    201   1.26    atatat 				    "with which the operating system attempts "
    202   1.26    atatat 				    "to comply"),
    203    1.1    atatat 		       NULL, _POSIX_VERSION, NULL, 0,
    204    1.1    atatat 		       CTL_KERN, KERN_POSIX1, CTL_EOL);
    205   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    206   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    207   1.26    atatat 		       CTLTYPE_INT, "ngroups",
    208   1.26    atatat 		       SYSCTL_DESCR("Maximum number of supplemental groups"),
    209    1.1    atatat 		       NULL, NGROUPS_MAX, NULL, 0,
    210    1.1    atatat 		       CTL_KERN, KERN_NGROUPS, CTL_EOL);
    211   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    212   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    213   1.26    atatat 		       CTLTYPE_INT, "job_control",
    214   1.26    atatat 		       SYSCTL_DESCR("Whether job control is available"),
    215    1.1    atatat 		       NULL, 1, NULL, 0,
    216    1.1    atatat 		       CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
    217   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    218   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    219   1.26    atatat 		       CTLTYPE_INT, "saved_ids",
    220   1.37       mrg 		       SYSCTL_DESCR("Whether POSIX saved set-group/user ID is "
    221   1.26    atatat 				    "available"), NULL,
    222    1.1    atatat #ifdef _POSIX_SAVED_IDS
    223    1.1    atatat 		       1,
    224    1.1    atatat #else /* _POSIX_SAVED_IDS */
    225    1.1    atatat 		       0,
    226    1.1    atatat #endif /* _POSIX_SAVED_IDS */
    227    1.1    atatat 		       NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
    228   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    229  1.166       apb 		       CTLFLAG_PERMANENT|CTLFLAG_HEX,
    230  1.166       apb 		       CTLTYPE_INT, "boothowto",
    231  1.166       apb 		       SYSCTL_DESCR("Flags from boot loader"),
    232  1.166       apb 		       NULL, 0, &boothowto, sizeof(boothowto),
    233  1.166       apb 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    234  1.166       apb 	sysctl_createv(clog, 0, NULL, NULL,
    235   1.24    atatat 		       CTLFLAG_PERMANENT,
    236   1.26    atatat 		       CTLTYPE_STRUCT, "boottime",
    237   1.26    atatat 		       SYSCTL_DESCR("System boot time"),
    238  1.223   thorpej 		       sysctl_kern_boottime, 0, NULL, sizeof(struct timespec),
    239    1.1    atatat 		       CTL_KERN, KERN_BOOTTIME, CTL_EOL);
    240   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    241   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    242   1.26    atatat 		       CTLTYPE_INT, "maxpartitions",
    243   1.26    atatat 		       SYSCTL_DESCR("Maximum number of partitions allowed per "
    244   1.26    atatat 				    "disk"),
    245    1.1    atatat 		       NULL, MAXPARTITIONS, NULL, 0,
    246    1.1    atatat 		       CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
    247   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    248   1.24    atatat 		       CTLFLAG_PERMANENT,
    249    1.1    atatat 		       CTLTYPE_STRUCT, "timex", NULL,
    250    1.1    atatat 		       sysctl_notavail, 0, NULL, 0,
    251    1.1    atatat 		       CTL_KERN, KERN_TIMEX, CTL_EOL);
    252   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    253   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    254   1.26    atatat 		       CTLTYPE_INT, "rtc_offset",
    255   1.26    atatat 		       SYSCTL_DESCR("Offset of real time clock from UTC in "
    256   1.26    atatat 				    "minutes"),
    257   1.14    martin 		       sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
    258    1.1    atatat 		       CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
    259   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    260   1.24    atatat 		       CTLFLAG_PERMANENT,
    261   1.26    atatat 		       CTLTYPE_STRING, "root_device",
    262   1.26    atatat 		       SYSCTL_DESCR("Name of the root device"),
    263    1.1    atatat 		       sysctl_root_device, 0, NULL, 0,
    264    1.1    atatat 		       CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
    265   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    266   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    267   1.26    atatat 		       CTLTYPE_INT, "fsync",
    268   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b File "
    269   1.26    atatat 				    "Synchronization Option is available on "
    270   1.26    atatat 				    "this system"),
    271    1.1    atatat 		       NULL, 1, NULL, 0,
    272    1.1    atatat 		       CTL_KERN, KERN_FSYNC, CTL_EOL);
    273   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    274   1.92  christos 		       CTLFLAG_PERMANENT,
    275   1.92  christos 		       CTLTYPE_NODE, "ipc",
    276   1.92  christos 		       SYSCTL_DESCR("SysV IPC options"),
    277   1.92  christos 		       NULL, 0, NULL, 0,
    278   1.92  christos 		       CTL_KERN, KERN_SYSVIPC, CTL_EOL);
    279   1.92  christos 	sysctl_createv(clog, 0, NULL, NULL,
    280  1.206  pgoyette 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    281   1.26    atatat 		       CTLTYPE_INT, "sysvmsg",
    282   1.26    atatat 		       SYSCTL_DESCR("System V style message support available"),
    283  1.206  pgoyette 		       NULL, 0, &kern_has_sysvmsg, sizeof(int),
    284  1.206  pgoyette 		       CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, CTL_EOL);
    285   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    286  1.206  pgoyette 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    287   1.26    atatat 		       CTLTYPE_INT, "sysvsem",
    288   1.26    atatat 		       SYSCTL_DESCR("System V style semaphore support "
    289  1.206  pgoyette 				    "available"),
    290  1.206  pgoyette 		       NULL, 0, &kern_has_sysvsem, sizeof(int),
    291  1.206  pgoyette 		       CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
    292   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    293  1.206  pgoyette 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    294   1.26    atatat 		       CTLTYPE_INT, "sysvshm",
    295   1.26    atatat 		       SYSCTL_DESCR("System V style shared memory support "
    296  1.206  pgoyette 				    "available"),
    297  1.206  pgoyette 		       NULL, 0, &kern_has_sysvshm, sizeof(int),
    298  1.206  pgoyette 		       CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
    299   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    300   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    301   1.26    atatat 		       CTLTYPE_INT, "synchronized_io",
    302   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Synchronized "
    303   1.26    atatat 				    "I/O Option is available on this system"),
    304    1.1    atatat 		       NULL, 1, NULL, 0,
    305    1.1    atatat 		       CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
    306   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    307   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    308   1.26    atatat 		       CTLTYPE_INT, "iov_max",
    309   1.26    atatat 		       SYSCTL_DESCR("Maximum number of iovec structures per "
    310   1.26    atatat 				    "process"),
    311    1.1    atatat 		       NULL, IOV_MAX, NULL, 0,
    312    1.1    atatat 		       CTL_KERN, KERN_IOV_MAX, CTL_EOL);
    313   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    314   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    315   1.26    atatat 		       CTLTYPE_INT, "mapped_files",
    316   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Memory Mapped "
    317   1.26    atatat 				    "Files Option is available on this system"),
    318    1.1    atatat 		       NULL, 1, NULL, 0,
    319    1.1    atatat 		       CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
    320   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    321   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    322   1.26    atatat 		       CTLTYPE_INT, "memlock",
    323   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Process Memory "
    324   1.26    atatat 				    "Locking Option is available on this "
    325   1.26    atatat 				    "system"),
    326    1.1    atatat 		       NULL, 1, NULL, 0,
    327    1.1    atatat 		       CTL_KERN, KERN_MEMLOCK, CTL_EOL);
    328   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    329   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    330   1.26    atatat 		       CTLTYPE_INT, "memlock_range",
    331   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Range Memory "
    332   1.26    atatat 				    "Locking Option is available on this "
    333   1.26    atatat 				    "system"),
    334    1.1    atatat 		       NULL, 1, NULL, 0,
    335    1.1    atatat 		       CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
    336   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    337   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    338   1.26    atatat 		       CTLTYPE_INT, "memory_protection",
    339   1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Memory "
    340   1.26    atatat 				    "Protection Option is available on this "
    341   1.26    atatat 				    "system"),
    342    1.1    atatat 		       NULL, 1, NULL, 0,
    343    1.1    atatat 		       CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
    344   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    345   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    346   1.26    atatat 		       CTLTYPE_INT, "login_name_max",
    347   1.26    atatat 		       SYSCTL_DESCR("Maximum login name length"),
    348    1.1    atatat 		       NULL, LOGIN_NAME_MAX, NULL, 0,
    349    1.1    atatat 		       CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
    350   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    351   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    352   1.26    atatat 		       CTLTYPE_STRING, "defcorename",
    353   1.26    atatat 		       SYSCTL_DESCR("Default core file name"),
    354    1.1    atatat 		       sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
    355    1.1    atatat 		       CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
    356   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    357   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    358   1.26    atatat 		       CTLTYPE_INT, "logsigexit",
    359   1.26    atatat 		       SYSCTL_DESCR("Log process exit when caused by signals"),
    360    1.1    atatat 		       NULL, 0, &kern_logsigexit, 0,
    361    1.1    atatat 		       CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
    362   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    363   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    364   1.26    atatat 		       CTLTYPE_INT, "fscale",
    365   1.26    atatat 		       SYSCTL_DESCR("Kernel fixed-point scale factor"),
    366    1.1    atatat 		       NULL, FSCALE, NULL, 0,
    367    1.1    atatat 		       CTL_KERN, KERN_FSCALE, CTL_EOL);
    368   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    369   1.24    atatat 		       CTLFLAG_PERMANENT,
    370   1.26    atatat 		       CTLTYPE_INT, "ccpu",
    371   1.26    atatat 		       SYSCTL_DESCR("Scheduler exponential decay value"),
    372    1.1    atatat 		       NULL, 0, &ccpu, 0,
    373    1.1    atatat 		       CTL_KERN, KERN_CCPU, CTL_EOL);
    374   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    375   1.24    atatat 		       CTLFLAG_PERMANENT,
    376   1.26    atatat 		       CTLTYPE_STRUCT, "cp_time",
    377   1.26    atatat 		       SYSCTL_DESCR("Clock ticks spent in different CPU states"),
    378    1.1    atatat 		       sysctl_kern_cptime, 0, NULL, 0,
    379    1.1    atatat 		       CTL_KERN, KERN_CP_TIME, CTL_EOL);
    380   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    381   1.24    atatat 		       CTLFLAG_PERMANENT,
    382   1.26    atatat 		       CTLTYPE_STRUCT, "consdev",
    383   1.26    atatat 		       SYSCTL_DESCR("Console device"),
    384    1.1    atatat 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    385    1.1    atatat 		       CTL_KERN, KERN_CONSDEV, CTL_EOL);
    386    1.1    atatat #if NPTY > 0
    387   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    388   1.24    atatat 		       CTLFLAG_PERMANENT,
    389   1.26    atatat 		       CTLTYPE_INT, "maxptys",
    390   1.26    atatat 		       SYSCTL_DESCR("Maximum number of pseudo-ttys"),
    391    1.1    atatat 		       sysctl_kern_maxptys, 0, NULL, 0,
    392    1.1    atatat 		       CTL_KERN, KERN_MAXPTYS, CTL_EOL);
    393    1.1    atatat #endif /* NPTY > 0 */
    394   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    395   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    396   1.26    atatat 		       CTLTYPE_INT, "maxphys",
    397   1.26    atatat 		       SYSCTL_DESCR("Maximum raw I/O transfer size"),
    398    1.1    atatat 		       NULL, MAXPHYS, NULL, 0,
    399    1.1    atatat 		       CTL_KERN, KERN_MAXPHYS, CTL_EOL);
    400   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    401   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    402   1.26    atatat 		       CTLTYPE_INT, "monotonic_clock",
    403   1.26    atatat 		       SYSCTL_DESCR("Implementation version of the POSIX "
    404   1.26    atatat 				    "1003.1b Monotonic Clock Option"),
    405    1.1    atatat 		       /* XXX _POSIX_VERSION */
    406    1.1    atatat 		       NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
    407    1.1    atatat 		       CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
    408   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    409   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    410   1.26    atatat 		       CTLTYPE_INT, "labelsector",
    411   1.26    atatat 		       SYSCTL_DESCR("Sector number containing the disklabel"),
    412    1.1    atatat 		       NULL, LABELSECTOR, NULL, 0,
    413    1.1    atatat 		       CTL_KERN, KERN_LABELSECTOR, CTL_EOL);
    414   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    415   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    416   1.26    atatat 		       CTLTYPE_INT, "labeloffset",
    417   1.26    atatat 		       SYSCTL_DESCR("Offset of the disklabel within the "
    418   1.26    atatat 				    "sector"),
    419    1.1    atatat 		       NULL, LABELOFFSET, NULL, 0,
    420    1.1    atatat 		       CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
    421   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    422  1.183    bouyer 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    423  1.183    bouyer 		       CTLTYPE_INT, "labelusesmbr",
    424  1.183    bouyer 		       SYSCTL_DESCR("disklabel is inside MBR partition"),
    425  1.183    bouyer 		       NULL, LABELUSESMBR, NULL, 0,
    426  1.183    bouyer 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    427  1.183    bouyer 	sysctl_createv(clog, 0, NULL, NULL,
    428   1.24    atatat 		       CTLFLAG_PERMANENT,
    429   1.26    atatat 		       CTLTYPE_NODE, "lwp",
    430   1.26    atatat 		       SYSCTL_DESCR("System-wide LWP information"),
    431    1.1    atatat 		       sysctl_kern_lwp, 0, NULL, 0,
    432    1.1    atatat 		       CTL_KERN, KERN_LWP, CTL_EOL);
    433   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    434   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    435   1.26    atatat 		       CTLTYPE_INT, "forkfsleep",
    436   1.26    atatat 		       SYSCTL_DESCR("Milliseconds to sleep on fork failure due "
    437   1.26    atatat 				    "to process limits"),
    438    1.1    atatat 		       sysctl_kern_forkfsleep, 0, NULL, 0,
    439    1.1    atatat 		       CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
    440   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    441   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    442   1.26    atatat 		       CTLTYPE_INT, "posix_threads",
    443   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    444   1.26    atatat 				    "Threads option to which the system "
    445   1.26    atatat 				    "attempts to conform"),
    446    1.1    atatat 		       /* XXX _POSIX_VERSION */
    447    1.1    atatat 		       NULL, _POSIX_THREADS, NULL, 0,
    448    1.1    atatat 		       CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
    449   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    450  1.188     joerg 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    451   1.26    atatat 		       CTLTYPE_INT, "posix_semaphores",
    452   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    453   1.26    atatat 				    "Semaphores option to which the system "
    454   1.26    atatat 				    "attempts to conform"), NULL,
    455  1.188     joerg 		       200112, NULL, 0,
    456  1.188     joerg 		       CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
    457   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    458   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    459   1.26    atatat 		       CTLTYPE_INT, "posix_barriers",
    460   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    461   1.26    atatat 				    "Barriers option to which the system "
    462   1.26    atatat 				    "attempts to conform"),
    463    1.1    atatat 		       /* XXX _POSIX_VERSION */
    464    1.1    atatat 		       NULL, _POSIX_BARRIERS, NULL, 0,
    465    1.1    atatat 		       CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
    466   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    467   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    468   1.26    atatat 		       CTLTYPE_INT, "posix_timers",
    469   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    470   1.26    atatat 				    "Timers option to which the system "
    471   1.26    atatat 				    "attempts to conform"),
    472    1.1    atatat 		       /* XXX _POSIX_VERSION */
    473    1.1    atatat 		       NULL, _POSIX_TIMERS, NULL, 0,
    474    1.1    atatat 		       CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
    475   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    476   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    477   1.26    atatat 		       CTLTYPE_INT, "posix_spin_locks",
    478   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
    479   1.26    atatat 				    "Locks option to which the system attempts "
    480   1.26    atatat 				    "to conform"),
    481    1.1    atatat 		       /* XXX _POSIX_VERSION */
    482    1.1    atatat 		       NULL, _POSIX_SPIN_LOCKS, NULL, 0,
    483    1.1    atatat 		       CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
    484   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    485   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    486   1.26    atatat 		       CTLTYPE_INT, "posix_reader_writer_locks",
    487   1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    488   1.26    atatat 				    "Read-Write Locks option to which the "
    489   1.26    atatat 				    "system attempts to conform"),
    490    1.1    atatat 		       /* XXX _POSIX_VERSION */
    491    1.1    atatat 		       NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
    492    1.1    atatat 		       CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
    493   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    494   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    495   1.26    atatat 		       CTLTYPE_INT, "dump_on_panic",
    496   1.26    atatat 		       SYSCTL_DESCR("Perform a crash dump on system panic"),
    497    1.1    atatat 		       NULL, 0, &dumponpanic, 0,
    498    1.1    atatat 		       CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
    499   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    500   1.24    atatat 		       CTLFLAG_PERMANENT,
    501   1.26    atatat 		       CTLTYPE_INT, "root_partition",
    502   1.26    atatat 		       SYSCTL_DESCR("Root partition on the root device"),
    503    1.1    atatat 		       sysctl_kern_root_partition, 0, NULL, 0,
    504    1.1    atatat 		       CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
    505   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    506   1.24    atatat 		       CTLFLAG_PERMANENT,
    507   1.26    atatat 		       CTLTYPE_STRUCT, "drivers",
    508   1.26    atatat 		       SYSCTL_DESCR("List of all drivers with block and "
    509   1.26    atatat 				    "character device numbers"),
    510    1.1    atatat 		       sysctl_kern_drivers, 0, NULL, 0,
    511    1.1    atatat 		       CTL_KERN, KERN_DRIVERS, CTL_EOL);
    512   1.34    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    513   1.34    atatat 		       CTLFLAG_PERMANENT,
    514   1.45  christos 		       CTLTYPE_STRUCT, "cp_id",
    515   1.45  christos 		       SYSCTL_DESCR("Mapping of CPU number to CPU id"),
    516   1.45  christos 		       sysctl_kern_cpid, 0, NULL, 0,
    517   1.45  christos 		       CTL_KERN, KERN_CP_ID, CTL_EOL);
    518   1.75      elad 	sysctl_createv(clog, 0, NULL, &rnode,
    519   1.75      elad 		       CTLFLAG_PERMANENT,
    520   1.75      elad 		       CTLTYPE_NODE, "coredump",
    521   1.75      elad 		       SYSCTL_DESCR("Coredump settings."),
    522   1.75      elad 		       NULL, 0, NULL, 0,
    523   1.75      elad 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    524   1.75      elad 	sysctl_createv(clog, 0, &rnode, &rnode,
    525   1.75      elad 		       CTLFLAG_PERMANENT,
    526   1.75      elad 		       CTLTYPE_NODE, "setid",
    527   1.75      elad 		       SYSCTL_DESCR("Set-id processes' coredump settings."),
    528   1.75      elad 		       NULL, 0, NULL, 0,
    529   1.75      elad 		       CTL_CREATE, CTL_EOL);
    530   1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    531   1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    532   1.75      elad 		       CTLTYPE_INT, "dump",
    533   1.75      elad 		       SYSCTL_DESCR("Allow set-id processes to dump core."),
    534   1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_dump,
    535   1.75      elad 		       sizeof(security_setidcore_dump),
    536   1.75      elad 		       CTL_CREATE, CTL_EOL);
    537   1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    538   1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    539   1.75      elad 		       CTLTYPE_STRING, "path",
    540   1.75      elad 		       SYSCTL_DESCR("Path pattern for set-id coredumps."),
    541   1.75      elad 		       sysctl_security_setidcorename, 0,
    542  1.190       dsl 		       security_setidcore_path,
    543   1.75      elad 		       sizeof(security_setidcore_path),
    544   1.75      elad 		       CTL_CREATE, CTL_EOL);
    545   1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    546   1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    547   1.75      elad 		       CTLTYPE_INT, "owner",
    548   1.75      elad 		       SYSCTL_DESCR("Owner id for set-id processes' cores."),
    549   1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_owner,
    550   1.75      elad 		       0,
    551   1.75      elad 		       CTL_CREATE, CTL_EOL);
    552   1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    553   1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    554   1.75      elad 		       CTLTYPE_INT, "group",
    555   1.75      elad 		       SYSCTL_DESCR("Group id for set-id processes' cores."),
    556   1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_group,
    557   1.75      elad 		       0,
    558   1.75      elad 		       CTL_CREATE, CTL_EOL);
    559   1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    560   1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    561   1.75      elad 		       CTLTYPE_INT, "mode",
    562   1.75      elad 		       SYSCTL_DESCR("Mode for set-id processes' cores."),
    563   1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_mode,
    564   1.75      elad 		       0,
    565   1.75      elad 		       CTL_CREATE, CTL_EOL);
    566  1.145  wrstuden 	sysctl_createv(clog, 0, NULL, NULL,
    567  1.187     rmind 		       CTLFLAG_IMMEDIATE|CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    568  1.145  wrstuden 		       CTLTYPE_INT, "no_sa_support",
    569  1.179  christos 		       SYSCTL_DESCR("0 if the kernel supports SA, otherwise "
    570  1.179  christos 		       "it doesn't"),
    571  1.187     rmind 		       NULL, 1, NULL, 0,
    572  1.106     joerg 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    573  1.204       apb 	sysctl_createv(clog, 0, NULL, NULL,
    574  1.204       apb 			CTLFLAG_PERMANENT,
    575  1.204       apb 			CTLTYPE_STRING, "configname",
    576  1.204       apb 			SYSCTL_DESCR("Name of config file"),
    577  1.204       apb 			NULL, 0, __UNCONST(kernel_ident), 0,
    578  1.204       apb 			CTL_KERN, CTL_CREATE, CTL_EOL);
    579  1.204       apb 	sysctl_createv(clog, 0, NULL, NULL,
    580  1.204       apb 			CTLFLAG_PERMANENT,
    581  1.204       apb 			CTLTYPE_STRING, "buildinfo",
    582  1.204       apb 			SYSCTL_DESCR("Information from build environment"),
    583  1.204       apb 			NULL, 0, __UNCONST(buildinfo), 0,
    584  1.204       apb 			CTL_KERN, CTL_CREATE, CTL_EOL);
    585  1.211  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    586  1.211  pgoyette 			CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    587  1.211  pgoyette 			CTLTYPE_INT, "messages",
    588  1.211  pgoyette 			SYSCTL_DESCR("Kernel message verbosity"),
    589  1.211  pgoyette 			sysctl_kern_messages, 0, NULL, 0,
    590  1.211  pgoyette 			CTL_KERN, CTL_CREATE, CTL_EOL);
    591    1.1    atatat }
    592    1.1    atatat 
    593  1.209     pooka SYSCTL_SETUP(sysctl_hw_misc_setup, "sysctl hw subtree misc setup")
    594    1.1    atatat {
    595    1.1    atatat 
    596   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    597   1.24    atatat 		       CTLFLAG_PERMANENT,
    598   1.26    atatat 		       CTLTYPE_INT, "usermem",
    599   1.26    atatat 		       SYSCTL_DESCR("Bytes of non-kernel memory"),
    600    1.1    atatat 		       sysctl_hw_usermem, 0, NULL, 0,
    601    1.1    atatat 		       CTL_HW, HW_USERMEM, CTL_EOL);
    602   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    603   1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
    604   1.26    atatat 		       CTLTYPE_STRING, "cnmagic",
    605   1.26    atatat 		       SYSCTL_DESCR("Console magic key sequence"),
    606    1.1    atatat 		       sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
    607    1.1    atatat 		       CTL_HW, HW_CNMAGIC, CTL_EOL);
    608   1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    609   1.24    atatat 		       CTLFLAG_PERMANENT,
    610   1.26    atatat 		       CTLTYPE_QUAD, "usermem64",
    611   1.26    atatat 		       SYSCTL_DESCR("Bytes of non-kernel memory"),
    612    1.1    atatat 		       sysctl_hw_usermem, 0, NULL, 0,
    613    1.1    atatat 		       CTL_HW, HW_USERMEM64, CTL_EOL);
    614    1.1    atatat }
    615    1.1    atatat 
    616    1.1    atatat #ifdef DEBUG
    617    1.1    atatat /*
    618    1.1    atatat  * Debugging related system variables.
    619    1.1    atatat  */
    620    1.1    atatat struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
    621    1.1    atatat struct ctldebug debug5, debug6, debug7, debug8, debug9;
    622    1.1    atatat struct ctldebug debug10, debug11, debug12, debug13, debug14;
    623    1.1    atatat struct ctldebug debug15, debug16, debug17, debug18, debug19;
    624  1.217       mrg static struct ctldebug *debugvars[] = {
    625    1.1    atatat 	&debug0, &debug1, &debug2, &debug3, &debug4,
    626    1.1    atatat 	&debug5, &debug6, &debug7, &debug8, &debug9,
    627    1.1    atatat 	&debug10, &debug11, &debug12, &debug13, &debug14,
    628    1.1    atatat 	&debug15, &debug16, &debug17, &debug18, &debug19,
    629    1.1    atatat };
    630    1.1    atatat 
    631    1.1    atatat /*
    632    1.1    atatat  * this setup routine is a replacement for debug_sysctl()
    633    1.1    atatat  *
    634    1.1    atatat  * note that it creates several nodes per defined debug variable
    635    1.1    atatat  */
    636    1.1    atatat SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
    637    1.1    atatat {
    638    1.1    atatat 	struct ctldebug *cdp;
    639    1.1    atatat 	char nodename[20];
    640    1.1    atatat 	int i;
    641    1.1    atatat 
    642    1.1    atatat 	/*
    643    1.1    atatat 	 * two ways here:
    644    1.1    atatat 	 *
    645    1.1    atatat 	 * the "old" way (debug.name -> value) which was emulated by
    646    1.1    atatat 	 * the sysctl(8) binary
    647    1.1    atatat 	 *
    648    1.1    atatat 	 * the new way, which the sysctl(8) binary was actually using
    649    1.1    atatat 
    650    1.1    atatat 	 node	debug
    651    1.1    atatat 	 node	debug.0
    652  1.110  christos 	 string debug.0.name
    653    1.1    atatat 	 int	debug.0.value
    654    1.1    atatat 	 int	debug.name
    655    1.1    atatat 
    656    1.1    atatat 	 */
    657    1.1    atatat 
    658  1.217       mrg 	for (i = 0; i < __arraycount(debugvars); i++) {
    659    1.1    atatat 		cdp = debugvars[i];
    660    1.1    atatat 		if (cdp->debugname == NULL || cdp->debugvar == NULL)
    661    1.1    atatat 			continue;
    662    1.1    atatat 
    663    1.1    atatat 		snprintf(nodename, sizeof(nodename), "debug%d", i);
    664   1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
    665   1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
    666    1.1    atatat 			       CTLTYPE_NODE, nodename, NULL,
    667    1.1    atatat 			       NULL, 0, NULL, 0,
    668    1.1    atatat 			       CTL_DEBUG, i, CTL_EOL);
    669   1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
    670   1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
    671    1.1    atatat 			       CTLTYPE_STRING, "name", NULL,
    672   1.40  christos 			       /*XXXUNCONST*/
    673   1.40  christos 			       NULL, 0, __UNCONST(cdp->debugname), 0,
    674    1.1    atatat 			       CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
    675   1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
    676   1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
    677    1.1    atatat 			       CTLTYPE_INT, "value", NULL,
    678    1.1    atatat 			       NULL, 0, cdp->debugvar, 0,
    679    1.1    atatat 			       CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
    680   1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
    681   1.24    atatat 			       CTLFLAG_PERMANENT,
    682    1.1    atatat 			       CTLTYPE_INT, cdp->debugname, NULL,
    683    1.1    atatat 			       NULL, 0, cdp->debugvar, 0,
    684    1.1    atatat 			       CTL_DEBUG, CTL_CREATE, CTL_EOL);
    685    1.1    atatat 	}
    686    1.1    atatat }
    687    1.1    atatat #endif /* DEBUG */
    688    1.1    atatat 
    689    1.1    atatat /*
    690    1.1    atatat  * ********************************************************************
    691    1.1    atatat  * section 2: private node-specific helper routines.
    692    1.1    atatat  * ********************************************************************
    693    1.1    atatat  */
    694    1.1    atatat 
    695    1.1    atatat /*
    696  1.110  christos  * sysctl helper routine for kern.maxvnodes.  Drain vnodes if
    697   1.13      yamt  * new value is lower than desiredvnodes and then calls reinit
    698    1.1    atatat  * routines that needs to adjust to the new value.
    699    1.1    atatat  */
    700    1.1    atatat static int
    701    1.1    atatat sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
    702    1.1    atatat {
    703  1.142        ad 	int error, new_vnodes, old_vnodes, new_max;
    704    1.1    atatat 	struct sysctlnode node;
    705    1.1    atatat 
    706    1.1    atatat 	new_vnodes = desiredvnodes;
    707    1.1    atatat 	node = *rnode;
    708    1.1    atatat 	node.sysctl_data = &new_vnodes;
    709    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    710    1.1    atatat 	if (error || newp == NULL)
    711    1.1    atatat 		return (error);
    712    1.1    atatat 
    713  1.191   mlelstv 	/*
    714  1.191   mlelstv 	 * sysctl passes down unsigned values, require them
    715  1.191   mlelstv 	 * to be positive
    716  1.191   mlelstv 	 */
    717  1.191   mlelstv 	if (new_vnodes <= 0)
    718  1.191   mlelstv 		return (EINVAL);
    719  1.191   mlelstv 
    720  1.197      para 	/* Limits: 75% of kmem and physical memory. */
    721  1.197      para 	new_max = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC),
    722  1.197      para 	    75, 75) / VNODE_COST;
    723  1.142        ad 	if (new_vnodes > new_max)
    724  1.142        ad 		new_vnodes = new_max;
    725  1.142        ad 
    726   1.12      yamt 	old_vnodes = desiredvnodes;
    727    1.1    atatat 	desiredvnodes = new_vnodes;
    728  1.212   hannken 	error = vfs_drainvnodes();
    729  1.203   hannken 	if (error) {
    730  1.203   hannken 		desiredvnodes = old_vnodes;
    731  1.203   hannken 		return (error);
    732   1.12      yamt 	}
    733    1.1    atatat 	vfs_reinit();
    734    1.1    atatat 
    735    1.1    atatat 	return (0);
    736    1.1    atatat }
    737    1.1    atatat 
    738    1.1    atatat /*
    739  1.211  pgoyette  * sysctl helper routine for kern.messages.
    740  1.211  pgoyette  * Alters boothowto to display kernel messages in increasing verbosity
    741  1.211  pgoyette  * from 0 to 4.
    742  1.211  pgoyette  */
    743  1.211  pgoyette 
    744  1.211  pgoyette #define MAXMESSAGES            4
    745  1.211  pgoyette static int
    746  1.211  pgoyette sysctl_kern_messages(SYSCTLFN_ARGS)
    747  1.211  pgoyette {
    748  1.211  pgoyette 	int error, messageverbose, messagemask, newboothowto;
    749  1.211  pgoyette 	struct sysctlnode node;
    750  1.211  pgoyette 
    751  1.211  pgoyette 	messagemask = (AB_NORMAL|AB_QUIET|AB_SILENT|AB_VERBOSE|AB_DEBUG);
    752  1.211  pgoyette 	switch (boothowto & messagemask) {
    753  1.211  pgoyette 	case AB_SILENT:
    754  1.211  pgoyette 		messageverbose = 0;
    755  1.211  pgoyette 		break;
    756  1.211  pgoyette 	case AB_QUIET:
    757  1.211  pgoyette 		messageverbose = 1;
    758  1.211  pgoyette 		break;
    759  1.211  pgoyette 	case AB_VERBOSE:
    760  1.211  pgoyette 		messageverbose = 3;
    761  1.211  pgoyette 		break;
    762  1.211  pgoyette 	case AB_DEBUG:
    763  1.211  pgoyette 		messageverbose = 4;
    764  1.211  pgoyette 		break;
    765  1.211  pgoyette 	case AB_NORMAL:
    766  1.211  pgoyette 	default:
    767  1.211  pgoyette 		messageverbose = 2;
    768  1.218  christos 	}
    769  1.211  pgoyette 
    770  1.211  pgoyette 	node = *rnode;
    771  1.211  pgoyette 	node.sysctl_data = &messageverbose;
    772  1.211  pgoyette 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    773  1.211  pgoyette 	if (error || newp == NULL)
    774  1.211  pgoyette 		return (error);
    775  1.211  pgoyette 	if (messageverbose < 0 || messageverbose > MAXMESSAGES)
    776  1.211  pgoyette 		return EINVAL;
    777  1.211  pgoyette 
    778  1.211  pgoyette 	/* Set boothowto */
    779  1.211  pgoyette 	newboothowto = boothowto & ~messagemask;
    780  1.211  pgoyette 
    781  1.211  pgoyette 	switch (messageverbose) {
    782  1.211  pgoyette 	case 0:
    783  1.211  pgoyette 		newboothowto |= AB_SILENT;
    784  1.211  pgoyette 		break;
    785  1.211  pgoyette 	case 1:
    786  1.211  pgoyette 		newboothowto |= AB_QUIET;
    787  1.211  pgoyette 		break;
    788  1.211  pgoyette 	case 3:
    789  1.211  pgoyette 		newboothowto |= AB_VERBOSE;
    790  1.211  pgoyette 		break;
    791  1.211  pgoyette 	case 4:
    792  1.211  pgoyette 		newboothowto |= AB_DEBUG;
    793  1.211  pgoyette 		break;
    794  1.211  pgoyette 	case 2:
    795  1.211  pgoyette 	default:                /* Messages default to normal. */
    796  1.211  pgoyette 		break;
    797  1.211  pgoyette 	}
    798  1.211  pgoyette 
    799  1.211  pgoyette 	boothowto = newboothowto;
    800  1.211  pgoyette 
    801  1.211  pgoyette 	return (0);
    802  1.211  pgoyette }
    803  1.211  pgoyette 
    804  1.211  pgoyette /*
    805  1.223   thorpej  * sysctl helper routine for the kern.boottime node
    806  1.223   thorpej  */
    807  1.223   thorpej static int
    808  1.223   thorpej sysctl_kern_boottime(SYSCTLFN_ARGS)
    809  1.223   thorpej {
    810  1.223   thorpej 	struct sysctlnode node;
    811  1.223   thorpej 	struct timespec ts;
    812  1.223   thorpej 
    813  1.223   thorpej 	getnanoboottime(&ts);
    814  1.223   thorpej 	node = *rnode;
    815  1.223   thorpej 	node.sysctl_data = &ts;
    816  1.223   thorpej 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    817  1.223   thorpej }
    818  1.223   thorpej 
    819  1.223   thorpej /*
    820   1.14    martin  * sysctl helper routine for rtc_offset - set time after changes
    821   1.14    martin  */
    822   1.14    martin static int
    823   1.14    martin sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
    824   1.14    martin {
    825   1.57  christos 	struct timespec ts, delta;
    826   1.57  christos 	int error, new_rtc_offset;
    827   1.14    martin 	struct sysctlnode node;
    828   1.14    martin 
    829   1.14    martin 	new_rtc_offset = rtc_offset;
    830   1.14    martin 	node = *rnode;
    831   1.14    martin 	node.sysctl_data = &new_rtc_offset;
    832   1.14    martin 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    833   1.14    martin 	if (error || newp == NULL)
    834   1.14    martin 		return (error);
    835   1.14    martin 
    836   1.83      elad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
    837   1.83      elad 	    KAUTH_REQ_SYSTEM_TIME_RTCOFFSET,
    838  1.114      elad 	    KAUTH_ARG(new_rtc_offset), NULL, NULL))
    839   1.14    martin 		return (EPERM);
    840   1.14    martin 	if (rtc_offset == new_rtc_offset)
    841   1.14    martin 		return (0);
    842   1.14    martin 
    843   1.14    martin 	/* if we change the offset, adjust the time */
    844   1.57  christos 	nanotime(&ts);
    845   1.57  christos 	delta.tv_sec = 60 * (new_rtc_offset - rtc_offset);
    846   1.57  christos 	delta.tv_nsec = 0;
    847   1.57  christos 	timespecadd(&ts, &delta, &ts);
    848   1.14    martin 	rtc_offset = new_rtc_offset;
    849  1.114      elad 	return (settime(l->l_proc, &ts));
    850   1.14    martin }
    851   1.14    martin 
    852   1.14    martin /*
    853  1.110  christos  * sysctl helper routine for kern.maxproc. Ensures that the new
    854    1.1    atatat  * values are not too low or too high.
    855    1.1    atatat  */
    856    1.1    atatat static int
    857    1.1    atatat sysctl_kern_maxproc(SYSCTLFN_ARGS)
    858    1.1    atatat {
    859    1.1    atatat 	int error, nmaxproc;
    860    1.1    atatat 	struct sysctlnode node;
    861    1.1    atatat 
    862    1.1    atatat 	nmaxproc = maxproc;
    863    1.1    atatat 	node = *rnode;
    864    1.1    atatat 	node.sysctl_data = &nmaxproc;
    865    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    866    1.1    atatat 	if (error || newp == NULL)
    867    1.1    atatat 		return (error);
    868    1.1    atatat 
    869    1.1    atatat 	if (nmaxproc < 0 || nmaxproc >= PID_MAX)
    870    1.1    atatat 		return (EINVAL);
    871    1.1    atatat #ifdef __HAVE_CPU_MAXPROC
    872    1.1    atatat 	if (nmaxproc > cpu_maxproc())
    873    1.1    atatat 		return (EINVAL);
    874    1.1    atatat #endif
    875  1.224     skrll 	error = 0;
    876  1.224     skrll #ifdef __HAVE_MAXPROC_HOOK
    877  1.224     skrll 	error = cpu_maxproc_hook(nmaxproc);
    878  1.224     skrll #endif
    879  1.224     skrll 	if (error)
    880  1.224     skrll 		return error;
    881  1.224     skrll 
    882    1.1    atatat 	maxproc = nmaxproc;
    883    1.1    atatat 
    884    1.1    atatat 	return (0);
    885    1.1    atatat }
    886    1.1    atatat 
    887    1.1    atatat /*
    888  1.110  christos  * sysctl helper function for kern.hostid. The hostid is a long, but
    889    1.1    atatat  * we export it as an int, so we need to give it a little help.
    890    1.1    atatat  */
    891    1.1    atatat static int
    892    1.1    atatat sysctl_kern_hostid(SYSCTLFN_ARGS)
    893    1.1    atatat {
    894    1.1    atatat 	int error, inthostid;
    895    1.1    atatat 	struct sysctlnode node;
    896    1.1    atatat 
    897   1.29    martin 	inthostid = hostid;  /* XXX assumes sizeof int <= sizeof long */
    898    1.1    atatat 	node = *rnode;
    899    1.1    atatat 	node.sysctl_data = &inthostid;
    900    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    901    1.1    atatat 	if (error || newp == NULL)
    902    1.1    atatat 		return (error);
    903    1.1    atatat 
    904   1.27    atatat 	hostid = (unsigned)inthostid;
    905    1.1    atatat 
    906    1.1    atatat 	return (0);
    907    1.1    atatat }
    908    1.1    atatat 
    909    1.1    atatat /*
    910  1.110  christos  * sysctl helper routine for kern.defcorename. In the case of a new
    911    1.1    atatat  * string being assigned, check that it's not a zero-length string.
    912    1.1    atatat  * (XXX the check in -current doesn't work, but do we really care?)
    913    1.1    atatat  */
    914    1.1    atatat static int
    915    1.1    atatat sysctl_kern_defcorename(SYSCTLFN_ARGS)
    916    1.1    atatat {
    917    1.1    atatat 	int error;
    918   1.62      yamt 	char *newcorename;
    919    1.1    atatat 	struct sysctlnode node;
    920    1.1    atatat 
    921   1.62      yamt 	newcorename = PNBUF_GET();
    922    1.1    atatat 	node = *rnode;
    923    1.1    atatat 	node.sysctl_data = &newcorename[0];
    924    1.1    atatat 	memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
    925    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    926   1.62      yamt 	if (error || newp == NULL) {
    927   1.62      yamt 		goto done;
    928   1.62      yamt 	}
    929    1.1    atatat 
    930    1.1    atatat 	/*
    931    1.1    atatat 	 * when sysctl_lookup() deals with a string, it's guaranteed
    932  1.110  christos 	 * to come back nul terminated. So there.  :)
    933    1.1    atatat 	 */
    934   1.62      yamt 	if (strlen(newcorename) == 0) {
    935   1.62      yamt 		error = EINVAL;
    936   1.62      yamt 	} else {
    937   1.62      yamt 		memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
    938   1.62      yamt 		error = 0;
    939   1.62      yamt 	}
    940   1.62      yamt done:
    941   1.62      yamt 	PNBUF_PUT(newcorename);
    942   1.62      yamt 	return error;
    943    1.1    atatat }
    944    1.1    atatat 
    945    1.1    atatat /*
    946  1.110  christos  * sysctl helper routine for kern.cp_time node. Adds up cpu time
    947    1.1    atatat  * across all cpus.
    948    1.1    atatat  */
    949    1.1    atatat static int
    950    1.1    atatat sysctl_kern_cptime(SYSCTLFN_ARGS)
    951    1.1    atatat {
    952    1.1    atatat 	struct sysctlnode node = *rnode;
    953   1.59     perry 	uint64_t *cp_time = NULL;
    954   1.96        ad 	int error, n = ncpu, i;
    955    1.1    atatat 	struct cpu_info *ci;
    956    1.1    atatat 	CPU_INFO_ITERATOR cii;
    957    1.1    atatat 
    958    1.1    atatat 	/*
    959    1.1    atatat 	 * if you specifically pass a buffer that is the size of the
    960    1.1    atatat 	 * sum, or if you are probing for the size, you get the "sum"
    961    1.1    atatat 	 * of cp_time (and the size thereof) across all processors.
    962    1.1    atatat 	 *
    963    1.1    atatat 	 * alternately, you can pass an additional mib number and get
    964    1.1    atatat 	 * cp_time for that particular processor.
    965    1.1    atatat 	 */
    966    1.1    atatat 	switch (namelen) {
    967    1.1    atatat 	case 0:
    968  1.110  christos 		if (*oldlenp == sizeof(uint64_t) * CPUSTATES || oldp == NULL) {
    969   1.59     perry 			node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
    970    1.1    atatat 			n = -1; /* SUM */
    971    1.1    atatat 		}
    972    1.1    atatat 		else {
    973   1.59     perry 			node.sysctl_size = n * sizeof(uint64_t) * CPUSTATES;
    974    1.1    atatat 			n = -2; /* ALL */
    975    1.1    atatat 		}
    976    1.1    atatat 		break;
    977    1.1    atatat 	case 1:
    978    1.1    atatat 		if (name[0] < 0 || name[0] >= n)
    979   1.18    atatat 			return (ENOENT); /* ENOSUCHPROCESSOR */
    980   1.59     perry 		node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
    981    1.1    atatat 		n = name[0];
    982    1.1    atatat 		/*
    983    1.1    atatat 		 * adjust these so that sysctl_lookup() will be happy
    984    1.1    atatat 		 */
    985    1.1    atatat 		name++;
    986    1.1    atatat 		namelen--;
    987    1.7    martin 		break;
    988    1.1    atatat 	default:
    989    1.1    atatat 		return (EINVAL);
    990    1.1    atatat 	}
    991    1.1    atatat 
    992  1.118        ad 	cp_time = kmem_alloc(node.sysctl_size, KM_SLEEP);
    993    1.1    atatat 	node.sysctl_data = cp_time;
    994    1.1    atatat 	memset(cp_time, 0, node.sysctl_size);
    995    1.1    atatat 
    996    1.1    atatat 	for (CPU_INFO_FOREACH(cii, ci)) {
    997  1.118        ad 		if (n <= 0) {
    998  1.118        ad 			for (i = 0; i < CPUSTATES; i++) {
    999    1.1    atatat 				cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
   1000  1.118        ad 			}
   1001  1.118        ad 		}
   1002    1.1    atatat 		/*
   1003    1.1    atatat 		 * if a specific processor was requested and we just
   1004    1.1    atatat 		 * did it, we're done here
   1005    1.1    atatat 		 */
   1006    1.1    atatat 		if (n == 0)
   1007    1.1    atatat 			break;
   1008    1.1    atatat 		/*
   1009    1.1    atatat 		 * if doing "all", skip to next cp_time set for next processor
   1010    1.1    atatat 		 */
   1011    1.1    atatat 		if (n == -2)
   1012    1.1    atatat 			cp_time += CPUSTATES;
   1013    1.1    atatat 		/*
   1014    1.1    atatat 		 * if we're doing a specific processor, we're one
   1015    1.1    atatat 		 * processor closer
   1016    1.1    atatat 		 */
   1017    1.1    atatat 		if (n > 0)
   1018    1.1    atatat 			n--;
   1019    1.1    atatat 	}
   1020    1.1    atatat 
   1021    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1022  1.118        ad 	kmem_free(node.sysctl_data, node.sysctl_size);
   1023    1.5    martin 	return (error);
   1024    1.1    atatat }
   1025    1.1    atatat 
   1026    1.1    atatat #if NPTY > 0
   1027    1.1    atatat /*
   1028  1.110  christos  * sysctl helper routine for kern.maxptys. Ensures that any new value
   1029    1.1    atatat  * is acceptable to the pty subsystem.
   1030    1.1    atatat  */
   1031    1.1    atatat static int
   1032    1.1    atatat sysctl_kern_maxptys(SYSCTLFN_ARGS)
   1033    1.1    atatat {
   1034    1.1    atatat 	int pty_maxptys(int, int);		/* defined in kern/tty_pty.c */
   1035   1.40  christos 	int error, xmax;
   1036    1.1    atatat 	struct sysctlnode node;
   1037    1.1    atatat 
   1038    1.1    atatat 	/* get current value of maxptys */
   1039   1.40  christos 	xmax = pty_maxptys(0, 0);
   1040    1.1    atatat 
   1041    1.1    atatat 	node = *rnode;
   1042   1.40  christos 	node.sysctl_data = &xmax;
   1043    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1044    1.1    atatat 	if (error || newp == NULL)
   1045    1.1    atatat 		return (error);
   1046   1.33     perry 
   1047   1.40  christos 	if (xmax != pty_maxptys(xmax, 1))
   1048    1.1    atatat 		return (EINVAL);
   1049    1.1    atatat 
   1050    1.1    atatat 	return (0);
   1051    1.1    atatat }
   1052    1.1    atatat #endif /* NPTY > 0 */
   1053    1.1    atatat 
   1054    1.1    atatat /*
   1055    1.1    atatat  * sysctl helper routine to do kern.lwp.* work.
   1056    1.1    atatat  */
   1057    1.1    atatat static int
   1058    1.1    atatat sysctl_kern_lwp(SYSCTLFN_ARGS)
   1059    1.1    atatat {
   1060    1.1    atatat 	struct kinfo_lwp klwp;
   1061    1.1    atatat 	struct proc *p;
   1062  1.118        ad 	struct lwp *l2, *l3;
   1063    1.1    atatat 	char *where, *dp;
   1064    1.1    atatat 	int pid, elem_size, elem_count;
   1065    1.1    atatat 	int buflen, needed, error;
   1066  1.118        ad 	bool gotit;
   1067    1.1    atatat 
   1068  1.228  christos 	hash_value_ensure_initialized();
   1069  1.228  christos 
   1070   1.19    atatat 	if (namelen == 1 && name[0] == CTL_QUERY)
   1071   1.43    atatat 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   1072   1.19    atatat 
   1073    1.1    atatat 	dp = where = oldp;
   1074    1.1    atatat 	buflen = where != NULL ? *oldlenp : 0;
   1075    1.1    atatat 	error = needed = 0;
   1076    1.1    atatat 
   1077   1.11    simonb 	if (newp != NULL || namelen != 3)
   1078    1.1    atatat 		return (EINVAL);
   1079   1.11    simonb 	pid = name[0];
   1080   1.11    simonb 	elem_size = name[1];
   1081   1.11    simonb 	elem_count = name[2];
   1082    1.1    atatat 
   1083  1.118        ad 	sysctl_unlock();
   1084  1.101      yamt 	if (pid == -1) {
   1085  1.226        ad 		mutex_enter(&proc_lock);
   1086  1.162      yamt 		PROCLIST_FOREACH(p, &allproc) {
   1087  1.118        ad 			/* Grab a hold on the process. */
   1088  1.118        ad 			if (!rw_tryenter(&p->p_reflock, RW_READER)) {
   1089  1.118        ad 				continue;
   1090  1.118        ad 			}
   1091  1.226        ad 			mutex_exit(&proc_lock);
   1092  1.118        ad 
   1093  1.133        ad 			mutex_enter(p->p_lock);
   1094  1.118        ad 			LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
   1095  1.118        ad 				if (buflen >= elem_size && elem_count > 0) {
   1096  1.118        ad 					lwp_lock(l2);
   1097  1.118        ad 					fill_lwp(l2, &klwp);
   1098  1.118        ad 					lwp_unlock(l2);
   1099  1.133        ad 					mutex_exit(p->p_lock);
   1100  1.101      yamt 
   1101  1.118        ad 					/*
   1102  1.118        ad 					 * Copy out elem_size, but not
   1103  1.118        ad 					 * larger than the size of a
   1104  1.118        ad 					 * struct kinfo_proc2.
   1105  1.118        ad 					 */
   1106  1.118        ad 					error = dcopyout(l, &klwp, dp,
   1107  1.216  riastrad 					    uimin(sizeof(klwp), elem_size));
   1108  1.118        ad 					if (error) {
   1109  1.118        ad 						rw_exit(&p->p_reflock);
   1110  1.118        ad 						goto cleanup;
   1111  1.118        ad 					}
   1112  1.133        ad 					mutex_enter(p->p_lock);
   1113  1.118        ad 					LIST_FOREACH(l3, &p->p_lwps,
   1114  1.118        ad 					    l_sibling) {
   1115  1.118        ad 						if (l2 == l3)
   1116  1.118        ad 							break;
   1117  1.118        ad 					}
   1118  1.118        ad 					if (l3 == NULL) {
   1119  1.133        ad 						mutex_exit(p->p_lock);
   1120  1.118        ad 						rw_exit(&p->p_reflock);
   1121  1.118        ad 						error = EAGAIN;
   1122  1.118        ad 						goto cleanup;
   1123  1.118        ad 					}
   1124  1.118        ad 					dp += elem_size;
   1125  1.118        ad 					buflen -= elem_size;
   1126  1.118        ad 					elem_count--;
   1127  1.118        ad 				}
   1128  1.118        ad 				needed += elem_size;
   1129  1.101      yamt 			}
   1130  1.133        ad 			mutex_exit(p->p_lock);
   1131  1.118        ad 
   1132  1.118        ad 			/* Drop reference to process. */
   1133  1.226        ad 			mutex_enter(&proc_lock);
   1134  1.118        ad 			rw_exit(&p->p_reflock);
   1135  1.101      yamt 		}
   1136  1.226        ad 		mutex_exit(&proc_lock);
   1137  1.101      yamt 	} else {
   1138  1.226        ad 		mutex_enter(&proc_lock);
   1139  1.175     rmind 		p = proc_find(pid);
   1140  1.101      yamt 		if (p == NULL) {
   1141  1.118        ad 			error = ESRCH;
   1142  1.226        ad 			mutex_exit(&proc_lock);
   1143  1.118        ad 			goto cleanup;
   1144  1.118        ad 		}
   1145  1.118        ad 		/* Grab a hold on the process. */
   1146  1.118        ad 		gotit = rw_tryenter(&p->p_reflock, RW_READER);
   1147  1.226        ad 		mutex_exit(&proc_lock);
   1148  1.118        ad 		if (!gotit) {
   1149  1.118        ad 			error = ESRCH;
   1150  1.118        ad 			goto cleanup;
   1151  1.101      yamt 		}
   1152  1.118        ad 
   1153  1.133        ad 		mutex_enter(p->p_lock);
   1154  1.101      yamt 		LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
   1155  1.101      yamt 			if (buflen >= elem_size && elem_count > 0) {
   1156  1.101      yamt 				lwp_lock(l2);
   1157  1.101      yamt 				fill_lwp(l2, &klwp);
   1158  1.101      yamt 				lwp_unlock(l2);
   1159  1.133        ad 				mutex_exit(p->p_lock);
   1160  1.101      yamt 				/*
   1161  1.101      yamt 				 * Copy out elem_size, but not larger than
   1162  1.101      yamt 				 * the size of a struct kinfo_proc2.
   1163  1.101      yamt 				 */
   1164  1.101      yamt 				error = dcopyout(l, &klwp, dp,
   1165  1.216  riastrad 				    uimin(sizeof(klwp), elem_size));
   1166  1.107        ad 				if (error) {
   1167  1.118        ad 					rw_exit(&p->p_reflock);
   1168  1.107        ad 					goto cleanup;
   1169  1.107        ad 				}
   1170  1.133        ad 				mutex_enter(p->p_lock);
   1171  1.107        ad 				LIST_FOREACH(l3, &p->p_lwps, l_sibling) {
   1172  1.107        ad 					if (l2 == l3)
   1173  1.107        ad 						break;
   1174  1.107        ad 				}
   1175  1.108     rmind 				if (l3 == NULL) {
   1176  1.133        ad 					mutex_exit(p->p_lock);
   1177  1.118        ad 					rw_exit(&p->p_reflock);
   1178  1.107        ad 					error = EAGAIN;
   1179  1.101      yamt 					goto cleanup;
   1180  1.107        ad 				}
   1181  1.101      yamt 				dp += elem_size;
   1182  1.101      yamt 				buflen -= elem_size;
   1183  1.101      yamt 				elem_count--;
   1184  1.101      yamt 			}
   1185  1.101      yamt 			needed += elem_size;
   1186    1.1    atatat 		}
   1187  1.133        ad 		mutex_exit(p->p_lock);
   1188  1.118        ad 
   1189  1.118        ad 		/* Drop reference to process. */
   1190  1.118        ad 		rw_exit(&p->p_reflock);
   1191    1.1    atatat 	}
   1192    1.1    atatat 
   1193    1.1    atatat 	if (where != NULL) {
   1194    1.1    atatat 		*oldlenp = dp - where;
   1195  1.118        ad 		if (needed > *oldlenp) {
   1196  1.118        ad 			sysctl_relock();
   1197    1.1    atatat 			return (ENOMEM);
   1198  1.118        ad 		}
   1199    1.1    atatat 	} else {
   1200   1.22    atatat 		needed += KERN_LWPSLOP;
   1201    1.1    atatat 		*oldlenp = needed;
   1202    1.1    atatat 	}
   1203  1.118        ad 	error = 0;
   1204    1.1    atatat  cleanup:
   1205  1.118        ad 	sysctl_relock();
   1206    1.1    atatat 	return (error);
   1207    1.1    atatat }
   1208    1.1    atatat 
   1209    1.1    atatat /*
   1210  1.110  christos  * sysctl helper routine for kern.forkfsleep node. Ensures that the
   1211    1.1    atatat  * given value is not too large or two small, and is at least one
   1212    1.1    atatat  * timer tick if not zero.
   1213    1.1    atatat  */
   1214    1.1    atatat static int
   1215    1.1    atatat sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
   1216    1.1    atatat {
   1217    1.1    atatat 	/* userland sees value in ms, internally is in ticks */
   1218    1.1    atatat 	extern int forkfsleep;		/* defined in kern/kern_fork.c */
   1219    1.1    atatat 	int error, timo, lsleep;
   1220    1.1    atatat 	struct sysctlnode node;
   1221    1.1    atatat 
   1222    1.1    atatat 	lsleep = forkfsleep * 1000 / hz;
   1223    1.1    atatat 	node = *rnode;
   1224    1.1    atatat 	node.sysctl_data = &lsleep;
   1225    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1226    1.1    atatat 	if (error || newp == NULL)
   1227    1.1    atatat 		return (error);
   1228    1.1    atatat 
   1229    1.1    atatat 	/* refuse negative values, and overly 'long time' */
   1230    1.1    atatat 	if (lsleep < 0 || lsleep > MAXSLP * 1000)
   1231    1.1    atatat 		return (EINVAL);
   1232    1.1    atatat 
   1233    1.1    atatat 	timo = mstohz(lsleep);
   1234    1.1    atatat 
   1235    1.1    atatat 	/* if the interval is >0 ms && <1 tick, use 1 tick */
   1236    1.1    atatat 	if (lsleep != 0 && timo == 0)
   1237    1.1    atatat 		forkfsleep = 1;
   1238    1.1    atatat 	else
   1239    1.1    atatat 		forkfsleep = timo;
   1240    1.1    atatat 
   1241    1.1    atatat 	return (0);
   1242    1.1    atatat }
   1243    1.1    atatat 
   1244    1.1    atatat /*
   1245    1.1    atatat  * sysctl helper routine for kern.root_partition
   1246    1.1    atatat  */
   1247    1.1    atatat static int
   1248    1.1    atatat sysctl_kern_root_partition(SYSCTLFN_ARGS)
   1249    1.1    atatat {
   1250    1.1    atatat 	int rootpart = DISKPART(rootdev);
   1251    1.1    atatat 	struct sysctlnode node = *rnode;
   1252    1.1    atatat 
   1253    1.1    atatat 	node.sysctl_data = &rootpart;
   1254    1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1255    1.1    atatat }
   1256    1.1    atatat 
   1257    1.1    atatat /*
   1258    1.1    atatat  * sysctl helper function for kern.drivers
   1259    1.1    atatat  */
   1260    1.1    atatat static int
   1261    1.1    atatat sysctl_kern_drivers(SYSCTLFN_ARGS)
   1262    1.1    atatat {
   1263    1.1    atatat 	int error;
   1264    1.1    atatat 	size_t buflen;
   1265    1.1    atatat 	struct kinfo_drivers kd;
   1266    1.1    atatat 	char *start, *where;
   1267    1.1    atatat 	const char *dname;
   1268    1.1    atatat 	int i;
   1269    1.1    atatat 	extern struct devsw_conv *devsw_conv;
   1270    1.1    atatat 	extern int max_devsw_convs;
   1271    1.1    atatat 
   1272    1.1    atatat 	start = where = oldp;
   1273    1.1    atatat 	buflen = *oldlenp;
   1274    1.1    atatat 	if (where == NULL) {
   1275    1.1    atatat 		*oldlenp = max_devsw_convs * sizeof kd;
   1276    1.1    atatat 		return 0;
   1277    1.1    atatat 	}
   1278    1.1    atatat 
   1279    1.1    atatat 	/*
   1280    1.1    atatat 	 * An array of kinfo_drivers structures
   1281    1.1    atatat 	 */
   1282    1.1    atatat 	error = 0;
   1283  1.118        ad 	sysctl_unlock();
   1284  1.152     pooka 	mutex_enter(&device_lock);
   1285    1.1    atatat 	for (i = 0; i < max_devsw_convs; i++) {
   1286    1.1    atatat 		dname = devsw_conv[i].d_name;
   1287    1.1    atatat 		if (dname == NULL)
   1288    1.1    atatat 			continue;
   1289    1.1    atatat 		if (buflen < sizeof kd) {
   1290    1.1    atatat 			error = ENOMEM;
   1291    1.1    atatat 			break;
   1292    1.1    atatat 		}
   1293   1.25    atatat 		memset(&kd, 0, sizeof(kd));
   1294    1.1    atatat 		kd.d_bmajor = devsw_conv[i].d_bmajor;
   1295    1.1    atatat 		kd.d_cmajor = devsw_conv[i].d_cmajor;
   1296    1.1    atatat 		strlcpy(kd.d_name, dname, sizeof kd.d_name);
   1297  1.152     pooka 		mutex_exit(&device_lock);
   1298   1.86      manu 		error = dcopyout(l, &kd, where, sizeof kd);
   1299  1.152     pooka 		mutex_enter(&device_lock);
   1300    1.1    atatat 		if (error != 0)
   1301    1.1    atatat 			break;
   1302    1.1    atatat 		buflen -= sizeof kd;
   1303    1.1    atatat 		where += sizeof kd;
   1304    1.1    atatat 	}
   1305  1.152     pooka 	mutex_exit(&device_lock);
   1306  1.118        ad 	sysctl_relock();
   1307    1.1    atatat 	*oldlenp = where - start;
   1308    1.1    atatat 	return error;
   1309    1.1    atatat }
   1310    1.1    atatat 
   1311   1.61      elad static int
   1312   1.61      elad sysctl_security_setidcore(SYSCTLFN_ARGS)
   1313   1.61      elad {
   1314   1.61      elad 	int newsize, error;
   1315   1.61      elad 	struct sysctlnode node;
   1316   1.61      elad 
   1317   1.61      elad 	node = *rnode;
   1318   1.61      elad 	node.sysctl_data = &newsize;
   1319   1.61      elad 	newsize = *(int *)rnode->sysctl_data;
   1320   1.61      elad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1321   1.61      elad 	if (error || newp == NULL)
   1322   1.61      elad 		return error;
   1323   1.61      elad 
   1324   1.83      elad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
   1325   1.85      elad 	    0, NULL, NULL, NULL))
   1326   1.61      elad 		return (EPERM);
   1327   1.61      elad 
   1328   1.61      elad 	*(int *)rnode->sysctl_data = newsize;
   1329   1.61      elad 
   1330   1.61      elad 	return 0;
   1331   1.61      elad }
   1332   1.61      elad 
   1333   1.61      elad static int
   1334   1.61      elad sysctl_security_setidcorename(SYSCTLFN_ARGS)
   1335   1.61      elad {
   1336   1.61      elad 	int error;
   1337   1.72      yamt 	char *newsetidcorename;
   1338   1.61      elad 	struct sysctlnode node;
   1339   1.61      elad 
   1340   1.72      yamt 	newsetidcorename = PNBUF_GET();
   1341   1.61      elad 	node = *rnode;
   1342   1.72      yamt 	node.sysctl_data = newsetidcorename;
   1343   1.61      elad 	memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
   1344   1.61      elad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1345   1.72      yamt 	if (error || newp == NULL) {
   1346   1.72      yamt 		goto out;
   1347   1.72      yamt 	}
   1348   1.83      elad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
   1349   1.85      elad 	    0, NULL, NULL, NULL)) {
   1350   1.72      yamt 		error = EPERM;
   1351   1.72      yamt 		goto out;
   1352   1.72      yamt 	}
   1353   1.72      yamt 	if (strlen(newsetidcorename) == 0) {
   1354   1.72      yamt 		error = EINVAL;
   1355   1.72      yamt 		goto out;
   1356   1.72      yamt 	}
   1357   1.61      elad 	memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
   1358   1.72      yamt out:
   1359   1.72      yamt 	PNBUF_PUT(newsetidcorename);
   1360   1.72      yamt 	return error;
   1361   1.61      elad }
   1362   1.61      elad 
   1363   1.38      elad /*
   1364  1.110  christos  * sysctl helper routine for kern.cp_id node. Maps cpus to their
   1365   1.45  christos  * cpuids.
   1366   1.45  christos  */
   1367   1.45  christos static int
   1368   1.45  christos sysctl_kern_cpid(SYSCTLFN_ARGS)
   1369   1.45  christos {
   1370   1.45  christos 	struct sysctlnode node = *rnode;
   1371   1.59     perry 	uint64_t *cp_id = NULL;
   1372   1.96        ad 	int error, n = ncpu;
   1373   1.45  christos 	struct cpu_info *ci;
   1374   1.45  christos 	CPU_INFO_ITERATOR cii;
   1375   1.45  christos 
   1376   1.45  christos 	/*
   1377  1.110  christos 	 * Here you may either retrieve a single cpu id or the whole
   1378  1.110  christos 	 * set. The size you get back when probing depends on what
   1379   1.46    atatat 	 * you ask for.
   1380   1.45  christos 	 */
   1381   1.45  christos 	switch (namelen) {
   1382   1.45  christos 	case 0:
   1383   1.59     perry 		node.sysctl_size = n * sizeof(uint64_t);
   1384   1.45  christos 		n = -2; /* ALL */
   1385   1.45  christos 		break;
   1386   1.45  christos 	case 1:
   1387   1.45  christos 		if (name[0] < 0 || name[0] >= n)
   1388   1.45  christos 			return (ENOENT); /* ENOSUCHPROCESSOR */
   1389   1.59     perry 		node.sysctl_size = sizeof(uint64_t);
   1390   1.45  christos 		n = name[0];
   1391   1.45  christos 		/*
   1392   1.45  christos 		 * adjust these so that sysctl_lookup() will be happy
   1393   1.45  christos 		 */
   1394   1.45  christos 		name++;
   1395   1.45  christos 		namelen--;
   1396   1.45  christos 		break;
   1397   1.45  christos 	default:
   1398   1.45  christos 		return (EINVAL);
   1399   1.45  christos 	}
   1400   1.45  christos 
   1401  1.118        ad 	cp_id = kmem_alloc(node.sysctl_size, KM_SLEEP);
   1402   1.45  christos 	node.sysctl_data = cp_id;
   1403   1.45  christos 	memset(cp_id, 0, node.sysctl_size);
   1404   1.45  christos 
   1405   1.45  christos 	for (CPU_INFO_FOREACH(cii, ci)) {
   1406   1.45  christos 		if (n <= 0)
   1407  1.138        ad 			cp_id[0] = cpu_index(ci);
   1408   1.45  christos 		/*
   1409   1.45  christos 		 * if a specific processor was requested and we just
   1410   1.45  christos 		 * did it, we're done here
   1411   1.45  christos 		 */
   1412   1.45  christos 		if (n == 0)
   1413   1.45  christos 			break;
   1414   1.45  christos 		/*
   1415   1.45  christos 		 * if doing "all", skip to next cp_id slot for next processor
   1416   1.45  christos 		 */
   1417   1.45  christos 		if (n == -2)
   1418   1.45  christos 			cp_id++;
   1419   1.45  christos 		/*
   1420   1.45  christos 		 * if we're doing a specific processor, we're one
   1421   1.45  christos 		 * processor closer
   1422   1.45  christos 		 */
   1423   1.45  christos 		if (n > 0)
   1424   1.45  christos 			n--;
   1425   1.45  christos 	}
   1426   1.45  christos 
   1427   1.45  christos 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1428  1.118        ad 	kmem_free(node.sysctl_data, node.sysctl_size);
   1429   1.45  christos 	return (error);
   1430   1.45  christos }
   1431   1.45  christos 
   1432   1.45  christos /*
   1433  1.110  christos  * sysctl helper routine for hw.usermem and hw.usermem64. Values are
   1434    1.1    atatat  * calculate on the fly taking into account integer overflow and the
   1435    1.1    atatat  * current wired count.
   1436    1.1    atatat  */
   1437    1.1    atatat static int
   1438    1.1    atatat sysctl_hw_usermem(SYSCTLFN_ARGS)
   1439    1.1    atatat {
   1440    1.1    atatat 	u_int ui;
   1441    1.1    atatat 	u_quad_t uq;
   1442    1.1    atatat 	struct sysctlnode node;
   1443    1.1    atatat 
   1444    1.1    atatat 	node = *rnode;
   1445    1.1    atatat 	switch (rnode->sysctl_num) {
   1446  1.155    cegger 	case HW_USERMEM:
   1447    1.1    atatat 		if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
   1448    1.1    atatat 			ui = UINT_MAX;
   1449    1.1    atatat 		else
   1450    1.1    atatat 			ui *= PAGE_SIZE;
   1451    1.1    atatat 		node.sysctl_data = &ui;
   1452    1.1    atatat 		break;
   1453    1.1    atatat 	case HW_USERMEM64:
   1454    1.1    atatat 		uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
   1455    1.1    atatat 		node.sysctl_data = &uq;
   1456    1.1    atatat 		break;
   1457    1.1    atatat 	default:
   1458    1.1    atatat 		return (EINVAL);
   1459    1.1    atatat 	}
   1460    1.1    atatat 
   1461    1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1462    1.1    atatat }
   1463    1.1    atatat 
   1464    1.1    atatat /*
   1465  1.110  christos  * sysctl helper routine for kern.cnmagic node. Pulls the old value
   1466    1.1    atatat  * out, encoded, and stuffs the new value in for decoding.
   1467    1.1    atatat  */
   1468    1.1    atatat static int
   1469    1.1    atatat sysctl_hw_cnmagic(SYSCTLFN_ARGS)
   1470    1.1    atatat {
   1471    1.1    atatat 	char magic[CNS_LEN];
   1472    1.1    atatat 	int error;
   1473    1.1    atatat 	struct sysctlnode node;
   1474    1.1    atatat 
   1475    1.1    atatat 	if (oldp)
   1476    1.1    atatat 		cn_get_magic(magic, CNS_LEN);
   1477    1.1    atatat 	node = *rnode;
   1478    1.1    atatat 	node.sysctl_data = &magic[0];
   1479    1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1480    1.1    atatat 	if (error || newp == NULL)
   1481    1.1    atatat 		return (error);
   1482   1.33     perry 
   1483    1.1    atatat 	return (cn_set_magic(magic));
   1484    1.1    atatat }
   1485    1.3    martin 
   1486    1.1    atatat /*
   1487    1.1    atatat  * ********************************************************************
   1488    1.1    atatat  * section 3: public helper routines that are used for more than one
   1489    1.1    atatat  * node
   1490    1.1    atatat  * ********************************************************************
   1491    1.1    atatat  */
   1492    1.1    atatat 
   1493    1.1    atatat /*
   1494    1.1    atatat  * sysctl helper routine for the kern.root_device node and some ports'
   1495    1.1    atatat  * machdep.root_device nodes.
   1496    1.1    atatat  */
   1497    1.1    atatat int
   1498    1.1    atatat sysctl_root_device(SYSCTLFN_ARGS)
   1499    1.1    atatat {
   1500    1.1    atatat 	struct sysctlnode node;
   1501    1.1    atatat 
   1502    1.1    atatat 	node = *rnode;
   1503  1.193       chs 	node.sysctl_data = __UNCONST(device_xname(root_device));
   1504  1.130    cegger 	node.sysctl_size = strlen(device_xname(root_device)) + 1;
   1505    1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1506    1.1    atatat }
   1507    1.1    atatat 
   1508    1.1    atatat /*
   1509    1.1    atatat  * sysctl helper routine for kern.consdev, dependent on the current
   1510  1.110  christos  * state of the console. Also used for machdep.console_device on some
   1511    1.1    atatat  * ports.
   1512    1.1    atatat  */
   1513    1.1    atatat int
   1514    1.1    atatat sysctl_consdev(SYSCTLFN_ARGS)
   1515    1.1    atatat {
   1516    1.1    atatat 	dev_t consdev;
   1517  1.165  christos 	uint32_t oconsdev;
   1518    1.1    atatat 	struct sysctlnode node;
   1519    1.1    atatat 
   1520    1.1    atatat 	if (cn_tab != NULL)
   1521    1.1    atatat 		consdev = cn_tab->cn_dev;
   1522    1.1    atatat 	else
   1523    1.1    atatat 		consdev = NODEV;
   1524    1.1    atatat 	node = *rnode;
   1525  1.165  christos 	switch (*oldlenp) {
   1526  1.165  christos 	case sizeof(consdev):
   1527  1.165  christos 		node.sysctl_data = &consdev;
   1528  1.165  christos 		node.sysctl_size = sizeof(consdev);
   1529  1.165  christos 		break;
   1530  1.165  christos 	case sizeof(oconsdev):
   1531  1.165  christos 		oconsdev = (uint32_t)consdev;
   1532  1.165  christos 		node.sysctl_data = &oconsdev;
   1533  1.165  christos 		node.sysctl_size = sizeof(oconsdev);
   1534  1.165  christos 		break;
   1535  1.165  christos 	default:
   1536  1.165  christos 		return EINVAL;
   1537  1.165  christos 	}
   1538    1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1539    1.1    atatat }
   1540    1.1    atatat 
   1541    1.1    atatat /*
   1542    1.1    atatat  * ********************************************************************
   1543    1.1    atatat  * section 4: support for some helpers
   1544    1.1    atatat  * ********************************************************************
   1545    1.1    atatat  */
   1546  1.146  christos 
   1547    1.1    atatat 
   1548    1.1    atatat /*
   1549    1.1    atatat  * Fill in a kinfo_lwp structure for the specified lwp.
   1550    1.1    atatat  */
   1551    1.1    atatat static void
   1552    1.1    atatat fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
   1553    1.1    atatat {
   1554  1.219      maxv 	const bool allowaddr = get_expose_address(curproc);
   1555  1.101      yamt 	struct proc *p = l->l_proc;
   1556  1.115      yamt 	struct timeval tv;
   1557    1.1    atatat 
   1558  1.131      yamt 	KASSERT(lwp_locked(l, NULL));
   1559  1.131      yamt 
   1560  1.174     pooka 	memset(kl, 0, sizeof(*kl));
   1561  1.174     pooka 
   1562  1.101      yamt 	kl->l_forw = 0;
   1563  1.101      yamt 	kl->l_back = 0;
   1564  1.219      maxv 	COND_SET_VALUE(kl->l_laddr, PTRTOUINT64(l), allowaddr);
   1565  1.219      maxv 	COND_SET_VALUE(kl->l_addr, PTRTOUINT64(l->l_addr), allowaddr);
   1566    1.1    atatat 	kl->l_stat = l->l_stat;
   1567    1.1    atatat 	kl->l_lid = l->l_lid;
   1568  1.170       dsl 	kl->l_flag = L_INMEM;
   1569  1.170       dsl 	kl->l_flag |= sysctl_map_flags(sysctl_lwpprflagmap, l->l_prflag);
   1570  1.144  christos 	kl->l_flag |= sysctl_map_flags(sysctl_lwpflagmap, l->l_flag);
   1571    1.1    atatat 
   1572    1.1    atatat 	kl->l_swtime = l->l_swtime;
   1573    1.1    atatat 	kl->l_slptime = l->l_slptime;
   1574   1.95        ad 	if (l->l_stat == LSONPROC)
   1575    1.1    atatat 		kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
   1576   1.95        ad 	else
   1577    1.1    atatat 		kl->l_schedflags = 0;
   1578  1.113        ad 	kl->l_priority = lwp_eprio(l);
   1579  1.113        ad 	kl->l_usrpri = l->l_priority;
   1580  1.131      yamt 	if (l->l_wchan)
   1581  1.129   xtraeme 		strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
   1582  1.219      maxv 	COND_SET_VALUE(kl->l_wchan, PTRTOUINT64(l->l_wchan), allowaddr);
   1583  1.138        ad 	kl->l_cpuid = cpu_index(l->l_cpu);
   1584  1.115      yamt 	bintime2timeval(&l->l_rtime, &tv);
   1585  1.115      yamt 	kl->l_rtime_sec = tv.tv_sec;
   1586  1.115      yamt 	kl->l_rtime_usec = tv.tv_usec;
   1587  1.101      yamt 	kl->l_cpticks = l->l_cpticks;
   1588  1.101      yamt 	kl->l_pctcpu = l->l_pctcpu;
   1589  1.101      yamt 	kl->l_pid = p->p_pid;
   1590  1.101      yamt 	if (l->l_name == NULL)
   1591  1.101      yamt 		kl->l_name[0] = '\0';
   1592  1.128   xtraeme 	else
   1593  1.129   xtraeme 		strlcpy(kl->l_name, l->l_name, sizeof(kl->l_name));
   1594    1.1    atatat }
   1595