summaryrefslogtreecommitdiff
path: root/src/md/compiler/mdutil.h
blob: eda2bca877bf2056be7771b72f9d26954fee972a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//*****************************************************************************
// MDUtil.h
// 

//
// Contains utility code for MD directory
//
//*****************************************************************************
#ifndef __MDUtil__h__
#define __MDUtil__h__

#include "metadata.h"


HRESULT _GetFixedSigOfVarArg(           // S_OK or error.
    PCCOR_SIGNATURE pvSigBlob,          // [IN] point to a blob of COM+ method signature
    ULONG   cbSigBlob,                  // [IN] size of signature
    CQuickBytes *pqbSig,                // [OUT] output buffer for fixed part of VarArg Signature
    ULONG   *pcbSigBlob);               // [OUT] number of bytes written to the above output buffer

ULONG _GetSizeOfConstantBlob(
    DWORD       dwCPlusTypeFlag,            // ELEMENT_TYPE_*
    void        *pValue,                    // BLOB value
    ULONG       cchString);                 // Size of string in wide chars, or -1 for auto.


//*********************************************************************
// APIs to help look up TypeRef using CORPATH environment variable
//*********************************************************************
class CORPATHService
{
public:

    static HRESULT GetClassFromCORPath(
        __in __in_z LPWSTR      wzClassname,            // fully qualified class name
        mdTypeRef   tr,                     // TypeRef to be resolved
        IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined.
        REFIID      riid, 
        IUnknown    **ppIScope,
        mdTypeDef   *ptd);                  // [OUT] typedef corresponding the typeref

    static HRESULT GetClassFromDir(
        __in __in_z LPWSTR      wzClassname,            // Fully qualified class name.
        __in __in_z LPWSTR      dir,                    // Directory to try.
        int         iLen,                   // Length of the directory.
        mdTypeRef   tr,                     // TypeRef to resolve.
        IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined.
        REFIID      riid, 
        IUnknown    **ppIScope,
        mdTypeDef   *ptd);                  // [OUT] typedef

    static HRESULT FindTypeDef(
        __in __in_z LPWSTR      wzModule,               // name of the module that we are going to open
        mdTypeRef   tr,                     // TypeRef to resolve.
        IMetaModelCommon *pCommon,          // Scope in which the TypeRef is defined.
        REFIID      riid, 
        IUnknown    **ppIScope,
        mdTypeDef   *ptd );                 // [OUT] the type that we resolve to
};  // class CORPATHService


#if defined(FEATURE_METADATA_IN_VM) || defined(FEATURE_METADATA_STANDALONE_WINRT)

class RegMeta;

//*********************************************************************
//
// Structure to record the all loaded modules and helpers.
// RegMeta instance is added to the global variable that is tracking 
// the opened scoped. This happens in RegMeta's constructor. 
// In RegMeta's destructor, the RegMeta pointer will be removed from
// this list.
//
//*********************************************************************
class UTSemReadWrite;
#define LOADEDMODULES_HASH_SIZE 47

class LOADEDMODULES : public CDynArray<RegMeta *> 
{
private:
    static HRESULT InitializeStatics();
    
    // Global per-process list of loaded modules
    static LOADEDMODULES * s_pLoadedModules;
    
public:
    static void DeleteStatics();
    
    // Named for locking macros - see code:LOCKREAD
    static UTSemReadWrite * m_pSemReadWrite;
    static RegMeta *(m_HashedModules[LOADEDMODULES_HASH_SIZE]);
    
    static ULONG HashFileName(LPCWSTR szName);

    static HRESULT AddModuleToLoadedList(RegMeta *pRegMeta);
    static BOOL RemoveModuleFromLoadedList(RegMeta *pRegMeta);  // true if found and removed.
    
    static HRESULT FindCachedReadOnlyEntry(LPCWSTR szName, DWORD dwOpenFlags, RegMeta **ppMeta);

#ifdef FEATURE_METADATA_IN_VM
    static HRESULT ResolveTypeRefWithLoadedModules(
        mdTypeRef          tkTypeRef,       // [IN] TypeRef to be resolved.
        RegMeta *          pTypeRefRegMeta, // [IN] Scope in which the TypeRef is defined.
        IMetaModelCommon * pTypeRefScope,   // [IN] Scope in which the TypeRef is defined.
        REFIID             riid,            // [IN] iid for the return interface.
        IUnknown **        ppIScope,        // [OUT] Return interface.
        mdTypeDef *        ptd);            // [OUT] TypeDef corresponding the TypeRef.
#endif //FEATURE_METADATA_IN_VM

#ifdef _DEBUG
    static BOOL IsEntryInList(RegMeta *pRegMeta);
#endif
};  // class LOADEDMODULES

#endif //FEATURE_METADATA_IN_VM || FEATURE_METADATA_STANDALONE_WINRT

#endif // __MDUtil__h__