2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Use TLS variables to store RNG state, make RNG lockless

This commit is contained in:
Witold Kręcicki
2018-08-24 11:21:27 +02:00
parent e79b42fec0
commit 8c5aeb6c4c
5 changed files with 38 additions and 7 deletions

View File

@@ -62,14 +62,26 @@
*/
#include "xoshiro128starstar.c"
#if defined(HAVE_TLS)
#if defined(HAVE_THREAD_LOCAL)
static thread_local isc_once_t isc_random_once = ISC_ONCE_INIT;
#elif defined(HAVE___THREAD)
static __thread isc_once_t isc_random_once = ISC_ONCE_INIT;
#else
#error "Unknown method for defining a TLS variable!"
#endif
#else
static isc_once_t isc_random_once = ISC_ONCE_INIT;
#endif
static void
isc_random_initialize(void) {
#if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
memset(seed, 0, sizeof(seed));
#else
isc_entropy_get(seed, sizeof(seed));
int useed[4] = {0,0,0,0};
isc_entropy_get(useed, sizeof(useed));
memcpy(seed, useed, sizeof(seed));
#endif
}