Skip to content

Commit

Permalink
Some cleanups in Assembly/Loader area (#57023)
Browse files Browse the repository at this point in the history
* rename GAC -> TPA

* remove GetAvailableImageTypes

* Removed ICLRPrivAssembly

* Move Assembly:: Add/Release to .inl

* ApplicationContext is not implementing IUnknown

* ApplicationContext does not need AppDomainId

* ICLRPrivBinder is not a COM object

* Assembly is not a binder and should not have BindAssemblyByName

* ApplicationContext is always an embedded value and does not need reference counting.

* Simplified GetBinderID and GetLoaderAllocator, since not COM

* Moved AppContext to up to ICLRPrivBinder

* Removed GetBinderHash

* Removed a couple now pointless AddRef/Release

* virtualized BindUsingAssemblyName

* renamed ICLRPrivBinder --> AssemblyBinder

* renamed BINDER_SPACE::AssemblyBinder --> BINDER_SPACE::AssemblyBinderCommon

* Merge CCoreCLRBinderHelper into AssemblyBinderCommon

* Rename CLRPrivBinderCoreCLR -->DefaultAssemblyBinder

* Renamed CLRPrivBinderAssemblyLoadContext  -->  CustomAssemblyBinder

* Renamed PTR_ICLRPrivBinder --> PTR_AssemblyBinder

* Remove clrprivbinding_i.cpp

* A few touch ups

* fix Linux build
  • Loading branch information
VSadov authored Aug 18, 2021
1 parent 797f161 commit 7f85a8c
Show file tree
Hide file tree
Showing 67 changed files with 684 additions and 1,531 deletions.
14 changes: 6 additions & 8 deletions src/coreclr/binder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ include_directories(BEFORE "inc")
set(BINDER_COMMON_SOURCES
applicationcontext.cpp
assembly.cpp
assemblybinder.cpp
assemblybindercommon.cpp
assemblyidentitycache.cpp
assemblyname.cpp
bindertracing.cpp
clrprivbindercoreclr.cpp
coreclrbindercommon.cpp
defaultassemblybinder.cpp
failurecache.cpp
stringlexer.cpp
textualidentityparser.cpp
Expand All @@ -23,7 +22,7 @@ set(BINDER_COMMON_HEADERS
inc/applicationcontext.inl
inc/assembly.hpp
inc/assembly.inl
inc/assemblybinder.hpp
inc/assemblybindercommon.hpp
inc/assemblyentry.hpp
inc/assemblyhashtraits.hpp
inc/assemblyidentity.hpp
Expand All @@ -36,8 +35,7 @@ set(BINDER_COMMON_HEADERS
inc/bindertracing.h
inc/bindresult.hpp
inc/bindresult.inl
inc/clrprivbindercoreclr.h
inc/coreclrbindercommon.h
inc/defaultassemblybinder.h
inc/failurecache.hpp
inc/failurecachehashtraits.hpp
inc/loadcontext.hpp
Expand All @@ -51,13 +49,13 @@ set(BINDER_COMMON_HEADERS
set(BINDER_SOURCES
${BINDER_COMMON_SOURCES}
activitytracker.cpp
clrprivbinderassemblyloadcontext.cpp
customassemblybinder.cpp
)

set(BINDER_HEADERS
${BINDER_COMMON_HEADERS}
inc/activitytracker.h
inc/clrprivbinderassemblyloadcontext.h
inc/customassemblybinder.h
inc/contextentry.hpp
)

Expand Down
53 changes: 3 additions & 50 deletions src/coreclr/binder/applicationcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,17 @@ using namespace clr::fs;

namespace BINDER_SPACE
{
STDMETHODIMP ApplicationContext::QueryInterface(REFIID riid,
void **ppv)
{
HRESULT hr = S_OK;

if (ppv == NULL)
{
hr = E_POINTER;
}
else
{
if (IsEqualIID(riid, IID_IUnknown))
{
AddRef();
*ppv = static_cast<IUnknown *>(this);
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}
}

return hr;
}

STDMETHODIMP_(ULONG) ApplicationContext::AddRef()
{
return InterlockedIncrement(&m_cRef);
}

STDMETHODIMP_(ULONG) ApplicationContext::Release()
{
ULONG ulRef = InterlockedDecrement(&m_cRef);

if (ulRef == 0)
{
delete this;
}

return ulRef;
}

ApplicationContext::ApplicationContext()
{
m_cRef = 1;
m_dwAppDomainId = 0;
m_pExecutionContext = NULL;
m_pFailureCache = NULL;
m_contextCS = NULL;
m_pTrustedPlatformAssemblyMap = nullptr;
m_binderID = 0;
}

ApplicationContext::~ApplicationContext()
{
SAFE_RELEASE(m_pExecutionContext);
SAFE_DELETE(m_pExecutionContext);
SAFE_DELETE(m_pFailureCache);

if (m_contextCS != NULL)
Expand All @@ -93,11 +47,11 @@ namespace BINDER_SPACE
}
}

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

ReleaseHolder<ExecutionContext> pExecutionContext;
NewHolder<ExecutionContext> pExecutionContext;

FailureCache *pFailureCache = NULL;

Expand All @@ -121,7 +75,6 @@ namespace BINDER_SPACE
m_pFailureCache = pFailureCache;
}

m_binderID = binderID;
Exit:
return hr;
}
Expand Down
78 changes: 6 additions & 72 deletions src/coreclr/binder/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,6 @@ namespace BINDER_SPACE
}
};

STDMETHODIMP Assembly::QueryInterface(REFIID riid,
void **ppv)
{
HRESULT hr = S_OK;

if (ppv == NULL)
{
hr = E_POINTER;
}
else
{
if (IsEqualIID(riid, IID_IUnknown))
{
AddRef();
*ppv = static_cast<IUnknown *>(this);
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}
}

return hr;
}

STDMETHODIMP_(ULONG) Assembly::AddRef()
{
return InterlockedIncrement(&m_cRef);
}

STDMETHODIMP_(ULONG) Assembly::Release()
{
ULONG ulRef = InterlockedDecrement(&m_cRef);

if (ulRef == 0)
{
delete this;
}

return ulRef;
}

Assembly::Assembly()
{
m_cRef = 1;
Expand Down Expand Up @@ -103,7 +60,7 @@ namespace BINDER_SPACE
PEImage *pPEImage,
PEImage *pNativePEImage,
SString &assemblyPath,
BOOL fIsInGAC)
BOOL fIsInTPA)
{
HRESULT hr = S_OK;

Expand All @@ -113,15 +70,15 @@ namespace BINDER_SPACE
// Get assembly name def from meta data import and store it for later refs access
IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind));
SetMDImport(pIMetaDataAssemblyImport);
if (!fIsInGAC)
if (!fIsInTPA)
{
GetPath().Set(assemblyPath);
}

