blob: 854eac73f230a120e2d77451a0aaa5e760c572f9 [file] [log] [blame]
Reid Spencer91886b72004-09-15 05:47:40 +00001//===- Win32/Process.cpp - Win32 Process Implementation ------- -*- C++ -*-===//
Michael J. Spencer447762d2010-11-29 18:16:10 +00002//
Reid Spencer91886b72004-09-15 05:47:40 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer447762d2010-11-29 18:16:10 +00007//
Reid Spencer91886b72004-09-15 05:47:40 +00008//===----------------------------------------------------------------------===//
9//
10// This file provides the Win32 specific implementation of the Process class.
11//
12//===----------------------------------------------------------------------===//
13
David Majnemer61eae2e2013-10-07 01:00:07 +000014#include "llvm/Support/Allocator.h"
Alp Toker552f2f72014-06-03 03:01:03 +000015#include "llvm/Support/ErrorHandling.h"
Rafael Espindola5c4f8292014-06-11 19:05:50 +000016#include "llvm/Support/WindowsError.h"
Chandler Carruth10b09152014-01-07 12:37:13 +000017#include <malloc.h>
18
19// The Windows.h header must be after LLVM and standard headers.
Reid Klecknerd59e2fa2014-02-12 21:26:20 +000020#include "WindowsSupport.h"
Chandler Carruth10b09152014-01-07 12:37:13 +000021
Daniel Dunbar9b92e2b2011-09-23 23:23:36 +000022#include <direct.h>
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include <io.h>
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include <psapi.h>
David Majnemer61eae2e2013-10-07 01:00:07 +000025#include <shellapi.h>
Jeff Cohen7ae0bc72004-12-20 03:24:56 +000026
Reid Spencer187b4ad2006-06-01 19:03:21 +000027#ifdef __MINGW32__
28 #if (HAVE_LIBPSAPI != 1)
29 #error "libpsapi.a should be present"
30 #endif
David Majnemer61eae2e2013-10-07 01:00:07 +000031 #if (HAVE_LIBSHELL32 != 1)
32 #error "libshell32.a should be present"
33 #endif
Reid Spencer187b4ad2006-06-01 19:03:21 +000034#else
David Majnemerf636cf42013-10-06 20:44:34 +000035 #pragma comment(lib, "psapi.lib")
David Majnemer61eae2e2013-10-07 01:00:07 +000036 #pragma comment(lib, "shell32.lib")
Reid Spencer187b4ad2006-06-01 19:03:21 +000037#endif
Reid Spencer91886b72004-09-15 05:47:40 +000038
39//===----------------------------------------------------------------------===//
Michael J. Spencer447762d2010-11-29 18:16:10 +000040//=== WARNING: Implementation here must contain only Win32 specific code
Reid Spencer91886b72004-09-15 05:47:40 +000041//=== and must not be UNIX code
42//===----------------------------------------------------------------------===//
43
Jeff Cohen07e22ba2005-02-19 03:01:13 +000044#ifdef __MINGW32__
Jeff Cohen53fbecc2004-12-23 03:44:40 +000045// This ban should be lifted when MinGW 1.0+ has defined this value.
46# define _HEAPOK (-2)
47#endif
48
Chandler Carruth5473dfb2012-12-31 11:45:20 +000049using namespace llvm;
Reid Spencer91886b72004-09-15 05:47:40 +000050using namespace sys;
Chandler Carruth97683aa2012-12-31 11:17:50 +000051
Chandler Carruthef7f9682013-01-04 23:19:55 +000052static TimeValue getTimeValueFromFILETIME(FILETIME Time) {
53 ULARGE_INTEGER TimeInteger;
54 TimeInteger.LowPart = Time.dwLowDateTime;
55 TimeInteger.HighPart = Time.dwHighDateTime;
56
57 // FILETIME's are # of 100 nanosecond ticks (1/10th of a microsecond)
58 return TimeValue(
59 static_cast<TimeValue::SecondsType>(TimeInteger.QuadPart / 10000000),
60 static_cast<TimeValue::NanoSecondsType>(
61 (TimeInteger.QuadPart % 10000000) * 100));
62}
63
Alp Tokerd71b6df2014-05-19 16:13:28 +000064// This function retrieves the page size using GetNativeSystemInfo() and is
65// present solely so it can be called once to initialize the self_process member
66// below.
Rafael Espindolac0610bf2014-12-04 16:59:36 +000067static unsigned computePageSize() {
Alp Tokerd71b6df2014-05-19 16:13:28 +000068 // GetNativeSystemInfo() provides the physical page size which may differ
69 // from GetSystemInfo() in 32-bit applications running under WOW64.
Reid Spencer91886b72004-09-15 05:47:40 +000070 SYSTEM_INFO info;
Alp Tokerd71b6df2014-05-19 16:13:28 +000071 GetNativeSystemInfo(&info);
NAKAMURA Takumi7a042342013-09-04 14:12:26 +000072 // FIXME: FileOffset in MapViewOfFile() should be aligned to not dwPageSize,
73 // but dwAllocationGranularity.
Reid Spencer91886b72004-09-15 05:47:40 +000074 return static_cast<unsigned>(info.dwPageSize);
75}
76
Rafael Espindolac0610bf2014-12-04 16:59:36 +000077unsigned Process::getPageSize() {
78 static unsigned Ret = computePageSize();
79 return Ret;
Reid Spencer91886b72004-09-15 05:47:40 +000080}
81
Michael J. Spencer447762d2010-11-29 18:16:10 +000082size_t
Reid Spencerac38f3a2004-12-20 00:59:28 +000083Process::GetMallocUsage()
84{
Jeff Cohen7ae0bc72004-12-20 03:24:56 +000085 _HEAPINFO hinfo;
86 hinfo._pentry = NULL;
87
88 size_t size = 0;
89
90 while (_heapwalk(&hinfo) == _HEAPOK)
91 size += hinfo._size;
92
93 return size;
Reid Spencerac38f3a2004-12-20 00:59:28 +000094}
95
Chandler Carruthef7f9682013-01-04 23:19:55 +000096void Process::GetTimeUsage(TimeValue &elapsed, TimeValue &user_time,
97 TimeValue &sys_time) {
Reid Spencerac38f3a2004-12-20 00:59:28 +000098 elapsed = TimeValue::now();
99
Chandler Carruthef7f9682013-01-04 23:19:55 +0000100 FILETIME ProcCreate, ProcExit, KernelTime, UserTime;
101 if (GetProcessTimes(GetCurrentProcess(), &ProcCreate, &ProcExit, &KernelTime,
102 &UserTime) == 0)
103 return;
Reid Spencerac38f3a2004-12-20 00:59:28 +0000104
Chandler Carruthef7f9682013-01-04 23:19:55 +0000105 user_time = getTimeValueFromFILETIME(UserTime);
Chandler Carruthb79a7aa2013-01-04 23:46:04 +0000106 sys_time = getTimeValueFromFILETIME(KernelTime);
Reid Spencerac38f3a2004-12-20 00:59:28 +0000107}
108
Reid Spencercf15b872004-12-27 06:17:27 +0000109// Some LLVM programs such as bugpoint produce core files as a normal part of
Aaron Ballmandcd57572013-08-16 14:33:07 +0000110// their operation. To prevent the disk from filling up, this configuration
111// item does what's necessary to prevent their generation.
Reid Spencercf15b872004-12-27 06:17:27 +0000112void Process::PreventCoreFiles() {
Aaron Ballmandcd57572013-08-16 14:33:07 +0000113 // Windows does have the concept of core files, called minidumps. However,
114 // disabling minidumps for a particular application extends past the lifetime
115 // of that application, which is the incorrect behavior for this API.
116 // Additionally, the APIs require elevated privileges to disable and re-
117 // enable minidumps, which makes this untenable. For more information, see
118 // WerAddExcludedApplication and WerRemoveExcludedApplication (Vista and
119 // later).
120 //
121 // Windows also has modal pop-up message boxes. As this method is used by
122 // bugpoint, preventing these pop-ups is additionally important.
Jeff Cohen81549a52005-02-18 07:05:18 +0000123 SetErrorMode(SEM_FAILCRITICALERRORS |
124 SEM_NOGPFAULTERRORBOX |
125 SEM_NOOPENFILEERRORBOX);
Reid Spencercf15b872004-12-27 06:17:27 +0000126}
127
Rui Ueyama471d0c52013-09-10 19:45:51 +0000128/// Returns the environment variable \arg Name's value as a string encoded in
129/// UTF-8. \arg Name is assumed to be in UTF-8 encoding.
130Optional<std::string> Process::GetEnv(StringRef Name) {
131 // Convert the argument to UTF-16 to pass it to _wgetenv().
132 SmallVector<wchar_t, 128> NameUTF16;
Ahmed Charlesce30de92014-03-05 05:04:00 +0000133 if (windows::UTF8ToUTF16(Name, NameUTF16))
Rui Ueyama471d0c52013-09-10 19:45:51 +0000134 return None;
135
136 // Environment variable can be encoded in non-UTF8 encoding, and there's no
137 // way to know what the encoding is. The only reliable way to look up
138 // multibyte environment variable is to use GetEnvironmentVariableW().
David Majnemer61eae2e2013-10-07 01:00:07 +0000139 SmallVector<wchar_t, MAX_PATH> Buf;
140 size_t Size = MAX_PATH;
141 do {
David Majnemerf07777c2013-10-07 21:57:07 +0000142 Buf.reserve(Size);
143 Size =
144 GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
David Majnemer61eae2e2013-10-07 01:00:07 +0000145 if (Size == 0)
146 return None;
147
Rui Ueyama471d0c52013-09-10 19:45:51 +0000148 // Try again with larger buffer.
David Majnemer61eae2e2013-10-07 01:00:07 +0000149 } while (Size > Buf.capacity());
150 Buf.set_size(Size);
Rui Ueyama471d0c52013-09-10 19:45:51 +0000151
152 // Convert the result from UTF-16 to UTF-8.
David Majnemer61eae2e2013-10-07 01:00:07 +0000153 SmallVector<char, MAX_PATH> Res;
Ahmed Charlesce30de92014-03-05 05:04:00 +0000154 if (windows::UTF16ToUTF8(Buf.data(), Size, Res))
Rui Ueyama471d0c52013-09-10 19:45:51 +0000155 return None;
David Majnemerf07777c2013-10-07 21:57:07 +0000156 return std::string(Res.data());
Rui Ueyama471d0c52013-09-10 19:45:51 +0000157}
158
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000159static std::error_code windows_error(DWORD E) {
Rafael Espindola5c4f8292014-06-11 19:05:50 +0000160 return mapWindowsError(E);
Rafael Espindolaa813d602014-06-11 03:58:34 +0000161}
162
Hans Wennborg21f0f132014-07-16 00:52:11 +0000163static void AllocateAndPush(const SmallVectorImpl<char> &S,
164 SmallVectorImpl<const char *> &Vector,
165 SpecificBumpPtrAllocator<char> &Allocator) {
166 char *Buffer = Allocator.Allocate(S.size() + 1);
167 ::memcpy(Buffer, S.data(), S.size());
168 Buffer[S.size()] = '\0';
169 Vector.push_back(Buffer);
170}
171
172/// Convert Arg from UTF-16 to UTF-8 and push it onto Args.
173static std::error_code
174ConvertAndPushArg(const wchar_t *Arg, SmallVectorImpl<const char *> &Args,
175 SpecificBumpPtrAllocator<char> &Allocator) {
176 SmallVector<char, MAX_PATH> ArgString;
177 if (std::error_code ec = windows::UTF16ToUTF8(Arg, wcslen(Arg), ArgString))
178 return ec;
179 AllocateAndPush(ArgString, Args, Allocator);
180 return std::error_code();
181}
182
183/// \brief Perform wildcard expansion of Arg, or just push it into Args if it
184/// doesn't have wildcards or doesn't match any files.
185static std::error_code
186WildcardExpand(const wchar_t *Arg, SmallVectorImpl<const char *> &Args,
187 SpecificBumpPtrAllocator<char> &Allocator) {
188 if (!wcspbrk(Arg, L"*?")) {
189 // Arg does not contain any wildcard characters. This is the common case.
190 return ConvertAndPushArg(Arg, Args, Allocator);
191 }
192
Hans Wennborge34a71a2014-07-24 21:09:45 +0000193 if (wcscmp(Arg, L"/?") == 0 || wcscmp(Arg, L"-?") == 0) {
194 // Don't wildcard expand /?. Always treat it as an option.
195 return ConvertAndPushArg(Arg, Args, Allocator);
196 }
197
Hans Wennborg21f0f132014-07-16 00:52:11 +0000198 // Extract any directory part of the argument.
199 SmallVector<char, MAX_PATH> Dir;
200 if (std::error_code ec = windows::UTF16ToUTF8(Arg, wcslen(Arg), Dir))
201 return ec;
202 sys::path::remove_filename(Dir);
203 const int DirSize = Dir.size();
204
205 // Search for matching files.
206 WIN32_FIND_DATAW FileData;
207 HANDLE FindHandle = FindFirstFileW(Arg, &FileData);
208 if (FindHandle == INVALID_HANDLE_VALUE) {
209 return ConvertAndPushArg(Arg, Args, Allocator);
210 }
211
212 std::error_code ec;
213 do {
214 SmallVector<char, MAX_PATH> FileName;
215 ec = windows::UTF16ToUTF8(FileData.cFileName, wcslen(FileData.cFileName),
216 FileName);
217 if (ec)
218 break;
219
220 // Push the filename onto Dir, and remove it afterwards.
221 llvm::sys::path::append(Dir, StringRef(FileName.data(), FileName.size()));
222 AllocateAndPush(Dir, Args, Allocator);
223 Dir.resize(DirSize);
224 } while (FindNextFileW(FindHandle, &FileData));
225
226 FindClose(FindHandle);
227 return ec;
228}
229
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +0000230std::error_code
David Majnemer61eae2e2013-10-07 01:00:07 +0000231Process::GetArgumentVector(SmallVectorImpl<const char *> &Args,
232 ArrayRef<const char *>,
233 SpecificBumpPtrAllocator<char> &ArgAllocator) {
Hans Wennborg21f0f132014-07-16 00:52:11 +0000234 int ArgCount;
235 wchar_t **UnicodeCommandLine =
236 CommandLineToArgvW(GetCommandLineW(), &ArgCount);
David Majnemer61eae2e2013-10-07 01:00:07 +0000237 if (!UnicodeCommandLine)
238 return windows_error(::GetLastError());
239
Hans Wennborg21f0f132014-07-16 00:52:11 +0000240 Args.reserve(ArgCount);
241 std::error_code ec;
David Majnemer61eae2e2013-10-07 01:00:07 +0000242
Hans Wennborg21f0f132014-07-16 00:52:11 +0000243 for (int i = 0; i < ArgCount; ++i) {
244 ec = WildcardExpand(UnicodeCommandLine[i], Args, ArgAllocator);
David Majnemer61eae2e2013-10-07 01:00:07 +0000245 if (ec)
246 break;
David Majnemer61eae2e2013-10-07 01:00:07 +0000247 }
David Majnemer61eae2e2013-10-07 01:00:07 +0000248
Hans Wennborg21f0f132014-07-16 00:52:11 +0000249 LocalFree(UnicodeCommandLine);
250 return ec;
David Majnemer61eae2e2013-10-07 01:00:07 +0000251}
252
David Majnemer121a1742014-10-06 23:16:18 +0000253std::error_code Process::FixupStandardFileDescriptors() {
254 return std::error_code();
255}
256
David Majnemer51c2afc2014-10-07 05:48:40 +0000257std::error_code Process::SafelyCloseFileDescriptor(int FD) {
258 if (::close(FD) < 0)
259 return std::error_code(errno, std::generic_category());
260 return std::error_code();
261}
262
Jeff Cohenb90c31f2005-01-01 22:54:05 +0000263bool Process::StandardInIsUserInput() {
Dan Gohmane5929232009-09-11 20:46:33 +0000264 return FileDescriptorIsDisplayed(0);
Jeff Cohenb90c31f2005-01-01 22:54:05 +0000265}
266
267bool Process::StandardOutIsDisplayed() {
Dan Gohmane5929232009-09-11 20:46:33 +0000268 return FileDescriptorIsDisplayed(1);
Jeff Cohenb90c31f2005-01-01 22:54:05 +0000269}
270
271bool Process::StandardErrIsDisplayed() {
Dan Gohmane5929232009-09-11 20:46:33 +0000272 return FileDescriptorIsDisplayed(2);
273}
274
275bool Process::FileDescriptorIsDisplayed(int fd) {
Bill Wendling2b079652012-07-19 00:06:06 +0000276 DWORD Mode; // Unused
NAKAMURA Takumi23ebef12010-11-10 08:37:47 +0000277 return (GetConsoleMode((HANDLE)_get_osfhandle(fd), &Mode) != 0);
Jeff Cohenb90c31f2005-01-01 22:54:05 +0000278}
279
Douglas Gregor15436612009-05-11 18:05:52 +0000280unsigned Process::StandardOutColumns() {
281 unsigned Columns = 0;
282 CONSOLE_SCREEN_BUFFER_INFO csbi;
283 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
284 Columns = csbi.dwSize.X;
285 return Columns;
286}
287
288unsigned Process::StandardErrColumns() {
289 unsigned Columns = 0;
290 CONSOLE_SCREEN_BUFFER_INFO csbi;
291 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi))
292 Columns = csbi.dwSize.X;
293 return Columns;
294}
295
Daniel Dunbar712de822012-07-20 18:29:38 +0000296// The terminal always has colors.
Benjamin Kramerdfaa0f32012-07-20 19:49:33 +0000297bool Process::FileDescriptorHasColors(int fd) {
Daniel Dunbar712de822012-07-20 18:29:38 +0000298 return FileDescriptorIsDisplayed(fd);
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000299}
300
301bool Process::StandardOutHasColors() {
Daniel Dunbar712de822012-07-20 18:29:38 +0000302 return FileDescriptorHasColors(1);
303}
304
305bool Process::StandardErrHasColors() {
306 return FileDescriptorHasColors(2);
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000307}
Torok Edwin63e44bb2009-06-04 08:18:25 +0000308
Nico Rieck92d649a2013-09-11 00:36:48 +0000309static bool UseANSI = false;
310void Process::UseANSIEscapeCodes(bool enable) {
311 UseANSI = enable;
312}
313
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000314namespace {
315class DefaultColors
316{
317 private:
318 WORD defaultColor;
319 public:
320 DefaultColors()
321 :defaultColor(GetCurrentColor()) {}
322 static unsigned GetCurrentColor() {
323 CONSOLE_SCREEN_BUFFER_INFO csbi;
324 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
325 return csbi.wAttributes;
326 return 0;
327 }
328 WORD operator()() const { return defaultColor; }
329};
330
331DefaultColors defaultColors;
332}
333
334bool Process::ColorNeedsFlush() {
Nico Rieck92d649a2013-09-11 00:36:48 +0000335 return !UseANSI;
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000336}
337
338const char *Process::OutputBold(bool bg) {
Nico Rieck92d649a2013-09-11 00:36:48 +0000339 if (UseANSI) return "\033[1m";
340
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000341 WORD colors = DefaultColors::GetCurrentColor();
342 if (bg)
343 colors |= BACKGROUND_INTENSITY;
344 else
345 colors |= FOREGROUND_INTENSITY;
346 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
347 return 0;
348}
349
350const char *Process::OutputColor(char code, bool bold, bool bg) {
Nico Rieck92d649a2013-09-11 00:36:48 +0000351 if (UseANSI) return colorcodes[bg?1:0][bold?1:0][code&7];
352
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000353 WORD colors;
354 if (bg) {
355 colors = ((code&1) ? BACKGROUND_RED : 0) |
356 ((code&2) ? BACKGROUND_GREEN : 0 ) |
357 ((code&4) ? BACKGROUND_BLUE : 0);
358 if (bold)
359 colors |= BACKGROUND_INTENSITY;
360 } else {
361 colors = ((code&1) ? FOREGROUND_RED : 0) |
362 ((code&2) ? FOREGROUND_GREEN : 0 ) |
363 ((code&4) ? FOREGROUND_BLUE : 0);
364 if (bold)
365 colors |= FOREGROUND_INTENSITY;
366 }
367 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
368 return 0;
369}
370
Benjamin Kramer13d16f32012-04-16 08:56:50 +0000371static WORD GetConsoleTextAttribute(HANDLE hConsoleOutput) {
372 CONSOLE_SCREEN_BUFFER_INFO info;
373 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
374 return info.wAttributes;
375}
376
377const char *Process::OutputReverse() {
Nico Rieck92d649a2013-09-11 00:36:48 +0000378 if (UseANSI) return "\033[7m";
379
Benjamin Kramer13d16f32012-04-16 08:56:50 +0000380 const WORD attributes
381 = GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE));
382
383 const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
384 FOREGROUND_RED | FOREGROUND_INTENSITY;
385 const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
386 BACKGROUND_RED | BACKGROUND_INTENSITY;
387 const WORD color_mask = foreground_mask | background_mask;
388
389 WORD new_attributes =
390 ((attributes & FOREGROUND_BLUE )?BACKGROUND_BLUE :0) |
391 ((attributes & FOREGROUND_GREEN )?BACKGROUND_GREEN :0) |
392 ((attributes & FOREGROUND_RED )?BACKGROUND_RED :0) |
393 ((attributes & FOREGROUND_INTENSITY)?BACKGROUND_INTENSITY:0) |
394 ((attributes & BACKGROUND_BLUE )?FOREGROUND_BLUE :0) |
395 ((attributes & BACKGROUND_GREEN )?FOREGROUND_GREEN :0) |
396 ((attributes & BACKGROUND_RED )?FOREGROUND_RED :0) |
397 ((attributes & BACKGROUND_INTENSITY)?FOREGROUND_INTENSITY:0) |
398 0;
399 new_attributes = (attributes & ~color_mask) | (new_attributes & color_mask);
400
401 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), new_attributes);
402 return 0;
403}
404
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000405const char *Process::ResetColor() {
Nico Rieck92d649a2013-09-11 00:36:48 +0000406 if (UseANSI) return "\033[0m";
Torok Edwin9b5a47f2009-06-04 07:09:50 +0000407 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
408 return 0;
409}
Aaron Ballman78440732014-02-04 14:49:21 +0000410
411unsigned Process::GetRandomNumber() {
Aaron Ballman3f5e8b82014-02-11 02:47:33 +0000412 HCRYPTPROV HCPC;
413 if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
414 CRYPT_VERIFYCONTEXT))
Alp Toker552f2f72014-06-03 03:01:03 +0000415 report_fatal_error("Could not acquire a cryptographic context");
Aaron Ballman3f5e8b82014-02-11 02:47:33 +0000416
417 ScopedCryptContext CryptoProvider(HCPC);
418 unsigned Ret;
419 if (!::CryptGenRandom(CryptoProvider, sizeof(Ret),
420 reinterpret_cast<BYTE *>(&Ret)))
Alp Toker552f2f72014-06-03 03:01:03 +0000421 report_fatal_error("Could not generate a random number");
Aaron Ballman3f5e8b82014-02-11 02:47:33 +0000422 return Ret;
Aaron Ballman78440732014-02-04 14:49:21 +0000423}