CPU/CodeCache: Fix crash on Apple Silicon

This commit is contained in:
Stenzek
2023-10-24 18:23:55 +10:00
parent 06c4dc5e1b
commit f786138175
5 changed files with 72 additions and 46 deletions

View File

@ -18,6 +18,11 @@
#include <unistd.h>
#endif
#if defined(__APPLE__) && defined(__aarch64__)
// pthread_jit_write_protect_np()
#include <pthread.h>
#endif
Log_SetChannel(MemoryArena);
#ifdef _WIN32
@ -398,3 +403,31 @@ bool SharedMemoryMappingArea::Unmap(void* map_base, size_t map_size)
}
#endif
#if defined(__APPLE__) && defined(__aarch64__)
static thread_local int s_code_write_depth = 0;
void MemMap::BeginCodeWrite()
{
// Log_DebugFmt("BeginCodeWrite(): {}", s_code_write_depth);
if ((s_code_write_depth++) == 0)
{
// Log_DebugPrint(" pthread_jit_write_protect_np(0)");
pthread_jit_write_protect_np(0);
}
}
void MemMap::EndCodeWrite()
{
// Log_DebugFmt("EndCodeWrite(): {}", s_code_write_depth);
DebugAssert(s_code_write_depth > 0);
if ((--s_code_write_depth) == 0)
{
// Log_DebugPrint(" pthread_jit_write_protect_np(1)");
pthread_jit_write_protect_np(1);
}
}
#endif