|
41 | 41 | #include "llvm/Config/config.h" // Get build system configuration settings
|
42 | 42 | #include "llvm/Support/Chrono.h"
|
43 | 43 | #include "llvm/Support/Compiler.h"
|
| 44 | +#include "llvm/Support/VersionTuple.h" |
44 | 45 | #include <cassert>
|
45 | 46 | #include <string>
|
46 | 47 | #include <system_error>
|
@@ -71,6 +72,40 @@ inline bool RunningWindows8OrGreater() {
|
71 | 72 | Mask) != FALSE;
|
72 | 73 | }
|
73 | 74 |
|
| 75 | +typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); |
| 76 | +#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) |
| 77 | + |
| 78 | +inline llvm::VersionTuple GetWindowsOSVersion() { |
| 79 | + HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); |
| 80 | + if (hMod) { |
| 81 | + auto getVer = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion"); |
| 82 | + if (getVer) { |
| 83 | + RTL_OSVERSIONINFOEXW info{}; |
| 84 | + info.dwOSVersionInfoSize = sizeof(info); |
| 85 | + if (getVer((PRTL_OSVERSIONINFOW)&info) == STATUS_SUCCESS) { |
| 86 | + return llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0, |
| 87 | + info.dwBuildNumber); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + OSVERSIONINFOEX info; |
| 93 | + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
| 94 | + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
| 95 | +#pragma warning(push) |
| 96 | +#pragma warning(disable : 4996) |
| 97 | + // Starting with Microsoft SDK for Windows 8.1, this function is deprecated |
| 98 | + // in favor of the new Windows Version Helper APIs. Since we don't specify a |
| 99 | + // minimum SDK version, it's easier to simply disable the warning rather than |
| 100 | + // try to support both APIs. |
| 101 | + if (GetVersionEx((LPOSVERSIONINFO)&info) == 0) |
| 102 | + return llvm::VersionTuple(); |
| 103 | +#pragma warning(pop) |
| 104 | + |
| 105 | + return llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion, 0, |
| 106 | + info.dwBuildNumber); |
| 107 | +} |
| 108 | + |
74 | 109 | inline bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix) {
|
75 | 110 | if (!ErrMsg)
|
76 | 111 | return true;
|
|
0 commit comments