From e5d2ac95da1ff06f9e6669b33e739c8d2784e6c3 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Mon, 16 Jan 2023 16:47:44 +0000 Subject: [PATCH] PAL netbsd, the 10th release finally supports getrandom syscall. (#583) --- src/snmalloc/pal/pal_netbsd.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/snmalloc/pal/pal_netbsd.h b/src/snmalloc/pal/pal_netbsd.h index 7539470..6e91d98 100644 --- a/src/snmalloc/pal/pal_netbsd.h +++ b/src/snmalloc/pal/pal_netbsd.h @@ -4,6 +4,7 @@ # include "pal_bsd_aligned.h" # include +# include /** * We skip the pthread cancellation checkpoints by reaching directly @@ -42,12 +43,20 @@ namespace snmalloc PALBSD_Aligned::pal_features | Entropy; /** - * Temporary solution while waiting getrandom support for the next release + * Temporary solution for NetBSD < 10 * random_device seems unimplemented in clang for this platform + * otherwise using getrandom */ static uint64_t get_entropy64() { +# if defined(SYS_getrandom) + uint64_t result; + if (getrandom(&result, sizeof(result), 0) != sizeof(result)) + error("Failed to get system randomness"); + return result; +# else return PALPOSIX::dev_urandom(); +# endif } }; } // namespace snmalloc