aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/Windows/Process.inc
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-04-23 16:57:46 -0700
committerStephen Hines <srhines@google.com>2014-04-24 15:53:16 -0700
commit36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch)
treee6cfb69fbbd937f450eeb83bfb83b9da3b01275a /lib/Support/Windows/Process.inc
parent69a8640022b04415ae9fac62f8ab090601d8f889 (diff)
downloadexternal_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'lib/Support/Windows/Process.inc')
-rw-r--r--lib/Support/Windows/Process.inc24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc
index f9a3db9..a87c9e8 100644
--- a/lib/Support/Windows/Process.inc
+++ b/lib/Support/Windows/Process.inc
@@ -12,11 +12,13 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Allocator.h"
+#include <malloc.h>
+
+// The Windows.h header must be after LLVM and standard headers.
+#include "WindowsSupport.h"
-#include "Windows.h"
#include <direct.h>
#include <io.h>
-#include <malloc.h>
#include <psapi.h>
#include <shellapi.h>
@@ -152,7 +154,7 @@ void Process::PreventCoreFiles() {
Optional<std::string> Process::GetEnv(StringRef Name) {
// Convert the argument to UTF-16 to pass it to _wgetenv().
SmallVector<wchar_t, 128> NameUTF16;
- if (error_code ec = windows::UTF8ToUTF16(Name, NameUTF16))
+ if (windows::UTF8ToUTF16(Name, NameUTF16))
return None;
// Environment variable can be encoded in non-UTF8 encoding, and there's no
@@ -173,7 +175,7 @@ Optional<std::string> Process::GetEnv(StringRef Name) {
// Convert the result from UTF-16 to UTF-8.
SmallVector<char, MAX_PATH> Res;
- if (error_code ec = windows::UTF16ToUTF8(Buf.data(), Size, Res))
+ if (windows::UTF16ToUTF8(Buf.data(), Size, Res))
return None;
return std::string(Res.data());
}
@@ -358,3 +360,17 @@ const char *Process::ResetColor() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
return 0;
}
+
+unsigned Process::GetRandomNumber() {
+ 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;
+}