From 11ab9b7fa96fd03ca3d90e127574604cbff9af18 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 5 Jun 2021 16:41:02 +0300 Subject: [PATCH] Fix sys_event_flag_wait result set (#10404) Set result upon syscall exit, not at the beginning. --- rpcs3/Emu/Cell/lv2/sys_event_flag.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index de8be5dd8b..aaca1761e0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -102,7 +102,16 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm ppu.gpr[6] = 0; // Always set result - if (result) *result = 0; + struct store_result + { + vm::ptr ptr; + u64 val = 0; + + ~store_result() noexcept + { + if (ptr) *ptr = val; + } + } store{result}; if (!lv2_event_flag::check_mode(mode)) { @@ -156,7 +165,7 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm } else { - if (result) *result = ppu.gpr[6]; + store.val = ppu.gpr[6]; return CELL_OK; } @@ -201,12 +210,7 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm } } - if (ppu.test_stopped()) - { - return 0; - } - - if (result) *result = ppu.gpr[6]; + store.val = ppu.gpr[6]; return not_an_error(ppu.gpr[3]); }