1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 08:22:04 +00:00

Loader: Fix bugs in CreateProcess(), which now succeeds on hardware (1.0.0)

This commit is contained in:
Michael Scire 2018-04-24 17:56:32 -06:00
parent 195528adc6
commit 3e36e81e80
4 changed files with 10 additions and 6 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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);
};