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"
17 IsWindowsVersionOrLater(uint32_t aVersion
)
19 static uint32_t minVersion
= 0;
20 static uint32_t maxVersion
= UINT32_MAX
;
22 if (minVersion
>= aVersion
) {
26 if (aVersion
>= maxVersion
) {
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
,
48 minVersion
= aVersion
;
52 maxVersion
= aVersion
;
57 IsWindowsBuildOrLater(uint32_t aBuild
)
59 static uint32_t minBuild
= 0;
60 static uint32_t maxBuild
= UINT32_MAX
;
62 if (minBuild
>= aBuild
) {
66 if (aBuild
>= maxBuild
) {
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
)) {
87 #if defined(_M_X64) || defined(_M_AMD64)
88 // We support only Win7 or later on Win64.
89 MOZ_ALWAYS_INLINE
bool
95 MOZ_ALWAYS_INLINE
bool
101 MOZ_ALWAYS_INLINE
bool
102 IsWin2003SP2OrLater()
107 MOZ_ALWAYS_INLINE
bool
113 MOZ_ALWAYS_INLINE
bool
119 MOZ_ALWAYS_INLINE
bool
125 MOZ_ALWAYS_INLINE
bool
128 return IsWindowsVersionOrLater(0x05010300ul
);
131 MOZ_ALWAYS_INLINE
bool
134 return IsWindowsVersionOrLater(0x05020000ul
);
137 MOZ_ALWAYS_INLINE
bool
138 IsWin2003SP2OrLater()
140 return IsWindowsVersionOrLater(0x05020200ul
);
143 MOZ_ALWAYS_INLINE
bool
146 return IsWindowsVersionOrLater(0x06000000ul
);
149 MOZ_ALWAYS_INLINE
bool
152 return IsWindowsVersionOrLater(0x06000100ul
);
155 MOZ_ALWAYS_INLINE
bool
158 return IsWindowsVersionOrLater(0x06010000ul
);
162 MOZ_ALWAYS_INLINE
bool
165 return IsWindowsVersionOrLater(0x06010100ul
);
168 MOZ_ALWAYS_INLINE
bool
171 return IsWindowsVersionOrLater(0x06020000ul
);
174 MOZ_ALWAYS_INLINE
bool
177 return IsWin7SP1OrLater() || !IsWin7OrLater() ||
178 IsWindowsBuildOrLater(7600);
181 } // namespace mozilla
183 #endif /* mozilla_WindowsVersion_h */