From 13a70b1964cd9a8f1fe14aacd27c054602ca52b0 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 20 Dec 2018 11:12:06 +0300 Subject: [PATCH] Fix executable memory allocation in GC_unix_get_mem Previously, sbrk() was used for the memory allocation even if the executable pages were requested. * os_dep.c [!OS2 && !PCR && !AMIGA && !USE_WINALLOC && !MACOS && !DOS4GW && !NONSTOP && !SN_TARGET_PSP2 && !RTEMS && !__CC_ARM && MMAP_SUPPORTED] (GC_unix_get_mem): Do not call GC_unix_sbrk_get_mem if GC_pages_executable; add comment. --- os_dep.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/os_dep.c b/os_dep.c index f51a61d2..f52552d4 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2138,6 +2138,11 @@ ptr_t GC_unix_get_mem(size_t bytes) static GC_bool sbrk_failed = FALSE; ptr_t result = 0; + if (GC_pages_executable) { + /* If the allocated memory should have the execute permission */ + /* then sbrk() cannot be used. */ + return GC_unix_mmap_get_mem(bytes); + } if (!sbrk_failed) result = GC_unix_sbrk_get_mem(bytes); if (0 == result) { sbrk_failed = TRUE; -- 2.40.0