Bumping manifests a=b2g-bump
[gecko.git] / mfbt / WindowsVersion.h
blobfcf24acc2e92c2e64de35ddc3da8669bc410d108
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 MOZ_ALWAYS_INLINE bool
88 IsXPSP3OrLater()
90 return IsWindowsVersionOrLater(0x05010300ul);
93 MOZ_ALWAYS_INLINE bool
94 IsWin2003OrLater()
96 return IsWindowsVersionOrLater(0x05020000ul);
99 MOZ_ALWAYS_INLINE bool
100 IsWin2003SP2OrLater()
102 return IsWindowsVersionOrLater(0x05020200ul);
105 MOZ_ALWAYS_INLINE bool
106 IsVistaOrLater()
108 return IsWindowsVersionOrLater(0x06000000ul);
111 MOZ_ALWAYS_INLINE bool
112 IsVistaSP1OrLater()
114 return IsWindowsVersionOrLater(0x06000100ul);
117 MOZ_ALWAYS_INLINE bool
118 IsWin7OrLater()
120 return IsWindowsVersionOrLater(0x06010000ul);
123 MOZ_ALWAYS_INLINE bool
124 IsWin7SP1OrLater()
126 return IsWindowsVersionOrLater(0x06010100ul);
129 MOZ_ALWAYS_INLINE bool
130 IsWin8OrLater()
132 return IsWindowsVersionOrLater(0x06020000ul);
135 MOZ_ALWAYS_INLINE bool
136 IsNotWin7PreRTM()
138 return IsWin7SP1OrLater() || !IsWin7OrLater() ||
139 IsWindowsBuildOrLater(7600);
142 } // namespace mozilla
144 #endif /* mozilla_WindowsVersion_h */