Skip to content

Commit

Permalink
Interpreter Fixes (dotnet#108485)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Robinson <[email protected]>
  • Loading branch information
cshung and AaronRobinsonMSFT authored Oct 3, 2024
1 parent 49399d9 commit 7a4678f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/coreclr/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9302,7 +9302,7 @@ void Interpreter::DoCallWork(bool virtualCall, void* thisArg, CORINFO_RESOLVED_T
// Hardware intrinsics are recognized by name.
const char* namespaceName = NULL;
const char* className = NULL;
const char* methodName = getMethodName(&m_interpCeeInfo, (CORINFO_METHOD_HANDLE)methToCall, &className, &namespaceName, NULL);
const char* methodName = getMethodName(&m_interpCeeInfo, (CORINFO_METHOD_HANDLE)methToCall, &className, &namespaceName);
if (
(strcmp(namespaceName, "System.Runtime.Intrinsics") == 0 ||
#if defined(TARGET_X86) || defined(TARGET_AMD64)
Expand Down Expand Up @@ -11943,7 +11943,7 @@ Interpreter::InterpreterNamedIntrinsics Interpreter::getNamedIntrinsicID(CEEInfo

const char* namespaceName = NULL;
const char* className = NULL;
const char* methodName = getMethodName(info, (CORINFO_METHOD_HANDLE)methodHnd, &className, &namespaceName, NULL);
const char* methodName = getMethodName(info, (CORINFO_METHOD_HANDLE)methodHnd, &className, &namespaceName);

if (strncmp(namespaceName, "System", 6) == 0)
{
Expand Down Expand Up @@ -12010,7 +12010,7 @@ Interpreter::InterpreterNamedIntrinsics Interpreter::getNamedIntrinsicID(CEEInfo

// Simple version of getMethodName which supports IL Stubs such as IL_STUB_PInvoke additionally.
// Also see getMethodNameFromMetadata and printMethodName in corinfo.h
const char* Interpreter::getMethodName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd, const char** className, const char** namespaceName, const char **enclosingClassName)
const char* Interpreter::getMethodName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd, const char** className, const char** namespaceName)
{
MethodDesc *pMD = GetMethod(hnd);
if (pMD->IsILStub())
Expand All @@ -12022,7 +12022,7 @@ const char* Interpreter::getMethodName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd,
return pMD->GetName();
}

return info->getMethodNameFromMetadata(hnd, className, namespaceName, enclosingClassName);
return info->getMethodNameFromMetadata(hnd, className, namespaceName, nullptr, 0);
}

const char* eeGetMethodFullName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd, const char** clsName)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ class Interpreter
NI_System_Threading_Interlocked_ExchangeAdd,
};
static InterpreterNamedIntrinsics getNamedIntrinsicID(CEEInfo* info, CORINFO_METHOD_HANDLE methodHnd);
static const char* getMethodName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd, const char** className, const char** namespaceName = NULL, const char **enclosingClassName = NULL);
static const char* getMethodName(CEEInfo* info, CORINFO_METHOD_HANDLE hnd, const char** className, const char** namespaceName = NULL);

private:
// Architecture-dependent helpers.
Expand Down
47 changes: 25 additions & 22 deletions src/coreclr/vm/stublink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,14 +1308,17 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
// make that INT32_MAX.
//

StubUnwindInfoHeader *pHeader = pStubRW->GetUnwindInfoHeader();
_ASSERTE(IS_ALIGNED(pHeader, sizeof(void*)));
StubUnwindInfoHeader *pHeaderRW = pStubRW->GetUnwindInfoHeader();
StubUnwindInfoHeader *pHeaderRX = pStubRX->GetUnwindInfoHeader();
_ASSERTE(IS_ALIGNED(pHeaderRW, sizeof(void*)));

BYTE *pbBaseAddress = pbRegionBaseAddress;
BYTE *pbBaseAddressRX = pbRegionBaseAddress;
BYTE *pbBaseAddressRW = (BYTE*)((uint64_t)pbRegionBaseAddress + (uint64_t)pHeaderRW - (uint64_t)pHeaderRX);

while ((size_t)((BYTE*)pHeader - pbBaseAddress) > MaxSegmentSize)
while ((size_t)((BYTE*)pHeaderRX - pbBaseAddressRX) > MaxSegmentSize)
{
pbBaseAddress += MaxSegmentSize;
pbBaseAddressRX += MaxSegmentSize;
pbBaseAddressRW += MaxSegmentSize;
}

//
Expand All @@ -1327,7 +1330,7 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
// allocations are freed.
//

if ((size_t)(pCode + globalsize - pbBaseAddress) > MaxSegmentSize)
if ((size_t)(pCode + globalsize - pbBaseAddressRX) > MaxSegmentSize)
{
return false;
}
Expand Down Expand Up @@ -1442,17 +1445,17 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
PT_RUNTIME_FUNCTION pCurFunction = &pUnwindInfoHeader->FunctionEntry;
_ASSERTE(IS_ALIGNED(pCurFunction, sizeof(ULONG)));

S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddressRX);
if (sBeginAddress.IsOverflow())
COMPlusThrowArithmetic();
pCurFunction->BeginAddress = sBeginAddress.Value();

