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