Added FsStorageId. Added pmshell init/exit and pmshellLaunchProcess.

This commit is contained in:
yellows8 2018-04-12 02:52:49 -04:00
parent a3baa0eeb1
commit 8091db8931
3 changed files with 77 additions and 4 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;
}