1 /* $NetBSD: init_main.c,v 1.412 2009/12/17 01:25:10 rmind Exp $ */
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
66 * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions
71 * 1. Redistributions of source code must retain the above copyright
72 * notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright
74 * notice, this list of conditions and the following disclaimer in the
75 * documentation and/or other materials provided with the distribution.
76 * 3. All advertising materials mentioning features or use of this software
77 * must display the following acknowledgement:
78 * This product includes software developed by the University of
79 * California, Berkeley and its contributors.
80 * 4. Neither the name of the University nor the names of its contributors
81 * may be used to endorse or promote products derived from this software
82 * without specific prior written permission.
84 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
85 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
99 #include <sys/cdefs.h>
100 __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.412 2009/12/17 01:25:10 rmind Exp $");
103 #include "opt_ipsec.h"
104 #include "opt_modular.h"
106 #include "opt_pipe.h"
108 #include "opt_syscall_debug.h"
109 #include "opt_sysv.h"
110 #include "opt_fileassoc.h"
111 #include "opt_ktrace.h"
113 #include "opt_compat_netbsd.h"
114 #include "opt_wapbl.h"
115 #include "opt_ptrace.h"
120 #include "sysmon_envsys.h"
121 #include "sysmon_power.h"
122 #include "sysmon_taskq.h"
123 #include "sysmon_wdog.h"
124 #include "veriexec.h"
126 #include <sys/param.h>
127 #include <sys/acct.h>
128 #include <sys/filedesc.h>
129 #include <sys/file.h>
130 #include <sys/errno.h>
131 #include <sys/callout.h>
133 #include <sys/spldebug.h>
134 #include <sys/kernel.h>
135 #include <sys/mount.h>
136 #include <sys/proc.h>
137 #include <sys/kthread.h>
138 #include <sys/resourcevar.h>
139 #include <sys/signalvar.h>
140 #include <sys/systm.h>
141 #include <sys/vnode.h>
142 #include <sys/fstrans.h>
144 #include <sys/conf.h>
145 #include <sys/disklabel.h>
147 #include <sys/device.h>
148 #include <sys/exec.h>
149 #include <sys/socketvar.h>
150 #include <sys/protosw.h>
151 #include <sys/percpu.h>
152 #include <sys/pset.h>
153 #include <sys/sysctl.h>
154 #include <sys/reboot.h>
155 #include <sys/event.h>
156 #include <sys/mbuf.h>
157 #include <sys/sched.h>
158 #include <sys/sleepq.h>
159 #include <sys/iostat.h>
160 #include <sys/vmem.h>
161 #include <sys/uuid.h>
162 #include <sys/extent.h>
163 #include <sys/disk.h>
164 #include <sys/msgbuf.h>
165 #include <sys/module.h>
166 #include <sys/event.h>
167 #include <sys/lockf.h>
168 #include <sys/once.h>
169 #include <sys/ksyms.h>
170 #include <sys/uidinfo.h>
171 #include <sys/kprintf.h>
173 #include <netipsec/ipsec.h>
184 #include <sys/domain.h>
185 #include <sys/namei.h>
189 #include <sys/pipe.h>
191 #include <sys/verified_exec.h>
192 #endif /* NVERIEXEC > 0 */
194 #include <sys/ktrace.h>
196 #include <sys/kauth.h>
198 #include <sys/wapbl.h>
201 #include <sys/savar.h>
203 #include <net80211/ieee80211_netbsd.h>
205 #include <sys/ptrace.h>
208 #include <sys/syscall.h>
209 #include <sys/syscallargs.h>
211 #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
213 #endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
215 #include <ufs/ufs/quota.h>
217 #include <miscfs/genfs/genfs.h>
218 #include <miscfs/syncfs/syncfs.h>
219 #include <miscfs/specfs/specdev.h>
225 #if NSYSMON_TASKQ > 0
226 #include <dev/sysmon/sysmon_taskq.h>
229 #include <dev/cons.h>
231 #if NSYSMON_ENVSYS > 0 || NSYSMON_POWER > 0 || NSYSMON_WDOG > 0
232 #include <dev/sysmon/sysmonvar.h>
236 #include <net/raw_cb.h>
238 #include <prop/proplib.h>
241 #include <compat/sys/time.h>
242 struct timeval50 boottime50
;
246 #include "opt_userconf.h"
249 #include <sys/userconf.h>
252 extern struct proc proc0
;
253 extern struct lwp lwp0
;
254 extern time_t rootfstime
;
257 struct lwp
*curlwp
= &lwp0
;
259 struct proc
*initproc
;
261 struct vnode
*rootvp
, *swapdev_vp
;
263 int cold
= 1; /* still working on startup */
264 struct timespec boottime
; /* time at system startup - will only follow settime deltas */
266 int start_init_exec
; /* semaphore for start_init() */
268 static void check_console(struct lwp
*l
);
269 static void start_init(void *);
270 static void configure(void);
271 static void configure2(void);
275 * System startup; initialize the world, create process 0, mount root
276 * filesystem, and fork to create init and pagedaemon. Most of the
277 * hard work is done in the lower-level initialization routines including
278 * startup(), which does memory initialization and autoconfiguration.
283 struct timespec time
;
287 #ifdef NVNODE_IMPLICIT
290 CPU_INFO_ITERATOR cii
;
294 #ifndef LWP0_CPU_INFO
297 l
->l_pflag
|= LP_RUNNING
;
300 * Attempt to find console and initialize
301 * in case of early panic or other messages.
307 mutex_init(&cpu_lock
, MUTEX_DEFAULT
, IPL_NONE
);
309 /* Initialize the device switch tables. */
316 #if ((NKSYMS > 0) || (NDDB > 0) || (NMODULAR > 0))
323 /* Initialize lock caches. */
327 /* Initialize the extent manager. */
330 /* Do machine-dependent initialization. */
333 /* Initialize the sysctl subsystem. */
336 /* Initialize callouts, part 1. */
339 /* Initialize the kernel authorization subsystem. */
344 /* Start module system. */
348 * Initialize the kernel authorization subsystem and start the
349 * default security model, if any. We need to do this early
350 * enough so that subsystems relying on any of the aforementioned
351 * can work properly. Since the security model may dictate the
352 * credential inheritance policy, it is needed at least before
353 * any process is created, specifically proc0.
355 module_init_class(MODULE_CLASS_SECMODEL
);
357 /* Initialize the buffer cache */
360 /* Initialize sockets. */
364 * The following things must be done before autoconfiguration.
366 evcnt_init(); /* initialize event counters */
368 rnd_init(); /* initialize random number generator */
371 /* Initialize process and pgrp structures. */
378 /* Initialize signal-related data structures. */
381 /* Initialize resource management. */
384 /* Create process 0. */
387 /* Disable preemption during boot. */
390 /* Initialize the UID hash table. */
393 /* Charge root for one process. */
394 (void)chgproccnt(0, 1);
396 /* Initialize timekeeping. */
399 /* Initialize the run queues, turnstiles and sleep queues. */
402 sleeptab_init(&sleeptab
);
406 /* Initialize processor-sets */
409 /* MI initialization of the boot cpu */
410 error
= mi_cpu_attach(curcpu());
413 /* Initialize timekeeping, part 2. */
417 * Initialize mbuf's. Do this now because we might attempt to
418 * allocate mbufs or mbuf clusters during autoconfiguration.
422 /* Initialize I/O statistics. */
425 /* Initialize the log device. */
428 /* Second part of module system initialization. */
431 /* Initialize the file systems. */
432 #ifdef NVNODE_IMPLICIT
434 * If maximum number of vnodes in namei vnode cache is not explicitly
435 * defined in kernel config, adjust the number such as we use roughly
436 * 10% of memory for vnodes and associated data structures in the
437 * assumed worst case. Do not provide fewer than NVNODE vnodes.
440 calc_cache_size(kernel_map
, 10, VNODE_VA_MAXPCT
) / VNODE_COST
;
441 if (usevnodes
> desiredvnodes
)
442 desiredvnodes
= usevnodes
;
447 /* Initialize fstrans. */
450 /* Initialize the file descriptor system. */
453 /* Initialize cwd structures */
456 /* Initialize kqueue. */
459 /* Initialize the system monitor subsystems. */
460 #if NSYSMON_TASKQ > 0
461 sysmon_task_queue_preinit();
464 #if NSYSMON_ENVSYS > 0
465 sysmon_envsys_init();
468 #if NSYSMON_POWER > 0
479 /* Initialize tty subsystem. */
483 /* Initialize the buffer cache, part 2. */
486 /* Initialize the disk wedge subsystem. */
489 /* Initialize interfaces. */
494 /* Configure the system hardware. This will enable interrupts. */
500 /* Now timer is working. Enable preemption. */
503 ubc_init(); /* must be after autoconfig */
506 /* Initialize System V style shared memory. */
511 /* Initialize System V style semaphores. */
516 /* Initialize System V style message queues. */
522 * Initialise the Veriexec subsystem.
525 #endif /* NVERIEXEC > 0 */
527 #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
529 #endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
532 /* Attach network crypto subsystem */
537 * Initialize protocols. Block reception of incoming packets
538 * until everything is ready.
547 /* Initialize kernel profiling. */
551 /* Initialize system accounting. */
554 #ifndef PIPE_SOCKETPAIR
555 /* Initialize pipes. */
560 /* Initialize ktrace. */
565 /* Initialize ptrace. */
569 /* Initialize the UUID system calls. */
573 /* Initialize write-ahead physical block logging. */
580 * Create process 1 (init(8)). We do this now, as Unix has
581 * historically had init be process 1, and changing this would
582 * probably upset a lot of people.
584 * Note that process 1 won't immediately exec init(8), but will
585 * wait for us to inform it that the root file system has been
588 if (fork1(l
, 0, SIGCHLD
, NULL
, 0, start_init
, NULL
, NULL
, &initproc
))
592 * Load any remaining builtin modules, and hand back temporary
593 * storage to the VM system.
595 module_init_class(MODULE_CLASS_ANY
);
598 * Finalize configuration now that all real devices have been
599 * found. This needs to be done before the root device is
600 * selected, since finalization may create the root device.
607 * Now that autoconfiguration has completed, we can determine
608 * the root and dump devices.
613 /* Mount the root file system. */
616 if ((error
= vfs_mountroot())) {
617 printf("cannot mount root, error = %d\n", error
);
618 boothowto
|= RB_ASKNAME
;
620 (rootdev
!= NODEV
) ? DISKPART(rootdev
) : 0);
622 } while (error
!= 0);
623 mountroothook_destroy();
626 * Initialise the time-of-day clock, passing the time recorded
627 * in the root filesystem (if any) for use by systems that
628 * don't have a non-volatile time-of-day device.
630 inittodr(rootfstime
);
633 * Now can look at time, having had a chance to verify the time
634 * from the file system. Reset l->l_rtime as it may have been
635 * munched in mi_switch() after the time got set.
642 TIMESPEC_TO_TIMEVAL(&tv
, &time
);
643 timeval_to_timeval50(&tv
, &boottime50
);
646 mutex_enter(proc_lock
);
647 LIST_FOREACH(p
, &allproc
, p_list
) {
648 KASSERT((p
->p_flag
& PK_MARKER
) == 0);
649 mutex_enter(p
->p_lock
);
650 TIMESPEC_TO_TIMEVAL(&p
->p_stats
->p_start
, &time
);
651 LIST_FOREACH(l
, &p
->p_lwps
, l_sibling
) {
653 memset(&l
->l_rtime
, 0, sizeof(l
->l_rtime
));
656 mutex_exit(p
->p_lock
);
658 mutex_exit(proc_lock
);
659 binuptime(&curlwp
->l_stime
);
661 for (CPU_INFO_FOREACH(cii
, ci
)) {
662 ci
->ci_schedstate
.spc_lastmod
= time_second
;
665 /* Create the pageout daemon kernel thread. */
667 if (kthread_create(PRI_PGDAEMON
, KTHREAD_MPSAFE
, NULL
, uvm_pageout
,
668 NULL
, NULL
, "pgdaemon"))
669 panic("fork pagedaemon");
671 /* Create the filesystem syncer kernel thread. */
672 if (kthread_create(PRI_IOFLUSH
, KTHREAD_MPSAFE
, NULL
, sched_sync
,
673 NULL
, NULL
, "ioflush"))
674 panic("fork syncer");
676 /* Create the aiodone daemon kernel thread. */
677 if (workqueue_create(&uvm
.aiodone_queue
, "aiodoned",
678 uvm_aiodone_worker
, NULL
, PRI_VM
, IPL_NONE
, WQ_MPSAFE
))
679 panic("fork aiodoned");
683 /* Initialize exec structures */
687 * Okay, now we can let init(8) exec! It's off to userland!
689 mutex_enter(proc_lock
);
691 cv_broadcast(&lbolt
);
692 mutex_exit(proc_lock
);
694 /* The scheduler is an infinite loop. */
700 * Configure the system's hardware.
706 /* Initialize autoconf data structures. */
710 * callout_setfunc() requires mutex(9) so it can't be in config_init()
711 * on amiga and atari which use config_init() and autoconf(9) fucntions
712 * to initialize console devices.
714 config_twiddle_init();
722 if (boothowto
& RB_USERCONF
)
726 if ((boothowto
& (AB_SILENT
|AB_VERBOSE
)) == AB_SILENT
) {
727 printf_nolog("Detecting hardware...");
731 * Do the machine-dependent portion of autoconfiguration. This
732 * sets the configuration machinery here in motion by "finding"
733 * the root bus. When this function returns, we expect interrupts
742 CPU_INFO_ITERATOR cii
;
747 * Now that we've found all the hardware, start the real time
748 * and statistics clocks.
752 cold
= 0; /* clocks are running, we're warm now! */
754 curcpu()->ci_schedstate
.spc_flags
|= SPCF_RUNNING
;
757 /* Boot the secondary processors. */
758 for (CPU_INFO_FOREACH(cii
, ci
)) {
762 #if defined(MULTIPROCESSOR)
763 cpu_boot_secondary_processors();
766 /* Setup the runqueues and scheduler. */
771 * Bus scans can make it appear as if the system has paused, so
772 * twiddle constantly while config_interrupts() jobs are running.
774 config_twiddle_fn(NULL
);
777 * Create threads to call back and finish configuration for
778 * devices that want interrupts enabled.
780 config_create_interruptthreads();
782 /* Get the threads going and into any sleeps before continuing. */
787 check_console(struct lwp
*l
)
792 error
= namei_simple_kernel("/dev/console",
793 NSM_FOLLOW_NOEMULROOT
, &vp
);
796 else if (error
== ENOENT
)
797 printf("warning: no /dev/console\n");
799 printf("warning: lookup /dev/console: error %d\n", error
);
803 * List of paths to try when searching for "init".
805 static const char * const initpaths
[] = {
813 * Start the initial user process; try exec'ing each pathname in "initpaths".
814 * The program is invoked with one argument containing the boot flags.
817 start_init(void *arg
)
820 struct proc
*p
= l
->l_proc
;
822 struct sys_execve_args
/* {
823 syscallarg(const char *) path;
824 syscallarg(char * const *) argp;
825 syscallarg(char * const *) envp;
827 int options
, i
, error
;
828 register_t retval
[2];
829 char flags
[4], *flagsp
;
830 const char *path
, *slash
;
831 char *ucp
, **uap
, *arg0
, *arg1
= NULL
;
838 strncpy(p
->p_comm
, "init", MAXCOMLEN
);
841 * Wait for main() to tell us that it's safe to exec.
843 mutex_enter(proc_lock
);
844 while (start_init_exec
== 0)
845 cv_wait(&lbolt
, proc_lock
);
846 mutex_exit(proc_lock
);
849 * This is not the right way to do this. We really should
850 * hand-craft a descriptor onto /dev/console to hand to init,
851 * but that's a _lot_ more work, and the benefit from this easy
852 * hack makes up for the "good is the enemy of the best" effect.
857 * Need just enough stack to hold the faked-up "execve()" arguments.
859 addr
= (vaddr_t
)STACK_ALLOC(USRSTACK
, PAGE_SIZE
);
860 if (uvm_map(&p
->p_vmspace
->vm_map
, &addr
, PAGE_SIZE
,
861 NULL
, UVM_UNKNOWN_OFFSET
, 0,
862 UVM_MAPFLAG(UVM_PROT_ALL
, UVM_PROT_ALL
, UVM_INH_COPY
,
864 UVM_FLAG_FIXED
|UVM_FLAG_OVERLAY
|UVM_FLAG_COPYONW
)) != 0)
865 panic("init: couldn't allocate argument space");
866 p
->p_vmspace
->vm_maxsaddr
= (void *)STACK_MAX(addr
, PAGE_SIZE
);
870 if (boothowto
& RB_ASKNAME
) {
873 printf(" (default %s)", initpaths
[ipx
]);
875 len
= cngetsn(ipath
, sizeof(ipath
)-1);
876 if (len
== 4 && strcmp(ipath
, "halt") == 0) {
877 cpu_reboot(RB_HALT
, NULL
);
878 } else if (len
== 6 && strcmp(ipath
, "reboot") == 0) {
881 } else if (len
== 3 && strcmp(ipath
, "ddb") == 0) {
885 } else if (len
> 0 && ipath
[0] == '/') {
888 } else if (len
== 0 && initpaths
[ipx
] != NULL
) {
889 path
= initpaths
[ipx
++];
891 printf("use absolute path, ");
895 printf("\"halt\", or \"reboot\"\n");
899 if ((path
= initpaths
[ipx
++]) == NULL
) {
901 boothowto
|= RB_ASKNAME
;
906 ucp
= (char *)USRSTACK
;
909 * Construct the boot flag argument.
915 if (boothowto
& RB_SINGLE
) {
920 if (boothowto
& RB_FASTBOOT
) {
927 * Move out the flags (arg 1), if necessary.
933 printf("init: copying out flags `%s' %d\n", flags
, i
);
935 arg1
= STACK_ALLOC(ucp
, i
);
936 ucp
= STACK_MAX(arg1
, i
);
937 (void)copyout((void *)flags
, arg1
, i
);
941 * Move out the file name (also arg 0).
943 i
= strlen(path
) + 1;
945 printf("init: copying out path `%s' %d\n", path
, i
);
947 if (boothowto
& RB_ASKNAME
|| path
!= initpaths
[0])
948 printf("init: trying %s\n", path
);
950 arg0
= STACK_ALLOC(ucp
, i
);
951 ucp
= STACK_MAX(arg0
, i
);
952 (void)copyout(path
, arg0
, i
);
955 * Move out the arg pointers.
957 ucp
= (void *)STACK_ALIGN(ucp
, ALIGNBYTES
);
958 uap
= (char **)STACK_ALLOC(ucp
, sizeof(char *) * 3);
959 SCARG(&args
, path
) = arg0
;
960 SCARG(&args
, argp
) = uap
;
961 SCARG(&args
, envp
) = NULL
;
962 slash
= strrchr(path
, '/');
964 (void)suword((void *)uap
++,
965 (long)arg0
+ (slash
+ 1 - path
));
967 (void)suword((void *)uap
++, (long)arg0
);
969 (void)suword((void *)uap
++, (long)arg1
);
970 (void)suword((void *)uap
++, 0); /* terminator */
973 * Now try to exec the program. If can't for any reason
974 * other than it doesn't exist, complain.
976 error
= sys_execve(l
, &args
, retval
);
977 if (error
== 0 || error
== EJUSTRETURN
) {
978 KERNEL_UNLOCK_LAST(l
);
981 printf("exec %s: error %d\n", path
, error
);
983 printf("init: not found\n");
988 * calculate cache size from physmem and vm_map size.
991 calc_cache_size(struct vm_map
*map
, int pct
, int va_pct
)
995 /* XXX should consider competing cache if any */
996 /* XXX should consider submaps */
997 t
= (uintmax_t)physmem
* pct
/ 100 * PAGE_SIZE
;
1001 vsize
= vm_map_max(map
) - vm_map_min(map
);
1002 vsize
= (uintmax_t)vsize
* va_pct
/ 100;
1011 * Print the system start up banner.
1013 * - Print a limited banner if AB_SILENT.
1014 * - Always send normal banner to the log.
1016 #define MEM_PBUFSIZE sizeof("99999 MB")
1021 static char notice
[] = " Notice: this software is "
1022 "protected by copyright";
1024 void (*pr
)(const char *, ...);
1027 if ((boothowto
& AB_SILENT
) != 0) {
1028 snprintf(pbuf
, sizeof(pbuf
), "%s %s (%s)",
1029 ostype
, osrelease
, kernel_ident
);
1030 printf_nolog("%s", pbuf
);
1031 for (i
= 80 - strlen(pbuf
) - sizeof(notice
); i
> 0; i
--)
1033 printf_nolog("%s\n", notice
);
1039 memset(pbuf
, 0, sizeof(pbuf
));
1040 (*pr
)("%s%s", copyright
, version
);
1041 format_bytes(pbuf
, MEM_PBUFSIZE
, ctob((uint64_t)physmem
));
1042 (*pr
)("total memory = %s\n", pbuf
);
1043 format_bytes(pbuf
, MEM_PBUFSIZE
, ctob((uint64_t)uvmexp
.free
));
1044 (*pr
)("avail memory = %s\n", pbuf
);