Skip to content
Open
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
21 changes: 18 additions & 3 deletions src/coreclr/vm/wasm/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ TADDR GetWasmVirtualIPFromStackPointer(TADDR sp)
}
}

static void WasmUnwindStackFrameCore(TADDR* pSP, TADDR* pIP, UINT_PTR ImageBase, PRUNTIME_FUNCTION FunctionEntry)
static void WasmUnwindStackFrameCore(TADDR* pSP, TADDR* pIP, UINT_PTR ImageBase, PRUNTIME_FUNCTION FunctionEntry, bool callerIsNative = false)
{
TADDR sp = *pSP;
TADDR fp = GetWasmFramePointerFromStackPointer_Internal(sp);
Expand All @@ -1774,7 +1774,9 @@ static void WasmUnwindStackFrameCore(TADDR* pSP, TADDR* pIP, UINT_PTR ImageBase,
{
PTR_BYTE pUnwindData = dac_cast<PTR_BYTE>(FunctionEntry->UnwindData + ImageBase);
*pSP = fp + DecodeULEB128AsU32(&pUnwindData); // Unwind the frame pointer to the callers stack pointer
*pIP = GetWasmVirtualIPFromStackPointer(*pSP);
// A reverse-pinvoke frame's caller is native, not an R2R shadow frame; leave the IP unset so the walk
// continues via the Frame chain instead of reading the native caller SP as a shadow frame.
*pIP = callerIsNative ? 0 : GetWasmVirtualIPFromStackPointer(*pSP);
}
}

Expand Down Expand Up @@ -1846,7 +1848,20 @@ RtlVirtualUnwind (
*HandlerData = 0;
*EstablisherFrame = 0;

WasmUnwindStackFrameCore((TADDR*)&ContextRecord->InterpreterSP, (TADDR*)&ContextRecord->InterpreterIP, ImageBase, FunctionEntry);
// Reverse-pinvoke frames (UnmanagedCallersOnly methods and reverse P/Invoke IL stubs) are called from
// native code, so terminate the R2R walk at this boundary.
bool callerIsNative = false;
{
EECodeInfo codeInfo;
codeInfo.Init((PCODE)ControlPc);
if (codeInfo.IsValid())
Comment thread
pavelsavara marked this conversation as resolved.
{
GcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR);
callerIsNative = gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME;
}
}

WasmUnwindStackFrameCore((TADDR*)&ContextRecord->InterpreterSP, (TADDR*)&ContextRecord->InterpreterIP, ImageBase, FunctionEntry, callerIsNative);

if (ContextRecord->InterpreterSP != 0)
{
Expand Down
Loading