From e05df993422abcd5709017bd1ebea98bb42afa0d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 21 Mar 2022 23:52:16 -0700 Subject: [PATCH] pm/kern: update for 14.0.0 --- .../mesosphere/kern_k_memory_layout.hpp | 4 +- .../source/init/kern_init_slab_setup.cpp | 2 +- .../pm/impl/pm_debug_monitor_interface.hpp | 2 + .../pm/impl/pm_information_interface.hpp | 12 +- .../pm/impl/pm_shell_interface.hpp | 23 ++-- .../include/stratosphere/pm/pm_dmnt_api.hpp | 1 + .../include/stratosphere/pm/pm_info_api.hpp | 3 + .../include/stratosphere/pm/pm_shell_api.hpp | 1 + .../include/stratosphere/pm/pm_types.hpp | 8 ++ .../libstratosphere/source/pm/pm_dmnt_api.cpp | 6 + .../libstratosphere/source/pm/pm_info_api.cpp | 12 ++ .../source/pm/pm_shell_api.cpp | 5 + .../pm/source/impl/pm_process_manager.cpp | 72 ++++++----- .../pm/source/impl/pm_process_manager.hpp | 3 + .../pm/source/impl/pm_resource_manager.cpp | 117 +++++++++++++++--- .../pm/source/impl/pm_resource_manager.hpp | 5 + .../pm/source/pm_debug_monitor_service.cpp | 24 ++-- .../pm/source/pm_debug_monitor_service.hpp | 1 + stratosphere/pm/source/pm_info_service.cpp | 18 ++- stratosphere/pm/source/pm_info_service.hpp | 2 + stratosphere/pm/source/pm_main.cpp | 12 +- stratosphere/pm/source/pm_shell_service.cpp | 22 ++-- stratosphere/pm/source/pm_shell_service.hpp | 1 + 23 files changed, 260 insertions(+), 96 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp index 34d3d2e6a..e451b9622 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp @@ -49,8 +49,8 @@ namespace ams::kern { constexpr size_t KernelSlabHeapGapsSizeMax = 2_MB - 64_KB; constexpr size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSizeMax; - /* NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. */ - constexpr size_t KernelSlabHeapAdditionalSize = 0x68000; + /* NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x800. */ + constexpr size_t KernelSlabHeapAdditionalSize = 0x148000; constexpr size_t KernelResourceSize = KernelPageTableHeapSize + KernelInitialPageHeapSize + KernelSlabHeapSize; diff --git a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp index 781df17f1..031260817 100644 --- a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp +++ b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp @@ -72,7 +72,7 @@ namespace ams::kern::init { constexpr size_t SlabCountKIoPool = 1; constexpr size_t SlabCountKIoRegion = 6; - constexpr size_t SlabCountExtraKThread = 160; + constexpr size_t SlabCountExtraKThread = (1024 + 256 + 256) - SlabCountKThread; namespace test { diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp index 08e899d79..e6555f7ff 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp @@ -27,6 +27,7 @@ AMS_SF_METHOD_INFO(C, H, 4, Result, GetApplicationProcessId, (sf::Out out), (out)) \ AMS_SF_METHOD_INFO(C, H, 5, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook), (out_hook)) \ AMS_SF_METHOD_INFO(C, H, 6, Result, ClearHook, (u32 which), (which), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetProgramId, (sf::Out out, os::ProcessId process_id), (out, process_id)) \ AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessInfo, (sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id), (out_process_handle, out_loc, out_status, process_id)) \ AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetCurrentLimitInfo, (sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource), (out_cur_val, out_lim_val, group, resource)) @@ -40,6 +41,7 @@ AMS_SF_DEFINE_INTERFACE(ams::pm::impl, IDebugMonitorInterface, AMS_PM_I_DEBUG_MO AMS_SF_METHOD_INFO(C, H, 4, Result, HookToCreateProcess, (sf::OutCopyHandle out_hook, ncm::ProgramId program_id), (out_hook, program_id)) \ AMS_SF_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (sf::Out out), (out)) \ AMS_SF_METHOD_INFO(C, H, 6, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook), (out_hook)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetProgramId, (sf::Out out, os::ProcessId process_id), (out, process_id)) \ AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessInfo, (sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id), (out_process_handle, out_loc, out_status, process_id)) \ AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetCurrentLimitInfo, (sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource), (out_cur_val, out_lim_val, group, resource)) diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp index 23c7065c3..7a28ff575 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp @@ -19,10 +19,12 @@ #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, 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)) +#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, 1, Result, GetAppletCurrentResourceLimitValues, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetAppletPeakResourceLimitValues, (sf::Out out), (out)) \ + 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/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp index 5bd0dc95b..45684f8f8 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp @@ -19,17 +19,18 @@ #include #include -#define AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, LaunchProgram, (sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags), (out_process_id, loc, flags)) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id), (program_id)) \ - AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out), (out)) \ - AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out), (out)) \ - AMS_SF_METHOD_INFO(C, H, 5, void, NotifyBootFinished, (), ()) \ - AMS_SF_METHOD_INFO(C, H, 6, Result, GetApplicationProcessIdForShell, (sf::Out out), (out)) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, BoostSystemMemoryResourceLimit, (u64 boost_size), (boost_size)) \ - AMS_SF_METHOD_INFO(C, H, 8, Result, BoostApplicationThreadResourceLimit, (), (), hos::Version_7_0_0) \ - AMS_SF_METHOD_INFO(C, H, 9, void, GetBootFinishedEventHandle, (sf::OutCopyHandle out), (out), hos::Version_8_0_0) +#define AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, LaunchProgram, (sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags), (out_process_id, loc, flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id), (program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, void, NotifyBootFinished, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetApplicationProcessIdForShell, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, BoostSystemMemoryResourceLimit, (u64 boost_size), (boost_size)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, BoostApplicationThreadResourceLimit, (), (), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 9, void, GetBootFinishedEventHandle, (sf::OutCopyHandle out), (out), hos::Version_8_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, BoostSystemThreadResourceLimit, (), ()) AMS_SF_DEFINE_INTERFACE(ams::pm::impl, IShellInterface, AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp index 78cbbdc27..7a896ae66 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_dmnt_api.hpp @@ -24,6 +24,7 @@ namespace ams::pm::dmnt { /* Debug Monitor API. */ Result StartProcess(os::ProcessId process_id); + Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id); Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id); Result GetApplicationProcessId(os::ProcessId *out_process_id); Result HookToCreateApplicationProcess(os::NativeHandle *out_handle); diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_info_api.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_info_api.hpp index f18226c79..c771eb33f 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_info_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_info_api.hpp @@ -29,6 +29,9 @@ namespace ams::pm::info { Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id); Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id); + Result GetAppletCurrentResourceLimitValues(pm::ResourceLimitValues *out); + Result GetAppletPeakResourceLimitValues(pm::ResourceLimitValues *out); + Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id); /* Information convenience API. */ diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp index cbcd2043a..6e215222d 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_shell_api.hpp @@ -30,5 +30,6 @@ namespace ams::pm::shell { Result GetApplicationProcessIdForShell(os::ProcessId *out); Result BoostSystemMemoryResourceLimit(u64 size); Result EnableApplicationExtraThread(); + Result EnableSystemExtraThread(); } diff --git a/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp b/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp index d61f96304..9266302fc 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/pm_types.hpp @@ -52,6 +52,14 @@ namespace ams::pm { LaunchFlagsDeprecated_SignalOnStart = (1 << 5), }; + struct ResourceLimitValues { + u64 physical_memory; + u32 thread_count; + u32 event_count; + u32 transfer_memory_count; + u32 session_count; + }; + constexpr inline u32 LaunchFlagsMask = (1 << 6) - 1; enum class ProcessEvent : u32 { diff --git a/libraries/libstratosphere/source/pm/pm_dmnt_api.cpp b/libraries/libstratosphere/source/pm/pm_dmnt_api.cpp index 2f1b29353..e72ed069e 100644 --- a/libraries/libstratosphere/source/pm/pm_dmnt_api.cpp +++ b/libraries/libstratosphere/source/pm/pm_dmnt_api.cpp @@ -25,6 +25,12 @@ namespace ams::pm::dmnt { return pmdmntStartProcess(static_cast(process_id)); } + Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id) { + /* TODO: return return pmdmntGetProgramId(reinterpret_cast(out_program_id), static_cast(process_id)); */ + AMS_UNUSED(out_program_id, process_id); + AMS_ABORT("TODO"); + } + Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id) { return pmdmntGetProcessId(reinterpret_cast(out_process_id), static_cast(program_id)); } diff --git a/libraries/libstratosphere/source/pm/pm_info_api.cpp b/libraries/libstratosphere/source/pm/pm_info_api.cpp index 978defda2..44c039eba 100644 --- a/libraries/libstratosphere/source/pm/pm_info_api.cpp +++ b/libraries/libstratosphere/source/pm/pm_info_api.cpp @@ -28,6 +28,18 @@ namespace ams::pm::info { return pminfoAtmosphereGetProcessId(reinterpret_cast(out_process_id), static_cast(program_id)); } + Result GetAppletCurrentResourceLimitValues(pm::ResourceLimitValues *out) { + /* TODO: return pminfoGetAppletCurrentResourceLimitValues(reinterpret_cast(out)); */ + AMS_UNUSED(out); + AMS_ABORT("TODO"); + } + + Result GetAppletPeakResourceLimitValues(pm::ResourceLimitValues *out) { + /* TODO: return pminfoGetAppletPeakResourceLimitValues(reinterpret_cast(out)); */ + AMS_UNUSED(out); + AMS_ABORT("TODO"); + } + Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { *out_loc = {}; *out_status = {}; diff --git a/libraries/libstratosphere/source/pm/pm_shell_api.cpp b/libraries/libstratosphere/source/pm/pm_shell_api.cpp index 7dc4f2d9e..dbee04e91 100644 --- a/libraries/libstratosphere/source/pm/pm_shell_api.cpp +++ b/libraries/libstratosphere/source/pm/pm_shell_api.cpp @@ -55,4 +55,9 @@ namespace ams::pm::shell { } #endif + Result EnableSystemExtraThread() { + /* TODO: return ::pmshellEnableSystemExtraThread(); */ + AMS_ABORT("TODO"); + } + } diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 2da99fdef..2f2d1b89a 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -209,7 +209,7 @@ namespace ams::pm::impl { Result StartProcess(ProcessInfo *process_info, const ldr::ProgramInfo *program_info) { R_TRY(svc::StartProcess(process_info->GetHandle(), program_info->main_thread_priority, program_info->default_cpu_id, program_info->main_thread_stack_size)); process_info->SetState(svc::ProcessState_Running); - return ResultSuccess(); + R_SUCCEED(); } void CleanupProcessInfo(ProcessListAccessor &list, ProcessInfo *process_info) { @@ -416,7 +416,7 @@ namespace ams::pm::impl { /* Start thread. */ os::StartThread(std::addressof(g_process_track_thread)); - return ResultSuccess(); + R_SUCCEED(); } /* Process Management. */ @@ -433,7 +433,7 @@ namespace ams::pm::impl { g_process_launch_start_event.Signal(); g_process_launch_finish_event.Wait(); - return g_process_launch_result; + R_RETURN(g_process_launch_result); } Result StartProcess(os::ProcessId process_id) { @@ -445,7 +445,7 @@ namespace ams::pm::impl { ldr::ProgramInfo program_info; R_TRY(ldr::pm::GetProgramInfo(std::addressof(program_info), process_info->GetProgramLocation())); - return StartProcess(process_info, std::addressof(program_info)); + R_RETURN(StartProcess(process_info, std::addressof(program_info))); } Result TerminateProcess(os::ProcessId process_id) { @@ -454,7 +454,7 @@ namespace ams::pm::impl { auto process_info = list->Find(process_id); R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); - return svc::TerminateProcess(process_info->GetHandle()); + R_RETURN(svc::TerminateProcess(process_info->GetHandle())); } Result TerminateProgram(ncm::ProgramId program_id) { @@ -463,12 +463,12 @@ namespace ams::pm::impl { auto process_info = list->Find(program_id); R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); - return svc::TerminateProcess(process_info->GetHandle()); + R_RETURN(svc::TerminateProcess(process_info->GetHandle())); } Result GetProcessEventHandle(os::NativeHandle *out) { *out = os::GetReadableHandleOfSystemEvent(std::addressof(g_process_event)); - return ResultSuccess(); + R_SUCCEED(); } Result GetProcessEventInfo(ProcessEventInfo *out) { @@ -482,7 +482,7 @@ namespace ams::pm::impl { process.ClearStartedStateChanged(); out->event = GetProcessEventValue(ProcessEvent::Started); out->process_id = process.GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } if (process.HasSuspendedStateChanged()) { process.ClearSuspendedStateChanged(); @@ -492,18 +492,18 @@ namespace ams::pm::impl { out->event = GetProcessEventValue(ProcessEvent::DebugRunning); } out->process_id = process.GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } if (process.HasExceptionOccurred()) { process.ClearExceptionOccurred(); out->event = GetProcessEventValue(ProcessEvent::Exception); out->process_id = process.GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } if (hos::GetVersion() < hos::Version_5_0_0 && process.ShouldSignalOnExit() && process.HasTerminated()) { out->event = GetProcessEventValue(ProcessEvent::Exited); out->process_id = process.GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } } } @@ -518,13 +518,13 @@ namespace ams::pm::impl { out->process_id = process_info.GetProcessId(); CleanupProcessInfo(dead_list, std::addressof(process_info)); - return ResultSuccess(); + R_SUCCEED(); } } out->process_id = os::ProcessId{}; out->event = GetProcessEventValue(ProcessEvent::None); - return ResultSuccess(); + R_SUCCEED(); } Result CleanupProcess(os::ProcessId process_id) { @@ -535,7 +535,7 @@ namespace ams::pm::impl { R_UNLESS(process_info->HasTerminated(), pm::ResultNotTerminated()); CleanupProcessInfo(list, process_info); - return ResultSuccess(); + R_SUCCEED(); } Result ClearExceptionOccurred(os::ProcessId process_id) { @@ -545,7 +545,7 @@ namespace ams::pm::impl { R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); process_info->ClearExceptionOccurred(); - return ResultSuccess(); + R_SUCCEED(); } /* Information Getters. */ @@ -553,7 +553,7 @@ namespace ams::pm::impl { /* This function was always stubbed... */ AMS_UNUSED(out_buf, max_out_count, unused); *out_count = 0; - return ResultSuccess(); + R_SUCCEED(); } Result GetExceptionProcessIdList(u32 *out_count, os::ProcessId *out_process_ids, size_t max_out_count) { @@ -574,7 +574,7 @@ namespace ams::pm::impl { } *out_count = static_cast(count); - return ResultSuccess(); + R_SUCCEED(); } Result GetProcessId(os::ProcessId *out, ncm::ProgramId program_id) { @@ -584,7 +584,7 @@ namespace ams::pm::impl { R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); *out = process_info->GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } Result GetProgramId(ncm::ProgramId *out, os::ProcessId process_id) { @@ -594,7 +594,7 @@ namespace ams::pm::impl { R_UNLESS(process_info != nullptr, pm::ResultProcessNotFound()); *out = process_info->GetProgramLocation().program_id; - return ResultSuccess(); + R_SUCCEED(); } Result GetApplicationProcessId(os::ProcessId *out_process_id) { @@ -603,11 +603,11 @@ namespace ams::pm::impl { for (auto &process : *list) { if (process.IsApplication()) { *out_process_id = process.GetProcessId(); - return ResultSuccess(); + R_SUCCEED(); } } - return pm::ResultProcessNotFound(); + R_THROW(pm::ResultProcessNotFound()); } Result AtmosphereGetProcessInfo(os::NativeHandle *out_process_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { @@ -619,7 +619,7 @@ namespace ams::pm::impl { *out_process_handle = process_info->GetHandle(); *out_loc = process_info->GetProgramLocation(); *out_status = process_info->GetOverrideStatus(); - return ResultSuccess(); + R_SUCCEED(); } /* Hook API. */ @@ -632,7 +632,7 @@ namespace ams::pm::impl { } *out_hook = os::GetReadableHandleOfSystemEvent(std::addressof(g_hook_to_create_process_event)); - return ResultSuccess(); + R_SUCCEED(); } Result HookToCreateApplicationProcess(os::NativeHandle *out_hook) { @@ -644,7 +644,7 @@ namespace ams::pm::impl { } *out_hook = os::GetReadableHandleOfSystemEvent(std::addressof(g_hook_to_create_application_process_event)); - return ResultSuccess(); + R_SUCCEED(); } Result ClearHook(u32 which) { @@ -654,7 +654,7 @@ namespace ams::pm::impl { if (which & HookType_Application) { g_application_hook = false; } - return ResultSuccess(); + R_SUCCEED(); } /* Boot API. */ @@ -676,7 +676,7 @@ namespace ams::pm::impl { s_has_boot_finished = true; os::SignalSystemEvent(std::addressof(g_boot_finished_event)); } - return ResultSuccess(); + R_SUCCEED(); } Result GetBootFinishedEventHandle(os::NativeHandle *out) { @@ -685,20 +685,32 @@ namespace ams::pm::impl { /* We will signal it always, but only allow this function to succeed on safe mode. */ AMS_ABORT_UNLESS(spl::IsRecoveryBoot()); *out = os::GetReadableHandleOfSystemEvent(std::addressof(g_boot_finished_event)); - return ResultSuccess(); + R_SUCCEED(); } /* Resource Limit API. */ Result BoostSystemMemoryResourceLimit(u64 boost_size) { - return resource::BoostSystemMemoryResourceLimit(boost_size); + R_RETURN(resource::BoostSystemMemoryResourceLimit(boost_size)); } Result BoostApplicationThreadResourceLimit() { - return resource::BoostApplicationThreadResourceLimit(); + R_RETURN(resource::BoostApplicationThreadResourceLimit()); + } + + Result BoostSystemThreadResourceLimit() { + R_RETURN(resource::BoostSystemThreadResourceLimit()); + } + + Result GetAppletCurrentResourceLimitValues(pm::ResourceLimitValues *out) { + R_RETURN(resource::GetCurrentResourceLimitValues(ResourceLimitGroup_Applet, out)); + } + + Result GetAppletPeakResourceLimitValues(pm::ResourceLimitValues *out) { + R_RETURN(resource::GetPeakResourceLimitValues(ResourceLimitGroup_Applet, out)); } Result AtmosphereGetCurrentLimitInfo(s64 *out_cur_val, s64 *out_lim_val, u32 group, u32 resource) { - return resource::GetResourceLimitValues(out_cur_val, out_lim_val, static_cast(group), static_cast(resource)); + R_RETURN(resource::GetResourceLimitValues(out_cur_val, out_lim_val, static_cast(group), static_cast(resource))); } } diff --git a/stratosphere/pm/source/impl/pm_process_manager.hpp b/stratosphere/pm/source/impl/pm_process_manager.hpp index 2e49a3983..d2af22ac2 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.hpp +++ b/stratosphere/pm/source/impl/pm_process_manager.hpp @@ -51,6 +51,9 @@ namespace ams::pm::impl { /* Resource Limit API. */ Result BoostSystemMemoryResourceLimit(u64 boost_size); Result BoostApplicationThreadResourceLimit(); + Result BoostSystemThreadResourceLimit(); + Result GetAppletCurrentResourceLimitValues(pm::ResourceLimitValues *out); + Result GetAppletPeakResourceLimitValues(pm::ResourceLimitValues *out); Result AtmosphereGetCurrentLimitInfo(s64 *out_cur_val, s64 *out_lim_val, u32 group, u32 resource); } diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index 609510166..9fdb91837 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -35,31 +35,44 @@ namespace ams::pm::resource { /* Atmosphere always allocates extra memory for system usage. */ constexpr size_t ExtraSystemMemorySizeAtmosphere = 24_MB; + /* Desired extra threads. */ + constexpr u64 BaseApplicationThreads = 96; + constexpr u64 BaseAppletThreads = 96; + constexpr u64 BaseSystemThreads = 800 - BaseAppletThreads - BaseApplicationThreads; + + constexpr s64 ExtraSystemThreads = 1024 - BaseSystemThreads; + constexpr s64 ExtraApplicationThreads = 256 - BaseApplicationThreads; + constexpr s64 ExtraAppletThreads = 256 - BaseAppletThreads; + + static_assert(ExtraSystemThreads >= 0); + static_assert(ExtraApplicationThreads >= 0); + static_assert(ExtraAppletThreads >= 0); + /* Globals. */ constinit os::SdkMutex g_resource_limit_lock; constinit os::NativeHandle g_resource_limit_handles[ResourceLimitGroup_Count]; constinit spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard; constinit u64 g_system_memory_boost_size = 0; - constinit u64 g_extra_application_threads_available = 0; + constinit u64 g_extra_threads_available[ResourceLimitGroup_Count]; constinit u64 g_resource_limits[ResourceLimitGroup_Count][svc::LimitableResource_Count] = { [ResourceLimitGroup_System] = { [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized dynamically later. */ - [svc::LimitableResource_ThreadCountMax] = 608, + [svc::LimitableResource_ThreadCountMax] = BaseSystemThreads, [svc::LimitableResource_EventCountMax] = 0, /* Initialized dynamically later. */ [svc::LimitableResource_TransferMemoryCountMax] = 0, /* Initialized dynamically later. */ [svc::LimitableResource_SessionCountMax] = 0, /* Initialized dynamically later. */ }, [ResourceLimitGroup_Application] = { [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized dynamically later. */ - [svc::LimitableResource_ThreadCountMax] = 96, + [svc::LimitableResource_ThreadCountMax] = BaseApplicationThreads, [svc::LimitableResource_EventCountMax] = 0, [svc::LimitableResource_TransferMemoryCountMax] = 32, [svc::LimitableResource_SessionCountMax] = 1, }, [ResourceLimitGroup_Applet] = { [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized dynamically later. */ - [svc::LimitableResource_ThreadCountMax] = 96, + [svc::LimitableResource_ThreadCountMax] = BaseAppletThreads, [svc::LimitableResource_EventCountMax] = 0, [svc::LimitableResource_TransferMemoryCountMax] = 32, [svc::LimitableResource_SessionCountMax] = 5, @@ -118,7 +131,8 @@ namespace ams::pm::resource { } R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(group), resource, g_resource_limits[group][resource])); } - return ResultSuccess(); + + R_SUCCEED(); } inline ResourceLimitGroup GetResourceLimitGroup(const ldr::ProgramInfo *info) { @@ -166,6 +180,46 @@ namespace ams::pm::resource { return value != 0; } + ALWAYS_INLINE Result BoostThreadResourceLimitLocked(ResourceLimitGroup group) { + AMS_ASSERT(g_resource_limit_lock.IsLockedByCurrentThread()); + + /* Set new limit. */ + const s64 new_thread_count = g_resource_limits[group][svc::LimitableResource_ThreadCountMax] + g_extra_threads_available[group]; + R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(group), svc::LimitableResource_ThreadCountMax, new_thread_count)); + + /* Record that we did so. */ + g_resource_limits[group][svc::LimitableResource_ThreadCountMax] = new_thread_count; + g_extra_threads_available[group] = 0; + + R_SUCCEED(); + } + + template + ALWAYS_INLINE Result GetResourceLimitValuesImpl(ResourceLimitGroup group, pm::ResourceLimitValues *out) { + /* Sanity check group. */ + AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count); + + /* Get handle. */ + const auto handle = GetResourceLimitHandle(group); + + /* Get values. */ + int64_t values[svc::LimitableResource_Count]; + R_ABORT_UNLESS(GetResourceLimitValueImpl(std::addressof(values[svc::LimitableResource_PhysicalMemoryMax]), handle, svc::LimitableResource_PhysicalMemoryMax)); + R_ABORT_UNLESS(GetResourceLimitValueImpl(std::addressof(values[svc::LimitableResource_ThreadCountMax]), handle, svc::LimitableResource_ThreadCountMax)); + R_ABORT_UNLESS(GetResourceLimitValueImpl(std::addressof(values[svc::LimitableResource_EventCountMax]), handle, svc::LimitableResource_EventCountMax)); + R_ABORT_UNLESS(GetResourceLimitValueImpl(std::addressof(values[svc::LimitableResource_TransferMemoryCountMax]), handle, svc::LimitableResource_TransferMemoryCountMax)); + R_ABORT_UNLESS(GetResourceLimitValueImpl(std::addressof(values[svc::LimitableResource_SessionCountMax]), handle, svc::LimitableResource_SessionCountMax)); + + /* Set to output. */ + out->physical_memory = values[svc::LimitableResource_PhysicalMemoryMax]; + out->thread_count = values[svc::LimitableResource_ThreadCountMax]; + out->event_count = values[svc::LimitableResource_EventCountMax]; + out->transfer_memory_count = values[svc::LimitableResource_TransferMemoryCountMax]; + out->session_count = values[svc::LimitableResource_SessionCountMax]; + + R_SUCCEED(); + } + } /* Resource API. */ @@ -225,8 +279,20 @@ namespace ams::pm::resource { const s64 required_threads = g_resource_limits[ResourceLimitGroup_System][svc::LimitableResource_ThreadCountMax] + g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] + g_resource_limits[ResourceLimitGroup_Applet][svc::LimitableResource_ThreadCountMax]; AMS_ABORT_UNLESS(total_threads >= required_threads); - /* Set the number of extra application threads. */ - g_extra_application_threads_available = total_threads - required_threads; + /* Set the number of extra threads. */ + const s64 extra_threads = total_threads - required_threads; + if constexpr (true /* TODO: Should we expose the old "all extra threads are application" behavior? Seems pointless. */) { + if (extra_threads > 0) { + /* If we have any extra threads at all, require that we have enough. */ + AMS_ABORT_UNLESS(extra_threads >= (ExtraSystemThreads + ExtraApplicationThreads + ExtraAppletThreads)); + + g_extra_threads_available[ResourceLimitGroup_System] += ExtraSystemThreads; + g_extra_threads_available[ResourceLimitGroup_Application] += ExtraApplicationThreads; + g_extra_threads_available[ResourceLimitGroup_Applet] += ExtraAppletThreads; + } + } else { + g_extra_threads_available[ResourceLimitGroup_Application] = extra_threads; + } } /* Choose and initialize memory arrangement. */ @@ -282,7 +348,7 @@ namespace ams::pm::resource { } } - return ResultSuccess(); + R_SUCCEED(); } Result BoostSystemMemoryResourceLimit(u64 boost_size) { @@ -316,21 +382,26 @@ namespace ams::pm::resource { g_system_memory_boost_size = boost_size; } - return ResultSuccess(); + R_SUCCEED(); } Result BoostApplicationThreadResourceLimit() { std::scoped_lock lk(g_resource_limit_lock); - /* Set new limit. */ - const s64 new_thread_count = g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] + g_extra_application_threads_available; - R_TRY(svc::SetResourceLimitLimitValue(GetResourceLimitHandle(ResourceLimitGroup_Application), svc::LimitableResource_ThreadCountMax, new_thread_count)); + /* Boost the limit. */ + R_TRY(BoostThreadResourceLimitLocked(ResourceLimitGroup_Application)); - /* Record that we did so. */ - g_resource_limits[ResourceLimitGroup_Application][svc::LimitableResource_ThreadCountMax] = new_thread_count; - g_extra_application_threads_available = 0; + R_SUCCEED(); + } - return ResultSuccess(); + Result BoostSystemThreadResourceLimit() { + std::scoped_lock lk(g_resource_limit_lock); + + /* Boost the limits. */ + R_TRY(BoostThreadResourceLimitLocked(ResourceLimitGroup_Applet)); + R_TRY(BoostThreadResourceLimitLocked(ResourceLimitGroup_System)); + + R_SUCCEED(); } os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group) { @@ -350,6 +421,18 @@ namespace ams::pm::resource { } } + Result GetCurrentResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out) { + R_RETURN(GetResourceLimitValuesImpl<::ams::svc::GetResourceLimitCurrentValue>(group, out)); + } + + Result GetPeakResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out) { + R_RETURN(GetResourceLimitValuesImpl<::ams::svc::GetResourceLimitPeakValue>(group, out)); + } + + Result GetLimitResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out) { + R_RETURN(GetResourceLimitValuesImpl<::ams::svc::GetResourceLimitLimitValue>(group, out)); + } + Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource) { /* Do not allow out of bounds access. */ AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count); @@ -359,7 +442,7 @@ namespace ams::pm::resource { R_TRY(svc::GetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource)); R_TRY(svc::GetResourceLimitLimitValue(out_lim, reslimit_hnd, resource)); - return ResultSuccess(); + R_SUCCEED(); } } diff --git a/stratosphere/pm/source/impl/pm_resource_manager.hpp b/stratosphere/pm/source/impl/pm_resource_manager.hpp index d9bef4d5d..bd59f28c8 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.hpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.hpp @@ -22,12 +22,17 @@ namespace ams::pm::resource { Result InitializeResourceManager(); Result BoostSystemMemoryResourceLimit(u64 boost_size); Result BoostApplicationThreadResourceLimit(); + Result BoostSystemThreadResourceLimit(); os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group); os::NativeHandle GetResourceLimitHandle(const ldr::ProgramInfo *info); void WaitResourceAvailable(const ldr::ProgramInfo *info); + Result GetCurrentResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out); + Result GetPeakResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out); + Result GetLimitResourceLimitValues(ResourceLimitGroup group, pm::ResourceLimitValues *out); + Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource); } diff --git a/stratosphere/pm/source/pm_debug_monitor_service.cpp b/stratosphere/pm/source/pm_debug_monitor_service.cpp index dd1a4fb64..dd5433c78 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.cpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.cpp @@ -22,20 +22,20 @@ namespace ams::pm { /* Actual command implementations. */ Result DebugMonitorService::GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused) { R_UNLESS(out_buf.GetSize() <= std::numeric_limits::max(), pm::ResultInvalidSize()); - return impl::GetModuleIdList(out_count.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), unused); + R_RETURN(impl::GetModuleIdList(out_count.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), unused)); } Result DebugMonitorService::GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids) { R_UNLESS(out_process_ids.GetSize() <= std::numeric_limits::max(), pm::ResultInvalidSize()); - return impl::GetExceptionProcessIdList(out_count.GetPointer(), out_process_ids.GetPointer(), out_process_ids.GetSize()); + R_RETURN(impl::GetExceptionProcessIdList(out_count.GetPointer(), out_process_ids.GetPointer(), out_process_ids.GetSize())); } Result DebugMonitorService::StartProcess(os::ProcessId process_id) { - return impl::StartProcess(process_id); + R_RETURN(impl::StartProcess(process_id)); } Result DebugMonitorService::GetProcessId(sf::Out out, ncm::ProgramId program_id) { - return impl::GetProcessId(out.GetPointer(), program_id); + R_RETURN(impl::GetProcessId(out.GetPointer(), program_id)); } Result DebugMonitorService::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id) { @@ -43,11 +43,11 @@ namespace ams::pm { R_TRY(impl::HookToCreateProcess(std::addressof(event_handle), program_id)); out_hook.SetValue(event_handle, false); - return ResultSuccess(); + R_SUCCEED(); } Result DebugMonitorService::GetApplicationProcessId(sf::Out out) { - return impl::GetApplicationProcessId(out.GetPointer()); + R_RETURN(impl::GetApplicationProcessId(out.GetPointer())); } Result DebugMonitorService::HookToCreateApplicationProcess(sf::OutCopyHandle out_hook) { @@ -55,11 +55,15 @@ namespace ams::pm { R_TRY(impl::HookToCreateApplicationProcess(std::addressof(event_handle))); out_hook.SetValue(event_handle, false); - return ResultSuccess(); + R_SUCCEED(); } Result DebugMonitorService::ClearHook(u32 which) { - return impl::ClearHook(which); + R_RETURN(impl::ClearHook(which)); + } + + Result DebugMonitorService::GetProgramId(sf::Out out, os::ProcessId process_id) { + R_RETURN(impl::GetProgramId(out.GetPointer(), process_id)); } /* Atmosphere extension commands. */ @@ -68,11 +72,11 @@ namespace ams::pm { R_TRY(impl::AtmosphereGetProcessInfo(std::addressof(process_handle), out_loc.GetPointer(), out_status.GetPointer(), process_id)); out_process_handle.SetValue(process_handle, false); - return ResultSuccess(); + R_SUCCEED(); } Result DebugMonitorService::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); + R_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 d4f49f632..052e611c9 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.hpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.hpp @@ -29,6 +29,7 @@ namespace ams::pm { Result GetApplicationProcessId(sf::Out out); Result HookToCreateApplicationProcess(sf::OutCopyHandle out_hook); Result ClearHook(u32 which); + Result GetProgramId(sf::Out out, os::ProcessId process_id); /* Atmosphere extension commands. */ Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); diff --git a/stratosphere/pm/source/pm_info_service.cpp b/stratosphere/pm/source/pm_info_service.cpp index b342768e6..26c7f2781 100644 --- a/stratosphere/pm/source/pm_info_service.cpp +++ b/stratosphere/pm/source/pm_info_service.cpp @@ -23,29 +23,37 @@ namespace ams::pm { namespace info { Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id) { - return ldr::pm::HasLaunchedBootProgram(out, program_id); + R_RETURN(ldr::pm::HasLaunchedBootProgram(out, program_id)); } } /* Actual command implementations. */ Result InformationService::GetProgramId(sf::Out out, os::ProcessId process_id) { - return impl::GetProgramId(out.GetPointer(), process_id); + R_RETURN(impl::GetProgramId(out.GetPointer(), process_id)); + } + + Result InformationService::GetAppletCurrentResourceLimitValues(sf::Out out) { + R_RETURN(impl::GetAppletCurrentResourceLimitValues(out.GetPointer())); + } + + Result InformationService::GetAppletPeakResourceLimitValues(sf::Out out) { + R_RETURN(impl::GetAppletPeakResourceLimitValues(out.GetPointer())); } /* Atmosphere extension commands. */ Result InformationService::AtmosphereGetProcessId(sf::Out out, ncm::ProgramId program_id) { - return impl::GetProcessId(out.GetPointer(), program_id); + R_RETURN(impl::GetProcessId(out.GetPointer(), program_id)); } Result InformationService::AtmosphereHasLaunchedBootProgram(sf::Out out, ncm::ProgramId program_id) { - return pm::info::HasLaunchedBootProgram(out.GetPointer(), program_id); + R_RETURN(pm::info::HasLaunchedBootProgram(out.GetPointer(), program_id)); } Result InformationService::AtmosphereGetProcessInfo(sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { /* NOTE: We don't need to worry about closing this handle, because it's an in-process copy, not a newly allocated handle. */ os::NativeHandle dummy_handle; - return impl::AtmosphereGetProcessInfo(&dummy_handle, out_loc.GetPointer(), out_status.GetPointer(), process_id); + R_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 7bce1fc8a..1f8010f11 100644 --- a/stratosphere/pm/source/pm_info_service.hpp +++ b/stratosphere/pm/source/pm_info_service.hpp @@ -22,6 +22,8 @@ namespace ams::pm { public: /* Actual command implementations. */ Result GetProgramId(sf::Out out, os::ProcessId process_id); + Result GetAppletCurrentResourceLimitValues(sf::Out out); + Result GetAppletPeakResourceLimitValues(sf::Out out); /* Atmosphere extension commands. */ Result AtmosphereGetProcessId(sf::Out out, ncm::ProgramId program_id); diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index aa8138ec6..b7d775be9 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -132,20 +132,20 @@ namespace ams { switch (port_index) { case PortIndex_Shell: if (hos::GetVersion() >= hos::Version_5_0_0) { - return this->AcceptImpl(server, g_shell_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_shell_service.GetShared())); } else { - return this->AcceptImpl(server, g_deprecated_shell_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_deprecated_shell_service.GetShared())); } case PortIndex_DebugMonitor: if (hos::GetVersion() >= hos::Version_5_0_0) { - return this->AcceptImpl(server, g_dmnt_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_dmnt_service.GetShared())); } else { - return this->AcceptImpl(server, g_deprecated_dmnt_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_deprecated_dmnt_service.GetShared())); } case PortIndex_BootMode: - return this->AcceptImpl(server, g_boot_mode_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_boot_mode_service.GetShared())); case PortIndex_Information: - return this->AcceptImpl(server, g_information_service.GetShared()); + R_RETURN(this->AcceptImpl(server, g_information_service.GetShared())); AMS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/pm/source/pm_shell_service.cpp b/stratosphere/pm/source/pm_shell_service.cpp index 2adf545b9..7248bc0e2 100644 --- a/stratosphere/pm/source/pm_shell_service.cpp +++ b/stratosphere/pm/source/pm_shell_service.cpp @@ -23,22 +23,22 @@ namespace ams::pm { namespace shell { Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) { - return impl::LaunchProgram(out_process_id, loc, launch_flags); + R_RETURN(impl::LaunchProgram(out_process_id, loc, launch_flags)); } } /* Service command implementations. */ Result ShellService::LaunchProgram(sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags) { - return pm::shell::LaunchProgram(out_process_id.GetPointer(), loc, flags); + R_RETURN(pm::shell::LaunchProgram(out_process_id.GetPointer(), loc, flags)); } Result ShellService::TerminateProcess(os::ProcessId process_id) { - return impl::TerminateProcess(process_id); + R_RETURN(impl::TerminateProcess(process_id)); } Result ShellService::TerminateProgram(ncm::ProgramId program_id) { - return impl::TerminateProgram(program_id); + R_RETURN(impl::TerminateProgram(program_id)); } void ShellService::GetProcessEventHandle(sf::OutCopyHandle out) { @@ -53,11 +53,11 @@ namespace ams::pm { } Result ShellService::CleanupProcess(os::ProcessId process_id) { - return impl::CleanupProcess(process_id); + R_RETURN(impl::CleanupProcess(process_id)); } Result ShellService::ClearExceptionOccurred(os::ProcessId process_id) { - return impl::ClearExceptionOccurred(process_id); + R_RETURN(impl::ClearExceptionOccurred(process_id)); } void ShellService::NotifyBootFinished() { @@ -65,15 +65,15 @@ namespace ams::pm { } Result ShellService::GetApplicationProcessIdForShell(sf::Out out) { - return impl::GetApplicationProcessId(out.GetPointer()); + R_RETURN(impl::GetApplicationProcessId(out.GetPointer())); } Result ShellService::BoostSystemMemoryResourceLimit(u64 boost_size) { - return impl::BoostSystemMemoryResourceLimit(boost_size); + R_RETURN(impl::BoostSystemMemoryResourceLimit(boost_size)); } Result ShellService::BoostApplicationThreadResourceLimit() { - return impl::BoostApplicationThreadResourceLimit(); + R_RETURN(impl::BoostApplicationThreadResourceLimit()); } void ShellService::GetBootFinishedEventHandle(sf::OutCopyHandle out) { @@ -83,4 +83,8 @@ namespace ams::pm { out.SetValue(event_handle, false); } + Result ShellService::BoostSystemThreadResourceLimit() { + R_RETURN(impl::BoostSystemThreadResourceLimit()); + } + } diff --git a/stratosphere/pm/source/pm_shell_service.hpp b/stratosphere/pm/source/pm_shell_service.hpp index c851bfedd..bb08d80bd 100644 --- a/stratosphere/pm/source/pm_shell_service.hpp +++ b/stratosphere/pm/source/pm_shell_service.hpp @@ -33,6 +33,7 @@ namespace ams::pm { Result BoostSystemMemoryResourceLimit(u64 boost_size); Result BoostApplicationThreadResourceLimit(); void GetBootFinishedEventHandle(sf::OutCopyHandle out); + Result BoostSystemThreadResourceLimit(); }; static_assert(pm::impl::IsIShellInterface);