Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
be13383
rename GAC -> TPA
VSadov Aug 6, 2021
440bd6e
remove GetAvailableImageTypes
VSadov Aug 7, 2021
081f08c
Removed ICLRPrivAssembly
VSadov Aug 7, 2021
27d414c
Move Assembly:: Add/Release to .inl
VSadov Aug 7, 2021
767ef95
ApplicationContext is not implementing IUnknown
VSadov Aug 13, 2021
a984bd5
ApplicationContext does not need AppDomainId
VSadov Aug 13, 2021
5b2218c
ICLRPrivBinder is not a COM object
VSadov Aug 13, 2021
68a9b4c
Assembly is not a binder and should not have BindAssemblyByName
VSadov Aug 14, 2021
24ca380
ApplicationContext is always an embedded value and does not need refe…
VSadov Aug 14, 2021
6ed1653
Simplified GetBinderID and GetLoaderAllocator, since not COM
VSadov Aug 14, 2021
d435108
Moved AppContext to up to ICLRPrivBinder
VSadov Aug 16, 2021
eb3bc8e
Removed GetBinderHash
VSadov Aug 16, 2021
331eccb
Removed a couple now pointless AddRef/Release
VSadov Aug 16, 2021
a186ca4
virtualized BindUsingAssemblyName
VSadov Aug 16, 2021
a616b18
renamed ICLRPrivBinder --> AssemblyBinder
VSadov Aug 16, 2021
63ef26b
renamed BINDER_SPACE::AssemblyBinder --> BINDER_SPACE::AssemblyBinder…
VSadov Aug 16, 2021
8d61a2d
Merge CCoreCLRBinderHelper into AssemblyBinderCommon
VSadov Aug 16, 2021
61068b0
Rename CLRPrivBinderCoreCLR -->DefaultAssemblyBinder
VSadov Aug 16, 2021
f1ee77f
Renamed CLRPrivBinderAssemblyLoadContext --> CustomAssemblyBinder
VSadov Aug 16, 2021
9920bc9
Renamed PTR_ICLRPrivBinder --> PTR_AssemblyBinder
VSadov Aug 16, 2021
6cc9cef
Remove clrprivbinding_i.cpp
VSadov Aug 16, 2021
babbcd2
A few touch ups
VSadov Aug 16, 2021
b241939
fix Linux build
VSadov Aug 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed GetBinderHash
  • Loading branch information
VSadov committed Aug 18, 2021
commit eb3bc8ee9b9c0cecb3f44137a44cdecbbb0bea3e
4 changes: 1 addition & 3 deletions src/coreclr/binder/applicationcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace BINDER_SPACE
m_pFailureCache = NULL;
m_contextCS = NULL;
m_pTrustedPlatformAssemblyMap = nullptr;
m_binderID = 0;
}

ApplicationContext::~ApplicationContext()
Expand All @@ -48,7 +47,7 @@ namespace BINDER_SPACE
}
}

HRESULT ApplicationContext::Init(UINT_PTR binderID)
HRESULT ApplicationContext::Init()
{
HRESULT hr = S_OK;

Expand Down Expand Up @@ -76,7 +75,6 @@ namespace BINDER_SPACE
m_pFailureCache = pFailureCache;
}

m_binderID = binderID;
Exit:
return hr;
}
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/binder/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ namespace BINDER_SPACE
return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName());
}

UINT_PTR Assembly::GetBinderID()
{
return m_pBinder ? m_pBinder->GetBinderID() : 0;
}

AssemblyLoaderAllocator* Assembly::GetLoaderAllocator()
{
return m_pBinder ? m_pBinder->GetLoaderAllocator() : NULL;
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/binder/assemblybinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace BINDER_SPACE
// 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 AssemblyBinder::BindAssembly(/* in */ ApplicationContext *pApplicationContext,
HRESULT AssemblyBinder::BindAssembly(/* in */ ICLRPrivBinder *pBinder,
/* in */ AssemblyName *pAssemblyName,
/* in */ LPCWSTR szCodeBase,
/* in */ PEAssembly *pParentAssembly,
Expand All @@ -261,9 +261,10 @@ namespace BINDER_SPACE
HRESULT hr = S_OK;
LONG kContextVersion = 0;
BindResult bindResult;
ApplicationContext* pApplicationContext = pBinder->GetAppContext();

// Tracing happens outside the binder lock to avoid calling into managed code within the lock
BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pApplicationContext->GetBinderID(), 0 /*managedALC*/, hr};
BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pBinder, 0 /*managedALC*/, hr};

