#include <sys/syscall.h>
#include <linux/bug.h>
+#ifdef __NR_getrandom
static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
{
return syscall(SYS_getrandom, buf, buflen, flags);
}
+#else
+extern int urandom_fd;
+
+static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
+{
+ return read(urandom_fd, buf, buflen);
+}
+#endif
static inline void get_random_bytes(void *buf, int nbytes)
{
rcu_init();
rcu_register_thread();
}
+
+#ifndef __NR_getrandom
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+int urandom_fd;
+
+__attribute__((constructor(101)))
+static void rand_init(void)
+{
+ urandom_fd = open("/dev/urandom", O_RDONLY);
+ BUG_ON(urandom_fd < 0);
+}
+#endif