Stratosphere: Skeleton create process up through the ProcessCreation::CreateProcess() call

This commit is contained in:
Michael Scire 2018-04-21 19:52:49 -06:00
parent 878d68f7e0
commit 6a51ce25b3
8 changed files with 75 additions and 5 deletions

View file

@ -71,3 +71,12 @@ void LaunchQueue::clear() {
g_launch_queue[i].tid = 0; g_launch_queue[i].tid = 0;
} }
} }
LaunchQueue::LaunchItem *LaunchQueue::get_item(u64 tid) {
int idx;
if ((idx = get_index(tid)) == LAUNCH_QUEUE_FULL) {
return NULL;
}
return &g_launch_queue[idx];
}

View file

@ -14,6 +14,8 @@ class LaunchQueue {
char args[LAUNCH_QUEUE_ARG_SIZE_MAX]; char args[LAUNCH_QUEUE_ARG_SIZE_MAX];
}; };
static LaunchQueue::LaunchItem *get_item(u64 tid);
static Result add(u64 tid, const char *args, u64 arg_size); static Result add(u64 tid, const char *args, u64 arg_size);
static Result add_item(const LaunchItem *item); static Result add_item(const LaunchItem *item);
static Result add_copy(u64 tid_base, u64 new_tid); static Result add_copy(u64 tid_base, u64 new_tid);

View file

@ -0,0 +1,13 @@
#pragma once
#include <switch.h>
#include "ldr_process_creation.hpp"
#include "ldr_registration.hpp"
#include "ldr_launch_queue.hpp"
#include "ldr_content_management.hpp"
#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;
}

View file

@ -0,0 +1,12 @@
#pragma once
#include <switch.h>
#include "ldr_registration.hpp"
#include "ldr_launch_queue.hpp"
/* Utilities for Process Creation, for Loader. */
class ProcessCreation {
public:
static Result CreateProcess(Handle *out_process_h, u64 index, char *nca_path, LaunchQueue::LaunchItem *launch_item, u64 flags, Handle reslimit_h);
};

View file

@ -28,10 +28,30 @@ Result ProcessManagerService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u
return rc; return rc;
} }
std::tuple<Result, MovedHandle> ProcessManagerService::create_process(u64 flags, u64 title_id, CopiedHandle reslimit_h) { std::tuple<Result, MovedHandle> ProcessManagerService::create_process(u64 flags, u64 index, CopiedHandle reslimit_h) {
/* TODO */ Result rc;
fprintf(stderr, "CreateProcess(%016lx, %016lx, %08x);\n", flags, title_id, reslimit_h.handle); Registration::TidSid tid_sid;
return std::make_tuple(0xF601, MovedHandle{0x00}); LaunchQueue::LaunchItem *launch_item;
char nca_path[FS_MAX_PATH] = {0};
Handle process_h = 0;
fprintf(stderr, "CreateProcess(%016lx, %016lx, %08x);\n", flags, index, reslimit_h.handle);
rc = Registration::get_registered_tid_sid(index, &tid_sid);
if (R_FAILED(rc)) {
std::make_tuple(rc, MovedHandle{process_h});
}
rc = ContentManagement::GetContentPathForTidSid(nca_path, &tid_sid);
if (R_FAILED(rc)) {
std::make_tuple(rc, MovedHandle{process_h});
}
launch_item = LaunchQueue::get_item(tid_sid.title_id);
rc = ProcessCreation::CreateProcess(&process_h, index, nca_path, launch_item, flags, reslimit_h.handle);
return std::make_tuple(rc, MovedHandle{process_h});
} }
std::tuple<Result> ProcessManagerService::get_program_info(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info) { std::tuple<Result> ProcessManagerService::get_program_info(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info) {

View file

@ -3,6 +3,7 @@
#include "iserviceobject.hpp" #include "iserviceobject.hpp"
#include "ldr_registration.hpp" #include "ldr_registration.hpp"
#include "ldr_process_creation.hpp"
enum ProcessManagerServiceCmd { enum ProcessManagerServiceCmd {
Pm_Cmd_CreateProcess = 0, Pm_Cmd_CreateProcess = 0,
@ -32,7 +33,7 @@ class ProcessManagerService : IServiceObject {
private: private:
/* Actual commands. */ /* Actual commands. */
std::tuple<Result, MovedHandle> create_process(u64 flags, u64 title_id, CopiedHandle reslimit_h); std::tuple<Result, MovedHandle> create_process(u64 flags, u64 index, CopiedHandle reslimit_h);
std::tuple<Result> get_program_info(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info); std::tuple<Result> get_program_info(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info);
std::tuple<Result, u64> register_title(Registration::TidSid tid_sid); std::tuple<Result, u64> register_title(Registration::TidSid tid_sid);
std::tuple<Result> unregister_title(u64 index); std::tuple<Result> unregister_title(u64 index);

View file

@ -63,6 +63,18 @@ bool Registration::unregister_index(u64 index) {
return true; return true;
} }
Result Registration::get_registered_tid_sid(u64 index, Registration::TidSid *out) {
Registration::Process *target_process = get_process(index);
if (target_process == NULL) {
return 0x1009;
}
*out = target_process->tid_sid;
return 0;
}
void Registration::set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min) { void Registration::set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min) {
Registration::Process *target_process = get_process(index); Registration::Process *target_process = get_process(index);
if (target_process == NULL) { if (target_process == NULL) {

View file

@ -41,6 +41,7 @@ class Registration {
static Registration::Process *get_free_process(); static Registration::Process *get_free_process();
static Registration::Process *get_process(u64 index); static Registration::Process *get_process(u64 index);
static Registration::Process *get_process_by_process_id(u64 pid); static Registration::Process *get_process_by_process_id(u64 pid);
static Result get_registered_tid_sid(u64 index, Registration::TidSid *out);
static bool register_tid_sid(const TidSid *tid_sid, u64 *out_index); static bool register_tid_sid(const TidSid *tid_sid, u64 *out_index);
static bool unregister_index(u64 index); static bool unregister_index(u64 index);
static void set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min); static void set_process_id_and_tid_min(u64 index, u64 process_id, u64 tid_min);