Rizin
unix-like reverse engineering framework and cli tools
random-getrandom.c File Reference
#include "uv.h"
#include "internal.h"
#include <stddef.h>
#include <dlfcn.h>

Go to the source code of this file.

Typedefs

typedef ssize_t(* uv__getrandom_cb) (void *, size_t, unsigned)
 

Functions

static void uv__random_getrandom_init_once (void)
 
static int uv__random_getrandom_init (void)
 
int uv__random_getrandom (void *buf, size_t buflen)
 

Variables

static uv__getrandom_cb uv__getrandom
 
static uv_once_t once = UV_ONCE_INIT
 

Typedef Documentation

◆ uv__getrandom_cb

typedef ssize_t(* uv__getrandom_cb) (void *, size_t, unsigned)

Definition at line 36 of file random-getrandom.c.

Function Documentation

◆ uv__random_getrandom()

int uv__random_getrandom ( void *  buf,
size_t  buflen 
)

Definition at line 56 of file random-getrandom.c.

56  {
57  ssize_t n;
58  size_t pos;
59  int rc;
60 
62  if (rc != 0)
63  return rc;
64 
65  for (pos = 0; pos != buflen; pos += n) {
66  do {
67  n = buflen - pos;
68 
69  /* Most getrandom() implementations promise that reads <= 256 bytes
70  * will always succeed and won't be interrupted by signals.
71  * It's therefore useful to split it up in smaller reads because
72  * one big read may, in theory, continuously fail with EINTR.
73  */
74  if (n > 256)
75  n = 256;
76 
77  n = uv__getrandom((char *) buf + pos, n, 0);
78  } while (n == -1 && errno == EINTR);
79 
80  if (n == -1)
81  return UV__ERR(errno);
82 
83  if (n == 0)
84  return UV_EIO;
85  }
86 
87  return 0;
88 }
#define UV__ERR(x)
Definition: errno.h:29
voidpf void * buf
Definition: ioapi.h:138
int n
Definition: mipsasm.c:19
static int uv__random_getrandom_init(void)
static uv__getrandom_cb uv__getrandom
#define EINTR
Definition: sftypes.h:114
int ssize_t
Definition: sftypes.h:39
int pos
Definition: main.c:11
ut64 buflen
Definition: core.c:76

References buflen, EINTR, n, pos, UV__ERR, uv__getrandom, and uv__random_getrandom_init().

Referenced by uv__random().

◆ uv__random_getrandom_init()

static int uv__random_getrandom_init ( void  )
static

Definition at line 45 of file random-getrandom.c.

45  {
47 
48  if (uv__getrandom == NULL)
49  return UV_ENOSYS;
50 
51  return 0;
52 }
#define NULL
Definition: cris-opc.c:27
static void uv__random_getrandom_init_once(void)
static uv_once_t once
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References NULL, once, uv__getrandom, uv__random_getrandom_init_once(), and uv_once().

Referenced by uv__random_getrandom().

◆ uv__random_getrandom_init_once()

static void uv__random_getrandom_init_once ( void  )
static

Definition at line 41 of file random-getrandom.c.

41  {
42  uv__getrandom = (uv__getrandom_cb) dlsym(RTLD_DEFAULT, "getrandom");
43 }
ssize_t(* uv__getrandom_cb)(void *, size_t, unsigned)

References uv__getrandom.

Referenced by uv__random_getrandom_init().

Variable Documentation

◆ once

uv_once_t once = UV_ONCE_INIT
static

Definition at line 39 of file random-getrandom.c.

Referenced by uv__random_getrandom_init().

◆ uv__getrandom