Skip to content

Commit d27032f

Browse files
authored
Backport "Merge PR #6598: FIX(plugins): Load correct pages for modules" to 1.5.x (#6600)
2 parents b1f149f + 9c56565 commit d27032f

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
@@ -34,6 +34,7 @@ Modules HostWindows::modules() const {
3434

3535
const auto snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, m_pid);
3636
if (snapshotHandle == INVALID_HANDLE_VALUE) {
37+
CloseHandle(processHandle);
3738
return {};
3839
}
3940

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

0 commit comments

Comments
 (0)