From af65f581090cf1304e64392a385b7e4c8a736567 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 17 Jan 2021 22:03:26 -0800 Subject: [PATCH] ro: update for new sf semantics --- .../ldr/impl/ldr_debug_monitor_interface.hpp | 12 +++---- .../impl/ldr_process_manager_interface.hpp | 18 +++++----- .../include/stratosphere/ldr/ldr_pm_api.hpp | 2 +- .../pm/impl/pm_information_interface.hpp | 10 +++--- .../include/stratosphere/pm/pm_info_api.hpp | 4 +-- libstratosphere/source/boot2/boot2_api.cpp | 2 +- libstratosphere/source/cfg/cfg_override.cpp | 2 +- libstratosphere/source/hid/hid_api.cpp | 2 +- libstratosphere/source/ldr/ldr_ams.c | 10 +++--- libstratosphere/source/ldr/ldr_ams.h | 4 +-- libstratosphere/source/ldr/ldr_pm_api.cpp | 4 +-- libstratosphere/source/pm/pm_ams.c | 2 +- libstratosphere/source/pm/pm_ams.h | 2 +- libstratosphere/source/pm/pm_info_api.cpp | 34 +++---------------- 14 files changed, 41 insertions(+), 67 deletions(-) diff --git a/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp b/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp index c1d95380..6f666231 100644 --- a/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp +++ b/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp @@ -19,11 +19,11 @@ #include #include -#define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), (program_id, args, args_size), hos::Version_Min, hos::Version_10_2_0) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), (program_id, args), hos::Version_11_0_0 ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, (), ()) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessModuleInfo, (sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id), (count, out, process_id)) \ - AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) +#define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), (program_id, args, args_size), hos::Version_Min, hos::Version_10_2_0) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), (program_id, args), hos::Version_11_0_0 ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessModuleInfo, (sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id), (count, out, process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedBootProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, IDebugMonitorInterface, AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) diff --git a/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp b/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp index b73cb5f5..3beda438 100644 --- a/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp +++ b/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp @@ -19,14 +19,14 @@ #include #include -#define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, ldr::PinId id, u32 flags, sf::CopyHandle reslimit_h), (proc_h, id, flags, reslimit_h)) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc), (out_program_info, loc)) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc), (out_id, loc)) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (ldr::PinId id), (id)) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), (enabled), hos::Version_10_0_0) \ - AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ - AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc), (out_program_info, out_status, loc)) \ - AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status), (out_id, loc, override_status)) +#define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, ldr::PinId id, u32 flags, sf::CopyHandle reslimit_h), (proc_h, id, flags, reslimit_h)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc), (out_program_info, loc)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc), (out_id, loc)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (ldr::PinId id), (id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), (enabled), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedBootProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc), (out_program_info, out_status, loc)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status), (out_id, loc, override_status)) AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, IProcessManagerInterface, AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO) diff --git a/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp b/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp index a541310b..efe5f39d 100644 --- a/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp +++ b/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp @@ -25,7 +25,7 @@ namespace ams::ldr::pm { Result PinProgram(PinId *out, const ncm::ProgramLocation &loc); Result UnpinProgram(PinId pin_id); Result SetEnabledProgramVerification(bool enabled); - Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id); + Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id); /* Atmosphere extension API. */ Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc); diff --git a/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp b/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp index 6cdfc2f9..5e05a1e8 100644 --- a/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp +++ b/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp @@ -19,10 +19,10 @@ #include #include -#define AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, GetProgramId, (sf::Out out, os::ProcessId process_id), (out, process_id)) \ - AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessId, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ - AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ - AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereGetProcessInfo, (sf::Out out_loc, sf::Out out_status, os::ProcessId process_id), (out_loc, out_status, process_id)) +#define AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProgramId, (sf::Out out, os::ProcessId process_id), (out, process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessId, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereHasLaunchedBootProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereGetProcessInfo, (sf::Out out_loc, sf::Out out_status, os::ProcessId process_id), (out_loc, out_status, process_id)) AMS_SF_DEFINE_INTERFACE(ams::pm::impl, IInformationInterface, AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO) diff --git a/libstratosphere/include/stratosphere/pm/pm_info_api.hpp b/libstratosphere/include/stratosphere/pm/pm_info_api.hpp index 940621f0..16cba105 100644 --- a/libstratosphere/include/stratosphere/pm/pm_info_api.hpp +++ b/libstratosphere/include/stratosphere/pm/pm_info_api.hpp @@ -27,12 +27,12 @@ namespace ams::pm::info { /* Information API. */ Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id); Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id); - Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id); + Result HasLaunchedBootProgram(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); + bool HasLaunchedBootProgram(ncm::ProgramId program_id); Result IsHblProcessId(bool *out, os::ProcessId process_id); Result IsHblProgramId(bool *out, ncm::ProgramId program_id); diff --git a/libstratosphere/source/boot2/boot2_api.cpp b/libstratosphere/source/boot2/boot2_api.cpp index c089267b..2c085abd 100644 --- a/libstratosphere/source/boot2/boot2_api.cpp +++ b/libstratosphere/source/boot2/boot2_api.cpp @@ -294,7 +294,7 @@ namespace ams::boot2 { void LaunchFlaggedProgramsOnSdCard() { IterateOverFlaggedProgramsOnSdCard([](ncm::ProgramId program_id) { /* Check if we've already launched the program. */ - if (pm::info::HasLaunchedProgram(program_id)) { + if (pm::info::HasLaunchedBootProgram(program_id)) { return; } diff --git a/libstratosphere/source/cfg/cfg_override.cpp b/libstratosphere/source/cfg/cfg_override.cpp index d7ffd145..23422373 100644 --- a/libstratosphere/source/cfg/cfg_override.cpp +++ b/libstratosphere/source/cfg/cfg_override.cpp @@ -388,7 +388,7 @@ namespace ams::cfg { } /* For system modules and anything launched before the home menu, always override. */ - if (program_id < ncm::SystemAppletId::Start || !pm::info::HasLaunchedProgram(ncm::SystemAppletId::Qlaunch)) { + if (program_id < ncm::SystemAppletId::Start || !pm::info::HasLaunchedBootProgram(ncm::SystemAppletId::Qlaunch)) { status.SetProgramSpecific(); return status; } diff --git a/libstratosphere/source/hid/hid_api.cpp b/libstratosphere/source/hid/hid_api.cpp index 3ef35f95..ece8133f 100644 --- a/libstratosphere/source/hid/hid_api.cpp +++ b/libstratosphere/source/hid/hid_api.cpp @@ -53,7 +53,7 @@ namespace ams::hid { Result EnsureHidInitialized() { if (!g_initialized_hid) { if (!serviceIsActive(hidGetServiceSession())) { - if (!pm::info::HasLaunchedProgram(ncm::SystemProgramId::Hid)) { + if (!pm::info::HasLaunchedBootProgram(ncm::SystemProgramId::Hid)) { return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID); } InitializeHid(); diff --git a/libstratosphere/source/ldr/ldr_ams.c b/libstratosphere/source/ldr/ldr_ams.c index 9b39f9cd..b33559d3 100644 --- a/libstratosphere/source/ldr/ldr_ams.c +++ b/libstratosphere/source/ldr/ldr_ams.c @@ -17,19 +17,19 @@ #include #include "ldr_ams.h" -static Result _ldrAtmosphereHasLaunchedProgram(Service *srv, bool *out, u64 program_id) { +static Result _ldrAtmosphereHasLaunchedBootProgram(Service *srv, bool *out, u64 program_id) { u8 tmp; Result rc = serviceDispatchInOut(srv, 65000, program_id, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; return rc; } -Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { - return _ldrAtmosphereHasLaunchedProgram(ldrDmntGetServiceSession(), out, program_id); +Result ldrDmntAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id) { + return _ldrAtmosphereHasLaunchedBootProgram(ldrDmntGetServiceSession(), out, program_id); } -Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { - return _ldrAtmosphereHasLaunchedProgram(ldrPmGetServiceSession(), out, program_id); +Result ldrPmAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id) { + return _ldrAtmosphereHasLaunchedBootProgram(ldrPmGetServiceSession(), out, program_id); } Result ldrPmAtmosphereGetProgramInfo(LoaderProgramInfo *out_program_info, CfgOverrideStatus *out_status, const NcmProgramLocation *loc) { diff --git a/libstratosphere/source/ldr/ldr_ams.h b/libstratosphere/source/ldr/ldr_ams.h index feff70e4..30a5e416 100644 --- a/libstratosphere/source/ldr/ldr_ams.h +++ b/libstratosphere/source/ldr/ldr_ams.h @@ -16,8 +16,8 @@ typedef struct { u64 flags; } CfgOverrideStatus; -Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id); -Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id); +Result ldrPmAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id); +Result ldrDmntAtmosphereHasLaunchedBootProgram(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); diff --git a/libstratosphere/source/ldr/ldr_pm_api.cpp b/libstratosphere/source/ldr/ldr_pm_api.cpp index d6d1c190..046e6a95 100644 --- a/libstratosphere/source/ldr/ldr_pm_api.cpp +++ b/libstratosphere/source/ldr/ldr_pm_api.cpp @@ -36,8 +36,8 @@ namespace ams::ldr::pm { return ldrPmUnpinProgram(pin_id.value); } - Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) { - return ldrPmAtmosphereHasLaunchedProgram(out, static_cast(program_id)); + Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id) { + return ldrPmAtmosphereHasLaunchedBootProgram(out, static_cast(program_id)); } Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc) { diff --git a/libstratosphere/source/pm/pm_ams.c b/libstratosphere/source/pm/pm_ams.c index 5ca42261..92798753 100644 --- a/libstratosphere/source/pm/pm_ams.c +++ b/libstratosphere/source/pm/pm_ams.c @@ -21,7 +21,7 @@ Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id) { return serviceDispatchInOut(pminfoGetServiceSession(), 65000, program_id, *out_pid); } -Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id) { +Result pminfoAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id) { u8 tmp; Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, program_id, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; diff --git a/libstratosphere/source/pm/pm_ams.h b/libstratosphere/source/pm/pm_ams.h index 74e2a015..c66c7599 100644 --- a/libstratosphere/source/pm/pm_ams.h +++ b/libstratosphere/source/pm/pm_ams.h @@ -17,7 +17,7 @@ typedef struct { } CfgOverrideStatus; Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id); -Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id); +Result pminfoAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id); Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); diff --git a/libstratosphere/source/pm/pm_info_api.cpp b/libstratosphere/source/pm/pm_info_api.cpp index 3c550d0f..e1d7998c 100644 --- a/libstratosphere/source/pm/pm_info_api.cpp +++ b/libstratosphere/source/pm/pm_info_api.cpp @@ -18,58 +18,32 @@ namespace ams::pm::info { - namespace { - - /* Global lock. */ - os::Mutex g_info_lock(false); - /* TODO: Less memory-intensive storage? */ - std::set g_cached_launched_programs; - - } - /* Information API. */ Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id) { - std::scoped_lock lk(g_info_lock); - return pminfoGetProgramId(reinterpret_cast(out_program_id), static_cast(process_id)); } Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id) { - std::scoped_lock lk(g_info_lock); - 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_SYMBOL HasLaunchedProgram(bool *out, ncm::ProgramId program_id) { - std::scoped_lock lk(g_info_lock); - - if (g_cached_launched_programs.find(static_cast(program_id)) != g_cached_launched_programs.end()) { - *out = true; - return ResultSuccess(); - } - + Result WEAK_SYMBOL HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id) { bool has_launched = false; - R_TRY(pminfoAtmosphereHasLaunchedProgram(&has_launched, static_cast(program_id))); - if (has_launched) { - g_cached_launched_programs.insert(static_cast(program_id)); - } - + R_TRY(pminfoAtmosphereHasLaunchedBootProgram(&has_launched, static_cast(program_id))); *out = has_launched; return ResultSuccess(); } - bool HasLaunchedProgram(ncm::ProgramId program_id) { + bool HasLaunchedBootProgram(ncm::ProgramId program_id) { bool has_launched = false; - R_ABORT_UNLESS(HasLaunchedProgram(&has_launched, program_id)); + R_ABORT_UNLESS(HasLaunchedBootProgram(&has_launched, program_id)); return has_launched; }