cdata.set('HAVE_GETTIMEOFDAY', cc.has_function('gettimeofday'))
cdata.set('HAVE_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix : '#include <stdlib.h>'))
cdata.set('HAVE_MMAP', cc.has_function('mmap'))
+cdata.set('HAVE_PTHREAD_JIT', cc.has_function('pthread_jit_write_protect_np'))
cdata.set('HAVE_SYS_TIME_H', cc.has_header('sys/time.h'))
cdata.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
#define MAP_ANONYMOUS MAP_ANON
#endif
+#ifndef MAP_JIT
+#define MAP_JIT 0
+#endif
+
static int
orc_code_region_allocate_codemem_anon_map (OrcCodeRegion *region)
{
region->exec_ptr = mmap (NULL, SIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ MAP_PRIVATE|MAP_ANONYMOUS|MAP_JIT, -1, 0);
if (region->exec_ptr == MAP_FAILED) {
ORC_WARNING("failed to create write/exec map. err=%i", errno);
return FALSE;
if (orc_code_region_allocate_codemem_anon_map (region)) return;
+#ifdef __APPLE__
+ ORC_ERROR("Failed to create write and exec mmap regions. This "
+ "is probably because the Hardened Runtime is enabled without "
+ "the com.apple.security.cs.allow-jit entitlement.");
+#else
ORC_ERROR("Failed to create write and exec mmap regions. This "
"is probably because SELinux execmem check is enabled (good) "
"and $TMPDIR and $HOME are mounted noexec (bad).");
+#endif
}
#endif
#include <stdlib.h>
#include <stdarg.h>
+#if defined(HAVE_PTHREAD_JIT)
+ #include <pthread.h>
+#endif
+
#if defined(HAVE_CODEMEM_VIRTUALALLOC)
#include <windows.h>
#ifdef ORC_WINAPI_ONLY_APP
}
}
#endif
+
+#if defined(HAVE_PTHREAD_JIT)
+ ORC_INFO("pthread_jit_write_protect_supported_np() = %i",
+ pthread_jit_write_protect_supported_np());
+#endif
}
int
program->orccode->code_size = compiler->codeptr - compiler->code;
orc_code_allocate_codemem (program->orccode, program->orccode->code_size);
+#if defined(HAVE_PTHREAD_JIT)
+ pthread_jit_write_protect_np(0);
+#endif
#if defined(HAVE_CODEMEM_VIRTUALALLOC)
/* Ensure that code region is writable before memcpy */
_set_virtual_protect (program->orccode->code, program->orccode->code_size,
compiler->target->flush_cache (program->orccode);
}
+#if defined(HAVE_PTHREAD_JIT)
+ pthread_jit_write_protect_np(1);
+#endif
#if defined(HAVE_CODEMEM_VIRTUALALLOC)
/* Code region is now ready for execution */
if (!_set_virtual_protect (program->orccode->exec, program->orccode->code_size,