From 7c313703a2c68fd952ac01a76780703ff9cd9cd4 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi <18193363+elad335@users.noreply.github.com> Date: Fri, 10 May 2024 19:44:39 +0300 Subject: [PATCH] Savestates: Fix SPU pause from access violation handler --- Utilities/Thread.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 6293785d60..3bd5752ac4 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1260,6 +1260,36 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe const auto cpu = get_current_cpu_thread(); + struct spu_unsavable + { + spu_thread* _spu; + + spu_unsavable(cpu_thread* cpu) noexcept + : _spu(cpu ? cpu->try_get() : nullptr) + { + if (_spu) + { + if (_spu->unsavable) + { + _spu = nullptr; + } + else + { + // Must not be saved inside access violation handler because it is unpredictable + _spu->unsavable = true; + } + } + } + + ~spu_unsavable() noexcept + { + if (_spu) + { + _spu->unsavable = false; + } + } + } spu_protection{cpu}; + if (addr < RAW_SPU_BASE_ADDR && vm::check_addr(addr) && rsx::g_access_violation_handler) { bool state_changed = false;