]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: change strategy for marking executable pages on macos aarch64
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Nov 2023 01:43:00 +0000 (17:43 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 15 Nov 2023 01:43:00 +0000 (17:43 -0800)
vm/main-unix.cpp
vm/os-unix.cpp

index 551734ef30f6a53e3a97f34959b208a7de00a7af..03038b03771cd34b1615b0da4f14df0b5252a764 100644 (file)
@@ -1,6 +1,9 @@
 #include "master.hpp"
 
 int main(int argc, char** argv) {
+#if defined(__APPLE__) && defined(FACTOR_ARM64)
+  pthread_jit_write_protect_np(0);
+#endif
   factor::init_mvm();
   factor::start_standalone_factor(argc, argv);
   return 0;
index adf235880032d1edae34a3eb0fb910a7e8a16852..e7ff74f0ad0b6dc4c60ad904ff6dce2222b496d8 100644 (file)
@@ -79,20 +79,20 @@ segment::segment(cell size_, bool executable_p) {
 
   int pagesize = getpagesize();
 
+#if defined(__APPLE__) && defined(FACTOR_ARM64)
+  int prot = PROT_READ | PROT_WRITE;
+  int flags = MAP_ANON | MAP_PRIVATE | MAP_JIT;
+#else
   int prot;
   if (executable_p)
     prot = PROT_READ | PROT_WRITE | PROT_EXEC;
   else
     prot = PROT_READ | PROT_WRITE;
+  int flags = MAP_ANON | MAP_PRIVATE;
+#endif
 
   cell alloc_size = 2 * pagesize + size;
-#if defined(__APPLE__) && defined(FACTOR_ARM64)  // FIXME: could be in header file
-  char* array = (char*)mmap(NULL, alloc_size, prot,
-                            MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0);
-#else
-  char* array = (char*)mmap(NULL, alloc_size, prot,
-                            MAP_ANON | MAP_PRIVATE, -1, 0);
-#endif
+  char* array = (char*)mmap(NULL, alloc_size, prot, flags, -1, 0);
 
   if (array == (char*)-1)
     fatal_error("Out of memory in mmap", alloc_size);
@@ -100,6 +100,13 @@ segment::segment(cell size_, bool executable_p) {
   start = (cell)(array + pagesize);
   end = start + size;
 
+#if defined(__APPLE__) && defined(FACTOR_ARM64)
+  if (executable_p) {
+    if (mprotect((char*)start, size, prot | PROT_EXEC) == -1)
+      fatal_error("mprotect executable page failed", 0);
+  }
+#endif
+
   set_border_locked(true);
 }