xref: /openbsd-src/sys/kern/init_main.c (revision 43003dfe3ad45d1698bed8a37f2b0f5b14f20d4f)
1 /*	$OpenBSD: init_main.c,v 1.162 2009/08/11 18:43:33 blambert 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 	/* Allocate a prototype map so we have something to fork. */
318 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
319 	    trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
320 	p->p_vmspace = &vmspace0;
321 
322 	p->p_addr = proc0paddr;				/* XXX */
323 
324 	/*
325 	 * We continue to place resource usage info in the
326 	 * user struct so they're pageable.
327 	 */
328 	p->p_stats = &p->p_addr->u_stats;
329 
330 	/*
331 	 * Charge root for one process.
332 	 */
333 	(void)chgproccnt(0, 1);
334 
335 	/* Initialize run queues */
336 	sched_init_runqueues();
337 	sleep_queue_init();
338 	sched_init_cpu(curcpu());
339 
340 	/* Initialize work queues */
341 	workq_init();
342 
343 	/* Configure the devices */
344 	cpu_configure();
345 
346 	/* Configure virtual memory system, set vm rlimits. */
347 	uvm_init_limits(p);
348 
349 	/* Initialize the file systems. */
350 #if defined(NFSSERVER) || defined(NFSCLIENT)
351 	nfs_init();			/* initialize server/shared data */
352 #endif
353 	vfsinit();
354 
355 	/* Start real time and statistics clocks. */
356 	initclocks();
357 
358 	/* Lock the kernel on behalf of proc0. */
359 	KERNEL_PROC_LOCK(p);
360 
361 #ifdef SYSVSHM
362 	/* Initialize System V style shared memory. */
363 	shminit();
364 #endif
365 
366 #ifdef SYSVSEM
367 	/* Initialize System V style semaphores. */
368 	seminit();
369 #endif
370 
371 #ifdef SYSVMSG
372 	/* Initialize System V style message queues. */
373 	msginit();
374 #endif
375 
376 	/* Attach pseudo-devices. */
377 	randomattach();
378 	for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
379 		if (pdev->pdev_count > 0)
380 			(*pdev->pdev_attach)(pdev->pdev_count);
381 
382 #ifdef CRYPTO
383 	swcr_init();
384 #endif /* CRYPTO */
385 
386 	/*
387 	 * Initialize protocols.  Block reception of incoming packets
388 	 * until everything is ready.
389 	 */
390 	s = splnet();
391 	ifinit();
392 	domaininit();
393 	if_attachdomain();
394 	splx(s);
395 
396 #ifdef GPROF
397 	/* Initialize kernel profiling. */
398 	kmstartup();
399 #endif
400 
401 #if !defined(NO_PROPOLICE)
402 	{
403 		volatile long newguard[8];
404 
405 		arc4random_buf((long *)newguard, sizeof(newguard));
406 
407 		for (i = nitems(__guard) - 1; i; i--)
408 			__guard[i] = newguard[i];
409 	}
410 #endif
411 
412 	/* init exec and emul */
413 	init_exec();
414 
415 	/* Start the scheduler */
416 	scheduler_start();
417 
418 	/*
419 	 * Create process 1 (init(8)).  We do this now, as Unix has
420 	 * historically had init be process 1, and changing this would
421 	 * probably upset a lot of people.
422 	 *
423 	 * Note that process 1 won't immediately exec init(8), but will
424 	 * wait for us to inform it that the root file system has been
425 	 * mounted.
426 	 */
427 	if (fork1(p, SIGCHLD, FORK_FORK, NULL, 0, start_init, NULL, NULL,
428 	    &initproc))
429 		panic("fork init");
430 
431 	/*
432 	 * Create any kernel threads whose creation was deferred because
433 	 * initproc had not yet been created.
434 	 */
435 	kthread_run_deferred_queue();
436 
437 	/*
438 	 * Now that device driver threads have been created, wait for
439 	 * them to finish any deferred autoconfiguration.  Note we don't
440 	 * need to lock this semaphore, since we haven't booted any
441 	 * secondary processors, yet.
442 	 */
443 	while (config_pending)
444 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
445 
446 	dostartuphooks();
447 
448 #if NMPATH > 0
449 	config_rootfound("mpath", NULL);
450 #endif
451 #if NVSCSI > 0
452 	config_rootfound("vscsi", NULL);
453 #endif
454 #if NSOFTRAID > 0
455 	config_rootfound("softraid", NULL);
456 #endif
457 
458 	/* Configure root/swap devices */
459 	diskconf();
460 
461 	if (mountroot == NULL || ((*mountroot)() != 0))
462 		panic("cannot mount root");
463 
464 	CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
465 
466 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
467 	if (VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode))
468 		panic("cannot find root vnode");
469 	p->p_fd->fd_cdir = rootvnode;
470 	vref(p->p_fd->fd_cdir);
471 	VOP_UNLOCK(rootvnode, 0, p);
472 	p->p_fd->fd_rdir = NULL;
473 
474 	/*
475 	 * Now that root is mounted, we can fixup initproc's CWD
476 	 * info.  All other processes are kthreads, which merely
477 	 * share proc0's CWD info.
478 	 */
479 	initproc->p_fd->fd_cdir = rootvnode;
480 	vref(initproc->p_fd->fd_cdir);
481 	initproc->p_fd->fd_rdir = NULL;
482 
483 	/*
484 	 * Now can look at time, having had a chance to verify the time
485 	 * from the file system.  Reset p->p_rtime as it may have been
486 	 * munched in mi_switch() after the time got set.
487 	 */
488 #ifdef __HAVE_TIMECOUNTER
489 	microtime(&boottime);
490 #else
491 	boottime = mono_time = time;
492 #endif
493 	LIST_FOREACH(p, &allproc, p_list) {
494 		p->p_stats->p_start = boottime;
495 		microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
496 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
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, NULL, "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 #ifdef CRYPTO
522 	/* Create the crypto kernel thread. */
523 	init_crypto();
524 #endif /* CRYPTO */
525 
526 	microtime(&rtv);
527 	srandom((u_int32_t)(rtv.tv_sec ^ rtv.tv_usec) ^ arc4random());
528 
529 	randompid = 1;
530 
531 #if defined(MULTIPROCESSOR)
532 	/* Boot the secondary processors. */
533 	cpu_boot_secondary_processors();
534 #endif
535 
536 	domountroothooks();
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          * proc0: nothing to do, back to sleep
546          */
547         while (1)
548                 tsleep(&proc0, PVM, "scheduler", 0);
549 	/* NOTREACHED */
550 }
551 
552 /*
553  * List of paths to try when searching for "init".
554  */
555 static char *initpaths[] = {
556 	"/sbin/init",
557 	"/sbin/oinit",
558 	"/sbin/init.bak",
559 	NULL,
560 };
561 
562 void
563 check_console(struct proc *p)
564 {
565 	struct nameidata nd;
566 	int error;
567 
568 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
569 	error = namei(&nd);
570 	if (error) {
571 		if (error == ENOENT)
572 			printf("warning: /dev/console does not exist\n");
573 		else
574 			printf("warning: /dev/console error %d\n", error);
575 	} else
576 		vrele(nd.ni_vp);
577 }
578 
579 /*
580  * Start the initial user process; try exec'ing each pathname in "initpaths".
581  * The program is invoked with one argument containing the boot flags.
582  */
583 void
584 start_init(void *arg)
585 {
586 	struct proc *p = arg;
587 	vaddr_t addr;
588 	struct sys_execve_args /* {
589 		syscallarg(const char *) path;
590 		syscallarg(char *const *) argp;
591 		syscallarg(char *const *) envp;
592 	} */ args;
593 	int options, error;
594 	long i;
595 	register_t retval[2];
596 	char flags[4], *flagsp;
597 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
598 
599 	/*
600 	 * Now in process 1.
601 	 */
602 
603 	/*
604 	 * Wait for main() to tell us that it's safe to exec.
605 	 */
606 	while (start_init_exec == 0)
607 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
608 
609 	check_console(p);
610 
611 	/*
612 	 * Need just enough stack to hold the faked-up "execve()" arguments.
613 	 */
614 #ifdef MACHINE_STACK_GROWS_UP
615 	addr = USRSTACK;
616 #else
617 	addr = USRSTACK - PAGE_SIZE;
618 #endif
619 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
620 	    NULL, UVM_UNKNOWN_OFFSET, 0,
621 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_ALL, UVM_INH_COPY,
622 	    UVM_ADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
623 		panic("init: couldn't allocate argument space");
624 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
625 
626 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
627 #ifdef MACHINE_STACK_GROWS_UP
628 		ucp = (char *)addr;
629 #else
630 		ucp = (char *)(addr + PAGE_SIZE);
631 #endif
632 		/*
633 		 * Construct the boot flag argument.
634 		 */
635 		flagsp = flags;
636 		*flagsp++ = '-';
637 		options = 0;
638 
639 		if (boothowto & RB_SINGLE) {
640 			*flagsp++ = 's';
641 			options = 1;
642 		}
643 #ifdef notyet
644 		if (boothowto & RB_FASTBOOT) {
645 			*flagsp++ = 'f';
646 			options = 1;
647 		}
648 #endif
649 
650 		/*
651 		 * Move out the flags (arg 1), if necessary.
652 		 */
653 		if (options != 0) {
654 			*flagsp++ = '\0';
655 			i = flagsp - flags;
656 #ifdef DEBUG
657 			printf("init: copying out flags `%s' %d\n", flags, i);
658 #endif
659 #ifdef MACHINE_STACK_GROWS_UP
660 			arg1 = ucp;
661 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
662 			ucp += i;
663 #else
664 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
665 			arg1 = ucp;
666 #endif
667 		}
668 
669 		/*
670 		 * Move out the file name (also arg 0).
671 		 */
672 		i = strlen(path) + 1;
673 #ifdef DEBUG
674 		printf("init: copying out path `%s' %d\n", path, i);
675 #endif
676 #ifdef MACHINE_STACK_GROWS_UP
677 		arg0 = ucp;
678 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
679 		ucp += i;
680 		ucp = (caddr_t)ALIGN((u_long)ucp);
681 		uap = (char **)ucp + 3;
682 #else
683 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
684 		arg0 = ucp;
685 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
686 #endif
687 
688 		/*
689 		 * Move out the arg pointers.
690 		 */
691 		i = 0;
692 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
693 		if (options != 0)
694 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
695 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
696 
697 		/*
698 		 * Point at the arguments.
699 		 */
700 		SCARG(&args, path) = arg0;
701 		SCARG(&args, argp) = uap;
702 		SCARG(&args, envp) = NULL;
703 
704 		/*
705 		 * Now try to exec the program.  If can't for any reason
706 		 * other than it doesn't exist, complain.
707 		 */
708 		if ((error = sys_execve(p, &args, retval)) == 0) {
709 			KERNEL_PROC_UNLOCK(p);
710 			return;
711 		}
712 		if (error != ENOENT)
713 			printf("exec %s: error %d\n", path, error);
714 	}
715 	printf("init: not found\n");
716 	panic("no init");
717 }
718 
719 void
720 start_update(void *arg)
721 {
722 	sched_sync(curproc);
723 	/* NOTREACHED */
724 }
725 
726 void
727 start_cleaner(void *arg)
728 {
729 	buf_daemon(curproc);
730 	/* NOTREACHED */
731 }
732 
733 void
734 start_reaper(void *arg)
735 {
736 	reaper();
737 	/* NOTREACHED */
738 }
739