[llvm] b074acb - [Support] Don't modify the current EH context during stack unwinding

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 17:05:31 PST 2020


Author: Reid Kleckner
Date: 2020-01-31T17:04:01-08:00
New Revision: b074acb82f7e75a189fa7933b09627241b166121

URL: https://github.com/llvm/llvm-project/commit/b074acb82f7e75a189fa7933b09627241b166121
DIFF: https://github.com/llvm/llvm-project/commit/b074acb82f7e75a189fa7933b09627241b166121.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Support/Windows/Signals.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc
index a5c833d30cde..e5f36bc4b0e4 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -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;
 }


        


More information about the llvm-commits mailing list