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

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: fixes and cross bitness 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
Index: util/win/process_info.cc
diff --git a/util/win/process_info.cc b/util/win/process_info.cc
index ff8689ed5300f48ad122ab5af8b42574f34cd854..165f164f1f84671d450f08f7cd9d0986c673258f 100644
--- a/util/win/process_info.cc
+++ b/util/win/process_info.cc
@@ -253,12 +253,68 @@ 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,
Mark Mentovai 2015/09/26 03:36:36 So if you ask about a 32-bit process from a 64-bit
scottmg 2015/09/26 04:08:53 Yeah, there's one very big region at: base_addr
+ 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()
+ : base_address(0),
+ region_size(0),
+ allocation_base(0),
+ state(0),
+ allocation_protect(0),
+ protect(0),
+ type(0) {
+}
+
+ProcessInfo::MemoryInfo::MemoryInfo(const MEMORY_BASIC_INFORMATION& mbi)
+ : base_address(reinterpret_cast<WinVMAddress>(mbi.BaseAddress)),
+ region_size(mbi.RegionSize),
Mark Mentovai 2015/09/26 03:36:36 You need casts for the address fields but not the
scottmg 2015/09/26 04:08:53 Yeah, the size is a SIZE_T, but the addresses are
+ 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 +322,7 @@ ProcessInfo::ProcessInfo()
peb_address_(0),
peb_size_(0),
modules_(),
+ memory_info_(),
is_64_bit_(false),
is_wow64_(false),
initialized_() {
@@ -320,6 +377,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 +423,9 @@ bool ProcessInfo::Modules(std::vector<Module>* modules) const {
return true;
}
+const std::vector<ProcessInfo::MemoryInfo>& ProcessInfo::MemoryInformation()
+ const {
+ return memory_info_;
+}
+
} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698