#ifndef CROSSGEN_COMPILE
Retry:
Expand Down Expand Up @@ -1428,7 +1429,7 @@ HRESULT AssemblyBinder::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedA
}

/* static */
HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicationContext,
HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ICLRPrivBinder* pBinder,
/* in */ BINDER_SPACE::AssemblyName *pAssemblyName,
/* in */ PEImage *pPEImage,
/* in */ PEKIND peKind,
Expand All @@ -1442,9 +1443,10 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat

// Prepare binding data
*ppAssembly = NULL;
ApplicationContext* pApplicationContext = pBinder->GetAppContext();

// Tracing happens outside the binder lock to avoid calling into managed code within the lock
BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pApplicationContext->GetBinderID(), 0 /*managedALC*/, hr};
BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pBinder, 0 /*managedALC*/, hr};

// Attempt the actual bind (eventually more than once)
Retry:
Expand Down
23 changes: 8 additions & 15 deletions src/coreclr/binder/bindertracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ namespace
#endif // CROSSGEN_COMPILE
}

void GetAssemblyLoadContextNameFromBinderID(UINT_PTR binderID, AppDomain *domain, /*out*/ SString &alcName)
void GetAssemblyLoadContextNameFromBindContext(ICLRPrivBinder *bindContext, AppDomain *domain, /*out*/ SString &alcName)
{
ICLRPrivBinder *binder = reinterpret_cast<ICLRPrivBinder *>(binderID);
if (binder == domain->GetTPABinderContext())
_ASSERTE(bindContext != nullptr);

if (bindContext == domain->GetTPABinderContext())
{
alcName.Set(W("Default"));
}
Expand All @@ -123,21 +124,13 @@ namespace
#ifdef CROSSGEN_COMPILE
GetAssemblyLoadContextNameFromManagedALC(0, alcName);
#else // CROSSGEN_COMPILE
CLRPrivBinderAssemblyLoadContext *alcBinder = static_cast<CLRPrivBinderAssemblyLoadContext *>(binder);
CLRPrivBinderAssemblyLoadContext* alcBinder = static_cast<CLRPrivBinderAssemblyLoadContext*>(bindContext);

GetAssemblyLoadContextNameFromManagedALC(alcBinder->GetManagedAssemblyLoadContext(), alcName);
#endif // CROSSGEN_COMPILE
}
}

void GetAssemblyLoadContextNameFromBindContext(ICLRPrivBinder *bindContext, AppDomain *domain, /*out*/ SString &alcName)
{
_ASSERTE(bindContext != nullptr);

UINT_PTR binderID = bindContext->GetBinderID();
GetAssemblyLoadContextNameFromBinderID(binderID, domain, alcName);
}

void GetAssemblyLoadContextNameFromSpec(AssemblySpec *spec, /*out*/ SString &alcName)
{
_ASSERTE(spec != nullptr);
Expand Down Expand Up @@ -256,14 +249,14 @@ namespace BinderTracing

namespace BinderTracing
{
ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, UINT_PTR binderID, INT_PTR managedALC, const HRESULT& hr)
ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, ICLRPrivBinder* bindContext, INT_PTR managedALC, const HRESULT& hr)
: m_hr { hr }
, m_stage { Stage::NotYetStarted }
, m_tracingEnabled { BinderTracing::IsEnabled() }
, m_assemblyNameObject { assemblyName }
, m_pFoundAssembly { nullptr }
{
_ASSERTE(binderID != 0 || managedALC != 0);
_ASSERTE(bindContext != nullptr || managedALC != 0);

if (!m_tracingEnabled)
return;
Expand All @@ -279,7 +272,7 @@ namespace BinderTracing
}
else
{
GetAssemblyLoadContextNameFromBinderID(binderID, GetAppDomain(), m_assemblyLoadContextName);
GetAssemblyLoadContextNameFromBindContext(bindContext, GetAppDomain(), m_assemblyLoadContextName);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE:
#endif

// Do we have the assembly already loaded in the context of the current binder?
hr = AssemblyBinder::BindAssembly(GetAppContext(),
hr = AssemblyBinder::BindAssembly(this,
pAssemblyName,
NULL,
NULL,
Expand Down Expand Up @@ -150,7 +150,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pP
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND));
}

