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