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:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user