Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4a7e9ea

Browse files
author
Mike McLaughlin
authored
Fix CoreCLR debug launch (#19730) (#19770)
1 parent 590166a commit 4a7e9ea

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/dlls/dbgshim/dbgshim.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,26 +1054,27 @@ IsCoreClrWithGoodHeader(
10541054
}
10551055

10561056
static
1057-
HMODULE*
1057+
HRESULT
10581058
EnumProcessModulesInternal(
10591059
HANDLE hProcess,
1060-
DWORD *pCountModules)
1061-
{
1060+
DWORD *pCountModules,
1061+
HMODULE** ppModules)
1062+
{
10621063
*pCountModules = 0;
1064+
*ppModules = nullptr;
10631065

10641066
// Start with 1024 modules
10651067
DWORD cbNeeded = sizeof(HMODULE) * 1024;
10661068

10671069
ArrayHolder<HMODULE> modules = new (nothrow) HMODULE[cbNeeded / sizeof(HMODULE)];
10681070
if (modules == nullptr)
10691071
{
1070-
SetLastError(ERROR_OUTOFMEMORY);
1071-
return nullptr;
1072+
return HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
10721073
}
10731074

10741075
if(!EnumProcessModules(hProcess, modules, cbNeeded, &cbNeeded))
10751076
{
1076-
return nullptr;
1077+
return HRESULT_FROM_WIN32(GetLastError());
10771078
}
10781079

10791080
// If 1024 isn't enough, try the modules array size returned (cbNeeded)
@@ -1082,14 +1083,13 @@ EnumProcessModulesInternal(
10821083
modules = new (nothrow) HMODULE[cbNeeded / sizeof(HMODULE)];
10831084
if (modules == nullptr)
10841085
{
1085-
SetLastError(ERROR_OUTOFMEMORY);
1086-
return nullptr;
1086+
return HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
10871087
}
10881088

10891089
DWORD cbNeeded2;
10901090
if(!EnumProcessModules(hProcess, modules, cbNeeded, &cbNeeded2))
10911091
{
1092-
return nullptr;
1092+
return HRESULT_FROM_WIN32(GetLastError());
10931093
}
10941094

10951095
// The only way cbNeeded2 could change on the second call is if number of
@@ -1101,7 +1101,8 @@ EnumProcessModulesInternal(
11011101
}
11021102

11031103
*pCountModules = cbNeeded / sizeof(HMODULE);
1104-
return modules.Detach();
1104+
*ppModules = modules.Detach();
1105+
return S_OK;
11051106
}
11061107

11071108
//-----------------------------------------------------------------------------
@@ -1143,10 +1144,11 @@ EnumerateCLRs(
11431144

11441145
// The modules in the array returned don't need to be closed
11451146
DWORD countModules;
1146-
ArrayHolder<HMODULE> modules = EnumProcessModulesInternal(hProcess, &countModules);
1147-
if (modules == nullptr)
1147+
ArrayHolder<HMODULE> modules = nullptr;
1148+
HRESULT hr = EnumProcessModulesInternal(hProcess, &countModules, &modules);
1149+
if (FAILED(hr))
11481150
{
1149-
return HRESULT_FROM_WIN32(GetLastError());
1151+
return hr;
11501152
}
11511153

11521154
//
@@ -1321,10 +1323,11 @@ GetRemoteModuleBaseAddress(
13211323

13221324
// The modules in the array returned don't need to be closed
13231325
DWORD countModules;
1324-
ArrayHolder<HMODULE> modules = EnumProcessModulesInternal(hProcess, &countModules);
1325-
if (modules == nullptr)
1326+
ArrayHolder<HMODULE> modules = nullptr;
1327+
HRESULT hr = EnumProcessModulesInternal(hProcess, &countModules, &modules);
1328+
if (FAILED(hr))
13261329
{
1327-
ThrowHR(HRESULT_FROM_WIN32(GetLastError()));
1330+
ThrowHR(hr);
13281331
}
13291332

13301333
for(DWORD i = 0; i < countModules; i++)

src/inc/clrhost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//
4545
#ifdef _DEBUG
4646

47-
#define LAST_ERROR_TRASH_VALUE 42424
47+
#define LAST_ERROR_TRASH_VALUE 42424 /* = 0xa5b8 */
4848

4949
#define TRASH_LASTERROR \
5050
SetLastError(LAST_ERROR_TRASH_VALUE)

0 commit comments

Comments
 (0)