From 1c62b365b088c409c7ee3546783194c8fdbef31b Mon Sep 17 00:00:00 2001 From: Ivan Maidanski <ivmai@mail.ru> Date: Fri, 21 Dec 2018 02:33:49 +0300 Subject: [PATCH] Abort with appropriate message if executable pages cannot be allocated 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/os_dep.c b/os_dep.c index 52391bde..1f6a0b5d 100644 --- 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) -- 2.40.0