mirror of
https://github.com/golang/go
synced 2024-11-25 04:07:55 -07:00
runtime: don't use twice the memory with grsec-like kernels
grsec needs the FIXED flag to be provided to mmap, which works now. That said, when the allocation fails to be made in the specific address, we're still given back a writable page. This change will unmap that page to avoid using twice the amount of memory needed. It'd also be pretty easy to avoid the extra system calls once we detected that the flag is needed, but I'm not sure if that edge case is worth the effort. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4634086
This commit is contained in:
parent
b4bab6f8b3
commit
65b036c381
@ -91,6 +91,9 @@ runtime·SysMap(void *v, uintptr n)
|
|||||||
if(p != v && addrspace_free(v, n)) {
|
if(p != v && addrspace_free(v, n)) {
|
||||||
// On some systems, mmap ignores v without
|
// On some systems, mmap ignores v without
|
||||||
// MAP_FIXED, so retry if the address space is free.
|
// MAP_FIXED, so retry if the address space is free.
|
||||||
|
if(p > (void*)4096) {
|
||||||
|
runtime·munmap(p, 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user