Added Rosalina, see details
- see release notes - ( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°) - (∩ ͡° ͜ʖ ͡°)⊃━☆゚ - ( ͡ᵔ ͜ʖ ͡ᵔ) ♫┌( ͡° ͜ʖ ͡°)┘♪ ♫└( ͡° ͜ʖ ͡°)┐♪
This commit is contained in:
@@ -102,6 +102,7 @@ AccessControlInfo:
|
||||
UnmapMemoryBlock: 32
|
||||
WaitSynchronization1: 36
|
||||
WaitSynchronizationN: 37
|
||||
KernelSetState: 124
|
||||
InterruptNumbers:
|
||||
ServiceAccessControl:
|
||||
- fs:LDR
|
||||
@@ -112,4 +113,4 @@ AccessControlInfo:
|
||||
SystemControlInfo:
|
||||
SaveDataSize: 0KB # It doesn't use any save data.
|
||||
RemasterVersion: 0
|
||||
StackSize: 0x1000
|
||||
StackSize: 0x1000
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
char magic[4];
|
||||
|
||||
u8 versionMajor;
|
||||
u8 versionMinor;
|
||||
u8 versionBuild;
|
||||
u8 flags;
|
||||
|
||||
u32 commitHash;
|
||||
|
||||
u32 config;
|
||||
} CFWInfo;
|
||||
|
||||
u32 svcGetCFWInfo(CFWInfo *info);
|
||||
@@ -1,9 +0,0 @@
|
||||
.text
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
.global svcGetCFWInfo
|
||||
.type svcGetCFWInfo, %function
|
||||
svcGetCFWInfo:
|
||||
svc 0x2e
|
||||
bx lr
|
||||
@@ -4,94 +4,96 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 reserved[5];
|
||||
u8 flag;
|
||||
u8 remasterversion[2];
|
||||
u8 reserved[5];
|
||||
u8 flag;
|
||||
u8 remasterversion[2];
|
||||
} PACKED exheader_systeminfoflags;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 address;
|
||||
u32 nummaxpages;
|
||||
u32 codesize;
|
||||
u32 address;
|
||||
u32 nummaxpages;
|
||||
u32 codesize;
|
||||
} PACKED exheader_codesegmentinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 name[8];
|
||||
exheader_systeminfoflags flags;
|
||||
exheader_codesegmentinfo text;
|
||||
u8 stacksize[4];
|
||||
exheader_codesegmentinfo ro;
|
||||
u8 reserved[4];
|
||||
exheader_codesegmentinfo data;
|
||||
u32 bsssize;
|
||||
u8 name[8];
|
||||
exheader_systeminfoflags flags;
|
||||
exheader_codesegmentinfo text;
|
||||
u8 stacksize[4];
|
||||
exheader_codesegmentinfo ro;
|
||||
u8 reserved[4];
|
||||
exheader_codesegmentinfo data;
|
||||
u32 bsssize;
|
||||
} PACKED exheader_codesetinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid[0x30];
|
||||
u64 programid[0x30];
|
||||
} PACKED exheader_dependencylist;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 savedatasize[4];
|
||||
u8 reserved[4];
|
||||
u8 jumpid[8];
|
||||
u8 reserved2[0x30];
|
||||
u8 savedatasize[4];
|
||||
u8 reserved[4];
|
||||
u8 jumpid[8];
|
||||
u8 reserved2[0x30];
|
||||
} PACKED exheader_systeminfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 extsavedataid[8];
|
||||
u8 systemsavedataid[8];
|
||||
u8 reserved[8];
|
||||
u8 accessinfo[7];
|
||||
u8 otherattributes;
|
||||
u8 extsavedataid[8];
|
||||
u8 systemsavedataid[8];
|
||||
u8 reserved[8];
|
||||
u8 accessinfo[7];
|
||||
u8 otherattributes;
|
||||
} PACKED exheader_storageinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid;
|
||||
u8 flags[8];
|
||||
u16 resourcelimitdescriptor[0x10];
|
||||
exheader_storageinfo storageinfo;
|
||||
u64 serviceaccesscontrol[0x20];
|
||||
u8 reserved[0x1f];
|
||||
u8 resourcelimitcategory;
|
||||
u64 programid;
|
||||
u32 coreversion;
|
||||
u8 flags[3];
|
||||
u8 priority;
|
||||
u16 resourcelimitdescriptor[0x10];
|
||||
exheader_storageinfo storageinfo;
|
||||
u64 serviceaccesscontrol[0x22];
|
||||
u8 reserved[0xf];
|
||||
u8 resourcelimitcategory;
|
||||
} PACKED exheader_arm11systemlocalcaps;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 descriptors[28];
|
||||
u8 reserved[0x10];
|
||||
u32 descriptors[28];
|
||||
u8 reserved[0x10];
|
||||
} PACKED exheader_arm11kernelcapabilities;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 descriptors[15];
|
||||
u8 descversion;
|
||||
u8 descriptors[15];
|
||||
u8 descversion;
|
||||
} PACKED exheader_arm9accesscontrol;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// systemcontrol info {
|
||||
// coreinfo {
|
||||
exheader_codesetinfo codesetinfo;
|
||||
exheader_dependencylist deplist;
|
||||
// }
|
||||
exheader_systeminfo systeminfo;
|
||||
// }
|
||||
// accesscontrolinfo {
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
// }
|
||||
struct {
|
||||
u8 signature[0x100];
|
||||
u8 ncchpubkeymodulus[0x100];
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
} PACKED accessdesc;
|
||||
// systemcontrol info {
|
||||
// coreinfo {
|
||||
exheader_codesetinfo codesetinfo;
|
||||
exheader_dependencylist deplist;
|
||||
// }
|
||||
exheader_systeminfo systeminfo;
|
||||
// }
|
||||
// accesscontrolinfo {
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
// }
|
||||
struct {
|
||||
u8 signature[0x100];
|
||||
u8 ncchpubkeymodulus[0x100];
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
} PACKED accessdesc;
|
||||
} PACKED exheader_header;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include "pxipm.h"
|
||||
#include "srvsys.h"
|
||||
|
||||
#define MAX_SESSIONS 1
|
||||
#define MAX_SESSIONS 1
|
||||
#define HBLDR_3DSX_TID (*(vu64 *)0x1FF81100)
|
||||
|
||||
const char CODE_PATH[] = {0x01, 0x00, 0x00, 0x00, 0x2E, 0x63, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00};
|
||||
|
||||
@@ -163,13 +164,28 @@ static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int i
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result HBLDR_Init(Handle *session)
|
||||
{
|
||||
Result res;
|
||||
while (1)
|
||||
{
|
||||
res = svcConnectToPort(session, "hb:ldr");
|
||||
if (R_LEVEL(res) != RL_PERMANENT ||
|
||||
R_SUMMARY(res) != RS_NOTFOUND ||
|
||||
R_DESCRIPTION(res) != RD_NOT_FOUND
|
||||
) break;
|
||||
svcSleepThread(500000);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static Result loader_GetProgramInfo(exheader_header *exheader, u64 prog_handle)
|
||||
{
|
||||
Result res;
|
||||
|
||||
if (prog_handle >> 32 == 0xFFFF0000)
|
||||
{
|
||||
return FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
res = FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -178,13 +194,41 @@ static Result loader_GetProgramInfo(exheader_header *exheader, u64 prog_handle)
|
||||
//so use PXIPM if FSREG fails OR returns "info", is the second condition a bug?
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
return PXIPM_GetProgramInfo(exheader, prog_handle);
|
||||
res = PXIPM_GetProgramInfo(exheader, prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
res = FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
// Force always having sdmc:/ and nand:/rw permission
|
||||
exheader->arm11systemlocalcaps.storageinfo.accessinfo[0] |= 0x480;
|
||||
exheader->accessdesc.arm11systemlocalcaps.storageinfo.accessinfo[0] |= 0x480;
|
||||
|
||||
// Tweak 3dsx placeholder title exheader
|
||||
if (exheader->arm11systemlocalcaps.programid == HBLDR_3DSX_TID)
|
||||
{
|
||||
Handle hbldr = 0;
|
||||
res = HBLDR_Init(&hbldr);
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(4,0,2);
|
||||
cmdbuf[1] = IPC_Desc_Buffer(sizeof(*exheader), IPC_BUFFER_RW);
|
||||
cmdbuf[2] = (u32)exheader;
|
||||
res = svcSendSyncRequest(hbldr);
|
||||
svcCloseHandle(hbldr);
|
||||
if (R_SUCCEEDED(res)) {
|
||||
res = cmdbuf[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static Result loader_LoadProcess(Handle *process, u64 prog_handle)
|
||||
@@ -228,6 +272,39 @@ static Result loader_LoadProcess(Handle *process, u64 prog_handle)
|
||||
return MAKERESULT(RL_PERMANENT, RS_INVALIDARG, 1, 2);
|
||||
}
|
||||
|
||||
// check for 3dsx process
|
||||
progid = g_exheader.arm11systemlocalcaps.programid;
|
||||
if (progid == HBLDR_3DSX_TID)
|
||||
{
|
||||
Handle hbldr = 0;
|
||||
res = HBLDR_Init(&hbldr);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(1,6,0);
|
||||
cmdbuf[1] = g_exheader.codesetinfo.text.address;
|
||||
cmdbuf[2] = flags & 0xF00;
|
||||
cmdbuf[3] = progid;
|
||||
cmdbuf[4] = progid>>32;
|
||||
memcpy(&cmdbuf[5], g_exheader.codesetinfo.name, 8);
|
||||
res = svcSendSyncRequest(hbldr);
|
||||
svcCloseHandle(hbldr);
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
res = cmdbuf[1];
|
||||
}
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
codeset = (Handle)cmdbuf[3];
|
||||
res = svcCreateProcess(process, codeset, g_exheader.arm11kernelcaps.descriptors, count);
|
||||
svcCloseHandle(codeset);
|
||||
return res;
|
||||
}
|
||||
|
||||
// allocate process memory
|
||||
vaddr.text_addr = g_exheader.codesetinfo.text.address;
|
||||
vaddr.text_size = (g_exheader.codesetinfo.text.codesize + 4095) >> 12;
|
||||
@@ -243,7 +320,6 @@ static Result loader_LoadProcess(Handle *process, u64 prog_handle)
|
||||
}
|
||||
|
||||
// load code
|
||||
progid = g_exheader.arm11systemlocalcaps.programid;
|
||||
if ((res = load_code(progid, &shared_addr, prog_handle, g_exheader.codesetinfo.flags.flag & 1)) >= 0)
|
||||
{
|
||||
memcpy(&codesetinfo.name, g_exheader.codesetinfo.name, 8);
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include "strings.h"
|
||||
#include "fsldr.h"
|
||||
#include "ifile.h"
|
||||
#include "CFWInfo.h"
|
||||
#include "../build/bundled.h"
|
||||
|
||||
static CFWInfo info;
|
||||
static u32 config;
|
||||
static bool isN3DS, isSafeMode, isSdMode;
|
||||
|
||||
static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, s32 offset, const void *replace, u32 repSize, u32 count)
|
||||
{
|
||||
@@ -61,14 +61,14 @@ static bool dirCheck(FS_ArchiveID archiveId, const char *path)
|
||||
|
||||
static bool openLumaFile(IFile *file, const char *path)
|
||||
{
|
||||
FS_ArchiveID archiveId = LOADERFLAG(ISSDMODE) ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
|
||||
return R_SUCCEEDED(fileOpen(file, archiveId, path, FS_OPEN_READ));
|
||||
}
|
||||
|
||||
static u32 checkLumaDir(const char *path)
|
||||
{
|
||||
FS_ArchiveID archiveId = LOADERFLAG(ISSDMODE) ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
|
||||
return dirCheck(archiveId, path) ? archiveId : 0;
|
||||
}
|
||||
@@ -76,14 +76,21 @@ static u32 checkLumaDir(const char *path)
|
||||
static inline void loadCFWInfo(void)
|
||||
{
|
||||
static bool infoLoaded = false;
|
||||
s64 out;
|
||||
|
||||
if(infoLoaded) return;
|
||||
|
||||
svcGetCFWInfo(&info);
|
||||
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 2))) svcBreak(USERBREAK_ASSERT);
|
||||
config = (u32)out;
|
||||
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 4))) svcBreak(USERBREAK_ASSERT);
|
||||
isN3DS = (bool)out;
|
||||
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 5))) svcBreak(USERBREAK_ASSERT);
|
||||
isSafeMode = (bool)out;
|
||||
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 6))) svcBreak(USERBREAK_ASSERT);
|
||||
isSdMode = (bool)out;
|
||||
|
||||
IFile file;
|
||||
if(LOADERFLAG(ISSAFEMODE)) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted
|
||||
|
||||
if(isSafeMode) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted
|
||||
infoLoaded = true;
|
||||
}
|
||||
|
||||
@@ -170,116 +177,6 @@ static u32 findFunctionStart(u8 *code, u32 pos)
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
static inline u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset)
|
||||
{
|
||||
/* HANS:
|
||||
Look for error code which is known to be stored near cfg:u handle
|
||||
this way we can find the right candidate
|
||||
(handle should also be stored right after end of candidate function) */
|
||||
|
||||
u32 n = 0,
|
||||
possible[24];
|
||||
|
||||
for(u8 *pos = code + 16; n < 24 && pos <= code + size - 16; pos += 4)
|
||||
{
|
||||
if(*(u32 *)pos != 0xD8A103F9) continue;
|
||||
|
||||
for(u32 *l = (u32 *)pos - 4; n < 24 && l < (u32 *)pos + 4; l++)
|
||||
if(*l <= 0x10000000) possible[n++] = *l;
|
||||
}
|
||||
|
||||
if(!n) return NULL;
|
||||
|
||||
for(u8 *CFGU_GetConfigInfoBlk2_endPos = code; CFGU_GetConfigInfoBlk2_endPos <= code + size - 12; CFGU_GetConfigInfoBlk2_endPos += 4)
|
||||
{
|
||||
//There might be multiple implementations of GetConfigInfoBlk2 but let's search for the one we want
|
||||
u32 *cmp = (u32 *)CFGU_GetConfigInfoBlk2_endPos;
|
||||
|
||||
if(cmp[0] != 0xE8BD8010 || cmp[1] != 0x00010082) continue;
|
||||
|
||||
for(u32 i = 0; i < n; i++)
|
||||
if(possible[i] == cmp[2])
|
||||
{
|
||||
*CFGUHandleOffset = cmp[2];
|
||||
|
||||
return CFGU_GetConfigInfoBlk2_endPos;
|
||||
}
|
||||
|
||||
CFGU_GetConfigInfoBlk2_endPos += 4;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline bool patchCfgGetLanguage(u8 *code, u32 size, u8 languageId, u8 *CFGU_GetConfigInfoBlk2_endPos)
|
||||
{
|
||||
u32 additive = findFunctionStart(code, (u32)(CFGU_GetConfigInfoBlk2_endPos - code));
|
||||
|
||||
if(additive == 0xFFFFFFFF) return false;
|
||||
|
||||
u8 *CFGU_GetConfigInfoBlk2_startPos = code + additive;
|
||||
|
||||
for(u8 *languageBlkIdPos = code; languageBlkIdPos <= code + size - 4; languageBlkIdPos += 4)
|
||||
{
|
||||
if(*(u32 *)languageBlkIdPos != 0xA0002) continue;
|
||||
|
||||
for(u8 *instr = languageBlkIdPos - 8; instr >= languageBlkIdPos - 0x1008 && instr >= code + 4; instr -= 4) //Should be enough
|
||||
{
|
||||
if(instr[3] != 0xEB) continue; //We're looking for BL
|
||||
|
||||
u8 *calledFunction = instr;
|
||||
u32 i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
u32 low24 = (*(u32 *)calledFunction & 0x00FFFFFF) << 2;
|
||||
u32 signMask = (u32)(-(low24 >> 25)) & 0xFC000000; //Sign extension
|
||||
s32 offset = (s32)(low24 | signMask) + 8; //Branch offset + 8 for prefetch
|
||||
|
||||
calledFunction += offset;
|
||||
|
||||
if(calledFunction >= CFGU_GetConfigInfoBlk2_startPos - 4 && calledFunction <= CFGU_GetConfigInfoBlk2_endPos)
|
||||
{
|
||||
*((u32 *)instr - 1) = 0xE3A00000 | languageId; //mov r0, sp => mov r0, =languageId
|
||||
*(u32 *)instr = 0xE5CD0000; //bl CFGU_GetConfigInfoBlk2 => strb r0, [sp]
|
||||
*((u32 *)instr + 1) = 0xE3B00000; //(1 or 2 instructions) => movs r0, 0 (result code)
|
||||
|
||||
//We're done
|
||||
return true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
while(i < 2 && calledFunction[3] == 0xEA);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void patchCfgGetRegion(u8 *code, u32 size, u8 regionId, u32 CFGUHandleOffset)
|
||||
{
|
||||
for(u8 *cmdPos = code; cmdPos <= code + size - 28; cmdPos += 4)
|
||||
{
|
||||
u32 *cmp = (u32 *)cmdPos;
|
||||
|
||||
if(*cmp != 0xE3A00802) continue;
|
||||
|
||||
for(u32 i = 1; i < 3; i++)
|
||||
if((*(cmp - i) & 0xFFFF0FFF) == 0xEE1D0F70 && *((u16 *)cmdPos + 5) == 0xE59F &&
|
||||
*(u32 *)(cmdPos + 16 + *((u16 *)cmdPos + 4)) == CFGUHandleOffset)
|
||||
{
|
||||
cmp[3] = 0xE3A00000 | regionId; //mov r0, =regionId
|
||||
cmp[4] = 0xE5C40008; //strb r0, [r4, #8]
|
||||
cmp[5] = 0xE3A00000; //mov r0, #0 (result code)
|
||||
cmp[6] = 0xE5840004; //str r0, [r4, #4]
|
||||
|
||||
//The remaining, not patched, function code will do the rest for us
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool findLayeredFsSymbols(u8 *code, u32 size, u32 *fsMountArchive, u32 *fsRegisterArchive, u32 *fsTryOpenFile, u32 *fsOpenFileDirectly)
|
||||
{
|
||||
u32 found = 0,
|
||||
@@ -480,55 +377,97 @@ static inline bool loadTitleCodeSection(u64 progId, u8 *code, u32 size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline bool loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
|
||||
static inline bool loadTitleLocaleConfig(u64 progId, u8 *mask, u8 *regionId, u8 *languageId, u8 *countryId, u8 *stateId)
|
||||
{
|
||||
/* Here we look for "/luma/titles/[u64 titleID in hex, uppercase]/locale.txt"
|
||||
If it exists it should contain, for example, "EUR IT" */
|
||||
|
||||
char path[] = "/luma/titles/0000000000000000/locale.txt";
|
||||
progIdToStr(path + 28, progId);
|
||||
*mask = *regionId = *languageId = *countryId = *stateId = 0;
|
||||
|
||||
IFile file;
|
||||
|
||||
if(!openLumaFile(&file, path)) return true;
|
||||
if(!openLumaFile(&file, path)) return false;
|
||||
|
||||
bool ret = false;
|
||||
u64 fileSize;
|
||||
|
||||
if(R_FAILED(IFile_GetSize(&file, &fileSize)) || fileSize < 6 || fileSize > 8) goto exit;
|
||||
if(R_FAILED(IFile_GetSize(&file, &fileSize)) || fileSize < 3) goto exit;
|
||||
if(fileSize >= 12) fileSize = 12;
|
||||
|
||||
char buf[8];
|
||||
char buf[12] = "------------";
|
||||
u64 total;
|
||||
|
||||
if(R_FAILED(IFile_Read(&file, &total, buf, fileSize))) goto exit;
|
||||
|
||||
static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"},
|
||||
*languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"};
|
||||
ret = true;
|
||||
|
||||
static const char *regions[] = {"--", "JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"},
|
||||
*languages[] = {"--", "JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"},
|
||||
*countries[] = {"--", "JP", "--", "--", "--", "--", "--", "--", "AI", "AG", "AR", "AW",
|
||||
"BS", "BB", "BZ", "BO", "BR", "VG", "CA", "KY", "CL", "CO", "CR", "DM",
|
||||
"DO", "EC", "SV", "GF", "GD", "GP", "GT", "GY", "HT", "HN", "JM", "MQ",
|
||||
"MX", "MS", "AN", "NI", "PA", "PY", "PE", "KN", "LC", "VC", "SR", "TT",
|
||||
"TC", "US", "UY", "VI", "VE", "--", "--", "--", "--", "--", "--", "--",
|
||||
"--", "--", "--", "--", "AL", "AU", "AT", "BE", "BA", "BW", "BG", "HR",
|
||||
"CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IS", "IE", "IT",
|
||||
"LV", "LS", "LI", "LT", "LU", "MK", "MT", "ME", "MZ", "NA", "NL", "NZ",
|
||||
"NO", "PL", "PT", "RO", "RU", "RS", "SK", "SI", "ZA", "ES", "SZ", "SE",
|
||||
"CH", "TR", "GB", "ZM", "ZW", "AZ", "MR", "ML", "NE", "TD", "SD", "ER",
|
||||
"DJ", "SO", "AD", "GI", "GG", "IM", "JE", "MC", "TW", "--", "--", "--",
|
||||
"--", "--", "--", "--", "KR", "--", "--", "--", "--", "--", "--", "--",
|
||||
"HK", "MO", "--", "--", "--", "--", "--", "--", "ID", "SG", "TH", "PH",
|
||||
"MY", "--", "--", "--", "CN", "--", "--", "--", "--", "--", "--", "--",
|
||||
"AE", "IN", "EG", "OM", "QA", "KW", "SA", "SY", "BH", "JO", "--", "--",
|
||||
"--", "--", "--", "--", "SM", "VA"};
|
||||
|
||||
u32 i;
|
||||
|
||||
for(i = 0; i < sizeof(regions) / sizeof(char *); i++)
|
||||
{
|
||||
if(memcmp(buf, regions[i], 3) == 0)
|
||||
if(memcmp(buf, regions[i], 3) == 0 && i != 0)
|
||||
{
|
||||
*regionId = (u8)i;
|
||||
*regionId = (u8)(i - 1);
|
||||
*mask |= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i != sizeof(regions) / sizeof(char *))
|
||||
for(i = 0; fileSize >= 6 && i < sizeof(languages) / sizeof(char *); i++)
|
||||
{
|
||||
for(i = 0; i < sizeof(languages) / sizeof(char *); i++)
|
||||
if(memcmp(buf + 4, languages[i], 2) == 0 && i != 0)
|
||||
{
|
||||
if(memcmp(buf + 4, languages[i], 2) == 0)
|
||||
{
|
||||
*languageId = (u8)i;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
*languageId = (u8)(i - 1);
|
||||
*mask |= 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; fileSize >= 9 && i < sizeof(countries) / sizeof(char *); i++)
|
||||
{
|
||||
if(memcmp(buf + 7, countries[i], 2) == 0 && i != 0)
|
||||
{
|
||||
*countryId = (u8)i;
|
||||
*mask |= 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(fileSize >= 12 &&
|
||||
((buf[10] >= '0' && buf[10] <= '9') || (buf[10] >= 'a' && buf[10] <= 'f') || (buf[10] >= 'A' && buf[10] <= 'F')) &&
|
||||
((buf[11] >= '0' && buf[11] <= '9') || (buf[11] >= 'a' && buf[11] <= 'f') || (buf[11] >= 'A' && buf[11] <= 'F')))
|
||||
{
|
||||
if (buf[10] >= '0' && buf[10] <= '9') *stateId = 16 * (buf[10] - '0');
|
||||
else if(buf[10] >= 'a' && buf[10] <= 'f') *stateId = 16 * (buf[10] - 'a');
|
||||
else if(buf[10] >= 'A' && buf[10] <= 'F') *stateId = 16 * (buf[10] - 'A');
|
||||
|
||||
if (buf[11] >= '0' && buf[11] <= '9') *stateId += buf[11] - '0';
|
||||
else if(buf[11] >= 'a' && buf[11] <= 'f') *stateId += buf[11] - 'a';
|
||||
else if(buf[11] >= 'A' && buf[11] <= 'F') *stateId += buf[11] - 'A';
|
||||
|
||||
*mask |= 8;
|
||||
}
|
||||
|
||||
exit:
|
||||
IFile_Close(&file);
|
||||
|
||||
@@ -775,7 +714,7 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
if(ret == 0 || (ret == 1 && progVer > 0xB)) goto error;
|
||||
}
|
||||
|
||||
if(LOADERFLAG(ISN3DS))
|
||||
if(isN3DS)
|
||||
{
|
||||
u32 cpuSetting = MULTICONFIG(NEWCPU);
|
||||
|
||||
@@ -796,6 +735,11 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
*(off + 3) = 0xE3800000 | cpuSetting;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -866,33 +810,6 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
)) goto error;
|
||||
}
|
||||
|
||||
else if(progId == 0x0004003000008A02LL && CONFIG(ENABLEEXCEPTIONHANDLERS) && !CONFIG(PATCHUNITINFO)) //ErrDisp
|
||||
{
|
||||
static const u8 pattern[] = {
|
||||
0x00, 0xD0, 0xE5, 0xDB
|
||||
},
|
||||
pattern2[] = {
|
||||
0x14, 0x00, 0xD0, 0xE5, 0x01
|
||||
},
|
||||
patch[] = {
|
||||
0x00, 0x00, 0xA0, 0xE3
|
||||
};
|
||||
|
||||
//Patch UNITINFO checks to make ErrDisp more verbose
|
||||
if(!patchMemory(code, textSize,
|
||||
pattern,
|
||||
sizeof(pattern), -1,
|
||||
patch,
|
||||
sizeof(patch), 1
|
||||
) ||
|
||||
patchMemory(code, textSize,
|
||||
pattern2,
|
||||
sizeof(pattern2), 0,
|
||||
patch,
|
||||
sizeof(patch), 3
|
||||
) != 3) goto error;
|
||||
}
|
||||
|
||||
else if(progId == 0x0004013000002802LL) //DLP
|
||||
{
|
||||
static const u8 pattern[] = {
|
||||
@@ -918,22 +835,15 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
||||
|
||||
if((u32)((progId >> 0x20) & 0xFFFFFFEDULL) == 0x00040000)
|
||||
{
|
||||
u8 regionId = 0xFF,
|
||||
languageId;
|
||||
u8 mask,
|
||||
regionId,
|
||||
languageId,
|
||||
countryId,
|
||||
stateId;
|
||||
|
||||
if(!loadTitleLocaleConfig(progId, ®ionId, &languageId) ||
|
||||
!patchLayeredFs(progId, code, size, textSize, roSize, dataSize, roAddress, dataAddress)) goto error;
|
||||
|
||||
if(regionId != 0xFF)
|
||||
{
|
||||
u32 CFGUHandleOffset;
|
||||
u8 *CFGU_GetConfigInfoBlk2_endPos = getCfgOffsets(code, textSize, &CFGUHandleOffset);
|
||||
|
||||
if(CFGU_GetConfigInfoBlk2_endPos == NULL ||
|
||||
!patchCfgGetLanguage(code, textSize, languageId, CFGU_GetConfigInfoBlk2_endPos)) goto error;
|
||||
|
||||
patchCfgGetRegion(code, textSize, regionId, CFGUHandleOffset);
|
||||
}
|
||||
if(loadTitleLocaleConfig(progId, &mask, ®ionId, &languageId, &countryId, &stateId))
|
||||
svcKernelSetState(0x10001, ((u32)stateId << 24) | ((u32)countryId << 16) | ((u32)languageId << 8) | ((u32)regionId << 4) | (u32)mask , progId);
|
||||
if(!patchLayeredFs(progId, code, size, textSize, roSize, dataSize, roAddress, dataAddress)) goto error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
|
||||
#define CONFIG(a) (((info.config >> (a + 17)) & 1) != 0)
|
||||
#define MULTICONFIG(a) ((info.config >> (a * 2 + 7)) & 3)
|
||||
#define BOOTCONFIG(a, b) ((info.config >> a) & b)
|
||||
#define LOADERFLAG(a) ((info.flags >> (a + 4)) & 1) != 0
|
||||
#define CONFIG(a) (((config >> (a + 17)) & 1) != 0)
|
||||
#define MULTICONFIG(a) ((config >> (a * 2 + 7)) & 3)
|
||||
#define BOOTCONFIG(a, b) ((config >> a) & b)
|
||||
|
||||
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
|
||||
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
|
||||
@@ -32,15 +31,7 @@ enum singleOptions
|
||||
PATCHVERSTRING,
|
||||
SHOWGBABOOT,
|
||||
PATCHACCESS,
|
||||
PATCHUNITINFO,
|
||||
ENABLEEXCEPTIONHANDLERS
|
||||
};
|
||||
|
||||
enum flags
|
||||
{
|
||||
ISN3DS = 0,
|
||||
ISSAFEMODE,
|
||||
ISSDMODE
|
||||
PATCHUNITINFO
|
||||
};
|
||||
|
||||
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress);
|
||||
|
||||
@@ -17,4 +17,4 @@ void progIdToStr(char *strEnd, u64 progId)
|
||||
*strEnd-- = hexDigits[(u32)(progId & 0xF)];
|
||||
progId >>= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
#include <3ds/types.h>
|
||||
|
||||
size_t strnlen(const char *string, size_t maxlen);
|
||||
void progIdToStr(char *strEnd, u64 progId);
|
||||
void progIdToStr(char *strEnd, u64 progId);
|
||||
|
||||
78
sysmodules/rosalina/Makefile
Normal file
78
sysmodules/rosalina/Makefile
Normal file
@@ -0,0 +1,78 @@
|
||||
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/3ds_rules
|
||||
|
||||
CC := arm-none-eabi-gcc
|
||||
AS := arm-none-eabi-as
|
||||
LD := arm-none-eabi-ld
|
||||
OC := arm-none-eabi-objcopy
|
||||
|
||||
name := $(shell basename $(CURDIR))
|
||||
|
||||
dir_source := source
|
||||
dir_include := include
|
||||
dir_build := build
|
||||
dir_out := ../../$(dir_build)
|
||||
dir_kernel_extension := kernel_extension
|
||||
|
||||
LIBS := -lctru
|
||||
LIBDIRS := $(CTRULIB)
|
||||
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include)
|
||||
|
||||
ARCH := -mcpu=mpcore -mfloat-abi=hard
|
||||
ASFLAGS := -g $(ARCH)
|
||||
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -mtp=soft -fno-builtin -std=c11 -O2 -flto -ffast-math -mword-relocations \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections $(INCLUDE) -I$(dir_include) -DARM11 -D_3DS
|
||||
LDFLAGS := -specs=3dsx.specs -g $(ARCH) -mtp=soft -Wl,--section-start,.text=0x14000000 -Wl,--gc-sections
|
||||
|
||||
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||
|
||||
xml_files = $(call rwildcard, $(dir_source), *.xml)
|
||||
|
||||
.PHONY: all
|
||||
all: $(dir_out)/$(name).cxi
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@$(MAKE) -C $(dir_kernel_extension) clean
|
||||
@rm -rf $(dir_build)
|
||||
|
||||
.PHONY: $(dir_kernel_extension)
|
||||
|
||||
$(dir_out)/$(name).cxi: $(dir_build)/$(name).elf
|
||||
@makerom -f ncch -rsf rosalina.rsf -nocodepadding -o $@ -elf $<
|
||||
|
||||
$(dir_build)/$(name).elf: $(objects)
|
||||
$(LINK.o) $(OUTPUT_OPTION) $^ $(LIBPATHS) $(LIBS)
|
||||
|
||||
$(dir_build)/kernel_extension.bin: $(dir_kernel_extension)
|
||||
@mkdir -p "$(@D)"
|
||||
@$(MAKE) -C $<
|
||||
|
||||
$(dir_build)/xml_data.h: $(xml_files)
|
||||
@ echo "" > $(@)
|
||||
@$(foreach f, $(xml_files),\
|
||||
echo "static const char" `(echo $(notdir $(f)) | sed -e 's/^\([0-9]\)/_\1/g' | tr . _)`"[] = " >> $(@);\
|
||||
sed -e 's/\\/\\\\/g;s/"/\\"/g;s/^/"/g;s/[ \t\r\n]*$$/\\n"/g' $(f) >> $(@);\
|
||||
echo ';' >> $@;\
|
||||
)
|
||||
$(dir_build)/gdb/xfer.o: $(dir_build)/xml_data.h
|
||||
$(dir_build)/memory.o : CFLAGS += -O3
|
||||
$(dir_build)/kernel_extension.o: $(dir_build)/kernel_extension.bin
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.c
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.s
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||
include $(call rwildcard, $(dir_build), *.d)
|
||||
111
sysmodules/rosalina/include/3dsx.h
Normal file
111
sysmodules/rosalina/include/3dsx.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/* File entirely written by fincs */
|
||||
|
||||
#pragma once
|
||||
#include <3ds/types.h>
|
||||
#include "ifile.h"
|
||||
|
||||
// File layout:
|
||||
// - File header
|
||||
// - Code, rodata and data relocation table headers
|
||||
// - Code segment
|
||||
// - Rodata segment
|
||||
// - Loadable (non-BSS) part of the data segment
|
||||
// - Code relocation table
|
||||
// - Rodata relocation table
|
||||
// - Data relocation table
|
||||
|
||||
// Memory layout before relocations are applied:
|
||||
// [0..codeSegSize) -> code segment
|
||||
// [codeSegSize..rodataSegSize) -> rodata segment
|
||||
// [rodataSegSize..dataSegSize) -> data segment
|
||||
|
||||
// Memory layout after relocations are applied: well, however the loader sets it up :)
|
||||
// The entrypoint is always the start of the code segment.
|
||||
// The BSS section must be cleared manually by the application.
|
||||
|
||||
// File header
|
||||
#define _3DSX_MAGIC 0x58534433 // '3DSX'
|
||||
typedef struct
|
||||
{
|
||||
u32 magic;
|
||||
u16 headerSize, relocHdrSize;
|
||||
u32 formatVer;
|
||||
u32 flags;
|
||||
|
||||
// Sizes of the code, rodata and data segments +
|
||||
// size of the BSS section (uninitialized latter half of the data segment)
|
||||
u32 codeSegSize, rodataSegSize, dataSegSize, bssSize;
|
||||
} _3DSX_Header;
|
||||
|
||||
// Relocation header: all fields (even extra unknown fields) are guaranteed to be relocation counts.
|
||||
typedef struct
|
||||
{
|
||||
u32 cAbsolute; // # of absolute relocations (that is, fix address to post-relocation memory layout)
|
||||
u32 cRelative; // # of cross-segment relative relocations (that is, 32bit signed offsets that need to be patched)
|
||||
// more?
|
||||
|
||||
// Relocations are written in this order:
|
||||
// - Absolute relocs
|
||||
// - Relative relocs
|
||||
} _3DSX_RelocHdr;
|
||||
|
||||
// Relocation entry: from the current pointer, skip X words and patch Y words
|
||||
typedef struct
|
||||
{
|
||||
u16 skip, patch;
|
||||
} _3DSX_Reloc;
|
||||
|
||||
// _prm structure
|
||||
#define _PRM_MAGIC 0x6D72705F // '_prm'
|
||||
typedef struct
|
||||
{
|
||||
u32 magic;
|
||||
u32 pSrvOverride;
|
||||
u32 aptAppId;
|
||||
u32 heapSize, linearHeapSize;
|
||||
u32 pArgList;
|
||||
u32 runFlags;
|
||||
} PrmStruct;
|
||||
|
||||
// Service override structure
|
||||
typedef struct
|
||||
{
|
||||
u32 count;
|
||||
struct
|
||||
{
|
||||
char name[8];
|
||||
Handle handle;
|
||||
} services[];
|
||||
} SrvOverride;
|
||||
|
||||
#define ARGVBUF_SIZE 0x400
|
||||
extern u32 ldrArgvBuf[ARGVBUF_SIZE/4];
|
||||
|
||||
bool Ldr_Get3dsxSize(u32* pSize, IFile *file);
|
||||
Handle Ldr_CodesetFrom3dsx(const char* name, u32* codePages, u32 baseAddr, IFile *file, u64 tid);
|
||||
46
sysmodules/rosalina/include/MyThread.h
Normal file
46
sysmodules/rosalina/include/MyThread.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
|
||||
#define THREAD_STACK_SIZE 0x1000
|
||||
|
||||
typedef struct MyThread
|
||||
{
|
||||
Handle handle;
|
||||
void (*ep)(void);
|
||||
bool finished;
|
||||
void* stacktop;
|
||||
} MyThread;
|
||||
|
||||
Result MyThread_Create(MyThread *t, void (*entrypoint)(void), void *stack, u32 stackSize, int prio, int affinity);
|
||||
Result MyThread_Join(MyThread *thread, s64 timeout_ns);
|
||||
void MyThread_Exit(void);
|
||||
137
sysmodules/rosalina/include/csvc.h
Normal file
137
sysmodules/rosalina/include/csvc.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/* This paricular file is licensed under the following terms: */
|
||||
|
||||
/*
|
||||
* This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable
|
||||
* for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it
|
||||
* and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
* This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
/// Operations for svcControlService
|
||||
typedef enum ServiceOp
|
||||
{
|
||||
SERVICEOP_STEAL_CLIENT_SESSION = 0, ///< Steal a client session given a service or global port name
|
||||
SERVICEOP_GET_NAME, ///< Get the name of a service or global port given a client or session handle
|
||||
} ServiceOp;
|
||||
|
||||
/**
|
||||
* @brief Executes a function in supervisor mode, using the supervisor-mode stack.
|
||||
* @param func Function to execute.
|
||||
* @param ... Function parameters, up to 3 registers.
|
||||
*/
|
||||
Result svcCustomBackdoor(void *func, ...);
|
||||
|
||||
///@name I/O
|
||||
///@{
|
||||
/**
|
||||
* @brief Gives the physical address corresponding to a virtual address.
|
||||
* @param VA Virtual address.
|
||||
* @param writeCheck whether to check if the VA is writable in supervisor mode
|
||||
* @return The corresponding physical address, or NULL.
|
||||
*/
|
||||
u32 svcConvertVAToPA(const void *VA, bool writeCheck);
|
||||
|
||||
/**
|
||||
* @brief Flushes a range of the data cache (L2C included).
|
||||
* @param addr Start address.
|
||||
* @param len Length of the range.
|
||||
*/
|
||||
void svcFlushDataCacheRange(void *addr, u32 len);
|
||||
|
||||
/**
|
||||
* @brief Flushes the data cache entirely (L2C included).
|
||||
*/
|
||||
void svcFlushEntireDataCache(void);
|
||||
|
||||
/**
|
||||
* @brief Invalidates a range of the instruction cache.
|
||||
* @param addr Start address.
|
||||
* @param len Length of the range.
|
||||
*/
|
||||
void svcInvalidateInstructionCacheRange(void *addr, u32 len);
|
||||
|
||||
/**
|
||||
* @brief Invalidates the data cache entirely.
|
||||
*/
|
||||
void svcInvalidateEntireInstructionCache(void);
|
||||
///@}
|
||||
|
||||
///@name Memory management
|
||||
///@{
|
||||
/**
|
||||
* @brief Maps a block of process memory.
|
||||
* @param process Handle of the process.
|
||||
* @param destAddress Address of the mapped block in the current process.
|
||||
* @param srcAddress Address of the mapped block in the source process.
|
||||
* @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes).
|
||||
*/
|
||||
Result svcMapProcessMemoryEx(Handle process, u32 destAddr, u32 srcAddr, u32 size);
|
||||
|
||||
/**
|
||||
* @brief Unmaps a block of process memory.
|
||||
* @param process Handle of the process.
|
||||
* @param destAddress Address of the block of memory to unmap, in the current (destination) process.
|
||||
* @param size Size of the block of memory to unmap (truncated to a multiple of 0x1000 bytes).
|
||||
*/
|
||||
Result svcUnmapProcessMemoryEx(Handle process, u32 destAddress, u32 size);
|
||||
|
||||
/**
|
||||
* @brief Controls memory mapping, with the choice to use region attributes or not.
|
||||
* @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0.
|
||||
* @param addr0 The virtual address to be used for the operation.
|
||||
* @param addr1 The virtual address to be (un)mirrored by @p addr0 when using @ref MEMOP_MAP or @ref MEMOP_UNMAP.
|
||||
* It has to be pointing to a RW memory.
|
||||
* Use NULL if the operation is @ref MEMOP_FREE or @ref MEMOP_ALLOC.
|
||||
* @param size The requested size for @ref MEMOP_ALLOC and @ref MEMOP_ALLOC_LINEAR.
|
||||
* @param op Operation flags. See @ref MemOp.
|
||||
* @param perm A combination of @ref MEMPERM_READ and @ref MEMPERM_WRITE. Using MEMPERM_EXECUTE will return an error.
|
||||
* Value 0 is used when unmapping memory.
|
||||
* @param isLoader Whether to use the region attributes
|
||||
* If a memory is mapped for two or more addresses, you have to use MEMOP_UNMAP before being able to MEMOP_FREE it.
|
||||
* MEMOP_MAP will fail if @p addr1 was already mapped to another address.
|
||||
*
|
||||
* @sa svcControlMemory
|
||||
*/
|
||||
Result svcControlMemoryEx(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||
///@}
|
||||
|
||||
///@name System
|
||||
///@{
|
||||
/**
|
||||
* @brief Performs actions related to services or global handles.
|
||||
* @param op The operation to perform, see @ref ServiceOp.
|
||||
*
|
||||
* Examples:
|
||||
* svcControlService(SERVICEOP_GET_NAME, (char [12])outName, (Handle)clientOrSessionHandle);
|
||||
* svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, (Handle *)&outHandle, (const char *)name);
|
||||
*/
|
||||
Result svcControlService(ServiceOp op, ...);
|
||||
|
||||
/**
|
||||
* @brief Copy a handle from a process to another one.
|
||||
* @param[out] out The output handle.
|
||||
* @param outProcess Handle of the process of the output handle.
|
||||
* @param in The input handle. Pseudo-handles are not accepted.
|
||||
* @param inProcess Handle of the process of the input handle.
|
||||
*/
|
||||
Result svcCopyHandle(Handle *out, Handle outProcess, Handle in, Handle inProcess);
|
||||
|
||||
/**
|
||||
* @brief Get the address and class name of the underlying kernel object corresponding to a handle.
|
||||
* @param[out] outKAddr The output kernel address.
|
||||
* @param[out] outName Output class name. The buffer should be large enough to contain it.
|
||||
* @param in The input handle.
|
||||
*/
|
||||
Result svcTranslateHandle(u32 *outKAddr, char *outClassName, Handle in);
|
||||
///@}
|
||||
85
sysmodules/rosalina/include/draw.h
Normal file
85
sysmodules/rosalina/include/draw.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/gfx.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define GPU_FB_TOP_LEFT_ADDR_1 REG32(0x10400468)
|
||||
#define GPU_FB_TOP_LEFT_ADDR_2 REG32(0x1040046C)
|
||||
#define GPU_FB_TOP_FMT REG32(0x10400470)
|
||||
#define GPU_FB_TOP_SEL REG32(0x10400478)
|
||||
#define GPU_FB_TOP_STRIDE REG32(0x10400490)
|
||||
#define GPU_FB_TOP_RIGHT_ADDR_1 REG32(0x10400494)
|
||||
#define GPU_FB_TOP_RIGHT_ADDR_2 REG32(0x10400498)
|
||||
|
||||
#define GPU_FB_BOTTOM_ADDR_1 REG32(0x10400568)
|
||||
#define GPU_FB_BOTTOM_ADDR_2 REG32(0x1040056C)
|
||||
#define GPU_FB_BOTTOM_FMT REG32(0x10400570)
|
||||
#define GPU_FB_BOTTOM_SEL REG32(0x10400578)
|
||||
#define GPU_FB_BOTTOM_STRIDE REG32(0x10400590)
|
||||
|
||||
#define GPU_PSC0_CNT REG32(0x1040001C)
|
||||
#define GPU_PSC1_CNT REG32(0x1040001C)
|
||||
|
||||
#define GPU_TRANSFER_CNT REG32(0x10400C18)
|
||||
#define GPU_CMDLIST_CNT REG32(0x104018F0)
|
||||
|
||||
#define FB_BOTTOM_VRAM_ADDR ((void *)0x1F48F000) // cached
|
||||
#define FB_BOTTOM_VRAM_PA 0x1848F000
|
||||
#define FB_BOTTOM_SIZE (320 * 240 * 2)
|
||||
|
||||
#define SCREEN_BOT_WIDTH 320
|
||||
#define SCREEN_BOT_HEIGHT 240
|
||||
|
||||
#define SPACING_Y 11
|
||||
#define SPACING_X 6
|
||||
|
||||
#define COLOR_TITLE RGB565(0x00, 0x26, 0x1F)
|
||||
#define COLOR_WHITE RGB565(0x1F, 0x3F, 0x1F)
|
||||
#define COLOR_RED RGB565(0x1F, 0x00, 0x00)
|
||||
#define COLOR_BLACK RGB565(0x00, 0x00, 0x00)
|
||||
|
||||
#define DRAW_MAX_FORMATTED_STRING_SIZE 512
|
||||
|
||||
void Draw_Lock(void);
|
||||
void Draw_Unlock(void);
|
||||
|
||||
void Draw_DrawCharacter(u32 posX, u32 posY, u32 color, char character);
|
||||
u32 Draw_DrawString(u32 posX, u32 posY, u32 color, const char *string);
|
||||
u32 Draw_DrawFormattedString(u32 posX, u32 posY, u32 color, const char *fmt, ...);
|
||||
|
||||
void Draw_FillFramebuffer(u32 value);
|
||||
void Draw_ClearFramebuffer(void);
|
||||
void Draw_SetupFramebuffer(void);
|
||||
void Draw_RestoreFramebuffer(void);
|
||||
void Draw_FlushFramebuffer(void);
|
||||
u32 Draw_GetCurrentFramebufferAddress(bool top, bool left);
|
||||
|
||||
void Draw_CreateBitmapHeader(u8 *dst, u32 width, u32 heigth);
|
||||
u8 *Draw_ConvertFrameBufferLine(bool top, bool left, u32 y);
|
||||
34
sysmodules/rosalina/include/errdisp.h
Normal file
34
sysmodules/rosalina/include/errdisp.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "MyThread.h"
|
||||
|
||||
MyThread *errDispCreateThread(void);
|
||||
|
||||
void errDispThreadMain(void);
|
||||
127
sysmodules/rosalina/include/exheader.h
Normal file
127
sysmodules/rosalina/include/exheader.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/* File written by fincs */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 reserved[5];
|
||||
u8 flag;
|
||||
u8 remasterversion[2];
|
||||
} PACKED exheader_systeminfoflags;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 address;
|
||||
u32 nummaxpages;
|
||||
u32 codesize;
|
||||
} PACKED exheader_codesegmentinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 name[8];
|
||||
exheader_systeminfoflags flags;
|
||||
exheader_codesegmentinfo text;
|
||||
u8 stacksize[4];
|
||||
exheader_codesegmentinfo ro;
|
||||
u8 reserved[4];
|
||||
exheader_codesegmentinfo data;
|
||||
u32 bsssize;
|
||||
} PACKED exheader_codesetinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid[0x30];
|
||||
} PACKED exheader_dependencylist;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 savedatasize[4];
|
||||
u8 reserved[4];
|
||||
u8 jumpid[8];
|
||||
u8 reserved2[0x30];
|
||||
} PACKED exheader_systeminfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 extsavedataid[8];
|
||||
u8 systemsavedataid[8];
|
||||
u8 reserved[8];
|
||||
u8 accessinfo[7];
|
||||
u8 otherattributes;
|
||||
} PACKED exheader_storageinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid;
|
||||
u32 firm;
|
||||
u8 flags[3];
|
||||
u8 priority;
|
||||
u16 resourcelimitdescriptor[0x10];
|
||||
exheader_storageinfo storageinfo;
|
||||
u64 serviceaccesscontrol[0x20];
|
||||
u8 reserved[0x1f];
|
||||
u8 resourcelimitcategory;
|
||||
} PACKED exheader_arm11systemlocalcaps;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 descriptors[28];
|
||||
u8 reserved[0x10];
|
||||
} PACKED exheader_arm11kernelcapabilities;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 descriptors[15];
|
||||
u8 descversion;
|
||||
} PACKED exheader_arm9accesscontrol;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// systemcontrol info {
|
||||
// coreinfo {
|
||||
exheader_codesetinfo codesetinfo;
|
||||
exheader_dependencylist deplist;
|
||||
// }
|
||||
exheader_systeminfo systeminfo;
|
||||
// }
|
||||
// accesscontrolinfo {
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
// }
|
||||
struct {
|
||||
u8 signature[0x100];
|
||||
u8 ncchpubkeymodulus[0x100];
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
} PACKED accessdesc;
|
||||
} PACKED exheader_header;
|
||||
32
sysmodules/rosalina/include/fmt.h
Normal file
32
sysmodules/rosalina/include/fmt.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "memory.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int vsprintf(char *buf, const char *fmt, va_list args);
|
||||
int sprintf(char *buf, const char *fmt, ...);
|
||||
3083
sysmodules/rosalina/include/font.h
Normal file
3083
sysmodules/rosalina/include/font.h
Normal file
File diff suppressed because it is too large
Load Diff
41
sysmodules/rosalina/include/fsreg.h
Normal file
41
sysmodules/rosalina/include/fsreg.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "exheader.h"
|
||||
|
||||
Result fsregInit(void);
|
||||
void fsregExit(void);
|
||||
Result FSREG_CheckHostLoadId(u64 prog_handle);
|
||||
Result FSREG_LoadProgram(u64 *prog_handle, FS_ProgramInfo *title);
|
||||
Result FSREG_GetProgramInfo(exheader_header *exheader, u32 entry_count, u64 prog_handle);
|
||||
Result FSREG_UnloadProgram(u64 prog_handle);
|
||||
Result FSREG_Unregister(u32 pid);
|
||||
Result FSREG_Register(u32 pid, u64 prog_handle, FS_ProgramInfo *info, void *storageinfo);
|
||||
Result fsregSetupPermissions(void);
|
||||
Handle fsregGetHandle(void);
|
||||
130
sysmodules/rosalina/include/gdb.h
Normal file
130
sysmodules/rosalina/include/gdb.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/result.h>
|
||||
#include "sock_util.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define MAX_DEBUG 3
|
||||
#define MAX_DEBUG_THREAD 127
|
||||
#define MAX_BREAKPOINT 256
|
||||
// 512+24 is the ideal size as IDA will try to read exactly 0x100 bytes at a time. Add 4 to this, for $#<checksum>, see below.
|
||||
// IDA seems to want additional bytes as well.
|
||||
// 1024 is fine enough to put all regs in the 'T' stop reply packets
|
||||
#define GDB_BUF_LEN 1024
|
||||
|
||||
#define GDB_HANDLER(name) GDB_Handle##name
|
||||
#define GDB_QUERY_HANDLER(name) GDB_HANDLER(Query##name)
|
||||
#define GDB_VERBOSE_HANDLER(name) GDB_HANDLER(Verbose##name)
|
||||
|
||||
#define GDB_DECLARE_HANDLER(name) int GDB_HANDLER(name)(GDBContext *ctx)
|
||||
#define GDB_DECLARE_QUERY_HANDLER(name) GDB_DECLARE_HANDLER(Query##name)
|
||||
#define GDB_DECLARE_VERBOSE_HANDLER(name) GDB_DECLARE_HANDLER(Verbose##name)
|
||||
|
||||
typedef struct Breakpoint
|
||||
{
|
||||
u32 address;
|
||||
u32 savedInstruction;
|
||||
u8 instructionSize;
|
||||
bool persistent;
|
||||
} Breakpoint;
|
||||
|
||||
typedef enum GDBFlags
|
||||
{
|
||||
GDB_FLAG_SELECTED = 1,
|
||||
GDB_FLAG_USED = 2,
|
||||
GDB_FLAG_PROCESS_CONTINUING = 4,
|
||||
GDB_FLAG_TERMINATE_PROCESS = 8,
|
||||
} GDBFlags;
|
||||
|
||||
typedef enum GDBState
|
||||
{
|
||||
GDB_STATE_DISCONNECTED,
|
||||
GDB_STATE_CONNECTED,
|
||||
GDB_STATE_NOACK_SENT,
|
||||
GDB_STATE_NOACK,
|
||||
GDB_STATE_CLOSING
|
||||
} GDBState;
|
||||
|
||||
typedef struct ThreadInfo
|
||||
{
|
||||
u32 id;
|
||||
u32 tls;
|
||||
} ThreadInfo;
|
||||
|
||||
typedef struct GDBContext
|
||||
{
|
||||
sock_ctx super;
|
||||
|
||||
RecursiveLock lock;
|
||||
GDBFlags flags;
|
||||
GDBState state;
|
||||
|
||||
u32 pid;
|
||||
Handle debug;
|
||||
ThreadInfo threadInfos[MAX_DEBUG_THREAD];
|
||||
u32 nbThreads;
|
||||
|
||||
u32 currentThreadId, selectedThreadId, selectedThreadIdForContinuing;
|
||||
|
||||
Handle clientAcceptedEvent, continuedEvent;
|
||||
Handle eventToWaitFor;
|
||||
|
||||
bool catchThreadEvents;
|
||||
bool processEnded, processExited;
|
||||
|
||||
DebugEventInfo latestDebugEvent;
|
||||
DebugFlags continueFlags;
|
||||
u32 svcMask[8];
|
||||
|
||||
u32 nbBreakpoints;
|
||||
Breakpoint breakpoints[MAX_BREAKPOINT];
|
||||
|
||||
u32 nbWatchpoints;
|
||||
u32 watchpoints[2];
|
||||
|
||||
bool isGDB;
|
||||
char *commandData, *commandEnd;
|
||||
int latestSentPacketSize;
|
||||
char buffer[GDB_BUF_LEN + 4];
|
||||
|
||||
char threadListData[0x800];
|
||||
u32 threadListDataPos;
|
||||
|
||||
char memoryOsInfoXmlData[0x800];
|
||||
char processesOsInfoXmlData[0x2000];
|
||||
} GDBContext;
|
||||
|
||||
typedef int (*GDBCommandHandler)(GDBContext *ctx);
|
||||
|
||||
void GDB_InitializeContext(GDBContext *ctx);
|
||||
void GDB_FinalizeContext(GDBContext *ctx);
|
||||
GDB_DECLARE_HANDLER(Unsupported);
|
||||
39
sysmodules/rosalina/include/gdb/breakpoints.h
Normal file
39
sysmodules/rosalina/include/gdb/breakpoints.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
// We'll actually use SVC 0xFF for breakpoints :P
|
||||
#define BREAKPOINT_INSTRUCTION_ARM 0xEF0000FF
|
||||
#define BREAKPOINT_INSTRUCTION_THUMB 0xDFFF
|
||||
|
||||
u32 GDB_FindClosestBreakpointSlot(GDBContext *ctx, u32 address);
|
||||
int GDB_GetBreakpointInstruction(u32 *instr, GDBContext *ctx, u32 address);
|
||||
int GDB_AddBreakpoint(GDBContext *ctx, u32 address, bool thumb, bool persist);
|
||||
int GDB_DisableBreakpointById(GDBContext *ctx, u32 id);
|
||||
int GDB_RemoveBreakpoint(GDBContext *ctx, u32 address);
|
||||
41
sysmodules/rosalina/include/gdb/debug.h
Normal file
41
sysmodules/rosalina/include/gdb/debug.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
GDB_DECLARE_HANDLER(Detach);
|
||||
GDB_DECLARE_HANDLER(Kill);
|
||||
GDB_DECLARE_HANDLER(Break);
|
||||
GDB_DECLARE_HANDLER(Continue);
|
||||
GDB_DECLARE_VERBOSE_HANDLER(Continue);
|
||||
GDB_DECLARE_HANDLER(GetStopReason);
|
||||
|
||||
void GDB_PreprocessDebugEvent(GDBContext *ctx, DebugEventInfo *info);
|
||||
int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info);
|
||||
int GDB_HandleDebugEvents(GDBContext *ctx);
|
||||
void GDB_BreakProcessAndSinkDebugEvents(GDBContext *ctx, DebugFlags flags);
|
||||
40
sysmodules/rosalina/include/gdb/mem.h
Normal file
40
sysmodules/rosalina/include/gdb/mem.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
Result GDB_ReadMemoryInPage(void *out, GDBContext *ctx, u32 addr, u32 len);
|
||||
Result GDB_WriteMemoryInPage(GDBContext *ctx, const void *in, u32 addr, u32 len);
|
||||
int GDB_SendMemory(GDBContext *ctx, const char *prefix, u32 prefixLen, u32 addr, u32 len);
|
||||
int GDB_WriteMemory(GDBContext *ctx, const void *buf, u32 addr, u32 len);
|
||||
u32 GDB_SearchMemory(bool *found, GDBContext *ctx, u32 addr, u32 len, const void *pattern, u32 patternLen);
|
||||
|
||||
GDB_DECLARE_HANDLER(ReadMemory);
|
||||
GDB_DECLARE_HANDLER(WriteMemory);
|
||||
GDB_DECLARE_HANDLER(WriteMemoryRaw);
|
||||
GDB_DECLARE_QUERY_HANDLER(SearchMemory);
|
||||
32
sysmodules/rosalina/include/gdb/monitor.h
Normal file
32
sysmodules/rosalina/include/gdb/monitor.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
#include "gdb/server.h"
|
||||
|
||||
void GDB_RunMonitor(GDBServer *server);
|
||||
47
sysmodules/rosalina/include/gdb/net.h
Normal file
47
sysmodules/rosalina/include/gdb/net.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
#define _REENT_ONLY
|
||||
#include <errno.h>
|
||||
|
||||
u8 GDB_ComputeChecksum(const char *packetData, u32 len);
|
||||
void GDB_EncodeHex(char *dst, const void *src, u32 len);
|
||||
u32 GDB_DecodeHex(void *dst, const char *src, u32 len);
|
||||
u32 GDB_UnescapeBinaryData(void *dst, const void *src, u32 len);
|
||||
const char *GDB_ParseIntegerList(u32 *dst, const char *src, u32 nb, char sep, char lastSep, u32 base, bool allowPrefix);
|
||||
const char *GDB_ParseHexIntegerList(u32 *dst, const char *src, u32 nb, char lastSep);
|
||||
int GDB_ReceivePacket(GDBContext *ctx);
|
||||
int GDB_SendPacket(GDBContext *ctx, const char *packetData, u32 len);
|
||||
int GDB_SendFormattedPacket(GDBContext *ctx, const char *packetDataFmt, ...);
|
||||
int GDB_SendHexPacket(GDBContext *ctx, const void *packetData, u32 len);
|
||||
int GDB_SendStreamData(GDBContext *ctx, const char *streamData, u32 offset, u32 length, u32 totalSize, bool forceEmptyLast);
|
||||
int GDB_SendDebugString(GDBContext *ctx, const char *fmt, ...); // unsecure
|
||||
int GDB_ReplyEmpty(GDBContext *ctx);
|
||||
int GDB_ReplyOk(GDBContext *ctx);
|
||||
int GDB_ReplyErrno(GDBContext *ctx, int no);
|
||||
37
sysmodules/rosalina/include/gdb/query.h
Normal file
37
sysmodules/rosalina/include/gdb/query.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
int GDB_HandleReadQuery(GDBContext *ctx);
|
||||
int GDB_HandleWriteQuery(GDBContext *ctx);
|
||||
|
||||
GDB_DECLARE_QUERY_HANDLER(Supported);
|
||||
GDB_DECLARE_QUERY_HANDLER(StartNoAckMode);
|
||||
GDB_DECLARE_QUERY_HANDLER(Attached);
|
||||
GDB_DECLARE_QUERY_HANDLER(CatchSyscalls);
|
||||
34
sysmodules/rosalina/include/gdb/regs.h
Normal file
34
sysmodules/rosalina/include/gdb/regs.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
GDB_DECLARE_HANDLER(ReadRegisters);
|
||||
GDB_DECLARE_HANDLER(WriteRegisters);
|
||||
GDB_DECLARE_HANDLER(ReadRegister);
|
||||
GDB_DECLARE_HANDLER(WriteRegister);
|
||||
39
sysmodules/rosalina/include/gdb/remote_command.h
Normal file
39
sysmodules/rosalina/include/gdb/remote_command.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
#define GDB_REMOTE_COMMAND_HANDLER(name) GDB_HANDLER(RemoteCommand##name)
|
||||
#define GDB_DECLARE_REMOTE_COMMAND_HANDLER(name) GDB_DECLARE_HANDLER(RemoteCommand##name)
|
||||
|
||||
GDB_DECLARE_REMOTE_COMMAND_HANDLER(SyncRequestInfo);
|
||||
GDB_DECLARE_REMOTE_COMMAND_HANDLER(TranslateHandle);
|
||||
GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMmuConfig);
|
||||
GDB_DECLARE_REMOTE_COMMAND_HANDLER(FlushCaches);
|
||||
|
||||
GDB_DECLARE_QUERY_HANDLER(Rcmd);
|
||||
55
sysmodules/rosalina/include/gdb/server.h
Normal file
55
sysmodules/rosalina/include/gdb/server.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
#ifndef GDB_PORT_BASE
|
||||
#define GDB_PORT_BASE 4000
|
||||
#endif
|
||||
|
||||
typedef struct GDBServer
|
||||
{
|
||||
sock_server super;
|
||||
s32 referenceCount;
|
||||
Handle statusUpdated;
|
||||
GDBContext ctxs[MAX_DEBUG];
|
||||
} GDBServer;
|
||||
|
||||
Result GDB_InitializeServer(GDBServer *server);
|
||||
void GDB_FinalizeServer(GDBServer *server);
|
||||
|
||||
void GDB_IncrementServerReferenceCount(GDBServer *server);
|
||||
void GDB_DecrementServerReferenceCount(GDBServer *server);
|
||||
|
||||
void GDB_RunServer(GDBServer *server);
|
||||
|
||||
int GDB_AcceptClient(GDBContext *ctx);
|
||||
int GDB_CloseClient(GDBContext *ctx);
|
||||
GDBContext *GDB_GetClient(GDBServer *server, u16 port);
|
||||
void GDB_ReleaseClient(GDBServer *server, GDBContext *ctx);
|
||||
int GDB_DoPacket(GDBContext *ctx);
|
||||
31
sysmodules/rosalina/include/gdb/stop_point.h
Normal file
31
sysmodules/rosalina/include/gdb/stop_point.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
GDB_DECLARE_HANDLER(ToggleStopPoint);
|
||||
41
sysmodules/rosalina/include/gdb/thread.h
Normal file
41
sysmodules/rosalina/include/gdb/thread.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
u32 GDB_GetCurrentThreadFromList(GDBContext *ctx, u32 *threadIds, u32 nbThreads);
|
||||
u32 GDB_GetCurrentThread(GDBContext *ctx);
|
||||
|
||||
GDB_DECLARE_HANDLER(SetThreadId);
|
||||
GDB_DECLARE_HANDLER(IsThreadAlive);
|
||||
|
||||
GDB_DECLARE_QUERY_HANDLER(CurrentThreadId);
|
||||
GDB_DECLARE_QUERY_HANDLER(fThreadInfo);
|
||||
GDB_DECLARE_QUERY_HANDLER(sThreadInfo);
|
||||
GDB_DECLARE_QUERY_HANDLER(ThreadEvents);
|
||||
GDB_DECLARE_QUERY_HANDLER(ThreadExtraInfo);
|
||||
32
sysmodules/rosalina/include/gdb/verbose.h
Normal file
32
sysmodules/rosalina/include/gdb/verbose.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
GDB_DECLARE_HANDLER(VerboseCommand);
|
||||
GDB_DECLARE_VERBOSE_HANDLER(ContinueSupported);
|
||||
44
sysmodules/rosalina/include/gdb/watchpoints.h
Normal file
44
sysmodules/rosalina/include/gdb/watchpoints.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
typedef enum WatchpointKind
|
||||
{
|
||||
WATCHPOINT_DISABLED = 0,
|
||||
WATCHPOINT_READ,
|
||||
WATCHPOINT_WRITE,
|
||||
WATCHPOINT_READWRITE
|
||||
} WatchpointKind;
|
||||
|
||||
void GDB_ResetWatchpoints(void); // needed for software breakpoints to be detected as debug events as well
|
||||
|
||||
int GDB_AddWatchpoint(GDBContext *ctx, u32 address, u32 size, WatchpointKind kind);
|
||||
int GDB_RemoveWatchpoint(GDBContext *ctx, u32 address, WatchpointKind kind);
|
||||
|
||||
WatchpointKind GDB_GetWatchpointKind(GDBContext *ctx, u32 address);
|
||||
45
sysmodules/rosalina/include/gdb/xfer.h
Normal file
45
sysmodules/rosalina/include/gdb/xfer.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gdb.h"
|
||||
|
||||
#define GDB_XFER_HANDLER(name) GDB_HANDLER(Xfer##name)
|
||||
#define GDB_DECLARE_XFER_HANDLER(name) int GDB_XFER_HANDLER(name)(GDBContext *ctx, bool write, const char *annex, u32 offset, u32 length)
|
||||
|
||||
#define GDB_XFER_OSDATA_HANDLER(name) GDB_XFER_HANDLER(OsData##name)
|
||||
#define GDB_DECLARE_XFER_OSDATA_HANDLER(name) int GDB_XFER_OSDATA_HANDLER(name)(GDBContext *ctx, bool write, u32 offset, u32 length)
|
||||
|
||||
GDB_DECLARE_XFER_HANDLER(Features);
|
||||
|
||||
GDB_DECLARE_XFER_OSDATA_HANDLER(CfwVersion);
|
||||
GDB_DECLARE_XFER_OSDATA_HANDLER(Memory);
|
||||
GDB_DECLARE_XFER_OSDATA_HANDLER(Processes);
|
||||
|
||||
GDB_DECLARE_XFER_HANDLER(OsData);
|
||||
|
||||
GDB_DECLARE_QUERY_HANDLER(Xfer);
|
||||
38
sysmodules/rosalina/include/hbloader.h
Normal file
38
sysmodules/rosalina/include/hbloader.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/* File mainly written by fincs */
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "MyThread.h"
|
||||
|
||||
#define HBLDR_DEFAULT_3DSX_TID 0x000400000D921E00ULL
|
||||
#define HBLDR_3DSX_TID (*(vu64 *)0x1FF81100)
|
||||
|
||||
MyThread *hbldrCreateThread(void);
|
||||
|
||||
void hbldrThreadMain(void);
|
||||
44
sysmodules/rosalina/include/ifile.h
Normal file
44
sysmodules/rosalina/include/ifile.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
#define PATH_MAX 255
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Handle handle;
|
||||
u64 pos;
|
||||
u64 size;
|
||||
} IFile;
|
||||
|
||||
Result IFile_Open(IFile *file, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 flags);
|
||||
Result IFile_Close(IFile *file);
|
||||
Result IFile_GetSize(IFile *file, u64 *size);
|
||||
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
|
||||
Result IFile_Write(IFile *file, u64 *total, void *buffer, u32 len, u32 flags);
|
||||
39
sysmodules/rosalina/include/input_redirection.h
Normal file
39
sysmodules/rosalina/include/input_redirection.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "MyThread.h"
|
||||
|
||||
extern bool inputRedirectionEnabled;
|
||||
extern Handle inputRedirectionThreadStartedEvent;
|
||||
|
||||
extern int inputRedirectionStartResult;
|
||||
|
||||
MyThread *inputRedirectionCreateThread(void);
|
||||
void inputRedirectionThreadMain(void);
|
||||
Result InputRedirection_DoOrUndoPatches(void);
|
||||
38
sysmodules/rosalina/include/kernel_extension.h
Normal file
38
sysmodules/rosalina/include/kernel_extension.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PA_FROM_VA_PTR(addr) PA_PTR(convertVAToPA(addr))
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
Result svc0x2F(void *function, ...); // custom backdoor before kernel ext. is installed (and only before!)
|
||||
|
||||
void *convertVAToPA(const void *VA);
|
||||
|
||||
extern u8 kernel_extension[];
|
||||
extern u32 kernel_extension_size;
|
||||
30
sysmodules/rosalina/include/kernel_extension_setup.h
Normal file
30
sysmodules/rosalina/include/kernel_extension_setup.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <3ds/types.h>
|
||||
|
||||
void installKernelExtension(void);
|
||||
44
sysmodules/rosalina/include/memory.h
Normal file
44
sysmodules/rosalina/include/memory.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, u32 size);
|
||||
int memcmp(const void *buf1, const void *buf2, u32 size);
|
||||
void *memset(void *dest, u32 value, u32 size) __attribute__((used));
|
||||
void *memset32(void *dest, u32 value, u32 size);
|
||||
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, u32 size);
|
||||
s32 strnlen(const char *string, s32 maxlen);
|
||||
s32 strlen(const char *string);
|
||||
s32 strcmp(const char *str1, const char *str2);
|
||||
s32 strncmp(const char *str1, const char *str2, u32 size);
|
||||
const char *strchr(const char *string, int c);
|
||||
void hexItoa(u64 number, char *out, u32 digits, bool uppercase);
|
||||
unsigned long int xstrtoul(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok);
|
||||
85
sysmodules/rosalina/include/menu.h
Normal file
85
sysmodules/rosalina/include/menu.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "MyThread.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define HID_PAD (REG32(0x10146000) ^ 0xFFF)
|
||||
|
||||
#define BUTTON_A (1 << 0)
|
||||
#define BUTTON_B (1 << 1)
|
||||
#define BUTTON_SELECT (1 << 2)
|
||||
#define BUTTON_START (1 << 3)
|
||||
#define BUTTON_RIGHT (1 << 4)
|
||||
#define BUTTON_LEFT (1 << 5)
|
||||
#define BUTTON_UP (1 << 6)
|
||||
#define BUTTON_DOWN (1 << 7)
|
||||
#define BUTTON_R1 (1 << 8)
|
||||
#define BUTTON_L1 (1 << 9)
|
||||
#define BUTTON_X (1 << 10)
|
||||
#define BUTTON_Y (1 << 11)
|
||||
|
||||
#define DEFAULT_MENU_COMBO (BUTTON_L1 | BUTTON_DOWN | BUTTON_SELECT)
|
||||
|
||||
#define CORE_APPLICATION 0
|
||||
#define CORE_SYSTEM 1
|
||||
|
||||
typedef enum MenuItemAction {
|
||||
METHOD,
|
||||
MENU
|
||||
} MenuItemAction;
|
||||
typedef struct MenuItem {
|
||||
const char *title;
|
||||
|
||||
MenuItemAction action_type;
|
||||
union {
|
||||
struct Menu *menu;
|
||||
void (*method)(void);
|
||||
};
|
||||
} MenuItem;
|
||||
typedef struct Menu {
|
||||
const char *title;
|
||||
|
||||
u32 nbItems;
|
||||
MenuItem items[0x40];
|
||||
} Menu;
|
||||
|
||||
extern bool terminationRequest;
|
||||
extern Handle terminationRequestEvent;
|
||||
|
||||
extern u32 menuCombo;
|
||||
|
||||
u32 waitInputWithTimeout(u32 msec);
|
||||
u32 waitInput(void);
|
||||
|
||||
MyThread *menuCreateThread(void);
|
||||
void menuEnter(void);
|
||||
void menuLeave(void);
|
||||
void menuThreadMain(void);
|
||||
void menuShow(Menu *root);
|
||||
37
sysmodules/rosalina/include/menus.h
Normal file
37
sysmodules/rosalina/include/menus.h
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "menu.h"
|
||||
|
||||
extern Menu rosalinaMenu;
|
||||
|
||||
void RosalinaMenu_TakeScreenshot(void);
|
||||
void RosalinaMenu_ShowCredits(void);
|
||||
void RosalinaMenu_ProcessList(void);
|
||||
35
sysmodules/rosalina/include/menus/debugger.h
Normal file
35
sysmodules/rosalina/include/menus/debugger.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "menu.h"
|
||||
|
||||
extern Menu debuggerMenu;
|
||||
|
||||
void DebuggerMenu_EnableDebugger(void);
|
||||
void DebuggerMenu_DisableDebugger(void);
|
||||
36
sysmodules/rosalina/include/menus/miscellaneous.h
Normal file
36
sysmodules/rosalina/include/menus/miscellaneous.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "menu.h"
|
||||
|
||||
extern Menu miscellaneousMenu;
|
||||
|
||||
void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void);
|
||||
void MiscellaneousMenu_ChangeMenuCombo(void);
|
||||
void MiscellaneousMenu_InputRedirection(void);
|
||||
36
sysmodules/rosalina/include/menus/n3ds.h
Normal file
36
sysmodules/rosalina/include/menus/n3ds.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "menu.h"
|
||||
|
||||
extern Menu N3DSMenu;
|
||||
|
||||
void N3DSMenu_UpdateStatus(void);
|
||||
void N3DSMenu_ChangeClockRate(void);
|
||||
void N3DSMenu_EnableDisableL2Cache(void);
|
||||
33
sysmodules/rosalina/include/menus/process_list.h
Normal file
33
sysmodules/rosalina/include/menus/process_list.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
#define PROCESSES_PER_MENU_PAGE 18
|
||||
|
||||
void RosalinaMenu_ProcessList(void);
|
||||
35
sysmodules/rosalina/include/menus/process_patches.h
Normal file
35
sysmodules/rosalina/include/menus/process_patches.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "menu.h"
|
||||
|
||||
extern Menu processPatchesMenu;
|
||||
|
||||
void ProcessPatchesMenu_PatchUnpatchSM(void);
|
||||
void ProcessPatchesMenu_PatchUnpatchFS(void);
|
||||
62
sysmodules/rosalina/include/minisoc.h
Normal file
62
sysmodules/rosalina/include/minisoc.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/services/soc.h>
|
||||
#include <poll.h>
|
||||
|
||||
#define _REENT_ONLY
|
||||
#include <errno.h>
|
||||
|
||||
#define SYNC_ERROR ENODEV
|
||||
|
||||
extern Handle SOCU_handle;
|
||||
extern Handle socMemhandle;
|
||||
|
||||
Result miniSocInit();
|
||||
Result miniSocExit(void);
|
||||
|
||||
s32 _net_convert_error(s32 sock_retval);
|
||||
|
||||
int socSocket(int domain, int type, int protocol);
|
||||
int socBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
int socListen(int sockfd, int max_connections);
|
||||
int socAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int socPoll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
int socSetsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
int socClose(int sockfd);
|
||||
|
||||
ssize_t soc_recv(int sockfd, void *buf, size_t len, int flags);
|
||||
ssize_t soc_send(int sockfd, const void *buf, size_t len, int flags);
|
||||
|
||||
// actually provided by ctrulib
|
||||
ssize_t soc_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
|
||||
ssize_t soc_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
40
sysmodules/rosalina/include/services.h
Normal file
40
sysmodules/rosalina/include/services.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
#define SDK_VERSION 0x70200C8
|
||||
|
||||
/// Initializes the service API.
|
||||
Result srvSysInit(void);
|
||||
|
||||
/// Exits the service API.
|
||||
Result srvSysExit(void);
|
||||
|
||||
/// Initializes FSUSER. Requires FSREG.
|
||||
void fsSysInit(void);
|
||||
95
sysmodules/rosalina/include/sock_util.h
Normal file
95
sysmodules/rosalina/include/sock_util.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/* File mainly written by Stary */
|
||||
|
||||
#pragma once
|
||||
#include <3ds/types.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define MAX_PORTS 3
|
||||
#define MAX_CTXS (2 * MAX_PORTS)
|
||||
|
||||
struct sock_server;
|
||||
struct sock_ctx;
|
||||
|
||||
typedef int (*sock_accept_cb)(struct sock_ctx *client_ctx);
|
||||
typedef int (*sock_data_cb)(struct sock_ctx *client_ctx);
|
||||
typedef int (*sock_close_cb)(struct sock_ctx *client_ctx);
|
||||
|
||||
typedef struct sock_ctx* (*sock_alloc_func)(struct sock_server *serv, u16 port);
|
||||
typedef void (*sock_free_func)(struct sock_server *serv, struct sock_ctx *ctx);
|
||||
|
||||
typedef enum socket_type
|
||||
{
|
||||
SOCK_NONE,
|
||||
SOCK_SERVER,
|
||||
SOCK_CLIENT
|
||||
} socket_type;
|
||||
|
||||
typedef struct sock_ctx
|
||||
{
|
||||
enum socket_type type;
|
||||
bool should_close;
|
||||
int sockfd;
|
||||
struct sockaddr_in addr_in;
|
||||
struct sock_ctx *serv;
|
||||
int n;
|
||||
int i;
|
||||
} sock_ctx;
|
||||
|
||||
typedef struct sock_server
|
||||
{
|
||||
// params
|
||||
u32 host;
|
||||
int clients_per_server;
|
||||
|
||||
// poll stuff
|
||||
struct pollfd poll_fds[MAX_CTXS];
|
||||
struct sock_ctx serv_ctxs[MAX_PORTS];
|
||||
struct sock_ctx *ctx_ptrs[MAX_CTXS];
|
||||
|
||||
nfds_t nfds;
|
||||
bool running;
|
||||
Handle started_event;
|
||||
bool compact_needed;
|
||||
|
||||
// callbacks
|
||||
sock_accept_cb accept_cb;
|
||||
sock_data_cb data_cb;
|
||||
sock_close_cb close_cb;
|
||||
|
||||
sock_alloc_func alloc;
|
||||
sock_free_func free;
|
||||
|
||||
Handle shall_terminate_event;
|
||||
} sock_server;
|
||||
|
||||
Result server_init(struct sock_server *serv);
|
||||
void server_bind(struct sock_server *serv, u16 port);
|
||||
void server_run(struct sock_server *serv);
|
||||
void server_finalize(struct sock_server *serv);
|
||||
59
sysmodules/rosalina/include/utils.h
Normal file
59
sysmodules/rosalina/include/utils.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/result.h>
|
||||
#include "csvc.h"
|
||||
|
||||
// For accessing physmem uncached (and directly)
|
||||
#define PA_PTR(addr) (void *)((u32)(addr) | 1 << 31)
|
||||
|
||||
#ifndef PA_FROM_VA_PTR
|
||||
#define PA_FROM_VA_PTR(addr) PA_PTR(svcConvertVAToPA((const void *)(addr), false))
|
||||
#endif
|
||||
|
||||
#define REG32(addr) (*(vu32 *)(PA_PTR(addr)))
|
||||
|
||||
static inline u32 makeARMBranch(const void *src, const void *dst, bool link) // the macros for those are ugly and buggy
|
||||
{
|
||||
u32 instrBase = link ? 0xEB000000 : 0xEA000000;
|
||||
u32 off = (u32)((const u8 *)dst - ((const u8 *)src + 8)); // the PC is always two instructions ahead of the one being executed
|
||||
|
||||
return instrBase | ((off >> 2) & 0xFFFFFF);
|
||||
}
|
||||
|
||||
static inline void *decodeARMBranch(const void *src)
|
||||
{
|
||||
u32 instr = *(const u32 *)src;
|
||||
s32 off = (instr & 0xFFFFFF) << 2;
|
||||
off = (off << 6) >> 6; // sign extend
|
||||
|
||||
return (void *)((const u8 *)src + 8 + off);
|
||||
}
|
||||
|
||||
Result OpenProcessByName(const char *name, Handle *h);
|
||||
47
sysmodules/rosalina/kernel_extension/Makefile
Normal file
47
sysmodules/rosalina/kernel_extension/Makefile
Normal file
@@ -0,0 +1,47 @@
|
||||
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/base_tools
|
||||
|
||||
name := kernel_extension
|
||||
|
||||
dir_source := source
|
||||
dir_include := include
|
||||
dir_build := build
|
||||
|
||||
ARCH := -mcpu=mpcore -mfpu=vfp
|
||||
ASFLAGS := $(ARCH)
|
||||
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -I$(dir_include) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math \
|
||||
-mword-relocations -ffunction-sections -fdata-sections
|
||||
LDFLAGS := -nostdlib -Wl,--gc-sections $(ARCH)
|
||||
|
||||
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||
|
||||
.PHONY: all
|
||||
all: ../$(dir_build)/$(name).bin
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -rf $(dir_build)
|
||||
|
||||
../$(dir_build)/$(name).bin: $(dir_build)/$(name).elf
|
||||
$(OBJCOPY) -S -O binary $< $@
|
||||
|
||||
$(dir_build)/$(name).elf: $(objects)
|
||||
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||
|
||||
$(dir_build)/memory.o : CFLAGS += -O3 -marm
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.c
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.s
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||
include $(call rwildcard, $(dir_build), *.d)
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
bool isExceptionFatal(u32 spsr);
|
||||
bool isDataAbortExceptionRangeControlled(u32 spsr, u32 addr);
|
||||
|
||||
|
||||
void FIQHandler(void);
|
||||
void undefinedInstructionHandler(void);
|
||||
void prefetchAbortHandler(void);
|
||||
void dataAbortHandler(void);
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
u32 magic[2];
|
||||
u16 versionMinor, versionMajor;
|
||||
|
||||
u16 processor, core;
|
||||
u32 type;
|
||||
|
||||
u32 totalSize;
|
||||
u32 registerDumpSize;
|
||||
u32 codeDumpSize;
|
||||
u32 stackDumpSize;
|
||||
u32 additionalDataSize;
|
||||
} ExceptionDumpHeader;
|
||||
121
sysmodules/rosalina/kernel_extension/include/globals.h
Normal file
121
sysmodules/rosalina/kernel_extension/include/globals.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
extern KRecursiveLock *criticalSectionLock;
|
||||
extern KObjectList *threadList;
|
||||
extern KObjectMutex *synchronizationMutex;
|
||||
|
||||
extern void (*KRecursiveLock__Lock)(KRecursiveLock *this);
|
||||
extern void (*KRecursiveLock__Unlock)(KRecursiveLock *this);
|
||||
|
||||
extern void (*KAutoObject__AddReference)(KAutoObject *this);
|
||||
|
||||
extern KProcess * (*KProcessHandleTable__ToKProcess)(KProcessHandleTable *this, Handle processHandle);
|
||||
extern KThread * (*KProcessHandleTable__ToKThread)(KProcessHandleTable *this, Handle threadHandle);
|
||||
extern KAutoObject * (*KProcessHandleTable__ToKAutoObject)(KProcessHandleTable *this, Handle handle);
|
||||
extern void (*KSynchronizationObject__Signal)(KSynchronizationObject *this, bool isPulse);
|
||||
extern Result (*WaitSynchronization1)(void *this_unused, KThread *thread, KSynchronizationObject *syncObject, s64 timeout);
|
||||
extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Handle *out, KAutoObject *obj, u8 token);
|
||||
extern Result (*KProcessHwInfo__MapProcessMemory)(KProcessHwInfo *this, KProcessHwInfo *other, void *dst, void *src, u32 nbPages);
|
||||
extern Result (*KProcessHwInfo__UnmapProcessMemory)(KProcessHwInfo *this, void *addr, u32 nbPages);
|
||||
extern Result (*KEvent__Clear)(KEvent *this);
|
||||
extern void (*KObjectMutex__WaitAndAcquire)(KObjectMutex *this);
|
||||
extern void (*KObjectMutex__ErrorOccured)(void);
|
||||
|
||||
extern void (*KScheduler__AdjustThread)(KScheduler *this, KThread *thread, u32 oldSchedulingMask);
|
||||
extern void (*KScheduler__AttemptSwitchingThreadContext)(KScheduler *this);
|
||||
|
||||
extern Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||
extern void (*SleepThread)(s64 ns);
|
||||
extern Result (*CloseHandle)(Handle handle);
|
||||
extern Result (*GetSystemInfo)(s64 *out, s32 type, s32 param);
|
||||
extern Result (*GetProcessInfo)(s64 *out, Handle processHandle, u32 type);
|
||||
extern Result (*GetThreadInfo)(s64 *out, Handle threadHandle, u32 type);
|
||||
extern Result (*ConnectToPort)(Handle *out, const char *name);
|
||||
extern Result (*SendSyncRequest)(Handle handle);
|
||||
extern Result (*OpenProcess)(Handle *out, u32 processId);
|
||||
extern Result (*GetProcessId)(u32 *out, Handle process);
|
||||
extern Result (*DebugActiveProcess)(Handle *out, u32 processId);
|
||||
extern Result (*KernelSetState)(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||
|
||||
extern void (*flushDataCacheRange)(void *addr, u32 len);
|
||||
extern void (*invalidateInstructionCacheRange)(void *addr, u32 len);
|
||||
|
||||
extern bool (*usrToKernelMemcpy8)(void *dst, const void *src, u32 len);
|
||||
extern bool (*usrToKernelMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
extern s32 (*usrToKernelStrncpy)(char *dst, const char *src, u32 len);
|
||||
extern bool (*kernelToUsrMemcpy8)(void *dst, const void *src, u32 len);
|
||||
extern bool (*kernelToUsrMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
extern s32 (*kernelToUsrStrncpy)(char *dst, const char *src, u32 len);
|
||||
|
||||
extern Result (*CustomBackdoor)(void *function, ...);
|
||||
|
||||
extern void (*svcFallbackHandler)(u8 svcId);
|
||||
extern void (*kernelpanic)(void);
|
||||
extern void (*PostprocessSvc)(void);
|
||||
|
||||
extern Result (*SignalDebugEvent)(DebugEventType type, u32 info, ...);
|
||||
|
||||
extern bool isN3DS;
|
||||
extern u32 *exceptionStackTop;
|
||||
|
||||
extern u32 TTBCR;
|
||||
extern u32 L1MMUTableAddrs[4];
|
||||
|
||||
extern u32 kernelVersion;
|
||||
extern void *kernelUsrCopyFuncsStart, *kernelUsrCopyFuncsEnd;
|
||||
|
||||
extern bool *isDevUnit;
|
||||
|
||||
extern InterruptManager *interruptManager;
|
||||
extern KBaseInterruptEvent *customInterruptEvent;
|
||||
|
||||
extern void (*initFPU)(void);
|
||||
extern void (*mcuReboot)(void);
|
||||
extern void (*coreBarrier)(void);
|
||||
|
||||
typedef struct PACKED CfwInfo
|
||||
{
|
||||
char magic[4];
|
||||
|
||||
u8 versionMajor;
|
||||
u8 versionMinor;
|
||||
u8 versionBuild;
|
||||
u8 flags;
|
||||
|
||||
u32 commitHash;
|
||||
|
||||
u32 config;
|
||||
} CfwInfo;
|
||||
|
||||
extern CfwInfo cfwInfo;
|
||||
|
||||
extern u32 rosalinaState;
|
||||
extern bool hasStartedRosalinaNetworkFuncsOnce;
|
||||
61
sysmodules/rosalina/kernel_extension/include/ipc.h
Normal file
61
sysmodules/rosalina/kernel_extension/include/ipc.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "globals.h"
|
||||
#include "kernel.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_SESSION 345
|
||||
|
||||
// the structure of sessions is apparently not the same on older versions...
|
||||
|
||||
typedef struct SessionInfo
|
||||
{
|
||||
KSession *session;
|
||||
char name[12];
|
||||
} SessionInfo;
|
||||
|
||||
typedef struct LangemuAttributes
|
||||
{
|
||||
u64 titleId;
|
||||
u8 mask, region, language, country, state;
|
||||
} LangemuAttributes;
|
||||
|
||||
extern KRecursiveLock processLangemuLock;
|
||||
extern LangemuAttributes processLangemuAttributes[0x40];
|
||||
|
||||
SessionInfo *SessionInfo_Lookup(KSession *session);
|
||||
SessionInfo *SessionInfo_FindFirst(const char *name);
|
||||
void SessionInfo_ChangeVtable(KSession *session);
|
||||
void SessionInfo_Add(KSession *session, const char *name);
|
||||
void SessionInfo_Remove(KSession *session);
|
||||
|
||||
bool doLangEmu(Result *res, Handle handle, u32 *cmdbuf);
|
||||
Result doPublishToProcessHook(Handle handle, u32 *cmdbuf);
|
||||
bool doErrfThrowHook(u32 *cmdbuf);
|
||||
1190
sysmodules/rosalina/kernel_extension/include/kernel.h
Normal file
1190
sysmodules/rosalina/kernel_extension/include/kernel.h
Normal file
File diff suppressed because it is too large
Load Diff
42
sysmodules/rosalina/kernel_extension/include/memory.h
Normal file
42
sysmodules/rosalina/kernel_extension/include/memory.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void *memcpy(void *dest, const void *src, u32 size) USED;
|
||||
int memcmp(const void *buf1, const void *buf2, u32 size) USED;
|
||||
void *memset(void *dest, u32 value, u32 size) USED; // thanks binutils for the nice bug involving memset.
|
||||
void *memset32(void *dest, u32 value, u32 size);
|
||||
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, u32 size);
|
||||
s32 strnlen(const char *string, s32 maxlen);
|
||||
s32 strlen(const char *string);
|
||||
s32 strcmp(const char *str1, const char *str2);
|
||||
s32 strncmp(const char *str1, const char *str2, u32 size);
|
||||
void hexItoa(u64 number, char *out, u32 digits, bool uppercase);
|
||||
37
sysmodules/rosalina/kernel_extension/include/svc.h
Normal file
37
sysmodules/rosalina/kernel_extension/include/svc.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "globals.h"
|
||||
#include "kernel.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern void *officialSVCs[0x7E];
|
||||
|
||||
void svcDefaultHandler(u8 svcId);
|
||||
void *svcHook(u8 *pageEnd);
|
||||
33
sysmodules/rosalina/kernel_extension/include/svc/Backdoor.h
Normal file
33
sysmodules/rosalina/kernel_extension/include/svc/Backdoor.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
void Backdoor(void *function);
|
||||
32
sysmodules/rosalina/kernel_extension/include/svc/Break.h
Normal file
32
sysmodules/rosalina/kernel_extension/include/svc/Break.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
|
||||
void __attribute__((noreturn)) Break(UserBreakType type, ...);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result ConnectToPortHookWrapper(u32 dummy, const char *name);
|
||||
Result ConnectToPortHook(Handle *out, const char *name);
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result ControlMemoryHookWrapper(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
|
||||
Result ControlMemoryHook(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
|
||||
Result ControlMemoryEx(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
/// Operations for svcControlService
|
||||
typedef enum ServiceOp
|
||||
{
|
||||
SERVICEOP_STEAL_CLIENT_SESSION = 0, ///< Steal a client session given a service or global port name
|
||||
SERVICEOP_GET_NAME, ///< Get the name of a service or global port given a client or session handle
|
||||
} ServiceOp;
|
||||
|
||||
Result ControlService(ServiceOp op, u32 varg1, u32 varg2);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result CopyHandleWrapper(Handle *outHandle, Handle outProcessHandle, Handle inHandle, Handle inProcessHandle);
|
||||
Result CopyHandle(Handle *outHandle, Handle outProcessHandle, Handle inHandle, Handle inProcessHandle);
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
#include "globals.h"
|
||||
|
||||
// DEPRECATED
|
||||
Result GetCFWInfo(CfwInfo *out);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result GetProcessInfoHookWrapper(u32 dummy, Handle processHandle, u32 type);
|
||||
Result GetProcessInfoHook(s64 *out, Handle processHandle, u32 type);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result GetSystemInfoHookWrapper(u32 dummy, s32 type, s32 param);
|
||||
Result GetSystemInfoHook(s64 *out, s32 type, s32 param);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result GetThreadInfoHookWrapper(u32 dummy, Handle threadHandle, u32 type);
|
||||
Result GetThreadInfoHook(s64 *out, Handle threadHandle, u32 type);
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
extern u32 rosalinaState;
|
||||
bool shouldSignalSyscallDebugEvent(KProcess *process, u8 svcId);
|
||||
Result KernelSetStateHook(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result MapProcessMemoryEx(Handle processHandle, void *dst, void *src, u32 size);
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result SendSyncRequestHook(Handle handle);
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result SetGpuProt(bool prot);
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
void SetWifiEnabled(bool enable);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result TranslateHandleWrapper(u32 *outKAddr, char *outClassName, Handle handle);
|
||||
Result TranslateHandle(u32 *outKAddr, char *outClassName, Handle handle);
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "svc.h"
|
||||
|
||||
Result UnmapProcessMemoryEx(Handle processHandle, void *dst, u32 size);
|
||||
29
sysmodules/rosalina/kernel_extension/include/svcHandler.h
Normal file
29
sysmodules/rosalina/kernel_extension/include/svcHandler.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void svcHandler(void);
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "kernel.h"
|
||||
|
||||
typedef KSchedulableInterruptEvent* (*SGI0Handler_t)(KBaseInterruptEvent *this, u32 interruptID);
|
||||
|
||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0360f/CCHDIFIJ.html
|
||||
void executeFunctionOnCores(SGI0Handler_t func, u8 targetList, u8 targetListFilter);
|
||||
|
||||
// Taken from ctrulib:
|
||||
|
||||
static inline void __dsb(void)
|
||||
{
|
||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 4" :: [val] "r" (0) : "memory");
|
||||
}
|
||||
|
||||
static inline void __clrex(void)
|
||||
{
|
||||
__asm__ __volatile__("clrex" ::: "memory");
|
||||
}
|
||||
|
||||
static inline s32 __ldrex(s32* addr)
|
||||
{
|
||||
s32 val;
|
||||
__asm__ __volatile__("ldrex %[val], %[addr]" : [val] "=r" (val) : [addr] "Q" (*addr));
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline bool __strex(s32* addr, s32 val)
|
||||
{
|
||||
bool res;
|
||||
__asm__ __volatile__("strex %[res], %[val], %[addr]" : [res] "=&r" (res) : [val] "r" (val), [addr] "Q" (*addr));
|
||||
return res;
|
||||
}
|
||||
97
sysmodules/rosalina/kernel_extension/include/types.h
Normal file
97
sysmodules/rosalina/kernel_extension/include/types.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
// Taken from ctrulib
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/// The maximum value of a u64.
|
||||
#define U64_MAX UINT64_MAX
|
||||
|
||||
/// would be nice if newlib had this already
|
||||
#ifndef SSIZE_MAX
|
||||
#ifdef SIZE_MAX
|
||||
#define SSIZE_MAX ((SIZE_MAX) >> 1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8; ///< 8-bit unsigned integer
|
||||
typedef uint16_t u16; ///< 16-bit unsigned integer
|
||||
typedef uint32_t u32; ///< 32-bit unsigned integer
|
||||
typedef uint64_t u64; ///< 64-bit unsigned integer
|
||||
|
||||
typedef int8_t s8; ///< 8-bit signed integer
|
||||
typedef int16_t s16; ///< 16-bit signed integer
|
||||
typedef int32_t s32; ///< 32-bit signed integer
|
||||
typedef int64_t s64; ///< 64-bit signed integer
|
||||
|
||||
typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
|
||||
typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
|
||||
typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
|
||||
typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
|
||||
|
||||
typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
|
||||
typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
|
||||
typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
|
||||
typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
|
||||
|
||||
typedef u32 Handle; ///< Resource handle.
|
||||
typedef s32 Result; ///< Function result.
|
||||
|
||||
/// Creates a bitmask from a bit number.
|
||||
#define BIT(n) (1U<<(n))
|
||||
|
||||
/// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m.
|
||||
#define ALIGN(m) __attribute__((aligned(m)))
|
||||
/// Packs a struct (and other types?) so it won't include padding bytes.
|
||||
#define PACKED __attribute__((packed))
|
||||
#define USED __attribute__((used))
|
||||
#define UNUSED __attribute__((unused))
|
||||
/// Packs a system version from its components.
|
||||
#define SYSTEM_VERSION(major, minor, revision) \
|
||||
(((major)<<24)|((minor)<<16)|((revision)<<8))
|
||||
|
||||
#define CUR_THREAD_HANDLE 0xFFFF8000
|
||||
#define CUR_PROCESS_HANDLE 0xFFFF8001
|
||||
|
||||
#define MPCORE_REGS_BASE (0x17E00000 | (1u << 31))
|
||||
#define MPCORE_SCU_CFG (*(vu32 *)(MPCORE_REGS_BASE + 4))
|
||||
#define MPCORE_INT_ACK (*(vu32 *)(MPCORE_REGS_BASE + 0x10C))
|
||||
|
||||
#define MPCORE_GID_REGS_BASE (MPCORE_REGS_BASE + 0x1000)
|
||||
#define MPCORE_GID_SGI (*(vu32 *)(MPCORE_GID_REGS_BASE + 0xF00))
|
||||
|
||||
#define CFG11_REGS_BASE (0x10140000 | (1u << 31))
|
||||
#define CFG11_WIFICNT (*(vu8 *)(CFG11_REGS_BASE + 0x180))
|
||||
#define CFG11_MPCORE_CFG (*(vu16 *)(CFG11_REGS_BASE + 0xFFC))
|
||||
#define CFG11_MPCORE_CLKCNT (*(vu16 *)(CFG11_REGS_BASE + 0x1300))
|
||||
|
||||
#define L2C_REGS_BASE (0x17E10000 | (1u << 31))
|
||||
#define L2C_CTRL (*(vu32 *)(L2C_REGS_BASE + 0x100))
|
||||
87
sysmodules/rosalina/kernel_extension/include/utils.h
Normal file
87
sysmodules/rosalina/kernel_extension/include/utils.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "kernel.h"
|
||||
|
||||
// For accessing physmem uncached (and directly)
|
||||
#define PA_PTR(addr) (void *)((u32)(addr) | 1u << 31)
|
||||
#define PA_FROM_VA_PTR(addr) PA_PTR(convertVAToPA(addr, false))
|
||||
|
||||
static inline u32 makeARMBranch(const void *src, const void *dst, bool link) // the macros for those are ugly and buggy
|
||||
{
|
||||
u32 instrBase = link ? 0xEB000000 : 0xEA000000;
|
||||
u32 off = (u32)((const u8 *)dst - ((const u8 *)src + 8)); // the PC is always two instructions ahead of the one being executed
|
||||
|
||||
return instrBase | ((off >> 2) & 0xFFFFFF);
|
||||
}
|
||||
|
||||
static inline void *decodeARMBranch(const void *src)
|
||||
{
|
||||
u32 instr = *(const u32 *)src;
|
||||
s32 off = (instr & 0xFFFFFF) << 2;
|
||||
off = (off << 6) >> 6; // sign extend
|
||||
|
||||
return (void *)((const u8 *)src + 8 + off);
|
||||
}
|
||||
|
||||
// For ARM prologs in the form of: push {regs} ... sub sp, #off (this obviously doesn't intend to cover all cases)
|
||||
static inline u32 computeARMFrameSize(const u32 *prolog)
|
||||
{
|
||||
const u32 *off;
|
||||
|
||||
for(off = prolog; (*off >> 16) != 0xE92D; off++); // look for stmfd sp! = push
|
||||
u32 nbPushedRegs = 0;
|
||||
for(u32 val = *off & 0xFFFF; val != 0; val >>= 1) // 1 bit = 1 pushed register
|
||||
nbPushedRegs += val & 1;
|
||||
for(; (*off >> 8) != 0xE24DD0; off++); // look for sub sp, #offset
|
||||
u32 localVariablesSpaceSize = *off & 0xFF;
|
||||
|
||||
return 4 * nbPushedRegs + localVariablesSpaceSize;
|
||||
}
|
||||
|
||||
static inline u32 getNumberOfCores(void)
|
||||
{
|
||||
return (MPCORE_SCU_CFG & 3) + 1;
|
||||
}
|
||||
|
||||
static inline u32 getCurrentCoreID(void)
|
||||
{
|
||||
u32 coreId;
|
||||
__asm__ volatile("mrc p15, 0, %0, c0, c0, 5" : "=r"(coreId));
|
||||
return coreId & 3;
|
||||
}
|
||||
|
||||
u32 convertVAToPA(const void *addr, bool writeCheck);
|
||||
|
||||
u32 safecpy(void *dst, const void *src, u32 len);
|
||||
void KObjectMutex__Acquire(KObjectMutex *this);
|
||||
void KObjectMutex__Release(KObjectMutex *this);
|
||||
|
||||
void flushEntireDataCache(void);
|
||||
void invalidateEntireInstructionCache(void);
|
||||
14
sysmodules/rosalina/kernel_extension/linker.ld
Normal file
14
sysmodules/rosalina/kernel_extension/linker.ld
Normal file
@@ -0,0 +1,14 @@
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x40000000;
|
||||
|
||||
.text : ALIGN(4) { *(.text.start) *(.text*); . = ALIGN(4); }
|
||||
.rodata : ALIGN(4) { *(.rodata*); . = ALIGN(4); }
|
||||
.data : ALIGN(4) { *(.data*); . = ALIGN(8); *(.bss* COMMON); . = ALIGN(8); }
|
||||
|
||||
. = ALIGN(4);
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
@
|
||||
@ This program is free software: you can redistribute it and/or modify
|
||||
@ it under the terms of the GNU General Public License as published by
|
||||
@ the Free Software Foundation, either version 3 of the License, or
|
||||
@ (at your option) any later version.
|
||||
@
|
||||
@ This program is distributed in the hope that it will be useful,
|
||||
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
@ GNU General Public License for more details.
|
||||
@
|
||||
@ You should have received a copy of the GNU General Public License
|
||||
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.macro TEST_IF_MODE_AND_ARM_INST_OR_JUMP lbl, mode
|
||||
cpsid aif
|
||||
mrs sp, spsr
|
||||
tst sp, #0x20
|
||||
bne \lbl
|
||||
and sp, #0x1f @ get previous processor mode
|
||||
cmp sp, #\mode
|
||||
bne \lbl
|
||||
|
||||
sub sp, lr, #4
|
||||
mcr p15, 0, sp, c7, c8, 0 @ VA to PA translation with privileged read permission check
|
||||
mrc p15, 0, sp, c7, c4, 0 @ read PA register
|
||||
tst sp, #1 @ failure bit
|
||||
bne \lbl
|
||||
.endm
|
||||
|
||||
|
||||
.macro GEN_USUAL_HANDLER name, index, pos
|
||||
\name\()Handler:
|
||||
ldr sp, =exceptionStackTop
|
||||
ldr sp, [sp]
|
||||
sub sp, #0x100
|
||||
|
||||
push {r0-r12, lr}
|
||||
mrs r0, spsr
|
||||
bl isExceptionFatal
|
||||
cmp r0, #0
|
||||
pop {r0-r12, lr}
|
||||
bne _exc_is_fatal_\name
|
||||
|
||||
ldr sp, =originalHandlers
|
||||
ldr sp, [sp, #\pos]
|
||||
bx sp
|
||||
|
||||
_exc_is_fatal_\name:
|
||||
push {r8, r9}
|
||||
mov r8, #\index
|
||||
b _commonHandler
|
||||
.endm
|
||||
|
||||
.text
|
||||
.arm
|
||||
.balign 4
|
||||
|
||||
_die:
|
||||
cpsid aif
|
||||
_die_loop:
|
||||
wfi
|
||||
b _die_loop
|
||||
|
||||
_commonHandler:
|
||||
cpsid aif
|
||||
|
||||
push {r0}
|
||||
ldr r0, =_fatalExceptionOccured
|
||||
ldr r0, [r0]
|
||||
cmp r0, #0
|
||||
bne _die_loop
|
||||
pop {r0}
|
||||
|
||||
ldr r9, =_regs
|
||||
stmia r9, {r0-r7}
|
||||
mov r1, r8
|
||||
pop {r8,r9}
|
||||
|
||||
ldr r0, =_fatalExceptionOccured
|
||||
mov r4, #1
|
||||
|
||||
_try_lock:
|
||||
ldrex r2, [r0]
|
||||
strex r3, r4, [r0]
|
||||
cmp r3, #0
|
||||
bne _try_lock
|
||||
|
||||
push {r1, r12, lr} @ attempt to hang the other cores
|
||||
adr r0, _die
|
||||
mov r1, #0xf
|
||||
mov r2, #1
|
||||
mov r3, #0
|
||||
bl executeFunctionOnCores
|
||||
pop {r1, r12, lr}
|
||||
|
||||
mrs r2, spsr
|
||||
mrs r3, cpsr
|
||||
ldr r6, =_regs
|
||||
add r6, #0x20
|
||||
|
||||
ands r4, r2, #0xf @ get the mode that triggered the exception
|
||||
moveq r4, #0xf @ usr => sys
|
||||
bic r5, r3, #0xf
|
||||
orr r5, r4
|
||||
msr cpsr_c, r5 @ change processor mode
|
||||
stmia r6!, {r8-lr}
|
||||
msr cpsr_c, r3 @ restore processor mode
|
||||
|
||||
str lr, [r6], #4
|
||||
str r2, [r6], #4
|
||||
|
||||
mov r0, r6
|
||||
|
||||
mrc p15, 0, r4, c5, c0, 0 @ dfsr
|
||||
mrc p15, 0, r5, c5, c0, 1 @ ifsr
|
||||
mrc p15, 0, r6, c6, c0, 0 @ far
|
||||
fmrx r7, fpexc
|
||||
fmrx r8, fpinst
|
||||
fmrx r9, fpinst2
|
||||
bic r3, #(1<<31)
|
||||
fmxr fpexc, r3 @ clear the VFP11 exception flag (if it's set)
|
||||
|
||||
stmia r0!, {r4-r9}
|
||||
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c14, 0 @ Clean and Invalidate Entire Data Cache
|
||||
mcr p15, 0, r0, c7, c10, 4 @ Drain Synchronization Barrier
|
||||
|
||||
ldr r0, =isN3DS
|
||||
ldr r0, [r0]
|
||||
cmp r0, #0
|
||||
beq _no_L2C
|
||||
ldr r0, =(0x17e10100 | 1 << 31)
|
||||
ldr r0, [r0]
|
||||
tst r0, #1 @ is the L2C enabled?
|
||||
beq _no_L2C
|
||||
|
||||
ldr r0, =0xffff
|
||||
ldr r2, =(0x17e10730 | 1 << 31)
|
||||
str r0, [r2, #0x4c] @ invalidate by way
|
||||
|
||||
_L2C_sync:
|
||||
ldr r0, [r2] @ L2C cache sync register
|
||||
tst r0, #1
|
||||
bne _L2C_sync
|
||||
|
||||
_no_L2C:
|
||||
|
||||
cps #0x1F
|
||||
ldr sp, =exceptionStackTop
|
||||
ldr sp, [sp]
|
||||
sub sp, #0x100
|
||||
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c10, 5 @ Drain Memory Barrier
|
||||
ldr r0, =_regs
|
||||
mrc p15, 0, r2, c0, c0, 5 @ CPU ID register
|
||||
bl fatalExceptionHandlersMain
|
||||
|
||||
ldr r12, =mcuReboot
|
||||
ldr r12, [r12]
|
||||
bx r12
|
||||
|
||||
.global FIQHandler
|
||||
.type FIQHandler, %function
|
||||
GEN_USUAL_HANDLER FIQ, 0, 28
|
||||
|
||||
.global undefinedInstructionHandler
|
||||
.type undefinedInstructionHandler, %function
|
||||
undefinedInstructionHandler:
|
||||
TEST_IF_MODE_AND_ARM_INST_OR_JUMP _undefinedInstructionNormalHandler, 0x10
|
||||
|
||||
ldr sp, [lr, #-4] @ test if it's an VFP instruction that was aborted
|
||||
lsl sp, #4
|
||||
sub sp, #0xc0000000
|
||||
cmp sp, #0x30000000
|
||||
bcs _undefinedInstructionNormalHandler
|
||||
fmrx sp, fpexc
|
||||
tst sp, #0x40000000
|
||||
bne _undefinedInstructionNormalHandler
|
||||
|
||||
@ FPU init
|
||||
sub lr, #4
|
||||
srsfd sp!, #0x13
|
||||
cps #0x13
|
||||
stmfd sp, {r0-r3, r11-lr}^
|
||||
sub sp, #0x20
|
||||
ldr r12, =initFPU
|
||||
ldr r12, [r12]
|
||||
blx r12
|
||||
ldmfd sp, {r0-r3, r11-lr}^
|
||||
add sp, #0x20
|
||||
rfefd sp! @ retry aborted instruction
|
||||
|
||||
GEN_USUAL_HANDLER _undefinedInstructionNormal, 1, 4
|
||||
|
||||
.global prefetchAbortHandler
|
||||
.type prefetchAbortHandler, %function
|
||||
prefetchAbortHandler:
|
||||
TEST_IF_MODE_AND_ARM_INST_OR_JUMP _prefetchAbortNormalHandler, 0x13
|
||||
|
||||
ldr sp, =(Break + 3*4 + 4)
|
||||
cmp lr, sp
|
||||
bne _prefetchAbortNormalHandler
|
||||
|
||||
sub sp, r0, #0x110
|
||||
pop {r0-r7, r12, lr}
|
||||
pop {r8-r11}
|
||||
ldr lr, [sp, #8]!
|
||||
ldr sp, [sp, #4]
|
||||
msr spsr, sp
|
||||
addne lr, #2 @ adjust address for later
|
||||
|
||||
GEN_USUAL_HANDLER _prefetchAbortNormal, 2, 12
|
||||
|
||||
.global dataAbortHandler
|
||||
.type dataAbortHandler, %function
|
||||
dataAbortHandler:
|
||||
ldr sp, =exceptionStackTop
|
||||
ldr sp, [sp]
|
||||
push {r0-r12, lr}
|
||||
mrs r0, spsr
|
||||
sub r1, lr, #8
|
||||
bl isDataAbortExceptionRangeControlled
|
||||
cmp r0, #0
|
||||
pop {r0-r12, lr}
|
||||
beq _dataAbortNormalHandler
|
||||
|
||||
msr spsr_f, #(1 << 30)
|
||||
mov r12, #0
|
||||
subs pc, lr, #4
|
||||
|
||||
GEN_USUAL_HANDLER _dataAbortNormal, 3, 16
|
||||
|
||||
.bss
|
||||
.balign 4
|
||||
_regs: .skip (4 * 23)
|
||||
_fatalExceptionOccured: .word 0
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "fatalExceptionHandlers.h"
|
||||
#include "utils.h"
|
||||
#include "kernel.h"
|
||||
#include "memory.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define REG_DUMP_SIZE 4 * 23
|
||||
#define CODE_DUMP_SIZE 48
|
||||
|
||||
bool isExceptionFatal(u32 spsr)
|
||||
{
|
||||
if((spsr & 0x1f) != 0x10) return true;
|
||||
|
||||
KThread *thread = currentCoreContext->objectContext.currentThread;
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
|
||||
if(thread != NULL && thread->threadLocalStorage != NULL && *((vu32 *)thread->threadLocalStorage + 0x10) != 0)
|
||||
return false;
|
||||
|
||||
if(currentProcess != NULL)
|
||||
{
|
||||
if(debugOfProcess(currentProcess) != NULL)
|
||||
return false;
|
||||
|
||||
thread = KPROCESS_GET_RVALUE(currentProcess, mainThread);
|
||||
if(thread != NULL && thread->threadLocalStorage != NULL && *((vu32 *)thread->threadLocalStorage + 0x10) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern u32 safecpy_sz;
|
||||
bool isDataAbortExceptionRangeControlled(u32 spsr, u32 addr)
|
||||
{
|
||||
return ((spsr & 0x1F) != 0x10) && (
|
||||
((u32)kernelUsrCopyFuncsStart <= addr && addr < (u32)kernelUsrCopyFuncsEnd) ||
|
||||
((u32)safecpy <= addr && addr < (u32)safecpy + safecpy_sz)
|
||||
);
|
||||
}
|
||||
void fatalExceptionHandlersMain(u32 *registerDump, u32 type, u32 cpuId)
|
||||
{
|
||||
ExceptionDumpHeader dumpHeader;
|
||||
|
||||
u8 codeDump[CODE_DUMP_SIZE];
|
||||
u8 *finalBuffer = (u8 *)PA_PTR(0x25000000);
|
||||
u8 *final = finalBuffer;
|
||||
|
||||
dumpHeader.magic[0] = 0xDEADC0DE;
|
||||
dumpHeader.magic[1] = 0xDEADCAFE;
|
||||
dumpHeader.versionMajor = 1;
|
||||
dumpHeader.versionMinor = 2;
|
||||
|
||||
dumpHeader.processor = 11;
|
||||
dumpHeader.core = cpuId & 0xF;
|
||||
dumpHeader.type = type;
|
||||
|
||||
dumpHeader.registerDumpSize = REG_DUMP_SIZE;
|
||||
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
||||
|
||||
u32 cpsr = registerDump[16];
|
||||
u32 pc = registerDump[15] - (type < 3 ? (((cpsr & 0x20) != 0 && type == 1) ? 2 : 4) : 8);
|
||||
|
||||
registerDump[15] = pc;
|
||||
|
||||
//Dump code
|
||||
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //Doesn't work well on 32-bit Thumb instructions, but it isn't much of a problem
|
||||
dumpHeader.codeDumpSize = ((u32)instr & (((cpsr & 0x20) != 0) ? 1 : 3)) != 0 ? 0 : safecpy(codeDump, instr, dumpHeader.codeDumpSize);
|
||||
|
||||
//Copy register dump and code dump
|
||||
final = (u8 *)(finalBuffer + sizeof(ExceptionDumpHeader));
|
||||
memcpy(final, registerDump, dumpHeader.registerDumpSize);
|
||||
final += dumpHeader.registerDumpSize;
|
||||
memcpy(final, codeDump, dumpHeader.codeDumpSize);
|
||||
final += dumpHeader.codeDumpSize;
|
||||
|
||||
//Dump stack in place
|
||||
dumpHeader.stackDumpSize = safecpy(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF));
|
||||
final += dumpHeader.stackDumpSize;
|
||||
|
||||
if(currentCoreContext->objectContext.currentProcess)
|
||||
{
|
||||
vu64 *additionalData = (vu64 *)final;
|
||||
KCodeSet *currentCodeSet = codeSetOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
if(currentCodeSet != NULL)
|
||||
{
|
||||
dumpHeader.additionalDataSize = 16;
|
||||
memcpy((void *)additionalData, currentCodeSet->processName, 8);
|
||||
additionalData[1] = currentCodeSet->titleId;
|
||||
}
|
||||
else dumpHeader.additionalDataSize = 0;
|
||||
}
|
||||
else dumpHeader.additionalDataSize = 0;
|
||||
|
||||
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
|
||||
|
||||
//Copy header (actually optimized by the compiler)
|
||||
*(ExceptionDumpHeader *)finalBuffer = dumpHeader;
|
||||
}
|
||||
104
sysmodules/rosalina/kernel_extension/source/globals.c
Normal file
104
sysmodules/rosalina/kernel_extension/source/globals.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
KRecursiveLock *criticalSectionLock;
|
||||
KObjectList *threadList;
|
||||
KObjectMutex *synchronizationMutex;
|
||||
|
||||
void (*KRecursiveLock__Lock)(KRecursiveLock *this);
|
||||
void (*KRecursiveLock__Unlock)(KRecursiveLock *this);
|
||||
|
||||
void (*KAutoObject__AddReference)(KAutoObject *this);
|
||||
KProcess * (*KProcessHandleTable__ToKProcess)(KProcessHandleTable *this, Handle processHandle);
|
||||
KThread * (*KProcessHandleTable__ToKThread)(KProcessHandleTable *this, Handle threadHandle);
|
||||
KAutoObject * (*KProcessHandleTable__ToKAutoObject)(KProcessHandleTable *this, Handle handle);
|
||||
void (*KSynchronizationObject__Signal)(KSynchronizationObject *this, bool isPulse);
|
||||
Result (*WaitSynchronization1)(void *this_unused, KThread *thread, KSynchronizationObject *syncObject, s64 timeout);
|
||||
Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Handle *out, KAutoObject *obj, u8 token);
|
||||
Result (*KProcessHwInfo__MapProcessMemory)(KProcessHwInfo *this, KProcessHwInfo *other, void *dst, void *src, u32 nbPages);
|
||||
Result (*KProcessHwInfo__UnmapProcessMemory)(KProcessHwInfo *this, void *addr, u32 nbPages);
|
||||
Result (*KEvent__Clear)(KEvent *this);
|
||||
void (*KObjectMutex__WaitAndAcquire)(KObjectMutex *this);
|
||||
void (*KObjectMutex__ErrorOccured)(void);
|
||||
|
||||
void (*KScheduler__AdjustThread)(KScheduler *this, KThread *thread, u32 oldSchedulingMask);
|
||||
void (*KScheduler__AttemptSwitchingThreadContext)(KScheduler *this);
|
||||
|
||||
Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||
void (*SleepThread)(s64 ns);
|
||||
Result (*CloseHandle)(Handle handle);
|
||||
Result (*GetSystemInfo)(s64 *out, s32 type, s32 param);
|
||||
Result (*GetProcessInfo)(s64 *out, Handle processHandle, u32 type);
|
||||
Result (*GetThreadInfo)(s64 *out, Handle threadHandle, u32 type);
|
||||
Result (*ConnectToPort)(Handle *out, const char *name);
|
||||
Result (*SendSyncRequest)(Handle handle);
|
||||
Result (*OpenProcess)(Handle *out, u32 processId);
|
||||
Result (*GetProcessId)(u32 *out, Handle process);
|
||||
Result (*DebugActiveProcess)(Handle *out, u32 processId);
|
||||
Result (*KernelSetState)(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||
|
||||
void (*flushDataCacheRange)(void *addr, u32 len);
|
||||
void (*invalidateInstructionCacheRange)(void *addr, u32 len);
|
||||
|
||||
bool (*usrToKernelMemcpy8)(void *dst, const void *src, u32 len);
|
||||
bool (*usrToKernelMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
s32 (*usrToKernelStrncpy)(char *dst, const char *src, u32 len);
|
||||
bool (*kernelToUsrMemcpy8)(void *dst, const void *src, u32 len);
|
||||
bool (*kernelToUsrMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
s32 (*kernelToUsrStrncpy)(char *dst, const char *src, u32 len);
|
||||
|
||||
Result (*CustomBackdoor)(void *function, ...);
|
||||
|
||||
void (*svcFallbackHandler)(u8 svcId);
|
||||
void (*kernelpanic)(void);
|
||||
void (*PostprocessSvc)(void);
|
||||
|
||||
Result (*SignalDebugEvent)(DebugEventType type, u32 info, ...);
|
||||
|
||||
bool isN3DS;
|
||||
u32 *exceptionStackTop;
|
||||
|
||||
u32 TTBCR;
|
||||
u32 L1MMUTableAddrs[4];
|
||||
|
||||
u32 kernelVersion;
|
||||
void *kernelUsrCopyFuncsStart, *kernelUsrCopyFuncsEnd;
|
||||
|
||||
bool *isDevUnit;
|
||||
|
||||
InterruptManager *interruptManager;
|
||||
KBaseInterruptEvent *customInterruptEvent;
|
||||
|
||||
void (*initFPU)(void);
|
||||
void (*mcuReboot)(void);
|
||||
void (*coreBarrier)(void);
|
||||
|
||||
CfwInfo cfwInfo;
|
||||
|
||||
u32 rosalinaState;
|
||||
bool hasStartedRosalinaNetworkFuncsOnce;
|
||||
321
sysmodules/rosalina/kernel_extension/source/ipc.c
Normal file
321
sysmodules/rosalina/kernel_extension/source/ipc.c
Normal file
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "ipc.h"
|
||||
#include "memory.h"
|
||||
|
||||
static SessionInfo sessionInfos[MAX_SESSION] = { {NULL} };
|
||||
static u32 nbActiveSessions = 0;
|
||||
static KRecursiveLock sessionInfosLock = { NULL };
|
||||
|
||||
KRecursiveLock processLangemuLock;
|
||||
LangemuAttributes processLangemuAttributes[0x40];
|
||||
|
||||
static void *customSessionVtable[0x10] = { NULL }; // should be enough
|
||||
|
||||
static u32 SessionInfo_FindClosestSlot(KSession *session)
|
||||
{
|
||||
if(nbActiveSessions == 0 || session <= sessionInfos[0].session)
|
||||
return 0;
|
||||
else if(session > sessionInfos[nbActiveSessions - 1].session)
|
||||
return nbActiveSessions;
|
||||
|
||||
u32 a = 0, b = nbActiveSessions - 1, m;
|
||||
|
||||
do
|
||||
{
|
||||
m = (a + b) / 2;
|
||||
if(sessionInfos[m].session < session)
|
||||
a = m;
|
||||
else if(sessionInfos[m].session > session)
|
||||
b = m;
|
||||
else
|
||||
return m;
|
||||
}
|
||||
while(b - a > 1);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
SessionInfo *SessionInfo_Lookup(KSession *session)
|
||||
{
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&sessionInfosLock);
|
||||
|
||||
SessionInfo *ret;
|
||||
u32 id = SessionInfo_FindClosestSlot(session);
|
||||
if(id == nbActiveSessions)
|
||||
ret = NULL;
|
||||
else
|
||||
ret = (void **)(sessionInfos[id].session->autoObject.vtable) == customSessionVtable ? &sessionInfos[id] : NULL;
|
||||
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SessionInfo *SessionInfo_FindFirst(const char *name)
|
||||
{
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&sessionInfosLock);
|
||||
|
||||
SessionInfo *ret;
|
||||
u32 id;
|
||||
for(id = 0; id < nbActiveSessions && strncmp(sessionInfos[id].name, name, 12) != 0; id++);
|
||||
if(id == nbActiveSessions)
|
||||
ret = NULL;
|
||||
else
|
||||
ret = (void **)(sessionInfos[id].session->autoObject.vtable) == customSessionVtable ? &sessionInfos[id] : NULL;
|
||||
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SessionInfo_Add(KSession *session, const char *name)
|
||||
{
|
||||
KAutoObject__AddReference(&session->autoObject);
|
||||
SessionInfo_ChangeVtable(session);
|
||||
session->autoObject.vtable->DecrementReferenceCount(&session->autoObject);
|
||||
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&sessionInfosLock);
|
||||
|
||||
if(nbActiveSessions == MAX_SESSION)
|
||||
{
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return;
|
||||
}
|
||||
|
||||
u32 id = SessionInfo_FindClosestSlot(session);
|
||||
|
||||
if(id != nbActiveSessions && sessionInfos[id].session == session)
|
||||
{
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return;
|
||||
}
|
||||
|
||||
for(u32 i = nbActiveSessions; i > id && i != 0; i--)
|
||||
sessionInfos[i] = sessionInfos[i - 1];
|
||||
|
||||
nbActiveSessions++;
|
||||
|
||||
sessionInfos[id].session = session;
|
||||
strncpy(sessionInfos[id].name, name, 12);
|
||||
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
}
|
||||
|
||||
void SessionInfo_Remove(KSession *session)
|
||||
{
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&sessionInfosLock);
|
||||
|
||||
if(nbActiveSessions == MAX_SESSION)
|
||||
{
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return;
|
||||
}
|
||||
|
||||
u32 id = SessionInfo_FindClosestSlot(session);
|
||||
|
||||
if(id == nbActiveSessions)
|
||||
{
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return;
|
||||
}
|
||||
|
||||
for(u32 i = id; i < nbActiveSessions - 1; i++)
|
||||
sessionInfos[i] = sessionInfos[i + 1];
|
||||
|
||||
memset(&sessionInfos[--nbActiveSessions], 0, sizeof(SessionInfo));
|
||||
|
||||
KRecursiveLock__Unlock(&sessionInfosLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
}
|
||||
|
||||
static void (*KSession__dtor_orig)(KAutoObject *this);
|
||||
static void KSession__dtor_hook(KAutoObject *this)
|
||||
{
|
||||
KSession__dtor_orig(this);
|
||||
SessionInfo_Remove((KSession *)this);
|
||||
}
|
||||
|
||||
void SessionInfo_ChangeVtable(KSession *session)
|
||||
{
|
||||
if(customSessionVtable[2] == NULL)
|
||||
{
|
||||
memcpy(customSessionVtable, session->autoObject.vtable, 0x40);
|
||||
KSession__dtor_orig = session->autoObject.vtable->dtor;
|
||||
customSessionVtable[2] = (void *)KSession__dtor_hook;
|
||||
}
|
||||
session->autoObject.vtable = (Vtable__KAutoObject *)customSessionVtable;
|
||||
}
|
||||
|
||||
bool doLangEmu(Result *res, Handle handle, u32 *cmdbuf)
|
||||
{
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&processLangemuLock);
|
||||
|
||||
u64 titleId = codeSetOfProcess(currentCoreContext->objectContext.currentProcess)->titleId;
|
||||
LangemuAttributes *attribs = NULL;
|
||||
bool skip = true;
|
||||
|
||||
*res = 0;
|
||||
for(u32 i = 0; i < 0x40; i++)
|
||||
{
|
||||
if(processLangemuAttributes[i].titleId == titleId)
|
||||
attribs = &processLangemuAttributes[i];
|
||||
}
|
||||
|
||||
if(attribs == NULL)
|
||||
{
|
||||
KRecursiveLock__Unlock(&processLangemuLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return false;
|
||||
}
|
||||
|
||||
if((cmdbuf[0] == 0x20000 || cmdbuf[0] == 0x4060000 || cmdbuf[0] == 0x8160000) && (attribs->mask & 1)) // SecureInfoGetRegion
|
||||
{
|
||||
cmdbuf[0] = (cmdbuf[0] & 0xFFFF0000) | 0x80;
|
||||
cmdbuf[1] = 0;
|
||||
cmdbuf[2] = attribs->region;
|
||||
}
|
||||
else if(cmdbuf[1] == 1 && cmdbuf[2] == 0xA0002 && cmdbuf[3] == 0x1C && (attribs->mask & 2))
|
||||
{
|
||||
cmdbuf[0] = (cmdbuf[0] & 0xFFFF0000) | 0x40;
|
||||
cmdbuf[1] = 0;
|
||||
*(u8 *)cmdbuf[4] = attribs->language;
|
||||
}
|
||||
else if(cmdbuf[1] == 4 && cmdbuf[2] == 0xB0000 && cmdbuf[3] == 0x4C && (attribs->mask & 0xC))
|
||||
{
|
||||
u8 *ptr = (u8 *)cmdbuf[4];
|
||||
*res = SendSyncRequest(handle);
|
||||
flushEntireDataCache(); // looks like it's needed. WTF?!
|
||||
if(*res == 0)
|
||||
{
|
||||
if(attribs->mask & 4)
|
||||
ptr[3] = attribs->country;
|
||||
if(attribs->mask & 8)
|
||||
ptr[2] = attribs->state;
|
||||
}
|
||||
}
|
||||
else
|
||||
skip = false;
|
||||
|
||||
KRecursiveLock__Unlock(&processLangemuLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return skip;
|
||||
}
|
||||
|
||||
Result doPublishToProcessHook(Handle handle, u32 *cmdbuf)
|
||||
{
|
||||
Result res = 0;
|
||||
u32 pid;
|
||||
bool terminateRosalina = cmdbuf[1] == 0x100 && cmdbuf[2] == 0; // cmdbuf[2] to check for well-formed requests
|
||||
u32 savedCmdbuf[4];
|
||||
memcpy(savedCmdbuf, cmdbuf, 16);
|
||||
|
||||
if(!terminateRosalina || GetProcessId(&pid, cmdbuf[3]) != 0)
|
||||
terminateRosalina = false;
|
||||
else
|
||||
{
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KProcess *process = KProcessHandleTable__ToKProcess(handleTable, cmdbuf[3]);
|
||||
if((strcmp(codeSetOfProcess(process)->processName, "socket") == 0 && (rosalinaState & 2)) ||
|
||||
strcmp(codeSetOfProcess(process)->processName, "pxi") == 0)
|
||||
terminateRosalina = true;
|
||||
else
|
||||
terminateRosalina = false;
|
||||
((KAutoObject *)process)->vtable->DecrementReferenceCount((KAutoObject *)process);
|
||||
}
|
||||
|
||||
if(terminateRosalina)
|
||||
{
|
||||
Handle rosalinaProcessHandle;
|
||||
res = OpenProcess(&rosalinaProcessHandle, 5);
|
||||
if(res == 0)
|
||||
{
|
||||
cmdbuf[0] = cmdbuf[0];
|
||||
cmdbuf[1] = 0x100;
|
||||
cmdbuf[2] = 0;
|
||||
cmdbuf[3] = rosalinaProcessHandle;
|
||||
|
||||
res = SendSyncRequest(handle);
|
||||
CloseHandle(rosalinaProcessHandle);
|
||||
memcpy(cmdbuf, savedCmdbuf, 16);
|
||||
}
|
||||
}
|
||||
|
||||
return SendSyncRequest(handle);
|
||||
}
|
||||
|
||||
bool doErrfThrowHook(u32 *cmdbuf)
|
||||
{
|
||||
// If fatalErrorInfo->type is "card removed" or "logged", returning from ERRF:Throw is a no-op
|
||||
// for the SDK function
|
||||
|
||||
// r6 (arm) or r4 (thumb) is copied into cmdbuf[1..31]
|
||||
u32 *r0_to_r7_r12_usr = (u32 *)((u8 *)currentCoreContext->objectContext.currentThread->endOfThreadContext - 0x110);
|
||||
u32 spsr = *(u32 *)((u8 *)currentCoreContext->objectContext.currentThread->endOfThreadContext - 0xCC);
|
||||
u8 *srcerrbuf = (u8 *)r0_to_r7_r12_usr[(spsr & 0x20) ? 4 : 6];
|
||||
const char *pname = codeSetOfProcess(currentCoreContext->objectContext.currentProcess)->processName;
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *name;
|
||||
Result errCode;
|
||||
} errorCodesToIgnore[] =
|
||||
{
|
||||
/*
|
||||
If you're getting this error, you have broken your head-tracking hardware,
|
||||
and should uncomment the following line:
|
||||
*/
|
||||
//{ "qtm", (Result)0xF96183FE },
|
||||
|
||||
{ "", 0 }, // impossible case to ensure the array has at least 1 element
|
||||
};
|
||||
|
||||
for(u32 i = 0; i < sizeof(errorCodesToIgnore) / sizeof(errorCodesToIgnore[0]); i++)
|
||||
{
|
||||
if(strcmp(pname, errorCodesToIgnore[i].name) == 0 && (Result)cmdbuf[2] == errorCodesToIgnore[i].errCode)
|
||||
{
|
||||
srcerrbuf[0] = 5;
|
||||
cmdbuf[0] = 0x10040;
|
||||
cmdbuf[1] = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
310
sysmodules/rosalina/kernel_extension/source/main.c
Normal file
310
sysmodules/rosalina/kernel_extension/source/main.c
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include "globals.h"
|
||||
#include "synchronization.h"
|
||||
#include "fatalExceptionHandlers.h"
|
||||
#include "svc.h"
|
||||
#include "svc/ConnectToPort.h"
|
||||
#include "svcHandler.h"
|
||||
#include "memory.h"
|
||||
|
||||
static const u32 *const exceptionsPage = (const u32 *)0xFFFF0000;
|
||||
void *originalHandlers[8] = {NULL};
|
||||
|
||||
enum VECTORS { RESET = 0, UNDEFINED_INSTRUCTION, SVC, PREFETCH_ABORT, DATA_ABORT, RESERVED, IRQ, FIQ };
|
||||
|
||||
static void setupSGI0Handler(void)
|
||||
{
|
||||
for(u32 i = 0; i < getNumberOfCores(); i++)
|
||||
interruptManager->N3DS.privateInterrupts[i][0].interruptEvent = customInterruptEvent;
|
||||
}
|
||||
|
||||
static inline void **getHandlerDestination(enum VECTORS vector)
|
||||
{
|
||||
u32 *branch_dst = (u32 *)decodeARMBranch((u32 *)exceptionsPage + (u32)vector);
|
||||
return (void **)(branch_dst + 2);
|
||||
}
|
||||
|
||||
static inline void swapHandlerInVeneer(enum VECTORS vector, void *handler)
|
||||
{
|
||||
void **dst = getHandlerDestination(vector);
|
||||
originalHandlers[(u32)vector] = *dst;
|
||||
if(handler != NULL)
|
||||
*(void**)PA_FROM_VA_PTR(dst) = handler;
|
||||
}
|
||||
|
||||
static u32 *trampo_;
|
||||
static bool **enableUserExceptionHandlersForCPUExcLoc;
|
||||
static bool enableUserExceptionHandlersForCPUExc = true;
|
||||
|
||||
static void setupSvcHandler(void)
|
||||
{
|
||||
swapHandlerInVeneer(SVC, svcHandler);
|
||||
|
||||
void **arm11SvcTable = (void**)originalHandlers[(u32)SVC];
|
||||
while(*arm11SvcTable != NULL) arm11SvcTable++; //Look for SVC0 (NULL)
|
||||
memcpy(officialSVCs, arm11SvcTable, 4 * 0x7E);
|
||||
|
||||
u32 *off;
|
||||
for(off = (u32 *)officialSVCs[0x2D]; *off != 0x65736162; off++);
|
||||
*(void **)PA_FROM_VA_PTR(arm11SvcTable + 0x2D) = officialSVCs[0x2D] = (void *)off[1];
|
||||
trampo_ = (u32 *)PA_FROM_VA_PTR(off + 3);
|
||||
|
||||
CustomBackdoor = (Result (*)(void *, ...))((u32 *)officialSVCs[0x2F] + 2);
|
||||
*(void **)PA_FROM_VA_PTR(arm11SvcTable + 0x2F) = officialSVCs[0x2F] = (void *)*((u32 *)officialSVCs[0x2F] + 1);
|
||||
|
||||
off = (u32 *)originalHandlers[(u32) SVC];
|
||||
while(*off++ != 0xE1A00009);
|
||||
svcFallbackHandler = (void (*)(u8))decodeARMBranch(off);
|
||||
for(; *off != 0xE92D000F; off++);
|
||||
PostprocessSvc = (void (*)(void))decodeARMBranch(off + 1);
|
||||
}
|
||||
|
||||
static void setupExceptionHandlers(void)
|
||||
{
|
||||
swapHandlerInVeneer(FIQ, FIQHandler);
|
||||
swapHandlerInVeneer(UNDEFINED_INSTRUCTION, undefinedInstructionHandler);
|
||||
swapHandlerInVeneer(PREFETCH_ABORT, prefetchAbortHandler);
|
||||
swapHandlerInVeneer(DATA_ABORT, dataAbortHandler);
|
||||
|
||||
setupSvcHandler();
|
||||
}
|
||||
|
||||
static void findUsefulSymbols(void)
|
||||
{
|
||||
u32 *off;
|
||||
|
||||
KProcessHandleTable__ToKProcess = (KProcess * (*)(KProcessHandleTable *, Handle))decodeARMBranch(5 + (u32 *)officialSVCs[0x76]);
|
||||
|
||||
for(off = (u32 *)KProcessHandleTable__ToKProcess; *off != 0xE28DD014; off++);
|
||||
KAutoObject__AddReference = (void (*)(KAutoObject *))decodeARMBranch(off - 1);
|
||||
|
||||
for(; *off != 0xE8BD80F0; off++);
|
||||
KProcessHandleTable__ToKAutoObject = (KAutoObject * (*)(KProcessHandleTable *, Handle))decodeARMBranch(off + 2);
|
||||
|
||||
for(off = (u32 *)decodeARMBranch(3 + (u32 *)officialSVCs[9]); /* KThread::Terminate */ *off != 0xE5D42034; off++);
|
||||
off -= 2;
|
||||
criticalSectionLock = (KRecursiveLock *)off[2 + (off[0] & 0xFF) / 4];
|
||||
KRecursiveLock__Lock = (void (*)(KRecursiveLock *))decodeARMBranch(off + 1);
|
||||
off += 4;
|
||||
|
||||
for(; (*off >> 16) != 0xE59F; off++);
|
||||
KRecursiveLock__Unlock = (void (*)(KRecursiveLock *))decodeARMBranch(off + 1);
|
||||
|
||||
for(; *off != 0xE5C4007D; off++);
|
||||
KSynchronizationObject__Signal = (void (*)(KSynchronizationObject *, bool))decodeARMBranch(off + 3);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x19]; *off != 0xE1A04005; off++);
|
||||
KEvent__Clear = (Result (*)(KEvent *))decodeARMBranch(off + 1);
|
||||
for(off = (u32 *)KEvent__Clear; *off != 0xE8BD8070; off++)
|
||||
synchronizationMutex = *(KObjectMutex **)(off + 1);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x24]; *off != 0xE59F004C; off++);
|
||||
WaitSynchronization1 = (Result (*)(void *, KThread *, KSynchronizationObject *, s64))decodeARMBranch(off + 6);
|
||||
|
||||
for(off = (u32 *)decodeARMBranch(3 + (u32 *)officialSVCs[0x33]) /* OpenProcess */ ; *off != 0xE20030FF; off++);
|
||||
KProcessHandleTable__CreateHandle = (Result (*)(KProcessHandleTable *, Handle *, KAutoObject *, u8))decodeARMBranch(off + 2);
|
||||
|
||||
for(off = (u32 *)decodeARMBranch(3 + (u32 *)officialSVCs[0x34]) /* OpenThread */; *off != 0xD9001BF7; off++);
|
||||
threadList = *(KObjectList **)(off + 1);
|
||||
|
||||
KProcessHandleTable__ToKThread = (KThread * (*)(KProcessHandleTable *, Handle))decodeARMBranch((u32 *)decodeARMBranch((u32 *)officialSVCs[0x37] + 3) /* GetThreadId */ + 5);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x54]; *off != 0xE8BD8008; off++);
|
||||
flushDataCacheRange = (void (*)(void *, u32))(*(u32 **)(off[1]) + 3);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x71]; *off != 0xE2101102; off++);
|
||||
KProcessHwInfo__MapProcessMemory = (Result (*)(KProcessHwInfo *, KProcessHwInfo *, void *, void *, u32))decodeARMBranch(off - 1);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x72]; *off != 0xE2041102; off++);
|
||||
KProcessHwInfo__UnmapProcessMemory = (Result (*)(KProcessHwInfo *, void *, u32))decodeARMBranch(off - 1);
|
||||
|
||||
for(off = (u32 *)officialSVCs[0x7C]; *off != 0x03530000; off++);
|
||||
KObjectMutex__WaitAndAcquire = (void (*)(KObjectMutex *))decodeARMBranch(++off);
|
||||
for(; *off != 0xE320F000; off++);
|
||||
KObjectMutex__ErrorOccured = (void (*)(void))decodeARMBranch(off + 1);
|
||||
|
||||
for(off = (u32 *)originalHandlers[(u32) DATA_ABORT]; *off != (u32)exceptionStackTop; off++);
|
||||
kernelUsrCopyFuncsStart = (void *)off[1];
|
||||
kernelUsrCopyFuncsEnd = (void *)off[2];
|
||||
|
||||
u32 n_cmp_0;
|
||||
for(off = (u32 *)kernelUsrCopyFuncsStart, n_cmp_0 = 1; n_cmp_0 <= 6; off++)
|
||||
{
|
||||
if(*off == 0xE3520000)
|
||||
{
|
||||
// We're missing some funcs
|
||||
switch(n_cmp_0)
|
||||
{
|
||||
case 1:
|
||||
usrToKernelMemcpy8 = (bool (*)(void *, const void *, u32))off;
|
||||
break;
|
||||
case 2:
|
||||
usrToKernelMemcpy32 = (bool (*)(u32 *, const u32 *, u32))off;
|
||||
break;
|
||||
case 3:
|
||||
usrToKernelStrncpy = (s32 (*)(char *, const char *, u32))off;
|
||||
break;
|
||||
case 4:
|
||||
kernelToUsrMemcpy8 = (bool (*)(void *, const void *, u32))off;
|
||||
break;
|
||||
case 5:
|
||||
kernelToUsrMemcpy32 = (bool (*)(u32 *, const u32 *, u32))off;
|
||||
break;
|
||||
case 6:
|
||||
kernelToUsrStrncpy = (s32 (*)(char *, const char *, u32))off;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
n_cmp_0++;
|
||||
}
|
||||
}
|
||||
|
||||
// The official prototype of ControlMemory doesn't have that extra param'
|
||||
ControlMemory = (Result (*)(u32 *, u32, u32, u32, MemOp, MemPerm, bool))
|
||||
decodeARMBranch((u32 *)officialSVCs[0x01] + 5);
|
||||
SleepThread = (void (*)(s64))officialSVCs[0x0A];
|
||||
CloseHandle = (Result (*)(Handle))officialSVCs[0x23];
|
||||
GetSystemInfo = (Result (*)(s64 *, s32, s32))decodeARMBranch((u32 *)officialSVCs[0x2A] + 3);
|
||||
GetProcessInfo = (Result (*)(s64 *, Handle, u32))decodeARMBranch((u32 *)officialSVCs[0x2B] + 3);
|
||||
GetThreadInfo = (Result (*)(s64 *, Handle, u32))decodeARMBranch((u32 *)officialSVCs[0x2C] + 3);
|
||||
ConnectToPort = (Result (*)(Handle *, const char*))decodeARMBranch((u32 *)officialSVCs[0x2D] + 3);
|
||||
SendSyncRequest = (Result (*)(Handle))officialSVCs[0x32];
|
||||
OpenProcess = (Result (*)(Handle *, u32))decodeARMBranch((u32 *)officialSVCs[0x33] + 3);
|
||||
GetProcessId = (Result (*)(u32 *, Handle))decodeARMBranch((u32 *)officialSVCs[0x35] + 3);
|
||||
DebugActiveProcess = (Result (*)(Handle *, u32))decodeARMBranch((u32 *)officialSVCs[0x60] + 3);
|
||||
KernelSetState = (Result (*)(u32, u32, u32, u32))((u32 *)officialSVCs[0x7C] + 1);
|
||||
|
||||
for(off = (u32 *)svcFallbackHandler; *off != 0xE8BD4010; off++);
|
||||
kernelpanic = (void (*)(void))off;
|
||||
|
||||
for(off = (u32 *)0xFFFF0000; off[0] != 0xE3A01002 || off[1] != 0xE3A00004; off++);
|
||||
SignalDebugEvent = (Result (*)(DebugEventType type, u32 info, ...))decodeARMBranch(off + 2);
|
||||
|
||||
for(; *off != 0x96007F9; off++);
|
||||
isDevUnit = *(bool **)(off - 1);
|
||||
enableUserExceptionHandlersForCPUExcLoc = (bool **)(off + 1);
|
||||
|
||||
///////////////////////////////////////////
|
||||
|
||||
// Shitty/lazy heuristic but it works on even 4.5, so...
|
||||
u32 textStart = ((u32)originalHandlers[(u32) SVC]) & ~0xFFFF;
|
||||
u32 rodataStart = (u32)(interruptManager->N3DS.privateInterrupts[0][6].interruptEvent->vtable) & ~0xFFF;
|
||||
|
||||
u32 textSize = rodataStart - textStart;
|
||||
for(off = (u32 *)textStart; off < (u32 *)(textStart + textSize) - 3; off++)
|
||||
{
|
||||
if(off[0] == 0xE5D13034 && off[1] == 0xE1530002)
|
||||
KScheduler__AdjustThread = (void (*)(KScheduler *, KThread *, u32))off;
|
||||
else if(off[0] == (u32)interruptManager && off[1] == (u32)¤tCoreContext->objectContext)
|
||||
KScheduler__AttemptSwitchingThreadContext = (void (*)(KScheduler *))(off - 2);
|
||||
else if(off[0] == 0xE3510B1A && off[1] == 0xE3A06000)
|
||||
{
|
||||
u32 *off2;
|
||||
for(off2 = off; *off2 != 0xE92D40F8; off2--);
|
||||
invalidateInstructionCacheRange = (void (*)(void *, u32))off2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Parameters
|
||||
{
|
||||
void (*SGI0HandlerCallback)(struct Parameters *, u32 *);
|
||||
InterruptManager *interruptManager;
|
||||
u32 *L2MMUTable; // bit31 mapping
|
||||
|
||||
void (*initFPU)(void);
|
||||
void (*mcuReboot)(void);
|
||||
void (*coreBarrier)(void);
|
||||
|
||||
u32 TTBCR;
|
||||
u32 L1MMUTableAddrs[4];
|
||||
|
||||
u32 kernelVersion;
|
||||
|
||||
CfwInfo cfwInfo;
|
||||
};
|
||||
|
||||
static void enableDebugFeatures(void)
|
||||
{
|
||||
*isDevUnit = true; // for debug SVCs and user exc. handlers, etc.
|
||||
*(bool **)PA_FROM_VA_PTR(enableUserExceptionHandlersForCPUExcLoc) = &enableUserExceptionHandlersForCPUExc;
|
||||
|
||||
u32 *off;
|
||||
for(off = (u32 *)officialSVCs[0x7C]; off[0] != 0xE5D00001 || off[1] != 0xE3500000; off++);
|
||||
*(u32 *)PA_FROM_VA_PTR(off + 2) = 0xE1A00000; // in case 6: beq -> nop
|
||||
|
||||
for(off = (u32 *)DebugActiveProcess; *off != 0xE3110001; off++);
|
||||
*(u32 *)PA_FROM_VA_PTR(off) = 0xE3B01001; // tst r1, #1 -> movs r1, #1
|
||||
}
|
||||
|
||||
static void doOtherPatches(void)
|
||||
{
|
||||
u32 *kpanic = (u32 *)kernelpanic;
|
||||
*(u32 *)PA_FROM_VA_PTR(kpanic) = 0xE12FFF7E; // bkpt 0xFFFE
|
||||
|
||||
u32 *off;
|
||||
for(off = (u32 *)ControlMemory; (off[0] & 0xFFF0FFFF) != 0xE3500001 || (off[1] & 0xFFFF0FFF) != 0x13A00000; off++);
|
||||
off -= 2;
|
||||
|
||||
/*
|
||||
Here we replace currentProcess->processID == 1 by additionnalParameter == 1.
|
||||
This patch should be generic enough to work even on firmware version 5.0.
|
||||
|
||||
It effectively changes the prototype of the ControlMemory function which
|
||||
only caller is the svc 0x01 handler on OFW.
|
||||
*/
|
||||
*(u32 *)PA_FROM_VA_PTR(off) = 0xE59D0000 | (*off & 0x0000F000) | (8 + computeARMFrameSize((u32 *)ControlMemory)); // ldr r0, [sp, #(frameSize + 8)]
|
||||
|
||||
}
|
||||
|
||||
void main(volatile struct Parameters *p)
|
||||
{
|
||||
isN3DS = getNumberOfCores() == 4;
|
||||
interruptManager = p->interruptManager;
|
||||
|
||||
initFPU = p->initFPU;
|
||||
mcuReboot = p->mcuReboot;
|
||||
coreBarrier = p->coreBarrier;
|
||||
|
||||
TTBCR = p->TTBCR;
|
||||
memcpy(L1MMUTableAddrs, (const void *)p->L1MMUTableAddrs, 16);
|
||||
exceptionStackTop = (u32 *)0xFFFF2000 + (1 << (32 - TTBCR - 20));
|
||||
kernelVersion = p->kernelVersion;
|
||||
cfwInfo = p->cfwInfo;
|
||||
|
||||
setupSGI0Handler();
|
||||
setupExceptionHandlers();
|
||||
findUsefulSymbols();
|
||||
enableDebugFeatures();
|
||||
doOtherPatches();
|
||||
|
||||
rosalinaState = 0;
|
||||
hasStartedRosalinaNetworkFuncsOnce = false;
|
||||
*trampo_ = (u32)ConnectToPortHookWrapper;
|
||||
}
|
||||
176
sysmodules/rosalina/kernel_extension/source/memory.c
Normal file
176
sysmodules/rosalina/kernel_extension/source/memory.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
|
||||
void *memcpy(void *dest, const void *src, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
const u8 *srcc = (const u8 *)src;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
destc[i] = srcc[i];
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *buf1, const void *buf2, u32 size)
|
||||
{
|
||||
const u8 *buf1c = (const u8 *)buf1;
|
||||
const u8 *buf2c = (const u8 *)buf2;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
{
|
||||
int cmp = buf1c[i] - buf2c[i];
|
||||
if(cmp)
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memset(void *dest, u32 value, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
|
||||
for(u32 i = 0; i < size; i++) destc[i] = (u8)value;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset32(void *dest, u32 value, u32 size)
|
||||
{
|
||||
u32 *dest32 = (u32 *)dest;
|
||||
|
||||
for(u32 i = 0; i < size/4; i++) dest32[i] = value;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
//Boyer-Moore Horspool algorithm, adapted from http://www-igm.univ-mlv.fr/~lecroq/string/node18.html#SECTION00180
|
||||
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
|
||||
{
|
||||
const u8 *patternc = (const u8 *)pattern;
|
||||
u32 table[256];
|
||||
|
||||
//Preprocessing
|
||||
for(u32 i = 0; i < 256; i++)
|
||||
table[i] = patternSize;
|
||||
for(u32 i = 0; i < patternSize - 1; i++)
|
||||
table[patternc[i]] = patternSize - i - 1;
|
||||
|
||||
//Searching
|
||||
u32 j = 0;
|
||||
while(j <= size - patternSize)
|
||||
{
|
||||
u8 c = startPos[j + patternSize - 1];
|
||||
if(patternc[patternSize - 1] == c && memcmp(pattern, startPos + j, patternSize - 1) == 0)
|
||||
return startPos + j;
|
||||
j += table[c];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
u32 i;
|
||||
for(i = 0; src[i] != 0; i++)
|
||||
dest[i] = src[i];
|
||||
|
||||
dest[i] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, u32 size)
|
||||
{
|
||||
u32 i;
|
||||
for(i = 0; i < size && src[i] != 0; i++)
|
||||
dest[i] = src[i];
|
||||
|
||||
for(; i < size; i++)
|
||||
dest[i] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
s32 strnlen(const char *string, s32 maxlen)
|
||||
{
|
||||
s32 size;
|
||||
for(size = 0; *string && size < maxlen; string++, size++);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
s32 strlen(const char *string)
|
||||
{
|
||||
char *stringEnd = (char *)string;
|
||||
while(*stringEnd) stringEnd++;
|
||||
|
||||
return stringEnd - string;
|
||||
}
|
||||
|
||||
s32 strcmp(const char *str1, const char *str2)
|
||||
{
|
||||
while(*str1 && (*str1 == *str2))
|
||||
{
|
||||
str1++;
|
||||
str2++;
|
||||
}
|
||||
|
||||
return *str1 - *str2;
|
||||
}
|
||||
|
||||
s32 strncmp(const char *str1, const char *str2, u32 size)
|
||||
{
|
||||
while(size && *str1 && (*str1 == *str2))
|
||||
{
|
||||
str1++;
|
||||
str2++;
|
||||
size--;
|
||||
}
|
||||
if (!size)
|
||||
return 0;
|
||||
else
|
||||
return *str1 - *str2;
|
||||
}
|
||||
|
||||
void hexItoa(u64 number, char *out, u32 digits, bool uppercase)
|
||||
{
|
||||
const char hexDigits[] = "0123456789ABCDEF";
|
||||
const char hexDigitsLowercase[] = "0123456789abcdef";
|
||||
u32 i = 0;
|
||||
|
||||
while(number > 0)
|
||||
{
|
||||
out[digits - 1 - i++] = uppercase ? hexDigits[number & 0xF] : hexDigitsLowercase[number & 0xF];
|
||||
number >>= 4;
|
||||
}
|
||||
|
||||
while(i < digits) out[digits - 1 - i++] = '0';
|
||||
}
|
||||
55
sysmodules/rosalina/kernel_extension/source/start.s
Normal file
55
sysmodules/rosalina/kernel_extension/source/start.s
Normal file
@@ -0,0 +1,55 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
@
|
||||
@ This program is free software: you can redistribute it and/or modify
|
||||
@ it under the terms of the GNU General Public License as published by
|
||||
@ the Free Software Foundation, either version 3 of the License, or
|
||||
@ (at your option) any later version.
|
||||
@
|
||||
@ This program is distributed in the hope that it will be useful,
|
||||
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
@ GNU General Public License for more details.
|
||||
@
|
||||
@ You should have received a copy of the GNU General Public License
|
||||
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.section .text.start
|
||||
.balign 4
|
||||
.global _start
|
||||
_start:
|
||||
push {r4, lr}
|
||||
|
||||
mrc p15, 0, r4, c0, c0, 5 @ CPUID register
|
||||
and r4, #3
|
||||
cmp r4, #1
|
||||
beq _core1_only
|
||||
|
||||
_waitLoop:
|
||||
wfe
|
||||
ldr r0, =_setupFinished
|
||||
ldr r0, [r0]
|
||||
cmp r0, #0
|
||||
beq _waitLoop
|
||||
b end
|
||||
|
||||
_core1_only:
|
||||
bl main
|
||||
ldr r0, =_setupFinished
|
||||
str r4, [r0]
|
||||
sev
|
||||
|
||||
end:
|
||||
pop {r4, pc}
|
||||
|
||||
.bss
|
||||
.balign 4
|
||||
_setupFinished: .word 0
|
||||
155
sysmodules/rosalina/kernel_extension/source/svc.c
Normal file
155
sysmodules/rosalina/kernel_extension/source/svc.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc.h"
|
||||
#include "svc/ControlMemory.h"
|
||||
#include "svc/GetProcessInfo.h"
|
||||
#include "svc/GetThreadInfo.h"
|
||||
#include "svc/GetSystemInfo.h"
|
||||
#include "svc/GetCFWInfo.h"
|
||||
#include "svc/ConnectToPort.h"
|
||||
#include "svc/SendSyncRequest.h"
|
||||
#include "svc/Break.h"
|
||||
#include "svc/SetGpuProt.h"
|
||||
#include "svc/SetWifiEnabled.h"
|
||||
#include "svc/Backdoor.h"
|
||||
#include "svc/KernelSetState.h"
|
||||
#include "svc/MapProcessMemoryEx.h"
|
||||
#include "svc/UnmapProcessMemoryEx.h"
|
||||
#include "svc/ControlService.h"
|
||||
#include "svc/CopyHandle.h"
|
||||
#include "svc/TranslateHandle.h"
|
||||
|
||||
void *officialSVCs[0x7E] = {NULL};
|
||||
|
||||
static inline void yieldDuringRosalinaMenu(void)
|
||||
{
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
|
||||
u64 titleId = codeSetOfProcess(currentProcess)->titleId;
|
||||
u32 highTitleId = (u32)(titleId >> 32), lowTitleId = (u32)titleId;
|
||||
while((rosalinaState & 1) && idOfProcess(currentProcess) >= 6 &&
|
||||
(highTitleId != 0x00040130 || (highTitleId == 0x00040130 && (lowTitleId == 0x1A02 || lowTitleId == 0x1C02))))
|
||||
SleepThread(25 * 1000 * 1000LL);
|
||||
}
|
||||
|
||||
void signalSvcEntry(u8 *pageEnd)
|
||||
{
|
||||
u32 svcId = (u32) *(u8 *)(pageEnd - 0xB5);
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
|
||||
yieldDuringRosalinaMenu();
|
||||
|
||||
if(svcId == 0xFE)
|
||||
svcId = *(u32 *)(pageEnd - 0x110 + 8 * 4); // r12 ; note: max theortical SVC atm: 0x3FFFFFFF. We don't support catching svcIds >= 0x100 atm either
|
||||
|
||||
// Since DBGEVENT_SYSCALL_ENTRY is non blocking, we'll cheat using EXCEVENT_UNDEFINED_SYSCALL (debug->svcId is fortunately an u16!)
|
||||
if(debugOfProcess(currentProcess) != NULL && shouldSignalSyscallDebugEvent(currentProcess, svcId))
|
||||
SignalDebugEvent(DBGEVENT_OUTPUT_STRING, 0xFFFFFFFE, svcId);
|
||||
}
|
||||
|
||||
void signalSvcReturn(u8 *pageEnd)
|
||||
{
|
||||
u32 svcId = (u32) *(u8 *)(pageEnd - 0xB5);
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
|
||||
yieldDuringRosalinaMenu();
|
||||
|
||||
if(svcId == 0xFE)
|
||||
svcId = *(u32 *)(pageEnd - 0x110 + 8 * 4); // r12 ; note: max theortical SVC atm: 0x1FFFFFFF. We don't support catching svcIds >= 0x100 atm either
|
||||
|
||||
// Since DBGEVENT_SYSCALL_RETURN is non blocking, we'll cheat using EXCEVENT_UNDEFINED_SYSCALL (debug->svcId is fortunately an u16!)
|
||||
if(debugOfProcess(currentProcess) != NULL && shouldSignalSyscallDebugEvent(currentProcess, svcId))
|
||||
SignalDebugEvent(DBGEVENT_OUTPUT_STRING, 0xFFFFFFFF, svcId);
|
||||
}
|
||||
|
||||
void *svcHook(u8 *pageEnd)
|
||||
{
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
|
||||
u32 svcId = *(u8 *)(pageEnd - 0xB5);
|
||||
if(svcId == 0xFE)
|
||||
svcId = *(u32 *)(pageEnd - 0x110 + 8 * 4); // r12 ; note: max theortical SVC atm: 0x3FFFFFFF. We don't support catching svcIds >= 0x100 atm either
|
||||
switch(svcId)
|
||||
{
|
||||
case 0x01:
|
||||
return ControlMemoryHookWrapper;
|
||||
case 0x2A:
|
||||
return GetSystemInfoHookWrapper;
|
||||
case 0x2B:
|
||||
return GetProcessInfoHookWrapper;
|
||||
case 0x2C:
|
||||
return GetThreadInfoHookWrapper;
|
||||
case 0x2D:
|
||||
return ConnectToPortHookWrapper;
|
||||
case 0x2E:
|
||||
return GetCFWInfo; // DEPRECATED
|
||||
case 0x32:
|
||||
return SendSyncRequestHook;
|
||||
case 0x3C:
|
||||
return (debugOfProcess(currentProcess) != NULL) ? officialSVCs[0x3C] : (void *)Break;
|
||||
case 0x59:
|
||||
return SetGpuProt;
|
||||
case 0x5A:
|
||||
return SetWifiEnabled;
|
||||
case 0x7B:
|
||||
return Backdoor;
|
||||
case 0x7C:
|
||||
return KernelSetStateHook;
|
||||
|
||||
|
||||
case 0x80:
|
||||
return CustomBackdoor;
|
||||
|
||||
case 0x90:
|
||||
return convertVAToPA;
|
||||
case 0x91:
|
||||
return flushDataCacheRange;
|
||||
case 0x92:
|
||||
return flushEntireDataCache;
|
||||
case 0x93:
|
||||
return invalidateInstructionCacheRange;
|
||||
case 0x94:
|
||||
return invalidateEntireInstructionCache;
|
||||
|
||||
case 0xA0:
|
||||
return MapProcessMemoryEx;
|
||||
case 0xA1:
|
||||
return UnmapProcessMemoryEx;
|
||||
case 0xA2:
|
||||
return ControlMemoryEx;
|
||||
|
||||
case 0xB0:
|
||||
return ControlService;
|
||||
case 0xB1:
|
||||
return CopyHandleWrapper;
|
||||
case 0xB2:
|
||||
return TranslateHandleWrapper;
|
||||
|
||||
default:
|
||||
return (svcId <= 0x7D) ? officialSVCs[svcId] : NULL;
|
||||
}
|
||||
}
|
||||
43
sysmodules/rosalina/kernel_extension/source/svc/Backdoor.s
Normal file
43
sysmodules/rosalina/kernel_extension/source/svc/Backdoor.s
Normal file
@@ -0,0 +1,43 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
@
|
||||
@ This program is free software: you can redistribute it and/or modify
|
||||
@ it under the terms of the GNU General Public License as published by
|
||||
@ the Free Software Foundation, either version 3 of the License, or
|
||||
@ (at your option) any later version.
|
||||
@
|
||||
@ This program is distributed in the hope that it will be useful,
|
||||
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
@ GNU General Public License for more details.
|
||||
@
|
||||
@ You should have received a copy of the GNU General Public License
|
||||
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.text
|
||||
.arm
|
||||
.balign 4
|
||||
|
||||
.global Backdoor
|
||||
.type Backdoor, %function
|
||||
Backdoor:
|
||||
@ Nintendo's code
|
||||
bic r1, sp, #0xff
|
||||
orr r1, r1, #0xf00
|
||||
add r1, r1, #0x28 @ get user stack.
|
||||
|
||||
ldr r2, [r1]
|
||||
stmdb r2!, {sp, lr}
|
||||
mov sp, r2 @ sp_svc = sp_usr. You'll get nice crashes if an interrupt or context switch occurs during svcBackdoor
|
||||
blx r0
|
||||
pop {r0, r1}
|
||||
mov sp, r0
|
||||
bx r1
|
||||
35
sysmodules/rosalina/kernel_extension/source/svc/Break.s
Normal file
35
sysmodules/rosalina/kernel_extension/source/svc/Break.s
Normal file
@@ -0,0 +1,35 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
@
|
||||
@ This program is free software: you can redistribute it and/or modify
|
||||
@ it under the terms of the GNU General Public License as published by
|
||||
@ the Free Software Foundation, either version 3 of the License, or
|
||||
@ (at your option) any later version.
|
||||
@
|
||||
@ This program is distributed in the hope that it will be useful,
|
||||
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
@ GNU General Public License for more details.
|
||||
@
|
||||
@ You should have received a copy of the GNU General Public License
|
||||
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.text
|
||||
.arm
|
||||
.balign 4
|
||||
|
||||
.global Break
|
||||
.type Break, %function
|
||||
Break:
|
||||
bic r0, sp, #0xf00
|
||||
bic r0, #0xff
|
||||
add r0, #0x1000 @ get page context top
|
||||
bkpt 0xffff
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/ConnectToPort.h"
|
||||
#include "memory.h"
|
||||
#include "ipc.h"
|
||||
|
||||
Result ConnectToPortHook(Handle *out, const char *name)
|
||||
{
|
||||
char portName[12] = {0};
|
||||
Result res = 0;
|
||||
if(name != NULL)
|
||||
{
|
||||
s32 nb = usrToKernelStrncpy(portName, name, 12);
|
||||
if(nb < 0)
|
||||
return 0xD9001814;
|
||||
else if(nb == 12 && portName[11] != 0)
|
||||
return 0xE0E0181E;
|
||||
}
|
||||
res = ConnectToPort(out, name);
|
||||
if(res != 0)
|
||||
return res;
|
||||
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KClientSession *clientSession = (KClientSession *)KProcessHandleTable__ToKAutoObject(handleTable, *out);
|
||||
if(clientSession != NULL)
|
||||
{
|
||||
SessionInfo_Add(clientSession->parentSession, portName);
|
||||
clientSession->syncObject.autoObject.vtable->DecrementReferenceCount(&clientSession->syncObject.autoObject);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/ControlMemory.h"
|
||||
|
||||
Result ControlMemoryHook(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm)
|
||||
{
|
||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||
return ControlMemory(addrOut, addr0, addr1, size, op, perm, idOfProcess(currentProcess) == 1);
|
||||
}
|
||||
|
||||
108
sysmodules/rosalina/kernel_extension/source/svc/ControlService.c
Normal file
108
sysmodules/rosalina/kernel_extension/source/svc/ControlService.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/ControlService.h"
|
||||
#include "memory.h"
|
||||
#include "ipc.h"
|
||||
|
||||
Result ControlService(ServiceOp op, u32 varg1, u32 varg2)
|
||||
{
|
||||
Result res = 0;
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
|
||||
switch(op)
|
||||
{
|
||||
case SERVICEOP_GET_NAME:
|
||||
{
|
||||
KSession *session = NULL;
|
||||
SessionInfo *info = NULL;
|
||||
KAutoObject *obj = KProcessHandleTable__ToKAutoObject(handleTable, (Handle)varg2);
|
||||
if(obj == NULL)
|
||||
return 0xD8E007F7; // invalid handle
|
||||
else if(kernelVersion >= SYSTEM_VERSION(2, 46, 0))
|
||||
{
|
||||
KClassToken tok;
|
||||
obj->vtable->GetClassToken(&tok, obj);
|
||||
if(tok.flags == 0x95)
|
||||
session = ((KServerSession *)obj)->parentSession;
|
||||
else if(tok.flags == 0xA5)
|
||||
session = ((KClientSession *)obj)->parentSession;
|
||||
}
|
||||
else
|
||||
{ // not the exact same tests but it should work
|
||||
if(strcmp(obj->vtable->GetClassName(obj), "KServerSession") == 0)
|
||||
session = ((KServerSession *)obj)->parentSession;
|
||||
else if(strcmp(obj->vtable->GetClassName(obj), "KClientSession") == 0)
|
||||
session = ((KClientSession *)obj)->parentSession;
|
||||
}
|
||||
|
||||
if(session != NULL)
|
||||
info = SessionInfo_Lookup(session);
|
||||
|
||||
if(info == NULL)
|
||||
res = 0xD8E007F7;
|
||||
else
|
||||
{
|
||||
// names are limited to 11 characters (for ports)
|
||||
// kernelToUsrStrncpy doesn't clear trailing bytes
|
||||
char name[12] = { 0 };
|
||||
strncpy(name, info->name, 12);
|
||||
res = kernelToUsrMemcpy8((void *)varg1, name, strlen(name) + 1) ? 0 : 0xE0E01BF5;
|
||||
}
|
||||
|
||||
obj->vtable->DecrementReferenceCount(obj);
|
||||
return res;
|
||||
}
|
||||
|
||||
case SERVICEOP_STEAL_CLIENT_SESSION:
|
||||
{
|
||||
char name[12] = { 0 };
|
||||
SessionInfo *info = NULL;
|
||||
if(name != NULL)
|
||||
{
|
||||
s32 nb = usrToKernelStrncpy(name, (const char *)varg2, 12);
|
||||
if(nb < 0)
|
||||
return 0xD9001814;
|
||||
else if(nb == 12 && name[11] != 0)
|
||||
return 0xE0E0181E;
|
||||
}
|
||||
|
||||
info = SessionInfo_FindFirst(name);
|
||||
|
||||
if(info == NULL)
|
||||
return 0x9401BFE; // timeout (the wanted service is likely not initalized)
|
||||
else
|
||||
{
|
||||
Handle out;
|
||||
res = createHandleForThisProcess(&out, &info->session->clientSession.syncObject.autoObject);
|
||||
return (res != 0) ? res : (kernelToUsrMemcpy32((u32 *)varg1, (u32 *)&out, 4) ? 0 : (Result)0xE0E01BF5);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return 0xF8C007F4;
|
||||
}
|
||||
}
|
||||
76
sysmodules/rosalina/kernel_extension/source/svc/CopyHandle.c
Normal file
76
sysmodules/rosalina/kernel_extension/source/svc/CopyHandle.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/CopyHandle.h"
|
||||
#include "memory.h"
|
||||
|
||||
Result CopyHandle(Handle *outHandle, Handle outProcessHandle, Handle inHandle, Handle inProcessHandle)
|
||||
{
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KProcess *inProcess, *outProcess;
|
||||
Result res;
|
||||
|
||||
if(inProcessHandle == CUR_PROCESS_HANDLE)
|
||||
{
|
||||
inProcess = currentCoreContext->objectContext.currentProcess;
|
||||
KAutoObject__AddReference((KAutoObject *)inProcess);
|
||||
}
|
||||
else
|
||||
inProcess = KProcessHandleTable__ToKProcess(handleTable, inProcessHandle);
|
||||
|
||||
if(inProcess == NULL)
|
||||
return 0xD8E007F7; // invalid handle
|
||||
|
||||
if(outProcessHandle == CUR_PROCESS_HANDLE)
|
||||
{
|
||||
outProcess = currentCoreContext->objectContext.currentProcess;
|
||||
KAutoObject__AddReference((KAutoObject *)outProcess);
|
||||
}
|
||||
else
|
||||
outProcess = KProcessHandleTable__ToKProcess(handleTable, outProcessHandle);
|
||||
|
||||
if(outProcess == NULL)
|
||||
{
|
||||
((KAutoObject *)inProcess)->vtable->DecrementReferenceCount((KAutoObject *)inProcess);
|
||||
return 0xD8E007F7; // invalid handle
|
||||
}
|
||||
|
||||
KAutoObject *obj = KProcessHandleTable__ToKAutoObject(handleTableOfProcess(inProcess), inHandle);
|
||||
if(obj == NULL)
|
||||
{
|
||||
((KAutoObject *)inProcess)->vtable->DecrementReferenceCount((KAutoObject *)inProcess);
|
||||
((KAutoObject *)outProcess)->vtable->DecrementReferenceCount((KAutoObject *)outProcess);
|
||||
return 0xD8E007F7; // invalid handle
|
||||
}
|
||||
|
||||
res = createHandleForProcess(outHandle, outProcess, obj);
|
||||
|
||||
obj->vtable->DecrementReferenceCount(obj);
|
||||
((KAutoObject *)inProcess)->vtable->DecrementReferenceCount((KAutoObject *)inProcess);
|
||||
((KAutoObject *)outProcess)->vtable->DecrementReferenceCount((KAutoObject *)outProcess);
|
||||
|
||||
return res;
|
||||
}
|
||||
33
sysmodules/rosalina/kernel_extension/source/svc/GetCFWInfo.c
Normal file
33
sysmodules/rosalina/kernel_extension/source/svc/GetCFWInfo.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/GetCFWInfo.h"
|
||||
|
||||
// DEPRECATED
|
||||
Result GetCFWInfo(CfwInfo *out)
|
||||
{
|
||||
return kernelToUsrMemcpy8(out, &cfwInfo, 16) ? 0 : 0xE0E01BF5;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/GetProcessInfo.h"
|
||||
#include "memory.h"
|
||||
|
||||
Result GetProcessInfoHook(s64 *out, Handle processHandle, u32 type)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
if(type >= 0x10000)
|
||||
{
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KProcess *process;
|
||||
if(processHandle == CUR_PROCESS_HANDLE)
|
||||
{
|
||||
process = currentCoreContext->objectContext.currentProcess;
|
||||
KAutoObject__AddReference((KAutoObject *)process);
|
||||
}
|
||||
else
|
||||
process = KProcessHandleTable__ToKProcess(handleTable, processHandle);
|
||||
|
||||
if(process == NULL)
|
||||
return 0xD8E007F7; // invalid handle
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 0x10000:
|
||||
memcpy(out, codeSetOfProcess(process)->processName, 8);
|
||||
break;
|
||||
case 0x10001:
|
||||
*(u64 *)out = codeSetOfProcess(process)->titleId;
|
||||
break;
|
||||
case 0x10002:
|
||||
*out = codeSetOfProcess(process)->nbTextPages << 12;
|
||||
break;
|
||||
case 0x10003:
|
||||
*out = codeSetOfProcess(process)->nbRodataPages << 12;
|
||||
break;
|
||||
case 0x10004:
|
||||
*out = codeSetOfProcess(process)->nbRwPages << 12;
|
||||
break;
|
||||
case 0x10005:
|
||||
*out = (s64)(u64)(u32)codeSetOfProcess(process)->textSection.section.loadAddress;
|
||||
break;
|
||||
case 0x10006:
|
||||
*out = (s64)(u64)(u32)codeSetOfProcess(process)->rodataSection.section.loadAddress;
|
||||
break;
|
||||
case 0x10007:
|
||||
*out = (s64)(u64)(u32)codeSetOfProcess(process)->dataSection.section.loadAddress;
|
||||
break;
|
||||
case 0x10008:
|
||||
*out = (isN3DS ? hwInfoOfProcess(process)->N3DS.translationTableBase :
|
||||
(kernelVersion >= SYSTEM_VERSION(2, 44, 6)
|
||||
? hwInfoOfProcess(process)->O3DS8x.translationTableBase
|
||||
: hwInfoOfProcess(process)->O3DSPre8x.translationTableBase)
|
||||
) & ~((1 << (14 - TTBCR)) - 1);
|
||||
break;
|
||||
default:
|
||||
res = 0xD8E007ED; // invalid enum value
|
||||
break;
|
||||
}
|
||||
|
||||
((KAutoObject *)process)->vtable->DecrementReferenceCount((KAutoObject *)process);
|
||||
}
|
||||
|
||||
else
|
||||
res = GetProcessInfo(out, processHandle, type);
|
||||
|
||||
return res;
|
||||
}
|
||||
123
sysmodules/rosalina/kernel_extension/source/svc/GetSystemInfo.c
Normal file
123
sysmodules/rosalina/kernel_extension/source/svc/GetSystemInfo.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/GetSystemInfo.h"
|
||||
#include "utils.h"
|
||||
#include "ipc.h"
|
||||
#include "synchronization.h"
|
||||
|
||||
Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 0x10000:
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case 0:
|
||||
*out = SYSTEM_VERSION(cfwInfo.versionMajor, cfwInfo.versionMinor, cfwInfo.versionBuild);
|
||||
break;
|
||||
case 1:
|
||||
*out = cfwInfo.commitHash;
|
||||
break;
|
||||
case 2:
|
||||
*out = cfwInfo.config;
|
||||
break;
|
||||
case 3: // isRelease
|
||||
*out = cfwInfo.flags & 1;
|
||||
break;
|
||||
case 4: // isN3DS
|
||||
*out = (cfwInfo.flags >> 4) & 1;
|
||||
break;
|
||||
case 5: // isSafeMode
|
||||
*out = (cfwInfo.flags >> 5) & 1;
|
||||
break;
|
||||
case 6: // isSdMode
|
||||
*out = (cfwInfo.flags >> 6) & 1;
|
||||
break;
|
||||
default:
|
||||
res = 0xF8C007F4; // not implemented
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x10001: // N3DS-related info
|
||||
{
|
||||
if(isN3DS)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case 0: // current clock rate
|
||||
*out = (((CFG11_MPCORE_CLKCNT >> 1) & 3) + 1) * 268;
|
||||
break;
|
||||
case 1: // higher clock rate
|
||||
*out = (((CFG11_MPCORE_CFG >> 2) & 1) + 2) * 268;
|
||||
break;
|
||||
case 2: // L2C enabled status
|
||||
*out = L2C_CTRL & 1;
|
||||
break;
|
||||
default:
|
||||
res = 0xF8C007F4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
res = 0xF8C007F4;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x10002: // MMU config (cached values from booting)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case 0:
|
||||
*out = TTBCR;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if((u32)param <= getNumberOfCores())
|
||||
*out = L1MMUTableAddrs[param - 1];
|
||||
else
|
||||
res = 0xF8C007F4;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
GetSystemInfo(out, type, param);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/GetThreadInfo.h"
|
||||
#include "memory.h"
|
||||
|
||||
Result GetThreadInfoHook(s64 *out, Handle threadHandle, u32 type)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
if(type == 0x10000) // Get TLS
|
||||
{
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KThread *thread;
|
||||
|
||||
if(threadHandle == CUR_THREAD_HANDLE)
|
||||
{
|
||||
thread = currentCoreContext->objectContext.currentThread;
|
||||
KAutoObject__AddReference(&thread->syncObject.autoObject);
|
||||
}
|
||||
else
|
||||
thread = KProcessHandleTable__ToKThread(handleTable, threadHandle);
|
||||
|
||||
if(thread == NULL)
|
||||
return 0xD8E007F7; // invalid handle
|
||||
|
||||
*out = (s64)(u64)(u32)thread->threadLocalStorage;
|
||||
|
||||
KAutoObject *obj = (KAutoObject *)thread;
|
||||
obj->vtable->DecrementReferenceCount(obj);
|
||||
}
|
||||
|
||||
else
|
||||
res = GetThreadInfo(out, threadHandle, type);
|
||||
|
||||
return res;
|
||||
}
|
||||
149
sysmodules/rosalina/kernel_extension/source/svc/KernelSetState.c
Normal file
149
sysmodules/rosalina/kernel_extension/source/svc/KernelSetState.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/KernelSetState.h"
|
||||
#include "synchronization.h"
|
||||
#include "ipc.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define MAX_DEBUG 3
|
||||
|
||||
static u32 nbEnabled = 0;
|
||||
static u32 maskedPids[MAX_DEBUG];
|
||||
static u32 masks[MAX_DEBUG][8] = {0};
|
||||
|
||||
bool shouldSignalSyscallDebugEvent(KProcess *process, u8 svcId)
|
||||
{
|
||||
u32 pid = idOfProcess(process);
|
||||
u32 id;
|
||||
for(id = 0; id < nbEnabled && maskedPids[id] != pid; id++);
|
||||
if(id == MAX_DEBUG)
|
||||
return false;
|
||||
else
|
||||
return ((masks[id][svcId / 32] >> (31 - (svcId % 32))) & 1) != 0;
|
||||
}
|
||||
|
||||
Result SetSyscallDebugEventMask(u32 pid, bool enable, const u32 *mask)
|
||||
{
|
||||
static KRecursiveLock syscallDebugEventMaskLock = { NULL };
|
||||
|
||||
u32 tmpMask[8];
|
||||
if(enable && nbEnabled == MAX_DEBUG)
|
||||
return 0xC86018FF; // Out of resource (255)
|
||||
|
||||
if(enable && !usrToKernelMemcpy8(&tmpMask, mask, 32))
|
||||
return 0xE0E01BF5;
|
||||
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&syscallDebugEventMaskLock);
|
||||
|
||||
if(enable)
|
||||
{
|
||||
maskedPids[nbEnabled] = pid;
|
||||
memcpy(&masks[nbEnabled++], tmpMask, 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 id;
|
||||
for(id = 0; id < nbEnabled && maskedPids[id] != pid; id++);
|
||||
if(id == nbEnabled)
|
||||
{
|
||||
KRecursiveLock__Unlock(&syscallDebugEventMaskLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return 0xE0E01BFD; // out of range (it's not fully technically correct but meh)
|
||||
}
|
||||
|
||||
for(u32 i = id; i < nbEnabled - 1; i++)
|
||||
{
|
||||
maskedPids[i] = maskedPids[i + 1];
|
||||
memcpy(&masks[i], &masks[i + 1], 32);
|
||||
}
|
||||
maskedPids[--nbEnabled] = 0;
|
||||
memset(&masks[nbEnabled], 0, 32);
|
||||
}
|
||||
|
||||
KRecursiveLock__Unlock(&syscallDebugEventMaskLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result KernelSetStateHook(u32 type, u32 varg1, u32 varg2, u32 varg3)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 0x10000:
|
||||
{
|
||||
do
|
||||
{
|
||||
__ldrex((s32 *)&rosalinaState);
|
||||
}
|
||||
while(__strex((s32 *)&rosalinaState, (s32)(rosalinaState ^ varg1)));
|
||||
|
||||
if(rosalinaState & 2)
|
||||
hasStartedRosalinaNetworkFuncsOnce = true;
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x10001:
|
||||
{
|
||||
KRecursiveLock__Lock(criticalSectionLock);
|
||||
KRecursiveLock__Lock(&processLangemuLock);
|
||||
|
||||
u32 i;
|
||||
for(i = 0; i < 0x40 && processLangemuAttributes[i].titleId != 0ULL; i++);
|
||||
if(i < 0x40)
|
||||
{
|
||||
processLangemuAttributes[i].titleId = ((u64)varg3 << 32) | (u32)varg2;
|
||||
processLangemuAttributes[i].state = (u8)(varg1 >> 24);
|
||||
processLangemuAttributes[i].country = (u8)(varg1 >> 16);
|
||||
processLangemuAttributes[i].language = (u8)(varg1 >> 8);
|
||||
processLangemuAttributes[i].region = (u8)(varg1 >> 4);
|
||||
processLangemuAttributes[i].mask = (u8)(varg1 & 0xf);
|
||||
}
|
||||
else
|
||||
res = 0xD8609013;
|
||||
|
||||
KRecursiveLock__Unlock(&processLangemuLock);
|
||||
KRecursiveLock__Unlock(criticalSectionLock);
|
||||
break;
|
||||
}
|
||||
case 0x10002:
|
||||
{
|
||||
res = SetSyscallDebugEventMask(varg1, (bool)varg2, (const u32 *)varg3);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
res = KernelSetState(type, varg1, varg2, varg3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "svc/MapProcessMemoryEx.h"
|
||||
|
||||
Result MapProcessMemoryEx(Handle processHandle, void *dst, void *src, u32 size)
|
||||
{
|
||||
KProcessHandleTable *handleTable = handleTableOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KProcessHwInfo *currentHwInfo = hwInfoOfProcess(currentCoreContext->objectContext.currentProcess);
|
||||
KProcess *process = KProcessHandleTable__ToKProcess(handleTable, processHandle);
|
||||
|
||||
if(process == NULL)
|
||||
return 0xD8E007F7;
|
||||
|
||||
Result res = KProcessHwInfo__MapProcessMemory(currentHwInfo, hwInfoOfProcess(process), dst, src, size >> 12);
|
||||
|
||||
KAutoObject *obj = (KAutoObject *)process;
|
||||
obj->vtable->DecrementReferenceCount(obj);
|
||||
|
||||
return res;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user