Bumping manifests a=b2g-bump
[gecko.git] / mfbt / WindowsVersion.h
blob2e9621cb5d6e92d997847606051607394aafc933
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/Attributes.h"
11 #include <stdint.h>
12 #include <windows.h>
14 namespace mozilla {
16 inline bool
17 IsWindowsVersionOrLater(uint32_t aVersion)
19 static uint32_t minVersion = 0;
20 static uint32_t maxVersion = UINT32_MAX;
22 if (minVersion >= aVersion) {
23 return true;
26 if (aVersion >= maxVersion) {
27 return false;
30 OSVERSIONINFOEX info;
31 ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
32 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
33 info.dwMajorVersion = aVersion >> 24;
34 info.dwMinorVersion = (aVersion >> 16) & 0xFF;
35 info.wServicePackMajor = (aVersion >> 8) & 0xFF;
36 info.wServicePackMinor = aVersion & 0xFF;
38 DWORDLONG conditionMask = 0;
39 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
40 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
41 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
42 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
44 if (VerifyVersionInfo(&info,
45 VER_MAJORVERSION | VER_MINORVERSION |
46 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
47 conditionMask)) {
48 minVersion = aVersion;
49 return true;
52 maxVersion = aVersion;
53 return false;
56 inline bool
57 IsWindowsBuildOrLater(uint32_t aBuild)
59 static uint32_t minBuild = 0;
60 static uint32_t maxBuild = UINT32_MAX;
62 if (minBuild >= aBuild) {
63 return true;
66 if (aBuild >= maxBuild) {
67 return false;
70 OSVERSIONINFOEX info;
71 ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
72 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
73 info.dwBuildNumber = aBuild;
75 DWORDLONG conditionMask = 0;
76 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
78 if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) {
79 minBuild = aBuild;
80 return true;
83 maxBuild = aBuild;
84 return false;
87 #if defined(_M_X64) || defined(_M_AMD64)
88 // We support only Win7 or later on Win64.
89 MOZ_ALWAYS_INLINE bool
90 IsXPSP3OrLater()
92 return true;
95 MOZ_ALWAYS_INLINE bool
96 IsWin2003OrLater()
98 return true;
101 MOZ_ALWAYS_INLINE bool
102 IsWin2003SP2OrLater()
104 return true;
107 MOZ_ALWAYS_INLINE bool
108 IsVistaOrLater()
110 return true;
113 MOZ_ALWAYS_INLINE bool
114 IsVistaSP1OrLater()
116 return true;
119 MOZ_ALWAYS_INLINE bool
120 IsWin7OrLater()
122 return true;
124 #else
125 MOZ_ALWAYS_INLINE bool
126 IsXPSP3OrLater()
128 return IsWindowsVersionOrLater(0x05010300ul);
131 MOZ_ALWAYS_INLINE bool
132 IsWin2003OrLater()
134 return IsWindowsVersionOrLater(0x05020000ul);
137 MOZ_ALWAYS_INLINE bool
138 IsWin2003SP2OrLater()
140 return IsWindowsVersionOrLater(0x05020200ul);
143 MOZ_ALWAYS_INLINE bool
144 IsVistaOrLater()
146 return IsWindowsVersionOrLater(0x06000000ul);
149 MOZ_ALWAYS_INLINE bool
150 IsVistaSP1OrLater()
152 return IsWindowsVersionOrLater(0x06000100ul);
155 MOZ_ALWAYS_INLINE bool
156 IsWin7OrLater()
158 return IsWindowsVersionOrLater(0x06010000ul);
160 #endif
162 MOZ_ALWAYS_INLINE bool
163 IsWin7SP1OrLater()
165 return IsWindowsVersionOrLater(0x06010100ul);
168 MOZ_ALWAYS_INLINE bool
169 IsWin8OrLater()
171 return IsWindowsVersionOrLater(0x06020000ul);
174 MOZ_ALWAYS_INLINE bool
175 IsNotWin7PreRTM()
177 return IsWin7SP1OrLater() || !IsWin7OrLater() ||
178 IsWindowsBuildOrLater(7600);
181 } // namespace mozilla
183 #endif /* mozilla_WindowsVersion_h */