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