VERY experimental Nintendo Switch 2 emulator
C++
am: rewrite ILockAccessor
Liam844cd30b4a43
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex f8e093be79..073e42e008 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -431,8 +431,6 @@ add_library(core STATIChle/service/am/idle.hhle/service/am/library_applet_storage.cpphle/service/am/library_applet_storage.h- hle/service/am/lock_accessor.cpp- hle/service/am/lock_accessor.hhle/service/am/managed_layer_holder.cpphle/service/am/managed_layer_holder.hhle/service/am/omm.cpp@@ -471,6 +469,8 @@ add_library(core STATIChle/service/am/service/library_applet_proxy.hhle/service/am/service/library_applet_self_accessor.cpphle/service/am/service/library_applet_self_accessor.h+ hle/service/am/service/lock_accessor.cpp+ hle/service/am/service/lock_accessor.hhle/service/am/service/process_winding_controller.cpphle/service/am/service/process_winding_controller.hhle/service/am/service/self_controller.cppdiff --git a/src/core/hle/service/am/lock_accessor.cpp b/src/core/hle/service/am/lock_accessor.cppdeleted file mode 100644index d0bd8d95ee..0000000000--- a/src/core/hle/service/am/lock_accessor.cpp+++ /dev/null@@ -1,71 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#include "core/hle/service/am/lock_accessor.h"-#include "core/hle/service/ipc_helpers.h"--namespace Service::AM {--ILockAccessor::ILockAccessor(Core::System& system_)- : ServiceFramework{system_, "ILockAccessor"}, service_context{system_, "ILockAccessor"} {- // clang-format off- static const FunctionInfo functions[] = {- {1, &ILockAccessor::TryLock, "TryLock"},- {2, &ILockAccessor::Unlock, "Unlock"},- {3, &ILockAccessor::GetEvent, "GetEvent"},- {4,&ILockAccessor::IsLocked, "IsLocked"},- };- // clang-format on-- RegisterHandlers(functions);-- lock_event = service_context.CreateEvent("ILockAccessor::LockEvent");-}--ILockAccessor::~ILockAccessor() {- service_context.CloseEvent(lock_event);-};--void ILockAccessor::TryLock(HLERequestContext& ctx) {- IPC::RequestParser rp{ctx};- const auto return_handle = rp.Pop<bool>();-- LOG_WARNING(Service_AM, "(STUBBED) called, return_handle={}", return_handle);-- // TODO: When return_handle is true this function should return the lock handle-- is_locked = true;-- IPC::ResponseBuilder rb{ctx, 3};- rb.Push(ResultSuccess);- rb.Push<u8>(is_locked);-}--void ILockAccessor::Unlock(HLERequestContext& ctx) {- LOG_INFO(Service_AM, "called");-- is_locked = false;-- IPC::ResponseBuilder rb{ctx, 2};- rb.Push(ResultSuccess);-}--void ILockAccessor::GetEvent(HLERequestContext& ctx) {- LOG_INFO(Service_AM, "called");-- lock_event->Signal();-- IPC::ResponseBuilder rb{ctx, 2, 1};- rb.Push(ResultSuccess);- rb.PushCopyObjects(lock_event->GetReadableEvent());-}--void ILockAccessor::IsLocked(HLERequestContext& ctx) {- LOG_INFO(Service_AM, "called");-- IPC::ResponseBuilder rb{ctx, 2};- rb.Push(ResultSuccess);- rb.Push<u8>(is_locked);-}--} // namespace Service::AMdiff --git a/src/core/hle/service/am/lock_accessor.h b/src/core/hle/service/am/lock_accessor.hdeleted file mode 100644index 626f60e079..0000000000--- a/src/core/hle/service/am/lock_accessor.h+++ /dev/null@@ -1,28 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#pragma once--#include "core/hle/service/kernel_helpers.h"-#include "core/hle/service/service.h"--namespace Service::AM {--class ILockAccessor final : public ServiceFramework<ILockAccessor> {-public:- explicit ILockAccessor(Core::System& system_);- ~ILockAccessor() override;--private:- void TryLock(HLERequestContext& ctx);- void Unlock(HLERequestContext& ctx);- void GetEvent(HLERequestContext& ctx);- void IsLocked(HLERequestContext& ctx);-- bool is_locked{};-- Kernel::KEvent* lock_event;- KernelHelpers::ServiceContext service_context;-};--} // namespace Service::AMdiff --git a/src/core/hle/service/am/service/common_state_getter.cpp b/src/core/hle/service/am/service/common_state_getter.cppindex ac05b457b5..12d7e8cb18 100644--- a/src/core/hle/service/am/service/common_state_getter.cpp+++ b/src/core/hle/service/am/service/common_state_getter.cpp@@ -4,8 +4,8 @@#include "common/settings.h"#include "core/hle/service/am/am_results.h"#include "core/hle/service/am/applet.h"-#include "core/hle/service/am/lock_accessor.h"#include "core/hle/service/am/service/common_state_getter.h"+#include "core/hle/service/am/service/lock_accessor.h"#include "core/hle/service/apm/apm_interface.h"#include "core/hle/service/cmif_serialization.h"#include "core/hle/service/pm/pm.h"diff --git a/src/core/hle/service/am/service/lock_accessor.cpp b/src/core/hle/service/am/service/lock_accessor.cppnew file mode 100644index 0000000000..8e556fdd68--- /dev/null+++ b/src/core/hle/service/am/service/lock_accessor.cpp@@ -0,0 +1,75 @@+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#include "core/hle/service/am/service/lock_accessor.h"+#include "core/hle/service/cmif_serialization.h"++namespace Service::AM {++ILockAccessor::ILockAccessor(Core::System& system_)+ : ServiceFramework{system_, "ILockAccessor"}, m_context{system_, "ILockAccessor"},+ m_event{m_context} {+ // clang-format off+ static const FunctionInfo functions[] = {+ {1, D<&ILockAccessor::TryLock>, "TryLock"},+ {2, D<&ILockAccessor::Unlock>, "Unlock"},+ {3, D<&ILockAccessor::GetEvent>, "GetEvent"},+ {4, D<&ILockAccessor::IsLocked>, "IsLocked"},+ };+ // clang-format on++ RegisterHandlers(functions);++ m_event.Signal();+}++ILockAccessor::~ILockAccessor() = default;++Result ILockAccessor::TryLock(Out<bool> out_is_locked,+ OutCopyHandle<Kernel::KReadableEvent> out_handle,+ bool return_handle) {+ LOG_INFO(Service_AM, "called, return_handle={}", return_handle);++ {+ std::scoped_lock lk{m_mutex};+ if (m_is_locked) {+ *out_is_locked = false;+ } else {+ m_is_locked = true;+ *out_is_locked = true;+ }+ }++ if (return_handle) {+ *out_handle = m_event.GetHandle();+ }++ R_SUCCEED();+}++Result ILockAccessor::Unlock() {+ LOG_INFO(Service_AM, "called");++ {+ std::scoped_lock lk{m_mutex};+ m_is_locked = false;+ }++ m_event.Signal();+ R_SUCCEED();+}++Result ILockAccessor::GetEvent(OutCopyHandle<Kernel::KReadableEvent> out_handle) {+ LOG_INFO(Service_AM, "called");+ *out_handle = m_event.GetHandle();+ R_SUCCEED();+}++Result ILockAccessor::IsLocked(Out<bool> out_is_locked) {+ LOG_INFO(Service_AM, "called");+ std::scoped_lock lk{m_mutex};+ *out_is_locked = m_is_locked;+ R_SUCCEED();+}++} // namespace Service::AMdiff --git a/src/core/hle/service/am/service/lock_accessor.h b/src/core/hle/service/am/service/lock_accessor.hnew file mode 100644index 0000000000..9bfb5c0502--- /dev/null+++ b/src/core/hle/service/am/service/lock_accessor.h@@ -0,0 +1,32 @@+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#pragma once++#include "core/hle/service/cmif_types.h"+#include "core/hle/service/kernel_helpers.h"+#include "core/hle/service/os/event.h"+#include "core/hle/service/service.h"++namespace Service::AM {++class ILockAccessor final : public ServiceFramework<ILockAccessor> {+public:+ explicit ILockAccessor(Core::System& system_);+ ~ILockAccessor() override;++private:+ Result TryLock(Out<bool> out_is_locked, OutCopyHandle<Kernel::KReadableEvent> out_handle,+ bool return_handle);+ Result Unlock();+ Result GetEvent(OutCopyHandle<Kernel::KReadableEvent> out_handle);+ Result IsLocked(Out<bool> out_is_locked);++private:+ KernelHelpers::ServiceContext m_context;+ Event m_event;+ std::mutex m_mutex{};+ bool m_is_locked{};+};++} // namespace Service::AM