Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_WindowsVersion_h |
michael@0 | 6 | #define mozilla_WindowsVersion_h |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Attributes.h" |
michael@0 | 9 | #include <stdint.h> |
michael@0 | 10 | #include <windows.h> |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla |
michael@0 | 13 | { |
michael@0 | 14 | inline bool |
michael@0 | 15 | IsWindowsVersionOrLater(uint32_t aVersion) |
michael@0 | 16 | { |
michael@0 | 17 | static uint32_t minVersion = 0; |
michael@0 | 18 | static uint32_t maxVersion = UINT32_MAX; |
michael@0 | 19 | |
michael@0 | 20 | if (minVersion >= aVersion) { |
michael@0 | 21 | return true; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | if (aVersion >= maxVersion) { |
michael@0 | 25 | return false; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | OSVERSIONINFOEX info; |
michael@0 | 29 | ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
michael@0 | 30 | info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
michael@0 | 31 | info.dwMajorVersion = aVersion >> 24; |
michael@0 | 32 | info.dwMinorVersion = (aVersion >> 16) & 0xFF; |
michael@0 | 33 | info.wServicePackMajor = (aVersion >> 8) & 0xFF; |
michael@0 | 34 | info.wServicePackMinor = aVersion & 0xFF; |
michael@0 | 35 | |
michael@0 | 36 | DWORDLONG conditionMask = 0; |
michael@0 | 37 | VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); |
michael@0 | 38 | VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); |
michael@0 | 39 | VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); |
michael@0 | 40 | VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); |
michael@0 | 41 | |
michael@0 | 42 | if (VerifyVersionInfo(&info, |
michael@0 | 43 | VER_MAJORVERSION | VER_MINORVERSION | |
michael@0 | 44 | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, |
michael@0 | 45 | conditionMask)) { |
michael@0 | 46 | minVersion = aVersion; |
michael@0 | 47 | return true; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | maxVersion = aVersion; |
michael@0 | 51 | return false; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | inline bool |
michael@0 | 55 | IsWindowsBuildOrLater(uint32_t aBuild) |
michael@0 | 56 | { |
michael@0 | 57 | static uint32_t minBuild = 0; |
michael@0 | 58 | static uint32_t maxBuild = UINT32_MAX; |
michael@0 | 59 | |
michael@0 | 60 | if (minBuild >= aBuild) { |
michael@0 | 61 | return true; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | if (aBuild >= maxBuild) { |
michael@0 | 65 | return false; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | OSVERSIONINFOEX info; |
michael@0 | 69 | ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
michael@0 | 70 | info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
michael@0 | 71 | info.dwBuildNumber = aBuild; |
michael@0 | 72 | |
michael@0 | 73 | DWORDLONG conditionMask = 0; |
michael@0 | 74 | VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); |
michael@0 | 75 | |
michael@0 | 76 | if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) { |
michael@0 | 77 | minBuild = aBuild; |
michael@0 | 78 | return true; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | maxBuild = aBuild; |
michael@0 | 82 | return false; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | MOZ_ALWAYS_INLINE bool |
michael@0 | 86 | IsXPSP3OrLater() |
michael@0 | 87 | { return IsWindowsVersionOrLater(0x05010300ul); } |
michael@0 | 88 | |
michael@0 | 89 | MOZ_ALWAYS_INLINE bool |
michael@0 | 90 | IsWin2003OrLater() |
michael@0 | 91 | { return IsWindowsVersionOrLater(0x05020000ul); } |
michael@0 | 92 | |
michael@0 | 93 | MOZ_ALWAYS_INLINE bool |
michael@0 | 94 | IsWin2003SP2OrLater() |
michael@0 | 95 | { return IsWindowsVersionOrLater(0x05020200ul); } |
michael@0 | 96 | |
michael@0 | 97 | MOZ_ALWAYS_INLINE bool |
michael@0 | 98 | IsVistaOrLater() |
michael@0 | 99 | { return IsWindowsVersionOrLater(0x06000000ul); } |
michael@0 | 100 | |
michael@0 | 101 | MOZ_ALWAYS_INLINE bool |
michael@0 | 102 | IsVistaSP1OrLater() |
michael@0 | 103 | { return IsWindowsVersionOrLater(0x06000100ul); } |
michael@0 | 104 | |
michael@0 | 105 | MOZ_ALWAYS_INLINE bool |
michael@0 | 106 | IsWin7OrLater() |
michael@0 | 107 | { return IsWindowsVersionOrLater(0x06010000ul); } |
michael@0 | 108 | |
michael@0 | 109 | MOZ_ALWAYS_INLINE bool |
michael@0 | 110 | IsWin7SP1OrLater() |
michael@0 | 111 | { return IsWindowsVersionOrLater(0x06010100ul); } |
michael@0 | 112 | |
michael@0 | 113 | MOZ_ALWAYS_INLINE bool |
michael@0 | 114 | IsWin8OrLater() |
michael@0 | 115 | { return IsWindowsVersionOrLater(0x06020000ul); } |
michael@0 | 116 | |
michael@0 | 117 | MOZ_ALWAYS_INLINE bool |
michael@0 | 118 | IsNotWin7PreRTM() |
michael@0 | 119 | { |
michael@0 | 120 | return IsWin7SP1OrLater() || !IsWin7OrLater() || |
michael@0 | 121 | IsWindowsBuildOrLater(7600); |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | #endif /* mozilla_WindowsVersion_h */ |