[libunwind] ebae562 - [libunwind] [SEH] Initialize _msContext with RtlCaptureContext

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 13 02:06:30 PDT 2023


Author: Martin Storsjö
Date: 2023-04-13T12:03:35+03:00
New Revision: ebae5622d11655feaa74e64151067897153f9c71

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

LOG: [libunwind] [SEH] Initialize _msContext with RtlCaptureContext

When we initialize the UnwindCursor (unw_cursor_t) based on
an existing Registers object (unw_context_t), we only initialize
a subset of the class.

Fill the struct properly for the current thread with RtlCaptureContext,
followed by overwriting of the subset of registers that we do have
available in the Registers class.

One might think that it's enough to initialize specifically the
registers that we signal availability for with ContextFlags,
however in practice, that's not enough.

This fixes crashes when restoring the context via RtlRestoreContext
(via UnwindCursor::jumpto), via __unw_resume.

Differential Revision: https://reviews.llvm.org/D147636

Added: 
    

Modified: 
    libunwind/src/UnwindCursor.hpp

Removed: 
    


################################################################################
diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 9ea0cf1465e8..8b6451c68b46 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -579,6 +579,7 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
   _dispContext.HistoryTable = &_histTable;
   // Initialize MS context from ours.
   R r(context);
+  RtlCaptureContext(&_msContext);
   _msContext.ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;
 #if defined(_LIBUNWIND_TARGET_X86_64)
   _msContext.Rax = r.getRegister(UNW_X86_64_RAX);


        


More information about the cfe-commits mailing list