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//
6// AssemblyBinder.hpp
7//
8
9
10//
11// Defines the AssemblyBinder class
12//
13// ============================================================
14
15#ifndef __BINDER__ASSEMBLY_BINDER_HPP__
16#define __BINDER__ASSEMBLY_BINDER_HPP__
17
18#include "bindertypes.hpp"
19#include "bindresult.hpp"
20#include "coreclrbindercommon.h"
21
22class CLRPrivBinderAssemblyLoadContext;
23class CLRPrivBinderCoreCLR;
24
25namespace BINDER_SPACE
26{
27 typedef enum
28 {
29 kBindingStoreGAC = 0x01,
30 kBindingStoreManifest = 0x02,
31 kBindingStoreHost = 0x04,
32 kBindingStoreContext = 0x08
33 } BindingStore;
34
35 class AssemblyBinder
36 {
37 public:
38 static HRESULT Startup();
39
40 // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
41 // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
42 // for an example of how they're used.
43 static HRESULT BindAssembly(/* in */ ApplicationContext *pApplicationContext,
44 /* in */ AssemblyName *pAssemblyName,
45 /* in */ LPCWSTR szCodeBase,
46 /* in */ PEAssembly *pParentAssembly,
47 /* in */ BOOL fNgenExplicitBind,
48 /* in */ BOOL fExplicitBindToNativeImage,
49 /* in */ bool excludeAppPaths,
50 /* out */ Assembly **ppAssembly);
51
52 static HRESULT BindToSystem(/* in */ SString &systemDirectory,
53 /* out */ Assembly **ppSystemAssembly,
54 /* in */ bool fBindToNativeImage);
55
56 static HRESULT BindToSystemSatellite(/* in */ SString &systemDirectory,
57 /* in */ SString &simpleName,
58 /* in */ SString &cultureName,
59 /* out */ Assembly **ppSystemAssembly);
60
61 static HRESULT GetAssemblyFromImage(/* in */ PEImage *pPEImage,
62 /* in */ PEImage *pNativePEImage,
63 /* out */ Assembly **ppAssembly);
64
65 // Special assembly binder entry point for byte arrays
66 static HRESULT PreBindByteArray(/* in */ ApplicationContext *pApplicationContext,
67 /* in */ PEImage *pPEImage,
68 /* in */ BOOL fInspectionOnly);
69
70 static HRESULT GetAssembly(/* in */ SString &assemblyPath,
71 /* in */ BOOL fInspectionOnly,
72 /* in */ BOOL fIsInGAC,
73 /* in */ BOOL fExplicitBindToNativeImage,
74 /* out */ Assembly **ppAssembly,
75 /* in */ LPCTSTR szMDAssemblyPath = NULL);
76
77#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
78 static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin,
79 /* in */ AssemblyName *pAssemblyName,
80 /* in */ IAssemblyName *pIAssemblyName,
81 /* in */ CLRPrivBinderCoreCLR *pTPABinder,
82 /* out */ Assembly **ppAssembly);
83
84 static HRESULT BindUsingPEImage(/* in */ ApplicationContext *pApplicationContext,
85 /* in */ BINDER_SPACE::AssemblyName *pAssemblyName,
86 /* in */ PEImage *pPEImage,
87 /* in */ PEKIND peKind,
88 /* in */ IMDInternalImport *pIMetaDataAssemblyImport,
89 /* [retval] [out] */ Assembly **ppAssembly);
90#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
91
92 static HRESULT TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind);
93
94 protected:
95 enum
96 {
97 BIND_NONE = 0x00,
98 BIND_CACHE_FAILURES = 0x01,
99 BIND_CACHE_RERUN_BIND = 0x02,
100 BIND_IGNORE_DYNAMIC_BINDS = 0x04
101#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
102 ,
103 BIND_IGNORE_REFDEF_MATCH = 0x8
104#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
105 };
106
107 static BOOL IgnoreDynamicBinds(DWORD dwBindFlags)
108 {
109 return ((dwBindFlags & BIND_IGNORE_DYNAMIC_BINDS) != 0);
110 }
111
112 static BOOL CacheBindFailures(DWORD dwBindFlags)
113 {
114 return ((dwBindFlags & BIND_CACHE_FAILURES) != 0);
115 }
116
117 static BOOL RerunBind(DWORD dwBindFlags)
118 {
119 return ((dwBindFlags & BIND_CACHE_RERUN_BIND) != 0);
120 }
121
122#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
123 static BOOL IgnoreRefDefMatch(DWORD dwBindFlags)
124 {
125 return ((dwBindFlags & BIND_IGNORE_REFDEF_MATCH) != 0);
126 }
127#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
128
129 static HRESULT BindByName(/* in */ ApplicationContext *pApplicationContext,
130 /* in */ AssemblyName *pAssemblyName,
131 /* in */ DWORD dwBindFlags,
132 /* in */ bool excludeAppPaths,
133 /* out */ BindResult *pBindResult);
134
135 // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
136 // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
137 // for an example of how they're used.
138 static HRESULT BindWhereRef(/* in */ ApplicationContext *pApplicationContext,
139 /* in */ PathString &assemblyPath,
140 /* in */ BOOL fNgenExplicitBind,
141 /* in */ BOOL fExplicitBindToNativeImage,
142 /* in */ bool excludeAppPaths,
143 /* out */ BindResult *pBindResult);
144
145 static HRESULT BindLocked(/* in */ ApplicationContext *pApplicationContext,
146 /* in */ AssemblyName *pAssemblyName,
147 /* in */ DWORD dwBindFlags,
148 /* in */ bool excludeAppPaths,
149 /* out */ BindResult *pBindResult);
150 static HRESULT BindLockedOrService(/* in */ ApplicationContext *pApplicationContext,
151 /* in */ AssemblyName *pAssemblyName,
152 /* in */ bool excludeAppPaths,
153 /* out */ BindResult *pBindResult);
154
155 static HRESULT FindInExecutionContext(/* in */ ApplicationContext *pApplicationContext,
156 /* in */ AssemblyName *pAssemblyName,
157 /* out */ ContextEntry **ppContextEntry);
158
159 static HRESULT BindByTpaList(/* in */ ApplicationContext *pApplicationContext,
160 /* in */ AssemblyName *pRequestedAssemblyName,
161 /* in */ BOOL fInspectionOnly,
162 /* in */ bool excludeAppPaths,
163 /* out */ BindResult *pBindResult);
164
165 static HRESULT Register(/* in */ ApplicationContext *pApplicationContext,
166 /* in */ BOOL fInspectionOnly,
167 /* in */ BindResult *pBindResult);
168 static HRESULT RegisterAndGetHostChosen(/* in */ ApplicationContext *pApplicationContext,
169 /* in */ LONG kContextVersion,
170 /* in */ BindResult *pBindResult,
171 /* out */ BindResult *pHostBindResult);
172
173 static HRESULT OtherBindInterfered(/* in */ ApplicationContext *pApplicationContext,
174 /* in */ BindResult *pBindResult);
175 };
176};
177
178#endif
179