2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
30 * The Regents of the University of California. All rights reserved.
31 * (c) UNIX System Laboratories, Inc.
32 * All or some portions of this file are derived from material licensed
33 * to the University of California by American Telephone and Telegraph
34 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
35 * the permission of UNIX System Laboratories, Inc.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
70 * Mach Operating System
71 * Copyright (c) 1987 Carnegie-Mellon University
72 * All rights reserved. The CMU software License Agreement specifies
73 * the terms and conditions for use and redistribution.
76 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
77 * support for mandatory and extensible security protections. This notice
78 * is included in support of clause 2.2 (b) of the Apple Public License,
82 #include <sys/param.h>
83 #include <sys/filedesc.h>
84 #include <sys/kernel.h>
85 #include <sys/mount_internal.h>
86 #include <sys/proc_internal.h>
87 #include <sys/kauth.h>
88 #include <sys/systm.h>
89 #include <sys/vnode_internal.h>
91 #include <sys/buf_internal.h>
92 #include <sys/clist.h>
95 #include <sys/systm.h>
98 #include <bsm/audit_kernel.h>
100 #include <sys/malloc.h>
101 #include <sys/dkstat.h>
102 #include <sys/codesign.h>
104 #include <kern/startup.h>
105 #include <kern/thread.h>
106 #include <kern/task.h>
107 #include <kern/ast.h>
109 #include <mach/vm_param.h>
111 #include <vm/vm_map.h>
112 #include <vm/vm_kern.h>
114 #include <sys/ux_exception.h> /* for ux_exception_port */
116 #include <sys/reboot.h>
117 #include <mach/exception_types.h>
118 #include <dev/busvar.h> /* for pseudo_inits */
119 #include <sys/kdebug.h>
121 #include <mach/mach_types.h>
122 #include <mach/vm_prot.h>
123 #include <mach/semaphore.h>
124 #include <mach/sync_policy.h>
125 #include <kern/clock.h>
126 #include <mach/kern_return.h>
127 #include <mach/thread_act.h> /* for thread_resume() */
128 #include <mach/task.h> /* for task_set_exception_ports() */
129 #include <sys/ux_exception.h> /* for ux_handler() */
130 #include <sys/ubc_internal.h> /* for ubc_init() */
131 #include <sys/mcache.h> /* for mcache_init() */
132 #include <sys/mbuf.h> /* for mbinit() */
133 #include <sys/event.h> /* for knote_init() */
134 #include <sys/aio_kern.h> /* for aio_init() */
135 #include <sys/semaphore.h> /* for psem_cache_init() */
136 #include <net/dlil.h> /* for dlil_init() */
137 #include <net/kpi_protocol.h> /* for proto_kpi_init() */
138 #include <sys/pipe.h> /* for pipeinit() */
139 #include <sys/socketvar.h> /* for socketinit() */
140 #include <sys/protosw.h> /* for domaininit() */
141 #include <kern/sched_prim.h> /* for thread_wakeup() */
142 #include <net/if_ether.h> /* for ether_family_init() */
143 #include <vm/vm_protos.h> /* for vnode_pager_bootstrap() */
144 #include <miscfs/devfs/devfsdefs.h> /* for devfs_kernel_mount() */
145 #include <mach/host_priv.h> /* for host_set_exception_ports() */
146 #include <kern/host.h> /* for host_priv_self() */
147 #include <vm/vm_kern.h> /* for kmem_suballoc() */
148 #include <sys/semaphore.h> /* for psem_lock_init() */
149 #include <sys/msgbuf.h> /* for log_setsize() */
151 #include <net/init.h>
154 #include <security/mac_framework.h>
155 #include <security/mac_internal.h> /* mac_init_bsd() */
156 #include <security/mac_mach_internal.h> /* mac_update_task_label() */
159 #include <machine/exec.h>
162 #include <sys/imageboot.h>
165 #include <pexpert/pexpert.h>
167 void * get_user_regs(thread_t
); /* XXX kludge for <machine/thread.h> */
168 void IOKitInitializeTime(void); /* XXX */
169 void loopattach(void); /* XXX */
172 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\t"
173 "The Regents of the University of California. "
174 "All rights reserved.\n\n";
176 /* Components of the first process -- never freed. */
178 struct session session0
;
180 struct filedesc filedesc0
;
181 struct plimit limit0
;
182 struct pstats pstats0
;
183 struct sigacts sigacts0
;
193 /* Global variables to make pstat happy. We do swapping differently */
197 struct swdevt swdevt
[1];
199 dev_t rootdev
; /* device of the root */
200 dev_t dumpdev
; /* device to take dumps on */
201 long dumplo
; /* offset into dumpdev */
203 char hostname
[MAXHOSTNAMELEN
];
205 char domainname
[MAXDOMNAMELEN
];
208 struct exec_archhandler exec_archhandler_ppc
= {
209 .path
= "/usr/libexec/oah/translate",
212 struct exec_archhandler exec_archhandler_ppc
;
213 #endif /* __i386__ */
215 char rootdevice
[16]; /* hfs device names have at least 9 chars */
218 struct kmemstats kmemstats
[M_LAST
];
221 int lbolt
; /* awoken once a second */
222 struct vnode
*rootvp
;
223 int boothowto
= RB_DEBUG
;
225 void lightning_bolt(void *);
226 extern kern_return_t
IOFindBSDRoot(char *, dev_t
*, u_int32_t
*);
227 extern void IOSecureBSDRoot(const char * rootName
);
228 extern kern_return_t
IOKitBSDInit(void );
229 extern void kminit(void);
230 extern void klogwakeup(void);
231 extern void file_lock_init(void);
232 extern void kmeminit(void);
233 extern void bsd_bufferinit(void);
238 #define BSD_SIMUL_EXECS 33 /* 32 , allow for rounding */
239 #define BSD_PAGABLE_MAP_SIZE (BSD_SIMUL_EXECS * (NCARGS + PAGE_SIZE))
240 vm_map_t bsd_pageable_map
;
242 semaphore_t execve_semaphore
;
245 extern int customnbuf
;
247 void bsd_init(void) __attribute__((section("__TEXT, initcode")));
248 __private_extern__
void ubc_init(void ) __attribute__((section("__TEXT, initcode")));
249 void vfsinit(void) __attribute__((section("__TEXT, initcode")));
250 kern_return_t
bsd_autoconf(void) __attribute__((section("__TEXT, initcode")));
251 void bsd_utaskbootstrap(void) __attribute__((section("__TEXT, initcode")));
253 static void parse_bsd_args(void);
254 extern task_t bsd_init_task
;
255 extern char init_task_failure_data
[];
256 extern void time_zone_slock_init(void);
257 static void process_name(const char *, proc_t
);
259 static void setconf(void);
261 funnel_t
*kernel_flock
;
264 extern void sysv_shm_lock_init(void);
267 extern void sysv_sem_lock_init(void);
270 extern void sysv_msg_lock_init(void);
272 extern void pthread_init(void);
274 /* kmem access not enabled by default; can be changed with boot-args */
277 /* size of kernel trace buffer, disabled by default */
278 unsigned int new_nkdbufs
= 0;
280 /* mach leak logging */
282 int turn_on_log_leaks
= 0;
284 extern void stackshot_lock_init(void);
287 * Initialization code.
288 * Called from cold start routine as
289 * soon as a stack and segmentation
290 * have been established.
293 * hand craft 0th process
294 * call all initialization routines
295 * hand craft 1st user process
299 * Sets the name for the given task.
302 process_name(const char *s
, proc_t p
)
304 size_t length
= strlen(s
);
307 length
>= sizeof(p
->p_comm
) ? sizeof(p
->p_comm
) :
311 /* To allow these values to be patched, they're globals here */
312 #include <machine/vmparam.h>
313 struct rlimit vm_initial_limit_stack
= { DFLSSIZ
, MAXSSIZ
- PAGE_SIZE
};
314 struct rlimit vm_initial_limit_data
= { DFLDSIZ
, MAXDSIZ
};
315 struct rlimit vm_initial_limit_core
= { DFLCSIZ
, MAXCSIZ
};
317 extern thread_t
cloneproc(proc_t
, int);
318 extern int (*mountroot
)(void);
319 extern int netboot_mountroot(void); /* netboot.c */
320 extern int netboot_setup(void);
322 lck_grp_t
* proc_lck_grp
;
323 lck_grp_attr_t
* proc_lck_grp_attr
;
324 lck_attr_t
* proc_lck_attr
;
325 lck_mtx_t
* proc_list_mlock
;
326 lck_mtx_t
* proc_klist_mlock
;
328 /* hook called after root is mounted XXX temporary hack */
329 void (*mountroot_post_hook
)(void);
332 * This function is called very early on in the Mach startup, from the
333 * function start_kernel_threads() in osfmk/kern/startup.c. It's called
334 * in the context of the current (startup) task using a call to the
335 * function kernel_thread_create() to jump into start_kernel_threads().
336 * Internally, kernel_thread_create() calls thread_create_internal(),
337 * which calls uthread_alloc(). The function of uthread_alloc() is
338 * normally to allocate a uthread structure, and fill out the uu_sigmask,
339 * uu_context fields. It skips filling these out in the case of the "task"
340 * being "kernel_task", because the order of operation is inverted. To
341 * account for that, we need to manually fill in at least the contents
342 * of the uu_context.vc_ucred field so that the uthread structure can be
343 * used like any other.
354 struct vfs_context context
;
356 struct ucred temp_cred
;
358 #define bsd_init_kprintf(x...) /* kprintf("bsd_init: " x) */
360 kernel_flock
= funnel_alloc(KERNEL_FUNNEL
);
361 if (kernel_flock
== (funnel_t
*)0 ) {
362 panic("bsd_init: Failed to allocate kernel funnel");
367 bsd_init_kprintf("calling kmeminit\n");
370 bsd_init_kprintf("calling parse_bsd_args\n");
373 /* Initialize kauth subsystem before instancing the first credential */
374 bsd_init_kprintf("calling kauth_init\n");
377 /* Initialize process and pgrp structures. */
378 bsd_init_kprintf("calling procinit\n");
385 /* kernel_task->proc = kernproc; */
386 set_bsdtask_info(kernel_task
,(void *)p
);
390 /* give kernproc a name */
391 bsd_init_kprintf("calling process_name\n");
392 process_name("kernel_task", p
);
394 /* allocate proc lock group attribute and group */
395 bsd_init_kprintf("calling lck_grp_attr_alloc_init\n");
396 proc_lck_grp_attr
= lck_grp_attr_alloc_init();
398 proc_lck_grp
= lck_grp_alloc_init("proc", proc_lck_grp_attr
);
400 /* Allocate proc lock attribute */
401 proc_lck_attr
= lck_attr_alloc_init();
403 #if __PROC_INTERNAL_DEBUG
404 lck_attr_setdebug(proc_lck_attr
);
408 proc_list_mlock
= lck_mtx_alloc_init(proc_lck_grp
, proc_lck_attr
);
409 proc_klist_mlock
= lck_mtx_alloc_init(proc_lck_grp
, proc_lck_attr
);
410 lck_mtx_init(&p
->p_mlock
, proc_lck_grp
, proc_lck_attr
);
411 lck_mtx_init(&p
->p_fdmlock
, proc_lck_grp
, proc_lck_attr
);
412 lck_spin_init(&p
->p_slock
, proc_lck_grp
, proc_lck_attr
);
414 if (current_task() != kernel_task
)
415 printf("bsd_init: We have a problem, "
416 "current task is not kernel task\n");
418 bsd_init_kprintf("calling get_bsdthread_info\n");
419 ut
= (uthread_t
)get_bsdthread_info(current_thread());
423 * Initialize the MAC Framework
425 mac_policy_initbsd();
426 p
->p_mac_enforce
= 0;
433 LIST_INSERT_HEAD(&allproc
, p
, p_list
);
435 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0
, pg_hash
);
436 LIST_INIT(&pgrp0
.pg_members
);
437 lck_mtx_init(&pgrp0
.pg_mlock
, proc_lck_grp
, proc_lck_attr
);
438 /* There is no other bsd thread this point and is safe without pgrp lock */
439 LIST_INSERT_HEAD(&pgrp0
.pg_members
, p
, p_pglist
);
440 p
->p_listflag
|= P_LIST_INPGRP
;
443 pgrp0
.pg_session
= &session0
;
444 pgrp0
.pg_membercnt
= 1;
446 session0
.s_count
= 1;
447 session0
.s_leader
= p
;
448 session0
.s_listflags
= 0;
449 lck_mtx_init(&session0
.s_mlock
, proc_lck_grp
, proc_lck_attr
);
450 LIST_INSERT_HEAD(SESSHASH(0), &session0
, s_hash
);
457 p
->task
= kernel_task
;
460 p
->p_flag
= P_SYSTEM
;
464 TAILQ_INIT(&p
->p_uthlist
);
465 TAILQ_INSERT_TAIL(&p
->p_uthlist
, ut
, uu_list
);
468 p
->sigwait_thread
= THREAD_NULL
;
469 p
->exit_thread
= THREAD_NULL
;
470 p
->p_csflags
= CS_VALID
;
473 * Create credential. This also Initializes the audit information.
474 * XXX It is not clear what the initial values should be for audit ID,
475 * XXX session ID, etc..
477 bsd_init_kprintf("calling bzero\n");
478 bzero(&temp_cred
, sizeof(temp_cred
));
479 temp_cred
.cr_ngroups
= 1;
481 bsd_init_kprintf("calling kauth_cred_create\n");
482 p
->p_ucred
= kauth_cred_create(&temp_cred
);
484 /* give the (already exisiting) initial thread a reference on it */
485 bsd_init_kprintf("calling kauth_cred_ref\n");
486 kauth_cred_ref(p
->p_ucred
);
487 ut
->uu_context
.vc_ucred
= p
->p_ucred
;
488 ut
->uu_context
.vc_thread
= current_thread();
490 TAILQ_INIT(&p
->aio_activeq
);
491 TAILQ_INIT(&p
->aio_doneq
);
492 p
->aio_active_count
= 0;
493 p
->aio_done_count
= 0;
495 bsd_init_kprintf("calling file_lock_init\n");
499 mac_cred_label_associate_kernel(p
->p_ucred
);
500 mac_task_label_update_cred (p
->p_ucred
, (struct task
*) p
->task
);
503 /* Create the file descriptor table. */
504 filedesc0
.fd_refcnt
= 1+1; /* +1 so shutdown will not _FREE_ZONE */
505 p
->p_fd
= &filedesc0
;
506 filedesc0
.fd_cmask
= cmask
;
507 filedesc0
.fd_knlistsize
= -1;
508 filedesc0
.fd_knlist
= NULL
;
509 filedesc0
.fd_knhash
= NULL
;
510 filedesc0
.fd_knhashmask
= 0;
512 /* Create the limits structures. */
513 p
->p_limit
= &limit0
;
514 for (i
= 0; i
< sizeof(p
->p_rlimit
)/sizeof(p
->p_rlimit
[0]); i
++)
515 limit0
.pl_rlimit
[i
].rlim_cur
=
516 limit0
.pl_rlimit
[i
].rlim_max
= RLIM_INFINITY
;
517 limit0
.pl_rlimit
[RLIMIT_NOFILE
].rlim_cur
= NOFILE
;
518 limit0
.pl_rlimit
[RLIMIT_NPROC
].rlim_cur
= maxprocperuid
;
519 limit0
.pl_rlimit
[RLIMIT_NPROC
].rlim_max
= maxproc
;
520 limit0
.pl_rlimit
[RLIMIT_STACK
] = vm_initial_limit_stack
;
521 limit0
.pl_rlimit
[RLIMIT_DATA
] = vm_initial_limit_data
;
522 limit0
.pl_rlimit
[RLIMIT_CORE
] = vm_initial_limit_core
;
523 limit0
.pl_refcnt
= 1;
525 p
->p_stats
= &pstats0
;
526 p
->p_sigacts
= &sigacts0
;
529 * Charge root for two processes: init and mach_init.
531 bsd_init_kprintf("calling chgproccnt\n");
532 (void)chgproccnt(0, 1);
535 * Allocate a kernel submap for pageable memory
536 * for temporary copying (execve()).
541 bsd_init_kprintf("calling kmem_suballoc\n");
542 ret
= kmem_suballoc(kernel_map
,
544 (vm_size_t
)BSD_PAGABLE_MAP_SIZE
,
548 if (ret
!= KERN_SUCCESS
)
549 panic("bsd_init: Failed to allocate bsd pageable map");
553 * Initialize buffers and hash links for buffers
555 * SIDE EFFECT: Starts a thread for bcleanbuf_thread(), so must
556 * happen after a credential has been associated with
559 bsd_init_kprintf("calling bsd_bufferinit\n");
562 /* Initialize the execve() semaphore */
563 bsd_init_kprintf("calling semaphore_create\n");
564 ret
= semaphore_create(kernel_task
, &execve_semaphore
,
565 SYNC_POLICY_FIFO
, BSD_SIMUL_EXECS
-1);
566 if (ret
!= KERN_SUCCESS
)
567 panic("bsd_init: Failed to create execve semaphore");
570 * Initialize the calendar.
572 bsd_init_kprintf("calling IOKitInitializeTime\n");
573 IOKitInitializeTime();
575 if (turn_on_log_leaks
&& !new_nkdbufs
)
576 new_nkdbufs
= 200000;
577 start_kern_tracing(new_nkdbufs
);
578 if (turn_on_log_leaks
)
581 bsd_init_kprintf("calling ubc_init\n");
584 /* Initialize the file systems. */
585 bsd_init_kprintf("calling vfsinit\n");
589 /* Initialize per-CPU cache allocator */
592 /* Initialize mbuf's. */
593 bsd_init_kprintf("calling mbinit\n");
598 * Initializes security event auditing.
599 * XXX: Should/could this occur later?
602 bsd_init_kprintf("calling audit_init\n");
606 /* Initialize kqueues */
607 bsd_init_kprintf("calling knote_init\n");
611 /* Initialize kernel memory status notifications */
612 bsd_init_kprintf("calling kern_memorystatus_init\n");
613 kern_memorystatus_init();
616 /* Initialize for async IO */
617 bsd_init_kprintf("calling aio_init\n");
620 /* Initialize pipes */
621 bsd_init_kprintf("calling pipeinit\n");
624 /* Initialize SysV shm subsystem locks; the subsystem proper is
625 * initialized through a sysctl.
628 bsd_init_kprintf("calling sysv_shm_lock_init\n");
629 sysv_shm_lock_init();
632 bsd_init_kprintf("calling sysv_sem_lock_init\n");
633 sysv_sem_lock_init();
636 bsd_init_kprintf("sysv_msg_lock_init\n");
637 sysv_msg_lock_init();
639 bsd_init_kprintf("calling pshm_lock_init\n");
641 bsd_init_kprintf("calling psem_lock_init\n");
645 /* POSIX Shm and Sem */
646 bsd_init_kprintf("calling pshm_cache_init\n");
648 bsd_init_kprintf("calling psem_cache_init\n");
650 bsd_init_kprintf("calling time_zone_slock_init\n");
651 time_zone_slock_init();
653 /* Stack snapshot facility lock */
654 stackshot_lock_init();
656 * Initialize protocols. Block reception of incoming packets
657 * until everything is ready.
659 bsd_init_kprintf("calling sysctl_register_fixed\n");
660 sysctl_register_fixed();
661 bsd_init_kprintf("calling sysctl_mib_init\n");
664 bsd_init_kprintf("calling dlil_init\n");
666 bsd_init_kprintf("calling proto_kpi_init\n");
668 #endif /* NETWORKING */
670 bsd_init_kprintf("calling socketinit\n");
672 bsd_init_kprintf("calling domaininit\n");
676 p
->p_fd
->fd_cdir
= NULL
;
677 p
->p_fd
->fd_rdir
= NULL
;
680 /* Initialize kernel profiling. */
684 /* kick off timeout driven events by calling first time */
685 thread_wakeup(&lbolt
);
686 timeout(lightning_bolt
, 0, hz
);
688 bsd_init_kprintf("calling bsd_autoconf\n");
692 extern void dtrace_postinit(void);
697 * We attach the loopback interface *way* down here to ensure
698 * it happens after autoconf(), otherwise it becomes the
699 * "primary" interface.
703 bsd_init_kprintf("calling loopattach\n");
704 loopattach(); /* XXX */
708 /* Register the built-in dlil ethernet interface family */
709 bsd_init_kprintf("calling ether_family_init\n");
714 /* Call any kext code that wants to run just after network init */
715 bsd_init_kprintf("calling net_init_run\n");
717 #endif /* NETWORKING */
719 bsd_init_kprintf("calling vnode_pager_bootstrap\n");
720 vnode_pager_bootstrap();
722 /* XXX Hack for early debug stop */
723 printf("\nabout to sleep for 10 seconds\n");
724 IOSleep( 10 * 1000 );
725 /* Debugger("hello"); */
728 bsd_init_kprintf("calling inittodr\n");
733 /* print out early VM statistics */
735 vm_statistics_data_t stat
;
736 mach_msg_type_number_t count
;
738 count
= HOST_VM_INFO_COUNT
;
739 kr1
= host_statistics(host_self(),
743 kprintf("Mach Virtual Memory Statistics (page size of 4096) bytes\n"
744 "Pages free:\t\t\t%u.\n"
745 "Pages active:\t\t\t%u.\n"
746 "Pages inactive:\t\t\t%u.\n"
747 "Pages wired down:\t\t%u.\n"
748 "\"Translation faults\":\t\t%u.\n"
749 "Pages copy-on-write:\t\t%u.\n"
750 "Pages zero filled:\t\t%u.\n"
751 "Pages reactivated:\t\t%u.\n"
752 "Pageins:\t\t\t%u.\n"
753 "Pageouts:\t\t\t\%u.\n"
754 "Object cache: %u hits of %u lookups (%d%% hit rate)\n",
762 stat
.zero_fill_count
,
768 (stat
.hits
== 0) ? 100 :
769 ((stat
.lookups
* 100) / stat
.hits
));
771 #endif /* CONFIG_EMBEDDED */
773 /* Mount the root file system. */
777 bsd_init_kprintf("calling setconf\n");
780 bsd_init_kprintf("vfs_mountroot\n");
781 if (0 == (err
= vfs_mountroot()))
783 rootdevice
[0] = '\0';
785 if (mountroot
== netboot_mountroot
) {
786 printf("bsd_init: netboot_mountroot failed,"
787 " errno = %d\n", err
);
788 panic("bsd_init: failed to mount network root: %s", PE_boot_args());
791 printf("cannot mount root, errno = %d\n", err
);
792 boothowto
|= RB_ASKNAME
;
795 IOSecureBSDRoot(rootdevice
);
797 context
.vc_thread
= current_thread();
798 context
.vc_ucred
= p
->p_ucred
;
799 mountlist
.tqh_first
->mnt_flag
|= MNT_ROOTFS
;
801 bsd_init_kprintf("calling VFS_ROOT\n");
802 /* Get the vnode for '/'. Set fdp->fd_fd.fd_cdir to reference it. */
803 if (VFS_ROOT(mountlist
.tqh_first
, &rootvnode
, &context
))
804 panic("bsd_init: cannot find root vnode: %s", PE_boot_args());
805 rootvnode
->v_flag
|= VROOT
;
806 (void)vnode_ref(rootvnode
);
807 (void)vnode_put(rootvnode
);
808 filedesc0
.fd_cdir
= rootvnode
;
811 if (mountroot
== netboot_mountroot
) {
813 /* post mount setup */
814 if ((err
= netboot_setup()) != 0) {
815 panic("bsd_init: NetBoot could not find root, %d: %s", err
, PE_boot_args());
823 * See if a system disk image is present. If so, mount it and
824 * switch the root vnode to point to it
827 if(imageboot_needed()) {
830 /* An image was found */
831 if((err
= imageboot_setup())) {
833 * this is not fatal. Keep trying to root
834 * off the original media
836 printf("%s: imageboot could not find root, %d\n",
840 #endif /* CONFIG_IMAGEBOOT */
842 microtime(&p
->p_stats
->p_start
); /* for compat sake */
843 microtime(&p
->p_start
);
844 p
->p_rtime
.tv_sec
= p
->p_rtime
.tv_usec
= 0;
848 char mounthere
[] = "/dev"; /* !const because of internal casting */
850 bsd_init_kprintf("calling devfs_kernel_mount\n");
851 devfs_kernel_mount(mounthere
);
855 /* Initialize signal state for process 0. */
856 bsd_init_kprintf("calling siginit\n");
859 bsd_init_kprintf("calling bsd_utaskbootstrap\n");
860 bsd_utaskbootstrap();
863 /* this should be done after the root filesystem is mounted */
864 error
= set_archhandler(p
, CPU_TYPE_POWERPC
);
865 if (error
) /* XXX make more generic */
866 exec_archhandler_ppc
.path
[0] = 0;
869 bsd_init_kprintf("calling mountroot_post_hook\n");
871 /* invoke post-root-mount hook */
872 if (mountroot_post_hook
!= NULL
)
873 mountroot_post_hook();
880 bsd_init_kprintf("done\n");
883 /* Called with kernel funnel held */
887 proc_t p
= current_proc();
891 process_name("init", p
);
895 thread
= current_thread();
896 (void) host_set_exception_ports(host_priv_self(),
897 EXC_MASK_ALL
& ~(EXC_MASK_SYSCALL
|
898 EXC_MASK_MACH_SYSCALL
|
901 (mach_port_t
)ux_exception_port
,
902 EXCEPTION_DEFAULT
| MACH_EXCEPTION_CODES
,
905 ut
= (uthread_t
)get_bsdthread_info(thread
);
907 bsd_init_task
= get_threadtask(thread
);
908 init_task_failure_data
[0] = 0;
911 mac_cred_label_associate_user(p
->p_ucred
);
912 mac_task_label_update_cred (p
->p_ucred
, (struct task
*) p
->task
);
914 load_init_program(p
);
919 lightning_bolt(__unused
void *dummy
)
921 boolean_t funnel_state
;
923 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
925 thread_wakeup(&lbolt
);
926 timeout(lightning_bolt
,0,hz
);
929 (void) thread_funnel_set(kernel_flock
, FALSE
);
935 kprintf("bsd_autoconf: calling kminit\n");
939 * Early startup for bsd pseudodevices.
942 struct pseudo_init
*pi
;
944 for (pi
= pseudo_inits
; pi
->ps_func
; pi
++)
945 (*pi
->ps_func
) (pi
->ps_count
);
948 return( IOKitBSDInit());
952 #include <sys/disklabel.h> /* for MAXPARTITIONS */
961 * calls into IOKit can generate networking registrations
962 * which needs to be under network funnel. Right thing to do
963 * here is to drop the funnel alltogether and regrab it afterwards
965 err
= IOFindBSDRoot( rootdevice
, &rootdev
, &flags
);
967 printf("setconf: IOFindBSDRoot returned an error (%d);"
968 "setting rootdevice to 'sd0a'.\n", err
); /* XXX DEBUG TEMP */
969 rootdev
= makedev( 6, 0 );
970 strlcpy(rootdevice
, "sd0a", sizeof(rootdevice
));
977 mountroot
= netboot_mountroot
;
980 /* otherwise have vfs determine root filesystem */
989 bsd_utaskbootstrap(void)
994 thread
= cloneproc(kernproc
, 0);
995 /* Hold the reference as it will be dropped during shutdown */
996 initproc
= proc_find(1);
997 #if __PROC_INTERNAL_DEBUG
998 if (initproc
== PROC_NULL
)
999 panic("bsd_utaskbootstrap: initproc not set\n");
1001 /* Set the launch time for init */
1002 microtime(&initproc
->p_start
);
1003 microtime(&initproc
->p_stats
->p_start
); /* for compat sake */
1006 ut
= (struct uthread
*)get_bsdthread_info(thread
);
1008 act_set_astbsd(thread
);
1009 (void) thread_resume(thread
);
1013 parse_bsd_args(void)
1018 if (PE_parse_boot_arg("-s", namep
))
1019 boothowto
|= RB_SINGLE
;
1021 if (PE_parse_boot_arg("-b", namep
))
1022 boothowto
|= RB_NOBOOTRC
;
1024 if (PE_parse_boot_arg("-x", namep
)) /* safe boot */
1025 boothowto
|= RB_SAFEBOOT
;
1027 if (PE_parse_boot_arg("-l", namep
)) /* leaks logging */
1028 turn_on_log_leaks
= 1;
1030 PE_parse_boot_arg("srv", &srv
);
1031 PE_parse_boot_arg("ncl", &ncl
);
1032 if (PE_parse_boot_arg("nbuf", &max_nbuf_headers
)) {
1035 #if !defined(SECURE_KERNEL)
1036 PE_parse_boot_arg("kmem", &setup_kmem
);
1038 PE_parse_boot_arg("trace", &new_nkdbufs
);
1040 if (PE_parse_boot_arg("msgbuf", &msgbuf
)) {
1041 log_setsize(msgbuf
);