Remove dead code.
[oota-llvm.git] / lib / Support / Windows / Process.inc
index 16e4092e9faf5b3ab2d5ac9921ba26f780b01dc4..a794ca08f670d4a9dfe8577dd0af8b6986afdd27 100644 (file)
@@ -15,7 +15,7 @@
 #include <malloc.h>
 
 // The Windows.h header must be after LLVM and standard headers.
-#include "Windows.h"
+#include "WindowsSupport.h"
 
 #include <direct.h>
 #include <io.h>
@@ -362,8 +362,15 @@ const char *Process::ResetColor() {
 }
 
 unsigned Process::GetRandomNumber() {
-  unsigned int result;
-  const errno_t 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;
 }