Report Windows error code in a fatal error after a system call.
authorPaul Robinson <paul_robinson@playstation.sony.com>
Wed, 11 Nov 2015 20:49:32 +0000 (20:49 +0000)
committerPaul Robinson <paul_robinson@playstation.sony.com>
Wed, 11 Nov 2015 20:49:32 +0000 (20:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252800 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Windows/Process.inc

index 8164956d1511bd81a6fc6a39993c03a95a1b0f96..dae35a88132ba12a85f076f511f2ca4d4908319b 100644 (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;
 }