svc_lock.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/core.h"
  4. #include "core/hle/kernel/k_memory_layout.h"
  5. #include "core/hle/kernel/k_process.h"
  6. #include "core/hle/kernel/svc.h"
  7. namespace Kernel::Svc {
  8. /// Attempts to locks a mutex
  9. Result ArbitrateLock(Core::System& system, Handle thread_handle, u64 address, u32 tag) {
  10. LOG_TRACE(Kernel_SVC, "called thread_handle=0x{:08X}, address=0x{:X}, tag=0x{:08X}",
  11. thread_handle, address, tag);
  12. // Validate the input address.
  13. R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
  14. R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress);
  15. R_RETURN(GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag));
  16. }
  17. /// Unlock a mutex
  18. Result ArbitrateUnlock(Core::System& system, u64 address) {
  19. LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);
  20. // Validate the input address.
  21. R_UNLESS(!IsKernelAddress(address), ResultInvalidCurrentMemory);
  22. R_UNLESS(Common::IsAligned(address, sizeof(u32)), ResultInvalidAddress);
  23. R_RETURN(GetCurrentProcess(system.Kernel()).SignalToAddress(address));
  24. }
  25. Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) {
  26. R_RETURN(ArbitrateLock(system, thread_handle, address, tag));
  27. }
  28. Result ArbitrateUnlock64(Core::System& system, uint64_t address) {
  29. R_RETURN(ArbitrateUnlock(system, address));
  30. }
  31. Result ArbitrateLock64From32(Core::System& system, Handle thread_handle, uint32_t address,
  32. uint32_t tag) {
  33. R_RETURN(ArbitrateLock(system, thread_handle, address, tag));
  34. }
  35. Result ArbitrateUnlock64From32(Core::System& system, uint32_t address) {
  36. R_RETURN(ArbitrateUnlock(system, address));
  37. }
  38. } // namespace Kernel::Svc