diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 1360842753d..d5168f03a6d 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -12,11 +12,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Config/config.h" -#if LLVM_ON_WIN32 - // This define makes stdlib.h declare the rand_s function. -#define _CRT_RAND_S -#include -#endif #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Process.h" diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index 62b6da0cb1b..a0e3bc413a3 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -362,8 +362,15 @@ const char *Process::ResetColor() { } unsigned Process::GetRandomNumber() { - unsigned int result; - const int ec = rand_s(&result); - assert(ec == 0 && "rand_s failed"); - return result; + HCRYPTPROV HCPC; + if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) + assert(false && "Could not acquire a cryptographic context"); + + ScopedCryptContext CryptoProvider(HCPC); + unsigned Ret; + if (!::CryptGenRandom(CryptoProvider, sizeof(Ret), + reinterpret_cast(&Ret))) + assert(false && "Could not generate a random number"); + return Ret; }