From 1a6f57240591af639ccfac841853e62dc60d9e76 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Wed, 9 May 2018 18:23:35 -0700 Subject: [PATCH] Fixes --- ctr/exec-3dsx/exec_3dsx.c | 11 ++++++----- ctr/exec-3dsx/exec_3dsx.h | 7 +++++++ ctr/exec-3dsx/exec_cia.c | 32 +++++++++++++++++++++----------- ctr/exec-3dsx/exec_cia.h | 5 +++++ frontend/drivers/platform_ctr.c | 8 ++++---- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/ctr/exec-3dsx/exec_3dsx.c b/ctr/exec-3dsx/exec_3dsx.c index 07595996e7..0cda976eee 100644 --- a/ctr/exec-3dsx/exec_3dsx.c +++ b/ctr/exec-3dsx/exec_3dsx.c @@ -45,22 +45,23 @@ int exec_3dsx(const char* path, const char* args){ inited = loader_Rosalina.init(); if(inited){ loader_Rosalina.launchFile(path, &newProgramArgs, NULL); - exit(0); + //exit(0); } inited = loader_Ninjhax2.init(); if(inited){ loader_Ninjhax2.launchFile(path, &newProgramArgs, NULL); - exit(0); + //exit(0); } inited = loader_Ninjhax1.init(); if(inited){ loader_Ninjhax1.launchFile(path, &newProgramArgs, NULL); - exit(0); + //exit(0); } //should never be reached - errno = ENOTSUP; - return -1; + //errno = ENOTSUP; + //return -1; + return 0; } \ No newline at end of file diff --git a/ctr/exec-3dsx/exec_3dsx.h b/ctr/exec-3dsx/exec_3dsx.h index 3aa5b6a98b..29301a64aa 100644 --- a/ctr/exec-3dsx/exec_3dsx.h +++ b/ctr/exec-3dsx/exec_3dsx.h @@ -1 +1,8 @@ +#ifndef EXEC_3DSX_H +#define EXEC_3DSX_H + +//since 3dsx programs are not guaranteed access to the OS, the 3dsx bootloader run by the exploit must run the next program +//your program must call this then exit gracefully to work, exit() also doesnt work int exec_3dsx(const char* path, const char* args); + +#endif \ No newline at end of file diff --git a/ctr/exec-3dsx/exec_cia.c b/ctr/exec-3dsx/exec_cia.c index 428fd1c293..50d63926f0 100644 --- a/ctr/exec-3dsx/exec_cia.c +++ b/ctr/exec-3dsx/exec_cia.c @@ -14,6 +14,15 @@ typedef struct{ }ciaParam; +static void errorAndQuit(const char* errorStr){ + errorConf error; + + errorInit(&error, ERROR_TEXT, CFG_LANGUAGE_EN); + errorText(&error, errorStr); + errorDisp(&error); + exit(0); +} + static int isCiaInstalled(u64 titleId){ u32 titlesToRetrieve; u32 titlesRetrieved; @@ -71,6 +80,8 @@ static int installCia(Handle ciaFile){ failed = FSFILE_Write(outputHandle, &bytesWritten, fileOffset, transferBuffer, bytesRead, 0); if(R_FAILED(failed)){ AM_CancelCIAInstall(outputHandle); + if(R_DESCRIPTION(failed) == RD_ALREADY_EXISTS) + return 1; return -1; } @@ -100,15 +111,6 @@ static u64 getCiaTitleId(Handle ciaFile){ return ciaInfo.titleID; } -static void errorAndQuit(const char* errorStr){ - errorConf error; - - errorInit(&error, ERROR_TEXT, CFG_LANGUAGE_EN); - errorText(&error, errorStr); - errorDisp(&error); - exit(0); -} - int exec_cia(const char* path, const char* args){ struct stat sBuff; bool fileExists; @@ -132,6 +134,7 @@ int exec_cia(const char* path, const char* args){ inited = R_SUCCEEDED(amInit()) && R_SUCCEEDED(fsInit()); if(inited){ Result res; + int error; FS_Archive ciaArchive; Handle ciaFile; u64 titleId; @@ -202,8 +205,15 @@ int exec_cia(const char* path, const char* args){ } res = APT_PrepareToDoApplicationJump(0, titleId, 0x1); - if(R_SUCCEEDED(res)) - res = APT_DoApplicationJump(¶m, sizeof(param.argc) + argsLength, __argv_hmac); + if(R_FAILED(res)) + errorAndQuit("CIA cant run, cant prepare."); + + res = APT_DoApplicationJump(¶m, sizeof(param.argc) + argsLength, __argv_hmac); + if(R_FAILED(res)) + errorAndQuit("CIA cant run, cant jump."); + + //wait for application jump, for some reason its not instant + while(1); } //should never be reached diff --git a/ctr/exec-3dsx/exec_cia.h b/ctr/exec-3dsx/exec_cia.h index 4544fb94ef..3a131720bf 100644 --- a/ctr/exec-3dsx/exec_cia.h +++ b/ctr/exec-3dsx/exec_cia.h @@ -1 +1,6 @@ +#ifndef EXEC_CIA_H +#define EXEC_CIA_H + int exec_cia(const char* path, const char* args); + +#endif \ No newline at end of file diff --git a/frontend/drivers/platform_ctr.c b/frontend/drivers/platform_ctr.c index 917d92bb00..3cfb559294 100644 --- a/frontend/drivers/platform_ctr.c +++ b/frontend/drivers/platform_ctr.c @@ -182,6 +182,7 @@ static void frontend_ctr_deinit(void* data) static void frontend_ctr_exec(const char* path, bool should_load_game) { + int error = 0; char args[0x300 - 0x4]; DEBUG_VAR(path); @@ -223,16 +224,15 @@ static void frontend_ctr_exec(const char* path, bool should_load_game) } } #endif - int error; if (envIsHomebrew()) error = exec_3dsx(path, args); else error = exec_cia(path, args); - if (error) - RARCH_LOG("Cant execute new core:%s.\n", strerror(errno)); + } - svcSleepThread(INT64_MAX); + if (error) + RARCH_LOG("Cant execute new core:%s.\n", strerror(errno)); } #ifndef IS_SALAMANDER