]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: fix heap allocation on WOW64 and /3GB enabled 32 bit machines
authorCorinna Vinschen <corinna@vinschen.de>
Wed, 19 Dec 2018 20:10:37 +0000 (21:10 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 19 Dec 2018 20:10:37 +0000 (21:10 +0100)
The check for the TEB being allocated beyond the first 2GB area is not
valid anymore.  At least on W10 WOW64, the TEB is allocated in the
lower 2GB even in large-address aware executables.  Use VirtualQuery
instead.  It fails for invalid addresses so that's a simple enough test.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/heap.cc

index 18145d21c2423261e93afc11b3c551066090826d..e18cd5508259131cbdbd5ef24974f69dd7d9e2f1 100644 (file)
@@ -44,22 +44,28 @@ eval_start_address ()
      starting at 0x20000000.  This should work right from the start in 99%
      of the cases. */
   uintptr_t start_address = 0x20000000L;
-  if ((uintptr_t) NtCurrentTeb () >= 0xbf000000L)
+  MEMORY_BASIC_INFORMATION mbi;
+
+  if (VirtualQuery ((void *) 0xbf000000L, &mbi, sizeof mbi))
     {
       /* However, if we're running on a /3GB enabled 32 bit system or on
         a 64 bit system, and the executable is large address aware, then
         we know that we have spare 1 Gig (32 bit) or even 2 Gigs (64 bit)
         virtual address space.  This memory region is practically unused
-        by Windows, only PEB and TEBs are allocated top-down here.  We use
-        the current TEB address as very simple test that this is a large
-        address aware executable.
-        The above test for an address beyond 0xbf000000 is supposed to
-        make sure that we really have 3GB on a 32 bit system.  Windows
-        supports smaller large address regions, but then it's not that
-        interesting for us to use it for the heap.
-        If the region is big enough, the heap gets allocated at its
-        start.  What we get are 0.999 or 1.999 Gigs of free contiguous
-        memory for heap, thread stacks, and shared memory regions. */
+        by Windows, only PEB and TEBs are allocated top-down here.
+
+        We used to use the current TEB address as very simple test that
+        this is a large address aware executable, but that fails on W10
+        WOW64 because the main TEB is apparently commited in the lower
+        2 Gigs these days.
+
+        The above test for address 0xbf000000 is supposed to make sure
+        that we really have 3GB on a 32 bit system.  Windows supports
+        smaller large address regions, but then it's not that interesting
+        for us to use it for the heap.  If the region is big enough, the
+        heap gets allocated at its 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;
     }
 #endif
This page took 0.030312 seconds and 5 git commands to generate.