summaryrefslogtreecommitdiff
path: root/src/runtime/mem_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/mem_linux.c')
-rw-r--r--src/runtime/mem_linux.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/runtime/mem_linux.c b/src/runtime/mem_linux.c
index bfb405607..52e02b34e 100644
--- a/src/runtime/mem_linux.c
+++ b/src/runtime/mem_linux.c
@@ -11,7 +11,7 @@
enum
{
- _PAGE_SIZE = 4096,
+ _PAGE_SIZE = PhysPageSize,
EACCES = 13,
};
@@ -36,8 +36,9 @@ addrspace_free(void *v, uintptr n)
errval = runtime·mincore((int8*)v + off, chunk, vec);
// ENOMEM means unmapped, which is what we want.
// Anything else we assume means the pages are mapped.
- if (errval != -ENOMEM)
+ if (errval != -ENOMEM && errval != ENOMEM) {
return 0;
+ }
}
return 1;
}
@@ -48,12 +49,15 @@ mmap_fixed(byte *v, uintptr n, int32 prot, int32 flags, int32 fd, uint32 offset)
void *p;
p = runtime·mmap(v, n, prot, flags, fd, offset);
- if(p != v && addrspace_free(v, n)) {
+ if(p != v) {
+ if(p > (void*)4096) {
+ runtime·munmap(p, n);
+ p = nil;
+ }
// On some systems, mmap ignores v without
// MAP_FIXED, so retry if the address space is free.
- if(p > (void*)4096)
- runtime·munmap(p, n);
- p = runtime·mmap(v, n, prot, flags|MAP_FIXED, fd, offset);
+ if(addrspace_free(v, n))
+ p = runtime·mmap(v, n, prot, flags|MAP_FIXED, fd, offset);
}
return p;
}