init_main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /* $OpenBSD: init_main.c,v 1.243 2015/07/09 19:45:37 miod Exp $ */
  2. /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
  3. /*
  4. * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
  5. * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
  6. * The Regents of the University of California. All rights reserved.
  7. * (c) UNIX System Laboratories, Inc.
  8. * All or some portions of this file are derived from material licensed
  9. * to the University of California by American Telephone and Telegraph
  10. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  11. * the permission of UNIX System Laboratories, Inc.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * @(#)init_main.c 8.9 (Berkeley) 1/21/94
  38. */
  39. #include <sys/param.h>
  40. #include <sys/filedesc.h>
  41. #include <sys/file.h>
  42. #include <sys/errno.h>
  43. #include <sys/exec.h>
  44. #include <sys/kernel.h>
  45. #include <sys/kthread.h>
  46. #include <sys/mount.h>
  47. #include <sys/proc.h>
  48. #include <sys/resourcevar.h>
  49. #include <sys/signalvar.h>
  50. #include <sys/systm.h>
  51. #include <sys/namei.h>
  52. #include <sys/vnode.h>
  53. #include <sys/tty.h>
  54. #include <sys/conf.h>
  55. #include <sys/buf.h>
  56. #include <sys/device.h>
  57. #include <sys/socketvar.h>
  58. #include <sys/lockf.h>
  59. #include <sys/protosw.h>
  60. #include <sys/reboot.h>
  61. #include <sys/user.h>
  62. #ifdef SYSVSHM
  63. #include <sys/shm.h>
  64. #endif
  65. #ifdef SYSVSEM
  66. #include <sys/sem.h>
  67. #endif
  68. #ifdef SYSVMSG
  69. #include <sys/msg.h>
  70. #endif
  71. #include <sys/domain.h>
  72. #include <sys/msgbuf.h>
  73. #include <sys/mbuf.h>
  74. #include <sys/pipe.h>
  75. #include <sys/task.h>
  76. #include <sys/syscall.h>
  77. #include <sys/syscallargs.h>
  78. #include <uvm/uvm_extern.h>
  79. #include <dev/rndvar.h>
  80. #include <ufs/ufs/quota.h>
  81. #include <net/if.h>
  82. #include <net/netisr.h>
  83. #if defined(CRYPTO)
  84. #include <crypto/cryptodev.h>
  85. #include <crypto/cryptosoft.h>
  86. #endif
  87. #if defined(NFSSERVER) || defined(NFSCLIENT)
  88. extern void nfs_init(void);
  89. #endif
  90. #include "mpath.h"
  91. #include "vscsi.h"
  92. #include "softraid.h"
  93. const char copyright[] =
  94. "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
  95. "\tThe Regents of the University of California. All rights reserved.\n"
  96. "Copyright (c) 1995-2015 OpenBSD. All rights reserved. http://www.OpenBSD.org\n";
  97. /* Components of the first process -- never freed. */
  98. struct session session0;
  99. struct pgrp pgrp0;
  100. struct proc proc0;
  101. struct process process0;
  102. struct plimit limit0;
  103. struct vmspace vmspace0;
  104. struct sigacts sigacts0;
  105. struct process *initprocess;
  106. struct proc *reaperproc;
  107. #ifndef SMALL_KERNEL
  108. extern struct timeout setperf_to;
  109. void setperf_auto(void *);
  110. #endif
  111. extern struct user *proc0paddr;
  112. struct vnode *rootvp, *swapdev_vp;
  113. int boothowto;
  114. struct timespec boottime;
  115. int ncpus = 1;
  116. int ncpusfound = 1; /* number of cpus we find */
  117. volatile int start_init_exec; /* semaphore for start_init() */
  118. #if !defined(NO_PROPOLICE)
  119. long __guard_local __attribute__((section(".openbsd.randomdata")));
  120. #endif
  121. /* XXX return int so gcc -Werror won't complain */
  122. int main(void *);
  123. void check_console(struct proc *);
  124. void start_init(void *);
  125. void start_cleaner(void *);
  126. void start_update(void *);
  127. void start_reaper(void *);
  128. void crypto_init(void);
  129. void init_exec(void);
  130. void kqueue_init(void);
  131. void taskq_init(void);
  132. void pool_gc_pages(void *);
  133. extern char sigcode[], esigcode[];
  134. #ifdef SYSCALL_DEBUG
  135. extern char *syscallnames[];
  136. #endif
  137. struct emul emul_native = {
  138. "native",
  139. NULL,
  140. sendsig,
  141. SYS_syscall,
  142. SYS_MAXSYSCALL,
  143. sysent,
  144. #ifdef SYSCALL_DEBUG
  145. syscallnames,
  146. #else
  147. NULL,
  148. #endif
  149. 0,
  150. copyargs,
  151. setregs,
  152. NULL, /* fixup */
  153. NULL, /* coredump */
  154. sigcode,
  155. esigcode,
  156. EMUL_ENABLED | EMUL_NATIVE,
  157. };
  158. /*
  159. * System startup; initialize the world, create process 0, mount root
  160. * filesystem, and fork to create init and pagedaemon. Most of the
  161. * hard work is done in the lower-level initialization routines including
  162. * startup(), which does memory initialization and autoconfiguration.
  163. */
  164. /* XXX return int, so gcc -Werror won't complain */
  165. int
  166. main(void *framep)
  167. {
  168. struct proc *p;
  169. struct process *pr;
  170. struct pdevinit *pdev;
  171. quad_t lim;
  172. int s, i;
  173. extern struct pdevinit pdevinit[];
  174. extern void disk_init(void);
  175. /*
  176. * Initialize the current process pointer (curproc) before
  177. * any possible traps/probes to simplify trap processing.
  178. */
  179. curproc = p = &proc0;
  180. p->p_cpu = curcpu();
  181. /*
  182. * Initialize timeouts.
  183. */
  184. timeout_startup();
  185. /*
  186. * Attempt to find console and initialize
  187. * in case of early panic or other messages.
  188. */
  189. config_init(); /* init autoconfiguration data structures */
  190. consinit();
  191. printf("%s\n", copyright);
  192. KERNEL_LOCK_INIT();
  193. SCHED_LOCK_INIT();
  194. uvm_init();
  195. disk_init(); /* must come before autoconfiguration */
  196. tty_init(); /* initialise tty's */
  197. cpu_startup();
  198. random_start(); /* Start the flow */
  199. /*
  200. * Initialize mbuf's. Do this now because we might attempt to
  201. * allocate mbufs or mbuf clusters during autoconfiguration.
  202. */
  203. mbinit();
  204. /* Initialize sockets. */
  205. soinit();
  206. /* Initialize SRP subsystem. */
  207. srp_startup();
  208. /*
  209. * Initialize process and pgrp structures.
  210. */
  211. procinit();
  212. /* Initialize file locking. */
  213. lf_init();
  214. /*
  215. * Initialize filedescriptors.
  216. */
  217. filedesc_init();
  218. /*
  219. * Initialize pipes.
  220. */
  221. pipe_init();
  222. /*
  223. * Initialize kqueues.
  224. */
  225. kqueue_init();
  226. /* Create credentials. */
  227. p->p_ucred = crget();
  228. p->p_ucred->cr_ngroups = 1; /* group 0 */
  229. /*
  230. * Create process 0 (the swapper).
  231. */
  232. pr = &process0;
  233. process_initialize(pr, p);
  234. LIST_INSERT_HEAD(&allprocess, pr, ps_list);
  235. atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
  236. /* Set the default routing table/domain. */
  237. process0.ps_rtableid = 0;
  238. LIST_INSERT_HEAD(&allproc, p, p_list);
  239. pr->ps_pgrp = &pgrp0;
  240. LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
  241. LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
  242. LIST_INIT(&pgrp0.pg_members);
  243. LIST_INSERT_HEAD(&pgrp0.pg_members, pr, ps_pglist);
  244. pgrp0.pg_session = &session0;
  245. session0.s_count = 1;
  246. session0.s_leader = pr;
  247. atomic_setbits_int(&p->p_flag, P_SYSTEM);
  248. p->p_stat = SONPROC;
  249. pr->ps_nice = NZERO;
  250. pr->ps_emul = &emul_native;
  251. strlcpy(p->p_comm, "swapper", sizeof(p->p_comm));
  252. /* Init timeouts. */
  253. timeout_set(&p->p_sleep_to, endtsleep, p);
  254. /* Initialize signal state for process 0. */
  255. signal_init();
  256. pr->ps_sigacts = &sigacts0;
  257. siginit(pr);
  258. /* Create the file descriptor table. */
  259. p->p_fd = pr->ps_fd = fdinit();
  260. /* Create the limits structures. */
  261. pr->ps_limit = &limit0;
  262. for (i = 0; i < nitems(p->p_rlimit); i++)
  263. limit0.pl_rlimit[i].rlim_cur =
  264. limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
  265. limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
  266. limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
  267. (maxfiles - NOFILE > NOFILE) ? maxfiles - NOFILE : NOFILE);
  268. limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
  269. lim = ptoa(uvmexp.free);
  270. limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
  271. limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
  272. limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
  273. limit0.p_refcnt = 1;
  274. /* Allocate a prototype map so we have something to fork. */
  275. uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
  276. trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
  277. p->p_vmspace = pr->ps_vmspace = &vmspace0;
  278. p->p_addr = proc0paddr; /* XXX */
  279. /*
  280. * Charge root for one process.
  281. */
  282. (void)chgproccnt(0, 1);
  283. /* Initialize run queues */
  284. sched_init_runqueues();
  285. sleep_queue_init();
  286. sched_init_cpu(curcpu());
  287. p->p_cpu->ci_randseed = (arc4random() & 0x7fffffff) + 1;
  288. /* Initialize task queues */
  289. taskq_init();
  290. /* Initialize the interface/address trees */
  291. ifinit();
  292. /* Lock the kernel on behalf of proc0. */
  293. KERNEL_LOCK();
  294. #if NMPATH > 0
  295. /* Attach mpath before hardware */
  296. config_rootfound("mpath", NULL);
  297. #endif
  298. /* Configure the devices */
  299. cpu_configure();
  300. /* Configure virtual memory system, set vm rlimits. */
  301. uvm_init_limits(p);
  302. /* Initialize the file systems. */
  303. #if defined(NFSSERVER) || defined(NFSCLIENT)
  304. nfs_init(); /* initialize server/shared data */
  305. #endif
  306. vfsinit();
  307. /* Start real time and statistics clocks. */
  308. initclocks();
  309. #ifdef SYSVSHM
  310. /* Initialize System V style shared memory. */
  311. shminit();
  312. #endif
  313. #ifdef SYSVSEM
  314. /* Initialize System V style semaphores. */
  315. seminit();
  316. #endif
  317. #ifdef SYSVMSG
  318. /* Initialize System V style message queues. */
  319. msginit();
  320. #endif
  321. /* Attach pseudo-devices. */
  322. for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
  323. if (pdev->pdev_count > 0)
  324. (*pdev->pdev_attach)(pdev->pdev_count);
  325. #ifdef CRYPTO
  326. crypto_init();
  327. swcr_init();
  328. #endif /* CRYPTO */
  329. /*
  330. * Initialize protocols. Block reception of incoming packets
  331. * until everything is ready.
  332. */
  333. s = splnet();
  334. netisr_init();
  335. domaininit();
  336. if_attachdomain();
  337. splx(s);
  338. initconsbuf();
  339. #ifdef GPROF
  340. /* Initialize kernel profiling. */
  341. kmstartup();
  342. #endif
  343. #if !defined(NO_PROPOLICE)
  344. if (__guard_local == 0) {
  345. volatile long newguard;
  346. arc4random_buf((void *)&newguard, sizeof newguard);
  347. __guard_local = newguard;
  348. }
  349. #endif
  350. /* init exec and emul */
  351. init_exec();
  352. /* Start the scheduler */
  353. scheduler_start();
  354. /*
  355. * Create process 1 (init(8)). We do this now, as Unix has
  356. * historically had init be process 1, and changing this would
  357. * probably upset a lot of people.
  358. *
  359. * Note that process 1 won't immediately exec init(8), but will
  360. * wait for us to inform it that the root file system has been
  361. * mounted.
  362. */
  363. {
  364. struct proc *initproc;
  365. if (fork1(p, FORK_FORK, NULL, 0, start_init, NULL, NULL,
  366. &initproc))
  367. panic("fork init");
  368. initprocess = initproc->p_p;
  369. }
  370. randompid = 1;
  371. /*
  372. * Create any kernel threads whose creation was deferred because
  373. * initprocess had not yet been created.
  374. */
  375. kthread_run_deferred_queue();
  376. /*
  377. * Now that device driver threads have been created, wait for
  378. * them to finish any deferred autoconfiguration. Note we don't
  379. * need to lock this semaphore, since we haven't booted any
  380. * secondary processors, yet.
  381. */
  382. while (config_pending)
  383. (void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
  384. dostartuphooks();
  385. #if NVSCSI > 0
  386. config_rootfound("vscsi", NULL);
  387. #endif
  388. #if NSOFTRAID > 0
  389. config_rootfound("softraid", NULL);
  390. #endif
  391. /* Configure root/swap devices */
  392. diskconf();
  393. if (mountroot == NULL || ((*mountroot)() != 0))
  394. panic("cannot mount root");
  395. TAILQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
  396. /* Get the vnode for '/'. Set p->p_fd->fd_cdir to reference it. */
  397. if (VFS_ROOT(TAILQ_FIRST(&mountlist), &rootvnode))
  398. panic("cannot find root vnode");
  399. p->p_fd->fd_cdir = rootvnode;
  400. vref(p->p_fd->fd_cdir);
  401. VOP_UNLOCK(rootvnode, 0, p);
  402. p->p_fd->fd_rdir = NULL;
  403. /*
  404. * Now that root is mounted, we can fixup initprocess's CWD
  405. * info. All other processes are kthreads, which merely
  406. * share proc0's CWD info.
  407. */
  408. initprocess->ps_fd->fd_cdir = rootvnode;
  409. vref(initprocess->ps_fd->fd_cdir);
  410. initprocess->ps_fd->fd_rdir = NULL;
  411. /*
  412. * Now can look at time, having had a chance to verify the time
  413. * from the file system. Reset p->p_rtime as it may have been
  414. * munched in mi_switch() after the time got set.
  415. */
  416. nanotime(&boottime);
  417. LIST_FOREACH(pr, &allprocess, ps_list) {
  418. pr->ps_start = boottime;
  419. TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
  420. nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
  421. timespecclear(&p->p_rtime);
  422. }
  423. }
  424. uvm_swap_init();
  425. /* Create the pageout daemon kernel thread. */
  426. if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
  427. panic("fork pagedaemon");
  428. /* Create the reaper daemon kernel thread. */
  429. if (kthread_create(start_reaper, NULL, &reaperproc, "reaper"))
  430. panic("fork reaper");
  431. /* Create the cleaner daemon kernel thread. */
  432. if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
  433. panic("fork cleaner");
  434. /* Create the update daemon kernel thread. */
  435. if (kthread_create(start_update, NULL, NULL, "update"))
  436. panic("fork update");
  437. /* Create the aiodone daemon kernel thread. */
  438. if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
  439. panic("fork aiodoned");
  440. #if !defined(__hppa__)
  441. /* Create the page zeroing kernel thread. */
  442. if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread"))
  443. panic("fork zerothread");
  444. #endif
  445. #if defined(MULTIPROCESSOR)
  446. /* Boot the secondary processors. */
  447. cpu_boot_secondary_processors();
  448. #endif
  449. domountroothooks();
  450. /*
  451. * Okay, now we can let init(8) exec! It's off to userland!
  452. */
  453. start_init_exec = 1;
  454. wakeup((void *)&start_init_exec);
  455. #ifndef SMALL_KERNEL
  456. timeout_set(&setperf_to, setperf_auto, NULL);
  457. #endif
  458. /*
  459. * Start the idle pool page garbage collector
  460. */
  461. #if !(defined(__m88k__) && defined(MULTIPROCESSOR)) /* XXX */
  462. pool_gc_pages(NULL);
  463. #endif
  464. /*
  465. * proc0: nothing to do, back to sleep
  466. */
  467. while (1)
  468. tsleep(&proc0, PVM, "scheduler", 0);
  469. /* NOTREACHED */
  470. }
  471. /*
  472. * List of paths to try when searching for "init".
  473. */
  474. static char *initpaths[] = {
  475. "/sbin/init",
  476. "/sbin/oinit",
  477. "/sbin/init.bak",
  478. NULL,
  479. };
  480. void
  481. check_console(struct proc *p)
  482. {
  483. struct nameidata nd;
  484. int error;
  485. NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
  486. error = namei(&nd);
  487. if (error) {
  488. if (error == ENOENT)
  489. printf("warning: /dev/console does not exist\n");
  490. else
  491. printf("warning: /dev/console error %d\n", error);
  492. } else
  493. vrele(nd.ni_vp);
  494. }
  495. /*
  496. * Start the initial user process; try exec'ing each pathname in "initpaths".
  497. * The program is invoked with one argument containing the boot flags.
  498. */
  499. void
  500. start_init(void *arg)
  501. {
  502. struct proc *p = arg;
  503. vaddr_t addr;
  504. struct sys_execve_args /* {
  505. syscallarg(const char *) path;
  506. syscallarg(char *const *) argp;
  507. syscallarg(char *const *) envp;
  508. } */ args;
  509. int options, error;
  510. long i;
  511. register_t retval[2];
  512. char flags[4], *flagsp;
  513. char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
  514. /*
  515. * Now in process 1.
  516. */
  517. /*
  518. * Wait for main() to tell us that it's safe to exec.
  519. */
  520. while (start_init_exec == 0)
  521. (void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
  522. check_console(p);
  523. /* process 0 ignores SIGCHLD, but we can't */
  524. p->p_p->ps_sigacts->ps_flags = 0;
  525. /*
  526. * Need just enough stack to hold the faked-up "execve()" arguments.
  527. */
  528. #ifdef MACHINE_STACK_GROWS_UP
  529. addr = USRSTACK;
  530. #else
  531. addr = USRSTACK - PAGE_SIZE;
  532. #endif
  533. p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
  534. p->p_vmspace->vm_minsaddr = (caddr_t)(addr + PAGE_SIZE);
  535. if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
  536. NULL, UVM_UNKNOWN_OFFSET, 0,
  537. UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_MASK, MAP_INHERIT_COPY,
  538. MADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
  539. panic("init: couldn't allocate argument space");
  540. for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
  541. #ifdef MACHINE_STACK_GROWS_UP
  542. ucp = (char *)addr;
  543. #else
  544. ucp = (char *)(addr + PAGE_SIZE);
  545. #endif
  546. /*
  547. * Construct the boot flag argument.
  548. */
  549. flagsp = flags;
  550. *flagsp++ = '-';
  551. options = 0;
  552. if (boothowto & RB_SINGLE) {
  553. *flagsp++ = 's';
  554. options = 1;
  555. }
  556. #ifdef notyet
  557. if (boothowto & RB_FASTBOOT) {
  558. *flagsp++ = 'f';
  559. options = 1;
  560. }
  561. #endif
  562. /*
  563. * Move out the flags (arg 1), if necessary.
  564. */
  565. if (options != 0) {
  566. *flagsp++ = '\0';
  567. i = flagsp - flags;
  568. #ifdef DEBUG
  569. printf("init: copying out flags `%s' %ld\n", flags, i);
  570. #endif
  571. #ifdef MACHINE_STACK_GROWS_UP
  572. arg1 = ucp;
  573. (void)copyout((caddr_t)flags, (caddr_t)ucp, i);
  574. ucp += i;
  575. #else
  576. (void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
  577. arg1 = ucp;
  578. #endif
  579. }
  580. /*
  581. * Move out the file name (also arg 0).
  582. */
  583. i = strlen(path) + 1;
  584. #ifdef DEBUG
  585. printf("init: copying out path `%s' %ld\n", path, i);
  586. #endif
  587. #ifdef MACHINE_STACK_GROWS_UP
  588. arg0 = ucp;
  589. (void)copyout((caddr_t)path, (caddr_t)ucp, i);
  590. ucp += i;
  591. ucp = (caddr_t)ALIGN((u_long)ucp);
  592. uap = (char **)ucp + 3;
  593. #else
  594. (void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
  595. arg0 = ucp;
  596. uap = (char **)((u_long)ucp & ~ALIGNBYTES);
  597. #endif
  598. /*
  599. * Move out the arg pointers.
  600. */
  601. i = 0;
  602. copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
  603. if (options != 0)
  604. copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
  605. copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
  606. /*
  607. * Point at the arguments.
  608. */
  609. SCARG(&args, path) = arg0;
  610. SCARG(&args, argp) = uap;
  611. SCARG(&args, envp) = NULL;
  612. /*
  613. * Now try to exec the program. If can't for any reason
  614. * other than it doesn't exist, complain.
  615. */
  616. if ((error = sys_execve(p, &args, retval)) == 0) {
  617. KERNEL_UNLOCK();
  618. return;
  619. }
  620. if (error != ENOENT)
  621. printf("exec %s: error %d\n", path, error);
  622. }
  623. printf("init: not found\n");
  624. panic("no init");
  625. }
  626. void
  627. start_update(void *arg)
  628. {
  629. sched_sync(curproc);
  630. /* NOTREACHED */
  631. }
  632. void
  633. start_cleaner(void *arg)
  634. {
  635. buf_daemon(curproc);
  636. /* NOTREACHED */
  637. }
  638. void
  639. start_reaper(void *arg)
  640. {
  641. reaper();
  642. /* NOTREACHED */
  643. }