Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: util/win/process_info.cc

Issue 1369833002: win: Gather memory information (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@save-peb-stuff
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/win/process_info.h ('k') | util/win/process_info_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/win/process_info.cc
diff --git a/util/win/process_info.cc b/util/win/process_info.cc
index ff8689ed5300f48ad122ab5af8b42574f34cd854..ed5262c7f7cc9d7f2d2958d3c7c74a1b69a7b9a6 100644
--- a/util/win/process_info.cc
+++ b/util/win/process_info.cc
@@ -253,12 +253,58 @@ bool ReadProcessData(HANDLE process,
return true;
}
+bool ReadMemoryInfo(HANDLE process, ProcessInfo* process_info) {
+ DCHECK(process_info->memory_info_.empty());
+
+ SYSTEM_INFO system_info;
+ GetSystemInfo(&system_info);
+ const WinVMAddress min_address =
+ reinterpret_cast<WinVMAddress>(system_info.lpMinimumApplicationAddress);
+ const WinVMAddress max_address =
+ reinterpret_cast<WinVMAddress>(system_info.lpMaximumApplicationAddress);
+ MEMORY_BASIC_INFORMATION memory_basic_information;
+ for (WinVMAddress address = min_address; address <= max_address;
+ address += memory_basic_information.RegionSize) {
+ size_t result = VirtualQueryEx(process,
+ reinterpret_cast<void*>(address),
+ &memory_basic_information,
+ sizeof(memory_basic_information));
+ if (result == 0) {
+ PLOG(ERROR) << "VirtualQueryEx";
+ return false;
+ }
+
+ process_info->memory_info_.push_back(
+ ProcessInfo::MemoryInfo(memory_basic_information));
+
+ if (memory_basic_information.RegionSize == 0) {
+ LOG(ERROR) << "RegionSize == 0";
+ return false;
+ }
+ }
+
+ return true;
+}
+
ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() {
}
ProcessInfo::Module::~Module() {
}
+ProcessInfo::MemoryInfo::MemoryInfo(const MEMORY_BASIC_INFORMATION& mbi)
+ : base_address(reinterpret_cast<WinVMAddress>(mbi.BaseAddress)),
+ region_size(mbi.RegionSize),
+ allocation_base(reinterpret_cast<WinVMAddress>(mbi.AllocationBase)),
+ state(mbi.State),
+ allocation_protect(mbi.AllocationProtect),
+ protect(mbi.Protect),
+ type(mbi.Type) {
+}
+
+ProcessInfo::MemoryInfo::~MemoryInfo() {
+}
+
ProcessInfo::ProcessInfo()
: process_id_(),
inherited_from_process_id_(),
@@ -266,6 +312,7 @@ ProcessInfo::ProcessInfo()
peb_address_(0),
peb_size_(0),
modules_(),
+ memory_info_(),
is_64_bit_(false),
is_wow64_(false),
initialized_() {
@@ -320,6 +367,11 @@ bool ProcessInfo::Initialize(HANDLE process) {
return false;
}
+ if (!ReadMemoryInfo(process, this)) {
+ LOG(ERROR) << "ReadMemoryInfo failed";
+ return false;
+ }
+
INITIALIZATION_STATE_SET_VALID(initialized_);
return true;
}
@@ -361,4 +413,9 @@ bool ProcessInfo::Modules(std::vector<Module>* modules) const {
return true;
}
+const std::vector<ProcessInfo::MemoryInfo>& ProcessInfo::MemoryInformation()
+ const {
+ return memory_info_;
+}
+
} // namespace crashpad
« no previous file with comments | « util/win/process_info.h ('k') | util/win/process_info_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698