diff --git a/k11_extension/source/svc.c b/k11_extension/source/svc.c index 50ac06d..088f82d 100644 --- a/k11_extension/source/svc.c +++ b/k11_extension/source/svc.c @@ -84,8 +84,6 @@ void postprocessSvc(void) officialPostProcessSvc(); } -static bool doingVeryShittyPmResLimitWorkaround = false; // I feel dirty - void *svcHook(u8 *pageEnd) { KProcess *currentProcess = currentCoreContext->objectContext.currentProcess; @@ -97,13 +95,6 @@ void *svcHook(u8 *pageEnd) { case 0x01: return ControlMemoryHookWrapper; - case 0x17: - if(strcmp(codeSetOfProcess(currentProcess)->processName, "pm") == 0) // only called twice in pm, by the same function - { - *(vu32 *)(configPage + 0x44) += __end__ - __start__; - doingVeryShittyPmResLimitWorkaround = true; - } - return officialSVCs[0x17]; case 0x29: return GetHandleInfoHookWrapper; case 0x2A: @@ -124,13 +115,6 @@ void *svcHook(u8 *pageEnd) return SetGpuProt; case 0x5A: return SetWifiEnabled; - case 0x79: - if(doingVeryShittyPmResLimitWorkaround) - { - *(vu32 *)(configPage + 0x44) -= __end__ - __start__; - doingVeryShittyPmResLimitWorkaround = false; - } - return officialSVCs[0x79]; case 0x7B: return Backdoor; case 0x7C: diff --git a/sysmodules/loader/source/loader.c b/sysmodules/loader/source/loader.c index 3e51ee0..524af07 100644 --- a/sysmodules/loader/source/loader.c +++ b/sysmodules/loader/source/loader.c @@ -28,26 +28,6 @@ static u64 g_cached_prog_handle; static ExHeader_Info g_exheader; static char g_ret_buf[1024]; -// MAKE SURE fsreg has been init before calling this -static Result fsldrPatchPermissions(void) -{ - u32 pid; - Result res; - FS_ProgramInfo info; - ExHeader_Arm11StorageInfo storageInfo = { - .fs_access_info = FSACCESS_NANDRW | FSACCESS_NANDRO_RO | FSACCESS_SDMC_RW, - }; - - info.programId = 0x0004013000001302LL; // loader PID - info.mediaType = MEDIATYPE_NAND; - res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE); - if (R_SUCCEEDED(res)) - { - res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo); - } - return res; -} - static inline void loadCFWInfo(void) { s64 out; @@ -585,8 +565,10 @@ void __appInit() svcBreak(USERBREAK_PANIC); } - fsRegInit(); - fsldrPatchPermissions(); + // Wait for pm to call fs:REG Register on us + bool registered = false; + while (srvIsServiceRegistered(®istered, "pm:app"), registered) + svcSleepThread(500 * 1000LL); //fsldrInit(); res = srvGetServiceHandle(fsGetSessionHandle(), "fs:LDR"); diff --git a/sysmodules/loader/source/patcher.c b/sysmodules/loader/source/patcher.c index b1c551f..9fbfee6 100644 --- a/sysmodules/loader/source/patcher.c +++ b/sysmodules/loader/source/patcher.c @@ -737,17 +737,6 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro memset(start, 0, end - start); } - - s64 nbSection0Modules; - svcGetSystemInfo(&nbSection0Modules, 26, 0); - - if(nbSection0Modules == 6) - { - // Makes ErrDisp to not start up - static const u64 errDispTid = 0x0004003000008A02ULL; - u32 *errDispTidLoc = (u32 *)memsearch(code, &errDispTid, size, sizeof(errDispTid)); - *(errDispTidLoc - 6) = 0xE3A00000; // mov r0, #0 - } } else if(progId == 0x0004013000001702LL) //CFG diff --git a/sysmodules/pm/source/launch.c b/sysmodules/pm/source/launch.c index acb7abc..8e3b581 100644 --- a/sysmodules/pm/source/launch.c +++ b/sysmodules/pm/source/launch.c @@ -7,6 +7,7 @@ #include "exheader_info_heap.h" #include "task_runner.h" #include "util.h" +#include "luma.h" static inline void removeAccessToService(const char *service, char (*serviceAccessList)[8]) { @@ -204,6 +205,11 @@ static Result loadWithDependencies(Handle *outDebug, ProcessData **outProcessDat static Result launchTitleImpl(Handle *debug, ProcessData **outProcessData, const FS_ProgramInfo *programInfo, const FS_ProgramInfo *programInfoUpdate, u32 launchFlags, ExHeader_Info *exheaderInfo) { + if (isTitleLaunchPrevented(programInfo->programId)) { + *debug = 0; + return 0; + } + if (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION) { launchFlags |= PMLAUNCHFLAG_LOAD_DEPENDENCIES; } else { @@ -299,7 +305,7 @@ static Result launchTitleImplWrapper(Handle *outDebug, u32 *outPid, const FS_Pro ProcessData *process; Result res = launchTitleImpl(outDebug, &process, programInfo, programInfoUpdate, launchFlags, exheaderInfo); - if (outPid != NULL) { + if (outPid != NULL && process != NULL) { *outPid = process->pid; } diff --git a/sysmodules/pm/source/luma.c b/sysmodules/pm/source/luma.c new file mode 100644 index 0000000..b3664c3 --- /dev/null +++ b/sysmodules/pm/source/luma.c @@ -0,0 +1,34 @@ +#include <3ds.h> +#include +#include "luma.h" +#include "util.h" + +u32 getKExtSize(void) +{ + s64 val; + Result res = svcGetSystemInfo(&val, 0x10000, 0x300); + return R_FAILED(res) ? 0 : (u32)val; +} + +bool isTitleLaunchPrevented(u64 titleId) +{ + s64 numKips = 0; + + svcGetSystemInfo(&numKips, 26, 0); + return numKips >= 6 && (titleId & ~N3DS_TID_BIT) == 0x0004003000008A02ULL; // ErrDisp +} + +Result fsRegSetupPermissionsForKip(u32 pid, u64 titleId) +{ + FS_ProgramInfo info; + + ExHeader_Arm11StorageInfo storageInfo = { + .fs_access_info = FSACCESS_NANDRO_RW | FSACCESS_NANDRW | FSACCESS_SDMC_RW, + }; + + // Non-dummy TID + info.programId = titleId; + info.mediaType = MEDIATYPE_NAND; + + return FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo);; +} \ No newline at end of file diff --git a/sysmodules/pm/source/luma.h b/sysmodules/pm/source/luma.h new file mode 100644 index 0000000..f6d46de --- /dev/null +++ b/sysmodules/pm/source/luma.h @@ -0,0 +1,7 @@ +#pragma once + +#include <3ds/types.h> + +u32 getKExtSize(void); +bool isTitleLaunchPrevented(u64 titleId); +Result fsRegSetupPermissionsForKip(u32 pid, u64 titleId); \ No newline at end of file diff --git a/sysmodules/pm/source/manager.c b/sysmodules/pm/source/manager.c index f75efb8..ddc5834 100644 --- a/sysmodules/pm/source/manager.c +++ b/sysmodules/pm/source/manager.c @@ -3,6 +3,7 @@ #include "manager.h" #include "reslimit.h" #include "util.h" +#include "luma.h" Manager g_manager; @@ -41,6 +42,13 @@ void Manager_RegisterKips(void) } ProcessList_Unlock(&g_manager.processList); + + // Register loader, pm, and rosalina (if applicable) + assertSuccess(fsRegSetupPermissionsForKip(1, 0x0004013000001302LL)); // loader + assertSuccess(fsRegSetupPermissionsForKip(2, 0x0004013000001202LL)); // pm + if (numKips >= 6) { + assertSuccess(fsRegSetupPermissionsForKip(5, 0x0004013000006902LL)); // rosalina + } } Result UnregisterProcess(u64 titleId) diff --git a/sysmodules/pm/source/reslimit.c b/sysmodules/pm/source/reslimit.c index ff6249f..0e3d0f9 100644 --- a/sysmodules/pm/source/reslimit.c +++ b/sysmodules/pm/source/reslimit.c @@ -2,6 +2,7 @@ #include "reslimit.h" #include "util.h" #include "manager.h" +#include "luma.h" typedef s64 ReslimitValues[10]; @@ -242,7 +243,7 @@ static ReslimitValues *fixupReslimitValues(void) { // In order: APPLICATION, SYS_APPLET, LIB_APPLET, OTHER // Fixup "commit" reslimit - u32 sysmemalloc = SYSMEMALLOC; + u32 sysmemalloc = SYSMEMALLOC + getKExtSize(); ReslimitValues *values = !IS_N3DS ? g_o3dsReslimitValues : g_n3dsReslimitValues; static const u32 minAppletMemAmount = 0x1200000; diff --git a/sysmodules/rosalina/source/main.c b/sysmodules/rosalina/source/main.c index 32b6638..096421f 100644 --- a/sysmodules/rosalina/source/main.c +++ b/sysmodules/rosalina/source/main.c @@ -37,39 +37,6 @@ #include "menus/miscellaneous.h" #include "menus/screen_filters.h" -static Result stealFsReg(void) -{ - Result ret = 0; - - ret = svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, fsRegGetSessionHandle(), "fs:REG"); - while(ret == 0x9401BFE) - { - svcSleepThread(500 * 1000LL); - ret = svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, fsRegGetSessionHandle(), "fs:REG"); - } - - return ret; -} - -static Result fsRegSetupPermissions(void) -{ - u32 pid; - Result res; - FS_ProgramInfo info; - - ExHeader_Arm11StorageInfo storageInfo = { - .fs_access_info = FSACCESS_NANDRO_RW | FSACCESS_NANDRW | FSACCESS_SDMC_RW, - }; - - info.programId = 0x0004013000006902LL; // Rosalina TID - info.mediaType = MEDIATYPE_NAND; - - if(R_SUCCEEDED(res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE))) - res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo); - - return res; -} - // this is called before main bool isN3DS; void __appInit() @@ -82,7 +49,12 @@ void __appInit() svcBreak(USERBREAK_PANIC); } - if (R_FAILED(stealFsReg()) || R_FAILED(fsRegSetupPermissions()) || R_FAILED(fsInit())) + // Wait for pm to call fs:REG Register on us + bool registered = false; + while (srvIsServiceRegistered(®istered, "pm:app"), registered) + svcSleepThread(500 * 1000LL); + + if (R_FAILED(fsInit())) svcBreak(USERBREAK_PANIC); }