Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
int st;
unw_context_t unwContext;
unw_cursor_t cursor;
#if defined(__APPLE__)
DWORD64 curPc;
#endif

#if UNWIND_CONTEXT_IS_UCONTEXT_T
WinContextToUnwindContext(context, &unwContext);
Expand All @@ -147,14 +150,33 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
WinContextToUnwindCursor(context, &cursor);
#endif

#if defined(__APPLE__)
// OSX appears to do two different things when unwinding
// 1: If it reaches where it cannot unwind anymore, say a
// managed frame. It wil return 0, but also update the $pc
// 2: If it unwinds all the way to _start it will return
// 0 from the step, but $pc will stay the same.
// The behaviour of libunwind from nongnu.org is to null the PC
// So we bank the original PC here, so we can compare it after
// the step
curPc = context->Rip;
#endif

st = unw_step(&cursor);
if (st < 0)
{
return FALSE;
}

// Update the passed in windows context to reflect the unwind
//
UnwindContextToWinContext(&cursor, context);
#if defined(__APPLE__)
if (st == 0 && context->Rip == curPc)
{
context->Rip = 0;
}
#endif

if (contextPointers != NULL)
{
Expand Down