xref: /openbsd-src/sys/kern/init_main.c (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*	$OpenBSD: init_main.c,v 1.304 2021/01/01 07:00:33 jsg 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 <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(KUBSAN)
98 extern void kubsan_init(void);
99 #endif
100 
101 #if defined(NFSSERVER) || defined(NFSCLIENT)
102 extern void nfs_init(void);
103 #endif
104 
105 #include "stoeplitz.h"
106 #if NSTOEPLITZ > 0
107 extern void stoeplitz_init(void);
108 #endif
109 
110 #include "mpath.h"
111 #include "vscsi.h"
112 #include "softraid.h"
113 
114 const char	copyright[] =
115 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
116 "\tThe Regents of the University of California.  All rights reserved.\n"
117 "Copyright (c) 1995-2021 OpenBSD. All rights reserved.  https://www.OpenBSD.org\n";
118 
119 /* Components of the first process -- never freed. */
120 struct	session session0;
121 struct	pgrp pgrp0;
122 struct	proc proc0;
123 struct	process process0;
124 struct	plimit limit0;
125 struct	vmspace vmspace0;
126 struct	sigacts sigacts0;
127 struct	process *initprocess;
128 struct	proc *reaperproc;
129 
130 extern	struct user *proc0paddr;
131 
132 struct	vnode *rootvp, *swapdev_vp;
133 int	boothowto;
134 int	db_active = 0;
135 int	ncpus =  1;
136 int	ncpusfound = 1;			/* number of cpus we find */
137 volatile int start_init_exec;		/* semaphore for start_init() */
138 
139 #if !defined(NO_PROPOLICE)
140 long	__guard_local __attribute__((section(".openbsd.randomdata")));
141 #endif
142 
143 /* XXX return int so gcc -Werror won't complain */
144 int	main(void *);
145 void	check_console(struct proc *);
146 void	start_init(void *);
147 void	crypto_init(void);
148 void	db_ctf_init(void);
149 void	prof_init(void);
150 void	init_exec(void);
151 void	kqueue_init(void);
152 void	futex_init(void);
153 void	taskq_init(void);
154 void	timeout_proc_init(void);
155 void	pool_gc_pages(void *);
156 void	percpu_init(void);
157 
158 extern char sigcode[], esigcode[], sigcoderet[];
159 #ifdef SYSCALL_DEBUG
160 extern char *syscallnames[];
161 #endif
162 
163 struct emul emul_native = {
164 	"native",
165 	NULL,
166 	SYS_syscall,
167 	SYS_MAXSYSCALL,
168 	sysent,
169 #ifdef SYSCALL_DEBUG
170 	syscallnames,
171 #else
172 	NULL,
173 #endif
174 	0,
175 	copyargs,
176 	setregs,
177 	NULL,		/* fixup */
178 	NULL,		/* coredump */
179 	sigcode,
180 	esigcode,
181 	sigcoderet
182 };
183 
184 #ifdef DIAGNOSTIC
185 int pdevinit_done = 0;
186 #endif
187 
188 /*
189  * System startup; initialize the world, create process 0, mount root
190  * filesystem, and fork to create init and pagedaemon.  Most of the
191  * hard work is done in the lower-level initialization routines including
192  * startup(), which does memory initialization and autoconfiguration.
193  */
194 /* XXX return int, so gcc -Werror won't complain */
195 int
196 main(void *framep)
197 {
198 	struct proc *p;
199 	struct process *pr;
200 	struct pdevinit *pdev;
201 	extern struct pdevinit pdevinit[];
202 	extern void disk_init(void);
203 
204 	/*
205 	 * Initialize the current process pointer (curproc) before
206 	 * any possible traps/probes to simplify trap processing.
207 	 */
208 	curproc = p = &proc0;
209 	p->p_cpu = curcpu();
210 
211 	/*
212 	 * Initialize timeouts.
213 	 */
214 	timeout_startup();
215 
216 	/*
217 	 * Attempt to find console and initialize
218 	 * in case of early panic or other messages.
219 	 */
220 	config_init();		/* init autoconfiguration data structures */
221 	consinit();
222 
223 	printf("%s\n", copyright);
224 
225 #ifdef KUBSAN
226 	/* Initialize kubsan. */
227 	kubsan_init();
228 #endif
229 
230 	WITNESS_INITIALIZE();
231 
232 	KERNEL_LOCK_INIT();
233 	SCHED_LOCK_INIT();
234 
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 	mbcpuinit();	/* enable per cpu mbuf data */
435 	uvm_init_percpu();
436 
437 	/* init exec and emul */
438 	init_exec();
439 
440 	/* Start the scheduler */
441 	scheduler_start();
442 
443 	/*
444 	 * Create process 1 (init(8)).  We do this now, as Unix has
445 	 * historically had init be process 1, and changing this would
446 	 * probably upset a lot of people.
447 	 *
448 	 * Note that process 1 won't immediately exec init(8), but will
449 	 * wait for us to inform it that the root file system has been
450 	 * mounted.
451 	 */
452 	{
453 		struct proc *initproc;
454 
455 		if (fork1(p, FORK_FORK, start_init, NULL, NULL, &initproc))
456 			panic("fork init");
457 		initprocess = initproc->p_p;
458 	}
459 
460 	randompid = 1;
461 
462 	/*
463 	 * Create any kernel threads whose creation was deferred because
464 	 * initprocess had not yet been created.
465 	 */
466 	kthread_run_deferred_queue();
467 
468 	/*
469 	 * Now that device driver threads have been created, wait for
470 	 * them to finish any deferred autoconfiguration.  Note we don't
471 	 * need to lock this semaphore, since we haven't booted any
472 	 * secondary processors, yet.
473 	 */
474 	while (config_pending)
475 		tsleep_nsec(&config_pending, PWAIT, "cfpend", INFSLP);
476 
477 	dostartuphooks();
478 
479 #if NVSCSI > 0
480 	config_rootfound("vscsi", NULL);
481 #endif
482 #if NSOFTRAID > 0
483 	config_rootfound("softraid", NULL);
484 #endif
485 
486 	/* Configure root/swap devices */
487 	diskconf();
488 
489 #ifdef DDB
490 	/* Make debug symbols available in ddb. */
491 	db_ctf_init();
492 #endif
493 
494 	if (mountroot == NULL || ((*mountroot)() != 0))
495 		panic("cannot mount root");
496 
497 	TAILQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
498 
499 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
500 	if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
501 		panic("cannot find root vnode");
502 	p->p_fd->fd_cdir = rootvnode;
503 	vref(p->p_fd->fd_cdir);
504 	VOP_UNLOCK(rootvnode);
505 	p->p_fd->fd_rdir = NULL;
506 
507 	/*
508 	 * Now that root is mounted, we can fixup initprocess's CWD
509 	 * info.  All other processes are kthreads, which merely
510 	 * share proc0's CWD info.
511 	 */
512 	initprocess->ps_fd->fd_cdir = rootvnode;
513 	vref(initprocess->ps_fd->fd_cdir);
514 	initprocess->ps_fd->fd_rdir = NULL;
515 
516 	/*
517 	 * Now can look at time, having had a chance to verify the time
518 	 * from the file system.  Reset p->p_rtime as it may have been
519 	 * munched in mi_switch() after the time got set.
520 	 */
521 	LIST_FOREACH(pr, &allprocess, ps_list) {
522 		nanouptime(&pr->ps_start);
523 		SMR_TAILQ_FOREACH_LOCKED(p, &pr->ps_threads, p_thr_link) {
524 			nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
525 			timespecclear(&p->p_rtime);
526 		}
527 	}
528 
529 	uvm_swap_init();
530 
531 	/* Create the pageout daemon kernel thread. */
532 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
533 		panic("fork pagedaemon");
534 
535 	/* Create the reaper daemon kernel thread. */
536 	if (kthread_create(reaper, NULL, &reaperproc, "reaper"))
537 		panic("fork reaper");
538 
539 	/* Create the cleaner daemon kernel thread. */
540 	if (kthread_create(buf_daemon, NULL, &cleanerproc, "cleaner"))
541 		panic("fork cleaner");
542 
543 	/* Create the update daemon kernel thread. */
544 	if (kthread_create(syncer_thread, NULL, &syncerproc, "update"))
545 		panic("fork update");
546 
547 	/* Create the aiodone daemon kernel thread. */
548 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
549 		panic("fork aiodoned");
550 
551 #if !defined(__hppa__)
552 	/* Create the page zeroing kernel thread. */
553 	if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread"))
554 		panic("fork zerothread");
555 #endif
556 
557 #if defined(MULTIPROCESSOR)
558 	/* Boot the secondary processors. */
559 	cpu_boot_secondary_processors();
560 #endif
561 
562 	/* Now that all CPUs partake in scheduling, start SMR thread. */
563 	smr_startup_thread();
564 
565 	config_process_deferred_mountroot();
566 
567 	/*
568 	 * Okay, now we can let init(8) exec!  It's off to userland!
569 	 */
570 	start_init_exec = 1;
571 	wakeup((void *)&start_init_exec);
572 
573 	/*
574 	 * Start the idle pool page garbage collector
575 	 */
576 #if !(defined(__m88k__) && defined(MULTIPROCESSOR))	/* XXX */
577 	pool_gc_pages(NULL);
578 #endif
579 
580 	start_periodic_resettodr();
581 
582         /*
583          * proc0: nothing to do, back to sleep
584          */
585         while (1)
586                 tsleep_nsec(&proc0, PVM, "scheduler", INFSLP);
587 	/* NOTREACHED */
588 }
589 
590 /*
591  * List of paths to try when searching for "init".
592  */
593 static char *initpaths[] = {
594 	"/sbin/init",
595 	"/sbin/oinit",
596 	"/sbin/init.bak",
597 	NULL,
598 };
599 
600 void
601 check_console(struct proc *p)
602 {
603 	struct nameidata nd;
604 	int error;
605 
606 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
607 	error = namei(&nd);
608 	if (error) {
609 		if (error == ENOENT)
610 			printf("warning: /dev/console does not exist\n");
611 		else
612 			printf("warning: /dev/console error %d\n", error);
613 	} else
614 		vrele(nd.ni_vp);
615 }
616 
617 /*
618  * Start the initial user process; try exec'ing each pathname in "initpaths".
619  * The program is invoked with one argument containing the boot flags.
620  */
621 void
622 start_init(void *arg)
623 {
624 	struct proc *p = arg;
625 	vaddr_t addr;
626 	struct sys_execve_args /* {
627 		syscallarg(const char *) path;
628 		syscallarg(char *const *) argp;
629 		syscallarg(char *const *) envp;
630 	} */ args;
631 	int options, error;
632 	long i;
633 	register_t retval[2];
634 	char flags[4], *flagsp;
635 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
636 
637 	/*
638 	 * Now in process 1.
639 	 */
640 
641 	/*
642 	 * Wait for main() to tell us that it's safe to exec.
643 	 */
644 	while (start_init_exec == 0)
645 		tsleep_nsec(&start_init_exec, PWAIT, "initexec", INFSLP);
646 
647 	check_console(p);
648 
649 	/* process 0 ignores SIGCHLD, but we can't */
650 	p->p_p->ps_sigacts->ps_sigflags = 0;
651 
652 	/*
653 	 * Need just enough stack to hold the faked-up "execve()" arguments.
654 	 */
655 #ifdef MACHINE_STACK_GROWS_UP
656 	addr = USRSTACK;
657 #else
658 	addr = USRSTACK - PAGE_SIZE;
659 #endif
660 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
661 	p->p_vmspace->vm_minsaddr = (caddr_t)(addr + PAGE_SIZE);
662 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
663 	    NULL, UVM_UNKNOWN_OFFSET, 0,
664 	    UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_MASK, MAP_INHERIT_COPY,
665 	    MADV_NORMAL,
666 	    UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW|UVM_FLAG_STACK|UVM_FLAG_SYSCALL)))
667 		panic("init: couldn't allocate argument space");
668 
669 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
670 #ifdef MACHINE_STACK_GROWS_UP
671 		ucp = (char *)addr;
672 #else
673 		ucp = (char *)(addr + PAGE_SIZE);
674 #endif
675 		/*
676 		 * Construct the boot flag argument.
677 		 */
678 		flagsp = flags;
679 		*flagsp++ = '-';
680 		options = 0;
681 
682 		if (boothowto & RB_SINGLE) {
683 			*flagsp++ = 's';
684 			options = 1;
685 		}
686 #ifdef notyet
687 		if (boothowto & RB_FASTBOOT) {
688 			*flagsp++ = 'f';
689 			options = 1;
690 		}
691 #endif
692 
693 		/*
694 		 * Move out the flags (arg 1), if necessary.
695 		 */
696 		if (options != 0) {
697 			*flagsp++ = '\0';
698 			i = flagsp - flags;
699 #ifdef DEBUG
700 			printf("init: copying out flags `%s' %ld\n", flags, i);
701 #endif
702 #ifdef MACHINE_STACK_GROWS_UP
703 			arg1 = ucp;
704 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
705 			ucp += i;
706 #else
707 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
708 			arg1 = ucp;
709 #endif
710 		}
711 
712 		/*
713 		 * Move out the file name (also arg 0).
714 		 */
715 		i = strlen(path) + 1;
716 #ifdef DEBUG
717 		printf("init: copying out path `%s' %ld\n", path, i);
718 #endif
719 #ifdef MACHINE_STACK_GROWS_UP
720 		arg0 = ucp;
721 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
722 		ucp += i;
723 		ucp = (caddr_t)ALIGN((u_long)ucp);
724 		uap = (char **)ucp + 3;
725 #else
726 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
727 		arg0 = ucp;
728 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
729 #endif
730 
731 		/*
732 		 * Move out the arg pointers.
733 		 */
734 		i = 0;
735 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
736 		if (options != 0)
737 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
738 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
739 
740 		/*
741 		 * Point at the arguments.
742 		 */
743 		SCARG(&args, path) = arg0;
744 		SCARG(&args, argp) = uap;
745 		SCARG(&args, envp) = NULL;
746 
747 		/*
748 		 * Now try to exec the program.  If can't for any reason
749 		 * other than it doesn't exist, complain.
750 		 */
751 		if ((error = sys_execve(p, &args, retval)) == 0) {
752 			KERNEL_UNLOCK();
753 			return;
754 		}
755 		if (error != ENOENT)
756 			printf("exec %s: error %d\n", path, error);
757 	}
758 	printf("init: not found\n");
759 	panic("no init");
760 }
761