mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-21 07:35:41 -04:00
CPU/CodeCache: Fix crash on Apple Silicon
This commit is contained in:
@ -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
|
||||
|
@ -41,6 +41,17 @@ void DestroySharedMemory(void* ptr);
|
||||
void* MapSharedMemory(void* handle, size_t offset, void* baseaddr, size_t size, PageProtect mode);
|
||||
void UnmapSharedMemory(void* baseaddr, size_t size);
|
||||
bool MemProtect(void* baseaddr, size_t size, PageProtect mode);
|
||||
|
||||
/// JIT write protect for Apple Silicon. Needs to be called prior to writing to any RWX pages.
|
||||
#if !defined(__APPLE__) || !defined(__aarch64__)
|
||||
// clang-format off
|
||||
ALWAYS_INLINE static void BeginCodeWrite() { }
|
||||
ALWAYS_INLINE static void EndCodeWrite() { }
|
||||
// clang-format on
|
||||
#else
|
||||
void BeginCodeWrite();
|
||||
void EndCodeWrite();
|
||||
#endif
|
||||
} // namespace MemMap
|
||||
|
||||
class SharedMemoryMappingArea
|
||||
|
Reference in New Issue
Block a user