From 0e11788e43c3dd37213477228e74d9580bad3584 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 23 Apr 2018 13:33:56 -0600 Subject: [PATCH] Stratosphere: Make TODOs for Loader::CreateProcess(). --- stratosphere/loader/source/ldr_npdm.cpp | 7 +++ stratosphere/loader/source/ldr_npdm.hpp | 1 + .../loader/source/ldr_process_creation.cpp | 54 ++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/stratosphere/loader/source/ldr_npdm.cpp b/stratosphere/loader/source/ldr_npdm.cpp index c2b80e295..881035c79 100644 --- a/stratosphere/loader/source/ldr_npdm.cpp +++ b/stratosphere/loader/source/ldr_npdm.cpp @@ -6,6 +6,13 @@ static NpdmUtils::NpdmCache g_npdm_cache = {0}; +Result NpdmUtils::LoadNpdmFromCache(u64 tid, NpdmInfo *out) { + if (g_npdm_cache.info.title_id != tid) { + return LoadNpdm(tid, out); + } + *out = g_npdm_cache.info; + return 0; +} Result NpdmUtils::LoadNpdm(u64 tid, NpdmInfo *out) { Result rc; diff --git a/stratosphere/loader/source/ldr_npdm.hpp b/stratosphere/loader/source/ldr_npdm.hpp index aebed3dab..c132b76af 100644 --- a/stratosphere/loader/source/ldr_npdm.hpp +++ b/stratosphere/loader/source/ldr_npdm.hpp @@ -78,4 +78,5 @@ class NpdmUtils { static_assert(sizeof(NpdmAci0) == 0x40, "Incorrectly defined NpdmAci0!"); static Result LoadNpdm(u64 tid, NpdmInfo *out); + static Result LoadNpdmFromCache(u64 tid, NpdmInfo *out); }; \ No newline at end of file diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index c8d6e29a8..562dff886 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -7,6 +7,56 @@ #include "ldr_npdm.hpp" Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nca_path, LaunchQueue::LaunchItem *launch_item, u64 flags, Handle reslimit_h) { - /* TODO */ - return 0xA09; + NpdmUtils::NpdmInfo info; + Registration::Process *target_process; + Result rc; + + target_process = Registration::get_process(index); + if (target_process == NULL) { + return 0x1009; + } + + rc = ContentManagement::MountCodeForTidSid(&target_process->tid_sid); + if (R_FAILED(rc)) { + return rc; + } + + rc = NpdmUtils::LoadNpdmFromCache(target_process->tid_sid.title_id, &info); + if (R_FAILED(rc)) { + goto CREATE_PROCESS_END; + } + + if (info.aci0->title_id < info.acid->title_id_range_min || info.aci0->title_id > info.acid->title_id_range_max) { + rc = 0x1209; + goto CREATE_PROCESS_END; + } + + /* TODO: Parse and verify ACI0 kernel caps vs ACID kernel caps. */ + + /* TODO: Read in all NSO headers, see what NSOs are present. */ + + /* TODO: Validate that the set of NSOs to be loaded is correct. */ + + /* TODO: Create the CreateProcessInfo. */ + + /* TODO: Figure out where NSOs will be mapped, and how much space they (and arguments) will take up. */ + + /* TODO: Call svcCreateProcessInfo(). */ + + /* TODO: For each NSO, call svcMapProcessMemory, load the NSO into memory there (validating it), and then svcUnmapProcessMemory. */ + + /* TODO: svcSetProcessMemoryPermission for each memory segment in the new process. */ + + /* TODO: Map and load arguments to the process, if relevant. */ + + /* TODO: Update the list of registered processes with the new process. */ + + rc = 0; +CREATE_PROCESS_END: + if (R_SUCCEEDED(rc)) { + rc = ContentManagement::UnmountCode(); + } else { + ContentManagement::UnmountCode(); + } + return rc; }