From 607bad48f3687c2490d90f8c55efa2dcd7cbc195 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 30 Nov 2022 10:53:57 +0100 Subject: [PATCH] Invalidate CPU I-cache on Apple Silicon Call __builtin___clear_cache() after pthread_jit_write_protect_np() according to https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon --- src/virtual_memory.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/virtual_memory.c b/src/virtual_memory.c index 0fdc553..d2cdcda 100644 --- a/src/virtual_memory.c +++ b/src/virtual_memory.c @@ -189,6 +189,7 @@ void setPagesRX(void* ptr, size_t bytes) { && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 if (__builtin_available(macOS 11.0, *)) { pthread_jit_write_protect_np(1); + __builtin___clear_cache((char*)ptr, ((char*)ptr) + bytes); } else { pageProtect(ptr, bytes, PAGE_EXECUTE_READ, &errfunc); }