From b4f3eb0637df31602df515b32b445acbf0039703 Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Wed, 26 Feb 2020 11:38:55 +0100 Subject: [PATCH] Fix getrandom on Ubuntu 16.04 (GLIBC 2.23) (#14) * use system call SYS_getrandom * Add Ubuntu 16.04 to Travis CI script --- .travis.yml | 2 ++ rng/unix/mc_getrandom_stubs.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d308afd..151c6a1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,7 @@ matrix: include: - os: osx env: OCAML_VERSION=4.08 + - dist: xenial + env: OCAML_VERSION=4.08 notifications: email: false diff --git a/rng/unix/mc_getrandom_stubs.c b/rng/unix/mc_getrandom_stubs.c index fc8b7413..88bc9019 100644 --- a/rng/unix/mc_getrandom_stubs.c +++ b/rng/unix/mc_getrandom_stubs.c @@ -6,9 +6,16 @@ #include #if defined(__linux) +# include // on Linux, we use getrandom and loop -#include -#include + +# if __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 25 +# include +# define getrandom(buf, len, flags) syscall(SYS_getrandom, (buf), (len), (flags)) +# else +# include +# define getrandom(buf, len, flags) getrandom((buf), (len), (flags)) +# endif void raw_getrandom (uint8_t *data, uint32_t len) { int r, off = 0; @@ -19,7 +26,6 @@ void raw_getrandom (uint8_t *data, uint32_t len) { off += r; } } - #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)) // on BSD and macOS, loop (in pieces of 256) getentropy #if defined(__APPLE__)