fuchsia: Defer initialization of memory map

This allows partial reading of the current process (e.g. modules or
CrashpadInfo), even though the memory map read (and so thread retrieval)
will fail if ProcessSnapshotFuchsia is used on the current process.

This is a follow up to
db6f51d3fc
which broke the CrashpadInfoClientOptions.* tests.

Bug: fuchsia:34598
Change-Id: Ifa17b4dbefcd198ff67ecea91f946cfa2439ca4c
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1776936
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
This commit is contained in:
Scott Graham 2019-08-29 16:43:39 -07:00 committed by Commit Bot
parent 10a1d2d877
commit b71f61f8e3
3 changed files with 42 additions and 11 deletions

View File

@ -105,10 +105,6 @@ bool ProcessReaderFuchsia::Initialize(const zx::process& process) {
process_memory_.reset(new ProcessMemoryFuchsia());
process_memory_->Initialize(*process_);
if (!memory_map_.Initialize(*process_)) {
return false;
}
INITIALIZATION_STATE_SET_VALID(initialized_);
return true;
}
@ -135,6 +131,16 @@ ProcessReaderFuchsia::Threads() {
return threads_;
}
const MemoryMapFuchsia* ProcessReaderFuchsia::MemoryMap() {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
if (!initialized_memory_map_) {
InitializeMemoryMap();
}
return memory_map_.get();
}
void ProcessReaderFuchsia::InitializeModules() {
DCHECK(!initialized_modules_);
DCHECK(modules_.empty());
@ -315,7 +321,13 @@ void ProcessReaderFuchsia::InitializeThreads() {
} else {
thread.general_registers = general_regs;
GetStackRegions(general_regs, memory_map_, &thread.stack_regions);
const MemoryMapFuchsia* memory_map = MemoryMap();
if (memory_map) {
// Attempt to retrive stack regions if a memory map was retrieved. In
// particular, this may be null when operating on the current process
// where the memory map will not be able to be retrieved.
GetStackRegions(general_regs, *memory_map, &thread.stack_regions);
}
}
zx_thread_state_vector_regs_t vector_regs;
@ -333,4 +345,15 @@ void ProcessReaderFuchsia::InitializeThreads() {
}
}
void ProcessReaderFuchsia::InitializeMemoryMap() {
DCHECK(!initialized_memory_map_);
initialized_memory_map_ = true;
memory_map_.reset(new MemoryMapFuchsia);
if (!memory_map_->Initialize(*process_)) {
memory_map_.reset();
}
}
} // namespace crashpad

View File

@ -112,7 +112,7 @@ class ProcessReaderFuchsia {
const ProcessMemory* Memory() const { return process_memory_.get(); }
//! \brief Return a memory map for the target process.
const MemoryMapFuchsia* MemoryMap() const { return &memory_map_; }
const MemoryMapFuchsia* MemoryMap();
private:
//! Performs lazy initialization of the \a modules_ vector on behalf of
@ -123,15 +123,20 @@ class ProcessReaderFuchsia {
//! Threads().
void InitializeThreads();
//! Performs lazy initialization of the \a memory_map_ on behalf of
//! MemoryMap().
void InitializeMemoryMap();
std::vector<Module> modules_;
std::vector<Thread> threads_;
std::vector<std::unique_ptr<ElfImageReader>> module_readers_;
std::vector<std::unique_ptr<ProcessMemoryRange>> process_memory_ranges_;
std::unique_ptr<ProcessMemoryFuchsia> process_memory_;
MemoryMapFuchsia memory_map_;
std::unique_ptr<MemoryMapFuchsia> memory_map_;
zx::unowned_process process_;
bool initialized_modules_ = false;
bool initialized_threads_ = false;
bool initialized_memory_map_ = false;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(ProcessReaderFuchsia);

View File

@ -41,10 +41,13 @@ bool ProcessSnapshotFuchsia::Initialize(const zx::process& process) {
InitializeThreads();
InitializeModules();
for (const auto& entry : process_reader_.MemoryMap()->Entries()) {
if (entry.type == ZX_INFO_MAPS_TYPE_MAPPING) {
memory_map_.push_back(
std::make_unique<internal::MemoryMapRegionSnapshotFuchsia>(entry));
const MemoryMapFuchsia* memory_map = process_reader_.MemoryMap();
if (memory_map) {
for (const auto& entry : memory_map->Entries()) {
if (entry.type == ZX_INFO_MAPS_TYPE_MAPPING) {
memory_map_.push_back(
std::make_unique<internal::MemoryMapRegionSnapshotFuchsia>(entry));
}
}
}