PPU: Cleanup MacOs executable write protection guards

This commit is contained in:
Elad
2026-05-09 15:29:34 +03:00
parent d6e813cd72
commit 99d15190e5
5 changed files with 55 additions and 67 deletions
+25 -3
View File
@@ -434,13 +434,35 @@ namespace asmjit
#endif
}
#ifdef __APPLE__
struct jit_write_guard
{
jit_write_guard() noexcept
{
pthread_jit_write_protect_np(false);
// Ensure stores are not reordered by the compiler
atomic_fence_acq_rel();
}
~jit_write_guard() noexcept
{
// Ensure stores are not reordered by the compiler
atomic_fence_seq_cst();
pthread_jit_write_protect_np(true);
}
};
#else
#define jit_write_guard [[maybe_unused]] int
#endif
// Build runtime function with asmjit::X86Assembler
template <typename FT, typename Asm = native_asm, typename F>
inline FT build_function_asm(std::string_view name, F&& builder, ::jit_runtime* custom_runtime = nullptr, bool reduced_size = false)
{
#ifdef __APPLE__
pthread_jit_write_protect_np(false);
#endif
jit_write_guard jit_guard;
using namespace asmjit;
auto& rt = custom_runtime ? *custom_runtime : get_global_runtime();