Merge branch '496-tls-in-rng' into 'master'
Resolve "RNG should not be locking" Closes #340 and #496 See merge request isc-projects/bind9!697
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
||||
5020. [func] RNG uses thread-local storage instead of locks, if
|
||||
supported by platform. [GL #496]
|
||||
|
||||
5019. [cleanup] A message is now logged when ixfr-from-differences is
|
||||
set at zone level for an inline-signed zone. [GL #470]
|
||||
|
||||
|
||||
@@ -161,18 +161,19 @@ dns_test_begin(FILE *logfile, bool start_managers) {
|
||||
|
||||
void
|
||||
dns_test_end(void) {
|
||||
cleanup_managers();
|
||||
|
||||
if (dst_active) {
|
||||
dst_lib_destroy();
|
||||
dst_active = false;
|
||||
}
|
||||
|
||||
cleanup_managers();
|
||||
|
||||
if (lctx != NULL)
|
||||
isc_log_destroy(&lctx);
|
||||
|
||||
if (mctx != NULL)
|
||||
isc_mem_destroy(&mctx);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -62,14 +62,28 @@
|
||||
*/
|
||||
#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;
|
||||
#elif defined(HAVE___DECLSPEC_THREAD)
|
||||
static __declspec( 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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
***** Platform-dependent defines.
|
||||
*****/
|
||||
|
||||
#if _MSC_VER > 1400
|
||||
#define HAVE_TLS 1
|
||||
#define HAVE___DECLSPEC_THREAD 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some compatibility cludges
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,21 @@
|
||||
*
|
||||
* The state must be seeded so that it is not everywhere zero.
|
||||
*/
|
||||
#if defined(HAVE_TLS)
|
||||
#define _LOCK() {};
|
||||
#define _UNLOCK() {};
|
||||
|
||||
#if defined(HAVE_THREAD_LOCAL)
|
||||
static thread_local uint32_t seed[4];
|
||||
#elif defined(HAVE___THREAD)
|
||||
static __thread uint32_t seed[4];
|
||||
#elif defined(HAVE___DECLSPEC_THREAD)
|
||||
static __declspec( thread ) uint32_t seed[4];
|
||||
#else
|
||||
#error "Unknown method for defining a TLS variable!"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
static volatile HANDLE _mutex = NULL;
|
||||
@@ -61,16 +76,18 @@ static volatile HANDLE _mutex = NULL;
|
||||
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define _LOCK() pthread_mutex_lock(&_mutex)
|
||||
#define _UNLOCK() pthread_mutex_unlock(&_mutex)
|
||||
#define _LOCK() RUNTIME_CHECK(pthread_mutex_lock(&_mutex)==0)
|
||||
#define _UNLOCK() RUNTIME_CHECK(pthread_mutex_unlock(&_mutex)==0)
|
||||
#endif /* defined(_WIN32) || defined(_WIN64) */
|
||||
|
||||
static uint32_t seed[4];
|
||||
|
||||
#endif /* defined(HAVE_TLS) */
|
||||
|
||||
static inline uint32_t rotl(const uint32_t x, int k) {
|
||||
return (x << k) | (x >> (32 - k));
|
||||
}
|
||||
|
||||
static uint32_t seed[4];
|
||||
|
||||
static inline uint32_t
|
||||
next(void) {
|
||||
uint32_t result_starstar, t;
|
||||
|
||||
@@ -277,13 +277,13 @@ ns_test_begin(FILE *logfile, bool start_managers) {
|
||||
|
||||
void
|
||||
ns_test_end(void) {
|
||||
cleanup_managers();
|
||||
|
||||
if (dst_active) {
|
||||
dst_lib_destroy();
|
||||
dst_active = false;
|
||||
}
|
||||
|
||||
cleanup_managers();
|
||||
|
||||
if (lctx != NULL)
|
||||
isc_log_destroy(&lctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user