1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:54:41 -07:00

runtime: fix mmap error return on linux.

Fixes #1511 again.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/4527070
This commit is contained in:
Dmitry Chestnykh 2011-05-26 21:43:27 -07:00 committed by Ian Lance Taylor
parent bddb75127f
commit e4492ce3c3

View File

@ -39,13 +39,19 @@ runtime·SysFree(void *v, uintptr n)
void* void*
runtime·SysReserve(void *v, uintptr n) runtime·SysReserve(void *v, uintptr n)
{ {
void *p;
// On 64-bit, people with ulimit -v set complain if we reserve too // On 64-bit, people with ulimit -v set complain if we reserve too
// much address space. Instead, assume that the reservation is okay // much address space. Instead, assume that the reservation is okay
// and check the assumption in SysMap. // and check the assumption in SysMap.
if(sizeof(void*) == 8) if(sizeof(void*) == 8)
return v; return v;
return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
if(p < (void*)4096) {
return nil;
}
return p;
} }
enum enum
@ -63,6 +69,8 @@ runtime·SysMap(void *v, uintptr n)
// On 64-bit, we don't actually have v reserved, so tread carefully. // On 64-bit, we don't actually have v reserved, so tread carefully.
if(sizeof(void*) == 8) { if(sizeof(void*) == 8) {
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
if(p == (void*)ENOMEM)
runtime·throw("runtime: out of memory");
if(p != v) { if(p != v) {
runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p); runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
runtime·throw("runtime: address space conflict"); runtime·throw("runtime: address space conflict");
@ -71,7 +79,7 @@ runtime·SysMap(void *v, uintptr n)
} }
p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0); p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
if(p == (void*)-ENOMEM) if(p == (void*)ENOMEM)
runtime·throw("runtime: out of memory"); runtime·throw("runtime: out of memory");
if(p != v) if(p != v)
runtime·throw("runtime: cannot map pages in arena address space"); runtime·throw("runtime: cannot map pages in arena address space");