mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 14:11:43 +00:00
Loader: Fix bugs in CreateProcess(), which now succeeds on hardware (1.0.0)
This commit is contained in:
parent
195528adc6
commit
3e36e81e80
4 changed files with 10 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -160,8 +160,9 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
|
|||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
Loading…
Reference in a new issue