Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 1 addition & 7 deletions src/coreclr/vm/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Assembly
static Assembly *Create(PEAssembly *pPEAssembly, AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocator);
static void Initialize();

BOOL IsSystem() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->IsSystem(); }
bool IsSystem() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->IsSystem(); }

static Assembly* CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNameParts* pAssemblyNameParts, INT32 hashAlgorithm, INT32 access, LOADERALLOCATORREF* pKeepAlive);

Expand Down Expand Up @@ -211,12 +211,6 @@ class Assembly
return GetPEAssembly()->GetSimpleName();
}

BOOL IsStrongNamed()
{
WRAPPER_NO_CONTRACT;
return GetPEAssembly()->IsStrongNamed();
}

const void *GetPublicKey(DWORD *pcbPK)
{
WRAPPER_NO_CONTRACT;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pIma
}
}

PEAssemblyHolder pPEAssembly(PEAssembly::Open(pAssembly->GetPEImage(), pAssembly));
PEAssemblyHolder pPEAssembly(PEAssembly::Open(pAssembly));
bindOperation.SetResult(pPEAssembly);

return pCurDomain->LoadAssembly(&spec, pPEAssembly, FILE_LOADED);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/ceeload.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ class Module : public ModuleBase
#endif

BOOL IsReflectionEmit() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return (m_dwTransientFlags & IS_REFLECTION_EMIT) != 0; }
BOOL IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_pPEAssembly->IsSystem(); }
bool IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_pPEAssembly->IsSystem(); }

virtual BOOL IsEditAndContinueCapable() const { return FALSE; }

Expand Down
84 changes: 26 additions & 58 deletions src/coreclr/vm/peassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,36 +639,34 @@ ULONG PEAssembly::GetPEImageTimeDateStamp()
#ifndef DACCESS_COMPILE

