Abort with appropriate message if executable pages cannot be allocated
authorIvan Maidanski <ivmai@mail.ru>
Thu, 20 Dec 2018 23:33:49 +0000 (02:33 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 20 Dec 2018 23:33:49 +0000 (02:33 +0300)
This may happen e.g. if PaX MPROTECT feature is enabled.

* os_dep.c [!OS2 && !PCR && !AMIGA && !USE_WINALLOC && !MACOS
&& !DOS4GW && !NONSTOP && !SN_TARGET_PSP2 && !RTEMS && !__CC_ARM
&& MMAP_SUPPORTED] (GC_unix_mmap_get_mem): Treat result==MAP_FAILED as
unlikely; if the first mmap call returns MAP_FAILED then ABORT with the
appropriate message if GC_pages_executable (and errno is EACCES).

os_dep.c

index 52391bd..1f6a0b5 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -2184,7 +2184,11 @@ void GC_register_data_segments(void)
                   GC_MMAP_FLAGS | OPT_MAP_ANON, zero_fd, 0/* offset */);
 #   undef IGNORE_PAGES_EXECUTABLE
 
-    if (result == MAP_FAILED) return(0);
+    if (EXPECT(MAP_FAILED == result, FALSE)) {
+      if (HEAP_START == last_addr && GC_pages_executable && EACCES == errno)
+        ABORT("Cannot allocate executable pages");
+      return NULL;
+    }
     last_addr = (ptr_t)(((word)result + bytes + GC_page_size - 1)
                         & ~(GC_page_size - 1));
 #   if !defined(LINUX)