VERY experimental Nintendo Switch 2 emulator
C++
am: rewrite appletAE, appletOE
Liam0276ae2f951e
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cppindex 4acc609563..a4d8454e8d 100644--- a/src/android/app/src/main/jni/native.cpp+++ b/src/android/app/src/main/jni/native.cpp@@ -49,9 +49,7 @@#include "core/frontend/applets/profile_select.h"#include "core/frontend/applets/software_keyboard.h"#include "core/frontend/applets/web_browser.h"-#include "core/hle/service/am/applet_ae.h"#include "core/hle/service/am/applet_manager.h"-#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/am/frontend/applets.h"#include "core/hle/service/filesystem/filesystem.h"#include "core/loader/loader.h"diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex 2d54909684..5ae31932c1 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -417,14 +417,10 @@ add_library(core STATIChle/service/am/am_types.hhle/service/am/applet.cpphle/service/am/applet.h- hle/service/am/applet_ae.cpp- hle/service/am/applet_ae.hhle/service/am/applet_manager.cpphle/service/am/applet_data_broker.cpphle/service/am/applet_data_broker.hhle/service/am/applet_manager.h- hle/service/am/applet_oe.cpp- hle/service/am/applet_oe.hhle/service/am/applet_common_functions.cpphle/service/am/applet_common_functions.hhle/service/am/applet_message_queue.cpp@@ -473,6 +469,10 @@ add_library(core STATIChle/service/am/process.hhle/service/am/self_controller.cpphle/service/am/self_controller.h+ hle/service/am/service/all_system_applet_proxies_service.cpp+ hle/service/am/service/all_system_applet_proxies_service.h+ hle/service/am/service/application_proxy_service.cpp+ hle/service/am/service/application_proxy_service.hhle/service/am/system_applet_proxy.cpphle/service/am/system_applet_proxy.hhle/service/am/system_buffer_manager.cppdiff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cppindex 8f90eba34b..da0f9e3df5 100644--- a/src/core/hle/service/am/am.cpp+++ b/src/core/hle/service/am/am.cpp@@ -2,10 +2,10 @@// SPDX-License-Identifier: GPL-2.0-or-later#include "core/hle/service/am/am.h"-#include "core/hle/service/am/applet_ae.h"-#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/am/idle.h"#include "core/hle/service/am/omm.h"+#include "core/hle/service/am/service/all_system_applet_proxies_service.h"+#include "core/hle/service/am/service/application_proxy_service.h"#include "core/hle/service/am/spsm.h"#include "core/hle/service/server_manager.h"@@ -14,10 +14,10 @@ namespace Service::AM {void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {auto server_manager = std::make_unique<ServerManager>(system);- server_manager->RegisterNamedService("appletAE",- std::make_shared<AppletAE>(nvnflinger, system));- server_manager->RegisterNamedService("appletOE",- std::make_shared<AppletOE>(nvnflinger, system));+ server_manager->RegisterNamedService(+ "appletAE", std::make_shared<IAllSystemAppletProxiesService>(system, nvnflinger));+ server_manager->RegisterNamedService(+ "appletOE", std::make_shared<IApplicationProxyService>(system, nvnflinger));server_manager->RegisterNamedService("idle:sys", std::make_shared<IdleSys>(system));server_manager->RegisterNamedService("omm", std::make_shared<OMM>(system));server_manager->RegisterNamedService("spsm", std::make_shared<SPSM>(system));diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.hindex 8c33feb159..749081e3d8 100644--- a/src/core/hle/service/am/am_types.h+++ b/src/core/hle/service/am/am_types.h@@ -169,6 +169,12 @@ struct AppletIdentityInfo {};static_assert(sizeof(AppletIdentityInfo) == 0x10, "AppletIdentityInfo has incorrect size.");+struct AppletAttribute {+ u8 flag;+ INSERT_PADDING_BYTES_NOINIT(0x7F);+};+static_assert(sizeof(AppletAttribute) == 0x80, "AppletAttribute has incorrect size.");+using AppletResourceUserId = u64;using ProgramId = u64;diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cppdeleted file mode 100644index 1b715dea6e..0000000000--- a/src/core/hle/service/am/applet_ae.cpp+++ /dev/null@@ -1,73 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#include "core/hle/service/am/applet_ae.h"-#include "core/hle/service/am/applet_manager.h"-#include "core/hle/service/am/library_applet_proxy.h"-#include "core/hle/service/am/system_applet_proxy.h"-#include "core/hle/service/ipc_helpers.h"--namespace Service::AM {--AppletAE::AppletAE(Nvnflinger::Nvnflinger& nvnflinger_, Core::System& system_)- : ServiceFramework{system_, "appletAE"}, nvnflinger{nvnflinger_} {- // clang-format off- static const FunctionInfo functions[] = {- {100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"},- {200, &AppletAE::OpenLibraryAppletProxyOld, "OpenLibraryAppletProxyOld"},- {201, &AppletAE::OpenLibraryAppletProxy, "OpenLibraryAppletProxy"},- {300, nullptr, "OpenOverlayAppletProxy"},- {350, nullptr, "OpenSystemApplicationProxy"},- {400, nullptr, "CreateSelfLibraryAppletCreatorForDevelop"},- {410, nullptr, "GetSystemAppletControllerForDebug"},- {1000, nullptr, "GetDebugFunctions"},- };- // clang-format on-- RegisterHandlers(functions);-}--AppletAE::~AppletAE() = default;--void AppletAE::OpenSystemAppletProxy(HLERequestContext& ctx) {- LOG_DEBUG(Service_AM, "called");-- if (const auto applet = GetAppletFromContext(ctx)) {- IPC::ResponseBuilder rb{ctx, 2, 0, 1};- rb.Push(ResultSuccess);- rb.PushIpcInterface<ISystemAppletProxy>(nvnflinger, applet, system);- } else {- UNIMPLEMENTED();-- IPC::ResponseBuilder rb{ctx, 2};- rb.Push(ResultUnknown);- }-}--void AppletAE::OpenLibraryAppletProxy(HLERequestContext& ctx) {- LOG_DEBUG(Service_AM, "called");-- if (const auto applet = GetAppletFromContext(ctx)) {- IPC::ResponseBuilder rb{ctx, 2, 0, 1};- rb.Push(ResultSuccess);- rb.PushIpcInterface<ILibraryAppletProxy>(nvnflinger, applet, system);- } else {- UNIMPLEMENTED();-- IPC::ResponseBuilder rb{ctx, 2};- rb.Push(ResultUnknown);- }-}--void AppletAE::OpenLibraryAppletProxyOld(HLERequestContext& ctx) {- LOG_DEBUG(Service_AM, "called");-- return OpenLibraryAppletProxy(ctx);-}--std::shared_ptr<Applet> AppletAE::GetAppletFromContext(HLERequestContext& ctx) {- const auto aruid = ctx.GetPID();- return system.GetAppletManager().GetByAppletResourceUserId(aruid);-}--} // namespace Service::AMdiff --git a/src/core/hle/service/am/applet_ae.h b/src/core/hle/service/am/applet_ae.hdeleted file mode 100644index 3d7961fa1d..0000000000--- a/src/core/hle/service/am/applet_ae.h+++ /dev/null@@ -1,39 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#pragma once--#include <memory>--#include "core/hle/service/service.h"--namespace Service {-namespace FileSystem {-class FileSystemController;-}--namespace Nvnflinger {-class Nvnflinger;-}--namespace AM {--struct Applet;--class AppletAE final : public ServiceFramework<AppletAE> {-public:- explicit AppletAE(Nvnflinger::Nvnflinger& nvnflinger_, Core::System& system_);- ~AppletAE() override;--private:- void OpenSystemAppletProxy(HLERequestContext& ctx);- void OpenLibraryAppletProxy(HLERequestContext& ctx);- void OpenLibraryAppletProxyOld(HLERequestContext& ctx);-- std::shared_ptr<Applet> GetAppletFromContext(HLERequestContext& ctx);-- Nvnflinger::Nvnflinger& nvnflinger;-};--} // namespace AM-} // namespace Servicediff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cppdeleted file mode 100644index 56bafd1622..0000000000--- a/src/core/hle/service/am/applet_oe.cpp+++ /dev/null@@ -1,42 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#include "core/hle/service/am/am.h"-#include "core/hle/service/am/applet_manager.h"-#include "core/hle/service/am/applet_oe.h"-#include "core/hle/service/am/application_proxy.h"-#include "core/hle/service/ipc_helpers.h"--namespace Service::AM {--AppletOE::AppletOE(Nvnflinger::Nvnflinger& nvnflinger_, Core::System& system_)- : ServiceFramework{system_, "appletOE"}, nvnflinger{nvnflinger_} {- static const FunctionInfo functions[] = {- {0, &AppletOE::OpenApplicationProxy, "OpenApplicationProxy"},- };- RegisterHandlers(functions);-}--AppletOE::~AppletOE() = default;--void AppletOE::OpenApplicationProxy(HLERequestContext& ctx) {- LOG_DEBUG(Service_AM, "called");-- if (const auto applet = GetAppletFromContext(ctx)) {- IPC::ResponseBuilder rb{ctx, 2, 0, 1};- rb.Push(ResultSuccess);- rb.PushIpcInterface<IApplicationProxy>(nvnflinger, applet, system);- } else {- UNIMPLEMENTED();-- IPC::ResponseBuilder rb{ctx, 2};- rb.Push(ResultUnknown);- }-}--std::shared_ptr<Applet> AppletOE::GetAppletFromContext(HLERequestContext& ctx) {- const auto aruid = ctx.GetPID();- return system.GetAppletManager().GetByAppletResourceUserId(aruid);-}--} // namespace Service::AMdiff --git a/src/core/hle/service/am/applet_oe.h b/src/core/hle/service/am/applet_oe.hdeleted file mode 100644index f2ba1c9242..0000000000--- a/src/core/hle/service/am/applet_oe.h+++ /dev/null@@ -1,37 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#pragma once--#include <memory>--#include "core/hle/service/service.h"--namespace Service {-namespace FileSystem {-class FileSystemController;-}--namespace Nvnflinger {-class Nvnflinger;-}--namespace AM {--struct Applet;--class AppletOE final : public ServiceFramework<AppletOE> {-public:- explicit AppletOE(Nvnflinger::Nvnflinger& nvnflinger_, Core::System& system_);- ~AppletOE() override;--private:- void OpenApplicationProxy(HLERequestContext& ctx);-- std::shared_ptr<Applet> GetAppletFromContext(HLERequestContext& ctx);-- Nvnflinger::Nvnflinger& nvnflinger;-};--} // namespace AM-} // namespace Servicediff --git a/src/core/hle/service/am/frontend/applets.cpp b/src/core/hle/service/am/frontend/applets.cppindex db2b045754..944d8b1055 100644--- a/src/core/hle/service/am/frontend/applets.cpp+++ b/src/core/hle/service/am/frontend/applets.cpp@@ -15,11 +15,8 @@#include "core/frontend/applets/web_browser.h"#include "core/hle/kernel/k_event.h"#include "core/hle/service/am/am.h"-#include "core/hle/service/am/applet_ae.h"#include "core/hle/service/am/applet_data_broker.h"#include "core/hle/service/am/applet_manager.h"-#include "core/hle/service/am/applet_message_queue.h"-#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/am/frontend/applet_cabinet.h"#include "core/hle/service/am/frontend/applet_controller.h"#include "core/hle/service/am/frontend/applet_error.h"diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp b/src/core/hle/service/am/service/all_system_applet_proxies_service.cppnew file mode 100644index 0000000000..66c23a7494--- /dev/null+++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp@@ -0,0 +1,80 @@+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#include "core/core.h"+#include "core/hle/service/am/applet_manager.h"+#include "core/hle/service/am/library_applet_proxy.h"+#include "core/hle/service/am/service/all_system_applet_proxies_service.h"+#include "core/hle/service/am/system_applet_proxy.h"+#include "core/hle/service/cmif_serialization.h"++namespace Service::AM {++IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_,+ Nvnflinger::Nvnflinger& nvnflinger)+ : ServiceFramework{system_, "appletAE"}, m_nvnflinger{nvnflinger} {+ // clang-format off+ static const FunctionInfo functions[] = {+ {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"},+ {200, D<&IAllSystemAppletProxiesService::OpenLibraryAppletProxyOld>, "OpenLibraryAppletProxyOld"},+ {201, D<&IAllSystemAppletProxiesService::OpenLibraryAppletProxy>, "OpenLibraryAppletProxy"},+ {300, nullptr, "OpenOverlayAppletProxy"},+ {350, nullptr, "OpenSystemApplicationProxy"},+ {400, nullptr, "CreateSelfLibraryAppletCreatorForDevelop"},+ {410, nullptr, "GetSystemAppletControllerForDebug"},+ {1000, nullptr, "GetDebugFunctions"},+ };+ // clang-format on++ RegisterHandlers(functions);+}++IAllSystemAppletProxiesService::~IAllSystemAppletProxiesService() = default;++Result IAllSystemAppletProxiesService::OpenSystemAppletProxy(+ Out<SharedPointer<ISystemAppletProxy>> out_system_applet_proxy, ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle) {+ LOG_DEBUG(Service_AM, "called");++ if (const auto applet = this->GetAppletFromProcessId(pid); applet) {+ *out_system_applet_proxy =+ std::make_shared<ISystemAppletProxy>(m_nvnflinger, applet, system);+ R_SUCCEED();+ } else {+ UNIMPLEMENTED();+ R_THROW(ResultUnknown);+ }+}++Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy(+ Out<SharedPointer<ILibraryAppletProxy>> out_library_applet_proxy, ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle,+ InLargeData<AppletAttribute, BufferAttr_HipcMapAlias> attribute) {+ LOG_DEBUG(Service_AM, "called");++ if (const auto applet = this->GetAppletFromProcessId(pid); applet) {+ *out_library_applet_proxy =+ std::make_shared<ILibraryAppletProxy>(m_nvnflinger, applet, system);+ R_SUCCEED();+ } else {+ UNIMPLEMENTED();+ R_THROW(ResultUnknown);+ }+}++Result IAllSystemAppletProxiesService::OpenLibraryAppletProxyOld(+ Out<SharedPointer<ILibraryAppletProxy>> out_library_applet_proxy, ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle) {+ LOG_DEBUG(Service_AM, "called");++ AppletAttribute attribute{};+ R_RETURN(+ this->OpenLibraryAppletProxy(out_library_applet_proxy, pid, process_handle, attribute));+}++std::shared_ptr<Applet> IAllSystemAppletProxiesService::GetAppletFromProcessId(+ ProcessId process_id) {+ return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid);+}++} // namespace Service::AMdiff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.h b/src/core/hle/service/am/service/all_system_applet_proxies_service.hnew file mode 100644index 0000000000..38b1ca2eac--- /dev/null+++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.h@@ -0,0 +1,47 @@+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#pragma once++#include "core/hle/service/cmif_types.h"+#include "core/hle/service/service.h"++namespace Service {++namespace Nvnflinger {+class Nvnflinger;+}++namespace AM {++struct Applet;+struct AppletAttribute;+class ILibraryAppletProxy;+class ISystemAppletProxy;++class IAllSystemAppletProxiesService final+ : public ServiceFramework<IAllSystemAppletProxiesService> {+public:+ explicit IAllSystemAppletProxiesService(Core::System& system_,+ Nvnflinger::Nvnflinger& nvnflinger);+ ~IAllSystemAppletProxiesService() override;++private:+ Result OpenSystemAppletProxy(Out<SharedPointer<ISystemAppletProxy>> out_system_applet_proxy,+ ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle);+ Result OpenLibraryAppletProxy(Out<SharedPointer<ILibraryAppletProxy>> out_library_applet_proxy,+ ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle,+ InLargeData<AppletAttribute, BufferAttr_HipcMapAlias> attribute);+ Result OpenLibraryAppletProxyOld(+ Out<SharedPointer<ILibraryAppletProxy>> out_library_applet_proxy, ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle);++private:+ std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);+ Nvnflinger::Nvnflinger& m_nvnflinger;+};++} // namespace AM+} // namespace Servicediff --git a/src/core/hle/service/am/service/application_proxy_service.cpp b/src/core/hle/service/am/service/application_proxy_service.cppnew file mode 100644index 0000000000..b8532d0476--- /dev/null+++ b/src/core/hle/service/am/service/application_proxy_service.cpp@@ -0,0 +1,42 @@+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#include "core/core.h"+#include "core/hle/service/am/am.h"+#include "core/hle/service/am/applet_manager.h"+#include "core/hle/service/am/application_proxy.h"+#include "core/hle/service/am/service/application_proxy_service.h"+#include "core/hle/service/cmif_serialization.h"++namespace Service::AM {++IApplicationProxyService::IApplicationProxyService(Core::System& system_,+ Nvnflinger::Nvnflinger& nvnflinger)+ : ServiceFramework{system_, "appletOE"}, m_nvnflinger{nvnflinger} {+ static const FunctionInfo functions[] = {+ {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"},+ };+ RegisterHandlers(functions);+}++IApplicationProxyService::~IApplicationProxyService() = default;++Result IApplicationProxyService::OpenApplicationProxy(+ Out<SharedPointer<IApplicationProxy>> out_application_proxy, ClientProcessId pid,+ InCopyHandle<Kernel::KProcess> process_handle) {+ LOG_DEBUG(Service_AM, "called");++ if (const auto applet = this->GetAppletFromProcessId(pid)) {+ *out_application_proxy = std::make_shared<IApplicationProxy>(m_nvnflinger, applet, system);+ R_SUCCEED();+ } else {+ UNIMPLEMENTED();+ R_THROW(ResultUnknown);+ }+}++std::shared_ptr<Applet> IApplicationProxyService::GetAppletFromProcessId(ProcessId process_id) {+ return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid);+}++} // namespace Service::AMdiff --git a/src/core/hle/service/am/service/application_proxy_service.h b/src/core/hle/service/am/service/application_proxy_service.hnew file mode 100644index 0000000000..1c1d32d0b9--- /dev/null+++ b/src/core/hle/service/am/service/application_proxy_service.h@@ -0,0 +1,35 @@+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project+// SPDX-License-Identifier: GPL-2.0-or-later++#pragma once++#include "core/hle/service/cmif_types.h"+#include "core/hle/service/service.h"++namespace Service {++namespace Nvnflinger {+class Nvnflinger;+}++namespace AM {++struct Applet;+class IApplicationProxy;++class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> {+public:+ explicit IApplicationProxyService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger);+ ~IApplicationProxyService() override;++private:+ Result OpenApplicationProxy(Out<SharedPointer<IApplicationProxy>> out_application_proxy,+ ClientProcessId pid, InCopyHandle<Kernel::KProcess> process_handle);++private:+ std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);+ Nvnflinger::Nvnflinger& m_nvnflinger;+};++} // namespace AM+} // namespace Servicediff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cppindex e28df10bdb..28c3baf086 100644--- a/src/yuzu/configuration/configure_input.cpp+++ b/src/yuzu/configuration/configure_input.cpp@@ -8,10 +8,7 @@#include "common/settings_enums.h"#include "core/core.h"#include "core/hle/service/am/am.h"-#include "core/hle/service/am/applet_ae.h"#include "core/hle/service/am/applet_manager.h"-#include "core/hle/service/am/applet_message_queue.h"-#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/sm/sm.h"#include "hid_core/frontend/emulated_controller.h"#include "hid_core/hid_core.h"diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cppindex 13381fea83..dfa50006ab 100644--- a/src/yuzu/main.cpp+++ b/src/yuzu/main.cpp@@ -44,9 +44,6 @@#include "core/frontend/applets/mii_edit.h"#include "core/frontend/applets/software_keyboard.h"#include "core/hle/service/acc/profile_manager.h"-#include "core/hle/service/am/applet_ae.h"-#include "core/hle/service/am/applet_message_queue.h"-#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/am/frontend/applets.h"#include "core/hle/service/set/system_settings_server.h"#include "frontend_common/content_manager.h"