Skip to content

Commit dbe9c3a

Browse files
rnkzmodem
authored andcommitted
[Support] Don't modify the current EH context during stack unwinding
Copy it instead. Otherwise, key registers (such as RBP) may get zeroed out by the stack unwinder. Fixes CrashRecoveryTest.DumpStackCleanup with MSVC in release builds. Reviewed By: stella.stamenova Differential Revision: https://reviews.llvm.org/D73809 (cherry picked from commit b074acb)
1 parent 4e6ec0f commit dbe9c3a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/lib/Support/Windows/Signals.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,13 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
820820
<< "\n";
821821
}
822822

823-
LocalPrintStackTrace(llvm::errs(), ep ? ep->ContextRecord : nullptr);
823+
// Stack unwinding appears to modify the context. Copy it to preserve the
824+
// caller's context.
825+
CONTEXT ContextCopy;
826+
if (ep)
827+
memcpy(&ContextCopy, ep->ContextRecord, sizeof(ContextCopy));
828+
829+
LocalPrintStackTrace(llvm::errs(), ep ? &ContextCopy : nullptr);
824830

825831
return EXCEPTION_EXECUTE_HANDLER;
826832
}

0 commit comments

Comments
 (0)