diff options
| author | Ian Lance Taylor <iant@golang.org> | 2014-03-25 13:22:19 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2014-03-25 13:22:19 -0700 |
| commit | 4ebfa8319914e1ed9727592d1fa360ce339b7597 (patch) | |
| tree | 23893ff60e07c9b69a0b3af54e03c1f08491f33e /src/pkg/runtime/mem_linux.c | |
| parent | cc2c5fc3d28ef2e179e605fa41d5e7eec04e34ac (diff) | |
| download | go-4ebfa8319914e1ed9727592d1fa360ce339b7597.tar.xz | |
runtime: accurately record whether heap memory is reserved
The existing code did not have a clear notion of whether
memory has been actually reserved. It checked based on
whether in 32-bit mode or 64-bit mode and (on GNU/Linux) the
requested address, but it confused the requested address and
the returned address.
LGTM=rsc
R=rsc, dvyukov
CC=golang-codereviews, michael.hudson
https://golang.org/cl/79610043
Diffstat (limited to 'src/pkg/runtime/mem_linux.c')
| -rw-r--r-- | src/pkg/runtime/mem_linux.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/pkg/runtime/mem_linux.c b/src/pkg/runtime/mem_linux.c index 2ead204101..3f997be96b 100644 --- a/src/pkg/runtime/mem_linux.c +++ b/src/pkg/runtime/mem_linux.c @@ -99,7 +99,7 @@ runtime·SysFault(void *v, uintptr n) } void* -runtime·SysReserve(void *v, uintptr n) +runtime·SysReserve(void *v, uintptr n, bool *reserved) { void *p; @@ -107,7 +107,7 @@ runtime·SysReserve(void *v, uintptr n) // much address space. Instead, assume that the reservation is okay // if we can reserve at least 64K and check the assumption in SysMap. // Only user-mode Linux (UML) rejects these requests. - if(sizeof(void*) == 8 && (uintptr)v >= 0xffffffffU) { + if(sizeof(void*) == 8 && n > 1LL<<32) { p = mmap_fixed(v, 64<<10, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); if (p != v) { if(p >= (void*)4096) @@ -115,24 +115,26 @@ runtime·SysReserve(void *v, uintptr n) return nil; } runtime·munmap(p, 64<<10); + *reserved = false; return v; } p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); if((uintptr)p < 4096) return nil; + *reserved = true; return p; } void -runtime·SysMap(void *v, uintptr n, uint64 *stat) +runtime·SysMap(void *v, uintptr n, bool reserved, uint64 *stat) { void *p; runtime·xadd64(stat, n); // On 64-bit, we don't actually have v reserved, so tread carefully. - if(sizeof(void*) == 8 && (uintptr)v >= 0xffffffffU) { + if(!reserved) { p = mmap_fixed(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); if(p == (void*)ENOMEM) runtime·throw("runtime: out of memory"); |
