diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp index f9e00fdfc..7150fa38d 100644 --- a/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp @@ -202,6 +202,7 @@ T GetValueFromIpcParsedCommand(IpcParsedCommand& r, IpcCommand& out_c, u8 *point } else if constexpr (is_ipc_handle::value) { return r.Handles[h_index++]; } else if constexpr (std::is_same::value) { + cur_rawdata_index += sizeof(u64) / sizeof(u32); return PidDescriptor(r.Pid); } else { cur_rawdata_index += size_in_raw_data::value / sizeof(u32); diff --git a/stratosphere/loader/loader.json b/stratosphere/loader/loader.json index 71da27f7d..27544a507 100644 --- a/stratosphere/loader/loader.json +++ b/stratosphere/loader/loader.json @@ -59,6 +59,8 @@ "svcSetProcessMemoryPermission" : "0x73", "svcMapProcessMemory" : "0x74", "svcUnmapProcessMemory" : "0x75", + "svcMapProcessCodeMemory" : "0x77", + "svcUnmapProcessCodeMemory" : "0x78", "svcCreateProcess" : "0x79" } } diff --git a/stratosphere/loader/source/ldr_map.cpp b/stratosphere/loader/source/ldr_map.cpp index 7ac554e16..12e3dc527 100644 --- a/stratosphere/loader/source/ldr_map.cpp +++ b/stratosphere/loader/source/ldr_map.cpp @@ -1,4 +1,5 @@ #include +#include #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); diff --git a/stratosphere/loader/source/ldr_nro.cpp b/stratosphere/loader/source/ldr_nro.cpp index d30cc1f5f..45575f78a 100644 --- a/stratosphere/loader/source/ldr_nro.cpp +++ b/stratosphere/loader/source/ldr_nro.cpp @@ -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(); diff --git a/stratosphere/loader/source/ldr_registration.cpp b/stratosphere/loader/source/ldr_registration.cpp index 90fe3a81a..729a2c3ad 100644 --- a/stratosphere/loader/source/ldr_registration.cpp +++ b/stratosphere/loader/source/ldr_registration.cpp @@ -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; } } } diff --git a/stratosphere/loader/source/ldr_ro_service.cpp b/stratosphere/loader/source/ldr_ro_service.cpp index 959467c0f..1ee023b5c 100644 --- a/stratosphere/loader/source/ldr_ro_service.cpp +++ b/stratosphere/loader/source/ldr_ro_service.cpp @@ -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 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 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; }