Bug 1714154 [wpt PR 29187] - Fix OOF fragments to be up-to-date under certain conditi...
[gecko.git] / mfbt / WindowsVersion.h
blob502015382195a78a96c7b77a65aafed48956ddfc
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/. */
7 #ifndef mozilla_WindowsVersion_h
8 #define mozilla_WindowsVersion_h
10 #include "mozilla/Atomics.h"
11 #include "mozilla/Attributes.h"
12 #include <stdint.h>
13 #include <windows.h>
15 namespace mozilla {
17 inline bool IsWindowsVersionOrLater(uint32_t aVersion) {
18 static Atomic<uint32_t> minVersion(0);
19 static Atomic<uint32_t> maxVersion(UINT32_MAX);
21 if (minVersion >= aVersion) {
22 return true;
25 if (aVersion >= maxVersion) {
26 return false;
29 OSVERSIONINFOEXW info;
30 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
31 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
32 info.dwMajorVersion = aVersion >> 24;
33 info.dwMinorVersion = (aVersion >> 16) & 0xFF;
34 info.wServicePackMajor = (aVersion >> 8) & 0xFF;
35 info.wServicePackMinor = aVersion & 0xFF;
37 DWORDLONG conditionMask = 0;
38 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
39 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
40 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
41 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
43 if (VerifyVersionInfoW(&info,
44 VER_MAJORVERSION | VER_MINORVERSION |
45 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
46 conditionMask)) {
47 minVersion = aVersion;
48 return true;
51 maxVersion = aVersion;
52 return false;
55 inline bool IsWindowsBuildOrLater(uint32_t aBuild) {
56 static Atomic<uint32_t> minBuild(0);
57 static Atomic<uint32_t> maxBuild(UINT32_MAX);
59 if (minBuild >= aBuild) {
60 return true;
63 if (aBuild >= maxBuild) {
64 return false;
67 OSVERSIONINFOEXW info;
68 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
69 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
70 info.dwBuildNumber = aBuild;
72 DWORDLONG conditionMask = 0;
73 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
75 if (VerifyVersionInfoW(&info, VER_BUILDNUMBER, conditionMask)) {
76 minBuild = aBuild;
77 return true;
80 maxBuild = aBuild;
81 return false;
84 inline bool IsWindows10BuildOrLater(uint32_t aBuild) {
85 static Atomic<uint32_t> minBuild(0);
86 static Atomic<uint32_t> maxBuild(UINT32_MAX);
88 if (minBuild >= aBuild) {
89 return true;
92 if (aBuild >= maxBuild) {
93 return false;
96 OSVERSIONINFOEXW info;
97 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
98 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
99 info.dwMajorVersion = 10;
100 info.dwBuildNumber = aBuild;
102 DWORDLONG conditionMask = 0;
103 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
104 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
105 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
106 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
107 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
109 if (VerifyVersionInfoW(&info,
110 VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER |
111 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
112 conditionMask)) {
113 minBuild = aBuild;
114 return true;
117 maxBuild = aBuild;
118 return false;
121 MOZ_ALWAYS_INLINE bool IsWin7SP1OrLater() {
122 return IsWindowsVersionOrLater(0x06010100ul);
125 MOZ_ALWAYS_INLINE bool IsWin8OrLater() {
126 return IsWindowsVersionOrLater(0x06020000ul);
129 MOZ_ALWAYS_INLINE bool IsWin8Point1OrLater() {
130 return IsWindowsVersionOrLater(0x06030000ul);
133 MOZ_ALWAYS_INLINE bool IsWin10OrLater() {
134 return IsWindowsVersionOrLater(0x0a000000ul);
137 MOZ_ALWAYS_INLINE bool IsWin10November2015UpdateOrLater() {
138 return IsWindows10BuildOrLater(10586);
141 MOZ_ALWAYS_INLINE bool IsWin10AnniversaryUpdateOrLater() {
142 return IsWindows10BuildOrLater(14393);
145 MOZ_ALWAYS_INLINE bool IsWin10CreatorsUpdateOrLater() {
146 return IsWindows10BuildOrLater(15063);
149 MOZ_ALWAYS_INLINE bool IsWin10FallCreatorsUpdateOrLater() {
150 return IsWindows10BuildOrLater(16299);
153 MOZ_ALWAYS_INLINE bool IsWin10April2018UpdateOrLater() {
154 return IsWindows10BuildOrLater(17134);
157 MOZ_ALWAYS_INLINE bool IsWin10Sep2018UpdateOrLater() {
158 return IsWindows10BuildOrLater(17763);
161 MOZ_ALWAYS_INLINE bool IsWin10May2019UpdateOrLater() {
162 return IsWindows10BuildOrLater(18362);
165 MOZ_ALWAYS_INLINE bool IsNotWin7PreRTM() {
166 return IsWin7SP1OrLater() || IsWindowsBuildOrLater(7600);
169 inline bool IsWin7AndPre2000Compatible() {
171 * See Bug 1279171.
172 * We'd like to avoid using WMF on specific OS version when compatibility
173 * mode is in effect. The purpose of this function is to check if FF runs on
174 * Win7 OS with application compatibility mode being set to 95/98/ME.
175 * Those compatibility mode options (95/98/ME) can only display and
176 * be selected for 32-bit application.
177 * If the compatibility mode is in effect, the GetVersionEx function will
178 * report the OS as it identifies itself, which may not be the OS that is
179 * installed.
180 * Note : 1) We only target for Win7 build number greater than 7600.
181 * 2) GetVersionEx may be altered or unavailable for release after
182 * Win8.1. Set pragma to avoid build warning as error.
184 bool isWin7 = IsNotWin7PreRTM() && !IsWin8OrLater();
185 if (!isWin7) {
186 return false;
189 OSVERSIONINFOEXW info;
190 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
192 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
193 #pragma warning(push)
194 #pragma warning(disable : 4996)
195 bool success = GetVersionExW((LPOSVERSIONINFOW)&info);
196 #pragma warning(pop)
197 if (!success) {
198 return false;
200 return info.dwMajorVersion < 5;
203 } // namespace mozilla
205 #endif /* mozilla_WindowsVersion_h */