From 4d193ecb6aa24a747848f87238bd60c363fa106a Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 29 Aug 2024 03:28:04 +0300 Subject: [PATCH] Block parallel JIT allocation on macos --- Utilities/JITASM.cpp | 5 +++++ rpcs3/util/vm_native.cpp | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Utilities/JITASM.cpp b/Utilities/JITASM.cpp index 785e25c97f..c39d261c22 100644 --- a/Utilities/JITASM.cpp +++ b/Utilities/JITASM.cpp @@ -253,6 +253,11 @@ uchar* jit_runtime::_alloc(usz size, usz align) noexcept u8* jit_runtime::alloc(usz size, usz align, bool exec) noexcept { +#if defined(__APPLE__) + static std::mutex s_alloc_lock; + std::lock_guard lock(s_alloc_lock); +#endif + if (exec) { return add_jit_memory(size, align); diff --git a/rpcs3/util/vm_native.cpp b/rpcs3/util/vm_native.cpp index 5be4b06d9b..0d566e3532 100644 --- a/rpcs3/util/vm_native.cpp +++ b/rpcs3/util/vm_native.cpp @@ -260,13 +260,7 @@ namespace utils #ifdef __APPLE__ #ifdef ARCH_ARM64 - // NOTE: On MacOS, parallel calls to mmap can return the same address more than once. Trying to madvise the same address twice throws EPERM. - static std::mutex mmap_lock; - void* ptr; - { - std::lock_guard lock(mmap_lock); - ptr = ::mmap(use_addr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); - } + auto ptr = ::mmap(use_addr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); #else auto ptr = ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); #endif