Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,14 @@ static PVOID detour_alloc_region_from_lo(PBYTE pbLo, PBYTE pbHi)
mbi.State));

if (mbi.State == MEM_FREE && mbi.RegionSize >= DETOUR_REGION_SIZE) {

#ifdef DETOURS_X86
// Reduce memory fragmentation by allocating the end of the region
pbTry += mbi.RegionSize; // Advance pbTry to the end of the free block.
if (pbTry > pbHi) {
pbTry = pbHi;
}
pbTry -= DETOUR_REGION_SIZE; // Move pbTry backwards to ensure that the free block is large enough to hold a trampoline region.
#endif
PVOID pv = VirtualAlloc(pbTry,
DETOUR_REGION_SIZE,
MEM_COMMIT|MEM_RESERVE,
Expand Down Expand Up @@ -1389,7 +1396,14 @@ static PVOID detour_alloc_region_from_hi(PBYTE pbLo, PBYTE pbHi)
mbi.State));

if (mbi.State == MEM_FREE && mbi.RegionSize >= DETOUR_REGION_SIZE) {

#ifdef DETOURS_X86
// Reduce memory fragmentation by allocating the end of the region
pbTry += mbi.RegionSize; // Advance pbTry to the end of the free block.
if (pbTry > pbHi) {
pbTry = pbHi;
}
pbTry -= DETOUR_REGION_SIZE; // Move pbTry backwards to ensure that the free block is large enough to hold a trampoline region.
#endif
PVOID pv = VirtualAlloc(pbTry,
DETOUR_REGION_SIZE,
MEM_COMMIT|MEM_RESERVE,
Expand Down