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"
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
) {
25 if (aVersion
>= maxVersion
) {
30 ZeroMemory(&info
, sizeof(OSVERSIONINFOEX
));
31 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
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 (VerifyVersionInfo(&info
,
44 VER_MAJORVERSION
| VER_MINORVERSION
|
45 VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
47 minVersion
= aVersion
;
51 maxVersion
= aVersion
;
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
) {
63 if (aBuild
>= maxBuild
) {
68 ZeroMemory(&info
, sizeof(OSVERSIONINFOEX
));
69 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
70 info
.dwBuildNumber
= aBuild
;
72 DWORDLONG conditionMask
= 0;
73 VER_SET_CONDITION(conditionMask
, VER_BUILDNUMBER
, VER_GREATER_EQUAL
);
75 if (VerifyVersionInfo(&info
, VER_BUILDNUMBER
, conditionMask
)) {
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
) {
92 if (aBuild
>= maxBuild
) {
97 ZeroMemory(&info
, sizeof(OSVERSIONINFOEX
));
98 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
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 (VerifyVersionInfo(&info
,
110 VER_MAJORVERSION
| VER_MINORVERSION
| VER_BUILDNUMBER
|
111 VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
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 IsNotWin7PreRTM() {
162 return IsWin7SP1OrLater() || IsWindowsBuildOrLater(7600);
165 inline bool IsWin7AndPre2000Compatible() {
168 * We'd like to avoid using WMF on specific OS version when compatibility
169 * mode is in effect. The purpose of this function is to check if FF runs on
170 * Win7 OS with application compatibility mode being set to 95/98/ME.
171 * Those compatibility mode options (95/98/ME) can only display and
172 * be selected for 32-bit application.
173 * If the compatibility mode is in effect, the GetVersionEx function will
174 * report the OS as it identifies itself, which may not be the OS that is
176 * Note : 1) We only target for Win7 build number greater than 7600.
177 * 2) GetVersionEx may be altered or unavailable for release after
178 * Win8.1. Set pragma to avoid build warning as error.
180 bool isWin7
= IsNotWin7PreRTM() && !IsWin8OrLater();
185 OSVERSIONINFOEX info
;
186 ZeroMemory(&info
, sizeof(OSVERSIONINFOEX
));
188 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
189 #pragma warning(push)
190 #pragma warning(disable : 4996)
191 bool success
= GetVersionEx((LPOSVERSIONINFO
)&info
);
196 return info
.dwMajorVersion
< 5;
199 } // namespace mozilla
201 #endif /* mozilla_WindowsVersion_h */