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