ARM64 macOS JIT - fix warnings + some cleanup

This commit is contained in:
WaluigiWare64 2021-07-23 14:07:23 +01:00
parent b1c2665c39
commit 8513900892
3 changed files with 28 additions and 20 deletions

View File

@ -43,9 +43,6 @@
#include "Wifi.h" #include "Wifi.h"
#include "NDSCart.h" #include "NDSCart.h"
#if defined(__APPLE__) && defined(__aarch64__)
#include <pthread.h>
#endif
#include "ARMJIT_x64/ARMJIT_Offsets.h" #include "ARMJIT_x64/ARMJIT_Offsets.h"
static_assert(offsetof(ARM, CPSR) == ARM_CPSR_offset, ""); static_assert(offsetof(ARM, CPSR) == ARM_CPSR_offset, "");
@ -320,9 +317,7 @@ void Init()
void DeInit() void DeInit()
{ {
#if defined(__APPLE__) && defined(__aarch64__) JitEnableWrite();
pthread_jit_write_protect_np(false);
#endif
ResetBlockCache(); ResetBlockCache();
ARMJIT_Memory::DeInit(); ARMJIT_Memory::DeInit();
@ -331,9 +326,7 @@ void DeInit()
void Reset() void Reset()
{ {
#if defined(__APPLE__) && defined(__aarch64__) JitEnableWrite();
pthread_jit_write_protect_np(false);
#endif
ResetBlockCache(); ResetBlockCache();
ARMJIT_Memory::Reset(); ARMJIT_Memory::Reset();
@ -918,13 +911,10 @@ void CompileBlock(ARM* cpu)
block->StartAddrLocal = localAddr; block->StartAddrLocal = localAddr;
FloodFillSetFlags(instrs, i - 1, 0xF); FloodFillSetFlags(instrs, i - 1, 0xF);
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(false); JitEnableWrite();
#endif
block->EntryPoint = JITCompiler->CompileBlock(cpu, thumb, instrs, i, hasMemoryInstr); block->EntryPoint = JITCompiler->CompileBlock(cpu, thumb, instrs, i, hasMemoryInstr);
#if defined(__APPLE__) && defined(__aarch64__) JitEnableExecute();
pthread_jit_write_protect_np(true);
#endif
JIT_DEBUGPRINT("block start %p\n", block->EntryPoint); JIT_DEBUGPRINT("block start %p\n", block->EntryPoint);
} }
@ -1168,4 +1158,20 @@ void ResetBlockCache()
JITCompiler->Reset(); JITCompiler->Reset();
} }
void JitEnableWrite()
{
#if defined(__APPLE__) && defined(__aarch64__)
if (__builtin_available(macOS 11.0, *))
pthread_jit_write_protect_np(false);
#endif
}
void JitEnableExecute()
{
#if defined(__APPLE__) && defined(__aarch64__)
if (__builtin_available(macOS 11.0, *))
pthread_jit_write_protect_np(true);
#endif
}
} }

View File

@ -24,6 +24,10 @@
#include "ARM.h" #include "ARM.h"
#include "ARM_InstrInfo.h" #include "ARM_InstrInfo.h"
#if defined(__APPLE__) && defined(__aarch64__)
#include <pthread.h>
#endif
namespace ARMJIT namespace ARMJIT
{ {
@ -48,6 +52,8 @@ void ResetBlockCache();
JitBlockEntry LookUpBlock(u32 num, u64* entries, u32 offset, u32 addr); JitBlockEntry LookUpBlock(u32 num, u64* entries, u32 offset, u32 addr);
bool SetupExecutableRegion(u32 num, u32 blockAddr, u64*& entry, u32& start, u32& size); bool SetupExecutableRegion(u32 num, u32 blockAddr, u64*& entry, u32& start, u32& size);
void JitEnableWrite();
void JitEnableExecute();
} }
extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry); extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry);

View File

@ -33,10 +33,6 @@ extern char __start__;
#include <stdlib.h> #include <stdlib.h>
#ifdef __APPLE__
#include <pthread.h>
#endif
using namespace Arm64Gen; using namespace Arm64Gen;
extern "C" void ARM_Ret(); extern "C" void ARM_Ret();
@ -266,7 +262,7 @@ Compiler::Compiler()
u64 alignedSize = (((u64)JitMem + sizeof(JitMem)) & ~(pageSize - 1)) - (u64)pageAligned; u64 alignedSize = (((u64)JitMem + sizeof(JitMem)) & ~(pageSize - 1)) - (u64)pageAligned;
#ifdef __APPLE__ #ifdef __APPLE__
pageAligned = (u8*)mmap(NULL, 1024*1024*16, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT,-1, 0); pageAligned = (u8*)mmap(NULL, 1024*1024*16, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT,-1, 0);
pthread_jit_write_protect_np(false); JitEnableWrite();
#else #else
mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE);
#endif #endif