From: Geoff Norton Date: Fri, 29 Apr 2011 20:23:15 +0000 (-0400) Subject: [boehm] Avoid a ENOMEM when allocating across an unallocated page X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15be24c6720ebc1d70d2b2de37e1b3d2bf496127;p=gc [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. --- 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 }