From d0c56235f4c000e9574a1c80ad02f71c519cdd55 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Sat, 26 Nov 2022 00:16:52 +0530 Subject: [PATCH] Read `address` atomically in `WaitForAddress` We didn't read the values for arbitration atomically in all cases as we should have, this consolidates the reading of the value and uses the value across all cases. --- app/src/main/cpp/skyline/kernel/types/KProcess.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index bac9a112..303e7a9a 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -288,14 +288,14 @@ namespace skyline::kernel::type { { std::scoped_lock lock{syncWaiterMutex}; + u32 userValue{__atomic_load_n(address, __ATOMIC_SEQ_CST)}; switch (type) { case ArbitrationType::WaitIfLessThan: - if (*address >= value) [[unlikely]] + if (userValue >= value) [[unlikely]] return result::InvalidState; break; case ArbitrationType::DecrementAndWaitIfLessThan: { - u32 userValue{__atomic_load_n(address, __ATOMIC_SEQ_CST)}; do { if (value <= userValue) [[unlikely]] // We want to explicitly decrement **after** the check return result::InvalidState; @@ -304,7 +304,7 @@ namespace skyline::kernel::type { } case ArbitrationType::WaitIfEqual: - if (*address != value) [[unlikely]] + if (userValue != value) [[unlikely]] return result::InvalidState; break; }