diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 3028ca94c1..d35ec740cc 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -858,6 +858,11 @@ error_code sys_spu_thread_write_ls(ppu_thread& ppu, u32 id, u32 lsa, u64 value, sys_spu.trace("sys_spu_thread_write_ls(id=0x%x, lsa=0x%05x, value=0x%llx, type=%d)", id, lsa, value, type); + if (lsa >= 0x40000 || type > 8 || !type || (type | lsa) & (type - 1)) // check range and alignment + { + return CELL_EINVAL; + } + const auto thread = idm::get>(id); if (UNLIKELY(!thread || !thread->group)) @@ -865,11 +870,6 @@ error_code sys_spu_thread_write_ls(ppu_thread& ppu, u32 id, u32 lsa, u64 value, return CELL_ESRCH; } - if (lsa >= 0x40000 || lsa + type > 0x40000 || lsa % type) // check range and alignment - { - return CELL_EINVAL; - } - const auto group = thread->group; std::lock_guard lock(group->mutex); @@ -885,7 +885,7 @@ error_code sys_spu_thread_write_ls(ppu_thread& ppu, u32 id, u32 lsa, u64 value, case 2: thread->_ref(lsa) = (u16)value; break; case 4: thread->_ref(lsa) = (u32)value; break; case 8: thread->_ref(lsa) = value; break; - default: return CELL_EINVAL; + default: ASSUME(0); } return CELL_OK; @@ -897,6 +897,11 @@ error_code sys_spu_thread_read_ls(ppu_thread& ppu, u32 id, u32 lsa, vm::ptr sys_spu.trace("sys_spu_thread_read_ls(id=0x%x, lsa=0x%05x, value=*0x%x, type=%d)", id, lsa, value, type); + if (lsa >= 0x40000 || type > 8 || !type || (type | lsa) & (type - 1)) // check range and alignment + { + return CELL_EINVAL; + } + const auto thread = idm::get>(id); if (UNLIKELY(!thread || !thread->group)) @@ -904,11 +909,6 @@ error_code sys_spu_thread_read_ls(ppu_thread& ppu, u32 id, u32 lsa, vm::ptr return CELL_ESRCH; } - if (lsa >= 0x40000 || lsa + type > 0x40000 || lsa % type) // check range and alignment - { - return CELL_EINVAL; - } - const auto group = thread->group; std::lock_guard lock(group->mutex); @@ -924,7 +924,7 @@ error_code sys_spu_thread_read_ls(ppu_thread& ppu, u32 id, u32 lsa, vm::ptr case 2: *value = thread->_ref(lsa); break; case 4: *value = thread->_ref(lsa); break; case 8: *value = thread->_ref(lsa); break; - default: return CELL_EINVAL; + default: ASSUME(0); } return CELL_OK;