xref: /openbsd-src/sys/kern/init_main.c (revision ac9b4aacc1da35008afea06a5d23c2f2dea9b93e)
1 /*	$OpenBSD: init_main.c,v 1.184 2012/08/28 16:39:09 matthew 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 #include <net/netisr.h>
93 
94 #if defined(CRYPTO)
95 #include <crypto/cryptodev.h>
96 #include <crypto/cryptosoft.h>
97 #endif
98 
99 #if defined(NFSSERVER) || defined(NFSCLIENT)
100 extern void nfs_init(void);
101 #endif
102 
103 #include "mpath.h"
104 #include "vscsi.h"
105 #include "softraid.h"
106 
107 const char	copyright[] =
108 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
109 "\tThe Regents of the University of California.  All rights reserved.\n"
110 "Copyright (c) 1995-2012 OpenBSD. All rights reserved.  http://www.OpenBSD.org\n";
111 
112 /* Components of the first process -- never freed. */
113 struct	session session0;
114 struct	pgrp pgrp0;
115 struct	proc proc0;
116 struct	process process0;
117 struct	pcred cred0;
118 struct	plimit limit0;
119 struct	vmspace vmspace0;
120 struct	sigacts sigacts0;
121 struct	proc *initproc;
122 struct	proc *reaperproc;
123 
124 int	cmask = CMASK;
125 extern	struct user *proc0paddr;
126 
127 struct	vnode *rootvp, *swapdev_vp;
128 int	boothowto;
129 struct	timeval boottime;
130 int	ncpus =  1;
131 int	ncpusfound = 1;			/* number of cpus we find */
132 __volatile int start_init_exec;		/* semaphore for start_init() */
133 
134 #if !defined(NO_PROPOLICE)
135 #ifdef __ELF__
136 long	__guard_local __dso_hidden;
137 #endif
138 long	__guard[8];
139 #endif
140 
141 /* XXX return int so gcc -Werror won't complain */
142 int	main(void *);
143 void	check_console(struct proc *);
144 void	start_init(void *);
145 void	start_cleaner(void *);
146 void	start_update(void *);
147 void	start_reaper(void *);
148 void	crypto_init(void);
149 void	init_exec(void);
150 void	kqueue_init(void);
151 void	workq_init(void);
152 
153 extern char sigcode[], esigcode[];
154 #ifdef SYSCALL_DEBUG
155 extern char *syscallnames[];
156 #endif
157 
158 struct emul emul_native = {
159 	"native",
160 	NULL,
161 	sendsig,
162 	SYS_syscall,
163 	SYS_MAXSYSCALL,
164 	sysent,
165 #ifdef SYSCALL_DEBUG
166 	syscallnames,
167 #else
168 	NULL,
169 #endif
170 	0,
171 	copyargs,
172 	setregs,
173 	NULL,
174 	coredump_trad,
175 	sigcode,
176 	esigcode,
177 	EMUL_ENABLED | EMUL_NATIVE,
178 };
179 
180 
181 /*
182  * System startup; initialize the world, create process 0, mount root
183  * filesystem, and fork to create init and pagedaemon.  Most of the
184  * hard work is done in the lower-level initialization routines including
185  * startup(), which does memory initialization and autoconfiguration.
186  */
187 /* XXX return int, so gcc -Werror won't complain */
188 int
189 main(void *framep)
190 {
191 	struct proc *p;
192 	struct process *pr;
193 	struct pdevinit *pdev;
194 	struct timeval rtv;
195 	quad_t lim;
196 	int s, i;
197 	extern struct pdevinit pdevinit[];
198 	extern void disk_init(void);
199 
200 	/*
201 	 * Initialize the current process pointer (curproc) before
202 	 * any possible traps/probes to simplify trap processing.
203 	 */
204 	curproc = p = &proc0;
205 	p->p_cpu = curcpu();
206 
207 	/*
208 	 * Initialize timeouts.
209 	 */
210 	timeout_startup();
211 
212 	/*
213 	 * Attempt to find console and initialize
214 	 * in case of early panic or other messages.
215 	 */
216 	config_init();		/* init autoconfiguration data structures */
217 	consinit();
218 
219 	printf("%s\n", copyright);
220 
221 	KERNEL_LOCK_INIT();
222 	SCHED_LOCK_INIT();
223 
224 	random_init();
225 
226 	uvm_init();
227 	disk_init();		/* must come before autoconfiguration */
228 	tty_init();		/* initialise tty's */
229 	cpu_startup();
230 
231 	/*
232 	 * Initialize mbuf's.  Do this now because we might attempt to
233 	 * allocate mbufs or mbuf clusters during autoconfiguration.
234 	 */
235 	mbinit();
236 
237 	/* Initialize sockets. */
238 	soinit();
239 
240 	/*
241 	 * Initialize process and pgrp structures.
242 	 */
243 	procinit();
244 
245 	/* Initialize file locking. */
246 	lf_init();
247 
248 	/*
249 	 * Initialize filedescriptors.
250 	 */
251 	filedesc_init();
252 
253 	/*
254 	 * Initialize pipes.
255 	 */
256 	pipe_init();
257 
258 	/*
259 	 * Initialize kqueues.
260 	 */
261 	kqueue_init();
262 
263 	/*
264 	 * Create process 0 (the swapper).
265 	 */
266 
267 	process0.ps_mainproc = p;
268 	TAILQ_INIT(&process0.ps_threads);
269 	TAILQ_INSERT_TAIL(&process0.ps_threads, p, p_thr_link);
270 	process0.ps_refcnt = 1;
271 	p->p_p = pr = &process0;
272 
273 	/* Set the default routing table/domain. */
274 	process0.ps_rtableid = 0;
275 
276 	LIST_INSERT_HEAD(&allproc, p, p_list);
277 	pr->ps_pgrp = &pgrp0;
278 	LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
279 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
280 	LIST_INIT(&pgrp0.pg_members);
281 	LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
282 
283 	pgrp0.pg_session = &session0;
284 	session0.s_count = 1;
285 	session0.s_leader = pr;
286 
287 	atomic_setbits_int(&p->p_flag, P_SYSTEM);
288 	p->p_stat = SONPROC;
289 	pr->ps_nice = NZERO;
290 	p->p_emul = &emul_native;
291 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
292 
293 	/* Init timeouts. */
294 	timeout_set(&p->p_sleep_to, endtsleep, p);
295 	timeout_set(&pr->ps_realit_to, realitexpire, pr);
296 
297 	/* Create credentials. */
298 	p->p_cred = &cred0;
299 	p->p_ucred = crget();
300 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
301 
302 	/* Initialize signal state for process 0. */
303 	signal_init();
304 	p->p_sigacts = &sigacts0;
305 	siginit(p);
306 
307 	/* Create the file descriptor table. */
308 	p->p_fd = fdinit(NULL);
309 
310 	/* Create the limits structures. */
311 	pr->ps_limit = &limit0;
312 	for (i = 0; i < nitems(p->p_rlimit); i++)
313 		limit0.pl_rlimit[i].rlim_cur =
314 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
315 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
316 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
317 	    (maxfiles - NOFILE > NOFILE) ?  maxfiles - NOFILE : NOFILE);
318 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
319 	lim = ptoa(uvmexp.free);
320 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
321 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
322 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
323 	limit0.p_refcnt = 1;
324 
325 	/* Allocate a prototype map so we have something to fork. */
326 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
327 	    trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
328 	p->p_vmspace = &vmspace0;
329 
330 	p->p_addr = proc0paddr;				/* XXX */
331 
332 	/*
333 	 * Charge root for one process.
334 	 */
335 	(void)chgproccnt(0, 1);
336 
337 	/* Initialize run queues */
338 	sched_init_runqueues();
339 	sleep_queue_init();
340 	sched_init_cpu(curcpu());
341 
342 	/* Initialize work queues */
343 	workq_init();
344 
345 	random_start();
346 
347 	/* Initialize the interface/address trees */
348 	ifinit();
349 
350 	/* Configure the devices */
351 	cpu_configure();
352 
353 	/* Configure virtual memory system, set vm rlimits. */
354 	uvm_init_limits(p);
355 
356 	/* Initialize the file systems. */
357 #if defined(NFSSERVER) || defined(NFSCLIENT)
358 	nfs_init();			/* initialize server/shared data */
359 #endif
360 	vfsinit();
361 
362 	/* Start real time and statistics clocks. */
363 	initclocks();
364 
365 	/* Lock the kernel on behalf of proc0. */
366 	KERNEL_LOCK();
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 	/*
394 	 * Initialize protocols.  Block reception of incoming packets
395 	 * until everything is ready.
396 	 */
397 	s = splnet();
398 	netisr_init();
399 	domaininit();
400 	if_attachdomain();
401 	splx(s);
402 
403 #ifdef GPROF
404 	/* Initialize kernel profiling. */
405 	kmstartup();
406 #endif
407 
408 #if !defined(NO_PROPOLICE)
409 	{
410 		volatile long newguard[8];
411 
412 		arc4random_buf((long *)newguard, sizeof(newguard));
413 
414 #ifdef __ELF__
415 		__guard_local = newguard[0];
416 #endif
417 		for (i = nitems(__guard) - 1; i; i--)
418 			__guard[i] = newguard[i];
419 	}
420 #endif
421 
422 	/* init exec and emul */
423 	init_exec();
424 
425 	/* Start the scheduler */
426 	scheduler_start();
427 
428 	/*
429 	 * Create process 1 (init(8)).  We do this now, as Unix has
430 	 * historically had init be process 1, and changing this would
431 	 * probably upset a lot of people.
432 	 *
433 	 * Note that process 1 won't immediately exec init(8), but will
434 	 * wait for us to inform it that the root file system has been
435 	 * mounted.
436 	 */
437 	if (fork1(p, SIGCHLD, FORK_FORK, NULL, 0, start_init, NULL, NULL,
438 	    &initproc))
439 		panic("fork init");
440 
441 	/*
442 	 * Create any kernel threads whose creation was deferred because
443 	 * initproc had not yet been created.
444 	 */
445 	kthread_run_deferred_queue();
446 
447 	/*
448 	 * Now that device driver threads have been created, wait for
449 	 * them to finish any deferred autoconfiguration.  Note we don't
450 	 * need to lock this semaphore, since we haven't booted any
451 	 * secondary processors, yet.
452 	 */
453 	while (config_pending)
454 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
455 
456 	dostartuphooks();
457 
458 #if NMPATH > 0
459 	config_rootfound("mpath", NULL);
460 #endif
461 #if NVSCSI > 0
462 	config_rootfound("vscsi", NULL);
463 #endif
464 #if NSOFTRAID > 0
465 	config_rootfound("softraid", NULL);
466 #endif
467 
468 	/* Configure root/swap devices */
469 	diskconf();
470 
471 	if (mountroot == NULL || ((*mountroot)() != 0))
472 		panic("cannot mount root");
473 
474 	CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
475 
476 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
477 	if (VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode))
478 		panic("cannot find root vnode");
479 	p->p_fd->fd_cdir = rootvnode;
480 	vref(p->p_fd->fd_cdir);
481 	VOP_UNLOCK(rootvnode, 0, p);
482 	p->p_fd->fd_rdir = NULL;
483 
484 	/*
485 	 * Now that root is mounted, we can fixup initproc's CWD
486 	 * info.  All other processes are kthreads, which merely
487 	 * share proc0's CWD info.
488 	 */
489 	initproc->p_fd->fd_cdir = rootvnode;
490 	vref(initproc->p_fd->fd_cdir);
491 	initproc->p_fd->fd_rdir = NULL;
492 
493 	/*
494 	 * Now can look at time, having had a chance to verify the time
495 	 * from the file system.  Reset p->p_rtime as it may have been
496 	 * munched in mi_switch() after the time got set.
497 	 */
498 #ifdef __HAVE_TIMECOUNTER
499 	microtime(&boottime);
500 #else
501 	boottime = mono_time = time;
502 #endif
503 	LIST_FOREACH(p, &allproc, p_list) {
504 		p->p_p->ps_start = boottime;
505 		microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
506 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
507 	}
508 
509 	uvm_swap_init();
510 
511 	/* Create the pageout daemon kernel thread. */
512 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
513 		panic("fork pagedaemon");
514 
515 	/* Create the reaper daemon kernel thread. */
516 	if (kthread_create(start_reaper, NULL, &reaperproc, "reaper"))
517 		panic("fork reaper");
518 
519 	/* Create the cleaner daemon kernel thread. */
520 	if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
521 		panic("fork cleaner");
522 
523 	/* Create the update daemon kernel thread. */
524 	if (kthread_create(start_update, NULL, NULL, "update"))
525 		panic("fork update");
526 
527 	/* Create the aiodone daemon kernel thread. */
528 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
529 		panic("fork aiodoned");
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 	/* process 0 ignores SIGCHLD, but we can't */
617 	p->p_sigacts->ps_flags = 0;
618 
619 	/*
620 	 * Need just enough stack to hold the faked-up "execve()" arguments.
621 	 */
622 #ifdef MACHINE_STACK_GROWS_UP
623 	addr = USRSTACK;
624 #else
625 	addr = USRSTACK - PAGE_SIZE;
626 #endif
627 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
628 	    NULL, UVM_UNKNOWN_OFFSET, 0,
629 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_ALL, UVM_INH_COPY,
630 	    UVM_ADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
631 		panic("init: couldn't allocate argument space");
632 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
633 
634 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
635 #ifdef MACHINE_STACK_GROWS_UP
636 		ucp = (char *)addr;
637 #else
638 		ucp = (char *)(addr + PAGE_SIZE);
639 #endif
640 		/*
641 		 * Construct the boot flag argument.
642 		 */
643 		flagsp = flags;
644 		*flagsp++ = '-';
645 		options = 0;
646 
647 		if (boothowto & RB_SINGLE) {
648 			*flagsp++ = 's';
649 			options = 1;
650 		}
651 #ifdef notyet
652 		if (boothowto & RB_FASTBOOT) {
653 			*flagsp++ = 'f';
654 			options = 1;
655 		}
656 #endif
657 
658 		/*
659 		 * Move out the flags (arg 1), if necessary.
660 		 */
661 		if (options != 0) {
662 			*flagsp++ = '\0';
663 			i = flagsp - flags;
664 #ifdef DEBUG
665 			printf("init: copying out flags `%s' %d\n", flags, i);
666 #endif
667 #ifdef MACHINE_STACK_GROWS_UP
668 			arg1 = ucp;
669 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
670 			ucp += i;
671 #else
672 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
673 			arg1 = ucp;
674 #endif
675 		}
676 
677 		/*
678 		 * Move out the file name (also arg 0).
679 		 */
680 		i = strlen(path) + 1;
681 #ifdef DEBUG
682 		printf("init: copying out path `%s' %d\n", path, i);
683 #endif
684 #ifdef MACHINE_STACK_GROWS_UP
685 		arg0 = ucp;
686 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
687 		ucp += i;
688 		ucp = (caddr_t)ALIGN((u_long)ucp);
689 		uap = (char **)ucp + 3;
690 #else
691 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
692 		arg0 = ucp;
693 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
694 #endif
695 
696 		/*
697 		 * Move out the arg pointers.
698 		 */
699 		i = 0;
700 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
701 		if (options != 0)
702 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
703 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
704 
705 		/*
706 		 * Point at the arguments.
707 		 */
708 		SCARG(&args, path) = arg0;
709 		SCARG(&args, argp) = uap;
710 		SCARG(&args, envp) = NULL;
711 
712 		/*
713 		 * Now try to exec the program.  If can't for any reason
714 		 * other than it doesn't exist, complain.
715 		 */
716 		if ((error = sys_execve(p, &args, retval)) == 0) {
717 			KERNEL_UNLOCK();
718 			return;
719 		}
720 		if (error != ENOENT)
721 			printf("exec %s: error %d\n", path, error);
722 	}
723 	printf("init: not found\n");
724 	panic("no init");
725 }
726 
727 void
728 start_update(void *arg)
729 {
730 	sched_sync(curproc);
731 	/* NOTREACHED */
732 }
733 
734 void
735 start_cleaner(void *arg)
736 {
737 	buf_daemon(curproc);
738 	/* NOTREACHED */
739 }
740 
741 void
742 start_reaper(void *arg)
743 {
744 	reaper();
745 	/* NOTREACHED */
746 }
747