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