| 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 "sandbox/win/src/target_process.h" | 5 #include "sandbox/win/src/target_process.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/win/pe_image.h" | 9 #include "base/win/pe_image.h" |
| 10 #include "base/win/startup_information.h" | 10 #include "base/win/startup_information.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE | 81 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE |
| 82 // will take effect only when the context changes. As far as the testing went, | 82 // will take effect only when the context changes. As far as the testing went, |
| 83 // this wait was enough to switch context and kill the processes in the job. | 83 // this wait was enough to switch context and kill the processes in the job. |
| 84 // If this process is already dead, the function will return without waiting. | 84 // If this process is already dead, the function will return without waiting. |
| 85 // TODO(nsylvain): If the process is still alive at the end, we should kill | 85 // TODO(nsylvain): If the process is still alive at the end, we should kill |
| 86 // it. http://b/893891 | 86 // it. http://b/893891 |
| 87 // For now, this wait is there only to do a best effort to prevent some leaks | 87 // For now, this wait is there only to do a best effort to prevent some leaks |
| 88 // from showing up in purify. | 88 // from showing up in purify. |
| 89 if (sandbox_process_info_.IsValid()) { | 89 if (sandbox_process_info_.IsValid()) { |
| 90 ::WaitForSingleObject(sandbox_process_info_.process_handle(), 50); | 90 ::WaitForSingleObject(sandbox_process_info_.process_handle(), 50); |
| 91 // At this point, the target process should have been killed. Check. |
| 91 if (!::GetExitCodeProcess(sandbox_process_info_.process_handle(), | 92 if (!::GetExitCodeProcess(sandbox_process_info_.process_handle(), |
| 92 &exit_code) || (STILL_ACTIVE == exit_code)) { | 93 &exit_code) || (STILL_ACTIVE == exit_code)) { |
| 93 // It is an error to destroy this object while the target process is still | 94 // Something went wrong. We don't know if the target is in a state where |
| 94 // alive because we need to destroy the IPC subsystem and cannot risk to | 95 // it can manage to do another IPC call. If it can, and we've destroyed |
| 95 // have an IPC reach us after this point. | 96 // the |ipc_server_|, it will crash the broker. So we intentionally leak |
| 97 // that. |
| 96 if (shared_section_.IsValid()) | 98 if (shared_section_.IsValid()) |
| 97 shared_section_.Take(); | 99 shared_section_.Take(); |
| 98 SharedMemIPCServer* server = ipc_server_.release(); | 100 ipc_server_.release(); |
| 99 sandbox_process_info_.TakeProcessHandle(); | 101 sandbox_process_info_.TakeProcessHandle(); |
| 100 return; | 102 return; |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 // ipc_server_ references our process handle, so make sure the former is shut | 106 // ipc_server_ references our process handle, so make sure the former is shut |
| 105 // down before the latter is closed (by ScopedProcessInformation). | 107 // down before the latter is closed (by ScopedProcessInformation). |
| 106 ipc_server_.reset(); | 108 ipc_server_.reset(); |
| 107 } | 109 } |
| 108 | 110 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { | 330 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { |
| 329 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); | 331 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); |
| 330 PROCESS_INFORMATION process_info = {}; | 332 PROCESS_INFORMATION process_info = {}; |
| 331 process_info.hProcess = process; | 333 process_info.hProcess = process; |
| 332 target->sandbox_process_info_.Set(process_info); | 334 target->sandbox_process_info_.Set(process_info); |
| 333 target->base_address_ = base_address; | 335 target->base_address_ = base_address; |
| 334 return target; | 336 return target; |
| 335 } | 337 } |
| 336 | 338 |
| 337 } // namespace sandbox | 339 } // namespace sandbox |
| OLD | NEW |