ectx: add ectxrPullContext

This commit is contained in:
Michael Scire 2020-12-03 09:49:22 -08:00
parent 2d470ee2af
commit f225a246cf
3 changed files with 71 additions and 0 deletions

View File

@ -123,6 +123,7 @@ extern "C" {
#include "switch/services/lp2p.h" #include "switch/services/lp2p.h"
#include "switch/services/news.h" #include "switch/services/news.h"
#include "switch/services/ins.h" #include "switch/services/ins.h"
#include "switch/services/ectx.h"
#include "switch/display/binder.h" #include "switch/display/binder.h"
#include "switch/display/parcel.h" #include "switch/display/parcel.h"

View File

@ -0,0 +1,25 @@
/**
* @file ectx.h
* @brief Error Context services IPC wrapper.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../kernel/event.h"
#include "../sf/service.h"
/// Initialize ectx:r.
Result ectxrInitialize(void);
/// Exit ectx:r.
void ectxrExit(void);
/// Gets the Service object for the actual ectx:r service session.
Service* ectxrGetServiceSession(void);
/**
* @brief Retrieves the error context associated with an error descriptor and result.
* @return Result code.
*/
Result ectxrPullContext(s32 *out0, u32 *out_total_size, u32 *out_size, void *dst, size_t dst_size, u32 descriptor, Result result);

45
nx/source/services/ectx.c Normal file
View File

@ -0,0 +1,45 @@
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include "service_guard.h"
#include "services/ectx.h"
static Service g_ectxrSrv;
NX_GENERATE_SERVICE_GUARD(ectxr);
Result _ectxrInitialize(void) {
return smGetService(&g_ectxrSrv, "ectx:r");
}
void _ectxrCleanup(void) {
serviceClose(&g_ectxrSrv);
}
Service* ectxrGetServiceSession(void) {
return &g_ectxrSrv;
}
Result ectxrPullContext(s32 *out0, u32 *out_total_size, u32 *out_size, void *dst, size_t dst_size, u32 descriptor, Result result) {
const struct {
u32 desc;
u32 res;
} in = { descriptor, result };
struct {
s32 unk0;
u32 total_size;
u32 size;
} out;
Result rc = serviceDispatchInOut(&g_ectxrSrv, 1, in, out,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
.buffers = { { dst, dst_size } },
);
if (R_SUCCEEDED(rc)) {
if (out0) *out0 = out.unk0;
if (out_total_size) *out_total_size = out.total_size;
if (out_size) *out_size = out.size;
}
return rc;
}