| 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/process/process.h" | 5 #include "base/process/process.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 void Process::Close() { | 118 void Process::Close() { |
| 119 is_current_process_ = false; | 119 is_current_process_ = false; |
| 120 if (!process_.IsValid()) | 120 if (!process_.IsValid()) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 process_.Close(); | 123 process_.Close(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Process::Terminate(int result_code) { | 126 bool Process::Terminate(int result_code, bool wait) const { |
| 127 DCHECK(IsValid()); | 127 DCHECK(IsValid()); |
| 128 | 128 // TODO(rvargas) crbug/417532: Move the implementation here. |
| 129 // Call NtTerminateProcess directly, without going through the import table, | 129 return KillProcess(Handle(), result_code, wait); |
| 130 // which might have been hooked with a buggy replacement by third party | |
| 131 // software. http://crbug.com/81449. | |
| 132 HMODULE module = GetModuleHandle(L"ntdll.dll"); | |
| 133 typedef UINT (WINAPI *TerminateProcessPtr)(HANDLE handle, UINT code); | |
| 134 TerminateProcessPtr terminate_process = reinterpret_cast<TerminateProcessPtr>( | |
| 135 GetProcAddress(module, "NtTerminateProcess")); | |
| 136 terminate_process(Handle(), result_code); | |
| 137 } | 130 } |
| 138 | 131 |
| 139 bool Process::WaitForExit(int* exit_code) { | 132 bool Process::WaitForExit(int* exit_code) { |
| 140 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), | 133 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(INFINITE), |
| 141 exit_code); | 134 exit_code); |
| 142 } | 135 } |
| 143 | 136 |
| 144 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { | 137 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) { |
| 145 // Limit timeout to INFINITE. | 138 // Limit timeout to INFINITE. |
| 146 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); | 139 DWORD timeout_ms = saturated_cast<DWORD>(timeout.InMilliseconds()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 186 |
| 194 return (::SetPriorityClass(Handle(), priority) != 0); | 187 return (::SetPriorityClass(Handle(), priority) != 0); |
| 195 } | 188 } |
| 196 | 189 |
| 197 int Process::GetPriority() const { | 190 int Process::GetPriority() const { |
| 198 DCHECK(IsValid()); | 191 DCHECK(IsValid()); |
| 199 return ::GetPriorityClass(Handle()); | 192 return ::GetPriorityClass(Handle()); |
| 200 } | 193 } |
| 201 | 194 |
| 202 } // namespace base | 195 } // namespace base |
| OLD | NEW |