assemblybinder.cpp
stringlexer.cpp
clrprivbindercoreclr.cpp
- binderinterface.cpp
debuglog.cpp
bindinglog.cpp
cdebuglog.cpp
inc/assemblyname.inl
inc/assemblyversion.hpp
inc/assemblyversion.inl
- inc/binderinterface.hpp
inc/bindertypes.hpp
inc/bindinglog.hpp
inc/bindinglog.inl
{
return ((kArchitecture != peMSIL) && (kArchitecture != peNone));
}
-
- HRESULT GetAssemblyRefTokens(IMDInternalImport *pMDImport,
- mdAssembly **ppAssemblyRefTokens,
- DWORD *pdwCAssemblyRefTokens)
- {
- HRESULT hr = S_OK;
-
- _ASSERTE(pMDImport != NULL);
- _ASSERTE(ppAssemblyRefTokens != NULL);
- _ASSERTE(pdwCAssemblyRefTokens != NULL);
-
- mdAssembly *pAssemblyRefTokens = NULL;
- COUNT_T assemblyRefCount;
-
- HENUMInternalHolder hEnumAssemblyRef(pMDImport);
- IF_FAIL_GO(hEnumAssemblyRef.EnumInitNoThrow(mdtAssemblyRef, mdTokenNil));
-
- assemblyRefCount = hEnumAssemblyRef.EnumGetCount();
-
- pAssemblyRefTokens = new (nothrow) mdAssemblyRef[assemblyRefCount];
- if (pAssemblyRefTokens == NULL)
- {
- IF_FAIL_GO(E_OUTOFMEMORY);
- }
- ZeroMemory(pAssemblyRefTokens, assemblyRefCount * sizeof(mdAssemblyRef));
-
- for (COUNT_T i = 0; i < assemblyRefCount; i++)
- {
- bool ret = hEnumAssemblyRef.EnumNext(&(pAssemblyRefTokens[i]));
- _ASSERTE(ret);
- }
-
- *ppAssemblyRefTokens = pAssemblyRefTokens;
- pAssemblyRefTokens = NULL;
-
- *pdwCAssemblyRefTokens= assemblyRefCount;
- hr = S_OK;
-
-Exit:
- SAFE_DELETE_ARRAY(pAssemblyRefTokens);
-
- return hr;
- }
};
STDMETHODIMP Assembly::QueryInterface(REFIID riid,
m_pNativePEImage = NULL;
m_pAssemblyName = NULL;
m_pMDImport = NULL;
- m_pAssemblyRefTokens = NULL;
- m_dwCAssemblyRefTokens = static_cast<DWORD>(-1);
m_dwAssemblyFlags = FLAG_NONE;
m_pBinder = NULL;
}
SAFE_RELEASE(m_pAssemblyName);
SAFE_RELEASE(m_pMDImport);
- SAFE_DELETE_ARRAY(m_pAssemblyRefTokens);
}
HRESULT Assembly::Init(IMDInternalImport *pIMetaDataAssemblyImport,
#define APP_DOMAIN_LOCKED_UNLOCKED 0x02
#define APP_DOMAIN_LOCKED_CONTEXT 0x04
-#define BIND_BEHAVIOR_STATIC 0
-#define BIND_BEHAVIOR_ORDER_INDEPENDENT 1
-#define BIND_BEHAVIOR_BEST_MATCH 2
-
#ifndef IMAGE_FILE_MACHINE_ARM64
#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
#endif
return hr;
}
- HRESULT LogBindBehavior(ApplicationContext *pApplicationContext,
- DWORD dwBindBehavior)
- {
- HRESULT hr = S_OK;
- BindingLog *pBindingLog = pApplicationContext->GetBindingLog();
-
- if (pBindingLog->CanLog())
- {
- PathString bindBehavior;
- UINT uiBindBehavior = 0;
-
- switch (dwBindBehavior)
- {
- case BIND_BEHAVIOR_STATIC:
- uiBindBehavior = ID_FUSLOG_BINDING_BEHAVIOR_STATIC;
- break;
- case BIND_BEHAVIOR_ORDER_INDEPENDENT:
- uiBindBehavior = ID_FUSLOG_BINDING_BEHAVIOR_ORDER_INDEPENDENT;
- break;
- case BIND_BEHAVIOR_BEST_MATCH:
- uiBindBehavior = ID_FUSLOG_BINDING_BEHAVIOR_BEST_MATCH;
- break;
- default:
- _ASSERTE(0);
- IF_FAIL_GO(E_INVALIDARG);
- break;
- }
-
- IF_FAIL_GO(bindBehavior.LoadResourceAndReturnHR(CCompRC::Debugging, uiBindBehavior));
- IF_FAIL_GO(pBindingLog->Log(bindBehavior.GetUnicode()));
- }
-
- Exit:
- return hr;
- }
-
HRESULT LogAssemblyNameWhereRef(ApplicationContext *pApplicationContext,
Assembly *pAssembly)
{
Exit:
return hr;
}
-
- HRESULT LogPathAttempt(ApplicationContext *pApplicationContext,
- PathString &assemblyPath)
- {
- HRESULT hr = S_OK;
- BindingLog *pBindingLog = pApplicationContext->GetBindingLog();
-
- if (pBindingLog->CanLog())
- {
- PathString tmp;
- PathString info;
-
- IF_FAIL_GO(tmp.LoadResourceAndReturnHR(CCompRC::Debugging,
- ID_FUSLOG_BINDING_LOG_PATH_ATTEMPT));
- info.Printf(tmp.GetUnicode(), assemblyPath.GetUnicode());
-
- IF_FAIL_GO(pBindingLog->Log(info));
- }
-
- Exit:
- return hr;
- }
#endif // FEATURE_VERSIONING_LOG
#ifndef CROSSGEN_COMPILE
+++ /dev/null
-// 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.
-// ============================================================
-//
-// BinderInterface.cpp
-//
-
-
-//
-// Implements the public AssemblyBinder interface
-//
-// ============================================================
-
-#include "assemblybinder.hpp"
-#include "assemblyname.hpp"
-#include "applicationcontext.hpp"
-#include "binderinterface.hpp"
-#include "bindresult.inl"
-#include "utils.hpp"
-
-#include "ex.h"
-
-using namespace BINDER_SPACE;
-
-namespace BinderInterface
-{
-
- HRESULT Init()
- {
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- hr = AssemblyBinder::Startup();
- }
- EX_CATCH_HRESULT(hr);
-
- return hr;
- }
-
- HRESULT SetupContext(LPCWSTR wszApplicationBase,
- DWORD dwAppDomainId,
- IUnknown **ppIApplicationContext)
- {
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- BINDER_LOG_LOCK();
- BINDER_LOG_ENTER(L"BinderInterface::SetupContext");
-
- // Verify input arguments
- IF_FALSE_GO(ppIApplicationContext != NULL);
-
- {
- ReleaseHolder<ApplicationContext> pApplicationContext;
-
- SAFE_NEW(pApplicationContext, ApplicationContext);
- IF_FAIL_GO(pApplicationContext->Init());
- pApplicationContext->SetAppDomainId(dwAppDomainId);
- *ppIApplicationContext = static_cast<IUnknown *>(pApplicationContext.Extract());
- }
-
- Exit:
- BINDER_LOG_LEAVE_HR(L"BinderInterface::SetupContext", hr);
- }
- EX_CATCH_HRESULT(hr);
-
- return hr;
- }
-
- // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
- // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
- // for an example of how they're used.
- HRESULT Bind(IUnknown *pIApplicationContext,
- SString &assemblyDisplayName,
- LPCWSTR wszCodeBase,
- PEAssembly *pParentAssembly,
- BOOL fNgenExplicitBind,
- BOOL fExplicitBindToNativeImage,
- BINDER_SPACE::Assembly **ppAssembly)
- {
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- BINDER_LOG_LOCK();
- BINDER_LOG_ENTER(L"BinderInterface::Bind");
-
- // Verify input arguments
- IF_FALSE_GO(pIApplicationContext != NULL);
- IF_FALSE_GO(ppAssembly != NULL);
-
- {
- ApplicationContext *pApplicationContext =
- static_cast<ApplicationContext *>(pIApplicationContext);
-
- ReleaseHolder<AssemblyName> pAssemblyName;
- if (!assemblyDisplayName.IsEmpty())
- {
- SAFE_NEW(pAssemblyName, AssemblyName);
- IF_FAIL_GO(pAssemblyName->Init(assemblyDisplayName));
- }
-
- IF_FAIL_GO(AssemblyBinder::BindAssembly(pApplicationContext,
- pAssemblyName,
- wszCodeBase,
- pParentAssembly,
- fNgenExplicitBind,
- fExplicitBindToNativeImage,
- false, // excludeAppPaths
- ppAssembly));
- }
-
- Exit:
- BINDER_LOG_LEAVE_HR(L"BinderInterface::Bind", hr);
- }
- EX_CATCH_HRESULT(hr);
-
- return hr;
- }
-
- HRESULT BindToSystem(SString &sSystemDirectory,
- BINDER_SPACE::Assembly **ppSystemAssembly,
- bool fBindToNativeImage)
- {
- HRESULT hr = S_OK;
-
- IF_FALSE_GO(ppSystemAssembly != NULL);
-
- EX_TRY
- {
- BINDER_LOG_LOCK();
-
- IF_FAIL_GO(AssemblyBinder::BindToSystem(sSystemDirectory, ppSystemAssembly, fBindToNativeImage));
- }
- EX_CATCH_HRESULT(hr);
-
- Exit:
- return hr;
- }
-
- HRESULT SetupBindingPaths(IUnknown *pIApplicationContext,
- SString &sTrustedPlatformAssemblies,
- SString &sPlatformResourceRoots,
- SString &sAppPaths,
- SString &sAppNiPaths)
- {
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- BINDER_LOG_LOCK();
- BINDER_LOG_ENTER(L"BinderInterface::SetupBindingPaths");
-
- // Verify input arguments
- IF_FALSE_GO(pIApplicationContext != NULL);
-
- {
- ApplicationContext *pApplicationContext =
- static_cast<ApplicationContext *>(pIApplicationContext);
- _ASSERTE(pApplicationContext != NULL);
-
- IF_FAIL_GO(pApplicationContext->SetupBindingPaths(sTrustedPlatformAssemblies, sPlatformResourceRoots, sAppPaths, sAppNiPaths, TRUE /* fAcquireLock */));
- }
-
- Exit:
- BINDER_LOG_LEAVE_HR(L"BinderInterface::SetupBindingPaths", hr);
- }
- EX_CATCH_HRESULT(hr);
-
- return hr;
- }
-
-#ifdef BINDER_DEBUG_LOG
- HRESULT Log(LPCWSTR wszMessage)
- {
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- BINDER_LOG_LOCK();
- BINDER_LOG((WCHAR *) wszMessage);
- }
- EX_CATCH_HRESULT(hr);
-
- return hr;
- }
-#endif // BINDER_DEBUG_LOG
-};
#include <strsafe.h>
#include "shlwapi.h"
-#include "binderinterface.hpp"
#include "assemblyidentity.hpp"
#include "textualidentityparser.hpp"
inline IMDInternalImport *GetMDImport();
inline void SetMDImport(IMDInternalImport *pMDImport);
- inline mdAssembly *GetAssemblyRefTokens();
-
- inline DWORD GetNbAssemblyRefTokens();
- inline void SetNbAsssemblyRefTokens(DWORD dwCAssemblyRefTokens);
LONG m_cRef;
PEImage *m_pPEImage;
PEImage *m_pNativePEImage;
IMDInternalImport *m_pMDImport;
- mdAssembly *m_pAssemblyRefTokens;
- DWORD m_dwCAssemblyRefTokens;
AssemblyName *m_pAssemblyName;
SString m_assemblyPath;
DWORD m_dwAssemblyFlags;
m_pMDImport->AddRef();
}
-mdAssembly *Assembly::GetAssemblyRefTokens()
-{
- return m_pAssemblyRefTokens;
-}
-
-DWORD Assembly::GetNbAssemblyRefTokens()
-{
- return m_dwCAssemblyRefTokens;
-}
-
-void Assembly::SetNbAsssemblyRefTokens(DWORD dwCAssemblyRefTokens)
-{
- m_dwCAssemblyRefTokens = dwCAssemblyRefTokens;
-}
-
BINDER_SPACE::Assembly* GetAssemblyFromPrivAssemblyFast(ICLRPrivAssembly *pPrivAssembly)
{
#ifdef _DEBUG
+++ /dev/null
-// 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.
-// ============================================================
-//
-// BinderInterface.hpp
-//
-
-
-//
-// Defines the public AssemblyBinder interface
-//
-// ============================================================
-
-#ifndef __BINDER_INTERFACE_HPP__
-#define __BINDER_INTERFACE_HPP__
-
-class PEImage;
-class PEAssembly;
-class StringArrayList;
-
-namespace BINDER_SPACE
-{
- class Assembly;
- class AssemblyIdentityUTF8;
-};
-
-namespace BinderInterface
-{
- HRESULT Init();
-
- HRESULT SetupContext(/* in */ LPCWSTR wszApplicationBase,
- /* in */ DWORD dwAppDomainId,
- /* out */ IUnknown **ppIApplicationContext);
-
- // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
- // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
- // for an example of how they're used.
- HRESULT Bind(/* in */ IUnknown *pIApplicationContext,
- /* in */ SString &assemblyDisplayName,
- /* in */ LPCWSTR wszCodeBase,
- /* in */ PEAssembly *pParentAssembly,
- /* in */ BOOL fNgenExplicitBind,
- /* in */ BOOL fExplicitBindToNativeImage,
- /*out */ BINDER_SPACE::Assembly **ppAssembly);
-
- //
- // Called via managed AppDomain.ExecuteAssembly variants and during binding host setup
- //
- HRESULT SetupBindingPaths(/* in */ IUnknown *pIApplicationContext,
- /* in */ SString &sTrustedPlatformAssemblies,
- /* in */ SString &sPlatformResourceRoots,
- /* in */ SString &sAppPaths,
- /* in */ SString &sAppNiPaths);
-
- //
- // Called via CoreAssemblySpec::BindToSystem
- //
- HRESULT BindToSystem(/* in */ SString &sSystemDirectory,
- /* out */ BINDER_SPACE::Assembly **ppSystemAssembly,
- /* in */ bool fBindToNativeImage);
-
-#ifdef BINDER_DEBUG_LOG
- HRESULT Log(/* in */ LPCWSTR wszMessage);
-#endif // BINDER_DEBUG_LOG
-
-};
-
-#endif
}
#endif // defined(FEATURE_COMINTEROP_APARTMENT_SUPPORT) && !defined(CROSSGEN_COMPILE)
-// Helper function to load an assembly. This is called from LoadCOMClass.
-/* static */
-
-Assembly *AppDomain::LoadAssemblyHelper(LPCWSTR wszAssembly,
- LPCWSTR wszCodeBase)
-{
- CONTRACT(Assembly *)
- {
- THROWS;
- POSTCONDITION(CheckPointer(RETVAL));
- PRECONDITION(wszAssembly || wszCodeBase);
- INJECT_FAULT(COMPlusThrowOM(););
- }
- CONTRACT_END;
-
- AssemblySpec spec;
- if(wszAssembly) {
- #define MAKE_TRANSLATIONFAILED { ThrowOutOfMemory(); }
- MAKE_UTF8PTR_FROMWIDE(szAssembly,wszAssembly);
- #undef MAKE_TRANSLATIONFAILED
-
- IfFailThrow(spec.Init(szAssembly));
- }
-
- if (wszCodeBase) {
- spec.SetCodeBase(wszCodeBase);
- }
- RETURN spec.LoadAssembly(FILE_LOADED);
-}
-
#if defined(FEATURE_CLASSIC_COMINTEROP) && !defined(CROSSGEN_COMPILE)
MethodTable *AppDomain::LoadCOMClass(GUID clsid,
void TryIncrementalLoad(DomainFile *pFile, FileLoadLevel workLevel, FileLoadLockHolder &lockHolder);
- Assembly *LoadAssemblyHelper(LPCWSTR wszAssembly,
- LPCWSTR wszCodeBase);
-
#ifndef DACCESS_COMPILE // needs AssemblySpec
void GetCacheAssemblyList(SetSHash<PTR_DomainAssembly>& assemblyList);
PEAssembly *TryResolveAssembly(AssemblySpec *pSpec);
- // Store a successful binding into the cache. This will keep the file from
- // being physically unmapped, as well as shortcutting future attempts to bind
- // the same spec throught the Cached entry point.
- //
- // Right now we only cache assembly binds for "probing" type
- // binding situations, basically when loading domain neutral assemblies or
- // zap files.
- //
- // <TODO>@todo: We may want to be more aggressive about this if
- // there are other situations where we are repeatedly binding the
- // same assembly specs, though.</TODO>
- //
- // Returns TRUE if stored
- // FALSE if it's a duplicate (caller should clean up args)
- BOOL StoreBindAssemblySpecResult(AssemblySpec *pSpec,
- PEAssembly *pFile,
- BOOL clone = TRUE);
-
- BOOL StoreBindAssemblySpecError(AssemblySpec *pSpec,
- HRESULT hr,
- OBJECTREF *pThrowable,
- BOOL clone = TRUE);
-
//****************************************************************************************
//
//****************************************************************************************