From aa0826bb708e4f4345e78a4547f6a05773144753 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 14 Oct 2019 22:49:06 -0700 Subject: [PATCH] pm: update for new-ipc --- .../include/stratosphere/pm/pm_dmnt_api.hpp | 8 +- .../include/stratosphere/pm/pm_info_api.hpp | 4 +- .../include/stratosphere/pm/pm_shell_api.hpp | 2 +- .../include/stratosphere/pm/pm_types.hpp | 3 +- .../sf/impl/sf_impl_command_serialization.hpp | 4 +- .../stratosphere/sm/sm_manager_api.hpp | 5 +- .../libstratosphere/source/pm/pm_dmnt_api.cpp | 16 ++-- .../libstratosphere/source/pm/pm_info_api.cpp | 8 +- .../source/pm/pm_shell_api.cpp | 4 +- .../source/sm/sm_manager_api.cpp | 8 +- stratosphere/pm/source/boot2/boot2_api.cpp | 11 +-- .../pm/source/impl/pm_process_info.cpp | 4 +- .../pm/source/impl/pm_process_info.hpp | 8 +- .../pm/source/impl/pm_process_manager.cpp | 62 +++++++-------- .../pm/source/impl/pm_process_manager.hpp | 20 ++--- .../pm/source/impl/pm_resource_manager.cpp | 20 ++--- .../pm/source/pm_boot_mode_service.cpp | 2 +- .../pm/source/pm_boot_mode_service.hpp | 8 +- .../pm/source/pm_debug_monitor_service.cpp | 26 +++---- .../pm/source/pm_debug_monitor_service.hpp | 60 +++++++-------- stratosphere/pm/source/pm_info_service.cpp | 6 +- stratosphere/pm/source/pm_info_service.hpp | 14 ++-- stratosphere/pm/source/pm_main.cpp | 75 ++++++++++++------- stratosphere/pm/source/pm_shell_service.cpp | 18 ++--- stratosphere/pm/source/pm_shell_service.hpp | 62 +++++++-------- 25 files changed, 239 insertions(+), 219 deletions(-) diff --git a/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp b/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp index 607b4c43d..a9dc38941 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp @@ -22,11 +22,11 @@ namespace sts::pm::dmnt { /* Debug Monitor API. */ - Result StartProcess(u64 process_id); - Result GetProcessId(u64 *out_process_id, const ncm::TitleId title_id); - Result GetApplicationProcessId(u64 *out_process_id); + Result StartProcess(os::ProcessId process_id); + Result GetProcessId(os::ProcessId *out_process_id, const ncm::TitleId title_id); + Result GetApplicationProcessId(os::ProcessId *out_process_id); Result HookToCreateApplicationProcess(Handle *out_handle); - Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, u64 process_id); + Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, 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 91b64e3e8..ab330ba22 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_info_api.hpp @@ -22,8 +22,8 @@ namespace sts::pm::info { /* Information API. */ - Result GetTitleId(ncm::TitleId *out_title_id, u64 process_id); - Result GetProcessId(u64 *out_process_id, ncm::TitleId title_id); + Result GetTitleId(ncm::TitleId *out_title_id, os::ProcessId process_id); + Result GetProcessId(os::ProcessId *out_process_id, ncm::TitleId title_id); Result HasLaunchedTitle(bool *out, ncm::TitleId title_id); /* Information convenience API. */ diff --git a/stratosphere/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp b/stratosphere/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp index f3f6002c5..4277e3f85 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp @@ -22,6 +22,6 @@ namespace sts::pm::shell { /* Shell API. */ - Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags); + Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags); } diff --git a/stratosphere/libstratosphere/include/stratosphere/pm/pm_types.hpp b/stratosphere/libstratosphere/include/stratosphere/pm/pm_types.hpp index bb6eb29a2..d7ad6ce62 100644 --- a/stratosphere/libstratosphere/include/stratosphere/pm/pm_types.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/pm/pm_types.hpp @@ -16,6 +16,7 @@ #pragma once #include +#include "../os/os_common_types.hpp" namespace sts::pm { @@ -36,7 +37,7 @@ namespace sts::pm { struct ProcessEventInfo { u32 event; - u64 process_id; + os::ProcessId process_id; }; static_assert(sizeof(ProcessEventInfo) == 0x10 && std::is_pod::value, "ProcessEventInfo definition!"); diff --git a/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index 2ea26530b..e71677783 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -581,7 +581,7 @@ namespace sts::sf::impl { constexpr inline uintptr_t GetAddress() const { static_assert(Offset <= Size, "Offset <= Size"); static_assert(TypeSize <= Size, "TypeSize <= Size"); - static_assert(Offset + TypeSize <= Size, "Offset + TypeSize <= Size"); + static_assert(Offset + TypeSize <= Size || false, "Offset + TypeSize <= Size"); return reinterpret_cast(&data[Offset]); } @@ -944,7 +944,7 @@ namespace sts::sf::impl { } } else if constexpr (Info.arg_type == ArgumentType::OutData) { /* New out rawdata. */ - constexpr size_t Offset = CommandMeta::InDataOffsets[Info.out_raw_data_index]; + constexpr size_t Offset = CommandMeta::OutDataOffsets[Info.out_raw_data_index]; return T(out_raw_holder.template GetAddress()); } else if constexpr (Info.arg_type == ArgumentType::InHandle) { /* New InHandle. */ diff --git a/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp b/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp index c9e01f75a..a2279fac9 100644 --- a/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/sm/sm_manager_api.hpp @@ -18,12 +18,13 @@ #include "sm_types.hpp" #include "../ncm/ncm_types.hpp" +#include "../os/os_common_types.hpp" namespace sts::sm::manager { /* Manager API. */ - Result RegisterProcess(u64 process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size); - Result UnregisterProcess(u64 process_id); + Result RegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size); + Result UnregisterProcess(os::ProcessId process_id); /* Atmosphere extensions. */ Result EndInitialDefers(); diff --git a/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp b/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp index 656669b62..3687eb003 100644 --- a/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp +++ b/stratosphere/libstratosphere/source/pm/pm_dmnt_api.cpp @@ -23,16 +23,16 @@ namespace sts::pm::dmnt { /* Debug Monitor API. */ - Result StartProcess(u64 process_id) { - return pmdmntStartProcess(process_id); + Result StartProcess(os::ProcessId process_id) { + return pmdmntStartProcess(static_cast(process_id)); } - Result GetProcessId(u64 *out_process_id, const ncm::TitleId title_id) { - return pmdmntGetTitlePid(out_process_id, static_cast(title_id)); + Result GetProcessId(os::ProcessId *out_process_id, const ncm::TitleId title_id) { + return pmdmntGetTitlePid(reinterpret_cast(out_process_id), static_cast(title_id)); } - Result GetApplicationProcessId(u64 *out_process_id) { - return pmdmntGetApplicationPid(out_process_id); + Result GetApplicationProcessId(os::ProcessId *out_process_id) { + return pmdmntGetApplicationPid(reinterpret_cast(out_process_id)); } Result HookToCreateApplicationProcess(Handle *out_handle) { @@ -42,10 +42,10 @@ namespace sts::pm::dmnt { return ResultSuccess; } - Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, u64 process_id) { + Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) { *out_handle = INVALID_HANDLE; *out_loc = {}; - return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast(&out_loc->title_id), &out_loc->storage_id, process_id); + return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast(&out_loc->title_id), &out_loc->storage_id, 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 9f3c8b7db..9d8a8c835 100644 --- a/stratosphere/libstratosphere/source/pm/pm_info_api.cpp +++ b/stratosphere/libstratosphere/source/pm/pm_info_api.cpp @@ -31,16 +31,16 @@ namespace sts::pm::info { } /* Information API. */ - Result GetTitleId(ncm::TitleId *out_title_id, u64 process_id) { + Result GetTitleId(ncm::TitleId *out_title_id, os::ProcessId process_id) { std::scoped_lock lk(g_info_lock); - return pminfoGetTitleId(reinterpret_cast(out_title_id), process_id); + return pminfoGetTitleId(reinterpret_cast(out_title_id), static_cast(process_id)); } - Result GetProcessId(u64 *out_process_id, ncm::TitleId title_id) { + Result GetProcessId(os::ProcessId *out_process_id, ncm::TitleId title_id) { std::scoped_lock lk(g_info_lock); - return pminfoAtmosphereGetProcessId(out_process_id, static_cast(title_id)); + return pminfoAtmosphereGetProcessId(reinterpret_cast(out_process_id), static_cast(title_id)); } Result WEAK HasLaunchedTitle(bool *out, ncm::TitleId title_id) { diff --git a/stratosphere/libstratosphere/source/pm/pm_shell_api.cpp b/stratosphere/libstratosphere/source/pm/pm_shell_api.cpp index 09d5e4d2b..f85eb1a33 100644 --- a/stratosphere/libstratosphere/source/pm/pm_shell_api.cpp +++ b/stratosphere/libstratosphere/source/pm/pm_shell_api.cpp @@ -21,8 +21,8 @@ namespace sts::pm::shell { /* Shell API. */ - Result WEAK LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { - return pmshellLaunchProcess(launch_flags, static_cast(loc.title_id), loc.storage_id, out_process_id); + Result WEAK LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { + return pmshellLaunchProcess(launch_flags, static_cast(loc.title_id), loc.storage_id, reinterpret_cast(out_process_id)); } } diff --git a/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp b/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp index 84dd48318..f83d041d4 100644 --- a/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp +++ b/stratosphere/libstratosphere/source/sm/sm_manager_api.cpp @@ -24,12 +24,12 @@ namespace sts::sm::manager { /* Manager API. */ - Result RegisterProcess(u64 process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) { - return smManagerAtmosphereRegisterProcess(process_id, static_cast(title_id), acid, acid_size, aci, aci_size); + Result RegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) { + return smManagerAtmosphereRegisterProcess(static_cast(process_id), static_cast(title_id), acid, acid_size, aci, aci_size); } - Result UnregisterProcess(u64 process_id) { - return smManagerUnregisterProcess(process_id); + Result UnregisterProcess(os::ProcessId process_id) { + return smManagerUnregisterProcess(static_cast(process_id)); } /* Atmosphere extensions. */ diff --git a/stratosphere/pm/source/boot2/boot2_api.cpp b/stratosphere/pm/source/boot2/boot2_api.cpp index 385a3d816..d7b898d27 100644 --- a/stratosphere/pm/source/boot2/boot2_api.cpp +++ b/stratosphere/pm/source/boot2/boot2_api.cpp @@ -139,8 +139,8 @@ namespace sts::boot2 { return c == '\r' || c == '\n'; } - void LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { - u64 process_id = 0; + void LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { + os::ProcessId process_id = os::InvalidProcessId; switch (pm::shell::LaunchTitle(&process_id, loc, launch_flags)) { case ResultKernelResourceExhausted: @@ -187,7 +187,8 @@ namespace sts::boot2 { R_ASSERT(set_sys_holder.GetResult()); u8 force_maintenance = 1; - setsysGetSettingsItemValue("boot", "force_maintenance", &force_maintenance, sizeof(force_maintenance)); + u64 size_out; + setsysGetSettingsItemValue("boot", "force_maintenance", &force_maintenance, sizeof(force_maintenance), &size_out); if (force_maintenance != 0) { return true; } @@ -318,7 +319,7 @@ namespace sts::boot2 { /* Wait for other atmosphere mitm modules to initialize. */ R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("set:sys"))); - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) { + if (hos::GetVersion() >= hos::Version_200) { R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc"))); } else { R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc:c"))); @@ -340,7 +341,7 @@ namespace sts::boot2 { if (maintenance) { LaunchList(AdditionalMaintenanceLaunchPrograms, NumAdditionalMaintenanceLaunchPrograms); /* Starting in 7.0.0, npns is launched during maintenance boot. */ - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_700) { + if (hos::GetVersion() >= hos::Version_700) { LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Npns, ncm::StorageId::NandSystem), 0); } } else { diff --git a/stratosphere/pm/source/impl/pm_process_info.cpp b/stratosphere/pm/source/impl/pm_process_info.cpp index 01ed87bbc..73864bf2c 100644 --- a/stratosphere/pm/source/impl/pm_process_info.cpp +++ b/stratosphere/pm/source/impl/pm_process_info.cpp @@ -21,7 +21,7 @@ namespace sts::pm::impl { - ProcessInfo::ProcessInfo(Handle h, u64 pid, ldr::PinId pin, const ncm::TitleLocation &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::TitleLocation &l) : process_id(pid), pin_id(pin), loc(l), handle(h), state(ProcessState_Created), flags(0), waitable_holder(h) { this->waitable_holder.SetUserData(reinterpret_cast(this)); } @@ -32,7 +32,7 @@ namespace sts::pm::impl { void ProcessInfo::Cleanup() { if (this->handle != INVALID_HANDLE) { /* Unregister the process. */ - fsprUnregisterProgram(this->process_id); + fsprUnregisterProgram(static_cast(this->process_id)); sm::manager::UnregisterProcess(this->process_id); ldr::pm::UnpinTitle(this->pin_id); diff --git a/stratosphere/pm/source/impl/pm_process_info.hpp b/stratosphere/pm/source/impl/pm_process_info.hpp index 1b40c557e..aef076465 100644 --- a/stratosphere/pm/source/impl/pm_process_info.hpp +++ b/stratosphere/pm/source/impl/pm_process_info.hpp @@ -44,7 +44,7 @@ namespace sts::pm::impl { }; private: util::IntrusiveListNode list_node; - const u64 process_id; + const os::ProcessId process_id; const ldr::PinId pin_id; const ncm::TitleLocation loc; Handle handle; @@ -64,7 +64,7 @@ namespace sts::pm::impl { return (this->flags & flag); } public: - ProcessInfo(Handle h, u64 pid, ldr::PinId pin, const ncm::TitleLocation &l); + ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::TitleLocation &l); ~ProcessInfo(); void Cleanup(); @@ -76,7 +76,7 @@ namespace sts::pm::impl { return this->handle; } - u64 GetProcessId() const { + os::ProcessId GetProcessId() const { return this->process_id; } @@ -176,7 +176,7 @@ namespace sts::pm::impl { this->erase(this->iterator_to(*process_info)); } - ProcessInfo *Find(u64 process_id) { + ProcessInfo *Find(os::ProcessId process_id) { for (auto it = this->begin(); it != this->end(); it++) { if ((*it).GetProcessId() == process_id) { return &*it; diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 6ddd31eb5..b608c3550 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -37,7 +37,7 @@ namespace sts::pm::impl { }; struct LaunchProcessArgs { - u64 *out_process_id; + os::ProcessId *out_process_id; ncm::TitleLocation location; u32 flags; }; @@ -62,38 +62,38 @@ namespace sts::pm::impl { LaunchFlagsDeprecated_SignalOnStart = (1 << 5), }; -#define GET_FLAG_MASK(flag) (firmware_version >= FirmwareVersion_500 ? static_cast(LaunchFlags_##flag) : static_cast(LaunchFlagsDeprecated_##flag)) +#define GET_FLAG_MASK(flag) (hos_version >= hos::Version_500 ? static_cast(LaunchFlags_##flag) : static_cast(LaunchFlagsDeprecated_##flag)) inline bool ShouldSignalOnExit(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); + const auto hos_version = hos::GetVersion(); return launch_flags & GET_FLAG_MASK(SignalOnExit); } inline bool ShouldSignalOnStart(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); - if (firmware_version < FirmwareVersion_200) { + const auto hos_version = hos::GetVersion(); + if (hos_version < hos::Version_200) { return false; } return launch_flags & GET_FLAG_MASK(SignalOnStart); } inline bool ShouldSignalOnException(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); + const auto hos_version = hos::GetVersion(); return launch_flags & GET_FLAG_MASK(SignalOnException); } inline bool ShouldSignalOnDebugEvent(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); + const auto hos_version = hos::GetVersion(); return launch_flags & GET_FLAG_MASK(SignalOnDebugEvent); } inline bool ShouldStartSuspended(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); + const auto hos_version = hos::GetVersion(); return launch_flags & GET_FLAG_MASK(StartSuspended); } inline bool ShouldDisableAslr(u32 launch_flags) { - const auto firmware_version = GetRuntimeFirmwareVersion(); + const auto hos_version = hos::GetVersion(); return launch_flags & GET_FLAG_MASK(DisableAslr); } @@ -118,7 +118,7 @@ namespace sts::pm::impl { }; inline u32 GetProcessEventValue(ProcessEvent event) { - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { + if (hos::GetVersion() >= hos::Version_500) { return static_cast(event); } switch (event) { @@ -194,7 +194,7 @@ namespace sts::pm::impl { inline u32 GetLoaderCreateProcessFlags(u32 launch_flags) { u32 ldr_flags = 0; - if (ShouldSignalOnException(launch_flags) || (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && !ShouldStartSuspended(launch_flags))) { + if (ShouldSignalOnException(launch_flags) || (hos::GetVersion() >= hos::Version_200 && !ShouldStartSuspended(launch_flags))) { ldr_flags |= ldr::CreateProcessFlag_EnableDebug; } if (ShouldDisableAslr(launch_flags)) { @@ -235,7 +235,7 @@ namespace sts::pm::impl { ldr::ProgramInfo program_info; R_TRY(ldr::pm::GetProgramInfo(&program_info, 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) || GetRuntimeFirmwareVersion() < FirmwareVersion_200; + const bool allow_debug = (program_info.flags & ldr::ProgramInfoFlag_AllowDebug) || hos::GetVersion() < hos::Version_200; /* Ensure we only try to run one application. */ if (is_application && HasApplicationProcess()) { @@ -259,8 +259,8 @@ namespace sts::pm::impl { }); /* Get the process id. */ - u64 process_id; - R_ASSERT(svcGetProcessId(&process_id, process_handle)); + os::ProcessId process_id = os::InvalidProcessId; + R_ASSERT(svcGetProcessId(&process_id.value, process_handle)); /* Make new process info. */ ProcessInfo *process_info = new ProcessInfo(process_handle, process_id, pin_id, location); @@ -285,7 +285,7 @@ namespace sts::pm::impl { const u8 *aci_fah = acid_fac + program_info.acid_fac_size; /* Register with FS and SM. */ - R_TRY(fsprRegisterProgram(process_id, static_cast(location.title_id), static_cast(location.storage_id), aci_fah, program_info.aci_fah_size, acid_fac, program_info.acid_fac_size)); + R_TRY(fsprRegisterProgram(static_cast(process_id), static_cast(location.title_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.title_id, acid_sac, program_info.acid_sac_size, aci_sac, program_info.aci_sac_size)); /* Set flags. */ @@ -348,7 +348,7 @@ namespace sts::pm::impl { process_info->ClearSuspended(); process_info->SetSuspendedStateChanged(); g_process_event.Signal(); - } else if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 && process_info->ShouldSignalOnStart()) { + } else if (hos::GetVersion() >= hos::Version_200 && process_info->ShouldSignalOnStart()) { process_info->SetStartedStateChanged(); process_info->ClearSignalOnStart(); g_process_event.Signal(); @@ -366,14 +366,14 @@ namespace sts::pm::impl { } break; case ProcessState_Exited: - if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 && process_info->ShouldSignalOnExit()) { + if (hos::GetVersion() < hos::Version_500 && process_info->ShouldSignalOnExit()) { g_process_event.Signal(); } else { /* Free process resources, unlink from waitable manager. */ process_info->Cleanup(); /* Handle the case where we need to keep the process alive some time longer. */ - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 && process_info->ShouldSignalOnExit()) { + if (hos::GetVersion() >= hos::Version_500 && process_info->ShouldSignalOnExit()) { /* Remove from the living list. */ list->Remove(process_info); @@ -425,7 +425,7 @@ namespace sts::pm::impl { } /* Process Management. */ - Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 flags) { + Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags) { /* Ensure we only try to launch one title at a time. */ static os::Mutex s_lock; std::scoped_lock lk(s_lock); @@ -442,7 +442,7 @@ namespace sts::pm::impl { return g_process_launch_result; } - Result StartProcess(u64 process_id) { + Result StartProcess(os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -459,7 +459,7 @@ namespace sts::pm::impl { return StartProcess(process_info, &program_info); } - Result TerminateProcess(u64 process_id) { + Result TerminateProcess(os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -515,7 +515,7 @@ namespace sts::pm::impl { out->process_id = process.GetProcessId(); return ResultSuccess; } - if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 && process.ShouldSignalOnExit() && process.HasExited()) { + if (hos::GetVersion() < hos::Version_500 && process.ShouldSignalOnExit() && process.HasExited()) { out->event = GetProcessEventValue(ProcessEvent::Exited); out->process_id = process.GetProcessId(); return ResultSuccess; @@ -524,7 +524,7 @@ namespace sts::pm::impl { } /* Check for event from exited process. */ - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { + if (hos::GetVersion() >= hos::Version_500) { ProcessListAccessor dead_list(g_dead_process_list); if (!dead_list->empty()) { @@ -537,12 +537,12 @@ namespace sts::pm::impl { } } - out->process_id = 0; + out->process_id = os::ProcessId{}; out->event = GetProcessEventValue(ProcessEvent::None); return ResultSuccess; } - Result CleanupProcess(u64 process_id) { + Result CleanupProcess(os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -558,7 +558,7 @@ namespace sts::pm::impl { return ResultSuccess; } - Result ClearExceptionOccurred(u64 process_id) { + Result ClearExceptionOccurred(os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -577,7 +577,7 @@ namespace sts::pm::impl { return ResultSuccess; } - Result GetExceptionProcessIdList(u32 *out_count, u64 *out_process_ids, size_t max_out_count) { + Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count) { ProcessListAccessor list(g_process_list); size_t count = 0; @@ -590,7 +590,7 @@ namespace sts::pm::impl { return ResultSuccess; } - Result GetProcessId(u64 *out, ncm::TitleId title_id) { + Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(title_id); @@ -602,7 +602,7 @@ namespace sts::pm::impl { return ResultSuccess; } - Result GetTitleId(ncm::TitleId *out, u64 process_id) { + Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); @@ -614,7 +614,7 @@ namespace sts::pm::impl { return ResultSuccess; } - Result GetApplicationProcessId(u64 *out_process_id) { + Result GetApplicationProcessId(os::ProcessId *out_process_id) { ProcessListAccessor list(g_process_list); for (auto &process : *list) { @@ -627,7 +627,7 @@ namespace sts::pm::impl { return ResultPmProcessNotFound; } - Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, u64 process_id) { + Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) { ProcessListAccessor list(g_process_list); auto process_info = list->Find(process_id); diff --git a/stratosphere/pm/source/impl/pm_process_manager.hpp b/stratosphere/pm/source/impl/pm_process_manager.hpp index bc576da78..88d596105 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.hpp +++ b/stratosphere/pm/source/impl/pm_process_manager.hpp @@ -26,22 +26,22 @@ namespace sts::pm::impl { Result InitializeProcessManager(); /* Process Management. */ - Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 flags); - Result StartProcess(u64 process_id); - Result TerminateProcess(u64 process_id); + Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 flags); + Result StartProcess(os::ProcessId process_id); + Result TerminateProcess(os::ProcessId process_id); Result TerminateTitle(ncm::TitleId title_id); Result GetProcessEventHandle(Handle *out); Result GetProcessEventInfo(ProcessEventInfo *out); - Result CleanupProcess(u64 process_id); - Result ClearExceptionOccurred(u64 process_id); + Result CleanupProcess(os::ProcessId process_id); + Result ClearExceptionOccurred(os::ProcessId process_id); /* Information Getters. */ Result GetModuleIdList(u32 *out_count, u8 *out_buf, size_t max_out_count, u64 unused); - Result GetExceptionProcessIdList(u32 *out_count, u64 *out_process_ids, size_t max_out_count); - Result GetProcessId(u64 *out, ncm::TitleId title_id); - Result GetTitleId(ncm::TitleId *out, u64 process_id); - Result GetApplicationProcessId(u64 *out_process_id); - Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, u64 process_id); + Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count); + Result GetProcessId(os::ProcessId *out, ncm::TitleId title_id); + Result GetTitleId(ncm::TitleId *out, os::ProcessId process_id); + Result GetApplicationProcessId(os::ProcessId *out_process_id); + Result AtmosphereGetProcessInfo(Handle *out_process_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id); /* Hook API. */ Result HookToCreateProcess(Handle *out_hook, ncm::TitleId title_id); diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index f83529080..0ddbc6c19 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -182,9 +182,9 @@ namespace sts::pm::resource { } } - /* Adjust resource limits based on firmware version. */ - const auto firmware_version = GetRuntimeFirmwareVersion(); - if (firmware_version >= FirmwareVersion_400) { + /* Adjust resource limits based on hos firmware version. */ + const auto hos_version = hos::GetVersion(); + if (hos_version >= hos::Version_400) { /* 4.0.0 increased the system thread limit. */ g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] += ExtraSystemThreadCount400; /* 4.0.0 also took memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */ @@ -193,21 +193,21 @@ namespace sts::pm::resource { g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize400; g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400; } - if (firmware_version >= FirmwareVersion_500) { + if (hos_version >= hos::Version_500) { /* 5.0.0 took more memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */ g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize500; g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500; g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize500; g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500; } - if (firmware_version >= FirmwareVersion_600) { + if (hos_version >= hos::Version_600) { /* 6.0.0 increased the system event and session limits. */ g_resource_limits[ResourceLimitGroup_System][LimitableResource_Events] += ExtraSystemEventCount600; g_resource_limits[ResourceLimitGroup_System][LimitableResource_Sessions] += ExtraSystemSessionCount600; } /* 7.0.0+: Calculate the number of extra application threads available. */ - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_700) { + if (hos::GetVersion() >= hos::Version_700) { /* See how many threads we have available. */ u64 total_threads_available = 0; R_ASSERT(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads)); @@ -225,7 +225,7 @@ namespace sts::pm::resource { } /* Choose and initialize memory arrangement. */ - if (firmware_version >= FirmwareVersion_600) { + if (hos_version >= hos::Version_600) { /* 6.0.0 retrieves memory limit information from the kernel, rather than using a hardcoded profile. */ g_memory_arrangement = spl::MemoryArrangement_Dynamic; @@ -253,7 +253,7 @@ namespace sts::pm::resource { /* We take memory away from applet normally, but away from application on < 3.0.0 to avoid a rare hang on boot. */ for (size_t i = 0; i < spl::MemoryArrangement_Count; i++) { g_memory_resource_limits[i][ResourceLimitGroup_System] += ExtraSystemMemorySizeAtmosphere; - if (firmware_version >= FirmwareVersion_300) { + if (hos_version >= hos::Version_300) { g_memory_resource_limits[i][ResourceLimitGroup_Applet] -= ExtraSystemMemorySizeAtmosphere; } else { g_memory_resource_limits[i][ResourceLimitGroup_Application] -= ExtraSystemMemorySizeAtmosphere; @@ -282,7 +282,7 @@ namespace sts::pm::resource { { std::scoped_lock lk(g_resource_limit_lock); - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { + if (hos::GetVersion() >= hos::Version_500) { /* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */ if (boost_size < g_system_memory_boost_size) { R_TRY(svcSetUnsafeLimit(boost_size)); @@ -332,7 +332,7 @@ namespace sts::pm::resource { void WaitResourceAvailable(const ldr::ProgramInfo *info) { if (GetResourceLimitGroup(info) == ResourceLimitGroup_Application) { WaitResourceAvailable(ResourceLimitGroup_Application); - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { + if (hos::GetVersion() >= hos::Version_500) { WaitApplicationMemoryAvailable(); } } diff --git a/stratosphere/pm/source/pm_boot_mode_service.cpp b/stratosphere/pm/source/pm_boot_mode_service.cpp index 2af1af1e2..fd2731343 100644 --- a/stratosphere/pm/source/pm_boot_mode_service.cpp +++ b/stratosphere/pm/source/pm_boot_mode_service.cpp @@ -35,7 +35,7 @@ namespace sts::pm::bm { } /* Service command implementations. */ - void BootModeService::GetBootMode(Out out) { + void BootModeService::GetBootMode(sf::Out out) { out.SetValue(static_cast(pm::bm::GetBootMode())); } diff --git a/stratosphere/pm/source/pm_boot_mode_service.hpp b/stratosphere/pm/source/pm_boot_mode_service.hpp index b70cc2713..ecbe88f21 100644 --- a/stratosphere/pm/source/pm_boot_mode_service.hpp +++ b/stratosphere/pm/source/pm_boot_mode_service.hpp @@ -21,7 +21,7 @@ namespace sts::pm::bm { - class BootModeService final : public IServiceObject { + class BootModeService final : public sf::IServiceObject { private: enum class CommandId { GetBootMode = 0, @@ -29,12 +29,12 @@ namespace sts::pm::bm { }; private: /* Actual command implementations. */ - void GetBootMode(Out out); + void GetBootMode(sf::Out out); void SetMaintenanceBoot(); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(BootModeService, GetBootMode), - MAKE_SERVICE_COMMAND_META(BootModeService, SetMaintenanceBoot), + MAKE_SERVICE_COMMAND_META(GetBootMode), + MAKE_SERVICE_COMMAND_META(SetMaintenanceBoot), }; }; diff --git a/stratosphere/pm/source/pm_debug_monitor_service.cpp b/stratosphere/pm/source/pm_debug_monitor_service.cpp index af4c6fa82..9b26969c1 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.cpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.cpp @@ -21,37 +21,37 @@ namespace sts::pm::dmnt { /* Actual command implementations. */ - Result DebugMonitorServiceBase::GetModuleIdList(Out out_count, OutBuffer out_buf, u64 unused) { - if (out_buf.num_elements > std::numeric_limits::max()) { + Result DebugMonitorServiceBase::GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused) { + if (out_buf.GetSize() > std::numeric_limits::max()) { return ResultPmInvalidSize; } - return impl::GetModuleIdList(out_count.GetPointer(), out_buf.buffer, out_buf.num_elements, unused); + return impl::GetModuleIdList(out_count.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), unused); } - Result DebugMonitorServiceBase::GetExceptionProcessIdList(Out out_count, OutBuffer out_process_ids) { - if (out_process_ids.num_elements > std::numeric_limits::max()) { + Result DebugMonitorServiceBase::GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids) { + if (out_process_ids.GetSize() > std::numeric_limits::max()) { return ResultPmInvalidSize; } - return impl::GetExceptionProcessIdList(out_count.GetPointer(), out_process_ids.buffer, out_process_ids.num_elements); + return impl::GetExceptionProcessIdList(out_count.GetPointer(), out_process_ids.GetPointer(), out_process_ids.GetSize()); } - Result DebugMonitorServiceBase::StartProcess(u64 process_id) { + Result DebugMonitorServiceBase::StartProcess(os::ProcessId process_id) { return impl::StartProcess(process_id); } - Result DebugMonitorServiceBase::GetProcessId(Out out, ncm::TitleId title_id) { + Result DebugMonitorServiceBase::GetProcessId(sf::Out out, ncm::TitleId title_id) { return impl::GetProcessId(out.GetPointer(), title_id); } - Result DebugMonitorServiceBase::HookToCreateProcess(Out out_hook, ncm::TitleId title_id) { + Result DebugMonitorServiceBase::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::TitleId title_id) { return impl::HookToCreateProcess(out_hook.GetHandlePointer(), title_id); } - Result DebugMonitorServiceBase::GetApplicationProcessId(Out out) { + Result DebugMonitorServiceBase::GetApplicationProcessId(sf::Out out) { return impl::GetApplicationProcessId(out.GetPointer()); } - Result DebugMonitorServiceBase::HookToCreateApplicationProcess(Out out_hook) { + Result DebugMonitorServiceBase::HookToCreateApplicationProcess(sf::OutCopyHandle out_hook) { return impl::HookToCreateApplicationProcess(out_hook.GetHandlePointer()); } @@ -60,11 +60,11 @@ namespace sts::pm::dmnt { } /* Atmosphere extension commands. */ - Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(Out out_process_handle, Out out_loc, u64 process_id) { + 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::AtmosphereGetCurrentLimitInfo(Out out_cur_val, Out out_lim_val, u32 group, u32 resource) { + Result DebugMonitorServiceBase::AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource) { return impl::AtmosphereGetCurrentLimitInfo(out_cur_val.GetPointer(), out_lim_val.GetPointer(), group, resource); } diff --git a/stratosphere/pm/source/pm_debug_monitor_service.hpp b/stratosphere/pm/source/pm_debug_monitor_service.hpp index edd125b40..9ebce6375 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.hpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.hpp @@ -22,25 +22,21 @@ namespace sts::pm::dmnt { - class DebugMonitorServiceBase : public IServiceObject { + class DebugMonitorServiceBase : public sf::IServiceObject { protected: /* Actual command implementations. */ - virtual Result GetModuleIdList(Out out_count, OutBuffer out_buf, u64 unused); - virtual Result GetExceptionProcessIdList(Out out_count, OutBuffer out_process_ids); - virtual Result StartProcess(u64 process_id); - virtual Result GetProcessId(Out out, ncm::TitleId title_id); - virtual Result HookToCreateProcess(Out out_hook, ncm::TitleId title_id); - virtual Result GetApplicationProcessId(Out out); - virtual Result HookToCreateApplicationProcess(Out out_hook); + virtual Result GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused); + virtual Result GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids); + virtual Result StartProcess(os::ProcessId process_id); + virtual Result GetProcessId(sf::Out out, ncm::TitleId title_id); + virtual Result HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::TitleId title_id); + virtual Result GetApplicationProcessId(sf::Out out); + virtual Result HookToCreateApplicationProcess(sf::OutCopyHandle out_hook); virtual Result ClearHook(u32 which); /* Atmosphere extension commands. */ - virtual Result AtmosphereGetProcessInfo(Out out_process_handle, Out out_loc, u64 process_id); - virtual Result AtmosphereGetCurrentLimitInfo(Out out_cur_val, Out out_lim_val, u32 group, u32 resource); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* No entries, because DebugMonitorServiceBase is abstract. */ - }; + virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, os::ProcessId process_id); + virtual Result AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource); }; /* This represents modern DebugMonitorService (5.0.0+). */ @@ -62,19 +58,19 @@ namespace sts::pm::dmnt { public: DEFINE_SERVICE_DISPATCH_TABLE { /* 5.0.0-* */ - MAKE_SERVICE_COMMAND_META(DebugMonitorService, GetExceptionProcessIdList), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, StartProcess), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, GetProcessId), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, HookToCreateProcess), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, GetApplicationProcessId), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, HookToCreateApplicationProcess), + MAKE_SERVICE_COMMAND_META(GetExceptionProcessIdList), + MAKE_SERVICE_COMMAND_META(StartProcess), + MAKE_SERVICE_COMMAND_META(GetProcessId), + MAKE_SERVICE_COMMAND_META(HookToCreateProcess), + MAKE_SERVICE_COMMAND_META(GetApplicationProcessId), + MAKE_SERVICE_COMMAND_META(HookToCreateApplicationProcess), /* 6.0.0-* */ - MAKE_SERVICE_COMMAND_META(DebugMonitorService, ClearHook, FirmwareVersion_600), + MAKE_SERVICE_COMMAND_META(ClearHook, hos::Version_600), /* Atmosphere extensions. */ - MAKE_SERVICE_COMMAND_META(DebugMonitorService, AtmosphereGetProcessInfo), - MAKE_SERVICE_COMMAND_META(DebugMonitorService, AtmosphereGetCurrentLimitInfo), + MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), + MAKE_SERVICE_COMMAND_META(AtmosphereGetCurrentLimitInfo), }; }; @@ -96,17 +92,17 @@ namespace sts::pm::dmnt { public: DEFINE_SERVICE_DISPATCH_TABLE { /* 1.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, GetModuleIdList), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, GetExceptionProcessIdList), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, StartProcess), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, GetProcessId), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, HookToCreateProcess), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, GetApplicationProcessId), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, HookToCreateApplicationProcess), + MAKE_SERVICE_COMMAND_META(GetModuleIdList), + MAKE_SERVICE_COMMAND_META(GetExceptionProcessIdList), + MAKE_SERVICE_COMMAND_META(StartProcess), + MAKE_SERVICE_COMMAND_META(GetProcessId), + MAKE_SERVICE_COMMAND_META(HookToCreateProcess), + MAKE_SERVICE_COMMAND_META(GetApplicationProcessId), + MAKE_SERVICE_COMMAND_META(HookToCreateApplicationProcess), /* Atmosphere extensions. */ - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, AtmosphereGetProcessInfo), - MAKE_SERVICE_COMMAND_META(DebugMonitorServiceDeprecated, AtmosphereGetCurrentLimitInfo), + MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), + MAKE_SERVICE_COMMAND_META(AtmosphereGetCurrentLimitInfo), }; }; diff --git a/stratosphere/pm/source/pm_info_service.cpp b/stratosphere/pm/source/pm_info_service.cpp index 7d1b98d3d..f21428aaa 100644 --- a/stratosphere/pm/source/pm_info_service.cpp +++ b/stratosphere/pm/source/pm_info_service.cpp @@ -28,16 +28,16 @@ namespace sts::pm::info { } /* Actual command implementations. */ - Result InformationService::GetTitleId(Out out, u64 process_id) { + Result InformationService::GetTitleId(sf::Out out, os::ProcessId process_id) { return impl::GetTitleId(out.GetPointer(), process_id); } /* Atmosphere extension commands. */ - Result InformationService::AtmosphereGetProcessId(Out out, ncm::TitleId title_id) { + Result InformationService::AtmosphereGetProcessId(sf::Out out, ncm::TitleId title_id) { return impl::GetProcessId(out.GetPointer(), title_id); } - Result InformationService::AtmosphereHasLaunchedTitle(Out out, ncm::TitleId title_id) { + Result InformationService::AtmosphereHasLaunchedTitle(sf::Out out, ncm::TitleId title_id) { return pm::info::HasLaunchedTitle(out.GetPointer(), title_id); } diff --git a/stratosphere/pm/source/pm_info_service.hpp b/stratosphere/pm/source/pm_info_service.hpp index 51e0d4f20..0133e785f 100644 --- a/stratosphere/pm/source/pm_info_service.hpp +++ b/stratosphere/pm/source/pm_info_service.hpp @@ -22,7 +22,7 @@ namespace sts::pm::info { - class InformationService final : public IServiceObject { + class InformationService final : public sf::IServiceObject { private: enum class CommandId { GetTitleId = 0, @@ -32,17 +32,17 @@ namespace sts::pm::info { }; private: /* Actual command implementations. */ - Result GetTitleId(Out out, u64 process_id); + Result GetTitleId(sf::Out out, os::ProcessId process_id); /* Atmosphere extension commands. */ - Result AtmosphereGetProcessId(Out out, ncm::TitleId title_id); - Result AtmosphereHasLaunchedTitle(Out out, ncm::TitleId title_id); + Result AtmosphereGetProcessId(sf::Out out, ncm::TitleId title_id); + Result AtmosphereHasLaunchedTitle(sf::Out out, ncm::TitleId title_id); public: DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(InformationService, GetTitleId), + MAKE_SERVICE_COMMAND_META(GetTitleId), - MAKE_SERVICE_COMMAND_META(InformationService, AtmosphereGetProcessId), - MAKE_SERVICE_COMMAND_META(InformationService, AtmosphereHasLaunchedTitle), + MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessId), + MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedTitle), }; }; diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 7a35aec8c..608445755 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -36,6 +35,7 @@ extern "C" { extern u32 __start__; u32 __nx_applet_type = AppletType_None; + u32 __nx_fs_num_sessions = 1; #define INNER_HEAP_SIZE 0x40000 size_t nx_inner_heap_size = INNER_HEAP_SIZE; @@ -70,6 +70,8 @@ void __libnx_initheap(void) { fake_heap_end = (char*)addr + size; } +using namespace sts; + namespace { constexpr u32 PrivilegedFileAccessHeader[0x1C / sizeof(u32)] = {0x00000001, 0x00000000, 0x80000000, 0x0000001C, 0x00000000, 0x0000001C, 0x00000000}; @@ -78,22 +80,22 @@ namespace { constexpr size_t ProcessCountMax = 0x40; /* This uses debugging SVCs to retrieve a process's title id. */ - sts::ncm::TitleId GetProcessTitleId(u64 process_id) { + ncm::TitleId GetProcessTitleId(os::ProcessId process_id) { /* Check if we should return our title id. */ /* Doing this here works around a bug fixed in 6.0.0. */ /* Not doing so will cause svcDebugActiveProcess to deadlock on lower firmwares if called for it's own process. */ - u64 current_process_id = 0; - R_ASSERT(svcGetProcessId(¤t_process_id, CUR_PROCESS_HANDLE)); + os::ProcessId current_process_id = os::InvalidProcessId; + R_ASSERT(svcGetProcessId(¤t_process_id.value, CUR_PROCESS_HANDLE)); if (current_process_id == process_id) { return __stratosphere_title_id; } /* Get a debug handle. */ - sts::os::ManagedHandle debug_handle; - R_ASSERT(svcDebugActiveProcess(debug_handle.GetPointer(), process_id)); + os::ManagedHandle debug_handle; + R_ASSERT(svcDebugActiveProcess(debug_handle.GetPointer(), static_cast(process_id))); /* Loop until we get the event that tells us about the process. */ - sts::svc::DebugEventInfo d; + svc::DebugEventInfo d; while (true) { R_ASSERT(svcGetDebugEvent(reinterpret_cast(&d), debug_handle.Get())); if (d.type == sts::svc::DebugEventType::AttachProcess) { @@ -105,22 +107,22 @@ namespace { /* This works around a bug fixed by FS in 4.0.0. */ /* Not doing so will cause KIPs with higher process IDs than 7 to be unable to use filesystem services. */ /* It also registers privileged processes with SM, so that their title IDs can be known. */ - void RegisterPrivilegedProcess(u64 process_id) { - fsprUnregisterProgram(process_id); - fsprRegisterProgram(process_id, process_id, FsStorageId_NandSystem, PrivilegedFileAccessHeader, sizeof(PrivilegedFileAccessHeader), PrivilegedFileAccessControl, sizeof(PrivilegedFileAccessControl)); + void RegisterPrivilegedProcess(os::ProcessId process_id) { + fsprUnregisterProgram(static_cast(process_id)); + fsprRegisterProgram(static_cast(process_id), static_cast(process_id), FsStorageId_NandSystem, PrivilegedFileAccessHeader, sizeof(PrivilegedFileAccessHeader), PrivilegedFileAccessControl, sizeof(PrivilegedFileAccessControl)); sts::sm::manager::UnregisterProcess(process_id); sts::sm::manager::RegisterProcess(process_id, GetProcessTitleId(process_id), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl), PrivilegedServiceAccessControl, sizeof(PrivilegedServiceAccessControl)); } void RegisterPrivilegedProcesses() { /* Get privileged process range. */ - u64 min_priv_process_id = 0, max_priv_process_id = 0; + os::ProcessId min_priv_process_id = os::InvalidProcessId, max_priv_process_id = os::InvalidProcessId; sts::cfg::GetInitialProcessRange(&min_priv_process_id, &max_priv_process_id); /* Get list of processes, register all privileged ones. */ u32 num_pids; - u64 pids[ProcessCountMax]; - R_ASSERT(svcGetProcessList(&num_pids, pids, ProcessCountMax)); + os::ProcessId pids[ProcessCountMax]; + R_ASSERT(svcGetProcessList(&num_pids, reinterpret_cast(pids), ProcessCountMax)); for (size_t i = 0; i < num_pids; i++) { if (min_priv_process_id <= pids[i] && pids[i] <= max_priv_process_id) { RegisterPrivilegedProcess(pids[i]); @@ -131,7 +133,7 @@ namespace { } void __appInit(void) { - SetFirmwareVersionForLibnx(); + hos::SetVersionForLibnx(); DoWithSmSession([&]() { R_ASSERT(fsprInitialize()); @@ -164,29 +166,52 @@ void __appExit(void) { fsprExit(); } +namespace { + + using ServerOptions = sf::hipc::DefaultServerManagerOptions; + + constexpr sm::ServiceName ShellServiceName = sm::ServiceName::Encode("pm:shell"); + constexpr size_t ShellMaxSessions = 3; + + constexpr sm::ServiceName DebugMonitorServiceName = sm::ServiceName::Encode("pm:dmnt"); + constexpr size_t DebugMonitorMaxSessions = 3; + + constexpr sm::ServiceName BootModeServiceName = sm::ServiceName::Encode("pm:bm"); + constexpr size_t BootModeMaxSessions = 6; + + constexpr sm::ServiceName InformationServiceName = sm::ServiceName::Encode("pm:info"); + constexpr size_t InformationMaxSessions = 32 - (ShellMaxSessions + DebugMonitorMaxSessions + BootModeMaxSessions); + + static_assert(InformationMaxSessions >= 16, "InformationMaxSessions"); + + /* pm:shell, pm:dmnt, pm:bm, pm:info. */ + constexpr size_t NumServers = 4; + constexpr size_t MaxSessions = ShellMaxSessions + DebugMonitorMaxSessions + BootModeMaxSessions + InformationMaxSessions; + static_assert(MaxSessions == 32, "MaxSessions"); + sf::hipc::ServerManager g_server_manager; + +} + int main(int argc, char **argv) { /* Initialize process manager implementation. */ R_ASSERT(sts::pm::impl::InitializeProcessManager()); - /* Create Server Manager. */ - static auto s_server_manager = WaitableManager(1); - /* Create Services. */ /* NOTE: Extra sessions have been added to pm:bm and pm:info to facilitate access by the rest of stratosphere. */ /* Also Note: PM was rewritten in 5.0.0, so the shell and dmnt services are different before/after. */ - if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { - s_server_manager.AddWaitable(new ServiceServer("pm:shell", 3)); - s_server_manager.AddWaitable(new ServiceServer("pm:dmnt", 3)); + if (hos::GetVersion() >= hos::Version_500) { + R_ASSERT((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } else { - s_server_manager.AddWaitable(new ServiceServer("pm:shell", 3)); - s_server_manager.AddWaitable(new ServiceServer("pm:dmnt", 3)); + R_ASSERT((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } - s_server_manager.AddWaitable(new ServiceServer("pm:bm", 6)); - s_server_manager.AddWaitable(new ServiceServer("pm:info", 19)); + R_ASSERT((g_server_manager.RegisterServer(BootModeServiceName, BootModeMaxSessions))); + R_ASSERT((g_server_manager.RegisterServer(InformationServiceName, InformationMaxSessions))); /* Loop forever, servicing our services. */ - s_server_manager.Process(); + g_server_manager.LoopProcess(); return 0; } diff --git a/stratosphere/pm/source/pm_shell_service.cpp b/stratosphere/pm/source/pm_shell_service.cpp index 8a59c3f52..7f48309ec 100644 --- a/stratosphere/pm/source/pm_shell_service.cpp +++ b/stratosphere/pm/source/pm_shell_service.cpp @@ -20,16 +20,16 @@ namespace sts::pm::shell { /* Overrides for libstratosphere pm::shell commands. */ - Result LaunchTitle(u64 *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { + Result LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) { return impl::LaunchTitle(out_process_id, loc, launch_flags); } /* Service command implementations. */ - Result ShellServiceBase::LaunchTitle(Out out_process_id, ncm::TitleLocation loc, u32 flags) { + Result ShellServiceBase::LaunchTitle(sf::Out out_process_id, const ncm::TitleLocation &loc, u32 flags) { return pm::shell::LaunchTitle(out_process_id.GetPointer(), loc, flags); } - Result ShellServiceBase::TerminateProcess(u64 process_id) { + Result ShellServiceBase::TerminateProcess(os::ProcessId process_id) { return impl::TerminateProcess(process_id); } @@ -37,19 +37,19 @@ namespace sts::pm::shell { return impl::TerminateTitle(title_id); } - void ShellServiceBase::GetProcessEventHandle(Out out) { + void ShellServiceBase::GetProcessEventHandle(sf::OutCopyHandle out) { R_ASSERT(impl::GetProcessEventHandle(out.GetHandlePointer())); } - void ShellServiceBase::GetProcessEventInfo(Out out) { + void ShellServiceBase::GetProcessEventInfo(sf::Out out) { R_ASSERT(impl::GetProcessEventInfo(out.GetPointer())); } - Result ShellServiceBase::CleanupProcess(u64 process_id) { + Result ShellServiceBase::CleanupProcess(os::ProcessId process_id) { return impl::CleanupProcess(process_id); } - Result ShellServiceBase::ClearExceptionOccurred(u64 process_id) { + Result ShellServiceBase::ClearExceptionOccurred(os::ProcessId process_id) { return impl::ClearExceptionOccurred(process_id); } @@ -57,7 +57,7 @@ namespace sts::pm::shell { R_ASSERT(impl::NotifyBootFinished()); } - Result ShellServiceBase::GetApplicationProcessIdForShell(Out out) { + Result ShellServiceBase::GetApplicationProcessIdForShell(sf::Out out) { return impl::GetApplicationProcessId(out.GetPointer()); } @@ -69,7 +69,7 @@ namespace sts::pm::shell { return impl::BoostApplicationThreadResourceLimit(); } - void ShellServiceBase::GetBootFinishedEventHandle(Out out) { + void ShellServiceBase::GetBootFinishedEventHandle(sf::OutCopyHandle out) { R_ASSERT(impl::GetBootFinishedEventHandle(out.GetHandlePointer())); } diff --git a/stratosphere/pm/source/pm_shell_service.hpp b/stratosphere/pm/source/pm_shell_service.hpp index cca6f2a1e..2a6010090 100644 --- a/stratosphere/pm/source/pm_shell_service.hpp +++ b/stratosphere/pm/source/pm_shell_service.hpp @@ -22,25 +22,21 @@ namespace sts::pm::shell { - class ShellServiceBase : public IServiceObject { + class ShellServiceBase : public sf::IServiceObject { protected: /* Actual command implementations. */ - virtual Result LaunchTitle(Out out_process_id, ncm::TitleLocation loc, u32 flags); - virtual Result TerminateProcess(u64 process_id); + virtual Result LaunchTitle(sf::Out out_process_id, const ncm::TitleLocation &loc, u32 flags); + virtual Result TerminateProcess(os::ProcessId process_id); virtual Result TerminateTitle(ncm::TitleId title_id); - virtual void GetProcessEventHandle(Out out); - virtual void GetProcessEventInfo(Out out); - virtual Result CleanupProcess(u64 process_id); - virtual Result ClearExceptionOccurred(u64 process_id); + virtual void GetProcessEventHandle(sf::OutCopyHandle out); + virtual void GetProcessEventInfo(sf::Out out); + virtual Result CleanupProcess(os::ProcessId process_id); + virtual Result ClearExceptionOccurred(os::ProcessId process_id); virtual void NotifyBootFinished(); - virtual Result GetApplicationProcessIdForShell(Out out); + virtual Result GetApplicationProcessIdForShell(sf::Out out); virtual Result BoostSystemMemoryResourceLimit(u64 boost_size); virtual Result BoostApplicationThreadResourceLimit(); - virtual void GetBootFinishedEventHandle(Out out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* No entries, because ShellServiceBase is abstract. */ - }; + virtual void GetBootFinishedEventHandle(sf::OutCopyHandle out); }; /* This represents modern ShellService (5.0.0+). */ @@ -61,20 +57,20 @@ namespace sts::pm::shell { public: DEFINE_SERVICE_DISPATCH_TABLE { /* 5.0.0-* */ - MAKE_SERVICE_COMMAND_META(ShellService, LaunchTitle), - MAKE_SERVICE_COMMAND_META(ShellService, TerminateProcess), - MAKE_SERVICE_COMMAND_META(ShellService, TerminateTitle), - MAKE_SERVICE_COMMAND_META(ShellService, GetProcessEventHandle), - MAKE_SERVICE_COMMAND_META(ShellService, GetProcessEventInfo), - MAKE_SERVICE_COMMAND_META(ShellService, NotifyBootFinished), - MAKE_SERVICE_COMMAND_META(ShellService, GetApplicationProcessIdForShell), - MAKE_SERVICE_COMMAND_META(ShellService, BoostSystemMemoryResourceLimit), + MAKE_SERVICE_COMMAND_META(LaunchTitle), + MAKE_SERVICE_COMMAND_META(TerminateProcess), + MAKE_SERVICE_COMMAND_META(TerminateTitle), + MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), + MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), + MAKE_SERVICE_COMMAND_META(NotifyBootFinished), + MAKE_SERVICE_COMMAND_META(GetApplicationProcessIdForShell), + MAKE_SERVICE_COMMAND_META(BoostSystemMemoryResourceLimit), /* 7.0.0-* */ - MAKE_SERVICE_COMMAND_META(ShellService, BoostApplicationThreadResourceLimit, FirmwareVersion_700), + MAKE_SERVICE_COMMAND_META(BoostApplicationThreadResourceLimit, hos::Version_700), /* 8.0.0-* */ - MAKE_SERVICE_COMMAND_META(ShellService, GetBootFinishedEventHandle, FirmwareVersion_800), + MAKE_SERVICE_COMMAND_META(GetBootFinishedEventHandle, hos::Version_800), }; }; @@ -96,18 +92,18 @@ namespace sts::pm::shell { public: DEFINE_SERVICE_DISPATCH_TABLE { /* 1.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, LaunchTitle), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, TerminateProcess), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, TerminateTitle), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, GetProcessEventHandle), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, GetProcessEventInfo), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, CleanupProcess), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, ClearExceptionOccurred), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, NotifyBootFinished), - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, GetApplicationProcessIdForShell), + MAKE_SERVICE_COMMAND_META(LaunchTitle), + MAKE_SERVICE_COMMAND_META(TerminateProcess), + MAKE_SERVICE_COMMAND_META(TerminateTitle), + MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), + MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), + MAKE_SERVICE_COMMAND_META(CleanupProcess), + MAKE_SERVICE_COMMAND_META(ClearExceptionOccurred), + MAKE_SERVICE_COMMAND_META(NotifyBootFinished), + MAKE_SERVICE_COMMAND_META(GetApplicationProcessIdForShell), /* 4.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(ShellServiceDeprecated, BoostSystemMemoryResourceLimit), + MAKE_SERVICE_COMMAND_META(BoostSystemMemoryResourceLimit, hos::Version_400), }; };