| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <userenv.h> | 10 #include <userenv.h> |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DLOG(ERROR) << "Error waiting for process exit: " << GetLastError(); | 311 DLOG(ERROR) << "Error waiting for process exit: " << GetLastError(); |
| 312 } else if (!result) { | 312 } else if (!result) { |
| 313 DLOG(ERROR) << "Unable to terminate process: " << GetLastError(); | 313 DLOG(ERROR) << "Unable to terminate process: " << GetLastError(); |
| 314 } | 314 } |
| 315 return result; | 315 return result; |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool DidProcessCrash(bool* child_exited, ProcessHandle handle) { | 318 bool DidProcessCrash(bool* child_exited, ProcessHandle handle) { |
| 319 DWORD exitcode = 0; | 319 DWORD exitcode = 0; |
| 320 | 320 |
| 321 if (child_exited) | |
| 322 *child_exited = true; // On Windows it an error to call this function if | |
| 323 // the child hasn't already exited. | |
| 324 if (!::GetExitCodeProcess(handle, &exitcode)) { | 321 if (!::GetExitCodeProcess(handle, &exitcode)) { |
| 325 NOTREACHED(); | 322 NOTREACHED(); |
| 323 // Assume the child has exited. |
| 324 if (child_exited) |
| 325 *child_exited = true; |
| 326 return false; | 326 return false; |
| 327 } | 327 } |
| 328 if (exitcode == STILL_ACTIVE) { | 328 if (exitcode == STILL_ACTIVE) { |
| 329 // The process is likely not dead or it used 0x103 as exit code. | 329 DWORD wait_result = WaitForSingleObject(handle, 0); |
| 330 if (wait_result == WAIT_TIMEOUT) { |
| 331 if (child_exited) |
| 332 *child_exited = false; |
| 333 return false; |
| 334 } |
| 335 |
| 336 DCHECK_EQ(WAIT_OBJECT_0, wait_result); |
| 337 |
| 338 // Strange, the process used 0x103 (STILL_ACTIVE) as exit code. |
| 330 NOTREACHED(); | 339 NOTREACHED(); |
| 340 |
| 331 return false; | 341 return false; |
| 332 } | 342 } |
| 333 | 343 |
| 344 // We're sure the child has exited. |
| 345 if (child_exited) |
| 346 *child_exited = true; |
| 347 |
| 334 // Warning, this is not generic code; it heavily depends on the way | 348 // Warning, this is not generic code; it heavily depends on the way |
| 335 // the rest of the code kills a process. | 349 // the rest of the code kills a process. |
| 336 | 350 |
| 337 if (exitcode == PROCESS_END_NORMAL_TERMINATON || | 351 if (exitcode == PROCESS_END_NORMAL_TERMINATON || |
| 338 exitcode == PROCESS_END_KILLED_BY_USER || | 352 exitcode == PROCESS_END_KILLED_BY_USER || |
| 339 exitcode == PROCESS_END_PROCESS_WAS_HUNG || | 353 exitcode == PROCESS_END_PROCESS_WAS_HUNG || |
| 340 exitcode == 0xC0000354 || // STATUS_DEBUGGER_INACTIVE. | 354 exitcode == 0xC0000354 || // STATUS_DEBUGGER_INACTIVE. |
| 341 exitcode == 0xC000013A || // Control-C/end session. | 355 exitcode == 0xC000013A || // Control-C/end session. |
| 342 exitcode == 0x40010004) { // Debugger terminated process/end session. | 356 exitcode == 0x40010004) { // Debugger terminated process/end session. |
| 343 return false; | 357 return false; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 837 |
| 824 PERFORMANCE_INFORMATION info; | 838 PERFORMANCE_INFORMATION info; |
| 825 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 839 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
| 826 LOG(ERROR) << "Failed to fetch internal performance info."; | 840 LOG(ERROR) << "Failed to fetch internal performance info."; |
| 827 return 0; | 841 return 0; |
| 828 } | 842 } |
| 829 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 843 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
| 830 } | 844 } |
| 831 | 845 |
| 832 } // namespace base | 846 } // namespace base |
| OLD | NEW |