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