From e20658209177667e490c661dfd35b976749ef3f7 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 6 Jan 2018 23:08:09 +0100 Subject: [PATCH] add getrandom syscall wrapper This syscall is available since Linux 3.17 and was also implemented in glibc in version 2.25 using the same interfaces. --- include/sys/random.h | 19 +++++++++++++++++++ src/linux/getrandom.c | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 include/sys/random.h create mode 100644 src/linux/getrandom.c diff --git a/include/sys/random.h b/include/sys/random.h new file mode 100644 index 00000000..4ee7bf2c --- /dev/null +++ b/include/sys/random.h @@ -0,0 +1,19 @@ +#ifndef _SYS_RANDOM_H +#define _SYS_RANDOM_H +#ifdef __cplusplus +extern "C" { +#endif + +#define __NEED_size_t +#define __NEED_ssize_t +#include + +#define GRND_NONBLOCK 0x0001 +#define GRND_RANDOM 0x0002 + +ssize_t getrandom(void *, size_t, unsigned); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/linux/getrandom.c b/src/linux/getrandom.c new file mode 100644 index 00000000..6cc6f6b0 --- /dev/null +++ b/src/linux/getrandom.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t getrandom(void *buf, size_t buflen, unsigned flags) +{ + return syscall_cp(SYS_getrandom, buf, buflen, flags); +} -- 2.25.1