From ddba30988be3602a0ac12569e4101dd6c04c56b8 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 19 Aug 2022 12:02:45 +0300 Subject: [PATCH] vm: Attempt to not remove cpu_flag::wait flag during access violation --- Utilities/Thread.cpp | 6 ++++-- rpcs3/Emu/Cell/lv2/sys_sync.h | 2 +- rpcs3/Emu/Memory/vm.cpp | 5 ++++- rpcs3/Emu/Memory/vm_locking.h | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index f4e1215747..62a303d0d0 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1242,14 +1242,16 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe if (rsx::g_access_violation_handler) { + bool state_changed = false; + if (cpu) { - vm::temporary_unlock(*cpu); + state_changed = vm::temporary_unlock(*cpu); } bool handled = rsx::g_access_violation_handler(addr, is_writing); - if (cpu && (cpu->state += cpu_flag::temp, cpu->test_stopped())) + if (state_changed && (cpu->state += cpu_flag::temp, cpu->test_stopped())) { // } diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index 68dc6a1e3a..6803a221fc 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -63,7 +63,7 @@ enum ppu_thread_status : u32; namespace vm { - void temporary_unlock(cpu_thread& cpu) noexcept; + bool temporary_unlock(cpu_thread& cpu) noexcept; } namespace cpu_counter diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index b1907b7354..0c6cbae8a9 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -380,7 +380,7 @@ namespace vm } } - void temporary_unlock(cpu_thread& cpu) noexcept + bool temporary_unlock(cpu_thread& cpu) noexcept { bs_t add_state = cpu_flag::wait; @@ -392,7 +392,10 @@ namespace vm if (add_state - cpu.state) { cpu.state += add_state; + return true; } + + return false; } void temporary_unlock() noexcept diff --git a/rpcs3/Emu/Memory/vm_locking.h b/rpcs3/Emu/Memory/vm_locking.h index 269041260b..229e5df789 100644 --- a/rpcs3/Emu/Memory/vm_locking.h +++ b/rpcs3/Emu/Memory/vm_locking.h @@ -105,7 +105,7 @@ namespace vm void passive_unlock(cpu_thread& cpu); // Optimization (set cpu_flag::memory) - void temporary_unlock(cpu_thread& cpu) noexcept; + bool temporary_unlock(cpu_thread& cpu) noexcept; void temporary_unlock() noexcept; struct writer_lock final