diff --git a/stratosphere/pm/source/pm_info.cpp b/stratosphere/pm/source/pm_info.cpp new file mode 100644 index 000000000..6b9dfe60d --- /dev/null +++ b/stratosphere/pm/source/pm_info.cpp @@ -0,0 +1,31 @@ +#include +#include "pm_registration.hpp" +#include "pm_info.hpp" + +Result InformationService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) { + Result rc = 0xF601; + switch ((InformationCmd)cmd_id) { + case Information_Cmd_GetTitleId: + rc = WrapIpcCommandImpl<&InformationService::get_title_id>(this, r, out_c, pointer_buffer, pointer_buffer_size); + break; + default: + break; + } + return rc; +} + +Result InformationService::handle_deferred() { + /* This service is never deferrable. */ + return 0; +} + +std::tuple InformationService::get_title_id(u64 pid) { + Registration::AutoProcessListLock auto_lock; + + Registration::Process *proc = Registration::GetProcess(pid); + if (proc != NULL) { + return {0x0, proc->tid_sid.title_id}; + } else { + return {0x20F, 0x0}; + } +} diff --git a/stratosphere/pm/source/pm_info.hpp b/stratosphere/pm/source/pm_info.hpp new file mode 100644 index 000000000..ee8618220 --- /dev/null +++ b/stratosphere/pm/source/pm_info.hpp @@ -0,0 +1,17 @@ +#pragma once +#include +#include + +enum InformationCmd { + Information_Cmd_GetTitleId = 0, +}; + +class InformationService : IServiceObject { + public: + virtual Result dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size); + virtual Result handle_deferred(); + + private: + /* Actual commands. */ + std::tuple get_title_id(u64 pid); +}; \ No newline at end of file diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index ce7edd9b0..910cb41ac 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -7,6 +7,8 @@ #include #include "pm_boot_mode.hpp" +#include "pm_info.hpp" +#include "pm_shell.hpp" #include "pm_process_track.hpp" #include "pm_registration.hpp" @@ -107,7 +109,9 @@ int main(int argc, char **argv) WaitableManager *server_manager = new WaitableManager(U64_MAX); /* TODO: Create services. */ - server_manager->add_waitable(new ServiceServer("pm:bm", 4)); + server_manager->add_waitable(new ServiceServer("pm:shell", 3)); + server_manager->add_waitable(new ServiceServer("pm:bm", 5)); + server_manager->add_waitable(new ServiceServer("pm:info", 1)); /* Loop forever, servicing our services. */ server_manager->process(); diff --git a/stratosphere/pm/source/pm_shell.cpp b/stratosphere/pm/source/pm_shell.cpp index 84ede2dfa..364fb8892 100644 --- a/stratosphere/pm/source/pm_shell.cpp +++ b/stratosphere/pm/source/pm_shell.cpp @@ -51,7 +51,7 @@ Result ShellService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id rc = WrapIpcCommandImpl<&ShellService::get_process_event_type>(this, r, out_c, pointer_buffer, pointer_buffer_size); break; case Shell_Cmd_FinalizeExitedProcess: - rc = WrapIpcCommandImpl<&ShellService::finalize_dead_process>(this, r, out_c, pointer_buffer, pointer_buffer_size); + rc = WrapIpcCommandImpl<&ShellService::finalize_exited_process>(this, r, out_c, pointer_buffer, pointer_buffer_size); break; case Shell_Cmd_ClearProcessNotificationFlag: rc = WrapIpcCommandImpl<&ShellService::clear_process_notification_flag>(this, r, out_c, pointer_buffer, pointer_buffer_size); @@ -77,13 +77,13 @@ Result ShellService::handle_deferred() { return 0; } -std::tuple launch_process(u64 launch_flags, Registration::TidSid tid_sid) { +std::tuple ShellService::launch_process(u64 launch_flags, Registration::TidSid tid_sid) { u64 pid = 0; Result rc = Registration::LaunchProcessByTidSid(tid_sid, launch_flags, &pid); return {rc, pid}; } -std::tuple terminate_process_id(u64 pid) { +std::tuple ShellService::terminate_process_id(u64 pid) { Registration::AutoProcessListLock auto_lock; Registration::Process *proc = Registration::GetProcess(pid); @@ -94,7 +94,7 @@ std::tuple terminate_process_id(u64 pid) { } } -std::tuple terminate_title_id(u64 tid) { +std::tuple ShellService::terminate_title_id(u64 tid) { Registration::AutoProcessListLock auto_lock; Registration::Process *proc = Registration::GetProcessByTitleId(tid); @@ -105,17 +105,17 @@ std::tuple terminate_title_id(u64 tid) { } } -std::tuple get_process_wait_event() { +std::tuple ShellService::get_process_wait_event() { return {0x0, Registration::GetProcessEventHandle()}; } -std::tuple get_process_event_type() { +std::tuple ShellService::get_process_event_type() { u64 type, pid; Registration::GetProcessEventType(&pid, &type); return {0x0, type, pid}; } -std::tuple finalize_exited_process(u64 pid) { +std::tuple ShellService::finalize_exited_process(u64 pid) { Registration::AutoProcessListLock auto_lock; Registration::Process *proc = Registration::GetProcess(pid); @@ -129,7 +129,7 @@ std::tuple finalize_exited_process(u64 pid) { } } -std::tuple clear_process_notification_flag(u64 pid) { +std::tuple ShellService::clear_process_notification_flag(u64 pid) { Registration::AutoProcessListLock auto_lock; Registration::Process *proc = Registration::GetProcess(pid); @@ -141,7 +141,7 @@ std::tuple clear_process_notification_flag(u64 pid) { } } -std::tuple notify_boot_finished() { +std::tuple ShellService::notify_boot_finished() { u64 boot2_pid; if (!g_has_boot_finished) { g_has_boot_finished = true; @@ -150,7 +150,7 @@ std::tuple notify_boot_finished() { return {0}; } -std::tuple get_application_process_id() { +std::tuple ShellService::get_application_process_id() { Registration::AutoProcessListLock auto_lock; Registration::Process *app_proc; @@ -160,7 +160,7 @@ std::tuple get_application_process_id() { return {0x20F, 0}; } -std::tuple boost_system_memory_resource_limit() { +std::tuple ShellService::boost_system_memory_resource_limit() { if (!kernelAbove400()) { return {0xF601}; } diff --git a/stratosphere/pm/source/pm_shell.hpp b/stratosphere/pm/source/pm_shell.hpp index b7627e08b..e4a85898b 100644 --- a/stratosphere/pm/source/pm_shell.hpp +++ b/stratosphere/pm/source/pm_shell.hpp @@ -42,7 +42,7 @@ class ShellService : IServiceObject { std::tuple terminate_title_id(u64 tid); std::tuple get_process_wait_event(); std::tuple get_process_event_type(); - std::tuple finalize_dead_process(u64 pid); + std::tuple finalize_exited_process(u64 pid); std::tuple clear_process_notification_flag(u64 pid); std::tuple notify_boot_finished(); std::tuple get_application_process_id();