]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/startup.c
xnu-3247.10.11.tar.gz
[apple/xnu.git] / osfmk / kern / startup.c
index e67c01a8b493e48e08a70ebb61ced5f02fef83af..53013fa79ef7dfa820f3459e6254ebfc29764777 100644 (file)
@@ -86,7 +86,9 @@
 #include <kern/machine.h>
 #include <kern/processor.h>
 #include <kern/sched_prim.h>
+#if CONFIG_SCHED_SFI
 #include <kern/sfi.h>
+#endif
 #include <kern/startup.h>
 #include <kern/task.h>
 #include <kern/thread.h>
 #if CONFIG_TELEMETRY
 #include <kern/telemetry.h>
 #endif
-#include <kern/wait_queue.h>
 #include <kern/xpr.h>
 #include <kern/zalloc.h>
 #include <kern/locks.h>
+#include <kern/debug.h>
+#include <corpses/task_corpse.h>
 #include <prng/random.h>
 #include <console/serial_protos.h>
 #include <vm/vm_kern.h>
 #include <sys/kdebug.h>
 #include <sys/random.h>
 
+#include <kern/waitq.h>
+
+
 #if CONFIG_ATM
 #include <atm/atm_internal.h>
 #endif
 #include <security/mac_mach_internal.h>
 #endif
 
-#if CONFIG_COUNTERS
-#include <pmc/pmc.h>
-#endif
-
 #if KPC
 #include <kern/kpc.h>
 #endif
@@ -192,6 +194,7 @@ unsigned int new_nkdbufs = 0;
 unsigned int wake_nkdbufs = 0;
 unsigned int write_trace_on_panic = 0;
 unsigned int trace_typefilter = 0;
+boolean_t    trace_serial = FALSE;
 
 /* mach leak logging */
 int log_leaks = 0;
@@ -201,14 +204,14 @@ static inline void
 kernel_bootstrap_log(const char *message)
 {
 //     kprintf("kernel_bootstrap: %s\n", message);
-       kernel_debug_string(message);
+       kernel_debug_string_simple(message);
 }
 
 static inline void
 kernel_bootstrap_thread_log(const char *message)
 {
 //     kprintf("kernel_bootstrap_thread: %s\n", message);
-       kernel_debug_string(message);
+       kernel_debug_string_simple(message);
 }
 
 void
@@ -226,12 +229,16 @@ kernel_early_bootstrap(void)
         */
        timer_call_init();
 
+#if CONFIG_SCHED_SFI
        /*
         * Configure SFI classes
         */
        sfi_early_init();
+#endif
 }
 
+extern boolean_t IORamDiskBSDRoot(void);
+extern kern_return_t cpm_preallocate_early(void);
 
 void
 kernel_bootstrap(void)
@@ -266,26 +273,34 @@ kernel_bootstrap(void)
        machine_info.major_version = version_major;
        machine_info.minor_version = version_minor;
 
+
 #if CONFIG_TELEMETRY
        kernel_bootstrap_log("telemetry_init");
        telemetry_init();
 #endif
 
+#if CONFIG_CSR
+       kernel_bootstrap_log("csr_init");
+       csr_init();
+#endif
+
        kernel_bootstrap_log("stackshot_lock_init");    
        stackshot_lock_init();
 
        kernel_bootstrap_log("sched_init");
        sched_init();
 
-       kernel_bootstrap_log("wait_queue_bootstrap");
-       wait_queue_bootstrap();
+       kernel_bootstrap_log("waitq_bootstrap");
+       waitq_bootstrap();
 
        kernel_bootstrap_log("ipc_bootstrap");
        ipc_bootstrap();
 
 #if CONFIG_MACF
+       kernel_bootstrap_log("mac_policy_init");
        mac_policy_init();
 #endif
+
        kernel_bootstrap_log("ipc_init");
        ipc_init();
 
@@ -311,8 +326,8 @@ kernel_bootstrap(void)
         *      Initialize the IPC, task, and thread subsystems.
         */
 #if CONFIG_COALITIONS
-       kernel_bootstrap_log("coalition_init");
-       coalition_init();
+       kernel_bootstrap_log("coalitions_init");
+       coalitions_init();
 #endif
 
        kernel_bootstrap_log("task_init");
@@ -327,17 +342,15 @@ kernel_bootstrap(void)
        atm_init();
 #endif
 
-#if CONFIG_CSR
-       kernel_bootstrap_log("csr_init");
-       csr_init();
-#endif
-
 #if CONFIG_BANK
        /* Initialize the BANK Manager. */
        kernel_bootstrap_log("bank_init");
        bank_init();
 #endif
        
+       /* initialize the corpse config based on boot-args */
+       corpses_init();
+
        /*
         *      Create a kernel thread to execute the kernel bootstrap.
         */
@@ -347,6 +360,7 @@ kernel_bootstrap(void)
        if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);
 
        thread->state = TH_RUN;
+       thread->last_made_runnable_time = mach_absolute_time();
        thread_deallocate(thread);
 
        kernel_bootstrap_log("load_context - done");
@@ -358,6 +372,7 @@ int kth_started = 0;
 
 vm_offset_t vm_kernel_addrperm;
 vm_offset_t buf_kernel_addrperm;
+vm_offset_t vm_kernel_addrperm_ext;
 
 /*
  * Now running in a thread.  Kick off other services,
@@ -450,10 +465,6 @@ kernel_bootstrap_thread(void)
        alternate_debugger_init();
 #endif
 
-#if CONFIG_COUNTERS
-       pmc_bootstrap();
-#endif
-
 #if KPC
        kpc_init();
 #endif
@@ -480,6 +491,11 @@ kernel_bootstrap_thread(void)
 #endif
 
 #if (defined(__i386__) || defined(__x86_64__))
+       if (kdebug_serial) {
+               new_nkdbufs = 1;
+               if (trace_typefilter == 0)
+                       trace_typefilter = 1;
+       }
        if (turn_on_log_leaks && !new_nkdbufs)
                new_nkdbufs = 200000;
        if (trace_typefilter)
@@ -538,14 +554,16 @@ kernel_bootstrap_thread(void)
        mac_policy_initmach();
 #endif
 
+#if CONFIG_SCHED_SFI
        kernel_bootstrap_log("sfi_init");
        sfi_init();
+#endif
 
        /*
-        * Initialize the global used for permuting kernel
+        * Initialize the globals used for permuting kernel
         * addresses that may be exported to userland as tokens
-        * using VM_KERNEL_ADDRPERM(). Force the random number
-        * to be odd to avoid mapping a non-zero
+        * using VM_KERNEL_ADDRPERM()/VM_KERNEL_ADDRPERM_EXTERNAL().
+        * Force the random number to be odd to avoid mapping a non-zero
         * word-aligned address to zero via addition.
         * Note: at this stage we can use the cryptographically secure PRNG
         * rather than early_random().
@@ -554,6 +572,12 @@ kernel_bootstrap_thread(void)
        vm_kernel_addrperm |= 1;
        read_random(&buf_kernel_addrperm, sizeof(buf_kernel_addrperm));
        buf_kernel_addrperm |= 1;
+       read_random(&vm_kernel_addrperm_ext, sizeof(vm_kernel_addrperm_ext));
+       vm_kernel_addrperm_ext |= 1;
+
+       vm_set_restrictions();
+
+
 
        /*
         *      Start the user bootstrap.
@@ -571,7 +595,7 @@ kernel_bootstrap_thread(void)
        serial_keyboard_init();         /* Start serial keyboard if wanted */
 
        vm_page_init_local_q();
-       
+
        thread_bind(PROCESSOR_NULL);
 
        /*