Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 module.size = ldr_data_table_entry.SizeOfImage; | 246 module.size = ldr_data_table_entry.SizeOfImage; |
| 247 module.timestamp = ldr_data_table_entry.TimeDateStamp; | 247 module.timestamp = ldr_data_table_entry.TimeDateStamp; |
| 248 process_info->modules_.push_back(module); | 248 process_info->modules_.push_back(module); |
| 249 if (cur == last) | 249 if (cur == last) |
| 250 break; | 250 break; |
| 251 } | 251 } |
| 252 | 252 |
| 253 return true; | 253 return true; |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool ReadMemoryInfo(HANDLE process, ProcessInfo* process_info) { | |
| 257 DCHECK(process_info->memory_info_.empty()); | |
| 258 | |
| 259 SYSTEM_INFO system_info; | |
| 260 GetSystemInfo(&system_info); | |
| 261 const WinVMAddress min_address = | |
| 262 reinterpret_cast<WinVMAddress>(system_info.lpMinimumApplicationAddress); | |
| 263 const WinVMAddress max_address = | |
| 264 reinterpret_cast<WinVMAddress>(system_info.lpMaximumApplicationAddress); | |
| 265 MEMORY_BASIC_INFORMATION memory_basic_information; | |
| 266 for (WinVMAddress address = min_address; address <= max_address; | |
| 267 address += memory_basic_information.RegionSize) { | |
| 268 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
| |
| 269 reinterpret_cast<void*>(address), | |
| 270 &memory_basic_information, | |
| 271 sizeof(memory_basic_information)); | |
| 272 if (result == 0) { | |
| 273 PLOG(ERROR) << "VirtualQueryEx"; | |
| 274 return false; | |
| 275 } | |
| 276 | |
| 277 process_info->memory_info_.push_back( | |
| 278 ProcessInfo::MemoryInfo(memory_basic_information)); | |
| 279 | |
| 280 if (memory_basic_information.RegionSize == 0) { | |
| 281 LOG(ERROR) << "RegionSize == 0"; | |
| 282 return false; | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 return true; | |
| 287 } | |
| 288 | |
| 256 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { | 289 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { |
| 257 } | 290 } |
| 258 | 291 |
| 259 ProcessInfo::Module::~Module() { | 292 ProcessInfo::Module::~Module() { |
| 260 } | 293 } |
| 261 | 294 |
| 295 ProcessInfo::MemoryInfo::MemoryInfo() | |
| 296 : base_address(0), | |
| 297 region_size(0), | |
| 298 allocation_base(0), | |
| 299 state(0), | |
| 300 allocation_protect(0), | |
| 301 protect(0), | |
| 302 type(0) { | |
| 303 } | |
| 304 | |
| 305 ProcessInfo::MemoryInfo::MemoryInfo(const MEMORY_BASIC_INFORMATION& mbi) | |
| 306 : base_address(reinterpret_cast<WinVMAddress>(mbi.BaseAddress)), | |
| 307 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
| |
| 308 allocation_base(reinterpret_cast<WinVMAddress>(mbi.AllocationBase)), | |
| 309 state(mbi.State), | |
| 310 allocation_protect(mbi.AllocationProtect), | |
| 311 protect(mbi.Protect), | |
| 312 type(mbi.Type) { | |
| 313 } | |
| 314 | |
| 315 ProcessInfo::MemoryInfo::~MemoryInfo() { | |
| 316 } | |
| 317 | |
| 262 ProcessInfo::ProcessInfo() | 318 ProcessInfo::ProcessInfo() |
| 263 : process_id_(), | 319 : process_id_(), |
| 264 inherited_from_process_id_(), | 320 inherited_from_process_id_(), |
| 265 command_line_(), | 321 command_line_(), |
| 266 peb_address_(0), | 322 peb_address_(0), |
| 267 peb_size_(0), | 323 peb_size_(0), |
| 268 modules_(), | 324 modules_(), |
| 325 memory_info_(), | |
| 269 is_64_bit_(false), | 326 is_64_bit_(false), |
| 270 is_wow64_(false), | 327 is_wow64_(false), |
| 271 initialized_() { | 328 initialized_() { |
| 272 } | 329 } |
| 273 | 330 |
| 274 ProcessInfo::~ProcessInfo() { | 331 ProcessInfo::~ProcessInfo() { |
| 275 } | 332 } |
| 276 | 333 |
| 277 bool ProcessInfo::Initialize(HANDLE process) { | 334 bool ProcessInfo::Initialize(HANDLE process) { |
| 278 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 335 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 | 370 |
| 314 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( | 371 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( |
| 315 process, peb_address_, this) | 372 process, peb_address_, this) |
| 316 : ReadProcessData<process_types::internal::Traits32>( | 373 : ReadProcessData<process_types::internal::Traits32>( |
| 317 process, peb_address_, this); | 374 process, peb_address_, this); |
| 318 if (!result) { | 375 if (!result) { |
| 319 LOG(ERROR) << "ReadProcessData failed"; | 376 LOG(ERROR) << "ReadProcessData failed"; |
| 320 return false; | 377 return false; |
| 321 } | 378 } |
| 322 | 379 |
| 380 if (!ReadMemoryInfo(process, this)) { | |
| 381 LOG(ERROR) << "ReadMemoryInfo failed"; | |
| 382 return false; | |
| 383 } | |
| 384 | |
| 323 INITIALIZATION_STATE_SET_VALID(initialized_); | 385 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 324 return true; | 386 return true; |
| 325 } | 387 } |
| 326 | 388 |
| 327 bool ProcessInfo::Is64Bit() const { | 389 bool ProcessInfo::Is64Bit() const { |
| 328 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 390 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 329 return is_64_bit_; | 391 return is_64_bit_; |
| 330 } | 392 } |
| 331 | 393 |
| 332 bool ProcessInfo::IsWow64() const { | 394 bool ProcessInfo::IsWow64() const { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 354 *peb_address = peb_address_; | 416 *peb_address = peb_address_; |
| 355 *peb_size = peb_size_; | 417 *peb_size = peb_size_; |
| 356 } | 418 } |
| 357 | 419 |
| 358 bool ProcessInfo::Modules(std::vector<Module>* modules) const { | 420 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
| 359 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 421 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 360 *modules = modules_; | 422 *modules = modules_; |
| 361 return true; | 423 return true; |
| 362 } | 424 } |
| 363 | 425 |
| 426 const std::vector<ProcessInfo::MemoryInfo>& ProcessInfo::MemoryInformation() | |
| 427 const { | |
| 428 return memory_info_; | |
| 429 } | |
| 430 | |
| 364 } // namespace crashpad | 431 } // namespace crashpad |
| OLD | NEW |