From 19d68b6df4c58bd482544928bf67e2171a52ad70 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Wed, 14 Jun 2017 01:29:55 +0200 Subject: [PATCH] Adjust config mem values --- k11_extension/include/globals.h | 5 +++++ k11_extension/include/kernel.h | 10 ++++++++++ k11_extension/source/globals.c | 4 ++++ k11_extension/source/main.c | 12 +++++++----- k11_extension/source/start.s | 10 +--------- k11_extension/source/svc.c | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/k11_extension/include/globals.h b/k11_extension/include/globals.h index ae014e4..f575bd1 100644 --- a/k11_extension/include/globals.h +++ b/k11_extension/include/globals.h @@ -94,8 +94,13 @@ extern bool *isDevUnit; extern vu8 *configPage; extern u32 kernelVersion; +extern FcramLayout fcramLayout; + +extern void *originalHandlers[8]; extern u32 nbSection0Modules; +extern u8 __start__[], __end__[], __bss_start__[], __bss_end__[]; + extern Result (*InterruptManager__MapInterrupt)(InterruptManager *manager, KBaseInterruptEvent *iEvent, u32 interruptID, u32 coreID, u32 priority, bool disableUponReceipt, bool levelHighActive); extern InterruptManager *interruptManager; diff --git a/k11_extension/include/kernel.h b/k11_extension/include/kernel.h index bf64b39..75d8710 100644 --- a/k11_extension/include/kernel.h +++ b/k11_extension/include/kernel.h @@ -1123,6 +1123,16 @@ typedef union KCacheMaintenanceInterruptEvent KCacheMaintenanceInterruptEventO3DS O3DS; } KCacheMaintenanceInterruptEvent; +typedef struct FcramLayout +{ + void *applicationAddr; + u32 applicationSize; + void *systemAddr; + u32 systemSize; + void *baseAddr; + u32 baseSize; +} FcramLayout; + extern bool isN3DS; extern void *officialSVCs[0x7E]; diff --git a/k11_extension/source/globals.c b/k11_extension/source/globals.c index 63e55f6..2978e4c 100644 --- a/k11_extension/source/globals.c +++ b/k11_extension/source/globals.c @@ -90,6 +90,10 @@ bool *isDevUnit; vu8 *configPage; u32 kernelVersion; +FcramLayout fcramLayout; + +void *originalHandlers[8] = {NULL}; + u32 nbSection0Modules; Result (*InterruptManager__MapInterrupt)(InterruptManager *manager, KBaseInterruptEvent *iEvent, u32 interruptID, diff --git a/k11_extension/source/main.c b/k11_extension/source/main.c index 3c08f93..40a65f6 100644 --- a/k11_extension/source/main.c +++ b/k11_extension/source/main.c @@ -33,10 +33,6 @@ #include "svcHandler.h" #include "memory.h" -void *originalHandlers[8] = {NULL}; - -extern u8 __start__[], __end__[], __bss_start__[], __bss_end__[]; - struct KExtParameters { u32 ALIGN(0x400) L2MMUTableFor0x40000000[256]; @@ -94,6 +90,9 @@ void configHook(vu8 *cfgPage) configPage = cfgPage; kernelVersion = *(vu32 *)configPage; + *(vu32 *)(configPage + 0x40) = fcramLayout.applicationSize; + *(vu32 *)(configPage + 0x44) = fcramLayout.systemSize; + *(vu32 *)(configPage + 0x48) = fcramLayout.baseSize; *isDevUnit = true; // enable debug features } @@ -248,12 +247,15 @@ static void findUsefulSymbols(void) } } -void main(void) +void main(FcramLayout *layout) { struct KExtParameters *p = &kExtParameters; u32 TTBCR_; s64 nb; + layout->systemSize -= __end__ - __start__; + fcramLayout = *layout; + __asm__ volatile("mrc p15, 0, %0, c2, c0, 2" : "=r"(TTBCR_)); TTBCR = TTBCR_; isN3DS = getNumberOfCores() == 4; diff --git a/k11_extension/source/start.s b/k11_extension/source/start.s index c1e970f..02d25e6 100644 --- a/k11_extension/source/start.s +++ b/k11_extension/source/start.s @@ -49,15 +49,7 @@ start: push {r0-r12, lr} - @ Adjust the size of the SYSTEM memregion - sub r4, #8 - ldr r0, [r4, #0xC] - ldr r1, =__end__ - ldr r2, =__start__ - sub r1, r2 - sub r0, r1 - str r0, [r4, #0xC] - + sub r0, r4, #8 bl main pop {r0-r12, pc} diff --git a/k11_extension/source/svc.c b/k11_extension/source/svc.c index fe0f38f..d4ca18a 100644 --- a/k11_extension/source/svc.c +++ b/k11_extension/source/svc.c @@ -24,6 +24,7 @@ * reasonable ways as different from the original version. */ +#include "memory.h" #include "svc.h" #include "svc/ControlMemory.h" #include "svc/GetProcessInfo.h" @@ -87,6 +88,8 @@ void signalSvcReturn(u8 *pageEnd) SignalDebugEvent(DBGEVENT_OUTPUT_STRING, 0xFFFFFFFF, svcId); } +static bool doingVeryShittyPmResLimitWorkaround = false; // I feel dirty + void *svcHook(u8 *pageEnd) { KProcess *currentProcess = currentCoreContext->objectContext.currentProcess; @@ -98,6 +101,13 @@ 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 0x2A: return GetSystemInfoHookWrapper; case 0x2B: @@ -116,6 +126,13 @@ 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: