From cf510ad9bf232865ee20d84402d43062cb46f3c3 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 8 Nov 2018 05:28:52 -0800 Subject: [PATCH] pm: Only register privileged processes with FS as needed --- stratosphere/pm/pm.json | 1 + stratosphere/pm/source/pm_main.cpp | 18 +++++++++++++++--- stratosphere/pm/source/pm_registration.cpp | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/stratosphere/pm/pm.json b/stratosphere/pm/pm.json index 0fd963c2b..af1a699c6 100644 --- a/stratosphere/pm/pm.json +++ b/stratosphere/pm/pm.json @@ -65,6 +65,7 @@ "svcReplyAndReceiveWithUserBuffer": "0x44", "svcCreateEvent": "0x45", "svcSetUnsafeLimit": "0x4a", + "svcGetProcessList": "0x65", "svcStartProcess": "0x7a", "svcTerminateProcess": "0x7b", "svcGetProcessInfo": "0x7c", diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 07f9fc2ec..ac3abde53 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -65,9 +65,21 @@ void RegisterPrivilegedProcessesWithFs() { const u32 PRIVILEGED_FAH[0x1C/sizeof(u32)] = {0x00000001, 0x00000000, 0x80000000, 0x0000001C, 0x00000000, 0x0000001C, 0x00000000}; const u32 PRIVILEGED_FAC[0x2C/sizeof(u32)] = {0x00000001, 0x00000000, 0x80000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF}; - for (u64 pid = PRIVILEGED_PROCESS_MIN; pid <= PRIVILEGED_PROCESS_MAX; pid++) { - fsprUnregisterProgram(pid); - fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC)); + u32 num_pids; + u64 pids[PRIVILEGED_PROCESS_MAX+1]; + if (R_SUCCEEDED(svcGetProcessList(&num_pids, pids, sizeof(pids)/sizeof(pids[0])))) { + for (u32 i = 0; i < num_pids; i++) { + const u64 pid = pids[i]; + if (PRIVILEGED_PROCESS_MIN <= pid && pid <= PRIVILEGED_PROCESS_MAX) { + fsprUnregisterProgram(pid); + fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC)); + } + } + } else { + for (u64 pid = PRIVILEGED_PROCESS_MIN; pid <= PRIVILEGED_PROCESS_MAX; pid++) { + fsprUnregisterProgram(pid); + fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC)); + } } } diff --git a/stratosphere/pm/source/pm_registration.cpp b/stratosphere/pm/source/pm_registration.cpp index 362c47fe5..bf7958dec 100644 --- a/stratosphere/pm/source/pm_registration.cpp +++ b/stratosphere/pm/source/pm_registration.cpp @@ -292,15 +292,15 @@ void Registration::FinalizeExitedProcess(std::shared_ptr bool signal_debug_process_5x = kernelAbove500() && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED; /* Unregister with FS. */ if (R_FAILED(fsprUnregisterProgram(process->pid))) { - /* TODO: Panic. */ + std::abort(); } /* Unregister with SM. */ if (R_FAILED(smManagerUnregisterProcess(process->pid))) { - /* TODO: Panic. */ + std::abort(); } /* Unregister with LDR. */ if (R_FAILED(ldrPmUnregisterTitle(process->ldr_queue_index))) { - /* TODO: Panic. */ + std::abort(); } /* Close the process's handle. */