loader/pm: move "force init SD" code to pm. Greatly reduces the number of Arm9 svcBreak with 0xC8804465

This commit is contained in:
TuxSH 2020-04-27 00:47:16 +01:00
parent 9d62995799
commit f334e3b951
5 changed files with 48 additions and 8 deletions

View File

@ -6,7 +6,7 @@
#include "hbldr.h"
extern u32 config, multiConfig, bootConfig;
extern bool isN3DS, needToInitSd, isSdMode;
extern bool isN3DS, isSdMode;
static u8 g_ret_buf[sizeof(ExHeader_Info)];
static u64 g_cached_programHandle;

View File

@ -7,7 +7,7 @@
#include "service_manager.h"
u32 config, multiConfig, bootConfig;
bool isN3DS, needToInitSd, isSdMode;
bool isN3DS, isSdMode;
// MAKE SURE fsreg has been init before calling this
static Result fsldrPatchPermissions(void)
@ -38,13 +38,10 @@ static inline void loadCFWInfo(void)
assertSuccess(svcGetSystemInfo(&out, 0x10000, 0x201));
isN3DS = (bool)out;
assertSuccess(svcGetSystemInfo(&out, 0x10000, 0x202));
needToInitSd = (bool)out;
//assertSuccess(svcGetSystemInfo(&out, 0x10000, 0x202));
//needToInitSd = (bool)out;
assertSuccess(svcGetSystemInfo(&out, 0x10000, 0x203));
isSdMode = (bool)out;
IFile file;
if(needToInitSd) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted
}
void __ctru_exit(int rc) { (void)rc; } // needed to avoid linking error

View File

@ -39,7 +39,7 @@ enum singleOptions
};
extern u32 config, multiConfig, bootConfig;
extern bool isN3DS, needToInitSd, isSdMode;
extern bool isN3DS, isSdMode;
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress);
Result fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags);

View File

@ -117,7 +117,11 @@ AccessControlInfo:
ServiceAccessControl:
# Note: pm also uses srv:pm and Loader but doesn't list them here.
- fs:REG
# Custom:
- fs:USER
FileSystemAccess:
# Custom
- DirectSdmc
SystemControlInfo:
SaveDataSize: 0KB # It doesn't use any save data.

View File

@ -6,6 +6,35 @@
#include "exheader_info_heap.h"
#include "task_runner.h"
static Result fsRegSetupPermissions(void)
{
u32 pid;
Result res;
FS_ProgramInfo info;
ExHeader_Arm11StorageInfo storageInfo = {
.fs_access_info = FSACCESS_SDMC_RW,
};
info.programId = 0x0004013000001202LL; // PM's TID
info.mediaType = MEDIATYPE_NAND;
if(R_SUCCEEDED(res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE)))
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo);
return res;
}
void forceMountSdCard(void)
{
FS_Archive sdmcArchive;
assertSuccess(fsRegSetupPermissions());
assertSuccess(fsInit());
assertSuccess(FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")));
// No need to clean up things as we will firmlaunch straight away
}
static Result terminateUnusedDependencies(const u64 *dependencies, u32 numDeps)
{
ProcessData *process;
@ -315,6 +344,16 @@ ProcessData *terminateAllProcesses(u32 callerPid, s64 timeout)
commitPendingTerminations(timeoutTicks >= 0 ? ticksToNs(timeoutTicks) : 0LL);
g_manager.waitingForTermination = false;
if (callerPid == (u32)-1) {
// On firmlaunch, try to force Process9 to mount the SD card to allow the Process9 firmlaunch patch to load boot.firm if needed
// Need to do that before we tell PXI to terminate
s64 out;
if(R_SUCCEEDED(svcGetSystemInfo(&out, 0x10000, 0x203)) && out != 0) {
// If boot.firm is on the SD card, then...
forceMountSdCard();
}
}
// Now, send termination notification to PXI (PID 4). Also do the same for Rosalina.
assertSuccess(svcClearEvent(g_manager.allNotifiedTerminationEvent));
g_manager.waitingForTermination = true;