xref: /openbsd-src/sys/kern/init_main.c (revision 1a8dbaac879b9f3335ad7fb25429ce63ac1d6bac)
1 /*	$OpenBSD: init_main.c,v 1.301 2020/09/13 09:42:31 claudio 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-2020 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 
436 	/* init exec and emul */
437 	init_exec();
438 
439 	/* Start the scheduler */
440 	scheduler_start();
441 
442 	/*
443 	 * Create process 1 (init(8)).  We do this now, as Unix has
444 	 * historically had init be process 1, and changing this would
445 	 * probably upset a lot of people.
446 	 *
447 	 * Note that process 1 won't immediately exec init(8), but will
448 	 * wait for us to inform it that the root file system has been
449 	 * mounted.
450 	 */
451 	{
452 		struct proc *initproc;
453 
454 		if (fork1(p, FORK_FORK, start_init, NULL, NULL, &initproc))
455 			panic("fork init");
456 		initprocess = initproc->p_p;
457 	}
458 
459 	randompid = 1;
460 
461 	/*
462 	 * Create any kernel threads whose creation was deferred because
463 	 * initprocess had not yet been created.
464 	 */
465 	kthread_run_deferred_queue();
466 
467 	/*
468 	 * Now that device driver threads have been created, wait for
469 	 * them to finish any deferred autoconfiguration.  Note we don't
470 	 * need to lock this semaphore, since we haven't booted any
471 	 * secondary processors, yet.
472 	 */
473 	while (config_pending)
474 		tsleep_nsec(&config_pending, PWAIT, "cfpend", INFSLP);
475 
476 	dostartuphooks();
477 
478 #if NVSCSI > 0
479 	config_rootfound("vscsi", NULL);
480 #endif
481 #if NSOFTRAID > 0
482 	config_rootfound("softraid", NULL);
483 #endif
484 
485 	/* Configure root/swap devices */
486 	diskconf();
487 
488 #ifdef DDB
489 	/* Make debug symbols available in ddb. */
490 	db_ctf_init();
491 #endif
492 
493 	if (mountroot == NULL || ((*mountroot)() != 0))
494 		panic("cannot mount root");
495 
496 	TAILQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
497 
498 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
499 	if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
500 		panic("cannot find root vnode");
501 	p->p_fd->fd_cdir = rootvnode;
502 	vref(p->p_fd->fd_cdir);
503 	VOP_UNLOCK(rootvnode);
504 	p->p_fd->fd_rdir = NULL;
505 
506 	/*
507 	 * Now that root is mounted, we can fixup initprocess's CWD
508 	 * info.  All other processes are kthreads, which merely
509 	 * share proc0's CWD info.
510 	 */
511 	initprocess->ps_fd->fd_cdir = rootvnode;
512 	vref(initprocess->ps_fd->fd_cdir);
513 	initprocess->ps_fd->fd_rdir = NULL;
514 
515 	/*
516 	 * Now can look at time, having had a chance to verify the time
517 	 * from the file system.  Reset p->p_rtime as it may have been
518 	 * munched in mi_switch() after the time got set.
519 	 */
520 	LIST_FOREACH(pr, &allprocess, ps_list) {
521 		nanouptime(&pr->ps_start);
522 		TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
523 			nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
524 			timespecclear(&p->p_rtime);
525 		}
526 	}
527 
528 	uvm_swap_init();
529 
530 	/* Create the pageout daemon kernel thread. */
531 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
532 		panic("fork pagedaemon");
533 
534 	/* Create the reaper daemon kernel thread. */
535 	if (kthread_create(reaper, NULL, &reaperproc, "reaper"))
536 		panic("fork reaper");
537 
538 	/* Create the cleaner daemon kernel thread. */
539 	if (kthread_create(buf_daemon, NULL, &cleanerproc, "cleaner"))
540 		panic("fork cleaner");
541 
542 	/* Create the update daemon kernel thread. */
543 	if (kthread_create(syncer_thread, NULL, &syncerproc, "update"))
544 		panic("fork update");
545 
546 	/* Create the aiodone daemon kernel thread. */
547 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
548 		panic("fork aiodoned");
549 
550 #if !defined(__hppa__)
551 	/* Create the page zeroing kernel thread. */
552 	if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread"))
553 		panic("fork zerothread");
554 #endif
555 
556 #if defined(MULTIPROCESSOR)
557 	/* Boot the secondary processors. */
558 	cpu_boot_secondary_processors();
559 #endif
560 
561 	/* Now that all CPUs partake in scheduling, start SMR thread. */
562 	smr_startup_thread();
563 
564 	config_process_deferred_mountroot();
565 
566 	/*
567 	 * Okay, now we can let init(8) exec!  It's off to userland!
568 	 */
569 	start_init_exec = 1;
570 	wakeup((void *)&start_init_exec);
571 
572 	/*
573 	 * Start the idle pool page garbage collector
574 	 */
575 #if !(defined(__m88k__) && defined(MULTIPROCESSOR))	/* XXX */
576 	pool_gc_pages(NULL);
577 #endif
578 
579 	start_periodic_resettodr();
580 
581         /*
582          * proc0: nothing to do, back to sleep
583          */
584         while (1)
585                 tsleep_nsec(&proc0, PVM, "scheduler", INFSLP);
586 	/* NOTREACHED */
587 }
588 
589 /*
590  * List of paths to try when searching for "init".
591  */
592 static char *initpaths[] = {
593 	"/sbin/init",
594 	"/sbin/oinit",
595 	"/sbin/init.bak",
596 	NULL,
597 };
598 
599 void
600 check_console(struct proc *p)
601 {
602 	struct nameidata nd;
603 	int error;
604 
605 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
606 	error = namei(&nd);
607 	if (error) {
608 		if (error == ENOENT)
609 			printf("warning: /dev/console does not exist\n");
610 		else
611 			printf("warning: /dev/console error %d\n", error);
612 	} else
613 		vrele(nd.ni_vp);
614 }
615 
616 /*
617  * Start the initial user process; try exec'ing each pathname in "initpaths".
618  * The program is invoked with one argument containing the boot flags.
619  */
620 void
621 start_init(void *arg)
622 {
623 	struct proc *p = arg;
624 	vaddr_t addr;
625 	struct sys_execve_args /* {
626 		syscallarg(const char *) path;
627 		syscallarg(char *const *) argp;
628 		syscallarg(char *const *) envp;
629 	} */ args;
630 	int options, error;
631 	long i;
632 	register_t retval[2];
633 	char flags[4], *flagsp;
634 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
635 
636 	/*
637 	 * Now in process 1.
638 	 */
639 
640 	/*
641 	 * Wait for main() to tell us that it's safe to exec.
642 	 */
643 	while (start_init_exec == 0)
644 		tsleep_nsec(&start_init_exec, PWAIT, "initexec", INFSLP);
645 
646 	check_console(p);
647 
648 	/* process 0 ignores SIGCHLD, but we can't */
649 	p->p_p->ps_sigacts->ps_sigflags = 0;
650 
651 	/*
652 	 * Need just enough stack to hold the faked-up "execve()" arguments.
653 	 */
654 #ifdef MACHINE_STACK_GROWS_UP
655 	addr = USRSTACK;
656 #else
657 	addr = USRSTACK - PAGE_SIZE;
658 #endif
659 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
660 	p->p_vmspace->vm_minsaddr = (caddr_t)(addr + PAGE_SIZE);
661 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
662 	    NULL, UVM_UNKNOWN_OFFSET, 0,
663 	    UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_MASK, MAP_INHERIT_COPY,
664 	    MADV_NORMAL,
665 	    UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW|UVM_FLAG_STACK|UVM_FLAG_SYSCALL)))
666 		panic("init: couldn't allocate argument space");
667 
668 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
669 #ifdef MACHINE_STACK_GROWS_UP
670 		ucp = (char *)addr;
671 #else
672 		ucp = (char *)(addr + PAGE_SIZE);
673 #endif
674 		/*
675 		 * Construct the boot flag argument.
676 		 */
677 		flagsp = flags;
678 		*flagsp++ = '-';
679 		options = 0;
680 
681 		if (boothowto & RB_SINGLE) {
682 			*flagsp++ = 's';
683 			options = 1;
684 		}
685 #ifdef notyet
686 		if (boothowto & RB_FASTBOOT) {
687 			*flagsp++ = 'f';
688 			options = 1;
689 		}
690 #endif
691 
692 		/*
693 		 * Move out the flags (arg 1), if necessary.
694 		 */
695 		if (options != 0) {
696 			*flagsp++ = '\0';
697 			i = flagsp - flags;
698 #ifdef DEBUG
699 			printf("init: copying out flags `%s' %ld\n", flags, i);
700 #endif
701 #ifdef MACHINE_STACK_GROWS_UP
702 			arg1 = ucp;
703 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
704 			ucp += i;
705 #else
706 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
707 			arg1 = ucp;
708 #endif
709 		}
710 
711 		/*
712 		 * Move out the file name (also arg 0).
713 		 */
714 		i = strlen(path) + 1;
715 #ifdef DEBUG
716 		printf("init: copying out path `%s' %ld\n", path, i);
717 #endif
718 #ifdef MACHINE_STACK_GROWS_UP
719 		arg0 = ucp;
720 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
721 		ucp += i;
722 		ucp = (caddr_t)ALIGN((u_long)ucp);
723 		uap = (char **)ucp + 3;
724 #else
725 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
726 		arg0 = ucp;
727 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
728 #endif
729 
730 		/*
731 		 * Move out the arg pointers.
732 		 */
733 		i = 0;
734 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
735 		if (options != 0)
736 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
737 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
738 
739 		/*
740 		 * Point at the arguments.
741 		 */
742 		SCARG(&args, path) = arg0;
743 		SCARG(&args, argp) = uap;
744 		SCARG(&args, envp) = NULL;
745 
746 		/*
747 		 * Now try to exec the program.  If can't for any reason
748 		 * other than it doesn't exist, complain.
749 		 */
750 		if ((error = sys_execve(p, &args, retval)) == 0) {
751 			KERNEL_UNLOCK();
752 			return;
753 		}
754 		if (error != ENOENT)
755 			printf("exec %s: error %d\n", path, error);
756 	}
757 	printf("init: not found\n");
758 	panic("no init");
759 }
760