Skip to content

Commit

Permalink
Fix contract violation when reporting tailcall stub loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbotsch committed Apr 19, 2021
1 parent e98d043 commit cf4d578
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void ScanTailCallArgBufferRoots(Thread* pThread, promote_func* fn, ScanCo
const PortableTailCallFrame* frame = tls->GetFrame();
if (frame->NextCall != NULL)
{
MethodDesc* pMD = Entry2MethodDesc((PCODE)frame->NextCall, NULL);
MethodDesc* pMD = NonVirtualEntry2MethodDesc((PCODE)frame->NextCall);
if (pMD != NULL)
GcReportLoaderAllocator(fn, sc, pMD->GetLoaderAllocator());
}
Expand Down
44 changes: 28 additions & 16 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,31 @@ PCODE MethodDesc::GetCallTarget(OBJECTREF* pThisObj, TypeHandle ownerType)
return pTarget;
}

MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END

RangeSection* pRS = ExecutionManager::FindCodeRange(entryPoint, ExecutionManager::GetScanFlags());
if (pRS == NULL)
return NULL;

MethodDesc* pMD;
if (pRS->pjit->JitCodeToMethodInfo(pRS, entryPoint, &pMD, NULL))
return pMD;

if (pRS->pjit->GetStubCodeBlockKind(pRS, entryPoint) == STUB_CODE_BLOCK_PRECODE)
return MethodDesc::GetMethodDescFromStubAddr(entryPoint);

// We should never get here
_ASSERTE(!"NonVirtualEntry2MethodDesc failed for RangeSection");
return NULL;
}

//*******************************************************************************
// convert an entry point into a method desc
MethodDesc* Entry2MethodDesc(PCODE entryPoint, MethodTable *pMT)
Expand All @@ -2242,27 +2267,14 @@ MethodDesc* Entry2MethodDesc(PCODE entryPoint, MethodTable *pMT)
}
CONTRACT_END

MethodDesc * pMD;

RangeSection * pRS = ExecutionManager::FindCodeRange(entryPoint, ExecutionManager::GetScanFlags());
if (pRS != NULL)
{
if (pRS->pjit->JitCodeToMethodInfo(pRS, entryPoint, &pMD, NULL))
RETURN(pMD);

if (pRS->pjit->GetStubCodeBlockKind(pRS, entryPoint) == STUB_CODE_BLOCK_PRECODE)
RETURN(MethodDesc::GetMethodDescFromStubAddr(entryPoint));

// We should never get here
_ASSERTE(!"Entry2MethodDesc failed for RangeSection");
RETURN (NULL);
}
MethodDesc* pMD = NonVirtualEntry2MethodDesc(entryPoint);
if (pMD != NULL)
RETURN(pMD);

pMD = VirtualCallStubManagerManager::Entry2MethodDesc(entryPoint, pMT);
if (pMD != NULL)
RETURN(pMD);


// Is it an FCALL?
pMD = ECall::MapTargetBackToMethod(entryPoint);
if (pMD != NULL)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,7 @@ inline MethodDescChunk *MethodDesc::GetMethodDescChunk() const
(sizeof(MethodDescChunk) + (GetMethodDescIndex() * MethodDesc::ALIGNMENT)));
}

MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint);
// convert an entry point into a MethodDesc
MethodDesc* Entry2MethodDesc(PCODE entryPoint, MethodTable *pMT);

Expand Down

0 comments on commit cf4d578

Please sign in to comment.