OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 7 #include <windows.h> |
8 #include <winternl.h> | 8 #include <winternl.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace base { | 26 namespace base { |
27 | 27 |
28 int GetCurrentProcId() { | 28 int GetCurrentProcId() { |
29 return ::GetCurrentProcessId(); | 29 return ::GetCurrentProcessId(); |
30 } | 30 } |
31 | 31 |
32 ProcessHandle GetCurrentProcessHandle() { | 32 ProcessHandle GetCurrentProcessHandle() { |
33 return ::GetCurrentProcess(); | 33 return ::GetCurrentProcess(); |
34 } | 34 } |
35 | 35 |
| 36 bool CloseProcessHandle(ProcessHandle process) { |
| 37 return ::CloseHandle(process) ? true : false; |
| 38 } |
| 39 |
36 // Helper for GetProcId() | 40 // Helper for GetProcId() |
37 bool GetProcIdViaGetProcessId(ProcessHandle process, DWORD* id) { | 41 bool GetProcIdViaGetProcessId(ProcessHandle process, DWORD* id) { |
38 // Dynamically get a pointer to GetProcessId(). | 42 // Dynamically get a pointer to GetProcessId(). |
39 typedef DWORD (WINAPI *GetProcessIdFunction)(HANDLE); | 43 typedef DWORD (WINAPI *GetProcessIdFunction)(HANDLE); |
40 static GetProcessIdFunction GetProcessIdPtr = NULL; | 44 static GetProcessIdFunction GetProcessIdPtr = NULL; |
41 static bool initialize_get_process_id = true; | 45 static bool initialize_get_process_id = true; |
42 if (initialize_get_process_id) { | 46 if (initialize_get_process_id) { |
43 initialize_get_process_id = false; | 47 initialize_get_process_id = false; |
44 HMODULE kernel32_handle = GetModuleHandle(L"kernel32.dll"); | 48 HMODULE kernel32_handle = GetModuleHandle(L"kernel32.dll"); |
45 if (!kernel32_handle) { | 49 if (!kernel32_handle) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return false; | 185 return false; |
182 } | 186 } |
183 if (exitcode == STILL_ACTIVE) { | 187 if (exitcode == STILL_ACTIVE) { |
184 // The process is likely not dead or it used 0x103 as exit code. | 188 // The process is likely not dead or it used 0x103 as exit code. |
185 NOTREACHED(); | 189 NOTREACHED(); |
186 return false; | 190 return false; |
187 } | 191 } |
188 | 192 |
189 // Warning, this is not generic code; it heavily depends on the way | 193 // Warning, this is not generic code; it heavily depends on the way |
190 // the rest of the code kills a process. | 194 // the rest of the code kills a process. |
191 | 195 |
192 if (exitcode == PROCESS_END_NORMAL_TERMINATON || | 196 if (exitcode == PROCESS_END_NORMAL_TERMINATON || |
193 exitcode == PROCESS_END_KILLED_BY_USER || | 197 exitcode == PROCESS_END_KILLED_BY_USER || |
194 exitcode == PROCESS_END_PROCESS_WAS_HUNG || | 198 exitcode == PROCESS_END_PROCESS_WAS_HUNG || |
195 exitcode == 0xC0000354 || // STATUS_DEBUGGER_INACTIVE. | 199 exitcode == 0xC0000354 || // STATUS_DEBUGGER_INACTIVE. |
196 exitcode == 0xC000013A || // Control-C/end session. | 200 exitcode == 0xC000013A || // Control-C/end session. |
197 exitcode == 0x40010004) { // Debugger terminated process/end session. | 201 exitcode == 0x40010004) { // Debugger terminated process/end session. |
198 return false; | 202 return false; |
199 } | 203 } |
200 | 204 |
201 // All other exit codes indicate crashes. | 205 // All other exit codes indicate crashes. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 void EnableTerminationOnHeapCorruption() { | 630 void EnableTerminationOnHeapCorruption() { |
627 // Ignore the result code. Supported on XP SP3 and Vista. | 631 // Ignore the result code. Supported on XP SP3 and Vista. |
628 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 632 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
629 } | 633 } |
630 | 634 |
631 void RaiseProcessToHighPriority() { | 635 void RaiseProcessToHighPriority() { |
632 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 636 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
633 } | 637 } |
634 | 638 |
635 } // namespace base | 639 } // namespace base |
OLD | NEW |