From 56d807d4a012cce1a98cdbea30928b438609c424 Mon Sep 17 00:00:00 2001 From: Juan Hoyos <19413848+hoyosjs@users.noreply.github.com> Date: Thu, 14 Oct 2021 11:42:39 -0700 Subject: [PATCH] Don't error out from GetOrCreateLayout in the DAC if no layout creation is needed (#60401) --- src/coreclr/vm/peimage.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 4d8af1517b27a..25aeb9625ec66 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -761,6 +761,8 @@ PEImage::PEImage(): m_pLayoutLock=new SimpleRWLock(PREEMPTIVE,LOCK_TYPE_DEFAULT); } +// Misnomer under the DAC, but has a lot of callers. The DAC can't create layouts, so in that +// case this is a get. PTR_PEImageLayout PEImage::GetOrCreateLayout(DWORD imageLayoutMask) { WRAPPER_NO_CONTRACT; @@ -771,19 +773,19 @@ PTR_PEImageLayout PEImage::GetOrCreateLayout(DWORD imageLayoutMask) // Note: we use reader-writer lock, but only writes are synchronized. PTR_PEImageLayout pRetVal = GetExistingLayoutInternal(imageLayoutMask); -#ifndef DACCESS_COMPILE if (pRetVal == NULL) { +#ifndef DACCESS_COMPILE GCX_PREEMP(); SimpleWriteLockHolder lock(m_pLayoutLock); pRetVal = GetOrCreateLayoutInternal(imageLayoutMask); - } #else - // In DAC builds, we can't create any layouts - we must require that they already exist. - // We also don't take any AddRefs or locks in DAC builds - it's inspection-only. - _ASSERTE_MSG(false, "DACization error - caller expects PEImage layout to exist and it doesn't"); - DacError(E_UNEXPECTED); + // In DAC builds, we can't create any layouts - we must require that they already exist. + // We also don't take any AddRefs or locks in DAC builds - it's inspection-only. + _ASSERTE_MSG(false, "DACization error - caller expects PEImage layout to exist and it doesn't"); + DacError(E_UNEXPECTED); #endif + } return pRetVal; }