@@ -1194,10 +1194,26 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalStackOverflow(EXCEPTION_POINTERS *pE
11941194 UNREACHABLE ();
11951195}
11961196
1197+ #if defined(_TARGET_X86_) && defined(PLATFORM_WINDOWS)
1198+ // This noinline method is required to ensure that RtlCaptureContext captures
1199+ // the context of HandleFatalError. On x86 RtlCaptureContext will not capture
1200+ // the current method's context
1201+ // NOTE: explicitly turning off optimizations to force the compiler to spill to the
1202+ // stack and establish a stack frame. This is required to ensure that
1203+ // RtlCaptureContext captures the context of HandleFatalError
1204+ #pragma optimize("", off)
1205+ int NOINLINE WrapperClrCaptureContext (CONTEXT* context)
1206+ {
1207+ ClrCaptureContext (context);
1208+ return 0 ;
1209+ }
1210+ #pragma optimize("", on)
1211+ #endif // defined(_TARGET_X86_) && defined(PLATFORM_WINDOWS)
11971212
1198-
1199-
1200- void DECLSPEC_NORETURN EEPolicy::HandleFatalError (UINT exitCode, UINT_PTR address, LPCWSTR pszMessage /* = NULL */ , PEXCEPTION_POINTERS pExceptionInfo /* = NULL */ , LPCWSTR errorSource /* = NULL */ , LPCWSTR argExceptionString /* = NULL */ )
1213+ // This method must return a value to avoid getting non-actionable dumps on x86.
1214+ // If this method were a DECLSPEC_NORETURN then dumps would not provide the necessary
1215+ // context at the point of the failure
1216+ int NOINLINE EEPolicy::HandleFatalError (UINT exitCode, UINT_PTR address, LPCWSTR pszMessage /* = NULL */ , PEXCEPTION_POINTERS pExceptionInfo /* = NULL */ , LPCWSTR errorSource /* = NULL */ , LPCWSTR argExceptionString /* = NULL */ )
12011217{
12021218 WRAPPER_NO_CONTRACT;
12031219
@@ -1215,7 +1231,12 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalError(UINT exitCode, UINT_PTR addres
12151231 ZeroMemory (&context, sizeof (context));
12161232
12171233 context.ContextFlags = CONTEXT_CONTROL;
1234+ #if defined(_TARGET_X86_) && defined(PLATFORM_WINDOWS)
1235+ // Add a frame to ensure that the context captured is this method and not the caller
1236+ WrapperClrCaptureContext (&context);
1237+ #else // defined(_TARGET_X86_) && defined(PLATFORM_WINDOWS)
12181238 ClrCaptureContext (&context);
1239+ #endif
12191240
12201241 exceptionRecord.ExceptionCode = exitCode;
12211242 exceptionRecord.ExceptionAddress = reinterpret_cast < PVOID >(address);
@@ -1269,6 +1290,7 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalError(UINT exitCode, UINT_PTR addres
12691290 }
12701291
12711292 UNREACHABLE ();
1293+ return -1 ;
12721294}
12731295
12741296void EEPolicy::HandleExitProcessFromEscalation (EPolicyAction action, UINT exitCode)
0 commit comments