Windows/Path.inc: Move <shlobj.h> after "Windows.h" for some API available.
[oota-llvm.git] / lib / Support / Windows / Process.inc
index 16e4092e9faf5b3ab2d5ac9921ba26f780b01dc4..a0e3bc413a3f2c32d9de0fc28fafeefc5b1337c7 100644 (file)
@@ -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;
 }