From b6c42976ebe2498f0a49a52c564645d55756bbb0 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 18 Jul 2011 08:43:49 +0000 Subject: [PATCH] * heap.cc (heap_init): Change type of largest_found to PVOID. Start querying memory at 0x20000000. Use largest_found pointer when trying to allocate largest free memory area found. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/heap.cc | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0256a82e0..87f1f59d9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2011-07-18 Corinna Vinschen + + * heap.cc (heap_init): Change type of largest_found to PVOID. Start + querying memory at 0x20000000. Use largest_found pointer when trying + to allocate largest free memory area found. + 2011-07-14 Corinna Vinschen * fhandler_console.cc (fhandler_console::input_tcsetattr): Revert to diff --git a/winsup/cygwin/heap.cc b/winsup/cygwin/heap.cc index 4b2c964ac..ee27484c0 100644 --- a/winsup/cygwin/heap.cc +++ b/winsup/cygwin/heap.cc @@ -43,7 +43,7 @@ heap_init () This should work right from the start in 99% of the cases. But, there's always a but. Read on... */ uintptr_t start_address = 0x20000000L; - uintptr_t largest_found = 0; + PVOID largest_found = NULL; size_t largest_found_size = 0; SIZE_T ret; MEMORY_BASIC_INFORMATION mbi; @@ -60,8 +60,8 @@ heap_init () /* Ok, so we are at the 1% which didn't work with 0x20000000 out of the box. What we do now is to search for the next free region which matches our desired heap size. While doing that, - we keep track of the largest region we found. */ - start_address += wincap.allocation_granularity (); + we keep track of the largest region we found, including the + region starting at 0x20000000. */ while ((ret = VirtualQuery ((LPCVOID) start_address, &mbi, sizeof mbi)) != 0) { @@ -71,7 +71,7 @@ heap_init () break; if (mbi.RegionSize > largest_found_size) { - largest_found = (uintptr_t) mbi.BaseAddress; + largest_found = mbi.BaseAddress; largest_found_size = mbi.RegionSize; } } @@ -91,8 +91,7 @@ heap_init () { cygheap->user_heap.chunk = largest_found_size; cygheap->user_heap.base = - VirtualAlloc ((LPVOID) start_address, - cygheap->user_heap.chunk, + VirtualAlloc (largest_found, cygheap->user_heap.chunk, alloctype, PAGE_NOACCESS); } /* Last resort (but actually we are probably broken anyway):