From 139a93040741ec78a4ee13035eab1b1b705bdcf8 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> Date: Sun, 15 Jan 2023 16:16:24 -0500 Subject: [PATCH] Implement missing service calls in `pm` (#4210) * Implement `GetTitleId` Fixes #2516 * Null check + Proper result code * Better comment * Implement `GetApplicationProcessId` * Add TODOs * Update Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs Co-authored-by: Ac_K * Update Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs Co-authored-by: Ac_K * Remove new function from KernelStatic Co-authored-by: Ac_K --- Ryujinx.HLE/HOS/Kernel/KernelStatic.cs | 5 ++--- .../HOS/Services/Pm/IDebugMonitorInterface.cs | 18 +++++++++++++++ .../HOS/Services/Pm/IInformationInterface.cs | 22 ++++++++++++++++++- Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs | 17 ++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs diff --git a/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs b/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs index 18cf212a9e..21d7d90c4e 100644 --- a/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs +++ b/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs @@ -1,5 +1,4 @@ -using Ryujinx.HLE.HOS.Kernel.Common; -using Ryujinx.HLE.HOS.Kernel.Memory; +using Ryujinx.HLE.HOS.Kernel.Memory; using Ryujinx.HLE.HOS.Kernel.Process; using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.Horizon.Common; @@ -71,4 +70,4 @@ namespace Ryujinx.HLE.HOS.Kernel return null; } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs b/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs index c9c6354df0..8d4934fabb 100644 --- a/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs @@ -10,6 +10,24 @@ namespace Ryujinx.HLE.HOS.Services.Pm { public IDebugMonitorInterface(ServiceCtx context) { } + [CommandHipc(4)] + // GetProgramId() -> sf::Out out_process_id + public ResultCode GetApplicationProcessId(ServiceCtx context) + { + // TODO: Not correct as it shouldn't be directly using kernel objects here + foreach (KProcess process in context.Device.System.KernelContext.Processes.Values) + { + if (process.IsApplication) + { + context.ResponseData.Write(process.Pid); + + return ResultCode.Success; + } + } + + return ResultCode.ProcessNotFound; + } + [CommandHipc(65000)] // AtmosphereGetProcessInfo(os::ProcessId process_id) -> sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status public ResultCode GetProcessInfo(ServiceCtx context) diff --git a/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs b/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs index 0be85c4f61..e3ce6d2af2 100644 --- a/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Pm/IInformationInterface.cs @@ -1,8 +1,28 @@ -namespace Ryujinx.HLE.HOS.Services.Pm +using Ryujinx.HLE.HOS.Kernel; +using Ryujinx.HLE.HOS.Kernel.Process; + +namespace Ryujinx.HLE.HOS.Services.Pm { [Service("pm:info")] class IInformationInterface : IpcService { public IInformationInterface(ServiceCtx context) { } + + [CommandHipc(0)] + // GetProgramId(os::ProcessId process_id) -> sf::Out out + public ResultCode GetProgramId(ServiceCtx context) + { + ulong pid = context.RequestData.ReadUInt64(); + + // TODO: Not correct as it shouldn't be directly using kernel objects here + if (context.Device.System.KernelContext.Processes.TryGetValue(pid, out KProcess process)) + { + context.ResponseData.Write(process.TitleId); + + return ResultCode.Success; + } + + return ResultCode.ProcessNotFound; + } } } \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs b/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs new file mode 100644 index 0000000000..92b5925e4d --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Pm/ResultCode.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.HLE.HOS.Services.Pm +{ + enum ResultCode + { + ModuleId = 15, + ErrorCodeShift = 9, + + Success = 0, + + ProcessNotFound = (1 << ErrorCodeShift) | ModuleId, + AlreadyStarted = (2 << ErrorCodeShift) | ModuleId, + NotTerminated = (3 << ErrorCodeShift) | ModuleId, + DebugHookInUse = (4 << ErrorCodeShift) | ModuleId, + ApplicationRunning = (5 << ErrorCodeShift) | ModuleId, + InvalidSize = (6 << ErrorCodeShift) | ModuleId, + } +} \ No newline at end of file