From 87e5abff3083ad9480d376f99bd136420cff62a1 Mon Sep 17 00:00:00 2001 From: David Wrighton <10779849+davidwrighton@users.noreply.github.com> Date: Tue, 29 Sep 2026 19:31:00 +0000 Subject: [PATCH 1/4] Use internal metadata interfaces in CoreCLR Avoid legacy public metadata import and emit interfaces when profiler support is disabled, and migrate Reflection.Emit to the internal metadata surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/ildasm/dasm.cpp | 3 +- src/coreclr/inc/corpriv.h | 50 +--- src/coreclr/inc/metadata.h | 236 +++++++++++++++++- src/coreclr/md/compiler/CMakeLists.txt | 7 +- src/coreclr/md/compiler/emit.cpp | 6 + src/coreclr/md/compiler/helper.cpp | 151 ++--------- src/coreclr/md/compiler/regmeta.cpp | 27 +- src/coreclr/md/compiler/regmeta.h | 33 +-- src/coreclr/md/enc/CMakeLists.txt | 7 +- src/coreclr/md/enc/mdinternalrw.cpp | 79 +----- src/coreclr/md/inc/liteweightstgdb.h | 4 +- src/coreclr/md/inc/mdinternalrw.h | 14 +- src/coreclr/md/runtime/CMakeLists.txt | 7 +- src/coreclr/md/runtime/mdinternalro.cpp | 98 ++------ src/coreclr/md/runtime/mdinternalro.h | 12 +- src/coreclr/md/runtime/noopmetadataimport.cpp | 4 +- src/coreclr/vm/assembly.cpp | 10 +- src/coreclr/vm/assembly.hpp | 2 +- src/coreclr/vm/assemblyspec.cpp | 2 +- src/coreclr/vm/assemblyspec.hpp | 2 +- src/coreclr/vm/baseassemblyspec.h | 1 - src/coreclr/vm/baseassemblyspec.inl | 84 ------- src/coreclr/vm/ceeload.cpp | 16 +- src/coreclr/vm/ceeload.h | 4 +- src/coreclr/vm/comdynamic.cpp | 10 +- src/coreclr/vm/commodule.cpp | 64 ++--- src/coreclr/vm/field.h | 10 - src/coreclr/vm/method.hpp | 18 -- src/coreclr/vm/peassembly.cpp | 51 +++- src/coreclr/vm/peassembly.h | 19 +- src/coreclr/vm/peassembly.inl | 12 +- src/coreclr/vm/reflectclasswriter.cpp | 42 +--- src/coreclr/vm/reflectclasswriter.h | 22 +- 33 files changed, 473 insertions(+), 634 deletions(-) diff --git a/src/coreclr/ildasm/dasm.cpp b/src/coreclr/ildasm/dasm.cpp index 45f0070ffc390d..c068407ca28b9b 100644 --- a/src/coreclr/ildasm/dasm.cpp +++ b/src/coreclr/ildasm/dasm.cpp @@ -628,7 +628,8 @@ BOOL EnumClasses() } } } - g_pImport->EnumMethodImplClose(&hBody,&hDecl); + g_pImport->EnumClose(&hBody); + g_pImport->EnumClose(&hDecl); } i++; } diff --git a/src/coreclr/inc/corpriv.h b/src/coreclr/inc/corpriv.h index 5df28e8d8ba851..56c3498bcc5b68 100644 --- a/src/coreclr/inc/corpriv.h +++ b/src/coreclr/inc/corpriv.h @@ -18,8 +18,10 @@ STDAPI CreateMetaDataDispenser( REFIID riid, void ** pMetaDataDispenserOut); +#ifdef FEATURE_ISYM_READER // Helper function to get a do-nothing IMetaDataImport2 instance for DIA. IMetaDataImport2* GetNoopMetaDataImport2(); +#endif // FEATURE_ISYM_READER // Helper function to get an Internal interface with an in-memory metadata section STDAPI GetMDInternalInterface( @@ -114,54 +116,6 @@ DECLARE_INTERFACE_(IMetaDataHelper, IUnknown) }; // IMetaDataHelper -EXTERN_GUID(IID_IMetaDataEmitHelper, 0x5c240ae4, 0x1e09, 0x11d3, 0x94, 0x24, 0x0, 0x0, 0xf8, 0x8, 0x34, 0x60); - -#undef INTERFACE -#define INTERFACE IMetaDataEmitHelper -DECLARE_INTERFACE_(IMetaDataEmitHelper, IUnknown) -{ - // emit helper functions - STDMETHOD(DefineMethodSemanticsHelper)( - mdToken tkAssociation, // [IN] property or event token - DWORD dwFlags, // [IN] semantics - mdMethodDef md) PURE; // [IN] method to associated with - - STDMETHOD(SetFieldLayoutHelper)( // Return hresult. - mdFieldDef fd, // [IN] field to associate the layout info - ULONG ulOffset) PURE; // [IN] the offset for the field - - STDMETHOD(DefineEventHelper) ( - mdTypeDef td, // [IN] the class/interface on which the event is being defined - LPCWSTR szEvent, // [IN] Name of the event - DWORD dwEventFlags, // [IN] CorEventAttr - mdToken tkEventType, // [IN] a reference (mdTypeRef or mdTypeRef) to the Event class - mdEvent *pmdEvent) PURE; // [OUT] output event token - - STDMETHOD(AddDeclarativeSecurityHelper) ( - mdToken tk, // [IN] Parent token (typedef/methoddef) - DWORD dwAction, // [IN] Security action (CorDeclSecurity) - void const *pValue, // [IN] Permission set blob - DWORD cbValue, // [IN] Byte count of permission set blob - mdPermission*pmdPermission) PURE; // [OUT] Output permission token - - STDMETHOD(SetResolutionScopeHelper)( // Return hresult. - mdTypeRef tr, // [IN] TypeRef record to update - mdToken rs) PURE; // [IN] new ResolutionScope - - STDMETHOD(SetManifestResourceOffsetHelper)( // Return hresult. - mdManifestResource mr, // [IN] The manifest token - ULONG ulOffset) PURE; // [IN] new offset - - STDMETHOD(SetTypeParent)( // Return hresult. - mdTypeDef td, // [IN] Type definition - mdToken tkExtends) PURE; // [IN] parent type - - STDMETHOD(AddInterfaceImpl)( // Return hresult. - mdTypeDef td, // [IN] Type definition - mdToken tkInterface) PURE; // [IN] interface type - -}; // IMetaDataEmitHelper - ////////////////////////////////////////////////////////////////////////////// // enum CorElementTypeZapSig defines some additional internal ELEMENT_TYPE's // values that are only used by ZapSig signatures. diff --git a/src/coreclr/inc/metadata.h b/src/coreclr/inc/metadata.h index 0ccd84eca08ab9..b6cb6eedc03387 100644 --- a/src/coreclr/inc/metadata.h +++ b/src/coreclr/inc/metadata.h @@ -18,6 +18,7 @@ class IMetaModelCommon; class MDInternalRW; +struct IMDInternalEmit; inline int IsGlobalMethodParentTk(mdTypeDef td) { @@ -324,10 +325,6 @@ DECLARE_INTERFACE_(IMDInternalImport, IUnknown) return phEnumBody->m_ulCount; } - STDMETHOD_(void, EnumMethodImplReset)( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) PURE; // [IN] MethodDecl enumerator. - __checkReturn STDMETHOD(EnumMethodImplNext)( // return hresult (S_OK = TRUE, S_FALSE = FALSE or error code) HENUMInternal *phEnumBody, // [IN] input enum for MethodBody @@ -335,10 +332,6 @@ DECLARE_INTERFACE_(IMDInternalImport, IUnknown) mdToken *ptkBody, // [OUT] return token for MethodBody mdToken *ptkDecl) PURE; // [OUT] return token for MethodDecl - STDMETHOD_(void, EnumMethodImplClose)( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) PURE; // [IN] MethodDecl enumerator. - //***************************************** // Enumerator helpers for memberdef, memberref, interfaceimp, // event, property, exception, param @@ -939,8 +932,8 @@ DECLARE_INTERFACE_(IMDInternalImport, IUnknown) ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit *pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit *emit, // [IN] emit interface + IMDInternalEmit *pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit *emit, // [IN] emit interface CQuickBytes *pqkSigEmit, // [OUT] buffer to hold translated signature ULONG *pcbSig) PURE; // [OUT] count of bytes in the translated signature @@ -1079,6 +1072,229 @@ DECLARE_INTERFACE_(IMDInternalEmit, IUnknown) STDMETHOD(SetMDUpdateMode)( ULONG updateMode, ULONG *pPreviousUpdateMode) PURE; + STDMETHOD(SetModuleProps)( + LPCWSTR szName) PURE; + + STDMETHOD(GetSaveSize)( + CorSaveSize fSave, + DWORD *pdwSaveSize) PURE; + + STDMETHOD(SaveToMemory)( + void *pbData, + ULONG cbData) PURE; + + STDMETHOD(DefineTypeDef)( + LPCWSTR szTypeDef, + DWORD dwTypeDefFlags, + mdToken tkExtends, + mdToken rtkImplements[], + mdTypeDef *ptd) PURE; + + STDMETHOD(DefineNestedType)( + LPCWSTR szTypeDef, + DWORD dwTypeDefFlags, + mdToken tkExtends, + mdToken rtkImplements[], + mdTypeDef tdEncloser, + mdTypeDef *ptd) PURE; + + STDMETHOD(DefineMethod)( + mdTypeDef td, + LPCWSTR szName, + DWORD dwMethodFlags, + PCCOR_SIGNATURE pvSigBlob, + ULONG cbSigBlob, + ULONG ulCodeRVA, + DWORD dwImplFlags, + mdMethodDef *pmd) PURE; + + STDMETHOD(DefineMethodImpl)( + mdTypeDef td, + mdToken tkBody, + mdToken tkDecl) PURE; + + STDMETHOD(DefineTypeRefByName)( + mdToken tkResolutionScope, + LPCWSTR szName, + mdTypeRef *ptr) PURE; + + STDMETHOD(DefineMemberRef)( + mdToken tkImport, + LPCWSTR szName, + PCCOR_SIGNATURE pvSigBlob, + ULONG cbSigBlob, + mdMemberRef *pmr) PURE; + + STDMETHOD(SetClassLayout)( + mdTypeDef td, + DWORD dwPackSize, + COR_FIELD_OFFSET rFieldOffsets[], + ULONG ulClassSize) PURE; + + STDMETHOD(GetTokenFromSig)( + PCCOR_SIGNATURE pvSig, + ULONG cbSig, + mdSignature *pmsig) PURE; + + STDMETHOD(DefineModuleRef)( + LPCWSTR szName, + mdModuleRef *pmur) PURE; + + STDMETHOD(GetTokenFromTypeSpec)( + PCCOR_SIGNATURE pvSig, + ULONG cbSig, + mdTypeSpec *ptypespec) PURE; + + STDMETHOD(DefineUserString)( + LPCWSTR szString, + ULONG cchString, + mdString *pstk) PURE; + + STDMETHOD(SetMethodProps)( + mdMethodDef md, + DWORD dwMethodFlags, + ULONG ulCodeRVA, + DWORD dwImplFlags) PURE; + + STDMETHOD(DefinePinvokeMap)( + mdToken tk, + DWORD dwMappingFlags, + LPCWSTR szImportName, + mdModuleRef mrImportDLL) PURE; + + STDMETHOD(DefineCustomAttribute)( + mdToken tkOwner, + mdToken tkCtor, + void const *pCustomAttribute, + ULONG cbCustomAttribute, + mdCustomAttribute *pcv) PURE; + + STDMETHOD(DefineField)( + mdTypeDef td, + LPCWSTR szName, + DWORD dwFieldFlags, + PCCOR_SIGNATURE pvSigBlob, + ULONG cbSigBlob, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue, + mdFieldDef *pmd) PURE; + + STDMETHOD(DefineProperty)( + mdTypeDef td, + LPCWSTR szProperty, + DWORD dwPropFlags, + PCCOR_SIGNATURE pvSig, + ULONG cbSig, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue, + mdMethodDef mdSetter, + mdMethodDef mdGetter, + mdMethodDef rmdOtherMethods[], + mdProperty *pmdProp) PURE; + + STDMETHOD(DefineParam)( + mdMethodDef md, + ULONG ulParamSeq, + LPCWSTR szName, + DWORD dwParamFlags, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue, + mdParamDef *ppd) PURE; + + STDMETHOD(SetFieldProps)( + mdFieldDef fd, + DWORD dwFieldFlags, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue) PURE; + + STDMETHOD(SetPropertyProps)( + mdProperty pr, + DWORD dwPropFlags, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue, + mdMethodDef mdSetter, + mdMethodDef mdGetter, + mdMethodDef rmdOtherMethods[]) PURE; + + STDMETHOD(SetParamProps)( + mdParamDef pd, + LPCWSTR szName, + DWORD dwParamFlags, + DWORD dwCPlusTypeFlag, + void const *pValue, + ULONG cchValue) PURE; + + STDMETHOD(SetMethodImplFlags)( + mdMethodDef md, + DWORD dwImplFlags) PURE; + + STDMETHOD(SetFieldRVA)( + mdFieldDef fd, + ULONG ulRVA) PURE; + + STDMETHOD(DefineMethodSpec)( + mdToken tkParent, + PCCOR_SIGNATURE pvSigBlob, + ULONG cbSigBlob, + mdMethodSpec *pmi) PURE; + + STDMETHOD(DefineGenericParam)( + mdToken tk, + ULONG ulParamSeq, + DWORD dwParamFlags, + LPCWSTR szName, + DWORD reserved, + mdToken rtkConstraints[], + mdGenericParam *pgp) PURE; + + STDMETHOD(DefineAssembly)( + const void *pbPublicKey, + ULONG cbPublicKey, + ULONG ulHashAlgId, + LPCWSTR szName, + const ASSEMBLYMETADATA *pMetaData, + DWORD dwAssemblyFlags, + mdAssembly *pma) PURE; + + STDMETHOD(DefineAssemblyRef)( + const void *pbPublicKeyOrToken, + ULONG cbPublicKeyOrToken, + LPCWSTR szName, + const ASSEMBLYMETADATA *pMetaData, + const void *pbHashValue, + ULONG cbHashValue, + DWORD dwAssemblyRefFlags, + mdAssemblyRef *pmdar) PURE; + + STDMETHOD(DefineMethodSemanticsHelper)( + mdToken tkAssociation, + DWORD dwFlags, + mdMethodDef md) PURE; + + STDMETHOD(SetFieldLayoutHelper)( + mdFieldDef fd, + ULONG ulOffset) PURE; + + STDMETHOD(DefineEventHelper)( + mdTypeDef td, + LPCWSTR szEvent, + DWORD dwEventFlags, + mdToken tkEventType, + mdEvent *pmdEvent) PURE; + + STDMETHOD(SetTypeParent)( + mdTypeDef td, + mdToken tkExtends) PURE; + + STDMETHOD(AddInterfaceImpl)( + mdTypeDef td, + mdToken tkInterface) PURE; + }; // IMDInternalEmit enum MetaDataReorderingOptions { diff --git a/src/coreclr/md/compiler/CMakeLists.txt b/src/coreclr/md/compiler/CMakeLists.txt index 7a365343b36718..99c3a62511527f 100644 --- a/src/coreclr/md/compiler/CMakeLists.txt +++ b/src/coreclr/md/compiler/CMakeLists.txt @@ -48,16 +48,21 @@ endif() add_library_clr(mdcompiler_dac ${MDCOMPILER_SOURCES}) set_target_properties(mdcompiler_dac PROPERTIES DAC_COMPONENT TRUE) +target_compile_definitions(mdcompiler_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdcompiler_dac PRIVATE stdafx.h) add_library_clr(mdcompiler_wks OBJECT ${MDCOMPILER_SOURCES}) target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +if (FEATURE_CORPROFILER) + target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) +endif() target_precompile_headers(mdcompiler_wks PRIVATE stdafx.h) add_library_clr(mdcompiler-dbi ${MDCOMPILER_SOURCES}) set_target_properties(mdcompiler-dbi PROPERTIES DBI_COMPONENT TRUE) +target_compile_definitions(mdcompiler-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdcompiler-dbi PRIVATE stdafx.h) add_library_clr(mdcompiler_ppdb ${MDCOMPILER_SOURCES}) -target_compile_definitions(mdcompiler_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB SELF_NO_HOST) +target_compile_definitions(mdcompiler_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdcompiler_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/compiler/emit.cpp b/src/coreclr/md/compiler/emit.cpp index 6394b4918d86b0..114bf109261f52 100644 --- a/src/coreclr/md/compiler/emit.cpp +++ b/src/coreclr/md/compiler/emit.cpp @@ -370,6 +370,7 @@ STDMETHODIMP RegMeta::DefineTypeRefByName( // S_OK or error. //***************************************************************************** // Create a reference, in an emit scope, to a TypeDef in another scope. //***************************************************************************** +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::DefineImportType( // S_OK or error. IMetaDataAssemblyImport *pAssemImport, // [IN] Assembly containing the TypeDef. const void *pbHashValue, // [IN] Hash Blob for Assembly. @@ -436,6 +437,7 @@ STDMETHODIMP RegMeta::DefineImportType( // S_OK or error. return hr; #endif //!FEATURE_METADATA_EMIT_IN_DEBUGGER } // RegMeta::DefineImportType +#endif // FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Create and set a MemberRef record. @@ -524,6 +526,7 @@ STDMETHODIMP RegMeta::DefineMemberRef( // S_OK or error //***************************************************************************** // Create a MemberRef record based on a member in an import scope. //***************************************************************************** +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::DefineImportMember( // S_OK or error. IMetaDataAssemblyImport *pAssemImport, // [IN] Assembly containing the Member. const void *pbHashValue, // [IN] Hash Blob for Assembly. @@ -625,6 +628,7 @@ STDMETHODIMP RegMeta::DefineImportMember( // S_OK or error. return hr; #endif //!FEATURE_METADATA_EMIT_IN_DEBUGGER } // RegMeta::DefineImportMember +#endif // FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Define and set a Event record. @@ -2944,6 +2948,7 @@ HRESULT RegMeta::DefineSecurityAttributeSet(// Return code. //***************************************************************************** // Apply edit and continue changes to this metadata. //***************************************************************************** +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::ApplyEditAndContinue( // S_OK or error. IUnknown *pUnk) // [IN] Metadata from the delta PE. { @@ -2975,5 +2980,6 @@ STDMETHODIMP RegMeta::ApplyEditAndContinue( // S_OK or error. return E_NOTIMPL; #endif //!FEATURE_METADATA_EMIT_ALL } // RegMeta::ApplyEditAndContinue +#endif // FEATURE_METADATA_PUBLIC_INTERFACES #endif //FEATURE_METADATA_EMIT diff --git a/src/coreclr/md/compiler/helper.cpp b/src/coreclr/md/compiler/helper.cpp index 955642853d543a..5330d31dc17e22 100644 --- a/src/coreclr/md/compiler/helper.cpp +++ b/src/coreclr/md/compiler/helper.cpp @@ -5,7 +5,7 @@ // // -// Implementation of some internal APIs from code:IMetaDataHelper and code:IMetaDataEmitHelper. +// Implementation of some internal APIs from code:IMetaDataHelper and code:IMDInternalEmit. // //***************************************************************************** #include "stdafx.h" @@ -40,13 +40,22 @@ STDMETHODIMP RegMeta::TranslateSigWithScope( // S_OK or error. IMDCommon *pAssemImportMDCommon = NULL; IMDCommon *pImportMDCommon = NULL; - RegMeta *pRegMetaAssemEmit = static_cast(pAssemEmit); + ReleaseHolder pInternalAssemEmit; + ReleaseHolder pInternalEmit; + RegMeta *pRegMetaAssemEmit = NULL; RegMeta *pRegMetaEmit = NULL; CQuickBytes qkSigEmit; ULONG cbEmit; - pRegMetaEmit = static_cast(pEmit); + if (pAssemEmit != NULL) + { + IfFailGo(pAssemEmit->QueryInterface(IID_IMDInternalEmit, (void **)&pInternalAssemEmit)); + pRegMetaAssemEmit = static_cast((IMDInternalEmit *)pInternalAssemEmit); + } + + IfFailGo(pEmit->QueryInterface(IID_IMDInternalEmit, (void **)&pInternalEmit)); + pRegMetaEmit = static_cast((IMDInternalEmit *)pInternalEmit); { // This function can cause new TypeRef being introduced. @@ -100,50 +109,6 @@ STDMETHODIMP RegMeta::TranslateSigWithScope( // S_OK or error. #if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_INTERNAL_APIS) -//***************************************************************************** -// Helper : Set ResolutionScope of a TypeRef -// -// Implements internal API code:IMetaDataEmitHelper::SetResolutionScopeHelper. -//***************************************************************************** -HRESULT RegMeta::SetResolutionScopeHelper( // Return hresult. - mdTypeRef tr, // [IN] TypeRef record to update - mdToken rs) // [IN] new ResolutionScope -{ - HRESULT hr = NOERROR; - TypeRefRec * pTypeRef; - - LOCKWRITE(); - - IfFailGo(m_pStgdb->m_MiniMd.GetTypeRefRecord(RidFromToken(tr), &pTypeRef)); - IfFailGo(m_pStgdb->m_MiniMd.PutToken(TBL_TypeRef, TypeRefRec::COL_ResolutionScope, pTypeRef, rs)); - -ErrExit: - return hr; -} // RegMeta::SetResolutionScopeHelper - - -//***************************************************************************** -// Helper : Set offset of a ManifestResource -// -// Implements internal API code:IMetaDataEmitHelper::SetManifestResourceOffsetHelper. -//***************************************************************************** -HRESULT -RegMeta::SetManifestResourceOffsetHelper( - mdManifestResource mr, // [IN] The manifest token - ULONG ulOffset) // [IN] new offset -{ - HRESULT hr = NOERROR; - ManifestResourceRec * pRec; - - LOCKWRITE(); - - IfFailGo(m_pStgdb->m_MiniMd.GetManifestResourceRecord(RidFromToken(mr), &pRec)); - pRec->SetOffset(ulOffset); - -ErrExit: - return hr; -} // RegMeta::SetManifestResourceOffsetHelper - //******************************************************************************* // // Following APIs are used by reflection emit. @@ -153,7 +118,7 @@ RegMeta::SetManifestResourceOffsetHelper( //******************************************************************************* // helper to define method semantics // -// Implements internal API code:IMetaDataEmitHelper::DefineMethodSemanticsHelper. +// Implements internal API code:IMDInternalEmit::DefineMethodSemanticsHelper. //******************************************************************************* HRESULT RegMeta::DefineMethodSemanticsHelper( mdToken tkAssociation, // [IN] property or event token @@ -171,7 +136,7 @@ HRESULT RegMeta::DefineMethodSemanticsHelper( //******************************************************************************* // helper to set field layout // -// Implements internal API code:IMetaDataEmitHelper::SetFieldLayoutHelper. +// Implements internal API code:IMDInternalEmit::SetFieldLayoutHelper. //******************************************************************************* HRESULT RegMeta::SetFieldLayoutHelper( // Return hresult. mdFieldDef fd, // [IN] field to associate the layout info @@ -209,7 +174,7 @@ HRESULT RegMeta::SetFieldLayoutHelper( // Return hresult. //******************************************************************************* // helper to define event // -// Implements internal API code:IMetaDataEmitHelper::DefineEventHelper. +// Implements internal API code:IMDInternalEmit::DefineEventHelper. //******************************************************************************* STDMETHODIMP RegMeta::DefineEventHelper( // Return hresult. mdTypeDef td, // [IN] the class/interface on which the event is being defined @@ -231,92 +196,10 @@ STDMETHODIMP RegMeta::DefineEventHelper( // Return hresult. } // RegMeta::DefineEvent -//******************************************************************************* -// helper to add a declarative security blob to a class or method -// -// Implements internal API code:IMetaDataEmitHelper::AddDeclarativeSecurityHelper. -//******************************************************************************* -STDMETHODIMP RegMeta::AddDeclarativeSecurityHelper( - mdToken tk, // [IN] Parent token (typedef/methoddef) - DWORD dwAction, // [IN] Security action (CorDeclSecurity) - void const *pValue, // [IN] Permission set blob - DWORD cbValue, // [IN] Byte count of permission set blob - mdPermission*pmdPermission) // [OUT] Output permission token -{ - HRESULT hr = S_OK; - DeclSecurityRec *pDeclSec = NULL; - RID iDeclSec; - short sAction = static_cast(dwAction); - mdPermission tkPerm = mdTokenNil; - - LOCKWRITE(); - IfFailGo(m_pStgdb->m_MiniMd.PreUpdate()); - - _ASSERTE(TypeFromToken(tk) == mdtTypeDef || TypeFromToken(tk) == mdtMethodDef || TypeFromToken(tk) == mdtAssembly); - - // Check for valid Action. - if (sAction == 0 || sAction > dclMaximumValue) - IfFailGo(E_INVALIDARG); - - if (CheckDups(MDDupPermission)) - { - hr = ImportHelper::FindPermission(&(m_pStgdb->m_MiniMd), tk, sAction, &tkPerm); - - if (SUCCEEDED(hr)) - { - // Set output parameter. - if (pmdPermission) - *pmdPermission = tkPerm; - if (IsENCOn()) - IfFailGo(m_pStgdb->m_MiniMd.GetDeclSecurityRecord(RidFromToken(tkPerm), &pDeclSec)); - else - { - hr = META_S_DUPLICATE; - goto ErrExit; - } - } - else if (hr != CLDB_E_RECORD_NOTFOUND) - IfFailGo(hr); - } - - // Create a new record. - if (!pDeclSec) - { - IfFailGo(m_pStgdb->m_MiniMd.AddDeclSecurityRecord(&pDeclSec, &iDeclSec)); - tkPerm = TokenFromRid(iDeclSec, mdtPermission); - - // Set output parameter. - if (pmdPermission) - *pmdPermission = tkPerm; - - // Save parent and action information. - IfFailGo(m_pStgdb->m_MiniMd.PutToken(TBL_DeclSecurity, DeclSecurityRec::COL_Parent, pDeclSec, tk)); - pDeclSec->SetAction(sAction); - - // Turn on the internal security flag on the parent. - if (TypeFromToken(tk) == mdtTypeDef) - IfFailGo(_TurnInternalFlagsOn(tk, tdHasSecurity)); - else if (TypeFromToken(tk) == mdtMethodDef) - IfFailGo(_TurnInternalFlagsOn(tk, mdHasSecurity)); - IfFailGo(UpdateENCLog(tk)); - } - - // Write the blob into the record. - IfFailGo(m_pStgdb->m_MiniMd.PutBlob(TBL_DeclSecurity, DeclSecurityRec::COL_PermissionSet, - pDeclSec, pValue, cbValue)); - - IfFailGo(UpdateENCLog(tkPerm)); - -ErrExit: - - return hr; -} // RegMeta::AddDeclarativeSecurityHelper - - //******************************************************************************* // helper to set type's extends column // -// Implements internal API code:IMetaDataEmitHelper::SetTypeParent. +// Implements internal API code:IMDInternalEmit::SetTypeParent. //******************************************************************************* HRESULT RegMeta::SetTypeParent( // Return hresult. mdTypeDef td, // [IN] Type definition @@ -338,7 +221,7 @@ HRESULT RegMeta::SetTypeParent( // Return hresult. //******************************************************************************* // helper to set type's extends column // -// Implements internal API code:IMetaDataEmitHelper::AddInterfaceImpl. +// Implements internal API code:IMDInternalEmit::AddInterfaceImpl. //******************************************************************************* HRESULT RegMeta::AddInterfaceImpl( // Return hresult. mdTypeDef td, // [IN] Type definition diff --git a/src/coreclr/md/compiler/regmeta.cpp b/src/coreclr/md/compiler/regmeta.cpp index f4f55457db25b0..b7d5378d1137e1 100644 --- a/src/coreclr/md/compiler/regmeta.cpp +++ b/src/coreclr/md/compiler/regmeta.cpp @@ -473,12 +473,17 @@ RegMeta::QueryInterface( if (riid == IID_IUnknown) { +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES *ppUnk = (IUnknown *)(IMetaDataImport2 *)this; +#else + *ppUnk = static_cast(static_cast(this)); +#endif } else if (riid == IID_IMDCommon) { *ppUnk = (IMDCommon *)this; } +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES else if (riid == IID_IMetaDataImport) { *ppUnk = (IMetaDataImport2 *)this; @@ -491,6 +496,7 @@ RegMeta::QueryInterface( { *ppUnk = (IMetaDataAssemblyImport *)this; } +#endif else if (riid == IID_IMetaDataTables) { *ppUnk = static_cast(this); @@ -505,7 +511,7 @@ RegMeta::QueryInterface( *ppUnk = static_cast(this); } -#ifdef FEATURE_METADATA_EMIT +#if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) else if (riid == IID_IMetaDataEmit) { *ppUnk = (IMetaDataEmit2 *)this; @@ -532,7 +538,7 @@ RegMeta::QueryInterface( *ppUnk = (IMetaDataAssemblyEmit *)this; fIsInterfaceRW = true; } -#endif //FEATURE_METADATA_EMIT +#endif // FEATURE_METADATA_EMIT && FEATURE_METADATA_PUBLIC_INTERFACES #ifdef FEATURE_METADATA_EMIT_ALL @@ -550,6 +556,7 @@ RegMeta::QueryInterface( else if (riid == IID_IMDInternalEmit) { *ppUnk = static_cast(this); + fIsInterfaceRW = true; } else if (riid == IID_IGetIMDInternalImport) { @@ -557,14 +564,6 @@ RegMeta::QueryInterface( } #endif //FEATURE_METADATA_INTERNAL_APIS -#if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_INTERNAL_APIS) - else if (riid == IID_IMetaDataEmitHelper) - { - *ppUnk = (IMetaDataEmitHelper *)this; - fIsInterfaceRW = true; - } -#endif //FEATURE_METADATA_EMIT && FEATURE_METADATA_INTERNAL_APIS - #ifdef FEATURE_METADATA_IN_VM #ifdef FEATURE_COMINTEROP else if (riid == IID_IMarshal) @@ -579,7 +578,9 @@ RegMeta::QueryInterface( if (m_pFreeThreadedMarshaler == NULL) { // First time! Create the FreeThreadedMarshaler - IfFailGo(CoCreateFreeThreadedMarshaler((IUnknown *)(IMetaDataEmit2 *)this, &m_pFreeThreadedMarshaler)); + IfFailGo(CoCreateFreeThreadedMarshaler( + (IUnknown *)(IMetaDataEmit2 *)this, + &m_pFreeThreadedMarshaler)); } } @@ -1404,7 +1405,11 @@ HRESULT RegMeta::GetIMDInternalImport( MDInternalRW *pInternalRW = NULL; bool isLockedForWrite = false; IUnknown *pIUnkInternal = NULL; +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES IUnknown *pThis = (IMetaDataImport2*)this; +#else + IUnknown *pThis = static_cast(static_cast(this)); +#endif pIUnkInternal = this->GetCachedInternalInterface(TRUE); if (pIUnkInternal) diff --git a/src/coreclr/md/compiler/regmeta.h b/src/coreclr/md/compiler/regmeta.h index 71d5597885acae..e0fc3453eceb97 100644 --- a/src/coreclr/md/compiler/regmeta.h +++ b/src/coreclr/md/compiler/regmeta.h @@ -120,13 +120,15 @@ struct CaNamedArg; // class RegMeta : +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES public IMetaDataImport2, public IMetaDataAssemblyImport, +#endif public IMetaDataTables2 , public IMetaDataInfo -#ifdef FEATURE_METADATA_EMIT +#if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) #ifndef FEATURE_METADATA_EMIT_PORTABLE_PDB , public IMetaDataEmit2 #else @@ -146,10 +148,6 @@ class RegMeta : , public IGetIMDInternalImport #endif -#if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_INTERNAL_APIS) - , public IMetaDataEmitHelper -#endif - , public IMDCommon { friend class CImportTlb; @@ -162,8 +160,8 @@ class RegMeta : ULONG cbHashValue, PCCOR_SIGNATURE pbSigBlob, ULONG cbSigBlob, - IMetaDataAssemblyEmit* pAssemEmit, - IMetaDataEmit* emit, + IMDInternalEmit* pAssemEmit, + IMDInternalEmit* emit, CQuickBytes* pqkSigEmit, ULONG* pcbSig); public: @@ -1234,7 +1232,7 @@ class RegMeta : #ifdef FEATURE_METADATA_INTERNAL_APIS //***************************************************************************** -// IMetaDataEmitHelper +// IMDInternalEmit //***************************************************************************** STDMETHODIMP DefineMethodSemanticsHelper( mdToken tkAssociation, // [IN] property or event token @@ -1252,21 +1250,6 @@ class RegMeta : mdToken tkEventType, // [IN] a reference (mdTypeRef or mdTypeRef) to the Event class mdEvent *pmdEvent); // [OUT] output event token - STDMETHODIMP AddDeclarativeSecurityHelper( - mdToken tk, // [IN] Parent token (typedef/methoddef) - DWORD dwAction, // [IN] Security action (CorDeclSecurity) - void const *pValue, // [IN] Permission set blob - DWORD cbValue, // [IN] Byte count of permission set blob - mdPermission*pmdPermission); // [OUT] Output permission token - - STDMETHODIMP SetResolutionScopeHelper( // Return hresult. - mdTypeRef tr, // [IN] TypeRef record to update - mdToken rs); // [IN] new ResolutionScope - - STDMETHODIMP SetManifestResourceOffsetHelper( // Return hresult. - mdManifestResource mr, // [IN] The manifest token - ULONG ulOffset); // [IN] new offset - STDMETHODIMP SetTypeParent( // Return hresult. mdTypeDef td, // [IN] Type definition mdToken tkExtends); // [IN] parent type @@ -1275,10 +1258,6 @@ class RegMeta : mdTypeDef td, // [IN] Type definition mdToken tkInterface); // [IN] interface type -//***************************************************************************** -// IMDInternalEmit -//***************************************************************************** - STDMETHODIMP ChangeMvid( // S_OK or error. REFGUID newMvid); // GUID to use as the MVID diff --git a/src/coreclr/md/enc/CMakeLists.txt b/src/coreclr/md/enc/CMakeLists.txt index e8674fab6643b1..86a1a1b3fbe1df 100644 --- a/src/coreclr/md/enc/CMakeLists.txt +++ b/src/coreclr/md/enc/CMakeLists.txt @@ -50,16 +50,21 @@ convert_to_absolute_path(MDRUNTIMERW_SOURCES ${MDRUNTIMERW_SOURCES}) add_library_clr(mdruntimerw_dac ${MDRUNTIMERW_SOURCES}) set_target_properties(mdruntimerw_dac PROPERTIES DAC_COMPONENT TRUE) +target_compile_definitions(mdruntimerw_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdruntimerw_dac PRIVATE stdafx.h) add_library_clr(mdruntimerw_wks OBJECT ${MDRUNTIMERW_SOURCES}) target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +if (FEATURE_CORPROFILER) + target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) +endif() target_precompile_headers(mdruntimerw_wks PRIVATE stdafx.h) add_library_clr(mdruntimerw-dbi ${MDRUNTIMERW_SOURCES}) set_target_properties(mdruntimerw-dbi PROPERTIES DBI_COMPONENT TRUE) +target_compile_definitions(mdruntimerw-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdruntimerw-dbi PRIVATE stdafx.h) add_library_clr(mdruntimerw_ppdb ${MDRUNTIMERW_SOURCES}) -target_compile_definitions(mdruntimerw_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB SELF_NO_HOST) +target_compile_definitions(mdruntimerw_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdruntimerw_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/enc/mdinternalrw.cpp b/src/coreclr/md/enc/mdinternalrw.cpp index 450c7f18c9dde3..9bc8e672d75de1 100644 --- a/src/coreclr/md/enc/mdinternalrw.cpp +++ b/src/coreclr/md/enc/mdinternalrw.cpp @@ -45,16 +45,16 @@ HRESULT TranslateSigHelper( // S_OK or error. ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit* pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit* emit, // [IN] emit interface + IMDInternalEmit* pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit* emit, // [IN] emit interface CQuickBytes* pqkSigEmit, // [OUT] buffer to hold translated signature ULONG* pcbSig) // [OUT] count of bytes in the translated signature { #ifdef FEATURE_METADATA_EMIT HRESULT hr = S_OK; IMetaModelCommon *pCommon = pImport->GetMetaModelCommon(); - RegMeta *pAssemEmitRM = static_cast(pAssemEmit); - RegMeta *pEmitRM = static_cast(emit); + RegMeta *pAssemEmitRM = static_cast(pAssemEmit); + RegMeta *pEmitRM = static_cast(emit); CMiniMdRW *pMiniMdAssemEmit = pAssemEmitRM ? &pAssemEmitRM->m_pStgdb->m_MiniMd : NULL; CMiniMdRW *pMiniMdEmit = &(pEmitRM->m_pStgdb->m_MiniMd); @@ -628,8 +628,8 @@ HRESULT MDInternalRW::TranslateSigWithScope( ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit* pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit* emit, // [IN] emit interface + IMDInternalEmit* pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit* emit, // [IN] emit interface CQuickBytes* pqkSigEmit, // [OUT] buffer to hold translated signature ULONG* pcbSig) // [OUT] count of bytes in the translated signature { @@ -905,40 +905,6 @@ MDInternalRW::EnumMethodImplNext( // return hresult return EnumNext(phEnumDecl, ptkDecl) ? S_OK : S_FALSE; } // MDInternalRW::EnumMethodImplNext -//***************************************** -// Reset the enumerator to the beginning. -//***************************************** -void MDInternalRW::EnumMethodImplReset( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. -{ - _ASSERTE((phEnumBody->m_tkKind >> 24) == TBL_MethodImpl && - (phEnumDecl->m_tkKind >> 24) == TBL_MethodImpl); - _ASSERTE(phEnumBody->m_EnumType == MDDynamicArrayEnum && - phEnumDecl->m_EnumType == MDDynamicArrayEnum); - _ASSERTE(phEnumBody->m_ulCount == phEnumDecl->m_ulCount); - - EnumReset(phEnumBody); - EnumReset(phEnumDecl); -} // MDInternalRW::EnumMethodImplReset - - -//***************************************** -// Close the enumerator. -//***************************************** -void MDInternalRW::EnumMethodImplClose( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. -{ - _ASSERTE((phEnumBody->m_tkKind >> 24) == TBL_MethodImpl && - (phEnumDecl->m_tkKind >> 24) == TBL_MethodImpl); - _ASSERTE(phEnumBody->m_EnumType == MDDynamicArrayEnum && - phEnumDecl->m_EnumType == MDDynamicArrayEnum); - _ASSERTE(phEnumBody->m_ulCount == phEnumDecl->m_ulCount); - - EnumClose(phEnumBody); - EnumClose(phEnumDecl); -} // MDInternalRW::EnumMethodImplClose #endif //!DACCESS_COMPILE //****************************************************************************** @@ -1356,11 +1322,6 @@ HRESULT MDInternalRW::EnumInit( // return S_FALSE if record not found phEnum->u.m_ulStart = 1; phEnum->u.m_ulEnd = m_pStgdb->m_MiniMd.getCountManifestResources() + 1; break; - case mdtModuleRef: - _ASSERTE(IsNilToken(tkParent)); - phEnum->u.m_ulStart = 1; - phEnum->u.m_ulEnd = m_pStgdb->m_MiniMd.getCountModuleRefs() + 1; - break; default: _ASSERTE(!"ENUM INIT not implemented for the uncompressed format!"); IfFailGo(E_NOTIMPL); @@ -1404,14 +1365,6 @@ HRESULT MDInternalRW::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountTypeRefs(); break; - case mdtMemberRef: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountMemberRefs(); - break; - - case mdtSignature: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountStandAloneSigs(); - break; - case mdtMethodDef: phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountMethods(); break; @@ -1420,10 +1373,6 @@ HRESULT MDInternalRW::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountMethodSpecs(); break; - case mdtFieldDef: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountFields(); - break; - case mdtTypeSpec: phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountTypeSpecs(); break; @@ -1432,22 +1381,6 @@ HRESULT MDInternalRW::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountAssemblyRefs(); break; - case mdtModuleRef: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountModuleRefs(); - break; - - case mdtTypeDef: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountTypeDefs(); - break; - - case mdtFile: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountFiles(); - break; - - case mdtCustomAttribute: - phEnum->m_ulCount = m_pStgdb->m_MiniMd.getCountCustomAttributes(); - break; - default: _ASSERTE(!"Bad token kind!"); break; diff --git a/src/coreclr/md/inc/liteweightstgdb.h b/src/coreclr/md/inc/liteweightstgdb.h index 2209c769e067d3..a8ddcd78ebefe6 100644 --- a/src/coreclr/md/inc/liteweightstgdb.h +++ b/src/coreclr/md/inc/liteweightstgdb.h @@ -90,8 +90,8 @@ class CLiteWeightStgdbRW : public CLiteWeightStgdb ULONG cbHashValue, PCCOR_SIGNATURE pbSigBlob, ULONG cbSigBlob, - IMetaDataAssemblyEmit* pAssemEmit, - IMetaDataEmit* emit, + IMDInternalEmit* pAssemEmit, + IMDInternalEmit* emit, CQuickBytes* pqkSigEmit, ULONG* pcbSig); public: diff --git a/src/coreclr/md/inc/mdinternalrw.h b/src/coreclr/md/inc/mdinternalrw.h index e50b04bc1e4310..c068c4f06cb7a6 100644 --- a/src/coreclr/md/inc/mdinternalrw.h +++ b/src/coreclr/md/inc/mdinternalrw.h @@ -42,8 +42,8 @@ class MDInternalRW : public IMDInternalImportENC, public IMDCommon ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit *pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit *emit, // [IN] emit interface + IMDInternalEmit *pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit *emit, // [IN] emit interface CQuickBytes *pqkSigEmit, // [OUT] buffer to hold translated signature ULONG *pcbSig) // [OUT] count of bytes in the translated signature DAC_UNEXPECTED(); @@ -101,11 +101,6 @@ class MDInternalRW : public IMDInternalImportENC, public IMDCommon HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. DAC_UNEXPECTED(); - STDMETHODIMP_(void) EnumMethodImplReset( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. - DAC_UNEXPECTED(); - __checkReturn STDMETHODIMP EnumMethodImplNext( // return hresult (S_OK = TRUE, S_FALSE = FALSE or error code) HENUMInternal *phEnumBody, // [IN] input enum for MethodBody @@ -114,11 +109,6 @@ class MDInternalRW : public IMDInternalImportENC, public IMDCommon mdToken *ptkDecl) // [OUT] return token for MethodDecl DAC_UNEXPECTED(); - STDMETHODIMP_(void) EnumMethodImplClose( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. - DAC_UNEXPECTED(); - //***************************************** // Enumerator helpers for memberdef, memberref, interfaceimp, // event, property, param, methodimpl diff --git a/src/coreclr/md/runtime/CMakeLists.txt b/src/coreclr/md/runtime/CMakeLists.txt index c0ebe3a65ffdc1..84fe039e97d485 100644 --- a/src/coreclr/md/runtime/CMakeLists.txt +++ b/src/coreclr/md/runtime/CMakeLists.txt @@ -51,16 +51,21 @@ endif (CLR_CMAKE_TARGET_WIN32) add_library_clr(mdruntime_dac ${MDRUNTIME_SOURCES}) set_target_properties(mdruntime_dac PROPERTIES DAC_COMPONENT TRUE) +target_compile_definitions(mdruntime_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdruntime_dac PRIVATE stdafx.h) add_library_clr(mdruntime_wks OBJECT ${MDRUNTIME_SOURCES}) target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +if (FEATURE_CORPROFILER) + target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) +endif() target_precompile_headers(mdruntime_wks PRIVATE stdafx.h) add_library_clr(mdruntime-dbi ${MDRUNTIME_SOURCES}) set_target_properties(mdruntime-dbi PROPERTIES DBI_COMPONENT TRUE) +target_compile_definitions(mdruntime-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) target_precompile_headers(mdruntime-dbi PRIVATE stdafx.h) add_library_clr(mdruntime_ppdb ${MDRUNTIME_SOURCES}) -target_compile_definitions(mdruntime_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB SELF_NO_HOST) +target_compile_definitions(mdruntime_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdruntime_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/runtime/mdinternalro.cpp b/src/coreclr/md/runtime/mdinternalro.cpp index 3d9a388b321aa0..57e85ff5316431 100644 --- a/src/coreclr/md/runtime/mdinternalro.cpp +++ b/src/coreclr/md/runtime/mdinternalro.cpp @@ -34,8 +34,8 @@ HRESULT TranslateSigHelper( // S_OK or error. ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit *pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit *emit, // [IN] emit interface + IMDInternalEmit *pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit *emit, // [IN] emit interface CQuickBytes *pqkSigEmit, // [OUT] buffer to hold translated signature ULONG *pcbSig); // [OUT] count of bytes in the translated signature #endif //!DACCESS_COMPILE @@ -137,8 +137,8 @@ HRESULT MDInternalRO::TranslateSigWithScope( ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit* pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit* emit, // [IN] emit interface + IMDInternalEmit* pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit* emit, // [IN] emit interface CQuickBytes* pqkSigEmit, // [OUT] buffer to hold translated signature ULONG* pcbSig) // [OUT] count of bytes in the translated signature { @@ -226,7 +226,29 @@ HRESULT MDInternalRO::EnumMethodImplInit( // return hresult HENUMInternal *phEnumBody, // [OUT] buffer to fill for enumerator data for MethodBody tokens. HENUMInternal *phEnumDecl) // [OUT] buffer to fill for enumerator data for MethodDecl tokens. { - return EnumInit(TBL_MethodImpl << 24, td, phEnumBody); + _ASSERTE(TypeFromToken(td) == mdtTypeDef && !IsNilToken(td)); + _ASSERTE(phEnumBody && phEnumDecl); + + HENUMInternal::ZeroEnum(phEnumBody); + HENUMInternal::ZeroEnum(phEnumDecl); + + phEnumBody->m_tkKind = (TBL_MethodImpl << 24); + phEnumBody->m_EnumType = MDSimpleEnum; + + HRESULT hr = m_LiteWeightStgdb.m_MiniMd.getMethodImplsForClass( + RidFromToken(td), + &phEnumBody->u.m_ulEnd, + &phEnumBody->u.m_ulStart); + if (FAILED(hr)) + return hr; + + if (phEnumBody->u.m_ulEnd < phEnumBody->u.m_ulStart) + return CLDB_E_FILE_CORRUPT; + + phEnumBody->m_ulCount = phEnumBody->u.m_ulEnd - phEnumBody->u.m_ulStart; + phEnumBody->u.m_ulCur = phEnumBody->u.m_ulStart; + + return S_OK; } // MDInternalRO::EnumMethodImplInit //***************************************************************************** @@ -271,32 +293,6 @@ MDInternalRO::EnumMethodImplNext( // return hresult return S_OK; } // MDInternalRO::EnumMethodImplNext -//***************************************** -// Reset the enumerator to the beginning. -//***************************************** -void MDInternalRO::EnumMethodImplReset( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. -{ - _ASSERTE(phEnumBody && ((phEnumBody->m_tkKind >> 24) == TBL_MethodImpl)); - _ASSERTE(phEnumBody->m_EnumType == MDSimpleEnum); - - phEnumBody->u.m_ulCur = phEnumBody->u.m_ulStart; -} // MDInternalRO::EnumMethodImplReset - - -//***************************************** -// Close the enumerator. -//***************************************** -void MDInternalRO::EnumMethodImplClose( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl) // [IN] MethodDecl enumerator. -{ - _ASSERTE(phEnumBody && ((phEnumBody->m_tkKind >> 24) == TBL_MethodImpl)); - _ASSERTE(phEnumBody->m_EnumType == MDSimpleEnum); -} // MDInternalRO::EnumMethodImplClose - - //****************************************************************************** // enumerator for global functions //****************************************************************************** @@ -458,18 +454,6 @@ HRESULT MDInternalRO::EnumInit( // return S_FALSE if record not found phEnum->u.m_ulStart = 1; phEnum->u.m_ulEnd = m_LiteWeightStgdb.m_MiniMd.getCountManifestResources() + 1; break; - case mdtModuleRef: - _ASSERTE(IsNilToken(tkParent)); - phEnum->u.m_ulStart = 1; - phEnum->u.m_ulEnd = m_LiteWeightStgdb.m_MiniMd.getCountModuleRefs() + 1; - break; - case (TBL_MethodImpl << 24): - _ASSERTE(! IsNilToken(tkParent)); - IfFailGo(m_LiteWeightStgdb.m_MiniMd.getMethodImplsForClass( - RidFromToken(tkParent), - &phEnum->u.m_ulEnd, - &phEnum->u.m_ulStart)); - break; default: _ASSERTE(!"ENUM INIT not implemented for the compressed format!"); IfFailGo(E_NOTIMPL); @@ -513,14 +497,6 @@ HRESULT MDInternalRO::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountTypeRefs(); break; - case mdtMemberRef: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountMemberRefs(); - break; - - case mdtSignature: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountStandAloneSigs(); - break; - case mdtMethodDef: phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountMethods(); break; @@ -529,10 +505,6 @@ HRESULT MDInternalRO::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountMethodSpecs(); break; - case mdtFieldDef: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountFields(); - break; - case mdtTypeSpec: phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountTypeSpecs(); break; @@ -541,22 +513,6 @@ HRESULT MDInternalRO::EnumAllInit( // return S_FALSE if record not found phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountAssemblyRefs(); break; - case mdtModuleRef: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountModuleRefs(); - break; - - case mdtTypeDef: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountTypeDefs(); - break; - - case mdtFile: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountFiles(); - break; - - case mdtCustomAttribute: - phEnum->m_ulCount = m_LiteWeightStgdb.m_MiniMd.getCountCustomAttributes(); - break; - default: _ASSERTE(!"Bad token kind!"); break; diff --git a/src/coreclr/md/runtime/mdinternalro.h b/src/coreclr/md/runtime/mdinternalro.h index 1df15736f147be..e469ce8c5ac3fe 100644 --- a/src/coreclr/md/runtime/mdinternalro.h +++ b/src/coreclr/md/runtime/mdinternalro.h @@ -37,8 +37,8 @@ class MDInternalRO : public IMDInternalImport, IMDCommon ULONG cbHashValue, // [IN] count of bytes in the hash value. PCCOR_SIGNATURE pbSigBlob, // [IN] signature in the importing scope ULONG cbSigBlob, // [IN] count of bytes of signature - IMetaDataAssemblyEmit *pAssemEmit, // [IN] assembly emit scope. - IMetaDataEmit *emit, // [IN] emit interface + IMDInternalEmit *pAssemEmit, // [IN] assembly emit scope. + IMDInternalEmit *emit, // [IN] emit interface CQuickBytes *pqkSigEmit, // [OUT] buffer to hold translated signature ULONG *pcbSig) // [OUT] count of bytes in the translated signature DAC_UNEXPECTED(); @@ -95,10 +95,6 @@ class MDInternalRO : public IMDInternalImport, IMDCommon HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. HENUMInternal *phEnumDecl); // [IN] MethodDecl enumerator. - STDMETHODIMP_(void) EnumMethodImplReset( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl); // [IN] MethodDecl enumerator. - __checkReturn STDMETHODIMP EnumMethodImplNext( // return hresult HENUMInternal *phEnumBody, // [IN] input enum for MethodBody @@ -106,10 +102,6 @@ class MDInternalRO : public IMDInternalImport, IMDCommon mdToken *ptkBody, // [OUT] return token for MethodBody mdToken *ptkDecl); // [OUT] return token for MethodDecl - STDMETHODIMP_(void) EnumMethodImplClose( - HENUMInternal *phEnumBody, // [IN] MethodBody enumerator. - HENUMInternal *phEnumDecl); // [IN] MethodDecl enumerator. - //***************************************** // Enumerator helpers for memberdef, memberref, interfaceimp, // event, property, param, methodimpl diff --git a/src/coreclr/md/runtime/noopmetadataimport.cpp b/src/coreclr/md/runtime/noopmetadataimport.cpp index fa25d62fbce1b5..0510d7c92ae3d6 100644 --- a/src/coreclr/md/runtime/noopmetadataimport.cpp +++ b/src/coreclr/md/runtime/noopmetadataimport.cpp @@ -5,7 +5,7 @@ #include "stdafx.h" -#ifdef FEATURE_METADATA_IN_VM +#ifdef FEATURE_ISYM_READER // This importer is only used to satisfy the symbol binder's non-null parameter. // It is intentionally inert so we do not materialize the module's real public importer. @@ -155,4 +155,4 @@ IMetaDataImport2* GetNoopMetaDataImport2() return &g_NoopMetadataImport; } -#endif // FEATURE_METADATA_IN_VM +#endif // FEATURE_ISYM_READER diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 9cbf69135c6948..4e05e2cbcf4d34 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -394,17 +394,17 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar COMPlusThrow(kArgumentException, W("ArgumentNull_AssemblyNameName")); // Set up the assembly manifest metadata - // When we create dynamic assembly, we always use a working copy of IMetaDataAssemblyEmit + // When we create dynamic assembly, we always use a working copy of IMDInternalEmit // to store temporary runtime assembly information. This is to preserve the invariant that // an assembly must have a PEAssembly with proper metadata. - // This working copy of IMetaDataAssemblyEmit will store every AssemblyRef as a simple name + // This working copy of IMDInternalEmit will store every AssemblyRef as a simple name // reference as we must have an instance of Assembly(can be dynamic assembly) before we can // add such a reference. Also because the referenced assembly if dynamic strong name, it may // not be ready to be hashed! - ReleaseHolderAnyMode pAssemblyEmit; + ReleaseHolderAnyMode pAssemblyEmit; DefineEmitScope( - IID_IMetaDataAssemblyEmit, + IID_IMDInternalEmit, (void**)&pAssemblyEmit); // Now create a dynamic PE file out of the name & metadata @@ -1642,7 +1642,7 @@ bool Assembly::TrySetTypeLib(_In_ ITypeLib *pNew) // Add an assembly to the assemblyref list. pAssemEmitter specifies where // the AssemblyRef is emitted to. //*********************************************************** -mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter) +mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMDInternalEmit *pAssemEmitter) { CONTRACTL { diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index 0e209b3d8a2cfd..1a9cb9827a547b 100644 --- a/src/coreclr/vm/assembly.hpp +++ b/src/coreclr/vm/assembly.hpp @@ -372,7 +372,7 @@ class Assembly void AddType(Module* pModule, mdTypeDef cl); void AddExportedType(mdExportedType cl); - mdAssemblyRef AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter); + mdAssemblyRef AddAssemblyRef(Assembly *refedAssembly, IMDInternalEmit *pAssemEmitter); //**************************************************************************************** diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 05de4d9b8afc13..38d82e2a5c1149 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -400,7 +400,7 @@ HRESULT AssemblySpec::CheckFriendAssemblyName() } HRESULT AssemblySpec::EmitToken( - IMetaDataAssemblyEmit *pEmit, + IMDInternalEmit *pEmit, mdAssemblyRef *pToken) { CONTRACTL diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index b62e696d5ce9fb..245a34f8f4754d 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -153,7 +153,7 @@ class AssemblySpec : public BaseAssemblySpec HRESULT CheckFriendAssemblyName(); - HRESULT EmitToken(IMetaDataAssemblyEmit *pEmit, + HRESULT EmitToken(IMDInternalEmit *pEmit, mdAssemblyRef *pToken); HRESULT Bind( diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index 77180a3db980e8..698c8c6e14e95d 100644 --- a/src/coreclr/vm/baseassemblyspec.h +++ b/src/coreclr/vm/baseassemblyspec.h @@ -49,7 +49,6 @@ class BaseAssemblySpec DWORD dwFlags); HRESULT Init(mdToken tkAssemblyRef, IMDInternalImport *pImport); - HRESULT Init(mdAssembly tkAssemblyRef, IMetaDataAssemblyImport* pImport); void Init(SString& assemblyDisplayName); HRESULT InitNoThrow(SString& assemblyDisplayName); diff --git a/src/coreclr/vm/baseassemblyspec.inl b/src/coreclr/vm/baseassemblyspec.inl index f189d1d0fa2574..20e919d7a0d2c2 100644 --- a/src/coreclr/vm/baseassemblyspec.inl +++ b/src/coreclr/vm/baseassemblyspec.inl @@ -329,90 +329,6 @@ inline HRESULT BaseAssemblySpec::Init(mdToken kAssemblyToken, return S_OK; } -inline HRESULT BaseAssemblySpec::Init(mdToken tkAssemblyRef, - IMetaDataAssemblyImport *pImport) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - - // Retrieve size of assembly name - ASSEMBLYMETADATA sContext; - LPWSTR wszAssemblyName=NULL; - ZeroMemory(&sContext, sizeof(ASSEMBLYMETADATA)); - HRESULT hr = S_OK; - if(TypeFromToken(tkAssemblyRef) == mdtAssembly) - { - DWORD cchName; - IfFailRet(pImport->GetAssemblyProps(tkAssemblyRef, // [IN] The Assembly for which to get the properties. - NULL, // [OUT] Pointer to the public key or token. - NULL, // [OUT] Count of bytes in the public key or token. - NULL, // [OUT] Hash Algorithm - NULL, // [OUT] Buffer to fill with name. - 0, // [IN] Size of buffer in wide chars. - &cchName, // [OUT] Actual # of wide chars in name. - &sContext, // [OUT] Assembly MetaData. - NULL)); // [OUT] Flags. - - // Get the assembly name other naming properties - wszAssemblyName = (LPWSTR)_alloca(cchName * sizeof(WCHAR)); - IfFailRet(pImport->GetAssemblyProps(tkAssemblyRef, - (const void **)&m_pbPublicKeyOrToken, - &m_cbPublicKeyOrToken, - NULL, - wszAssemblyName, - cchName, - &cchName, - &sContext, - &m_dwFlags)); - } - else if(TypeFromToken(tkAssemblyRef) == mdtAssemblyRef) - { - DWORD cchName; - IfFailRet(pImport->GetAssemblyRefProps(tkAssemblyRef, // [IN] The AssemblyRef for which to get the properties. - NULL, // [OUT] Pointer to the public key or token. - NULL, // [OUT] Count of bytes in the public key or token. - NULL, // [OUT] Buffer to fill with name. - 0, // [IN] Size of buffer in wide chars. - &cchName, // [OUT] Actual # of wide chars in name. - &sContext, // [OUT] Assembly MetaData. - NULL, // [OUT] Hash blob. - NULL, // [OUT] Count of bytes in the hash blob. - NULL)); // [OUT] Flags. - - // Get the assembly name other naming properties - wszAssemblyName = (LPWSTR)_alloca(cchName * sizeof(WCHAR)); - IfFailRet(pImport->GetAssemblyRefProps(tkAssemblyRef, - (const void **)&m_pbPublicKeyOrToken, - &m_cbPublicKeyOrToken, - wszAssemblyName, - cchName, - &cchName, - &sContext, - NULL, - NULL, - &m_dwFlags)); - } - else - { - _ASSERTE(false && "unexpected token"); - } - MAKE_UTF8PTR_FROMWIDE_NOTHROW(szAssemblyName,wszAssemblyName); - IfNullRet(szAssemblyName); - size_t len=strlen(szAssemblyName)+1; - NewArrayHolder assemblyName(new(nothrow) char[len]); - IfNullRet(assemblyName); - strcpy_s(assemblyName,len,szAssemblyName); - - m_pAssemblyName=assemblyName.Extract(); - SetContext(&sContext); - return S_OK; -} - inline void BaseAssemblySpec::SetName(LPCSTR szName) { CONTRACTL diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index bae6a7593dfeac..41d79afe6149a1 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -1622,6 +1622,7 @@ BOOL Module::IsInSameVersionBubble(Module *target) #endif // FEATURE_READYTORUN //--------------------------------------------------------------------------------------- +#ifdef PROFILING_SUPPORTED // // Wrapper for Module::GetRWImporter + QI when writing is not needed. // @@ -1671,6 +1672,7 @@ HRESULT Module::GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID rii return hr; } +#endif // PROFILING_SUPPORTED // a special token that indicates no reader could be created - don't try again static ISymUnmanagedReader* const k_pInvalidSymReader = (ISymUnmanagedReader*)0x1; @@ -3871,7 +3873,11 @@ void ReflectionModule::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) m_pInMemoryWriter = new RefClassWriter(); - IfFailThrow(m_pInMemoryWriter->Init(GetCeeGen(), GetEmitter(), szName)); + IfFailThrow(m_pInMemoryWriter->Init( + GetCeeGen(), + GetPEAssembly()->GetMDInternalEmit(), + GetMDImport(), + szName)); m_CrstLeafLock.Init(CrstLeafLock); } @@ -3916,15 +3922,15 @@ class MDUpdateModeHolder WRAPPER_NO_CONTRACT; (void)Release(); } - HRESULT SetMDUpdateMode(IMetaDataEmit *pEmitter, ULONG updateMode) + HRESULT SetMDUpdateMode(IMDInternalEmit *pEmitter, ULONG updateMode) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; _ASSERTE(updateMode != UINT32_MAX); - IfFailRet(pEmitter->QueryInterface(IID_IMDInternalEmit, (void **)&m_pInternalEmitter)); - _ASSERTE(m_pInternalEmitter != NULL); + m_pInternalEmitter = pEmitter; + m_pInternalEmitter->AddRef(); IfFailRet(m_pInternalEmitter->SetMDUpdateMode(updateMode, &m_OriginalMDUpdateMode)); _ASSERTE(m_OriginalMDUpdateMode != UINT32_MAX); @@ -3996,7 +4002,7 @@ void ReflectionModule::CaptureModuleMetaDataToMemory() CONTRACTL_END; // Do not release the emitter. This is a weak reference. - IMetaDataEmit *pEmitter = this->GetEmitter(); + IMDInternalEmit *pEmitter = m_pInMemoryWriter->GetEmitter(); _ASSERTE(pEmitter != NULL); HRESULT hr; diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 91ccbe5ad5dac5..02098a710f0efa 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -1030,7 +1030,7 @@ class Module : public ModuleBase return m_pPEAssembly->GetMDImport(); } -#ifndef DACCESS_COMPILE +#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) IMetaDataEmit *GetEmitter() { WRAPPER_NO_CONTRACT; @@ -1046,7 +1046,7 @@ class Module : public ModuleBase } HRESULT GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID riid, LPVOID * ppvInterface); -#endif // !DACCESS_COMPILE +#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE #if defined(FEATURE_READYTORUN) BOOL IsInSameVersionBubble(Module *target); diff --git a/src/coreclr/vm/comdynamic.cpp b/src/coreclr/vm/comdynamic.cpp index a951046046d49c..9f2f29a97d8d05 100644 --- a/src/coreclr/vm/comdynamic.cpp +++ b/src/coreclr/vm/comdynamic.cpp @@ -148,7 +148,7 @@ extern "C" void QCALLTYPE TypeBuilder_SetParentType(QCall::ModuleHandle pModule, RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); - IfFailThrow( pRCW->GetEmitHelper()->SetTypeParent(tdType, tkParent) ); + IfFailThrow( pRCW->GetEmitter()->SetTypeParent(tdType, tkParent) ); END_QCALL; } @@ -163,7 +163,7 @@ extern "C" void QCALLTYPE TypeBuilder_AddInterfaceImpl(QCall::ModuleHandle pModu RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); - IfFailThrow( pRCW->GetEmitHelper()->AddInterfaceImpl(tdType, tkInterface) ); + IfFailThrow( pRCW->GetEmitter()->AddInterfaceImpl(tdType, tkInterface) ); END_QCALL; } @@ -588,7 +588,7 @@ extern "C" INT32 QCALLTYPE TypeBuilder_DefineEvent(QCall::ModuleHandle pModule, _ASSERTE(pRCW); // Define the Event - IfFailThrow(pRCW->GetEmitHelper()->DefineEventHelper( + IfFailThrow(pRCW->GetEmitter()->DefineEventHelper( tkParent, // ParentTypeDef wszName, // Name of Member attr, // property Attributes (prDefaultProperty, etc); @@ -616,7 +616,7 @@ extern "C" void QCALLTYPE TypeBuilder_DefineMethodSemantics(QCall::ModuleHandle _ASSERTE(pRCW); // Define the MethodSemantics - IfFailThrow(pRCW->GetEmitHelper()->DefineMethodSemanticsHelper( + IfFailThrow(pRCW->GetEmitter()->DefineMethodSemanticsHelper( tkAssociation, attr, tkMethod)); @@ -801,7 +801,7 @@ extern "C" void QCALLTYPE TypeBuilder_SetFieldLayoutOffset(QCall::ModuleHandle p _ASSERTE(pRCW); // Set the field layout - IfFailThrow(pRCW->GetEmitHelper()->SetFieldLayoutHelper( + IfFailThrow(pRCW->GetEmitter()->SetFieldLayoutHelper( tkField, // field iOffset)); // layout offset diff --git a/src/coreclr/vm/commodule.cpp b/src/coreclr/vm/commodule.cpp index 61b48f17a6de50..933ef25265f950 100644 --- a/src/coreclr/vm/commodule.cpp +++ b/src/coreclr/vm/commodule.cpp @@ -36,8 +36,8 @@ extern "C" mdTypeRef QCALLTYPE ModuleBuilder_GetTypeRef(QCall::ModuleHandle pMod RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); _ASSERTE(pRCW); - IMetaDataEmit * pEmit = pRCW->GetEmitter(); - IMetaDataImport * pImport = pRCW->GetRWImporter(); + IMDInternalEmit * pEmit = pRCW->GetEmitter(); + IMDInternalImport * pImport = pRCW->GetMDImport(); if (wszFullName == NULL) { COMPlusThrow(kArgumentNullException, W("ArgumentNull_String")); @@ -69,8 +69,14 @@ extern "C" mdTypeRef QCALLTYPE ModuleBuilder_GetTypeRef(QCall::ModuleHandle pMod if (pModule == pRefedModule) { // referenced type is from the same module so we must be able to find a TypeDef. - IfFailThrow(pImport->FindTypeDefByName( - wszFullNameUnescaped, + MAKE_UTF8PTR_FROMWIDE(szFullNameUnescaped, wszFullNameUnescaped); + LPCSTR szNamespace; + LPCSTR szName; + ns::SplitInline(szFullNameUnescaped, szNamespace, szName); + + IfFailThrow(pImport->FindTypeDef( + szNamespace, + szName, RidFromToken(tkResolutionArg) ? tkResolutionArg : mdTypeDefNil, &tr)); } @@ -86,11 +92,8 @@ extern "C" mdTypeRef QCALLTYPE ModuleBuilder_GetTypeRef(QCall::ModuleHandle pMod { // reference to top level type - ReleaseHolder pAssemblyEmit; - // Generate AssemblyRef - IfFailThrow( pEmit->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pAssemblyEmit) ); - tkResolution = pThisAssembly->AddAssemblyRef(pRefedAssembly, pAssemblyEmit); + tkResolution = pThisAssembly->AddAssemblyRef(pRefedAssembly, pEmit); // Add the assembly ref token and the manifest module it is referring to this module's rid map. // This is needed regardless of whether the dynamic assembly has run access. Even in Save-only @@ -166,36 +169,44 @@ namespace // //****************************************************************************** void DefineTypeRefHelper( - IMetaDataEmit *pEmit, // given emit scope + IMDInternalImport *pImport, // given import scope + IMDInternalEmit *pEmit, // given emit scope mdTypeDef td, // given typedef in the emit scope mdTypeRef *ptr) // return typeref { CONTRACTL { STANDARD_VM_CHECK; + PRECONDITION(CheckPointer(pImport)); PRECONDITION(CheckPointer(pEmit)); PRECONDITION(CheckPointer(ptr)); } CONTRACTL_END; - CQuickBytes qb; - WCHAR* szTypeDef = (WCHAR*) qb.AllocThrows((MAX_CLASSNAME_LENGTH+1) * sizeof(WCHAR)); - mdToken rs; // resolution scope - DWORD dwFlags; + LPCSTR szName; + LPCSTR szNamespace; + IfFailThrow(pImport->GetNameOfTypeDef(td, &szName, &szNamespace)); + + DWORD dwFlags; + mdToken extends; + IfFailThrow(pImport->GetTypeDefProps(td, &dwFlags, &extends)); - ReleaseHolderAnyMode pImport; - IfFailThrow( pEmit->QueryInterface(IID_IMetaDataImport, (void **)&pImport) ); - IfFailThrow( pImport->GetTypeDefProps(td, szTypeDef, MAX_CLASSNAME_LENGTH, NULL, &dwFlags, NULL) ); + mdToken rs; if ( IsTdNested(dwFlags) ) { mdToken tdNested; IfFailThrow( pImport->GetNestedClassProps(td, &tdNested) ); - DefineTypeRefHelper( pEmit, tdNested, &rs); + DefineTypeRefHelper(pImport, pEmit, tdNested, &rs); } else rs = TokenFromRid( 1, mdtModule ); - IfFailThrow( pEmit->DefineTypeRefByName( rs, szTypeDef, ptr) ); + SString typeNamespace(SString::Utf8, szNamespace); + SString typeName(SString::Utf8, szName); + StackSString fullName; + fullName.MakeFullNamespacePath(typeNamespace, typeName); + + IfFailThrow(pEmit->DefineTypeRefByName(rs, fullName.GetUnicode(), ptr)); } // DefineTypeRefHelper } @@ -246,9 +257,6 @@ extern "C" INT32 QCALLTYPE ModuleBuilder_GetMemberRef(QCall::ModuleHandle pModul COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleBoundNonCollectible")); } - ReleaseHolder pAssemblyEmit; - IfFailThrow( pRefingAssembly->GetModule()->GetEmitter()->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pAssemblyEmit) ); - CQuickBytes qbNewSig; ULONG cbNewSig; @@ -257,7 +265,7 @@ extern "C" INT32 QCALLTYPE ModuleBuilder_GetMemberRef(QCall::ModuleHandle pModul NULL, 0, // hash value pvComSig, cbComSig, - pAssemblyEmit, // Emit assembly scope. + pRCW->GetEmitter(), pRCW->GetEmitter(), &qbNewSig, &cbNewSig) ); @@ -267,7 +275,7 @@ extern "C" INT32 QCALLTYPE ModuleBuilder_GetMemberRef(QCall::ModuleHandle pModul if (TypeFromToken(tr) == mdtTypeDef) { // define a TypeRef using the TypeDef - DefineTypeRefHelper(pRCW->GetEmitter(), tr, &tref); + DefineTypeRefHelper(pRCW->GetMDImport(), pRCW->GetEmitter(), tr, &tref); } else tref = tr; @@ -323,9 +331,6 @@ extern "C" INT32 QCALLTYPE ModuleBuilder_GetMemberRefOfMethodInfo(QCall::ModuleH Assembly * pRefedAssembly = pMeth->GetModule()->GetAssembly(); Assembly * pRefingAssembly = pModule->GetAssembly(); - ReleaseHolder pAssemblyEmit; - IfFailThrow( pRefingAssembly->GetModule()->GetEmitter()->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pAssemblyEmit) ); - CQuickBytes qbNewSig; ULONG cbNewSig; @@ -342,7 +347,7 @@ extern "C" INT32 QCALLTYPE ModuleBuilder_GetMemberRefOfMethodInfo(QCall::ModuleH NULL, 0, // hash blob value pvComSig, cbComSig, - pAssemblyEmit, // Emit assembly scope. + pRCW->GetEmitter(), pRCW->GetEmitter(), &qbNewSig, &cbNewSig) ); @@ -409,9 +414,6 @@ extern "C" mdMemberRef QCALLTYPE ModuleBuilder_GetMemberRefOfFieldInfo(QCall::Mo else COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleBoundNonCollectible")); } - ReleaseHolder pAssemblyEmit; - IfFailThrow( pRefingAssembly->GetModule()->GetEmitter()->QueryInterface(IID_IMetaDataAssemblyEmit, (void **) &pAssemblyEmit) ); - // Translate the field signature this scope CQuickBytes qbNewSig; ULONG cbNewSig; @@ -421,7 +423,7 @@ extern "C" mdMemberRef QCALLTYPE ModuleBuilder_GetMemberRefOfFieldInfo(QCall::Mo NULL, 0, // hash value pvComSig, cbComSig, - pAssemblyEmit, // Emit assembly scope. + pRCW->GetEmitter(), pRCW->GetEmitter(), &qbNewSig, &cbNewSig) ); diff --git a/src/coreclr/vm/field.h b/src/coreclr/vm/field.h index 5b42aaff870bb2..ba6eda77ae805c 100644 --- a/src/coreclr/vm/field.h +++ b/src/coreclr/vm/field.h @@ -676,15 +676,6 @@ class FieldDesc return GetModule()->GetMDImport(); } -#ifndef DACCESS_COMPILE - IMetaDataImport *GetRWImporter() - { - WRAPPER_NO_CONTRACT; - - return GetModule()->GetRWImporter(); - } -#endif // DACCESS_COMPILE - TypeHandle LookupFieldTypeHandle(ClassLoadLevel level = CLASS_LOADED, BOOL dropGenericArgumentLevel = FALSE); TypeHandle LookupApproxFieldTypeHandle() @@ -745,4 +736,3 @@ struct cdac_data }; #endif // _FIELD_H_ - diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index 1c6e13fd9c1c73..31b2eb8a1390eb 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -1004,24 +1004,6 @@ class MethodDesc return pModule->GetCustomAttribute(GetMemberDef(), attribute, ppData, pcbData); } -#ifndef DACCESS_COMPILE - IMetaDataEmit* GetEmitter() - { - WRAPPER_NO_CONTRACT; - Module *pModule = GetModule(); - _ASSERTE(pModule != NULL); - return pModule->GetEmitter(); - } - - IMetaDataImport* GetRWImporter() - { - WRAPPER_NO_CONTRACT; - Module *pModule = GetModule(); - _ASSERTE(pModule != NULL); - return pModule->GetRWImporter(); - } -#endif // !DACCESS_COMPILE - #ifdef FEATURE_COMINTEROP WORD GetComSlot(); LONG GetComDispid(); diff --git a/src/coreclr/vm/peassembly.cpp b/src/coreclr/vm/peassembly.cpp index f83aa4fe6232cb..23da4c243e8c24 100644 --- a/src/coreclr/vm/peassembly.cpp +++ b/src/coreclr/vm/peassembly.cpp @@ -275,6 +275,7 @@ TADDR PEAssembly::GetIL(RVA il) #ifndef DACCESS_COMPILE +#ifdef PROFILING_SUPPORTED void PEAssembly::OpenImporter() { CONTRACTL @@ -298,6 +299,7 @@ void PEAssembly::OpenImporter() if (InterlockedCompareExchangeT(&m_pImporter, pIMDImport, NULL) != NULL) pIMDImport->Release(); } +#endif // PROFILING_SUPPORTED void PEAssembly::ConvertMDInternalToReadWrite() { @@ -316,6 +318,7 @@ void PEAssembly::ConvertMDInternalToReadWrite() // Take a local copy of *ppImport. This may be a pointer to an RO // or to an RW MDInternalXX. pOld = m_pMDImport; +#ifdef PROFILING_SUPPORTED IMetaDataImport *pIMDImport = m_pImporter; if (pIMDImport != NULL) { @@ -331,6 +334,7 @@ void PEAssembly::ConvertMDInternalToReadWrite() } } else +#endif // PROFILING_SUPPORTED { // If an RO, convert to an RW, return S_OK. If already RW, no conversion // needed, return S_FALSE. @@ -393,6 +397,7 @@ void PEAssembly::OpenMDImport() m_pMDImport->AddRef(); } +#ifdef PROFILING_SUPPORTED void PEAssembly::OpenEmitter() { CONTRACTL @@ -416,6 +421,7 @@ void PEAssembly::OpenEmitter() if (InterlockedCompareExchangeT(&m_pEmitter, pIMDEmit, NULL) != NULL) pIMDEmit->Release(); } +#endif // PROFILING_SUPPORTED // ------------------------------------------------------------ // PE file access @@ -632,7 +638,8 @@ ULONG PEAssembly::GetPEImageTimeDateStamp() PEAssembly::PEAssembly( BINDER_SPACE::Assembly* pBoundAssembly, - IMetaDataEmit* pEmit, + IMDInternalEmit* pEmit, + IMDInternalImport* pImport, AssemblyBinder* pDynamicAssemblyBinder /*= NULL*/) : #ifdef LOGGING @@ -641,8 +648,11 @@ PEAssembly::PEAssembly( m_PEImage{NULL} , m_MDImportIsRW_Debugger_Use_Only{FALSE} , m_pMDImport{NULL} +#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) , m_pImporter{NULL} , m_pEmitter{NULL} +#endif // PROFILING_SUPPORTED || DACCESS_COMPILE + , m_pMDInternalEmit{NULL} , m_refCount{1} , m_pHostAssembly{nullptr} , m_pAssemblyBinder{nullptr} @@ -650,7 +660,8 @@ PEAssembly::PEAssembly( CONTRACTL { // A PEAssembly is either bound by an AssemblyBinder or dynamic (reflection emit) - PRECONDITION((pBoundAssembly == NULL) != (pEmit == NULL)); + PRECONDITION((pBoundAssembly == NULL) != (pEmit == NULL && pImport == NULL)); + PRECONDITION((pEmit == NULL) == (pImport == NULL)); // A bound assembly takes its binder from the bind result, not from a caller. PRECONDITION(pBoundAssembly == NULL || pDynamicAssemblyBinder == NULL); STANDARD_VM_CHECK; @@ -669,13 +680,13 @@ PEAssembly::PEAssembly( } // Open metadata eagerly to minimize failure windows - if (pEmit == NULL) + if (pImport == NULL) OpenMDImport(); //constructor, cannot race with anything else { - IfFailThrow(GetMDInternalInterfaceFromPublic(pEmit, IID_IMDInternalImport, - (void **)&m_pMDImport)); - m_pEmitter = pEmit; + m_pMDImport = pImport; + pImport->AddRef(); + m_pMDInternalEmit = pEmit; pEmit->AddRef(); m_MDImportIsRW_Debugger_Use_Only = TRUE; } @@ -725,6 +736,7 @@ PEAssembly::~PEAssembly() GCX_PREEMP(); +#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) if (m_pImporter != NULL) { m_pImporter->Release(); @@ -736,6 +748,13 @@ PEAssembly::~PEAssembly() m_pEmitter->Release(); m_pEmitter = NULL; } +#endif // PROFILING_SUPPORTED || DACCESS_COMPILE + + if (m_pMDInternalEmit != NULL) + { + m_pMDInternalEmit->Release(); + m_pMDInternalEmit = NULL; + } if (m_pMDImport != NULL) { @@ -788,29 +807,35 @@ PEAssembly *PEAssembly::DoOpenSystem() ReleaseHolder pBoundAssembly; IfFailThrow(GetAppDomain()->GetDefaultBinder()->BindToSystem(&pBoundAssembly)); - return new PEAssembly(pBoundAssembly, NULL); + return new PEAssembly(pBoundAssembly, NULL, NULL); } PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBoundAssembly) { - return new PEAssembly(pBoundAssembly, NULL); + return new PEAssembly(pBoundAssembly, NULL, NULL); }; /* static */ -PEAssembly *PEAssembly::Create(IMetaDataAssemblyEmit *pAssemblyEmit, AssemblyBinder *pDynamicAssemblyBinder) +PEAssembly *PEAssembly::Create(IMDInternalEmit *pInternalEmit, AssemblyBinder *pDynamicAssemblyBinder) { CONTRACTL { - PRECONDITION(CheckPointer(pAssemblyEmit)); + PRECONDITION(CheckPointer(pInternalEmit)); STANDARD_VM_CHECK; } CONTRACTL_END; // Set up the metadata pointers in the PEAssembly. (This is the only identity // we have.) - ReleaseHolder pEmit; - pAssemblyEmit->QueryInterface(IID_IMetaDataEmit, (void **)&pEmit); - return new PEAssembly(NULL, pEmit, pDynamicAssemblyBinder); + ReleaseHolder pGetInternalImport; + IfFailThrow(pInternalEmit->QueryInterface( + IID_IGetIMDInternalImport, + (void **)&pGetInternalImport)); + + ReleaseHolder pInternalImport; + IfFailThrow(pGetInternalImport->GetIMDInternalImport(&pInternalImport)); + + return new PEAssembly(NULL, pInternalEmit, pInternalImport, pDynamicAssemblyBinder); } #endif // #ifndef DACCESS_COMPILE diff --git a/src/coreclr/vm/peassembly.h b/src/coreclr/vm/peassembly.h index eb64b15a2ae9db..e1343f7627e4de 100644 --- a/src/coreclr/vm/peassembly.h +++ b/src/coreclr/vm/peassembly.h @@ -52,7 +52,7 @@ typedef DPTR(PEAssembly) PTR_PEAssembly; // The source of the PEImage does not change the PEAssembly itself. // // 2. Dynamic - a reflection emit assembly -// It has no PEImage. Its metadata comes from an IMetaDataEmit and it uses the binder +// It has no PEImage. Its metadata comes from internal import and emit interfaces and it uses the binder // of the assembly that created it. // // See also file:..\inc\corhdr.h#ManagedHeader for more on the format of managed images. @@ -137,18 +137,19 @@ class PEAssembly final // ------------------------------------------------------------ IMDInternalImport *GetMDImport(); + IMDInternalEmit *GetMDInternalEmit(); -#ifndef DACCESS_COMPILE +#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) IMetaDataEmit *GetEmitter(); IMetaDataImport2 *GetRWImporter(); -#else +#elif defined(DACCESS_COMPILE) TADDR GetMDInternalRWAddress(); BOOL HasReadWriteMetadata() { LIMITED_METHOD_DAC_CONTRACT; return m_MDImportIsRW_Debugger_Use_Only; } -#endif // DACCESS_COMPILE +#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE void ConvertMDInternalToReadWrite(); @@ -303,7 +304,7 @@ class PEAssembly final static PEAssembly* Open(BINDER_SPACE::Assembly* pBoundAssembly); - static PEAssembly* Create(IMetaDataAssemblyEmit* pEmit, AssemblyBinder* pDynamicAssemblyBinder); + static PEAssembly* Create(IMDInternalEmit* pEmit, AssemblyBinder* pDynamicAssemblyBinder); // ------------------------------------------------------------ // Utility functions @@ -330,7 +331,8 @@ class PEAssembly final #else PEAssembly( BINDER_SPACE::Assembly* pBoundAssembly, - IMetaDataEmit* pEmit, + IMDInternalEmit* pEmit, + IMDInternalImport* pImport, AssemblyBinder* pDynamicAssemblyBinder = NULL ); @@ -338,8 +340,10 @@ class PEAssembly final #endif void OpenMDImport(); +#ifdef PROFILING_SUPPORTED void OpenImporter(); void OpenEmitter(); +#endif // PROFILING_SUPPORTED private: @@ -376,8 +380,11 @@ class PEAssembly final #endif }; +#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) IMetaDataImport2* m_pImporter; IMetaDataEmit* m_pEmitter; +#endif // PROFILING_SUPPORTED || DACCESS_COMPILE + IMDInternalEmit* m_pMDInternalEmit; Volatile m_refCount; diff --git a/src/coreclr/vm/peassembly.inl b/src/coreclr/vm/peassembly.inl index c0a09602f634b0..601f500d2ccd52 100644 --- a/src/coreclr/vm/peassembly.inl +++ b/src/coreclr/vm/peassembly.inl @@ -253,7 +253,15 @@ inline IMDInternalImport* PEAssembly::GetMDImport() #endif }; -#ifndef DACCESS_COMPILE +inline IMDInternalEmit* PEAssembly::GetMDInternalEmit() +{ + LIMITED_METHOD_CONTRACT; + + _ASSERTE(m_pMDInternalEmit != NULL); + return m_pMDInternalEmit; +} + +#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) inline IMetaDataImport2 *PEAssembly::GetRWImporter() { @@ -290,7 +298,7 @@ inline IMetaDataEmit *PEAssembly::GetEmitter() } -#endif // DACCESS_COMPILE +#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE // Same as the managed Module.ScopeName property, this unconditionally looks in the // metadata Module table to get the name. Useful for profilers and others who don't diff --git a/src/coreclr/vm/reflectclasswriter.cpp b/src/coreclr/vm/reflectclasswriter.cpp index caa8dff09d3db8..7ff79923d821ec 100644 --- a/src/coreclr/vm/reflectclasswriter.cpp +++ b/src/coreclr/vm/reflectclasswriter.cpp @@ -12,50 +12,40 @@ //* constructor for RefClassWriter //* //****************************************************** -HRESULT RefClassWriter::Init(ICeeGenInternal *pCeeGen, IUnknown *pUnk, LPCWSTR szName) +HRESULT RefClassWriter::Init( + ICeeGenInternal *pCeeGen, + IMDInternalEmit *pEmitter, + IMDInternalImport *pInternalImport, + LPCWSTR szName) { CONTRACTL { STANDARD_VM_CHECK; PRECONDITION(CheckPointer(pCeeGen)); - PRECONDITION(CheckPointer(pUnk)); + PRECONDITION(CheckPointer(pEmitter)); + PRECONDITION(CheckPointer(pInternalImport)); } CONTRACTL_END; // Initialize the Import and Emitter interfaces m_emitter = NULL; - m_importer = NULL; m_internalimport = NULL; m_ulResourceSize = 0; m_pCeeGen = pCeeGen; pCeeGen->AddRef(); - // Get the interfaces - HRESULT hr = pUnk->QueryInterface(IID_IMetaDataEmit2, (void**)&m_emitter); - if (FAILED(hr)) - return hr; - - hr = pUnk->QueryInterface(IID_IMetaDataImport, (void**)&m_importer); - if (FAILED(hr)) - return hr; - - hr = pUnk->QueryInterface(IID_IMetaDataEmitHelper, (void**)&m_pEmitHelper); - if (FAILED(hr)) - return hr; - - hr = GetMDInternalInterfaceFromPublic(pUnk, IID_IMDInternalImport, (void**)&m_internalimport); - if (FAILED(hr)) - return hr; + m_emitter = pEmitter; + m_emitter->AddRef(); + m_internalimport = pInternalImport; + m_internalimport->AddRef(); // We will need to set this at some point. - hr = m_emitter->SetModuleProps(szName); + HRESULT hr = m_emitter->SetModuleProps(szName); if (FAILED(hr)) return hr; _ASSERTE(m_emitter != nullptr); - _ASSERTE(m_importer != nullptr); - _ASSERTE(m_pEmitHelper != nullptr); _ASSERTE(m_internalimport != nullptr); return S_OK; } @@ -81,14 +71,6 @@ RefClassWriter::~RefClassWriter() m_emitter->Release(); } - if (m_importer) { - m_importer->Release(); - } - - if (m_pEmitHelper) { - m_pEmitHelper->Release(); - } - if (m_internalimport) { m_internalimport->Release(); } diff --git a/src/coreclr/vm/reflectclasswriter.h b/src/coreclr/vm/reflectclasswriter.h index d2255e0dd1cb69..72506434ce7c83 100644 --- a/src/coreclr/vm/reflectclasswriter.h +++ b/src/coreclr/vm/reflectclasswriter.h @@ -14,11 +14,9 @@ class RefClassWriter { protected: friend class COMDynamicWrite; - IMetaDataEmit2* m_emitter; // Emit interface. - IMetaDataImport* m_importer; // Import interface. + IMDInternalEmit* m_emitter; // Emit interface. IMDInternalImport* m_internalimport; // Scopeless internal import interface ICeeGenInternal* m_pCeeGen; - IMetaDataEmitHelper* m_pEmitHelper; ULONG m_ulResourceSize; public: @@ -26,23 +24,17 @@ class RefClassWriter { LIMITED_METHOD_CONTRACT; } - HRESULT Init(ICeeGenInternal *pCeeGen, IUnknown *pUnk, LPCWSTR szName); + HRESULT Init( + ICeeGenInternal *pCeeGen, + IMDInternalEmit *pEmitter, + IMDInternalImport *pInternalImport, + LPCWSTR szName); - IMetaDataEmit2* GetEmitter() { + IMDInternalEmit* GetEmitter() { LIMITED_METHOD_CONTRACT; return m_emitter; } - IMetaDataEmitHelper* GetEmitHelper() { - LIMITED_METHOD_CONTRACT; - return m_pEmitHelper; - } - - IMetaDataImport* GetRWImporter() { - LIMITED_METHOD_CONTRACT; - return m_importer; - } - IMDInternalImport* GetMDImport() { LIMITED_METHOD_CONTRACT; return m_internalimport; From bb6fc4017d13d5dcf7b16c35f5786749f678601d Mon Sep 17 00:00:00 2001 From: David Wrighton <10779849+davidwrighton@users.noreply.github.com> Date: Tue, 29 Sep 2026 23:38:09 +0000 Subject: [PATCH 2/4] Remove unused metadata implementation from CoreCLR Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/clrdefinitions.cmake | 4 + src/coreclr/debug/di/module.cpp | 34 +- src/coreclr/md/CMakeLists.txt | 5 + src/coreclr/md/compiler/CMakeLists.txt | 4 +- src/coreclr/md/compiler/disp.cpp | 8 +- src/coreclr/md/compiler/helper.cpp | 5 +- src/coreclr/md/compiler/importhelper.cpp | 336 ---------- src/coreclr/md/compiler/importhelper.h | 49 -- src/coreclr/md/compiler/regmeta.cpp | 8 +- src/coreclr/md/compiler/regmeta.h | 24 +- src/coreclr/md/compiler/regmeta_emit.cpp | 46 +- .../md/compiler/regmeta_imetadatatables.cpp | 4 + src/coreclr/md/enc/CMakeLists.txt | 4 +- src/coreclr/md/enc/liteweightstgdbrw.cpp | 2 + src/coreclr/md/enc/mdinternalrw.cpp | 5 +- src/coreclr/md/enc/metamodelrw.cpp | 66 +- src/coreclr/md/enc/rwutil.cpp | 583 +----------------- src/coreclr/md/enc/stgtiggerstorage.cpp | 12 + src/coreclr/md/enc/stgtiggerstream.cpp | 4 + src/coreclr/md/heaps/blobheap.h | 16 +- src/coreclr/md/heaps/guidheap.h | 2 + src/coreclr/md/heaps/stringheap.h | 16 +- src/coreclr/md/inc/metamodelrw.h | 10 +- src/coreclr/md/inc/rwutil.h | 184 +----- src/coreclr/md/inc/stgpool.h | 12 + src/coreclr/md/runtime/CMakeLists.txt | 4 +- src/coreclr/md/runtime/mdinternalro.cpp | 4 + src/coreclr/md/runtime/stgpool.cpp | 3 +- src/coreclr/md/tables/table.h | 4 + src/coreclr/vm/ceeload.cpp | 6 + src/coreclr/vm/ceeload.h | 4 + src/coreclr/vm/clsload.cpp | 2 + 32 files changed, 247 insertions(+), 1223 deletions(-) diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake index 0e2105600677ed..ce2b2184596145 100644 --- a/src/coreclr/clrdefinitions.cmake +++ b/src/coreclr/clrdefinitions.cmake @@ -34,6 +34,10 @@ endif(CLR_CMAKE_TARGET_LINUX_MUSL) add_definitions(-DDEBUGGING_SUPPORTED) +if (NOT CLR_CMAKE_TARGET_ARCH_WASM) + add_compile_definitions(FEATURE_METADATA_PERSISTENCE) +endif() + if (FEATURE_CORPROFILER) add_compile_definitions($<$>>:PROFILING_SUPPORTED>) add_compile_definitions($<$>>:FEATURE_PROFAPI_ATTACH_DETACH>) diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index 9846d82fcb9720..b89af61ee15de9 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -335,7 +335,7 @@ void CordbModule::UpdateMetaDataCacheIfNeeded(mdToken token) } // - // 1) Check if in-range? Compare against tables, etc. + // 1) Check whether the token is in the cached metadata. // if(CheckIfTokenInMetaData(token)) { @@ -365,37 +365,7 @@ BOOL CordbModule::CheckIfTokenInMetaData(mdToken token) CONTRACTL_END; LOG((LF_CORDB,LL_INFO10000, "CM::CITIM token=0x%x\n", token)); _ASSERTE(TypeFromToken(token) == mdtSignature); - RSExtSmartPtr pTable; - - HRESULT hr = GetMetaDataImporter()->QueryInterface(IID_IMetaDataTables, (void**) &pTable); - - _ASSERTE(SUCCEEDED(hr)); - if (FAILED(hr)) - { - ThrowHR(hr); - } - - ULONG cbRowsAvailable; // number of rows in the table - - hr = pTable->GetTableInfo( - mdtSignature >> 24, // [IN] Which table. - NULL, // [OUT] Size of a row, bytes. - &cbRowsAvailable, // [OUT] Number of rows. - NULL, // [OUT] Number of columns in each row. - NULL, // [OUT] Key column, or -1 if none. - NULL); // [OUT] Name of the table. - - _ASSERTE(SUCCEEDED(hr)); - if (FAILED(hr)) - { - ThrowHR(hr); - } - - - // Rows start counting with number 1. - ULONG rowRequested = RidFromToken(token); - LOG((LF_CORDB,LL_INFO10000, "CM::UMCIN requested=0x%x available=0x%x\n", rowRequested, cbRowsAvailable)); - return (rowRequested <= cbRowsAvailable); + return GetMetaDataImporter()->IsValidToken(token); } // This helper class ensures the remote serailzied buffer gets deleted in the RefreshMetaData diff --git a/src/coreclr/md/CMakeLists.txt b/src/coreclr/md/CMakeLists.txt index d0bf1d4367fc21..8bb474bcfb0663 100644 --- a/src/coreclr/md/CMakeLists.txt +++ b/src/coreclr/md/CMakeLists.txt @@ -1,5 +1,10 @@ add_compile_definitions(FEATURE_METADATA_EMIT) add_compile_definitions(FEATURE_METADATA_INTERNAL_APIS) +if (NOT CLR_CMAKE_TARGET_ARCH_WASM) + add_compile_definitions(FEATURE_METADATA_PERSISTENCE) +else() + add_compile_definitions($<$>,$>>:FEATURE_METADATA_PERSISTENCE>) +endif() add_compile_definitions($<$>,$>>:FEATURE_METADATA_EMIT_IN_DEBUGGER>) add_compile_definitions($<$>,$>>>:FEATURE_METADATA_IN_VM>) add_compile_definitions($<$>:FEATURE_METADATA_LOAD_TRUSTED_IMAGES>) diff --git a/src/coreclr/md/compiler/CMakeLists.txt b/src/coreclr/md/compiler/CMakeLists.txt index 99c3a62511527f..4c415397c48200 100644 --- a/src/coreclr/md/compiler/CMakeLists.txt +++ b/src/coreclr/md/compiler/CMakeLists.txt @@ -52,7 +52,7 @@ target_compile_definitions(mdcompiler_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERF target_precompile_headers(mdcompiler_dac PRIVATE stdafx.h) add_library_clr(mdcompiler_wks OBJECT ${MDCOMPILER_SOURCES}) -target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() @@ -64,5 +64,5 @@ target_compile_definitions(mdcompiler-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTERF target_precompile_headers(mdcompiler-dbi PRIVATE stdafx.h) add_library_clr(mdcompiler_ppdb ${MDCOMPILER_SOURCES}) -target_compile_definitions(mdcompiler_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) +target_compile_definitions(mdcompiler_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PERSISTENCE FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdcompiler_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/compiler/disp.cpp b/src/coreclr/md/compiler/disp.cpp index bc878ff6710c46..d1d8ad6e066a96 100644 --- a/src/coreclr/md/compiler/disp.cpp +++ b/src/coreclr/md/compiler/disp.cpp @@ -208,13 +208,13 @@ Disp::OpenRawScope( // Add the new RegMeta to the cache. IfFailGo(pMeta->AddToCache()); -#if defined(_DEBUG) +#if defined(_DEBUG) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) if (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MD_RegMetaDump)) { int DumpMD_impl(RegMeta *pMD); DumpMD_impl(pMeta); } -#endif // _DEBUG +#endif // _DEBUG && FEATURE_METADATA_PUBLIC_INTERFACES ErrExit: @@ -291,13 +291,13 @@ HRESULT Disp::OpenRawScopeOnMemory( // Return code. // Add the new RegMeta to the cache. IfFailGo(pMeta->AddToCache()); -#if defined(_DEBUG) +#if defined(_DEBUG) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) if (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MD_RegMetaDump)) { int DumpMD_impl(RegMeta *pMD); DumpMD_impl(pMeta); } -#endif // _DEBUG +#endif // _DEBUG && FEATURE_METADATA_PUBLIC_INTERFACES ErrExit: if (FAILED(hr)) diff --git a/src/coreclr/md/compiler/helper.cpp b/src/coreclr/md/compiler/helper.cpp index 5330d31dc17e22..811314ba5200b4 100644 --- a/src/coreclr/md/compiler/helper.cpp +++ b/src/coreclr/md/compiler/helper.cpp @@ -82,7 +82,6 @@ STDMETHODIMP RegMeta::TranslateSigWithScope( // S_OK or error. cbHashValue, // Size in bytes. pImportMetaModelCommon, // The scope where signature is from. pbSigBlob, // signature from the imported scope - NULL, // Internal OID mapping structure. &qkSigEmit, // [OUT] translated signature 0, // start from first byte of the signature 0, // don't care how many bytes consumed @@ -343,7 +342,11 @@ RegMeta::GetMetadata( HRESULT RegMeta::ChangeMvid( // S_OK or error. REFGUID newMvid) // GUID to use as the MVID { +#ifdef FEATURE_METADATA_CORECLR + return E_NOTIMPL; +#else return GetMiniMd()->ChangeMvid(newMvid); +#endif } //******************************************************************************* diff --git a/src/coreclr/md/compiler/importhelper.cpp b/src/coreclr/md/compiler/importhelper.cpp index 940911ccb50e34..6d595a6caa4612 100644 --- a/src/coreclr/md/compiler/importhelper.cpp +++ b/src/coreclr/md/compiler/importhelper.cpp @@ -66,110 +66,6 @@ HRESULT ImportHelper::FindMethodSpecByMethodAndInstantiation( } // HRESULT ImportHelper::FindMethodSpecByMethodAndInstantiation() -//******************************************************************************* -// Find the GenericParam by owner and constraint -//******************************************************************************* -//@GENERICS: todo: look in hashtable (cf. MetaModelRW.cpp) if necessary -HRESULT ImportHelper::FindGenericParamConstraintByOwnerAndConstraint( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdGenericParam tkOwner, // [IN] GenericParamConstraint Owner - mdToken tkConstraint, // [IN] GenericParamConstraint Constraint - mdGenericParamConstraint *pGenericParamConstraint,// [OUT] Put the GenericParam token here. - RID rid /* = 0*/) // [IN] Optional rid to be ignored. -{ - HRESULT hr; - GenericParamConstraintRec *pRecord; - mdGenericParam tkOwnerTmp; - mdToken tkConstraintTmp; - ULONG cGenericParamConstraints; - - ULONG i; - - _ASSERTE(pGenericParamConstraint); - - cGenericParamConstraints = pMiniMd->getCountGenericParamConstraints(); - - // linear scan through the GenericParam table - for (i=1; i <= cGenericParamConstraints; ++i) - { - // For the call from Validator ignore the rid passed in. - if (i == rid) - continue; - - IfFailRet(pMiniMd->GetGenericParamConstraintRecord(i, &pRecord)); - - tkOwnerTmp = pMiniMd->getOwnerOfGenericParamConstraint(pRecord); - tkConstraintTmp = pMiniMd->getConstraintOfGenericParamConstraint(pRecord); - - if ((tkOwnerTmp != tkOwner) || (tkConstraintTmp != tkConstraint)) - continue; - - // Matching record found. - *pGenericParamConstraint = TokenFromRid(i, mdtGenericParamConstraint); - return S_OK; - } - return CLDB_E_RECORD_NOTFOUND; -} // HRESULT ImportHelper::FindGenericParamConstraintByOwnerAndConstraint() - -//******************************************************************************* -// Find the GenericParam by owner and name or number -//******************************************************************************* -// @GENERICS: todo: look in hashtable (cf. MetaModelRW.cpp) if necessary -HRESULT ImportHelper::FindGenericParamByOwner( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdToken tkOwner, // [IN] GenericParam Owner - LPCUTF8 szUTF8Name, // [IN] GeneriParam Name, may be NULL if not used for search - ULONG *pNumber, // [IN] GeneriParam Number, may be NULL if not used for search - mdGenericParam *pGenericParam, // [OUT] Put the GenericParam token here. - RID rid /* = 0*/) // [IN] Optional rid to be ignored. -{ - HRESULT hr; - GenericParamRec *pRecord; - mdToken tkOwnerTmp; - ULONG cGenericParams; - LPCUTF8 szCurName; - ULONG curNumber; - ULONG i; - - _ASSERTE(pGenericParam); - - cGenericParams = pMiniMd->getCountGenericParams(); - - // linear scan through the GenericParam table - for (i=1; i <= cGenericParams; ++i) - { - // For the call from Validator ignore the rid passed in. - if (i == rid) - continue; - - IfFailRet(pMiniMd->GetGenericParamRecord(i, &pRecord)); - - tkOwnerTmp = pMiniMd->getOwnerOfGenericParam(pRecord); - if ( tkOwnerTmp != tkOwner) - continue; - - // if the name is significant, try to match it - if (szUTF8Name) - { - IfFailRet(pMiniMd->getNameOfGenericParam(pRecord, &szCurName)); - if (strcmp(szCurName, szUTF8Name)) - continue; - } - - // if the number is significant, try to match it - if (pNumber) - { curNumber = pMiniMd->getNumberOfGenericParam(pRecord); - if (*pNumber != curNumber) - continue; - } - - // Matching record found. - *pGenericParam = TokenFromRid(i, mdtGenericParam); - return S_OK; - } - return CLDB_E_RECORD_NOTFOUND; -} // HRESULT ImportHelper::FindGenericParamByOwner() - //******************************************************************************* // Find a Method given a parent, name and signature. //******************************************************************************* @@ -627,41 +523,6 @@ HRESULT ImportHelper::FindMethodImpl( return CLDB_E_RECORD_NOTFOUND; } // HRESULT ImportHelper::FindMethodImpl() -//******************************************************************************* -// Find the TypeRef given the fully qualified name and the assembly name -//******************************************************************************* -HRESULT ImportHelper::FindCustomAttributeCtorByName( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - LPCUTF8 szAssemblyName, // [IN] Assembly Name. - LPCUTF8 szNamespace, // [IN] TypeRef Namespace. - LPCUTF8 szName, // [IN] TypeRef Name. - mdTypeDef *ptk, // [OUT] Put the TypeRef token here. - RID rid /* = 0*/) // [IN] Optional rid to be ignored. -{ - HRESULT hr; - ULONG cRecs; // Count of records. - AssemblyRefRec *pRec; // Current record being looked at. - LPCUTF8 szTmp; // Temp string. - mdTypeRef tkCAType; - - cRecs = pMiniMd->getCountAssemblyRefs(); - // Search for the AssemblyRef record. - for (ULONG i = 1; i <= cRecs; i++) - { - IfFailRet(pMiniMd->GetAssemblyRefRecord(i, &pRec)); - - IfFailRet(pMiniMd->getNameOfAssemblyRef(pRec, &szTmp)); - if (!strcmp(szTmp, szAssemblyName) && - (SUCCEEDED(FindTypeRefByName(pMiniMd, TokenFromRid(i, mdtAssemblyRef), szNamespace, szName, &tkCAType, rid))) && - (SUCCEEDED(FindMemberRef(pMiniMd, tkCAType, COR_CTOR_METHOD_NAME, NULL, 0 ,ptk)))) - { - return S_OK; - } - } - - return CLDB_E_RECORD_NOTFOUND; -} - //******************************************************************************* // Find the TypeRef given the fully qualified name. //******************************************************************************* @@ -1145,136 +1006,6 @@ HRESULT ImportHelper::FindEvent( -//***************************************************************************** -// find an custom value record given by parent and type token. This will always return -// the first one that is found regardless duplicated. -//***************************************************************************** -HRESULT ImportHelper::FindCustomAttributeByToken( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdToken tkParent, // [IN] the parent that custom value is associated with - mdToken tkType, // [IN] type of the CustomAttribute - const void *pCustBlob, // [IN] custom attribute blob - ULONG cbCustBlob, // [IN] size of the blob. - mdCustomAttribute *pcv) // [OUT] CustomAttribute token -{ - HRESULT hr; - CustomAttributeRec *pRec; - ULONG ridStart, ridEnd; - ULONG i; - mdToken tkParentTmp; - mdToken tkTypeTmp; - const void *pCustBlobTmp; - ULONG cbCustBlobTmp; - - _ASSERTE(pcv); - *pcv = mdCustomAttributeNil; - if ( pMiniMd->IsSorted(TBL_CustomAttribute) ) - { - IfFailRet(pMiniMd->FindCustomAttributeFor( - RidFromToken(tkParent), - TypeFromToken(tkParent), - tkType, - (RID *)pcv)); - if (InvalidRid(*pcv)) - { - return S_FALSE; - } - else if (pCustBlob) - { - IfFailRet(pMiniMd->GetCustomAttributeRecord(RidFromToken(*pcv), &pRec)); - IfFailRet(pMiniMd->getValueOfCustomAttribute(pRec, (const BYTE **)&pCustBlobTmp, &cbCustBlobTmp)); - if (cbCustBlob == cbCustBlobTmp && - !memcmp(pCustBlob, pCustBlobTmp, cbCustBlob)) - { - return S_OK; - } - } - else - { - return S_OK; - } - } - else - { - CLookUpHash *pHashTable = pMiniMd->m_pLookUpHashes[TBL_CustomAttribute]; - - if (pHashTable) - { - // table is not sorted but hash is built - // We want to create dynmaic array to hold the dynamic enumerator. - TOKENHASHENTRY *p; - ULONG iHash; - int pos; - - // Hash the data. - iHash = pMiniMd->HashCustomAttribute(tkParent); - - // Go through every entry in the hash chain looking for ours. - for (p = pHashTable->FindFirst(iHash, pos); - p; - p = pHashTable->FindNext(pos)) - { - IfFailRet(pMiniMd->GetCustomAttributeRecord(RidFromToken(p->tok), &pRec)); - - tkParentTmp = pMiniMd->getParentOfCustomAttribute(pRec); - if (tkParentTmp != tkParent) - continue; - - tkTypeTmp = pMiniMd->getTypeOfCustomAttribute(pRec); - if (tkType != tkTypeTmp) - continue; - if (pCustBlob != NULL) - { - IfFailRet(pMiniMd->getValueOfCustomAttribute(pRec, (const BYTE **)&pCustBlobTmp, &cbCustBlobTmp)); - if (cbCustBlob == cbCustBlobTmp && - !memcmp(pCustBlob, pCustBlobTmp, cbCustBlob)) - { - *pcv = TokenFromRid(p->tok, mdtCustomAttribute); - return S_OK; - } - } - else - return S_OK; - } - } - else - { - // linear scan - ridStart = 1; - ridEnd = pMiniMd->getCountCustomAttributes() + 1; - - // loop through all custom values - for (i = ridStart; i < ridEnd; i++) - { - IfFailRet(pMiniMd->GetCustomAttributeRecord(i, &pRec)); - - tkParentTmp = pMiniMd->getParentOfCustomAttribute(pRec); - if ( tkParentTmp != tkParent ) - continue; - - tkTypeTmp = pMiniMd->getTypeOfCustomAttribute(pRec); - if (tkType != tkTypeTmp) - continue; - - if (pCustBlob != NULL) - { - IfFailRet(pMiniMd->getValueOfCustomAttribute(pRec, (const BYTE **)&pCustBlobTmp, &cbCustBlobTmp)); - if (cbCustBlob == cbCustBlobTmp && - !memcmp(pCustBlob, pCustBlobTmp, cbCustBlob)) - { - *pcv = TokenFromRid(i, mdtCustomAttribute); - return S_OK; - } - } - else - return S_OK; - } - } - // fall through - } - return S_FALSE; -} // ImportHelper::FindCustomAttributeByToken - //***************************************************************************** // Helper function to lookup and retrieve a CustomAttribute. //***************************************************************************** @@ -1588,7 +1319,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( ULONG cbHashValue, // [IN] Size in bytes for the hash value. IMetaModelCommon *pCommonImport, // [IN] The scope to merge into the emit scope. PCCOR_SIGNATURE pbSigImp, // signature from the imported scope - MDTOKENMAP *ptkMap, // Internal OID mapping structure. CQuickBytes *pqkSigEmit, // [OUT] buffer for translated signature ULONG cbStartEmit, // [IN] start point of buffer to write to ULONG *pcbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1644,7 +1374,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // from the imported scope - ptkMap, // OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbDestTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1665,7 +1394,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // from the imported scope - ptkMap, // OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbDestTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1693,7 +1421,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // The scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // signature from the imported scope - ptkMap, // Internal OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbDestTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1735,7 +1462,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // The scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // signature from the imported scope - ptkMap, // Internal OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbSrcTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1791,7 +1517,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // The scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // signature from the imported scope - ptkMap, // Internal OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbDestTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1810,20 +1535,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( // now get the embedded typeref token cb = CorSigUncompressToken(&pbSigImp[cbSrcTotal], &tkRidFrom); - // Map the ulRidFrom to ulRidTo - if (ptkMap) - { - // mdtBaseType does not record in the map. It is unique across modules - if ( TypeFromToken(tkRidFrom) == mdtBaseType ) - { - tkRidTo = tkRidFrom; - } - else - { - IfFailGo( ptkMap->Remap(tkRidFrom, &tkRidTo) ); - } - } - else { // If the token is a TypeDef or a TypeRef, get/create the // ResolutionScope for the outermost TypeRef. @@ -1872,7 +1583,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // The scope to merge into the emit scope. pvTypeSpecSig, // signature from the imported scope - ptkMap, // Internal OID mapping structure. &qkTypeSpecSigEmit, // [OUT] buffer for translated signature 0, // start from first byte of TypeSpec signature 0, // don't care how many bytes are consumed @@ -1939,7 +1649,6 @@ ImportHelper::MergeUpdateTokenInFieldSig( cbHashValue, // Size in bytes for the hash value. pCommonImport, // The scope to merge into the emit scope. &pbSigImp[cbSrcTotal], // signature from the imported scope - ptkMap, // Internal OID mapping structure. pqkSigEmit, // [OUT] buffer for translated signature cbStartEmit + cbDestTotal, // [IN] start point of buffer to write to &cbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -1982,7 +1691,6 @@ HRESULT ImportHelper::MergeUpdateTokenInSig(// S_OK or error. ULONG cbHashValue, // [IN] Size in bytes for the hash value. IMetaModelCommon *pCommonImport, // [IN] The scope to merge into the emit scope. PCCOR_SIGNATURE pbSigImp, // signature from the imported scope - MDTOKENMAP *ptkMap, // Internal OID mapping structure. CQuickBytes *pqkSigEmit, // [OUT] translated signature ULONG cbStartEmit, // [IN] start point of buffer to write to ULONG *pcbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -2026,7 +1734,6 @@ HRESULT ImportHelper::MergeUpdateTokenInSig(// S_OK or error. cbHashValue, pCommonImport, &pbSigImp[cbSrcTotal], - ptkMap, pqkSigEmit, // output buffer to hold the new sig for the field cbStartEmit + cbDestTotal, // number of bytes already in pqkSigDest &cbImp, // number of bytes consumed from imported signature @@ -2065,7 +1772,6 @@ HRESULT ImportHelper::MergeUpdateTokenInSig(// S_OK or error. cbHashValue, pCommonImport, &pbSigImp[cbSrcTotal], - ptkMap, pqkSigEmit, // output buffer to hold the new sig for the field cbStartEmit + cbDestTotal, // number of bytes already in pqkSigDest &cbImp, // number of bytes consumed from imported signature @@ -2088,7 +1794,6 @@ HRESULT ImportHelper::MergeUpdateTokenInSig(// S_OK or error. cbHashValue, pCommonImport, &pbSigImp[cbSrcTotal], - ptkMap, pqkSigEmit, // output buffer to hold the new sig for the field cbStartEmit + cbDestTotal, &cbImp, // number of bytes consumed from imported signature @@ -2350,47 +2055,6 @@ HRESULT ImportHelper::CreateNesterHierarchy( return hr; } // ImportHelper::CreateNesterHierarchy -//**************************************************************************** -// Given the arrays of names and namespaces for the Nested Type hierarchy, -// find the innermost TypeRef token. The arrays start with the innermost -// TypeRefs and go outwards. -//**************************************************************************** -HRESULT ImportHelper::FindNestedTypeRef( - CMiniMdRW *pMiniMd, // [IN] Scope in which to find the TypeRef. - CQuickArray &cqaNesterNamespaces, // [IN] Array of Names. - CQuickArray &cqaNesterNames, // [IN] Array of Namespaces. - mdToken tkResolutionScope, // [IN] Resolution scope for the outermost TypeRef. - mdTypeRef *ptr) // [OUT] Inner most TypeRef token. -{ - ULONG ulNesters; - ULONG ulCurNester; - HRESULT hr = S_OK; - - _ASSERTE(cqaNesterNames.Size() == cqaNesterNamespaces.Size() && - cqaNesterNames.Size()); - - // Set the output parameter to Nil token. - *ptr = mdTokenNil; - - // Get count in the hierarchy, the give TypeDef included. - ulNesters = (ULONG)cqaNesterNames.Size(); - - // For each nester try to find the corresponding TypeRef in - // the emit scope. For the outermost TypeDef enclosing class is Nil. - for (ulCurNester = ulNesters-1; ulCurNester != (ULONG) -1; ulCurNester--) - { - IfFailGo(FindTypeRefByName(pMiniMd, - tkResolutionScope, - cqaNesterNamespaces[ulCurNester], - cqaNesterNames[ulCurNester], - &tkResolutionScope)); - } - *ptr = tkResolutionScope; -ErrExit: - return hr; -} // HRESULT ImportHelper::FindNestedTypeRef() - - //**************************************************************************** // Given the arrays of names and namespaces for the Nested Type hierarchy, // find the innermost TypeDef token. The arrays start with the innermost diff --git a/src/coreclr/md/compiler/importhelper.h b/src/coreclr/md/compiler/importhelper.h index febcd7b5ae1788..264ae2d7a67213 100644 --- a/src/coreclr/md/compiler/importhelper.h +++ b/src/coreclr/md/compiler/importhelper.h @@ -12,8 +12,6 @@ #define __IMPORTHELPER__h__ class CMiniMdRW; -class MDTOKENMAP; - //********************************************************************* // Class to handle merge //********************************************************************* @@ -37,22 +35,6 @@ class ImportHelper RID rid = 0); // [IN] Optional rid to be ignored. - static HRESULT FindGenericParamConstraintByOwnerAndConstraint( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdGenericParam tkOwner, // [IN] GenericParamConstraint Owner - mdToken tkConstraint, // [IN] GenericParamConstraint Constraint - mdGenericParamConstraint *pGenericParamConstraint, // [OUT] Put the GenericParamConstraint token here. - RID rid = 0); // [IN] Optional rid to be ignored. - - - static HRESULT FindGenericParamByOwner( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdToken tkOwner, // [IN] GenericParam Owner - LPCUTF8 szUTF8Name, // [IN] GeneriParam Name, may be NULL if not used for search - ULONG *pNumber, // [IN] GeneriParam Number, may be NULL if not used for search - mdGenericParam *pGenericParam, // [OUT] Put the GenericParam token here. - RID rid = 0); // [IN] Optional rid to be ignored. - static HRESULT FindMethod( CMiniMdRW * pMiniMd, // [IN] the minimd to lookup mdTypeDef td, // [IN] parent. @@ -110,14 +92,6 @@ class ImportHelper mdToken tkDecl, // [IN] Method declaration token. RID *pRid); // [OUT] Put the MethodImpl rid here - static HRESULT FindCustomAttributeCtorByName( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - LPCUTF8 szAssemblyName, // [IN] Assembly Name. - LPCUTF8 szNamespace, // [IN] TypeRef Namespace. - LPCUTF8 szName, // [IN] TypeRef Name. - mdTypeDef *ptk, // [OUT] Put the TypeRef token here. - RID rid = 0); // [IN] Optional rid to be ignored. - static HRESULT FindTypeRefByName( CMiniMdRW *pMiniMd, // [IN] the minimd to lookup mdToken tkResolutionScope, // [IN] ResolutionScope, mdAssemblyRef or mdModuleRef. @@ -167,14 +141,6 @@ class ImportHelper LPCUTF8 szName, // [IN] name of the event mdProperty *pev); // [OUT] Event token - static HRESULT FindCustomAttributeByToken( - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdToken tkParent, // [IN] the parent that custom value is associated with - mdToken tkType, // [IN] type of the CustomAttribute - const void *pCustBlob, // [IN] custom value blob - ULONG cbCustBlob, // [IN] size of the blob. - mdCustomAttribute *pcv); // [OUT] CustomAttribute token - static HRESULT GetCustomAttributeByName(// S_OK or error. CMiniMdRW *pMiniMd, // [IN] the minimd to lookup mdToken tkObj, // [IN] Object with Custom Attribute. @@ -182,12 +148,6 @@ class ImportHelper const void **ppData, // [OUT] Put pointer to data here. ULONG *pcbData); // [OUT] Put size of data here. - static HRESULT GetCustomAttributeByName(// S_OK or error. - CMiniMdRW *pMiniMd, // [IN] the minimd to lookup - mdToken tkObj, // [IN] Object with Custom Attribute. - LPCUTF8 szName, // [IN] Name of desired Custom Attribute. - mdCustomAttribute pca); // [OUT] found CA token - static HRESULT MergeUpdateTokenInFieldSig( CMiniMdRW *pMiniMdAssemEmit, // [IN] The assembly emit scope. CMiniMdRW *pMiniMdEmit, // [IN] The emit scope. @@ -196,7 +156,6 @@ class ImportHelper ULONG cbHashValue, // [IN] Size in bytes for the hash value. IMetaModelCommon *pCommonImport, // [IN] The scope to merge into the emit scope. PCCOR_SIGNATURE pbSigImp, // [IN] signature from the imported scope - MDTOKENMAP *ptkMap, // [IN] Internal OID mapping structure. CQuickBytes *pqkSigEmit, // [OUT] buffer for translated signature ULONG cbStartEmit, // [IN] start point of buffer to write to ULONG *pcbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -210,7 +169,6 @@ class ImportHelper ULONG cbHashValue, // [IN] Size in bytes for the hash value. IMetaModelCommon *pCommonImport, // [IN] The scope to merge into the emit scope. PCCOR_SIGNATURE pbSigImp, // [IN] signature from the imported scope - MDTOKENMAP *ptkMap, // [IN] Internal OID mapping structure. CQuickBytes *pqkSigEmit, // [OUT] translated signature ULONG cbStartEmit, // [IN] start point of buffer to write to ULONG *pcbImp, // [OUT] total number of bytes consumed from pbSigImp @@ -258,13 +216,6 @@ class ImportHelper CQuickArray &cqaNamespaces, // Namespaces of the nesters. CQuickArray &cqaNames); // Names of the nesters. - static HRESULT FindNestedTypeRef( - CMiniMdRW *pMiniMd, // [IN] Scope in which to find the TypeRef. - CQuickArray &cqaNesterNamespaces, // [IN] Array of Namespaces. - CQuickArray &cqaNesterNames, // [IN] Array of Names. - mdToken tkResolutionScope, // [IN] Resolution scope for the outermost TypeRef. - mdTypeRef *ptr); // [OUT] Inner most TypeRef token. - static HRESULT FindNestedTypeDef( CMiniMdRW *pMiniMd, // [IN] Scope in which to find the TypeRef. CQuickArray &cqaNesterNamespaces, // [IN] Array of Namespaces. diff --git a/src/coreclr/md/compiler/regmeta.cpp b/src/coreclr/md/compiler/regmeta.cpp index b7d5378d1137e1..755418f831680d 100644 --- a/src/coreclr/md/compiler/regmeta.cpp +++ b/src/coreclr/md/compiler/regmeta.cpp @@ -497,6 +497,7 @@ RegMeta::QueryInterface( *ppUnk = (IMetaDataAssemblyImport *)this; } #endif +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES else if (riid == IID_IMetaDataTables) { *ppUnk = static_cast(this); @@ -510,6 +511,7 @@ RegMeta::QueryInterface( { *ppUnk = static_cast(this); } +#endif #if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) else if (riid == IID_IMetaDataEmit) @@ -666,6 +668,7 @@ RegMeta::QueryInterface( // - The file is not NT PE file (e.g. it is NT OBJ = .obj file produced by managed C++). // E_INVALIDARG - NULL was passed as an argument value. // +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES HRESULT RegMeta::GetFileMapping( const void ** ppvData, @@ -727,12 +730,13 @@ RegMeta::GetFileMapping( return hr; } // RegMeta::GetFileMapping +#endif //------------------------------------------------------------------------------ // Metadata dump // -#ifdef _DEBUG +#if defined(_DEBUG) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) #define STRING_BUFFER_LEN 1024 #define ENUM_BUFFER_SIZE 10 @@ -1273,7 +1277,7 @@ int DumpMD(UINT_PTR iMD) return DumpMD_impl(pMD); } -#endif //_DEBUG +#endif // _DEBUG && FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Using the existing RegMeta and reopen with another chuck of memory. Make sure that all stgdb diff --git a/src/coreclr/md/compiler/regmeta.h b/src/coreclr/md/compiler/regmeta.h index e0fc3453eceb97..b16a1326b02502 100644 --- a/src/coreclr/md/compiler/regmeta.h +++ b/src/coreclr/md/compiler/regmeta.h @@ -123,12 +123,10 @@ class RegMeta : #ifdef FEATURE_METADATA_PUBLIC_INTERFACES public IMetaDataImport2, public IMetaDataAssemblyImport, -#endif public IMetaDataTables2 - , public IMetaDataInfo -#if defined(FEATURE_METADATA_EMIT) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) +#ifdef FEATURE_METADATA_EMIT #ifndef FEATURE_METADATA_EMIT_PORTABLE_PDB , public IMetaDataEmit2 #else @@ -149,6 +147,17 @@ class RegMeta : #endif , public IMDCommon +#else +#ifdef FEATURE_METADATA_EMIT_ALL + public IMetaDataFilter, +#endif +#ifdef FEATURE_METADATA_INTERNAL_APIS + public IMetaDataHelper, + public IMDInternalEmit, + public IGetIMDInternalImport, +#endif + public IMDCommon +#endif { friend class CImportTlb; friend class MDInternalRW; @@ -1318,6 +1327,7 @@ class RegMeta : // IMetaDataTables //***************************************************************************** +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES // Fills size (*pcbStringsHeapSize) of internal strings heap (#String). // Returns S_OK or error code. Fills *pcbStringsHeapSize with 0 on error. // Implements public API code:IMetaDataTables::GetStringHeapSize. @@ -1496,7 +1506,7 @@ class RegMeta : const void ** ppvData, // [out] Pointer to the start of the mapped file. ULONGLONG * pcbData, // [out] Size of the mapped memory region.. DWORD * pdwMappingType); // [out] Type of file mapping (code:CorFileMapping). - +#endif //***************************************************************************** // IMDCommon methods @@ -1592,9 +1602,6 @@ class RegMeta : HRESULT PreSave(); - // Define a TypeRef given the name. - enum eCheckDups {eCheckDefault=0, eCheckNo=1, eCheckYes=2}; - HRESULT _DefinePermissionSet( mdToken tk, // [IN] the object to be decorated. DWORD dwAction, // [IN] CorDeclSecurity. @@ -1606,8 +1613,7 @@ class RegMeta : mdToken tkResolutionScope, // [IN] ModuleRef or AssemblyRef. const void *szName, // [IN] Name of the TypeRef. BOOL isUnicode, // [IN] Specifies whether the URL is unicode. - mdTypeRef *ptk, // [OUT] Put mdTypeRef here. - eCheckDups eCheck=eCheckDefault); // [IN] Specifies whether to check for duplicates. + mdTypeRef *ptk); // [OUT] Put mdTypeRef here. // Define MethodSemantics HRESULT _DefineMethodSemantics( // S_OK or error. diff --git a/src/coreclr/md/compiler/regmeta_emit.cpp b/src/coreclr/md/compiler/regmeta_emit.cpp index c53a45261b3826..11ea8d65bc9007 100644 --- a/src/coreclr/md/compiler/regmeta_emit.cpp +++ b/src/coreclr/md/compiler/regmeta_emit.cpp @@ -28,7 +28,7 @@ #include -#if defined(_DEBUG) +#if defined(_DEBUG) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) #define LOGGING #endif #include @@ -68,6 +68,7 @@ STDMETHODIMP RegMeta::SetModuleProps( // S_OK or error. //***************************************************************************** // Saves a scope to a file of a given name. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE STDMETHODIMP RegMeta::Save( // S_OK or error. LPCWSTR szFile, // [IN] The filename to save to. DWORD dwSaveFlags) // [IN] Flags for the save. @@ -93,7 +94,7 @@ STDMETHODIMP RegMeta::Save( // S_OK or error. int DumpMD_impl(RegMeta *pMD); DumpMD_impl(this); } -#endif // _DEBUG +#endif // _DEBUG && FEATURE_METADATA_PUBLIC_INTERFACES ErrExit: return hr; @@ -115,13 +116,13 @@ STDMETHODIMP RegMeta::SaveToStream( // S_OK or error. hr = _SaveToStream(pIStream, dwSaveFlags); -#if defined(_DEBUG) +#if defined(_DEBUG) && defined(FEATURE_METADATA_PUBLIC_INTERFACES) if (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MD_RegMetaDump)) { int DumpMD_impl(RegMeta *pMD); DumpMD_impl(this); } -#endif // _DEBUG +#endif // _DEBUG && FEATURE_METADATA_PUBLIC_INTERFACES ErrExit: return hr; @@ -238,6 +239,35 @@ STDMETHODIMP RegMeta::GetSaveSize( // S_OK or error. ErrExit: return hr; } // RegMeta::GetSaveSize +#else +STDMETHODIMP RegMeta::Save( + LPCWSTR szFile, + DWORD dwSaveFlags) +{ + return E_NOTIMPL; +} + +STDMETHODIMP RegMeta::SaveToStream( + IStream *pIStream, + DWORD dwSaveFlags) +{ + return E_NOTIMPL; +} + +STDMETHODIMP RegMeta::SaveToMemory( + void *pbData, + ULONG cbData) +{ + return E_NOTIMPL; +} + +STDMETHODIMP RegMeta::GetSaveSize( + CorSaveSize fSave, + DWORD *pdwSaveSize) +{ + return E_NOTIMPL; +} +#endif #ifdef FEATURE_METADATA_EMIT_ALL @@ -626,6 +656,7 @@ STDMETHODIMP RegMeta::SetHandler( // S_OK. //******************************************************************************* // Perform optimizations of the metadata prior to saving. //******************************************************************************* +#ifdef FEATURE_METADATA_PERSISTENCE HRESULT RegMeta::PreSave() // Return code. { HRESULT hr = S_OK; // A result. @@ -704,6 +735,7 @@ HRESULT RegMeta::PreSave() // Return code. return hr; } // RegMeta::PreSave +#endif //******************************************************************************* // Perform optimizations of ref to def @@ -873,8 +905,7 @@ HRESULT RegMeta::_DefineTypeRef( mdToken tkResolutionScope, // [IN] ModuleRef or AssemblyRef. const void *szName, // [IN] Name of the TypeRef. BOOL isUnicode, // [IN] Specifies whether the URL is unicode. - mdTypeRef *ptk, // [OUT] Put mdTypeRef here. - eCheckDups eCheck) // [IN] Specifies whether to check for duplicates. + mdTypeRef *ptk) // [OUT] Put mdTypeRef here. { HRESULT hr = S_OK; LPUTF8 szUTF8FullQualName; @@ -914,7 +945,7 @@ HRESULT RegMeta::_DefineTypeRef( _ASSERTE(bSuccess); // Search for existing TypeRef record. - if (eCheck==eCheckYes || (eCheck==eCheckDefault && CheckDups(MDDupTypeRef))) + if (CheckDups(MDDupTypeRef)) { hr = ImportHelper::FindTypeRefByName(&(m_pStgdb->m_MiniMd), tkResolutionScope, (LPCUTF8)qbNamespace.Ptr(), @@ -1904,4 +1935,3 @@ HRESULT RegMeta::_DefineTypeDef( // S_OK or error. } // RegMeta::_DefineTypeDef #endif //FEATURE_METADATA_EMIT - diff --git a/src/coreclr/md/compiler/regmeta_imetadatatables.cpp b/src/coreclr/md/compiler/regmeta_imetadatatables.cpp index 10bbabe473fdb8..d8c4fd737481ac 100644 --- a/src/coreclr/md/compiler/regmeta_imetadatatables.cpp +++ b/src/coreclr/md/compiler/regmeta_imetadatatables.cpp @@ -38,6 +38,8 @@ #include "stdafx.h" #include "regmeta.h" +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES + // -------------------------------------------------------------------------------------- // // Fills size (*pcbStringsHeapSize) of internal strings heap (#String). @@ -646,3 +648,5 @@ RegMeta::GetMetaDataStreamInfo( return m_pStgdb->GetRawStreamInfo(ix, ppchName, ppv, pcb); } // RegMeta::GetMetaDataStreamInfo + +#endif // FEATURE_METADATA_PUBLIC_INTERFACES diff --git a/src/coreclr/md/enc/CMakeLists.txt b/src/coreclr/md/enc/CMakeLists.txt index 86a1a1b3fbe1df..1516051c54799b 100644 --- a/src/coreclr/md/enc/CMakeLists.txt +++ b/src/coreclr/md/enc/CMakeLists.txt @@ -54,7 +54,7 @@ target_compile_definitions(mdruntimerw_dac PRIVATE FEATURE_METADATA_PUBLIC_INTER target_precompile_headers(mdruntimerw_dac PRIVATE stdafx.h) add_library_clr(mdruntimerw_wks OBJECT ${MDRUNTIMERW_SOURCES}) -target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() @@ -66,5 +66,5 @@ target_compile_definitions(mdruntimerw-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTER target_precompile_headers(mdruntimerw-dbi PRIVATE stdafx.h) add_library_clr(mdruntimerw_ppdb ${MDRUNTIMERW_SOURCES}) -target_compile_definitions(mdruntimerw_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) +target_compile_definitions(mdruntimerw_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PERSISTENCE FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdruntimerw_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/enc/liteweightstgdbrw.cpp b/src/coreclr/md/enc/liteweightstgdbrw.cpp index 4094e84aed5d17..99013e19b70a26 100644 --- a/src/coreclr/md/enc/liteweightstgdbrw.cpp +++ b/src/coreclr/md/enc/liteweightstgdbrw.cpp @@ -436,6 +436,7 @@ HRESULT CLiteWeightStgdbRW::InitNew() //***************************************************************************** // Determine what the size of the saved data will be. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn HRESULT CLiteWeightStgdbRW::GetSaveSize(// S_OK or error. CorSaveSize fSave, // Quick or accurate? @@ -911,6 +912,7 @@ HRESULT CLiteWeightStgdbRW::Save( delete pStorage; return hr; } // CLiteWeightStgdbRW::Save +#endif //***************************************************************************** // Pull the PEKind and Machine out of PE headers -- if we have PE headers. diff --git a/src/coreclr/md/enc/mdinternalrw.cpp b/src/coreclr/md/enc/mdinternalrw.cpp index 9bc8e672d75de1..b7b8c92f8c0525 100644 --- a/src/coreclr/md/enc/mdinternalrw.cpp +++ b/src/coreclr/md/enc/mdinternalrw.cpp @@ -72,7 +72,6 @@ HRESULT TranslateSigHelper( // S_OK or error. cbHashValue, // Size in bytes. pCommon, // The scope where signature is from. pbSigBlob, // signature from the imported scope - NULL, // Internal OID mapping structure. pqkSigEmit, // [OUT] translated signature 0, // start from first byte of the signature NULL, // don't care how many bytes consumed @@ -1978,6 +1977,9 @@ HRESULT MDInternalRW::FindTypeRefByName( // S_OK or error. mdToken tkResolutionScope, // [IN] Resolution Scope fo the TypeRef. mdTypeRef *ptk) // [OUT] TypeRef token returned. { +#ifdef FEATURE_METADATA_CORECLR + return E_NOTIMPL; +#else HRESULT hr = NOERROR; ULONG cTypeRefRecs; TypeRefRec *pTypeRefRec; @@ -2027,6 +2029,7 @@ HRESULT MDInternalRW::FindTypeRefByName( // S_OK or error. hr = CLDB_E_RECORD_NOTFOUND; ErrExit: return hr; +#endif } // MDInternalRW::FindTypeRefByName //***************************************************************************** diff --git a/src/coreclr/md/enc/metamodelrw.cpp b/src/coreclr/md/enc/metamodelrw.cpp index efd7aec6ba059d..f2d567b42d83fa 100644 --- a/src/coreclr/md/enc/metamodelrw.cpp +++ b/src/coreclr/md/enc/metamodelrw.cpp @@ -1233,16 +1233,17 @@ CMiniMdRW::MapToken( // Return value from user callback. mdToken tkn) // Token type. { HRESULT hr = S_OK; - TOKENREC *pTokenRec; - MDTOKENMAP *pMovementMap; // If not change, done. if (from == to) return S_OK; +#ifdef FEATURE_METADATA_PERSISTENCE + MDTOKENMAP *pMovementMap; pMovementMap = GetTokenMovementMap(); _ASSERTE(GetTokenMovementMap() != NULL); if (pMovementMap != NULL) - IfFailRet(pMovementMap->AppendRecord( TokenFromRid(from, tkn), false, TokenFromRid(to, tkn), &pTokenRec )); + IfFailRet(pMovementMap->AppendRecord(TokenFromRid(from, tkn), TokenFromRid(to, tkn))); +#endif // Notify client. if (m_pHandler != NULL) @@ -1792,6 +1793,7 @@ CMiniMdRW::InitNew() return hr; } // CMiniMdRW::InitNew +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Determine how big the tables would be when saved. //***************************************************************************** @@ -2133,6 +2135,8 @@ int CMiniMdRW::IsPoolEmpty( // True or false. return true; } // CMiniMdRW::IsPoolEmpty +#endif + // -------------------------------------------------------------------------------------- // // Gets user string (*Data) at index (nIndex) and fills the index (*pnNextIndex) of the next user string @@ -2225,6 +2229,7 @@ bool CMiniMdRW::CanHaveCustomAttribute( // Can a given table have a custom attri } // CMiniMdRW::CanHaveCustomAttribute #endif //_DEBUG +#ifdef FEATURE_METADATA_PERSISTENCE //--------------------------------------------------------------------------------------- // // Perform any available pre-save optimizations. @@ -3344,6 +3349,8 @@ CMiniMdRW::SavePoolToStream( return hr; } // CMiniMdRW::SavePoolToStream +#endif + //***************************************************************************** // Expand a table from the initial (hopeful) 2-byte column sizes to the large // (but always adequate) 4-byte column sizes. @@ -3562,6 +3569,7 @@ CMiniMdRW::ExpandTableColumns( } // CMiniMdRW::ExpandTableColumns +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Used by caller to let us know save is completed. //***************************************************************************** @@ -3632,6 +3640,7 @@ CMiniMdRW::FixUpRefToDef() { return NOERROR; } // CMiniMdRW::FixUpRefToDef +#endif //***************************************************************************** // Given a table with a pointer (index) to a sequence of rows in another @@ -6271,57 +6280,6 @@ CMiniMdRW::AddNamedItemToHash( return hr; } // CMiniMdRW::AddNamedItemToHash -//***************************************************************************** -// If the hash is built, search for the item. -//***************************************************************************** -CMiniMdRW::HashSearchResult -CMiniMdRW::FindNamedItemFromHash( - ULONG ixTbl, // Table with the item. - LPCUTF8 szName, // Name of item. - mdToken tkParent, // Token of parent, if any. - mdToken * ptk) // Return if found. -{ - // If the table is there, look for the item in the chain of items. - if (m_pNamedItemHash != NULL) - { - TOKENHASHENTRY *p; // Hash entry from chain. - ULONG iHash; // Item's hash value. - int pos; // Position in hash chain. - mdToken type; // Type of the item being sought. - - type = g_TblIndex[ixTbl].m_Token; - - // Hash the data. - iHash = HashNamedItem(tkParent, szName); - - // Go through every entry in the hash chain looking for ours. - for (p = m_pNamedItemHash->FindFirst(iHash, pos); - p != NULL; - p = m_pNamedItemHash->FindNext(pos)) - { // Check that the item is from the right table. - if (TypeFromToken(p->tok) != (ULONG)type) - { - //@FUTURE: if using the named item hash for multiple tables, remove - // this check. Until then, debugging aid. - _ASSERTE(!"Table mismatch in hash chain"); - continue; - } - // Item is in the right table, do the deeper check. - if (CompareNamedItems(ixTbl, p->tok, szName, tkParent) == S_OK) - { - *ptk = p->tok; - return Found; - } - } - - return NotFound; - } - else - { - return NoTable; - } -} // CMiniMdRW::FindNamedItemFromHash - //***************************************************************************** // Check a given mr token to see if this one is a match. //***************************************************************************** diff --git a/src/coreclr/md/enc/rwutil.cpp b/src/coreclr/md/enc/rwutil.cpp index 20bdb830c91fbb..8c301925dc6aad 100644 --- a/src/coreclr/md/enc/rwutil.cpp +++ b/src/coreclr/md/enc/rwutil.cpp @@ -561,97 +561,13 @@ HRESULT HENUMInternal::AddElementToEnum( -//***************************************************************************** -// find a token in the tokenmap. -//***************************************************************************** -MDTOKENMAP::~MDTOKENMAP() -{ - if (m_pMap) - m_pMap->Release(); -} // MDTOKENMAP::~MDTOKENMAP() - -HRESULT MDTOKENMAP::Init( - IUnknown *pImport) // The import that this map is for. -{ - HRESULT hr; // A result. - IMetaDataTables *pITables=0; // Table information. - ULONG cRows; // Count of rows in a table. - ULONG cTotal; // Running total of rows in db. - TOKENREC *pRec; // A TOKENREC record. - mdToken tkTable; // Token kind for a table. - - hr = pImport->QueryInterface(IID_IMetaDataTables, (void**)&pITables); - if (hr == S_OK) - { - // Determine the size of each table. - cTotal = 0; - for (ULONG ixTbl=0; ixTblGetTableInfo(ixTbl, 0, &cRows, 0,0,0)); - // Safe: cTotal += cRows - if (!ClrSafeInt::addition(cTotal, cRows, cTotal)) - { - IfFailGo(COR_E_OVERFLOW); - } - } - } - m_TableOffset[TBL_COUNT] = cTotal; - m_iCountIndexed = cTotal; - // Attempt to allocate space for all of the possible remaps. - if (!AllocateBlock(cTotal)) - IfFailGo(E_OUTOFMEMORY); - // Note that no sorts are needed. - m_sortKind = Indexed; - // Initialize entries to "not found". - for (ULONG i=0; iSetEmpty(); - } - } -#if defined(_DEBUG) - if (SUCCEEDED(pImport->QueryInterface(IID_IMetaDataImport, (void**)&m_pImport))) - { - // Ok, here's a pretty nasty workaround. We're going to make a big assumption here - // that we're owned by the pImport, and so we don't need to keep a refcount - // on the pImport object. - // - // If we did, we'd create a circular reference and neither this object nor - // the RegMeta would be freed. - m_pImport->Release(); - - } - - - -#endif - -ErrExit: - if (pITables) - pITables->Release(); - return hr; -} // HRESULT MDTOKENMAP::Init() - +#ifdef FEATURE_METADATA_PERSISTENCE HRESULT MDTOKENMAP::EmptyMap() { - int nCount = Count(); - for (int i=0; iSetEmpty(); - } - + Clear(); + m_iCountSorted = 0; return S_OK; -}// HRESULT MDTOKENMAP::Clear() +} //***************************************************************************** @@ -664,275 +580,29 @@ bool MDTOKENMAP::Find( int lo,mid,hi; // binary search indices. TOKENREC *pRec = NULL; - if (m_sortKind == Indexed && TypeFromToken(tkFind) != mdtString) - { - // Get the entry. - ULONG ixTbl = CMiniMdRW::GetTableForToken(tkFind); - if(ixTbl == (ULONG) -1) - return false; - ULONG iRid = RidFromToken(tkFind); - if((m_TableOffset[ixTbl] + iRid) > m_TableOffset[ixTbl+1]) - return false; - pRec = Get(m_TableOffset[ixTbl] + iRid - 1); - // See if it has been set. - if (pRec->IsEmpty()) - return false; - // Verify that it is what we think it is. - _ASSERTE(pRec->m_tkFrom == tkFind); - *ppRec = pRec; - return true; - } - else - { // Shouldn't be any unsorted records, and table must be sorted in proper ordering. - _ASSERTE( m_iCountTotal == m_iCountSorted && - (m_sortKind == SortByFromToken || m_sortKind == Indexed) ); - _ASSERTE( (m_iCountIndexed + m_iCountTotal) == (ULONG)Count() ); - - // Start with entire table. - lo = m_iCountIndexed; - hi = Count() - 1; - - // While there are rows in the range... - while (lo <= hi) - { // Look at the one in the middle. - mid = (lo + hi) / 2; - - pRec = Get(mid); - - // If equal to the target, done. - if (tkFind == pRec->m_tkFrom) - { - *ppRec = Get(mid); - return true; - } - - // If middle item is too small, search the top half. - if (pRec->m_tkFrom < tkFind) - lo = mid + 1; - else // but if middle is to big, search bottom half. - hi = mid - 1; - } - } - - // Didn't find anything that matched. - return false; -} // bool MDTOKENMAP::Find() - - - -//***************************************************************************** -// remap the token -//***************************************************************************** -HRESULT MDTOKENMAP::Remap( - mdToken tkFrom, - mdToken *ptkTo) -{ - HRESULT hr = NOERROR; - TOKENREC *pRec; - - // Remap nil to same thing (helps because System.Object has no base class.) - if (IsNilToken(tkFrom)) - { - *ptkTo = tkFrom; - return hr; - } - - if ( Find(tkFrom, &pRec) ) - { - *ptkTo = pRec->m_tkTo; - } - else - { - _ASSERTE( !" Bad lookup map!"); - hr = META_E_BADMETADATA; - } - return hr; -} // HRESULT MDTOKENMAP::Remap() - - - -//***************************************************************************** -// find a token in the tokenmap. -//***************************************************************************** -HRESULT MDTOKENMAP::InsertNotFound( - mdToken tkFind, - bool fDuplicate, - mdToken tkTo, - TOKENREC **ppRec) -{ - HRESULT hr = NOERROR; - int lo, mid, hi; // binary search indices. - TOKENREC *pRec; - - // If possible, validate the input. - _ASSERTE(!m_pImport || m_pImport->IsValidToken(tkFind)); + _ASSERTE(m_iCountSorted == (ULONG)Count()); - if (m_sortKind == Indexed && TypeFromToken(tkFind) != mdtString) - { - // Get the entry. - ULONG ixTbl = CMiniMdRW::GetTableForToken(tkFind); - _ASSERTE(ixTbl != (ULONG) -1); - ULONG iRid = RidFromToken(tkFind); - _ASSERTE((m_TableOffset[ixTbl] + iRid) <= m_TableOffset[ixTbl+1]); - pRec = Get(m_TableOffset[ixTbl] + iRid - 1); - // See if it has been set. - if (!pRec->IsEmpty()) - { // Verify that it is what we think it is. - _ASSERTE(pRec->m_tkFrom == tkFind); - } - // Store the data. - pRec->m_tkFrom = tkFind; - pRec->m_isDuplicate = fDuplicate; - pRec->m_tkTo = tkTo; - pRec->m_isFoundInImport = false; - // Return the result. - *ppRec = pRec; - } - else - { // Shouldn't be any unsorted records, and table must be sorted in proper ordering. - _ASSERTE( m_iCountTotal == m_iCountSorted && - (m_sortKind == SortByFromToken || m_sortKind == Indexed) ); - - if ((Count() - m_iCountIndexed) > 0) - { - // Start with entire table. - lo = m_iCountIndexed; - hi = Count() - 1; - - // While there are rows in the range... - while (lo < hi) - { // Look at the one in the middle. - mid = (lo + hi) / 2; - - pRec = Get(mid); - - // If equal to the target, done. - if (tkFind == pRec->m_tkFrom) - { - *ppRec = Get(mid); - goto ErrExit; - } - - // If middle item is too small, search the top half. - if (pRec->m_tkFrom < tkFind) - lo = mid + 1; - else // but if middle is to big, search bottom half. - hi = mid - 1; - } - _ASSERTE(hi <= lo); - pRec = Get(lo); - - if (tkFind == pRec->m_tkFrom) - { - if (tkTo == pRec->m_tkTo && fDuplicate == pRec->m_isDuplicate) - { - *ppRec = pRec; - } - else - { - _ASSERTE(!"inconsistent token has been added to the table!"); - IfFailGo( E_FAIL ); - } - } - - if (tkFind < pRec->m_tkFrom) - { - // insert before lo; - pRec = Insert(lo); - } - else - { - // insert after lo - pRec = Insert(lo + 1); - } - } - else - { - // table is empty - pRec = Insert(m_iCountIndexed); - } - - - // If pRec == NULL, return E_OUTOFMEMORY - IfNullGo(pRec); - - m_iCountTotal++; - m_iCountSorted++; - - *ppRec = pRec; - - // initialize the record - pRec->m_tkFrom = tkFind; - pRec->m_isDuplicate = fDuplicate; - pRec->m_tkTo = tkTo; - pRec->m_isFoundInImport = false; - } - -ErrExit: - return hr; -} // HRESULT MDTOKENMAP::InsertNotFound() - - -//***************************************************************************** -// find a "to" token in the tokenmap. Now that we are doing the ref to def optimization, -// we might have several from tokens map to the same to token. We need to return a range of index -// instead.... -//***************************************************************************** -bool MDTOKENMAP::FindWithToToken( - mdToken tkFind, // [IN] the token value to find - int *piPosition) // [OUT] return the first from-token that has the matching to-token -{ - int lo, mid, hi; // binary search indices. - TOKENREC *pRec; - TOKENREC *pRec2; - - // This makes sure that no insertions take place between calls to FindWithToToken. - // We want to avoid repeated sorting of the table. - _ASSERTE(m_sortKind != SortByToToken || m_iCountTotal == m_iCountSorted); - - // If the map is sorted with From tokens, change it to be sorted with To tokens. - if (m_sortKind != SortByToToken) - SortTokensByToToken(); - - // Start with entire table. lo = 0; hi = Count() - 1; - - // While there are rows in the range... while (lo <= hi) - { // Look at the one in the middle. + { mid = (lo + hi) / 2; - pRec = Get(mid); - // If equal to the target, done. - if (tkFind == pRec->m_tkTo) + if (tkFind == pRec->m_tkFrom) { - for (int i = mid-1; i >= 0; i--) - { - pRec2 = Get(i); - if (tkFind != pRec2->m_tkTo) - { - *piPosition = i + 1; - return true; - } - } - *piPosition = 0; + *ppRec = pRec; return true; } - // If middle item is too small, search the top half. - if (pRec->m_tkTo < tkFind) + if (pRec->m_tkFrom < tkFind) lo = mid + 1; - else // but if middle is to big, search bottom half. + else hi = mid - 1; } - // Didn't find anything that matched. - return false; -} // bool MDTOKENMAP::FindWithToToken() - - + return false; +} //***************************************************************************** // output a remapped token //***************************************************************************** @@ -941,36 +611,25 @@ mdToken MDTOKENMAP::SafeRemap( { TOKENREC *pRec; - // If possible, validate the input. - _ASSERTE(!m_pImport || m_pImport->IsValidToken(tkFrom)); - SortTokensByFromToken(); - if ( Find(tkFrom, &pRec) ) + if (Find(tkFrom, &pRec)) { return pRec->m_tkTo; } return tkFrom; -} // mdToken MDTOKENMAP::SafeRemap() - +} -//***************************************************************************** -// Sorting -//***************************************************************************** -void MDTOKENMAP::SortTokensByToToken() +void MDTOKENMAP::SortTokensByFromToken() { - // Only sort if there are unsorted records or the sort kind changed. - if (m_iCountSorted < m_iCountTotal || m_sortKind != SortByToToken) + ULONG count = Count(); + if (m_iCountSorted < count) { - // Sort the entire array. - m_iCountTotal = Count(); - m_iCountIndexed = 0; - SortRangeToToken(0, m_iCountTotal - 1); - m_iCountSorted = m_iCountTotal; - m_sortKind = SortByToToken; + SortRangeFromToken(0, count - 1); + m_iCountSorted = count; } -} // void MDTOKENMAP::SortTokensByToToken() +} void MDTOKENMAP::SortRangeFromToken( int iLeft, @@ -998,39 +657,7 @@ void MDTOKENMAP::SortRangeFromToken( // Sort the each partition. SortRangeFromToken(iLeft, iLast-1); SortRangeFromToken(iLast+1, iRight); -} // void MDTOKENMAP::SortRangeFromToken() - - -//***************************************************************************** -// Sorting -//***************************************************************************** -void MDTOKENMAP::SortRangeToToken( - int iLeft, - int iRight) -{ - int iLast; - int i; // loop variable. - - // if less than two elements you're done. - if (iLeft >= iRight) - return; - - // The mid-element is the pivot, move it to the left. - Swap(iLeft, (iLeft+iRight)/2); - iLast = iLeft; - - // move everything that is smaller than the pivot to the left. - for(i = iLeft+1; i <= iRight; i++) - if (CompareToToken(i, iLeft) < 0) - Swap(i, ++iLast); - - // Put the pivot to the point where it is in between smaller and larger elements. - Swap(iLeft, iLast); - - // Sort the each partition. - SortRangeToToken(iLeft, iLast-1); - SortRangeToToken(iLast+1, iRight); -} // void MDTOKENMAP::SortRangeToToken() +} //***************************************************************************** @@ -1038,177 +665,19 @@ void MDTOKENMAP::SortRangeToToken( //***************************************************************************** HRESULT MDTOKENMAP::AppendRecord( mdToken tkFind, - bool fDuplicate, - mdToken tkTo, - TOKENREC **ppRec) + mdToken tkTo) { - HRESULT hr = NOERROR; - TOKENREC *pRec; - - // If possible, validate the input. - _ASSERTE(!m_pImport || m_pImport->IsValidToken(tkFind)); - - // If the map is indexed, and this is a table token, update-in-place. - if (m_sortKind == Indexed && TypeFromToken(tkFind) != mdtString) - { - // Get the entry. - ULONG ixTbl = CMiniMdRW::GetTableForToken(tkFind); - _ASSERTE(ixTbl != (ULONG) -1); - ULONG iRid = RidFromToken(tkFind); - _ASSERTE((m_TableOffset[ixTbl] + iRid) <= m_TableOffset[ixTbl+1]); - pRec = Get(m_TableOffset[ixTbl] + iRid - 1); - // See if it has been set. - if (!pRec->IsEmpty()) - { // Verify that it is what we think it is. - _ASSERTE(pRec->m_tkFrom == tkFind); - } - } - else - { - pRec = Append(); - IfNullGo(pRec); - - // number of entries increased but not the sorted entry - m_iCountTotal++; - } + TOKENREC *pRec = Append(); + IfNullRet(pRec); - // Store the data. pRec->m_tkFrom = tkFind; - pRec->m_isDuplicate = fDuplicate; pRec->m_tkTo = tkTo; - pRec->m_isFoundInImport = false; - *ppRec = pRec; - -ErrExit: - return hr; -} // HRESULT MDTOKENMAP::AppendRecord() - - - -//********************************************************************************************************* -// -// CMapToken's constructor -// -//********************************************************************************************************* -CMapToken::CMapToken() -{ - m_cRef = 1; - m_pTKMap = NULL; - m_isSorted = true; -} // TokenManager::TokenManager() - - - -//********************************************************************************************************* -// -// CMapToken's destructor -// -//********************************************************************************************************* -CMapToken::~CMapToken() -{ - delete m_pTKMap; -} // CMapToken::~CMapToken() - - -ULONG CMapToken::AddRef() -{ - return InterlockedIncrement(&m_cRef); -} // CMapToken::AddRef() - - - -ULONG CMapToken::Release() -{ - ULONG cRef = InterlockedDecrement(&m_cRef); - if (!cRef) - delete this; - return (cRef); -} // CMapToken::Release() - - -HRESULT CMapToken::QueryInterface(REFIID riid, void **ppUnk) -{ - if (ppUnk == NULL) - return E_INVALIDARG; - - if (IsEqualIID(riid, IID_IMapToken)) - { - *ppUnk = (IMapToken *) this; - } - else if (IsEqualIID(riid, IID_IUnknown)) - { - *ppUnk = (IUnknown *) this; - } - else - { - *ppUnk = NULL; - return (E_NOINTERFACE); - } - - AddRef(); - return (S_OK); -} // CMapToken::QueryInterface - - - -//********************************************************************************************************* -// -// Track the token mapping -// -//********************************************************************************************************* -HRESULT CMapToken::Map( - mdToken tkFrom, - mdToken tkTo) -{ - HRESULT hr = NOERROR; - TOKENREC *pTkRec; - - if (m_pTKMap == NULL) - m_pTKMap = new (nothrow) MDTOKENMAP; - - IfNullGo( m_pTKMap ); - - IfFailGo( m_pTKMap->AppendRecord(tkFrom, false, tkTo, &pTkRec) ); - _ASSERTE( pTkRec ); - - m_isSorted = false; -ErrExit: - return hr; + return S_OK; } -//********************************************************************************************************* -// -// return what tkFrom is mapped to ptkTo. If there is no remap -// (ie the token from is filtered out by the filter mechanism, it will return false. -// -//********************************************************************************************************* -bool CMapToken::Find( - mdToken tkFrom, - TOKENREC **pRecTo) -{ - TOKENREC *pRec; - bool bRet; - if ( m_isSorted == false ) - { - // sort the map - m_pTKMap->SortTokensByFromToken(); - m_isSorted = true; - } - - bRet = m_pTKMap->Find(tkFrom, &pRec) ; - if (bRet) - { - _ASSERTE(pRecTo); - *pRecTo = pRec; - } - else - { - pRec = NULL; - } - return bRet; -} +#endif //********************************************************************************************************* // diff --git a/src/coreclr/md/enc/stgtiggerstorage.cpp b/src/coreclr/md/enc/stgtiggerstorage.cpp index 3b1b55b4c7bbd9..422bb302c3a183 100644 --- a/src/coreclr/md/enc/stgtiggerstorage.cpp +++ b/src/coreclr/md/enc/stgtiggerstorage.cpp @@ -81,7 +81,11 @@ TiggerStorage::Init( // For write case, dump the signature into the file up front. else { +#ifdef FEATURE_METADATA_PERSISTENCE IfFailGo(WriteSignature(pVersion)); +#else + IfFailGo(E_NOTIMPL); +#endif } ErrExit: @@ -440,9 +444,13 @@ HRESULT STDMETHODCALLTYPE TiggerStorage::CreateStream( DWORD reserved2, IStream **ppstm) { +#ifdef FEATURE_METADATA_PERSISTENCE char rcStream[MAXSTREAMNAME];// For converted name. VERIFY(WideCharToMultiByte(CP_ACP, 0, pwcsName, -1, rcStream, sizeof(rcStream), 0, 0)); return (CreateStream(rcStream, grfMode, reserved1, reserved2, ppstm)); +#else + return E_NOTIMPL; +#endif } @@ -454,6 +462,7 @@ HRESULT STDMETHODCALLTYPE TiggerStorage::CreateStream( DWORD reserved2, IStream **ppstm) { +#ifdef FEATURE_METADATA_PERSISTENCE PSTORAGESTREAM pStream; // For lookup. HRESULT hr; @@ -487,6 +496,9 @@ HRESULT STDMETHODCALLTYPE TiggerStorage::CreateStream( return (hr); } return (S_OK); +#else + return E_NOTIMPL; +#endif } #endif //!DACCESS_COMPILE diff --git a/src/coreclr/md/enc/stgtiggerstream.cpp b/src/coreclr/md/enc/stgtiggerstream.cpp index 3e5eba9b82f5eb..aea89751ce331f 100644 --- a/src/coreclr/md/enc/stgtiggerstream.cpp +++ b/src/coreclr/md/enc/stgtiggerstream.cpp @@ -35,7 +35,11 @@ HRESULT STDMETHODCALLTYPE TiggerStream::Write( ULONG cb, ULONG *pcbWritten) { +#ifdef FEATURE_METADATA_PERSISTENCE return (m_pStorage->Write(m_rcStream, pv, cb, pcbWritten)); +#else + return E_NOTIMPL; +#endif } diff --git a/src/coreclr/md/heaps/blobheap.h b/src/coreclr/md/heaps/blobheap.h index a3a643e3485d45..1a914e3d32cff7 100644 --- a/src/coreclr/md/heaps/blobheap.h +++ b/src/coreclr/md/heaps/blobheap.h @@ -206,7 +206,17 @@ class BlobHeapRW inline HRESULT GetAlignedSize( _Out_ UINT32 *pcbSize) const { - return m_BlobPool.GetSaveSize(pcbSize); + S_UINT32 size = S_UINT32(m_BlobPool.GetRawSize()); + size.AlignUp(4); + if (size.IsOverflow()) + { + *pcbSize = 0; + Debug_ReportInternalError("Aligned size of blob heap overflows - we should prevent creating such heaps."); + return CLDB_E_INTERNALERROR; + } + + *pcbSize = size.Value(); + return S_OK; } // Returns TRUE if the blob heap is empty (even if it contains only default empty blob). inline BOOL IsEmpty() const @@ -221,6 +231,7 @@ class BlobHeapRW return const_cast(m_BlobPool).IsValidCookie(nIndex); } +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn HRESULT SaveToStream_Aligned( UINT32 nStartIndex, @@ -240,6 +251,7 @@ class BlobHeapRW _ASSERTE(nStartIndex == m_BlobPool.GetOffsetOfEdit()); return const_cast(m_BlobPool).PersistPartialToStream(pStream, nStartIndex); } +#endif public: // @@ -296,6 +308,7 @@ class BlobHeapRW m_BlobPool.ResetOffsetOfEdit(); } // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn inline HRESULT GetEnCSessionAddedHeapSize_Aligned( _Out_ UINT32 *pcbSize) const @@ -308,6 +321,7 @@ class BlobHeapRW *pcbSize = 0; return S_OK; } +#endif }; // class BlobHeapRW diff --git a/src/coreclr/md/heaps/guidheap.h b/src/coreclr/md/heaps/guidheap.h index e6852d7c3f5769..e3eda4274a07fa 100644 --- a/src/coreclr/md/heaps/guidheap.h +++ b/src/coreclr/md/heaps/guidheap.h @@ -203,12 +203,14 @@ class GuidHeapRW return const_cast(m_GuidPool).IsValidCookie(nIndex); } +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn inline HRESULT SaveToStream( _In_ IStream *pStream) const { return const_cast(m_GuidPool).PersistToStream(pStream); } +#endif public: // diff --git a/src/coreclr/md/heaps/stringheap.h b/src/coreclr/md/heaps/stringheap.h index 403e66ec468929..cc86afabd9cee3 100644 --- a/src/coreclr/md/heaps/stringheap.h +++ b/src/coreclr/md/heaps/stringheap.h @@ -174,7 +174,17 @@ class StringHeapRW inline HRESULT GetAlignedSize( _Out_ UINT32 *pcbSize) const { - return m_StringPool.GetSaveSize(pcbSize); + S_UINT32 size = S_UINT32(m_StringPool.GetRawSize()); + size.AlignUp(4); + if (size.IsOverflow()) + { + *pcbSize = 0; + Debug_ReportInternalError("Aligned size of string heap overflows - we should prevent creating such heaps."); + return CLDB_E_INTERNALERROR; + } + + *pcbSize = size.Value(); + return S_OK; } // Returns TRUE if the string heap is empty (even if it contains only default empty string). inline BOOL IsEmpty() const @@ -189,6 +199,7 @@ class StringHeapRW return const_cast(m_StringPool).IsValidCookie(nIndex); } +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn inline HRESULT SaveToStream_Aligned( UINT32 nStartIndex, @@ -208,6 +219,7 @@ class StringHeapRW _ASSERTE(nStartIndex == m_StringPool.GetOffsetOfEdit()); return const_cast(m_StringPool).PersistPartialToStream(pStream, nStartIndex); } +#endif public: // @@ -279,6 +291,7 @@ class StringHeapRW m_StringPool.ResetOffsetOfEdit(); } // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn inline HRESULT GetEnCSessionAddedHeapSize_Aligned( _Out_ UINT32 *pcbSize) const @@ -291,6 +304,7 @@ class StringHeapRW *pcbSize = 0; return S_OK; } +#endif }; // class StringHeapRW diff --git a/src/coreclr/md/inc/metamodelrw.h b/src/coreclr/md/inc/metamodelrw.h index 34e2627ec1861f..52463024450a28 100644 --- a/src/coreclr/md/inc/metamodelrw.h +++ b/src/coreclr/md/inc/metamodelrw.h @@ -197,7 +197,9 @@ class ReorderData typedef CMetaDataHashBase CMemberRefHash; typedef CMetaDataHashBase CLookUpHash; +#ifdef FEATURE_METADATA_PERSISTENCE class MDTOKENMAP; +#endif class MDInternalRW; template class CLiteWeightStgdb; @@ -771,12 +773,6 @@ class CMiniMdRW : public CMiniMdTemplate LPCUTF8 szName, // Name of item. mdToken tkParent); // Token of parent, if any. - HashSearchResult FindNamedItemFromHash( - ULONG ixTbl, // Table with the item. - LPCUTF8 szName, // Name of item. - mdToken tkParent, // Token of parent, if any. - mdToken * ptk); // Return if found. - __checkReturn HRESULT CompareNamedItems( // S_OK match, S_FALSE no match. ULONG ixTbl, // Table with the item. @@ -1268,8 +1264,10 @@ class CMiniMdRW : public CMiniMdTemplate FORCEINLINE TOKENMAP *GetMemberRefToMemberDefMap() { return m_pTokenRemapManager ? m_pTokenRemapManager->GetMemberRefToMemberDefMap() : NULL; }; +#ifdef FEATURE_METADATA_PERSISTENCE FORCEINLINE MDTOKENMAP *GetTokenMovementMap() { return m_pTokenRemapManager ? m_pTokenRemapManager->GetTokenMovementMap() : NULL; }; +#endif FORCEINLINE TokenRemapManager *GetTokenRemapManager() { return m_pTokenRemapManager; }; diff --git a/src/coreclr/md/inc/rwutil.h b/src/coreclr/md/inc/rwutil.h index 27c956b9e1a13f..67886719de1c6e 100644 --- a/src/coreclr/md/inc/rwutil.h +++ b/src/coreclr/md/inc/rwutil.h @@ -46,171 +46,58 @@ Unicode2UTF( LPUTF8 szDst, // Buffer for the output UTF8 string. int cbDst); // Size of the buffer for UTF8 string. -//********************************************************************* -// The token remap record. -//********************************************************************* +#ifdef FEATURE_METADATA_PERSISTENCE struct TOKENREC { - mdToken m_tkFrom; // The imported token - bool m_isDuplicate; // Is record duplicate? This information is recorded during merge - bool m_isDeleted; // This information is recorded during RegMeta::ProcessFilter when we might have deleted a record - bool m_isFoundInImport; // This information is also recorded during RegMeta::ProcessFilter - mdToken m_tkTo; // The new token in the merged scope - - void SetEmpty() {m_tkFrom = m_tkTo = (mdToken) -1;} - BOOL IsEmpty() {return m_tkFrom == (mdToken) -1;} + mdToken m_tkFrom; + mdToken m_tkTo; }; - -//********************************************************************* -// -// This structure keeps track on token remap for an imported scope. This map is initially sorted by from -// tokens. It can then become sorted by To tokens. This usually happen during PreSave remap lookup. Thus -// we assert if we try to look up or sort by From token. -// -//********************************************************************* class MDTOKENMAP : public CDynArray { public: - - enum SortKind{ - Unsorted = 0, - SortByFromToken = 1, - SortByToToken = 2, - Indexed = 3, // Indexed by table/rid. Implies that strings are sorted by "From". - }; - MDTOKENMAP() - : m_pNextMap(NULL), - m_pMap(NULL), - m_iCountTotal(0), - m_iCountSorted(0), - m_sortKind(SortByFromToken), - m_iCountIndexed(0) -#if defined(_DEBUG) - ,m_pImport(0) -#endif - { } - ~MDTOKENMAP(); - - HRESULT Init(IUnknown *pImport); - - // find a token in the tokenmap. - bool Find(mdToken tkFrom, TOKENREC **ppRec); - - // remap a token. We assert if we don't find the tkFind in the table - HRESULT Remap(mdToken tkFrom, mdToken *ptkTo); - - // Insert a record. This function will keep the inserted record in a sorted sequence - HRESULT InsertNotFound(mdToken tkFrom, bool fDuplicate, mdToken tkTo, TOKENREC **ppRec); - - // This function will just append the record to the end of the list - HRESULT AppendRecord( - mdToken tkFrom, - bool fDuplicate, - mdToken tkTo, - TOKENREC **ppRec); - - // This is a safe remap. *tpkTo will be tkFind if we cannot find tkFind in the lookup table. - mdToken SafeRemap(mdToken tkFrom); // [IN] the token value to find - - bool FindWithToToken( - mdToken tkFind, // [IN] the token value to find - int *piPosition); // [OUT] return the first from-token that has the matching to-token - - FORCEINLINE void SortTokensByFromToken() + : m_iCountSorted(0) { - _ASSERTE(m_sortKind == SortByFromToken || m_sortKind == Indexed); - // Only sort if there are unsorted records. - if (m_iCountSorted < m_iCountTotal) - { - SortRangeFromToken(m_iCountIndexed, m_iCountIndexed+m_iCountTotal - 1); - m_iCountSorted = m_iCountTotal; - } - } // void MDTOKENMAP::SortTokensByFromToken() + } + HRESULT AppendRecord(mdToken tkFrom, mdToken tkTo); + mdToken SafeRemap(mdToken tkFrom); HRESULT EmptyMap(); - void SortTokensByToToken(); - - MDTOKENMAP *m_pNextMap; - IMapToken *m_pMap; - private: - FORCEINLINE int CompareFromToken( // -1, 0, or 1 - int iLeft, // First item to compare. - int iRight) // Second item to compare. - { - if ( Get(iLeft)->m_tkFrom < Get(iRight)->m_tkFrom ) - return -1; - if ( Get(iLeft)->m_tkFrom == Get(iRight)->m_tkFrom ) - return 0; - return 1; - } + bool Find(mdToken tkFrom, TOKENREC **ppRec); - FORCEINLINE int CompareToToken( // -1, 0, or 1 - int iLeft, // First item to compare. - int iRight) // Second item to compare. + int CompareFromToken( + int iLeft, + int iRight) { - if ( Get(iLeft)->m_tkTo < Get(iRight)->m_tkTo ) + if (Get(iLeft)->m_tkFrom < Get(iRight)->m_tkFrom) return -1; - if ( Get(iLeft)->m_tkTo == Get(iRight)->m_tkTo ) + if (Get(iLeft)->m_tkFrom == Get(iRight)->m_tkFrom) return 0; return 1; } - FORCEINLINE void Swap( - int iFirst, + void Swap( + int iFirst, int iSecond) { - if ( iFirst == iSecond ) return; - memcpy( &m_buf, Get(iFirst), sizeof(TOKENREC) ); - memcpy( Get(iFirst), Get(iSecond),sizeof(TOKENREC) ); - memcpy( Get(iSecond), &m_buf, sizeof(TOKENREC) ); + if (iFirst == iSecond) + return; + + memcpy(&m_buf, Get(iFirst), sizeof(TOKENREC)); + memcpy(Get(iFirst), Get(iSecond), sizeof(TOKENREC)); + memcpy(Get(iSecond), &m_buf, sizeof(TOKENREC)); } void SortRangeFromToken(int iLeft, int iRight); - void SortRangeToToken(int iLeft, int iRight); - - TOKENREC m_buf; - ULONG m_iCountTotal; // total entry in the map - ULONG m_iCountSorted; // number of entries that are sorted - - SortKind m_sortKind; - - ULONG m_TableOffset[TBL_COUNT+1]; // Start of each table in map. - ULONG m_iCountIndexed; // number of entries that are indexed. -#if defined(_DEBUG) - IMetaDataImport *m_pImport; // For data validation. -#endif -}; - - - -//********************************************************************* -// -// This CMapToken class implemented the IMapToken. It is used in RegMeta for -// filter process. This class can track all of the tokens are mapped. It also -// supplies a Find function. -// -//********************************************************************* -class CMapToken : public IMapToken -{ - friend class RegMeta; + void SortTokensByFromToken(); -public: - STDMETHODIMP QueryInterface(REFIID riid, PVOID *pp); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - STDMETHODIMP Map(mdToken tkImp, mdToken tkEmit); - bool Find(mdToken tkFrom, TOKENREC **pRecTo); - CMapToken(); - virtual ~CMapToken(); - MDTOKENMAP *m_pTKMap; -private: - LONG m_cRef; - bool m_isSorted; + TOKENREC m_buf; + ULONG m_iCountSorted; }; +#endif typedef CDynArray TOKENMAP; @@ -255,35 +142,22 @@ class TokenRemapManager m_MemberRefToMemberDefMap[RidFromToken(tkFrom)] = tkTo; } // RecordMemberRefToMemberDefOptimization - //********************************************************************* - // - // This function is called when the token kind does not change but token - // is moved. For example, when we sort CustomAttribute table or when we optimize - // away MethodPtr table. These operation will not change the token type. - // - //********************************************************************* - FORCEINLINE HRESULT RecordTokenMovement( - mdToken tkFrom, - mdToken tkTo) - { - TOKENREC *pTokenRec; - - _ASSERTE( TypeFromToken(tkFrom) == TypeFromToken(tkTo) ); - return m_TKMap.AppendRecord( tkFrom, false, tkTo, &pTokenRec ); - } // RecordTokenMovement - bool ResolveRefToDef( mdToken tkRef, // [IN] ref token mdToken *ptkDef); // [OUT] def token that it resolves to. If it does not resolve to a def FORCEINLINE TOKENMAP *GetTypeRefToTypeDefMap() { return &m_TypeRefToTypeDefMap; } FORCEINLINE TOKENMAP *GetMemberRefToMemberDefMap() { return &m_MemberRefToMemberDefMap; } +#ifdef FEATURE_METADATA_PERSISTENCE FORCEINLINE MDTOKENMAP *GetTokenMovementMap() { return &m_TKMap; } +#endif ~TokenRemapManager(); HRESULT ClearAndEnsureCapacity(ULONG cTypeRef, ULONG cMemberRef); private: +#ifdef FEATURE_METADATA_PERSISTENCE MDTOKENMAP m_TKMap; +#endif TOKENMAP m_TypeRefToTypeDefMap; TOKENMAP m_MemberRefToMemberDefMap; }; // class TokenRemapManager diff --git a/src/coreclr/md/inc/stgpool.h b/src/coreclr/md/inc/stgpool.h index 544d1e209a9a71..484f80ad337b0c 100644 --- a/src/coreclr/md/inc/stgpool.h +++ b/src/coreclr/md/inc/stgpool.h @@ -512,6 +512,7 @@ friend struct ::cdac_data; // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -601,6 +602,7 @@ friend struct ::cdac_data; LIMITED_METHOD_CONTRACT; return 0; } +#endif //***************************************************************************** // Return the size of the pool. @@ -858,6 +860,7 @@ class StgStringPool : public StgPool // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -890,6 +893,7 @@ class StgStringPool : public StgPool LIMITED_METHOD_CONTRACT; return ULONG( strlen( reinterpret_cast< LPCSTR >( data ) ) + 1 ); // using strlen since the string is UTF8 } +#endif private: __checkReturn @@ -975,11 +979,13 @@ class StgGuidPool : public StgPool // Get the size of the GUID obtained from the pool. // Needed for generic persisting of data blocks. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE virtual ULONG GetSizeOfData( void const * data ) { LIMITED_METHOD_CONTRACT; return sizeof( GUID ); } +#endif //***************************************************************************** // How many objects are there in the pool? If the count is 0, you don't need @@ -1020,6 +1026,7 @@ class StgGuidPool : public StgPool // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -1035,6 +1042,7 @@ class StgGuidPool : public StgPool _ASSERTE(*pcbSaveSize == ALIGN4BYTE(*pcbSaveSize)); return S_OK; } +#endif private: @@ -1133,6 +1141,7 @@ class StgBlobPool : public StgPool // Get the size of the blob obtained from the pool. // Needed for generic persisting of data blocks. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE virtual ULONG GetSizeOfData( void const * data ) { WRAPPER_NO_CONTRACT; @@ -1141,6 +1150,7 @@ class StgBlobPool : public StgPool ULONG blobsize = CPackedLen::GetLength( data, & blobdata ); // the size is encoded at the beginning of the block return blobsize + static_cast< ULONG >( reinterpret_cast< BYTE const * >( blobdata ) - reinterpret_cast< BYTE const * >( data ) ); } +#endif //***************************************************************************** // How many objects are there in the pool? If the count is 0, you don't need @@ -1165,6 +1175,7 @@ class StgBlobPool : public StgPool // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -1173,6 +1184,7 @@ class StgBlobPool : public StgPool return StgPool::GetSaveSize(pcbSaveSize); } +#endif protected: diff --git a/src/coreclr/md/runtime/CMakeLists.txt b/src/coreclr/md/runtime/CMakeLists.txt index 84fe039e97d485..1c9f12aff6290e 100644 --- a/src/coreclr/md/runtime/CMakeLists.txt +++ b/src/coreclr/md/runtime/CMakeLists.txt @@ -55,7 +55,7 @@ target_compile_definitions(mdruntime_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERFA target_precompile_headers(mdruntime_dac PRIVATE stdafx.h) add_library_clr(mdruntime_wks OBJECT ${MDRUNTIME_SOURCES}) -target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() @@ -67,5 +67,5 @@ target_compile_definitions(mdruntime-dbi PRIVATE FEATURE_METADATA_PUBLIC_INTERFA target_precompile_headers(mdruntime-dbi PRIVATE stdafx.h) add_library_clr(mdruntime_ppdb ${MDRUNTIME_SOURCES}) -target_compile_definitions(mdruntime_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) +target_compile_definitions(mdruntime_ppdb PRIVATE FEATURE_METADATA_EMIT_ALL FEATURE_METADATA_EMIT_PORTABLE_PDB FEATURE_METADATA_PERSISTENCE FEATURE_METADATA_PUBLIC_INTERFACES SELF_NO_HOST) target_precompile_headers(mdruntime_ppdb PRIVATE stdafx.h) diff --git a/src/coreclr/md/runtime/mdinternalro.cpp b/src/coreclr/md/runtime/mdinternalro.cpp index 57e85ff5316431..b77fb910139d50 100644 --- a/src/coreclr/md/runtime/mdinternalro.cpp +++ b/src/coreclr/md/runtime/mdinternalro.cpp @@ -1098,6 +1098,9 @@ HRESULT MDInternalRO::FindTypeRefByName( // S_OK or error. mdToken tkResolutionScope, // [IN] Resolution Scope fo the TypeRef. mdTypeRef *ptk) // [OUT] TypeRef token returned. { +#ifdef FEATURE_METADATA_CORECLR + return E_NOTIMPL; +#else HRESULT hr = NOERROR; _ASSERTE(ptk); @@ -1147,6 +1150,7 @@ HRESULT MDInternalRO::FindTypeRefByName( // S_OK or error. hr = CLDB_E_RECORD_NOTFOUND; ErrExit: return hr; +#endif } //***************************************************************************** diff --git a/src/coreclr/md/runtime/stgpool.cpp b/src/coreclr/md/runtime/stgpool.cpp index 06fa355b47003f..3307bb44b52e09 100644 --- a/src/coreclr/md/runtime/stgpool.cpp +++ b/src/coreclr/md/runtime/stgpool.cpp @@ -438,6 +438,7 @@ StgPool::AddSegment( return S_OK; } // StgPool::AddSegment +#ifdef FEATURE_METADATA_PERSISTENCE #ifndef DACCESS_COMPILE //***************************************************************************** // The entire string pool is written to the given stream. The stream is aligned @@ -575,6 +576,7 @@ StgPool::PersistPartialToStream( return hr; } // StgPool::PersistPartialToStream +#endif // FEATURE_METADATA_PERSISTENCE // Copies data from pSourcePool starting at index nStartSourceIndex. __checkReturn @@ -1791,4 +1793,3 @@ StgBlobPool::RehashBlobs() } return (S_OK); } // StgBlobPool::RehashBlobs - diff --git a/src/coreclr/md/tables/table.h b/src/coreclr/md/tables/table.h index 5e2a67468f0872..5068f0603dc3b5 100644 --- a/src/coreclr/md/tables/table.h +++ b/src/coreclr/md/tables/table.h @@ -151,10 +151,12 @@ class TableRW { return const_cast(m_RecordStorage).Count(); } +#ifdef FEATURE_METADATA_PERSISTENCE inline HRESULT GetRecordsDataSize(UINT32 *pcbSize) const { return m_RecordStorage.GetSaveSize(pcbSize); } +#endif __checkReturn inline HRESULT GetRecord( @@ -164,12 +166,14 @@ class TableRW return m_RecordStorage.GetRecord(nIndex, ppRecord); } +#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn inline HRESULT SaveToStream( IStream *pStream) const { return const_cast(m_RecordStorage).PersistToStream(pStream); } +#endif public: // diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 41d79afe6149a1..acbe44a8fb1dfc 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -2913,6 +2913,7 @@ void Module::SetJMCStatus(bool fStatus) m_debuggerSpecificData.m_fDefaultJMCStatus = fStatus; } +#ifdef FEATURE_METADATA_PERSISTENCE // Update the dynamic metadata if needed. Nop for non-dynamic modules void Module::UpdateDynamicMetadataIfNeeded() { @@ -2945,6 +2946,7 @@ void Module::UpdateDynamicMetadataIfNeeded() } } +#endif #ifdef DEBUGGING_SUPPORTED @@ -2955,12 +2957,14 @@ BOOL Module::NotifyDebuggerLoad(Assembly * pAssembly, int flags, BOOL attaching) { WRAPPER_NO_CONTRACT; +#ifdef FEATURE_METADATA_PERSISTENCE // Always capture metadata, even if no debugger is attached. If a debugger later attaches, it will use // this data. { Module * pModule = pAssembly->GetModule(); pModule->UpdateDynamicMetadataIfNeeded(); } +#endif // // Remaining work is only needed if a debugger is attached @@ -3992,6 +3996,7 @@ class MDUpdateModeHolder // Class-load events are high-volume and events are slow. We can avoid the chattiness by ensuring // the debugger knows that Class-load also means "refresh metadata". // +#ifdef FEATURE_METADATA_PERSISTENCE void ReflectionModule::CaptureModuleMetaDataToMemory() { CONTRACTL @@ -4048,6 +4053,7 @@ void ReflectionModule::CaptureModuleMetaDataToMemory() // Will be S_FALSE if someone changed the MDUpdateMode (from MDUpdateExtension) meanwhile _ASSERTE(hr == S_OK); } +#endif #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 02098a710f0efa..35431f1078f010 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -818,9 +818,11 @@ class Module : public ModuleBase bool GetJMCStatus(); void SetJMCStatus(bool fStatus); +#ifdef FEATURE_METADATA_PERSISTENCE // If this is a dynamic module, eagerly serialize the metadata so that it is available for DAC. // This is a nop for non-dynamic modules. void UpdateDynamicMetadataIfNeeded(); +#endif #ifdef _DEBUG // @@ -1792,8 +1794,10 @@ class ReflectionModule : public Module return m_pInMemoryWriter; } +#ifdef FEATURE_METADATA_PERSISTENCE // Eagerly serialize the metadata to a buffer that the debugger can retrieve. void CaptureModuleMetaDataToMemory(); +#endif }; struct ModuleHolderTraits final diff --git a/src/coreclr/vm/clsload.cpp b/src/coreclr/vm/clsload.cpp index 74252ae0ec82c0..7dd68bdfde04cf 100644 --- a/src/coreclr/vm/clsload.cpp +++ b/src/coreclr/vm/clsload.cpp @@ -2851,11 +2851,13 @@ void ClassLoader::NotifyLoad(TypeHandle typeHnd) LOG((LF_CLASSLOADER, LL_INFO100, "Successfully loaded class %s\n", pMT->GetDebugClassName())); #ifdef DEBUGGING_SUPPORTED +#ifdef FEATURE_METADATA_PERSISTENCE { Module * pModule = pMT->GetModule(); // Update metadata for dynamic module. pModule->UpdateDynamicMetadataIfNeeded(); } +#endif if (CORDebuggerAttached()) { From d581341ff41b95285c1d07ae5c1b415e3985c8cf Mon Sep 17 00:00:00 2001 From: David Wrighton <10779849+davidwrighton@users.noreply.github.com> Date: Wed, 30 Sep 2026 22:15:19 +0000 Subject: [PATCH 3/4] Address metadata interface review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/md/compiler/CMakeLists.txt | 2 +- src/coreclr/md/compiler/emit.cpp | 6 +++--- src/coreclr/md/compiler/helper.cpp | 7 ++++--- src/coreclr/md/enc/CMakeLists.txt | 2 +- src/coreclr/md/enc/mdinternalrw.cpp | 7 ++++--- src/coreclr/md/runtime/CMakeLists.txt | 2 +- src/coreclr/md/runtime/mdinternalro.cpp | 7 ++++--- src/coreclr/vm/ceeload.h | 4 ++-- src/coreclr/vm/peassembly.cpp | 8 ++++---- src/coreclr/vm/peassembly.h | 8 ++++---- src/coreclr/vm/peassembly.inl | 6 +++--- 11 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/coreclr/md/compiler/CMakeLists.txt b/src/coreclr/md/compiler/CMakeLists.txt index 4c415397c48200..cc81e8b24de549 100644 --- a/src/coreclr/md/compiler/CMakeLists.txt +++ b/src/coreclr/md/compiler/CMakeLists.txt @@ -52,7 +52,7 @@ target_compile_definitions(mdcompiler_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERF target_precompile_headers(mdcompiler_dac PRIVATE stdafx.h) add_library_clr(mdcompiler_wks OBJECT ${MDCOMPILER_SOURCES}) -target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdcompiler_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() diff --git a/src/coreclr/md/compiler/emit.cpp b/src/coreclr/md/compiler/emit.cpp index 114bf109261f52..50ff3c1ad2e9d0 100644 --- a/src/coreclr/md/compiler/emit.cpp +++ b/src/coreclr/md/compiler/emit.cpp @@ -367,10 +367,10 @@ STDMETHODIMP RegMeta::DefineTypeRefByName( // S_OK or error. #endif //!FEATURE_METADATA_EMIT_IN_DEBUGGER } // RegMeta::DefineTypeRefByName +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Create a reference, in an emit scope, to a TypeDef in another scope. //***************************************************************************** -#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::DefineImportType( // S_OK or error. IMetaDataAssemblyImport *pAssemImport, // [IN] Assembly containing the TypeDef. const void *pbHashValue, // [IN] Hash Blob for Assembly. @@ -523,10 +523,10 @@ STDMETHODIMP RegMeta::DefineMemberRef( // S_OK or error #endif //!FEATURE_METADATA_EMIT_IN_DEBUGGER } // RegMeta::DefineMemberRef +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Create a MemberRef record based on a member in an import scope. //***************************************************************************** -#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::DefineImportMember( // S_OK or error. IMetaDataAssemblyImport *pAssemImport, // [IN] Assembly containing the Member. const void *pbHashValue, // [IN] Hash Blob for Assembly. @@ -2945,10 +2945,10 @@ HRESULT RegMeta::DefineSecurityAttributeSet(// Return code. return E_NOTIMPL; } // RegMeta::DefineSecurityAttributeSet +#ifdef FEATURE_METADATA_PUBLIC_INTERFACES //***************************************************************************** // Apply edit and continue changes to this metadata. //***************************************************************************** -#ifdef FEATURE_METADATA_PUBLIC_INTERFACES STDMETHODIMP RegMeta::ApplyEditAndContinue( // S_OK or error. IUnknown *pUnk) // [IN] Metadata from the delta PE. { diff --git a/src/coreclr/md/compiler/helper.cpp b/src/coreclr/md/compiler/helper.cpp index 811314ba5200b4..80548a011c59d2 100644 --- a/src/coreclr/md/compiler/helper.cpp +++ b/src/coreclr/md/compiler/helper.cpp @@ -342,10 +342,11 @@ RegMeta::GetMetadata( HRESULT RegMeta::ChangeMvid( // S_OK or error. REFGUID newMvid) // GUID to use as the MVID { -#ifdef FEATURE_METADATA_CORECLR - return E_NOTIMPL; -#else +#ifdef FEATURE_METADATA_EMIT_PORTABLE_PDB + // ILAsm uses this API to produce a deterministic MVID. return GetMiniMd()->ChangeMvid(newMvid); +#else + return E_NOTIMPL; #endif } diff --git a/src/coreclr/md/enc/CMakeLists.txt b/src/coreclr/md/enc/CMakeLists.txt index 1516051c54799b..4c965d62c448bc 100644 --- a/src/coreclr/md/enc/CMakeLists.txt +++ b/src/coreclr/md/enc/CMakeLists.txt @@ -54,7 +54,7 @@ target_compile_definitions(mdruntimerw_dac PRIVATE FEATURE_METADATA_PUBLIC_INTER target_precompile_headers(mdruntimerw_dac PRIVATE stdafx.h) add_library_clr(mdruntimerw_wks OBJECT ${MDRUNTIMERW_SOURCES}) -target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdruntimerw_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() diff --git a/src/coreclr/md/enc/mdinternalrw.cpp b/src/coreclr/md/enc/mdinternalrw.cpp index b7b8c92f8c0525..96f143c7973d9e 100644 --- a/src/coreclr/md/enc/mdinternalrw.cpp +++ b/src/coreclr/md/enc/mdinternalrw.cpp @@ -1977,9 +1977,8 @@ HRESULT MDInternalRW::FindTypeRefByName( // S_OK or error. mdToken tkResolutionScope, // [IN] Resolution Scope fo the TypeRef. mdTypeRef *ptk) // [OUT] TypeRef token returned. { -#ifdef FEATURE_METADATA_CORECLR - return E_NOTIMPL; -#else +#ifdef FEATURE_METADATA_EMIT_PORTABLE_PDB + // ILDasm uses this API to resolve TypeRefs by name. HRESULT hr = NOERROR; ULONG cTypeRefRecs; TypeRefRec *pTypeRefRec; @@ -2029,6 +2028,8 @@ HRESULT MDInternalRW::FindTypeRefByName( // S_OK or error. hr = CLDB_E_RECORD_NOTFOUND; ErrExit: return hr; +#else + return E_NOTIMPL; #endif } // MDInternalRW::FindTypeRefByName diff --git a/src/coreclr/md/runtime/CMakeLists.txt b/src/coreclr/md/runtime/CMakeLists.txt index 1c9f12aff6290e..22b2e9157ddabd 100644 --- a/src/coreclr/md/runtime/CMakeLists.txt +++ b/src/coreclr/md/runtime/CMakeLists.txt @@ -55,7 +55,7 @@ target_compile_definitions(mdruntime_dac PRIVATE FEATURE_METADATA_PUBLIC_INTERFA target_precompile_headers(mdruntime_dac PRIVATE stdafx.h) add_library_clr(mdruntime_wks OBJECT ${MDRUNTIME_SOURCES}) -target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_CORECLR FEATURE_METADATA_EMIT_ALL) +target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_EMIT_ALL) if (FEATURE_CORPROFILER) target_compile_definitions(mdruntime_wks PRIVATE FEATURE_METADATA_PUBLIC_INTERFACES) endif() diff --git a/src/coreclr/md/runtime/mdinternalro.cpp b/src/coreclr/md/runtime/mdinternalro.cpp index b77fb910139d50..c90e8d0a0569fc 100644 --- a/src/coreclr/md/runtime/mdinternalro.cpp +++ b/src/coreclr/md/runtime/mdinternalro.cpp @@ -1098,9 +1098,8 @@ HRESULT MDInternalRO::FindTypeRefByName( // S_OK or error. mdToken tkResolutionScope, // [IN] Resolution Scope fo the TypeRef. mdTypeRef *ptk) // [OUT] TypeRef token returned. { -#ifdef FEATURE_METADATA_CORECLR - return E_NOTIMPL; -#else +#ifdef FEATURE_METADATA_EMIT_PORTABLE_PDB + // ILDasm uses this API to resolve TypeRefs by name. HRESULT hr = NOERROR; _ASSERTE(ptk); @@ -1150,6 +1149,8 @@ HRESULT MDInternalRO::FindTypeRefByName( // S_OK or error. hr = CLDB_E_RECORD_NOTFOUND; ErrExit: return hr; +#else + return E_NOTIMPL; #endif } diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 35431f1078f010..08da08fa12d2fa 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -1032,7 +1032,7 @@ class Module : public ModuleBase return m_pPEAssembly->GetMDImport(); } -#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED IMetaDataEmit *GetEmitter() { WRAPPER_NO_CONTRACT; @@ -1048,7 +1048,7 @@ class Module : public ModuleBase } HRESULT GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID riid, LPVOID * ppvInterface); -#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE +#endif // PROFILING_SUPPORTED #if defined(FEATURE_READYTORUN) BOOL IsInSameVersionBubble(Module *target); diff --git a/src/coreclr/vm/peassembly.cpp b/src/coreclr/vm/peassembly.cpp index 23da4c243e8c24..cdbba86ae9768f 100644 --- a/src/coreclr/vm/peassembly.cpp +++ b/src/coreclr/vm/peassembly.cpp @@ -648,10 +648,10 @@ PEAssembly::PEAssembly( m_PEImage{NULL} , m_MDImportIsRW_Debugger_Use_Only{FALSE} , m_pMDImport{NULL} -#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED , m_pImporter{NULL} , m_pEmitter{NULL} -#endif // PROFILING_SUPPORTED || DACCESS_COMPILE +#endif // PROFILING_SUPPORTED , m_pMDInternalEmit{NULL} , m_refCount{1} , m_pHostAssembly{nullptr} @@ -736,7 +736,7 @@ PEAssembly::~PEAssembly() GCX_PREEMP(); -#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED if (m_pImporter != NULL) { m_pImporter->Release(); @@ -748,7 +748,7 @@ PEAssembly::~PEAssembly() m_pEmitter->Release(); m_pEmitter = NULL; } -#endif // PROFILING_SUPPORTED || DACCESS_COMPILE +#endif // PROFILING_SUPPORTED if (m_pMDInternalEmit != NULL) { diff --git a/src/coreclr/vm/peassembly.h b/src/coreclr/vm/peassembly.h index e1343f7627e4de..b28f58b603b409 100644 --- a/src/coreclr/vm/peassembly.h +++ b/src/coreclr/vm/peassembly.h @@ -139,7 +139,7 @@ class PEAssembly final IMDInternalImport *GetMDImport(); IMDInternalEmit *GetMDInternalEmit(); -#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED IMetaDataEmit *GetEmitter(); IMetaDataImport2 *GetRWImporter(); #elif defined(DACCESS_COMPILE) @@ -149,7 +149,7 @@ class PEAssembly final LIMITED_METHOD_DAC_CONTRACT; return m_MDImportIsRW_Debugger_Use_Only; } -#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE +#endif // PROFILING_SUPPORTED void ConvertMDInternalToReadWrite(); @@ -380,10 +380,10 @@ class PEAssembly final #endif }; -#if defined(PROFILING_SUPPORTED) || defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED IMetaDataImport2* m_pImporter; IMetaDataEmit* m_pEmitter; -#endif // PROFILING_SUPPORTED || DACCESS_COMPILE +#endif // PROFILING_SUPPORTED IMDInternalEmit* m_pMDInternalEmit; Volatile m_refCount; diff --git a/src/coreclr/vm/peassembly.inl b/src/coreclr/vm/peassembly.inl index 601f500d2ccd52..3a6b6ad83e88ca 100644 --- a/src/coreclr/vm/peassembly.inl +++ b/src/coreclr/vm/peassembly.inl @@ -30,7 +30,7 @@ inline CHECK PEAssembly::Invariant() { // dynamic module case CHECK(m_PEImage == NULL); - CHECK(CheckPointer(m_pEmitter)); + CHECK(CheckPointer(m_pMDInternalEmit)); } else { @@ -261,7 +261,7 @@ inline IMDInternalEmit* PEAssembly::GetMDInternalEmit() return m_pMDInternalEmit; } -#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE) +#ifdef PROFILING_SUPPORTED inline IMetaDataImport2 *PEAssembly::GetRWImporter() { @@ -298,7 +298,7 @@ inline IMetaDataEmit *PEAssembly::GetEmitter() } -#endif // PROFILING_SUPPORTED && !DACCESS_COMPILE +#endif // PROFILING_SUPPORTED // Same as the managed Module.ScopeName property, this unconditionally looks in the // metadata Module table to get the name. Useful for profilers and others who don't From ef0ab38093cd9d5185bf2720587ad71e349dc484 Mon Sep 17 00:00:00 2001 From: David Wrighton <10779849+davidwrighton@users.noreply.github.com> Date: Thu, 1 Oct 2026 00:04:42 +0000 Subject: [PATCH 4/4] Place metadata guards before method headers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/md/compiler/regmeta_emit.cpp | 4 ++-- src/coreclr/md/enc/liteweightstgdbrw.cpp | 2 +- src/coreclr/md/heaps/blobheap.h | 2 +- src/coreclr/md/heaps/stringheap.h | 2 +- src/coreclr/md/inc/stgpool.h | 12 ++++++------ src/coreclr/vm/ceeload.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreclr/md/compiler/regmeta_emit.cpp b/src/coreclr/md/compiler/regmeta_emit.cpp index 11ea8d65bc9007..5acb927ac6ce00 100644 --- a/src/coreclr/md/compiler/regmeta_emit.cpp +++ b/src/coreclr/md/compiler/regmeta_emit.cpp @@ -65,10 +65,10 @@ STDMETHODIMP RegMeta::SetModuleProps( // S_OK or error. return hr; } // STDMETHODIMP RegMeta::SetModuleProps() +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Saves a scope to a file of a given name. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE STDMETHODIMP RegMeta::Save( // S_OK or error. LPCWSTR szFile, // [IN] The filename to save to. DWORD dwSaveFlags) // [IN] Flags for the save. @@ -653,10 +653,10 @@ STDMETHODIMP RegMeta::SetHandler( // S_OK. // Internal helper functions. //******************************************************************************* +#ifdef FEATURE_METADATA_PERSISTENCE //******************************************************************************* // Perform optimizations of the metadata prior to saving. //******************************************************************************* -#ifdef FEATURE_METADATA_PERSISTENCE HRESULT RegMeta::PreSave() // Return code. { HRESULT hr = S_OK; // A result. diff --git a/src/coreclr/md/enc/liteweightstgdbrw.cpp b/src/coreclr/md/enc/liteweightstgdbrw.cpp index 99013e19b70a26..949f42ebecfdd4 100644 --- a/src/coreclr/md/enc/liteweightstgdbrw.cpp +++ b/src/coreclr/md/enc/liteweightstgdbrw.cpp @@ -433,10 +433,10 @@ HRESULT CLiteWeightStgdbRW::InitNew() return m_MiniMd.InitNew(); } +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Determine what the size of the saved data will be. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn HRESULT CLiteWeightStgdbRW::GetSaveSize(// S_OK or error. CorSaveSize fSave, // Quick or accurate? diff --git a/src/coreclr/md/heaps/blobheap.h b/src/coreclr/md/heaps/blobheap.h index 1a914e3d32cff7..061d4764df5651 100644 --- a/src/coreclr/md/heaps/blobheap.h +++ b/src/coreclr/md/heaps/blobheap.h @@ -307,8 +307,8 @@ class BlobHeapRW { m_BlobPool.ResetOffsetOfEdit(); } - // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. #ifdef FEATURE_METADATA_PERSISTENCE + // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. __checkReturn inline HRESULT GetEnCSessionAddedHeapSize_Aligned( _Out_ UINT32 *pcbSize) const diff --git a/src/coreclr/md/heaps/stringheap.h b/src/coreclr/md/heaps/stringheap.h index cc86afabd9cee3..9e80d63531b46b 100644 --- a/src/coreclr/md/heaps/stringheap.h +++ b/src/coreclr/md/heaps/stringheap.h @@ -290,8 +290,8 @@ class StringHeapRW { m_StringPool.ResetOffsetOfEdit(); } - // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. #ifdef FEATURE_METADATA_PERSISTENCE + // Gets size (in bytes) aligned to 4-bytes of adds made from the beginning of the last EnC session. __checkReturn inline HRESULT GetEnCSessionAddedHeapSize_Aligned( _Out_ UINT32 *pcbSize) const diff --git a/src/coreclr/md/inc/stgpool.h b/src/coreclr/md/inc/stgpool.h index 484f80ad337b0c..74ed3a3974e271 100644 --- a/src/coreclr/md/inc/stgpool.h +++ b/src/coreclr/md/inc/stgpool.h @@ -507,12 +507,12 @@ friend struct ::cdac_data; //***************************************************************************** void Trim(); // +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Return the size in bytes of the persistent version of this pool. If // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -855,12 +855,12 @@ class StgStringPool : public StgPool return (GetNextOffset() <= 1); } +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Return the size in bytes of the persistent version of this pool. If // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -975,11 +975,11 @@ class StgGuidPool : public StgPool const GUID *pGuid, // The Guid to add to pool. UINT32 *pnIndex); // Return index of Guid here. +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Get the size of the GUID obtained from the pool. // Needed for generic persisting of data blocks. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE virtual ULONG GetSizeOfData( void const * data ) { LIMITED_METHOD_CONTRACT; @@ -1021,12 +1021,12 @@ class StgGuidPool : public StgPool ULONG GetNextIndex() { LIMITED_METHOD_CONTRACT; return (GetNextOffset() / sizeof(GUID)); } +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Return the size in bytes of the persistent version of this pool. If // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const @@ -1137,11 +1137,11 @@ class StgBlobPool : public StgPool __checkReturn virtual HRESULT SetHash(int bHash); +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Get the size of the blob obtained from the pool. // Needed for generic persisting of data blocks. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE virtual ULONG GetSizeOfData( void const * data ) { WRAPPER_NO_CONTRACT; @@ -1170,12 +1170,12 @@ class StgBlobPool : public StgPool return (GetNextOffset() <= 1); } +#ifdef FEATURE_METADATA_PERSISTENCE //***************************************************************************** // Return the size in bytes of the persistent version of this pool. If // PersistToStream were the next call, the amount of bytes written to pIStream // has to be same as the return value from this function. //***************************************************************************** -#ifdef FEATURE_METADATA_PERSISTENCE __checkReturn virtual HRESULT GetSaveSize( UINT32 *pcbSaveSize) const diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index acbe44a8fb1dfc..2d612c0f869b43 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -3979,6 +3979,7 @@ class MDUpdateModeHolder ULONG m_OriginalMDUpdateMode; }; +#ifdef FEATURE_METADATA_PERSISTENCE // Called in live paths to fetch metadata for dynamic modules. This makes the metadata available to the // debugger from out-of-process. // @@ -3996,7 +3997,6 @@ class MDUpdateModeHolder // Class-load events are high-volume and events are slow. We can avoid the chattiness by ensuring // the debugger knows that Class-load also means "refresh metadata". // -#ifdef FEATURE_METADATA_PERSISTENCE void ReflectionModule::CaptureModuleMetaDataToMemory() { CONTRACTL