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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/free_deleter.h" | 8 #include "base/memory/free_deleter.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
12 #include "base/win/scoped_handle.h" | 11 #include "base/win/scoped_handle.h" |
13 #include "base/win/scoped_process_information.h" | 12 #include "base/win/scoped_process_information.h" |
14 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
15 #include "sandbox/win/src/process_thread_interception.h" | 14 #include "sandbox/win/src/process_thread_interception.h" |
16 #include "sandbox/win/src/sandbox.h" | 15 #include "sandbox/win/src/sandbox.h" |
17 #include "sandbox/win/src/sandbox_factory.h" | 16 #include "sandbox/win/src/sandbox_factory.h" |
18 #include "sandbox/win/src/sandbox_policy.h" | 17 #include "sandbox/win/src/sandbox_policy.h" |
19 #include "sandbox/win/tests/common/controller.h" | 18 #include "sandbox/win/tests/common/controller.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 // Creates a process with the |exe| and |command| parameter using the | 23 // Creates a process with the |exe| and |command| parameter using the |
25 // unicode and ascii version of the api. | 24 // unicode and ascii version of the api. |
26 sandbox::SboxTestResult CreateProcessHelper(const base::string16& exe, | 25 sandbox::SboxTestResult CreateProcessHelper(const base::string16& exe, |
27 const base::string16& command) { | 26 const base::string16& command) { |
28 base::win::ScopedProcessInformation pi; | 27 base::win::ScopedProcessInformation pi; |
29 STARTUPINFOW si = {sizeof(si)}; | 28 STARTUPINFOW si = {sizeof(si)}; |
30 const wchar_t* exe_name = NULL; | 29 const wchar_t* exe_name = NULL; |
31 if (!exe.empty()) | 30 if (!exe.empty()) |
32 exe_name = exe.c_str(); | 31 exe_name = exe.c_str(); |
33 | 32 |
34 scoped_ptr<wchar_t, base::FreeDeleter> writable_command( | 33 std::unique_ptr<wchar_t, base::FreeDeleter> writable_command( |
35 _wcsdup(command.c_str())); | 34 _wcsdup(command.c_str())); |
36 | 35 |
37 // Create the process with the unicode version of the API. | 36 // Create the process with the unicode version of the API. |
38 sandbox::SboxTestResult ret1 = sandbox::SBOX_TEST_FAILED; | 37 sandbox::SboxTestResult ret1 = sandbox::SBOX_TEST_FAILED; |
39 PROCESS_INFORMATION temp_process_info = {}; | 38 PROCESS_INFORMATION temp_process_info = {}; |
40 if (::CreateProcessW(exe_name, | 39 if (::CreateProcessW(exe_name, |
41 command.empty() ? NULL : writable_command.get(), | 40 command.empty() ? NULL : writable_command.get(), |
42 NULL, | 41 NULL, |
43 NULL, | 42 NULL, |
44 FALSE, | 43 FALSE, |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 HANDLE thread = NULL; | 513 HANDLE thread = NULL; |
515 thread = TargetCreateThread( | 514 thread = TargetCreateThread( |
516 ::CreateThread, NULL, 0, &TestThreadFunc, | 515 ::CreateThread, NULL, 0, &TestThreadFunc, |
517 reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)), 0, &thread_id); | 516 reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)), 0, &thread_id); |
518 EXPECT_NE(static_cast<HANDLE>(NULL), thread); | 517 EXPECT_NE(static_cast<HANDLE>(NULL), thread); |
519 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE)); | 518 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE)); |
520 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE)); | 519 EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE)); |
521 } | 520 } |
522 | 521 |
523 } // namespace sandbox | 522 } // namespace sandbox |
OLD | NEW |