Backed out changeset 3fc04d8eb32b (bug 1659763) for frame checker crashes. a=backout
[gecko.git] / mfbt / WindowsVersion.h
blob9ee3c421ce72827991b69b4aa8c4ec2518642a25
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 IsWin11OrLater() {
166 return IsWindows10BuildOrLater(22000);
169 MOZ_ALWAYS_INLINE bool IsNotWin7PreRTM() {
170 return IsWin7SP1OrLater() || IsWindowsBuildOrLater(7600);
173 inline bool IsWin7AndPre2000Compatible() {
175 * See Bug 1279171.
176 * We'd like to avoid using WMF on specific OS version when compatibility
177 * mode is in effect. The purpose of this function is to check if FF runs on
178 * Win7 OS with application compatibility mode being set to 95/98/ME.
179 * Those compatibility mode options (95/98/ME) can only display and
180 * be selected for 32-bit application.
181 * If the compatibility mode is in effect, the GetVersionEx function will
182 * report the OS as it identifies itself, which may not be the OS that is
183 * installed.
184 * Note : 1) We only target for Win7 build number greater than 7600.
185 * 2) GetVersionEx may be altered or unavailable for release after
186 * Win8.1. Set pragma to avoid build warning as error.
188 bool isWin7 = IsNotWin7PreRTM() && !IsWin8OrLater();
189 if (!isWin7) {
190 return false;
193 OSVERSIONINFOEXW info;
194 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
196 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
197 #pragma warning(push)
198 #pragma warning(disable : 4996)
199 bool success = GetVersionExW((LPOSVERSIONINFOW)&info);
200 #pragma warning(pop)
201 if (!success) {
202 return false;
204 return info.dwMajorVersion < 5;
207 // Whether we're a Windows 11 build with "Suggested actions" feature which
208 // causes hangs. See bug 1774285.
209 MOZ_ALWAYS_INLINE bool NeedsWindows11SuggestedActionsWorkaround() {
210 return IsWindows10BuildOrLater(22621);
213 } // namespace mozilla
215 #endif /* mozilla_WindowsVersion_h */