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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 ProcessId GetCurrentProcId() { | 170 ProcessId GetCurrentProcId() { |
171 return ::GetCurrentProcessId(); | 171 return ::GetCurrentProcessId(); |
172 } | 172 } |
173 | 173 |
174 ProcessHandle GetCurrentProcessHandle() { | 174 ProcessHandle GetCurrentProcessHandle() { |
175 return ::GetCurrentProcess(); | 175 return ::GetCurrentProcess(); |
176 } | 176 } |
177 | 177 |
178 HMODULE GetModuleFromAddress(void* address) { | 178 HMODULE GetModuleFromAddress(void* address) { |
179 HMODULE instance = NULL; | 179 HMODULE hinst = NULL; |
180 if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | 180 if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, |
181 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | |
182 static_cast<char*>(address), | 181 static_cast<char*>(address), |
183 &instance)) { | 182 &hinst)) { |
184 NOTREACHED(); | 183 NOTREACHED(); |
185 } | 184 } |
186 return instance; | 185 return hinst; |
187 } | 186 } |
188 | 187 |
189 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { | 188 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { |
190 // We try to limit privileges granted to the handle. If you need this | 189 // We try to limit privileges granted to the handle. If you need this |
191 // for test code, consider using OpenPrivilegedProcessHandle instead of | 190 // for test code, consider using OpenPrivilegedProcessHandle instead of |
192 // adding more privileges here. | 191 // adding more privileges here. |
193 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, | 192 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, |
194 FALSE, pid); | 193 FALSE, pid); |
195 | 194 |
196 if (result == NULL) | 195 if (result == NULL) |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 | 995 |
997 PERFORMANCE_INFORMATION info; | 996 PERFORMANCE_INFORMATION info; |
998 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 997 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
999 DLOG(ERROR) << "Failed to fetch internal performance info."; | 998 DLOG(ERROR) << "Failed to fetch internal performance info."; |
1000 return 0; | 999 return 0; |
1001 } | 1000 } |
1002 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1001 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
1003 } | 1002 } |
1004 | 1003 |
1005 } // namespace base | 1004 } // namespace base |
OLD | NEW |