xref: /openbsd-src/sys/kern/init_main.c (revision cd1eb269cafb12c415be1749cd4a4b5422710415)
1 /*	$OpenBSD: init_main.c,v 1.166 2010/01/12 04:06:26 deraadt 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-2010 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 	/* Set the default routing domain. */
268 	process0.ps_rdomain = 0;
269 
270 	LIST_INSERT_HEAD(&allproc, p, p_list);
271 	p->p_pgrp = &pgrp0;
272 	LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
273 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
274 	LIST_INIT(&pgrp0.pg_members);
275 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
276 
277 	pgrp0.pg_session = &session0;
278 	session0.s_count = 1;
279 	session0.s_leader = p;
280 
281 	atomic_setbits_int(&p->p_flag, P_SYSTEM | P_NOCLDWAIT);
282 	p->p_stat = SONPROC;
283 	p->p_nice = NZERO;
284 	p->p_emul = &emul_native;
285 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
286 
287 	/* Init timeouts. */
288 	timeout_set(&p->p_sleep_to, endtsleep, p);
289 	timeout_set(&p->p_realit_to, realitexpire, p);
290 
291 	/* Create credentials. */
292 	cred0.p_refcnt = 1;
293 	p->p_cred = &cred0;
294 	p->p_ucred = crget();
295 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
296 
297 	/* Initialize signal state for process 0. */
298 	signal_init();
299 	p->p_sigacts = &sigacts0;
300 	siginit(p);
301 
302 	/* Create the file descriptor table. */
303 	p->p_fd = fdinit(NULL);
304 
305 	/* Create the limits structures. */
306 	p->p_p->ps_limit = &limit0;
307 	for (i = 0; i < nitems(p->p_rlimit); i++)
308 		limit0.pl_rlimit[i].rlim_cur =
309 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
310 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
311 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
312 	    (maxfiles - NOFILE > NOFILE) ?  maxfiles - NOFILE : NOFILE);
313 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
314 	lim = ptoa(uvmexp.free);
315 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
316 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
317 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
318 	limit0.p_refcnt = 1;
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 	/* Initialize the interface/address trees */
347 	ifinit();
348 
349 	/* Configure the devices */
350 	cpu_configure();
351 
352 	/* Configure virtual memory system, set vm rlimits. */
353 	uvm_init_limits(p);
354 
355 	/* Initialize the file systems. */
356 #if defined(NFSSERVER) || defined(NFSCLIENT)
357 	nfs_init();			/* initialize server/shared data */
358 #endif
359 	vfsinit();
360 
361 	/* Start real time and statistics clocks. */
362 	initclocks();
363 
364 	/* Lock the kernel on behalf of proc0. */
365 	KERNEL_PROC_LOCK(p);
366 
367 #ifdef SYSVSHM
368 	/* Initialize System V style shared memory. */
369 	shminit();
370 #endif
371 
372 #ifdef SYSVSEM
373 	/* Initialize System V style semaphores. */
374 	seminit();
375 #endif
376 
377 #ifdef SYSVMSG
378 	/* Initialize System V style message queues. */
379 	msginit();
380 #endif
381 
382 	/* Attach pseudo-devices. */
383 	randomattach();
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 	swcr_init();
390 #endif /* CRYPTO */
391 
392 	/*
393 	 * Initialize protocols.  Block reception of incoming packets
394 	 * until everything is ready.
395 	 */
396 	s = splnet();
397 	domaininit();
398 	if_attachdomain();
399 	splx(s);
400 
401 #ifdef GPROF
402 	/* Initialize kernel profiling. */
403 	kmstartup();
404 #endif
405 
406 #if !defined(NO_PROPOLICE)
407 	{
408 		volatile long newguard[8];
409 
410 		arc4random_buf((long *)newguard, sizeof(newguard));
411 
412 		for (i = nitems(__guard) - 1; i; i--)
413 			__guard[i] = newguard[i];
414 	}
415 #endif
416 
417 	/* init exec and emul */
418 	init_exec();
419 
420 	/* Start the scheduler */
421 	scheduler_start();
422 
423 	/*
424 	 * Create process 1 (init(8)).  We do this now, as Unix has
425 	 * historically had init be process 1, and changing this would
426 	 * probably upset a lot of people.
427 	 *
428 	 * Note that process 1 won't immediately exec init(8), but will
429 	 * wait for us to inform it that the root file system has been
430 	 * mounted.
431 	 */
432 	if (fork1(p, SIGCHLD, FORK_FORK, NULL, 0, start_init, NULL, NULL,
433 	    &initproc))
434 		panic("fork init");
435 
436 	/*
437 	 * Create any kernel threads whose creation was deferred because
438 	 * initproc 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 NMPATH > 0
454 	config_rootfound("mpath", NULL);
455 #endif
456 #if NVSCSI > 0
457 	config_rootfound("vscsi", NULL);
458 #endif
459 #if NSOFTRAID > 0
460 	config_rootfound("softraid", NULL);
461 #endif
462 
463 	/* Configure root/swap devices */
464 	diskconf();
465 
466 	if (mountroot == NULL || ((*mountroot)() != 0))
467 		panic("cannot mount root");
468 
469 	CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
470 
471 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
472 	if (VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode))
473 		panic("cannot find root vnode");
474 	p->p_fd->fd_cdir = rootvnode;
475 	vref(p->p_fd->fd_cdir);
476 	VOP_UNLOCK(rootvnode, 0, p);
477 	p->p_fd->fd_rdir = NULL;
478 
479 	/*
480 	 * Now that root is mounted, we can fixup initproc's CWD
481 	 * info.  All other processes are kthreads, which merely
482 	 * share proc0's CWD info.
483 	 */
484 	initproc->p_fd->fd_cdir = rootvnode;
485 	vref(initproc->p_fd->fd_cdir);
486 	initproc->p_fd->fd_rdir = NULL;
487 
488 	/*
489 	 * Now can look at time, having had a chance to verify the time
490 	 * from the file system.  Reset p->p_rtime as it may have been
491 	 * munched in mi_switch() after the time got set.
492 	 */
493 #ifdef __HAVE_TIMECOUNTER
494 	microtime(&boottime);
495 #else
496 	boottime = mono_time = time;
497 #endif
498 	LIST_FOREACH(p, &allproc, p_list) {
499 		p->p_stats->p_start = boottime;
500 		microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
501 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
502 	}
503 
504 	uvm_swap_init();
505 
506 	/* Create the pageout daemon kernel thread. */
507 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
508 		panic("fork pagedaemon");
509 
510 	/* Create the reaper daemon kernel thread. */
511 	if (kthread_create(start_reaper, NULL, NULL, "reaper"))
512 		panic("fork reaper");
513 
514 	/* Create the cleaner daemon kernel thread. */
515 	if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
516 		panic("fork cleaner");
517 
518 	/* Create the update daemon kernel thread. */
519 	if (kthread_create(start_update, NULL, NULL, "update"))
520 		panic("fork update");
521 
522 	/* Create the aiodone daemon kernel thread. */
523 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
524 		panic("fork aiodoned");
525 
526 #ifdef CRYPTO
527 	/* Create the crypto kernel thread. */
528 	init_crypto();
529 #endif /* CRYPTO */
530 
531 	microtime(&rtv);
532 	srandom((u_int32_t)(rtv.tv_sec ^ rtv.tv_usec) ^ arc4random());
533 
534 	randompid = 1;
535 
536 #if defined(MULTIPROCESSOR)
537 	/* Boot the secondary processors. */
538 	cpu_boot_secondary_processors();
539 #endif
540 
541 	domountroothooks();
542 
543 	/*
544 	 * Okay, now we can let init(8) exec!  It's off to userland!
545 	 */
546 	start_init_exec = 1;
547 	wakeup((void *)&start_init_exec);
548 
549         /*
550          * proc0: nothing to do, back to sleep
551          */
552         while (1)
553                 tsleep(&proc0, PVM, "scheduler", 0);
554 	/* NOTREACHED */
555 }
556 
557 /*
558  * List of paths to try when searching for "init".
559  */
560 static char *initpaths[] = {
561 	"/sbin/init",
562 	"/sbin/oinit",
563 	"/sbin/init.bak",
564 	NULL,
565 };
566 
567 void
568 check_console(struct proc *p)
569 {
570 	struct nameidata nd;
571 	int error;
572 
573 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
574 	error = namei(&nd);
575 	if (error) {
576 		if (error == ENOENT)
577 			printf("warning: /dev/console does not exist\n");
578 		else
579 			printf("warning: /dev/console error %d\n", error);
580 	} else
581 		vrele(nd.ni_vp);
582 }
583 
584 /*
585  * Start the initial user process; try exec'ing each pathname in "initpaths".
586  * The program is invoked with one argument containing the boot flags.
587  */
588 void
589 start_init(void *arg)
590 {
591 	struct proc *p = arg;
592 	vaddr_t addr;
593 	struct sys_execve_args /* {
594 		syscallarg(const char *) path;
595 		syscallarg(char *const *) argp;
596 		syscallarg(char *const *) envp;
597 	} */ args;
598 	int options, error;
599 	long i;
600 	register_t retval[2];
601 	char flags[4], *flagsp;
602 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
603 
604 	/*
605 	 * Now in process 1.
606 	 */
607 
608 	/*
609 	 * Wait for main() to tell us that it's safe to exec.
610 	 */
611 	while (start_init_exec == 0)
612 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
613 
614 	check_console(p);
615 
616 	/*
617 	 * Need just enough stack to hold the faked-up "execve()" arguments.
618 	 */
619 #ifdef MACHINE_STACK_GROWS_UP
620 	addr = USRSTACK;
621 #else
622 	addr = USRSTACK - PAGE_SIZE;
623 #endif
624 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
625 	    NULL, UVM_UNKNOWN_OFFSET, 0,
626 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_ALL, UVM_INH_COPY,
627 	    UVM_ADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
628 		panic("init: couldn't allocate argument space");
629 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
630 
631 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
632 #ifdef MACHINE_STACK_GROWS_UP
633 		ucp = (char *)addr;
634 #else
635 		ucp = (char *)(addr + PAGE_SIZE);
636 #endif
637 		/*
638 		 * Construct the boot flag argument.
639 		 */
640 		flagsp = flags;
641 		*flagsp++ = '-';
642 		options = 0;
643 
644 		if (boothowto & RB_SINGLE) {
645 			*flagsp++ = 's';
646 			options = 1;
647 		}
648 #ifdef notyet
649 		if (boothowto & RB_FASTBOOT) {
650 			*flagsp++ = 'f';
651 			options = 1;
652 		}
653 #endif
654 
655 		/*
656 		 * Move out the flags (arg 1), if necessary.
657 		 */
658 		if (options != 0) {
659 			*flagsp++ = '\0';
660 			i = flagsp - flags;
661 #ifdef DEBUG
662 			printf("init: copying out flags `%s' %d\n", flags, i);
663 #endif
664 #ifdef MACHINE_STACK_GROWS_UP
665 			arg1 = ucp;
666 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
667 			ucp += i;
668 #else
669 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
670 			arg1 = ucp;
671 #endif
672 		}
673 
674 		/*
675 		 * Move out the file name (also arg 0).
676 		 */
677 		i = strlen(path) + 1;
678 #ifdef DEBUG
679 		printf("init: copying out path `%s' %d\n", path, i);
680 #endif
681 #ifdef MACHINE_STACK_GROWS_UP
682 		arg0 = ucp;
683 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
684 		ucp += i;
685 		ucp = (caddr_t)ALIGN((u_long)ucp);
686 		uap = (char **)ucp + 3;
687 #else
688 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
689 		arg0 = ucp;
690 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
691 #endif
692 
693 		/*
694 		 * Move out the arg pointers.
695 		 */
696 		i = 0;
697 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
698 		if (options != 0)
699 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
700 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
701 
702 		/*
703 		 * Point at the arguments.
704 		 */
705 		SCARG(&args, path) = arg0;
706 		SCARG(&args, argp) = uap;
707 		SCARG(&args, envp) = NULL;
708 
709 		/*
710 		 * Now try to exec the program.  If can't for any reason
711 		 * other than it doesn't exist, complain.
712 		 */
713 		if ((error = sys_execve(p, &args, retval)) == 0) {
714 			KERNEL_PROC_UNLOCK(p);
715 			return;
716 		}
717 		if (error != ENOENT)
718 			printf("exec %s: error %d\n", path, error);
719 	}
720 	printf("init: not found\n");
721 	panic("no init");
722 }
723 
724 void
725 start_update(void *arg)
726 {
727 	sched_sync(curproc);
728 	/* NOTREACHED */
729 }
730 
731 void
732 start_cleaner(void *arg)
733 {
734 	buf_daemon(curproc);
735 	/* NOTREACHED */
736 }
737 
738 void
739 start_reaper(void *arg)
740 {
741 	reaper();
742 	/* NOTREACHED */
743 }
744