Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 0 additions & 8 deletions src/coreclr/vm/clrtocomcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ namespace
&stubLinker
);

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

szMetaSig.SuppressRelease();

return pStubMD;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/comcallablewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3223,7 +3223,7 @@ BOOL ComMethodTable::LayOutInterfaceMethodTable(MethodTable* pClsMT)
// to access empty slots quickly and, during cleanup, we can tell empty
// slots from full ones.
if (m_pMT->IsSparseForCOMInterop())
memset(pUnkVtable + cbExtraSlots, -1, m_cbSlots * sizeof(SLOT));
memset(((SLOT*)pUnkVtable) + cbExtraSlots, -1, m_cbSlots * sizeof(SLOT));

// Method descs are at the end of the vtable
// m_cbSlots interfaces methods + IUnk methods
Expand Down
29 changes: 4 additions & 25 deletions src/coreclr/vm/comtoclrcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ void ComCallMethodDesc::InitMethod(MethodDesc *pMD, MethodDesc *pInterfaceMD)
m_pInterfaceMD = PTR_MethodDesc(pInterfaceMD);
m_pILStub = NULL;

#ifdef TARGET_X86
m_dwSlotInfo = 0;
m_pwStubStackSlotOffsets = NULL;
#endif // TARGET_X86

// Initialize the native type information size of native stack, native retval flags, etc).
InitNativeInfo();
}
Expand All @@ -66,11 +61,6 @@ void ComCallMethodDesc::InitField(FieldDesc* pFD, BOOL isGetter)
m_pFD = pFD;
m_pILStub = NULL;

#ifdef TARGET_X86
m_dwSlotInfo = 0;
m_pwStubStackSlotOffsets = NULL;
#endif // TARGET_X86

m_flags = enum_IsFieldCall; // mark the attribute as a field
m_flags |= isGetter ? enum_IsGetter : 0;

Expand All @@ -92,11 +82,10 @@ void ComCallMethodDesc::InitNativeInfo()
}
CONTRACT_END;

m_StackBytes = (UINT16)-1;

EX_TRY
{
#ifdef TARGET_X86
m_StackBytes = (UINT16)-1;
// On x86, this method has to compute size of arguments because we need to know size of the native stack
// to be able to return back to unmanaged code
UINT16 nativeArgSize;
Expand Down Expand Up @@ -480,22 +469,12 @@ PCODE ComCallMethodDesc::CreateCOMToCLRStub(DWORD dwStubFlags, MethodDesc **ppSt

*ppStubMD = pStubMD;

_ASSERTE(pStubMD->IsILStub());

#ifdef TARGET_X86
// make sure our native stack computation in code:ComCallMethodDesc.InitNativeInfo is right
_ASSERTE(HasMarshalError() || !pStubMD->IsILStub() || pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize() == m_StackBytes);
#else // TARGET_X86

if (pStubMD->IsILStub())
{
m_StackBytes = pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize();
_ASSERTE(m_StackBytes == pStubMD->SizeOfArgStack());
}
else
{
UINT size = pStubMD->SizeOfArgStack();
_ASSERTE(size <= USHRT_MAX);
m_StackBytes = (UINT16)size;
}
m_StackBytes = pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize();
#endif // TARGET_X86

RETURN JitILStub(pStubMD);
Expand Down
50 changes: 16 additions & 34 deletions src/coreclr/vm/comtoclrcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,6 @@ class ComCallMethodDesc
RETURN m_pMD->GetSlot();
}

// get num stack bytes to pop
UINT16 GetNumStackBytes()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(m_flags & enum_NativeInfoInitialized);
SUPPORTS_DAC;
}
CONTRACTL_END;

return m_StackBytes;
}

//get call sig
PCCOR_SIGNATURE GetSig(DWORD *pcbSigSize = NULL)
{
Expand Down Expand Up @@ -292,29 +276,27 @@ class ComCallMethodDesc

PCODE m_pILStub; // IL stub for COM to CLR call, invokes GetCallMethodDesc()

// Platform specific data needed for efficient IL stub invocation:
#ifdef TARGET_X86
union
// Number of stack bytes pushed by the unmanaged caller.
UINT16 m_StackBytes;

public:
// get num stack bytes to pop
UINT16 GetNumStackBytes()
Comment thread
jkoritzinsky marked this conversation as resolved.
{
struct
CONTRACTL
{
// Index of the stack slot that gets stuffed into EDX when calling the stub.
UINT16 m_wSourceSlotEDX;

// Number of stack slots expected by the IL stub.
UINT16 m_wStubStackSlotCount;
};
// Combination of m_wSourceSlotEDX and m_wStubStackSlotCount for atomic updates.
UINT32 m_dwSlotInfo;
};
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(m_flags & enum_NativeInfoInitialized);
SUPPORTS_DAC;
}
CONTRACTL_END;

