]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/bsd_init.c
428220737ed24ab690ba2b7f43f208a317b99f77
[apple/xnu.git] / bsd / kern / bsd_init.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
32 * The Regents of the University of California. All rights reserved.
33 * (c) UNIX System Laboratories, Inc.
34 * All or some portions of this file are derived from material licensed
35 * to the University of California by American Telephone and Telegraph
36 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
37 * the permission of UNIX System Laboratories, Inc.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
68 */
69
70 /*
71 *
72 * Mach Operating System
73 * Copyright (c) 1987 Carnegie-Mellon University
74 * All rights reserved. The CMU software License Agreement specifies
75 * the terms and conditions for use and redistribution.
76 */
77
78 #include <sys/param.h>
79 #include <sys/filedesc.h>
80 #include <sys/kernel.h>
81 #include <sys/mount_internal.h>
82 #include <sys/proc_internal.h>
83 #include <sys/kauth.h>
84 #include <sys/systm.h>
85 #include <sys/vnode_internal.h>
86 #include <sys/conf.h>
87 #include <sys/buf_internal.h>
88 #include <sys/clist.h>
89 #include <sys/user.h>
90 #include <sys/time.h>
91 #include <sys/systm.h>
92 #include <sys/mman.h>
93
94 #include <bsm/audit_kernel.h>
95
96 #include <sys/malloc.h>
97 #include <sys/dkstat.h>
98
99 #include <kern/startup.h>
100 #include <kern/thread.h>
101 #include <kern/task.h>
102 #include <kern/ast.h>
103
104 #include <mach/vm_param.h>
105
106 #include <vm/vm_map.h>
107 #include <vm/vm_kern.h>
108
109 #include <sys/ux_exception.h> /* for ux_exception_port */
110
111 #include <sys/reboot.h>
112 #include <mach/exception_types.h>
113 #include <dev/busvar.h> /* for pseudo_inits */
114 #include <sys/kdebug.h>
115
116 #include <mach/mach_types.h>
117 #include <mach/vm_prot.h>
118 #include <mach/semaphore.h>
119 #include <mach/sync_policy.h>
120 #include <kern/clock.h>
121 #include <mach/kern_return.h>
122
123 #include <mach/shared_memory_server.h>
124 #include <vm/vm_shared_memory_server.h>
125
126 #include <net/init.h>
127
128 #include <machine/exec.h>
129
130 extern int app_profile; /* on/off switch for pre-heat cache */
131
132 char copyright[] =
133 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
134 "The Regents of the University of California. "
135 "All rights reserved.\n\n";
136
137 extern void ux_handler();
138
139 /* Components of the first process -- never freed. */
140 struct proc proc0;
141 struct session session0;
142 struct pgrp pgrp0;
143 struct filedesc filedesc0;
144 struct plimit limit0;
145 struct pstats pstats0;
146 struct sigacts sigacts0;
147 struct proc *kernproc, *initproc;
148
149 long tk_cancc;
150 long tk_nin;
151 long tk_nout;
152 long tk_rawcc;
153
154 int lock_trace = 0;
155 /* Global variables to make pstat happy. We do swapping differently */
156 int nswdev, nswap;
157 int nswapmap;
158 void *swapmap;
159 struct swdevt swdevt[1];
160
161 dev_t rootdev; /* device of the root */
162 dev_t dumpdev; /* device to take dumps on */
163 long dumplo; /* offset into dumpdev */
164 long hostid;
165 char hostname[MAXHOSTNAMELEN];
166 int hostnamelen;
167 char domainname[MAXDOMNAMELEN];
168 int domainnamelen;
169 #if __i386__
170 struct exec_archhandler exec_archhandler_ppc = {
171 .path = "/usr/libexec/oah/translate",
172 };
173 #else /* __i386__ */
174 struct exec_archhandler exec_archhandler_ppc;
175 #endif /* __i386__ */
176
177 char rootdevice[16]; /* hfs device names have at least 9 chars */
178
179 #ifdef KMEMSTATS
180 struct kmemstats kmemstats[M_LAST];
181 #endif
182
183 int lbolt; /* awoken once a second */
184 struct vnode *rootvp;
185 int boothowto = RB_DEBUG;
186
187 #define BSD_PAGABLE_MAP_SIZE (16 * 512 * 1024)
188 vm_map_t bsd_pageable_map;
189 vm_map_t mb_map;
190 semaphore_t execve_semaphore;
191
192 int cmask = CMASK;
193 extern int customnbuf;
194
195 int parse_bsd_args(void);
196 extern int bsd_hardclockinit;
197 extern task_t bsd_init_task;
198 extern char init_task_failure_data[];
199 extern void time_zone_slock_init(void);
200 static void process_name(char *, struct proc *);
201
202 static void setconf(void);
203
204 funnel_t *kernel_flock;
205
206 extern void sysv_shm_lock_init(void);
207 extern void sysv_sem_lock_init(void);
208 extern void sysv_msg_lock_init(void);
209 extern void pshm_lock_init();
210 extern void psem_lock_init();
211 extern int maxprocperuid;
212
213 /* kmem access not enabled by default; can be changed with boot-args */
214 int setup_kmem = 0;
215
216 extern void stackshot_lock_init();
217
218 /*
219 * Initialization code.
220 * Called from cold start routine as
221 * soon as a stack and segmentation
222 * have been established.
223 * Functions:
224 * turn on clock
225 * hand craft 0th process
226 * call all initialization routines
227 * hand craft 1st user process
228 */
229
230 /*
231 * Sets the name for the given task.
232 */
233 static void
234 process_name(s, p)
235 char *s;
236 struct proc *p;
237 {
238 int length = strlen(s);
239
240 bcopy(s, p->p_comm,
241 length >= sizeof(p->p_comm) ? sizeof(p->p_comm) :
242 length + 1);
243 }
244
245 /* To allow these values to be patched, they're globals here */
246 #include <machine/vmparam.h>
247 struct rlimit vm_initial_limit_stack = { DFLSSIZ, MAXSSIZ };
248 struct rlimit vm_initial_limit_data = { DFLDSIZ, MAXDSIZ };
249 struct rlimit vm_initial_limit_core = { DFLCSIZ, MAXCSIZ };
250
251 extern thread_t cloneproc(struct proc *, int);
252 extern int (*mountroot)(void);
253 extern int netboot_mountroot(); /* netboot.c */
254 extern int netboot_setup(struct proc * p);
255
256 lck_grp_t * proc_lck_grp;
257 lck_grp_attr_t * proc_lck_grp_attr;
258 lck_attr_t * proc_lck_attr;
259
260 /* hook called after root is mounted XXX temporary hack */
261 void (*mountroot_post_hook)(void);
262
263 /*
264 * This function is called very early on in the Mach startup, from the
265 * function start_kernel_threads() in osfmk/kern/startup.c. It's called
266 * in the context of the current (startup) task using a call to the
267 * function kernel_thread_create() to jump into start_kernel_threads().
268 * Internally, kernel_thread_create() calls thread_create_internal(),
269 * which calls uthread_alloc(). The function of uthread_alloc() is
270 * normally to allocate a uthread structure, and fill out the uu_sigmask,
271 * uu_act, and uu_ucred fields. It skips filling these out in the case
272 * of the "task" being "kernel_task", because the order of operation is
273 * inverted. To account for that, we need to manually fill in at least
274 * the uu_cred field so that the uthread structure can be used like any
275 * other.
276 */
277 void
278 bsd_init()
279 {
280 register struct proc *p;
281 struct uthread *ut;
282 extern kauth_cred_t rootcred;
283 register int i;
284 int s;
285 int error;
286 thread_t th;
287 struct vfs_context context;
288 void lightning_bolt(void );
289 kern_return_t ret;
290 boolean_t funnel_state;
291 struct ucred temp_cred;
292 extern void file_lock_init(void);
293
294 kernel_flock = funnel_alloc(KERNEL_FUNNEL);
295 if (kernel_flock == (funnel_t *)0 ) {
296 panic("bsd_init: Failed to allocate kernel funnel");
297 }
298
299 funnel_state = thread_funnel_set(kernel_flock, TRUE);
300
301 printf(copyright);
302
303 kmeminit();
304
305 parse_bsd_args();
306
307 /* Initialize the uthread zone */
308 //uthread_zone_init(); /* XXX redundant: previous uthread_alloc() */
309
310 /* Initialize kauth subsystem before instancing the first credential */
311 kauth_init();
312
313 /* Initialize process and pgrp structures. */
314 procinit();
315
316 kernproc = &proc0;
317
318 p = kernproc;
319
320 /* kernel_task->proc = kernproc; */
321 set_bsdtask_info(kernel_task,(void *)p);
322 p->p_pid = 0;
323
324 /* give kernproc a name */
325 process_name("kernel_task", p);
326
327 /* allocate proc lock group attribute and group */
328 proc_lck_grp_attr= lck_grp_attr_alloc_init();
329
330 proc_lck_grp = lck_grp_alloc_init("proc", proc_lck_grp_attr);
331
332 /* Allocate proc lock attribute */
333 proc_lck_attr = lck_attr_alloc_init();
334
335 lck_mtx_init(&p->p_mlock, proc_lck_grp, proc_lck_attr);
336 lck_mtx_init(&p->p_fdmlock, proc_lck_grp, proc_lck_attr);
337
338 if (current_task() != kernel_task)
339 printf("bsd_init: We have a problem, "
340 "current task is not kernel task\n");
341
342 ut = (uthread_t)get_bsdthread_info(current_thread());
343
344 /*
345 * Create process 0.
346 */
347 LIST_INSERT_HEAD(&allproc, p, p_list);
348 p->p_pgrp = &pgrp0;
349 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
350 LIST_INIT(&pgrp0.pg_members);
351 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
352
353 pgrp0.pg_session = &session0;
354 session0.s_count = 1;
355 session0.s_leader = p;
356
357 p->task = kernel_task;
358
359 p->p_stat = SRUN;
360 p->p_flag = P_SYSTEM;
361 p->p_nice = NZERO;
362 p->p_pptr = p;
363 lockinit(&p->signal_lock, PVM, "signal", 0, 0);
364 TAILQ_INIT(&p->p_uthlist);
365 p->sigwait = FALSE;
366 p->sigwait_thread = THREAD_NULL;
367 p->exit_thread = THREAD_NULL;
368
369 /*
370 * Create credential. This also Initializes the audit information.
371 * XXX It is not clear what the initial values should be for audit ID,
372 * XXX session ID, etc..
373 */
374 bzero(&temp_cred, sizeof(temp_cred));
375 temp_cred.cr_ngroups = 1;
376
377 p->p_ucred = kauth_cred_create(&temp_cred);
378
379 /* give the (already exisiting) initial thread a reference on it */
380 kauth_cred_ref(p->p_ucred);
381 ut->uu_ucred = p->p_ucred;
382
383 TAILQ_INIT(&p->aio_activeq);
384 TAILQ_INIT(&p->aio_doneq);
385 p->aio_active_count = 0;
386 p->aio_done_count = 0;
387
388 file_lock_init();
389
390 /* Create the file descriptor table. */
391 filedesc0.fd_refcnt = 1+1; /* +1 so shutdown will not _FREE_ZONE */
392 p->p_fd = &filedesc0;
393 filedesc0.fd_cmask = cmask;
394 filedesc0.fd_knlistsize = -1;
395 filedesc0.fd_knlist = NULL;
396 filedesc0.fd_knhash = NULL;
397 filedesc0.fd_knhashmask = 0;
398
399 /* Create the limits structures. */
400 p->p_limit = &limit0;
401 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
402 limit0.pl_rlimit[i].rlim_cur =
403 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
404 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
405 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = maxprocperuid;
406 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
407 limit0.pl_rlimit[RLIMIT_STACK] = vm_initial_limit_stack;
408 limit0.pl_rlimit[RLIMIT_DATA] = vm_initial_limit_data;
409 limit0.pl_rlimit[RLIMIT_CORE] = vm_initial_limit_core;
410 limit0.p_refcnt = 1;
411
412 p->p_stats = &pstats0;
413 p->p_sigacts = &sigacts0;
414
415 /*
416 * Charge root for two processes: init and mach_init.
417 */
418 (void)chgproccnt(0, 1);
419
420 /*
421 * Allocate a kernel submap for pageable memory
422 * for temporary copying (execve()).
423 */
424 {
425 vm_offset_t min;
426
427 ret = kmem_suballoc(kernel_map,
428 &min,
429 (vm_size_t)BSD_PAGABLE_MAP_SIZE,
430 TRUE,
431 VM_FLAGS_ANYWHERE,
432 &bsd_pageable_map);
433 if (ret != KERN_SUCCESS)
434 panic("bsd_init: Failed to allocate bsd pageable map");
435 }
436
437 /*
438 * Initialize buffers and hash links for buffers
439 *
440 * SIDE EFFECT: Starts a thread for bcleanbuf_thread(), so must
441 * happen after a credential has been associated with
442 * the kernel task.
443 */
444 bsd_bufferinit();
445
446 /* Initialize the execve() semaphore */
447 ret = semaphore_create(kernel_task, &execve_semaphore,
448 SYNC_POLICY_FIFO, (BSD_PAGABLE_MAP_SIZE / NCARGS));
449 if (ret != KERN_SUCCESS)
450 panic("bsd_init: Failed to create execve semaphore");
451
452 /*
453 * Initialize the calendar.
454 */
455 IOKitResetTime();
456
457 ubc_init();
458
459 /* Initialize the file systems. */
460 vfsinit();
461
462 /* Initialize mbuf's. */
463 mbinit();
464
465 /*
466 * Initializes security event auditing.
467 * XXX: Should/could this occur later?
468 */
469 audit_init();
470
471 /* Initialize kqueues */
472 knote_init();
473
474 /* Initialize for async IO */
475 aio_init();
476
477 /* Initialize pipes */
478 pipeinit();
479
480 /* Initialize SysV shm subsystem locks; the subsystem proper is
481 * initialized through a sysctl.
482 */
483 sysv_shm_lock_init();
484 sysv_sem_lock_init();
485 sysv_msg_lock_init();
486 pshm_lock_init();
487 psem_lock_init();
488
489 /* POSIX Shm and Sem */
490 pshm_cache_init();
491 psem_cache_init();
492 time_zone_slock_init();
493
494 /* Stack snapshot facility lock */
495 stackshot_lock_init();
496 /*
497 * Initialize protocols. Block reception of incoming packets
498 * until everything is ready.
499 */
500 sysctl_register_fixed();
501 sysctl_mib_init();
502 dlil_init();
503 proto_kpi_init();
504 socketinit();
505 domaininit();
506
507 p->p_fd->fd_cdir = NULL;
508 p->p_fd->fd_rdir = NULL;
509
510 #ifdef GPROF
511 /* Initialize kernel profiling. */
512 kmstartup();
513 #endif
514
515 /* kick off timeout driven events by calling first time */
516 thread_wakeup(&lbolt);
517 timeout((void (*)(void *))lightning_bolt, 0, hz);
518
519 bsd_autoconf();
520
521 /*
522 * We attach the loopback interface *way* down here to ensure
523 * it happens after autoconf(), otherwise it becomes the
524 * "primary" interface.
525 */
526 #include <loop.h>
527 #if NLOOP > 0
528 loopattach(); /* XXX */
529 #endif
530
531 /* Register the built-in dlil ethernet interface family */
532 ether_family_init();
533
534 /* Call any kext code that wants to run just after network init */
535 net_init_run();
536
537 vnode_pager_bootstrap();
538 #if 0
539 /* XXX Hack for early debug stop */
540 printf("\nabout to sleep for 10 seconds\n");
541 IOSleep( 10 * 1000 );
542 /* Debugger("hello"); */
543 #endif
544
545 inittodr(0);
546
547 /* Mount the root file system. */
548 while( TRUE) {
549 int err;
550
551 setconf();
552 bsd_hardclockinit = -1; /* start ticking */
553
554 if (0 == (err = vfs_mountroot()))
555 break;
556 #if NFSCLIENT
557 if (mountroot == netboot_mountroot) {
558 printf("cannot mount network root, errno = %d\n", err);
559 mountroot = NULL;
560 if (0 == (err = vfs_mountroot()))
561 break;
562 }
563 #endif
564 printf("cannot mount root, errno = %d\n", err);
565 boothowto |= RB_ASKNAME;
566 }
567
568 context.vc_proc = p;
569 context.vc_ucred = p->p_ucred;
570 mountlist.tqh_first->mnt_flag |= MNT_ROOTFS;
571
572 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
573 if (VFS_ROOT(mountlist.tqh_first, &rootvnode, &context))
574 panic("bsd_init: cannot find root vnode");
575 rootvnode->v_flag |= VROOT;
576 (void)vnode_ref(rootvnode);
577 (void)vnode_put(rootvnode);
578 filedesc0.fd_cdir = rootvnode;
579
580 #if NFSCLIENT
581 if (mountroot == netboot_mountroot) {
582 int err;
583 /* post mount setup */
584 if (err = netboot_setup(p)) {
585 panic("bsd_init: NetBoot could not find root, %d", err);
586 }
587 }
588 #endif
589
590
591 microtime(&p->p_stats->p_start);
592 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
593
594 #if DEVFS
595 {
596 extern void devfs_kernel_mount(char * str);
597
598 devfs_kernel_mount("/dev");
599 }
600 #endif /* DEVFS */
601
602 /* Initialize signal state for process 0. */
603 siginit(p);
604
605 bsd_utaskbootstrap();
606
607 #if __i386__
608 // this should be done after the root filesystem is mounted
609 error = set_archhandler(p, CPU_TYPE_POWERPC);
610 if (error)
611 exec_archhandler_ppc.path[0] = 0;
612 #endif
613
614 /* invoke post-root-mount hook */
615 if (mountroot_post_hook != NULL)
616 mountroot_post_hook();
617
618 (void) thread_funnel_set(kernel_flock, funnel_state);
619 }
620
621 /* Called with kernel funnel held */
622 void
623 bsdinit_task(void)
624 {
625 struct proc *p = current_proc();
626 struct uthread *ut;
627 kern_return_t kr;
628 thread_t th_act;
629 shared_region_mapping_t system_region;
630
631 process_name("init", p);
632
633 ux_handler_init();
634
635 th_act = current_thread();
636 (void) host_set_exception_ports(host_priv_self(),
637 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
638 EXC_MASK_MACH_SYSCALL |
639 EXC_MASK_RPC_ALERT),
640 ux_exception_port,
641 EXCEPTION_DEFAULT, 0);
642
643 (void) task_set_exception_ports(get_threadtask(th_act),
644 EXC_MASK_ALL & ~(EXC_MASK_SYSCALL |
645 EXC_MASK_MACH_SYSCALL |
646 EXC_MASK_RPC_ALERT),
647 ux_exception_port,
648 EXCEPTION_DEFAULT, 0);
649
650
651
652
653 ut = (uthread_t)get_bsdthread_info(th_act);
654
655 bsd_hardclockinit = 1; /* Start bsd hardclock */
656 bsd_init_task = get_threadtask(th_act);
657 init_task_failure_data[0] = 0;
658 system_region = lookup_default_shared_region(ENV_DEFAULT_ROOT, cpu_type());
659 if (system_region == NULL) {
660 shared_file_boot_time_init(ENV_DEFAULT_ROOT, cpu_type());
661 } else {
662 vm_set_shared_region(get_threadtask(th_act), system_region);
663 }
664 load_init_program(p);
665 /* turn on app-profiling i.e. pre-heating */
666 app_profile = 1;
667 lock_trace = 1;
668 }
669
670 void
671 lightning_bolt()
672 {
673 boolean_t funnel_state;
674 extern void klogwakeup(void);
675
676 funnel_state = thread_funnel_set(kernel_flock, TRUE);
677
678 thread_wakeup(&lbolt);
679 timeout(lightning_bolt,0,hz);
680 klogwakeup();
681
682 (void) thread_funnel_set(kernel_flock, FALSE);
683 }
684
685 bsd_autoconf()
686 {
687 extern kern_return_t IOKitBSDInit( void );
688
689 kminit();
690
691 /*
692 * Early startup for bsd pseudodevices.
693 */
694 {
695 struct pseudo_init *pi;
696
697 for (pi = pseudo_inits; pi->ps_func; pi++)
698 (*pi->ps_func) (pi->ps_count);
699 }
700
701 return( IOKitBSDInit());
702 }
703
704
705 #include <sys/disklabel.h> /* for MAXPARTITIONS */
706
707 static void
708 setconf(void)
709 {
710 extern kern_return_t IOFindBSDRoot( char * rootName,
711 dev_t * root, u_int32_t * flags );
712 u_int32_t flags;
713 kern_return_t err;
714
715 /*
716 * calls into IOKit can generate networking registrations
717 * which needs to be under network funnel. Right thing to do
718 * here is to drop the funnel alltogether and regrab it afterwards
719 */
720 thread_funnel_set(kernel_flock, FALSE);
721 err = IOFindBSDRoot( rootdevice, &rootdev, &flags );
722 thread_funnel_set(kernel_flock, TRUE);
723 if( err) {
724 printf("setconf: IOFindBSDRoot returned an error (%d);"
725 "setting rootdevice to 'sd0a'.\n", err); /* XXX DEBUG TEMP */
726 rootdev = makedev( 6, 0 );
727 strcpy( rootdevice, "sd0a" );
728 flags = 0;
729 }
730
731 #if NFSCLIENT
732 if( flags & 1 ) {
733 /* network device */
734 mountroot = netboot_mountroot;
735 } else {
736 #endif
737 /* otherwise have vfs determine root filesystem */
738 mountroot = NULL;
739 #if NFSCLIENT
740 }
741 #endif
742
743 }
744
745 bsd_utaskbootstrap()
746 {
747 thread_t th_act;
748 struct uthread *ut;
749
750 th_act = cloneproc(kernproc, 0);
751 initproc = pfind(1);
752 /* Set the launch time for init */
753 microtime(&initproc->p_stats->p_start);
754
755 ut = (struct uthread *)get_bsdthread_info(th_act);
756 ut->uu_sigmask = 0;
757 act_set_astbsd(th_act);
758 (void) thread_resume(th_act);
759 }
760
761 parse_bsd_args()
762 {
763 extern char init_args[];
764 char namep[16];
765 extern int boothowto;
766 extern int srv;
767 extern int ncl;
768
769 int len;
770
771 if (PE_parse_boot_arg("-s", namep)) {
772 boothowto |= RB_SINGLE;
773 len = strlen(init_args);
774 if(len != 0)
775 strcat(init_args," -s");
776 else
777 strcat(init_args,"-s");
778 }
779
780 if (PE_parse_boot_arg("-b", namep)) {
781 boothowto |= RB_NOBOOTRC;
782 len = strlen(init_args);
783 if(len != 0)
784 strcat(init_args," -b");
785 else
786 strcat(init_args,"-b");
787 }
788
789 if (PE_parse_boot_arg("-F", namep)) {
790 len = strlen(init_args);
791 if(len != 0)
792 strcat(init_args," -F");
793 else
794 strcat(init_args,"-F");
795 }
796
797 if (PE_parse_boot_arg("-v", namep)) {
798 len = strlen(init_args);
799 if(len != 0)
800 strcat(init_args," -v");
801 else
802 strcat(init_args,"-v");
803 }
804
805 if (PE_parse_boot_arg("-x", namep)) { /* safe boot */
806 len = strlen(init_args);
807 if(len != 0)
808 strcat(init_args," -x");
809 else
810 strcat(init_args,"-x");
811 }
812
813 if (PE_parse_boot_arg("-d", namep)) {
814 len = strlen(init_args);
815 if(len != 0)
816 strcat(init_args," -d");
817 else
818 strcat(init_args,"-d");
819 }
820
821 PE_parse_boot_arg("srv", &srv);
822 PE_parse_boot_arg("ncl", &ncl);
823 if (PE_parse_boot_arg("nbuf", &max_nbuf_headers))
824 customnbuf = 1;
825 PE_parse_boot_arg("kmem", &setup_kmem);
826
827 return 0;
828 }
829
830 #if !NFSCLIENT
831 int
832 netboot_root(void)
833 {
834 return(0);
835 }
836 #endif