From 26b5eebc17cdffd37708642e43a857ef452ecc28 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 4 Apr 2015 19:00:02 +0300 Subject: [PATCH] Bugfixes --- rpcs3/Emu/ARMv7/Modules/sceLibc.cpp | 36 +++++++++++++------- rpcs3/Emu/Cell/PPUInterpreter.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 8 ++--- rpcs3/Emu/SysCalls/lv2/sys_process.cpp | 26 ++++++++++---- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/rpcs3/Emu/ARMv7/Modules/sceLibc.cpp b/rpcs3/Emu/ARMv7/Modules/sceLibc.cpp index c724fe56a7..98fab490a0 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceLibc.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceLibc.cpp @@ -13,6 +13,8 @@ typedef void(atexit_func_t)(vm::psv::ptr); std::vector> g_atexit; +std::mutex g_atexit_mutex; + std::string armv7_fmt(ARMv7Context& context, vm::psv::ptr fmt, u32 g_count, u32 f_count, u32 v_count) { std::string result; @@ -152,7 +154,7 @@ namespace sce_libc_func { sceLibc.Warning("__cxa_atexit(func=*0x%x, arg=*0x%x, dso=*0x%x)", func, arg, dso); - LV2_LOCK; + std::lock_guard lock(g_atexit_mutex); g_atexit.insert(g_atexit.begin(), [func, arg, dso](ARMv7Context& context) { @@ -164,7 +166,7 @@ namespace sce_libc_func { sceLibc.Warning("__aeabi_atexit(arg=*0x%x, func=*0x%x, dso=*0x%x)", arg, func, dso); - LV2_LOCK; + std::lock_guard lock(g_atexit_mutex); g_atexit.insert(g_atexit.begin(), [func, arg, dso](ARMv7Context& context) { @@ -176,19 +178,27 @@ namespace sce_libc_func { sceLibc.Warning("exit()"); - for (auto func : g_atexit) + std::lock_guard lock(g_atexit_mutex); + + if (!Emu.IsStopped()) { - func(context); + for (auto func : decltype(g_atexit)(std::move(g_atexit))) + { + func(context); + } + + sceLibc.Success("Process finished"); + + CallAfter([]() + { + Emu.Stop(); + }); + + while (!Emu.IsStopped()) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } } - - g_atexit.clear(); - - sceLibc.Success("Process finished"); - - CallAfter([]() - { - Emu.Stop(); - }); } void printf(ARMv7Context& context, vm::psv::ptr fmt) // va_args... diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index 9257b33760..e012641c37 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -225,7 +225,7 @@ void ppu_interpreter::VCMPBFP(PPUThread& CPU, ppu_opcode_t op) const auto b = CPU.VPR[op.vb].vf; const auto sign = _mm_castsi128_ps(_mm_set1_epi32(0x80000000)); const auto bneg = _mm_xor_ps(b, sign); - CPU.VPR[op.vd].vf = _mm_or_ps(_mm_and_ps(_mm_cmple_ps(a, b), sign), _mm_and_ps(_mm_cmpge_ps(a, bneg), _mm_castsi128_ps(_mm_set1_epi32(0x40000000)))); + CPU.VPR[op.vd].vf = _mm_or_ps(_mm_and_ps(_mm_cmpnle_ps(a, b), sign), _mm_and_ps(_mm_cmpnge_ps(a, bneg), _mm_castsi128_ps(_mm_set1_epi32(0x40000000)))); } void ppu_interpreter::VCMPBFP_(PPUThread& CPU, ppu_opcode_t op) diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 34844ec5e5..f5d3426e95 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -230,7 +230,7 @@ s32 sys_lwmutex_lock(PPUThread& CPU, vm::ptr lwmutex, u64 timeout // locking succeeded auto old = lwmutex->owner.exchange(tid); - if (old.data() != se32(lwmutex_reserved)) + if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwmutex_lock(lwmutex=*0x%x): locking failed (owner=0x%x)", lwmutex, old); } @@ -301,7 +301,7 @@ s32 sys_lwmutex_trylock(PPUThread& CPU, vm::ptr lwmutex) // locking succeeded auto old = lwmutex->owner.exchange(tid); - if (old.data() != se32(lwmutex_reserved)) + if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwmutex_trylock(lwmutex=*0x%x): locking failed (owner=0x%x)", lwmutex, old); } @@ -592,7 +592,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) const auto old = lwmutex->owner.exchange(tid); lwmutex->recursive_count = recursive_value; - if (old.data() != se32(lwmutex_reserved)) + if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwcond_wait(lwcond=*0x%x): locking failed (lwmutex->owner=0x%x)", lwcond, old); } @@ -621,7 +621,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) const auto old = lwmutex->owner.exchange(tid); lwmutex->recursive_count = recursive_value; - if (old.data() != se32(lwmutex_reserved)) + if (old.data() != se32(lwmutex_reserved) && !Emu.IsStopped()) { sysPrxForUser.Fatal("sys_lwcond_wait(lwcond=*0x%x): locking failed after timeout (lwmutex->owner=0x%x)", lwcond, old); } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp index 45fb9d0a7b..ccafdcab30 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp @@ -30,15 +30,27 @@ s32 sys_process_getppid() return 0; } -s32 sys_process_exit(s32 errorcode) +s32 sys_process_exit(s32 status) { - sys_process.Warning("sys_process_exit(%d)", errorcode); - Emu.Pause(); - sys_process.Success("Process finished"); - CallAfter([]() + sys_process.Warning("sys_process_exit(status=0x%x)", status); + + LV2_LOCK; + + if (!Emu.IsStopped()) { - Emu.Stop(); - }); + sys_process.Success("Process finished"); + + CallAfter([]() + { + Emu.Stop(); + }); + + while (!Emu.IsStopped()) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + } + return CELL_OK; }