hr = AssemblyBinder::BindUsingPEImage(GetAppContext(), pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly);
hr = AssemblyBinder::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly);
if (hr == S_OK)
{
_ASSERTE(pCoreCLRFoundAssembly != NULL);
Expand Down Expand Up @@ -190,8 +190,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(CLRPrivBinderCoreCLR *pTP
ReleaseHolder<CLRPrivBinderAssemblyLoadContext> pBinder;

SAFE_NEW(pBinder, CLRPrivBinderAssemblyLoadContext);
UINT_PTR binderId = pBinder->GetBinderID();
hr = pBinder->GetAppContext()->Init(binderId);
hr = pBinder->GetAppContext()->Init();
if(SUCCEEDED(hr))
{
// Save reference to the TPABinder that is required to be present.
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/binder/clrprivbindercoreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam
_ASSERTE(!pAssemblyName->IsCoreLib());
#endif

hr = AssemblyBinder::BindAssembly(GetAppContext(),
hr = AssemblyBinder::BindAssembly(this,
pAssemblyName,
NULL,
NULL,
Expand Down Expand Up @@ -190,7 +190,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage,
}
}

hr = AssemblyBinder::BindUsingPEImage(GetAppContext(), pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly);
hr = AssemblyBinder::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly);
if (hr == S_OK)
{
_ASSERTE(pCoreCLRFoundAssembly != NULL);
Expand Down Expand Up @@ -235,7 +235,7 @@ HRESULT CLRPrivBinderCoreCLR::Bind(LPCWSTR wszCodeBase,
EX_TRY
{
ReleaseHolder<BINDER_SPACE::Assembly> pAsm;
hr = AssemblyBinder::BindAssembly(GetAppContext(),
hr = AssemblyBinder::BindAssembly(this,
NULL,
wszCodeBase,
pParentAssembly,
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/binder/coreclrbindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ HRESULT CCoreCLRBinderHelper::DefaultBinderSetupContext(CLRPrivBinderCoreCLR **p
SAFE_NEW(pBinder, CLRPrivBinderCoreCLR);

BINDER_SPACE::ApplicationContext *pApplicationContext = pBinder->GetAppContext();
UINT_PTR binderId = pBinder->GetBinderID();
hr = pApplicationContext->Init(binderId);
hr = pApplicationContext->Init();
if(SUCCEEDED(hr))
{
pBinder->SetManagedAssemblyLoadContext(NULL);
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/binder/inc/applicationcontext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace BINDER_SPACE
// ApplicationContext methods
ApplicationContext();
~ApplicationContext();
HRESULT Init(UINT_PTR binderID);
HRESULT Init();

inline SString &GetApplicationName();

Expand Down Expand Up @@ -114,8 +114,6 @@ namespace BINDER_SPACE
inline LONG GetVersion();
inline void IncrementVersion();

UINT_PTR GetBinderID() { return m_binderID; }

private:
Volatile<LONG> m_cVersion;
SString m_applicationName;
Expand All @@ -130,8 +128,6 @@ namespace BINDER_SPACE
StringArrayList m_appNiPaths;

SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap;

UINT_PTR m_binderID;
};

#include "applicationcontext.inl"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/binder/inc/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace BINDER_SPACE
ULONG Release();

LPCWSTR GetSimpleName();
UINT_PTR GetBinderID();
AssemblyLoaderAllocator* GetLoaderAllocator();

// --------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/binder/inc/assemblybinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "bindresult.hpp"
#include "bundle.h"

class ICLRPrivBinder;
class CLRPrivBinderCoreCLR;
class PEAssembly;
class PEImage;
Expand All @@ -30,7 +31,7 @@ namespace BINDER_SPACE
// 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.
static HRESULT BindAssembly(/* in */ ApplicationContext *pApplicationContext,
static HRESULT BindAssembly(/* in */ ICLRPrivBinder *pBinder,
/* in */ AssemblyName *pAssemblyName,
/* in */ LPCWSTR szCodeBase,
/* in */ PEAssembly *pParentAssembly,
Expand Down Expand Up @@ -61,7 +62,7 @@ namespace BINDER_SPACE
/* in */ CLRPrivBinderCoreCLR *pTPABinder,
/* out */ Assembly **ppAssembly);

static HRESULT BindUsingPEImage(/* in */ ApplicationContext *pApplicationContext,
static HRESULT BindUsingPEImage(/* in */ ICLRPrivBinder *pBinder,
/* in */ BINDER_SPACE::AssemblyName *pAssemblyName,
/* in */ PEImage *pPEImage,
/* in */ PEKIND peKind,
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/binder/inc/bindertracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ namespace BinderTracing
static void TraceAppDomainAssemblyResolve(AssemblySpec *spec, PEAssembly *resultAssembly, Exception *exception = nullptr);

public:
// One of binder ID and managed ALC is expected to be non-zero. If the managed ALC is set, binder ID is ignored.
ResolutionAttemptedOperation(BINDER_SPACE::AssemblyName *assemblyName, UINT_PTR binderId, INT_PTR managedALC, const HRESULT& hr);
// One of native bindContext or managedALC is expected to be non-zero. If the managed ALC is set, bindContext is ignored.
ResolutionAttemptedOperation(BINDER_SPACE::AssemblyName *assemblyName, ICLRPrivBinder* bindContext, INT_PTR managedALC, const HRESULT& hr);

void TraceBindResult(const BINDER_SPACE::BindResult &bindResult, bool mvidMismatch = false);

Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/vm/assemblyloadcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ class ICLRPrivBinder
**********************************************************************************/
virtual AssemblyLoaderAllocator* GetLoaderAllocator() = 0;

/**********************************************************************************
** GetBinderID
** pBinderId, pointer to binder id. The binder id has the following properties
** It is a pointer that does not change over the lifetime of a binder object
** It points at an object in memory that will remain allocated for the lifetime of the binder.
** This value should be the same for a set of binder objects that represent the same binder behavior.
**********************************************************************************/
UINT_PTR GetBinderID()
{
return reinterpret_cast<UINT_PTR>(this);
}

inline BINDER_SPACE::ApplicationContext* GetAppContext()
{
return &m_appContext;
Expand Down
15 changes: 5 additions & 10 deletions src/coreclr/vm/assemblyspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,6 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter
CONTRACTL_END;

UPTR key = (UPTR)pSpec->Hash();
UPTR lookupKey = key;

// On CoreCLR, we will use the BinderID as the key
ICLRPrivBinder *pBinderContextForLookup = NULL;
Expand Down Expand Up @@ -1044,11 +1043,10 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter

if (pBinderContextForLookup)
{
UINT_PTR binderID = pBinderContextForLookup->GetBinderID();
lookupKey = key^binderID;
key = key ^ (UPTR)pBinderContextForLookup;
}

AssemblyBinding* pEntry = (AssemblyBinding *)m_map.LookupValue(lookupKey, pSpec);
AssemblyBinding* pEntry = (AssemblyBinding *)m_map.LookupValue(key, pSpec);

// Reset the binding context if one was originally never present in the AssemblySpec and we didnt find any entry
// in the cache.
Expand Down Expand Up @@ -1260,8 +1258,7 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly
_ASSERTE(pBinderContextForLookup || pAssembly->GetFile()->IsSystem());
if (pBinderContextForLookup)
{
UINT_PTR binderID = pBinderContextForLookup->GetBinderID();
key = key^binderID;
key = key ^ (UPTR)pBinderContextForLookup;

if (!pSpec->GetBindingContext())
{
Expand Down Expand Up @@ -1343,8 +1340,7 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile)
_ASSERTE(pBinderContextForLookup || pFile->IsSystem());
if (pBinderContextForLookup)
{
UINT_PTR binderID = pBinderContextForLookup->GetBinderID();
key = key^binderID;
key = key ^ (UPTR)pBinderContextForLookup;

if (!pSpec->GetBindingContext())
{
Expand Down Expand Up @@ -1436,8 +1432,7 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE
if (!pSpec->IsAssemblySpecForCoreLib())
{
pBinderToSaveException = pSpec->GetBindingContextFromParentAssembly(pSpec->GetAppDomain());
UINT_PTR binderID = pBinderToSaveException->GetBinderID();
key = key^binderID;
key = key ^ (UPTR)pBinderToSaveException;
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/nativelibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ namespace
return NULL;
}

UINT_PTR assemblyBinderID = pBindingContext->GetBinderID();
ICLRPrivBinder *pCurrentBinder = reinterpret_cast<ICLRPrivBinder *>(assemblyBinderID);
ICLRPrivBinder *pCurrentBinder = pBindingContext;

// For assemblies bound via TPA binder, we should use the standard mechanism to make the pinvoke call.
if (pCurrentBinder == pTPABinder)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/vm/pefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ BOOL PEFile::Equals(PEFile *pFile)
// because another thread beats it; the losing thread will pick up the PEAssembly in the cache.
if (pFile->HasHostAssembly() && this->HasHostAssembly())
{
UINT_PTR fileBinderId = pFile->GetHostAssembly()->GetBinderID();
UINT_PTR thisBinderId = this->GetHostAssembly()->GetBinderID();
ICLRPrivBinder* fileBinderId = pFile->GetHostAssembly()->GetBinder();
ICLRPrivBinder* thisBinderId = this->GetHostAssembly()->GetBinder();

if (fileBinderId != thisBinderId || fileBinderId == 0)
if (fileBinderId != thisBinderId || fileBinderId == NULL)
return FALSE;
}

Expand Down