OLD | NEW |
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 "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/strings/string_piece.h" | 7 #include "base/strings/string_piece.h" |
8 #include "base/win/scoped_process_information.h" | 8 #include "base/win/scoped_process_information.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "sandbox/win/src/sandbox.h" | 10 #include "sandbox/win/src/sandbox.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 wchar_t prog_name[MAX_PATH]; | 375 wchar_t prog_name[MAX_PATH]; |
376 GetModuleFileNameW(NULL, prog_name, MAX_PATH); | 376 GetModuleFileNameW(NULL, prog_name, MAX_PATH); |
377 | 377 |
378 TargetPolicy* policy = broker->CreatePolicy(); | 378 TargetPolicy* policy = broker->CreatePolicy(); |
379 void* shared_handle = | 379 void* shared_handle = |
380 policy->AddHandleToShare(read_only_view.handle().GetHandle()); | 380 policy->AddHandleToShare(read_only_view.handle().GetHandle()); |
381 | 381 |
382 base::string16 arguments(L"\""); | 382 base::string16 arguments(L"\""); |
383 arguments += prog_name; | 383 arguments += prog_name; |
384 arguments += L"\" -child 0 shared_memory_handle "; | 384 arguments += L"\" -child 0 shared_memory_handle "; |
| 385 // Cast through uintptr_t and then unsigned int to make the truncation |
| 386 // explicit. Handles are size-of-pointer but are always 32-bit values. |
385 arguments += base::UintToString16( | 387 arguments += base::UintToString16( |
386 reinterpret_cast<unsigned int>(shared_handle)); | 388 static_cast<unsigned int>(reinterpret_cast<uintptr_t>(shared_handle))); |
387 | 389 |
388 // Launch the app. | 390 // Launch the app. |
389 ResultCode result = SBOX_ALL_OK; | 391 ResultCode result = SBOX_ALL_OK; |
390 base::win::ScopedProcessInformation target; | 392 base::win::ScopedProcessInformation target; |
391 | 393 |
392 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); | 394 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); |
393 PROCESS_INFORMATION temp_process_info = {}; | 395 PROCESS_INFORMATION temp_process_info = {}; |
394 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, | 396 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, |
395 &temp_process_info); | 397 &temp_process_info); |
396 policy->Release(); | 398 policy->Release(); |
397 | 399 |
398 EXPECT_EQ(SBOX_ALL_OK, result); | 400 EXPECT_EQ(SBOX_ALL_OK, result); |
399 if (result == SBOX_ALL_OK) | 401 if (result == SBOX_ALL_OK) |
400 target.Set(temp_process_info); | 402 target.Set(temp_process_info); |
401 | 403 |
402 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); | 404 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); |
403 | 405 |
404 EXPECT_EQ(WAIT_TIMEOUT, | 406 EXPECT_EQ(WAIT_TIMEOUT, |
405 ::WaitForSingleObject(target.process_handle(), 2000)); | 407 ::WaitForSingleObject(target.process_handle(), 2000)); |
406 | 408 |
407 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0)); | 409 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0)); |
408 | 410 |
409 ::WaitForSingleObject(target.process_handle(), INFINITE); | 411 ::WaitForSingleObject(target.process_handle(), INFINITE); |
410 } | 412 } |
411 | 413 |
412 } // namespace sandbox | 414 } // namespace sandbox |
OLD | NEW |