so bascially rosalina's image...

was in BASE (hardcoded by kernel) while its heaps were in SYSTEM. Fix this; also put the kext where BASE was.
This commit is contained in:
TuxSH 2020-05-18 01:15:44 +01:00
parent b02d0346fd
commit adda19ecb2
11 changed files with 47 additions and 14 deletions

View File

@ -110,6 +110,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
struct KExtParameters
{
u32 basePA;
u32 stolenSystemMemRegionSize;
void *originalHandlers[4];
u32 L1MMUTableAddrs[4];
@ -136,8 +137,9 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
static const u8 patternHook3_4[] = {0x00, 0x00, 0xA0, 0xE1, 0x03, 0xF0, 0x20, 0xE3, 0xFD, 0xFF, 0xFF, 0xEA}; //SGI0 setup code, etc.
//Our kernel11 extension is initially loaded in VRAM
u32 kextTotalSize = *(u32 *)0x18000020 - K11EXT_VA;
u32 dstKextPA = (ISN3DS ? 0x2E000000 : 0x26C00000) - kextTotalSize;
//u32 kextTotalSize = *(u32 *)0x18000020 - K11EXT_VA;
u32 stolenSystemMemRegionSize = ISN3DS ? 0 : 0 << 10; // no need to steal any mem on N3DS. Currently, everything fits in BASE on O3DS too (?)
u32 dstKextPA = (ISN3DS ? 0x2E000000 : 0x26C00000) - stolenSystemMemRegionSize; // start of BASE memregion (note: linear heap ---> <--- the rest)
u32 *hookVeneers = (u32 *)*freeK11Space;
u32 relocBase = 0xFFFF0000 + (*freeK11Space - (u8 *)arm11ExceptionsPage);
@ -179,6 +181,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32
struct KExtParameters *p = (struct KExtParameters *)(*(u32 *)0x18000024 - K11EXT_VA + 0x18000000);
p->basePA = dstKextPA;
p->stolenSystemMemRegionSize = stolenSystemMemRegionSize;
for(u32 i = 0; i < 4; i++)
{

View File

@ -133,6 +133,7 @@ typedef struct CfwInfo
extern CfwInfo cfwInfo;
extern u32 kextBasePa;
extern u32 stolenSystemMemRegionSize;
extern vu32 rosalinaState;
extern bool hasStartedRosalinaNetworkFuncsOnce;

View File

@ -1126,11 +1126,11 @@ typedef union KCacheMaintenanceInterruptEvent
typedef struct FcramLayout
{
void *applicationAddr;
u32 applicationAddr;
u32 applicationSize;
void *systemAddr;
u32 systemAddr;
u32 systemSize;
void *baseAddr;
u32 baseAddr;
u32 baseSize;
} FcramLayout;

View File

@ -109,6 +109,7 @@ void (*coreBarrier)(void);
CfwInfo cfwInfo;
u32 kextBasePa;
u32 stolenSystemMemRegionSize;
vu32 rosalinaState;
bool hasStartedRosalinaNetworkFuncsOnce;

View File

@ -37,6 +37,7 @@
struct KExtParameters
{
u32 basePA;
u32 stolenSystemMemRegionSize;
void *originalHandlers[4];
u32 L1MMUTableAddrs[4];
@ -261,7 +262,14 @@ void main(FcramLayout *layout, KCoreContext *ctxs)
u32 TTBCR_;
s64 nb;
layout->systemSize -= __end__ - __start__;
cfwInfo = p->cfwInfo;
kextBasePa = p->basePA;
stolenSystemMemRegionSize = p->stolenSystemMemRegionSize;
u32 kextSize = (u32)(__end__ - __start__);
layout->systemSize -= stolenSystemMemRegionSize;
layout->baseAddr = layout->baseAddr - stolenSystemMemRegionSize + kextSize;
layout->baseSize = layout->baseSize + stolenSystemMemRegionSize - kextSize;
fcramLayout = *layout;
coreCtxs = ctxs;
@ -270,8 +278,6 @@ void main(FcramLayout *layout, KCoreContext *ctxs)
isN3DS = getNumberOfCores() == 4;
memcpy(L1MMUTableAddrs, (const void *)p->L1MMUTableAddrs, 16);
exceptionStackTop = (u32 *)0xFFFF2000 + (1 << (32 - TTBCR - 20));
cfwInfo = p->cfwInfo;
kextBasePa = p->basePA;
memcpy(originalHandlers + 1, p->originalHandlers, 16);
void **arm11SvcTable = (void**)originalHandlers[2];

View File

@ -82,6 +82,10 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
*out = (s64)(((u64)kextBasePa << 32) | (u64)(__end__ - __start__));
break;
case 0x301: // stolen SYSTEM memory size
*out = stolenSystemMemRegionSize;
break;
default:
*out = 0;
res = 0xF8C007F4; // not implemented

View File

@ -3,11 +3,24 @@
#include "luma.h"
#include "util.h"
bool hasKExt(void)
{
s64 val;
return svcGetSystemInfo(&val, 0x20000, 0) == 1;
}
u32 getKExtSize(void)
{
s64 val;
Result res = svcGetSystemInfo(&val, 0x10000, 0x300);
return R_FAILED(res) ? 0 : (u32)val;
svcGetSystemInfo(&val, 0x10000, 0x300);
return (u32)val;
}
u32 getStolenSystemMemRegionSize(void)
{
s64 val;
svcGetSystemInfo(&val, 0x10000, 0x301);
return (u32)val;
}
bool isTitleLaunchPrevented(u64 titleId)

View File

@ -2,5 +2,7 @@
#include <3ds/types.h>
bool hasKExt(void);
u32 getKExtSize(void);
bool isTitleLaunchPrevented(u64 titleId);
u32 getStolenSystemMemRegionSize(void);
bool isTitleLaunchPrevented(u64 titleId);

View File

@ -243,7 +243,10 @@ static ReslimitValues *fixupReslimitValues(void)
{
// In order: APPLICATION, SYS_APPLET, LIB_APPLET, OTHER
// Fixup "commit" reslimit
u32 sysmemalloc = SYSMEMALLOC + getKExtSize();
// Note: we lie in the reslimit and make as if neither KExt nor Roslina existed, to avoid breakage
u32 sysmemalloc = SYSMEMALLOC + (hasKExt() ? getStolenSystemMemRegionSize() : 0);
ReslimitValues *values = !IS_N3DS ? g_o3dsReslimitValues : g_n3dsReslimitValues;
static const u32 minAppletMemAmount = 0x1200000;

View File

@ -37,7 +37,7 @@ AccessControlInfo:
CoreVersion : 2
DescVersion : 2
MemoryType : System # Application / System / Base
MemoryType : Base # Application / System / Base
HandleTableSize: 150
MemoryMapping:

View File

@ -62,7 +62,7 @@ Menu rosalinaMenu = {
bool rosalinaMenuShouldShowDebugInfo(void)
{
return false;
return true;
}
void RosalinaMenu_ShowDebugInfo(void)