Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/init_main.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/init_main.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.445.2.4 retrieving revision 1.446 diff -u -p -r1.445.2.4 -r1.446 --- src/sys/kern/init_main.c 2017/12/03 11:38:44 1.445.2.4 +++ src/sys/kern/init_main.c 2013/02/09 00:31:21 1.446 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.445.2.4 2017/12/03 11:38:44 jdolecek Exp $ */ +/* $NetBSD: init_main.c,v 1.446 2013/02/09 00:31:21 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,10 +97,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.445.2.4 2017/12/03 11:38:44 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.446 2013/02/09 00:31:21 christos Exp $"); #include "opt_ddb.h" -#include "opt_inet.h" #include "opt_ipsec.h" #include "opt_modular.h" #include "opt_ntp.h" @@ -113,17 +112,14 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c, #include "opt_compat_netbsd.h" #include "opt_wapbl.h" #include "opt_ptrace.h" -#include "opt_rnd_printf.h" -#include "opt_splash.h" -#include "opt_kernhist.h" - -#if defined(SPLASHSCREEN) && defined(makeoptions_SPLASHSCREEN_IMAGE) -extern void *_binary_splash_image_start; -extern void *_binary_splash_image_end; -#endif +#include "drvctl.h" #include "ksyms.h" +#include "sysmon_envsys.h" +#include "sysmon_power.h" +#include "sysmon_taskq.h" +#include "sysmon_wdog.h" #include "veriexec.h" #include @@ -161,7 +157,6 @@ extern void *_binary_splash_image_end; #include #include #include -#include #include #include #include @@ -176,10 +171,18 @@ extern void *_binary_splash_image_end; #include #include #include -#include -#ifdef IPSEC +#ifdef FAST_IPSEC #include #endif +#ifdef SYSVSHM +#include +#endif +#ifdef SYSVSEM +#include +#endif +#ifdef SYSVMSG +#include +#endif #include #include #include @@ -192,35 +195,51 @@ extern void *_binary_splash_image_end; #endif #include #include +#ifdef PTRACE +#include +#endif /* PTRACE */ #include #include #include +#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR) #include +#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */ #include #include #include +#include #include #include #include /* extern struct uvm uvm */ +#if NSYSMON_TASKQ > 0 +#include +#endif + #include -#include + +#if NSYSMON_ENVSYS > 0 || NSYSMON_POWER > 0 || NSYSMON_WDOG > 0 +#include +#endif #include #include -#include #include -#include #include +#ifdef COMPAT_50 +#include +struct timeval50 boottime50; +#endif + #include extern struct lwp lwp0; @@ -292,7 +311,6 @@ main(void) evcnt_init(); uvm_init(); - ubchist_init(); kcpuset_sysinit(); prop_kern_init(); @@ -351,18 +369,6 @@ main(void) /* Initialize the buffer cache */ bufinit(); - biohist_init(); - -#ifdef KERNHIST - sysctl_kernhist_init(); -#endif - - -#if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_IMAGE) - size_t splash_size = (&_binary_splash_image_end - - &_binary_splash_image_start) * sizeof(void *); - splash_setimage(&_binary_splash_image_start, splash_size); -#endif /* Initialize sockets. */ soinit(); @@ -443,8 +449,8 @@ main(void) * 10% of memory for vnodes and associated data structures in the * assumed worst case. Do not provide fewer than NVNODE vnodes. */ - usevnodes = calc_cache_size(vmem_size(kmem_arena, VMEM_FREE|VMEM_ALLOC), - 10, VNODE_KMEM_MAXPCT) / VNODE_COST; + usevnodes = + calc_cache_size(kernel_map, 10, VNODE_VA_MAXPCT) / VNODE_COST; if (usevnodes > desiredvnodes) desiredvnodes = usevnodes; #endif @@ -463,6 +469,23 @@ main(void) /* Initialize kqueue. */ kqueue_init(); + /* Initialize the system monitor subsystems. */ +#if NSYSMON_TASKQ > 0 + sysmon_task_queue_preinit(); +#endif + +#if NSYSMON_ENVSYS > 0 + sysmon_envsys_init(); +#endif + +#if NSYSMON_POWER > 0 + sysmon_power_init(); +#endif + +#if NSYSMON_WDOG > 0 + sysmon_wdog_init(); +#endif + inittimecounter(); ntp_init(); @@ -479,10 +502,7 @@ main(void) /* Initialize the kernel strong PRNG. */ kern_cprng = cprng_strong_create("kernel", IPL_VM, CPRNG_INIT_ANY|CPRNG_REKEY_ANY); - - /* Initialize pfil */ - pfil_init(); - + /* Initialize interfaces. */ ifinit1(); @@ -491,20 +511,9 @@ main(void) /* Initialize sockets thread(s) */ soinit1(); - /* - * Initialize the bufq strategy sub-system and any built-in - * strategy modules - they may be needed by some devices during - * auto-configuration - */ - bufq_init(); - module_init_class(MODULE_CLASS_BUFQ); - /* Configure the system hardware. This will enable interrupts. */ configure(); - /* Once all CPUs are detected, initialize the per-CPU cprng_fast. */ - cprng_fast_init(); - ssp_init(); ubc_init(); /* must be after autoconfig */ @@ -512,21 +521,12 @@ main(void) mm_init(); configure2(); - - ipi_sysinit(); - /* Now timer is working. Enable preemption. */ kpreempt_enable(); - /* Get the threads going and into any sleeps before continuing. */ - yield(); - - /* Enable deferred processing of RNG samples */ - rnd_init_softint(); - -#ifdef RND_PRINTF - /* Enable periodic injection of console output into entropy pool */ - kprintf_init_callout(); +#ifdef SYSVSHM + /* Initialize System V style shared memory. */ + shminit(); #endif vmem_rehash_start(); /* must be before exec_init */ @@ -534,6 +534,16 @@ main(void) /* Initialize exec structures */ exec_init(1); /* seminit calls exithook_establish() */ +#ifdef SYSVSEM + /* Initialize System V style semaphores. */ + seminit(); +#endif + +#ifdef SYSVMSG + /* Initialize System V style message queues. */ + msginit(); +#endif + #if NVERIEXEC > 0 /* * Initialise the Veriexec subsystem. @@ -541,9 +551,11 @@ main(void) veriexec_init(); #endif /* NVERIEXEC > 0 */ +#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR) pax_init(); +#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */ -#ifdef IPSEC +#ifdef FAST_IPSEC /* Attach network crypto subsystem */ ipsec_attach(); #endif @@ -554,9 +566,6 @@ main(void) */ s = splnet(); ifinit(); -#if defined(INET) || defined(INET6) - lltableinit(); -#endif domaininit(true); if_attachdomain(); splx(s); @@ -579,12 +588,18 @@ main(void) ktrinit(); #endif +#ifdef PTRACE + /* Initialize ptrace. */ + ptrace_init(); +#endif /* PTRACE */ + + /* Initialize the UUID system calls. */ + uuid_init(); + machdep_init(); procinit_sysctl(); - scdebug_init(); - /* * Create process 1 (init(8)). We do this now, as Unix has * historically had init be process 1, and changing this would @@ -649,7 +664,13 @@ main(void) */ getnanotime(&time); boottime = time; - +#ifdef COMPAT_50 + { + struct timeval tv; + TIMESPEC_TO_TIMEVAL(&tv, &time); + timeval_to_timeval50(&tv, &boottime50); + } +#endif mutex_enter(proc_lock); LIST_FOREACH(p, &allproc, p_list) { KASSERT((p->p_flag & PK_MARKER) == 0); @@ -685,9 +706,6 @@ main(void) uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE)) panic("fork aiodoned"); - /* Wait for final configure threads to complete. */ - config_finalize_mountroot(); - /* * Okay, now we can let init(8) exec! It's off to userland! */ @@ -719,9 +737,9 @@ configure(void) config_twiddle_init(); pmf_init(); - - /* Initialize driver modules */ - module_init_class(MODULE_CLASS_DRIVER); +#if NDRVCTL > 0 + drvctl_init(); +#endif userconf_init(); if (boothowto & RB_USERCONF) @@ -782,6 +800,9 @@ configure2(void) * devices that want interrupts enabled. */ config_create_interruptthreads(); + + /* Get the threads going and into any sleeps before continuing. */ + yield(); } static void @@ -801,12 +822,12 @@ configure3(void) static void rootconf_handle_wedges(void) { - struct disklabel label; + struct partinfo dpart; struct partition *p; struct vnode *vp; daddr_t startblk; uint64_t nblks; - device_t dev; + device_t dev; int error; if (booted_nblks) { @@ -834,7 +855,7 @@ rootconf_handle_wedges(void) if (vp == NULL) return; - error = VOP_IOCTL(vp, DIOCGDINFO, &label, FREAD, NOCRED); + error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED); VOP_CLOSE(vp, FREAD, NOCRED); vput(vp); if (error) @@ -843,7 +864,7 @@ rootconf_handle_wedges(void) KASSERT(booted_partition >= 0 && booted_partition < MAXPARTITIONS); - p = &label.d_partitions[booted_partition]; + p = &dpart.disklab->d_partitions[booted_partition]; dev = booted_device; startblk = p->p_offset; @@ -889,7 +910,6 @@ static const char * const initpaths[] = "/sbin/init", "/sbin/oinit", "/sbin/init.bak", - "/rescue/init", NULL, }; @@ -912,7 +932,7 @@ start_init(void *arg) register_t retval[2]; char flags[4], *flagsp; const char *path, *slash; - char *ucp, **uap, *arg0, *arg1, *argv[3]; + char *ucp, **uap, *arg0, *arg1 = NULL; char ipath[129]; int ipx, len; @@ -942,10 +962,10 @@ start_init(void *arg) */ addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE); if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE, - NULL, UVM_UNKNOWN_OFFSET, 0, - UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_COPY, - UVM_ADV_NORMAL, - UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0) + NULL, UVM_UNKNOWN_OFFSET, 0, + UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY, + UVM_ADV_NORMAL, + UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0) panic("init: couldn't allocate argument space"); p->p_vmspace->vm_maxsaddr = (void *)STACK_MAX(addr, PAGE_SIZE); @@ -1018,10 +1038,8 @@ start_init(void *arg) #endif arg1 = STACK_ALLOC(ucp, i); ucp = STACK_MAX(arg1, i); - if ((error = copyout((void *)flags, arg1, i)) != 0) - goto copyerr; - } else - arg1 = NULL; + (void)copyout((void *)flags, arg1, i); + } /* * Move out the file name (also arg 0). @@ -1035,27 +1053,28 @@ start_init(void *arg) #endif arg0 = STACK_ALLOC(ucp, i); ucp = STACK_MAX(arg0, i); - if ((error = copyout(path, arg0, i)) != 0) - goto copyerr; + (void)copyout(path, arg0, i); /* * Move out the arg pointers. */ ucp = (void *)STACK_ALIGN(ucp, STACK_ALIGNBYTES); - uap = (char **)STACK_ALLOC(ucp, sizeof(argv)); + uap = (char **)STACK_ALLOC(ucp, sizeof(char *) * 3); SCARG(&args, path) = arg0; SCARG(&args, argp) = uap; SCARG(&args, envp) = NULL; slash = strrchr(path, '/'); - - argv[0] = slash ? arg0 + (slash + 1 - path) : arg0; - argv[1] = arg1; - argv[2] = NULL; - if ((error = copyout(argv, uap, sizeof(argv))) != 0) - goto copyerr; + if (slash) + (void)suword((void *)uap++, + (long)arg0 + (slash + 1 - path)); + else + (void)suword((void *)uap++, (long)arg0); + if (options != 0) + (void)suword((void *)uap++, (long)arg1); + (void)suword((void *)uap++, 0); /* terminator */ /* - * Now try to exec the program. If it can't for any reason + * Now try to exec the program. If can't for any reason * other than it doesn't exist, complain. */ error = sys_execve(l, &args, retval); @@ -1067,22 +1086,23 @@ start_init(void *arg) } printf("init: not found\n"); panic("no init"); -copyerr: - panic("copyout %d", error); } /* - * calculate cache size (in bytes) from physmem and vsize. + * calculate cache size (in bytes) from physmem and vm_map size. */ vaddr_t -calc_cache_size(vsize_t vsize, int pct, int va_pct) +calc_cache_size(struct vm_map *map, int pct, int va_pct) { paddr_t t; /* XXX should consider competing cache if any */ /* XXX should consider submaps */ t = (uintmax_t)physmem * pct / 100 * PAGE_SIZE; - if (vsize != 0) { + if (map != NULL) { + vsize_t vsize; + + vsize = vm_map_max(map) - vm_map_min(map); vsize = (uintmax_t)vsize * va_pct / 100; if (t > vsize) { t = vsize;