PEAssembly::PEAssembly(
BINDER_SPACE::Assembly* pBindResultInfo,
BINDER_SPACE::Assembly* pBoundAssembly,
IMetaDataEmit* pEmit,
BOOL isSystem,
AssemblyBinder* pDynamicAssemblyBinder /*= NULL*/,
PEImage * pPEImage /*= NULL*/,
BINDER_SPACE::Assembly * pHostAssembly /*= NULL*/)
AssemblyBinder* pDynamicAssemblyBinder /*= NULL*/)
:
#ifdef LOGGING
m_pDebugName{NULL},
#endif // LOGGING
m_PEImage{NULL}
, m_MDImportIsRW_Debugger_Use_Only{FALSE}
, m_pMDImport{NULL}
, m_pImporter{NULL}
, m_pEmitter{NULL}
, m_refCount{1}
, m_pHostAssembly{nullptr}
, m_pAssemblyBinder{nullptr}
{
CONTRACTL
{
PRECONDITION(CheckPointer(pEmit, NULL_OK));
PRECONDITION(pBindResultInfo == NULL || pPEImage == NULL);
// A PEAssembly is either bound by an AssemblyBinder or dynamic (reflection emit)
PRECONDITION((pBoundAssembly == NULL) != (pEmit == NULL));
// A bound assembly takes its binder from the bind result, not from a caller.
PRECONDITION(pBoundAssembly == NULL || pDynamicAssemblyBinder == NULL);
STANDARD_VM_CHECK;
}
CONTRACTL_END;

#ifdef LOGGING
m_pDebugName = NULL;
#endif // LOGGING
m_PEImage = NULL;
m_MDImportIsRW_Debugger_Use_Only = FALSE;
m_pMDImport = NULL;
m_pImporter = NULL;
m_pEmitter = NULL;
m_refCount = 1;
m_isSystem = isSystem;
m_pHostAssembly = nullptr;
m_pAssemblyBinder = nullptr;

pPEImage = pBindResultInfo ? pBindResultInfo->GetPEImage() : pPEImage;
if (pPEImage)
PEImage* pPEImage = pBoundAssembly ? pBoundAssembly->GetPEImage() : NULL;
if (pPEImage != NULL)
{
_ASSERTE(pPEImage->CheckUniqueInstance());
pPEImage->AddRef();
Expand Down Expand Up @@ -704,21 +702,9 @@ PEAssembly::PEAssembly(

// Set the host assembly and binding context as the AssemblySpec initialization
// for CoreCLR will expect to have it set.
if (pHostAssembly != nullptr)
{
m_pHostAssembly = clr::SafeAddRef(pHostAssembly);
}

if(pBindResultInfo != nullptr)
{
// Cannot have both pHostAssembly and a coreclr based bind
_ASSERTE(pHostAssembly == nullptr);
pBindResultInfo = clr::SafeAddRef(pBindResultInfo);
m_pHostAssembly = pBindResultInfo;
}

if (m_pHostAssembly != nullptr)
if (pBoundAssembly != nullptr)
{
m_pHostAssembly = clr::SafeAddRef(pBoundAssembly);
m_pAssemblyBinder = m_pHostAssembly->GetBinder();
}
else
Expand All @@ -734,24 +720,6 @@ PEAssembly::PEAssembly(
#endif // !DACCESS_COMPILE


PEAssembly *PEAssembly::Open(
PEImage * pPEImageIL,
BINDER_SPACE::Assembly * pHostAssembly)
{
STANDARD_VM_CONTRACT;

PEAssembly * pPEAssembly = new PEAssembly(
nullptr, // BindResult
nullptr, // IMetaDataEmit
FALSE, // isSystem
nullptr, // DynamicAssemblyBinder
pPEImageIL,
pHostAssembly);

return pPEAssembly;
}


PEAssembly::~PEAssembly()
{
CONTRACTL
Expand Down Expand Up @@ -828,12 +796,12 @@ PEAssembly *PEAssembly::DoOpenSystem()
ReleaseHolder<BINDER_SPACE::Assembly> pBoundAssembly;
IfFailThrow(GetAppDomain()->GetDefaultBinder()->BindToSystem(&pBoundAssembly));

return new PEAssembly(pBoundAssembly, NULL, TRUE);
return new PEAssembly(pBoundAssembly, NULL);
}

PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBindResult)
PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBoundAssembly)
{
return new PEAssembly(pBindResult,NULL,/*isSystem*/ false);
return new PEAssembly(pBoundAssembly, NULL);
};

/* static */
Expand All @@ -850,7 +818,7 @@ PEAssembly *PEAssembly::Create(IMetaDataAssemblyEmit *pAssemblyEmit, AssemblyBin
// we have.)
ReleaseHolder<IMetaDataEmit> pEmit;
pAssemblyEmit->QueryInterface(IID_IMetaDataEmit, (void **)&pEmit);
return new PEAssembly(NULL, pEmit, FALSE, pDynamicAssemblyBinder);
return new PEAssembly(NULL, pEmit, pDynamicAssemblyBinder);
}

#endif // #ifndef DACCESS_COMPILE
Expand Down
69 changes: 19 additions & 50 deletions src/coreclr/vm/peassembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,41 @@
#include "sstring.h"
#include "peimage.h"
#include "metadata.h"
#include "corhlpr.h"
#include "utilcode.h"
#include "loaderheap.h"
#include "sstring.h"
#include "ex.h"
#include "assemblyspecbase.h"
#include "../binder/inc/assembly.hpp"
#include "eecontract.h"
Comment thread
elinor-fung marked this conversation as resolved.
#include "stackwalktypes.h"
#include <specstrings.h>
#include "slist.h"
#include "eventtrace.h"

#include "assemblybinderutil.h"

// --------------------------------------------------------------------------------
// Forward declared classes
// --------------------------------------------------------------------------------

class Module;
class EditAndContinueModule;

class PEAssembly;
class SimpleRWLock;

typedef DPTR(PEAssembly) PTR_PEAssembly;

// --------------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// A PEAssembly is an input to the CLR loader. It is produced as a result of
// binding, usually through fusion (although there are a few less common methods to
// obtain one which do not go through fusion, e.g. IJW loads)
// A PEAssembly is an input to the CLR loader. It is produced as a result of binding.
//
// Although a PEAssembly is usually a disk based PE file, it is not
// always the case. Thus it is a conscious decision to not export access to the PE
// file directly; rather the specific information required should be provided via
// individual query API.
//
// There are multiple "flavors" of PEAssemblies:
// A PEAssembly is one of two kinds, distinguished by IsReflectionEmit():
//
// 1. HMODULE - these PE Files are loaded in response to "spontaneous" OS callbacks.
// These should only occur for .exe main modules and IJW dlls loaded via LoadLibrary
// or static imports in umnanaged code.
// These get their PEImage loaded directly in PEImage::CreateFromHMODULE(HMODULE hMod)
// 1. Bound to a PE image - the result of an AssemblyBinder bind
// It holds the BINDER_SPACE::Assembly that the binder produced, and takes
// both its PEImage and its metadata from that bind result.
//
// 2. Assemblies loaded directly or indirectly by the managed code - these are the most
// common case. A path is obtained from assembly binding and the result is loaded
// via PEImage:
// a. Display name loads - these are metadata-based binds
// b. Path loads - these are loaded from an explicit path
// The PEImage may come from:
// - File on disk - loaded via binding to an assembly name or an explicit path
// - Byte array - via an API such as AssemblyLoadContext.LoadFromStream
// - HMODULE - IJW module already loaded into memory by the OS (Windows)
// The source of the PEImage does not change the PEAssembly itself.
//
// 3. Byte arrays - loaded explicitly by user code. These also go through PEImage.
//
// 4. Dynamic - these are not actual PE images at all, but are placeholders
// for reflection-based modules.
// 2. Dynamic - a reflection emit assembly
// It has no PEImage. Its metadata comes from an IMetaDataEmit and it uses the binder
// of the assembly that created it.
//
// See also file:..\inc\corhdr.h#ManagedHeader for more on the format of managed images.
// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -151,7 +129,7 @@ class PEAssembly final
// Classification
// ------------------------------------------------------------

BOOL IsSystem() const;
bool IsSystem() const;
BOOL IsReflectionEmit() const;

// ------------------------------------------------------------
Expand All @@ -177,7 +155,6 @@ class PEAssembly final
void GetMVID(GUID* pMvid);
ULONG GetHashAlgId();
HRESULT GetVersion(USHORT* pMajor, USHORT* pMinor, USHORT* pBuild, USHORT* pRevision);
BOOL IsStrongNamed();
LPCUTF8 GetSimpleName();
HRESULT GetScopeName(LPCUTF8 * pszName);
const void *GetPublicKey(DWORD *pcbPK);
Expand Down Expand Up @@ -321,14 +298,10 @@ class PEAssembly final
// Creation entry points
// ------------------------------------------------------------

static PEAssembly* Open(
PEImage* pPEImageIL,
BINDER_SPACE::Assembly* pHostAssembly);

// This opens the canonical System.Private.CoreLib.dll
static PEAssembly* OpenSystem();

static PEAssembly* Open(BINDER_SPACE::Assembly* pBindResult);
static PEAssembly* Open(BINDER_SPACE::Assembly* pBoundAssembly);

static PEAssembly* Create(IMetaDataAssemblyEmit* pEmit, AssemblyBinder* pDynamicAssemblyBinder);

Expand All @@ -352,16 +325,13 @@ class PEAssembly final

#ifdef DACCESS_COMPILE
// just to make the DAC and GCC happy.
~PEAssembly() {};
~PEAssembly() = default;
PEAssembly() = default;
#else
PEAssembly(
BINDER_SPACE::Assembly* pBindResultInfo,
BINDER_SPACE::Assembly* pBoundAssembly,
IMetaDataEmit* pEmit,
BOOL isSystem,
AssemblyBinder* pDynamicAssemblyBinder = NULL,
PEImage* pPEImageIL = NULL,
BINDER_SPACE::Assembly* pHostAssembly = NULL
AssemblyBinder* pDynamicAssemblyBinder = NULL
);

~PEAssembly();
Expand Down Expand Up @@ -410,7 +380,6 @@ class PEAssembly final
IMetaDataEmit* m_pEmitter;

Volatile<LONG> m_refCount;
bool m_isSystem;

PTR_BINDER_SPACE_Assembly m_pHostAssembly;
PTR_AssemblyBinder m_pAssemblyBinder;
Expand Down
20 changes: 2 additions & 18 deletions src/coreclr/vm/peassembly.inl
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ inline LPCUTF8 PEAssembly::GetDebugName()
// Classification
// ------------------------------------------------------------

inline BOOL PEAssembly::IsSystem() const
inline bool PEAssembly::IsSystem() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;

return m_isSystem;
return this == SystemDomain::SystemPEAssembly();
}

inline BOOL PEAssembly::IsReflectionEmit() const
Expand Down Expand Up @@ -751,22 +751,6 @@ inline LPCSTR PEAssembly::GetSimpleName()
return name;
}

inline BOOL PEAssembly::IsStrongNamed()
{
CONTRACTL
{
THROWS;
WRAPPER(GC_NOTRIGGER);
MODE_ANY;
}
CONTRACTL_END;

DWORD flags = 0;
IfFailThrow(GetMDImport()->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, NULL, NULL, &flags));
return (flags & afPublicKey) != 0;
}


//---------------------------------------------------------------------------------------
//
// Check to see if this assembly has had its strong name signature verified yet.
Expand Down
Loading