Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/ICodeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ class ICodeManager
virtual PTR_VOID GetFramePointer(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet) PURE_VIRTUAL

#ifdef TARGET_X86
virtual uintptr_t GetResumeSp(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet) PURE_VIRTUAL
#endif

virtual void EnumGcRefs(MethodInfo * pMethodInfo,
PTR_VOID safePointAddress,
REGDISPLAY * pRegisterSet,
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,13 @@ void StackFrameIterator::CalculateCurrentMethodState()
m_effectiveSafePointAddress = m_ControlPC;
m_FramePointer = GetCodeManager()->GetFramePointer(&m_methodInfo, &m_RegDisplay);

#ifdef TARGET_X86
if (m_dwFlags & UseResumeSp)
{
m_RegDisplay.SP = GetCodeManager()->GetResumeSp(&m_methodInfo, &m_RegDisplay);
}
#endif

m_dwFlags |= MethodStateCalculated;
}

Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/StackFrameIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ class StackFrameIterator
// When encountering a reverse P/Invoke, unwind directly to the P/Invoke frame using the saved transition frame.
SkipNativeFrames = 0x80,

// Set SP to an address that is valid for funclet resumption (x86 only)
UseResumeSp = 0x100,

GcStackWalkFlags = (CollapseFunclets | RemapHardwareFaultsToSafePoint | SkipNativeFrames),
EHStackWalkFlags = ApplyReturnAddressAdjustment,
EHStackWalkFlags = (ApplyReturnAddressAdjustment | UseResumeSp),
StackTraceStackWalkFlags = GcStackWalkFlags
};

Expand Down
36 changes: 34 additions & 2 deletions src/coreclr/nativeaot/Runtime/windows/CoffNativeCodeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ static PTR_VOID GetUnwindDataBlob(TADDR moduleBase, PTR_RUNTIME_FUNCTION pRuntim
#endif
}


CoffNativeCodeManager::CoffNativeCodeManager(TADDR moduleBase,
PTR_VOID pvManagedCodeStartRange, uint32_t cbManagedCodeRange,
PTR_RUNTIME_FUNCTION pRuntimeFunctionTable, uint32_t nRuntimeFunctionTable,
Expand Down Expand Up @@ -323,7 +322,7 @@ bool CoffNativeCodeManager::IsFilter(MethodInfo * pMethInfo)
}

PTR_VOID CoffNativeCodeManager::GetFramePointer(MethodInfo * pMethInfo,
REGDISPLAY * pRegisterSet)
REGDISPLAY * pRegisterSet)
{
CoffNativeMethodInfo * pMethodInfo = (CoffNativeMethodInfo *)pMethInfo;

Expand All @@ -341,6 +340,39 @@ PTR_VOID CoffNativeCodeManager::GetFramePointer(MethodInfo * pMethInfo,
return NULL;
}

#ifdef TARGET_X86
uintptr_t CoffNativeCodeManager::GetResumeSp(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet)
{
PTR_uint8_t gcInfo;
uint32_t codeOffset = GetCodeOffset(pMethodInfo, (PTR_VOID)pRegisterSet->IP, &gcInfo);

hdrInfo infoBuf;
size_t infoSize = DecodeGCHdrInfo(GCInfoToken(gcInfo), codeOffset, &infoBuf);
PTR_CBYTE table = gcInfo + infoSize;

_ASSERTE(infoBuf.epilogOffs == hdrInfo::NOT_IN_EPILOG && infoBuf.prologOffs == hdrInfo::NOT_IN_PROLOG);

bool isESPFrame = !infoBuf.ebpFrame && !infoBuf.doubleAlign;

CoffNativeMethodInfo * pNativeMethodInfo = (CoffNativeMethodInfo *)pMethodInfo;
if (pNativeMethodInfo->mainRuntimeFunction != pNativeMethodInfo->runtimeFunction)
{
// Treat funclet's frame as ESP frame
isESPFrame = true;
}

if (isESPFrame)
{
const uintptr_t curESP = pRegisterSet->SP;
return curESP + GetPushedArgSize(&infoBuf, table, codeOffset);
}

const uintptr_t curEBP = pRegisterSet->GetFP();
return curEBP - infoBuf.stackSize + sizeof(int);
}
#endif // TARGET_X86

uint32_t CoffNativeCodeManager::GetCodeOffset(MethodInfo* pMethodInfo, PTR_VOID address, /*out*/ PTR_uint8_t* gcInfo)
{
CoffNativeMethodInfo * pNativeMethodInfo = (CoffNativeMethodInfo *)pMethodInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class CoffNativeCodeManager : public ICodeManager
PTR_VOID GetFramePointer(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet);

#ifdef TARGET_X86
uintptr_t GetResumeSp(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet);
#endif

uint32_t GetCodeOffset(MethodInfo * pMethodInfo, PTR_VOID address, /*out*/ PTR_uint8_t* gcInfo);

bool IsSafePoint(PTR_VOID pvAddress);
Expand Down