Skip to content

Commit 0234029

Browse files
authored
Fix interpreter helper and stack size computation (#118477)
This change fixes two issues: * INTOP_CALL_HELPER_P_S was taking arguments from wrong locations in the instruction * The total stack size computation in the call stub generator was incorrect in case arguments smaller than 8 bytes were passed on the stack.
1 parent b622b6b commit 0234029

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/coreclr/vm/callstubgenerator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ void CallStubGenerator::ComputeCallStub(MetaSig &sig, PCODE *pRoutines)
14161416
m_s1 = NoRange; // indicates that there is no active range of stack arguments
14171417
m_s2 = 0;
14181418
m_routineIndex = 0;
1419-
m_totalStackSize = 0;
1419+
m_totalStackSize = argIt.SizeOfArgStack();
14201420
#if LOG_COMPUTE_CALL_STUB
14211421
printf("ComputeCallStub\n");
14221422
#endif
@@ -1527,7 +1527,6 @@ void CallStubGenerator::ComputeCallStub(MetaSig &sig, PCODE *pRoutines)
15271527
}
15281528
else if (m_s1 != NoRange)
15291529
{
1530-
m_totalStackSize += m_s2 - m_s1 + 1;
15311530
pRoutines[m_routineIndex++] = GetStackRoutine();
15321531
pRoutines[m_routineIndex++] = ((int64_t)(m_s2 - m_s1 + 1) << 32) | m_s1;
15331532
}
@@ -1571,7 +1570,6 @@ void CallStubGenerator::ProcessArgument(ArgIterator *pArgIt, ArgLocDesc& argLocD
15711570
{
15721571
// No stack argument is used to pass the current argument, but we already have a range of stack arguments,
15731572
// store the routine for the range
1574-
m_totalStackSize += m_s2 - m_s1 + 1;
15751573
pRoutines[m_routineIndex++] = GetStackRoutine();
15761574
pRoutines[m_routineIndex++] = ((int64_t)(m_s2 - m_s1 + 1) << 32) | m_s1;
15771575
m_s1 = NoRange;
@@ -1650,7 +1648,6 @@ void CallStubGenerator::ProcessArgument(ArgIterator *pArgIt, ArgLocDesc& argLocD
16501648
else
16511649
{
16521650
// Discontinuous range - store a routine for the current and start a new one
1653-
m_totalStackSize += m_s2 - m_s1 + 1;
16541651
pRoutines[m_routineIndex++] = GetStackRoutine();
16551652
pRoutines[m_routineIndex++] = ((int64_t)(m_s2 - m_s1 + 1) << 32) | m_s1;
16561653
m_s1 = argLocDesc.m_byteStackIndex;
@@ -1699,7 +1696,6 @@ void CallStubGenerator::ProcessArgument(ArgIterator *pArgIt, ArgLocDesc& argLocD
16991696
_ASSERTE(argLocDesc.m_byteStackIndex != -1);
17001697
pRoutines[m_routineIndex++] = GetStackRefRoutine();
17011698
pRoutines[m_routineIndex++] = ((int64_t)pArgIt->GetArgSize() << 32) | argLocDesc.m_byteStackIndex;
1702-
m_totalStackSize += argLocDesc.m_byteStackSize;
17031699
m_s1 = NoRange;
17041700
}
17051701
}

src/coreclr/vm/interpexec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,8 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
17211721

17221722
case INTOP_CALL_HELPER_P_S:
17231723
{
1724-
HELPER_FTN_P_P helperFtn = GetPossiblyIndirectHelper<HELPER_FTN_P_P>(pMethod, ip[2]);
1725-
void* helperArg = LOCAL_VAR(ip[3], void*);
1724+
HELPER_FTN_P_P helperFtn = GetPossiblyIndirectHelper<HELPER_FTN_P_P>(pMethod, ip[3]);
1725+
void* helperArg = LOCAL_VAR(ip[2], void*);
17261726

17271727
LOCAL_VAR(ip[1], void*) = helperFtn(helperArg);
17281728
ip += 4;

0 commit comments

Comments
 (0)