Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4361,6 +4361,24 @@ void InterpCompiler::EmitLoadPointer(intptr_t ptrValue)
}
}

void InterpCompiler::CheckForPInvokeThisCallWithNoArgs(CORINFO_SIG_INFO* sigInfo, CORINFO_METHOD_HANDLE methodHnd)
{
if (sigInfo->numArgs == 0)
{
CorInfoCallConv callConv = (CorInfoCallConv)(sigInfo->callConv & IMAGE_CEE_CS_CALLCONV_MASK);
bool isPInvoke = methodHnd != NULL || (callConv != CORINFO_CALLCONV_DEFAULT && callConv != CORINFO_CALLCONV_VARARG);
if (isPInvoke)
{
bool suppressGCTransition = false;
CorInfoCallConvExtension unmanagedCallConv = m_compHnd->getUnmanagedCallConv(methodHnd, sigInfo, &suppressGCTransition);
if (callConvIsInstanceMethodCallConv(unmanagedCallConv))
{
BADCODE("thiscall with 0 arguments");
}
}
}
}

void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool readonly, bool tailcall, bool newObj, bool isCalli)
{
uint32_t token = getU4LittleEndian(m_ip + 1);
Expand Down Expand Up @@ -4492,6 +4510,8 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
BADCODE("Vararg methods are not supported in interpreted code");
}

CheckForPInvokeThisCallWithNoArgs(&callInfo.sig, NULL);

callIFunctionPointerVar = m_pStackPointer[-1].var;
m_pStackPointer--;
calliCookie = m_compHnd->GetCookieForInterpreterCalliSig(&callInfo.sig);
Expand Down Expand Up @@ -4647,6 +4667,11 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
}
}

if (isPInvoke && !isMarshaledPInvoke)
{
CheckForPInvokeThisCallWithNoArgs(&callInfo.sig, callInfo.hMethod);
}

// Process sVars
int numArgsFromStack = callInfo.sig.numArgs + (newObj ? 0 : callInfo.sig.hasImplicitThis());
int newObjThisArgLocation = newObj && !doCallInsteadOfNew ? 0 : INT_MAX;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/interpreter/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ class InterpCompiler
void EmitPushSyncObject();
void EmitCallsiteCallout(CorInfoIsAccessAllowedResult accessAllowed, CORINFO_HELPER_DESC* calloutDesc);
void EmitCanAccessCallout(CORINFO_RESOLVED_TOKEN *pResolvedToken);
void CheckForPInvokeThisCallWithNoArgs(CORINFO_SIG_INFO* sigInfo, CORINFO_METHOD_HANDLE methodHnd);
void EmitLdftn(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool isLdvirtftn);
void EmitDup();
void EmitLoadPointer(intptr_t value);
Expand Down
Loading