Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/coreclr/vm/clrtocomcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ CLRToCOMCallInfo *CLRToCOMCall::PopulateCLRToCOMCallMethodDesc(MethodDesc* pMD,
LoaderHeap *pHeap = pMD->GetLoaderAllocator()->GetHighFrequencyHeap();
CLRToCOMCallInfo *pTemp = (CLRToCOMCallInfo *)(void *)pHeap->AllocMem(S_SIZE_T(sizeof(CLRToCOMCallInfo)));

#ifdef TARGET_X86
pTemp->InitStackArgumentSize();
#endif // TARGET_X86

InterlockedCompareExchangeT(&pCMD->m_pCLRToCOMCallInfo, pTemp, NULL);
}
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,9 @@ CLRToCOMCallInfo * COMDelegate::PopulateCLRToCOMCallInfo(MethodTable * pDelMT)
CLRToCOMCallInfo *pTemp = (CLRToCOMCallInfo *)(void *)pHeap->AllocMem(S_SIZE_T(sizeof(CLRToCOMCallInfo)));

pTemp->m_cachedComSlot = ComMethodTable::GetNumExtraSlots(ifVtable);
#ifdef TARGET_X86
pTemp->InitStackArgumentSize();
#endif // TARGET_X86

InterlockedCompareExchangeT(&pClass->m_pCLRToCOMCallInfo, pTemp, NULL);
}
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class ILStubState : public StubState
pStubMD->SetStatic();
}

#ifndef TARGET_X86
#if !defined(TARGET_X86) && defined(FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE)
// we store the real managed argument stack size in the stub MethodDesc on non-X86
UINT stackSize = pStubMD->SizeOfNativeArgStack();

Expand Down Expand Up @@ -3477,6 +3477,7 @@ BOOL PInvoke::MarshalingRequired(
if (!FitsInU2(dwStackSize))
return TRUE;

#ifdef TARGET_X86
// do not set the stack size for varargs - the number is call site specific
if (pMD != NULL && !pMD->IsVarArg())
{
Expand All @@ -3492,6 +3493,7 @@ BOOL PInvoke::MarshalingRequired(
}
#endif // FEATURE_COMINTEROP
}
#endif // TARGET_X86

return FALSE;
}
Expand Down Expand Up @@ -3886,11 +3888,13 @@ static void CreatePInvokeStubWorker(StubState* pss,
if (!FitsInU2(nativeStackSize))
COMPlusThrow(kMarshalDirectiveException, IDS_EE_SIGTOOCOMPLEX);

#ifdef FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE
DynamicMethodDesc *pDMD = pMD->AsDynamicMethodDesc();

pDMD->SetNativeStackArgSize(static_cast<WORD>(nativeStackSize));
if (fStubNeedsCOM)
pDMD->SetFlags(DynamicMethodDesc::FlagRequiresCOM);
#endif
}

// FinishEmit needs to know the native stack arg size so we call it after the number
Expand Down Expand Up @@ -3984,11 +3988,13 @@ static void CreateStructStub(ILStubState* pss,
pss->MarshalField(&mlInfo, managedOffset, externalOffset, pFD);
}

#if defined(FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE)
if (pMD->IsDynamicMethod())
{
DynamicMethodDesc* pDMD = pMD->AsDynamicMethodDesc();
pDMD->SetNativeStackArgSize(4 * TARGET_POINTER_SIZE); // The native stack arg size is constant since the signature for struct stubs is constant.
}
#endif

// FinishEmit needs to know the native stack arg size so we call it after the number
// has been set in the stub MD (code:DynamicMethodDesc.SetNativeStackArgSize)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ UINT MethodDesc::SizeOfArgStack()
return argit.SizeOfArgStack();
}


#ifdef FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE
UINT MethodDesc::SizeOfNativeArgStack()
{
#ifndef UNIX_AMD64_ABI
Expand All @@ -1740,6 +1740,7 @@ UINT MethodDesc::SizeOfNativeArgStack()
return argit.SizeOfArgStack();
#endif
}
#endif // FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE

