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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 } // namespace | 167 } // namespace |
168 | 168 |
169 ProcessId GetCurrentProcId() { | 169 ProcessId GetCurrentProcId() { |
170 return ::GetCurrentProcessId(); | 170 return ::GetCurrentProcessId(); |
171 } | 171 } |
172 | 172 |
173 ProcessHandle GetCurrentProcessHandle() { | 173 ProcessHandle GetCurrentProcessHandle() { |
174 return ::GetCurrentProcess(); | 174 return ::GetCurrentProcess(); |
175 } | 175 } |
176 | 176 |
177 HMODULE GetModuleFromAddress(void* address) { | |
178 MEMORY_BASIC_INFORMATION info = {0}; | |
Evan Martin
2012/01/27 16:17:41
FWIW, you can do
MEMORY_BASIC_INFORMATION info =
Jói
2012/02/10 09:11:57
Cool, nice tip :)
| |
179 ::VirtualQuery(address, &info, sizeof(info)); | |
Evan Martin
2012/01/27 16:17:41
Shouldn't we be checking the return value? What i
Jói
2012/02/10 09:11:57
It is now checked, for the new API that Robert sug
| |
180 return reinterpret_cast<HMODULE>(info.AllocationBase); | |
robertshield
2012/01/27 16:26:45
I know you took this from CF, so I almost feel bad
cpu_(ooo_6.6-7.5)
2012/01/27 19:31:50
Yes please use Robert's method.
On 2012/01/27 16:
| |
181 } | |
182 | |
177 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { | 183 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { |
178 // We try to limit privileges granted to the handle. If you need this | 184 // We try to limit privileges granted to the handle. If you need this |
179 // for test code, consider using OpenPrivilegedProcessHandle instead of | 185 // for test code, consider using OpenPrivilegedProcessHandle instead of |
180 // adding more privileges here. | 186 // adding more privileges here. |
181 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, | 187 ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, |
182 FALSE, pid); | 188 FALSE, pid); |
183 | 189 |
184 if (result == INVALID_HANDLE_VALUE) | 190 if (result == INVALID_HANDLE_VALUE) |
185 return false; | 191 return false; |
186 | 192 |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 | 998 |
993 PERFORMANCE_INFORMATION info; | 999 PERFORMANCE_INFORMATION info; |
994 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1000 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
995 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1001 DLOG(ERROR) << "Failed to fetch internal performance info."; |
996 return 0; | 1002 return 0; |
997 } | 1003 } |
998 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1004 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
999 } | 1005 } |
1000 | 1006 |
1001 } // namespace base | 1007 } // namespace base |
OLD | NEW |