Fix missing exception corruption severity setting
authorJan Vorlicek <janvorli@microsoft.com>
Mon, 15 Feb 2016 20:16:35 +0000 (21:16 +0100)
committerJan Vorlicek <janvorli@microsoft.com>
Tue, 16 Feb 2016 19:55:08 +0000 (20:55 +0100)
This change fixes missing exception corruption severity for exceptions
that were thrown by native code but didn't pass through any managed
frames yet.

We have seen assert in the RaiseTheException function when an exception
thrown from native code is caught in native code without passing through
any managed frames and then it is being thrown in a wrapper TargetInvocationException.

src/vm/exceptionhandling.cpp

index 408b4fadb41cdc6b290248fb55e70ca90f1b25db..6f4ddec53eb6b39f0e5b6a1ab9234f6280d39b2f 100644 (file)
@@ -4691,6 +4691,30 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex)
     }
     while (true);
 
+    // Ensure that the corruption severity is set for exceptions that didn't pass through managed frames
+    // yet and so there is no exception tracker.
+    if (ex.IsFirstPass())
+    {
+        // Get the thread and the thread exception state - they must exist at this point
+        Thread *pCurThread = GetThread();
+        _ASSERTE(pCurThread != NULL);
+
+        ThreadExceptionState * pCurTES = pCurThread->GetExceptionState();
+        _ASSERTE(pCurTES != NULL);
+
+        ExceptionTracker* pEHTracker = pCurTES->GetCurrentExceptionTracker();
+        if (pEHTracker == NULL)
+        {
+            CorruptionSeverity severity = NotCorrupting;
+            if (CEHelper::IsProcessCorruptedStateException(ex.ExceptionRecord.ExceptionCode))
+            {
+                severity = ProcessCorrupting;
+            }
+
+            pCurTES->SetLastActiveExceptionCorruptionSeverity(severity);
+        }
+    }
+
     throw ex;
 }