From 232e728c2d03ebfc57772407c09fd50227e05fde Mon Sep 17 00:00:00 2001 From: Gaurav Khanna Date: Fri, 25 Sep 2015 12:31:07 -0700 Subject: [PATCH] VS has mentioned that when they have an AV come through their reflection invoked code, they endup getting TargetInvocationException that is not actionable and also does not help in the Watson bucketing for the issue. To address this, they would like an opt-in flag to force a failfast when a CSE remains unhandled within reflection invocation. 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 | 1 + src/coreclr/src/vm/excep.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/coreclr/src/inc/clrconfigvalues.h b/src/coreclr/src/inc/clrconfigvalues.h index 391f127..221334d 100644 --- a/src/coreclr/src/inc/clrconfigvalues.h +++ b/src/coreclr/src/inc/clrconfigvalues.h @@ -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 diff --git a/src/coreclr/src/vm/excep.cpp b/src/coreclr/src/vm/excep.cpp index a5aed2d..7b4899d 100644 --- a/src/coreclr/src/vm/excep.cpp +++ b/src/coreclr/src/vm/excep.cpp @@ -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(pExceptionInfo->ExceptionRecord->ExceptionAddress), NULL, pExceptionInfo); + } + } + return ret; } // LONG ReflectionInvocationExceptionFilter() -- 2.7.4