diff options
author | Moonchild <moonchild@palemoon.org> | 2021-11-24 00:44:06 -0500 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-04-06 22:56:00 +0200 |
commit | af32d0b7d1b6797207d537f050b0328c69d09626 (patch) | |
tree | 107499912a53fff968d68f72dd9f44ae8861bad8 | |
parent | e6c662b5c67830c09df604aff125f7cf5bea3014 (diff) | |
download | uxp-af32d0b7d1b6797207d537f050b0328c69d09626.tar.gz |
Issue #1843 - Expand on WindowsVersion.h to add later versions.
Needs future cleanup because of way too many named individual functions
and redundancy.
-rw-r--r-- | mfbt/WindowsVersion.h | 217 |
1 files changed, 186 insertions, 31 deletions
diff --git a/mfbt/WindowsVersion.h b/mfbt/WindowsVersion.h index 4a44a558cd..2f2cbac22b 100644 --- a/mfbt/WindowsVersion.h +++ b/mfbt/WindowsVersion.h @@ -6,6 +6,7 @@ #ifndef mozilla_WindowsVersion_h #define mozilla_WindowsVersion_h +#include "mozilla/Atomics.h" #include "mozilla/Attributes.h" #include <stdint.h> #include <windows.h> @@ -15,8 +16,8 @@ namespace mozilla { inline bool IsWindowsVersionOrLater(uint32_t aVersion) { - static uint32_t minVersion = 0; - static uint32_t maxVersion = UINT32_MAX; + static Atomic<uint32_t> minVersion(0); + static Atomic<uint32_t> maxVersion(UINT32_MAX); if (minVersion >= aVersion) { return true; @@ -55,8 +56,8 @@ IsWindowsVersionOrLater(uint32_t aVersion) inline bool IsWindowsBuildOrLater(uint32_t aBuild) { - static uint32_t minBuild = 0; - static uint32_t maxBuild = UINT32_MAX; + static Atomic<uint32_t> minBuild(0); + static Atomic<uint32_t> maxBuild(UINT32_MAX); if (minBuild >= aBuild) { return true; @@ -83,78 +84,232 @@ IsWindowsBuildOrLater(uint32_t aBuild) return false; } -// Although many of the older versions are not supported, we should keep -// these entries for completeness (since they don't take any resources of -// note), and to cater to corner cases for applications running e.g. in -// Windows' compatibility mode. +inline bool +IsWindows10BuildOrLater(uint32_t aBuild) +{ + static Atomic<uint32_t> minBuild(0); + static Atomic<uint32_t> maxBuild(UINT32_MAX); + if (minBuild >= aBuild) { + return true; + } + + if (aBuild >= maxBuild) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + info.dwMajorVersion = 10; + info.dwBuildNumber = aBuild; + + DWORDLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); + + if (VerifyVersionInfo(&info, + VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | + VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, + conditionMask)) { + minBuild = aBuild; + return true; + } + + maxBuild = aBuild; + return false; +} + +// Windows 7 MOZ_ALWAYS_INLINE bool -IsXPSP3OrLater() +IsWin7SP1OrLater() { - return IsWindowsVersionOrLater(0x05010300ul); + return IsWindowsVersionOrLater(0x06010100ul); } +// Windows 8 MOZ_ALWAYS_INLINE bool -IsWin2003OrLater() +IsWin8OrLater() { - return IsWindowsVersionOrLater(0x05020000ul); + return IsWindowsVersionOrLater(0x06020000ul); } +// Windows 8.1 MOZ_ALWAYS_INLINE bool -IsWin2003SP2OrLater() +IsWin8Point1OrLater() { - return IsWindowsVersionOrLater(0x05020200ul); + return IsWindowsVersionOrLater(0x06030000ul); } +// Windows 10 MOZ_ALWAYS_INLINE bool -IsVistaOrLater() +IsWin10OrLater() { - return IsWindowsVersionOrLater(0x06000000ul); + return IsWindowsVersionOrLater(0x0a000000ul); } +// Windows 10 - RTM MOZ_ALWAYS_INLINE bool -IsVistaSP1OrLater() +IsWin10v1507OrLater() { - return IsWindowsVersionOrLater(0x06000100ul); + return IsWindows10BuildOrLater(10240); } +// Windows 10 - November Update MOZ_ALWAYS_INLINE bool -IsWin7OrLater() +IsWin10November2015UpdateOrLater() { - return IsWindowsVersionOrLater(0x06010000ul); + return IsWindows10BuildOrLater(10586); } +// Windows 10 - Redstone 1 - Anniversary Update MOZ_ALWAYS_INLINE bool -IsWin7SP1OrLater() +IsWin10AnniversaryUpdateOrLater() { - return IsWindowsVersionOrLater(0x06010100ul); + return IsWindows10BuildOrLater(14393); } +// Windows 10 - Redstone 2 - Creators Update MOZ_ALWAYS_INLINE bool -IsWin8OrLater() +IsWin10CreatorsUpdateOrLater() { - return IsWindowsVersionOrLater(0x06020000ul); + return IsWindows10BuildOrLater(15063); } +// Windows 10 - Redstone 3 - Fall Creators Update MOZ_ALWAYS_INLINE bool -IsWin8Point1OrLater() +IsWin10FallCreatorsUpdateOrLater() { - return IsWindowsVersionOrLater(0x06030000ul); + return IsWindows10BuildOrLater(16299); } +// Windows 10 - Redstone 4 - April 2018 Update MOZ_ALWAYS_INLINE bool -IsWin10OrLater() +IsWin10April2018UpdateOrLater() { - return IsWindowsVersionOrLater(0x0a000000ul); + return IsWindows10BuildOrLater(17134); } +// Windows 10 - Redstone 5 - September 2018 Update +MOZ_ALWAYS_INLINE bool +IsWin10Sep2018UpdateOrLater() +{ + return IsWindows10BuildOrLater(17763); +} + +// Windows 10 - 19H1 - May 2019 Update +MOZ_ALWAYS_INLINE bool +IsWin10May2019UpdateOrLater() +{ + return IsWindows10BuildOrLater(18362); +} + +// Windows 11 RTM +MOZ_ALWAYS_INLINE bool +IsWin11OrLater() +{ + // Windows 11 still identifies itself as NT 10. + return IsWindows10BuildOrLater(22000); +} + +// Compatibility version checks for the above for GRE porting. +// XXXMC: Needs cleanup. We shouldn't be using these. +MOZ_ALWAYS_INLINE bool IsWin10v1511OrLater() { return IsWin10November2015UpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1607OrLater() { return IsWin10AnniversaryUpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1703OrLater() { return IsWin10CreatorsUpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1709OrLater() { return IsWin10FallCreatorsUpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1803OrLater() { return IsWin10April2018UpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1809OrLater() { return IsWin10Sep2018UpdateOrLater(); } +MOZ_ALWAYS_INLINE bool IsWin10v1903OrLater() { return IsWin10May2019UpdateOrLater(); } + +// --- Additional granular version checks. +// XXXMC: Not sure why we can't just use IsWindows10BuildOrLater(build) directly, or at least +// a helper function taking an enum or something if build numbers are too difficult to remember. +// Unnecessary indirection and function declaration inflation. Kept for now, needs cleanup. + +// Windows 10 - 19H2 - November 2019 Update +MOZ_ALWAYS_INLINE bool +IsWin10v1909OrLater() +{ + return IsWindows10BuildOrLater(18363); +} + +// Windows 10 - 20H1 - May 2020 Update +MOZ_ALWAYS_INLINE bool +IsWin10v2004OrLater() +{ + return IsWindows10BuildOrLater(19041); +} + +// Windows 10 - 20H2 - October 2020 Update +MOZ_ALWAYS_INLINE bool +IsWin10v20H2OrLater() +{ + return IsWindows10BuildOrLater(19042); +} + +// Windows 10 - 21H1 - May 2021 Update +MOZ_ALWAYS_INLINE bool +IsWin10v21H1OrLater() +{ + return IsWindows10BuildOrLater(19043); +} + +// Windows 10 - 21H2 - November 2021 Update +MOZ_ALWAYS_INLINE bool +IsWin10v21H2OrLater() +{ + return IsWindows10BuildOrLater(19044); +} + +// --- End additional granular version checks. + MOZ_ALWAYS_INLINE bool IsNotWin7PreRTM() { - return IsWin7SP1OrLater() || !IsWin7OrLater() || - IsWindowsBuildOrLater(7600); + return IsWin7SP1OrLater() || IsWindowsBuildOrLater(7600); +} + +// Compatibility Mode +inline bool +IsWin7AndPre2000Compatible() +{ + /* + * See Bug 1279171. + * We'd like to avoid using WMF on specific OS version when compatibility + * mode is in effect. The purpose of this function is to check if FF runs on + * Win7 OS with application compatibility mode being set to 95/98/ME. + * Those compatibility mode options (95/98/ME) can only display and + * be selected for 32-bit application. + * If the compatibility mode is in effect, the GetVersionEx function will + * report the OS as it identifies itself, which may not be the OS that is + * installed. + * Note : 1) We only target for Win7 build number greater than 7600. + * 2) GetVersionEx may be altered or unavailable for release after + * Win8.1. Set pragma to avoid build warning as error. + */ + bool isWin7 = IsNotWin7PreRTM() && !IsWin8OrLater(); + if (!isWin7) { + return false; + } + + OSVERSIONINFOEX info; + ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); + + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); +#pragma warning(push) +#pragma warning(disable : 4996) + bool success = GetVersionEx((LPOSVERSIONINFO)&info); +#pragma warning(pop) + if (!success) { + return false; + } + return info.dwMajorVersion < 5; } -} // namespace mozilla +} // namespace mozilla #endif /* mozilla_WindowsVersion_h */ |