Skip to content

Commit 1498b83

Browse files
committed
FIX(plugins): Load correct pages for modules
This `VirtualQueryEx()` loop is called for each module in a process. It reads pages starting at the module address but seems to continue past into other modules and into dynamic allocations also. This check stops enumerating pages once it encounters one that no longer belongs to the module for which pages are being collected. (Also this function opens two handles, this adds a clean up for the first handle if opening the second fails.) Fixes #6558
1 parent 7ef9b74 commit 1498b83

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

plugins/HostWindows.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Modules HostWindows::modules() const {
3232

3333
const auto snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, m_pid);
3434
if (snapshotHandle == INVALID_HANDLE_VALUE) {
35+
CloseHandle(processHandle);
3536
return {};
3637
}
3738

@@ -49,7 +50,11 @@ Modules HostWindows::modules() const {
4950
MEMORY_BASIC_INFORMATION64 mbi;
5051
auto address = reinterpret_cast< procptr_t >(me.modBaseAddr);
5152
while (VirtualQueryEx(processHandle, reinterpret_cast< LPCVOID >(address),
52-
reinterpret_cast< PMEMORY_BASIC_INFORMATION >(&mbi), sizeof(mbi))) {
53+
reinterpret_cast< PMEMORY_BASIC_INFORMATION >(&mbi), sizeof(mbi))
54+
/* Only enumerate pages that belong to the allocation for this module.
55+
* This stops if it sees a page for a different allocation, belonging
56+
* to another module or dynamic memory, or gap between pages. */
57+
&& (mbi.AllocationBase == reinterpret_cast< procptr_t >(me.modBaseAddr))) {
5358
MemoryRegion region{};
5459
region.address = address;
5560
region.size = mbi.RegionSize;

0 commit comments

Comments
 (0)