Skip to content

Commit 77a8c39

Browse files
committed
Add handling of pInvokeMarshallingRequired and suppressGCTransition
1 parent 4c13e83 commit 77a8c39

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
@@ -2854,14 +2854,19 @@ void InterpCompiler::EmitPushLdvirtftn(int thisVar, CORINFO_RESOLVED_TOKEN* pRes
28542854
m_pLastNewIns->info.pCallInfo->pCallArgs = callArgs;
28552855
}
28562856

2857-
void InterpCompiler::EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CorInfoCallConv callConv)
2857+
void InterpCompiler::EmitCalli(bool isTailCall, void* calliCookie, int callIFunctionPointerVar, CORINFO_SIG_INFO* callSiteSig)
28582858
{
28592859
AddIns(isTailCall ? INTOP_CALLI_TAIL : INTOP_CALLI);
28602860
m_pLastNewIns->data[0] = GetDataItemIndex(calliCookie);
28612861
// data[1] is set to 1 if the calli is calling a pinvoke, 0 otherwise
2862-
m_pLastNewIns->data[1] = (callConv == CORINFO_CALLCONV_DEFAULT || callConv == CORINFO_CALLCONV_VARARG) ? 0 : 1;
2862+
bool suppressGCTransition = false;
2863+
m_compHnd->getUnmanagedCallConv(nullptr, callSiteSig, &suppressGCTransition);
2864+
bool isPInvoke = (callSiteSig->callConv != CORINFO_CALLCONV_DEFAULT && callSiteSig->callConv != CORINFO_CALLCONV_VARARG);
2865+
bool isPInvokeMarshalled = isPInvoke && m_compHnd->pInvokeMarshalingRequired(NULL, callSiteSig);
2866+
m_pLastNewIns->data[1] = (suppressGCTransition ? (int32_t)CalliFlags::SuppressGCTransition : 0) |
2867+
(isPInvoke ? (int32_t)CalliFlags::PInvoke : 0) |
2868+
(isPInvokeMarshalled ? (int32_t)CalliFlags::PInvokeMarshalled : 0);
28632869
m_pLastNewIns->SetSVars2(CALL_ARGS_SVAR, callIFunctionPointerVar);
2864-
28652870
}
28662871

28672872
void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool readonly, bool tailcall, bool newObj, bool isCalli)
@@ -3269,7 +3274,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
32693274
}
32703275
else if (isCalli)
32713276
{
3272-
EmitCalli(tailcall, calliCookie, callIFunctionPointerVar, callInfo.sig.getCallConv());
3277+
EmitCalli(tailcall, calliCookie, callIFunctionPointerVar, &callInfo.sig);
32733278
}
32743279
else
32753280
{
@@ -3326,7 +3331,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
33263331

33273332
calliCookie = m_compHnd->GetCookieForInterpreterCalliSig(&callInfo.sig);
33283333

3329-
EmitCalli(tailcall, calliCookie, codePointerLookupResult, callInfo.sig.getCallConv());
3334+
EmitCalli(tailcall, calliCookie, codePointerLookupResult, &callInfo.sig);
33303335
break;
33313336
}
33323337
case CORINFO_VIRTUALCALL_VTABLE:
@@ -3359,7 +3364,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
33593364

33603365
calliCookie = m_compHnd->GetCookieForInterpreterCalliSig(&callInfo.sig);
33613366

3362-
EmitCalli(tailcall, calliCookie, synthesizedLdvirtftnPtrVar, callInfo.sig.getCallConv());
3367+
EmitCalli(tailcall, calliCookie, synthesizedLdvirtftnPtrVar, &callInfo.sig);
33633368
}
33643369
else
33653370
{

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/inc/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
@@ -2152,7 +2152,7 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
21522152
callArgsOffset = ip[2];
21532153
int32_t calliFunctionPointerVar = ip[3];
21542154
int32_t calliCookie = ip[4];
2155-
bool isPInvoke = ip[5] != 0;
2155+
int32_t flags = ip[5];
21562156

21572157
void* cookie = pMethod->pDataItems[calliCookie];
21582158
ip += 6;
@@ -2161,7 +2161,7 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
21612161
pFrame->ip = ip;
21622162

21632163
// Interpreter-FIXME: isTailcall
2164-
if (isPInvoke)
2164+
if ((flags & (int32_t)CalliFlags::PInvoke) && !(flags & (int32_t)CalliFlags::SuppressGCTransition) && !(flags & (int32_t)CalliFlags::PInvokeMarshalled))
21652165
{
21662166
InvokePInvokeCalliStub(LOCAL_VAR(calliFunctionPointerVar, PCODE), cookie, stack, pFrame, stack + callArgsOffset, stack + returnOffset);
21672167
}

0 commit comments

Comments
 (0)