From 7d55a85fa612f6e30c873f096f04d51be77ceb58 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Tue, 16 Jan 2024 04:35:28 +0100 Subject: [PATCH] Replaces page fault triggers with assembly --- rpcs3/Emu/Cell/SPUThread.cpp | 4 ++-- rpcs3/Emu/Memory/vm.cpp | 2 +- rpcs3/util/asm.hpp | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index bf325019c4..0b92069975 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -3721,7 +3721,7 @@ bool spu_thread::do_putllc(const spu_mfc_cmd& args) if (!vm::check_addr(addr, vm::page_writable)) { - vm::_ref>(addr) += 0; // Access violate + utils::trigger_write_page_fault(vm::base(addr)); } raddr = 0; @@ -3823,7 +3823,7 @@ void do_cell_atomic_128_store(u32 addr, const void* to_write) else if (!g_use_rtm) { // Provoke page fault - vm::_ref>(addr) += 0; + utils::trigger_write_page_fault(vm::base(addr)); // Hard lock auto spu = cpu ? cpu->try_get() : nullptr; diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 4397dffc53..eb16be6123 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -237,7 +237,7 @@ namespace vm // Try triggering a page fault (write) // TODO: Read memory if needed - vm::_ref>(test / 4096 == begin / 4096 ? begin : test) += 0; + utils::trigger_write_page_fault(vm::base(test / 4096 == begin / 4096 ? begin : test)); continue; } } diff --git a/rpcs3/util/asm.hpp b/rpcs3/util/asm.hpp index 270e3e9ca8..4733516bdf 100644 --- a/rpcs3/util/asm.hpp +++ b/rpcs3/util/asm.hpp @@ -2,6 +2,7 @@ #include "util/types.hpp" #include "util/tsc.hpp" +#include "util/atomic.hpp" #include extern bool g_use_rtm; @@ -435,6 +436,15 @@ namespace utils return factor1 > 0 && T{umax} / factor1 < factor2 ? T{umax} : static_cast(factor1 * factor2); } + inline void trigger_write_page_fault(void* ptr) + { +#if defined(ARCH_X64) && !defined(_MSC_VER) + __asm__ volatile("lock orl $0, 0(%0)" :: "r" (ptr)); +#else + *static_cast *>(ptr) += 0; +#endif + } + inline void trap() { #ifdef _M_X64