From 8e1ba23b83cd871bb8205b92e2915fce1d9b452a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 9 Dec 2018 03:24:25 -0800 Subject: [PATCH] pm: Add remaining pm:dmnt services --- nx/include/switch/services/pm.h | 2 + nx/source/services/pm.c | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/nx/include/switch/services/pm.h b/nx/include/switch/services/pm.h index 79fb36e2..afd19d69 100644 --- a/nx/include/switch/services/pm.h +++ b/nx/include/switch/services/pm.h @@ -18,11 +18,13 @@ void pminfoExit(void); Result pmshellInitialize(void); void pmshellExit(void); +Result pmdmntGetDebugProcesses(u32* out_count, u64* out_pids, size_t max_pids); Result pmdmntStartProcess(u64 pid); Result pmdmntGetTitlePid(u64* pid_out, u64 title_id); Result pmdmntEnableDebugForTitleId(Handle* handle_out, u64 title_id); Result pmdmntGetApplicationPid(u64* pid_out); Result pmdmntEnableDebugForApplication(Handle* handle_out); +Result pmdmntDisableDebug(void); Result pminfoGetTitleId(u64* title_id_out, u64 pid); diff --git a/nx/source/services/pm.c b/nx/source/services/pm.c index a59eb4f7..cabfee9e 100644 --- a/nx/source/services/pm.c +++ b/nx/source/services/pm.c @@ -61,6 +61,43 @@ void pmshellExit(void) } } +Result pmdmntGetDebugProcesses(u32* out_count, u64* out_pids, size_t max_pids) { + IpcCommand c; + ipcInitialize(&c); + ipcAddRecvBuffer(&c, out_pids, sizeof(*out_pids) * max_pids, BufferType_Normal); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = kernelAbove500() ? 0 : 1; + + Result rc = serviceIpcDispatch(&g_pmdmntSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u32 out_count; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + if (out_count) *out_count = resp->out_count; + } + } + + return rc; +} + Result pmdmntStartProcess(u64 pid) { IpcCommand c; ipcInitialize(&c); @@ -276,6 +313,39 @@ Result pmdmntEnableDebugForApplication(Handle* handle_out) { return rc; } +Result pmdmntDisableDebug(void) { + if (!kernelAbove600()) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 6; + + Result rc = serviceIpcDispatch(&g_pmdmntSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid) { IpcCommand c; ipcInitialize(&c);