From 2930d609ea4b24226418dcee957c91555f50b6c4 Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:22:32 +0200 Subject: [PATCH] SPU: Detect invalid STOP codes (code mining) --- rpcs3/Emu/Cell/SPUThread.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index d366000072..1053059d65 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -4144,9 +4144,32 @@ bool spu_thread::is_exec_code(u32 addr, std::span ls_ptr, u32 base_add return false; } - if (type == spu_itype::STOP && op.rb) + if (type == spu_itype::STOP) { - return false; + if (op.rb) + { + return false; + } + + if (avoid_dead_code) + { + switch (op.opcode) + { + case SYS_SPU_THREAD_STOP_YIELD: + case SYS_SPU_THREAD_STOP_GROUP_EXIT: + case SYS_SPU_THREAD_STOP_THREAD_EXIT: + case SYS_SPU_THREAD_STOP_RECEIVE_EVENT: + case SYS_SPU_THREAD_STOP_TRY_RECEIVE_EVENT: + case SYS_SPU_THREAD_STOP_SWITCH_SYSTEM_MODULE: + { + break; + } + default: + { + return false; + } + } + } } if (type & spu_itype::branch) @@ -6105,6 +6128,12 @@ bool spu_thread::stop_and_signal(u32 code) return true; } + case SYS_SPU_THREAD_STOP_SWITCH_SYSTEM_MODULE: + { + fmt::throw_exception("SYS_SPU_THREAD_STOP_SWITCH_SYSTEM_MODULE (op=0x%x, Out_MBox=%s)", code, _ref(pc), ch_out_mbox); + return true; + } + case SYS_SPU_THREAD_STOP_YIELD: { // SPU thread group yield (TODO)