// Safe architecture for validation
PEKIND kAssemblyArchitecture;
kAssemblyArchitecture = pAssemblyName->GetArchitecture();
SetIsInGAC(fIsInGAC);
SetIsInTPA(fIsInTPA);
SetPEImage(pPEImage);
SetNativePEImage(pNativePEImage);
pAssemblyName->SetIsDefinition(TRUE);
Expand Down Expand Up @@ -174,40 +131,17 @@ namespace BINDER_SPACE
}

// --------------------------------------------------------------------
// ICLRPrivAssembly methods
// BINDER_SPACE::Assembly methods
// --------------------------------------------------------------------
LPCWSTR Assembly::GetSimpleName()
{
AssemblyName *pAsmName = GetAssemblyName();
return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName());
}

HRESULT Assembly::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly ** ppAssembly)
{
return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyNameData, ppAssembly);
}

HRESULT Assembly::GetBinderID(UINT_PTR *pBinderId)
{
return (m_pBinder == NULL) ? E_FAIL : m_pBinder->GetBinderID(pBinderId);
}

HRESULT Assembly::GetLoaderAllocator(LPVOID* pLoaderAllocator)
{
return (m_pBinder == NULL) ? E_FAIL : m_pBinder->GetLoaderAllocator(pLoaderAllocator);
}

HRESULT Assembly::GetAvailableImageTypes(
LPDWORD pdwImageTypes)
AssemblyLoaderAllocator* Assembly::GetLoaderAllocator()
{
HRESULT hr = E_FAIL;

if(pdwImageTypes == nullptr)
return E_INVALIDARG;

*pdwImageTypes = ASSEMBLY_IMAGE_TYPE_ASSEMBLY;

return S_OK;
return m_pBinder ? m_pBinder->GetLoaderAllocator() : NULL;
}
}

Loading

0 comments on commit 7f85a8c

Please sign in to comment.