VS has mentioned that when they have an AV come through their reflection invoked...
authorGaurav Khanna <gkhanna@microsoft.com>
Fri, 25 Sep 2015 19:31:07 +0000 (12:31 -0700)
committerMatt Ellis <matell@microsoft.com>
Sat, 26 Sep 2015 00:24:01 +0000 (17:24 -0700)
This change adds support for an opt-in flag that will trigger failfast in Reflection codepath inface of an unhandled CSE.

[tfs-changeset: 1529878]

Commit migrated from https://github.com/dotnet/coreclr/commit/f0c1382fd5c65e44585b84a4bf3dd8ec86d73c6c

src/coreclr/src/inc/clrconfigvalues.h
src/coreclr/src/vm/excep.cpp

index 391f127..221334d 100644 (file)
@@ -293,6 +293,7 @@ CONFIG_STRING_INFO(INTERNAL_TestHooks, W("TestHooks"), "Used by tests to get tes
 CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_AssertOnFailFast, W("AssertOnFailFast"), "")
 RETAIL_CONFIG_DWORD_INFO_EX(UNSUPPORTED_legacyCorruptedStateExceptionsPolicy, W("legacyCorruptedStateExceptionsPolicy"), 0, "Enabled Pre-V4 CSE behaviour", CLRConfig::FavorConfigFile)
 CONFIG_DWORD_INFO_EX(INTERNAL_SuppressLostExceptionTypeAssert, W("SuppressLostExceptionTypeAssert"), 0, "", CLRConfig::REGUTIL_default)
+RETAIL_CONFIG_DWORD_INFO_EX(UNSUPPORTED_FailFastOnCorruptedStateException, W("FailFastOnCorruptedStateException"), 0, "Failfast if a CSE is encountered", CLRConfig::FavorConfigFile)
 
 // 
 // Garbage collector
index a5aed2d..7b4899d 100644 (file)
@@ -8948,6 +8948,33 @@ LONG ReflectionInvocationExceptionFilter(
     }
 #endif // !FEATURE_PAL
 
+    // If the application has opted into triggering a failfast when a CorruptedStateException enters the Reflection system,
+    // then do the needful.
+    if (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_FailFastOnCorruptedStateException) == 1)
+    {
+         // Get the thread and the managed exception object - they must exist at this point
+        Thread *pCurThread = GetThread();
+        _ASSERTE(pCurThread != NULL);
+
+        // Get the thread exception state
+        ThreadExceptionState * pCurTES = pCurThread->GetExceptionState();
+        _ASSERTE(pCurTES != NULL);
+
+        // Get the exception tracker for the current exception
+#ifdef WIN64EXCEPTIONS
+        PTR_ExceptionTracker pEHTracker = pCurTES->GetCurrentExceptionTracker();
+#elif _TARGET_X86_
+        PTR_ExInfo pEHTracker = pCurTES->GetCurrentExceptionTracker();
+#else // !(_WIN64 || _TARGET_X86_)
+#error Unsupported platform
+#endif // _WIN64
+        
+        if (pEHTracker->GetCorruptionSeverity() == ProcessCorrupting)
+        {
+            EEPolicy::HandleFatalError(COR_E_FAILFAST, reinterpret_cast<UINT_PTR>(pExceptionInfo->ExceptionRecord->ExceptionAddress), NULL, pExceptionInfo);
+        }
+    }
+
     return ret;
 } // LONG ReflectionInvocationExceptionFilter()