Fix mmap(PROT_NONE) failure on AIX
authorPeter Wang <novalazy@gmail.com>
Thu, 6 Jun 2019 07:36:54 +0000 (17:36 +1000)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 10 Jun 2019 07:31:26 +0000 (10:31 +0300)
Issue #285 (bdwgc).

Unmap memory using mprotect(PROT_NONE) instead of mmap(PROT_NONE) on AIX.

* os_dep [USE_MUNMAP && AIX] (GC_unmap, GC_unmap_gap): Call mprotect()
instead of mmap(); update comment.

os_dep.c

index 0e6226d..d86fa6b 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -2560,9 +2560,11 @@ GC_INNER void GC_unmap(ptr_t start, size_t bytes)
       /* We immediately remap it to prevent an intervening mmap from    */
       /* accidentally grabbing the same address space.                  */
       {
-#       ifdef CYGWIN32
-          /* Calling mmap() with the new protection flags on an         */
-          /* existing memory map with MAP_FIXED is broken on Cygwin.    */
+#       if defined(AIX) || defined(CYGWIN32)
+          /* On AIX, mmap(PROT_NONE) fails with ENOMEM unless the       */
+          /* environment variable XPG_SUS_ENV is set to ON.             */
+          /* On Cygwin, calling mmap() with the new protection flags on */
+          /* an existing memory map with MAP_FIXED is broken.           */
           /* However, calling mprotect() on the given address range     */
           /* with PROT_NONE seems to work fine.                         */
           if (mprotect(start_addr, len, PROT_NONE))
@@ -2688,7 +2690,7 @@ GC_INNER void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2,
 #   else
       if (len != 0) {
         /* Immediately remap as above. */
-#       ifdef CYGWIN32
+#       if defined(AIX) || defined(CYGWIN32)
           if (mprotect(start_addr, len, PROT_NONE))
             ABORT("mprotect(PROT_NONE) failed");
 #       else