diff options
author | Mai <mai.iam2048@gmail.com> | 2023-02-05 08:26:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-05 08:26:52 +0100 |
commit | 037300014385d7dd25029d7aac188f325f1e5bc3 (patch) | |
tree | be79f36453a4735088d9230e02f426792077eeb4 /src/core/hle/kernel/svc/svc_lock.cpp | |
parent | Merge pull request #9720 from SoRadGaming/discordPresenceUpdate (diff) | |
parent | kernel/svc: Split implementations into separate files (diff) | |
download | yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar.gz yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar.bz2 yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar.lz yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar.xz yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.tar.zst yuzu-037300014385d7dd25029d7aac188f325f1e5bc3.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/svc/svc_lock.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/core/hle/kernel/svc/svc_lock.cpp b/src/core/hle/kernel/svc/svc_lock.cpp new file mode 100644 index 000000000..45f2a6553 --- /dev/null +++ b/src/core/hle/kernel/svc/svc_lock.cpp @@ -0,0 +1,57 @@ +// 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/svc.h" + +namespace Kernel::Svc { + +/// Attempts to locks a mutex +Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address, u32 tag) { + LOG_TRACE(Kernel_SVC, "called thread_handle=0x{:08X}, address=0x{:X}, tag=0x{:08X}", + thread_handle, address, tag); + + // Validate the input address. + if (IsKernelAddress(address)) { + LOG_ERROR(Kernel_SVC, "Attempting to arbitrate a lock on a kernel address (address={:08X})", + address); + return ResultInvalidCurrentMemory; + } + if (!Common::IsAligned(address, sizeof(u32))) { + LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address); + return ResultInvalidAddress; + } + + return system.Kernel().CurrentProcess()->WaitForAddress(thread_handle, address, tag); +} + +Result ArbitrateLock32(Core::System& system, Handle thread_handle, u32 address, u32 tag) { + return ArbitrateLock(system, thread_handle, address, tag); +} + +/// Unlock a mutex +Result ArbitrateUnlock(Core::System& system, VAddr address) { + LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); + + // Validate the input address. + if (IsKernelAddress(address)) { + LOG_ERROR(Kernel_SVC, + "Attempting to arbitrate an unlock on a kernel address (address={:08X})", + address); + return ResultInvalidCurrentMemory; + } + if (!Common::IsAligned(address, sizeof(u32))) { + LOG_ERROR(Kernel_SVC, "Input address must be 4 byte aligned (address: {:08X})", address); + return ResultInvalidAddress; + } + + return system.Kernel().CurrentProcess()->SignalToAddress(address); +} + +Result ArbitrateUnlock32(Core::System& system, u32 address) { + return ArbitrateUnlock(system, address); +} + +} // namespace Kernel::Svc |