-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path66cd264007c372347e54bfc812a380e5be993871.diff
393 lines (342 loc) · 15.7 KB
/
66cd264007c372347e54bfc812a380e5be993871.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
diff --git a/base/memory/platform_shared_memory_region_win.cc b/base/memory/platform_shared_memory_region_win.cc
index 96986601f6282..9fb72b5cefb1d 100644
--- a/base/memory/platform_shared_memory_region_win.cc
+++ b/base/memory/platform_shared_memory_region_win.cc
@@ -14,10 +14,15 @@
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process_handle.h"
+#include "base/rand_util.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/win/windows_version.h"
#include "partition_alloc/page_allocator.h"
-namespace base::subtle {
+namespace base {
+namespace subtle {
namespace {
@@ -211,6 +216,18 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Create(Mode mode,
}
std::u16string name;
+ if (win::GetVersion() < win::Version::WIN8_1) {
+ // Windows < 8.1 ignores DACLs on certain unnamed objects (like shared
+ // sections). So, we generate a random name when we need to enforce
+ // read-only.
+ uint64_t rand_values[4];
+ RandBytes(base::byte_span_from_ref(rand_values));
+ name = ASCIIToUTF16(StringPrintf("CrSharedMem_%016llx%016llx%016llx%016llx",
+ rand_values[0], rand_values[1],
+ rand_values[2], rand_values[3]));
+ DCHECK(!name.empty());
+ }
+
SECURITY_ATTRIBUTES sa = {sizeof(sa), &sd, FALSE};
// Ask for the file mapping with reduced permisions to avoid passing the
// access control permissions granted by default into unpriviledged process.
@@ -267,4 +284,5 @@ PlatformSharedMemoryRegion::PlatformSharedMemoryRegion(
const UnguessableToken& guid)
: handle_(std::move(handle)), mode_(mode), size_(size), guid_(guid) {}
-} // namespace base::subtle
+} // namespace subtle
+} // namespace base
diff --git a/base/win/scoped_handle_unittest.cc b/base/win/scoped_handle_unittest.cc
index 3642542777e69..e96d6bff99a49 100644
--- a/base/win/scoped_handle_unittest.cc
+++ b/base/win/scoped_handle_unittest.cc
@@ -15,6 +15,7 @@
#include "base/scoped_native_library.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
+#include "base/win/windows_version.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
@@ -34,6 +35,18 @@ std::string FailureMessage(const std::string& msg) {
#endif // defined(NDEBUG) && defined(OFFICIAL_BUILD)
}
+// Death tests don't seem to work on Windows 7 32-bit native with hooks enabled.
+bool DoDeathTestsWork() {
+#if defined(ARCH_CPU_32_BITS)
+ const auto* os_info = base::win::OSInfo::GetInstance();
+ if (os_info->version() <= base::win::Version::WIN7 &&
+ os_info->IsWowDisabled()) {
+ return false;
+ }
+#endif // defined(ARCH_CPU_32_BITS)
+ return true;
+}
+
} // namespace
namespace testing {
@@ -69,6 +82,9 @@ TEST_F(ScopedHandleTest, ScopedHandle) {
}
TEST_F(ScopedHandleDeathTest, HandleVerifierTrackedHasBeenClosed) {
+ // This test is only valid if hooks are enabled.
+ if (!DoDeathTestsWork())
+ return;
HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
ASSERT_NE(HANDLE(nullptr), handle);
@@ -83,6 +99,10 @@ TEST_F(ScopedHandleDeathTest, HandleVerifierTrackedHasBeenClosed) {
}
TEST_F(ScopedHandleDeathTest, HandleVerifierCloseTrackedHandle) {
+ // This test is only valid if hooks are enabled.
+ if (!DoDeathTestsWork())
+ return;
+
ASSERT_DEATH(
{
HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
@@ -105,6 +125,9 @@ TEST_F(ScopedHandleDeathTest, HandleVerifierCloseTrackedHandle) {
}
TEST_F(ScopedHandleDeathTest, HandleVerifierDoubleTracking) {
+ if (!DoDeathTestsWork())
+ return;
+
HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
ASSERT_NE(HANDLE(nullptr), handle);
@@ -115,6 +138,9 @@ TEST_F(ScopedHandleDeathTest, HandleVerifierDoubleTracking) {
}
TEST_F(ScopedHandleDeathTest, HandleVerifierWrongOwner) {
+ if (!DoDeathTestsWork())
+ return;
+
HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
ASSERT_NE(HANDLE(nullptr), handle);
@@ -130,6 +156,9 @@ TEST_F(ScopedHandleDeathTest, HandleVerifierWrongOwner) {
}
TEST_F(ScopedHandleDeathTest, HandleVerifierUntrackedHandle) {
+ if (!DoDeathTestsWork())
+ return;
+
HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
ASSERT_NE(HANDLE(nullptr), handle);
diff --git a/base/win/shortcut_unittest.cc b/base/win/shortcut_unittest.cc
index f0789753e7c47..a69db3b2bd28d 100644
--- a/base/win/shortcut_unittest.cc
+++ b/base/win/shortcut_unittest.cc
@@ -14,6 +14,7 @@
#include "base/test/test_file_util.h"
#include "base/test/test_shortcut_win.h"
#include "base/win/scoped_com_initializer.h"
+#include "base/win/windows_version.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -93,6 +94,11 @@ class ShortcutTest : public testing::Test {
} // namespace
TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
// Test all properties.
FilePath file_1(temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Link1.lnk")));
ASSERT_TRUE(CreateOrUpdateShortcutLink(file_1, link_properties_,
@@ -140,6 +146,10 @@ TEST_F(ShortcutTest, CreateAndResolveShortcutProperties) {
}
TEST_F(ShortcutTest, CreateAndResolveShortcut) {
+ // TODO(crbug.com/1264563): Disabled on Win7 bots for being flaky.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ShortcutProperties only_target_properties;
only_target_properties.set_target(link_properties_.target);
@@ -155,6 +165,10 @@ TEST_F(ShortcutTest, CreateAndResolveShortcut) {
}
TEST_F(ShortcutTest, ResolveShortcutWithArgs) {
+ // TODO(crbug.com/1264563): Disabled on Win7 bots for being flaky.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -169,6 +183,10 @@ TEST_F(ShortcutTest, ResolveShortcutWithArgs) {
}
TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1291225): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
ShortcutProperties target_and_args_properties;
target_and_args_properties.set_target(link_properties_.target);
target_and_args_properties.set_arguments(link_properties_.arguments);
@@ -180,6 +198,9 @@ TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) {
}
TEST_F(ShortcutTest, CreateShortcutVerifyProperties) {
+ // TODO(crbug.com/1264563) Flaky on Win 7.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -187,6 +208,9 @@ TEST_F(ShortcutTest, CreateShortcutVerifyProperties) {
}
TEST_F(ShortcutTest, UpdateShortcutVerifyPropertiess) {
+ // TODO(crbug.com/1264563) Flaky on Win 7.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -197,6 +221,11 @@ TEST_F(ShortcutTest, UpdateShortcutVerifyPropertiess) {
}
TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -220,6 +249,11 @@ TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) {
}
TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -235,6 +269,11 @@ TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) {
}
TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_2_,
ShortcutOperation::kCreateAlways));
@@ -251,6 +290,11 @@ TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) {
}
TEST_F(ShortcutTest, UpdateShortcutClearArguments) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -272,6 +316,11 @@ TEST_F(ShortcutTest, FailUpdateShortcutThatDoesNotExist) {
}
TEST_F(ShortcutTest, ReplaceShortcutAllProperties) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -282,6 +331,11 @@ TEST_F(ShortcutTest, ReplaceShortcutAllProperties) {
}
TEST_F(ShortcutTest, ReplaceShortcutSomeProperties) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
@@ -311,6 +365,11 @@ TEST_F(ShortcutTest, FailReplaceShortcutThatDoesNotExist) {
// Test that the old arguments remain on the replaced shortcut when not
// otherwise specified.
TEST_F(ShortcutTest, ReplaceShortcutKeepOldArguments) {
+ // This test is extremely flaky on Win7, so disable.
+ // TODO(crbug.com/1264563): Investigate why it's so flaky on Win7 bots.
+ if (base::win::OSInfo::GetInstance()->version() <= base::win::Version::WIN7)
+ GTEST_SKIP() << "Skipping test for win7";
+
ASSERT_TRUE(CreateOrUpdateShortcutLink(link_file_, link_properties_,
ShortcutOperation::kCreateAlways));
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index f9d3cec0b5499..6afaa72a24f09 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -101,9 +101,11 @@ POWER_PLATFORM_ROLE GetPlatformRole() {
return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2);
}
-// Because we used to support versions earlier than 8.1, we dynamically load
-// this function from user32.dll, so it won't fail to load in runtime.
-// TODO(https://crbug.com/1408307): Call SetProcessDpiAwareness directly.
+// Method used for Windows 8.1 and later.
+// Since we support versions earlier than 8.1, we must dynamically load this
+// function from user32.dll, so it won't fail to load in runtime. For earlier
+// Windows versions GetProcAddress will return null and report failure so that
+// callers can fall back on the deprecated SetProcessDPIAware.
bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
if (!IsUser32AndGdi32Available())
return false;
@@ -124,7 +126,8 @@ bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
}
- NOTREACHED() << "SetProcessDpiAwarenessInternal "
- "should be available on all platforms >= Windows 8.1";
+ DCHECK_LT(GetVersion(), Version::WIN8_1) << "SetProcessDpiAwarenessInternal "
+ "should be available on all "
+ "platforms >= Windows 8.1";
return false;
}
@@ -299,6 +302,13 @@ bool IsWindows10OrGreaterTabletMode(HWND hwnd) {
bool IsKeyboardPresentOnSlate(HWND hwnd, std::string* reason) {
bool result = false;
+ if (GetVersion() < Version::WIN8) {
+ if (reason)
+ *reason = "Detection not supported";
+ return false;
+ }
+
+ // This function is only supported for Windows 8 and up.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableUsbKeyboardDetect)) {
if (reason) {
@@ -544,6 +554,12 @@ void SetAbortBehaviorForCrashReporting() {
}
bool IsTabletDevice(std::string* reason, HWND hwnd) {
+ if (GetVersion() < Version::WIN8) {
+ if (reason)
+ *reason = "Tablet device detection not supported below Windows 8\n";
+ return false;
+ }
+
if (IsWindows10OrGreaterTabletMode(hwnd))
return true;
@@ -561,6 +577,12 @@ bool IsDeviceUsedAsATablet(std::string* reason) {
// reason is NULL.
std::optional<bool> ret;
+ if (GetVersion() < Version::WIN8) {
+ if (reason)
+ *reason = "Tablet device detection not supported below Windows 8\n";
+ return false;
+ }
+
if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) {
if (!reason) {
return false;
@@ -640,6 +662,10 @@ bool IsUser32AndGdi32Available() {
static const bool is_user32_and_gdi32_available = []() {
// If win32k syscalls aren't disabled, then user32 and gdi32 are available.
+ // Can't disable win32k prior to windows 8.
+ if (GetVersion() < Version::WIN8)
+ return true;
+
using GetProcessMitigationPolicyType =
decltype(GetProcessMitigationPolicy)*;
GetProcessMitigationPolicyType get_process_mitigation_policy_func =
@@ -748,11 +774,15 @@ void EnableHighDPISupport() {
if (EnablePerMonitorV2())
return;
- // Fall back to per-monitor DPI for older versions of Win10.
- PROCESS_DPI_AWARENESS process_dpi_awareness = PROCESS_PER_MONITOR_DPI_AWARE;
+ // Fall back to per-monitor DPI for older versions of Win10 instead of
+ // Win8.1 since Win8.1 does not have EnableChildWindowDpiMessage,
+ // necessary for correct non-client area scaling across monitors.
+ PROCESS_DPI_AWARENESS process_dpi_awareness =
+ GetVersion() >= Version::WIN10 ? PROCESS_PER_MONITOR_DPI_AWARE
+ : PROCESS_SYSTEM_DPI_AWARE;
if (!SetProcessDpiAwarenessWrapper(process_dpi_awareness)) {
- // For windows versions where SetProcessDpiAwareness fails, try its
- // predecessor.
+ // For windows versions where SetProcessDpiAwareness is not available or
+ // failed, try its predecessor.
BOOL result = ::SetProcessDPIAware();
DCHECK(result) << "SetProcessDPIAware failed.";
}