Skip to content

Commit 1b6d8da

Browse files
committed
Add handling of pInvokeMarshallingRequired and suppressGCTransition
1 parent 617f882 commit 1b6d8da

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,14 +2810,19 @@ void InterpCompiler::EmitPushLdvirtftn(int thisVar, CORINFO_RESOLVED_TOKEN* pRes
28102810
m_pLastNewIns->info.pCallInfo->pCallArgs = callArgs;
28112811
}
28122812

2813-
void InterpCompiler::EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CorInfoCallConv callConv)
2813+
void InterpCompiler::EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CORINFO_SIG_INFO* callSiteSig)
28142814
{
28152815
AddIns(isTailCall ? INTOP_CALLI_TAIL : INTOP_CALLI);
28162816
m_pLastNewIns->data[0] = GetDataItemIndex(calliCookie);
28172817
// data[1] is set to 1 if the calli is calling a pinvoke, 0 otherwise
2818-
m_pLastNewIns->data[1] = (callConv == CORINFO_CALLCONV_DEFAULT || callConv == CORINFO_CALLCONV_VARARG) ? 0 : 1;
2818+
bool suppressGCTransition = false;
2819+
m_compHnd->getUnmanagedCallConv(nullptr, callSiteSig, &suppressGCTransition);
2820+
bool isPInvoke = (callSiteSig->callConv != CORINFO_CALLCONV_DEFAULT && callSiteSig->callConv != CORINFO_CALLCONV_VARARG);
2821+
bool isPInvokeMarshalled = isPInvoke && m_compHnd->pInvokeMarshalingRequired(NULL, callSiteSig);
2822+
m_pLastNewIns->data[1] = (suppressGCTransition ? (int32_t)CalliFlags::SuppressGCTransition : 0) |
2823+
(isPInvoke ? (int32_t)CalliFlags::PInvoke : 0) |
2824+
(isPInvokeMarshalled ? (int32_t)CalliFlags::PInvokeMarshalled : 0);
28192825
m_pLastNewIns->SetSVars2(CALL_ARGS_SVAR, callIFunctionPointerVar);
2820-
28212826
}
28222827

28232828
void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool readonly, bool tailcall, bool newObj, bool isCalli)
@@ -3225,7 +3230,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
32253230
}
32263231
else if (isCalli)
32273232
{
3228-
EmitCalli(tailcall, calliCookie, callIFunctionPointerVar, callInfo.sig.getCallConv());
3233+
EmitCalli(tailcall, calliCookie, callIFunctionPointerVar, &callInfo.sig);
32293234
}
32303235
else
32313236
{
@@ -3282,7 +3287,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
32823287

32833288
calliCookie = m_compHnd->GetCookieForInterpreterCalliSig(&callInfo.sig);
32843289

3285-
EmitCalli(tailcall, calliCookie, codePointerLookupResult, callInfo.sig.getCallConv());
3290+
EmitCalli(tailcall, calliCookie, codePointerLookupResult, &callInfo.sig);
32863291
break;
32873292
}
32883293
case CORINFO_VIRTUALCALL_VTABLE:
@@ -3315,7 +3320,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
33153320

33163321
calliCookie = m_compHnd->GetCookieForInterpreterCalliSig(&callInfo.sig);
33173322

3318-
EmitCalli(tailcall, calliCookie, synthesizedLdvirtftnPtrVar, callInfo.sig.getCallConv());
3323+
EmitCalli(tailcall, calliCookie, synthesizedLdvirtftnPtrVar, &callInfo.sig);
33193324
}
33203325
else
33213326
{

src/coreclr/interpreter/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class InterpCompiler
711711
void EmitShiftOp(int32_t opBase);
712712
void EmitCompareOp(int32_t opBase);
713713
void EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool readonly, bool tailcall, bool newObj, bool isCalli);
714-
void EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CorInfoCallConv callConv);
714+
void EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CORINFO_SIG_INFO* callSiteSig);
715715
bool EmitNamedIntrinsicCall(NamedIntrinsic ni, CORINFO_CLASS_HANDLE clsHnd, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO sig);
716716
void EmitLdind(InterpType type, CORINFO_CLASS_HANDLE clsHnd, int32_t offset);
717717
void EmitStind(InterpType type, CORINFO_CLASS_HANDLE clsHnd, int32_t offset, bool reverseSVarOrder);

src/coreclr/interpreter/interpretershared.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,12 @@ enum class PInvokeCallFlags : int32_t
171171
SuppressGCTransition = 1 << 1, // The pinvoke is marked by the SuppressGCTransition attribute
172172
};
173173

174+
enum class CalliFlags : int32_t
175+
{
176+
None = 0,
177+
SuppressGCTransition = 1 << 1, // The call is marked by the SuppressGCTransition attribute
178+
PInvoke = 1 << 2, // The call is a PInvoke call
179+
PInvokeMarshalled = 1 << 3, // The call is a PInvoke call with marshaling
180+
};
181+
174182
#endif

src/coreclr/vm/interpexec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
20092009
callArgsOffset = ip[2];
20102010
int32_t calliFunctionPointerVar = ip[3];
20112011
int32_t calliCookie = ip[4];
2012-
bool isPInvoke = ip[5] != 0;
2012+
int32_t flags = ip[5];
20132013

20142014
CallStubHeader *pCallStub = (CallStubHeader*)pMethod->pDataItems[calliCookie];
20152015
ip += 6;
@@ -2018,7 +2018,7 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
20182018
pFrame->ip = ip;
20192019

20202020
// Interpreter-FIXME: isTailcall
2021-
if (isPInvoke)
2021+
if ((flags & (int32_t)CalliFlags::PInvoke) && !(flags & (int32_t)CalliFlags::SuppressGCTransition) && !(flags & (int32_t)CalliFlags::PInvokeMarshalled))
20222022
{
20232023
InvokePInvokeCalliStub(LOCAL_VAR(calliFunctionPointerVar, PCODE), pCallStub, stack, pFrame, stack + callArgsOffset, stack + returnOffset);
20242024
}

0 commit comments

Comments
 (0)