Rizin
unix-like reverse engineering framework and cli tools
random.c File Reference
#include "uv.h"
#include "uv-common.h"
#include "unix/internal.h"

Go to the source code of this file.

Functions

static int uv__random (void *buf, size_t buflen)
 
static void uv__random_work (struct uv__work *w)
 
static void uv__random_done (struct uv__work *w, int status)
 
int uv_random (uv_loop_t *loop, uv_random_t *req, void *buf, size_t buflen, unsigned flags, uv_random_cb cb)
 

Function Documentation

◆ uv__random()

static int uv__random ( void *  buf,
size_t  buflen 
)
static

Definition at line 31 of file random.c.

31  {
32  int rc;
33 
34 #if defined(__PASE__)
35  rc = uv__random_readpath("/dev/urandom", buf, buflen);
36 #elif defined(_AIX) || defined(__QNX__)
37  rc = uv__random_readpath("/dev/random", buf, buflen);
38 #elif defined(__APPLE__) || defined(__OpenBSD__) || \
39  (defined(__ANDROID_API__) && __ANDROID_API__ >= 28)
41  if (rc == UV_ENOSYS)
43 #elif defined(__NetBSD__)
45 #elif defined(__FreeBSD__) || defined(__linux__)
47  if (rc == UV_ENOSYS)
49 # if defined(__linux__)
50  switch (rc) {
51  case UV_EACCES:
52  case UV_EIO:
53  case UV_ELOOP:
54  case UV_EMFILE:
55  case UV_ENFILE:
56  case UV_ENOENT:
57  case UV_EPERM:
59  break;
60  }
61 # endif
62 #elif defined(_WIN32)
63  uv__once_init();
65 #else
67 #endif
68 
69  return rc;
70 }
voidpf void * buf
Definition: ioapi.h:138
int uv__random_getrandom(void *buf, size_t buflen)
int uv__random_readpath(const char *path, void *buf, size_t buflen)
int uv__random_sysctl(void *buf, size_t buflen)
Definition: netbsd.c:238
int uv__random_getentropy(void *buf, size_t buflen)
int uv__random_devurandom(void *buf, size_t buflen)
void uv__once_init(void)
Definition: core.c:329
int uv__random_rtlgenrandom(void *buf, size_t buflen)
Definition: util.c:1965
ut64 buflen
Definition: core.c:76

References buflen, uv__once_init(), uv__random_devurandom(), uv__random_getentropy(), uv__random_getrandom(), uv__random_readpath(), uv__random_rtlgenrandom(), and uv__random_sysctl().

Referenced by uv__random_work(), and uv_random().

◆ uv__random_done()

static void uv__random_done ( struct uv__work w,
int  status 
)
static

Definition at line 81 of file random.c.

81  {
83 
84  req = container_of(w, uv_random_t, work_req);
85  uv__req_unregister(req->loop, req);
86 
87  if (status == 0)
88  status = req->status;
89 
90  req->cb(req, status, req->buf, req->buflen);
91 }
#define w
Definition: crypto_rc6.c:13
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
#define container_of(ptr, type, member)
Definition: rz_types.h:650
#define uv__req_unregister(loop, req)
Definition: uv-common.h:230

References container_of, req, status, uv__req_unregister, and w.

Referenced by uv_random().

◆ uv__random_work()

static void uv__random_work ( struct uv__work w)
static

Definition at line 73 of file random.c.

73  {
75 
76  req = container_of(w, uv_random_t, work_req);
77  req->status = uv__random(req->buf, req->buflen);
78 }
static int uv__random(void *buf, size_t buflen)
Definition: random.c:31

References container_of, req, uv__random(), and w.

Referenced by uv_random().

◆ uv_random()

int uv_random ( uv_loop_t loop,
uv_random_t req,
void *  buf,
size_t  buflen,
unsigned  flags,
uv_random_cb  cb 
)

Definition at line 94 of file random.c.

99  {
100  if (buflen > 0x7FFFFFFFu)
101  return UV_E2BIG;
102 
103  if (flags != 0)
104  return UV_EINVAL;
105 
106  if (cb == NULL)
107  return uv__random(buf, buflen);
108 
109  uv__req_init(loop, req, UV_RANDOM);
110  req->loop = loop;
111  req->status = 0;
112  req->cb = cb;
113  req->buf = buf;
114  req->buflen = buflen;
115 
117  &req->work_req,
118  UV__WORK_CPU,
121 
122  return 0;
123 }
#define NULL
Definition: cris-opc.c:27
static void uv__random_work(struct uv__work *w)
Definition: random.c:73
static void uv__random_done(struct uv__work *w, int status)
Definition: random.c:81
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
uv_loop_t * loop
Definition: main.c:7
void uv__work_submit(uv_loop_t *loop, struct uv__work *w, enum uv__work_kind kind, void(*work)(struct uv__work *w), void(*done)(struct uv__work *w, int status))
Definition: threadpool.c:256
@ UV__WORK_CPU
Definition: uv-common.h:192
#define uv__req_init(loop, req, typ)
Definition: uv-common.h:329
static const char * cb[]
Definition: z80_tab.h:176

References buflen, cb, flags, loop, NULL, req, uv__random(), uv__random_done(), uv__random_work(), uv__req_init, UV__WORK_CPU, and uv__work_submit().