1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-22 20:06:40 +00:00

Stratosphere: Skeleton ldr:pm (RegisterTitle/UnregisterTitle are implemented)

This commit is contained in:
Michael Scire 2018-04-18 23:15:17 -06:00
parent 30e401d125
commit af11f9fdec
6 changed files with 106 additions and 6 deletions

View file

@ -7,6 +7,7 @@
#include "waitablemanager.hpp" #include "waitablemanager.hpp"
#include "serviceserver.hpp" #include "serviceserver.hpp"
#include "ldr_process_manager.hpp"
#include "ldr_debug_monitor.hpp" #include "ldr_debug_monitor.hpp"
#include "ldr_shell.hpp" #include "ldr_shell.hpp"
@ -39,6 +40,7 @@ int main(int argc, char **argv)
WaitableManager *server_manager = new WaitableManager(U64_MAX); WaitableManager *server_manager = new WaitableManager(U64_MAX);
/* Add services to manager. */ /* Add services to manager. */
server_manager->add_waitable(new ServiceServer<ProcessManagerService>("dbg:pm", 1));
server_manager->add_waitable(new ServiceServer<ShellService>("dbg:shel", 3)); server_manager->add_waitable(new ServiceServer<ShellService>("dbg:shel", 3));
server_manager->add_waitable(new ServiceServer<DebugMonitorService>("dbg:dmnt", 2)); server_manager->add_waitable(new ServiceServer<DebugMonitorService>("dbg:dmnt", 2));

View file

@ -0,0 +1,74 @@
#include <switch.h>
#include "ldr_process_manager.hpp"
#include "ldr_registration.hpp"
#include "ldr_launch_queue.hpp"
Result ProcessManagerService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count) {
Result rc = 0xF601;
switch ((ProcessManagerServiceCmd)cmd_id) {
case Pm_Cmd_CreateProcess:
/* TODO */
break;
case Pm_Cmd_GetProgramInfo:
/* TODO */
break;
case Pm_Cmd_RegisterTitle:
/* Validate arguments. */
if (in_rawdata_size < 0x10 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 0) {
break;
}
u64 out_index;
rc = register_title((Registration::TidSid *)in_rawdata, &out_index);
if (R_SUCCEEDED(rc)) {
((u64 *)out_rawdata)[0] = out_index;
*out_raw_data_count = 8;
} else {
((u64 *)out_rawdata)[0] = 0;
*out_raw_data_count = 0;
}
break;
case Pm_Cmd_UnregisterTitle:
/* Validate arguments. */
if (in_rawdata_size < 0x8 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 0) {
break;
}
rc = unregister_title(((u64 *)in_rawdata)[0]);
*out_raw_data_count = 0;
break;
default:
break;
}
return rc;
}
Result ProcessManagerService::create_process() {
/* TODO */
return 0xF601;
}
Result ProcessManagerService::get_program_info() {
/* TODO */
return 0xF601;
}
Result ProcessManagerService::register_title(const Registration::TidSid *tid_sid, u64 *out_index) {
if (Registration::register_tid_sid(tid_sid, out_index)) {
return 0;
} else {
return 0xE09;
}
}
Result ProcessManagerService::unregister_title(u64 index) {
if (Registration::unregister_index(index)) {
return 0;
} else {
return 0x1009;
}
}

View file

@ -0,0 +1,24 @@
#pragma once
#include <switch.h>
#include "iserviceobject.hpp"
#include "ldr_registration.hpp"
enum ProcessManagerServiceCmd {
Pm_Cmd_CreateProcess = 0,
Pm_Cmd_GetProgramInfo = 1,
Pm_Cmd_RegisterTitle = 2,
Pm_Cmd_UnregisterTitle = 3
};
class ProcessManagerService : IServiceObject {
public:
Result dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count);
private:
/* Actual commands. */
Result create_process();
Result get_program_info();
Result register_title(const Registration::TidSid *tid_sid, u64 *out_index);
Result unregister_title(u64 index);
};

View file

@ -6,7 +6,7 @@
static Registration::List g_registration_list = {0}; static Registration::List g_registration_list = {0};
static u64 g_num_registered = 1; static u64 g_num_registered = 1;
Registration::Process *get_free_process() { Registration::Process *Registration::get_free_process() {
unsigned int i; unsigned int i;
for (i = 0; i < REGISTRATION_LIST_MAX; i++) { for (i = 0; i < REGISTRATION_LIST_MAX; i++) {
if (!g_registration_list.processes[i].in_use) { if (!g_registration_list.processes[i].in_use) {
@ -16,7 +16,7 @@ Registration::Process *get_free_process() {
return NULL; return NULL;
} }
Registration::Process *get_process(u64 index) { Registration::Process *Registration::get_process(u64 index) {
unsigned int i; unsigned int i;
for (i = 0; !g_registration_list.processes[i].in_use || g_registration_list.processes[i].index != index; i++) { for (i = 0; !g_registration_list.processes[i].in_use || g_registration_list.processes[i].index != index; i++) {
if (i >= REGISTRATION_LIST_MAX) { if (i >= REGISTRATION_LIST_MAX) {

View file

@ -7,7 +7,7 @@ Result ShellService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_b
Result rc = 0xF601; Result rc = 0xF601;
switch ((ShellServiceCmd)cmd_id) { switch ((ShellServiceCmd)cmd_id) {
case Cmd_AddTitleToLaunchQueue: case Shell_Cmd_AddTitleToLaunchQueue:
/* Validate arguments. */ /* Validate arguments. */
if (in_rawdata_size < 0x10 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 1) { if (in_rawdata_size < 0x10 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 1) {
break; break;
@ -23,7 +23,7 @@ Result ShellService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32 *cmd_b
*out_raw_data_count = 0; *out_raw_data_count = 0;
break; break;
case Cmd_ClearLaunchQueue: case Shell_Cmd_ClearLaunchQueue:
if (r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 0) { if (r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 0) {
break; break;
} }

View file

@ -4,8 +4,8 @@
#include "iserviceobject.hpp" #include "iserviceobject.hpp"
enum ShellServiceCmd { enum ShellServiceCmd {
Cmd_AddTitleToLaunchQueue = 0, Shell_Cmd_AddTitleToLaunchQueue = 0,
Cmd_ClearLaunchQueue = 1 Shell_Cmd_ClearLaunchQueue = 1
}; };
class ShellService : IServiceObject { class ShellService : IServiceObject {