mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-14 00:56:35 +00:00
Loader: Fix bugs ldr:ro, Loader now works fully on hardware.
This commit is contained in:
parent
361e9607a9
commit
9e03852703
6 changed files with 13 additions and 6 deletions
|
@ -202,6 +202,7 @@ T GetValueFromIpcParsedCommand(IpcParsedCommand& r, IpcCommand& out_c, u8 *point
|
|||
} else if constexpr (is_ipc_handle<T>::value) {
|
||||
return r.Handles[h_index++];
|
||||
} else if constexpr (std::is_same<T, PidDescriptor>::value) {
|
||||
cur_rawdata_index += sizeof(u64) / sizeof(u32);
|
||||
return PidDescriptor(r.Pid);
|
||||
} else {
|
||||
cur_rawdata_index += size_in_raw_data<T>::value / sizeof(u32);
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
"svcSetProcessMemoryPermission" : "0x73",
|
||||
"svcMapProcessMemory" : "0x74",
|
||||
"svcUnmapProcessMemory" : "0x75",
|
||||
"svcMapProcessCodeMemory" : "0x77",
|
||||
"svcUnmapProcessCodeMemory" : "0x78",
|
||||
"svcCreateProcess" : "0x79"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <switch.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include "ldr_map.hpp"
|
||||
#include "ldr_random.hpp"
|
||||
|
@ -159,7 +160,7 @@ Result MapUtils::MapCodeMemoryForProcessDeprecated(Handle process_h, bool is_64_
|
|||
if (size > addspace_size) {
|
||||
return 0x6609;
|
||||
}
|
||||
|
||||
|
||||
u64 try_address;
|
||||
for (unsigned int i = 0; i < 0x200; i++) {
|
||||
try_address = addspace_base + (RandomUtils::GetRandomU64((u64)(addspace_size - size) >> 12) << 12);
|
||||
|
|
|
@ -30,8 +30,8 @@ Result NroUtils::ValidateNrrHeader(NrrHeader *header, u64 size, u64 title_id_min
|
|||
|
||||
Result NroUtils::LoadNro(Registration::Process *target_proc, Handle process_h, u64 nro_heap_address, u64 nro_heap_size, u64 bss_heap_address, u64 bss_heap_size, u64 *out_address) {
|
||||
NroHeader *nro;
|
||||
MappedCodeMemory mcm_nro;
|
||||
MappedCodeMemory mcm_bss;
|
||||
MappedCodeMemory mcm_nro = {0};
|
||||
MappedCodeMemory mcm_bss = {0};
|
||||
unsigned int i;
|
||||
Result rc;
|
||||
u8 nro_hash[0x20];
|
||||
|
@ -47,7 +47,7 @@ Result NroUtils::LoadNro(Registration::Process *target_proc, Handle process_h, u
|
|||
}
|
||||
for (i = 0; i < 0x200; i++) {
|
||||
if (R_SUCCEEDED(mcm_nro.Open(process_h, target_proc->is_64_bit_addspace, nro_heap_address, nro_heap_size))) {
|
||||
if (R_SUCCEEDED(mcm_bss.OpenAtAddress(process_h, bss_heap_address, bss_heap_size, nro_heap_address + nro_heap_size))) {
|
||||
if (R_SUCCEEDED(mcm_bss.OpenAtAddress(process_h, bss_heap_address, bss_heap_size, mcm_nro.code_memory_address + nro_heap_size))) {
|
||||
break;
|
||||
} else {
|
||||
mcm_nro.Close();
|
||||
|
|
|
@ -219,6 +219,7 @@ void Registration::AddNroToProcess(u64 index, MappedCodeMemory *nro, MappedCodeM
|
|||
target_process->nro_infos[i].rw_size = rw_size;
|
||||
std::copy(build_id, build_id + sizeof(target_process->nro_infos[i].build_id), target_process->nro_infos[i].build_id);
|
||||
target_process->nro_infos[i].in_use = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) {
|
||||
Result rc = 0xF601;
|
||||
|
||||
|
||||
switch ((RoServiceCmd)cmd_id) {
|
||||
case Ro_Cmd_LoadNro:
|
||||
rc = WrapIpcCommandImpl<&RelocatableObjectsService::load_nro>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
|
@ -29,6 +29,7 @@ Result RelocatableObjectsService::dispatch(IpcParsedCommand &r, IpcCommand &out_
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -92,6 +93,7 @@ std::tuple<Result> RelocatableObjectsService::load_nrr(PidDescriptor pid_desc, u
|
|||
Result rc;
|
||||
Registration::Process *target_proc = NULL;
|
||||
MappedCodeMemory nrr_info = {0};
|
||||
|
||||
if (!this->has_initialized || this->process_id != pid_desc.pid) {
|
||||
rc = 0xAE09;
|
||||
goto LOAD_NRR_END;
|
||||
|
@ -115,7 +117,7 @@ std::tuple<Result> RelocatableObjectsService::load_nrr(PidDescriptor pid_desc, u
|
|||
if (R_FAILED((rc = nrr_info.Open(this->process_handle, target_proc->is_64_bit_addspace, nrr_address, nrr_size)))) {
|
||||
goto LOAD_NRR_END;
|
||||
}
|
||||
|
||||
|
||||
if (R_FAILED((rc = nrr_info.Map()))) {
|
||||
goto LOAD_NRR_END;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue