Skip to content

Commit cf510ad

Browse files
committed
pm: Only register privileged processes with FS as needed
1 parent 9898a01 commit cf510ad

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

stratosphere/pm/pm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"svcReplyAndReceiveWithUserBuffer": "0x44",
6666
"svcCreateEvent": "0x45",
6767
"svcSetUnsafeLimit": "0x4a",
68+
"svcGetProcessList": "0x65",
6869
"svcStartProcess": "0x7a",
6970
"svcTerminateProcess": "0x7b",
7071
"svcGetProcessInfo": "0x7c",

stratosphere/pm/source/pm_main.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,21 @@ void RegisterPrivilegedProcessesWithFs() {
6565
const u32 PRIVILEGED_FAH[0x1C/sizeof(u32)] = {0x00000001, 0x00000000, 0x80000000, 0x0000001C, 0x00000000, 0x0000001C, 0x00000000};
6666
const u32 PRIVILEGED_FAC[0x2C/sizeof(u32)] = {0x00000001, 0x00000000, 0x80000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF};
6767

68-
for (u64 pid = PRIVILEGED_PROCESS_MIN; pid <= PRIVILEGED_PROCESS_MAX; pid++) {
69-
fsprUnregisterProgram(pid);
70-
fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC));
68+
u32 num_pids;
69+
u64 pids[PRIVILEGED_PROCESS_MAX+1];
70+
if (R_SUCCEEDED(svcGetProcessList(&num_pids, pids, sizeof(pids)/sizeof(pids[0])))) {
71+
for (u32 i = 0; i < num_pids; i++) {
72+
const u64 pid = pids[i];
73+
if (PRIVILEGED_PROCESS_MIN <= pid && pid <= PRIVILEGED_PROCESS_MAX) {
74+
fsprUnregisterProgram(pid);
75+
fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC));
76+
}
77+
}
78+
} else {
79+
for (u64 pid = PRIVILEGED_PROCESS_MIN; pid <= PRIVILEGED_PROCESS_MAX; pid++) {
80+
fsprUnregisterProgram(pid);
81+
fsprRegisterProgram(pid, pid, FsStorageId_NandSystem, PRIVILEGED_FAH, sizeof(PRIVILEGED_FAH), PRIVILEGED_FAC, sizeof(PRIVILEGED_FAC));
82+
}
7183
}
7284
}
7385

stratosphere/pm/source/pm_registration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ void Registration::FinalizeExitedProcess(std::shared_ptr<Registration::Process>
292292
bool signal_debug_process_5x = kernelAbove500() && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED;
293293
/* Unregister with FS. */
294294
if (R_FAILED(fsprUnregisterProgram(process->pid))) {
295-
/* TODO: Panic. */
295+
std::abort();
296296
}
297297
/* Unregister with SM. */
298298
if (R_FAILED(smManagerUnregisterProcess(process->pid))) {
299-
/* TODO: Panic. */
299+
std::abort();
300300
}
301301
/* Unregister with LDR. */
302302
if (R_FAILED(ldrPmUnregisterTitle(process->ldr_queue_index))) {
303-
/* TODO: Panic. */
303+
std::abort();
304304
}
305305

306306
/* Close the process's handle. */

0 commit comments

Comments
 (0)