From 8091db89314eac701443c77d6b7ffd32daa4aaf2 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 12 Apr 2018 02:52:49 -0400 Subject: [PATCH] Added FsStorageId. Added pmshell init/exit and pmshellLaunchProcess. --- nx/include/switch/services/fs.h | 10 +++++ nx/include/switch/services/pm.h | 6 +++ nx/source/services/pm.c | 65 +++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 71eb8619..56e1ac22 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -94,6 +94,16 @@ typedef enum FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries. } FsDirectoryFlags; +typedef enum +{ + FsStorageId_None = 0, + FsStorageId_Host = 1, + FsStorageId_GameCard = 2, + FsStorageId_NandSystem = 3, + FsStorageId_NandUser = 4, + FsStorageId_SdCard = 5, +} FsStorageId; + typedef enum { FS_CONTENTSTORAGEID_NandSystem = 0, diff --git a/nx/include/switch/services/pm.h b/nx/include/switch/services/pm.h index 6a1c8e3c..4312c49a 100644 --- a/nx/include/switch/services/pm.h +++ b/nx/include/switch/services/pm.h @@ -2,6 +2,7 @@ * @file pm.h * @brief Process management (pm*) service IPC wrapper. * @author plutoo + * @author yellows8 * @copyright libnx Authors */ #pragma once @@ -10,8 +11,13 @@ Result pmdmntInitialize(void); void pmdmntExit(void); +Result pmshellInitialize(void); +void pmshellExit(void); + 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 pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid); diff --git a/nx/source/services/pm.c b/nx/source/services/pm.c index 073a6802..f7321de9 100644 --- a/nx/source/services/pm.c +++ b/nx/source/services/pm.c @@ -6,12 +6,12 @@ #include "services/pm.h" #include "services/sm.h" -static Service g_pmdmntSrv; -static u64 g_refCnt; +static Service g_pmdmntSrv, g_pmshellSrv; +static u64 g_pmdmntRefCnt, g_pmshellRefCnt; Result pmdmntInitialize(void) { - atomicIncrement64(&g_refCnt); + atomicIncrement64(&g_pmdmntRefCnt); if (serviceIsActive(&g_pmdmntSrv)) return 0; @@ -21,11 +21,28 @@ Result pmdmntInitialize(void) void pmdmntExit(void) { - if (atomicDecrement64(&g_refCnt) == 0) { + if (atomicDecrement64(&g_pmdmntRefCnt) == 0) { serviceClose(&g_pmdmntSrv); } } +Result pmshellInitialize(void) +{ + atomicIncrement64(&g_pmshellRefCnt); + + if (serviceIsActive(&g_pmshellSrv)) + return 0; + + return smGetService(&g_pmshellSrv, "pm:shell"); +} + +void pmshellExit(void) +{ + if (atomicDecrement64(&g_pmshellRefCnt) == 0) { + serviceClose(&g_pmshellSrv); + } +} + Result pmdmntStartProcess(u64 pid) { IpcCommand c; ipcInitialize(&c); @@ -204,3 +221,43 @@ Result pmdmntEnableDebugForApplication(Handle* handle_out) { return rc; } + +Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u32 launch_flags; + u64 titleID; + u64 storageID; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + raw->launch_flags = launch_flags; + raw->titleID = titleID; + raw->storageID = storageID; + + 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) *pid = resp->pid; + } + + return rc; +}