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