SPU: Detect invalid STOP codes (code mining)

This commit is contained in:
Eladash 2024-03-07 16:22:32 +02:00 committed by Elad.Ash
parent 069ca214ff
commit 2930d609ea
1 changed files with 31 additions and 2 deletions

View File

@ -4144,11 +4144,34 @@ bool spu_thread::is_exec_code(u32 addr, std::span<const u8> ls_ptr, u32 base_add
return false;
}
if (type == spu_itype::STOP && op.rb)
if (type == spu_itype::STOP)
{
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)
{
if (type == spu_itype::BR && op.rt && op.rt != 127u)
@ -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<u32>(pc), ch_out_mbox);
return true;
}
case SYS_SPU_THREAD_STOP_YIELD:
{
// SPU thread group yield (TODO)