mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
Implement pm:dmnt
This commit is contained in:
parent
12410fc44a
commit
e5d0821678
@ -34,6 +34,7 @@ extern "C" {
|
|||||||
#include <switch/services/hid.h>
|
#include <switch/services/hid.h>
|
||||||
#include <switch/services/vi.h>
|
#include <switch/services/vi.h>
|
||||||
#include <switch/services/nv.h>
|
#include <switch/services/nv.h>
|
||||||
|
#include <switch/services/pm.h>
|
||||||
|
|
||||||
#include <switch/gfx/gfx.h>
|
#include <switch/gfx/gfx.h>
|
||||||
#include <switch/gfx/parcel.h>
|
#include <switch/gfx/parcel.h>
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
static Handle g_fsHandle = INVALID_HANDLE;
|
static Handle g_fsHandle = INVALID_HANDLE;
|
||||||
|
|
||||||
Result fsInitialize() {
|
Result fsInitialize() {
|
||||||
if(g_fsHandle != INVALID_HANDLE)return 0;
|
if (g_fsHandle != INVALID_HANDLE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
Result rc = smGetService(&g_fsHandle, "fsp-srv");
|
Result rc = smGetService(&g_fsHandle, "fsp-srv");
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
155
nx/source/services/pm.c
Normal file
155
nx/source/services/pm.c
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// Copyright 2017 plutoo
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
|
static Handle g_pmdmntHandle = INVALID_HANDLE;
|
||||||
|
|
||||||
|
Result pmdmntInitialize() {
|
||||||
|
Result rc = smGetService(&g_pmdmntHandle, "pm:dmnt");
|
||||||
|
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
|
g_pmdmntHandle = INVALID_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pmdmntStartProcess(u64 pid) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 pid;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 2;
|
||||||
|
raw->pid = pid;
|
||||||
|
|
||||||
|
Result rc = ipcDispatch(g_pmdmntHandle);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcCommandResponse r;
|
||||||
|
ipcParseResponse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pmdmntEnableDebugForTitleId(Handle* handle_out, u64 title_id) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 title_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 4;
|
||||||
|
raw->title_id = title_id;
|
||||||
|
|
||||||
|
Result rc = ipcDispatch(g_pmdmntHandle);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcCommandResponse r;
|
||||||
|
ipcParseResponse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*handle_out = r.Handles[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pmdmntGetApplicationPid(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 = 5;
|
||||||
|
|
||||||
|
Result rc = ipcDispatch(g_pmdmntHandle);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcCommandResponse r;
|
||||||
|
ipcParseResponse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
u64 pid;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*pid_out = resp->pid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pmdmntEnableDebugForApplication(Handle* handle_out) {
|
||||||
|
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 = ipcDispatch(g_pmdmntHandle);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcCommandResponse r;
|
||||||
|
ipcParseResponse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*handle_out = r.Handles[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user