| 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 | // Assembly.hpp |
| 7 | // |
| 8 | |
| 9 | |
| 10 | // |
| 11 | // Defines the Assembly class |
| 12 | // |
| 13 | // ============================================================ |
| 14 | |
| 15 | #ifndef __BINDER__ASSEMBLY_HPP__ |
| 16 | #define __BINDER__ASSEMBLY_HPP__ |
| 17 | |
| 18 | #include "bindertypes.hpp" |
| 19 | #include "assemblyname.hpp" |
| 20 | |
| 21 | #include "corpriv.h" |
| 22 | #include "clrprivbinding.h" |
| 23 | |
| 24 | #include "clrprivbindercoreclr.h" |
| 25 | |
| 26 | #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) |
| 27 | #include "clrprivbinderassemblyloadcontext.h" |
| 28 | #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) |
| 29 | |
| 30 | STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath, |
| 31 | PEImage **ppPEImage, |
| 32 | PEImage **ppNativeImage, |
| 33 | BOOL fExplicitBindToNativeImage); |
| 34 | |
| 35 | STDAPI BinderAcquireImport(PEImage *pPEImage, |
| 36 | IMDInternalImport **pIMetaDataAssemblyImport, |
| 37 | DWORD *pdwPAFlags, |
| 38 | BOOL bNativeImage); |
| 39 | |
| 40 | STDAPI (PEImage *pPEImage, |
| 41 | BOOL *result); |
| 42 | |
| 43 | STDAPI BinderGetImagePath(PEImage *pPEImage, |
| 44 | SString &imagePath); |
| 45 | |
| 46 | STDAPI BinderReleasePEImage(PEImage *pPEImage); |
| 47 | |
| 48 | STDAPI BinderAddRefPEImage(PEImage *pPEImage); |
| 49 | |
| 50 | namespace BINDER_SPACE |
| 51 | { |
| 52 | |
| 53 | // An assembly represents a particular set of bits. However we extend this to |
| 54 | // also include whether those bits have precompiled information (NGEN). Thus |
| 55 | // and assembly knows whether it has an NGEN image or not. |
| 56 | // |
| 57 | // This allows us to preferentially use the NGEN image if it is available. |
| 58 | class Assembly |
| 59 | : public ICLRPrivAssembly |
| 60 | { |
| 61 | public: |
| 62 | // -------------------------------------------------------------------- |
| 63 | // IUnknown methods |
| 64 | // -------------------------------------------------------------------- |
| 65 | STDMETHOD(QueryInterface)(REFIID riid, |
| 66 | void ** ppv); |
| 67 | STDMETHOD_(ULONG, AddRef)(); |
| 68 | STDMETHOD_(ULONG, Release)(); |
| 69 | |
| 70 | // -------------------------------------------------------------------- |
| 71 | // ICLRPrivAssembly methods |
| 72 | // -------------------------------------------------------------------- |
| 73 | LPCWSTR GetSimpleName(); |
| 74 | |
| 75 | STDMETHOD(BindAssemblyByName)( |
| 76 | IAssemblyName * pIAssemblyName, |
| 77 | ICLRPrivAssembly ** ppAssembly); |
| 78 | |
| 79 | STDMETHOD(IsShareable)(BOOL * pbIsShareable); |
| 80 | |
| 81 | STDMETHOD(GetAvailableImageTypes)(PDWORD pdwImageTypes); |
| 82 | |
| 83 | STDMETHOD(GetImageResource)( |
| 84 | DWORD dwImageType, |
| 85 | DWORD *pdwImageType, |
| 86 | ICLRPrivResource ** ppIResource); |
| 87 | |
| 88 | STDMETHOD(GetBinderID)(UINT_PTR *pBinderId); |
| 89 | |
| 90 | STDMETHOD(GetLoaderAllocator)(LPVOID* pLoaderAllocator); |
| 91 | |
| 92 | // -------------------------------------------------------------------- |
| 93 | // Assembly methods |
| 94 | // -------------------------------------------------------------------- |
| 95 | Assembly(); |
| 96 | virtual ~Assembly(); |
| 97 | |
| 98 | HRESULT Init(/* in */ IMDInternalImport *pIMetaDataAssemblyImport, |
| 99 | /* in */ PEKIND PeKind, |
| 100 | /* in */ PEImage *pPEImage, |
| 101 | /* in */ PEImage *pPENativeImage, |
| 102 | /* in */ SString &assemblyPath, |
| 103 | /* in */ BOOL fInspectionOnly, |
| 104 | /* in */ BOOL fIsInGAC); |
| 105 | |
| 106 | // Enumerates dependent assemblies |
| 107 | HRESULT GetNextAssemblyNameRef(/* in */ DWORD nIndex, |
| 108 | /* out */ AssemblyName **ppAssemblyName); |
| 109 | |
| 110 | inline AssemblyName *GetAssemblyName(BOOL fAddRef = FALSE); |
| 111 | inline BOOL GetIsInGAC(); |
| 112 | inline BOOL GetIsDynamicBind(); |
| 113 | inline void SetIsDynamicBind(BOOL fIsDynamicBind); |
| 114 | inline BOOL GetIsByteArray(); |
| 115 | inline void SetIsByteArray(BOOL fIsByteArray); |
| 116 | inline BOOL GetIsSharable(); |
| 117 | inline void SetIsSharable(BOOL fIsSharable); |
| 118 | inline SString &GetPath(); |
| 119 | |
| 120 | inline PEImage *GetPEImage(BOOL fAddRef = FALSE); |
| 121 | inline PEImage *GetNativePEImage(BOOL fAddRef = FALSE); |
| 122 | inline PEImage *GetNativeOrILPEImage(BOOL fAddRef = FALSE); |
| 123 | |
| 124 | HRESULT GetMVID(GUID *pMVID); |
| 125 | |
| 126 | static PEKIND GetSystemArchitecture(); |
| 127 | static BOOL IsValidArchitecture(PEKIND kArchitecture); |
| 128 | |
| 129 | inline ICLRPrivBinder* GetBinder() |
| 130 | { |
| 131 | return m_pBinder; |
| 132 | } |
| 133 | |
| 134 | #ifndef CROSSGEN_COMPILE |
| 135 | protected: |
| 136 | #endif |
| 137 | // Asssembly Flags |
| 138 | enum |
| 139 | { |
| 140 | FLAG_NONE = 0x00, |
| 141 | FLAG_INSPECTION_ONLY = 0x01, |
| 142 | FLAG_IS_IN_GAC = 0x02, |
| 143 | FLAG_IS_DYNAMIC_BIND = 0x04, |
| 144 | FLAG_IS_BYTE_ARRAY = 0x08, |
| 145 | FLAG_IS_SHARABLE = 0x10 |
| 146 | }; |
| 147 | |
| 148 | inline void SetPEImage(PEImage *pPEImage); |
| 149 | inline void SetNativePEImage(PEImage *pNativePEImage); |
| 150 | |
| 151 | inline void SetAssemblyName(AssemblyName *pAssemblyName, |
| 152 | BOOL fAddRef = TRUE); |
| 153 | inline BOOL GetInspectionOnly(); |
| 154 | inline void SetInspectionOnly(BOOL fInspectionOnly); |
| 155 | inline void SetIsInGAC(BOOL fIsInGAC); |
| 156 | |
| 157 | inline IMDInternalImport *GetMDImport(); |
| 158 | inline void SetMDImport(IMDInternalImport *pMDImport); |
| 159 | inline mdAssembly *GetAssemblyRefTokens(); |
| 160 | |
| 161 | inline DWORD GetNbAssemblyRefTokens(); |
| 162 | inline void SetNbAsssemblyRefTokens(DWORD dwCAssemblyRefTokens); |
| 163 | |
| 164 | LONG m_cRef; |
| 165 | PEImage *m_pPEImage; |
| 166 | PEImage *m_pNativePEImage; |
| 167 | IMDInternalImport *m_pMDImport; |
| 168 | mdAssembly *m_pAssemblyRefTokens; |
| 169 | DWORD m_dwCAssemblyRefTokens; |
| 170 | AssemblyName *m_pAssemblyName; |
| 171 | SString m_assemblyPath; |
| 172 | DWORD m_dwAssemblyFlags; |
| 173 | ICLRPrivBinder *m_pBinder; |
| 174 | |
| 175 | // Nested class used to implement ICLRPriv binder related interfaces |
| 176 | class CLRPrivResourceAssembly : |
| 177 | public ICLRPrivResource, public ICLRPrivResourceAssembly |
| 178 | { |
| 179 | public: |
| 180 | STDMETHOD(QueryInterface)(REFIID riid, void ** ppv); |
| 181 | STDMETHOD_(ULONG, AddRef)(); |
| 182 | STDMETHOD_(ULONG, Release)(); |
| 183 | STDMETHOD(GetResourceType)(IID *pIID); |
| 184 | STDMETHOD(GetAssembly)(LPVOID *ppAssembly); |
| 185 | } m_clrPrivRes; |
| 186 | |
| 187 | inline void SetBinder(ICLRPrivBinder *pBinder) |
| 188 | { |
| 189 | _ASSERTE(m_pBinder == NULL || m_pBinder == pBinder); |
| 190 | m_pBinder = pBinder; |
| 191 | } |
| 192 | |
| 193 | friend class ::CLRPrivBinderCoreCLR; |
| 194 | |
| 195 | #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) |
| 196 | friend class ::CLRPrivBinderAssemblyLoadContext; |
| 197 | #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) |
| 198 | }; |
| 199 | |
| 200 | // This is a fast version which goes around the COM interfaces and directly |
| 201 | // casts the interfaces and does't AddRef |
| 202 | inline BINDER_SPACE::Assembly * GetAssemblyFromPrivAssemblyFast(ICLRPrivAssembly *pPrivAssembly); |
| 203 | |
| 204 | #include "assembly.inl" |
| 205 | }; |
| 206 | |
| 207 | #endif |
| 208 | |