// This is an array of m_wStubStackSlotCount numbers where each element is the offset
// on the source stack where the particular stub stack slot should be copied from.
UINT16 *m_pwStubStackSlotOffsets;
return m_StackBytes;
}
#endif // TARGET_X86

// Number of stack bytes pushed by the unmanaged caller.
UINT16 m_StackBytes;
};

extern "C" void ComCallPreStub();
Expand Down
34 changes: 4 additions & 30 deletions src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,6 @@ class ILStubState
((PTR_DynamicMethodDesc)pStubMD)->SetFlags(DynamicMethodDesc::FlagStatic);
pStubMD->SetStatic();
}

#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();

if (!FitsInU2(stackSize))
COMPlusThrow(kMarshalDirectiveException, IDS_EE_SIGTOOCOMPLEX);

pStubMD->AsDynamicMethodDesc()->SetNativeStackArgSize(static_cast<WORD>(stackSize));
#endif // TARGET_X86
}

DWORD cbTempModuleIndependentSigLength;
Expand Down Expand Up @@ -3991,38 +3981,30 @@ static void CreatePInvokeStubWorker(ILStubState* pss,
nativeStackSize += TARGET_POINTER_SIZE;
}

#ifdef TARGET_X86
if (pMD->IsDynamicMethod())
{
// Set the native stack size to the IL stub MD. It is needed for alignment
// thunk generation on the Mac and stdcall name decoration on Windows.
// We do not store it directly in the interop MethodDesc here because due
// to sharing we come here only for the first call with given signature and
// the target MD may even be NULL.

#ifdef TARGET_X86
// Set the native stack size to the IL stub MD. It is needed for
// stdcall name decoration and correct stack management in error cases for COM->CLR calls.
if (fThisCall)
{
Comment thread
jkoritzinsky marked this conversation as resolved.
_ASSERTE(nativeStackSize >= TARGET_POINTER_SIZE);
nativeStackSize -= TARGET_POINTER_SIZE;
}
#endif // TARGET_X86

nativeStackSize = ALIGN_UP(nativeStackSize, TARGET_POINTER_SIZE);

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);
Comment thread
jkoritzinsky marked this conversation as resolved.
Outdated
#endif
}
#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)
pss->FinishEmit(pMD);
}

Expand Down Expand Up @@ -5632,14 +5614,6 @@ MethodDesc* PInvoke::CreateLayoutClassMarshalILStub(MethodTable* pMT, MarshalOpe
&pLinker
);

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

szMetaSig.SuppressRelease();

RETURN pStubMD;
Expand Down
14 changes: 0 additions & 14 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,20 +1759,6 @@ UINT MethodDesc::SizeOfArgStack()
return argit.SizeOfArgStack();
}

#ifdef FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE
UINT MethodDesc::SizeOfNativeArgStack()
{
#ifndef UNIX_AMD64_ABI
return SizeOfArgStack();
#else
WRAPPER_NO_CONTRACT;
MetaSig msig(this);
PInvokeArgIterator argit(&msig);
return argit.SizeOfArgStack();
#endif
}
#endif // FEATURE_DYNAMIC_METHOD_HAS_NATIVE_STACK_ARG_SIZE

#ifdef TARGET_X86
//*******************************************************************************
UINT MethodDesc::CbStackPop()
Expand Down
14 changes: 2 additions & 12 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ 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 @@ -870,12 +866,6 @@ 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()!
UINT CbStackPop();
Expand Down Expand Up @@ -2999,7 +2989,7 @@ class DynamicMethodDesc : public StoredSigMethodDesc
return asMetadata;
}

#if defined(TARGET_X86) || defined(FEATURE_COMINTEROP)
#if defined(TARGET_X86)
WORD GetNativeStackArgSize()
{
LIMITED_METHOD_DAC_CONTRACT;
Expand All @@ -3016,7 +3006,7 @@ class DynamicMethodDesc : public StoredSigMethodDesc
#endif
m_dwExtendedFlags = (m_dwExtendedFlags & ~StackArgSizeMask) | ((DWORD)cbArgSize << 16);
}
#endif // TARGET_X86 || FEATURE_COMINTEROP
#endif // TARGET_X86

bool IsReversePInvokeStub() const
{
Expand Down