Report Windows error code in a fatal error after a system call.

llvm-svn: 252800
This commit is contained in:
Paul Robinson 2015-11-11 20:49:32 +00:00
parent 1070a09f17
commit 8ab79a1e8a
1 changed files with 9 additions and 2 deletions

View File

@ -417,16 +417,23 @@ const char *Process::ResetColor() {
return 0;
}
// Include GetLastError() in a fatal error message.
static void ReportLastErrorFatal(const char *Msg) {
std::string ErrMsg;
MakeErrMsg(&ErrMsg, Msg);
report_fatal_error(ErrMsg);
}
unsigned Process::GetRandomNumber() {
HCRYPTPROV HCPC;
if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
report_fatal_error("Could not acquire a cryptographic context");
ReportLastErrorFatal("Could not acquire a cryptographic context");
ScopedCryptContext CryptoProvider(HCPC);
unsigned Ret;
if (!::CryptGenRandom(CryptoProvider, sizeof(Ret),
reinterpret_cast<BYTE *>(&Ret)))
report_fatal_error("Could not generate a random number");
ReportLastErrorFatal("Could not generate a random number");
return Ret;
}