From 7d76a64bd922ca34dc17224001d7e505c914ba6c Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 4 Aug 2021 22:00:04 +0200 Subject: [PATCH] Fix stack overflow reporting from native code (#56774) * Fix stack overflow reporting from native code When stack overflow happens in native code, the stack walker is unable to walk the stack and we end up reporting no call stack at all. This change fixes it by first unwinding the exception context to the first managed frame and then letting the stack walker to walk the frames. * Revert behavior for the Windows x86 case --- src/coreclr/vm/eepolicy.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/vm/eepolicy.cpp b/src/coreclr/vm/eepolicy.cpp index 9f1f962..b908456 100644 --- a/src/coreclr/vm/eepolicy.cpp +++ b/src/coreclr/vm/eepolicy.cpp @@ -629,7 +629,13 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalStackOverflow(EXCEPTION_POINTERS *pE if (pExceptionInfo && pExceptionInfo->ContextRecord) { GCX_COOP(); +#if defined(TARGET_X86) && defined(TARGET_WINDOWS) + // For Windows x86, we don't have a reliable method to unwind to the first managed call frame, + // so we handle at least the cases when the stack overflow happens in JIT helpers AdjustContextForJITHelpers(pExceptionInfo->ExceptionRecord, pExceptionInfo->ContextRecord); +#else + Thread::VirtualUnwindToFirstManagedCallFrame(pExceptionInfo->ContextRecord); +#endif fef.InitAndLink(pExceptionInfo->ContextRecord); } -- 2.7.4