From 15be24c6720ebc1d70d2b2de37e1b3d2bf496127 Mon Sep 17 00:00:00 2001 From: Geoff Norton Date: Fri, 29 Apr 2011 16:23:15 -0400 Subject: [PATCH] [boehm] Avoid a ENOMEM when allocating across an unallocated page A very rare allocation pattern could cause the boehm free list to call the GC_unmap_gap function, which actually calls down into munmap(). Darwins virtual memory manager will return a KERN_INVALID_ADDRESS which is translated into a ENOMEM, if mprotect attempts to change the protection of a range which includes an unallocated page. We address this by just mmap() back to ANON, instead of actually unallocating the page. --- os_dep.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/os_dep.c b/os_dep.c index ecaa27c7..8c8e0981 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2131,7 +2131,14 @@ void GC_unmap_gap(ptr_t start1, word bytes1, ptr_t start2, word bytes2) len -= free_len; } # else - if (len != 0 && munmap(start_addr, len) != 0) ABORT("munmap failed"); + if (len != 0) { + /* Immediately remap as above. */ + void * result; + result = mmap(start_addr, len, PROT_NONE, + MAP_PRIVATE | MAP_FIXED | OPT_MAP_ANON, + zero_fd, 0/* offset */); + if (result != (void *)start_addr) ABORT("mmap(...PROT_NONE...) failed"); + } GC_unmapped_bytes += len; # endif } -- 2.40.0