service: pass load result through process creation

This commit is contained in:
Liam 2024-02-25 21:03:41 -05:00
parent b199f77abb
commit 89e00dff57
4 changed files with 49 additions and 36 deletions

View File

@ -37,7 +37,29 @@ FileSys::StorageId GetStorageIdForFrontendSlot(
} }
std::unique_ptr<Process> CreateProcessImpl(std::unique_ptr<Loader::AppLoader>& out_loader, std::unique_ptr<Process> CreateProcessImpl(std::unique_ptr<Loader::AppLoader>& out_loader,
Core::System& system, u64 program_id, Loader::ResultStatus& out_load_result,
Core::System& system, FileSys::VirtualFile file,
u64 program_id, u64 program_index) {
// Get the appropriate loader to parse this NCA.
out_loader = Loader::GetLoader(system, file, program_id, program_index);
// Ensure we have a loader which can parse the NCA.
if (!out_loader) {
return nullptr;
}
// Try to load the process.
auto process = std::make_unique<Process>(system);
if (process->Initialize(*out_loader, out_load_result)) {
return process;
}
return nullptr;
}
} // Anonymous namespace
std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
u8 minimum_key_generation, u8 maximum_key_generation) { u8 minimum_key_generation, u8 maximum_key_generation) {
// Attempt to load program NCA. // Attempt to load program NCA.
FileSys::VirtualFile nca_raw{}; FileSys::VirtualFile nca_raw{};
@ -63,43 +85,24 @@ std::unique_ptr<Process> CreateProcessImpl(std::unique_ptr<Loader::AppLoader>& o
} }
} }
// Get the appropriate loader to parse this NCA.
out_loader = Loader::GetLoader(system, nca_raw, program_id, 0);
// Ensure we have a loader which can parse the NCA.
if (!out_loader) {
return nullptr;
}
// Try to load the process.
auto process = std::make_unique<Process>(system);
if (process->Initialize(*out_loader)) {
return process;
}
return nullptr;
}
} // Anonymous namespace
std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
u8 minimum_key_generation, u8 maximum_key_generation) {
std::unique_ptr<Loader::AppLoader> loader; std::unique_ptr<Loader::AppLoader> loader;
return CreateProcessImpl(loader, system, program_id, minimum_key_generation, Loader::ResultStatus status;
maximum_key_generation); return CreateProcessImpl(loader, status, system, nca_raw, program_id, 0);
} }
std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control, std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control,
Core::System& system, u64 application_id, std::unique_ptr<Loader::AppLoader>& out_loader,
u64 program_id) { Loader::ResultStatus& out_load_result,
std::unique_ptr<Loader::AppLoader> loader; Core::System& system, FileSys::VirtualFile file,
auto process = CreateProcessImpl(loader, system, program_id, 0, 0); u64 program_id, u64 program_index) {
auto process =
CreateProcessImpl(out_loader, out_load_result, system, file, program_id, program_index);
if (!process) { if (!process) {
return nullptr; return nullptr;
} }
FileSys::NACP nacp; FileSys::NACP nacp;
if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success) { if (out_loader->ReadControlData(nacp) == Loader::ResultStatus::Success) {
out_control = nacp.GetRawBytes(); out_control = nacp.GetRawBytes();
} else { } else {
out_control.resize(sizeof(FileSys::RawNACP)); out_control.resize(sizeof(FileSys::RawNACP));
@ -107,7 +110,7 @@ std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control,
auto& storage = system.GetContentProviderUnion(); auto& storage = system.GetContentProviderUnion();
Service::Glue::ApplicationLaunchProperty launch{}; Service::Glue::ApplicationLaunchProperty launch{};
launch.title_id = program_id; launch.title_id = process->GetProgramId();
FileSys::PatchManager pm{launch.title_id, system.GetFileSystemController(), storage}; FileSys::PatchManager pm{launch.title_id, system.GetFileSystemController(), storage};
launch.version = pm.GetGameVersion().value_or(0); launch.version = pm.GetGameVersion().value_or(0);

View File

@ -7,11 +7,17 @@
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/vfs/vfs_types.h"
namespace Core { namespace Core {
class System; class System;
} }
namespace Loader {
class AppLoader;
enum class ResultStatus : u16;
} // namespace Loader
namespace Service { namespace Service {
class Process; class Process;
} }
@ -21,7 +27,9 @@ namespace Service::AM {
std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id, std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
u8 minimum_key_generation, u8 maximum_key_generation); u8 minimum_key_generation, u8 maximum_key_generation);
std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control, std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control,
Core::System& system, u64 application_id, std::unique_ptr<Loader::AppLoader>& out_loader,
u64 program_id); Loader::ResultStatus& out_load_result,
Core::System& system, FileSys::VirtualFile file,
u64 program_id, u64 program_index);
} // namespace Service::AM } // namespace Service::AM

View File

@ -18,7 +18,7 @@ Process::~Process() {
this->Finalize(); this->Finalize();
} }
bool Process::Initialize(Loader::AppLoader& loader) { bool Process::Initialize(Loader::AppLoader& loader, Loader::ResultStatus& out_load_result) {
// First, ensure we are not holding another process. // First, ensure we are not holding another process.
this->Finalize(); this->Finalize();
@ -33,6 +33,7 @@ bool Process::Initialize(Loader::AppLoader& loader) {
// Insert process modules into memory. // Insert process modules into memory.
const auto [load_result, load_parameters] = loader.Load(*process, m_system); const auto [load_result, load_parameters] = loader.Load(*process, m_system);
out_load_result = load_result;
// Ensure loading was successful. // Ensure loading was successful.
if (load_result != Loader::ResultStatus::Success) { if (load_result != Loader::ResultStatus::Success) {

View File

@ -11,7 +11,8 @@ class System;
namespace Loader { namespace Loader {
class AppLoader; class AppLoader;
} enum class ResultStatus : u16;
} // namespace Loader
namespace Kernel { namespace Kernel {
class KProcess; class KProcess;
@ -24,7 +25,7 @@ public:
explicit Process(Core::System& system); explicit Process(Core::System& system);
~Process(); ~Process();
bool Initialize(Loader::AppLoader& loader); bool Initialize(Loader::AppLoader& loader, Loader::ResultStatus& out_load_result);
void Finalize(); void Finalize();
bool Run(); bool Run();