From 421324b498895b8eb4681123c7e9c8d3007cdab9 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 21 Nov 2019 04:03:19 -0800 Subject: [PATCH] mitm/cfg: pass around override status for decision-making --- .../source/bpc_mitm/bpc_mitm_service.hpp | 11 ++- .../source/fs_mitm/fs_mitm_service.hpp | 2 +- .../source/hid_mitm/hid_mitm_service.hpp | 2 +- .../source/ns_mitm/ns_am_mitm_service.hpp | 2 +- .../source/ns_mitm/ns_web_mitm_service.hpp | 2 +- .../source/set_mitm/set_mitm_service.hpp | 2 +- .../source/set_mitm/setsys_mitm_service.hpp | 2 +- .../dmnt/source/cheat/impl/dmnt_cheat_api.cpp | 11 +-- .../include/stratosphere/cfg/cfg_api.hpp | 9 +- .../include/stratosphere/cfg/cfg_types.hpp | 62 ++++++++++++++ .../include/stratosphere/ldr/ldr_pm_api.hpp | 4 + .../include/stratosphere/pm/pm_dmnt_api.hpp | 2 +- .../include/stratosphere/pm/pm_info_api.hpp | 2 + .../sf/hipc/sf_hipc_server_manager.hpp | 13 ++- .../include/stratosphere/sf/sf_common.hpp | 3 +- .../stratosphere/sf/sf_service_object.hpp | 7 +- .../stratosphere/sm/sm_manager_api.hpp | 2 +- .../include/stratosphere/sm/sm_mitm_api.hpp | 3 +- .../include/stratosphere/sm/sm_types.hpp | 10 +++ .../source/cfg/cfg_override.cpp | 82 +++++-------------- .../libstratosphere/source/ldr/ldr_ams.c | 15 ++++ .../libstratosphere/source/ldr/ldr_ams.h | 8 ++ .../libstratosphere/source/ldr/ldr_pm_api.cpp | 11 +++ .../libstratosphere/source/pm/pm_ams.c | 28 ++++++- .../libstratosphere/source/pm/pm_ams.h | 8 +- .../libstratosphere/source/pm/pm_dmnt_api.cpp | 6 +- .../libstratosphere/source/pm/pm_info_api.cpp | 9 ++ .../source/sf/hipc/sf_hipc_mitm_query_api.cpp | 4 +- .../libstratosphere/source/sm/sm_ams.c | 19 ++--- .../libstratosphere/source/sm/sm_ams.h | 2 +- .../source/sm/sm_manager_api.cpp | 5 +- .../libstratosphere/source/sm/sm_mitm_api.cpp | 4 +- .../libstratosphere/source/sm/smm_ams.c | 5 +- .../libstratosphere/source/sm/smm_ams.h | 7 +- .../loader/source/ldr_content_management.cpp | 69 +++++++--------- .../loader/source/ldr_content_management.hpp | 14 +++- .../loader/source/ldr_loader_service.cpp | 68 +++++++++------ .../loader/source/ldr_loader_service.hpp | 10 ++- stratosphere/loader/source/ldr_meta.cpp | 16 ++-- stratosphere/loader/source/ldr_meta.hpp | 4 +- .../loader/source/ldr_process_creation.cpp | 25 +++--- .../loader/source/ldr_process_creation.hpp | 4 +- stratosphere/loader/source/ldr_ro_manager.cpp | 7 +- stratosphere/loader/source/ldr_ro_manager.hpp | 4 +- .../pm/source/impl/pm_process_info.cpp | 2 +- .../pm/source/impl/pm_process_info.hpp | 9 +- .../pm/source/impl/pm_process_manager.cpp | 13 +-- .../pm/source/impl/pm_process_manager.hpp | 2 +- .../pm/source/pm_debug_monitor_service.cpp | 4 +- .../pm/source/pm_debug_monitor_service.hpp | 2 +- stratosphere/pm/source/pm_info_service.cpp | 5 ++ stratosphere/pm/source/pm_info_service.hpp | 3 + stratosphere/pm/source/pm_main.cpp | 2 +- .../sm/source/impl/sm_service_manager.cpp | 43 +++++----- .../sm/source/impl/sm_service_manager.hpp | 4 +- stratosphere/sm/source/sm_manager_service.cpp | 8 +- stratosphere/sm/source/sm_manager_service.hpp | 2 +- stratosphere/sm/source/sm_user_service.cpp | 4 +- stratosphere/sm/source/sm_user_service.hpp | 2 +- 59 files changed, 425 insertions(+), 265 deletions(-) create mode 100644 stratosphere/libstratosphere/include/stratosphere/cfg/cfg_types.hpp diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp index 1c4a596bc..550b265b4 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp @@ -25,16 +25,15 @@ namespace ams::mitm::bpc { RebootSystem = 1, }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: * - am, to intercept the Reboot/Power buttons in the overlay menu. * - fatal, to simplify payload reboot logic significantly - * - applications and hbl, to allow homebrew to take advantage of the feature. + * - hbl, to allow homebrew to take advantage of the feature. */ - return program_id == ncm::ProgramId::Am || - program_id == ncm::ProgramId::Fatal || - ncm::IsApplicationProgramId(program_id); - /* TODO: Hbl */ + return client_info.program_id == ncm::ProgramId::Am || + client_info.program_id == ncm::ProgramId::Fatal || + client_info.override_status.IsHbl(); } public: SF_MITM_SERVICE_OBJECT_CTOR(BpcMitmService) { /* ... */ } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp index 3326b2d04..9e842200b 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp @@ -25,7 +25,7 @@ namespace ams::mitm::fs { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp index 1920e8faa..9e2a684e2 100644 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp @@ -25,7 +25,7 @@ namespace ams::mitm::hid { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp index 401a0d462..a32166355 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp @@ -24,7 +24,7 @@ namespace ams::mitm::ns { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp index d423511f8..09f540a56 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp @@ -24,7 +24,7 @@ namespace ams::mitm::ns { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp index e6cf5b23b..600e32957 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp @@ -24,7 +24,7 @@ namespace ams::mitm::set { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp index 3b5c2c2c8..af76dc8ab 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp @@ -24,7 +24,7 @@ namespace ams::mitm::set { /* TODO */ }; public: - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id) { + static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO */ return false; } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index 61e06bb3d..ad15b9815 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -623,9 +623,10 @@ namespace ams::dmnt::cheat::impl { { Handle proc_h = INVALID_HANDLE; ncm::ProgramLocation loc = {}; + cfg::OverrideStatus status = {}; ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ASSERT(svcCloseHandle(proc_h)); } }; - R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, this->cheat_process_metadata.process_id)); + R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id)); this->cheat_process_metadata.program_id = loc.program_id; { @@ -638,11 +639,11 @@ namespace ams::dmnt::cheat::impl { this->cheat_process_metadata.aslr_extents.base = as_info.aslr_base; this->cheat_process_metadata.aslr_extents.size = as_info.aslr_size; } - } - /* If new process launch, we may not want to actually attach. */ - if (on_process_launch) { - R_UNLESS(cfg::IsCheatEnableKeyHeld(this->cheat_process_metadata.program_id), ResultCheatNotAttached()); + /* If new process launch, we may not want to actually attach. */ + if (on_process_launch) { + R_UNLESS(status.IsCheatEnabled(), ResultCheatNotAttached()); + } } /* Get module information from loader. */ diff --git a/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_api.hpp b/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_api.hpp index a33799d0b..89181b825 100644 --- a/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_api.hpp @@ -13,10 +13,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once -#include "../os/os_common_types.hpp" -#include "../ncm/ncm_types.hpp" +#include "cfg_types.hpp" namespace ams::cfg { @@ -31,10 +29,7 @@ namespace ams::cfg { void WaitSdCardInitialized(); /* Override key utilities. */ - bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id); - bool IsHblOverrideKeyHeld(ncm::ProgramId program_id); - void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id); - bool IsCheatEnableKeyHeld(ncm::ProgramId program_id); + OverrideStatus CaptureOverrideStatus(ncm::ProgramId program_id); /* Flag utilities. */ bool HasFlag(ncm::ProgramId program_id, const char *flag); diff --git a/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_types.hpp b/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_types.hpp new file mode 100644 index 000000000..530e41609 --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/cfg/cfg_types.hpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018-2019 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include "../os/os_common_types.hpp" +#include "../ncm/ncm_types.hpp" + +namespace ams::cfg { + + namespace impl { + + enum OverrideStatusFlag : u64 { + OverrideStatusFlag_Hbl = BIT(0), + OverrideStatusFlag_ProgramSpecific = BIT(1), + OverrideStatusFlag_CheatEnabled = BIT(2), + }; + + } + + struct OverrideStatus { + u64 keys_held; + u64 flags; + + constexpr inline u64 GetKeysHeld() const { return this->keys_held; } + + #define DEFINE_FLAG_ACCESSORS(flag) \ + constexpr inline bool Is##flag() const { return this->flags & impl::OverrideStatusFlag_##flag; } \ + constexpr inline void Set##flag() { this->flags |= impl::OverrideStatusFlag_##flag; } \ + constexpr inline void Clear##flag() { this->flags &= ~u64(impl::OverrideStatusFlag_##flag); } + + DEFINE_FLAG_ACCESSORS(Hbl) + DEFINE_FLAG_ACCESSORS(ProgramSpecific) + DEFINE_FLAG_ACCESSORS(CheatEnabled) + + #undef DEFINE_FLAG_ACCESSORS + }; + + static_assert(sizeof(OverrideStatus) == 0x10, "sizeof(OverrideStatus)"); + static_assert(std::is_pod::value, "std::is_pod::value"); + + constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) { + return lhs.keys_held == rhs.keys_held && lhs.flags == rhs.flags; + } + + constexpr inline bool operator!=(const OverrideStatus &lhs, const OverrideStatus &rhs) { + return !(lhs == rhs); + } + +} diff --git a/stratosphere/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp b/stratosphere/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp index 0945a32d7..1eb6418d7 100644 --- a/stratosphere/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp @@ -26,4 +26,8 @@ namespace ams::ldr::pm { Result UnpinProgram(PinId pin_id); Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id); + /* Atmosphere extension API. */ + Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc); + Result AtmospherePinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status); + } diff --git a/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp b/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp index 967dc28e0..616e4d9c1 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp @@ -26,7 +26,7 @@ namespace ams::pm::dmnt { Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id); Result GetApplicationProcessId(os::ProcessId *out_process_id); Result HookToCreateApplicationProcess(Handle *out_handle); - Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id); + Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id); Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource); } diff --git a/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp b/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp index cc8031858..0b5e6dce9 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp @@ -26,6 +26,8 @@ namespace ams::pm::info { Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id); Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id); + Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id); + /* Information convenience API. */ bool HasLaunchedProgram(ncm::ProgramId program_id); diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 6bdfd672d..04cbd79c4 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -36,7 +36,7 @@ namespace ams::sf::hipc { NON_COPYABLE(ServerManagerBase); NON_MOVEABLE(ServerManagerBase); public: - using MitmQueryFunction = bool (*)(os::ProcessId, ncm::ProgramId); + using MitmQueryFunction = bool (*)(const sm::MitmProcessInfo &); private: enum class UserDataTag : uintptr_t { Server = 1, @@ -106,11 +106,10 @@ namespace ams::sf::hipc { std::shared_ptr<::Service> forward_service = std::move(ServerSession::CreateForwardService()); /* Get mitm forward session. */ - os::ProcessId client_process_id; - ncm::ProgramId client_program_id; - R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_process_id, &client_program_id, this->service_name)); + sm::MitmProcessInfo client_info; + R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name)); - *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_process_id, client_program_id)))); + *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_info)))); *out_fsrv = std::move(forward_service); } else { *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared()))); @@ -166,8 +165,8 @@ namespace ams::sf::hipc { } template - static constexpr inline std::shared_ptr MakeSharedMitm(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) { - return std::make_shared(std::forward>(s), p, r); + static constexpr inline std::shared_ptr MakeSharedMitm(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &client_info) { + return std::make_shared(std::forward>(s), client_info); } Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func); diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/sf_common.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/sf_common.hpp index 71975321c..39e0edcf3 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/sf_common.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/sf_common.hpp @@ -17,4 +17,5 @@ #pragma once #include #include "../ams.hpp" -#include "../os.hpp" \ No newline at end of file +#include "../os.hpp" +#include "../sm/sm_types.hpp" \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/sf_service_object.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/sf_service_object.hpp index 8cf45caa5..fd87ddb2a 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/sf_service_object.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/sf_service_object.hpp @@ -25,16 +25,15 @@ namespace ams::sf { class IMitmServiceObject : public IServiceObject { protected: std::shared_ptr<::Service> forward_service; - os::ProcessId process_id; - ncm::ProgramId program_id; + sm::MitmProcessInfo client_info; public: - IMitmServiceObject(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : forward_service(std::move(s)), process_id(p), program_id(r) { /* ... */ } + IMitmServiceObject(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : forward_service(std::move(s)), client_info(c) { /* ... */ } static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id); }; /* Utility. */ - #define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : ::ams::sf::IMitmServiceObject(std::forward>(s), p, r) + #define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : ::ams::sf::IMitmServiceObject(std::forward>(s), c) template struct ServiceObjectTraits { diff --git a/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp b/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp index a499da1df..d746c5570 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp @@ -23,7 +23,7 @@ namespace ams::sm::manager { /* Manager API. */ - Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size); + Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus status, const void *acid, size_t acid_size, const void *aci, size_t aci_size); Result UnregisterProcess(os::ProcessId process_id); /* Atmosphere extensions. */ diff --git a/stratosphere/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp b/stratosphere/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp index 282f984c2..1e230a2f3 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp @@ -17,7 +17,6 @@ #pragma once #include "sm_types.hpp" -#include "../ncm/ncm_types.hpp" namespace ams::sm::mitm { @@ -25,7 +24,7 @@ namespace ams::sm::mitm { Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name); Result UninstallMitm(ServiceName name); Result DeclareFutureMitm(ServiceName name); - Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name); + Result AcknowledgeSession(Service *out_service, MitmProcessInfo *out_info, ServiceName name); Result HasMitm(bool *out, ServiceName name); Result WaitMitm(ServiceName name); diff --git a/stratosphere/libstratosphere/include/stratosphere/sm/sm_types.hpp b/stratosphere/libstratosphere/include/stratosphere/sm/sm_types.hpp index 7ee5fde16..c3a069292 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sm/sm_types.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sm/sm_types.hpp @@ -16,6 +16,8 @@ #pragma once #include +#include "../ncm/ncm_types.hpp" +#include "../cfg/cfg_types.hpp" namespace ams::sm { @@ -65,4 +67,12 @@ namespace ams::sm { }; static_assert(sizeof(ServiceRecord) == 0x30, "ServiceRecord definition!"); + /* For Mitm extensions. */ + struct MitmProcessInfo { + os::ProcessId process_id; + ncm::ProgramId program_id; + cfg::OverrideStatus override_status; + }; + static_assert(std::is_trivial::value && sizeof(MitmProcessInfo) == 0x20, "MitmProcessInfo definition!"); + } diff --git a/stratosphere/libstratosphere/source/cfg/cfg_override.cpp b/stratosphere/libstratosphere/source/cfg/cfg_override.cpp index f407b8d54..5140ce814 100644 --- a/stratosphere/libstratosphere/source/cfg/cfg_override.cpp +++ b/stratosphere/libstratosphere/source/cfg/cfg_override.cpp @@ -164,10 +164,9 @@ namespace ams::cfg { return 1; } - bool IsOverrideKeyHeld(const OverrideKey *cfg) { - u64 kHeld = 0; - bool keys_triggered = (R_SUCCEEDED(hid::GetKeysHeld(&kHeld)) && ((kHeld & cfg->key_combination) != 0)); - return IsSdCardInitialized() && (cfg->override_by_default ^ keys_triggered); + constexpr inline bool IsOverrideMatch(const OverrideStatus &status, const OverrideKey &cfg) { + bool keys_triggered = ((status.keys_held & cfg.key_combination) != 0); + return (cfg.override_by_default ^ keys_triggered); } void ParseIniFile(util::ini::Handler handler, const char *path, void *user_ctx) { @@ -207,82 +206,45 @@ namespace ams::cfg { } - bool IsHblOverrideKeyHeld(ncm::ProgramId program_id) { + OverrideStatus CaptureOverrideStatus(ncm::ProgramId program_id) { + OverrideStatus status = {}; + /* If the SD card isn't initialized, we can't override. */ if (!IsSdCardInitialized()) { - return false; + return status; } /* For system modules and anything launched before the home menu, always override. */ if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) { - return true; + status.SetProgramSpecific(); + return status; } /* Unconditionally refresh loader.ini contents. */ RefreshLoaderConfiguration(); - /* Check HBL config. */ - return IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key); - } - - bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id) { - /* If the SD card isn't initialized, we can't override. */ - if (!IsSdCardInitialized()) { - return false; + /* If we can't read the key state, don't override anything. */ + if (R_FAILED(hid::GetKeysHeld(&status.keys_held))) { + return status; } - /* For system modules and anything launched before the home menu, always override. */ - if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) { - return true; + /* Detect Hbl. */ + if (IsHblProgramId(program_id) && IsOverrideMatch(status, g_hbl_override_config.override_key)) { + status.SetHbl(); } - /* Unconditionally refresh loader.ini contents. */ - RefreshLoaderConfiguration(); - + /* Detect content specific keys. */ const auto content_cfg = GetContentOverrideConfig(program_id); - return IsOverrideKeyHeld(&content_cfg.override_key); - } - - void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id) { - - /* If the SD card isn't initialized, we can't override. */ - if (!IsSdCardInitialized()) { - *out_hbl = false; - *out_program = false; - return; + if (IsOverrideMatch(status, content_cfg.override_key)) { + status.SetProgramSpecific(); } - /* For system modules and anything launched before the home menu, always override. */ - if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) { - *out_hbl = false; - *out_program = true; - return; + /* Only allow cheat enable if not HBL. */ + if (!status.IsHbl() && IsOverrideMatch(status, content_cfg.cheat_enable_key)) { + status.SetCheatEnabled(); } - /* Unconditionally refresh loader.ini contents. */ - RefreshLoaderConfiguration(); - - /* Set HBL output. */ - *out_hbl = IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key); - - /* Set content specific output. */ - const auto content_cfg = GetContentOverrideConfig(program_id); - *out_program = IsOverrideKeyHeld(&content_cfg.override_key); - } - - bool IsCheatEnableKeyHeld(ncm::ProgramId program_id) { - /* If the SD card isn't initialized, don't apply cheats. */ - if (!IsSdCardInitialized()) { - return false; - } - - /* Don't apply cheats to HBL. */ - if (IsHblOverrideKeyHeld(program_id)) { - return false; - } - - const auto content_cfg = GetContentOverrideConfig(program_id); - return IsOverrideKeyHeld(&content_cfg.cheat_enable_key); + return status; } /* HBL Configuration utilities. */ diff --git a/stratosphere/libstratosphere/source/ldr/ldr_ams.c b/stratosphere/libstratosphere/source/ldr/ldr_ams.c index 9353d0a21..cc710f69f 100644 --- a/stratosphere/libstratosphere/source/ldr/ldr_ams.c +++ b/stratosphere/libstratosphere/source/ldr/ldr_ams.c @@ -31,3 +31,18 @@ Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { return _ldrAtmosphereHasLaunchedProgram(ldrPmGetServiceSession(), out, program_id); } + +Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out_program_info, CfgOverrideStatus *out_status, const NcmProgramLocation *loc) { + return serviceDispatchInOut(ldrPmGetServiceSession(), 65001, *loc, *out_status, + .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize }, + .buffers = { { out_program_info, sizeof(*out_program_info) } }, + ); +} + +Result ldrPmAtmospherePinProgram(u64 *out, const NcmProgramLocation *loc, const CfgOverrideStatus *status) { + const struct { + NcmProgramLocation loc; + CfgOverrideStatus status; + } in = { *loc, *status }; + return serviceDispatchInOut(ldrPmGetServiceSession(), 65002, in, *out); +} diff --git a/stratosphere/libstratosphere/source/ldr/ldr_ams.h b/stratosphere/libstratosphere/source/ldr/ldr_ams.h index eacee3187..feff70e4a 100644 --- a/stratosphere/libstratosphere/source/ldr/ldr_ams.h +++ b/stratosphere/libstratosphere/source/ldr/ldr_ams.h @@ -11,9 +11,17 @@ extern "C" { #endif +typedef struct { + u64 keys_down; + u64 flags; +} CfgOverrideStatus; + Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id); Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id); +Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out, CfgOverrideStatus *out_status, const NcmProgramLocation *loc); +Result ldrPmAtmospherePinProgram(u64 *out, const NcmProgramLocation *loc, const CfgOverrideStatus *status); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/stratosphere/libstratosphere/source/ldr/ldr_pm_api.cpp b/stratosphere/libstratosphere/source/ldr/ldr_pm_api.cpp index 6a81ad238..d9b95d06b 100644 --- a/stratosphere/libstratosphere/source/ldr/ldr_pm_api.cpp +++ b/stratosphere/libstratosphere/source/ldr/ldr_pm_api.cpp @@ -40,4 +40,15 @@ namespace ams::ldr::pm { return ldrPmAtmosphereHasLaunchedProgram(out, static_cast(program_id)); } + Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { + static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition!"); + return ldrPmAtmosphereGetProgramInfo(reinterpret_cast(out), reinterpret_cast(out_status), reinterpret_cast(&loc)); + } + + Result AtmospherePinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status) { + static_assert(sizeof(*out) == sizeof(u64), "PinId definition!"); + static_assert(sizeof(status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition!"); + return ldrPmAtmospherePinProgram(reinterpret_cast(out), reinterpret_cast(&loc), reinterpret_cast(&status)); + } + } diff --git a/stratosphere/libstratosphere/source/pm/pm_ams.c b/stratosphere/libstratosphere/source/pm/pm_ams.c index 9beeef7ed..858cae2aa 100644 --- a/stratosphere/libstratosphere/source/pm/pm_ams.c +++ b/stratosphere/libstratosphere/source/pm/pm_ams.c @@ -28,10 +28,31 @@ Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { return rc; } -Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *loc_out, u64 pid) { +Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid) { + struct { + NcmProgramLocation loc; + CfgOverrideStatus status; + } out; + + Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65002, pid, out); + + if (R_SUCCEEDED(rc)) { + if (loc_out) *loc_out = out.loc; + if (status_out) *status_out = out.status; + } + + return rc; +} + +Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid) { Handle tmp_handle; - Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, *loc_out, + struct { + NcmProgramLocation loc; + CfgOverrideStatus status; + } out; + + Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, out, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, .out_handles = &tmp_handle, ); @@ -42,6 +63,9 @@ Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *lo } else { svcCloseHandle(tmp_handle); } + + if (loc_out) *loc_out = out.loc; + if (status_out) *status_out = out.status; } return rc; diff --git a/stratosphere/libstratosphere/source/pm/pm_ams.h b/stratosphere/libstratosphere/source/pm/pm_ams.h index 5abcad080..74e2a015e 100644 --- a/stratosphere/libstratosphere/source/pm/pm_ams.h +++ b/stratosphere/libstratosphere/source/pm/pm_ams.h @@ -11,10 +11,16 @@ extern "C" { #endif +typedef struct { + u64 keys_held; + u64 flags; +} CfgOverrideStatus; + Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id); Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id); +Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); -Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, u64 pid); +Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource); #ifdef __cplusplus diff --git a/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp b/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp index 7087c83c9..2fec2e0c7 100644 --- a/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp +++ b/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp @@ -39,10 +39,12 @@ namespace ams::pm::dmnt { return ResultSuccess(); } - Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id) { + Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { *out_handle = INVALID_HANDLE; *out_loc = {}; - return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast(out_loc), static_cast(process_id)); + *out_status = {}; + static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus)); + return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast(out_loc), reinterpret_cast(out_status), static_cast(process_id)); } Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource) { diff --git a/stratosphere/libstratosphere/source/pm/pm_info_api.cpp b/stratosphere/libstratosphere/source/pm/pm_info_api.cpp index 969e9619d..e07a15310 100644 --- a/stratosphere/libstratosphere/source/pm/pm_info_api.cpp +++ b/stratosphere/libstratosphere/source/pm/pm_info_api.cpp @@ -40,6 +40,15 @@ namespace ams::pm::info { return pminfoAtmosphereGetProcessId(reinterpret_cast(out_process_id), static_cast(program_id)); } + Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { + std::scoped_lock lk(g_info_lock); + + *out_loc = {}; + *out_status = {}; + static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus)); + return pminfoAtmosphereGetProcessInfo(reinterpret_cast(out_loc), reinterpret_cast(out_status), static_cast(process_id)); + } + Result WEAK HasLaunchedProgram(bool *out, ncm::ProgramId program_id) { std::scoped_lock lk(g_info_lock); diff --git a/stratosphere/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp b/stratosphere/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp index abf747175..12d881be1 100644 --- a/stratosphere/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp +++ b/stratosphere/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp @@ -30,8 +30,8 @@ namespace ams::sf::hipc::impl { public: MitmQueryService(ServerManagerBase::MitmQueryFunction qf) : query_function(qf) { /* ... */ } - void ShouldMitm(sf::Out out, os::ProcessId process_id, ncm::ProgramId program_id) { - out.SetValue(this->query_function(process_id, program_id)); + void ShouldMitm(sf::Out out, const sm::MitmProcessInfo &client_info) { + out.SetValue(this->query_function(client_info)); } public: DEFINE_SERVICE_DISPATCH_TABLE { diff --git a/stratosphere/libstratosphere/source/sm/sm_ams.c b/stratosphere/libstratosphere/source/sm/sm_ams.c index 713fd3933..ac606e672 100644 --- a/stratosphere/libstratosphere/source/sm/sm_ams.c +++ b/stratosphere/libstratosphere/source/sm/sm_ams.c @@ -107,21 +107,16 @@ Result smAtmosphereMitmDeclareFuture(SmServiceName name) { return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSession(), 65006); } -Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, u64 *pid_out, u64 *tid_out, SmServiceName name) { +Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *_out, SmServiceName name) { struct { - u64 pid; - u64 tid; - } out; + u64 process_id; + u64 program_id; + u64 keys_held; + u64 flags; + } *out = _out; - Result rc = serviceDispatchInOut(&g_smAtmosphereMitmSrv, 65003, name, out, + return serviceDispatchInOut(&g_smAtmosphereMitmSrv, 65003, name, *out, .out_num_objects = 1, .out_objects = srv_out, ); - - if (R_SUCCEEDED(rc)) { - if (pid_out) *pid_out = out.pid; - if (tid_out) *tid_out = out.tid; - } - - return rc; } diff --git a/stratosphere/libstratosphere/source/sm/sm_ams.h b/stratosphere/libstratosphere/source/sm/sm_ams.h index 7358e3a7e..3036cde94 100644 --- a/stratosphere/libstratosphere/source/sm/sm_ams.h +++ b/stratosphere/libstratosphere/source/sm/sm_ams.h @@ -28,7 +28,7 @@ void smAtmosphereCloseSession(Service *srv); Result smAtmosphereMitmInstall(Service *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name); Result smAtmosphereMitmUninstall(SmServiceName name); Result smAtmosphereMitmDeclareFuture(SmServiceName name); -Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, u64 *pid_out, u64 *tid_out, SmServiceName name); +Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *info_out, SmServiceName name); #ifdef __cplusplus } diff --git a/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp b/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp index 41bb3e75a..c7f852108 100644 --- a/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp +++ b/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp @@ -19,8 +19,9 @@ namespace ams::sm::manager { /* Manager API. */ - Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) { - return smManagerAtmosphereRegisterProcess(static_cast(process_id), static_cast(program_id), acid, acid_size, aci, aci_size); + Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus status, const void *acid, size_t acid_size, const void *aci, size_t aci_size) { + static_assert(sizeof(status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition"); + return smManagerAtmosphereRegisterProcess(static_cast(process_id), static_cast(program_id), reinterpret_cast(&status), acid, acid_size, aci, aci_size); } Result UnregisterProcess(os::ProcessId process_id) { diff --git a/stratosphere/libstratosphere/source/sm/sm_mitm_api.cpp b/stratosphere/libstratosphere/source/sm/sm_mitm_api.cpp index 90503eb1c..cc5807c7f 100644 --- a/stratosphere/libstratosphere/source/sm/sm_mitm_api.cpp +++ b/stratosphere/libstratosphere/source/sm/sm_mitm_api.cpp @@ -36,9 +36,9 @@ namespace ams::sm::mitm { }); } - Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name) { + Result AcknowledgeSession(Service *out_service, MitmProcessInfo *out_info, ServiceName name) { return impl::DoWithMitmAcknowledgementSession([&]() { - return smAtmosphereMitmAcknowledgeSession(out_service, &out_process_id->value, &out_program_id->value, impl::ConvertName(name)); + return smAtmosphereMitmAcknowledgeSession(out_service, reinterpret_cast(out_info), impl::ConvertName(name)); }); } diff --git a/stratosphere/libstratosphere/source/sm/smm_ams.c b/stratosphere/libstratosphere/source/sm/smm_ams.c index ada3d7ed3..b88714000 100644 --- a/stratosphere/libstratosphere/source/sm/smm_ams.c +++ b/stratosphere/libstratosphere/source/sm/smm_ams.c @@ -19,11 +19,12 @@ Result smManagerAtmosphereEndInitialDefers(void) { return serviceDispatch(smManagerGetServiceSession(), 65000); } -Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) { +Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideStatus *status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) { const struct { u64 pid; u64 tid; - } in = { pid, tid }; + CfgOverrideStatus status; + } in = { pid, tid, *status }; return serviceDispatchIn(smManagerGetServiceSession(), 65002, in, .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias, diff --git a/stratosphere/libstratosphere/source/sm/smm_ams.h b/stratosphere/libstratosphere/source/sm/smm_ams.h index 0af187f5d..0f9c1d127 100644 --- a/stratosphere/libstratosphere/source/sm/smm_ams.h +++ b/stratosphere/libstratosphere/source/sm/smm_ams.h @@ -11,8 +11,13 @@ extern "C" { #endif +typedef struct { + u64 keys_held; + u64 flags; +} CfgOverrideStatus; + Result smManagerAtmosphereEndInitialDefers(void); -Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size); +Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideStatus *status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size); Result smManagerAtmosphereHasMitm(bool *out, SmServiceName name); #ifdef __cplusplus diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index f7e48e89f..b9c191339 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -31,10 +31,6 @@ namespace ams::ldr { /* Globals. */ bool g_has_mounted_sd_card = false; - ncm::ProgramId g_should_override_program_id; - bool g_should_override_hbl = false; - bool g_should_override_sd = false; - /* Helpers. */ inline void FixFileSystemPath(char *path) { /* Paths will fail when passed to FS if they use the wrong kinds of slashes. */ @@ -53,27 +49,6 @@ namespace ams::ldr { return relative_path; } - void UpdateShouldOverrideCache(ncm::ProgramId program_id) { - if (g_should_override_program_id != program_id) { - cfg::GetOverrideKeyHeldStatus(&g_should_override_hbl, &g_should_override_sd, program_id); - } - g_should_override_program_id = program_id; - } - - void InvalidateShouldOverrideCache() { - g_should_override_program_id = {}; - } - - bool ShouldOverrideWithHbl(ncm::ProgramId program_id) { - UpdateShouldOverrideCache(program_id); - return g_should_override_hbl; - } - - bool ShouldOverrideWithSd(ncm::ProgramId program_id) { - UpdateShouldOverrideCache(program_id); - return g_should_override_sd; - } - Result MountSdCardFileSystem() { return fsdevMountSdmc(); } @@ -109,14 +84,14 @@ namespace ams::ldr { return OpenFile(SdCardFileSystemDeviceName, path); } - bool IsFileStubbed(ncm::ProgramId program_id, const char *relative_path) { + bool IsFileStubbed(ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path) { /* Allow nullptr relative path -- those are simply not openable. */ if (relative_path == nullptr) { return true; } /* Only allow stubbing in the case where we're considering SD card content. */ - if (!ShouldOverrideWithSd(program_id)) { + if (!status.IsProgramSpecific()) { return false; } @@ -131,14 +106,14 @@ namespace ams::ldr { return true; } - FILE *OpenBaseExefsFile(ncm::ProgramId program_id, const char *relative_path) { + FILE *OpenBaseExefsFile(ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path) { /* Allow nullptr relative path -- those are simply not openable. */ if (relative_path == nullptr) { return nullptr; } /* Check if stubbed. */ - if (IsFileStubbed(program_id, relative_path)) { + if (IsFileStubbed(program_id, status, relative_path)) { return nullptr; } @@ -148,7 +123,11 @@ namespace ams::ldr { } /* ScopedCodeMount functionality. */ - ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc) : is_code_mounted(false), is_hbl_mounted(false) { + ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc) : has_status(false), is_code_mounted(false), is_hbl_mounted(false) { + this->result = this->Initialize(loc); + } + + ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &o) : override_status(o), has_status(true), is_code_mounted(false), is_hbl_mounted(false) { this->result = this->Initialize(loc); } @@ -160,9 +139,6 @@ namespace ams::ldr { if (this->is_hbl_mounted) { fsdevUnmountDevice(HblFileSystemDeviceName); } - - /* Unmounting code means we should invalidate our configuration cache. */ - InvalidateShouldOverrideCache(); } Result ScopedCodeMount::MountCodeFileSystem(const ncm::ProgramLocation &loc) { @@ -219,12 +195,17 @@ namespace ams::ldr { } } + /* Capture override status, if necessary. */ + if (!this->has_status) { + this->InitializeOverrideStatus(loc); + } + /* Check if we should override contents. */ - if (ShouldOverrideWithHbl(loc.program_id)) { + if (this->override_status.IsHbl()) { /* Try to mount HBL. */ this->MountHblFileSystem(); } - if (ShouldOverrideWithSd(loc.program_id)) { + if (this->override_status.IsProgramSpecific()) { /* Try to mount Code NSP on SD. */ this->MountSdCardCodeFileSystem(loc); } @@ -237,25 +218,31 @@ namespace ams::ldr { return ResultSuccess(); } - Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const char *relative_path) { + void ScopedCodeMount::InitializeOverrideStatus(const ncm::ProgramLocation &loc) { + AMS_ASSERT(!this->has_status); + this->override_status = cfg::CaptureOverrideStatus(loc.program_id); + this->has_status = true; + } + + Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path) { FILE *f = nullptr; const char *ecs_device_name = ecs::Get(program_id); if (ecs_device_name != nullptr) { /* First priority: Open from external content. */ f = OpenFile(ecs_device_name, relative_path); - } else if (ShouldOverrideWithHbl(program_id)) { + } else if (status.IsHbl()) { /* Next, try to open from HBL. */ f = OpenFile(HblFileSystemDeviceName, relative_path); } else { /* If not ECS or HBL, try a loose file on the SD. */ - if (ShouldOverrideWithSd(program_id)) { + if (status.IsProgramSpecific()) { f = OpenLooseSdFile(program_id, relative_path); } /* If we fail, try the original exefs. */ if (f == nullptr) { - f = OpenBaseExefsFile(program_id, relative_path); + f = OpenBaseExefsFile(program_id, status, relative_path); } } @@ -266,9 +253,9 @@ namespace ams::ldr { return ResultSuccess(); } - Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const char *relative_path) { + Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path) { /* Open the file. */ - FILE *f = OpenBaseExefsFile(program_id, relative_path); + FILE *f = OpenBaseExefsFile(program_id, status, relative_path); R_UNLESS(f != nullptr, fs::ResultPathNotFound()); out = f; diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index 4c957b191..9d739ad9c 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -23,10 +23,13 @@ namespace ams::ldr { NON_COPYABLE(ScopedCodeMount); private: Result result; + cfg::OverrideStatus override_status; + bool has_status; bool is_code_mounted; bool is_hbl_mounted; public: ScopedCodeMount(const ncm::ProgramLocation &loc); + ScopedCodeMount(const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); ~ScopedCodeMount(); Result GetResult() const { @@ -41,17 +44,24 @@ namespace ams::ldr { return this->is_hbl_mounted; } + const cfg::OverrideStatus &GetOverrideStatus() const { + AMS_ASSERT(this->has_status); + return this->override_status; + } + private: Result Initialize(const ncm::ProgramLocation &loc); + void InitializeOverrideStatus(const ncm::ProgramLocation &loc); + Result MountCodeFileSystem(const ncm::ProgramLocation &loc); Result MountSdCardCodeFileSystem(const ncm::ProgramLocation &loc); Result MountHblFileSystem(); }; /* Content Management API. */ - Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const char *relative_path); - Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const char *relative_path); + Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path); + Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const cfg::OverrideStatus &status, const char *relative_path); /* Redirection API. */ Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc); diff --git a/stratosphere/loader/source/ldr_loader_service.cpp b/stratosphere/loader/source/ldr_loader_service.cpp index e8ee8a4cb..2a1617ea5 100644 --- a/stratosphere/loader/source/ldr_loader_service.cpp +++ b/stratosphere/loader/source/ldr_loader_service.cpp @@ -23,46 +23,60 @@ namespace ams::ldr { + namespace { + + Result GetProgramInfoImpl(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { + /* Zero output. */ + std::memset(out, 0, sizeof(*out)); + cfg::OverrideStatus status = {}; + + R_TRY(ldr::GetProgramInfo(out, &status, loc)); + + if (loc.storage_id != static_cast(ncm::StorageId::None) && loc.program_id != out->program_id) { + char path[FS_MAX_PATH]; + const ncm::ProgramLocation new_loc = ncm::ProgramLocation::Make(out->program_id, static_cast(loc.storage_id)); + + R_TRY(ResolveContentPath(path, loc)); + R_TRY(RedirectContentPath(path, new_loc)); + + const auto arg_info = args::Get(loc.program_id); + if (arg_info != nullptr) { + R_TRY(args::Set(new_loc.program_id, arg_info->args, arg_info->args_size)); + } + } + + if (out_status != nullptr) { + *out_status = status; + } + + return ResultSuccess(); + } + + } + /* Official commands. */ Result LoaderService::CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h) { os::ManagedHandle reslimit_holder(reslimit_h.GetValue()); ncm::ProgramLocation loc; + cfg::OverrideStatus override_status; char path[FS_MAX_PATH]; - /* Get location. */ - R_TRY(ldr::ro::GetProgramLocation(&loc, id)); + /* Get location and override status. */ + R_TRY(ldr::ro::GetProgramLocationAndStatus(&loc, &override_status, id)); if (loc.storage_id != static_cast(ncm::StorageId::None)) { R_TRY(ResolveContentPath(path, loc)); } - return ldr::CreateProcess(proc_h.GetHandlePointer(), id, loc, path, flags, reslimit_holder.Get()); + return ldr::CreateProcess(proc_h.GetHandlePointer(), id, loc, override_status, path, flags, reslimit_holder.Get()); } Result LoaderService::GetProgramInfo(sf::Out out, const ncm::ProgramLocation &loc) { - /* Zero output. */ - std::memset(out.GetPointer(), 0, sizeof(*out.GetPointer())); - - R_TRY(ldr::GetProgramInfo(out.GetPointer(), loc)); - - if (loc.storage_id != static_cast(ncm::StorageId::None) && loc.program_id != out->program_id) { - char path[FS_MAX_PATH]; - const ncm::ProgramLocation new_loc = ncm::ProgramLocation::Make(out->program_id, static_cast(loc.storage_id)); - - R_TRY(ResolveContentPath(path, loc)); - R_TRY(RedirectContentPath(path, new_loc)); - - const auto arg_info = args::Get(loc.program_id); - if (arg_info != nullptr) { - R_TRY(args::Set(new_loc.program_id, arg_info->args, arg_info->args_size)); - } - } - - return ResultSuccess(); + return GetProgramInfoImpl(out.GetPointer(), nullptr, loc); } Result LoaderService::PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc) { - return ldr::ro::PinProgram(out_id.GetPointer(), loc); + return ldr::ro::PinProgram(out_id.GetPointer(), loc, cfg::OverrideStatus{}); } Result LoaderService::UnpinProgram(PinId id) { @@ -95,4 +109,12 @@ namespace ams::ldr { out.SetValue(ldr::HasLaunchedProgram(program_id)); } + Result LoaderService::AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc) { + return GetProgramInfoImpl(out_program_info.GetPointer(), out_status.GetPointer(), loc); + } + + Result LoaderService::AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status) { + return ldr::ro::PinProgram(out_id.GetPointer(), loc, override_status); + } + } diff --git a/stratosphere/loader/source/ldr_loader_service.hpp b/stratosphere/loader/source/ldr_loader_service.hpp index db95efb28..197a6cea8 100644 --- a/stratosphere/loader/source/ldr_loader_service.hpp +++ b/stratosphere/loader/source/ldr_loader_service.hpp @@ -33,6 +33,8 @@ namespace ams::ldr { virtual Result AtmosphereSetExternalContentSource(sf::OutMoveHandle out, ncm::ProgramId program_id); virtual void AtmosphereClearExternalContentSource(ncm::ProgramId program_id); virtual void AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); + virtual Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc); + virtual Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); }; namespace pm { @@ -42,10 +44,12 @@ namespace ams::ldr { enum class CommandId { CreateProcess = 0, GetProgramInfo = 1, - PinProgram = 2, - UnpinProgram = 3, + PinProgram = 2, + UnpinProgram = 3, AtmosphereHasLaunchedProgram = 65000, + AtmosphereGetProgramInfo = 65001, + AtmospherePinProgram = 65002, }; public: DEFINE_SERVICE_DISPATCH_TABLE { @@ -55,6 +59,8 @@ namespace ams::ldr { MAKE_SERVICE_COMMAND_META(UnpinProgram), MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), + MAKE_SERVICE_COMMAND_META(AtmosphereGetProgramInfo), + MAKE_SERVICE_COMMAND_META(AtmospherePinProgram), }; }; diff --git a/stratosphere/loader/source/ldr_meta.cpp b/stratosphere/loader/source/ldr_meta.cpp index 73433e7c2..5526b11ea 100644 --- a/stratosphere/loader/source/ldr_meta.cpp +++ b/stratosphere/loader/source/ldr_meta.cpp @@ -33,6 +33,7 @@ namespace ams::ldr { /* Global storage. */ ncm::ProgramId g_cached_program_id; + cfg::OverrideStatus g_cached_override_status; MetaCache g_meta_cache; MetaCache g_original_meta_cache; @@ -144,11 +145,11 @@ namespace ams::ldr { } /* API. */ - Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id) { + Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id, const cfg::OverrideStatus &status) { FILE *f = nullptr; /* Try to load meta from file. */ - R_TRY(OpenCodeFile(f, program_id, MetaFilePath)); + R_TRY(OpenCodeFile(f, program_id, status, MetaFilePath)); { ON_SCOPE_EXIT { fclose(f); }; R_TRY(LoadMetaFromFile(f, &g_meta_cache)); @@ -161,8 +162,8 @@ namespace ams::ldr { meta->aci->program_id = program_id; /* For HBL, we need to copy some information from the base meta. */ - if (cfg::IsHblOverrideKeyHeld(program_id)) { - if (R_SUCCEEDED(OpenCodeFileFromBaseExefs(f, program_id, MetaFilePath))) { + if (status.IsHbl()) { + if (R_SUCCEEDED(OpenCodeFileFromBaseExefs(f, program_id, status, MetaFilePath))) { ON_SCOPE_EXIT { fclose(f); }; if (R_SUCCEEDED(LoadMetaFromFile(f, &g_original_meta_cache))) { Meta *o_meta = &g_original_meta_cache.meta; @@ -182,14 +183,15 @@ namespace ams::ldr { /* Set output. */ g_cached_program_id = program_id; + g_cached_override_status = status; *out_meta = *meta; return ResultSuccess(); } - Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id) { - if (g_cached_program_id != program_id) { - return LoadMeta(out_meta, program_id); + Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id, const cfg::OverrideStatus &status) { + if (g_cached_program_id != program_id || g_cached_override_status != status) { + return LoadMeta(out_meta, program_id, status); } *out_meta = g_meta_cache.meta; return ResultSuccess(); diff --git a/stratosphere/loader/source/ldr_meta.hpp b/stratosphere/loader/source/ldr_meta.hpp index 77f287bee..56062a738 100644 --- a/stratosphere/loader/source/ldr_meta.hpp +++ b/stratosphere/loader/source/ldr_meta.hpp @@ -33,8 +33,8 @@ namespace ams::ldr { }; /* Meta API. */ - Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id); - Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id); + Result LoadMeta(Meta *out_meta, ncm::ProgramId program_id, const cfg::OverrideStatus &status); + Result LoadMetaFromCache(Meta *out_meta, ncm::ProgramId program_id, const cfg::OverrideStatus &status); void InvalidateMetaCache(); } diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index 053c311cb..70281d892 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -265,14 +265,14 @@ namespace ams::ldr { return static_cast((meta->acid->flags & Acid::AcidFlag_PoolPartitionMask) >> Acid::AcidFlag_PoolPartitionShift); } - Result LoadNsoHeaders(ncm::ProgramId program_id, NsoHeader *nso_headers, bool *has_nso) { + Result LoadNsoHeaders(ncm::ProgramId program_id, const cfg::OverrideStatus &override_status, NsoHeader *nso_headers, bool *has_nso) { /* Clear NSOs. */ std::memset(nso_headers, 0, sizeof(*nso_headers) * Nso_Count); std::memset(has_nso, 0, sizeof(*has_nso) * Nso_Count); for (size_t i = 0; i < Nso_Count; i++) { FILE *f = nullptr; - if (R_SUCCEEDED(OpenCodeFile(f, program_id, GetNsoName(i)))) { + if (R_SUCCEEDED(OpenCodeFile(f, program_id, override_status, GetNsoName(i)))) { ON_SCOPE_EXIT { fclose(f); }; /* Read NSO header. */ R_UNLESS(fread(nso_headers + i, sizeof(*nso_headers), 1, f) == 1, ResultInvalidNso()); @@ -611,14 +611,14 @@ namespace ams::ldr { return ResultSuccess(); } - Result LoadNsosIntoProcessMemory(const ProcessInfo *process_info, const ncm::ProgramId program_id, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info) { + Result LoadNsosIntoProcessMemory(const ProcessInfo *process_info, const ncm::ProgramId program_id, const cfg::OverrideStatus &override_status, const NsoHeader *nso_headers, const bool *has_nso, const args::ArgumentInfo *arg_info) { const Handle process_handle = process_info->process_handle.Get(); /* Load each NSO. */ for (size_t i = 0; i < Nso_Count; i++) { if (has_nso[i]) { FILE *f = nullptr; - R_TRY(OpenCodeFile(f, program_id, GetNsoName(i))); + R_TRY(OpenCodeFile(f, program_id, override_status, GetNsoName(i))); ON_SCOPE_EXIT { fclose(f); }; uintptr_t map_address = 0; @@ -655,7 +655,7 @@ namespace ams::ldr { } /* Process Creation API. */ - Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const char *path, u32 flags, Handle reslimit_h) { + Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, Handle reslimit_h) { /* Use global storage for NSOs. */ NsoHeader *nso_headers = g_nso_headers; bool *has_nso = g_has_nso; @@ -663,18 +663,18 @@ namespace ams::ldr { { /* Mount code. */ - ScopedCodeMount mount(loc); + ScopedCodeMount mount(loc, override_status); R_TRY(mount.GetResult()); /* Load meta, possibly from cache. */ Meta meta; - R_TRY(LoadMetaFromCache(&meta, loc.program_id)); + R_TRY(LoadMetaFromCache(&meta, loc.program_id, override_status)); /* Validate meta. */ R_TRY(ValidateMeta(&meta, loc)); /* Load, validate NSOs. */ - R_TRY(LoadNsoHeaders(loc.program_id, nso_headers, has_nso)); + R_TRY(LoadNsoHeaders(loc.program_id, override_status, nso_headers, has_nso)); R_TRY(ValidateNsoHeaders(nso_headers, has_nso)); /* Actually create process. */ @@ -682,7 +682,7 @@ namespace ams::ldr { R_TRY(CreateProcessImpl(&info, &meta, nso_headers, has_nso, arg_info, flags, reslimit_h)); /* Load NSOs into process memory. */ - R_TRY(LoadNsosIntoProcessMemory(&info, loc.program_id, nso_headers, has_nso, arg_info)); + R_TRY(LoadNsosIntoProcessMemory(&info, loc.program_id, override_status, nso_headers, has_nso, arg_info)); /* Register NSOs with ro manager. */ { @@ -719,14 +719,17 @@ namespace ams::ldr { return ResultSuccess(); } - Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) { + Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { Meta meta; /* Load Meta. */ { ScopedCodeMount mount(loc); R_TRY(mount.GetResult()); - R_TRY(LoadMeta(&meta, loc.program_id)); + R_TRY(LoadMeta(&meta, loc.program_id, mount.GetOverrideStatus())); + if (out_status != nullptr) { + *out_status = mount.GetOverrideStatus(); + } } return GetProgramInfoFromMeta(out, &meta); diff --git a/stratosphere/loader/source/ldr_process_creation.hpp b/stratosphere/loader/source/ldr_process_creation.hpp index 51e2a7ca6..f99eb56bc 100644 --- a/stratosphere/loader/source/ldr_process_creation.hpp +++ b/stratosphere/loader/source/ldr_process_creation.hpp @@ -19,7 +19,7 @@ namespace ams::ldr { /* Process Creation API. */ - Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const char *path, u32 flags, Handle reslimit_h); - Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc); + Result CreateProcess(Handle *out, PinId pin_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status, const char *path, u32 flags, Handle reslimit_h); + Result GetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc); } diff --git a/stratosphere/loader/source/ldr_ro_manager.cpp b/stratosphere/loader/source/ldr_ro_manager.cpp index a50c2c486..3ef079ef4 100644 --- a/stratosphere/loader/source/ldr_ro_manager.cpp +++ b/stratosphere/loader/source/ldr_ro_manager.cpp @@ -34,6 +34,7 @@ namespace ams::ldr::ro { PinId pin_id; os::ProcessId process_id; ncm::ProgramId program_id; + cfg::OverrideStatus override_status; ncm::ProgramLocation loc; ModuleInfo modules[ModuleCountMax]; bool in_use; @@ -76,7 +77,7 @@ namespace ams::ldr::ro { } /* RO Manager API. */ - Result PinProgram(PinId *out, const ncm::ProgramLocation &loc) { + Result PinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status) { *out = InvalidPinId; ProcessInfo *info = GetFreeProcessInfo(); R_UNLESS(info != nullptr, ldr::ResultTooManyProcesses()); @@ -86,6 +87,7 @@ namespace ams::ldr::ro { std::memset(info, 0, sizeof(*info)); info->pin_id = { s_cur_pin_id++ }; info->loc = loc; + info->override_status = status; info->in_use = true; *out = info->pin_id; return ResultSuccess(); @@ -100,11 +102,12 @@ namespace ams::ldr::ro { } - Result GetProgramLocation(ncm::ProgramLocation *out, PinId id) { + Result GetProgramLocationAndStatus(ncm::ProgramLocation *out, cfg::OverrideStatus *out_status, PinId id) { ProcessInfo *info = GetProcessInfo(id); R_UNLESS(info != nullptr, ldr::ResultNotPinned()); *out = info->loc; + *out_status = info->override_status; return ResultSuccess(); } diff --git a/stratosphere/loader/source/ldr_ro_manager.hpp b/stratosphere/loader/source/ldr_ro_manager.hpp index d5b0aa20a..059db0944 100644 --- a/stratosphere/loader/source/ldr_ro_manager.hpp +++ b/stratosphere/loader/source/ldr_ro_manager.hpp @@ -19,9 +19,9 @@ namespace ams::ldr::ro { /* RO Manager API. */ - Result PinProgram(PinId *out, const ncm::ProgramLocation &loc); + Result PinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status); Result UnpinProgram(PinId id); - Result GetProgramLocation(ncm::ProgramLocation *out, PinId id); + Result GetProgramLocationAndStatus(ncm::ProgramLocation *out, cfg::OverrideStatus *out_status, PinId id); Result RegisterProcess(PinId id, os::ProcessId process_id, ncm::ProgramId program_id); Result RegisterModule(PinId id, const u8 *build_id, uintptr_t address, size_t size); Result GetProcessModuleInfo(u32 *out_count, ModuleInfo *out, size_t max_out_count, os::ProcessId process_id); diff --git a/stratosphere/pm/source/impl/pm_process_info.cpp b/stratosphere/pm/source/impl/pm_process_info.cpp index bd3dfc9d6..7bc21b720 100644 --- a/stratosphere/pm/source/impl/pm_process_info.cpp +++ b/stratosphere/pm/source/impl/pm_process_info.cpp @@ -17,7 +17,7 @@ namespace ams::pm::impl { - ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) { + ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) { this->waitable_holder.SetUserData(reinterpret_cast(this)); } diff --git a/stratosphere/pm/source/impl/pm_process_info.hpp b/stratosphere/pm/source/impl/pm_process_info.hpp index 975379eaa..8c15a9964 100644 --- a/stratosphere/pm/source/impl/pm_process_info.hpp +++ b/stratosphere/pm/source/impl/pm_process_info.hpp @@ -41,6 +41,7 @@ namespace ams::pm::impl { const os::ProcessId process_id; const ldr::PinId pin_id; const ncm::ProgramLocation loc; + const cfg::OverrideStatus status; Handle handle; ProcessState state; u32 flags; @@ -58,7 +59,7 @@ namespace ams::pm::impl { return (this->flags & flag); } public: - ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l); + ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s); ~ProcessInfo(); void Cleanup(); @@ -78,10 +79,14 @@ namespace ams::pm::impl { return this->pin_id; } - const ncm::ProgramLocation &GetProgramLocation() { + const ncm::ProgramLocation &GetProgramLocation() const { return this->loc; } + const cfg::OverrideStatus &GetOverrideStatus() const { + return this->status; + } + ProcessState GetState() const { return this->state; } diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index de26de373..fecb1236a 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -277,7 +277,8 @@ namespace ams::pm::impl { Result LaunchProcess(os::WaitableManager &waitable_manager, const LaunchProcessArgs &args) { /* Get Program Info. */ ldr::ProgramInfo program_info; - R_TRY(ldr::pm::GetProgramInfo(&program_info, args.location)); + cfg::OverrideStatus override_status; + R_TRY(ldr::pm::AtmosphereGetProgramInfo(&program_info, &override_status, args.location)); const bool is_application = (program_info.flags & ldr::ProgramInfoFlag_ApplicationTypeMask) == ldr::ProgramInfoFlag_Application; const bool allow_debug = (program_info.flags & ldr::ProgramInfoFlag_AllowDebug) || hos::GetVersion() < hos::Version_200; @@ -289,8 +290,7 @@ namespace ams::pm::impl { /* Pin the program with loader. */ ldr::PinId pin_id; - R_TRY(ldr::pm::PinProgram(&pin_id, location)); - + R_TRY(ldr::pm::AtmospherePinProgram(&pin_id, location, override_status)); /* Ensure resources are available. */ resource::WaitResourceAvailable(&program_info); @@ -309,7 +309,7 @@ namespace ams::pm::impl { /* Make new process info. */ void *process_info_storage = g_process_info_allocator.AllocateProcessInfoStorage(); AMS_ASSERT(process_info_storage != nullptr); - ProcessInfo *process_info = new (process_info_storage) ProcessInfo(process_handle, process_id, pin_id, location); + ProcessInfo *process_info = new (process_info_storage) ProcessInfo(process_handle, process_id, pin_id, location, override_status); /* Link new process info. */ { @@ -332,7 +332,7 @@ namespace ams::pm::impl { /* Register with FS and SM. */ R_TRY(fsprRegisterProgram(static_cast(process_id), static_cast(location.program_id), static_cast(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size)); - R_TRY(sm::manager::RegisterProcess(process_id, location.program_id, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size)); + R_TRY(sm::manager::RegisterProcess(process_id, location.program_id, override_status, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size)); /* Set flags. */ if (is_application) { @@ -648,7 +648,7 @@ namespace ams::pm::impl { return pm::ResultProcessNotFound(); } - Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id) { + Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -656,6 +656,7 @@ namespace ams::pm::impl { *out_process_handle = process_info->GetHandle(); *out_loc = process_info->GetProgramLocation(); + *out_status = process_info->GetOverrideStatus(); return ResultSuccess(); } diff --git a/stratosphere/pm/source/impl/pm_process_manager.hpp b/stratosphere/pm/source/impl/pm_process_manager.hpp index f07a30f02..721a0afd6 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.hpp +++ b/stratosphere/pm/source/impl/pm_process_manager.hpp @@ -37,7 +37,7 @@ namespace ams::pm::impl { Result GetProcessId(os::ProcessId *out, ncm::ProgramId program_id); Result GetProgramId(ncm::ProgramId *out, os::ProcessId process_id); Result GetApplicationProcessId(os::ProcessId *out_process_id); - Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id); + Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id); /* Hook API. */ Result HookToCreateProcess(Handle *out_hook, ncm::ProgramId program_id); diff --git a/stratosphere/pm/source/pm_debug_monitor_service.cpp b/stratosphere/pm/source/pm_debug_monitor_service.cpp index 4534d023d..c0513989a 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.cpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.cpp @@ -54,8 +54,8 @@ namespace ams::pm::dmnt { } /* Atmosphere extension commands. */ - Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, os::ProcessId process_id) { - return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), process_id); + Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { + return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), out_status.GetPointer(), process_id); } Result DebugMonitorServiceBase::AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource) { diff --git a/stratosphere/pm/source/pm_debug_monitor_service.hpp b/stratosphere/pm/source/pm_debug_monitor_service.hpp index edd0df1d1..708574dd8 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.hpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.hpp @@ -31,7 +31,7 @@ namespace ams::pm::dmnt { virtual Result ClearHook(u32 which); /* Atmosphere extension commands. */ - virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, os::ProcessId process_id); + virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); virtual Result AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource); }; diff --git a/stratosphere/pm/source/pm_info_service.cpp b/stratosphere/pm/source/pm_info_service.cpp index a06529ef3..4c0e1ac28 100644 --- a/stratosphere/pm/source/pm_info_service.cpp +++ b/stratosphere/pm/source/pm_info_service.cpp @@ -37,4 +37,9 @@ namespace ams::pm::info { return pm::info::HasLaunchedProgram(out.GetPointer(), program_id); } + Result InformationService::AtmosphereGetProcessInfo(sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { + Handle dummy_handle; + return impl::AtmosphereGetProcessInfo(&dummy_handle, out_loc.GetPointer(), out_status.GetPointer(), process_id); + } + } diff --git a/stratosphere/pm/source/pm_info_service.hpp b/stratosphere/pm/source/pm_info_service.hpp index 51b133f93..e7ef07b62 100644 --- a/stratosphere/pm/source/pm_info_service.hpp +++ b/stratosphere/pm/source/pm_info_service.hpp @@ -25,6 +25,7 @@ namespace ams::pm::info { AtmosphereGetProcessId = 65000, AtmosphereHasLaunchedProgram = 65001, + AtmosphereGetProcessInfo = 65002, }; private: /* Actual command implementations. */ @@ -33,12 +34,14 @@ namespace ams::pm::info { /* Atmosphere extension commands. */ Result AtmosphereGetProcessId(sf::Out out, ncm::ProgramId program_id); Result AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); + Result AtmosphereGetProcessInfo(sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(GetProgramId), MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessId), MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), + MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), }; }; diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index b2bd892bd..3c83ec525 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -106,7 +106,7 @@ namespace { fsprUnregisterProgram(static_cast(process_id)); fsprRegisterProgram(static_cast(process_id), static_cast(process_id), NcmStorageId_BuiltInSystem, PrivilegedFileAccessHeader, sizeof(PrivilegedFileAccessHeader), PrivilegedFileAccessControl, sizeof(PrivilegedFileAccessControl)); sm::manager::UnregisterProcess(process_id); - sm::manager::RegisterProcess(process_id, GetProcessProgramId(process_id), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl)); + sm::manager::RegisterProcess(process_id, GetProcessProgramId(process_id), cfg::OverrideStatus{}, PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl)); } void RegisterPrivilegedProcesses() { diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index 7c88ae931..7b6994c47 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -29,6 +29,7 @@ namespace ams::sm::impl { struct ProcessInfo { os::ProcessId process_id; ncm::ProgramId program_id; + cfg::OverrideStatus override_status; size_t access_control_size; u8 access_control[AccessControlSizeMax]; @@ -39,13 +40,14 @@ namespace ams::sm::impl { void Free() { this->process_id = os::InvalidProcessId; this->program_id = ncm::InvalidProgramId; + this->override_status = {}; this->access_control_size = 0; std::memset(this->access_control, 0, sizeof(this->access_control)); } }; /* Forward declaration, for use in ServiceInfo. */ - ncm::ProgramId GetProgramIdForMitm(os::ProcessId process_id); + void GetMitmProcessInfo(MitmProcessInfo *out, os::ProcessId process_id); struct ServiceInfo { ServiceName name; @@ -96,10 +98,9 @@ namespace ams::sm::impl { this->mitm_process_id = os::InvalidProcessId; } - void AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd) { + void AcknowledgeMitmSession(MitmProcessInfo *out_info, Handle *out_hnd) { /* Copy to output. */ - *out_process_id = this->mitm_waiting_ack_process_id; - *out_program_id = GetProgramIdForMitm(this->mitm_waiting_ack_process_id); + GetMitmProcessInfo(out_info, this->mitm_waiting_ack_process_id); *out_hnd = this->mitm_fwd_sess_h.Move(); this->mitm_waiting_ack = false; this->mitm_waiting_ack_process_id = os::InvalidProcessId; @@ -224,11 +225,15 @@ namespace ams::sm::impl { return service_info != nullptr && IsValidProcessId(service_info->mitm_process_id); } - ncm::ProgramId GetProgramIdForMitm(os::ProcessId process_id) { + void GetMitmProcessInfo(MitmProcessInfo *out_info, os::ProcessId process_id) { /* Anything that can request a mitm session must have a process info. */ const auto process_info = GetProcessInfo(process_id); AMS_ASSERT(process_info != nullptr); - return process_info->program_id; + + /* Write to output. */ + out_info->process_id = process_id; + out_info->program_id = process_info->program_id; + out_info->override_status = process_info->override_status; } bool IsMitmDisallowed(ncm::ProgramId program_id) { @@ -341,16 +346,12 @@ namespace ams::sm::impl { return service == ServiceName::Encode("fsp-srv"); } - Result GetMitmServiceHandleImpl(Handle *out, ServiceInfo *service_info, os::ProcessId process_id, ncm::ProgramId program_id) { + Result GetMitmServiceHandleImpl(Handle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) { /* Send command to query if we should mitm. */ bool should_mitm; { Service srv { .session = service_info->mitm_query_h.Get() }; - const struct { - os::ProcessId process_id; - ncm::ProgramId program_id; - } in = { process_id, program_id }; - R_TRY(serviceDispatchInOut(&srv, 65000, in, should_mitm)); + R_TRY(serviceDispatchInOut(&srv, 65000, client_info, should_mitm)); } /* If we shouldn't mitm, give normal session. */ @@ -365,7 +366,7 @@ namespace ams::sm::impl { *out = hnd.Move(); } - service_info->mitm_waiting_ack_process_id = process_id; + service_info->mitm_waiting_ack_process_id = client_info.process_id; service_info->mitm_waiting_ack = true; return ResultSuccess(); @@ -377,11 +378,12 @@ namespace ams::sm::impl { /* Check if we should return a mitm handle. */ if (IsValidProcessId(service_info->mitm_process_id) && service_info->mitm_process_id != process_id) { - /* Get program id, ensure that we're allowed to mitm the given program. */ - const ncm::ProgramId program_id = GetProgramIdForMitm(process_id); - if (!IsMitmDisallowed(program_id)) { + /* Get mitm process info, ensure that we're allowed to mitm the given program. */ + MitmProcessInfo client_info; + GetMitmProcessInfo(&client_info, process_id); + if (!IsMitmDisallowed(client_info.program_id)) { /* We're mitm'd. Assert, because mitm service host dead is an error state. */ - R_ASSERT(GetMitmServiceHandleImpl(out, service_info, process_id, program_id)); + R_ASSERT(GetMitmServiceHandleImpl(out, service_info, client_info)); return ResultSuccess(); } } @@ -423,7 +425,7 @@ namespace ams::sm::impl { } /* Process management. */ - Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) { + Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) { /* Check that access control will fit in the ServiceInfo. */ R_UNLESS(aci_sac_size <= AccessControlSizeMax, sm::ResultTooLargeAccessControl()); @@ -438,6 +440,7 @@ namespace ams::sm::impl { /* Save info. */ proc->process_id = process_id; proc->program_id = program_id; + proc->override_status = override_status; proc->access_control_size = aci_sac_size; std::memcpy(proc->access_control, aci_sac, proc->access_control_size); return ResultSuccess(); @@ -651,7 +654,7 @@ namespace ams::sm::impl { return ResultSuccess(); } - Result AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd, os::ProcessId process_id, ServiceName service) { + Result AcknowledgeMitmSession(MitmProcessInfo *out_info, Handle *out_hnd, os::ProcessId process_id, ServiceName service) { /* Validate service name. */ R_TRY(ValidateServiceName(service)); @@ -670,7 +673,7 @@ namespace ams::sm::impl { R_UNLESS(service_info->mitm_waiting_ack, sm::ResultNotAllowed()); /* Acknowledge. */ - service_info->AcknowledgeMitmSession(out_process_id, out_program_id, out_hnd); + service_info->AcknowledgeMitmSession(out_info, out_hnd); return ResultSuccess(); } diff --git a/stratosphere/sm/source/impl/sm_service_manager.hpp b/stratosphere/sm/source/impl/sm_service_manager.hpp index 0e09d2c93..d6610769d 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.hpp +++ b/stratosphere/sm/source/impl/sm_service_manager.hpp @@ -20,7 +20,7 @@ namespace ams::sm::impl { /* Process management. */ - Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size); + Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size); Result UnregisterProcess(os::ProcessId process_id); /* Service management. */ @@ -37,7 +37,7 @@ namespace ams::sm::impl { Result InstallMitm(Handle *out, Handle *out_query, os::ProcessId process_id, ServiceName service); Result UninstallMitm(os::ProcessId process_id, ServiceName service); Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service); - Result AcknowledgeMitmSession(os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, Handle *out_hnd, os::ProcessId process_id, ServiceName service); + Result AcknowledgeMitmSession(MitmProcessInfo *out_info, Handle *out_hnd, os::ProcessId process_id, ServiceName service); /* Dmnt record extensions. */ Result GetServiceRecord(ServiceRecord *out, ServiceName service); diff --git a/stratosphere/sm/source/sm_manager_service.cpp b/stratosphere/sm/source/sm_manager_service.cpp index fca7e6975..5a40ebf8e 100644 --- a/stratosphere/sm/source/sm_manager_service.cpp +++ b/stratosphere/sm/source/sm_manager_service.cpp @@ -19,7 +19,7 @@ namespace ams::sm { Result ManagerService::RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) { - return impl::RegisterProcess(process_id, ncm::ProgramId::Invalid, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()); + return impl::RegisterProcess(process_id, ncm::ProgramId::Invalid, cfg::OverrideStatus{}, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()); } Result ManagerService::UnregisterProcess(os::ProcessId process_id) { @@ -34,9 +34,9 @@ namespace ams::sm { R_ASSERT(impl::HasMitm(out.GetPointer(), service)); } - Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) { - /* This takes in a program id, unlike RegisterProcess. */ - return impl::RegisterProcess(process_id, program_id, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()); + Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) { + /* This takes in a program id and override status, unlike RegisterProcess. */ + return impl::RegisterProcess(process_id, program_id, override_status, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()); } } diff --git a/stratosphere/sm/source/sm_manager_service.hpp b/stratosphere/sm/source/sm_manager_service.hpp index b8f31dc0d..b1c3f6425 100644 --- a/stratosphere/sm/source/sm_manager_service.hpp +++ b/stratosphere/sm/source/sm_manager_service.hpp @@ -36,7 +36,7 @@ namespace ams::sm { virtual Result UnregisterProcess(os::ProcessId process_id); virtual void AtmosphereEndInitDefers(); virtual void AtmosphereHasMitm(sf::Out out, ServiceName service); - virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); + virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(RegisterProcess), diff --git a/stratosphere/sm/source/sm_user_service.cpp b/stratosphere/sm/source/sm_user_service.cpp index 1ae208504..ddac80133 100644 --- a/stratosphere/sm/source/sm_user_service.cpp +++ b/stratosphere/sm/source/sm_user_service.cpp @@ -56,9 +56,9 @@ namespace ams::sm { return impl::UninstallMitm(this->process_id, service); } - Result UserService::AtmosphereAcknowledgeMitmSession(sf::Out client_process_id, sf::Out client_program_id, sf::OutMoveHandle fwd_h, ServiceName service) { + Result UserService::AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service) { R_TRY(this->EnsureInitialized()); - return impl::AcknowledgeMitmSession(client_process_id.GetPointer(), client_program_id.GetPointer(), fwd_h.GetHandlePointer(), this->process_id, service); + return impl::AcknowledgeMitmSession(client_info.GetPointer(), fwd_h.GetHandlePointer(), this->process_id, service); } Result UserService::AtmosphereHasMitm(sf::Out out, ServiceName service) { diff --git a/stratosphere/sm/source/sm_user_service.hpp b/stratosphere/sm/source/sm_user_service.hpp index 251892cbb..6baf448f8 100644 --- a/stratosphere/sm/source/sm_user_service.hpp +++ b/stratosphere/sm/source/sm_user_service.hpp @@ -55,7 +55,7 @@ namespace ams::sm { /* Atmosphere commands. */ virtual Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service); virtual Result AtmosphereUninstallMitm(ServiceName service); - virtual Result AtmosphereAcknowledgeMitmSession(sf::Out client_process_id, sf::Out client_program_id, sf::OutMoveHandle fwd_h, ServiceName service); + virtual Result AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service); virtual Result AtmosphereHasMitm(sf::Out out, ServiceName service); virtual Result AtmosphereWaitMitm(ServiceName service); virtual Result AtmosphereDeclareFutureMitm(ServiceName service);