Skip to content

Commit

Permalink
Invalidate CPU I-cache on Apple Silicon
Browse files Browse the repository at this point in the history
Call sys_icache_invalidate() after pthread_jit_write_protect_np() according to https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon
  • Loading branch information
SChernykh committed Nov 30, 2022
1 parent 261d58c commit 9ab7d58
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/virtual_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include <pthread.h>
# include <sys/utsname.h>
# include <stdio.h>
# if defined(MAC_OS_VERSION_11_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
# include <libkern/OSCacheControl.h>
# endif
# endif
#endif
#include <sys/types.h>
Expand Down Expand Up @@ -189,6 +192,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);
sys_icache_invalidate(ptr, bytes);
} else {
pageProtect(ptr, bytes, PAGE_EXECUTE_READ, &errfunc);
}
Expand Down

0 comments on commit 9ab7d58

Please sign in to comment.