Skip to content

Commit

Permalink
Windows: Always invalidate all regions of a section on unmap
Browse files Browse the repository at this point in the history
Unmapping a section will unmap the whole size initially allocated,
irrespective of how their protections are changed afterwards. Make sure
to follow this logic for invalidation too.
  • Loading branch information
bylaws committed Apr 18, 2024
1 parent 7ea1d42 commit 6c1b594
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/Windows/Common/InvalidationTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ void InvalidationTracker::InvalidateContainingSection(uint64_t Address, bool Fre
}

const auto SectionBase = reinterpret_cast<uint64_t>(Info.AllocationBase);
const auto SectionSize = reinterpret_cast<uint64_t>(Info.BaseAddress) + Info.RegionSize - reinterpret_cast<uint64_t>(Info.AllocationBase);
auto SectionSize = reinterpret_cast<uint64_t>(Info.BaseAddress) + Info.RegionSize - SectionBase;

while (!NtQueryVirtualMemory(NtCurrentProcess(), reinterpret_cast<void*>(SectionBase + SectionSize), MemoryBasicInformation, &Info,
sizeof(Info), nullptr) &&
reinterpret_cast<uint64_t>(Info.AllocationBase) == SectionBase) {
SectionSize += Info.RegionSize;
}
{
std::scoped_lock Lock(CTX.GetCodeInvalidationMutex());
for (auto Thread : Threads) {
Expand Down

0 comments on commit 6c1b594

Please sign in to comment.