GH-134291: Support older macOS deployment targets for JIT builds (GH-137211)

This commit is contained in:
Brandt Bucher 2025-07-30 15:48:18 -07:00 committed by GitHub
parent 5f35f9b8fa
commit d591b5effb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 14 deletions

View file

@ -69,10 +69,6 @@ jit_alloc(size_t size)
#else
int flags = MAP_ANONYMOUS | MAP_PRIVATE;
int prot = PROT_READ | PROT_WRITE;
# ifdef MAP_JIT
flags |= MAP_JIT;
prot |= PROT_EXEC;
# endif
unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0);
int failed = memory == MAP_FAILED;
#endif
@ -118,11 +114,8 @@ mark_executable(unsigned char *memory, size_t size)
int old;
int failed = !VirtualProtect(memory, size, PAGE_EXECUTE_READ, &old);
#else
int failed = 0;
__builtin___clear_cache((char *)memory, (char *)memory + size);
#ifndef MAP_JIT
failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
#endif
int failed = mprotect(memory, size, PROT_EXEC | PROT_READ);
#endif
if (failed) {
jit_error("unable to protect executable memory");
@ -531,9 +524,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
if (memory == NULL) {
return -1;
}
#ifdef MAP_JIT
pthread_jit_write_protect_np(0);
#endif
// Collect memory stats
OPT_STAT_ADD(jit_total_memory_size, total_size);
OPT_STAT_ADD(jit_code_size, code_size);
@ -571,9 +561,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
data += group->data_size;
assert(code == memory + code_size);
assert(data == memory + code_size + state.trampolines.size + code_padding + data_size);
#ifdef MAP_JIT
pthread_jit_write_protect_np(1);
#endif
if (mark_executable(memory, total_size)) {
jit_free(memory, total_size);
return -1;