From b8ad7125ca60fb78a3376a16b6d3cbef5e7958c7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 18 Apr 2018 03:52:19 -0600 Subject: [PATCH] Stratosphere: Skeleton more of ldr:dmnt->Dispatch() --- stratosphere/loader/source/iserviceobject.hpp | 2 +- .../loader/source/ldr_debug_monitor.cpp | 48 ++++++++++++++++++- .../loader/source/ldr_debug_monitor.hpp | 8 +++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/stratosphere/loader/source/iserviceobject.hpp b/stratosphere/loader/source/iserviceobject.hpp index 5817c2aec..61f7d65f0 100644 --- a/stratosphere/loader/source/iserviceobject.hpp +++ b/stratosphere/loader/source/iserviceobject.hpp @@ -3,5 +3,5 @@ class IServiceObject { public: - virtual void dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count); + virtual Result dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count); }; \ No newline at end of file diff --git a/stratosphere/loader/source/ldr_debug_monitor.cpp b/stratosphere/loader/source/ldr_debug_monitor.cpp index 379af82c2..9d24cb2ab 100644 --- a/stratosphere/loader/source/ldr_debug_monitor.cpp +++ b/stratosphere/loader/source/ldr_debug_monitor.cpp @@ -2,8 +2,52 @@ #include "ldr_debug_monitor.hpp" #include "ldr_launch_queue.hpp" -void DebugMonitorService::dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count) { - /* TODO */ +Result DebugMonitorService::dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count) { + + Result rc = 0xF601; + + /* TODO: Prepare SFCO. */ + + switch ((DebugMonitorServiceCmd)cmd_id) { + case Cmd_AddTitleToLaunchQueue: + /* Validate arguments. */ + if (in_rawdata_size < 0x10 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 1) { + break; + } + + rc = add_title_to_launch_queue(((u64 *)in_rawdata)[0], (const char *)r->Statics[0], r->StaticSizes[0]); + + *out_raw_data_count = 0; + + break; + case Cmd_ClearLaunchQueue: + if (r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 0) { + break; + } + + rc = clear_launch_queue(); + *out_raw_data_count = 0; + + break; + case Cmd_GetNsoInfo: + if (in_rawdata_size < 0x8 || r->HasPid || r->NumHandles != 0 || r->NumBuffers != 0 || r->NumStatics != 1) { + break; + } + + + rc = get_nso_info(((u64 *)in_rawdata)[0], r->Statics[0], r->StaticSizes[0], out_rawdata); + + if (R_SUCCEEDED(rc)) { + *out_raw_data_count = 4; + } else { + *out_raw_data_count = 0; + } + + break; + default: + break; + } + return rc; } Result DebugMonitorService::add_title_to_launch_queue(u64 tid, const char *args, size_t args_size) { diff --git a/stratosphere/loader/source/ldr_debug_monitor.hpp b/stratosphere/loader/source/ldr_debug_monitor.hpp index 3e278f2f9..01ae19f9f 100644 --- a/stratosphere/loader/source/ldr_debug_monitor.hpp +++ b/stratosphere/loader/source/ldr_debug_monitor.hpp @@ -3,9 +3,15 @@ #include "iserviceobject.hpp" +enum DebugMonitorServiceCmd { + Cmd_AddTitleToLaunchQueue = 0, + Cmd_ClearLaunchQueue = 1, + Cmd_GetNsoInfo = 2 +}; + class DebugMonitorService : IServiceObject { public: - void dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count); + Result dispatch(IpcParsedCommand *r, u32 *cmd_buf, u32 cmd_id, u32 *in_rawdata, u32 in_rawdata_size, u32 *out_rawdata, u32 *out_raw_data_count); private: /* Actual commands. */