Skip to content

Commit e5d2ac9

Browse files
authored
PAL netbsd, the 10th release finally supports getrandom syscall. (#583)
1 parent f032e3f commit e5d2ac9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/snmalloc/pal/pal_netbsd.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# include "pal_bsd_aligned.h"
55

66
# include <fcntl.h>
7+
# include <sys/syscall.h>
78

89
/**
910
* We skip the pthread cancellation checkpoints by reaching directly
@@ -42,12 +43,20 @@ namespace snmalloc
4243
PALBSD_Aligned::pal_features | Entropy;
4344

4445
/**
45-
* Temporary solution while waiting getrandom support for the next release
46+
* Temporary solution for NetBSD < 10
4647
* random_device seems unimplemented in clang for this platform
48+
* otherwise using getrandom
4749
*/
4850
static uint64_t get_entropy64()
4951
{
52+
# if defined(SYS_getrandom)
53+
uint64_t result;
54+
if (getrandom(&result, sizeof(result), 0) != sizeof(result))
55+
error("Failed to get system randomness");
56+
return result;
57+
# else
5058
return PALPOSIX::dev_urandom();
59+
# endif
5160
}
5261
};
5362
} // namespace snmalloc

0 commit comments

Comments
 (0)