Implemented arg parsing for NRO env. When args aren't available, set __system_argv to {ptr to NULL} instead of NULL.

This commit is contained in:
yellows8 2018-02-17 21:25:21 -05:00
parent a1462c8b0b
commit 20cd940095

View File

@ -13,6 +13,8 @@ extern char* fake_heap_end;
extern u32 __argdata__;
static char* g_argv_empty = NULL;
void argvSetup(void)
{
Result rc=0;
@ -21,22 +23,20 @@ void argvSetup(void)
u8 *argdata = (u8*)&__argdata__;
u32 *arg32 = (u32*)argdata;
u64 argdata_allocsize;
u64 argdata_strsize;
u32 argvptr_pos;
u64 argdata_allocsize=0;
u64 argdata_strsize=0;
u32 argvptr_pos=0;
u32 max_argv;
u32 argi;
u32 arglen=0;
bool quote_flag=0;
bool end_flag=0;
char *args;
char *args = NULL;
char *argstart;
char *argstorage;
__system_argc = 0;
__system_argv = NULL;
// TODO: Use envHasArgv()/envGetArgv() here for the NRO case.
__system_argv = &g_argv_empty;
if (envIsNso()) {
memset(&meminfo, 0, sizeof(meminfo));
@ -57,6 +57,24 @@ void argvSetup(void)
argvptr_pos = 0x20 + argdata_strsize+1;
if (argvptr_pos >= argdata_allocsize) return;
}
else if (envHasArgv()) {
args = envGetArgv();
argdata_allocsize = 0x9000;//Use the same size as NSO.
argdata_strsize = strlen(args);
argdata = (u8*)fake_heap_start;
if (argdata_strsize==0) return;
if (fake_heap_end - fake_heap_start < argdata_allocsize) return;
fake_heap_start += argdata_allocsize;
argvptr_pos = 0;
memset(argdata, 0, argdata_allocsize);
}
argstorage = (char*)&argdata[argvptr_pos];
argvptr_pos += (argdata_strsize+1 + 0x9) & ~0x7;
@ -118,6 +136,5 @@ void argvSetup(void)
}
__system_argv[__system_argc] = NULL;
}
}