summaryrefslogtreecommitdiff
path: root/src/vm/clrprivbinderfusion.h
blob: 001a4900c12e46a084b210bad09616900991b04b (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//



#pragma once

#include "holder.h"
#include "internalunknownimpl.h"
#include "shash.h"
#include "clrprivbinding.h"
#include "clrprivruntimebinders.h"

//=====================================================================================================================
// Forward declarations
class CLRPrivBinderFusion;
class CLRPrivAssemblyFusion;

class PEAssembly;
class DomainAssembly;
struct IMDInternalImport;

//=====================================================================================================================
class CLRPrivBinderFusion :
    public IUnknownCommon<ICLRPrivBinder, IBindContext>
{
    friend class CLRPrivAssemblyFusion;
    
public:
    // Scope for the bind operation
    enum BindingScope
    {
        // Binds only to subset of framework that is not on the black list (non-FX assemblies bindings are rejected)
        kBindingScope_FrameworkSubset, 
        // Binds to all framework assemblies (incl. those on the black list) (non-FX assemblies bindings are rejected)
        // Used by designer binding context and in DevMode
        kBindingScope_FrameworkAll
    };
    
public:
    //=============================================================================================
    // ICLRPrivBinder methods

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::BindAssemblyByName
    STDMETHOD(BindAssemblyByName(
        IAssemblyName * pAssemblyName,
        ICLRPrivAssembly ** ppAssembly));

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::VerifyBind
    STDMETHOD(VerifyBind)(
        IAssemblyName *pAssemblyName,
        ICLRPrivAssembly *pAssembly,
        ICLRPrivAssemblyInfo *pAssemblyInfo)
    {
        LIMITED_METHOD_CONTRACT;
        if (pAssemblyName == nullptr || pAssembly == nullptr || pAssemblyInfo == nullptr)
            return E_INVALIDARG;
        return S_OK;
    }

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::GetBinderFlags
    STDMETHOD(GetBinderFlags)(
        DWORD *pBinderFlags)
    {
        LIMITED_METHOD_CONTRACT;
        *pBinderFlags = BINDER_FINDASSEMBLYBYSPEC_REQUIRES_EXACT_MATCH;
        return S_OK;
    }

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::GetBinderID
    STDMETHOD(GetBinderID)(
        UINT_PTR *pBinderId);

    STDMETHOD(FindAssemblyBySpec)(
        LPVOID pvAppDomain,
        LPVOID pvAssemblySpec,
        HRESULT * pResult,
        ICLRPrivAssembly ** ppAssembly);

    //=============================================================================================
    // IBindContext methods

    // Implements code:IBindContext::PreBind
    STDMETHOD(PreBind)(
        IAssemblyName  *pIAssemblyName,
        DWORD           dwPreBindFlags,
        IBindResult   **ppIBindResult);

    // Implements code:IBindContext::IsDefaultContext
    STDMETHOD(IsDefaultContext)();

    //=============================================================================================
    // Class methods

    //---------------------------------------------------------------------------------------------
    CLRPrivBinderFusion()
        : m_SetHostAssemblyLock(CrstLeafLock)
    { STANDARD_VM_CONTRACT; }
    
    //---------------------------------------------------------------------------------------------
    ~CLRPrivBinderFusion();

    //---------------------------------------------------------------------------------------------
    HRESULT FindFusionAssemblyBySpec(
        LPVOID pvAppDomain,
        LPVOID pvAssemblySpec,
        BindingScope kBindingScope,
        HRESULT * pResult,
        ICLRPrivAssembly ** ppAssembly);

    //---------------------------------------------------------------------------------------------
    HRESULT BindFusionAssemblyByName(
        IAssemblyName *     pAssemblyName, 
        BindingScope        kBindingScope, 
        ICLRPrivAssembly ** ppAssembly);

    //---------------------------------------------------------------------------------------------
    HRESULT PreBindFusionAssemblyByName(
        IAssemblyName * pIAssemblyName,
        DWORD           dwPreBindFlags,
        IBindResult **  ppIBindResult);
    
    //---------------------------------------------------------------------------------------------
    // Binds mscorlib.dll
    void BindMscorlib(
        PEAssembly * pPEAssembly);
    
private:
    //---------------------------------------------------------------------------------------------
    HRESULT BindAssemblyByNameWorker(
        IAssemblyName *     pAssemblyName, 
        ICLRPrivAssembly ** ppAssembly);
    
private:
    //---------------------------------------------------------------------------------------------
    // This lock is used to serialize assigning ICLRPrivAssembly instances to PEAssembly objects.
    Crst              m_SetHostAssemblyLock;

};  // class CLRPrivBinderFusion

//=====================================================================================================================
class CLRPrivAssemblyFusion :
    public IUnknownCommon<ICLRPrivAssembly>
{
public:
    //---------------------------------------------------------------------------------------------
    CLRPrivAssemblyFusion(
        LPCWSTR               wszName, 
        CLRPrivBinderFusion * pBinder);
    
    //---------------------------------------------------------------------------------------------
    LPCWSTR GetName() const;
    
    //---------------------------------------------------------------------------------------------
    // Implements code:IUnknown::Release
    STDMETHOD_(ULONG, Release)();
    
    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::BindAssemblyByName
    STDMETHOD(BindAssemblyByName)(
        IAssemblyName * pAssemblyName,
        ICLRPrivAssembly ** ppAssembly);

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivAssembly::IsShareable
    STDMETHOD(IsShareable)(
        BOOL * pbIsShareable);

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivAssembly::GetAvailableImageTypes
    STDMETHOD(GetAvailableImageTypes)(
        LPDWORD pdwImageTypes);

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivAssembly::GetImageResource
    STDMETHOD(GetImageResource)(
        DWORD dwImageType,
        DWORD *pdwImageType,
        ICLRPrivResource ** ppIResource);

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::VerifyBind
    STDMETHOD(VerifyBind)(
        IAssemblyName *pAssemblyName,
        ICLRPrivAssembly *pAssembly,
        ICLRPrivAssemblyInfo *pAssemblyInfo)
    {
        WRAPPER_NO_CONTRACT;
        return m_pBinder->VerifyBind(pAssemblyName, pAssembly, pAssemblyInfo);
    }

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::GetBinderFlags
    STDMETHOD(GetBinderFlags)(
        DWORD *pBinderFlags)
    {
        LIMITED_METHOD_CONTRACT;
        return m_pBinder->GetBinderFlags(pBinderFlags);
    }

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::GetBinderID
    STDMETHOD(GetBinderID)(
        UINT_PTR *pBinderId);

    //---------------------------------------------------------------------------------------------
    // Implements code:ICLRPrivBinder::FindAssemblyBySpec
    STDMETHOD(FindAssemblyBySpec)(
        LPVOID pvAppDomain,
        LPVOID pvAssemblySpec,
        HRESULT * pResult,
        ICLRPrivAssembly ** ppAssembly)
    { STATIC_CONTRACT_WRAPPER; return m_pBinder->FindAssemblyBySpec(pvAppDomain, pvAssemblySpec, pResult, ppAssembly); }

protected:
    //---------------------------------------------------------------------------------------------
    // The fusion binder. Need to keep it around as long as this object is around.
    ReleaseHolder<CLRPrivBinderFusion> m_pBinder;
    
    // Full display name of the assembly - used to avoid duplicate CLRPrivAssemblyFusion objects
    NewArrayHolder<WCHAR> m_wszName;
    
};  // class CLRPrivAssemblyFusion