#ifdef TARGET_X86
//*******************************************************************************
Expand Down
35 changes: 13 additions & 22 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ EXTERN_C VOID STDCALL PInvokeImportThunk();
#define METHOD_TOKEN_RANGE_BIT_COUNT (24 - METHOD_TOKEN_REMAINDER_BIT_COUNT)
#define METHOD_TOKEN_RANGE_MASK ((1 << METHOD_TOKEN_RANGE_BIT_COUNT) - 1)

#if defined(TARGET_X86) || defined(FEATURE_COMINTEROP)
#define FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE
#endif

enum class AsyncMethodFlags
{
// Method uses CORINFO_CALLCONV_ASYNCCALL call convention.
Expand Down Expand Up @@ -858,9 +862,11 @@ class MethodDesc
// arguments passed in registers.
UINT SizeOfArgStack();

#ifdef FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE
// Returns the # of bytes of stack used by arguments in a call from native to this function.
// Does not include arguments passed in registers.
UINT SizeOfNativeArgStack();
#endif // FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE

// Returns the # of bytes to pop after a call. Not necessary the
// same as SizeOfArgStack()!
Expand Down Expand Up @@ -2887,23 +2893,25 @@ class DynamicMethodDesc : public StoredSigMethodDesc
return asMetadata;
}

#if defined(TARGET_X86) || defined(FEATURE_COMINTEROP)
WORD GetNativeStackArgSize()
{
LIMITED_METHOD_DAC_CONTRACT;
_ASSERTE(IsILStub());
return (WORD)((m_dwExtendedFlags & StackArgSizeMask) >> 16);
}

void SetNativeStackArgSize(WORD cbArgSize)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(IsILStub());
#if !defined(OSX_ARM64_ABI)
#if !defined(OSX_ARM64_ABI)
_ASSERTE((cbArgSize % TARGET_POINTER_SIZE) == 0);
#endif
#endif
m_dwExtendedFlags = (m_dwExtendedFlags & ~StackArgSizeMask) | ((DWORD)cbArgSize << 16);
}

#endif // TARGET_X86 || FEATURE_COMINTEROP

bool IsReversePInvokeStub() const
{
LIMITED_METHOD_DAC_CONTRACT;
Expand Down Expand Up @@ -3333,11 +3341,11 @@ class PInvokeMethodDesc : public MethodDesc
#endif
public:

#if defined(TARGET_X86)
void SetStackArgumentSize(WORD cbDstBuffer, CorInfoCallConvExtension unmgdCallConv)
{
LIMITED_METHOD_CONTRACT;

#if defined(TARGET_X86)
// thiscall passes the this pointer in ECX
if (unmgdCallConv == CorInfoCallConvExtension::Thiscall)
{
Expand All @@ -3354,10 +3362,8 @@ class PInvokeMethodDesc : public MethodDesc
{
_ASSERTE(m_cbStackArgumentSize == cbDstBuffer);
}
#endif // defined(TARGET_X86)
}

#if defined(TARGET_X86)
void EnsureStackArgumentSize();

WORD GetStackArgumentSize() const
Expand Down Expand Up @@ -3475,16 +3481,6 @@ struct CLRToCOMCallInfo
_ASSERTE(m_cbStackArgumentSize != 0xFFFF);
return m_cbStackArgumentSize;
}
#else // TARGET_X86
void InitStackArgumentSize()
{
LIMITED_METHOD_CONTRACT;
}

void SetStackArgumentSize(WORD cbDstBuffer)
{
LIMITED_METHOD_CONTRACT;
}
#endif // TARGET_X86
};

Expand Down Expand Up @@ -3554,11 +3550,6 @@ class CLRToCOMCallMethodDesc : public MethodDesc
LIMITED_METHOD_CONTRACT;
m_pCLRToCOMCallInfo->m_cbStackPop = (WORD)CbStackPop();
}
#else // TARGET_X86
void SetStackArgumentSize(WORD cbDstBuffer)
{
LIMITED_METHOD_CONTRACT;
}
#endif // TARGET_X86
};
#endif // FEATURE_COMINTEROP
Expand Down
Loading