[libunwind] [SEH] Initialize _msContext with RtlCaptureContext
authorMartin Storsjö <martin@martin.st>
Tue, 4 Apr 2023 20:28:49 +0000 (20:28 +0000)
committerMartin Storsjö <martin@martin.st>
Thu, 13 Apr 2023 09:03:35 +0000 (12:03 +0300)
commitebae5622d11655feaa74e64151067897153f9c71
tree1a80c4c90587cf11eaa499df714e6f2ad4f6cd17
parent5b9d969e7c07d720080eac386467c1112c45a76f
[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
libunwind/src/UnwindCursor.hpp