mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
Merge branch 'dev' into dev-slice
This commit is contained in:
commit
12c91999ac
1 changed files with 10 additions and 10 deletions
20
src/random.c
20
src/random.c
|
@ -168,16 +168,10 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
#if !defined(MI_USE_RTLGENRANDOM)
|
#if defined(MI_USE_RTLGENRANDOM) || defined(__cplusplus)
|
||||||
// We prefer to use BCryptGenRandom instead of RtlGenRandom but it can lead to a deadlock
|
// We prefer to use BCryptGenRandom instead of (the unofficial) RtlGenRandom but when using
|
||||||
// under the VS debugger when using dynamic overriding.
|
// dynamic overriding, we observed it can raise an exception when compiled with C++, and
|
||||||
#pragma comment (lib,"bcrypt.lib")
|
// sometimes deadlocks when also running under the VS debugger.
|
||||||
#include <bcrypt.h>
|
|
||||||
static bool os_random_buf(void* buf, size_t buf_len) {
|
|
||||||
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Use (unofficial) RtlGenRandom
|
|
||||||
#pragma comment (lib,"advapi32.lib")
|
#pragma comment (lib,"advapi32.lib")
|
||||||
#define RtlGenRandom SystemFunction036
|
#define RtlGenRandom SystemFunction036
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -190,6 +184,12 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
|
||||||
static bool os_random_buf(void* buf, size_t buf_len) {
|
static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
|
return (RtlGenRandom(buf, (ULONG)buf_len) != 0);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#pragma comment (lib,"bcrypt.lib")
|
||||||
|
#include <bcrypt.h>
|
||||||
|
static bool os_random_buf(void* buf, size_t buf_len) {
|
||||||
|
return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
|
Loading…
Add table
Reference in a new issue