* heap.cc (eval_start_address): Simplify test for large address

awareness of executable, which works for 32 and 64 bit systems.
	Change comment accordingly.
This commit is contained in:
Corinna Vinschen 2011-07-21 17:52:05 +00:00
parent 86719a10d0
commit 37aeec7f72
2 changed files with 23 additions and 14 deletions

View File

@ -1,3 +1,9 @@
2011-07-21 Corinna Vinschen <corinna@vinschen.de>
* heap.cc (eval_start_address): Simplify test for large address
awareness of executable, which works for 32 and 64 bit systems.
Change comment accordingly.
2011-07-21 Corinna Vinschen <corinna@vinschen.de> 2011-07-21 Corinna Vinschen <corinna@vinschen.de>
* heap.cc (eval_start_address): New static function to evaluate the * heap.cc (eval_start_address): New static function to evaluate the

View File

@ -17,6 +17,7 @@ details. */
#include "dtable.h" #include "dtable.h"
#include "cygheap.h" #include "cygheap.h"
#include "child_info.h" #include "child_info.h"
#include "ntdll.h"
#include <sys/param.h> #include <sys/param.h>
#define assert(x) #define assert(x)
@ -34,21 +35,23 @@ eval_start_address ()
safe region starting at 0x20000000. This should work right from the start safe region starting at 0x20000000. This should work right from the start
in 99% of the cases. */ in 99% of the cases. */
uintptr_t start_address = 0x20000000L; uintptr_t start_address = 0x20000000L;
if (wincap.is_wow64 ()) if ((uintptr_t) NtCurrentTeb () >= 0xbf000000L)
{ {
/* However, if we're running on a 64 bit system, we test here if the /* However, if we're running on a /3GB enabled 32 bit system or on
executable is large address aware. If so, the application gets a a 64 bit system, and the executable is large address aware, then
4 Gigs virtual address space, with almost all of the upper 2 Gigs we know that we have spare 1 Gig (32 bit) or even 2 Gigs (64 bit)
being unused by Windows (only PEB and TEBs are allocated here, virtual address space. This memory region is practically unused
apparently). So what we do here is to test if the large address by Windows, only PEB and TEBs are allocated top-down here. We use
awareness flag is set in the file header and, if so, allocate our the current TEB address as very simple test that this is a large
heap in that region. What we get are 1.999 Gigs free for heap, address aware executable.
thread stacks, and shared memory regions. */ The above test for an address beyond 0xbf000000 is supposed to
PIMAGE_DOS_HEADER idh = (PIMAGE_DOS_HEADER) GetModuleHandle (NULL); make sure that we really have 3GB on a 32 bit system. XP and
PIMAGE_NT_HEADERS32 inh = (PIMAGE_NT_HEADERS32) later support smaller large address regions, but then it's not
((PBYTE) idh + idh->e_lfanew); that interesting for us to use it for the heap.
if (inh->FileHeader.Characteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE) If the region is big enough, the heap gets allocated at its
start_address = 0x80000000L; start. What we get are 0.999 or 1.999 Gigs of free contiguous
memory for heap, thread stacks, and shared memory regions. */
start_address = 0x80000000L;
} }
return start_address; return start_address;
} }