mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
urandom fallback
This commit is contained in:
parent
4b9e40b23a
commit
8aaf7d913a
@ -10,10 +10,19 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
|
|
||||||
|
#ifdef __NR_getrandom
|
||||||
static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||||
{
|
{
|
||||||
return syscall(SYS_getrandom, buf, buflen, 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)
|
static inline void get_random_bytes(void *buf, int nbytes)
|
||||||
{
|
{
|
||||||
|
@ -179,3 +179,17 @@ static void sched_init(void)
|
|||||||
rcu_init();
|
rcu_init();
|
||||||
rcu_register_thread();
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user