Skip to content

Commit

Permalink
Remove if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
diegorusso committed Oct 18, 2024
1 parent 0b7fce8 commit f74cd79
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,12 @@ jit_alloc(size_t size)
int flags = MEM_COMMIT | MEM_RESERVE;
unsigned char *memory = VirtualAlloc(NULL, size, flags, PAGE_READWRITE);
int failed = memory == NULL;
#elif defined(__APPLE__)
int flags = MAP_ANONYMOUS | MAP_PRIVATE;
int prot = PROT_READ | PROT_WRITE;
//if (pthread_jit_write_protect_supported_np()) {
if (1) {
flags |= MAP_JIT;
prot |= PROT_EXEC;
}
#elif defined(__APPLE__) && defined(__aarch64__)
int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_JIT;
int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0);
int failed = memory == MAP_FAILED;
if (flags & MAP_JIT) {
pthread_jit_write_protect_np(0);
}
pthread_jit_write_protect_np(0);
#else
int flags = MAP_ANONYMOUS | MAP_PRIVATE;
int prot = PROT_READ | PROT_WRITE;
Expand Down Expand Up @@ -115,15 +108,10 @@ mark_executable(unsigned char *memory, size_t size)
}
int old;
int failed = !VirtualProtect(memory, size, PAGE_EXECUTE_READ, &old);
#elif defined(__APPLE__)
#elif defined(__APPLE__) && defined(__aarch64__)
int failed = 0;
__builtin___clear_cache((char *)memory, (char *)memory + size);
//if (pthread_jit_write_protect_supported_np()) {
if (1) {
pthread_jit_write_protect_np(1);
} else {
failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
}
pthread_jit_write_protect_np(1);
#else
__builtin___clear_cache((char *)memory, (char *)memory + size);
int failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
Expand Down

0 comments on commit f74cd79

Please sign in to comment.