| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
| 3 | // See the LICENSE file in the project root for more information. | 
| 4 | //***************************************************************************** | 
| 5 | // MDUtil.h | 
| 6 | //  | 
| 7 |  | 
| 8 | // | 
| 9 | // Contains utility code for MD directory | 
| 10 | // | 
| 11 | //***************************************************************************** | 
| 12 | #ifndef __MDUtil__h__ | 
| 13 | #define __MDUtil__h__ | 
| 14 |  | 
| 15 | #include "metadata.h" | 
| 16 |  | 
| 17 |  | 
| 18 | HRESULT _GetFixedSigOfVarArg(           // S_OK or error. | 
| 19 |     PCCOR_SIGNATURE pvSigBlob,          // [IN] point to a blob of COM+ method signature | 
| 20 |     ULONG   cbSigBlob,                  // [IN] size of signature | 
| 21 |     CQuickBytes *pqbSig,                // [OUT] output buffer for fixed part of VarArg Signature | 
| 22 |     ULONG   *pcbSigBlob);               // [OUT] number of bytes written to the above output buffer | 
| 23 |  | 
| 24 | ULONG _GetSizeOfConstantBlob( | 
| 25 |     DWORD       dwCPlusTypeFlag,            // ELEMENT_TYPE_* | 
| 26 |     void        *pValue,                    // BLOB value | 
| 27 |     ULONG       cchString);                 // Size of string in wide chars, or -1 for auto. | 
| 28 |  | 
| 29 |  | 
| 30 | //********************************************************************* | 
| 31 | // APIs to help look up TypeRef using CORPATH environment variable | 
| 32 | //********************************************************************* | 
| 33 | class CORPATHService | 
| 34 | { | 
| 35 | public: | 
| 36 |  | 
| 37 |     static HRESULT GetClassFromCORPath( | 
| 38 |         __in __in_z LPWSTR      wzClassname,            // fully qualified class name | 
| 39 |         mdTypeRef   tr,                     // TypeRef to be resolved | 
| 40 |         IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined. | 
| 41 |         REFIID      riid,  | 
| 42 |         IUnknown    **ppIScope, | 
| 43 |         mdTypeDef   *ptd);                  // [OUT] typedef corresponding the typeref | 
| 44 |  | 
| 45 |     static HRESULT GetClassFromDir( | 
| 46 |         __in __in_z LPWSTR      wzClassname, // Fully qualified class name. | 
| 47 |         __in SString&      dir,              // Directory to try. | 
| 48 |         mdTypeRef   tr,                     // TypeRef to resolve. | 
| 49 |         IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined. | 
| 50 |         REFIID      riid,  | 
| 51 |         IUnknown    **ppIScope, | 
| 52 |         mdTypeDef   *ptd);                  // [OUT] typedef | 
| 53 |  | 
| 54 |     static HRESULT FindTypeDef( | 
| 55 |         __in __in_z LPCWSTR      wzModule,  // name of the module that we are going to open | 
| 56 |         mdTypeRef   tr,                     // TypeRef to resolve. | 
| 57 |         IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined. | 
| 58 |         REFIID      riid,  | 
| 59 |         IUnknown    **ppIScope, | 
| 60 |         mdTypeDef   *ptd );                 // [OUT] the type that we resolve to | 
| 61 | };  // class CORPATHService | 
| 62 |  | 
| 63 |  | 
| 64 | #if defined(FEATURE_METADATA_IN_VM) | 
| 65 |  | 
| 66 | class RegMeta; | 
| 67 |  | 
| 68 | //********************************************************************* | 
| 69 | // | 
| 70 | // Structure to record the all loaded modules and helpers. | 
| 71 | // RegMeta instance is added to the global variable that is tracking  | 
| 72 | // the opened scoped. This happens in RegMeta's constructor.  | 
| 73 | // In RegMeta's destructor, the RegMeta pointer will be removed from | 
| 74 | // this list. | 
| 75 | // | 
| 76 | //********************************************************************* | 
| 77 | class UTSemReadWrite; | 
| 78 | #define LOADEDMODULES_HASH_SIZE 47 | 
| 79 |  | 
| 80 | class LOADEDMODULES : public CDynArray<RegMeta *>  | 
| 81 | { | 
| 82 | private: | 
| 83 |     static HRESULT InitializeStatics(); | 
| 84 |      | 
| 85 |     // Global per-process list of loaded modules | 
| 86 |     static LOADEDMODULES * s_pLoadedModules; | 
| 87 |      | 
| 88 | public: | 
| 89 |     static void DeleteStatics(); | 
| 90 |      | 
| 91 |     // Named for locking macros - see code:LOCKREAD | 
| 92 |     static UTSemReadWrite * m_pSemReadWrite; | 
| 93 |     static RegMeta *(m_HashedModules[LOADEDMODULES_HASH_SIZE]); | 
| 94 |      | 
| 95 |     static ULONG HashFileName(LPCWSTR szName); | 
| 96 |  | 
| 97 |     static HRESULT AddModuleToLoadedList(RegMeta *pRegMeta); | 
| 98 |     static BOOL RemoveModuleFromLoadedList(RegMeta *pRegMeta);  // true if found and removed. | 
| 99 |      | 
| 100 |     static HRESULT FindCachedReadOnlyEntry(LPCWSTR szName, DWORD dwOpenFlags, RegMeta **ppMeta); | 
| 101 |  | 
| 102 | #ifdef FEATURE_METADATA_IN_VM | 
| 103 |     static HRESULT ResolveTypeRefWithLoadedModules( | 
| 104 |         mdTypeRef          tkTypeRef,       // [IN] TypeRef to be resolved. | 
| 105 |         RegMeta *          pTypeRefRegMeta, // [IN] Scope in which the TypeRef is defined. | 
| 106 |         IMetaModelCommon * pTypeRefScope,   // [IN] Scope in which the TypeRef is defined. | 
| 107 |         REFIID             riid,            // [IN] iid for the return interface. | 
| 108 |         IUnknown **        ppIScope,        // [OUT] Return interface. | 
| 109 |         mdTypeDef *        ptd);            // [OUT] TypeDef corresponding the TypeRef. | 
| 110 | #endif //FEATURE_METADATA_IN_VM | 
| 111 |  | 
| 112 | #ifdef _DEBUG | 
| 113 |     static BOOL IsEntryInList(RegMeta *pRegMeta); | 
| 114 | #endif | 
| 115 | };  // class LOADEDMODULES | 
| 116 |  | 
| 117 | #endif //FEATURE_METADATA_IN_VM  | 
| 118 |  | 
| 119 | #endif // __MDUtil__h__ | 
| 120 |  |