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