mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
csrng: Updated for new-ipc. Removed copyright comment-header in the .c (other .c don't have it and the .h has one anyway).
This commit is contained in:
parent
e320f3cdf1
commit
ed2d72b9ff
@ -6,7 +6,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "../services/sm.h"
|
||||
#include "../sf/service.h"
|
||||
|
||||
Result csrngInitialize(void);
|
||||
void csrngExit(void);
|
||||
|
@ -1,27 +1,16 @@
|
||||
// Copyright 2018 SciresM
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "result.h"
|
||||
#include "arm/atomics.h"
|
||||
#include "kernel/ipc.h"
|
||||
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||
#include "service_guard.h"
|
||||
#include "services/csrng.h"
|
||||
#include "services/sm.h"
|
||||
#include "services/spl.h"
|
||||
|
||||
static Service g_csrngSrv;
|
||||
static u64 g_csrngRefCnt;
|
||||
|
||||
Result csrngInitialize(void) {
|
||||
atomicIncrement64(&g_csrngRefCnt);
|
||||
|
||||
if (serviceIsActive(&g_csrngSrv))
|
||||
return 0;
|
||||
NX_GENERATE_SERVICE_GUARD(csrng);
|
||||
|
||||
Result _csrngInitialize(void) {
|
||||
return smGetService(&g_csrngSrv, "csrng");
|
||||
}
|
||||
|
||||
void csrngExit(void) {
|
||||
if (atomicDecrement64(&g_csrngRefCnt) == 0)
|
||||
void _csrngCleanup(void) {
|
||||
serviceClose(&g_csrngSrv);
|
||||
}
|
||||
|
||||
@ -30,34 +19,8 @@ Service* csrngGetServiceSession(void) {
|
||||
}
|
||||
|
||||
Result csrngGetRandomBytes(void *out, size_t out_size) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
ipcAddRecvBuffer(&c, out, out_size, BufferType_Normal);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 0;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_csrngSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
return serviceDispatch(&g_csrngSrv, 0,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffers = { { out, out_size } },
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user