Skip to content

Commit c78f853

Browse files
authored
Fix TryEnsureSufficientExecutionStack with interpreter (#122248)
The ReflectionInvocation::TryEnsureSufficientExecutionStack was not taking into account the fact that with interpreter enabled, the code can be executed either by the interpreter or it can be AOTed. The interpreter has its own stack with its own limit. 3 libraries tests suites were failing due to this problem. As a best effort fix, this change adds check for the interpreter stack too and the method returns true only if there is enough space on both real and the interpreter stack, as it is not possible to decide which of them will be used.
1 parent 50a3154 commit c78f853

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/coreclr/vm/reflectioninvocation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "dbginterface.h"
2626
#include "argdestination.h"
2727

28+
#include "interpexec.h"
29+
2830
extern "C" void QCALLTYPE RuntimeFieldHandle_GetValue(FieldDesc* fieldDesc, QCall::ObjectHandleOnStack instance, QCall::TypeHandle fieldType, QCall::TypeHandle declaringType, BOOL* pIsClassInitialized, QCall::ObjectHandleOnStack result)
2931
{
3032
QCALL_CONTRACT;
@@ -1362,6 +1364,23 @@ FCIMPL0(FC_BOOL_RET, ReflectionInvocation::TryEnsureSufficientExecutionStack)
13621364
UINT_PTR current = reinterpret_cast<UINT_PTR>(&pThread);
13631365
UINT_PTR limit = pThread->GetCachedStackSufficientExecutionLimit();
13641366

1367+
#ifdef FEATURE_INTERPRETER
1368+
InterpThreadContext* pInterpThreadContext = pThread->GetInterpThreadContext();
1369+
if (pInterpThreadContext != nullptr)
1370+
{
1371+
// The interpreter has its own stack, so we need to check against that too.
1372+
#ifdef HOST_64BIT
1373+
const UINT_PTR MinExecutionStackSize = 128 * 1024;
1374+
#else // !HOST_64BIT
1375+
const UINT_PTR MinExecutionStackSize = 64 * 1024;
1376+
#endif // HOST_64BIT
1377+
if (pInterpThreadContext->pStackPointer >= pInterpThreadContext->pStackEnd - MinExecutionStackSize)
1378+
{
1379+
FC_RETURN_BOOL(FALSE);
1380+
}
1381+
}
1382+
#endif // FEATURE_INTERPRETER
1383+
13651384
FC_RETURN_BOOL(current >= limit);
13661385
}
13671386
FCIMPLEND

0 commit comments

Comments
 (0)