]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix memory allocation on 386
authorRuss Cox <rsc@golang.org>
Wed, 9 Feb 2011 20:08:30 +0000 (15:08 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 9 Feb 2011 20:08:30 +0000 (15:08 -0500)
BSD and Darwin require an extra page between
end and the first mapping, and Windows has various
memory in the way too.

Fixes #1464.

R=r, r2
CC=golang-dev
https://golang.org/cl/4167041

src/pkg/runtime/malloc.goc

index 8899b01195dce900f4006c31095afce6a2b0b6c6..18652d71a6c380617d2cd7f1efb47a4e4db58594 100644 (file)
@@ -286,10 +286,16 @@ runtime·mallocinit(void)
                // of address space, which is probably too much in a 32-bit world.
                bitmap_size = MaxArena32 / (sizeof(void*)*8/4);
                arena_size = 512<<20;
-
-               p = (void*)(((uintptr)end + 64*1024 - 1) & ~(64*1024-1));
-               if(runtime·SysReserve(p, bitmap_size + arena_size) != p)
-                       runtime·throw("runtime: cannot reserve memory bitmap virtual address space");
+               
+               // SysReserve treats the address we ask for, end, as a hint,
+               // not as an absolute requirement.  If we ask for the end
+               // of the data segment but the operating system requires
+               // a little more space before we can start allocating, it will
+               // give out a slightly higher pointer.  That's fine.  
+               // Run with what we get back.
+               p = runtime·SysReserve(end, bitmap_size + arena_size);
+               if(p == nil)
+                       runtime·throw("runtime: cannot reserve arena virtual address space");
        }
        runtime·mheap.bitmap = p;
        runtime·mheap.arena_start = p + bitmap_size;