From 94d1f7c01a5c73ee74b71269ca4bc3741e74b22c Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Tue, 4 May 2021 03:21:29 -0300 Subject: [PATCH] Simplify apple silicon changes --- src/backend/A64/block_of_code.cpp | 10 +++------- src/backend/A64/emitter/a64_emitter.cpp | 6 ++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/backend/A64/block_of_code.cpp b/src/backend/A64/block_of_code.cpp index c27f66a1..cff246f8 100644 --- a/src/backend/A64/block_of_code.cpp +++ b/src/backend/A64/block_of_code.cpp @@ -52,9 +52,11 @@ constexpr size_t FAR_CODE_OFFSET = 100 * 1024 * 1024; #ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT void ProtectMemory(const void* base, size_t size, bool is_executable) { -#ifdef _WIN32 +#if defined(_WIN32) DWORD oldProtect = 0; VirtualProtect(const_cast(base), size, is_executable ? PAGE_EXECUTE_READ : PAGE_READWRITE, &oldProtect); +#elif defined(__APPLE__) + pthread_jit_write_protect_np(is_executable); #else static const size_t pageSize = sysconf(_SC_PAGESIZE); const size_t iaddr = reinterpret_cast(base); @@ -90,18 +92,12 @@ void BlockOfCode::EnableWriting() { #ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT ProtectMemory(GetCodePtr(), TOTAL_CODE_SIZE, false); #endif -#ifdef __APPLE__ - pthread_jit_write_protect_np(false); -#endif } void BlockOfCode::DisableWriting() { #ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT ProtectMemory(GetCodePtr(), TOTAL_CODE_SIZE, true); #endif -#ifdef __APPLE__ - pthread_jit_write_protect_np(true); -#endif } void BlockOfCode::ClearCache() { diff --git a/src/backend/A64/emitter/a64_emitter.cpp b/src/backend/A64/emitter/a64_emitter.cpp index cfe905be..efbb4767 100644 --- a/src/backend/A64/emitter/a64_emitter.cpp +++ b/src/backend/A64/emitter/a64_emitter.cpp @@ -366,12 +366,10 @@ void ARM64XEmitter::FlushIcacheSection(const u8* start, const u8* end) { if (start == end) return; -#if defined(IOS) +#if defined(__APPLE__) // Header file says this is equivalent to: sys_icache_invalidate(start, end - // start); - sys_cache_control(kCacheFunctionPrepareForExecution, start, end - start); -#elif defined(__APPLE__) - sys_icache_invalidate(const_cast(start), end - start); + sys_cache_control(kCacheFunctionPrepareForExecution, const_cast(start), end - start); #else // Don't rely on GCC's __clear_cache implementation, as it caches // icache/dcache cache line sizes, that can vary between cores on