Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / mfbt / WindowsVersion.h
blobc357a76d2405d24cc9a52dfed15972c3ebc1b5d7
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 IsWindows10BuildOrLater(uint32_t aBuild) {
18 static Atomic<uint32_t> minBuild(0);
19 static Atomic<uint32_t> maxBuild(UINT32_MAX);
21 if (minBuild >= aBuild) {
22 return true;
25 if (aBuild >= maxBuild) {
26 return false;
29 OSVERSIONINFOEXW info;
30 ZeroMemory(&info, sizeof(OSVERSIONINFOEXW));
31 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
32 info.dwMajorVersion = 10;
33 info.dwBuildNumber = aBuild;
35 DWORDLONG conditionMask = 0;
36 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
37 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
38 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
39 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
40 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
42 if (VerifyVersionInfoW(&info,
43 VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER |
44 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
45 conditionMask)) {
46 minBuild = aBuild;
47 return true;
50 maxBuild = aBuild;
51 return false;
54 MOZ_ALWAYS_INLINE bool IsWin10AnniversaryUpdateOrLater() {
55 return IsWindows10BuildOrLater(14393);
58 MOZ_ALWAYS_INLINE bool IsWin10CreatorsUpdateOrLater() {
59 return IsWindows10BuildOrLater(15063);
62 MOZ_ALWAYS_INLINE bool IsWin10FallCreatorsUpdateOrLater() {
63 return IsWindows10BuildOrLater(16299);
66 MOZ_ALWAYS_INLINE bool IsWin10Sep2018UpdateOrLater() {
67 return IsWindows10BuildOrLater(17763);
70 MOZ_ALWAYS_INLINE bool IsWin11OrLater() {
71 return IsWindows10BuildOrLater(22000);
74 MOZ_ALWAYS_INLINE bool IsWin1122H2OrLater() {
75 return IsWindows10BuildOrLater(22621);
78 } // namespace mozilla
80 #endif /* mozilla_WindowsVersion_h */