xref: /openbsd-src/sys/kern/init_main.c (revision 03adc85b7600a1f8f04886b8321c1c1c0c4933d4)
1 /*	$OpenBSD: init_main.c,v 1.265 2017/01/21 05:42:03 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/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-2017 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	timeout_proc_init(void);
148 void	pool_gc_pages(void *);
149 void	percpu_init(void);
150 
151 extern char sigcode[], esigcode[], sigcoderet[];
152 #ifdef SYSCALL_DEBUG
153 extern char *syscallnames[];
154 #endif
155 
156 struct emul emul_native = {
157 	"native",
158 	NULL,
159 	sendsig,
160 	SYS_syscall,
161 	SYS_MAXSYSCALL,
162 	sysent,
163 #ifdef SYSCALL_DEBUG
164 	syscallnames,
165 #else
166 	NULL,
167 #endif
168 	0,
169 	copyargs,
170 	setregs,
171 	NULL,		/* fixup */
172 	NULL,		/* coredump */
173 	sigcode,
174 	esigcode,
175 	sigcoderet,
176 	EMUL_ENABLED | EMUL_NATIVE,
177 };
178 
179 
180 /*
181  * System startup; initialize the world, create process 0, mount root
182  * filesystem, and fork to create init and pagedaemon.  Most of the
183  * hard work is done in the lower-level initialization routines including
184  * startup(), which does memory initialization and autoconfiguration.
185  */
186 /* XXX return int, so gcc -Werror won't complain */
187 int
188 main(void *framep)
189 {
190 	struct proc *p;
191 	struct process *pr;
192 	struct pdevinit *pdev;
193 	quad_t lim;
194 	int s, i;
195 	extern struct pdevinit pdevinit[];
196 	extern void disk_init(void);
197 
198 	/*
199 	 * Initialize the current process pointer (curproc) before
200 	 * any possible traps/probes to simplify trap processing.
201 	 */
202 	curproc = p = &proc0;
203 	p->p_cpu = curcpu();
204 
205 	/*
206 	 * Initialize timeouts.
207 	 */
208 	timeout_startup();
209 
210 	/*
211 	 * Attempt to find console and initialize
212 	 * in case of early panic or other messages.
213 	 */
214 	config_init();		/* init autoconfiguration data structures */
215 	consinit();
216 
217 	printf("%s\n", copyright);
218 
219 	KERNEL_LOCK_INIT();
220 	SCHED_LOCK_INIT();
221 
222 	uvm_init();
223 	disk_init();		/* must come before autoconfiguration */
224 	tty_init();		/* initialise tty's */
225 	cpu_startup();
226 
227 	random_start();		/* Start the flow */
228 
229 	/*
230 	 * Initialize mbuf's.  Do this now because we might attempt to
231 	 * allocate mbufs or mbuf clusters during autoconfiguration.
232 	 */
233 	mbinit();
234 
235 	/* Initialize sockets. */
236 	soinit();
237 
238 	/* Initialize SRP subsystem. */
239 	srp_startup();
240 
241 	/*
242 	 * Initialize process and pgrp structures.
243 	 */
244 	procinit();
245 
246 	/* Initialize file locking. */
247 	lf_init();
248 
249 	/*
250 	 * Initialize filedescriptors.
251 	 */
252 	filedesc_init();
253 
254 	/*
255 	 * Initialize pipes.
256 	 */
257 	pipe_init();
258 
259 	/*
260 	 * Initialize kqueues.
261 	 */
262 	kqueue_init();
263 
264 	/* Create credentials. */
265 	p->p_ucred = crget();
266 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
267 
268 	/*
269 	 * Create process 0 (the swapper).
270 	 */
271 	pr = &process0;
272 	process_initialize(pr, p);
273 
274 	LIST_INSERT_HEAD(&allprocess, pr, ps_list);
275 	LIST_INSERT_HEAD(PIDHASH(0), pr, ps_hash);
276 	atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
277 
278 	/* Set the default routing table/domain. */
279 	process0.ps_rtableid = 0;
280 
281 	LIST_INSERT_HEAD(&allproc, p, p_list);
282 	pr->ps_pgrp = &pgrp0;
283 	LIST_INSERT_HEAD(TIDHASH(0), p, p_hash);
284 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
285 	LIST_INIT(&pgrp0.pg_members);
286 	LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
287 
288 	pgrp0.pg_session = &session0;
289 	session0.s_count = 1;
290 	session0.s_leader = pr;
291 
292 	atomic_setbits_int(&p->p_flag, P_SYSTEM);
293 	p->p_stat = SONPROC;
294 	pr->ps_nice = NZERO;
295 	pr->ps_emul = &emul_native;
296 	strlcpy(pr->ps_comm, "swapper", sizeof(pr->ps_comm));
297 
298 	/* Init timeouts. */
299 	timeout_set(&p->p_sleep_to, endtsleep, p);
300 
301 	/* Initialize signal state for process 0. */
302 	signal_init();
303 	pr->ps_sigacts = &sigacts0;
304 	siginit(pr);
305 
306 	/* Create the file descriptor table. */
307 	p->p_fd = pr->ps_fd = fdinit();
308 
309 	/* Create the limits structures. */
310 	pr->ps_limit = &limit0;
311 	for (i = 0; i < nitems(p->p_rlimit); i++)
312 		limit0.pl_rlimit[i].rlim_cur =
313 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
314 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
315 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
316 	    (maxfiles - NOFILE > NOFILE) ?  maxfiles - NOFILE : NOFILE);
317 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
318 	lim = ptoa(uvmexp.free);
319 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
320 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
321 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
322 	limit0.p_refcnt = 1;
323 
324 	/* Allocate a prototype map so we have something to fork. */
325 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
326 	    trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
327 	p->p_vmspace = pr->ps_vmspace = &vmspace0;
328 
329 	p->p_addr = proc0paddr;				/* XXX */
330 
331 	/*
332 	 * Charge root for one process.
333 	 */
334 	(void)chgproccnt(0, 1);
335 
336 	/* Initialize run queues */
337 	sched_init_runqueues();
338 	sleep_queue_init();
339 	sched_init_cpu(curcpu());
340 	p->p_cpu->ci_randseed = (arc4random() & 0x7fffffff) + 1;
341 
342 	/* Initialize timeouts in process context. */
343 	timeout_proc_init();
344 
345 	/* Initialize task queues */
346 	taskq_init();
347 
348 	/* Initialize the interface/address trees */
349 	ifinit();
350 
351 	/* Lock the kernel on behalf of proc0. */
352 	KERNEL_LOCK();
353 
354 #if NMPATH > 0
355 	/* Attach mpath before hardware */
356 	config_rootfound("mpath", NULL);
357 #endif
358 
359 	/* Configure the devices */
360 	cpu_configure();
361 
362 	/* Configure virtual memory system, set vm rlimits. */
363 	uvm_init_limits(p);
364 
365 	/* Per CPU memory allocation */
366 	percpu_init();
367 
368 	/* Initialize the file systems. */
369 #if defined(NFSSERVER) || defined(NFSCLIENT)
370 	nfs_init();			/* initialize server/shared data */
371 #endif
372 	vfsinit();
373 
374 	/* Start real time and statistics clocks. */
375 	initclocks();
376 
377 #ifdef SYSVSHM
378 	/* Initialize System V style shared memory. */
379 	shminit();
380 #endif
381 
382 #ifdef SYSVSEM
383 	/* Initialize System V style semaphores. */
384 	seminit();
385 #endif
386 
387 #ifdef SYSVMSG
388 	/* Initialize System V style message queues. */
389 	msginit();
390 #endif
391 
392 	/* Create default routing table before attaching lo0. */
393 	rtable_init();
394 
395 	/* Attach pseudo-devices. */
396 	for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
397 		if (pdev->pdev_count > 0)
398 			(*pdev->pdev_attach)(pdev->pdev_count);
399 
400 #ifdef CRYPTO
401 	crypto_init();
402 	swcr_init();
403 #endif /* CRYPTO */
404 
405 	/*
406 	 * Initialize protocols.  Block reception of incoming packets
407 	 * until everything is ready.
408 	 */
409 	s = splnet();
410 	domaininit();
411 	splx(s);
412 
413 	initconsbuf();
414 
415 #if defined(GPROF) || defined(DDBPROF)
416 	/* Initialize kernel profiling. */
417 	prof_init();
418 #endif
419 
420 	mbcpuinit();	/* enable per cpu mbuf data */
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 	{
438 		struct proc *initproc;
439 
440 		if (fork1(p, FORK_FORK, NULL, 0, start_init, NULL, NULL,
441 		    &initproc))
442 			panic("fork init");
443 		initprocess = initproc->p_p;
444 	}
445 
446 	randompid = 1;
447 
448 	/*
449 	 * Create any kernel threads whose creation was deferred because
450 	 * initprocess had not yet been created.
451 	 */
452 	kthread_run_deferred_queue();
453 
454 	/*
455 	 * Now that device driver threads have been created, wait for
456 	 * them to finish any deferred autoconfiguration.  Note we don't
457 	 * need to lock this semaphore, since we haven't booted any
458 	 * secondary processors, yet.
459 	 */
460 	while (config_pending)
461 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
462 
463 	dostartuphooks();
464 
465 #if NVSCSI > 0
466 	config_rootfound("vscsi", NULL);
467 #endif
468 #if NSOFTRAID > 0
469 	config_rootfound("softraid", NULL);
470 #endif
471 
472 	/* Configure root/swap devices */
473 	diskconf();
474 
475 	if (mountroot == NULL || ((*mountroot)() != 0))
476 		panic("cannot mount root");
477 
478 	TAILQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
479 
480 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
481 	if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
482 		panic("cannot find root vnode");
483 	p->p_fd->fd_cdir = rootvnode;
484 	vref(p->p_fd->fd_cdir);
485 	VOP_UNLOCK(rootvnode, p);
486 	p->p_fd->fd_rdir = NULL;
487 
488 	/*
489 	 * Now that root is mounted, we can fixup initprocess's CWD
490 	 * info.  All other processes are kthreads, which merely
491 	 * share proc0's CWD info.
492 	 */
493 	initprocess->ps_fd->fd_cdir = rootvnode;
494 	vref(initprocess->ps_fd->fd_cdir);
495 	initprocess->ps_fd->fd_rdir = NULL;
496 
497 	/*
498 	 * Now can look at time, having had a chance to verify the time
499 	 * from the file system.  Reset p->p_rtime as it may have been
500 	 * munched in mi_switch() after the time got set.
501 	 */
502 	nanotime(&boottime);
503 	LIST_FOREACH(pr, &allprocess, ps_list) {
504 		pr->ps_start = boottime;
505 		TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
506 			nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
507 			timespecclear(&p->p_rtime);
508 		}
509 	}
510 
511 	uvm_swap_init();
512 
513 	/* Create the pageout daemon kernel thread. */
514 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
515 		panic("fork pagedaemon");
516 
517 	/* Create the reaper daemon kernel thread. */
518 	if (kthread_create(start_reaper, NULL, &reaperproc, "reaper"))
519 		panic("fork reaper");
520 
521 	/* Create the cleaner daemon kernel thread. */
522 	if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
523 		panic("fork cleaner");
524 
525 	/* Create the update daemon kernel thread. */
526 	if (kthread_create(start_update, NULL, NULL, "update"))
527 		panic("fork update");
528 
529 	/* Create the aiodone daemon kernel thread. */
530 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
531 		panic("fork aiodoned");
532 
533 #if !defined(__hppa__)
534 	/* Create the page zeroing kernel thread. */
535 	if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread"))
536 		panic("fork zerothread");
537 #endif
538 
539 #if defined(MULTIPROCESSOR)
540 	/* Boot the secondary processors. */
541 	cpu_boot_secondary_processors();
542 #endif
543 
544 	config_process_deferred_mountroot();
545 
546 #ifdef DDBCTF
547 	db_ctf_init();
548 #endif
549 
550 	/*
551 	 * Okay, now we can let init(8) exec!  It's off to userland!
552 	 */
553 	start_init_exec = 1;
554 	wakeup((void *)&start_init_exec);
555 
556 	/*
557 	 * Start the idle pool page garbage collector
558 	 */
559 #if !(defined(__m88k__) && defined(MULTIPROCESSOR))	/* XXX */
560 	pool_gc_pages(NULL);
561 #endif
562 
563 	start_periodic_resettodr();
564 
565         /*
566          * proc0: nothing to do, back to sleep
567          */
568         while (1)
569                 tsleep(&proc0, PVM, "scheduler", 0);
570 	/* NOTREACHED */
571 }
572 
573 /*
574  * List of paths to try when searching for "init".
575  */
576 static char *initpaths[] = {
577 	"/sbin/init",
578 	"/sbin/oinit",
579 	"/sbin/init.bak",
580 	NULL,
581 };
582 
583 void
584 check_console(struct proc *p)
585 {
586 	struct nameidata nd;
587 	int error;
588 
589 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
590 	error = namei(&nd);
591 	if (error) {
592 		if (error == ENOENT)
593 			printf("warning: /dev/console does not exist\n");
594 		else
595 			printf("warning: /dev/console error %d\n", error);
596 	} else
597 		vrele(nd.ni_vp);
598 }
599 
600 /*
601  * Start the initial user process; try exec'ing each pathname in "initpaths".
602  * The program is invoked with one argument containing the boot flags.
603  */
604 void
605 start_init(void *arg)
606 {
607 	struct proc *p = arg;
608 	vaddr_t addr;
609 	struct sys_execve_args /* {
610 		syscallarg(const char *) path;
611 		syscallarg(char *const *) argp;
612 		syscallarg(char *const *) envp;
613 	} */ args;
614 	int options, error;
615 	long i;
616 	register_t retval[2];
617 	char flags[4], *flagsp;
618 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
619 
620 	/*
621 	 * Now in process 1.
622 	 */
623 
624 	/*
625 	 * Wait for main() to tell us that it's safe to exec.
626 	 */
627 	while (start_init_exec == 0)
628 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
629 
630 	check_console(p);
631 
632 	/* process 0 ignores SIGCHLD, but we can't */
633 	p->p_p->ps_sigacts->ps_flags = 0;
634 
635 	/*
636 	 * Need just enough stack to hold the faked-up "execve()" arguments.
637 	 */
638 #ifdef MACHINE_STACK_GROWS_UP
639 	addr = USRSTACK;
640 #else
641 	addr = USRSTACK - PAGE_SIZE;
642 #endif
643 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
644 	p->p_vmspace->vm_minsaddr = (caddr_t)(addr + PAGE_SIZE);
645 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
646 	    NULL, UVM_UNKNOWN_OFFSET, 0,
647 	    UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_MASK, MAP_INHERIT_COPY,
648 	    MADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
649 		panic("init: couldn't allocate argument space");
650 
651 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
652 #ifdef MACHINE_STACK_GROWS_UP
653 		ucp = (char *)addr;
654 #else
655 		ucp = (char *)(addr + PAGE_SIZE);
656 #endif
657 		/*
658 		 * Construct the boot flag argument.
659 		 */
660 		flagsp = flags;
661 		*flagsp++ = '-';
662 		options = 0;
663 
664 		if (boothowto & RB_SINGLE) {
665 			*flagsp++ = 's';
666 			options = 1;
667 		}
668 #ifdef notyet
669 		if (boothowto & RB_FASTBOOT) {
670 			*flagsp++ = 'f';
671 			options = 1;
672 		}
673 #endif
674 
675 		/*
676 		 * Move out the flags (arg 1), if necessary.
677 		 */
678 		if (options != 0) {
679 			*flagsp++ = '\0';
680 			i = flagsp - flags;
681 #ifdef DEBUG
682 			printf("init: copying out flags `%s' %ld\n", flags, i);
683 #endif
684 #ifdef MACHINE_STACK_GROWS_UP
685 			arg1 = ucp;
686 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
687 			ucp += i;
688 #else
689 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
690 			arg1 = ucp;
691 #endif
692 		}
693 
694 		/*
695 		 * Move out the file name (also arg 0).
696 		 */
697 		i = strlen(path) + 1;
698 #ifdef DEBUG
699 		printf("init: copying out path `%s' %ld\n", path, i);
700 #endif
701 #ifdef MACHINE_STACK_GROWS_UP
702 		arg0 = ucp;
703 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
704 		ucp += i;
705 		ucp = (caddr_t)ALIGN((u_long)ucp);
706 		uap = (char **)ucp + 3;
707 #else
708 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
709 		arg0 = ucp;
710 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
711 #endif
712 
713 		/*
714 		 * Move out the arg pointers.
715 		 */
716 		i = 0;
717 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
718 		if (options != 0)
719 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
720 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
721 
722 		/*
723 		 * Point at the arguments.
724 		 */
725 		SCARG(&args, path) = arg0;
726 		SCARG(&args, argp) = uap;
727 		SCARG(&args, envp) = NULL;
728 
729 		/*
730 		 * Now try to exec the program.  If can't for any reason
731 		 * other than it doesn't exist, complain.
732 		 */
733 		if ((error = sys_execve(p, &args, retval)) == 0) {
734 			KERNEL_UNLOCK();
735 			return;
736 		}
737 		if (error != ENOENT)
738 			printf("exec %s: error %d\n", path, error);
739 	}
740 	printf("init: not found\n");
741 	panic("no init");
742 }
743 
744 void
745 start_update(void *arg)
746 {
747 	sched_sync(curproc);
748 	/* NOTREACHED */
749 }
750 
751 void
752 start_cleaner(void *arg)
753 {
754 	buf_daemon(curproc);
755 	/* NOTREACHED */
756 }
757 
758 void
759 start_reaper(void *arg)
760 {
761 	reaper();
762 	/* NOTREACHED */
763 }
764