diff --git a/stratosphere/loader/source/ldr_nso.cpp b/stratosphere/loader/source/ldr_nso.cpp index 7e9ab7bef..174a3b33b 100644 --- a/stratosphere/loader/source/ldr_nso.cpp +++ b/stratosphere/loader/source/ldr_nso.cpp @@ -55,11 +55,12 @@ Result NsoUtils::LoadNsoHeaders(u64 title_id) { for (unsigned int i = 0; i < NSO_NUM_MAX; i++) { f_nso = OpenNso(i, title_id); if (f_nso != NULL) { - if (fread(&g_nso_headers[i], sizeof(NsoUtils::NsoHeader), 1, f_nso) != sizeof(NsoUtils::NsoHeader)) { + if (fread(&g_nso_headers[i], 1, sizeof(NsoUtils::NsoHeader), f_nso) != sizeof(NsoUtils::NsoHeader)) { return 0xA09; } g_nso_present[i] = true; fclose(f_nso); + f_nso = NULL; continue; } if (1 < i && i < 12) { @@ -197,6 +198,7 @@ Result NsoUtils::LoadNsoSegment(unsigned int index, unsigned int segment, FILE * u8 *dst_addr = map_base + g_nso_headers[index].segments[segment].dst_offset; u8 *load_addr = is_compressed ? map_end - size : dst_addr; + fseek(f_nso, g_nso_headers[index].segments[segment].file_offset, SEEK_SET); if (fread(load_addr, 1, size, f_nso) != size) { return 0xA09; } @@ -246,6 +248,7 @@ Result NsoUtils::LoadNsosIntoProcessMemory(Handle process_h, u64 title_id, NsoLo } } fclose(f_nso); + f_nso = NULL; /* Zero out memory before .text. */ u64 text_base = 0, text_start = g_nso_headers[i].segments[0].dst_offset; std::fill(map_base + text_base, map_base + text_start, 0); diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index e17abe9b1..a353b645d 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -144,7 +144,7 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc } /* Figure out where NSOs will be mapped, and how much space they (and arguments) will take up. */ - rc = NsoUtils::CalculateNsoLoadExtents(launch_item != NULL ? launch_item->arg_size : 0, process_info.process_flags, &nso_extents); + rc = NsoUtils::CalculateNsoLoadExtents(process_info.process_flags, launch_item != NULL ? launch_item->arg_size : 0, &nso_extents); if (R_FAILED(rc)) { goto CREATE_PROCESS_END; } @@ -153,15 +153,16 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc process_info.code_addr = nso_extents.base_address; process_info.code_num_pages = nso_extents.total_size + 0xFFF; process_info.code_num_pages >>= 12; - + /* Call svcCreateProcess(). */ rc = svcCreateProcess(&process_h, &process_info, (u32 *)npdm_info.aci0_kac, npdm_info.aci0->kac_size/sizeof(u32)); if (R_FAILED(rc)) { goto CREATE_PROCESS_END; } + /* Load all NSOs into Process memory, and set permissions accordingly. */ - if (launch_item == NULL) { + if (launch_item != NULL) { rc = NsoUtils::LoadNsosIntoProcessMemory(process_h, npdm_info.aci0->title_id, &nso_extents, (u8 *)launch_item->args, launch_item->arg_size); } else { rc = NsoUtils::LoadNsosIntoProcessMemory(process_h, npdm_info.aci0->title_id, &nso_extents, NULL, 0); diff --git a/stratosphere/loader/source/ldr_random.cpp b/stratosphere/loader/source/ldr_random.cpp index 3839c677b..a431fd4b3 100644 --- a/stratosphere/loader/source/ldr_random.cpp +++ b/stratosphere/loader/source/ldr_random.cpp @@ -42,7 +42,7 @@ u32 RandomUtils::GetRandomU32(u32 max) { return GetNext() % max; } -u32 RandomUtils::GetRandomU64(u64 max) { +u64 RandomUtils::GetRandomU64(u64 max) { u64 val = GetNext(); val |= ((u64)GetNext()) << 32; return val % max; diff --git a/stratosphere/loader/source/ldr_random.hpp b/stratosphere/loader/source/ldr_random.hpp index 63c0911af..633efef0e 100644 --- a/stratosphere/loader/source/ldr_random.hpp +++ b/stratosphere/loader/source/ldr_random.hpp @@ -5,5 +5,5 @@ class RandomUtils { public: static u32 GetNext(); static u32 GetRandomU32(u32 max); - static u32 GetRandomU64(u64 max); + static u64 GetRandomU64(u64 max); }; \ No newline at end of file