From c8691da29bea32e50727c43eee3e7afca561f970 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 13 Dec 2018 15:37:21 -0800 Subject: [PATCH] Fixes issue dotnet/coreclr#21485 and dotnet/coreclr#21484 (dotnet/coreclr#21526) Issue dotnet/coreclr#21485: fix EnumProcessModules hPseudoCurrentProcess bug. Added handle reference. Issue dotnet/coreclr#21484: createdump segfaults with ASP.NET app The problem is the ClrDataModule Request faulted on a dynamic module getting the file layout flag. Fixed the Request code not get the file layout and in the crash dump code skip any dynamic modules. Commit migrated from https://github.com/dotnet/coreclr/commit/a6403ba4d9187fc19af8e3dc64ec3e9e937d53eb --- .../src/debug/createdump/crashinfo.cpp | 34 +++++++++++++------ src/coreclr/src/debug/daccess/task.cpp | 7 +++- src/coreclr/src/pal/src/thread/process.cpp | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/coreclr/src/debug/createdump/crashinfo.cpp b/src/coreclr/src/debug/createdump/crashinfo.cpp index 6de6b94429a1b..4db2b00eeb9f4 100644 --- a/src/coreclr/src/debug/createdump/crashinfo.cpp +++ b/src/coreclr/src/debug/createdump/crashinfo.cpp @@ -708,6 +708,17 @@ CrashInfo::EnumerateManagedModules(IXCLRDataProcess* pClrDataProcess) break; } + // Skip any dynamic modules. The Request call below on some DACs crashes on dynamic modules. + ULONG32 flags; + if ((hr = pClrDataModule->GetFlags(&flags)) != S_OK) { + TRACE("MODULE: GetFlags FAILED %08x\n", hr); + continue; + } + if (flags & CLRDATA_MODULE_IS_DYNAMIC) { + TRACE("MODULE: Skipping dynamic module\n"); + continue; + } + DacpGetModuleData moduleData; if (SUCCEEDED(hr = moduleData.Request(pClrDataModule.GetPtr()))) { @@ -719,17 +730,20 @@ CrashInfo::EnumerateManagedModules(IXCLRDataProcess* pClrDataProcess) ArrayHolder wszUnicodeName = new WCHAR[MAX_LONGPATH + 1]; if (SUCCEEDED(hr = pClrDataModule->GetFileName(MAX_LONGPATH, nullptr, wszUnicodeName))) { - char* pszName = (char*)malloc(MAX_LONGPATH + 1); - if (pszName == nullptr) { - fprintf(stderr, "Allocating module name FAILED\n"); - result = false; - break; + // If the module file name isn't empty + if (wszUnicodeName[0] != 0) { + char* pszName = (char*)malloc(MAX_LONGPATH + 1); + if (pszName == nullptr) { + fprintf(stderr, "Allocating module name FAILED\n"); + result = false; + break; + } + sprintf_s(pszName, MAX_LONGPATH, "%S", (WCHAR*)wszUnicodeName); + TRACE(" %s\n", pszName); + + // Change the module mapping name + ReplaceModuleMapping(moduleData.LoadedPEAddress, pszName); } - sprintf_s(pszName, MAX_LONGPATH, "%S", (WCHAR*)wszUnicodeName); - TRACE(" %s\n", pszName); - - // Change the module mapping name - ReplaceModuleMapping(moduleData.LoadedPEAddress, pszName); } else { TRACE("\nModule.GetFileName FAILED %08x\n", hr); diff --git a/src/coreclr/src/debug/daccess/task.cpp b/src/coreclr/src/debug/daccess/task.cpp index 601ad401af62a..d7d8ba5a84785 100644 --- a/src/coreclr/src/debug/daccess/task.cpp +++ b/src/coreclr/src/debug/daccess/task.cpp @@ -2745,7 +2745,12 @@ ClrDataModule::RequestGetModuleData( COUNT_T peSize; outGMD->LoadedPEAddress = TO_CDADDR(PTR_TO_TADDR(pPEFile->GetLoadedImageContents(&peSize))); outGMD->LoadedPESize = (ULONG64)peSize; - outGMD->IsFileLayout = pPEFile->GetLoaded()->IsFlat(); + + // Can not get the file layout for a dynamic module + if (!outGMD->IsDynamic) + { + outGMD->IsFileLayout = pPEFile->GetLoaded()->IsFlat(); + } } // If there is a in memory symbol stream diff --git a/src/coreclr/src/pal/src/thread/process.cpp b/src/coreclr/src/pal/src/thread/process.cpp index a964ee8829b44..dcaa307e369be 100644 --- a/src/coreclr/src/pal/src/thread/process.cpp +++ b/src/coreclr/src/pal/src/thread/process.cpp @@ -2859,6 +2859,7 @@ GetProcessModulesFromHandle( if (hPseudoCurrentProcess == hProcess) { pobjProcess = g_pobjProcess; + pobjProcess->AddReference(); } else {