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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_WindowsVersion_h
6 #define mozilla_WindowsVersion_h
8 #include "mozilla/Attributes.h"
9 #include <stdint.h>
10 #include <windows.h>
12 namespace mozilla
13 {
14 inline bool
15 IsWindowsVersionOrLater(uint32_t aVersion)
16 {
17 static uint32_t minVersion = 0;
18 static uint32_t maxVersion = UINT32_MAX;
20 if (minVersion >= aVersion) {
21 return true;
22 }
24 if (aVersion >= maxVersion) {
25 return false;
26 }
28 OSVERSIONINFOEX info;
29 ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
30 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
31 info.dwMajorVersion = aVersion >> 24;
32 info.dwMinorVersion = (aVersion >> 16) & 0xFF;
33 info.wServicePackMajor = (aVersion >> 8) & 0xFF;
34 info.wServicePackMinor = aVersion & 0xFF;
36 DWORDLONG conditionMask = 0;
37 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
38 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, 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 (VerifyVersionInfo(&info,
43 VER_MAJORVERSION | VER_MINORVERSION |
44 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
45 conditionMask)) {
46 minVersion = aVersion;
47 return true;
48 }
50 maxVersion = aVersion;
51 return false;
52 }
54 inline bool
55 IsWindowsBuildOrLater(uint32_t aBuild)
56 {
57 static uint32_t minBuild = 0;
58 static uint32_t maxBuild = UINT32_MAX;
60 if (minBuild >= aBuild) {
61 return true;
62 }
64 if (aBuild >= maxBuild) {
65 return false;
66 }
68 OSVERSIONINFOEX info;
69 ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
70 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
71 info.dwBuildNumber = aBuild;
73 DWORDLONG conditionMask = 0;
74 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
76 if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) {
77 minBuild = aBuild;
78 return true;
79 }
81 maxBuild = aBuild;
82 return false;
83 }
85 MOZ_ALWAYS_INLINE bool
86 IsXPSP3OrLater()
87 { return IsWindowsVersionOrLater(0x05010300ul); }
89 MOZ_ALWAYS_INLINE bool
90 IsWin2003OrLater()
91 { return IsWindowsVersionOrLater(0x05020000ul); }
93 MOZ_ALWAYS_INLINE bool
94 IsWin2003SP2OrLater()
95 { return IsWindowsVersionOrLater(0x05020200ul); }
97 MOZ_ALWAYS_INLINE bool
98 IsVistaOrLater()
99 { return IsWindowsVersionOrLater(0x06000000ul); }
101 MOZ_ALWAYS_INLINE bool
102 IsVistaSP1OrLater()
103 { return IsWindowsVersionOrLater(0x06000100ul); }
105 MOZ_ALWAYS_INLINE bool
106 IsWin7OrLater()
107 { return IsWindowsVersionOrLater(0x06010000ul); }
109 MOZ_ALWAYS_INLINE bool
110 IsWin7SP1OrLater()
111 { return IsWindowsVersionOrLater(0x06010100ul); }
113 MOZ_ALWAYS_INLINE bool
114 IsWin8OrLater()
115 { return IsWindowsVersionOrLater(0x06020000ul); }
117 MOZ_ALWAYS_INLINE bool
118 IsNotWin7PreRTM()
119 {
120 return IsWin7SP1OrLater() || !IsWin7OrLater() ||
121 IsWindowsBuildOrLater(7600);
122 }
123 }
125 #endif /* mozilla_WindowsVersion_h */