From 3f5e8b8dc1b73eff352195e3f02bb5752690fb90 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 11 Feb 2014 02:47:33 +0000 Subject: [PATCH] Hopefully fixing the MinGW 32 build, which was broken by r200767. Not using rand_s() since MinGW does not have an implementation for it, but instead using the underlying CryptGenRandom APIs. llvm-svn: 201124 --- llvm/lib/Support/Process.cpp | 5 ----- llvm/lib/Support/Windows/Process.inc | 15 +++++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp index 1360842..d5168f0 100644 --- a/llvm/lib/Support/Process.cpp +++ b/llvm/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/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc index 62b6da0..a0e3bc41 100644 --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/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; } -- 2.7.4