PEImageLayout * pLoadLayout = NULL;
+ HRESULT loadFailure = S_OK;
if (m_bIsTrustedNativeImage || IsFile())
{
- // For CoreCLR, try to load all files via LoadLibrary first. If LoadLibrary did not work, retry using
- // regular mapping - but not for native images.
- pLoadLayout = PEImageLayout::Load(this, FALSE /* bNTSafeLoad */, m_bIsTrustedNativeImage /* bThrowOnError */);
+ // Try to load all files via LoadLibrary first. If LoadLibrary did not work,
+ // retry using regular mapping.
+ HRESULT* returnDontThrow = m_bIsTrustedNativeImage ? NULL : &loadFailure;
+ pLoadLayout = PEImageLayout::Load(this, FALSE /* bNTSafeLoad */, returnDontThrow);
}
if (pLoadLayout != NULL)
PEImageLayoutHolder pLayout(PEImageLayout::Map(this));
bool fMarkAnyCpuImageAsLoaded = false;
+
// Avoid mapping another image if we can. We can only do this for IL-ONLY images
- // since LoadLibrary is needed if we are to actually load code
+ // since LoadLibrary is needed if we are to actually load code (e.g. IJW).
if (pLayout->HasCorHeader())
{
- if (pLayout->IsILOnly())
+ // IJW images must be successfully loaded by the OS to handle
+ // native dependencies, therefore they cannot be mapped.
+ if (!pLayout->IsILOnly())
{
- // For CoreCLR, IL only images will always be mapped. We also dont bother doing the conversion of PE header on 64bit,
- // as done below for the desktop case, as there is no appcompat burden for CoreCLR on 64bit to have that conversion done.
- fMarkAnyCpuImageAsLoaded = true;
- }
- else
- {
- // IJW images must be loaded, not mapped
- ThrowHR(COR_E_BADIMAGEFORMAT);
+ // For compat with older CoreCLR versions we will fallback to the
+ // COR_E_BADIMAGEFORMAT error code if a failure wasn't indicated.
+ loadFailure = FAILED(loadFailure) ? loadFailure : COR_E_BADIMAGEFORMAT;
+ EEFileLoadException::Throw(GetPath(), loadFailure);
}
+
+ // IL only images will always be mapped. We don't bother doing a conversion
+ // of PE header on 64bit, as done for .NET Framework, since there is no
+ // appcompat burden for CoreCLR on 64bit.
+ fMarkAnyCpuImageAsLoaded = true;
}
pLayout.SuppressRelease();
return new ConvertedImageLayout(pFlat, isInBundle);
}
-PEImageLayout* PEImageLayout::Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError)
+PEImageLayout* PEImageLayout::Load(PEImage* pOwner, BOOL bNTSafeLoad, HRESULT* returnDontThrow)
{
STANDARD_VM_CONTRACT;
return PEImageLayout::LoadConverted(pOwner, true);
}
- PEImageLayoutHolder pAlloc(new LoadedImageLayout(pOwner,bNTSafeLoad,bThrowOnError));
+ PEImageLayoutHolder pAlloc(new LoadedImageLayout(pOwner,bNTSafeLoad,returnDontThrow));
if (pAlloc->GetBase()==NULL)
return NULL;
return pAlloc.Extract();
}
#if !defined(CROSSGEN_COMPILE) && !defined(TARGET_UNIX)
-LoadedImageLayout::LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError)
+LoadedImageLayout::LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, HRESULT* returnDontThrow)
{
CONTRACTL
{
m_Module = CLRLoadLibraryEx(pOwner->GetPath(), NULL, dwFlags);
if (m_Module == NULL)
{
- if (!bThrowOnError)
- return;
-
// Fetch the HRESULT upfront before anybody gets a chance to corrupt it
HRESULT hr = HRESULT_FROM_GetLastError();
- EEFileLoadException::Throw(pOwner->GetPath(), hr, NULL);
+ if (returnDontThrow != NULL)
+ {
+ *returnDontThrow = hr;
+ return;
+ }
+
+ EEFileLoadException::Throw(pOwner->GetPath(), hr);
}
IfFailThrow(Init(m_Module,true));
static PEImageLayout* CreateFlat(const void *flat, COUNT_T size,PEImage* pOwner);
static PEImageLayout* CreateFromHMODULE(HMODULE mappedbase,PEImage* pOwner, BOOL bTakeOwnership);
static PEImageLayout* LoadFromFlat(PEImageLayout* pflatimage);
- static PEImageLayout* Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError = TRUE);
+ static PEImageLayout* Load(PEImage* pOwner, BOOL bNTSafeLoad, HRESULT* returnDontThrow = NULL);
static PEImageLayout* LoadFlat(PEImage* pOwner);
static PEImageLayout* LoadConverted(PEImage* pOwner, BOOL isInBundle = FALSE);
static PEImageLayout* LoadNative(LPCWSTR fullPath);
HINSTANCE m_Module;
public:
#ifndef DACCESS_COMPILE
- LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError);
+ LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, HRESULT* returnDontThrow);
~LoadedImageLayout()
{
CONTRACTL