Skip to content

Commit

Permalink
[Support] Don't modify the current EH context during stack unwinding
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
rnk authored and zmodem committed Feb 11, 2020
1 parent 4e6ec0f commit dbe9c3a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion llvm/lib/Support/Windows/Signals.inc
Expand Up @@ -820,7 +820,13 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
<< "\n";
}

LocalPrintStackTrace(llvm::errs(), ep ? ep->ContextRecord : nullptr);
// Stack unwinding appears to modify the context. Copy it to preserve the
// caller's context.
CONTEXT ContextCopy;
if (ep)
memcpy(&ContextCopy, ep->ContextRecord, sizeof(ContextCopy));

LocalPrintStackTrace(llvm::errs(), ep ? &ContextCopy : nullptr);

return EXCEPTION_EXECUTE_HANDLER;
}
Expand Down

0 comments on commit dbe9c3a

Please sign in to comment.