From 6d2699b38d95db79ab0fa76729f6e4e62443c70c Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 4 Oct 2018 18:44:45 -0400 Subject: [PATCH] Added pmshellGetApplicationPid(). --- nx/include/switch/services/pm.h | 3 ++- nx/source/services/pm.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/services/pm.h b/nx/include/switch/services/pm.h index a55c7e73..79fb36e2 100644 --- a/nx/include/switch/services/pm.h +++ b/nx/include/switch/services/pm.h @@ -27,4 +27,5 @@ Result pmdmntEnableDebugForApplication(Handle* handle_out); Result pminfoGetTitleId(u64* title_id_out, u64 pid); Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid); -Result pmshellTerminateProcessByTitleId(u64 titleID); \ No newline at end of file +Result pmshellTerminateProcessByTitleId(u64 titleID); +Result pmshellGetApplicationPid(u64* pid_out); diff --git a/nx/source/services/pm.c b/nx/source/services/pm.c index d23c541a..a59eb4f7 100644 --- a/nx/source/services/pm.c +++ b/nx/source/services/pm.c @@ -348,3 +348,39 @@ Result pmshellTerminateProcessByTitleId(u64 titleID) { return rc; } + +Result pmshellGetApplicationPid(u64* pid_out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = kernelAbove500() ? 6 : 8; + + Result rc = serviceIpcDispatch(&g_pmshellSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u64 pid; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + *pid_out = resp->pid; + } + } + + return rc; +}