Fix executable memory allocation in GC_unix_get_mem
authorIvan Maidanski <ivmai@mail.ru>
Thu, 20 Dec 2018 08:12:06 +0000 (11:12 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 20 Dec 2018 08:12:06 +0000 (11:12 +0300)
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

index 25d893a..b2efe32 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -2263,6 +2263,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;