[llvm] r201124 - 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.
Aaron Ballman
aaron at aaronballman.com
Mon Feb 10 18:47:33 PST 2014
Author: aaronballman
Date: Mon Feb 10 20:47:33 2014
New Revision: 201124
URL: http://llvm.org/viewvc/llvm-project?rev=201124&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Support/Process.cpp
llvm/trunk/lib/Support/Windows/Process.inc
Modified: llvm/trunk/lib/Support/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Process.cpp?rev=201124&r1=201123&r2=201124&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Process.cpp (original)
+++ llvm/trunk/lib/Support/Process.cpp Mon Feb 10 20:47:33 2014
@@ -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 <stdlib.h>
-#endif
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Process.h"
Modified: llvm/trunk/lib/Support/Windows/Process.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=201124&r1=201123&r2=201124&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Process.inc (original)
+++ llvm/trunk/lib/Support/Windows/Process.inc Mon Feb 10 20:47:33 2014
@@ -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<BYTE *>(&Ret)))
+ assert(false && "Could not generate a random number");
+ return Ret;
}
More information about the llvm-commits
mailing list