S_UINT32 sEndAddress = S_BYTEPTR(pCode) + S_BYTEPTR(globalsize) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sEndAddress = S_BYTEPTR(pCode) + S_BYTEPTR(globalsize) - S_BYTEPTR(pbBaseAddressRX);
if (sEndAddress.IsOverflow())
COMPlusThrowArithmetic();
pCurFunction->EndAddress = sEndAddress.Value();

S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddressRW);
if (sTemp.IsOverflow())
COMPlusThrowArithmetic();
RUNTIME_FUNCTION__SetUnwindInfoAddress(pCurFunction, sTemp.Value());
Expand All @@ -1465,12 +1468,12 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
PT_RUNTIME_FUNCTION pCurFunction = &pUnwindInfoHeader->FunctionEntry;
_ASSERTE(IS_ALIGNED(pCurFunction, sizeof(ULONG)));

S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddressRX);
if (sBeginAddress.IsOverflow())
COMPlusThrowArithmetic();
RUNTIME_FUNCTION__SetBeginAddress(pCurFunction, sBeginAddress.Value());

S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddressRW);
if (sTemp.IsOverflow())
COMPlusThrowArithmetic();
RUNTIME_FUNCTION__SetUnwindInfoAddress(pCurFunction, sTemp.Value());
Expand Down Expand Up @@ -1620,11 +1623,11 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo

_ASSERTE(IS_ALIGNED(pCurFunction, sizeof(void*)));

S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sBeginAddress = S_BYTEPTR(pCode) - S_BYTEPTR(pbBaseAddressRX);
if (sBeginAddress.IsOverflow())
COMPlusThrowArithmetic();

S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddress);
S_UINT32 sTemp = S_BYTEPTR(pUnwindInfo) - S_BYTEPTR(pbBaseAddressRW);
if (sTemp.IsOverflow())
COMPlusThrowArithmetic();

Expand Down Expand Up @@ -1749,14 +1752,14 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
(pStubHeapSegment = *ppPrevStubHeapSegment);
(ppPrevStubHeapSegment = &pStubHeapSegment->pNext))
{
if (pbBaseAddress < pStubHeapSegment->pbBaseAddress)
if (pbBaseAddressRX < pStubHeapSegment->pbBaseAddress)
{
// The list is ordered, so address is between segments
pStubHeapSegment = NULL;
break;
}

if (pbBaseAddress == pStubHeapSegment->pbBaseAddress)
if (pbBaseAddressRX == pStubHeapSegment->pbBaseAddress)
{
// Found an existing segment
break;
Expand All @@ -1768,7 +1771,7 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
//
// RtlInstallFunctionTableCallback will only accept a ULONG for the
// region size. We've already checked above that the RUNTIME_FUNCTION
// offsets will work relative to pbBaseAddress.
// offsets will work relative to pbBaseAddressRX.
//

SIZE_T cbSegment = findBlockArgs.cbBlockSize;
Expand All @@ -1779,7 +1782,7 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
NewHolder<StubUnwindInfoHeapSegment> pNewStubHeapSegment = new StubUnwindInfoHeapSegment();


pNewStubHeapSegment->pbBaseAddress = pbBaseAddress;
pNewStubHeapSegment->pbBaseAddress = pbBaseAddressRX;
pNewStubHeapSegment->cbSegment = cbSegment;
pNewStubHeapSegment->pUnwindHeaderList = NULL;
#ifdef TARGET_AMD64
Expand All @@ -1796,7 +1799,7 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo

InstallEEFunctionTable(
pNewStubHeapSegment,
pbBaseAddress,
pbBaseAddressRX,
(ULONG)cbSegment,
&FindStubFunctionEntry,
pNewStubHeapSegment,
Expand All @@ -1807,8 +1810,8 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
// Link the new stub into the segment.
//

pHeader->pNext = pStubHeapSegment->pUnwindHeaderList;
pStubHeapSegment->pUnwindHeaderList = pHeader;
pHeaderRW->pNext = pStubHeapSegment->pUnwindHeaderList;
pStubHeapSegment->pUnwindHeaderList = pHeaderRW;

#ifdef TARGET_AMD64
// Publish Unwind info to ETW stack crawler
Expand All @@ -1819,8 +1822,8 @@ bool StubLinker::EmitUnwindInfo(Stub* pStubRX, Stub* pStubRW, int globalsize, Lo
#endif

#ifdef _DEBUG
_ASSERTE(pHeader->IsRegistered());
_ASSERTE( &pHeader->FunctionEntry
_ASSERTE(pHeaderRW->IsRegistered());
_ASSERTE( &pHeaderRW->FunctionEntry
== FindStubFunctionEntry((ULONG64)pCode, EncodeDynamicFunctionTableContext(pStubHeapSegment, DYNFNTABLE_STUB)));
#endif

Expand Down

0 comments on commit 7a4678f

Please sign in to comment.