diff --git a/src/coreclr/vm/binder.cpp b/src/coreclr/vm/binder.cpp index 25c4f540fbeda..042718a3b2e00 100644 --- a/src/coreclr/vm/binder.cpp +++ b/src/coreclr/vm/binder.cpp @@ -1038,8 +1038,7 @@ void CoreLibBinder::CheckExtended() else if (pMD->IsNDirect()) { - PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc((NDirectMethodDesc *)pMD, &sigInfo); + NDirect::PopulateNDirectMethodDesc((NDirectMethodDesc *)pMD); if (pMD->IsQCall()) { diff --git a/src/coreclr/vm/classcompat.cpp b/src/coreclr/vm/classcompat.cpp index 93d5d44ff6f6f..3c9556a66232a 100644 --- a/src/coreclr/vm/classcompat.cpp +++ b/src/coreclr/vm/classcompat.cpp @@ -3311,7 +3311,7 @@ HRESULT MethodTableBuilder::FindMethodDeclarationForMethodImpl( IfFailRet(pMDInternalImport->GetNameAndSigOfMemberRef(tkMethod, &pSig, &cSig, &szMember)); if (isCallConv( - MetaSig::GetCallingConvention(NULL, Signature(pSig, cSig)), + MetaSig::GetCallingConvention(Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)) { return VLDTR_E_MR_BADCALLINGCONV; diff --git a/src/coreclr/vm/compile.cpp b/src/coreclr/vm/compile.cpp index 1b559d0580edd..4edd220728a0e 100644 --- a/src/coreclr/vm/compile.cpp +++ b/src/coreclr/vm/compile.cpp @@ -5735,7 +5735,7 @@ void CEEPreloader::GenerateMethodStubs( { NDirectMethodDesc* pNMD = (NDirectMethodDesc*)pMD; PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc(pNMD, &sigInfo); + NDirect::InitializeSigInfoAndPopulateNDirectMethodDesc(pNMD, &sigInfo); pStubMD = NDirect::GetILStubMethodDesc((NDirectMethodDesc*)pMD, &sigInfo, dwNGenStubFlags); } #ifdef FEATURE_COMINTEROP diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index dbc66eae2fb9c..3ee31baf63bd5 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -90,46 +90,30 @@ namespace } } -StubSigDesc::StubSigDesc(MethodDesc *pMD, PInvokeStaticSigInfo* pSigInfo /*= NULL*/) +StubSigDesc::StubSigDesc(MethodDesc *pMD) { CONTRACTL { NOTHROW; GC_NOTRIGGER; SUPPORTS_DAC; + PRECONDITION(pMD != NULL); } CONTRACTL_END; m_pMD = pMD; m_pMT = nullptr; - if (pSigInfo != NULL) - { - m_sig = pSigInfo->GetSignature(); - m_pModule = pSigInfo->GetModule(); - } - else - { - _ASSERTE(pMD != NULL); - m_sig = pMD->GetSignature(); - m_pModule = pMD->GetModule(); // Used for token resolution. - } + m_sig = pMD->GetSignature(); + m_pModule = pMD->GetModule(); // Used for token resolution. - if (pMD != NULL) - { - m_tkMethodDef = pMD->GetMemberDef(); - SigTypeContext::InitTypeContext(pMD, &m_typeContext); - m_pLoaderModule = pMD->GetLoaderModule(); // Used for ILStubCache selection and MethodTable creation. - } - else - { - m_tkMethodDef = mdMethodDefNil; - m_pLoaderModule = m_pModule; - } + m_tkMethodDef = pMD->GetMemberDef(); + SigTypeContext::InitTypeContext(pMD, &m_typeContext); + m_pLoaderModule = pMD->GetLoaderModule(); // Used for ILStubCache selection and MethodTable creation. INDEBUG(InitDebugNames()); } -StubSigDesc::StubSigDesc(MethodDesc* pMD, Signature sig, Module* pModule) +StubSigDesc::StubSigDesc(MethodDesc* pMD, const Signature& sig, Module* pModule) { CONTRACTL { @@ -161,7 +145,7 @@ StubSigDesc::StubSigDesc(MethodDesc* pMD, Signature sig, Module* pModule) INDEBUG(InitDebugNames()); } -StubSigDesc::StubSigDesc(MethodTable* pMT, Signature sig, Module* pModule) +StubSigDesc::StubSigDesc(MethodTable* pMT, const Signature& sig, Module* pModule) { CONTRACTL { @@ -193,7 +177,7 @@ StubSigDesc::StubSigDesc(MethodTable* pMT, Signature sig, Module* pModule) INDEBUG(InitDebugNames()); } -StubSigDesc::StubSigDesc(std::nullptr_t, Signature sig, Module* pModule) +StubSigDesc::StubSigDesc(const Signature& sig, Module* pModule) { CONTRACTL { @@ -2531,7 +2515,7 @@ namespace } // Convert a CorNativeLinkType into an unambiguous usable value. - bool TryRemapLinkType(_In_ CorNativeLinkType value, _Out_ CorNativeLinkType* nlt) + HRESULT RemapLinkType(_In_ CorNativeLinkType value, _Out_ CorNativeLinkType* nlt) { LIMITED_METHOD_CONTRACT; _ASSERTE(nlt != NULL); @@ -2556,12 +2540,12 @@ namespace #endif break; default: - return false; + return E_INVALIDARG; } // Validate we remapped to a usable value. _ASSERTE(*nlt == nltAnsi || *nlt == nltUnicode); - return true; + return S_OK; } } @@ -2623,7 +2607,7 @@ void PInvokeStaticSigInfo::PreInit(MethodDesc* pMD) } PInvokeStaticSigInfo::PInvokeStaticSigInfo( - MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName) + _In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8 *pLibName, _Outptr_opt_ LPCUTF8 *pEntryPointName) { STANDARD_VM_CONTRACT; @@ -2659,9 +2643,9 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOn LONG cData = 0; CorPinvokeMap callConv = (CorPinvokeMap)0; - HRESULT hRESULT = pMT->GetCustomAttribute( + hr = pMT->GetCustomAttribute( WellKnownAttribute::UnmanagedFunctionPointer, (const VOID **)(&pData), (ULONG *)&cData); - IfFailThrow(hRESULT); + IfFailThrow(hr); if (cData != 0) { CustomAttributeParser ca(pData, cData); @@ -2670,6 +2654,7 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOn args[0].InitEnum(SERIALIZATION_TYPE_I4, (ULONG)m_callConv); IfFailGo(ParseKnownCaArgs(ca, args, lengthof(args))); + callConv = (CorPinvokeMap)(args[0].val.u4 << 8); enum UnmanagedFunctionPointerNamedArgs { @@ -2688,14 +2673,8 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOn IfFailGo(ParseKnownCaNamedArgs(ca, namedArgs, lengthof(namedArgs))); - callConv = (CorPinvokeMap)(args[0].val.u4 << 8); - CorNativeLinkType nlt; - if (!TryRemapLinkType((CorNativeLinkType)namedArgs[MDA_CharSet].val.u4, &nlt)) - { - hr = E_FAIL; - goto ErrExit; - } + IfFailGo(RemapLinkType((CorNativeLinkType)namedArgs[MDA_CharSet].val.u4, &nlt)); SetCharSet ( nlt ); SetBestFitMapping (namedArgs[MDA_BestFitMapping].val.u1); @@ -2704,12 +2683,12 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOn SetLinkFlags ((CorNativeLinkFlags)(nlfLastError | GetLinkFlags())); } + InitCallConv(GetCallConvValueForPInvokeCallConv(callConv), pMD->IsVarArg()); + ErrExit: - if (hr != S_OK) + if (FAILED(hr)) SetError(IDS_EE_NDIRECT_BADNATL); - InitCallConv(GetCallConvValueForPInvokeCallConv(callConv), pMD->IsVarArg()); - if (throwOnError) ReportErrors(); } @@ -2727,13 +2706,13 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo( PreInit(pModule, NULL); m_sig = sig; - SetIsStatic (!(MetaSig::GetCallingConvention(pModule, sig) & IMAGE_CEE_CS_CALLCONV_HASTHIS)); + SetIsStatic(!(MetaSig::GetCallingConvention(sig) & IMAGE_CEE_CS_CALLCONV_HASTHIS)); InitCallConv(CallConvWinApiSentinel, FALSE); ReportErrors(); } -void PInvokeStaticSigInfo::DllImportInit(MethodDesc* pMD, LPCUTF8 *ppLibName, LPCUTF8 *ppEntryPointName) +void PInvokeStaticSigInfo::DllImportInit(_In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8 *ppLibName, _Outptr_opt_ LPCUTF8 *ppEntryPointName) { CONTRACTL { @@ -2803,7 +2782,7 @@ void PInvokeStaticSigInfo::DllImportInit(MethodDesc* pMD, LPCUTF8 *ppLibName, LP else if (unmappableMask == pmThrowOnUnmappableCharDisabled) SetThrowOnUnmappableChar (FALSE); - // inkFlags : CorPinvoke -> CorNativeLinkFlags + // linkFlags : CorPinvoke -> CorNativeLinkFlags if (mappingFlags & pmSupportsLastError) SetLinkFlags ((CorNativeLinkFlags)(GetLinkFlags() | nlfLastError)); if (mappingFlags & pmNoMangle) @@ -2829,7 +2808,7 @@ void PInvokeStaticSigInfo::DllImportInit(MethodDesc* pMD, LPCUTF8 *ppLibName, LP break; } - if (TryRemapLinkType(nlt, &nlt)) + if (SUCCEEDED(RemapLinkType(nlt, &nlt))) { SetCharSet(nlt); } @@ -4190,46 +4169,86 @@ static void CreateNDirectStubAccessMetadata( } } -void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo) +namespace { - if (pNMD->IsSynchronized()) - COMPlusThrow(kTypeLoadException, IDS_EE_NOSYNCHRONIZED); + void PopulateNDirectMethodDescImpl(_Inout_ NDirectMethodDesc* pNMD, _In_ const PInvokeStaticSigInfo& sigInfo, _In_z_ LPCUTF8 libName, _In_z_ LPCUTF8 entryPointName) + { + CONTRACTL + { + STANDARD_VM_CHECK; + PRECONDITION(pNMD != NULL); + } + CONTRACTL_END; - WORD ndirectflags = 0; - if (pNMD->MethodDesc::IsVarArg()) - ndirectflags |= NDirectMethodDesc::kVarArgs; + WORD ndirectflags = 0; + if (pNMD->MethodDesc::IsVarArg()) + ndirectflags |= NDirectMethodDesc::kVarArgs; - LPCUTF8 szLibName = NULL, szEntryPointName = NULL; - new (pSigInfo) PInvokeStaticSigInfo(pNMD, &szLibName, &szEntryPointName); + if (sigInfo.GetCharSet() == nltAnsi) + ndirectflags |= NDirectMethodDesc::kNativeAnsi; - if (pSigInfo->GetCharSet() == nltAnsi) - ndirectflags |= NDirectMethodDesc::kNativeAnsi; + CorNativeLinkFlags linkflags = sigInfo.GetLinkFlags(); + if (linkflags & nlfLastError) + ndirectflags |= NDirectMethodDesc::kLastError; + if (linkflags & nlfNoMangle) + ndirectflags |= NDirectMethodDesc::kNativeNoMangle; - CorNativeLinkFlags linkflags = pSigInfo->GetLinkFlags(); - if (linkflags & nlfLastError) - ndirectflags |= NDirectMethodDesc::kLastError; - if (linkflags & nlfNoMangle) - ndirectflags |= NDirectMethodDesc::kNativeNoMangle; + CorInfoCallConvExtension callConv = sigInfo.GetCallConv(); + if (callConv == CorInfoCallConvExtension::Stdcall) + ndirectflags |= NDirectMethodDesc::kStdCall; + if (callConv == CorInfoCallConvExtension::Thiscall) + ndirectflags |= NDirectMethodDesc::kThisCall; + + if (pNMD->GetLoaderModule()->IsSystem() && (strcmp(libName, "QCall") == 0)) + { + ndirectflags |= NDirectMethodDesc::kIsQCall; + } + else + { + pNMD->ndirect.m_pszLibName.SetValueMaybeNull(libName); + pNMD->ndirect.m_pszEntrypointName.SetValueMaybeNull(entryPointName); + } - CorInfoCallConvExtension callConv = pSigInfo->GetCallConv(); - if (callConv == CorInfoCallConvExtension::Stdcall) - ndirectflags |= NDirectMethodDesc::kStdCall; - if (callConv == CorInfoCallConvExtension::Thiscall) - ndirectflags |= NDirectMethodDesc::kThisCall; + // Call this exactly ONCE per thread. Do not publish incomplete prestub flags + // or you will introduce a race condition. + pNMD->InterlockedSetNDirectFlags(ndirectflags); + } +} - if (pNMD->GetLoaderModule()->IsSystem() && (strcmp(szLibName, "QCall") == 0)) +void NDirect::PopulateNDirectMethodDesc(_Inout_ NDirectMethodDesc* pNMD) +{ + CONTRACTL { - ndirectflags |= NDirectMethodDesc::kIsQCall; + STANDARD_VM_CHECK; + PRECONDITION(CheckPointer(pNMD)); } - else + CONTRACTL_END; + + if (pNMD->IsSynchronized()) + COMPlusThrow(kTypeLoadException, IDS_EE_NOSYNCHRONIZED); + + LPCUTF8 szLibName = NULL, szEntryPointName = NULL; + PInvokeStaticSigInfo sigInfo(pNMD, &szLibName, &szEntryPointName); + PopulateNDirectMethodDescImpl(pNMD, sigInfo, szLibName, szEntryPointName); +} + +void NDirect::InitializeSigInfoAndPopulateNDirectMethodDesc(_Inout_ NDirectMethodDesc* pNMD, _Inout_ PInvokeStaticSigInfo* pSigInfo) +{ + CONTRACTL { - pNMD->ndirect.m_pszLibName.SetValueMaybeNull(szLibName); - pNMD->ndirect.m_pszEntrypointName.SetValueMaybeNull(szEntryPointName); + STANDARD_VM_CHECK; + PRECONDITION(CheckPointer(pNMD)); + PRECONDITION(CheckPointer(pSigInfo)); } + CONTRACTL_END; + + if (pNMD->IsSynchronized()) + COMPlusThrow(kTypeLoadException, IDS_EE_NOSYNCHRONIZED); - // Call this exactly ONCE per thread. Do not publish incomplete prestub flags - // or you will introduce a race condition. - pNMD->InterlockedSetNDirectFlags(ndirectflags); + LPCUTF8 szLibName = NULL, szEntryPointName = NULL; + new (pSigInfo) PInvokeStaticSigInfo(pNMD, &szLibName, &szEntryPointName); + + PopulateNDirectMethodDescImpl(pNMD, *pSigInfo, szLibName, szEntryPointName); } #ifdef FEATURE_COMINTEROP @@ -5044,7 +5063,7 @@ MethodDesc* NDirect::CreateFieldAccessILStub( sigBuilder.AppendBlob((const PVOID)(szMetaSig + 1), cbMetaSigSize - 1); szMetaSig = (PCCOR_SIGNATURE)sigBuilder.GetSignature(&cbMetaSigSize); - StubSigDesc sigDesc(nullptr, Signature(szMetaSig, cbMetaSigSize), pModule); + StubSigDesc sigDesc(Signature(szMetaSig, cbMetaSigSize), pModule); #ifdef _DEBUG sigDesc.m_pDebugName = pFD->GetDebugName(); @@ -5199,9 +5218,14 @@ MethodDesc* NDirect::CreateCLRToNativeILStub(PInvokeStaticSigInfo* pSigInfo, DWORD dwStubFlags, MethodDesc* pMD) { - STANDARD_VM_CONTRACT; + CONTRACTL + { + STANDARD_VM_CHECK; + PRECONDITION(pSigInfo != NULL); + } + CONTRACTL_END; - StubSigDesc sigDesc(pMD, pSigInfo); + StubSigDesc sigDesc(pMD, pSigInfo->GetSignature(), pSigInfo->GetModule()); return CreateCLRToNativeILStub(&sigDesc, pSigInfo->GetCharSet(), @@ -5212,7 +5236,12 @@ MethodDesc* NDirect::CreateCLRToNativeILStub(PInvokeStaticSigInfo* pSigInfo, MethodDesc* NDirect::GetILStubMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo, DWORD dwStubFlags) { - STANDARD_VM_CONTRACT; + CONTRACTL + { + STANDARD_VM_CHECK; + PRECONDITION(pNMD != NULL); + } + CONTRACTL_END; MethodDesc* pStubMD = NULL; @@ -5417,7 +5446,7 @@ PCODE NDirect::GetStubForILStub(NDirectMethodDesc* pNMD, MethodDesc** ppStubMD, if (NULL == *ppStubMD) { PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc(pNMD, &sigInfo); + NDirect::InitializeSigInfoAndPopulateNDirectMethodDesc(pNMD, &sigInfo); *ppStubMD = NDirect::GetILStubMethodDesc(pNMD, &sigInfo, dwStubFlags); } @@ -5782,8 +5811,7 @@ EXTERN_C LPVOID STDCALL NDirectImportWorker(NDirectMethodDesc* pMD) { // we need the MD to be populated in case we decide to build an intercept // stub to wrap the target in InitEarlyBoundNDirectTarget - PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc(pMD, &sigInfo); + NDirect::PopulateNDirectMethodDesc(pMD); } pMD->InitEarlyBoundNDirectTarget(); @@ -5805,8 +5833,7 @@ EXTERN_C LPVOID STDCALL NDirectImportWorker(NDirectMethodDesc* pMD) if (!pMD->IsZapped()) { - PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc(pMD, &sigInfo); + NDirect::PopulateNDirectMethodDesc(pMD); } else { @@ -5933,7 +5960,7 @@ PCODE GetILStubForCalli(VASigCookie *pVASigCookie, MethodDesc *pMD) dwStubFlags |= NDIRECTSTUB_FL_UNMANAGED_CALLI; // need to convert the CALLI signature to stub signature with managed calling convention - BYTE callConv = MetaSig::GetCallingConvention(pVASigCookie->pModule, signature); + BYTE callConv = MetaSig::GetCallingConvention(signature); // Unmanaged calling convention indicates modopt should be read if (callConv != IMAGE_CEE_CS_CALLCONV_UNMANAGED) diff --git a/src/coreclr/vm/dllimport.h b/src/coreclr/vm/dllimport.h index 6625ec11ca7ac..1631196899136 100644 --- a/src/coreclr/vm/dllimport.h +++ b/src/coreclr/vm/dllimport.h @@ -15,10 +15,10 @@ struct PInvokeStaticSigInfo; struct StubSigDesc { public: - StubSigDesc(MethodDesc * pMD, PInvokeStaticSigInfo* pSigInfo = NULL); - StubSigDesc(MethodDesc* pMD, Signature sig, Module* m_pModule); - StubSigDesc(MethodTable* pMT, Signature sig, Module* m_pModule); - StubSigDesc(std::nullptr_t, Signature sig, Module* m_pModule); + StubSigDesc(MethodDesc* pMD); + StubSigDesc(MethodDesc* pMD, const Signature& sig, Module* m_pModule); + StubSigDesc(MethodTable* pMT, const Signature& sig, Module* m_pModule); + StubSigDesc(const Signature& sig, Module* m_pModule); MethodDesc *m_pMD; MethodTable *m_pMT; @@ -71,7 +71,9 @@ class NDirect _In_opt_ PCCOR_SIGNATURE pSig = NULL, _In_opt_ Module* pModule = NULL, _In_ bool unmanagedCallersOnlyRequiresMarshalling = true); - static void PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo); + + static void PopulateNDirectMethodDesc(_Inout_ NDirectMethodDesc* pNMD); + static void InitializeSigInfoAndPopulateNDirectMethodDesc(_Inout_ NDirectMethodDesc* pNMD, _Inout_ PInvokeStaticSigInfo* pSigInfo); static MethodDesc* CreateCLRToNativeILStub( StubSigDesc* pSigDesc, @@ -303,30 +305,54 @@ struct PInvokeStaticSigInfo PInvokeStaticSigInfo(MethodDesc* pMdDelegate, ThrowOnError throwOnError = THROW_ON_ERROR); - PInvokeStaticSigInfo(MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName); - -public: - void ReportErrors(); + PInvokeStaticSigInfo(_In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8 *pLibName, _Outptr_opt_ LPCUTF8 *pEntryPointName); private: + void ReportErrors(); void InitCallConv(CorInfoCallConvExtension callConv, BOOL bIsVarArg); - void DllImportInit(MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName); + void DllImportInit(_In_ MethodDesc* pMD, _Outptr_opt_ LPCUTF8 *pLibName, _Outptr_opt_ LPCUTF8 *pEntryPointName); void PreInit(Module* pModule, MethodTable *pClass); void PreInit(MethodDesc* pMD); void SetError(WORD error) { if (!m_error) m_error = error; } void BestGuessNDirectDefaults(MethodDesc* pMD); -public: - DWORD GetStubFlags() +private: + enum + { + PINVOKE_STATIC_SIGINFO_IS_STATIC = 0x0001, + PINVOKE_STATIC_SIGINFO_THROW_ON_UNMAPPABLE_CHAR = 0x0002, + PINVOKE_STATIC_SIGINFO_BEST_FIT = 0x0004, + + COR_NATIVE_LINK_TYPE_MASK = 0x0038, // 0000 0000 0011 1000 <--- These 3 1's make the link type mask + + COR_NATIVE_LINK_FLAGS_MASK = 0x00C0, //0000 0000 1100 0000 <---- These 2 bits make up the link flags + + PINVOKE_STATIC_SIGINFO_IS_DELEGATE_INTEROP = 0x0100, + + }; + #define COR_NATIVE_LINK_TYPE_SHIFT 3 // Keep in synch with above mask + #define COR_NATIVE_LINK_FLAGS_SHIFT 6 // Keep in synch with above mask + +public: // getters + DWORD GetStubFlags() const { WRAPPER_NO_CONTRACT; return (GetThrowOnUnmappableChar() ? NDIRECTSTUB_FL_THROWONUNMAPPABLECHAR : 0) | (GetBestFitMapping() ? NDIRECTSTUB_FL_BESTFIT : 0) | (IsDelegateInterop() ? NDIRECTSTUB_FL_DELEGATE : 0); } - Module* GetModule() { LIMITED_METHOD_CONTRACT; return m_pModule; } - BOOL IsStatic() { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_IS_STATIC; } - void SetIsStatic (BOOL isStatic) + Module* GetModule() const { LIMITED_METHOD_CONTRACT; return m_pModule; } + BOOL IsStatic() const { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_IS_STATIC; } + BOOL GetThrowOnUnmappableChar() const { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_THROW_ON_UNMAPPABLE_CHAR; } + BOOL GetBestFitMapping() const { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_BEST_FIT; } + BOOL IsDelegateInterop() const { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_IS_DELEGATE_INTEROP; } + CorInfoCallConvExtension GetCallConv() const { LIMITED_METHOD_CONTRACT; return m_callConv; } + Signature GetSignature() const { LIMITED_METHOD_CONTRACT; return m_sig; } + CorNativeLinkType GetCharSet() const { LIMITED_METHOD_CONTRACT; return (CorNativeLinkType)((m_wFlags & COR_NATIVE_LINK_TYPE_MASK) >> COR_NATIVE_LINK_TYPE_SHIFT); } + CorNativeLinkFlags GetLinkFlags() const { LIMITED_METHOD_CONTRACT; return (CorNativeLinkFlags)((m_wFlags & COR_NATIVE_LINK_FLAGS_MASK) >> COR_NATIVE_LINK_FLAGS_SHIFT); } + +private: // setters + void SetIsStatic(BOOL isStatic) { LIMITED_METHOD_CONTRACT; if (isStatic) @@ -334,8 +360,7 @@ struct PInvokeStaticSigInfo else m_wFlags &= ~PINVOKE_STATIC_SIGINFO_IS_STATIC; } - BOOL GetThrowOnUnmappableChar() { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_THROW_ON_UNMAPPABLE_CHAR; } - void SetThrowOnUnmappableChar (BOOL throwOnUnmappableChar) + void SetThrowOnUnmappableChar(BOOL throwOnUnmappableChar) { LIMITED_METHOD_CONTRACT; if (throwOnUnmappableChar) @@ -343,8 +368,7 @@ struct PInvokeStaticSigInfo else m_wFlags &= ~PINVOKE_STATIC_SIGINFO_THROW_ON_UNMAPPABLE_CHAR; } - BOOL GetBestFitMapping() { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_BEST_FIT; } - void SetBestFitMapping (BOOL bestFit) + void SetBestFitMapping(BOOL bestFit) { LIMITED_METHOD_CONTRACT; if (bestFit) @@ -352,8 +376,7 @@ struct PInvokeStaticSigInfo else m_wFlags &= ~PINVOKE_STATIC_SIGINFO_BEST_FIT; } - BOOL IsDelegateInterop() { LIMITED_METHOD_CONTRACT; return m_wFlags & PINVOKE_STATIC_SIGINFO_IS_DELEGATE_INTEROP; } - void SetIsDelegateInterop (BOOL delegateInterop) + void SetIsDelegateInterop(BOOL delegateInterop) { LIMITED_METHOD_CONTRACT; if (delegateInterop) @@ -361,35 +384,6 @@ struct PInvokeStaticSigInfo else m_wFlags &= ~PINVOKE_STATIC_SIGINFO_IS_DELEGATE_INTEROP; } - CorInfoCallConvExtension GetCallConv() { LIMITED_METHOD_CONTRACT; return m_callConv; } - Signature GetSignature() { LIMITED_METHOD_CONTRACT; return m_sig; } - -private: - Module* m_pModule; - Signature m_sig; - CorInfoCallConvExtension m_callConv; - WORD m_error; - - enum - { - PINVOKE_STATIC_SIGINFO_IS_STATIC = 0x0001, - PINVOKE_STATIC_SIGINFO_THROW_ON_UNMAPPABLE_CHAR = 0x0002, - PINVOKE_STATIC_SIGINFO_BEST_FIT = 0x0004, - - COR_NATIVE_LINK_TYPE_MASK = 0x0038, // 0000 0000 0011 1000 <--- These 3 1's make the link type mask - - COR_NATIVE_LINK_FLAGS_MASK = 0x00C0, //0000 0000 1100 0000 <---- These 2 bits make up the link flags - - PINVOKE_STATIC_SIGINFO_IS_DELEGATE_INTEROP = 0x0100, - - }; - #define COR_NATIVE_LINK_TYPE_SHIFT 3 // Keep in synch with above mask - #define COR_NATIVE_LINK_FLAGS_SHIFT 6 // Keep in synch with above mask - WORD m_wFlags; - - public: - CorNativeLinkType GetCharSet() { LIMITED_METHOD_CONTRACT; return (CorNativeLinkType)((m_wFlags & COR_NATIVE_LINK_TYPE_MASK) >> COR_NATIVE_LINK_TYPE_SHIFT); } - CorNativeLinkFlags GetLinkFlags() { LIMITED_METHOD_CONTRACT; return (CorNativeLinkFlags)((m_wFlags & COR_NATIVE_LINK_FLAGS_MASK) >> COR_NATIVE_LINK_FLAGS_SHIFT); } void SetCharSet(CorNativeLinkType linktype) { LIMITED_METHOD_CONTRACT; @@ -408,6 +402,13 @@ struct PInvokeStaticSigInfo // Then set the given value m_wFlags |= (linkflags << COR_NATIVE_LINK_FLAGS_SHIFT); } + +private: + Module* m_pModule; + Signature m_sig; + CorInfoCallConvExtension m_callConv; + WORD m_error; + WORD m_wFlags; }; diff --git a/src/coreclr/vm/frames.cpp b/src/coreclr/vm/frames.cpp index 10ba921108d8c..8ab02c7642364 100644 --- a/src/coreclr/vm/frames.cpp +++ b/src/coreclr/vm/frames.cpp @@ -1261,7 +1261,7 @@ void TransitionFrame::PromoteCallerStack(promote_func* fn, ScanContext* sc) } //If not "vararg" calling convention, assume "default" calling convention - if (!MetaSig::IsVarArg(pFunction->GetModule(), callSignature)) + if (!MetaSig::IsVarArg(callSignature)) { SigTypeContext typeContext(pFunction); PCCOR_SIGNATURE pSig; @@ -2064,7 +2064,7 @@ bool CheckGCRefMapEqual(PTR_BYTE pGCRefMap, MethodDesc* pMD, bool isDispatchCell #ifdef _DEBUG GCRefMapBuilder gcRefMapNew; ComputeCallRefMap(pMD, &gcRefMapNew, isDispatchCell); - + DWORD dwFinalLength; PVOID pBlob = gcRefMapNew.GetBlob(&dwFinalLength); diff --git a/src/coreclr/vm/memberload.cpp b/src/coreclr/vm/memberload.cpp index 313e616568d2d..76d434ddcc1c2 100644 --- a/src/coreclr/vm/memberload.cpp +++ b/src/coreclr/vm/memberload.cpp @@ -338,7 +338,7 @@ void MemberLoader::GetDescFromMemberRef(Module * pModule, IfFailThrow(pInternalImport->GetNameAndSigOfMemberRef(MemberRef, &pSig, &cSig, &szMember)); BOOL fIsField = isCallConv( - MetaSig::GetCallingConvention(pModule, Signature(pSig, cSig)), + MetaSig::GetCallingConvention(Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD); if (fIsField) @@ -462,7 +462,7 @@ MethodDesc * MemberLoader::GetMethodDescFromMemberRefAndType(Module * pModule, IfFailThrow(pInternalImport->GetNameAndSigOfMemberRef(MemberRef, &pSig, &cSig, &szMember)); - _ASSERTE(!isCallConv(MetaSig::GetCallingConvention(pModule, Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)); + _ASSERTE(!isCallConv(MetaSig::GetCallingConvention(Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)); // For array method signatures, the caller's signature contains "actual" types whereas the callee's signature has // formals (ELEMENT_TYPE_VAR 0 wherever the element type of the array occurs). So we need to pass in a substitution @@ -532,7 +532,7 @@ FieldDesc * MemberLoader::GetFieldDescFromMemberRefAndType(Module * pModule, IfFailThrow(pInternalImport->GetNameAndSigOfMemberRef(MemberRef, &pSig, &cSig, &szMember)); - _ASSERTE(isCallConv(MetaSig::GetCallingConvention(pModule, Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)); + _ASSERTE(isCallConv(MetaSig::GetCallingConvention(Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)); FieldDesc * pFD = MemberLoader::FindField(pMT, szMember, pSig, cSig, pModule); diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 584adb25fe25d..75981105f3cdf 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -1140,7 +1140,7 @@ BOOL MethodDesc::IsVarArg() Signature signature = GetSignature(); _ASSERTE(!signature.IsEmpty()); - return MetaSig::IsVarArg(GetModule(), signature); + return MetaSig::IsVarArg(signature); } //******************************************************************************* @@ -2581,8 +2581,7 @@ void MethodDesc::Save(DataImage *image) { EX_TRY { - PInvokeStaticSigInfo sigInfo; - NDirect::PopulateNDirectMethodDesc((NDirectMethodDesc*)this, &sigInfo); + NDirect::PopulateNDirectMethodDesc((NDirectMethodDesc*)this); } EX_CATCH { diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index f14d3e2c0202c..ea8d9425889e1 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -2557,7 +2557,7 @@ HRESULT MethodTableBuilder::FindMethodDeclarationForMethodImpl( IfFailRet(pMDInternalImport->GetNameAndSigOfMemberRef(pToken, &pSig, &cSig, &szMember)); if (isCallConv( - MetaSig::GetCallingConvention(GetModule(), Signature(pSig, cSig)), + MetaSig::GetCallingConvention(Signature(pSig, cSig)), IMAGE_CEE_CS_CALLCONV_FIELD)) { return VLDTR_E_MR_BADCALLINGCONV; @@ -5008,7 +5008,7 @@ MethodTableBuilder::ValidateMethods() pMemberSignature = it.GetSig(&cMemberSignature); } - if (MetaSig::IsVarArg(pModule, Signature(pMemberSignature, cMemberSignature))) + if (MetaSig::IsVarArg(Signature(pMemberSignature, cMemberSignature))) { BuildMethodTableThrowException(BFA_GENCODE_NOT_BE_VARARG); } diff --git a/src/coreclr/vm/siginfo.hpp b/src/coreclr/vm/siginfo.hpp index c41abe99af5da..38d96109efd48 100644 --- a/src/coreclr/vm/siginfo.hpp +++ b/src/coreclr/vm/siginfo.hpp @@ -683,7 +683,6 @@ class MetaSig // defines in cor.h) - throws. //---------------------------------------------------------- static BYTE GetCallingConvention( - Module *pModule, const Signature &signature) { CONTRACTL @@ -710,7 +709,6 @@ class MetaSig //---------------------------------------------------------- __checkReturn static HRESULT GetCallingConvention_NoThrow( - Module *pModule, const Signature &signature, BYTE *pbCallingConvention) { @@ -798,7 +796,7 @@ class MetaSig //---------------------------------------------------------- // Is vararg? //---------------------------------------------------------- - static BOOL IsVarArg(Module *pModule, const Signature &signature) + static BOOL IsVarArg(const Signature &signature) { CONTRACTL { @@ -812,7 +810,7 @@ class MetaSig HRESULT hr; BYTE nCallingConvention; - hr = GetCallingConvention_NoThrow(pModule, signature, &nCallingConvention); + hr = GetCallingConvention_NoThrow(signature, &nCallingConvention); if (FAILED(hr)) { // Invalid signatures are not VarArg return FALSE;