WindowsVersion.h (2313B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_WindowsVersion_h 8 #define mozilla_WindowsVersion_h 9 10 #include "mozilla/Atomics.h" 11 #include "mozilla/Attributes.h" 12 #include <stdint.h> 13 #include <windows.h> 14 15 namespace mozilla { 16 17 inline bool IsWindows10BuildOrLater(uint32_t aBuild) { 18 static Atomic<uint32_t> minBuild(0); 19 static Atomic<uint32_t> maxBuild(UINT32_MAX); 20 21 if (minBuild >= aBuild) { 22 return true; 23 } 24 25 if (aBuild >= maxBuild) { 26 return false; 27 } 28 29 OSVERSIONINFOEXW info; 30 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW)); 31 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); 32 info.dwMajorVersion = 10; 33 info.dwBuildNumber = aBuild; 34 35 DWORDLONG conditionMask = 0; 36 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); 37 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); 38 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); 39 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); 40 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); 41 42 if (VerifyVersionInfoW(&info, 43 VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | 44 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, 45 conditionMask)) { 46 minBuild = aBuild; 47 return true; 48 } 49 50 maxBuild = aBuild; 51 return false; 52 } 53 54 MOZ_ALWAYS_INLINE bool IsWin10AnniversaryUpdateOrLater() { 55 return IsWindows10BuildOrLater(14393); 56 } 57 58 MOZ_ALWAYS_INLINE bool IsWin10CreatorsUpdateOrLater() { 59 return IsWindows10BuildOrLater(15063); 60 } 61 62 MOZ_ALWAYS_INLINE bool IsWin10FallCreatorsUpdateOrLater() { 63 return IsWindows10BuildOrLater(16299); 64 } 65 66 MOZ_ALWAYS_INLINE bool IsWin10Sep2018UpdateOrLater() { 67 return IsWindows10BuildOrLater(17763); 68 } 69 70 MOZ_ALWAYS_INLINE bool IsWin11OrLater() { 71 return IsWindows10BuildOrLater(22000); 72 } 73 74 MOZ_ALWAYS_INLINE bool IsWin1122H2OrLater() { 75 return IsWindows10BuildOrLater(22621); 76 } 77 78 } // namespace mozilla 79 80 #endif /* mozilla_WindowsVersion_h */