mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
ns:dev: Add TerminateProcess and TerminateProgram (#122)
* ns:dev: Add TerminateProcess and TerminateProgram
This commit is contained in:
parent
9770f4bb18
commit
dbbaf64ad3
@ -38,3 +38,10 @@ void nsvmExit(void);
|
|||||||
|
|
||||||
Result nsvmNeedsUpdateVulnerability(bool *out);
|
Result nsvmNeedsUpdateVulnerability(bool *out);
|
||||||
Result nsvmGetSafeSystemVersion(u16 *out);
|
Result nsvmGetSafeSystemVersion(u16 *out);
|
||||||
|
|
||||||
|
/* ns:dev */
|
||||||
|
Result nsdevInitialize();
|
||||||
|
void nsdevExit();
|
||||||
|
|
||||||
|
Result nsdevTerminateProcess(u64 pid);
|
||||||
|
Result nsdevTerminateProgram(u64 tid);
|
@ -6,8 +6,8 @@
|
|||||||
#include "services/sm.h"
|
#include "services/sm.h"
|
||||||
#include "services/ns.h"
|
#include "services/ns.h"
|
||||||
|
|
||||||
static Service g_nsAppManSrv, g_nsGetterSrv, g_nsvmSrv;
|
static Service g_nsAppManSrv, g_nsGetterSrv, g_nsvmSrv, g_nsdevSrv;
|
||||||
static u64 g_nsRefCnt, g_nsvmRefCnt;
|
static u64 g_nsRefCnt, g_nsvmRefCnt, g_nsdevRefCnt;
|
||||||
|
|
||||||
static Result _nsGetInterface(Service* srv_out, u64 cmd_id);
|
static Result _nsGetInterface(Service* srv_out, u64 cmd_id);
|
||||||
|
|
||||||
@ -43,6 +43,20 @@ void nsExit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result nsdevInitialize() {
|
||||||
|
atomicIncrement64(&g_nsdevRefCnt);
|
||||||
|
|
||||||
|
if (serviceIsActive(&g_nsdevSrv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return smGetService(&g_nsdevSrv, "ns:dev");
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsdevExit() {
|
||||||
|
if (atomicDecrement64(&g_nsdevRefCnt) == 0)
|
||||||
|
serviceClose(&g_nsdevSrv);
|
||||||
|
}
|
||||||
|
|
||||||
static Result _nsGetInterface(Service* srv_out, u64 cmd_id) {
|
static Result _nsGetInterface(Service* srv_out, u64 cmd_id) {
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
@ -289,4 +303,70 @@ Result nsvmGetSafeSystemVersion(u16 *out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result nsdevTerminateProcess(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 = 1;
|
||||||
|
raw->pid = pid;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&g_nsdevSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result nsdevTerminateProgram(u64 tid) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 tid;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 2;
|
||||||
|
raw->tid = tid;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&g_nsdevSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user