]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/debug.c
xnu-2050.7.9.tar.gz
[apple/xnu.git] / osfmk / kern / debug.c
index 1dd1aee281c1fc2a990b8688d5b51c55ac52f818..b89774897c23216fa7baadc80df1900a0227a8ab 100644 (file)
@@ -55,8 +55,6 @@
  */
 
 #include <mach_assert.h>
  */
 
 #include <mach_assert.h>
-#include <mach_kdb.h>
-#include <mach_kgdb.h>
 #include <mach_kdp.h>
 
 #include <kern/cpu_number.h>
 #include <mach_kdp.h>
 
 #include <kern/cpu_number.h>
@@ -123,6 +121,9 @@ unsigned int debug_buf_size = sizeof(debug_buf);
 static char model_name[64];
 /* uuid_string_t */ char kernel_uuid[37]; 
 
 static char model_name[64];
 /* uuid_string_t */ char kernel_uuid[37]; 
 
+static spl_t panic_prologue(const char *str);
+static void panic_epilogue(spl_t s);
+
 struct pasc {
   unsigned a: 7;
   unsigned b: 7;
 struct pasc {
   unsigned a: 7;
   unsigned b: 7;
@@ -227,13 +228,10 @@ void _consume_panic_args(int a __unused, ...)
     panic("panic");
 }
 
     panic("panic");
 }
 
-void
-panic(const char *str, ...)
+static spl_t
+panic_prologue(const char *str)
 {
 {
-       va_list listp;
        spl_t   s;
        spl_t   s;
-       thread_t thread;
-       wait_queue_t wq;
 
        if (kdebug_enable) {
                ml_set_interrupts_enabled(TRUE);
 
        if (kdebug_enable) {
                ml_set_interrupts_enabled(TRUE);
@@ -255,21 +253,14 @@ panic(const char *str, ...)
 
        panic_safe();
 
 
        panic_safe();
 
-       thread = current_thread();              /* Get failing thread */
-       wq = thread->wait_queue;                /* Save the old value */
-       thread->wait_queue = NULL;              /* Clear the wait so we do not get double panics when we try locks */
-
        if( logPanicDataToScreen )
                disable_debug_output = FALSE;
                
        debug_mode = TRUE;
 
        if( logPanicDataToScreen )
                disable_debug_output = FALSE;
                
        debug_mode = TRUE;
 
-       /* panic_caller is initialized to 0.  If set, don't change it */
-       if ( ! panic_caller )
-               panic_caller = (unsigned long)(char *)__builtin_return_address(0);
-       
 restart:
        PANIC_LOCK();
 restart:
        PANIC_LOCK();
+
        if (panicstr) {
                if (cpu_number() != paniccpu) {
                        PANIC_UNLOCK();
        if (panicstr) {
                if (cpu_number() != paniccpu) {
                        PANIC_UNLOCK();
@@ -294,26 +285,19 @@ restart:
        panicwait = 1;
 
        PANIC_UNLOCK();
        panicwait = 1;
 
        PANIC_UNLOCK();
-       kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
-       if (str) {
-               va_start(listp, str);
-               _doprnt(str, &listp, consdebug_putc, 0);
-               va_end(listp);
-       }
-       kdb_printf("\n");
+       return(s);
+}
 
 
-       /*
-        * Release panicwait indicator so that other cpus may call Debugger().
-        */
-       panicwait = 0;
-       Debugger("panic");
+
+static void
+panic_epilogue(spl_t   s)
+{
        /*
         * Release panicstr so that we can handle normally other panics.
         */
        PANIC_LOCK();
        panicstr = (char *)0;
        PANIC_UNLOCK();
        /*
         * Release panicstr so that we can handle normally other panics.
         */
        PANIC_LOCK();
        panicstr = (char *)0;
        PANIC_UNLOCK();
-       thread->wait_queue = wq;        /* Restore the wait queue */
 
        if (return_on_panic) {
                panic_normal();
 
        if (return_on_panic) {
                panic_normal();
@@ -321,12 +305,65 @@ restart:
                splx(s);
                return;
        }
                splx(s);
                return;
        }
-
        kdb_printf("panic: We are hanging here...\n");
        panic_stop();
        /* NOTREACHED */
 }
 
        kdb_printf("panic: We are hanging here...\n");
        panic_stop();
        /* NOTREACHED */
 }
 
+void
+panic(const char *str, ...)
+{
+       va_list listp;
+       spl_t   s;
+
+       /* panic_caller is initialized to 0.  If set, don't change it */
+       if ( ! panic_caller )
+               panic_caller = (unsigned long)(char *)__builtin_return_address(0);
+       
+       s = panic_prologue(str);
+       kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
+       if (str) {
+               va_start(listp, str);
+               _doprnt(str, &listp, consdebug_putc, 0);
+               va_end(listp);
+       }
+       kdb_printf("\n");
+
+       /*
+        * Release panicwait indicator so that other cpus may call Debugger().
+        */
+       panicwait = 0;
+       Debugger("panic");
+       panic_epilogue(s);
+}
+
+void
+panic_context(unsigned int reason, void *ctx, const char *str, ...)
+{
+       va_list listp;
+       spl_t   s;
+
+       /* panic_caller is initialized to 0.  If set, don't change it */
+       if ( ! panic_caller )
+               panic_caller = (unsigned long)(char *)__builtin_return_address(0);
+       
+       s = panic_prologue(str);
+       kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
+       if (str) {
+               va_start(listp, str);
+               _doprnt(str, &listp, consdebug_putc, 0);
+               va_end(listp);
+       }
+       kdb_printf("\n");
+
+       /*
+        * Release panicwait indicator so that other cpus may call Debugger().
+        */
+       panicwait = 0;
+       DebuggerWithContext(reason, ctx, "panic");
+       panic_epilogue(s);
+}
+
 void
 log(__unused int level, char *fmt, ...)
 {
 void
 log(__unused int level, char *fmt, ...)
 {
@@ -446,6 +483,15 @@ static void panic_display_kernel_uuid(void) {
                kdb_printf("Kernel UUID: %s\n", tmp_kernel_uuid);
 }
 
                kdb_printf("Kernel UUID: %s\n", tmp_kernel_uuid);
 }
 
+static void panic_display_kernel_aslr(void) {
+#if    defined(__x86_64__)
+       if (vm_kernel_slide) {
+               kdb_printf("Kernel slide:     0x%016lx\n", vm_kernel_slide);
+               kdb_printf("Kernel text base: %p\n", (void *) vm_kernel_stext);
+       }
+#endif
+}
+
 static void panic_display_uptime(void) {
        uint64_t        uptime;
        absolutetime_to_nanoseconds(mach_absolute_time(), &uptime);
 static void panic_display_uptime(void) {
        uint64_t        uptime;
        absolutetime_to_nanoseconds(mach_absolute_time(), &uptime);
@@ -469,6 +515,7 @@ __private_extern__ void panic_display_system_configuration(void) {
                    (osversion[0] != 0) ? osversion : "Not yet set");
                kdb_printf("\nKernel version:\n%s\n",version);
                panic_display_kernel_uuid();
                    (osversion[0] != 0) ? osversion : "Not yet set");
                kdb_printf("\nKernel version:\n%s\n",version);
                panic_display_kernel_uuid();
+               panic_display_kernel_aslr();
                panic_display_pal_info();
                panic_display_model_name();
                panic_display_uptime();
                panic_display_pal_info();
                panic_display_model_name();
                panic_display_uptime();