mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
fsldr: update to use new-ipc
This commit is contained in:
parent
aafbc310c2
commit
f5f768ea5c
@ -1,42 +1,32 @@
|
|||||||
// Copyright 2018 SciresM
|
// Copyright 2018 SciresM
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "service_guard.h"
|
||||||
#include "result.h"
|
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "kernel/ipc.h"
|
|
||||||
#include "runtime/hosversion.h"
|
#include "runtime/hosversion.h"
|
||||||
#include "services/fs.h"
|
#include "services/fs.h"
|
||||||
#include "services/sm.h"
|
|
||||||
#include "services/fsldr.h"
|
#include "services/fsldr.h"
|
||||||
|
|
||||||
static Service g_fsldrSrv;
|
static Service g_fsldrSrv;
|
||||||
static u64 g_fsldrRefCnt;
|
|
||||||
|
|
||||||
Result fsldrSetCurrentProcess(void);
|
NX_GENERATE_SERVICE_GUARD(fsldr);
|
||||||
|
|
||||||
Result fsldrInitialize(void) {
|
NX_INLINE Result _fsldrSetCurrentProcess(void);
|
||||||
atomicIncrement64(&g_fsldrRefCnt);
|
|
||||||
|
|
||||||
if (serviceIsActive(&g_fsldrSrv))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
Result _fsldrInitialize(void) {
|
||||||
Result rc = smGetService(&g_fsldrSrv, "fsp-ldr");
|
Result rc = smGetService(&g_fsldrSrv, "fsp-ldr");
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
rc = serviceConvertToDomain(&g_fsldrSrv);
|
rc = serviceConvertToDomain(&g_fsldrSrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc) && hosversionAtLeast(4,0,0)) {
|
if (R_SUCCEEDED(rc) && hosversionAtLeast(4,0,0)) {
|
||||||
rc = fsldrSetCurrentProcess();
|
rc = _fsldrSetCurrentProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsldrExit(void) {
|
void _fsldrCleanup(void) {
|
||||||
if (atomicDecrement64(&g_fsldrRefCnt) == 0)
|
serviceClose(&g_fsldrSrv);
|
||||||
serviceClose(&g_fsldrSrv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Service* fsldrGetServiceSession(void) {
|
Service* fsldrGetServiceSession(void) {
|
||||||
@ -44,115 +34,25 @@ Service* fsldrGetServiceSession(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) {
|
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) {
|
||||||
char send_path[FS_MAX_PATH+1] = {0};
|
char send_path[FS_MAX_PATH + 1];
|
||||||
IpcCommand c;
|
|
||||||
ipcInitialize(&c);
|
|
||||||
ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
u64 tid;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_fsldrSrv, &c, sizeof(*raw));
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 0;
|
|
||||||
raw->tid = tid;
|
|
||||||
|
|
||||||
strncpy(send_path, path, FS_MAX_PATH);
|
strncpy(send_path, path, FS_MAX_PATH);
|
||||||
Result rc = serviceIpcDispatch(&g_fsldrSrv);
|
return serviceDispatchIn(&g_fsldrSrv, 0, tid,
|
||||||
|
.buffer_attrs = {
|
||||||
if (R_SUCCEEDED(rc)) {
|
SfBufferAttr_HipcPointer | SfBufferAttr_In,
|
||||||
IpcParsedCommand r;
|
},
|
||||||
struct {
|
.buffers = {
|
||||||
u64 magic;
|
{ send_path, FS_MAX_PATH },
|
||||||
u64 result;
|
},
|
||||||
} *resp;
|
.out_num_objects = 1,
|
||||||
|
.out_objects = &out->s,
|
||||||
serviceIpcParse(&g_fsldrSrv, &r, sizeof(*resp));
|
);
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
serviceCreateSubservice(&out->s, &g_fsldrSrv, &r, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result fsldrIsArchivedProgram(u64 pid, bool *out) {
|
Result fsldrIsArchivedProgram(u64 pid, bool *out) {
|
||||||
IpcCommand c;
|
return serviceDispatchInOut(&g_fsldrSrv, 1, pid, *out);
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
u64 pid;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_fsldrSrv, &c, sizeof(*raw));
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 1;
|
|
||||||
raw->pid = pid;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_fsldrSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
u8 is_archived;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_fsldrSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
*out = resp->is_archived != 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result fsldrSetCurrentProcess(void) {
|
Result _fsldrSetCurrentProcess(void) {
|
||||||
IpcCommand c;
|
u64 pid_placeholder = 0;
|
||||||
ipcInitialize(&c);
|
return serviceDispatchIn(&g_fsldrSrv, 2, pid_placeholder, .in_send_pid = true);
|
||||||
ipcSendPid(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
u64 unk;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_fsldrSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 2;
|
|
||||||
raw->unk = 0;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_fsldrSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_fsldrSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user