[KDBG] Don't bring down the kernel either when int2c-ing from user mode
[reactos.git] / reactos / ntoskrnl / kdbg / kdb.c
index b13384c..3da12cc 100644 (file)
@@ -57,26 +57,27 @@ extern BOOLEAN KdbpBugCheckRequested;
 static KDB_ENTER_CONDITION KdbEnterConditions[][2] =
 {
     /* First chance       Last chance */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Zero devide */
-    { KdbEnterFromKmode,  KdbDoNotEnter },       /* Debug trap */
-    { KdbDoNotEnter,      KdbEnterAlways },      /* NMI */
-    { KdbEnterFromKmode,  KdbDoNotEnter },       /* INT3 */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Overflow */
-    { KdbDoNotEnter,      KdbEnterFromKmode },
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Invalid opcode */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* No math coprocessor fault */
-    { KdbEnterAlways,     KdbEnterAlways },
-    { KdbEnterAlways,     KdbEnterAlways },
-    { KdbDoNotEnter,      KdbEnterFromKmode },
-    { KdbDoNotEnter,      KdbEnterFromKmode },
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Stack fault */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* General protection fault */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Page fault */
-    { KdbEnterAlways,     KdbEnterAlways },      /* Reserved (15) */
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* FPU fault */
-    { KdbDoNotEnter,      KdbEnterFromKmode },
-    { KdbDoNotEnter,      KdbEnterFromKmode },
-    { KdbDoNotEnter,      KdbEnterFromKmode },   /* SIMD fault */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 0: Zero divide */
+    { KdbEnterFromKmode,  KdbDoNotEnter },       /* 1: Debug trap */
+    { KdbDoNotEnter,      KdbEnterAlways },      /* 2: NMI */
+    { KdbEnterFromKmode,  KdbDoNotEnter },       /* 3: INT3 */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 4: Overflow */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 5: BOUND range exceeded */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 6: Invalid opcode */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 7: No math coprocessor fault */
+    { KdbEnterAlways,     KdbEnterAlways },      /* 8: Double Fault */
+    { KdbEnterAlways,     KdbEnterAlways },      /* 9: Unknown(9) */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 10: Invalid TSS */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 11: Segment Not Present */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 12: Stack fault */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 13: General protection fault */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 14: Page fault */
+    { KdbEnterAlways,     KdbEnterAlways },      /* 15: Reserved (15) */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 16: FPU fault */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 17: Alignment Check */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 18: Machine Check */
+    { KdbDoNotEnter,      KdbEnterFromKmode },   /* 19: SIMD fault */
+    { KdbEnterFromKmode,  KdbDoNotEnter },       /* 20: Assertion failure */
     { KdbDoNotEnter,      KdbEnterFromKmode }    /* Last entry: used for unknown exceptions */
 };
 
@@ -102,7 +103,8 @@ static const CHAR *ExceptionNrToString[] =
     "Math Fault",
     "Alignment Check",
     "Machine Check",
-    "SIMD Fault"
+    "SIMD Fault",
+    "Assertion Failure"
 };
 
 ULONG
@@ -1234,7 +1236,7 @@ KdbpCallMainLoop(VOID)
  * Disables interrupts, releases display ownership, ...
  */
 static VOID
-KdbpInternalEnter()
+KdbpInternalEnter(VOID)
 {
     PETHREAD Thread;
     PVOID SavedInitialStack, SavedStackBase, SavedKernelStack;
@@ -1320,6 +1322,9 @@ KdbpGetExceptionNumberFromStatus(
         case STATUS_FLOAT_MULTIPLE_TRAPS:
             Ret = 18;
             break;
+        case STATUS_ASSERTION_FAILURE:
+            Ret = 20;
+            break;
 
         default:
             Ret = RTL_NUMBER_OF(KdbEnterConditions) - 1;
@@ -1366,8 +1371,12 @@ KdbEnterDebuggerException(
     KdbCurrentProcess = PsGetCurrentProcess();
 
     /* Set continue type to kdContinue for single steps and breakpoints */
-    if (ExceptionCode == STATUS_SINGLE_STEP || ExceptionCode == STATUS_BREAKPOINT)
+    if (ExceptionCode == STATUS_SINGLE_STEP ||
+        ExceptionCode == STATUS_BREAKPOINT ||
+        ExceptionCode == STATUS_ASSERTION_FAILURE)
+    {
         ContinueType = kdContinue;
+    }
 
     /* Check if we should handle the exception. */
     /* FIXME - won't get all exceptions here :( */
@@ -1662,7 +1671,7 @@ KdbEnterDebuggerException(
     /* Decrement the entry count */
     InterlockedDecrement(&KdbEntryCount);
 
-    /* HACK: Raise back to old IRWL */
+    /* HACK: Raise back to old IRQL */
     KeRaiseIrql(OldIrql, &OldIrql);
 
     /* Leave critical section */
@@ -1705,30 +1714,29 @@ INIT_FUNCTION
 KdbpGetCommandLineSettings(
     PCHAR p1)
 {
-    PCHAR p2;
+#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
 
-    while (p1 && (p2 = strchr(p1, ' ')))
+    while (p1 && (p1 = strchr(p1, ' ')))
     {
-        p2 += 2;
+        /* Skip other spaces */
+        while (*p1 == ' ') ++p1;
 
-        if (!_strnicmp(p2, "KDSERIAL", 8))
+        if (!_strnicmp(p1, "KDSERIAL", CONST_STR_LEN("KDSERIAL")))
         {
-            p2 += 8;
+            p1 += CONST_STR_LEN("KDSERIAL");
             KdbDebugState |= KD_DEBUG_KDSERIAL;
             KdpDebugMode.Serial = TRUE;
         }
-        else if (!_strnicmp(p2, "KDNOECHO", 8))
+        else if (!_strnicmp(p1, "KDNOECHO", CONST_STR_LEN("KDNOECHO")))
         {
-            p2 += 8;
+            p1 += CONST_STR_LEN("KDNOECHO");
             KdbDebugState |= KD_DEBUG_KDNOECHO;
         }
-        else if (!_strnicmp(p2, "FIRSTCHANCE", 11))
+        else if (!_strnicmp(p1, "FIRSTCHANCE", CONST_STR_LEN("FIRSTCHANCE")))
         {
-            p2 += 11;
+            p1 += CONST_STR_LEN("FIRSTCHANCE");
             KdbpSetEnterCondition(-1, TRUE, KdbEnterAlways);
         }
-
-        p1 = p2;
     }
 }