OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/win/scoped_handle.h" | 6 #include "base/win/scoped_handle.h" |
7 #include "sandbox/win/src/handle_closer_agent.h" | 7 #include "sandbox/win/src/handle_closer_agent.h" |
8 #include "sandbox/win/src/sandbox.h" | 8 #include "sandbox/win/src/sandbox.h" |
9 #include "sandbox/win/src/sandbox_factory.h" | 9 #include "sandbox/win/src/sandbox_factory.h" |
10 #include "sandbox/win/src/target_services.h" | 10 #include "sandbox/win/src/target_services.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // Create a unique marker file that is open while the test is running. | 66 // Create a unique marker file that is open while the test is running. |
67 // The handles leak, but it will be closed by the test or on exit. | 67 // The handles leak, but it will be closed by the test or on exit. |
68 for (int i = 0; i < arraysize(kFileExtensions); ++i) | 68 for (int i = 0; i < arraysize(kFileExtensions); ++i) |
69 EXPECT_NE(GetMarkerFile(kFileExtensions[i]), INVALID_HANDLE_VALUE); | 69 EXPECT_NE(GetMarkerFile(kFileExtensions[i]), INVALID_HANDLE_VALUE); |
70 return SBOX_TEST_SUCCEEDED; | 70 return SBOX_TEST_SUCCEEDED; |
71 | 71 |
72 case AFTER_REVERT: { | 72 case AFTER_REVERT: { |
73 // Brute force the handle table to find what we're looking for. | 73 // Brute force the handle table to find what we're looking for. |
74 DWORD handle_count = UINT_MAX; | 74 DWORD handle_count = UINT_MAX; |
75 const int kInvalidHandleThreshold = 100; | 75 const int kInvalidHandleThreshold = 100; |
76 const size_t kHandleOffset = sizeof(HANDLE); | 76 const size_t kHandleOffset = 4; // Handles are always a multiple of 4. |
77 HANDLE handle = NULL; | 77 HANDLE handle = NULL; |
78 int invalid_count = 0; | 78 int invalid_count = 0; |
79 base::string16 handle_name; | 79 base::string16 handle_name; |
80 | 80 |
81 if (!::GetProcessHandleCount(::GetCurrentProcess(), &handle_count)) | 81 if (!::GetProcessHandleCount(::GetCurrentProcess(), &handle_count)) |
82 return SBOX_TEST_FAILED_TO_RUN_TEST; | 82 return SBOX_TEST_FAILED_TO_RUN_TEST; |
83 | 83 |
84 while (handle_count && invalid_count < kInvalidHandleThreshold) { | 84 while (handle_count && invalid_count < kInvalidHandleThreshold) { |
85 reinterpret_cast<size_t&>(handle) += kHandleOffset; | 85 reinterpret_cast<size_t&>(handle) += kHandleOffset; |
86 if (GetHandleName(handle, &handle_name)) { | 86 if (GetHandleName(handle, &handle_name)) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 runner.SetTestState(AFTER_REVERT); | 186 runner.SetTestState(AFTER_REVERT); |
187 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 187 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
188 | 188 |
189 // Sever the CSRSS connection by closing ALPC ports inside the sandbox. | 189 // Sever the CSRSS connection by closing ALPC ports inside the sandbox. |
190 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK); | 190 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK); |
191 | 191 |
192 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool")); | 192 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool")); |
193 } | 193 } |
194 | 194 |
195 } // namespace sandbox | 195 } // namespace sandbox |
OLD | NEW |