From 97141448e9fe1b929cb74d55fc124f2a0cbadbfb Mon Sep 17 00:00:00 2001 From: plutoo Date: Sat, 20 Jan 2018 19:31:29 +0100 Subject: [PATCH] Implement NextLoadPath for loader env --- nx/include/switch/result.h | 3 ++- nx/include/switch/runtime/env.h | 2 ++ nx/source/runtime/env.c | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/result.h b/nx/include/switch/result.h index 04738019..7c6ae9b7 100644 --- a/nx/include/switch/result.h +++ b/nx/include/switch/result.h @@ -18,7 +18,8 @@ #define MAKERESULT(module,description) \ ((((module)&0x1FF)) | ((description)&0x1FFF)<<9) -#define MODULE_LIBNX 345 +#define MODULE_LIBNX 345 + enum { LIBNX_BADRELOC=1, LIBNX_OUTOFMEM, diff --git a/nx/include/switch/runtime/env.h b/nx/include/switch/runtime/env.h index fedb8b6a..d009d77b 100644 --- a/nx/include/switch/runtime/env.h +++ b/nx/include/switch/runtime/env.h @@ -45,3 +45,5 @@ bool envIsSyscallHinted(u8 svc); Handle envGetOwnProcessHandle(void); LoaderReturnFn envGetExitFuncPtr(void); + +Result envSetNextLoad(const char* path, const char* argv); diff --git a/nx/source/runtime/env.c b/nx/source/runtime/env.c index 845b1c28..6e38436c 100644 --- a/nx/source/runtime/env.c +++ b/nx/source/runtime/env.c @@ -10,6 +10,8 @@ static u64 g_overrideArgc = 0; static void* g_overrideArgv = NULL; static u64 g_syscallHints[2]; static Handle g_processHandle = INVALID_HANDLE; +static char* g_nextLoadPath = NULL; +static char* g_nextLoadArgv = NULL; extern __attribute__((weak)) u32 __nx_applet_type; @@ -48,7 +50,8 @@ void envParse(void* ctx, Handle main_thread, LoaderReturnFn saved_lr) break; case EntryType_NextLoadPath: - // TODO + g_nextLoadPath = (char*) ent->Value[0]; + g_nextLoadArgv = (char*) ent->Value[1]; break; case EntryType_OverrideHeap: @@ -140,3 +143,21 @@ Handle envGetOwnProcessHandle(void) { LoaderReturnFn envGetExitFuncPtr(void) { return g_loaderRetAddr; } + +Result envSetNextLoad(const char* path, const char* argv) +{ + if (g_nextLoadPath == NULL) + return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED); + + strcpy(g_nextLoadPath, path); + + if (g_nextLoadArgv != NULL) + { + if (argv == NULL) + g_nextLoadArgv[0] = '\0'; + else + strcpy(g_nextLoadArgv, argv); + } + + return 0; +}