Windows: Invalidate code in freed memory after the free syscall

Windows will populate Size/Address with those of the underlying free
region. This is important for cross-process free operations, where the
the 'before' callback is still called after the memory is freed so
querying the size of the section (which is not freed) fails.
This commit is contained in:
Billy Laws committed 2026-01-02 16:45:53 +00:00
1 parent a3779be9e1
commit 2faf2eb5b6
2 files changed
+5 -9

No files matched your search

+3 -5
View File
@@ -793,12 +793,10 @@ void NotifyMemoryFree(void* Address, SIZE_T Size, ULONG FreeType, BOOL After, NT
if (!After) {
ThreadCreationMutex.lock();
if (FreeType & MEM_DECOMMIT) {
InvalidationTracker->InvalidateAlignedInterval(reinterpret_cast<uint64_t>(Address), static_cast<uint64_t>(Size), true);
} else if (FreeType & MEM_RELEASE) {
InvalidationTracker->InvalidateContainingSection(reinterpret_cast<uint64_t>(Address), true);
}
} else {
if (!Status) {
InvalidationTracker->InvalidateAlignedInterval(reinterpret_cast<uint64_t>(Address), static_cast<uint64_t>(Size), true);
}
ThreadCreationMutex.unlock();
}
}
+2 -4
View File
@@ -966,12 +966,10 @@ void BTCpuNotifyMemoryProtect(void* Address, SIZE_T Size, ULONG NewProt, BOOL Af
void BTCpuNotifyMemoryFree(void* Address, SIZE_T Size, ULONG FreeType, BOOL After, ULONG Status) {
if (!After) {
ThreadCreationMutex.lock();
if (!Size) {
InvalidationTracker->InvalidateContainingSection(reinterpret_cast<uint64_t>(Address), true);
} else if (FreeType & MEM_DECOMMIT) {
} else {
if (!Status) {
InvalidationTracker->InvalidateAlignedInterval(reinterpret_cast<uint64_t>(Address), static_cast<uint64_t>(Size), true);
}
} else {
ThreadCreationMutex.unlock();
}
}