github.com/eh-steve/goloader@v0.0.0-20240111193454-90ff3cfdae39/mmap/darwin_arm64/darwin_arm64_cgo/mmap_darwin_arm64.go (about)

     1  //go:build darwin && arm64
     2  // +build darwin,arm64
     3  
     4  package darwin_arm64_cgo
     5  
     6  /*
     7  #cgo darwin LDFLAGS: -lpthread
     8  
     9  #include <pthread.h>
    10  #include <libkern/OSCacheControl.h>
    11  
    12  void jit_write_protect(int enable) {
    13  	pthread_jit_write_protect_np(enable);
    14  }
    15  void cache_invalidate(void* start, size_t len) {
    16  	sys_icache_invalidate(start, len);
    17  }
    18  */
    19  import "C"
    20  import "unsafe"
    21  
    22  func MakeThreadJITCodeExecutable(ptr uintptr, len int) {
    23  	C.jit_write_protect(C.int(1))
    24  	C.cache_invalidate(unsafe.Pointer(ptr), C.size_t(len))
    25  }
    26  
    27  func WriteProtectDisable() {
    28  	C.jit_write_protect(C.int(0))
    29  }