xref: /openbsd-src/sys/kern/init_main.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: init_main.c,v 1.258 2016/09/18 12:36:28 jasper Exp $	*/
2 /*	$NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $	*/
3 
4 /*
5  * Copyright (c) 1995 Christopher G. Demetriou.  All rights reserved.
6  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  * (c) UNIX System Laboratories, Inc.
9  * All or some portions of this file are derived from material licensed
10  * to the University of California by American Telephone and Telegraph
11  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12  * the permission of UNIX System Laboratories, Inc.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)init_main.c	8.9 (Berkeley) 1/21/94
39  */
40 
41 #include <sys/param.h>
42 #include <sys/filedesc.h>
43 #include <sys/file.h>
44 #include <sys/errno.h>
45 #include <sys/exec.h>
46 #include <sys/kernel.h>
47 #include <sys/kthread.h>
48 #include <sys/mount.h>
49 #include <sys/proc.h>
50 #include <sys/resourcevar.h>
51 #include <sys/signalvar.h>
52 #include <sys/systm.h>
53 #include <sys/namei.h>
54 #include <sys/vnode.h>
55 #include <sys/tty.h>
56 #include <sys/conf.h>
57 #include <sys/buf.h>
58 #include <sys/device.h>
59 #include <sys/socketvar.h>
60 #include <sys/lockf.h>
61 #include <sys/protosw.h>
62 #include <sys/reboot.h>
63 #include <sys/user.h>
64 #ifdef SYSVSHM
65 #include <sys/shm.h>
66 #endif
67 #ifdef SYSVSEM
68 #include <sys/sem.h>
69 #endif
70 #ifdef SYSVMSG
71 #include <sys/msg.h>
72 #endif
73 #include <sys/domain.h>
74 #include <sys/msgbuf.h>
75 #include <sys/mbuf.h>
76 #include <sys/pipe.h>
77 #include <sys/task.h>
78 
79 #include <sys/syscall.h>
80 #include <sys/syscallargs.h>
81 
82 #include <uvm/uvm_extern.h>
83 
84 #include <dev/rndvar.h>
85 
86 #include <ufs/ufs/quota.h>
87 
88 #include <net/if.h>
89 #include <net/rtable.h>
90 #include <net/netisr.h>
91 
92 #if defined(CRYPTO)
93 #include <crypto/cryptodev.h>
94 #include <crypto/cryptosoft.h>
95 #endif
96 
97 #if defined(NFSSERVER) || defined(NFSCLIENT)
98 extern void nfs_init(void);
99 #endif
100 
101 #include "mpath.h"
102 #include "vscsi.h"
103 #include "softraid.h"
104 
105 const char	copyright[] =
106 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
107 "\tThe Regents of the University of California.  All rights reserved.\n"
108 "Copyright (c) 1995-2016 OpenBSD. All rights reserved.  https://www.OpenBSD.org\n";
109 
110 /* Components of the first process -- never freed. */
111 struct	session session0;
112 struct	pgrp pgrp0;
113 struct	proc proc0;
114 struct	process process0;
115 struct	plimit limit0;
116 struct	vmspace vmspace0;
117 struct	sigacts sigacts0;
118 struct	process *initprocess;
119 struct	proc *reaperproc;
120 
121 extern	struct user *proc0paddr;
122 
123 struct	vnode *rootvp, *swapdev_vp;
124 int	boothowto;
125 struct	timespec boottime;
126 int	ncpus =  1;
127 int	ncpusfound = 1;			/* number of cpus we find */
128 volatile int start_init_exec;		/* semaphore for start_init() */
129 
130 #if !defined(NO_PROPOLICE)
131 long	__guard_local __attribute__((section(".openbsd.randomdata")));
132 #endif
133 
134 /* XXX return int so gcc -Werror won't complain */
135 int	main(void *);
136 void	check_console(struct proc *);
137 void	start_init(void *);
138 void	start_cleaner(void *);
139 void	start_update(void *);
140 void	start_reaper(void *);
141 void	crypto_init(void);
142 void	db_ctf_init(void);
143 void	prof_init(void);
144 void	init_exec(void);
145 void	kqueue_init(void);
146 void	taskq_init(void);
147 void	pool_gc_pages(void *);
148 
149 extern char sigcode[], esigcode[], sigcoderet[];
150 #ifdef SYSCALL_DEBUG
151 extern char *syscallnames[];
152 #endif
153 
154 struct emul emul_native = {
155 	"native",
156 	NULL,
157 	sendsig,
158 	SYS_syscall,
159 	SYS_MAXSYSCALL,
160 	sysent,
161 #ifdef SYSCALL_DEBUG
162 	syscallnames,
163 #else
164 	NULL,
165 #endif
166 	0,
167 	copyargs,
168 	setregs,
169 	NULL,		/* fixup */
170 	NULL,		/* coredump */
171 	sigcode,
172 	esigcode,
173 	sigcoderet,
174 	EMUL_ENABLED | EMUL_NATIVE,
175 };
176 
177 
178 /*
179  * System startup; initialize the world, create process 0, mount root
180  * filesystem, and fork to create init and pagedaemon.  Most of the
181  * hard work is done in the lower-level initialization routines including
182  * startup(), which does memory initialization and autoconfiguration.
183  */
184 /* XXX return int, so gcc -Werror won't complain */
185 int
186 main(void *framep)
187 {
188 	struct proc *p;
189 	struct process *pr;
190 	struct pdevinit *pdev;
191 	quad_t lim;
192 	int s, i;
193 	extern struct pdevinit pdevinit[];
194 	extern void disk_init(void);
195 
196 	/*
197 	 * Initialize the current process pointer (curproc) before
198 	 * any possible traps/probes to simplify trap processing.
199 	 */
200 	curproc = p = &proc0;
201 	p->p_cpu = curcpu();
202 
203 	/*
204 	 * Initialize timeouts.
205 	 */
206 	timeout_startup();
207 
208 	/*
209 	 * Attempt to find console and initialize
210 	 * in case of early panic or other messages.
211 	 */
212 	config_init();		/* init autoconfiguration data structures */
213 	consinit();
214 
215 	printf("%s\n", copyright);
216 
217 	KERNEL_LOCK_INIT();
218 	SCHED_LOCK_INIT();
219 
220 	uvm_init();
221 	disk_init();		/* must come before autoconfiguration */
222 	tty_init();		/* initialise tty's */
223 	cpu_startup();
224 
225 	random_start();		/* Start the flow */
226 
227 	/*
228 	 * Initialize mbuf's.  Do this now because we might attempt to
229 	 * allocate mbufs or mbuf clusters during autoconfiguration.
230 	 */
231 	mbinit();
232 
233 	/* Initialize sockets. */
234 	soinit();
235 
236 	/* Initialize SRP subsystem. */
237 	srp_startup();
238 
239 	/*
240 	 * Initialize process and pgrp structures.
241 	 */
242 	procinit();
243 
244 	/* Initialize file locking. */
245 	lf_init();
246 
247 	/*
248 	 * Initialize filedescriptors.
249 	 */
250 	filedesc_init();
251 
252 	/*
253 	 * Initialize pipes.
254 	 */
255 	pipe_init();
256 
257 	/*
258 	 * Initialize kqueues.
259 	 */
260 	kqueue_init();
261 
262 	/* Create credentials. */
263 	p->p_ucred = crget();
264 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
265 
266 	/*
267 	 * Create process 0 (the swapper).
268 	 */
269 	pr = &process0;
270 	process_initialize(pr, p);
271 
272 	LIST_INSERT_HEAD(&allprocess, pr, ps_list);
273 	atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
274 
275 	/* Set the default routing table/domain. */
276 	process0.ps_rtableid = 0;
277 
278 	LIST_INSERT_HEAD(&allproc, p, p_list);
279 	pr->ps_pgrp = &pgrp0;
280 	LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
281 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
282 	LIST_INIT(&pgrp0.pg_members);
283 	LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
284 
285 	pgrp0.pg_session = &session0;
286 	session0.s_count = 1;
287 	session0.s_leader = pr;
288 
289 	atomic_setbits_int(&p->p_flag, P_SYSTEM);
290 	p->p_stat = SONPROC;
291 	pr->ps_nice = NZERO;
292 	pr->ps_emul = &emul_native;
293 	strlcpy(p->p_comm, "swapper", sizeof(p->p_comm));
294 
295 	/* Init timeouts. */
296 	timeout_set(&p->p_sleep_to, endtsleep, p);
297 
298 	/* Initialize signal state for process 0. */
299 	signal_init();
300 	pr->ps_sigacts = &sigacts0;
301 	siginit(pr);
302 
303 	/* Create the file descriptor table. */
304 	p->p_fd = pr->ps_fd = fdinit();
305 
306 	/* Create the limits structures. */
307 	pr->ps_limit = &limit0;
308 	for (i = 0; i < nitems(p->p_rlimit); i++)
309 		limit0.pl_rlimit[i].rlim_cur =
310 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
311 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
312 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
313 	    (maxfiles - NOFILE > NOFILE) ?  maxfiles - NOFILE : NOFILE);
314 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
315 	lim = ptoa(uvmexp.free);
316 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
317 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
318 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
319 	limit0.p_refcnt = 1;
320 
321 	/* Allocate a prototype map so we have something to fork. */
322 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
323 	    trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
324 	p->p_vmspace = pr->ps_vmspace = &vmspace0;
325 
326 	p->p_addr = proc0paddr;				/* XXX */
327 
328 	/*
329 	 * Charge root for one process.
330 	 */
331 	(void)chgproccnt(0, 1);
332 
333 	/* Initialize run queues */
334 	sched_init_runqueues();
335 	sleep_queue_init();
336 	sched_init_cpu(curcpu());
337 	p->p_cpu->ci_randseed = (arc4random() & 0x7fffffff) + 1;
338 
339 	/* Initialize task queues */
340 	taskq_init();
341 
342 	/* Initialize the interface/address trees */
343 	ifinit();
344 
345 	/* Lock the kernel on behalf of proc0. */
346 	KERNEL_LOCK();
347 
348 #if NMPATH > 0
349 	/* Attach mpath before hardware */
350 	config_rootfound("mpath", NULL);
351 #endif
352 
353 	/* Configure the devices */
354 	cpu_configure();
355 
356 	/* Configure virtual memory system, set vm rlimits. */
357 	uvm_init_limits(p);
358 
359 	/* Initialize the file systems. */
360 #if defined(NFSSERVER) || defined(NFSCLIENT)
361 	nfs_init();			/* initialize server/shared data */
362 #endif
363 	vfsinit();
364 
365 	/* Start real time and statistics clocks. */
366 	initclocks();
367 
368 #ifdef SYSVSHM
369 	/* Initialize System V style shared memory. */
370 	shminit();
371 #endif
372 
373 #ifdef SYSVSEM
374 	/* Initialize System V style semaphores. */
375 	seminit();
376 #endif
377 
378 #ifdef SYSVMSG
379 	/* Initialize System V style message queues. */
380 	msginit();
381 #endif
382 
383 	/* Attach pseudo-devices. */
384 	for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
385 		if (pdev->pdev_count > 0)
386 			(*pdev->pdev_attach)(pdev->pdev_count);
387 
388 #ifdef CRYPTO
389 	crypto_init();
390 	swcr_init();
391 #endif /* CRYPTO */
392 
393 	rtable_init();
394 
395 	/*
396 	 * Initialize protocols.  Block reception of incoming packets
397 	 * until everything is ready.
398 	 */
399 	s = splnet();
400 	domaininit();
401 	splx(s);
402 
403 	initconsbuf();
404 
405 #if defined(GPROF) || defined(DDBPROF)
406 	/* Initialize kernel profiling. */
407 	prof_init();
408 #endif
409 
410 	/* init exec and emul */
411 	init_exec();
412 
413 	/* Start the scheduler */
414 	scheduler_start();
415 
416 	/*
417 	 * Create process 1 (init(8)).  We do this now, as Unix has
418 	 * historically had init be process 1, and changing this would
419 	 * probably upset a lot of people.
420 	 *
421 	 * Note that process 1 won't immediately exec init(8), but will
422 	 * wait for us to inform it that the root file system has been
423 	 * mounted.
424 	 */
425 	{
426 		struct proc *initproc;
427 
428 		if (fork1(p, FORK_FORK, NULL, 0, start_init, NULL, NULL,
429 		    &initproc))
430 			panic("fork init");
431 		initprocess = initproc->p_p;
432 	}
433 
434 	randompid = 1;
435 
436 	/*
437 	 * Create any kernel threads whose creation was deferred because
438 	 * initprocess had not yet been created.
439 	 */
440 	kthread_run_deferred_queue();
441 
442 	/*
443 	 * Now that device driver threads have been created, wait for
444 	 * them to finish any deferred autoconfiguration.  Note we don't
445 	 * need to lock this semaphore, since we haven't booted any
446 	 * secondary processors, yet.
447 	 */
448 	while (config_pending)
449 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
450 
451 	dostartuphooks();
452 
453 #if NVSCSI > 0
454 	config_rootfound("vscsi", NULL);
455 #endif
456 #if NSOFTRAID > 0
457 	config_rootfound("softraid", NULL);
458 #endif
459 
460 	/* Configure root/swap devices */
461 	diskconf();
462 
463 	if (mountroot == NULL || ((*mountroot)() != 0))
464 		panic("cannot mount root");
465 
466 	TAILQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
467 
468 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
469 	if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
470 		panic("cannot find root vnode");
471 	p->p_fd->fd_cdir = rootvnode;
472 	vref(p->p_fd->fd_cdir);
473 	VOP_UNLOCK(rootvnode, p);
474 	p->p_fd->fd_rdir = NULL;
475 
476 	/*
477 	 * Now that root is mounted, we can fixup initprocess's CWD
478 	 * info.  All other processes are kthreads, which merely
479 	 * share proc0's CWD info.
480 	 */
481 	initprocess->ps_fd->fd_cdir = rootvnode;
482 	vref(initprocess->ps_fd->fd_cdir);
483 	initprocess->ps_fd->fd_rdir = NULL;
484 
485 	/*
486 	 * Now can look at time, having had a chance to verify the time
487 	 * from the file system.  Reset p->p_rtime as it may have been
488 	 * munched in mi_switch() after the time got set.
489 	 */
490 	nanotime(&boottime);
491 	LIST_FOREACH(pr, &allprocess, ps_list) {
492 		pr->ps_start = boottime;
493 		TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
494 			nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
495 			timespecclear(&p->p_rtime);
496 		}
497 	}
498 
499 	uvm_swap_init();
500 
501 	/* Create the pageout daemon kernel thread. */
502 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
503 		panic("fork pagedaemon");
504 
505 	/* Create the reaper daemon kernel thread. */
506 	if (kthread_create(start_reaper, NULL, &reaperproc, "reaper"))
507 		panic("fork reaper");
508 
509 	/* Create the cleaner daemon kernel thread. */
510 	if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
511 		panic("fork cleaner");
512 
513 	/* Create the update daemon kernel thread. */
514 	if (kthread_create(start_update, NULL, NULL, "update"))
515 		panic("fork update");
516 
517 	/* Create the aiodone daemon kernel thread. */
518 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
519 		panic("fork aiodoned");
520 
521 #if !defined(__hppa__)
522 	/* Create the page zeroing kernel thread. */
523 	if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread"))
524 		panic("fork zerothread");
525 #endif
526 
527 #if defined(MULTIPROCESSOR)
528 	/* Boot the secondary processors. */
529 	cpu_boot_secondary_processors();
530 #endif
531 
532 	config_process_deferred_mountroot();
533 
534 #ifdef DDBCTF
535 	db_ctf_init();
536 #endif
537 
538 	/*
539 	 * Okay, now we can let init(8) exec!  It's off to userland!
540 	 */
541 	start_init_exec = 1;
542 	wakeup((void *)&start_init_exec);
543 
544 	/*
545 	 * Start the idle pool page garbage collector
546 	 */
547 #if !(defined(__m88k__) && defined(MULTIPROCESSOR))	/* XXX */
548 	pool_gc_pages(NULL);
549 #endif
550 
551 	start_periodic_resettodr();
552 
553         /*
554          * proc0: nothing to do, back to sleep
555          */
556         while (1)
557                 tsleep(&proc0, PVM, "scheduler", 0);
558 	/* NOTREACHED */
559 }
560 
561 /*
562  * List of paths to try when searching for "init".
563  */
564 static char *initpaths[] = {
565 	"/sbin/init",
566 	"/sbin/oinit",
567 	"/sbin/init.bak",
568 	NULL,
569 };
570 
571 void
572 check_console(struct proc *p)
573 {
574 	struct nameidata nd;
575 	int error;
576 
577 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
578 	error = namei(&nd);
579 	if (error) {
580 		if (error == ENOENT)
581 			printf("warning: /dev/console does not exist\n");
582 		else
583 			printf("warning: /dev/console error %d\n", error);
584 	} else
585 		vrele(nd.ni_vp);
586 }
587 
588 /*
589  * Start the initial user process; try exec'ing each pathname in "initpaths".
590  * The program is invoked with one argument containing the boot flags.
591  */
592 void
593 start_init(void *arg)
594 {
595 	struct proc *p = arg;
596 	vaddr_t addr;
597 	struct sys_execve_args /* {
598 		syscallarg(const char *) path;
599 		syscallarg(char *const *) argp;
600 		syscallarg(char *const *) envp;
601 	} */ args;
602 	int options, error;
603 	long i;
604 	register_t retval[2];
605 	char flags[4], *flagsp;
606 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
607 
608 	/*
609 	 * Now in process 1.
610 	 */
611 
612 	/*
613 	 * Wait for main() to tell us that it's safe to exec.
614 	 */
615 	while (start_init_exec == 0)
616 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
617 
618 	check_console(p);
619 
620 	/* process 0 ignores SIGCHLD, but we can't */
621 	p->p_p->ps_sigacts->ps_flags = 0;
622 
623 	/*
624 	 * Need just enough stack to hold the faked-up "execve()" arguments.
625 	 */
626 #ifdef MACHINE_STACK_GROWS_UP
627 	addr = USRSTACK;
628 #else
629 	addr = USRSTACK - PAGE_SIZE;
630 #endif
631 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
632 	p->p_vmspace->vm_minsaddr = (caddr_t)(addr + PAGE_SIZE);
633 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
634 	    NULL, UVM_UNKNOWN_OFFSET, 0,
635 	    UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_MASK, MAP_INHERIT_COPY,
636 	    MADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
637 		panic("init: couldn't allocate argument space");
638 
639 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
640 #ifdef MACHINE_STACK_GROWS_UP
641 		ucp = (char *)addr;
642 #else
643 		ucp = (char *)(addr + PAGE_SIZE);
644 #endif
645 		/*
646 		 * Construct the boot flag argument.
647 		 */
648 		flagsp = flags;
649 		*flagsp++ = '-';
650 		options = 0;
651 
652 		if (boothowto & RB_SINGLE) {
653 			*flagsp++ = 's';
654 			options = 1;
655 		}
656 #ifdef notyet
657 		if (boothowto & RB_FASTBOOT) {
658 			*flagsp++ = 'f';
659 			options = 1;
660 		}
661 #endif
662 
663 		/*
664 		 * Move out the flags (arg 1), if necessary.
665 		 */
666 		if (options != 0) {
667 			*flagsp++ = '\0';
668 			i = flagsp - flags;
669 #ifdef DEBUG
670 			printf("init: copying out flags `%s' %ld\n", flags, i);
671 #endif
672 #ifdef MACHINE_STACK_GROWS_UP
673 			arg1 = ucp;
674 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
675 			ucp += i;
676 #else
677 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
678 			arg1 = ucp;
679 #endif
680 		}
681 
682 		/*
683 		 * Move out the file name (also arg 0).
684 		 */
685 		i = strlen(path) + 1;
686 #ifdef DEBUG
687 		printf("init: copying out path `%s' %ld\n", path, i);
688 #endif
689 #ifdef MACHINE_STACK_GROWS_UP
690 		arg0 = ucp;
691 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
692 		ucp += i;
693 		ucp = (caddr_t)ALIGN((u_long)ucp);
694 		uap = (char **)ucp + 3;
695 #else
696 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
697 		arg0 = ucp;
698 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
699 #endif
700 
701 		/*
702 		 * Move out the arg pointers.
703 		 */
704 		i = 0;
705 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
706 		if (options != 0)
707 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
708 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
709 
710 		/*
711 		 * Point at the arguments.
712 		 */
713 		SCARG(&args, path) = arg0;
714 		SCARG(&args, argp) = uap;
715 		SCARG(&args, envp) = NULL;
716 
717 		/*
718 		 * Now try to exec the program.  If can't for any reason
719 		 * other than it doesn't exist, complain.
720 		 */
721 		if ((error = sys_execve(p, &args, retval)) == 0) {
722 			KERNEL_UNLOCK();
723 			return;
724 		}
725 		if (error != ENOENT)
726 			printf("exec %s: error %d\n", path, error);
727 	}
728 	printf("init: not found\n");
729 	panic("no init");
730 }
731 
732 void
733 start_update(void *arg)
734 {
735 	sched_sync(curproc);
736 	/* NOTREACHED */
737 }
738 
739 void
740 start_cleaner(void *arg)
741 {
742 	buf_daemon(curproc);
743 	/* NOTREACHED */
744 }
745 
746 void
747 start_reaper(void *arg)
748 {
749 	reaper();
750 	/* NOTREACHED */
751 }
752