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 <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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 ProcessId GetCurrentProcId() { | 28 ProcessId 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 OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { | 36 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { |
| 37 // TODO(phajdan.jr): Take even more permissions out of this list. |
37 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | | 38 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | |
38 PROCESS_TERMINATE | | 39 PROCESS_TERMINATE | |
39 PROCESS_QUERY_INFORMATION | | 40 PROCESS_QUERY_INFORMATION | |
40 SYNCHRONIZE, | 41 SYNCHRONIZE, |
41 FALSE, pid); | 42 FALSE, pid); |
42 | 43 |
43 if (result == INVALID_HANDLE_VALUE) | 44 if (result == INVALID_HANDLE_VALUE) |
44 return false; | 45 return false; |
45 | 46 |
46 *handle = result; | 47 *handle = result; |
47 return true; | 48 return true; |
48 } | 49 } |
49 | 50 |
| 51 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { |
| 52 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | |
| 53 PROCESS_TERMINATE | |
| 54 PROCESS_QUERY_INFORMATION | |
| 55 PROCESS_VM_READ | |
| 56 SYNCHRONIZE, |
| 57 FALSE, pid); |
| 58 |
| 59 if (result == INVALID_HANDLE_VALUE) |
| 60 return false; |
| 61 |
| 62 *handle = result; |
| 63 return true; |
| 64 } |
| 65 |
50 void CloseProcessHandle(ProcessHandle process) { | 66 void CloseProcessHandle(ProcessHandle process) { |
51 CloseHandle(process); | 67 CloseHandle(process); |
52 } | 68 } |
53 | 69 |
54 // Helper for GetProcId() | 70 // Helper for GetProcId() |
55 bool GetProcIdViaGetProcessId(ProcessHandle process, DWORD* id) { | 71 bool GetProcIdViaGetProcessId(ProcessHandle process, DWORD* id) { |
56 // Dynamically get a pointer to GetProcessId(). | 72 // Dynamically get a pointer to GetProcessId(). |
57 typedef DWORD (WINAPI *GetProcessIdFunction)(HANDLE); | 73 typedef DWORD (WINAPI *GetProcessIdFunction)(HANDLE); |
58 static GetProcessIdFunction GetProcessIdPtr = NULL; | 74 static GetProcessIdFunction GetProcessIdPtr = NULL; |
59 static bool initialize_get_process_id = true; | 75 static bool initialize_get_process_id = true; |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 void EnableTerminationOnHeapCorruption() { | 744 void EnableTerminationOnHeapCorruption() { |
729 // Ignore the result code. Supported on XP SP3 and Vista. | 745 // Ignore the result code. Supported on XP SP3 and Vista. |
730 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 746 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
731 } | 747 } |
732 | 748 |
733 void RaiseProcessToHighPriority() { | 749 void RaiseProcessToHighPriority() { |
734 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 750 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
735 } | 751 } |
736 | 752 |
737 } // namespace base | 753 } // namespace base |
OLD | NEW |