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