diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere
index b5f1ec02b..777984476 160000
--- a/stratosphere/libstratosphere
+++ b/stratosphere/libstratosphere
@@ -1 +1 @@
-Subproject commit b5f1ec02b30a3bbf8a8419f8b0cf3646071ebd2b
+Subproject commit 777984476ea7b1da56c9a3fd3f55575a8b899896
diff --git a/stratosphere/pm/source/pm_boot2.hpp b/stratosphere/pm/source/pm_boot2.hpp
index c33498928..30761a85e 100644
--- a/stratosphere/pm/source/pm_boot2.hpp
+++ b/stratosphere/pm/source/pm_boot2.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
class EmbeddedBoot2 {
diff --git a/stratosphere/pm/source/pm_boot_mode.cpp b/stratosphere/pm/source/pm_boot_mode.cpp
index b8326c391..bb0a2e541 100644
--- a/stratosphere/pm/source/pm_boot_mode.cpp
+++ b/stratosphere/pm/source/pm_boot_mode.cpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include "pm_boot_mode.hpp"
diff --git a/stratosphere/pm/source/pm_boot_mode.hpp b/stratosphere/pm/source/pm_boot_mode.hpp
index b7957c79e..96107e902 100644
--- a/stratosphere/pm/source/pm_boot_mode.hpp
+++ b/stratosphere/pm/source/pm_boot_mode.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
#include
@@ -23,7 +23,7 @@ enum BootModeCmd {
BootMode_Cmd_SetMaintenanceBoot = 1
};
-class BootModeService final : public IServiceObject {
+class BootModeService final : public IServiceObject {
private:
/* Actual commands. */
void GetBootMode(Out out);
diff --git a/stratosphere/pm/source/pm_debug_monitor.cpp b/stratosphere/pm/source/pm_debug_monitor.cpp
index ad93d2600..b546f3224 100644
--- a/stratosphere/pm/source/pm_debug_monitor.cpp
+++ b/stratosphere/pm/source/pm_debug_monitor.cpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include "pm_registration.hpp"
@@ -43,7 +43,7 @@ Result DebugMonitorService::LaunchDebugProcess(u64 pid) {
Result DebugMonitorService::GetTitleProcessId(Out pid, u64 tid) {
std::scoped_lock lk(Registration::GetProcessList());
-
+
std::shared_ptr proc = Registration::GetProcessByTitleId(tid);
if (proc != nullptr) {
pid.SetValue(proc->pid);
@@ -58,7 +58,7 @@ Result DebugMonitorService::EnableDebugForTitleId(Out event, u64 t
Result DebugMonitorService::GetApplicationProcessId(Out pid) {
std::scoped_lock lk(Registration::GetProcessList());
-
+
std::shared_ptr app_proc;
if (Registration::HasApplicationProcess(&app_proc)) {
pid.SetValue(app_proc->pid);
@@ -87,22 +87,14 @@ Result DebugMonitorService::AtmosphereGetProcessInfo(Out proc_hand
}
Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out cur_val, Out lim_val, u32 category, u32 resource) {
- Result rc;
if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) {
return ResultKernelInvalidEnumValue;
}
Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category);
- rc = svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource);
- if(R_FAILED(rc)) {
- return rc;
- }
-
- rc = svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource);
- if(R_FAILED(rc)) {
- return rc;
- }
+ R_TRY(svcGetResourceLimitCurrentValue(cur_val.GetPointer(), limit_h, (LimitableResource) resource));
+ R_TRY(svcGetResourceLimitLimitValue(lim_val.GetPointer(), limit_h, (LimitableResource) resource));
return ResultSuccess;
}
diff --git a/stratosphere/pm/source/pm_debug_monitor.hpp b/stratosphere/pm/source/pm_debug_monitor.hpp
index 6a04ddd03..26fd11880 100644
--- a/stratosphere/pm/source/pm_debug_monitor.hpp
+++ b/stratosphere/pm/source/pm_debug_monitor.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
#include
@@ -28,14 +28,14 @@ enum DmntCmd {
Dmnt_Cmd_EnableDebugForTitleId = 4,
Dmnt_Cmd_GetApplicationProcessId = 5,
Dmnt_Cmd_EnableDebugForApplication = 6,
-
+
Dmnt_Cmd_5X_GetDebugProcessIds = 0,
Dmnt_Cmd_5X_LaunchDebugProcess = 1,
Dmnt_Cmd_5X_GetTitleProcessId = 2,
Dmnt_Cmd_5X_EnableDebugForTitleId = 3,
Dmnt_Cmd_5X_GetApplicationProcessId = 4,
Dmnt_Cmd_5X_EnableDebugForApplication = 5,
-
+
Dmnt_Cmd_6X_DisableDebug = 6,
Dmnt_Cmd_AtmosphereGetProcessInfo = 65000,
@@ -67,7 +67,7 @@ class DebugMonitorService final : public IServiceObject {
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
-
+
/* 5.0.0-* */
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
@@ -75,10 +75,10 @@ class DebugMonitorService final : public IServiceObject {
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
-
+
/* 6.0.0-* */
MakeServiceCommandMeta(),
-
+
/* Atmosphere extensions. */
MakeServiceCommandMeta(),
MakeServiceCommandMeta(),
diff --git a/stratosphere/pm/source/pm_info.cpp b/stratosphere/pm/source/pm_info.cpp
index a05b8fe4b..83d409cda 100644
--- a/stratosphere/pm/source/pm_info.cpp
+++ b/stratosphere/pm/source/pm_info.cpp
@@ -13,14 +13,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include "pm_registration.hpp"
#include "pm_info.hpp"
Result InformationService::GetTitleId(Out tid, u64 pid) {
std::scoped_lock lk(Registration::GetProcessList());
-
+
std::shared_ptr proc = Registration::GetProcess(pid);
if (proc != NULL) {
tid.SetValue(proc->tid_sid.title_id);
diff --git a/stratosphere/pm/source/pm_info.hpp b/stratosphere/pm/source/pm_info.hpp
index cc60566d9..8643e2a9c 100644
--- a/stratosphere/pm/source/pm_info.hpp
+++ b/stratosphere/pm/source/pm_info.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
#include
diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp
index 484a1347e..58a0c6c23 100644
--- a/stratosphere/pm/source/pm_main.cpp
+++ b/stratosphere/pm/source/pm_main.cpp
@@ -178,7 +178,7 @@ int main(int argc, char **argv)
s_server_manager.AddWaitable(new ServiceServer("pm:dmnt", 3));
s_server_manager.AddWaitable(new ServiceServer("pm:bm", 6));
s_server_manager.AddWaitable(new ServiceServer("pm:info", 3));
-
+
/* Loop forever, servicing our services. */
s_server_manager.Process();
diff --git a/stratosphere/pm/source/pm_process_track.hpp b/stratosphere/pm/source/pm_process_track.hpp
index 72e5be378..c781a8cfe 100644
--- a/stratosphere/pm/source/pm_process_track.hpp
+++ b/stratosphere/pm/source/pm_process_track.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
diff --git a/stratosphere/pm/source/pm_process_wait.hpp b/stratosphere/pm/source/pm_process_wait.hpp
index a4b9fbfe6..1630a5518 100644
--- a/stratosphere/pm/source/pm_process_wait.hpp
+++ b/stratosphere/pm/source/pm_process_wait.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
#include
@@ -23,27 +23,27 @@
class ProcessWaiter final : public IWaitable {
public:
std::shared_ptr process;
-
+
ProcessWaiter(std::shared_ptr p) : process(p) {
/* ... */
}
-
- std::shared_ptr GetProcess() {
- return this->process;
+
+ std::shared_ptr GetProcess() {
+ return this->process;
}
-
- /* IWaitable */
+
+ /* IWaitable */
Handle GetHandle() override {
return this->process->handle;
}
-
+
Result HandleSignaled(u64 timeout) override {
return Registration::HandleSignaledProcess(this->GetProcess());
}
};
class ProcessList final {
- private:
+ private:
HosRecursiveMutex m;
HosRecursiveMutex *GetMutex() {
@@ -51,15 +51,15 @@ class ProcessList final {
}
public:
std::vector> processes;
-
+
void lock() {
GetMutex()->lock();
}
-
+
void unlock() {
GetMutex()->unlock();
}
-
+
void try_lock() {
GetMutex()->try_lock();
}
diff --git a/stratosphere/pm/source/pm_registration.cpp b/stratosphere/pm/source/pm_registration.cpp
index 7e306150f..b51d27684 100644
--- a/stratosphere/pm/source/pm_registration.cpp
+++ b/stratosphere/pm/source/pm_registration.cpp
@@ -24,7 +24,7 @@ static ProcessList g_process_list;
static ProcessList g_dead_process_list;
static IEvent *g_process_launch_start_event = nullptr;
-static HosSemaphore g_sema_finish_launch;
+static HosSignal g_finish_launch_signal;
static HosMutex g_process_launch_mutex;
static Registration::ProcessLaunchState g_process_launch_state;
@@ -37,8 +37,6 @@ static IEvent *g_debug_title_event = nullptr;
static IEvent *g_debug_application_event = nullptr;
static IEvent *g_boot_finished_event = nullptr;
-static u8 g_ac_buf[4 * sizeof(LoaderProgramInfo)];
-
ProcessList &Registration::GetProcessList() {
return g_process_list;
}
@@ -65,31 +63,29 @@ IWaitable *Registration::GetProcessLaunchStartEvent() {
return g_process_launch_start_event;
}
-void Registration::HandleProcessLaunch() {
+Result Registration::LaunchProcess(u64 *out_pid, const TidSid tid_sid, const u64 launch_flags) {
LoaderProgramInfo program_info = {0};
- Result rc;
- u64 launch_flags = g_process_launch_state.launch_flags;
- u64 *out_pid = g_process_launch_state.out_pid;
Process new_process = {0};
- new_process.tid_sid = g_process_launch_state.tid_sid;
- std::memset(g_ac_buf, 0xCC, sizeof(g_ac_buf));
- u8 *acid_sac = g_ac_buf, *aci0_sac = acid_sac + sizeof(LoaderProgramInfo), *fac = aci0_sac + sizeof(LoaderProgramInfo), *fah = fac + sizeof(LoaderProgramInfo);
+ new_process.tid_sid = tid_sid;
+
+ /* Clear, get accessors for access controls. */
+ static u8 s_ac_buf[4 * sizeof(LoaderProgramInfo)];
+ std::memset(s_ac_buf, 0xCC, sizeof(s_ac_buf));
+ u8 *acid_sac = s_ac_buf, *aci0_sac = acid_sac + sizeof(LoaderProgramInfo), *fac = aci0_sac + sizeof(LoaderProgramInfo), *fah = fac + sizeof(LoaderProgramInfo);
/* Check that this is a real program. */
- if (R_FAILED((rc = ldrPmGetProgramInfo(new_process.tid_sid.title_id, new_process.tid_sid.storage_id, &program_info)))) {
- goto HANDLE_PROCESS_LAUNCH_END;
- }
+ R_TRY(ldrPmGetProgramInfo(new_process.tid_sid.title_id, new_process.tid_sid.storage_id, &program_info));
/* Get the resource limit handle, ensure that we can launch the program. */
- if ((program_info.application_type & 3) == 1 && HasApplicationProcess(NULL)) {
- rc = ResultPmApplicationRunning;
- goto HANDLE_PROCESS_LAUNCH_END;
+ if ((program_info.application_type & 3) == 1 && HasApplicationProcess()) {
+ return ResultPmApplicationRunning;
}
/* Try to register the title for launch in loader... */
- if (R_FAILED((rc = ldrPmRegisterTitle(new_process.tid_sid.title_id, new_process.tid_sid.storage_id, &new_process.ldr_queue_index)))) {
- goto HANDLE_PROCESS_LAUNCH_END;
- }
+ R_TRY(ldrPmRegisterTitle(new_process.tid_sid.title_id, new_process.tid_sid.storage_id, &new_process.ldr_queue_index));
+ auto ldr_register_guard = SCOPE_GUARD {
+ ldrPmUnregisterTitle(new_process.ldr_queue_index);
+ };
/* Make sure the previous application is cleaned up. */
if ((program_info.application_type & 3) == 1) {
@@ -97,26 +93,32 @@ void Registration::HandleProcessLaunch() {
}
/* Try to create the process... */
- if (R_FAILED((rc = ldrPmCreateProcess(LAUNCHFLAGS_ARGLOW(launch_flags) | LAUNCHFLAGS_ARGHIGH(launch_flags), new_process.ldr_queue_index, ResourceLimitUtils::GetResourceLimitHandle(program_info.application_type), &new_process.handle)))) {
- goto PROCESS_CREATION_FAILED;
- }
+ R_TRY(ldrPmCreateProcess(LAUNCHFLAGS_ARGLOW(launch_flags) | LAUNCHFLAGS_ARGHIGH(launch_flags), new_process.ldr_queue_index, ResourceLimitUtils::GetResourceLimitHandle(program_info.application_type), &new_process.handle));
+ auto proc_create_guard = SCOPE_GUARD {
+ svcCloseHandle(new_process.handle);
+ new_process.handle = 0;
+ };
/* Get the new process's id. */
- svcGetProcessId(&new_process.pid, new_process.handle);
+ if (R_FAILED(svcGetProcessId(&new_process.pid, new_process.handle))) {
+ std::abort();
+ }
/* Register with FS. */
memcpy(fac, program_info.ac_buffer + program_info.acid_sac_size + program_info.aci0_sac_size, program_info.acid_fac_size);
memcpy(fah, program_info.ac_buffer + program_info.acid_sac_size + program_info.aci0_sac_size + program_info.acid_fac_size, program_info.aci0_fah_size);
- if (R_FAILED((rc = fsprRegisterProgram(new_process.pid, new_process.tid_sid.title_id, new_process.tid_sid.storage_id, fah, program_info.aci0_fah_size, fac, program_info.acid_fac_size)))) {
- goto FS_REGISTRATION_FAILED;
- }
+ R_TRY(fsprRegisterProgram(new_process.pid, new_process.tid_sid.title_id, new_process.tid_sid.storage_id, fah, program_info.aci0_fah_size, fac, program_info.acid_fac_size));
+ auto fs_register_guard = SCOPE_GUARD {
+ fsprUnregisterProgram(new_process.pid);
+ };
/* Register with SM. */
memcpy(acid_sac, program_info.ac_buffer, program_info.acid_sac_size);
memcpy(aci0_sac, program_info.ac_buffer + program_info.acid_sac_size, program_info.aci0_sac_size);
- if (R_FAILED((rc = smManagerRegisterProcess(new_process.pid, acid_sac, program_info.acid_sac_size, aci0_sac, program_info.aci0_sac_size)))) {
- goto SM_REGISTRATION_FAILED;
- }
+ R_TRY(smManagerRegisterProcess(new_process.pid, acid_sac, program_info.acid_sac_size, aci0_sac, program_info.aci0_sac_size));
+ auto sm_register_guard = SCOPE_GUARD {
+ smManagerUnregisterProcess(new_process.pid);
+ };
/* Setup process flags. */
if (program_info.application_type & 1) {
@@ -134,61 +136,46 @@ void Registration::HandleProcessLaunch() {
/* Add process to the list. */
Registration::AddProcessToList(std::make_shared(new_process));
+ auto reg_list_guard = SCOPE_GUARD {
+ Registration::RemoveProcessFromList(new_process.pid);
+ };
/* Signal, if relevant. */
if (new_process.tid_sid.title_id == g_debug_on_launch_tid.load()) {
g_debug_title_event->Signal();
g_debug_on_launch_tid = 0;
- rc = ResultSuccess;
} else if ((new_process.flags & PROCESSFLAGS_APPLICATION) && g_debug_next_application.load()) {
g_debug_application_event->Signal();
g_debug_next_application = false;
- rc = ResultSuccess;
- } else if (LAUNCHFLAGS_STARTSUSPENDED(launch_flags)) {
- rc = ResultSuccess;
- } else {
- rc = svcStartProcess(new_process.handle, program_info.main_thread_priority, program_info.default_cpu_id, program_info.main_thread_stack_size);
-
- if (R_SUCCEEDED(rc)) {
- SetProcessState(new_process.pid, ProcessState_Running);
- }
+ } else if (!(LAUNCHFLAGS_STARTSUSPENDED(launch_flags))) {
+ R_TRY(svcStartProcess(new_process.handle, program_info.main_thread_priority, program_info.default_cpu_id, program_info.main_thread_stack_size));
+ SetProcessState(new_process.pid, ProcessState_Running);
}
- if (R_FAILED(rc)) {
- Registration::RemoveProcessFromList(new_process.pid);
- smManagerUnregisterProcess(new_process.pid);
- }
+ /* Dismiss scope guards. */
+ reg_list_guard.Cancel();
+ sm_register_guard.Cancel();
+ fs_register_guard.Cancel();
+ proc_create_guard.Cancel();
+ ldr_register_guard.Cancel();
-SM_REGISTRATION_FAILED:
- if (R_FAILED(rc)) {
- fsprUnregisterProgram(new_process.pid);
- }
+ /* Set output pid. */
+ *out_pid = new_process.pid;
-FS_REGISTRATION_FAILED:
- if (R_FAILED(rc)) {
- svcCloseHandle(new_process.handle);
- new_process.handle = 0;
- }
+ return ResultSuccess;
+}
-PROCESS_CREATION_FAILED:
- if (R_FAILED(rc)) {
- ldrPmUnregisterTitle(new_process.ldr_queue_index);
- }
-
-HANDLE_PROCESS_LAUNCH_END:
- g_process_launch_state.result = rc;
- if (R_SUCCEEDED(rc)) {
- *out_pid = new_process.pid;
- }
-
- g_sema_finish_launch.Signal();
+void Registration::HandleProcessLaunch() {
+ /* Actually launch process. */
+ g_process_launch_state.result = LaunchProcess(g_process_launch_state.out_pid, g_process_launch_state.tid_sid, g_process_launch_state.launch_flags);
+ /* Signal to waiting thread. */
+ g_finish_launch_signal.Signal();
}
Result Registration::LaunchDebugProcess(u64 pid) {
std::scoped_lock lk(GetProcessList());
LoaderProgramInfo program_info = {0};
- Result rc;
std::shared_ptr proc = GetProcess(pid);
if (proc == NULL) {
@@ -200,15 +187,13 @@ Result Registration::LaunchDebugProcess(u64 pid) {
}
/* Check that this is a real program. */
- if (R_FAILED((rc = ldrPmGetProgramInfo(proc->tid_sid.title_id, proc->tid_sid.storage_id, &program_info)))) {
- return rc;
- }
+ R_TRY(ldrPmGetProgramInfo(proc->tid_sid.title_id, proc->tid_sid.storage_id, &program_info));
- if (R_SUCCEEDED((rc = svcStartProcess(proc->handle, program_info.main_thread_priority, program_info.default_cpu_id, program_info.main_thread_stack_size)))) {
- proc->state = ProcessState_Running;
- }
+ /* Actually start the process. */
+ R_TRY(svcStartProcess(proc->handle, program_info.main_thread_priority, program_info.default_cpu_id, program_info.main_thread_stack_size));
- return rc;
+ proc->state = ProcessState_Running;
+ return ResultSuccess;
}
Result Registration::LaunchProcess(u64 title_id, FsStorageId storage_id, u64 launch_flags, u64 *out_pid) {
@@ -220,8 +205,9 @@ Result Registration::LaunchProcess(u64 title_id, FsStorageId storage_id, u64 lau
g_process_launch_state.out_pid = out_pid;
/* Start a launch, and wait for it to exit. */
+ g_finish_launch_signal.Reset();
g_process_launch_start_event->Signal();
- g_sema_finish_launch.Wait();
+ g_finish_launch_signal.Wait();
return g_process_launch_state.result;
}
diff --git a/stratosphere/pm/source/pm_registration.hpp b/stratosphere/pm/source/pm_registration.hpp
index 47df1ccda..6eb07dd1b 100644
--- a/stratosphere/pm/source/pm_registration.hpp
+++ b/stratosphere/pm/source/pm_registration.hpp
@@ -170,7 +170,10 @@ class Registration {
u64* out_pid;
Result result;
};
-
+ private:
+ static Result LaunchProcess(u64 *out_pid, const TidSid tid_sid, const u64 launch_flags);
+ public:
+ /* TODO: Better evaluate public vs private API. */
static void InitializeSystemResources();
static IWaitable *GetProcessLaunchStartEvent();
static ProcessList &GetProcessList();
@@ -203,7 +206,7 @@ class Registration {
static void SignalBootFinished();
- static bool HasApplicationProcess(std::shared_ptr *out);
+ static bool HasApplicationProcess(std::shared_ptr *out = nullptr);
};
#include "pm_process_wait.hpp"
diff --git a/stratosphere/pm/source/pm_resource_limits.cpp b/stratosphere/pm/source/pm_resource_limits.cpp
index 45d72c653..804ea2961 100644
--- a/stratosphere/pm/source/pm_resource_limits.cpp
+++ b/stratosphere/pm/source/pm_resource_limits.cpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
@@ -81,27 +81,24 @@ static u64 g_system_boost_size = 0;
/* Tries to set Resource limits for a category. */
static Result SetResourceLimits(ResourceLimitUtils::ResourceLimitCategory category, u64 new_memory_size) {
- Result rc = ResultSuccess;
u64 old_memory_size = g_resource_limits[category][LimitableResource_Memory];
g_resource_limits[category][LimitableResource_Memory] = new_memory_size;
for (unsigned int r = 0; r < 5; r++) {
- if (R_FAILED((rc = svcSetResourceLimitLimitValue(g_resource_limit_handles[category], (LimitableResource)r, g_resource_limits[category][r])))) {
+ R_TRY_CLEANUP(svcSetResourceLimitLimitValue(g_resource_limit_handles[category], (LimitableResource)r, g_resource_limits[category][r]), {
g_resource_limits[category][LimitableResource_Memory] = old_memory_size;
- return rc;
- }
+ });
}
- return rc;
+ return ResultSuccess;
}
static Result SetNewMemoryResourceLimit(ResourceLimitUtils::ResourceLimitCategory category, u64 new_memory_size) {
- Result rc = ResultSuccess;
u64 old_memory_size = g_resource_limits[category][LimitableResource_Memory];
g_resource_limits[category][LimitableResource_Memory] = new_memory_size;
- if (R_FAILED((rc = svcSetResourceLimitLimitValue(g_resource_limit_handles[category], LimitableResource_Memory, g_resource_limits[category][LimitableResource_Memory])))) {
+ R_TRY_CLEANUP(svcSetResourceLimitLimitValue(g_resource_limit_handles[category], LimitableResource_Memory, g_resource_limits[category][LimitableResource_Memory]), {
g_resource_limits[category][LimitableResource_Memory] = old_memory_size;
- }
- return rc;
+ });
+ return ResultSuccess;
}
void ResourceLimitUtils::InitializeLimits() {
@@ -133,39 +130,39 @@ void ResourceLimitUtils::InitializeLimits() {
memcpy(&g_memory_resource_limits, &g_memory_resource_limits_deprecated, sizeof(g_memory_resource_limits_deprecated));
memcpy(&g_resource_limits, &g_resource_limits_deprecated, sizeof(g_resource_limits));
}
-
+
/* 7.0.0+: Nintendo restricts the number of system threads here, from 0x260 -> 0x60. */
/* We will not do this. */
-
+
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_600) {
/* NOTE: 5 is a fake type, official code does not do this. */
/* This is done for ease of backwards compatibility. */
g_memory_limit_type = 5;
-
+
/* Starting 6.x, 5 MB of memory is always reserved for system. */
const u64 reserved_system_size_6x = 0x500000;
-
+
/* Get total memory available. */
u64 total_memory = 0;
if (R_FAILED(svcGetResourceLimitLimitValue(&total_memory, g_resource_limit_handles[0], LimitableResource_Memory))) {
std::abort();
}
-
+
/* Get and save application + applet memory. */
if (R_FAILED(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][1], 0, 0, 0)) ||
R_FAILED(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][2], 0, 0, 1))) {
std::abort();
}
-
+
const u64 application_size = g_memory_resource_limits[g_memory_limit_type][1];
const u64 applet_size = g_memory_resource_limits[g_memory_limit_type][2];
const u64 reserved_nonsys_size = (application_size + applet_size + reserved_system_size_6x);
-
+
/* Ensure there's enough memory for system region. */
if (reserved_nonsys_size > total_memory) {
std::abort();
}
-
+
/* Set System memory. */
g_memory_resource_limits[g_memory_limit_type][0] = total_memory - (reserved_nonsys_size);
} else {
@@ -249,49 +246,32 @@ Handle ResourceLimitUtils::GetResourceLimitHandleByCategory(ResourceLimitCategor
}
Result ResourceLimitUtils::BoostSystemMemoryResourceLimit(u64 boost_size) {
- Result rc = ResultSuccess;
if (boost_size > g_memory_resource_limits[g_memory_limit_type][ResourceLimitCategory_Application]) {
return ResultPmInvalidSize;
}
+
u64 app_size = g_memory_resource_limits[g_memory_limit_type][ResourceLimitCategory_Application] - boost_size;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (boost_size < g_system_boost_size) {
- if (R_FAILED((rc = svcSetUnsafeLimit(boost_size)))) {
- return rc;
- }
- if (R_FAILED((rc = SetNewMemoryResourceLimit(ResourceLimitCategory_Application, app_size)))) {
- return rc;
- }
+ R_TRY(svcSetUnsafeLimit(boost_size));
+ R_TRY(SetNewMemoryResourceLimit(ResourceLimitCategory_Application, app_size));
} else {
- if (R_FAILED((rc = SetNewMemoryResourceLimit(ResourceLimitCategory_Application, app_size)))) {
- return rc;
- }
- if (R_FAILED((rc = svcSetUnsafeLimit(boost_size)))) {
- return rc;
- }
+ R_TRY(SetNewMemoryResourceLimit(ResourceLimitCategory_Application, app_size));
+ R_TRY(svcSetUnsafeLimit(boost_size));
}
} else if (GetRuntimeFirmwareVersion() >= FirmwareVersion_400) {
u64 sys_size = g_memory_resource_limits[g_memory_limit_type][ResourceLimitCategory_System] + boost_size;
if (boost_size < g_system_boost_size) {
- if (R_FAILED((rc = SetResourceLimits(ResourceLimitCategory_System, sys_size)))) {
- return rc;
- }
- if (R_FAILED((rc = SetResourceLimits(ResourceLimitCategory_Application, app_size)))) {
- return rc;
- }
+ R_TRY(SetResourceLimits(ResourceLimitCategory_System, sys_size));
+ R_TRY(SetResourceLimits(ResourceLimitCategory_Application, app_size));
} else {
- if (R_FAILED((rc = SetResourceLimits(ResourceLimitCategory_Application, app_size)))) {
- return rc;
- }
- if (R_FAILED((rc = SetResourceLimits(ResourceLimitCategory_System, sys_size)))) {
- return rc;
- }
+ R_TRY(SetResourceLimits(ResourceLimitCategory_Application, app_size));
+ R_TRY(SetResourceLimits(ResourceLimitCategory_System, sys_size));
}
} else {
- rc = ResultKernelConnectionClosed;
+ return ResultKernelConnectionClosed;
}
- if (R_SUCCEEDED(rc)) {
- g_system_boost_size = boost_size;
- }
- return rc;
+
+ g_system_boost_size = boost_size;
+ return ResultSuccess;
}
diff --git a/stratosphere/pm/source/pm_resource_limits.hpp b/stratosphere/pm/source/pm_resource_limits.hpp
index b5558fd0e..58bb9ebc1 100644
--- a/stratosphere/pm/source/pm_resource_limits.hpp
+++ b/stratosphere/pm/source/pm_resource_limits.hpp
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#pragma once
#include
#include