// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" #include "core/hle/kernel/k_memory_layout.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/svc.h" #include "core/hle/kernel/svc_results.h" namespace Kernel::Svc { /// Wait process wide key atomic Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_key, u32 tag, s64 timeout_ns) { LOG_TRACE(Kernel_SVC, "called address={:X}, cv_key={:X}, tag=0x{:08X}, timeout_ns={}", address, cv_key, tag, timeout_ns); // Validate input. if (IsKernelAddress(address)) { LOG_ERROR(Kernel_SVC, "Attempted to wait on kernel address (address={:08X})", address); return ResultInvalidCurrentMemory; } if (!Common::IsAligned(address, sizeof(s32))) { LOG_ERROR(Kernel_SVC, "Address must be 4 byte aligned (address={:08X})", address); return ResultInvalidAddress; } // Convert timeout from nanoseconds to ticks. s64 timeout{}; if (timeout_ns > 0) { const s64 offset_tick(timeout_ns); if (offset_tick > 0) { timeout = offset_tick + 2; if (timeout <= 0) { timeout = std::numeric_limits::max(); } } else { timeout = std::numeric_limits::max(); } } else { timeout = timeout_ns; } // Wait on the condition variable. return system.Kernel().CurrentProcess()->WaitConditionVariable( address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); } Result WaitProcessWideKeyAtomic32(Core::System& system, u32 address, u32 cv_key, u32 tag, u32 timeout_ns_low, u32 timeout_ns_high) { const auto timeout_ns = static_cast(timeout_ns_low | (u64{timeout_ns_high} << 32)); return WaitProcessWideKeyAtomic(system, address, cv_key, tag, timeout_ns); } /// Signal process wide key void SignalProcessWideKey(Core::System& system, VAddr cv_key, s32 count) { LOG_TRACE(Kernel_SVC, "called, cv_key=0x{:X}, count=0x{:08X}", cv_key, count); // Signal the condition variable. return system.Kernel().CurrentProcess()->SignalConditionVariable( Common::AlignDown(cv_key, sizeof(u32)), count); } void SignalProcessWideKey32(Core::System& system, u32 cv_key, s32 count) { SignalProcessWideKey(system, cv_key, count); } } // namespace Kernel::Svc