@@ -168,16 +168,10 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim
168168
169169#if defined(_WIN32 )
170170
171- #if !defined(MI_USE_RTLGENRANDOM )
172- // We prefer to use BCryptGenRandom instead of RtlGenRandom but it can lead to a deadlock
173- // under the VS debugger when using dynamic overriding.
174- #pragma comment (lib,"bcrypt.lib")
175- #include <bcrypt.h>
176- static bool os_random_buf (void * buf , size_t buf_len ) {
177- return (BCryptGenRandom (NULL , (PUCHAR )buf , (ULONG )buf_len , BCRYPT_USE_SYSTEM_PREFERRED_RNG ) >= 0 );
178- }
179- #else
180- // Use (unofficial) RtlGenRandom
171+ #if defined(MI_USE_RTLGENRANDOM ) || defined(__cplusplus )
172+ // We prefer to use BCryptGenRandom instead of (the unofficial) RtlGenRandom but when using
173+ // dynamic overriding, we observed it can raise an exception when compiled with C++, and
174+ // sometimes deadlocks when also running under the VS debugger.
181175#pragma comment (lib,"advapi32.lib")
182176#define RtlGenRandom SystemFunction036
183177#ifdef __cplusplus
@@ -190,6 +184,12 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
190184static bool os_random_buf (void * buf , size_t buf_len ) {
191185 return (RtlGenRandom (buf , (ULONG )buf_len ) != 0 );
192186}
187+ #else
188+ #pragma comment (lib,"bcrypt.lib")
189+ #include <bcrypt.h>
190+ static bool os_random_buf (void * buf , size_t buf_len ) {
191+ return (BCryptGenRandom (NULL , (PUCHAR )buf , (ULONG )buf_len , BCRYPT_USE_SYSTEM_PREFERRED_RNG ) >= 0 );
192+ }
193193#endif
194194
195195#elif defined(__APPLE__)
0 commit comments