Fix stack overflow reporting from native code (#56774)
authorJan Vorlicek <jan.vorlicek@volny.cz>
Wed, 4 Aug 2021 20:00:04 +0000 (22:00 +0200)
committerGitHub <noreply@github.com>
Wed, 4 Aug 2021 20:00:04 +0000 (22:00 +0200)
* 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

index 9f1f962..b908456 100644 (file)
@@ -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);
     }