2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2018 The Crashpad Authors
|
2018-02-15 13:21:00 -08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef CRASHPAD_SNAPSHOT_FUCHSIA_PROCESS_READER_H_
|
|
|
|
#define CRASHPAD_SNAPSHOT_FUCHSIA_PROCESS_READER_H_
|
|
|
|
|
2018-07-30 15:50:17 -07:00
|
|
|
#include <lib/zx/process.h>
|
2018-04-12 14:16:10 -07:00
|
|
|
#include <zircon/syscalls/debug.h>
|
|
|
|
|
2018-02-15 13:21:00 -08:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "snapshot/elf/elf_image_reader.h"
|
2018-04-30 12:57:03 -07:00
|
|
|
#include "snapshot/fuchsia/memory_map_fuchsia.h"
|
2018-02-20 16:10:33 -08:00
|
|
|
#include "snapshot/module_snapshot.h"
|
2018-02-15 13:21:00 -08:00
|
|
|
#include "util/misc/initialization_state_dcheck.h"
|
2018-04-30 12:57:03 -07:00
|
|
|
#include "util/numeric/checked_range.h"
|
2018-02-15 13:21:00 -08:00
|
|
|
#include "util/process/process_memory_fuchsia.h"
|
|
|
|
#include "util/process/process_memory_range.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
//! \brief Accesses information about another process, identified by a Fuchsia
|
|
|
|
//! process.
|
2018-02-22 12:12:26 -08:00
|
|
|
class ProcessReaderFuchsia {
|
2018-02-15 13:21:00 -08:00
|
|
|
public:
|
|
|
|
//! \brief Contains information about a module loaded into a process.
|
|
|
|
struct Module {
|
|
|
|
Module();
|
|
|
|
~Module();
|
|
|
|
|
2018-04-30 12:58:11 -07:00
|
|
|
//! \brief The `ZX_PROP_NAME` of the module.
|
2018-02-15 13:21:00 -08:00
|
|
|
std::string name;
|
|
|
|
|
|
|
|
//! \brief An image reader for the module.
|
|
|
|
//!
|
|
|
|
//! The lifetime of this ElfImageReader is scoped to the lifetime of the
|
2018-02-22 12:12:26 -08:00
|
|
|
//! ProcessReaderFuchsia that created it.
|
2018-02-15 13:21:00 -08:00
|
|
|
//!
|
|
|
|
//! This field may be `nullptr` if a reader could not be created for the
|
|
|
|
//! module.
|
|
|
|
ElfImageReader* reader;
|
2018-02-20 16:10:33 -08:00
|
|
|
|
|
|
|
//! \brief The module's type.
|
|
|
|
ModuleSnapshot::ModuleType type = ModuleSnapshot::kModuleTypeUnknown;
|
2018-02-15 13:21:00 -08:00
|
|
|
};
|
|
|
|
|
2018-02-22 11:06:35 -08:00
|
|
|
//! \brief Contains information about a thread that belongs to a process.
|
|
|
|
struct Thread {
|
|
|
|
Thread();
|
|
|
|
~Thread();
|
|
|
|
|
|
|
|
//! \brief The kernel identifier for the thread.
|
|
|
|
zx_koid_t id = ZX_KOID_INVALID;
|
|
|
|
|
|
|
|
//! \brief The state of the thread, the `ZX_THREAD_STATE_*` value or `-1` if
|
|
|
|
//! the value could not be retrieved.
|
|
|
|
uint32_t state = -1;
|
|
|
|
|
|
|
|
//! \brief The `ZX_PROP_NAME` property of the thread. This may be empty.
|
|
|
|
std::string name;
|
2018-04-12 14:16:10 -07:00
|
|
|
|
|
|
|
//! \brief The raw architecture-specific `zx_thread_state_general_regs_t` as
|
|
|
|
//! returned by `zx_thread_read_state()`.
|
|
|
|
zx_thread_state_general_regs_t general_registers = {};
|
2018-04-30 12:57:03 -07:00
|
|
|
|
2023-06-06 22:48:28 +00:00
|
|
|
//! \brief The raw architecture-specific `zx_thread_state_fp_regs_t` as
|
|
|
|
//! returned by `zx_thread_read_state()`.
|
|
|
|
zx_thread_state_fp_regs_t fp_registers = {};
|
|
|
|
|
2018-11-01 12:27:34 -07:00
|
|
|
//! \brief The raw architecture-specific `zx_thread_state_vector_regs_t` as
|
|
|
|
//! returned by `zx_thread_read_state()`.
|
|
|
|
zx_thread_state_vector_regs_t vector_registers = {};
|
|
|
|
|
2018-04-30 12:57:03 -07:00
|
|
|
//! \brief The regions representing the stack. The first entry in the vector
|
|
|
|
//! represents the callstack, and further entries optionally identify
|
|
|
|
//! other stack data when the thread uses a split stack representation.
|
|
|
|
std::vector<CheckedRange<zx_vaddr_t, size_t>> stack_regions;
|
2018-02-22 11:06:35 -08:00
|
|
|
};
|
|
|
|
|
2018-02-22 12:12:26 -08:00
|
|
|
ProcessReaderFuchsia();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
ProcessReaderFuchsia(const ProcessReaderFuchsia&) = delete;
|
|
|
|
ProcessReaderFuchsia& operator=(const ProcessReaderFuchsia&) = delete;
|
|
|
|
|
2018-02-22 12:12:26 -08:00
|
|
|
~ProcessReaderFuchsia();
|
2018-02-15 13:21:00 -08:00
|
|
|
|
|
|
|
//! \brief Initializes this object. This method must be called before any
|
|
|
|
//! other.
|
|
|
|
//!
|
|
|
|
//! \param[in] process A process handle with permissions to read properties
|
|
|
|
//! and memory from the target process.
|
|
|
|
//!
|
|
|
|
//! \return `true` on success, indicating that this object will respond
|
|
|
|
//! validly to further method calls. `false` on failure. On failure, no
|
|
|
|
//! further method calls should be made.
|
2018-07-30 15:50:17 -07:00
|
|
|
bool Initialize(const zx::process& process);
|
2018-02-15 13:21:00 -08:00
|
|
|
|
|
|
|
//! \return The modules loaded in the process. The first element (at index
|
|
|
|
//! `0`) corresponds to the main executable.
|
|
|
|
const std::vector<Module>& Modules();
|
|
|
|
|
2018-02-22 11:06:35 -08:00
|
|
|
//! \return The threads that are in the process.
|
|
|
|
const std::vector<Thread>& Threads();
|
|
|
|
|
|
|
|
//! \brief Return a memory reader for the target process.
|
2018-11-14 10:20:20 -08:00
|
|
|
const ProcessMemory* Memory() const { return process_memory_.get(); }
|
2018-02-22 11:06:35 -08:00
|
|
|
|
2018-12-14 13:17:43 -08:00
|
|
|
//! \brief Return a memory map for the target process.
|
2019-08-29 16:43:39 -07:00
|
|
|
const MemoryMapFuchsia* MemoryMap();
|
2018-12-14 13:17:43 -08:00
|
|
|
|
2018-02-15 13:21:00 -08:00
|
|
|
private:
|
2018-02-22 11:06:35 -08:00
|
|
|
//! Performs lazy initialization of the \a modules_ vector on behalf of
|
|
|
|
//! Modules().
|
2018-02-15 13:21:00 -08:00
|
|
|
void InitializeModules();
|
|
|
|
|
2018-02-22 11:06:35 -08:00
|
|
|
//! Performs lazy initialization of the \a threads_ vector on behalf of
|
|
|
|
//! Threads().
|
|
|
|
void InitializeThreads();
|
|
|
|
|
2019-08-29 16:43:39 -07:00
|
|
|
//! Performs lazy initialization of the \a memory_map_ on behalf of
|
|
|
|
//! MemoryMap().
|
|
|
|
void InitializeMemoryMap();
|
|
|
|
|
2018-02-15 13:21:00 -08:00
|
|
|
std::vector<Module> modules_;
|
2018-02-22 11:06:35 -08:00
|
|
|
std::vector<Thread> threads_;
|
2018-02-15 13:21:00 -08:00
|
|
|
std::vector<std::unique_ptr<ElfImageReader>> module_readers_;
|
|
|
|
std::vector<std::unique_ptr<ProcessMemoryRange>> process_memory_ranges_;
|
|
|
|
std::unique_ptr<ProcessMemoryFuchsia> process_memory_;
|
2019-08-29 16:43:39 -07:00
|
|
|
std::unique_ptr<MemoryMapFuchsia> memory_map_;
|
2018-07-30 15:50:17 -07:00
|
|
|
zx::unowned_process process_;
|
2018-02-15 13:21:00 -08:00
|
|
|
bool initialized_modules_ = false;
|
2018-02-22 11:06:35 -08:00
|
|
|
bool initialized_threads_ = false;
|
2019-08-29 16:43:39 -07:00
|
|
|
bool initialized_memory_map_ = false;
|
2018-02-15 13:21:00 -08:00
|
|
|
InitializationStateDcheck initialized_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
#endif // CRASHPAD_SNAPSHOT_FUCHSIA_PROCESS_READER_H_
|