Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: sandbox/win/src/process_policy_test.cc

Issue 1684963003: Use double cast to avoid VS 2015 64-bit warning (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Double casts for DWORD to ptr also Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 L"ProcessPolicyTest_%08x", pid); 277 L"ProcessPolicyTest_%08x", pid);
278 if (-1 != res) { 278 if (-1 != res) {
279 return std::wstring(buff); 279 return std::wstring(buff);
280 } 280 }
281 return std::wstring(); 281 return std::wstring();
282 } 282 }
283 283
284 // This is the function that is called when testing thread creation. 284 // This is the function that is called when testing thread creation.
285 // It is expected to set an event that the caller is waiting on. 285 // It is expected to set an event that the caller is waiting on.
286 DWORD TestThreadFunc(LPVOID lpdwThreadParam) { 286 DWORD TestThreadFunc(LPVOID lpdwThreadParam) {
287 std::wstring event_name = 287 std::wstring event_name = GenerateEventName(
288 GenerateEventName(reinterpret_cast<DWORD>(lpdwThreadParam)); 288 static_cast<DWORD>(reinterpret_cast<uintptr_t>(lpdwThreadParam)));
289 if (!event_name.length()) { 289 if (!event_name.length()) {
290 return 1; 290 return 1;
291 } 291 }
292 HANDLE event = ::OpenEvent(EVENT_ALL_ACCESS | EVENT_MODIFY_STATE, FALSE, 292 HANDLE event = ::OpenEvent(EVENT_ALL_ACCESS | EVENT_MODIFY_STATE, FALSE,
293 event_name.c_str()); 293 event_name.c_str());
294 if (!event) { 294 if (!event) {
295 return 1; 295 return 1;
296 } 296 }
297 if (!SetEvent(event)) { 297 if (!SetEvent(event)) {
298 return 1; 298 return 1;
299 } 299 }
300 return 0; 300 return 0;
301 } 301 }
302 302
303 SBOX_TESTS_COMMAND int Process_CreateThread(int argc, wchar_t** argv) { 303 SBOX_TESTS_COMMAND int Process_CreateThread(int argc, wchar_t** argv) {
304 DWORD pid = ::GetCurrentProcessId(); 304 DWORD pid = ::GetCurrentProcessId();
305 std::wstring event_name = GenerateEventName(pid); 305 std::wstring event_name = GenerateEventName(pid);
306 if (!event_name.length()) { 306 if (!event_name.length()) {
307 return SBOX_TEST_FIRST_ERROR; 307 return SBOX_TEST_FIRST_ERROR;
308 } 308 }
309 HANDLE event = ::CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); 309 HANDLE event = ::CreateEvent(NULL, TRUE, FALSE, event_name.c_str());
310 if (!event) { 310 if (!event) {
311 return SBOX_TEST_SECOND_ERROR; 311 return SBOX_TEST_SECOND_ERROR;
312 } 312 }
313 313
314 DWORD thread_id = 0; 314 DWORD thread_id = 0;
315 HANDLE thread = NULL; 315 HANDLE thread = NULL;
316 thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc, 316 thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc,
317 reinterpret_cast<LPVOID>(pid), 0, &thread_id); 317 reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)),
318 0, &thread_id);
318 319
319 if (!thread) { 320 if (!thread) {
320 return SBOX_TEST_THIRD_ERROR; 321 return SBOX_TEST_THIRD_ERROR;
321 } 322 }
322 if (!thread_id) { 323 if (!thread_id) {
323 return SBOX_TEST_FOURTH_ERROR; 324 return SBOX_TEST_FOURTH_ERROR;
324 } 325 }
325 if (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0) { 326 if (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0) {
326 return SBOX_TEST_FIFTH_ERROR; 327 return SBOX_TEST_FIFTH_ERROR;
327 } 328 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // This tests that our CreateThread interceptors works when called directly. 493 // This tests that our CreateThread interceptors works when called directly.
493 TEST(ProcessPolicyTest, TestCreateThreadOutsideSandbox) { 494 TEST(ProcessPolicyTest, TestCreateThreadOutsideSandbox) {
494 DWORD pid = ::GetCurrentProcessId(); 495 DWORD pid = ::GetCurrentProcessId();
495 std::wstring event_name = GenerateEventName(pid); 496 std::wstring event_name = GenerateEventName(pid);
496 ASSERT_STRNE(NULL, event_name.c_str()); 497 ASSERT_STRNE(NULL, event_name.c_str());
497 HANDLE event = ::CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); 498 HANDLE event = ::CreateEvent(NULL, TRUE, FALSE, event_name.c_str());
498 EXPECT_NE(static_cast<HANDLE>(NULL), event); 499 EXPECT_NE(static_cast<HANDLE>(NULL), event);
499 500
500 DWORD thread_id = 0; 501 DWORD thread_id = 0;
501 HANDLE thread = NULL; 502 HANDLE thread = NULL;
502 thread = TargetCreateThread(::CreateThread, NULL, 0, 503 thread = TargetCreateThread(
503 (LPTHREAD_START_ROUTINE)&TestThreadFunc, 504 ::CreateThread, NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc,
504 reinterpret_cast<LPVOID>(pid), 0, &thread_id); 505 reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)), 0, &thread_id);
505 EXPECT_NE(static_cast<HANDLE>(NULL), thread); 506 EXPECT_NE(static_cast<HANDLE>(NULL), thread);
506 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE)); 507 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE));
507 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE)); 508 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE));
508 } 509 }
509 510
510 } // namespace sandbox 511 } // namespace sandbox
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698