Home | History | Annotate | Line # | Download | only in kern
init_sysctl.c revision 1.81.4.8
      1  1.81.4.8        ad /*	$NetBSD: init_sysctl.c,v 1.81.4.8 2007/01/30 13:51:40 ad Exp $ */
      2       1.1    atatat 
      3       1.1    atatat /*-
      4       1.1    atatat  * Copyright (c) 2003 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.1    atatat  * by Andrew Brown.
      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  * 3. All advertising materials mentioning features or use of this software
     19       1.1    atatat  *    must display the following acknowledgement:
     20       1.1    atatat  *      This product includes software developed by the NetBSD
     21       1.1    atatat  *      Foundation, Inc. and its contributors.
     22       1.1    atatat  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1    atatat  *    contributors may be used to endorse or promote products derived
     24       1.1    atatat  *    from this software without specific prior written permission.
     25       1.1    atatat  *
     26       1.1    atatat  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1    atatat  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1    atatat  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1    atatat  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1    atatat  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1    atatat  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1    atatat  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1    atatat  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1    atatat  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1    atatat  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1    atatat  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1    atatat  */
     38       1.1    atatat 
     39      1.16    atatat #include <sys/cdefs.h>
     40  1.81.4.8        ad __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.81.4.8 2007/01/30 13:51:40 ad Exp $");
     41      1.16    atatat 
     42       1.1    atatat #include "opt_sysv.h"
     43       1.2    atatat #include "opt_multiprocessor.h"
     44       1.4      fvdl #include "opt_posix.h"
     45  1.81.4.5        ad #include "opt_compat_netbsd32.h"
     46  1.81.4.5        ad #include "opt_ktrace.h"
     47       1.1    atatat #include "pty.h"
     48       1.1    atatat #include "rnd.h"
     49       1.1    atatat 
     50       1.1    atatat #include <sys/types.h>
     51       1.1    atatat #include <sys/param.h>
     52       1.1    atatat #include <sys/sysctl.h>
     53       1.1    atatat #include <sys/errno.h>
     54       1.1    atatat #include <sys/systm.h>
     55       1.1    atatat #include <sys/kernel.h>
     56       1.1    atatat #include <sys/unistd.h>
     57       1.1    atatat #include <sys/disklabel.h>
     58       1.1    atatat #include <sys/rnd.h>
     59       1.1    atatat #include <sys/vnode.h>
     60       1.1    atatat #include <sys/mount.h>
     61       1.1    atatat #include <sys/namei.h>
     62       1.1    atatat #include <sys/msgbuf.h>
     63       1.1    atatat #include <dev/cons.h>
     64       1.1    atatat #include <sys/socketvar.h>
     65       1.1    atatat #include <sys/file.h>
     66      1.34    atatat #include <sys/filedesc.h>
     67       1.1    atatat #include <sys/tty.h>
     68       1.1    atatat #include <sys/malloc.h>
     69       1.1    atatat #include <sys/resource.h>
     70       1.1    atatat #include <sys/resourcevar.h>
     71       1.1    atatat #include <sys/exec.h>
     72       1.1    atatat #include <sys/conf.h>
     73       1.1    atatat #include <sys/device.h>
     74      1.61      elad #include <sys/stat.h>
     75      1.68      elad #include <sys/kauth.h>
     76  1.81.4.5        ad #ifdef KTRACE
     77  1.81.4.5        ad #include <sys/ktrace.h>
     78  1.81.4.5        ad #endif
     79       1.1    atatat 
     80  1.81.4.5        ad #ifdef COMPAT_NETBSD32
     81  1.81.4.5        ad #include <compat/netbsd32/netbsd32.h>
     82  1.81.4.5        ad #endif
     83  1.81.4.5        ad 
     84       1.4      fvdl #include <machine/cpu.h>
     85       1.1    atatat 
     86      1.54      elad /* XXX this should not be here */
     87      1.61      elad int security_setidcore_dump;
     88      1.61      elad char security_setidcore_path[MAXPATHLEN] = "/var/crash/%n.core";
     89      1.61      elad uid_t security_setidcore_owner = 0;
     90      1.61      elad gid_t security_setidcore_group = 0;
     91      1.61      elad mode_t security_setidcore_mode = (S_IRUSR|S_IWUSR);
     92      1.54      elad 
     93  1.81.4.6        ad static const u_int sysctl_flagmap[] = {
     94  1.81.4.6        ad 	P_ADVLOCK, KP_ADVLOCK,
     95  1.81.4.6        ad 	P_EXEC, KP_EXEC,
     96  1.81.4.6        ad 	P_NOCLDWAIT, KP_NOCLDWAIT,
     97  1.81.4.6        ad 	P_32, KP_32,
     98  1.81.4.6        ad 	P_CLDSIGIGN, KP_CLDSIGIGN,
     99  1.81.4.6        ad 	P_PAXMPROTECT, KP_PAXMPROTECT,
    100  1.81.4.6        ad 	P_PAXNOMPROTECT, KP_PAXNOMPROTECT,
    101  1.81.4.6        ad 	P_SYSTRACE, KP_SYSTRACE,
    102  1.81.4.6        ad 	P_SUGID, KP_SUGID,
    103  1.81.4.6        ad 	0
    104  1.81.4.6        ad };
    105  1.81.4.6        ad 
    106  1.81.4.6        ad static const u_int sysctl_sflagmap[] = {
    107  1.81.4.6        ad 	PS_NOCLDSTOP, KP_NOCLDSTOP,
    108  1.81.4.6        ad 	PS_PPWAIT, KP_PPWAIT,
    109  1.81.4.6        ad 	PS_WEXIT, KP_WEXIT,
    110  1.81.4.6        ad 	PS_STOPFORK, KP_STOPFORK,
    111  1.81.4.6        ad 	PS_STOPEXEC, KP_STOPEXEC,
    112  1.81.4.6        ad 	PS_STOPEXIT, KP_STOPEXIT,
    113  1.81.4.6        ad 	0
    114  1.81.4.6        ad };
    115  1.81.4.6        ad 
    116  1.81.4.6        ad static const u_int sysctl_slflagmap[] = {
    117  1.81.4.6        ad 	PSL_TRACED, KP_TRACED,
    118  1.81.4.6        ad 	PSL_FSTRACE, KP_FSTRACE,
    119  1.81.4.6        ad 	PSL_CHTRACED, KP_CHTRACED,
    120  1.81.4.6        ad 	PSL_SYSCALL, KP_SYSCALL,
    121  1.81.4.6        ad 	0
    122  1.81.4.6        ad };
    123  1.81.4.6        ad 
    124  1.81.4.6        ad static const u_int sysctl_lflagmap[] = {
    125  1.81.4.6        ad 	PL_CONTROLT, KP_CONTROLT,
    126  1.81.4.6        ad 	0
    127  1.81.4.6        ad };
    128  1.81.4.6        ad 
    129  1.81.4.6        ad static const u_int sysctl_stflagmap[] = {
    130  1.81.4.6        ad 	PST_PROFIL, KP_PROFIL,
    131  1.81.4.6        ad 	0
    132  1.81.4.6        ad 
    133  1.81.4.6        ad };
    134  1.81.4.6        ad 
    135  1.81.4.6        ad static const u_int sysctl_lwpflagmap[] = {
    136  1.81.4.6        ad 	L_INMEM, KP_INMEM,
    137  1.81.4.6        ad 	L_SELECT, KP_SELECT,
    138  1.81.4.6        ad 	L_SINTR, KP_SINTR,
    139  1.81.4.6        ad 	L_SYSTEM, KP_SYSTEM,
    140  1.81.4.6        ad 	0
    141  1.81.4.6        ad };
    142  1.81.4.6        ad 
    143  1.81.4.6        ad 
    144       1.1    atatat /*
    145       1.1    atatat  * try over estimating by 5 procs/lwps
    146       1.1    atatat  */
    147       1.1    atatat #define KERN_PROCSLOP	(5 * sizeof(struct kinfo_proc))
    148       1.1    atatat #define KERN_LWPSLOP	(5 * sizeof(struct kinfo_lwp))
    149       1.1    atatat 
    150  1.81.4.5        ad #ifdef KTRACE
    151  1.81.4.5        ad int dcopyout(struct lwp *, const void *, void *, size_t);
    152  1.81.4.5        ad 
    153  1.81.4.5        ad int
    154  1.81.4.5        ad dcopyout(l, kaddr, uaddr, len)
    155  1.81.4.5        ad 	struct lwp *l;
    156  1.81.4.5        ad 	const void *kaddr;
    157  1.81.4.5        ad 	void *uaddr;
    158  1.81.4.5        ad 	size_t len;
    159  1.81.4.5        ad {
    160  1.81.4.5        ad 	int error;
    161  1.81.4.5        ad 
    162  1.81.4.5        ad 	error = copyout(kaddr, uaddr, len);
    163  1.81.4.5        ad 	if (!error && KTRPOINT(l->l_proc, KTR_MIB)) {
    164  1.81.4.5        ad 		struct iovec iov;
    165  1.81.4.5        ad 
    166  1.81.4.5        ad 		iov.iov_base = uaddr;
    167  1.81.4.5        ad 		iov.iov_len = len;
    168  1.81.4.5        ad 		ktrgenio(l, -1, UIO_READ, &iov, len, 0);
    169  1.81.4.5        ad 	}
    170  1.81.4.5        ad 	return error;
    171  1.81.4.5        ad }
    172  1.81.4.5        ad #else /* !KTRACE */
    173  1.81.4.5        ad #define dcopyout(l, kaddr, uaddr, len) copyout(kaddr, uaddr, len)
    174  1.81.4.5        ad #endif /* KTRACE */
    175       1.1    atatat #ifndef MULTIPROCESSOR
    176       1.3    martin #define	sysctl_ncpus()	(1)
    177       1.1    atatat #else /* MULTIPROCESSOR */
    178       1.1    atatat #ifndef CPU_INFO_FOREACH
    179       1.1    atatat #define CPU_INFO_ITERATOR int
    180       1.1    atatat #define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = curcpu(); ci != NULL; ci = NULL
    181       1.1    atatat #endif
    182       1.1    atatat static int
    183       1.1    atatat sysctl_ncpus(void)
    184       1.1    atatat {
    185       1.1    atatat 	struct cpu_info *ci;
    186       1.1    atatat 	CPU_INFO_ITERATOR cii;
    187       1.1    atatat 
    188      1.42       jdc 	int ncpus = 0;
    189       1.1    atatat 	for (CPU_INFO_FOREACH(cii, ci))
    190      1.42       jdc 		ncpus++;
    191      1.42       jdc 	return (ncpus);
    192       1.1    atatat }
    193       1.1    atatat #endif /* MULTIPROCESSOR */
    194       1.1    atatat 
    195      1.64       erh #ifdef DIAGNOSTIC
    196      1.64       erh static int sysctl_kern_trigger_panic(SYSCTLFN_PROTO);
    197      1.64       erh #endif
    198       1.1    atatat static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
    199      1.14    martin static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
    200       1.1    atatat static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
    201       1.1    atatat static int sysctl_kern_hostid(SYSCTLFN_PROTO);
    202      1.17    atatat static int sysctl_setlen(SYSCTLFN_PROTO);
    203       1.1    atatat static int sysctl_kern_clockrate(SYSCTLFN_PROTO);
    204       1.1    atatat static int sysctl_kern_file(SYSCTLFN_PROTO);
    205       1.1    atatat static int sysctl_kern_autonice(SYSCTLFN_PROTO);
    206       1.1    atatat static int sysctl_msgbuf(SYSCTLFN_PROTO);
    207       1.1    atatat static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
    208       1.1    atatat static int sysctl_kern_cptime(SYSCTLFN_PROTO);
    209       1.6        he #if NPTY > 0
    210       1.1    atatat static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
    211       1.6        he #endif /* NPTY > 0 */
    212       1.1    atatat static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
    213       1.1    atatat static int sysctl_kern_urnd(SYSCTLFN_PROTO);
    214  1.81.4.5        ad static int sysctl_kern_arnd(SYSCTLFN_PROTO);
    215       1.1    atatat static int sysctl_kern_lwp(SYSCTLFN_PROTO);
    216       1.1    atatat static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
    217       1.1    atatat static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
    218       1.1    atatat static int sysctl_kern_drivers(SYSCTLFN_PROTO);
    219      1.34    atatat static int sysctl_kern_file2(SYSCTLFN_PROTO);
    220      1.61      elad static int sysctl_security_setidcore(SYSCTLFN_PROTO);
    221      1.61      elad static int sysctl_security_setidcorename(SYSCTLFN_PROTO);
    222      1.45  christos static int sysctl_kern_cpid(SYSCTLFN_PROTO);
    223       1.1    atatat static int sysctl_doeproc(SYSCTLFN_PROTO);
    224       1.1    atatat static int sysctl_kern_proc_args(SYSCTLFN_PROTO);
    225       1.1    atatat static int sysctl_hw_usermem(SYSCTLFN_PROTO);
    226       1.1    atatat static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
    227       1.3    martin static int sysctl_hw_ncpu(SYSCTLFN_PROTO);
    228       1.1    atatat 
    229  1.81.4.6        ad static u_int sysctl_map_flags(const u_int *, u_int);
    230       1.1    atatat static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
    231       1.1    atatat static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
    232      1.34    atatat static void fill_file(struct kinfo_file *, const struct file *, struct proc *,
    233      1.34    atatat 		      int);
    234       1.1    atatat 
    235       1.1    atatat /*
    236       1.1    atatat  * ********************************************************************
    237       1.1    atatat  * section 1: setup routines
    238       1.1    atatat  * ********************************************************************
    239       1.1    atatat  * these functions are stuffed into a link set for sysctl setup
    240       1.1    atatat  * functions.  they're never called or referenced from anywhere else.
    241       1.1    atatat  * ********************************************************************
    242       1.1    atatat  */
    243       1.1    atatat 
    244       1.1    atatat /*
    245       1.1    atatat  * sets up the base nodes...
    246       1.1    atatat  */
    247       1.1    atatat SYSCTL_SETUP(sysctl_root_setup, "sysctl base setup")
    248       1.1    atatat {
    249       1.1    atatat 
    250      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    251      1.24    atatat 		       CTLFLAG_PERMANENT,
    252      1.26    atatat 		       CTLTYPE_NODE, "kern",
    253      1.26    atatat 		       SYSCTL_DESCR("High kernel"),
    254       1.1    atatat 		       NULL, 0, NULL, 0,
    255       1.1    atatat 		       CTL_KERN, CTL_EOL);
    256      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    257      1.24    atatat 		       CTLFLAG_PERMANENT,
    258      1.26    atatat 		       CTLTYPE_NODE, "vm",
    259      1.26    atatat 		       SYSCTL_DESCR("Virtual memory"),
    260       1.1    atatat 		       NULL, 0, NULL, 0,
    261       1.1    atatat 		       CTL_VM, CTL_EOL);
    262      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    263      1.24    atatat 		       CTLFLAG_PERMANENT,
    264      1.26    atatat 		       CTLTYPE_NODE, "vfs",
    265      1.26    atatat 		       SYSCTL_DESCR("Filesystem"),
    266       1.1    atatat 		       NULL, 0, NULL, 0,
    267       1.1    atatat 		       CTL_VFS, CTL_EOL);
    268      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    269      1.24    atatat 		       CTLFLAG_PERMANENT,
    270      1.26    atatat 		       CTLTYPE_NODE, "net",
    271      1.26    atatat 		       SYSCTL_DESCR("Networking"),
    272       1.1    atatat 		       NULL, 0, NULL, 0,
    273       1.1    atatat 		       CTL_NET, CTL_EOL);
    274      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    275      1.24    atatat 		       CTLFLAG_PERMANENT,
    276      1.26    atatat 		       CTLTYPE_NODE, "debug",
    277      1.26    atatat 		       SYSCTL_DESCR("Debugging"),
    278       1.1    atatat 		       NULL, 0, NULL, 0,
    279       1.1    atatat 		       CTL_DEBUG, CTL_EOL);
    280      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    281      1.24    atatat 		       CTLFLAG_PERMANENT,
    282      1.26    atatat 		       CTLTYPE_NODE, "hw",
    283      1.26    atatat 		       SYSCTL_DESCR("Generic CPU, I/O"),
    284       1.1    atatat 		       NULL, 0, NULL, 0,
    285       1.1    atatat 		       CTL_HW, CTL_EOL);
    286      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    287      1.24    atatat 		       CTLFLAG_PERMANENT,
    288      1.26    atatat 		       CTLTYPE_NODE, "machdep",
    289      1.26    atatat 		       SYSCTL_DESCR("Machine dependent"),
    290       1.1    atatat 		       NULL, 0, NULL, 0,
    291       1.1    atatat 		       CTL_MACHDEP, CTL_EOL);
    292       1.1    atatat 	/*
    293       1.1    atatat 	 * this node is inserted so that the sysctl nodes in libc can
    294       1.1    atatat 	 * operate.
    295       1.1    atatat 	 */
    296      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    297      1.24    atatat 		       CTLFLAG_PERMANENT,
    298      1.26    atatat 		       CTLTYPE_NODE, "user",
    299      1.26    atatat 		       SYSCTL_DESCR("User-level"),
    300       1.1    atatat 		       NULL, 0, NULL, 0,
    301       1.1    atatat 		       CTL_USER, CTL_EOL);
    302      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    303      1.24    atatat 		       CTLFLAG_PERMANENT,
    304      1.26    atatat 		       CTLTYPE_NODE, "ddb",
    305      1.26    atatat 		       SYSCTL_DESCR("In-kernel debugger"),
    306       1.1    atatat 		       NULL, 0, NULL, 0,
    307       1.1    atatat 		       CTL_DDB, CTL_EOL);
    308      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    309      1.24    atatat 		       CTLFLAG_PERMANENT,
    310      1.26    atatat 		       CTLTYPE_NODE, "proc",
    311      1.26    atatat 		       SYSCTL_DESCR("Per-process"),
    312       1.1    atatat 		       NULL, 0, NULL, 0,
    313       1.1    atatat 		       CTL_PROC, CTL_EOL);
    314      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    315      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    316      1.26    atatat 		       CTLTYPE_NODE, "vendor",
    317      1.26    atatat 		       SYSCTL_DESCR("Vendor specific"),
    318       1.1    atatat 		       NULL, 0, NULL, 0,
    319       1.1    atatat 		       CTL_VENDOR, CTL_EOL);
    320      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    321      1.24    atatat 		       CTLFLAG_PERMANENT,
    322      1.26    atatat 		       CTLTYPE_NODE, "emul",
    323      1.26    atatat 		       SYSCTL_DESCR("Emulation settings"),
    324       1.1    atatat 		       NULL, 0, NULL, 0,
    325       1.1    atatat 		       CTL_EMUL, CTL_EOL);
    326      1.54      elad 	sysctl_createv(clog, 0, NULL, NULL,
    327      1.54      elad 		       CTLFLAG_PERMANENT,
    328      1.54      elad 		       CTLTYPE_NODE, "security",
    329      1.54      elad 		       SYSCTL_DESCR("Security"),
    330      1.54      elad 		       NULL, 0, NULL, 0,
    331      1.54      elad 		       CTL_SECURITY, CTL_EOL);
    332       1.1    atatat }
    333       1.1    atatat 
    334       1.1    atatat /*
    335       1.1    atatat  * this setup routine is a replacement for kern_sysctl()
    336       1.1    atatat  */
    337       1.1    atatat SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
    338       1.1    atatat {
    339       1.1    atatat 	extern int kern_logsigexit;	/* defined in kern/kern_sig.c */
    340       1.1    atatat 	extern fixpt_t ccpu;		/* defined in kern/kern_synch.c */
    341       1.1    atatat 	extern int dumponpanic;		/* defined in kern/subr_prf.c */
    342      1.75      elad 	const struct sysctlnode *rnode;
    343       1.1    atatat 
    344      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    345      1.24    atatat 		       CTLFLAG_PERMANENT,
    346       1.1    atatat 		       CTLTYPE_NODE, "kern", NULL,
    347       1.1    atatat 		       NULL, 0, NULL, 0,
    348       1.1    atatat 		       CTL_KERN, CTL_EOL);
    349       1.1    atatat 
    350      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    351      1.24    atatat 		       CTLFLAG_PERMANENT,
    352      1.26    atatat 		       CTLTYPE_STRING, "ostype",
    353      1.26    atatat 		       SYSCTL_DESCR("Operating system type"),
    354       1.1    atatat 		       NULL, 0, &ostype, 0,
    355       1.1    atatat 		       CTL_KERN, KERN_OSTYPE, CTL_EOL);
    356      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    357      1.24    atatat 		       CTLFLAG_PERMANENT,
    358      1.26    atatat 		       CTLTYPE_STRING, "osrelease",
    359      1.26    atatat 		       SYSCTL_DESCR("Operating system release"),
    360       1.1    atatat 		       NULL, 0, &osrelease, 0,
    361       1.1    atatat 		       CTL_KERN, KERN_OSRELEASE, 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, "osrevision",
    365      1.26    atatat 		       SYSCTL_DESCR("Operating system revision"),
    366       1.1    atatat 		       NULL, __NetBSD_Version__, NULL, 0,
    367       1.1    atatat 		       CTL_KERN, KERN_OSREV, CTL_EOL);
    368      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    369      1.24    atatat 		       CTLFLAG_PERMANENT,
    370      1.26    atatat 		       CTLTYPE_STRING, "version",
    371      1.26    atatat 		       SYSCTL_DESCR("Kernel version"),
    372       1.1    atatat 		       NULL, 0, &version, 0,
    373       1.1    atatat 		       CTL_KERN, KERN_VERSION, CTL_EOL);
    374      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    375      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    376      1.26    atatat 		       CTLTYPE_INT, "maxvnodes",
    377      1.26    atatat 		       SYSCTL_DESCR("Maximum number of vnodes"),
    378       1.1    atatat 		       sysctl_kern_maxvnodes, 0, NULL, 0,
    379       1.1    atatat 		       CTL_KERN, KERN_MAXVNODES, CTL_EOL);
    380      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    381      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    382      1.26    atatat 		       CTLTYPE_INT, "maxproc",
    383      1.26    atatat 		       SYSCTL_DESCR("Maximum number of simultaneous processes"),
    384       1.1    atatat 		       sysctl_kern_maxproc, 0, NULL, 0,
    385       1.1    atatat 		       CTL_KERN, KERN_MAXPROC, CTL_EOL);
    386      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    387      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    388      1.26    atatat 		       CTLTYPE_INT, "maxfiles",
    389      1.26    atatat 		       SYSCTL_DESCR("Maximum number of open files"),
    390       1.1    atatat 		       NULL, 0, &maxfiles, 0,
    391       1.1    atatat 		       CTL_KERN, KERN_MAXFILES, CTL_EOL);
    392      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    393      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    394      1.26    atatat 		       CTLTYPE_INT, "argmax",
    395      1.26    atatat 		       SYSCTL_DESCR("Maximum number of bytes of arguments to "
    396      1.26    atatat 				    "execve(2)"),
    397       1.1    atatat 		       NULL, ARG_MAX, NULL, 0,
    398       1.1    atatat 		       CTL_KERN, KERN_ARGMAX, CTL_EOL);
    399      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    400      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    401      1.26    atatat 		       CTLTYPE_STRING, "hostname",
    402      1.26    atatat 		       SYSCTL_DESCR("System hostname"),
    403      1.17    atatat 		       sysctl_setlen, 0, &hostname, MAXHOSTNAMELEN,
    404       1.1    atatat 		       CTL_KERN, KERN_HOSTNAME, CTL_EOL);
    405      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    406      1.27    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
    407      1.26    atatat 		       CTLTYPE_INT, "hostid",
    408      1.26    atatat 		       SYSCTL_DESCR("System host ID number"),
    409       1.1    atatat 		       sysctl_kern_hostid, 0, NULL, 0,
    410       1.1    atatat 		       CTL_KERN, KERN_HOSTID, CTL_EOL);
    411      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    412      1.24    atatat 		       CTLFLAG_PERMANENT,
    413      1.26    atatat 		       CTLTYPE_STRUCT, "clockrate",
    414      1.26    atatat 		       SYSCTL_DESCR("Kernel clock rates"),
    415       1.1    atatat 		       sysctl_kern_clockrate, 0, NULL,
    416       1.1    atatat 		       sizeof(struct clockinfo),
    417       1.1    atatat 		       CTL_KERN, KERN_CLOCKRATE, CTL_EOL);
    418      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    419      1.24    atatat 		       CTLFLAG_PERMANENT,
    420      1.53    rpaulo 		       CTLTYPE_INT, "hardclock_ticks",
    421      1.53    rpaulo 		       SYSCTL_DESCR("Number of hardclock ticks"),
    422      1.53    rpaulo 		       NULL, 0, &hardclock_ticks, sizeof(hardclock_ticks),
    423      1.53    rpaulo 		       CTL_KERN, KERN_HARDCLOCK_TICKS, CTL_EOL);
    424      1.53    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
    425      1.53    rpaulo 		       CTLFLAG_PERMANENT,
    426      1.26    atatat 		       CTLTYPE_STRUCT, "vnode",
    427      1.26    atatat 		       SYSCTL_DESCR("System vnode table"),
    428       1.1    atatat 		       sysctl_kern_vnode, 0, NULL, 0,
    429       1.1    atatat 		       CTL_KERN, KERN_VNODE, CTL_EOL);
    430      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    431      1.24    atatat 		       CTLFLAG_PERMANENT,
    432      1.26    atatat 		       CTLTYPE_STRUCT, "file",
    433      1.26    atatat 		       SYSCTL_DESCR("System open file table"),
    434       1.1    atatat 		       sysctl_kern_file, 0, NULL, 0,
    435       1.1    atatat 		       CTL_KERN, KERN_FILE, CTL_EOL);
    436       1.1    atatat #ifndef GPROF
    437      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    438      1.24    atatat 		       CTLFLAG_PERMANENT,
    439      1.26    atatat 		       CTLTYPE_NODE, "profiling",
    440      1.26    atatat 		       SYSCTL_DESCR("Profiling information (not available)"),
    441       1.1    atatat 		       sysctl_notavail, 0, NULL, 0,
    442       1.1    atatat 		       CTL_KERN, KERN_PROF, CTL_EOL);
    443       1.1    atatat #endif
    444      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    445      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    446      1.26    atatat 		       CTLTYPE_INT, "posix1version",
    447      1.26    atatat 		       SYSCTL_DESCR("Version of ISO/IEC 9945 (POSIX 1003.1) "
    448      1.26    atatat 				    "with which the operating system attempts "
    449      1.26    atatat 				    "to comply"),
    450       1.1    atatat 		       NULL, _POSIX_VERSION, NULL, 0,
    451       1.1    atatat 		       CTL_KERN, KERN_POSIX1, CTL_EOL);
    452      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    453      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    454      1.26    atatat 		       CTLTYPE_INT, "ngroups",
    455      1.26    atatat 		       SYSCTL_DESCR("Maximum number of supplemental groups"),
    456       1.1    atatat 		       NULL, NGROUPS_MAX, NULL, 0,
    457       1.1    atatat 		       CTL_KERN, KERN_NGROUPS, CTL_EOL);
    458      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    459      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    460      1.26    atatat 		       CTLTYPE_INT, "job_control",
    461      1.26    atatat 		       SYSCTL_DESCR("Whether job control is available"),
    462       1.1    atatat 		       NULL, 1, NULL, 0,
    463       1.1    atatat 		       CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
    464      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    465      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    466      1.26    atatat 		       CTLTYPE_INT, "saved_ids",
    467      1.37       mrg 		       SYSCTL_DESCR("Whether POSIX saved set-group/user ID is "
    468      1.26    atatat 				    "available"), NULL,
    469       1.1    atatat #ifdef _POSIX_SAVED_IDS
    470       1.1    atatat 		       1,
    471       1.1    atatat #else /* _POSIX_SAVED_IDS */
    472       1.1    atatat 		       0,
    473       1.1    atatat #endif /* _POSIX_SAVED_IDS */
    474       1.1    atatat 		       NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
    475      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    476      1.24    atatat 		       CTLFLAG_PERMANENT,
    477      1.26    atatat 		       CTLTYPE_STRUCT, "boottime",
    478      1.26    atatat 		       SYSCTL_DESCR("System boot time"),
    479       1.1    atatat 		       NULL, 0, &boottime, sizeof(boottime),
    480       1.1    atatat 		       CTL_KERN, KERN_BOOTTIME, CTL_EOL);
    481      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    482      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    483      1.26    atatat 		       CTLTYPE_STRING, "domainname",
    484      1.26    atatat 		       SYSCTL_DESCR("YP domain name"),
    485      1.17    atatat 		       sysctl_setlen, 0, &domainname, MAXHOSTNAMELEN,
    486       1.1    atatat 		       CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
    487      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    488      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    489      1.26    atatat 		       CTLTYPE_INT, "maxpartitions",
    490      1.26    atatat 		       SYSCTL_DESCR("Maximum number of partitions allowed per "
    491      1.26    atatat 				    "disk"),
    492       1.1    atatat 		       NULL, MAXPARTITIONS, NULL, 0,
    493       1.1    atatat 		       CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
    494      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    495      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    496      1.26    atatat 		       CTLTYPE_INT, "rawpartition",
    497      1.26    atatat 		       SYSCTL_DESCR("Raw partition of a disk"),
    498       1.1    atatat 		       NULL, RAW_PART, NULL, 0,
    499       1.1    atatat 		       CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
    500      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    501      1.24    atatat 		       CTLFLAG_PERMANENT,
    502       1.1    atatat 		       CTLTYPE_STRUCT, "timex", NULL,
    503       1.1    atatat 		       sysctl_notavail, 0, NULL, 0,
    504       1.1    atatat 		       CTL_KERN, KERN_TIMEX, CTL_EOL);
    505      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    506      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    507      1.26    atatat 		       CTLTYPE_INT, "autonicetime",
    508      1.26    atatat 		       SYSCTL_DESCR("CPU clock seconds before non-root "
    509      1.26    atatat 				    "process priority is lowered"),
    510       1.1    atatat 		       sysctl_kern_autonice, 0, &autonicetime, 0,
    511       1.1    atatat 		       CTL_KERN, KERN_AUTONICETIME, CTL_EOL);
    512      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    513      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    514      1.26    atatat 		       CTLTYPE_INT, "autoniceval",
    515      1.26    atatat 		       SYSCTL_DESCR("Automatic reniced non-root process "
    516      1.26    atatat 				    "priority"),
    517       1.1    atatat 		       sysctl_kern_autonice, 0, &autoniceval, 0,
    518       1.1    atatat 		       CTL_KERN, KERN_AUTONICEVAL, CTL_EOL);
    519      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    520      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    521      1.26    atatat 		       CTLTYPE_INT, "rtc_offset",
    522      1.26    atatat 		       SYSCTL_DESCR("Offset of real time clock from UTC in "
    523      1.26    atatat 				    "minutes"),
    524      1.14    martin 		       sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
    525       1.1    atatat 		       CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
    526      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    527      1.24    atatat 		       CTLFLAG_PERMANENT,
    528      1.26    atatat 		       CTLTYPE_STRING, "root_device",
    529      1.26    atatat 		       SYSCTL_DESCR("Name of the root device"),
    530       1.1    atatat 		       sysctl_root_device, 0, NULL, 0,
    531       1.1    atatat 		       CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
    532      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    533      1.24    atatat 		       CTLFLAG_PERMANENT,
    534      1.26    atatat 		       CTLTYPE_INT, "msgbufsize",
    535      1.26    atatat 		       SYSCTL_DESCR("Size of the kernel message buffer"),
    536      1.31    atatat 		       sysctl_msgbuf, 0, NULL, 0,
    537       1.1    atatat 		       CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
    538      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    539      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    540      1.26    atatat 		       CTLTYPE_INT, "fsync",
    541      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b File "
    542      1.26    atatat 				    "Synchronization Option is available on "
    543      1.26    atatat 				    "this system"),
    544       1.1    atatat 		       NULL, 1, NULL, 0,
    545       1.1    atatat 		       CTL_KERN, KERN_FSYNC, CTL_EOL);
    546      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    547  1.81.4.7        ad 		       CTLFLAG_PERMANENT,
    548  1.81.4.7        ad 		       CTLTYPE_NODE, "ipc",
    549  1.81.4.7        ad 		       SYSCTL_DESCR("SysV IPC options"),
    550  1.81.4.7        ad 		       NULL, 0, NULL, 0,
    551  1.81.4.7        ad 		       CTL_KERN, KERN_SYSVIPC, CTL_EOL);
    552  1.81.4.7        ad 	sysctl_createv(clog, 0, NULL, NULL,
    553      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    554      1.26    atatat 		       CTLTYPE_INT, "sysvmsg",
    555      1.26    atatat 		       SYSCTL_DESCR("System V style message support available"),
    556      1.26    atatat 		       NULL,
    557       1.1    atatat #ifdef SYSVMSG
    558       1.1    atatat 		       1,
    559       1.1    atatat #else /* SYSVMSG */
    560       1.1    atatat 		       0,
    561       1.1    atatat #endif /* SYSVMSG */
    562  1.81.4.7        ad 		       NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, CTL_EOL);
    563      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    564      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    565      1.26    atatat 		       CTLTYPE_INT, "sysvsem",
    566      1.26    atatat 		       SYSCTL_DESCR("System V style semaphore support "
    567      1.26    atatat 				    "available"), NULL,
    568       1.1    atatat #ifdef SYSVSEM
    569       1.1    atatat 		       1,
    570       1.1    atatat #else /* SYSVSEM */
    571       1.1    atatat 		       0,
    572       1.1    atatat #endif /* SYSVSEM */
    573  1.81.4.7        ad 		       NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
    574      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    575      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    576      1.26    atatat 		       CTLTYPE_INT, "sysvshm",
    577      1.26    atatat 		       SYSCTL_DESCR("System V style shared memory support "
    578      1.26    atatat 				    "available"), NULL,
    579       1.1    atatat #ifdef SYSVSHM
    580       1.1    atatat 		       1,
    581       1.1    atatat #else /* SYSVSHM */
    582       1.1    atatat 		       0,
    583       1.1    atatat #endif /* SYSVSHM */
    584  1.81.4.7        ad 		       NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
    585      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    586      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    587      1.26    atatat 		       CTLTYPE_INT, "synchronized_io",
    588      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Synchronized "
    589      1.26    atatat 				    "I/O Option is available on this system"),
    590       1.1    atatat 		       NULL, 1, NULL, 0,
    591       1.1    atatat 		       CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
    592      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    593      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    594      1.26    atatat 		       CTLTYPE_INT, "iov_max",
    595      1.26    atatat 		       SYSCTL_DESCR("Maximum number of iovec structures per "
    596      1.26    atatat 				    "process"),
    597       1.1    atatat 		       NULL, IOV_MAX, NULL, 0,
    598       1.1    atatat 		       CTL_KERN, KERN_IOV_MAX, CTL_EOL);
    599      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    600      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    601      1.26    atatat 		       CTLTYPE_INT, "mapped_files",
    602      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Memory Mapped "
    603      1.26    atatat 				    "Files Option is available on this system"),
    604       1.1    atatat 		       NULL, 1, NULL, 0,
    605       1.1    atatat 		       CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
    606      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    607      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    608      1.26    atatat 		       CTLTYPE_INT, "memlock",
    609      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Process Memory "
    610      1.26    atatat 				    "Locking Option is available on this "
    611      1.26    atatat 				    "system"),
    612       1.1    atatat 		       NULL, 1, NULL, 0,
    613       1.1    atatat 		       CTL_KERN, KERN_MEMLOCK, CTL_EOL);
    614      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    615      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    616      1.26    atatat 		       CTLTYPE_INT, "memlock_range",
    617      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Range Memory "
    618      1.26    atatat 				    "Locking Option is available on this "
    619      1.26    atatat 				    "system"),
    620       1.1    atatat 		       NULL, 1, NULL, 0,
    621       1.1    atatat 		       CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
    622      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    623      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    624      1.26    atatat 		       CTLTYPE_INT, "memory_protection",
    625      1.26    atatat 		       SYSCTL_DESCR("Whether the POSIX 1003.1b Memory "
    626      1.26    atatat 				    "Protection Option is available on this "
    627      1.26    atatat 				    "system"),
    628       1.1    atatat 		       NULL, 1, NULL, 0,
    629       1.1    atatat 		       CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
    630      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    631      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    632      1.26    atatat 		       CTLTYPE_INT, "login_name_max",
    633      1.26    atatat 		       SYSCTL_DESCR("Maximum login name length"),
    634       1.1    atatat 		       NULL, LOGIN_NAME_MAX, NULL, 0,
    635       1.1    atatat 		       CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
    636      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    637      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    638      1.26    atatat 		       CTLTYPE_STRING, "defcorename",
    639      1.26    atatat 		       SYSCTL_DESCR("Default core file name"),
    640       1.1    atatat 		       sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
    641       1.1    atatat 		       CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
    642      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    643      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    644      1.26    atatat 		       CTLTYPE_INT, "logsigexit",
    645      1.26    atatat 		       SYSCTL_DESCR("Log process exit when caused by signals"),
    646       1.1    atatat 		       NULL, 0, &kern_logsigexit, 0,
    647       1.1    atatat 		       CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
    648      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    649      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    650      1.26    atatat 		       CTLTYPE_INT, "fscale",
    651      1.26    atatat 		       SYSCTL_DESCR("Kernel fixed-point scale factor"),
    652       1.1    atatat 		       NULL, FSCALE, NULL, 0,
    653       1.1    atatat 		       CTL_KERN, KERN_FSCALE, CTL_EOL);
    654      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    655      1.24    atatat 		       CTLFLAG_PERMANENT,
    656      1.26    atatat 		       CTLTYPE_INT, "ccpu",
    657      1.26    atatat 		       SYSCTL_DESCR("Scheduler exponential decay value"),
    658       1.1    atatat 		       NULL, 0, &ccpu, 0,
    659       1.1    atatat 		       CTL_KERN, KERN_CCPU, CTL_EOL);
    660      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    661      1.24    atatat 		       CTLFLAG_PERMANENT,
    662      1.26    atatat 		       CTLTYPE_STRUCT, "cp_time",
    663      1.26    atatat 		       SYSCTL_DESCR("Clock ticks spent in different CPU states"),
    664       1.1    atatat 		       sysctl_kern_cptime, 0, NULL, 0,
    665       1.1    atatat 		       CTL_KERN, KERN_CP_TIME, CTL_EOL);
    666      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    667      1.24    atatat 		       CTLFLAG_PERMANENT,
    668      1.26    atatat 		       CTLTYPE_INT, "msgbuf",
    669      1.26    atatat 		       SYSCTL_DESCR("Kernel message buffer"),
    670       1.1    atatat 		       sysctl_msgbuf, 0, NULL, 0,
    671       1.1    atatat 		       CTL_KERN, KERN_MSGBUF, CTL_EOL);
    672      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    673      1.24    atatat 		       CTLFLAG_PERMANENT,
    674      1.26    atatat 		       CTLTYPE_STRUCT, "consdev",
    675      1.26    atatat 		       SYSCTL_DESCR("Console device"),
    676       1.1    atatat 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    677       1.1    atatat 		       CTL_KERN, KERN_CONSDEV, CTL_EOL);
    678       1.1    atatat #if NPTY > 0
    679      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    680      1.24    atatat 		       CTLFLAG_PERMANENT,
    681      1.26    atatat 		       CTLTYPE_INT, "maxptys",
    682      1.26    atatat 		       SYSCTL_DESCR("Maximum number of pseudo-ttys"),
    683       1.1    atatat 		       sysctl_kern_maxptys, 0, NULL, 0,
    684       1.1    atatat 		       CTL_KERN, KERN_MAXPTYS, CTL_EOL);
    685       1.1    atatat #endif /* NPTY > 0 */
    686      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    687      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    688      1.26    atatat 		       CTLTYPE_INT, "maxphys",
    689      1.26    atatat 		       SYSCTL_DESCR("Maximum raw I/O transfer size"),
    690       1.1    atatat 		       NULL, MAXPHYS, NULL, 0,
    691       1.1    atatat 		       CTL_KERN, KERN_MAXPHYS, CTL_EOL);
    692      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    693      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    694      1.26    atatat 		       CTLTYPE_INT, "sbmax",
    695      1.26    atatat 		       SYSCTL_DESCR("Maximum socket buffer size"),
    696       1.1    atatat 		       sysctl_kern_sbmax, 0, NULL, 0,
    697       1.1    atatat 		       CTL_KERN, KERN_SBMAX, CTL_EOL);
    698      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    699      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    700      1.26    atatat 		       CTLTYPE_INT, "monotonic_clock",
    701      1.26    atatat 		       SYSCTL_DESCR("Implementation version of the POSIX "
    702      1.26    atatat 				    "1003.1b Monotonic Clock Option"),
    703       1.1    atatat 		       /* XXX _POSIX_VERSION */
    704       1.1    atatat 		       NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
    705       1.1    atatat 		       CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
    706      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    707      1.24    atatat 		       CTLFLAG_PERMANENT,
    708      1.26    atatat 		       CTLTYPE_INT, "urandom",
    709      1.26    atatat 		       SYSCTL_DESCR("Random integer value"),
    710       1.1    atatat 		       sysctl_kern_urnd, 0, NULL, 0,
    711       1.1    atatat 		       CTL_KERN, KERN_URND, CTL_EOL);
    712      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    713  1.81.4.5        ad 		       CTLFLAG_PERMANENT,
    714  1.81.4.5        ad 		       CTLTYPE_INT, "arandom",
    715  1.81.4.5        ad 		       SYSCTL_DESCR("n bytes of random data"),
    716  1.81.4.5        ad 		       sysctl_kern_arnd, 0, NULL, 0,
    717  1.81.4.5        ad 		       CTL_KERN, KERN_ARND, CTL_EOL);
    718  1.81.4.5        ad 	sysctl_createv(clog, 0, NULL, NULL,
    719      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    720      1.26    atatat 		       CTLTYPE_INT, "labelsector",
    721      1.26    atatat 		       SYSCTL_DESCR("Sector number containing the disklabel"),
    722       1.1    atatat 		       NULL, LABELSECTOR, NULL, 0,
    723       1.1    atatat 		       CTL_KERN, KERN_LABELSECTOR, CTL_EOL);
    724      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    725      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    726      1.26    atatat 		       CTLTYPE_INT, "labeloffset",
    727      1.26    atatat 		       SYSCTL_DESCR("Offset of the disklabel within the "
    728      1.26    atatat 				    "sector"),
    729       1.1    atatat 		       NULL, LABELOFFSET, NULL, 0,
    730       1.1    atatat 		       CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
    731      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    732      1.24    atatat 		       CTLFLAG_PERMANENT,
    733      1.26    atatat 		       CTLTYPE_NODE, "lwp",
    734      1.26    atatat 		       SYSCTL_DESCR("System-wide LWP information"),
    735       1.1    atatat 		       sysctl_kern_lwp, 0, NULL, 0,
    736       1.1    atatat 		       CTL_KERN, KERN_LWP, CTL_EOL);
    737      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    738      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    739      1.26    atatat 		       CTLTYPE_INT, "forkfsleep",
    740      1.26    atatat 		       SYSCTL_DESCR("Milliseconds to sleep on fork failure due "
    741      1.26    atatat 				    "to process limits"),
    742       1.1    atatat 		       sysctl_kern_forkfsleep, 0, NULL, 0,
    743       1.1    atatat 		       CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
    744      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    745      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    746      1.26    atatat 		       CTLTYPE_INT, "posix_threads",
    747      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    748      1.26    atatat 				    "Threads option to which the system "
    749      1.26    atatat 				    "attempts to conform"),
    750       1.1    atatat 		       /* XXX _POSIX_VERSION */
    751       1.1    atatat 		       NULL, _POSIX_THREADS, NULL, 0,
    752       1.1    atatat 		       CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
    753      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    754      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    755      1.26    atatat 		       CTLTYPE_INT, "posix_semaphores",
    756      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    757      1.26    atatat 				    "Semaphores option to which the system "
    758      1.26    atatat 				    "attempts to conform"), NULL,
    759       1.1    atatat #ifdef P1003_1B_SEMAPHORE
    760       1.1    atatat 		       200112,
    761       1.1    atatat #else /* P1003_1B_SEMAPHORE */
    762       1.1    atatat 		       0,
    763       1.1    atatat #endif /* P1003_1B_SEMAPHORE */
    764       1.1    atatat 		       NULL, 0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
    765      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    766      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    767      1.26    atatat 		       CTLTYPE_INT, "posix_barriers",
    768      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    769      1.26    atatat 				    "Barriers option to which the system "
    770      1.26    atatat 				    "attempts to conform"),
    771       1.1    atatat 		       /* XXX _POSIX_VERSION */
    772       1.1    atatat 		       NULL, _POSIX_BARRIERS, NULL, 0,
    773       1.1    atatat 		       CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
    774      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    775      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    776      1.26    atatat 		       CTLTYPE_INT, "posix_timers",
    777      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    778      1.26    atatat 				    "Timers option to which the system "
    779      1.26    atatat 				    "attempts to conform"),
    780       1.1    atatat 		       /* XXX _POSIX_VERSION */
    781       1.1    atatat 		       NULL, _POSIX_TIMERS, NULL, 0,
    782       1.1    atatat 		       CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
    783      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    784      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    785      1.26    atatat 		       CTLTYPE_INT, "posix_spin_locks",
    786      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
    787      1.26    atatat 				    "Locks option to which the system attempts "
    788      1.26    atatat 				    "to conform"),
    789       1.1    atatat 		       /* XXX _POSIX_VERSION */
    790       1.1    atatat 		       NULL, _POSIX_SPIN_LOCKS, NULL, 0,
    791       1.1    atatat 		       CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
    792      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    793      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    794      1.26    atatat 		       CTLTYPE_INT, "posix_reader_writer_locks",
    795      1.26    atatat 		       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
    796      1.26    atatat 				    "Read-Write Locks option to which the "
    797      1.26    atatat 				    "system attempts to conform"),
    798       1.1    atatat 		       /* XXX _POSIX_VERSION */
    799       1.1    atatat 		       NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
    800       1.1    atatat 		       CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
    801      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    802      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    803      1.26    atatat 		       CTLTYPE_INT, "dump_on_panic",
    804      1.26    atatat 		       SYSCTL_DESCR("Perform a crash dump on system panic"),
    805       1.1    atatat 		       NULL, 0, &dumponpanic, 0,
    806       1.1    atatat 		       CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
    807      1.64       erh #ifdef DIAGNOSTIC
    808      1.64       erh 	sysctl_createv(clog, 0, NULL, NULL,
    809      1.64       erh 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    810      1.64       erh 		       CTLTYPE_INT, "panic_now",
    811      1.64       erh 		       SYSCTL_DESCR("Trigger a panic"),
    812      1.64       erh 		       sysctl_kern_trigger_panic, 0, NULL, 0,
    813      1.64       erh 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    814      1.64       erh #endif
    815      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    816      1.24    atatat 		       CTLFLAG_PERMANENT,
    817      1.26    atatat 		       CTLTYPE_INT, "root_partition",
    818      1.26    atatat 		       SYSCTL_DESCR("Root partition on the root device"),
    819       1.1    atatat 		       sysctl_kern_root_partition, 0, NULL, 0,
    820       1.1    atatat 		       CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
    821      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    822      1.24    atatat 		       CTLFLAG_PERMANENT,
    823      1.26    atatat 		       CTLTYPE_STRUCT, "drivers",
    824      1.26    atatat 		       SYSCTL_DESCR("List of all drivers with block and "
    825      1.26    atatat 				    "character device numbers"),
    826       1.1    atatat 		       sysctl_kern_drivers, 0, NULL, 0,
    827       1.1    atatat 		       CTL_KERN, KERN_DRIVERS, CTL_EOL);
    828      1.34    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    829      1.34    atatat 		       CTLFLAG_PERMANENT,
    830      1.36    atatat 		       CTLTYPE_STRUCT, "file2",
    831      1.34    atatat 		       SYSCTL_DESCR("System open file table"),
    832      1.34    atatat 		       sysctl_kern_file2, 0, NULL, 0,
    833      1.34    atatat 		       CTL_KERN, KERN_FILE2, CTL_EOL);
    834      1.45  christos 	sysctl_createv(clog, 0, NULL, NULL,
    835      1.45  christos 		       CTLFLAG_PERMANENT,
    836      1.45  christos 		       CTLTYPE_STRUCT, "cp_id",
    837      1.45  christos 		       SYSCTL_DESCR("Mapping of CPU number to CPU id"),
    838      1.45  christos 		       sysctl_kern_cpid, 0, NULL, 0,
    839      1.45  christos 		       CTL_KERN, KERN_CP_ID, CTL_EOL);
    840      1.75      elad 	sysctl_createv(clog, 0, NULL, &rnode,
    841      1.75      elad 		       CTLFLAG_PERMANENT,
    842      1.75      elad 		       CTLTYPE_NODE, "coredump",
    843      1.75      elad 		       SYSCTL_DESCR("Coredump settings."),
    844      1.75      elad 		       NULL, 0, NULL, 0,
    845      1.75      elad 		       CTL_KERN, CTL_CREATE, CTL_EOL);
    846      1.75      elad 	sysctl_createv(clog, 0, &rnode, &rnode,
    847      1.75      elad 		       CTLFLAG_PERMANENT,
    848      1.75      elad 		       CTLTYPE_NODE, "setid",
    849      1.75      elad 		       SYSCTL_DESCR("Set-id processes' coredump settings."),
    850      1.75      elad 		       NULL, 0, NULL, 0,
    851      1.75      elad 		       CTL_CREATE, CTL_EOL);
    852      1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    853      1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    854      1.75      elad 		       CTLTYPE_INT, "dump",
    855      1.75      elad 		       SYSCTL_DESCR("Allow set-id processes to dump core."),
    856      1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_dump,
    857      1.75      elad 		       sizeof(security_setidcore_dump),
    858      1.75      elad 		       CTL_CREATE, CTL_EOL);
    859      1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    860      1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    861      1.75      elad 		       CTLTYPE_STRING, "path",
    862      1.75      elad 		       SYSCTL_DESCR("Path pattern for set-id coredumps."),
    863      1.75      elad 		       sysctl_security_setidcorename, 0,
    864      1.75      elad 		       &security_setidcore_path,
    865      1.75      elad 		       sizeof(security_setidcore_path),
    866      1.75      elad 		       CTL_CREATE, CTL_EOL);
    867      1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    868      1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    869      1.75      elad 		       CTLTYPE_INT, "owner",
    870      1.75      elad 		       SYSCTL_DESCR("Owner id for set-id processes' cores."),
    871      1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_owner,
    872      1.75      elad 		       0,
    873      1.75      elad 		       CTL_CREATE, CTL_EOL);
    874      1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    875      1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    876      1.75      elad 		       CTLTYPE_INT, "group",
    877      1.75      elad 		       SYSCTL_DESCR("Group id for set-id processes' cores."),
    878      1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_group,
    879      1.75      elad 		       0,
    880      1.75      elad 		       CTL_CREATE, CTL_EOL);
    881      1.75      elad 	sysctl_createv(clog, 0, &rnode, NULL,
    882      1.75      elad 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    883      1.75      elad 		       CTLTYPE_INT, "mode",
    884      1.75      elad 		       SYSCTL_DESCR("Mode for set-id processes' cores."),
    885      1.75      elad 		       sysctl_security_setidcore, 0, &security_setidcore_mode,
    886      1.75      elad 		       0,
    887      1.75      elad 		       CTL_CREATE, CTL_EOL);
    888       1.1    atatat }
    889       1.1    atatat 
    890       1.1    atatat SYSCTL_SETUP(sysctl_kern_proc_setup,
    891       1.1    atatat 	     "sysctl kern.proc/proc2/proc_args subtree setup")
    892       1.1    atatat {
    893       1.1    atatat 
    894      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    895      1.24    atatat 		       CTLFLAG_PERMANENT,
    896       1.1    atatat 		       CTLTYPE_NODE, "kern", NULL,
    897       1.1    atatat 		       NULL, 0, NULL, 0,
    898       1.1    atatat 		       CTL_KERN, CTL_EOL);
    899       1.1    atatat 
    900      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    901      1.24    atatat 		       CTLFLAG_PERMANENT,
    902      1.26    atatat 		       CTLTYPE_NODE, "proc",
    903      1.26    atatat 		       SYSCTL_DESCR("System-wide process information"),
    904       1.1    atatat 		       sysctl_doeproc, 0, NULL, 0,
    905       1.1    atatat 		       CTL_KERN, KERN_PROC, CTL_EOL);
    906      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    907      1.24    atatat 		       CTLFLAG_PERMANENT,
    908      1.26    atatat 		       CTLTYPE_NODE, "proc2",
    909      1.26    atatat 		       SYSCTL_DESCR("Machine-independent process information"),
    910       1.1    atatat 		       sysctl_doeproc, 0, NULL, 0,
    911       1.1    atatat 		       CTL_KERN, KERN_PROC2, CTL_EOL);
    912      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    913      1.24    atatat 		       CTLFLAG_PERMANENT,
    914      1.26    atatat 		       CTLTYPE_NODE, "proc_args",
    915      1.26    atatat 		       SYSCTL_DESCR("Process argument information"),
    916       1.1    atatat 		       sysctl_kern_proc_args, 0, NULL, 0,
    917       1.1    atatat 		       CTL_KERN, KERN_PROC_ARGS, CTL_EOL);
    918       1.1    atatat 
    919       1.1    atatat 	/*
    920       1.1    atatat 	  "nodes" under these:
    921       1.1    atatat 
    922       1.1    atatat 	  KERN_PROC_ALL
    923       1.1    atatat 	  KERN_PROC_PID pid
    924       1.1    atatat 	  KERN_PROC_PGRP pgrp
    925       1.1    atatat 	  KERN_PROC_SESSION sess
    926       1.1    atatat 	  KERN_PROC_TTY tty
    927       1.1    atatat 	  KERN_PROC_UID uid
    928       1.1    atatat 	  KERN_PROC_RUID uid
    929       1.1    atatat 	  KERN_PROC_GID gid
    930       1.1    atatat 	  KERN_PROC_RGID gid
    931       1.1    atatat 
    932       1.1    atatat 	  all in all, probably not worth the effort...
    933       1.1    atatat 	*/
    934       1.1    atatat }
    935       1.1    atatat 
    936       1.1    atatat SYSCTL_SETUP(sysctl_hw_setup, "sysctl hw subtree setup")
    937       1.1    atatat {
    938       1.1    atatat 	u_int u;
    939       1.1    atatat 	u_quad_t q;
    940       1.1    atatat 
    941      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    942      1.24    atatat 		       CTLFLAG_PERMANENT,
    943       1.1    atatat 		       CTLTYPE_NODE, "hw", NULL,
    944       1.1    atatat 		       NULL, 0, NULL, 0,
    945       1.1    atatat 		       CTL_HW, CTL_EOL);
    946       1.1    atatat 
    947      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    948      1.24    atatat 		       CTLFLAG_PERMANENT,
    949      1.26    atatat 		       CTLTYPE_STRING, "machine",
    950      1.26    atatat 		       SYSCTL_DESCR("Machine class"),
    951       1.1    atatat 		       NULL, 0, machine, 0,
    952       1.1    atatat 		       CTL_HW, HW_MACHINE, CTL_EOL);
    953      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    954      1.24    atatat 		       CTLFLAG_PERMANENT,
    955      1.26    atatat 		       CTLTYPE_STRING, "model",
    956      1.26    atatat 		       SYSCTL_DESCR("Machine model"),
    957       1.1    atatat 		       NULL, 0, cpu_model, 0,
    958       1.1    atatat 		       CTL_HW, HW_MODEL, CTL_EOL);
    959      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    960      1.24    atatat 		       CTLFLAG_PERMANENT,
    961      1.26    atatat 		       CTLTYPE_INT, "ncpu",
    962      1.26    atatat 		       SYSCTL_DESCR("Number of active CPUs"),
    963       1.3    martin 		       sysctl_hw_ncpu, 0, NULL, 0,
    964       1.1    atatat 		       CTL_HW, HW_NCPU, CTL_EOL);
    965      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    966      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    967      1.26    atatat 		       CTLTYPE_INT, "byteorder",
    968      1.26    atatat 		       SYSCTL_DESCR("System byte order"),
    969       1.1    atatat 		       NULL, BYTE_ORDER, NULL, 0,
    970       1.1    atatat 		       CTL_HW, HW_BYTEORDER, CTL_EOL);
    971       1.1    atatat 	u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
    972       1.1    atatat 		UINT_MAX : physmem * PAGE_SIZE;
    973      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    974      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    975      1.26    atatat 		       CTLTYPE_INT, "physmem",
    976      1.26    atatat 		       SYSCTL_DESCR("Bytes of physical memory"),
    977       1.1    atatat 		       NULL, u, NULL, 0,
    978       1.1    atatat 		       CTL_HW, HW_PHYSMEM, CTL_EOL);
    979      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    980      1.24    atatat 		       CTLFLAG_PERMANENT,
    981      1.26    atatat 		       CTLTYPE_INT, "usermem",
    982      1.26    atatat 		       SYSCTL_DESCR("Bytes of non-kernel memory"),
    983       1.1    atatat 		       sysctl_hw_usermem, 0, NULL, 0,
    984       1.1    atatat 		       CTL_HW, HW_USERMEM, CTL_EOL);
    985      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    986      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    987      1.26    atatat 		       CTLTYPE_INT, "pagesize",
    988      1.26    atatat 		       SYSCTL_DESCR("Software page size"),
    989       1.1    atatat 		       NULL, PAGE_SIZE, NULL, 0,
    990       1.1    atatat 		       CTL_HW, HW_PAGESIZE, CTL_EOL);
    991      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    992      1.24    atatat 		       CTLFLAG_PERMANENT,
    993      1.26    atatat 		       CTLTYPE_STRING, "machine_arch",
    994      1.26    atatat 		       SYSCTL_DESCR("Machine CPU class"),
    995       1.1    atatat 		       NULL, 0, machine_arch, 0,
    996       1.1    atatat 		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
    997      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    998      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    999      1.26    atatat 		       CTLTYPE_INT, "alignbytes",
   1000      1.26    atatat 		       SYSCTL_DESCR("Alignment constraint for all possible "
   1001      1.26    atatat 				    "data types"),
   1002       1.1    atatat 		       NULL, ALIGNBYTES, NULL, 0,
   1003       1.1    atatat 		       CTL_HW, HW_ALIGNBYTES, CTL_EOL);
   1004      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1005      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
   1006      1.26    atatat 		       CTLTYPE_STRING, "cnmagic",
   1007      1.26    atatat 		       SYSCTL_DESCR("Console magic key sequence"),
   1008       1.1    atatat 		       sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
   1009       1.1    atatat 		       CTL_HW, HW_CNMAGIC, CTL_EOL);
   1010       1.1    atatat 	q = (u_quad_t)physmem * PAGE_SIZE;
   1011      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1012      1.24    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
   1013      1.26    atatat 		       CTLTYPE_QUAD, "physmem64",
   1014      1.26    atatat 		       SYSCTL_DESCR("Bytes of physical memory"),
   1015       1.1    atatat 		       NULL, q, NULL, 0,
   1016       1.1    atatat 		       CTL_HW, HW_PHYSMEM64, CTL_EOL);
   1017      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1018      1.24    atatat 		       CTLFLAG_PERMANENT,
   1019      1.26    atatat 		       CTLTYPE_QUAD, "usermem64",
   1020      1.26    atatat 		       SYSCTL_DESCR("Bytes of non-kernel memory"),
   1021       1.1    atatat 		       sysctl_hw_usermem, 0, NULL, 0,
   1022       1.1    atatat 		       CTL_HW, HW_USERMEM64, CTL_EOL);
   1023       1.1    atatat }
   1024       1.1    atatat 
   1025       1.1    atatat #ifdef DEBUG
   1026       1.1    atatat /*
   1027       1.1    atatat  * Debugging related system variables.
   1028       1.1    atatat  */
   1029       1.1    atatat struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
   1030       1.1    atatat struct ctldebug debug5, debug6, debug7, debug8, debug9;
   1031       1.1    atatat struct ctldebug debug10, debug11, debug12, debug13, debug14;
   1032       1.1    atatat struct ctldebug debug15, debug16, debug17, debug18, debug19;
   1033       1.1    atatat static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
   1034       1.1    atatat 	&debug0, &debug1, &debug2, &debug3, &debug4,
   1035       1.1    atatat 	&debug5, &debug6, &debug7, &debug8, &debug9,
   1036       1.1    atatat 	&debug10, &debug11, &debug12, &debug13, &debug14,
   1037       1.1    atatat 	&debug15, &debug16, &debug17, &debug18, &debug19,
   1038       1.1    atatat };
   1039       1.1    atatat 
   1040       1.1    atatat /*
   1041       1.1    atatat  * this setup routine is a replacement for debug_sysctl()
   1042       1.1    atatat  *
   1043       1.1    atatat  * note that it creates several nodes per defined debug variable
   1044       1.1    atatat  */
   1045       1.1    atatat SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
   1046       1.1    atatat {
   1047       1.1    atatat 	struct ctldebug *cdp;
   1048       1.1    atatat 	char nodename[20];
   1049       1.1    atatat 	int i;
   1050       1.1    atatat 
   1051       1.1    atatat 	/*
   1052       1.1    atatat 	 * two ways here:
   1053       1.1    atatat 	 *
   1054       1.1    atatat 	 * the "old" way (debug.name -> value) which was emulated by
   1055       1.1    atatat 	 * the sysctl(8) binary
   1056       1.1    atatat 	 *
   1057       1.1    atatat 	 * the new way, which the sysctl(8) binary was actually using
   1058       1.1    atatat 
   1059       1.1    atatat 	 node	debug
   1060       1.1    atatat 	 node	debug.0
   1061       1.1    atatat 	 string	debug.0.name
   1062       1.1    atatat 	 int	debug.0.value
   1063       1.1    atatat 	 int	debug.name
   1064       1.1    atatat 
   1065       1.1    atatat 	 */
   1066       1.1    atatat 
   1067      1.24    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1068      1.24    atatat 		       CTLFLAG_PERMANENT,
   1069       1.1    atatat 		       CTLTYPE_NODE, "debug", NULL,
   1070       1.1    atatat 		       NULL, 0, NULL, 0,
   1071       1.1    atatat 		       CTL_DEBUG, CTL_EOL);
   1072       1.1    atatat 
   1073       1.1    atatat 	for (i = 0; i < CTL_DEBUG_MAXID; i++) {
   1074       1.1    atatat 		cdp = debugvars[i];
   1075       1.1    atatat 		if (cdp->debugname == NULL || cdp->debugvar == NULL)
   1076       1.1    atatat 			continue;
   1077       1.1    atatat 
   1078       1.1    atatat 		snprintf(nodename, sizeof(nodename), "debug%d", i);
   1079      1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
   1080      1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
   1081       1.1    atatat 			       CTLTYPE_NODE, nodename, NULL,
   1082       1.1    atatat 			       NULL, 0, NULL, 0,
   1083       1.1    atatat 			       CTL_DEBUG, i, CTL_EOL);
   1084      1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
   1085      1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
   1086       1.1    atatat 			       CTLTYPE_STRING, "name", NULL,
   1087      1.40  christos 			       /*XXXUNCONST*/
   1088      1.40  christos 			       NULL, 0, __UNCONST(cdp->debugname), 0,
   1089       1.1    atatat 			       CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
   1090      1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
   1091      1.24    atatat 			       CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
   1092       1.1    atatat 			       CTLTYPE_INT, "value", NULL,
   1093       1.1    atatat 			       NULL, 0, cdp->debugvar, 0,
   1094       1.1    atatat 			       CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
   1095      1.24    atatat 		sysctl_createv(clog, 0, NULL, NULL,
   1096      1.24    atatat 			       CTLFLAG_PERMANENT,
   1097       1.1    atatat 			       CTLTYPE_INT, cdp->debugname, NULL,
   1098       1.1    atatat 			       NULL, 0, cdp->debugvar, 0,
   1099       1.1    atatat 			       CTL_DEBUG, CTL_CREATE, CTL_EOL);
   1100       1.1    atatat 	}
   1101       1.1    atatat }
   1102       1.1    atatat #endif /* DEBUG */
   1103       1.1    atatat 
   1104       1.1    atatat /*
   1105       1.1    atatat  * ********************************************************************
   1106       1.1    atatat  * section 2: private node-specific helper routines.
   1107       1.1    atatat  * ********************************************************************
   1108       1.1    atatat  */
   1109       1.1    atatat 
   1110      1.64       erh #ifdef DIAGNOSTIC
   1111      1.64       erh static int
   1112      1.64       erh sysctl_kern_trigger_panic(SYSCTLFN_ARGS)
   1113      1.64       erh {
   1114      1.64       erh 	int newtrig, error;
   1115      1.64       erh 	struct sysctlnode node;
   1116      1.64       erh 
   1117      1.64       erh 	newtrig = 0;
   1118      1.64       erh 	node = *rnode;
   1119      1.64       erh 	node.sysctl_data = &newtrig;
   1120      1.64       erh 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1121      1.64       erh 	if (error || newp == NULL)
   1122      1.64       erh 		return (error);
   1123      1.64       erh 
   1124      1.64       erh 	if (newtrig != 0)
   1125      1.64       erh 		panic("Panic triggered");
   1126      1.64       erh 
   1127      1.64       erh 	return (error);
   1128      1.64       erh }
   1129      1.64       erh #endif
   1130      1.64       erh 
   1131       1.1    atatat /*
   1132      1.13      yamt  * sysctl helper routine for kern.maxvnodes.  drain vnodes if
   1133      1.13      yamt  * new value is lower than desiredvnodes and then calls reinit
   1134       1.1    atatat  * routines that needs to adjust to the new value.
   1135       1.1    atatat  */
   1136       1.1    atatat static int
   1137       1.1    atatat sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
   1138       1.1    atatat {
   1139      1.12      yamt 	int error, new_vnodes, old_vnodes;
   1140       1.1    atatat 	struct sysctlnode node;
   1141       1.1    atatat 
   1142       1.1    atatat 	new_vnodes = desiredvnodes;
   1143       1.1    atatat 	node = *rnode;
   1144       1.1    atatat 	node.sysctl_data = &new_vnodes;
   1145       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1146       1.1    atatat 	if (error || newp == NULL)
   1147       1.1    atatat 		return (error);
   1148       1.1    atatat 
   1149      1.12      yamt 	old_vnodes = desiredvnodes;
   1150       1.1    atatat 	desiredvnodes = new_vnodes;
   1151      1.12      yamt 	if (new_vnodes < old_vnodes) {
   1152      1.58  christos 		error = vfs_drainvnodes(new_vnodes, l);
   1153      1.12      yamt 		if (error) {
   1154      1.12      yamt 			desiredvnodes = old_vnodes;
   1155      1.12      yamt 			return (error);
   1156      1.12      yamt 		}
   1157      1.12      yamt 	}
   1158       1.1    atatat 	vfs_reinit();
   1159       1.1    atatat 	nchreinit();
   1160       1.1    atatat 
   1161       1.1    atatat 	return (0);
   1162       1.1    atatat }
   1163       1.1    atatat 
   1164       1.1    atatat /*
   1165      1.14    martin  * sysctl helper routine for rtc_offset - set time after changes
   1166      1.14    martin  */
   1167      1.14    martin static int
   1168      1.14    martin sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
   1169      1.14    martin {
   1170      1.57  christos 	struct timespec ts, delta;
   1171      1.57  christos 	int error, new_rtc_offset;
   1172      1.14    martin 	struct sysctlnode node;
   1173      1.14    martin 
   1174      1.14    martin 	new_rtc_offset = rtc_offset;
   1175      1.14    martin 	node = *rnode;
   1176      1.14    martin 	node.sysctl_data = &new_rtc_offset;
   1177      1.14    martin 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1178      1.14    martin 	if (error || newp == NULL)
   1179      1.14    martin 		return (error);
   1180      1.14    martin 
   1181  1.81.4.5        ad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
   1182  1.81.4.5        ad 	    KAUTH_REQ_SYSTEM_TIME_RTCOFFSET,
   1183  1.81.4.5        ad 	    (void *)(u_long)new_rtc_offset, NULL, NULL))
   1184      1.14    martin 		return (EPERM);
   1185      1.14    martin 	if (rtc_offset == new_rtc_offset)
   1186      1.14    martin 		return (0);
   1187      1.14    martin 
   1188      1.14    martin 	/* if we change the offset, adjust the time */
   1189      1.57  christos 	nanotime(&ts);
   1190      1.57  christos 	delta.tv_sec = 60 * (new_rtc_offset - rtc_offset);
   1191      1.57  christos 	delta.tv_nsec = 0;
   1192      1.57  christos 	timespecadd(&ts, &delta, &ts);
   1193      1.14    martin 	rtc_offset = new_rtc_offset;
   1194      1.57  christos 	settime(l->l_proc, &ts);
   1195      1.14    martin 
   1196      1.14    martin 	return (0);
   1197      1.14    martin }
   1198      1.14    martin 
   1199      1.14    martin /*
   1200      1.52    simonb  * sysctl helper routine for kern.maxproc.  ensures that the new
   1201       1.1    atatat  * values are not too low or too high.
   1202       1.1    atatat  */
   1203       1.1    atatat static int
   1204       1.1    atatat sysctl_kern_maxproc(SYSCTLFN_ARGS)
   1205       1.1    atatat {
   1206       1.1    atatat 	int error, nmaxproc;
   1207       1.1    atatat 	struct sysctlnode node;
   1208       1.1    atatat 
   1209       1.1    atatat 	nmaxproc = maxproc;
   1210       1.1    atatat 	node = *rnode;
   1211       1.1    atatat 	node.sysctl_data = &nmaxproc;
   1212       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1213       1.1    atatat 	if (error || newp == NULL)
   1214       1.1    atatat 		return (error);
   1215       1.1    atatat 
   1216       1.1    atatat 	if (nmaxproc < 0 || nmaxproc >= PID_MAX)
   1217       1.1    atatat 		return (EINVAL);
   1218       1.1    atatat #ifdef __HAVE_CPU_MAXPROC
   1219       1.1    atatat 	if (nmaxproc > cpu_maxproc())
   1220       1.1    atatat 		return (EINVAL);
   1221       1.1    atatat #endif
   1222       1.1    atatat 	maxproc = nmaxproc;
   1223       1.1    atatat 
   1224       1.1    atatat 	return (0);
   1225       1.1    atatat }
   1226       1.1    atatat 
   1227       1.1    atatat /*
   1228       1.1    atatat  * sysctl helper function for kern.hostid.  the hostid is a long, but
   1229       1.1    atatat  * we export it as an int, so we need to give it a little help.
   1230       1.1    atatat  */
   1231       1.1    atatat static int
   1232       1.1    atatat sysctl_kern_hostid(SYSCTLFN_ARGS)
   1233       1.1    atatat {
   1234       1.1    atatat 	int error, inthostid;
   1235       1.1    atatat 	struct sysctlnode node;
   1236       1.1    atatat 
   1237      1.29    martin 	inthostid = hostid;  /* XXX assumes sizeof int <= sizeof long */
   1238       1.1    atatat 	node = *rnode;
   1239       1.1    atatat 	node.sysctl_data = &inthostid;
   1240       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1241       1.1    atatat 	if (error || newp == NULL)
   1242       1.1    atatat 		return (error);
   1243       1.1    atatat 
   1244      1.27    atatat 	hostid = (unsigned)inthostid;
   1245       1.1    atatat 
   1246       1.1    atatat 	return (0);
   1247       1.1    atatat }
   1248       1.1    atatat 
   1249       1.1    atatat /*
   1250      1.17    atatat  * sysctl helper function for kern.hostname and kern.domainnname.
   1251      1.17    atatat  * resets the relevant recorded length when the underlying name is
   1252      1.17    atatat  * changed.
   1253      1.15    martin  */
   1254      1.15    martin static int
   1255      1.17    atatat sysctl_setlen(SYSCTLFN_ARGS)
   1256      1.15    martin {
   1257      1.15    martin 	int error;
   1258      1.15    martin 
   1259      1.43    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(rnode));
   1260      1.15    martin 	if (error || newp == NULL)
   1261      1.15    martin 		return (error);
   1262      1.15    martin 
   1263      1.17    atatat 	switch (rnode->sysctl_num) {
   1264      1.17    atatat 	case KERN_HOSTNAME:
   1265      1.17    atatat 		hostnamelen = strlen((const char*)rnode->sysctl_data);
   1266      1.17    atatat 		break;
   1267      1.17    atatat 	case KERN_DOMAINNAME:
   1268      1.17    atatat 		domainnamelen = strlen((const char*)rnode->sysctl_data);
   1269      1.17    atatat 		break;
   1270      1.17    atatat 	}
   1271      1.17    atatat 
   1272      1.15    martin 	return (0);
   1273      1.15    martin }
   1274      1.15    martin 
   1275      1.15    martin /*
   1276       1.1    atatat  * sysctl helper routine for kern.clockrate.  assembles a struct on
   1277       1.1    atatat  * the fly to be returned to the caller.
   1278       1.1    atatat  */
   1279       1.1    atatat static int
   1280       1.1    atatat sysctl_kern_clockrate(SYSCTLFN_ARGS)
   1281       1.1    atatat {
   1282       1.1    atatat 	struct clockinfo clkinfo;
   1283       1.1    atatat 	struct sysctlnode node;
   1284       1.1    atatat 
   1285       1.1    atatat 	clkinfo.tick = tick;
   1286       1.1    atatat 	clkinfo.tickadj = tickadj;
   1287       1.1    atatat 	clkinfo.hz = hz;
   1288       1.1    atatat 	clkinfo.profhz = profhz;
   1289       1.1    atatat 	clkinfo.stathz = stathz ? stathz : hz;
   1290       1.1    atatat 
   1291       1.1    atatat 	node = *rnode;
   1292       1.1    atatat 	node.sysctl_data = &clkinfo;
   1293       1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1294       1.1    atatat }
   1295       1.1    atatat 
   1296       1.1    atatat 
   1297       1.1    atatat /*
   1298       1.1    atatat  * sysctl helper routine for kern.file pseudo-subtree.
   1299       1.1    atatat  */
   1300       1.1    atatat static int
   1301       1.1    atatat sysctl_kern_file(SYSCTLFN_ARGS)
   1302       1.1    atatat {
   1303       1.1    atatat 	int error;
   1304       1.1    atatat 	size_t buflen;
   1305       1.1    atatat 	struct file *fp;
   1306       1.1    atatat 	char *start, *where;
   1307       1.1    atatat 
   1308       1.1    atatat 	start = where = oldp;
   1309       1.1    atatat 	buflen = *oldlenp;
   1310       1.1    atatat 	if (where == NULL) {
   1311       1.1    atatat 		/*
   1312       1.1    atatat 		 * overestimate by 10 files
   1313       1.1    atatat 		 */
   1314       1.1    atatat 		*oldlenp = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
   1315       1.1    atatat 		return (0);
   1316       1.1    atatat 	}
   1317       1.1    atatat 
   1318       1.1    atatat 	/*
   1319  1.81.4.5        ad 	 * first dcopyout filehead
   1320       1.1    atatat 	 */
   1321       1.1    atatat 	if (buflen < sizeof(filehead)) {
   1322       1.1    atatat 		*oldlenp = 0;
   1323       1.1    atatat 		return (0);
   1324       1.1    atatat 	}
   1325  1.81.4.5        ad 	error = dcopyout(l, &filehead, where, sizeof(filehead));
   1326       1.1    atatat 	if (error)
   1327       1.1    atatat 		return (error);
   1328       1.1    atatat 	buflen -= sizeof(filehead);
   1329       1.1    atatat 	where += sizeof(filehead);
   1330       1.1    atatat 
   1331       1.1    atatat 	/*
   1332       1.1    atatat 	 * followed by an array of file structures
   1333       1.1    atatat 	 */
   1334       1.1    atatat 	LIST_FOREACH(fp, &filehead, f_list) {
   1335      1.78        ad 		if (kauth_authorize_generic(l->l_cred,
   1336      1.76      elad 		    KAUTH_GENERIC_CANSEE, fp->f_cred) != 0)
   1337      1.55      elad 			continue;
   1338       1.1    atatat 		if (buflen < sizeof(struct file)) {
   1339       1.1    atatat 			*oldlenp = where - start;
   1340       1.1    atatat 			return (ENOMEM);
   1341       1.1    atatat 		}
   1342  1.81.4.5        ad 		error = dcopyout(l, fp, where, sizeof(struct file));
   1343       1.1    atatat 		if (error)
   1344       1.1    atatat 			return (error);
   1345       1.1    atatat 		buflen -= sizeof(struct file);
   1346       1.1    atatat 		where += sizeof(struct file);
   1347       1.1    atatat 	}
   1348       1.1    atatat 	*oldlenp = where - start;
   1349       1.1    atatat 	return (0);
   1350       1.1    atatat }
   1351       1.1    atatat 
   1352       1.1    atatat /*
   1353       1.1    atatat  * sysctl helper routine for kern.autonicetime and kern.autoniceval.
   1354       1.1    atatat  * asserts that the assigned value is in the correct range.
   1355       1.1    atatat  */
   1356       1.1    atatat static int
   1357       1.1    atatat sysctl_kern_autonice(SYSCTLFN_ARGS)
   1358       1.1    atatat {
   1359       1.1    atatat 	int error, t = 0;
   1360       1.1    atatat 	struct sysctlnode node;
   1361       1.1    atatat 
   1362       1.1    atatat 	node = *rnode;
   1363       1.1    atatat 	t = *(int*)node.sysctl_data;
   1364       1.1    atatat 	node.sysctl_data = &t;
   1365       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1366       1.1    atatat 	if (error || newp == NULL)
   1367       1.1    atatat 		return (error);
   1368       1.1    atatat 
   1369       1.1    atatat 	switch (node.sysctl_num) {
   1370       1.1    atatat 	case KERN_AUTONICETIME:
   1371       1.1    atatat 		if (t >= 0)
   1372       1.1    atatat 			autonicetime = t;
   1373       1.1    atatat 		break;
   1374       1.1    atatat 	case KERN_AUTONICEVAL:
   1375       1.1    atatat 		if (t < PRIO_MIN)
   1376       1.1    atatat 			t = PRIO_MIN;
   1377       1.1    atatat 		else if (t > PRIO_MAX)
   1378       1.1    atatat 			t = PRIO_MAX;
   1379       1.1    atatat 		autoniceval = t;
   1380       1.1    atatat 		break;
   1381       1.1    atatat 	}
   1382       1.1    atatat 
   1383       1.1    atatat 	return (0);
   1384       1.1    atatat }
   1385       1.1    atatat 
   1386       1.1    atatat /*
   1387       1.1    atatat  * sysctl helper routine for kern.msgbufsize and kern.msgbuf.  for the
   1388      1.28    simonb  * former it merely checks the message buffer is set up.  for the latter,
   1389      1.28    simonb  * it also copies out the data if necessary.
   1390       1.1    atatat  */
   1391       1.1    atatat static int
   1392       1.1    atatat sysctl_msgbuf(SYSCTLFN_ARGS)
   1393       1.1    atatat {
   1394       1.1    atatat 	char *where = oldp;
   1395       1.1    atatat 	size_t len, maxlen;
   1396       1.1    atatat 	long beg, end;
   1397       1.1    atatat 	int error;
   1398       1.1    atatat 
   1399       1.1    atatat 	if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
   1400       1.1    atatat 		msgbufenabled = 0;
   1401       1.1    atatat 		return (ENXIO);
   1402       1.1    atatat 	}
   1403       1.1    atatat 
   1404       1.1    atatat 	switch (rnode->sysctl_num) {
   1405      1.31    atatat 	case KERN_MSGBUFSIZE: {
   1406      1.31    atatat 		struct sysctlnode node = *rnode;
   1407      1.31    atatat 		int msg_bufs = (int)msgbufp->msg_bufs;
   1408      1.31    atatat 		node.sysctl_data = &msg_bufs;
   1409      1.31    atatat 		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1410      1.31    atatat 	}
   1411       1.1    atatat 	case KERN_MSGBUF:
   1412       1.1    atatat 		break;
   1413       1.1    atatat 	default:
   1414       1.1    atatat 		return (EOPNOTSUPP);
   1415       1.1    atatat 	}
   1416       1.1    atatat 
   1417       1.1    atatat 	if (newp != NULL)
   1418       1.1    atatat 		return (EPERM);
   1419       1.1    atatat 
   1420       1.1    atatat         if (oldp == NULL) {
   1421       1.1    atatat 		/* always return full buffer size */
   1422       1.1    atatat 		*oldlenp = msgbufp->msg_bufs;
   1423       1.1    atatat 		return (0);
   1424       1.1    atatat         }
   1425       1.1    atatat 
   1426       1.1    atatat 	error = 0;
   1427       1.1    atatat 	maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
   1428       1.1    atatat 
   1429       1.1    atatat 	/*
   1430       1.1    atatat 	 * First, copy from the write pointer to the end of
   1431       1.1    atatat 	 * message buffer.
   1432       1.1    atatat 	 */
   1433       1.1    atatat 	beg = msgbufp->msg_bufx;
   1434       1.1    atatat 	end = msgbufp->msg_bufs;
   1435       1.1    atatat 	while (maxlen > 0) {
   1436       1.1    atatat 		len = MIN(end - beg, maxlen);
   1437       1.1    atatat 		if (len == 0)
   1438       1.1    atatat 			break;
   1439  1.81.4.5        ad 		error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
   1440       1.1    atatat 		if (error)
   1441       1.1    atatat 			break;
   1442       1.1    atatat 		where += len;
   1443       1.1    atatat 		maxlen -= len;
   1444       1.1    atatat 
   1445       1.1    atatat 		/*
   1446       1.1    atatat 		 * ... then, copy from the beginning of message buffer to
   1447       1.1    atatat 		 * the write pointer.
   1448       1.1    atatat 		 */
   1449       1.1    atatat 		beg = 0;
   1450       1.1    atatat 		end = msgbufp->msg_bufx;
   1451       1.1    atatat 	}
   1452       1.1    atatat 
   1453       1.1    atatat 	return (error);
   1454       1.1    atatat }
   1455       1.1    atatat 
   1456       1.1    atatat /*
   1457       1.1    atatat  * sysctl helper routine for kern.defcorename.  in the case of a new
   1458       1.1    atatat  * string being assigned, check that it's not a zero-length string.
   1459       1.1    atatat  * (XXX the check in -current doesn't work, but do we really care?)
   1460       1.1    atatat  */
   1461       1.1    atatat static int
   1462       1.1    atatat sysctl_kern_defcorename(SYSCTLFN_ARGS)
   1463       1.1    atatat {
   1464       1.1    atatat 	int error;
   1465      1.62      yamt 	char *newcorename;
   1466       1.1    atatat 	struct sysctlnode node;
   1467       1.1    atatat 
   1468      1.62      yamt 	newcorename = PNBUF_GET();
   1469       1.1    atatat 	node = *rnode;
   1470       1.1    atatat 	node.sysctl_data = &newcorename[0];
   1471       1.1    atatat 	memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
   1472       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1473      1.62      yamt 	if (error || newp == NULL) {
   1474      1.62      yamt 		goto done;
   1475      1.62      yamt 	}
   1476       1.1    atatat 
   1477       1.1    atatat 	/*
   1478       1.1    atatat 	 * when sysctl_lookup() deals with a string, it's guaranteed
   1479       1.1    atatat 	 * to come back nul terminated.  so there.  :)
   1480       1.1    atatat 	 */
   1481      1.62      yamt 	if (strlen(newcorename) == 0) {
   1482      1.62      yamt 		error = EINVAL;
   1483      1.62      yamt 	} else {
   1484      1.62      yamt 		memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
   1485      1.62      yamt 		error = 0;
   1486      1.62      yamt 	}
   1487      1.62      yamt done:
   1488      1.62      yamt 	PNBUF_PUT(newcorename);
   1489      1.62      yamt 	return error;
   1490       1.1    atatat }
   1491       1.1    atatat 
   1492       1.1    atatat /*
   1493       1.1    atatat  * sysctl helper routine for kern.cp_time node.  adds up cpu time
   1494       1.1    atatat  * across all cpus.
   1495       1.1    atatat  */
   1496       1.1    atatat static int
   1497       1.1    atatat sysctl_kern_cptime(SYSCTLFN_ARGS)
   1498       1.1    atatat {
   1499       1.1    atatat 	struct sysctlnode node = *rnode;
   1500       1.5    martin 
   1501       1.5    martin #ifndef MULTIPROCESSOR
   1502       1.5    martin 
   1503      1.18    atatat 	if (namelen == 1) {
   1504      1.18    atatat 		if (name[0] != 0)
   1505      1.18    atatat 			return (ENOENT);
   1506       1.5    martin 		/*
   1507       1.5    martin 		 * you're allowed to ask for the zero'th processor
   1508       1.5    martin 		 */
   1509       1.5    martin 		name++;
   1510       1.5    martin 		namelen--;
   1511       1.5    martin 	}
   1512       1.5    martin 	node.sysctl_data = curcpu()->ci_schedstate.spc_cp_time;
   1513       1.5    martin 	node.sysctl_size = sizeof(curcpu()->ci_schedstate.spc_cp_time);
   1514       1.5    martin 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1515       1.5    martin 
   1516       1.5    martin #else /* MULTIPROCESSOR */
   1517       1.5    martin 
   1518      1.59     perry 	uint64_t *cp_time = NULL;
   1519       1.5    martin 	int error, n = sysctl_ncpus(), i;
   1520       1.1    atatat 	struct cpu_info *ci;
   1521       1.1    atatat 	CPU_INFO_ITERATOR cii;
   1522       1.1    atatat 
   1523       1.1    atatat 	/*
   1524       1.1    atatat 	 * if you specifically pass a buffer that is the size of the
   1525       1.1    atatat 	 * sum, or if you are probing for the size, you get the "sum"
   1526       1.1    atatat 	 * of cp_time (and the size thereof) across all processors.
   1527       1.1    atatat 	 *
   1528       1.1    atatat 	 * alternately, you can pass an additional mib number and get
   1529       1.1    atatat 	 * cp_time for that particular processor.
   1530       1.1    atatat 	 */
   1531       1.1    atatat 	switch (namelen) {
   1532       1.1    atatat 	case 0:
   1533      1.59     perry 	    	if (*oldlenp == sizeof(uint64_t) * CPUSTATES || oldp == NULL) {
   1534      1.59     perry 			node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
   1535       1.1    atatat 			n = -1; /* SUM */
   1536       1.1    atatat 		}
   1537       1.1    atatat 		else {
   1538      1.59     perry 			node.sysctl_size = n * sizeof(uint64_t) * CPUSTATES;
   1539       1.1    atatat 			n = -2; /* ALL */
   1540       1.1    atatat 		}
   1541       1.1    atatat 		break;
   1542       1.1    atatat 	case 1:
   1543       1.1    atatat 		if (name[0] < 0 || name[0] >= n)
   1544      1.18    atatat 			return (ENOENT); /* ENOSUCHPROCESSOR */
   1545      1.59     perry 		node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
   1546       1.1    atatat 		n = name[0];
   1547       1.1    atatat 		/*
   1548       1.1    atatat 		 * adjust these so that sysctl_lookup() will be happy
   1549       1.1    atatat 		 */
   1550       1.1    atatat 		name++;
   1551       1.1    atatat 		namelen--;
   1552       1.7    martin 		break;
   1553       1.1    atatat 	default:
   1554       1.1    atatat 		return (EINVAL);
   1555       1.1    atatat 	}
   1556       1.1    atatat 
   1557       1.5    martin 	cp_time = malloc(node.sysctl_size, M_TEMP, M_WAITOK|M_CANFAIL);
   1558       1.1    atatat 	if (cp_time == NULL)
   1559       1.1    atatat 		return (ENOMEM);
   1560       1.1    atatat 	node.sysctl_data = cp_time;
   1561       1.1    atatat 	memset(cp_time, 0, node.sysctl_size);
   1562       1.1    atatat 
   1563       1.1    atatat 	for (CPU_INFO_FOREACH(cii, ci)) {
   1564       1.5    martin 		if (n <= 0)
   1565       1.1    atatat 			for (i = 0; i < CPUSTATES; i++)
   1566       1.1    atatat 				cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
   1567       1.1    atatat 		/*
   1568       1.1    atatat 		 * if a specific processor was requested and we just
   1569       1.1    atatat 		 * did it, we're done here
   1570       1.1    atatat 		 */
   1571       1.1    atatat 		if (n == 0)
   1572       1.1    atatat 			break;
   1573       1.1    atatat 		/*
   1574       1.1    atatat 		 * if doing "all", skip to next cp_time set for next processor
   1575       1.1    atatat 		 */
   1576       1.1    atatat 		if (n == -2)
   1577       1.1    atatat 			cp_time += CPUSTATES;
   1578       1.1    atatat 		/*
   1579       1.1    atatat 		 * if we're doing a specific processor, we're one
   1580       1.1    atatat 		 * processor closer
   1581       1.1    atatat 		 */
   1582       1.1    atatat 		if (n > 0)
   1583       1.1    atatat 			n--;
   1584       1.1    atatat 	}
   1585       1.1    atatat 
   1586       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1587       1.5    martin 	free(node.sysctl_data, M_TEMP);
   1588       1.5    martin 	return (error);
   1589       1.1    atatat 
   1590       1.5    martin #endif /* MULTIPROCESSOR */
   1591       1.1    atatat }
   1592       1.1    atatat 
   1593       1.1    atatat #if NPTY > 0
   1594       1.1    atatat /*
   1595       1.1    atatat  * sysctl helper routine for kern.maxptys.  ensures that any new value
   1596       1.1    atatat  * is acceptable to the pty subsystem.
   1597       1.1    atatat  */
   1598       1.1    atatat static int
   1599       1.1    atatat sysctl_kern_maxptys(SYSCTLFN_ARGS)
   1600       1.1    atatat {
   1601       1.1    atatat 	int pty_maxptys(int, int);		/* defined in kern/tty_pty.c */
   1602      1.40  christos 	int error, xmax;
   1603       1.1    atatat 	struct sysctlnode node;
   1604       1.1    atatat 
   1605       1.1    atatat 	/* get current value of maxptys */
   1606      1.40  christos 	xmax = pty_maxptys(0, 0);
   1607       1.1    atatat 
   1608       1.1    atatat 	node = *rnode;
   1609      1.40  christos 	node.sysctl_data = &xmax;
   1610       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1611       1.1    atatat 	if (error || newp == NULL)
   1612       1.1    atatat 		return (error);
   1613      1.33     perry 
   1614      1.40  christos 	if (xmax != pty_maxptys(xmax, 1))
   1615       1.1    atatat 		return (EINVAL);
   1616       1.1    atatat 
   1617       1.1    atatat 	return (0);
   1618       1.1    atatat }
   1619       1.1    atatat #endif /* NPTY > 0 */
   1620       1.1    atatat 
   1621       1.1    atatat /*
   1622       1.1    atatat  * sysctl helper routine for kern.sbmax.  basically just ensures that
   1623       1.1    atatat  * any new value is not too small.
   1624       1.1    atatat  */
   1625       1.1    atatat static int
   1626       1.1    atatat sysctl_kern_sbmax(SYSCTLFN_ARGS)
   1627       1.1    atatat {
   1628       1.1    atatat 	int error, new_sbmax;
   1629       1.1    atatat 	struct sysctlnode node;
   1630       1.1    atatat 
   1631       1.1    atatat 	new_sbmax = sb_max;
   1632       1.1    atatat 	node = *rnode;
   1633       1.1    atatat 	node.sysctl_data = &new_sbmax;
   1634       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1635       1.1    atatat 	if (error || newp == NULL)
   1636       1.1    atatat 		return (error);
   1637       1.1    atatat 
   1638       1.1    atatat 	error = sb_max_set(new_sbmax);
   1639       1.1    atatat 
   1640       1.1    atatat 	return (error);
   1641       1.1    atatat }
   1642       1.1    atatat 
   1643       1.1    atatat /*
   1644       1.1    atatat  * sysctl helper routine for kern.urandom node.  picks a random number
   1645       1.1    atatat  * for you.
   1646       1.1    atatat  */
   1647       1.1    atatat static int
   1648       1.1    atatat sysctl_kern_urnd(SYSCTLFN_ARGS)
   1649       1.1    atatat {
   1650       1.1    atatat #if NRND > 0
   1651       1.1    atatat 	int v;
   1652       1.1    atatat 
   1653       1.1    atatat 	if (rnd_extract_data(&v, sizeof(v), RND_EXTRACT_ANY) == sizeof(v)) {
   1654       1.1    atatat 		struct sysctlnode node = *rnode;
   1655       1.1    atatat 		node.sysctl_data = &v;
   1656       1.1    atatat 		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1657       1.1    atatat 	}
   1658       1.1    atatat 	else
   1659       1.1    atatat 		return (EIO);	/*XXX*/
   1660       1.1    atatat #else
   1661       1.1    atatat 	return (EOPNOTSUPP);
   1662       1.1    atatat #endif
   1663       1.1    atatat }
   1664       1.1    atatat 
   1665       1.1    atatat /*
   1666  1.81.4.5        ad  * sysctl helper routine for kern.arandom node.  picks a random number
   1667  1.81.4.5        ad  * for you.
   1668  1.81.4.5        ad  */
   1669  1.81.4.5        ad static int
   1670  1.81.4.5        ad sysctl_kern_arnd(SYSCTLFN_ARGS)
   1671  1.81.4.5        ad {
   1672  1.81.4.5        ad #if NRND > 0
   1673  1.81.4.5        ad 	int error;
   1674  1.81.4.5        ad 	void *v;
   1675  1.81.4.5        ad 	struct sysctlnode node = *rnode;
   1676  1.81.4.5        ad 
   1677  1.81.4.5        ad 	if (*oldlenp == 0)
   1678  1.81.4.5        ad 		return 0;
   1679  1.81.4.5        ad 	if (*oldlenp > 8192)
   1680  1.81.4.5        ad 		return E2BIG;
   1681  1.81.4.5        ad 
   1682  1.81.4.5        ad 	v = malloc(*oldlenp, M_TEMP, M_WAITOK);
   1683  1.81.4.5        ad 
   1684  1.81.4.5        ad 	arc4randbytes(v, *oldlenp);
   1685  1.81.4.5        ad 	node.sysctl_data = v;
   1686  1.81.4.5        ad 	node.sysctl_size = *oldlenp;
   1687  1.81.4.5        ad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1688  1.81.4.5        ad 	free(v, M_TEMP);
   1689  1.81.4.5        ad 	return error;
   1690  1.81.4.5        ad #else
   1691  1.81.4.5        ad 	return (EOPNOTSUPP);
   1692  1.81.4.5        ad #endif
   1693  1.81.4.5        ad }
   1694  1.81.4.5        ad /*
   1695       1.1    atatat  * sysctl helper routine to do kern.lwp.* work.
   1696       1.1    atatat  */
   1697       1.1    atatat static int
   1698       1.1    atatat sysctl_kern_lwp(SYSCTLFN_ARGS)
   1699       1.1    atatat {
   1700       1.1    atatat 	struct kinfo_lwp klwp;
   1701       1.1    atatat 	struct proc *p;
   1702       1.1    atatat 	struct lwp *l2;
   1703       1.1    atatat 	char *where, *dp;
   1704       1.1    atatat 	int pid, elem_size, elem_count;
   1705       1.1    atatat 	int buflen, needed, error;
   1706       1.1    atatat 
   1707      1.19    atatat 	if (namelen == 1 && name[0] == CTL_QUERY)
   1708      1.43    atatat 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   1709      1.19    atatat 
   1710       1.1    atatat 	dp = where = oldp;
   1711       1.1    atatat 	buflen = where != NULL ? *oldlenp : 0;
   1712       1.1    atatat 	error = needed = 0;
   1713       1.1    atatat 
   1714      1.11    simonb 	if (newp != NULL || namelen != 3)
   1715       1.1    atatat 		return (EINVAL);
   1716      1.11    simonb 	pid = name[0];
   1717      1.11    simonb 	elem_size = name[1];
   1718      1.11    simonb 	elem_count = name[2];
   1719       1.1    atatat 
   1720  1.81.4.2        ad 	p = p_find(pid, PFIND_UNLOCK_FAIL);
   1721       1.1    atatat 	if (p == NULL)
   1722       1.1    atatat 		return (ESRCH);
   1723  1.81.4.2        ad 	mutex_enter(&p->p_smutex);
   1724       1.1    atatat 	LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
   1725       1.1    atatat 		if (buflen >= elem_size && elem_count > 0) {
   1726  1.81.4.2        ad 			lwp_lock(l2);
   1727       1.1    atatat 			fill_lwp(l2, &klwp);
   1728  1.81.4.2        ad 			lwp_unlock(l2);
   1729  1.81.4.2        ad 
   1730       1.1    atatat 			/*
   1731       1.1    atatat 			 * Copy out elem_size, but not larger than
   1732       1.1    atatat 			 * the size of a struct kinfo_proc2.
   1733  1.81.4.2        ad 			 *
   1734  1.81.4.2        ad 			 * XXX We should not be holding p_smutex, but
   1735  1.81.4.2        ad 			 * for now, the buffer is wired.  Fix later.
   1736       1.1    atatat 			 */
   1737  1.81.4.5        ad 			error = dcopyout(l, &klwp, dp,
   1738       1.1    atatat 			    min(sizeof(klwp), elem_size));
   1739       1.1    atatat 			if (error)
   1740       1.1    atatat 				goto cleanup;
   1741       1.1    atatat 			dp += elem_size;
   1742       1.1    atatat 			buflen -= elem_size;
   1743       1.1    atatat 			elem_count--;
   1744       1.1    atatat 		}
   1745       1.1    atatat 		needed += elem_size;
   1746       1.1    atatat 	}
   1747  1.81.4.2        ad 	mutex_exit(&p->p_smutex);
   1748  1.81.4.2        ad 	rw_exit(&proclist_lock);
   1749       1.1    atatat 
   1750       1.1    atatat 	if (where != NULL) {
   1751       1.1    atatat 		*oldlenp = dp - where;
   1752       1.1    atatat 		if (needed > *oldlenp)
   1753       1.1    atatat 			return (ENOMEM);
   1754       1.1    atatat 	} else {
   1755      1.22    atatat 		needed += KERN_LWPSLOP;
   1756       1.1    atatat 		*oldlenp = needed;
   1757       1.1    atatat 	}
   1758       1.1    atatat 	return (0);
   1759       1.1    atatat  cleanup:
   1760       1.1    atatat 	return (error);
   1761       1.1    atatat }
   1762       1.1    atatat 
   1763       1.1    atatat /*
   1764       1.1    atatat  * sysctl helper routine for kern.forkfsleep node.  ensures that the
   1765       1.1    atatat  * given value is not too large or two small, and is at least one
   1766       1.1    atatat  * timer tick if not zero.
   1767       1.1    atatat  */
   1768       1.1    atatat static int
   1769       1.1    atatat sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
   1770       1.1    atatat {
   1771       1.1    atatat 	/* userland sees value in ms, internally is in ticks */
   1772       1.1    atatat 	extern int forkfsleep;		/* defined in kern/kern_fork.c */
   1773       1.1    atatat 	int error, timo, lsleep;
   1774       1.1    atatat 	struct sysctlnode node;
   1775       1.1    atatat 
   1776       1.1    atatat 	lsleep = forkfsleep * 1000 / hz;
   1777       1.1    atatat 	node = *rnode;
   1778       1.1    atatat 	node.sysctl_data = &lsleep;
   1779       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   1780       1.1    atatat 	if (error || newp == NULL)
   1781       1.1    atatat 		return (error);
   1782       1.1    atatat 
   1783       1.1    atatat 	/* refuse negative values, and overly 'long time' */
   1784       1.1    atatat 	if (lsleep < 0 || lsleep > MAXSLP * 1000)
   1785       1.1    atatat 		return (EINVAL);
   1786       1.1    atatat 
   1787       1.1    atatat 	timo = mstohz(lsleep);
   1788       1.1    atatat 
   1789       1.1    atatat 	/* if the interval is >0 ms && <1 tick, use 1 tick */
   1790       1.1    atatat 	if (lsleep != 0 && timo == 0)
   1791       1.1    atatat 		forkfsleep = 1;
   1792       1.1    atatat 	else
   1793       1.1    atatat 		forkfsleep = timo;
   1794       1.1    atatat 
   1795       1.1    atatat 	return (0);
   1796       1.1    atatat }
   1797       1.1    atatat 
   1798       1.1    atatat /*
   1799       1.1    atatat  * sysctl helper routine for kern.root_partition
   1800       1.1    atatat  */
   1801       1.1    atatat static int
   1802       1.1    atatat sysctl_kern_root_partition(SYSCTLFN_ARGS)
   1803       1.1    atatat {
   1804       1.1    atatat 	int rootpart = DISKPART(rootdev);
   1805       1.1    atatat 	struct sysctlnode node = *rnode;
   1806       1.1    atatat 
   1807       1.1    atatat 	node.sysctl_data = &rootpart;
   1808       1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   1809       1.1    atatat }
   1810       1.1    atatat 
   1811       1.1    atatat /*
   1812       1.1    atatat  * sysctl helper function for kern.drivers
   1813       1.1    atatat  */
   1814       1.1    atatat static int
   1815       1.1    atatat sysctl_kern_drivers(SYSCTLFN_ARGS)
   1816       1.1    atatat {
   1817       1.1    atatat 	int error;
   1818       1.1    atatat 	size_t buflen;
   1819       1.1    atatat 	struct kinfo_drivers kd;
   1820       1.1    atatat 	char *start, *where;
   1821       1.1    atatat 	const char *dname;
   1822       1.1    atatat 	int i;
   1823       1.1    atatat 	extern struct devsw_conv *devsw_conv;
   1824       1.1    atatat 	extern int max_devsw_convs;
   1825       1.1    atatat 
   1826       1.1    atatat 	if (newp != NULL || namelen != 0)
   1827       1.1    atatat 		return (EINVAL);
   1828       1.1    atatat 
   1829       1.1    atatat 	start = where = oldp;
   1830       1.1    atatat 	buflen = *oldlenp;
   1831       1.1    atatat 	if (where == NULL) {
   1832       1.1    atatat 		*oldlenp = max_devsw_convs * sizeof kd;
   1833       1.1    atatat 		return 0;
   1834       1.1    atatat 	}
   1835       1.1    atatat 
   1836       1.1    atatat 	/*
   1837       1.1    atatat 	 * An array of kinfo_drivers structures
   1838       1.1    atatat 	 */
   1839       1.1    atatat 	error = 0;
   1840       1.1    atatat 	for (i = 0; i < max_devsw_convs; i++) {
   1841       1.1    atatat 		dname = devsw_conv[i].d_name;
   1842       1.1    atatat 		if (dname == NULL)
   1843       1.1    atatat 			continue;
   1844       1.1    atatat 		if (buflen < sizeof kd) {
   1845       1.1    atatat 			error = ENOMEM;
   1846       1.1    atatat 			break;
   1847       1.1    atatat 		}
   1848      1.25    atatat 		memset(&kd, 0, sizeof(kd));
   1849       1.1    atatat 		kd.d_bmajor = devsw_conv[i].d_bmajor;
   1850       1.1    atatat 		kd.d_cmajor = devsw_conv[i].d_cmajor;
   1851       1.1    atatat 		strlcpy(kd.d_name, dname, sizeof kd.d_name);
   1852  1.81.4.5        ad 		error = dcopyout(l, &kd, where, sizeof kd);
   1853       1.1    atatat 		if (error != 0)
   1854       1.1    atatat 			break;
   1855       1.1    atatat 		buflen -= sizeof kd;
   1856       1.1    atatat 		where += sizeof kd;
   1857       1.1    atatat 	}
   1858       1.1    atatat 	*oldlenp = where - start;
   1859       1.1    atatat 	return error;
   1860       1.1    atatat }
   1861       1.1    atatat 
   1862      1.34    atatat /*
   1863      1.34    atatat  * sysctl helper function for kern.file2
   1864      1.34    atatat  */
   1865      1.34    atatat static int
   1866      1.34    atatat sysctl_kern_file2(SYSCTLFN_ARGS)
   1867      1.34    atatat {
   1868      1.34    atatat 	struct proc *p;
   1869      1.34    atatat 	struct file *fp;
   1870      1.34    atatat 	struct filedesc *fd;
   1871      1.34    atatat 	struct kinfo_file kf;
   1872      1.34    atatat 	char *dp;
   1873      1.34    atatat 	u_int i, op;
   1874      1.34    atatat 	size_t len, needed, elem_size, out_size;
   1875      1.34    atatat 	int error, arg, elem_count;
   1876      1.34    atatat 
   1877      1.34    atatat 	if (namelen == 1 && name[0] == CTL_QUERY)
   1878      1.43    atatat 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   1879      1.34    atatat 
   1880      1.34    atatat 	if (namelen != 4)
   1881      1.34    atatat 		return (EINVAL);
   1882      1.34    atatat 
   1883      1.34    atatat 	error = 0;
   1884      1.34    atatat 	dp = oldp;
   1885      1.34    atatat 	len = (oldp != NULL) ? *oldlenp : 0;
   1886      1.34    atatat 	op = name[0];
   1887      1.34    atatat 	arg = name[1];
   1888      1.34    atatat 	elem_size = name[2];
   1889      1.34    atatat 	elem_count = name[3];
   1890      1.34    atatat 	out_size = MIN(sizeof(kf), elem_size);
   1891      1.34    atatat 	needed = 0;
   1892      1.34    atatat 
   1893      1.34    atatat 	if (elem_size < 1 || elem_count < 0)
   1894      1.34    atatat 		return (EINVAL);
   1895      1.34    atatat 
   1896      1.34    atatat 	switch (op) {
   1897      1.34    atatat 	case KERN_FILE_BYFILE:
   1898      1.34    atatat 		/*
   1899      1.34    atatat 		 * doesn't use arg so it must be zero
   1900      1.34    atatat 		 */
   1901      1.34    atatat 		if (arg != 0)
   1902      1.34    atatat 			return (EINVAL);
   1903      1.34    atatat 		LIST_FOREACH(fp, &filehead, f_list) {
   1904      1.78        ad 			if (kauth_authorize_generic(l->l_cred,
   1905      1.76      elad 			    KAUTH_GENERIC_CANSEE, fp->f_cred) != 0)
   1906      1.55      elad 				continue;
   1907      1.34    atatat 			if (len >= elem_size && elem_count > 0) {
   1908      1.34    atatat 				fill_file(&kf, fp, NULL, 0);
   1909  1.81.4.5        ad 				error = dcopyout(l, &kf, dp, out_size);
   1910      1.34    atatat 				if (error)
   1911      1.34    atatat 					break;
   1912      1.34    atatat 				dp += elem_size;
   1913      1.34    atatat 				len -= elem_size;
   1914      1.34    atatat 			}
   1915      1.34    atatat 			if (elem_count > 0) {
   1916      1.34    atatat 				needed += elem_size;
   1917      1.34    atatat 				if (elem_count != INT_MAX)
   1918      1.34    atatat 					elem_count--;
   1919      1.34    atatat 			}
   1920      1.34    atatat 		}
   1921      1.34    atatat 		break;
   1922      1.69      yamt 	case KERN_FILE_BYPID:
   1923      1.34    atatat 		if (arg < -1)
   1924      1.34    atatat 			/* -1 means all processes */
   1925      1.34    atatat 			return (EINVAL);
   1926  1.81.4.1        ad 		rw_enter(&proclist_lock, RW_READER);
   1927      1.34    atatat 		PROCLIST_FOREACH(p, &allproc) {
   1928      1.34    atatat 			if (p->p_stat == SIDL)
   1929      1.34    atatat 				/* skip embryonic processes */
   1930      1.34    atatat 				continue;
   1931      1.78        ad 			if (kauth_authorize_process(l->l_cred,
   1932      1.71      yamt 			    KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL) != 0)
   1933      1.55      elad 				continue;
   1934      1.34    atatat 			if (arg > 0 && p->p_pid != arg)
   1935      1.34    atatat 				/* pick only the one we want */
   1936      1.34    atatat 				/* XXX want 0 to mean "kernel files" */
   1937      1.34    atatat 				continue;
   1938      1.34    atatat 			fd = p->p_fd;
   1939      1.34    atatat 			for (i = 0; i < fd->fd_nfiles; i++) {
   1940      1.34    atatat 				fp = fd->fd_ofiles[i];
   1941      1.34    atatat 				if (fp == NULL || !FILE_IS_USABLE(fp))
   1942      1.34    atatat 					continue;
   1943      1.34    atatat 				if (len >= elem_size && elem_count > 0) {
   1944      1.34    atatat 					fill_file(&kf, fd->fd_ofiles[i],
   1945      1.34    atatat 						  p, i);
   1946  1.81.4.5        ad 					error = dcopyout(l, &kf, dp, out_size);
   1947      1.34    atatat 					if (error)
   1948      1.34    atatat 						break;
   1949      1.34    atatat 					dp += elem_size;
   1950      1.34    atatat 					len -= elem_size;
   1951      1.34    atatat 				}
   1952      1.34    atatat 				if (elem_count > 0) {
   1953      1.34    atatat 					needed += elem_size;
   1954      1.34    atatat 					if (elem_count != INT_MAX)
   1955      1.34    atatat 						elem_count--;
   1956      1.34    atatat 				}
   1957      1.34    atatat 			}
   1958      1.34    atatat 		}
   1959  1.81.4.1        ad 		rw_exit(&proclist_lock);
   1960      1.34    atatat 		break;
   1961      1.34    atatat 	default:
   1962      1.34    atatat 		return (EINVAL);
   1963      1.34    atatat 	}
   1964      1.34    atatat 
   1965      1.34    atatat 	if (oldp == NULL)
   1966      1.34    atatat 		needed += KERN_FILESLOP * elem_size;
   1967      1.34    atatat 	*oldlenp = needed;
   1968      1.34    atatat 
   1969      1.34    atatat 	return (error);
   1970      1.34    atatat }
   1971      1.34    atatat 
   1972      1.34    atatat static void
   1973      1.34    atatat fill_file(struct kinfo_file *kp, const struct file *fp, struct proc *p, int i)
   1974      1.34    atatat {
   1975      1.34    atatat 
   1976      1.34    atatat 	memset(kp, 0, sizeof(*kp));
   1977      1.34    atatat 
   1978      1.34    atatat 	kp->ki_fileaddr =	PTRTOUINT64(fp);
   1979      1.34    atatat 	kp->ki_flag =		fp->f_flag;
   1980      1.34    atatat 	kp->ki_iflags =		fp->f_iflags;
   1981      1.34    atatat 	kp->ki_ftype =		fp->f_type;
   1982      1.34    atatat 	kp->ki_count =		fp->f_count;
   1983      1.34    atatat 	kp->ki_msgcount =	fp->f_msgcount;
   1984      1.34    atatat 	kp->ki_usecount =	fp->f_usecount;
   1985      1.34    atatat 	kp->ki_fucred =		PTRTOUINT64(fp->f_cred);
   1986      1.68      elad 	kp->ki_fuid =		kauth_cred_geteuid(fp->f_cred);
   1987      1.68      elad 	kp->ki_fgid =		kauth_cred_getegid(fp->f_cred);
   1988      1.34    atatat 	kp->ki_fops =		PTRTOUINT64(fp->f_ops);
   1989      1.34    atatat 	kp->ki_foffset =	fp->f_offset;
   1990      1.34    atatat 	kp->ki_fdata =		PTRTOUINT64(fp->f_data);
   1991      1.34    atatat 
   1992      1.34    atatat 	/* vnode information to glue this file to something */
   1993      1.34    atatat 	if (fp->f_type == DTYPE_VNODE) {
   1994      1.34    atatat 		struct vnode *vp = (struct vnode *)fp->f_data;
   1995      1.34    atatat 
   1996      1.34    atatat 		kp->ki_vun =	PTRTOUINT64(vp->v_un.vu_socket);
   1997      1.34    atatat 		kp->ki_vsize =	vp->v_size;
   1998      1.34    atatat 		kp->ki_vtype =	vp->v_type;
   1999      1.34    atatat 		kp->ki_vtag =	vp->v_tag;
   2000      1.34    atatat 		kp->ki_vdata =	PTRTOUINT64(vp->v_data);
   2001      1.34    atatat 	}
   2002      1.34    atatat 
   2003      1.34    atatat         /* process information when retrieved via KERN_FILE_BYPID */
   2004      1.34    atatat 	if (p) {
   2005      1.34    atatat 		kp->ki_pid =		p->p_pid;
   2006      1.34    atatat 		kp->ki_fd =		i;
   2007      1.34    atatat 		kp->ki_ofileflags =	p->p_fd->fd_ofileflags[i];
   2008      1.34    atatat 	}
   2009      1.34    atatat }
   2010      1.34    atatat 
   2011       1.1    atatat static int
   2012       1.1    atatat sysctl_doeproc(SYSCTLFN_ARGS)
   2013       1.1    atatat {
   2014      1.73  christos 	struct eproc *eproc;
   2015      1.73  christos 	struct kinfo_proc2 *kproc2;
   2016       1.1    atatat 	struct kinfo_proc *dp;
   2017       1.1    atatat 	struct proc *p;
   2018       1.1    atatat 	const struct proclist_desc *pd;
   2019       1.1    atatat 	char *where, *dp2;
   2020       1.1    atatat 	int type, op, arg;
   2021       1.1    atatat 	u_int elem_size, elem_count;
   2022       1.1    atatat 	size_t buflen, needed;
   2023       1.1    atatat 	int error;
   2024       1.1    atatat 
   2025      1.19    atatat 	if (namelen == 1 && name[0] == CTL_QUERY)
   2026      1.43    atatat 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   2027      1.19    atatat 
   2028       1.1    atatat 	dp = oldp;
   2029       1.1    atatat 	dp2 = where = oldp;
   2030       1.1    atatat 	buflen = where != NULL ? *oldlenp : 0;
   2031       1.1    atatat 	error = 0;
   2032       1.1    atatat 	needed = 0;
   2033       1.1    atatat 	type = rnode->sysctl_num;
   2034       1.1    atatat 
   2035       1.1    atatat 	if (type == KERN_PROC) {
   2036       1.1    atatat 		if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
   2037       1.1    atatat 			return (EINVAL);
   2038       1.1    atatat 		op = name[0];
   2039       1.1    atatat 		if (op != KERN_PROC_ALL)
   2040       1.1    atatat 			arg = name[1];
   2041       1.1    atatat 		else
   2042       1.1    atatat 			arg = 0;		/* Quell compiler warning */
   2043       1.1    atatat 		elem_size = elem_count = 0;	/* Ditto */
   2044       1.1    atatat 	} else {
   2045       1.1    atatat 		if (namelen != 4)
   2046       1.1    atatat 			return (EINVAL);
   2047       1.1    atatat 		op = name[0];
   2048       1.1    atatat 		arg = name[1];
   2049       1.1    atatat 		elem_size = name[2];
   2050       1.1    atatat 		elem_count = name[3];
   2051       1.1    atatat 	}
   2052       1.1    atatat 
   2053      1.74  christos 	if (type == KERN_PROC) {
   2054      1.74  christos 		eproc = malloc(sizeof(*eproc), M_TEMP, M_WAITOK);
   2055      1.74  christos 		kproc2 = NULL;
   2056      1.74  christos 	} else {
   2057      1.74  christos 		eproc = NULL;
   2058      1.74  christos 		kproc2 = malloc(sizeof(*kproc2), M_TEMP, M_WAITOK);
   2059      1.74  christos 	}
   2060  1.81.4.1        ad 	rw_enter(&proclist_lock, RW_READER);
   2061       1.1    atatat 
   2062       1.1    atatat 	pd = proclists;
   2063       1.1    atatat again:
   2064      1.32      yamt 	PROCLIST_FOREACH(p, pd->pd_list) {
   2065       1.1    atatat 		/*
   2066       1.1    atatat 		 * Skip embryonic processes.
   2067       1.1    atatat 		 */
   2068       1.1    atatat 		if (p->p_stat == SIDL)
   2069       1.1    atatat 			continue;
   2070      1.55      elad 
   2071      1.78        ad 		if (kauth_authorize_process(l->l_cred,
   2072      1.71      yamt 		    KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL) != 0)
   2073      1.55      elad 			continue;
   2074      1.55      elad 
   2075       1.1    atatat 		/*
   2076       1.1    atatat 		 * TODO - make more efficient (see notes below).
   2077       1.1    atatat 		 * do by session.
   2078       1.1    atatat 		 */
   2079       1.1    atatat 		switch (op) {
   2080       1.1    atatat 
   2081       1.1    atatat 		case KERN_PROC_PID:
   2082       1.1    atatat 			/* could do this with just a lookup */
   2083       1.1    atatat 			if (p->p_pid != (pid_t)arg)
   2084       1.1    atatat 				continue;
   2085       1.1    atatat 			break;
   2086       1.1    atatat 
   2087       1.1    atatat 		case KERN_PROC_PGRP:
   2088       1.1    atatat 			/* could do this by traversing pgrp */
   2089       1.1    atatat 			if (p->p_pgrp->pg_id != (pid_t)arg)
   2090       1.1    atatat 				continue;
   2091       1.1    atatat 			break;
   2092       1.1    atatat 
   2093       1.1    atatat 		case KERN_PROC_SESSION:
   2094       1.1    atatat 			if (p->p_session->s_sid != (pid_t)arg)
   2095       1.1    atatat 				continue;
   2096       1.1    atatat 			break;
   2097       1.1    atatat 
   2098       1.1    atatat 		case KERN_PROC_TTY:
   2099       1.1    atatat 			if (arg == (int) KERN_PROC_TTY_REVOKE) {
   2100  1.81.4.4        ad 				if ((p->p_lflag & PL_CONTROLT) == 0 ||
   2101       1.1    atatat 				    p->p_session->s_ttyp == NULL ||
   2102       1.1    atatat 				    p->p_session->s_ttyvp != NULL)
   2103       1.1    atatat 					continue;
   2104  1.81.4.4        ad 			} else if ((p->p_lflag & PL_CONTROLT) == 0 ||
   2105       1.1    atatat 			    p->p_session->s_ttyp == NULL) {
   2106       1.1    atatat 				if ((dev_t)arg != KERN_PROC_TTY_NODEV)
   2107       1.1    atatat 					continue;
   2108       1.1    atatat 			} else if (p->p_session->s_ttyp->t_dev != (dev_t)arg)
   2109       1.1    atatat 				continue;
   2110       1.1    atatat 			break;
   2111       1.1    atatat 
   2112       1.1    atatat 		case KERN_PROC_UID:
   2113      1.68      elad 			if (kauth_cred_geteuid(p->p_cred) != (uid_t)arg)
   2114       1.1    atatat 				continue;
   2115       1.1    atatat 			break;
   2116       1.1    atatat 
   2117       1.1    atatat 		case KERN_PROC_RUID:
   2118      1.68      elad 			if (kauth_cred_getuid(p->p_cred) != (uid_t)arg)
   2119       1.1    atatat 				continue;
   2120       1.1    atatat 			break;
   2121       1.1    atatat 
   2122       1.1    atatat 		case KERN_PROC_GID:
   2123      1.68      elad 			if (kauth_cred_getegid(p->p_cred) != (uid_t)arg)
   2124       1.1    atatat 				continue;
   2125       1.1    atatat 			break;
   2126       1.1    atatat 
   2127       1.1    atatat 		case KERN_PROC_RGID:
   2128      1.68      elad 			if (kauth_cred_getgid(p->p_cred) != (uid_t)arg)
   2129       1.1    atatat 				continue;
   2130       1.1    atatat 			break;
   2131       1.1    atatat 
   2132       1.1    atatat 		case KERN_PROC_ALL:
   2133       1.1    atatat 			/* allow everything */
   2134       1.1    atatat 			break;
   2135       1.1    atatat 
   2136       1.1    atatat 		default:
   2137       1.1    atatat 			error = EINVAL;
   2138       1.1    atatat 			goto cleanup;
   2139       1.1    atatat 		}
   2140       1.1    atatat 		if (type == KERN_PROC) {
   2141       1.1    atatat 			if (buflen >= sizeof(struct kinfo_proc)) {
   2142      1.73  christos 				fill_eproc(p, eproc);
   2143  1.81.4.5        ad 				error = dcopyout(l, p, &dp->kp_proc,
   2144       1.1    atatat 				    sizeof(struct proc));
   2145       1.1    atatat 				if (error)
   2146       1.1    atatat 					goto cleanup;
   2147  1.81.4.5        ad 				error = dcopyout(l, eproc, &dp->kp_eproc,
   2148      1.73  christos 				    sizeof(*eproc));
   2149       1.1    atatat 				if (error)
   2150       1.1    atatat 					goto cleanup;
   2151       1.1    atatat 				dp++;
   2152       1.1    atatat 				buflen -= sizeof(struct kinfo_proc);
   2153       1.1    atatat 			}
   2154       1.1    atatat 			needed += sizeof(struct kinfo_proc);
   2155       1.1    atatat 		} else { /* KERN_PROC2 */
   2156       1.1    atatat 			if (buflen >= elem_size && elem_count > 0) {
   2157      1.73  christos 				fill_kproc2(p, kproc2);
   2158       1.1    atatat 				/*
   2159       1.1    atatat 				 * Copy out elem_size, but not larger than
   2160       1.1    atatat 				 * the size of a struct kinfo_proc2.
   2161       1.1    atatat 				 */
   2162  1.81.4.5        ad 				error = dcopyout(l, kproc2, dp2,
   2163      1.73  christos 				    min(sizeof(*kproc2), elem_size));
   2164       1.1    atatat 				if (error)
   2165       1.1    atatat 					goto cleanup;
   2166       1.1    atatat 				dp2 += elem_size;
   2167       1.1    atatat 				buflen -= elem_size;
   2168       1.1    atatat 				elem_count--;
   2169       1.1    atatat 			}
   2170       1.1    atatat 			needed += elem_size;
   2171       1.1    atatat 		}
   2172       1.1    atatat 	}
   2173       1.1    atatat 	pd++;
   2174       1.1    atatat 	if (pd->pd_list != NULL)
   2175       1.1    atatat 		goto again;
   2176  1.81.4.1        ad 	rw_exit(&proclist_lock);
   2177       1.1    atatat 
   2178       1.1    atatat 	if (where != NULL) {
   2179       1.1    atatat 		if (type == KERN_PROC)
   2180       1.1    atatat 			*oldlenp = (char *)dp - where;
   2181       1.1    atatat 		else
   2182       1.1    atatat 			*oldlenp = dp2 - where;
   2183      1.73  christos 		if (needed > *oldlenp) {
   2184      1.73  christos 			error = ENOMEM;
   2185      1.73  christos 			goto out;
   2186      1.73  christos 		}
   2187       1.1    atatat 	} else {
   2188      1.22    atatat 		needed += KERN_PROCSLOP;
   2189       1.1    atatat 		*oldlenp = needed;
   2190       1.1    atatat 	}
   2191      1.74  christos 	if (kproc2)
   2192      1.74  christos 		free(kproc2, M_TEMP);
   2193      1.74  christos 	if (eproc)
   2194      1.74  christos 		free(eproc, M_TEMP);
   2195      1.74  christos 	return 0;
   2196       1.1    atatat  cleanup:
   2197  1.81.4.1        ad 	rw_exit(&proclist_lock);
   2198      1.73  christos  out:
   2199      1.74  christos 	if (kproc2)
   2200      1.74  christos 		free(kproc2, M_TEMP);
   2201      1.74  christos 	if (eproc)
   2202      1.74  christos 		free(eproc, M_TEMP);
   2203      1.74  christos 	return error;
   2204       1.1    atatat }
   2205       1.1    atatat 
   2206       1.1    atatat /*
   2207       1.1    atatat  * sysctl helper routine for kern.proc_args pseudo-subtree.
   2208       1.1    atatat  */
   2209       1.1    atatat static int
   2210       1.1    atatat sysctl_kern_proc_args(SYSCTLFN_ARGS)
   2211       1.1    atatat {
   2212       1.1    atatat 	struct ps_strings pss;
   2213      1.78        ad 	struct proc *p;
   2214  1.81.4.5        ad 	size_t len, i;
   2215       1.1    atatat 	struct uio auio;
   2216       1.1    atatat 	struct iovec aiov;
   2217       1.1    atatat 	pid_t pid;
   2218       1.1    atatat 	int nargv, type, error;
   2219       1.1    atatat 	char *arg;
   2220  1.81.4.5        ad 	char **argv = NULL;
   2221       1.1    atatat 	char *tmp;
   2222      1.56      yamt 	struct vmspace *vmspace;
   2223      1.56      yamt 	vaddr_t psstr_addr;
   2224      1.56      yamt 	vaddr_t offsetn;
   2225      1.56      yamt 	vaddr_t offsetv;
   2226       1.1    atatat 
   2227      1.19    atatat 	if (namelen == 1 && name[0] == CTL_QUERY)
   2228      1.43    atatat 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   2229      1.19    atatat 
   2230       1.1    atatat 	if (newp != NULL || namelen != 2)
   2231       1.1    atatat 		return (EINVAL);
   2232       1.1    atatat 	pid = name[0];
   2233       1.1    atatat 	type = name[1];
   2234       1.1    atatat 
   2235       1.1    atatat 	switch (type) {
   2236       1.1    atatat 	case KERN_PROC_ARGV:
   2237       1.1    atatat 	case KERN_PROC_NARGV:
   2238       1.1    atatat 	case KERN_PROC_ENV:
   2239       1.1    atatat 	case KERN_PROC_NENV:
   2240       1.1    atatat 		/* ok */
   2241       1.1    atatat 		break;
   2242       1.1    atatat 	default:
   2243       1.1    atatat 		return (EINVAL);
   2244       1.1    atatat 	}
   2245       1.1    atatat 
   2246  1.81.4.1        ad 	rw_enter(&proclist_lock, RW_READER);
   2247      1.56      yamt 
   2248       1.1    atatat 	/* check pid */
   2249      1.56      yamt 	if ((p = p_find(pid, PFIND_LOCKED)) == NULL) {
   2250      1.56      yamt 		error = EINVAL;
   2251      1.56      yamt 		goto out_locked;
   2252      1.56      yamt 	}
   2253       1.1    atatat 
   2254      1.78        ad 	error = kauth_authorize_process(l->l_cred,
   2255      1.71      yamt 	    KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL);
   2256      1.71      yamt 	if (error) {
   2257      1.56      yamt 		goto out_locked;
   2258      1.56      yamt 	}
   2259      1.55      elad 
   2260       1.1    atatat 	/* only root or same user change look at the environment */
   2261       1.1    atatat 	if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
   2262  1.81.4.5        ad 		if (kauth_authorize_process(l->l_cred, KAUTH_PROCESS_CANSEE,
   2263  1.81.4.5        ad 		     p, NULL, NULL, NULL)) {
   2264      1.56      yamt 				error = EPERM;
   2265      1.56      yamt 				goto out_locked;
   2266       1.1    atatat 		}
   2267       1.1    atatat 	}
   2268       1.1    atatat 
   2269       1.1    atatat 	if (oldp == NULL) {
   2270       1.1    atatat 		if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
   2271       1.1    atatat 			*oldlenp = sizeof (int);
   2272       1.1    atatat 		else
   2273       1.1    atatat 			*oldlenp = ARG_MAX;	/* XXX XXX XXX */
   2274      1.56      yamt 		error = 0;
   2275      1.56      yamt 		goto out_locked;
   2276       1.1    atatat 	}
   2277       1.1    atatat 
   2278       1.1    atatat 	/*
   2279       1.1    atatat 	 * Zombies don't have a stack, so we can't read their psstrings.
   2280       1.1    atatat 	 * System processes also don't have a user stack.
   2281       1.1    atatat 	 */
   2282      1.56      yamt 	if (P_ZOMBIE(p) || (p->p_flag & P_SYSTEM) != 0) {
   2283      1.56      yamt 		error = EINVAL;
   2284      1.56      yamt 		goto out_locked;
   2285      1.56      yamt 	}
   2286       1.1    atatat 
   2287       1.1    atatat 	/*
   2288       1.1    atatat 	 * Lock the process down in memory.
   2289       1.1    atatat 	 */
   2290       1.1    atatat 	/* XXXCDC: how should locking work here? */
   2291  1.81.4.2        ad 	if ((l->l_flag & L_WEXIT) || (p->p_vmspace->vm_refcnt < 1)) {
   2292      1.56      yamt 		error = EFAULT;
   2293      1.56      yamt 		goto out_locked;
   2294      1.56      yamt 	}
   2295       1.1    atatat 
   2296      1.56      yamt 	psstr_addr = (vaddr_t)p->p_psstr;
   2297      1.56      yamt 	if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV) {
   2298      1.56      yamt 		offsetn = p->p_psnargv;
   2299      1.56      yamt 		offsetv = p->p_psargv;
   2300      1.56      yamt 	} else {
   2301      1.56      yamt 		offsetn = p->p_psnenv;
   2302      1.56      yamt 		offsetv = p->p_psenv;
   2303      1.56      yamt 	}
   2304      1.56      yamt 	vmspace = p->p_vmspace;
   2305      1.56      yamt 	vmspace->vm_refcnt++;	/* XXX */
   2306      1.56      yamt 
   2307  1.81.4.1        ad 	rw_exit(&proclist_lock);
   2308       1.1    atatat 
   2309       1.1    atatat 	/*
   2310       1.1    atatat 	 * Allocate a temporary buffer to hold the arguments.
   2311       1.1    atatat 	 */
   2312       1.1    atatat 	arg = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
   2313       1.1    atatat 
   2314       1.1    atatat 	/*
   2315       1.1    atatat 	 * Read in the ps_strings structure.
   2316       1.1    atatat 	 */
   2317       1.1    atatat 	aiov.iov_base = &pss;
   2318       1.1    atatat 	aiov.iov_len = sizeof(pss);
   2319       1.1    atatat 	auio.uio_iov = &aiov;
   2320       1.1    atatat 	auio.uio_iovcnt = 1;
   2321      1.56      yamt 	auio.uio_offset = psstr_addr;
   2322       1.1    atatat 	auio.uio_resid = sizeof(pss);
   2323       1.1    atatat 	auio.uio_rw = UIO_READ;
   2324      1.63      yamt 	UIO_SETUP_SYSSPACE(&auio);
   2325      1.56      yamt 	error = uvm_io(&vmspace->vm_map, &auio);
   2326       1.1    atatat 	if (error)
   2327       1.1    atatat 		goto done;
   2328       1.1    atatat 
   2329      1.56      yamt 	memcpy(&nargv, (char *)&pss + offsetn, sizeof(nargv));
   2330       1.1    atatat 	if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
   2331  1.81.4.5        ad 		error = dcopyout(l, &nargv, oldp, sizeof(nargv));
   2332       1.1    atatat 		*oldlenp = sizeof(nargv);
   2333       1.1    atatat 		goto done;
   2334       1.1    atatat 	}
   2335       1.1    atatat 	/*
   2336       1.1    atatat 	 * Now read the address of the argument vector.
   2337       1.1    atatat 	 */
   2338       1.1    atatat 	switch (type) {
   2339       1.1    atatat 	case KERN_PROC_ARGV:
   2340      1.56      yamt 		/* FALLTHROUGH */
   2341       1.1    atatat 	case KERN_PROC_ENV:
   2342      1.56      yamt 		memcpy(&tmp, (char *)&pss + offsetv, sizeof(tmp));
   2343       1.1    atatat 		break;
   2344       1.1    atatat 	default:
   2345       1.1    atatat 		return (EINVAL);
   2346       1.1    atatat 	}
   2347  1.81.4.5        ad 
   2348  1.81.4.5        ad #ifdef COMPAT_NETBSD32
   2349  1.81.4.5        ad 	if (p->p_flag & P_32)
   2350  1.81.4.5        ad 		len = sizeof(netbsd32_charp) * nargv;
   2351  1.81.4.5        ad 	else
   2352  1.81.4.5        ad #endif
   2353  1.81.4.5        ad 		len = sizeof(char *) * nargv;
   2354  1.81.4.5        ad 
   2355  1.81.4.5        ad 	argv = malloc(len, M_TEMP, M_WAITOK);
   2356  1.81.4.5        ad 
   2357  1.81.4.5        ad 	aiov.iov_base = argv;
   2358  1.81.4.5        ad 	aiov.iov_len = len;
   2359       1.1    atatat 	auio.uio_iov = &aiov;
   2360       1.1    atatat 	auio.uio_iovcnt = 1;
   2361  1.81.4.5        ad 	auio.uio_offset = (off_t)(unsigned long)tmp;
   2362  1.81.4.5        ad 	auio.uio_resid = len;
   2363       1.1    atatat 	auio.uio_rw = UIO_READ;
   2364      1.63      yamt 	UIO_SETUP_SYSSPACE(&auio);
   2365      1.56      yamt 	error = uvm_io(&vmspace->vm_map, &auio);
   2366       1.1    atatat 	if (error)
   2367       1.1    atatat 		goto done;
   2368       1.1    atatat 
   2369  1.81.4.5        ad 	/*
   2370  1.81.4.5        ad 	 * Now copy each string.
   2371       1.1    atatat 	 */
   2372  1.81.4.5        ad 	len = 0; /* bytes written to user buffer */
   2373  1.81.4.5        ad 	for (i = 0; i < nargv; i++) {
   2374  1.81.4.5        ad 		int finished = 0;
   2375  1.81.4.5        ad 		vaddr_t base;
   2376  1.81.4.5        ad 		size_t xlen;
   2377  1.81.4.5        ad 		int j;
   2378  1.81.4.5        ad 
   2379  1.81.4.5        ad #ifdef COMPAT_NETBSD32
   2380  1.81.4.5        ad 		if (p->p_flag & P_32) {
   2381  1.81.4.5        ad 			netbsd32_charp *argv32;
   2382       1.1    atatat 
   2383  1.81.4.5        ad 			argv32 = (netbsd32_charp *)argv;
   2384       1.1    atatat 
   2385  1.81.4.5        ad 			base = (vaddr_t)NETBSD32PTR64(argv32[i]);
   2386  1.81.4.5        ad 		} else
   2387  1.81.4.5        ad #endif
   2388  1.81.4.5        ad 			base = (vaddr_t)argv[i];
   2389       1.1    atatat 
   2390  1.81.4.5        ad 		while (!finished) {
   2391  1.81.4.5        ad 			xlen = PAGE_SIZE - (base & PAGE_MASK);
   2392       1.1    atatat 
   2393  1.81.4.5        ad 			aiov.iov_base = arg;
   2394  1.81.4.5        ad 			aiov.iov_len = PAGE_SIZE;
   2395  1.81.4.5        ad 			auio.uio_iov = &aiov;
   2396  1.81.4.5        ad 			auio.uio_iovcnt = 1;
   2397  1.81.4.5        ad 			auio.uio_offset = base;
   2398  1.81.4.5        ad 			auio.uio_resid = xlen;
   2399  1.81.4.5        ad 			auio.uio_rw = UIO_READ;
   2400  1.81.4.5        ad 			UIO_SETUP_SYSSPACE(&auio);
   2401  1.81.4.5        ad 			error = uvm_io(&vmspace->vm_map, &auio);
   2402  1.81.4.5        ad 			if (error)
   2403  1.81.4.5        ad 				goto done;
   2404  1.81.4.5        ad 
   2405  1.81.4.5        ad 			/* Look for the end of the string */
   2406  1.81.4.5        ad 			for (j = 0; j < xlen; j++) {
   2407  1.81.4.5        ad 				if (arg[j] == '\0') {
   2408  1.81.4.5        ad 					xlen = j + 1;
   2409  1.81.4.5        ad 					finished = 1;
   2410  1.81.4.5        ad 					break;
   2411  1.81.4.5        ad 				}
   2412  1.81.4.5        ad 			}
   2413  1.81.4.5        ad 
   2414  1.81.4.5        ad 			/* Check for user buffer overflow */
   2415  1.81.4.5        ad 			if (len + xlen > *oldlenp) {
   2416  1.81.4.5        ad 				finished = 1;
   2417  1.81.4.5        ad 				if (len > *oldlenp)
   2418  1.81.4.5        ad 					xlen = 0;
   2419  1.81.4.5        ad 				else
   2420  1.81.4.5        ad 					xlen = *oldlenp - len;
   2421  1.81.4.5        ad 			}
   2422  1.81.4.5        ad 
   2423  1.81.4.5        ad 			/* Copyout the page */
   2424  1.81.4.5        ad 			error = dcopyout(l, arg, (char *)oldp + len, xlen);
   2425  1.81.4.5        ad 			if (error)
   2426  1.81.4.5        ad 				goto done;
   2427  1.81.4.5        ad 
   2428  1.81.4.5        ad 			len += xlen;
   2429  1.81.4.5        ad 			base += xlen;
   2430       1.1    atatat 		}
   2431       1.1    atatat 	}
   2432       1.1    atatat 	*oldlenp = len;
   2433       1.1    atatat 
   2434       1.1    atatat done:
   2435  1.81.4.5        ad 	if (argv != NULL)
   2436  1.81.4.5        ad 		free(argv, M_TEMP);
   2437  1.81.4.5        ad 
   2438      1.56      yamt 	uvmspace_free(vmspace);
   2439       1.1    atatat 
   2440       1.1    atatat 	free(arg, M_TEMP);
   2441      1.56      yamt 	return error;
   2442      1.56      yamt 
   2443      1.56      yamt out_locked:
   2444  1.81.4.1        ad 	rw_exit(&proclist_lock);
   2445      1.56      yamt 	return error;
   2446       1.1    atatat }
   2447       1.1    atatat 
   2448      1.61      elad static int
   2449      1.61      elad sysctl_security_setidcore(SYSCTLFN_ARGS)
   2450      1.61      elad {
   2451      1.61      elad 	int newsize, error;
   2452      1.61      elad 	struct sysctlnode node;
   2453      1.61      elad 
   2454      1.61      elad 	node = *rnode;
   2455      1.61      elad 	node.sysctl_data = &newsize;
   2456      1.61      elad 	newsize = *(int *)rnode->sysctl_data;
   2457      1.61      elad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   2458      1.61      elad 	if (error || newp == NULL)
   2459      1.61      elad 		return error;
   2460      1.61      elad 
   2461  1.81.4.5        ad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
   2462  1.81.4.5        ad 	    0, NULL, NULL, NULL))
   2463      1.61      elad 		return (EPERM);
   2464      1.61      elad 
   2465      1.61      elad 	*(int *)rnode->sysctl_data = newsize;
   2466      1.61      elad 
   2467      1.61      elad 	return 0;
   2468      1.61      elad }
   2469      1.61      elad 
   2470      1.61      elad static int
   2471      1.61      elad sysctl_security_setidcorename(SYSCTLFN_ARGS)
   2472      1.61      elad {
   2473      1.61      elad 	int error;
   2474      1.72      yamt 	char *newsetidcorename;
   2475      1.61      elad 	struct sysctlnode node;
   2476      1.61      elad 
   2477      1.72      yamt 	newsetidcorename = PNBUF_GET();
   2478      1.61      elad 	node = *rnode;
   2479      1.72      yamt 	node.sysctl_data = newsetidcorename;
   2480      1.61      elad 	memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
   2481      1.61      elad 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   2482      1.72      yamt 	if (error || newp == NULL) {
   2483      1.72      yamt 		goto out;
   2484      1.72      yamt 	}
   2485  1.81.4.5        ad 	if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
   2486  1.81.4.5        ad 	    0, NULL, NULL, NULL)) {
   2487      1.72      yamt 		error = EPERM;
   2488      1.72      yamt 		goto out;
   2489      1.72      yamt 	}
   2490      1.72      yamt 	if (strlen(newsetidcorename) == 0) {
   2491      1.72      yamt 		error = EINVAL;
   2492      1.72      yamt 		goto out;
   2493      1.72      yamt 	}
   2494      1.61      elad 	memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
   2495      1.72      yamt out:
   2496      1.72      yamt 	PNBUF_PUT(newsetidcorename);
   2497      1.72      yamt 	return error;
   2498      1.61      elad }
   2499      1.61      elad 
   2500      1.38      elad /*
   2501      1.45  christos  * sysctl helper routine for kern.cp_id node.  maps cpus to their
   2502      1.45  christos  * cpuids.
   2503      1.45  christos  */
   2504      1.45  christos static int
   2505      1.45  christos sysctl_kern_cpid(SYSCTLFN_ARGS)
   2506      1.45  christos {
   2507      1.45  christos 	struct sysctlnode node = *rnode;
   2508      1.45  christos 
   2509      1.45  christos #ifndef MULTIPROCESSOR
   2510      1.59     perry 	uint64_t id;
   2511      1.45  christos 
   2512      1.45  christos 	if (namelen == 1) {
   2513      1.45  christos 		if (name[0] != 0)
   2514      1.45  christos 			return (ENOENT);
   2515      1.45  christos 		/*
   2516      1.45  christos 		 * you're allowed to ask for the zero'th processor
   2517      1.45  christos 		 */
   2518      1.45  christos 		name++;
   2519      1.45  christos 		namelen--;
   2520      1.45  christos 	}
   2521      1.45  christos 	node.sysctl_data = &id;
   2522      1.45  christos 	node.sysctl_size = sizeof(id);
   2523      1.45  christos 	id = cpu_number();
   2524      1.45  christos 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   2525      1.45  christos 
   2526      1.45  christos #else /* MULTIPROCESSOR */
   2527      1.59     perry 	uint64_t *cp_id = NULL;
   2528      1.45  christos 	int error, n = sysctl_ncpus();
   2529      1.45  christos 	struct cpu_info *ci;
   2530      1.45  christos 	CPU_INFO_ITERATOR cii;
   2531      1.45  christos 
   2532      1.45  christos 	/*
   2533      1.46    atatat 	 * here you may either retrieve a single cpu id or the whole
   2534      1.46    atatat 	 * set.  the size you get back when probing depends on what
   2535      1.46    atatat 	 * you ask for.
   2536      1.45  christos 	 */
   2537      1.45  christos 	switch (namelen) {
   2538      1.45  christos 	case 0:
   2539      1.59     perry 		node.sysctl_size = n * sizeof(uint64_t);
   2540      1.45  christos 		n = -2; /* ALL */
   2541      1.45  christos 		break;
   2542      1.45  christos 	case 1:
   2543      1.45  christos 		if (name[0] < 0 || name[0] >= n)
   2544      1.45  christos 			return (ENOENT); /* ENOSUCHPROCESSOR */
   2545      1.59     perry 		node.sysctl_size = sizeof(uint64_t);
   2546      1.45  christos 		n = name[0];
   2547      1.45  christos 		/*
   2548      1.45  christos 		 * adjust these so that sysctl_lookup() will be happy
   2549      1.45  christos 		 */
   2550      1.45  christos 		name++;
   2551      1.45  christos 		namelen--;
   2552      1.45  christos 		break;
   2553      1.45  christos 	default:
   2554      1.45  christos 		return (EINVAL);
   2555      1.45  christos 	}
   2556      1.45  christos 
   2557      1.45  christos 	cp_id = malloc(node.sysctl_size, M_TEMP, M_WAITOK|M_CANFAIL);
   2558      1.45  christos 	if (cp_id == NULL)
   2559      1.45  christos 		return (ENOMEM);
   2560      1.45  christos 	node.sysctl_data = cp_id;
   2561      1.45  christos 	memset(cp_id, 0, node.sysctl_size);
   2562      1.45  christos 
   2563      1.45  christos 	for (CPU_INFO_FOREACH(cii, ci)) {
   2564      1.45  christos 		if (n <= 0)
   2565      1.45  christos 			cp_id[0] = ci->ci_cpuid;
   2566      1.45  christos 		/*
   2567      1.45  christos 		 * if a specific processor was requested and we just
   2568      1.45  christos 		 * did it, we're done here
   2569      1.45  christos 		 */
   2570      1.45  christos 		if (n == 0)
   2571      1.45  christos 			break;
   2572      1.45  christos 		/*
   2573      1.45  christos 		 * if doing "all", skip to next cp_id slot for next processor
   2574      1.45  christos 		 */
   2575      1.45  christos 		if (n == -2)
   2576      1.45  christos 			cp_id++;
   2577      1.45  christos 		/*
   2578      1.45  christos 		 * if we're doing a specific processor, we're one
   2579      1.45  christos 		 * processor closer
   2580      1.45  christos 		 */
   2581      1.45  christos 		if (n > 0)
   2582      1.45  christos 			n--;
   2583      1.45  christos 	}
   2584      1.45  christos 
   2585      1.45  christos 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   2586      1.45  christos 	free(node.sysctl_data, M_TEMP);
   2587      1.45  christos 	return (error);
   2588      1.45  christos 
   2589      1.45  christos #endif /* MULTIPROCESSOR */
   2590      1.45  christos }
   2591      1.45  christos 
   2592      1.45  christos /*
   2593       1.1    atatat  * sysctl helper routine for hw.usermem and hw.usermem64.  values are
   2594       1.1    atatat  * calculate on the fly taking into account integer overflow and the
   2595       1.1    atatat  * current wired count.
   2596       1.1    atatat  */
   2597       1.1    atatat static int
   2598       1.1    atatat sysctl_hw_usermem(SYSCTLFN_ARGS)
   2599       1.1    atatat {
   2600       1.1    atatat 	u_int ui;
   2601       1.1    atatat 	u_quad_t uq;
   2602       1.1    atatat 	struct sysctlnode node;
   2603       1.1    atatat 
   2604       1.1    atatat 	node = *rnode;
   2605       1.1    atatat 	switch (rnode->sysctl_num) {
   2606       1.1    atatat 	    case HW_USERMEM:
   2607       1.1    atatat 		if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
   2608       1.1    atatat 			ui = UINT_MAX;
   2609       1.1    atatat 		else
   2610       1.1    atatat 			ui *= PAGE_SIZE;
   2611       1.1    atatat 		node.sysctl_data = &ui;
   2612       1.1    atatat 		break;
   2613       1.1    atatat 	case HW_USERMEM64:
   2614       1.1    atatat 		uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
   2615       1.1    atatat 		node.sysctl_data = &uq;
   2616       1.1    atatat 		break;
   2617       1.1    atatat 	default:
   2618       1.1    atatat 		return (EINVAL);
   2619       1.1    atatat 	}
   2620       1.1    atatat 
   2621       1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   2622       1.1    atatat }
   2623       1.1    atatat 
   2624       1.1    atatat /*
   2625       1.1    atatat  * sysctl helper routine for kern.cnmagic node.  pulls the old value
   2626       1.1    atatat  * out, encoded, and stuffs the new value in for decoding.
   2627       1.1    atatat  */
   2628       1.1    atatat static int
   2629       1.1    atatat sysctl_hw_cnmagic(SYSCTLFN_ARGS)
   2630       1.1    atatat {
   2631       1.1    atatat 	char magic[CNS_LEN];
   2632       1.1    atatat 	int error;
   2633       1.1    atatat 	struct sysctlnode node;
   2634       1.1    atatat 
   2635       1.1    atatat 	if (oldp)
   2636       1.1    atatat 		cn_get_magic(magic, CNS_LEN);
   2637       1.1    atatat 	node = *rnode;
   2638       1.1    atatat 	node.sysctl_data = &magic[0];
   2639       1.1    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
   2640       1.1    atatat 	if (error || newp == NULL)
   2641       1.1    atatat 		return (error);
   2642      1.33     perry 
   2643       1.1    atatat 	return (cn_set_magic(magic));
   2644       1.1    atatat }
   2645       1.3    martin 
   2646       1.3    martin static int
   2647       1.3    martin sysctl_hw_ncpu(SYSCTLFN_ARGS)
   2648       1.3    martin {
   2649       1.3    martin 	int ncpu;
   2650       1.3    martin 	struct sysctlnode node;
   2651       1.3    martin 
   2652       1.3    martin 	ncpu = sysctl_ncpus();
   2653       1.3    martin 	node = *rnode;
   2654       1.3    martin 	node.sysctl_data = &ncpu;
   2655      1.33     perry 
   2656       1.3    martin 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   2657       1.3    martin }
   2658       1.3    martin 
   2659       1.1    atatat 
   2660       1.1    atatat /*
   2661       1.1    atatat  * ********************************************************************
   2662       1.1    atatat  * section 3: public helper routines that are used for more than one
   2663       1.1    atatat  * node
   2664       1.1    atatat  * ********************************************************************
   2665       1.1    atatat  */
   2666       1.1    atatat 
   2667       1.1    atatat /*
   2668       1.1    atatat  * sysctl helper routine for the kern.root_device node and some ports'
   2669       1.1    atatat  * machdep.root_device nodes.
   2670       1.1    atatat  */
   2671       1.1    atatat int
   2672       1.1    atatat sysctl_root_device(SYSCTLFN_ARGS)
   2673       1.1    atatat {
   2674       1.1    atatat 	struct sysctlnode node;
   2675       1.1    atatat 
   2676       1.1    atatat 	node = *rnode;
   2677       1.1    atatat 	node.sysctl_data = root_device->dv_xname;
   2678       1.1    atatat 	node.sysctl_size = strlen(root_device->dv_xname) + 1;
   2679       1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   2680       1.1    atatat }
   2681       1.1    atatat 
   2682       1.1    atatat /*
   2683       1.1    atatat  * sysctl helper routine for kern.consdev, dependent on the current
   2684       1.1    atatat  * state of the console.  also used for machdep.console_device on some
   2685       1.1    atatat  * ports.
   2686       1.1    atatat  */
   2687       1.1    atatat int
   2688       1.1    atatat sysctl_consdev(SYSCTLFN_ARGS)
   2689       1.1    atatat {
   2690       1.1    atatat 	dev_t consdev;
   2691       1.1    atatat 	struct sysctlnode node;
   2692       1.1    atatat 
   2693       1.1    atatat 	if (cn_tab != NULL)
   2694       1.1    atatat 		consdev = cn_tab->cn_dev;
   2695       1.1    atatat 	else
   2696       1.1    atatat 		consdev = NODEV;
   2697       1.1    atatat 	node = *rnode;
   2698       1.1    atatat 	node.sysctl_data = &consdev;
   2699       1.1    atatat 	node.sysctl_size = sizeof(consdev);
   2700       1.1    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
   2701       1.1    atatat }
   2702       1.1    atatat 
   2703       1.1    atatat /*
   2704       1.1    atatat  * ********************************************************************
   2705       1.1    atatat  * section 4: support for some helpers
   2706       1.1    atatat  * ********************************************************************
   2707       1.1    atatat  */
   2708       1.1    atatat 
   2709       1.1    atatat /*
   2710       1.1    atatat  * Fill in a kinfo_proc2 structure for the specified process.
   2711       1.1    atatat  */
   2712       1.1    atatat static void
   2713       1.1    atatat fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
   2714       1.1    atatat {
   2715       1.1    atatat 	struct tty *tp;
   2716  1.81.4.2        ad 	struct lwp *l, *l2;
   2717  1.81.4.2        ad 	struct timeval ut, st, rt;
   2718  1.81.4.4        ad 	sigset_t ss1, ss2;
   2719       1.1    atatat 
   2720       1.1    atatat 	memset(ki, 0, sizeof(*ki));
   2721       1.1    atatat 
   2722      1.21    atatat 	ki->p_paddr = PTRTOUINT64(p);
   2723      1.21    atatat 	ki->p_fd = PTRTOUINT64(p->p_fd);
   2724      1.21    atatat 	ki->p_cwdi = PTRTOUINT64(p->p_cwdi);
   2725      1.21    atatat 	ki->p_stats = PTRTOUINT64(p->p_stats);
   2726      1.21    atatat 	ki->p_limit = PTRTOUINT64(p->p_limit);
   2727      1.21    atatat 	ki->p_vmspace = PTRTOUINT64(p->p_vmspace);
   2728      1.21    atatat 	ki->p_sigacts = PTRTOUINT64(p->p_sigacts);
   2729      1.21    atatat 	ki->p_sess = PTRTOUINT64(p->p_session);
   2730       1.1    atatat 	ki->p_tsess = 0;	/* may be changed if controlling tty below */
   2731      1.21    atatat 	ki->p_ru = PTRTOUINT64(p->p_ru);
   2732       1.1    atatat 
   2733       1.1    atatat 	ki->p_eflag = 0;
   2734       1.1    atatat 	ki->p_exitsig = p->p_exitsig;
   2735  1.81.4.6        ad 
   2736  1.81.4.6        ad 	ki->p_flag = sysctl_map_flags(sysctl_flagmap, p->p_flag);
   2737  1.81.4.6        ad 	ki->p_flag |= sysctl_map_flags(sysctl_sflagmap, p->p_sflag);
   2738  1.81.4.6        ad 	ki->p_flag |= sysctl_map_flags(sysctl_slflagmap, p->p_slflag);
   2739  1.81.4.6        ad 	ki->p_flag |= sysctl_map_flags(sysctl_lflagmap, p->p_lflag);
   2740  1.81.4.6        ad 	ki->p_flag |= sysctl_map_flags(sysctl_stflagmap, p->p_stflag);
   2741       1.1    atatat 
   2742       1.1    atatat 	ki->p_pid = p->p_pid;
   2743       1.1    atatat 	if (p->p_pptr)
   2744       1.1    atatat 		ki->p_ppid = p->p_pptr->p_pid;
   2745       1.1    atatat 	else
   2746       1.1    atatat 		ki->p_ppid = 0;
   2747       1.1    atatat 	ki->p_sid = p->p_session->s_sid;
   2748       1.1    atatat 	ki->p__pgid = p->p_pgrp->pg_id;
   2749       1.1    atatat 
   2750       1.1    atatat 	ki->p_tpgid = NO_PGID;	/* may be changed if controlling tty below */
   2751       1.1    atatat 
   2752      1.68      elad 	ki->p_uid = kauth_cred_geteuid(p->p_cred);
   2753      1.68      elad 	ki->p_ruid = kauth_cred_getuid(p->p_cred);
   2754      1.68      elad 	ki->p_gid = kauth_cred_getegid(p->p_cred);
   2755      1.68      elad 	ki->p_rgid = kauth_cred_getgid(p->p_cred);
   2756      1.68      elad 	ki->p_svuid = kauth_cred_getsvuid(p->p_cred);
   2757      1.68      elad 	ki->p_svgid = kauth_cred_getsvgid(p->p_cred);
   2758      1.68      elad 
   2759      1.68      elad 	ki->p_ngroups = kauth_cred_ngroups(p->p_cred);
   2760      1.68      elad 	kauth_cred_getgroups(p->p_cred, ki->p_groups,
   2761      1.68      elad 	    min(ki->p_ngroups, sizeof(ki->p_groups) / sizeof(ki->p_groups[0])));
   2762       1.1    atatat 
   2763       1.1    atatat 	ki->p_jobc = p->p_pgrp->pg_jobc;
   2764  1.81.4.4        ad 	if ((p->p_lflag & PL_CONTROLT) && (tp = p->p_session->s_ttyp)) {
   2765       1.1    atatat 		ki->p_tdev = tp->t_dev;
   2766       1.1    atatat 		ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
   2767      1.21    atatat 		ki->p_tsess = PTRTOUINT64(tp->t_session);
   2768       1.1    atatat 	} else {
   2769       1.1    atatat 		ki->p_tdev = NODEV;
   2770       1.1    atatat 	}
   2771       1.1    atatat 
   2772       1.1    atatat 	ki->p_estcpu = p->p_estcpu;
   2773       1.1    atatat 	ki->p_cpticks = p->p_cpticks;
   2774       1.1    atatat 	ki->p_pctcpu = p->p_pctcpu;
   2775       1.1    atatat 
   2776       1.1    atatat 	ki->p_uticks = p->p_uticks;
   2777       1.1    atatat 	ki->p_sticks = p->p_sticks;
   2778       1.1    atatat 	ki->p_iticks = p->p_iticks;
   2779       1.1    atatat 
   2780      1.21    atatat 	ki->p_tracep = PTRTOUINT64(p->p_tracep);
   2781       1.1    atatat 	ki->p_traceflag = p->p_traceflag;
   2782       1.1    atatat 
   2783  1.81.4.3        ad 	mutex_enter(&p->p_smutex);
   2784  1.81.4.3        ad 
   2785       1.1    atatat 	memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
   2786       1.1    atatat 	memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
   2787       1.1    atatat 
   2788  1.81.4.4        ad 	ss1 = p->p_sigpend.sp_set;
   2789  1.81.4.6        ad 	LIST_FOREACH(l, &p->p_lwps, l_sibling) {
   2790  1.81.4.6        ad 		/* This is hardly correct, but... */
   2791  1.81.4.6        ad 		sigplusset(&l->l_sigpend.sp_set, &ss1);
   2792  1.81.4.8        ad 		sigplusset(&l->l_sigmask, &ss2);
   2793  1.81.4.6        ad 	}
   2794  1.81.4.4        ad 	memcpy(&ki->p_siglist, &ss1, sizeof(ki_sigset_t));
   2795  1.81.4.4        ad 	memcpy(&ki->p_sigmask, &ss2, sizeof(ki_sigset_t));
   2796  1.81.4.4        ad 
   2797       1.1    atatat 	ki->p_stat = p->p_stat; /* Will likely be overridden by LWP status */
   2798       1.1    atatat 	ki->p_realstat = p->p_stat;
   2799       1.1    atatat 	ki->p_nice = p->p_nice;
   2800       1.1    atatat 
   2801       1.1    atatat 	ki->p_xstat = p->p_xstat;
   2802       1.1    atatat 	ki->p_acflag = p->p_acflag;
   2803       1.1    atatat 
   2804       1.1    atatat 	strncpy(ki->p_comm, p->p_comm,
   2805       1.1    atatat 	    min(sizeof(ki->p_comm), sizeof(p->p_comm)));
   2806       1.1    atatat 
   2807       1.1    atatat 	strncpy(ki->p_login, p->p_session->s_login,
   2808       1.1    atatat 	    min(sizeof ki->p_login - 1, sizeof p->p_session->s_login));
   2809       1.1    atatat 
   2810       1.1    atatat 	ki->p_nlwps = p->p_nlwps;
   2811  1.81.4.6        ad 	ki->p_realflag = ki->p_flag;
   2812       1.1    atatat 
   2813       1.1    atatat 	if (p->p_stat == SIDL || P_ZOMBIE(p)) {
   2814       1.1    atatat 		ki->p_vm_rssize = 0;
   2815       1.1    atatat 		ki->p_vm_tsize = 0;
   2816       1.1    atatat 		ki->p_vm_dsize = 0;
   2817       1.1    atatat 		ki->p_vm_ssize = 0;
   2818  1.81.4.2        ad 		ki->p_nrlwps = 0;
   2819       1.1    atatat 		l = NULL;
   2820       1.1    atatat 	} else {
   2821       1.1    atatat 		struct vmspace *vm = p->p_vmspace;
   2822  1.81.4.2        ad 		int tmp;
   2823       1.1    atatat 
   2824       1.1    atatat 		ki->p_vm_rssize = vm_resident_count(vm);
   2825       1.1    atatat 		ki->p_vm_tsize = vm->vm_tsize;
   2826       1.1    atatat 		ki->p_vm_dsize = vm->vm_dsize;
   2827       1.1    atatat 		ki->p_vm_ssize = vm->vm_ssize;
   2828       1.1    atatat 
   2829       1.1    atatat 		/* Pick a "representative" LWP */
   2830  1.81.4.2        ad 		l = proc_representative_lwp(p, &tmp, 1);
   2831  1.81.4.6        ad 		lwp_lock(l);
   2832  1.81.4.2        ad 		ki->p_nrlwps = tmp;
   2833      1.21    atatat 		ki->p_forw = PTRTOUINT64(l->l_forw);
   2834      1.21    atatat 		ki->p_back = PTRTOUINT64(l->l_back);
   2835      1.21    atatat 		ki->p_addr = PTRTOUINT64(l->l_addr);
   2836       1.1    atatat 		ki->p_stat = l->l_stat;
   2837  1.81.4.6        ad 		ki->p_flag |= sysctl_map_flags(sysctl_lwpflagmap, l->l_flag);
   2838       1.1    atatat 		ki->p_swtime = l->l_swtime;
   2839       1.1    atatat 		ki->p_slptime = l->l_slptime;
   2840  1.81.4.6        ad 		if (l->l_stat == LSONPROC)
   2841       1.1    atatat 			ki->p_schedflags = l->l_cpu->ci_schedstate.spc_flags;
   2842  1.81.4.6        ad 		else
   2843       1.1    atatat 			ki->p_schedflags = 0;
   2844       1.1    atatat 		ki->p_holdcnt = l->l_holdcnt;
   2845       1.1    atatat 		ki->p_priority = l->l_priority;
   2846       1.1    atatat 		ki->p_usrpri = l->l_usrpri;
   2847       1.1    atatat 		if (l->l_wmesg)
   2848       1.1    atatat 			strncpy(ki->p_wmesg, l->l_wmesg, sizeof(ki->p_wmesg));
   2849      1.21    atatat 		ki->p_wchan = PTRTOUINT64(l->l_wchan);
   2850  1.81.4.2        ad 		lwp_unlock(l);
   2851       1.1    atatat 	}
   2852       1.1    atatat 	if (p->p_session->s_ttyvp)
   2853       1.1    atatat 		ki->p_eflag |= EPROC_CTTY;
   2854       1.1    atatat 	if (SESS_LEADER(p))
   2855       1.1    atatat 		ki->p_eflag |= EPROC_SLEADER;
   2856       1.1    atatat 
   2857       1.1    atatat 	/* XXX Is this double check necessary? */
   2858       1.1    atatat 	if (P_ZOMBIE(p)) {
   2859       1.1    atatat 		ki->p_uvalid = 0;
   2860  1.81.4.2        ad 		ki->p_rtime_sec = 0;
   2861  1.81.4.2        ad 		ki->p_rtime_usec = 0;
   2862       1.1    atatat 	} else {
   2863       1.1    atatat 		ki->p_uvalid = 1;
   2864       1.1    atatat 
   2865       1.1    atatat 		ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
   2866       1.1    atatat 		ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
   2867       1.1    atatat 
   2868  1.81.4.2        ad 		calcru(p, &ut, &st, NULL, &rt);
   2869  1.81.4.2        ad 		ki->p_rtime_sec = rt.tv_sec;
   2870  1.81.4.2        ad 		ki->p_rtime_usec = rt.tv_usec;
   2871       1.1    atatat 		ki->p_uutime_sec = ut.tv_sec;
   2872       1.1    atatat 		ki->p_uutime_usec = ut.tv_usec;
   2873       1.1    atatat 		ki->p_ustime_sec = st.tv_sec;
   2874       1.1    atatat 		ki->p_ustime_usec = st.tv_usec;
   2875       1.1    atatat 
   2876       1.1    atatat 		ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
   2877       1.1    atatat 		ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
   2878       1.1    atatat 		ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
   2879       1.1    atatat 		ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
   2880       1.1    atatat 		ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
   2881       1.1    atatat 		ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
   2882       1.1    atatat 		ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
   2883       1.1    atatat 		ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
   2884       1.1    atatat 		ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
   2885       1.1    atatat 		ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
   2886       1.1    atatat 		ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
   2887       1.1    atatat 		ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
   2888  1.81.4.2        ad 
   2889  1.81.4.2        ad 		ki->p_uru_nvcsw = 0;
   2890  1.81.4.2        ad 		ki->p_uru_nivcsw = 0;
   2891  1.81.4.2        ad 		LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
   2892  1.81.4.2        ad 			ki->p_uru_nvcsw += l->l_nvcsw;
   2893  1.81.4.2        ad 			ki->p_uru_nivcsw += l->l_nivcsw;
   2894  1.81.4.2        ad 		}
   2895       1.1    atatat 
   2896       1.1    atatat 		timeradd(&p->p_stats->p_cru.ru_utime,
   2897       1.1    atatat 			 &p->p_stats->p_cru.ru_stime, &ut);
   2898       1.1    atatat 		ki->p_uctime_sec = ut.tv_sec;
   2899       1.1    atatat 		ki->p_uctime_usec = ut.tv_usec;
   2900       1.1    atatat 	}
   2901       1.1    atatat #ifdef MULTIPROCESSOR
   2902  1.81.4.6        ad 	if (l != NULL)
   2903       1.1    atatat 		ki->p_cpuid = l->l_cpu->ci_cpuid;
   2904       1.1    atatat 	else
   2905       1.1    atatat #endif
   2906       1.1    atatat 		ki->p_cpuid = KI_NOCPU;
   2907  1.81.4.3        ad 
   2908  1.81.4.3        ad 	mutex_exit(&p->p_smutex);
   2909       1.1    atatat }
   2910       1.1    atatat 
   2911       1.1    atatat /*
   2912       1.1    atatat  * Fill in a kinfo_lwp structure for the specified lwp.
   2913       1.1    atatat  */
   2914       1.1    atatat static void
   2915       1.1    atatat fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
   2916       1.1    atatat {
   2917       1.1    atatat 
   2918      1.21    atatat 	kl->l_forw = PTRTOUINT64(l->l_forw);
   2919      1.21    atatat 	kl->l_back = PTRTOUINT64(l->l_back);
   2920      1.21    atatat 	kl->l_laddr = PTRTOUINT64(l);
   2921      1.21    atatat 	kl->l_addr = PTRTOUINT64(l->l_addr);
   2922       1.1    atatat 	kl->l_stat = l->l_stat;
   2923       1.1    atatat 	kl->l_lid = l->l_lid;
   2924       1.1    atatat 	kl->l_flag = l->l_flag;
   2925       1.1    atatat 
   2926       1.1    atatat 	kl->l_swtime = l->l_swtime;
   2927       1.1    atatat 	kl->l_slptime = l->l_slptime;
   2928  1.81.4.6        ad 	if (l->l_stat == LSONPROC)
   2929       1.1    atatat 		kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
   2930  1.81.4.6        ad 	else
   2931       1.1    atatat 		kl->l_schedflags = 0;
   2932       1.1    atatat 	kl->l_holdcnt = l->l_holdcnt;
   2933       1.1    atatat 	kl->l_priority = l->l_priority;
   2934       1.1    atatat 	kl->l_usrpri = l->l_usrpri;
   2935       1.1    atatat 	if (l->l_wmesg)
   2936       1.1    atatat 		strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
   2937      1.21    atatat 	kl->l_wchan = PTRTOUINT64(l->l_wchan);
   2938       1.1    atatat #ifdef MULTIPROCESSOR
   2939  1.81.4.6        ad 	kl->l_cpuid = l->l_cpu->ci_cpuid;
   2940  1.81.4.6        ad #else
   2941  1.81.4.6        ad 	kl->l_cpuid = KI_NOCPU;
   2942       1.1    atatat #endif
   2943       1.1    atatat }
   2944       1.1    atatat 
   2945       1.1    atatat /*
   2946       1.1    atatat  * Fill in an eproc structure for the specified process.
   2947       1.1    atatat  */
   2948       1.1    atatat void
   2949       1.1    atatat fill_eproc(struct proc *p, struct eproc *ep)
   2950       1.1    atatat {
   2951       1.1    atatat 	struct tty *tp;
   2952       1.1    atatat 	struct lwp *l;
   2953       1.1    atatat 
   2954       1.1    atatat 	ep->e_paddr = p;
   2955       1.1    atatat 	ep->e_sess = p->p_session;
   2956      1.77        ad 	kauth_cred_topcred(p->p_cred, &ep->e_pcred);
   2957      1.77        ad 	kauth_cred_toucred(p->p_cred, &ep->e_ucred);
   2958       1.1    atatat 	if (p->p_stat == SIDL || P_ZOMBIE(p)) {
   2959       1.1    atatat 		ep->e_vm.vm_rssize = 0;
   2960       1.1    atatat 		ep->e_vm.vm_tsize = 0;
   2961       1.1    atatat 		ep->e_vm.vm_dsize = 0;
   2962       1.1    atatat 		ep->e_vm.vm_ssize = 0;
   2963       1.1    atatat 		/* ep->e_vm.vm_pmap = XXX; */
   2964       1.1    atatat 	} else {
   2965       1.1    atatat 		struct vmspace *vm = p->p_vmspace;
   2966       1.1    atatat 
   2967       1.1    atatat 		ep->e_vm.vm_rssize = vm_resident_count(vm);
   2968       1.1    atatat 		ep->e_vm.vm_tsize = vm->vm_tsize;
   2969       1.1    atatat 		ep->e_vm.vm_dsize = vm->vm_dsize;
   2970       1.1    atatat 		ep->e_vm.vm_ssize = vm->vm_ssize;
   2971       1.1    atatat 
   2972       1.1    atatat 		/* Pick a "representative" LWP */
   2973  1.81.4.2        ad 		mutex_enter(&p->p_smutex);
   2974  1.81.4.2        ad 		l = proc_representative_lwp(p, NULL, 1);
   2975  1.81.4.6        ad 		lwp_lock(l);
   2976       1.1    atatat 		if (l->l_wmesg)
   2977       1.1    atatat 			strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN);
   2978  1.81.4.2        ad 		lwp_unlock(l);
   2979  1.81.4.2        ad 		mutex_exit(&p->p_smutex);
   2980       1.1    atatat 	}
   2981       1.1    atatat 	if (p->p_pptr)
   2982       1.1    atatat 		ep->e_ppid = p->p_pptr->p_pid;
   2983       1.1    atatat 	else
   2984       1.1    atatat 		ep->e_ppid = 0;
   2985       1.1    atatat 	ep->e_pgid = p->p_pgrp->pg_id;
   2986       1.1    atatat 	ep->e_sid = ep->e_sess->s_sid;
   2987       1.1    atatat 	ep->e_jobc = p->p_pgrp->pg_jobc;
   2988  1.81.4.4        ad 	if ((p->p_lflag & PL_CONTROLT) &&
   2989       1.1    atatat 	    (tp = ep->e_sess->s_ttyp)) {
   2990       1.1    atatat 		ep->e_tdev = tp->t_dev;
   2991       1.1    atatat 		ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
   2992       1.1    atatat 		ep->e_tsess = tp->t_session;
   2993       1.1    atatat 	} else
   2994       1.1    atatat 		ep->e_tdev = NODEV;
   2995       1.1    atatat 
   2996       1.1    atatat 	ep->e_xsize = ep->e_xrssize = 0;
   2997       1.1    atatat 	ep->e_xccount = ep->e_xswrss = 0;
   2998       1.1    atatat 	ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
   2999       1.1    atatat 	if (SESS_LEADER(p))
   3000       1.1    atatat 		ep->e_flag |= EPROC_SLEADER;
   3001       1.1    atatat 	strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
   3002       1.1    atatat }
   3003  1.81.4.6        ad 
   3004  1.81.4.6        ad u_int
   3005  1.81.4.6        ad sysctl_map_flags(const u_int *map, u_int word)
   3006  1.81.4.6        ad {
   3007  1.81.4.6        ad 	u_int rv;
   3008  1.81.4.6        ad 
   3009  1.81.4.6        ad 	for (rv = 0; *map != 0; map += 2)
   3010  1.81.4.6        ad 		if ((word & map[0]) != 0)
   3011  1.81.4.6        ad 			rv |= map[1];
   3012  1.81.4.6        ad 
   3013  1.81.4.6        ad 	return rv;
   3014  1.81.4.6        ad }
   3015