dmnt: fix edge case in debug events thread

This commit is contained in:
Michael Scire 2019-09-16 22:47:00 -07:00 committed by SciresM
parent 8abee1bdaa
commit fe2dd671fb

View file

@ -200,7 +200,7 @@ namespace sts::dmnt::cheat::impl {
/* Spawn application detection thread, spawn cheat vm thread. */ /* Spawn application detection thread, spawn cheat vm thread. */
R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, 0x4000, 39)); R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, 0x4000, 39));
R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, 0x4000, 48)); R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, 0x4000, 48));
R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, 0x4000, 48)); R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, 0x4000, 24));
/* Start threads. */ /* Start threads. */
R_ASSERT(this->detect_thread.Start()); R_ASSERT(this->detect_thread.Start());
@ -547,6 +547,7 @@ namespace sts::dmnt::cheat::impl {
while (true) { while (true) {
/* Atomically wait (and clear) signal for new process. */ /* Atomically wait (and clear) signal for new process. */
this_ptr->debug_events_signal.Wait(true); this_ptr->debug_events_signal.Wait(true);
while (true) {
while (R_SUCCEEDED(svcWaitSynchronizationSingle(this_ptr->GetCheatProcessHandle(), U64_MAX))) { while (R_SUCCEEDED(svcWaitSynchronizationSingle(this_ptr->GetCheatProcessHandle(), U64_MAX))) {
std::scoped_lock lk(this_ptr->cheat_lock); std::scoped_lock lk(this_ptr->cheat_lock);
@ -555,6 +556,14 @@ namespace sts::dmnt::cheat::impl {
dmnt::cheat::impl::ContinueCheatProcess(this_ptr->GetCheatProcessHandle()); dmnt::cheat::impl::ContinueCheatProcess(this_ptr->GetCheatProcessHandle());
} }
} }
/* WaitSynchronization failed. This means someone canceled our synchronization, possibly us. */
/* Let's check if we should quit! */
std::scoped_lock lk(this_ptr->cheat_lock);
if (!this_ptr->HasActiveCheatProcess()) {
break;
}
}
} }
} }