From: Andrew Au Date: Thu, 30 Aug 2018 16:31:53 +0000 (-0700) Subject: Fix CoreCLR debug launch (#19730) X-Git-Tag: accepted/tizen/unified/20190422.045933~1310 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=665c5cc83c5fe8b186c82e7f83bba0cdf860516a;p=platform%2Fupstream%2Fcoreclr.git Fix CoreCLR debug launch (#19730) --- diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index f274f85..1e5c876 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -1054,12 +1054,14 @@ IsCoreClrWithGoodHeader( } static -HMODULE* +HRESULT EnumProcessModulesInternal( HANDLE hProcess, - DWORD *pCountModules) -{ + DWORD *pCountModules, + HMODULE** ppModules) +{ *pCountModules = 0; + *ppModules = nullptr; // Start with 1024 modules DWORD cbNeeded = sizeof(HMODULE) * 1024; @@ -1067,13 +1069,12 @@ EnumProcessModulesInternal( ArrayHolder modules = new (nothrow) HMODULE[cbNeeded / sizeof(HMODULE)]; if (modules == nullptr) { - SetLastError(ERROR_OUTOFMEMORY); - return nullptr; + return HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); } if(!EnumProcessModules(hProcess, modules, cbNeeded, &cbNeeded)) { - return nullptr; + return HRESULT_FROM_WIN32(GetLastError()); } // If 1024 isn't enough, try the modules array size returned (cbNeeded) @@ -1082,14 +1083,13 @@ EnumProcessModulesInternal( modules = new (nothrow) HMODULE[cbNeeded / sizeof(HMODULE)]; if (modules == nullptr) { - SetLastError(ERROR_OUTOFMEMORY); - return nullptr; + return HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); } DWORD cbNeeded2; if(!EnumProcessModules(hProcess, modules, cbNeeded, &cbNeeded2)) { - return nullptr; + return HRESULT_FROM_WIN32(GetLastError()); } // The only way cbNeeded2 could change on the second call is if number of @@ -1101,7 +1101,8 @@ EnumProcessModulesInternal( } *pCountModules = cbNeeded / sizeof(HMODULE); - return modules.Detach(); + *ppModules = modules.Detach(); + return S_OK; } //----------------------------------------------------------------------------- @@ -1143,10 +1144,11 @@ EnumerateCLRs( // The modules in the array returned don't need to be closed DWORD countModules; - ArrayHolder modules = EnumProcessModulesInternal(hProcess, &countModules); - if (modules == nullptr) + ArrayHolder modules = nullptr; + HRESULT hr = EnumProcessModulesInternal(hProcess, &countModules, &modules); + if (FAILED(hr)) { - return HRESULT_FROM_WIN32(GetLastError()); + return hr; } // @@ -1321,10 +1323,11 @@ GetRemoteModuleBaseAddress( // The modules in the array returned don't need to be closed DWORD countModules; - ArrayHolder modules = EnumProcessModulesInternal(hProcess, &countModules); - if (modules == nullptr) + ArrayHolder modules = nullptr; + HRESULT hr = EnumProcessModulesInternal(hProcess, &countModules, &modules); + if (FAILED(hr)) { - ThrowHR(HRESULT_FROM_WIN32(GetLastError())); + ThrowHR(hr); } for(DWORD i = 0; i < countModules; i++) diff --git a/src/inc/clrhost.h b/src/inc/clrhost.h index 9fe978f..7b9c1dd 100644 --- a/src/inc/clrhost.h +++ b/src/inc/clrhost.h @@ -44,7 +44,7 @@ // #ifdef _DEBUG -#define LAST_ERROR_TRASH_VALUE 42424 +#define LAST_ERROR_TRASH_VALUE 42424 /* = 0xa5b8 */ #define TRASH_LASTERROR \ SetLastError(LAST_ERROR_TRASH_VALUE)