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