OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return hinst; | 184 return hinst; |
185 } | 185 } |
186 | 186 |
187 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { | 187 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { |
188 // We try to limit privileges granted to the handle. If you need this | 188 // We try to limit privileges granted to the handle. If you need this |
189 // for test code, consider using OpenPrivilegedProcessHandle instead of | 189 // for test code, consider using OpenPrivilegedProcessHandle instead of |
190 // adding more privileges here. | 190 // adding more privileges here. |
191 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, | 191 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, |
192 FALSE, pid); | 192 FALSE, pid); |
193 | 193 |
194 if (result == INVALID_HANDLE_VALUE) | 194 if (result == NULL) |
195 return false; | 195 return false; |
196 | 196 |
197 *handle = result; | 197 *handle = result; |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { | 201 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { |
202 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | | 202 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | |
203 PROCESS_TERMINATE | | 203 PROCESS_TERMINATE | |
204 PROCESS_QUERY_INFORMATION | | 204 PROCESS_QUERY_INFORMATION | |
205 PROCESS_VM_READ | | 205 PROCESS_VM_READ | |
206 SYNCHRONIZE, | 206 SYNCHRONIZE, |
207 FALSE, pid); | 207 FALSE, pid); |
208 | 208 |
209 if (result == INVALID_HANDLE_VALUE) | 209 if (result == NULL) |
210 return false; | 210 return false; |
211 | 211 |
212 *handle = result; | 212 *handle = result; |
213 return true; | 213 return true; |
214 } | 214 } |
215 | 215 |
216 bool OpenProcessHandleWithAccess(ProcessId pid, | 216 bool OpenProcessHandleWithAccess(ProcessId pid, |
217 uint32 access_flags, | 217 uint32 access_flags, |
218 ProcessHandle* handle) { | 218 ProcessHandle* handle) { |
219 ProcessHandle result = OpenProcess(access_flags, FALSE, pid); | 219 ProcessHandle result = OpenProcess(access_flags, FALSE, pid); |
220 | 220 |
221 if (result == INVALID_HANDLE_VALUE) | 221 if (result == NULL) |
222 return false; | 222 return false; |
223 | 223 |
224 *handle = result; | 224 *handle = result; |
225 return true; | 225 return true; |
226 } | 226 } |
227 | 227 |
228 void CloseProcessHandle(ProcessHandle process) { | 228 void CloseProcessHandle(ProcessHandle process) { |
229 CloseHandle(process); | 229 CloseHandle(process); |
230 } | 230 } |
231 | 231 |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 | 1002 |
1003 PERFORMANCE_INFORMATION info; | 1003 PERFORMANCE_INFORMATION info; |
1004 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1004 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
1005 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1005 DLOG(ERROR) << "Failed to fetch internal performance info."; |
1006 return 0; | 1006 return 0; |
1007 } | 1007 } |
1008 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1008 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
1009 } | 1009 } |
1010 | 1010 |
1011 } // namespace base | 1011 } // namespace base |
OLD | NEW |