| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // This object owns everything initialized here except thread_pool and | 56 // This object owns everything initialized here except thread_pool and |
| 57 // the job_ handle. The Job handle is closed by BrokerServices and results | 57 // the job_ handle. The Job handle is closed by BrokerServices and results |
| 58 // eventually in a call to our dtor. | 58 // eventually in a call to our dtor. |
| 59 : lockdown_token_(std::move(lockdown_token)), | 59 : lockdown_token_(std::move(lockdown_token)), |
| 60 initial_token_(std::move(initial_token)), | 60 initial_token_(std::move(initial_token)), |
| 61 job_(job), | 61 job_(job), |
| 62 thread_pool_(thread_pool), | 62 thread_pool_(thread_pool), |
| 63 base_address_(NULL) {} | 63 base_address_(NULL) {} |
| 64 | 64 |
| 65 TargetProcess::~TargetProcess() { | 65 TargetProcess::~TargetProcess() { |
| 66 DWORD exit_code = 0; | |
| 67 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE | 66 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE |
| 68 // will take effect only when the context changes. As far as the testing went, | 67 // will take effect only when the context changes. As far as the testing went, |
| 69 // this wait was enough to switch context and kill the processes in the job. | 68 // this wait was enough to switch context and kill the processes in the job. |
| 70 // If this process is already dead, the function will return without waiting. | 69 // If this process is already dead, the function will return without waiting. |
| 71 // TODO(nsylvain): If the process is still alive at the end, we should kill | |
| 72 // it. http://b/893891 | |
| 73 // For now, this wait is there only to do a best effort to prevent some leaks | 70 // For now, this wait is there only to do a best effort to prevent some leaks |
| 74 // from showing up in purify. | 71 // from showing up in purify. |
| 75 if (sandbox_process_info_.IsValid()) { | 72 if (sandbox_process_info_.IsValid()) { |
| 76 ::WaitForSingleObject(sandbox_process_info_.process_handle(), 50); | 73 ::WaitForSingleObject(sandbox_process_info_.process_handle(), 50); |
| 77 // At this point, the target process should have been killed. Check. | 74 // Terminate the process if it's still alive, as its IPC server is going |
| 78 if (!::GetExitCodeProcess(sandbox_process_info_.process_handle(), | 75 // away. 1 is RESULT_CODE_KILLED. |
| 79 &exit_code) || (STILL_ACTIVE == exit_code)) { | 76 ::TerminateProcess(sandbox_process_info_.process_handle(), 1); |
| 80 // Something went wrong. We don't know if the target is in a state where | |
| 81 // it can manage to do another IPC call. If it can, and we've destroyed | |
| 82 // the |ipc_server_|, it will crash the broker. So we intentionally leak | |
| 83 // that. | |
| 84 if (shared_section_.IsValid()) | |
| 85 shared_section_.Take(); | |
| 86 ignore_result(ipc_server_.release()); | |
| 87 sandbox_process_info_.TakeProcessHandle(); | |
| 88 return; | |
| 89 } | |
| 90 } | 77 } |
| 91 | 78 |
| 92 // ipc_server_ references our process handle, so make sure the former is shut | 79 // ipc_server_ references our process handle, so make sure the former is shut |
| 93 // down before the latter is closed (by ScopedProcessInformation). | 80 // down before the latter is closed (by ScopedProcessInformation). |
| 94 ipc_server_.reset(); | 81 ipc_server_.reset(); |
| 95 } | 82 } |
| 96 | 83 |
| 97 // Creates the target (child) process suspended and assigns it to the job | 84 // Creates the target (child) process suspended and assigns it to the job |
| 98 // object. | 85 // object. |
| 99 ResultCode TargetProcess::Create( | 86 ResultCode TargetProcess::Create( |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 TargetProcess* target = new TargetProcess( | 315 TargetProcess* target = new TargetProcess( |
| 329 base::win::ScopedHandle(), base::win::ScopedHandle(), NULL, NULL); | 316 base::win::ScopedHandle(), base::win::ScopedHandle(), NULL, NULL); |
| 330 PROCESS_INFORMATION process_info = {}; | 317 PROCESS_INFORMATION process_info = {}; |
| 331 process_info.hProcess = process; | 318 process_info.hProcess = process; |
| 332 target->sandbox_process_info_.Set(process_info); | 319 target->sandbox_process_info_.Set(process_info); |
| 333 target->base_address_ = base_address; | 320 target->base_address_ = base_address; |
| 334 return target; | 321 return target; |
| 335 } | 322 } |
| 336 | 323 |
| 337 } // namespace sandbox | 324 } // namespace sandbox |
| OLD | NEW |