From 50558576b62d61835b8ceccbf63a0b061c66b09e Mon Sep 17 00:00:00 2001 From: ZFY Date: Thu, 6 Apr 2023 00:07:40 +0800 Subject: [PATCH 1/2] Update eio_stubs.c getrandom and getentropy were added in glibc in version 2.25. Compiling will work to use raw system call for glibc version ahead of 2.25 --- lib_eio_linux/eio_stubs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib_eio_linux/eio_stubs.c b/lib_eio_linux/eio_stubs.c index a1102607d..27df42697 100644 --- a/lib_eio_linux/eio_stubs.c +++ b/lib_eio_linux/eio_stubs.c @@ -4,7 +4,9 @@ #include #include #include +#if __GLIBC__ > 2 || __GLIBC_MINOR__ > 24 #include +#endif #include #include #include @@ -97,7 +99,11 @@ CAMLprim value caml_eio_getrandom(value v_ba, value v_off, value v_len) { do { void *buf = Caml_ba_data_val(v_ba) + off; caml_enter_blocking_section(); +#if __GLIBC__ > 2 || __GLIBC_MINOR__ > 24 ret = getrandom(buf, len, 0); +#else + ret = syscall(SYS_getrandom, buf, len, 0); +#endif caml_leave_blocking_section(); } while (ret == -1 && errno == EINTR); if (ret == -1) uerror("getrandom", Nothing); From c1f47f805edf60a47d241ebe6663c5ef131b39e5 Mon Sep 17 00:00:00 2001 From: ZFY Date: Thu, 6 Apr 2023 00:15:16 +0800 Subject: [PATCH 2/2] raw system call of getrandom for glibc<2.25 getrandom were added in glibc in version 2.25. Compiling will work to use raw system call for glibc version ahead of 2.25 --- lib_eio_posix/eio_posix_stubs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_eio_posix/eio_posix_stubs.c b/lib_eio_posix/eio_posix_stubs.c index 93a0f10c4..6b75d43bb 100644 --- a/lib_eio_posix/eio_posix_stubs.c +++ b/lib_eio_posix/eio_posix_stubs.c @@ -2,7 +2,11 @@ #include #ifdef __linux__ +#if __GLIBC__ > 2 || __GLIBC_MINOR__ > 24 #include +#else +#include +#endif #endif #include #include @@ -40,7 +44,11 @@ CAMLprim value caml_eio_posix_getrandom(value v_ba, value v_off, value v_len) { void *buf = (uint8_t *)Caml_ba_data_val(v_ba) + off; caml_enter_blocking_section(); #ifdef __linux__ +#if __GLIBC__ > 2 || __GLIBC_MINOR__ > 24 ret = getrandom(buf, len, 0); +#else + ret = syscall(SYS_getrandom, buf, len, 0); +#endif #else arc4random_buf(buf, len); ret = len;