From e8a1bd1aad84511fcdd4f840a12051384134a97d Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Sat, 26 Nov 2022 00:13:01 +0530 Subject: [PATCH] Fix `WaitForAddress` timeout signal race A race could occur from the timeout path in `WaitForAddress` taking place at the same time as `SignalToAddress` has been caused, this causes a deadlock due to double-insertion. --- app/src/main/cpp/skyline/kernel/types/KProcess.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index 8a94d7bf..bac9a112 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -320,13 +320,18 @@ namespace skyline::kernel::type { std::scoped_lock lock{syncWaiterMutex}; auto queue{syncWaiters.equal_range(address)}; auto iterator{std::find(queue.first, queue.second, SyncWaiters::value_type{address, state.thread})}; - if (iterator != queue.second) + if (iterator != queue.second) { if (syncWaiters.erase(iterator) == queue.second) + // We need to update the boolean flag denoting that there are no more threads waiting on this address __atomic_store_n(address, false, __ATOMIC_SEQ_CST); + } else { + state.scheduler->WaitSchedule(false); + return {}; + } } state.scheduler->InsertThread(state.thread); - state.scheduler->WaitSchedule(); + state.scheduler->WaitSchedule(false); return result::TimedOut; } else {