Skip to main content

iptr_edge_analyzer/memory_reader/
mod.rs

1//! This module contains the core definition of [`ReadMemory`] trait,
2//! and several implementors like [`PerfMmapBasedMemoryReader`][perf_mmap::PerfMmapBasedMemoryReader].
3
4#[cfg(feature = "libxdc_memory_reader")]
5pub mod libxdc;
6#[cfg(feature = "perf_memory_reader")]
7pub mod perf_mmap;
8
9/// Memory reader
10pub trait ReadMemory {
11    /// Error for memory reading
12    type Error: std::error::Error;
13
14    /// Callback at begin of decoding.
15    ///
16    /// This is useful when using the same handler to process multiple Intel PT
17    /// traces
18    fn at_decode_begin(&mut self) -> Result<(), Self::Error>;
19
20    /// Read memories at given address with given size, and
21    /// invoke the given callback with the read memories.
22    ///
23    /// This function is allowed to read memories shorter than
24    /// `size`. The length of read bytes should be determined from users
25    /// by check the length of `&[u8]` at callback.
26    ///
27    /// This function will return the callback return value on success.
28    fn read_memory<T>(
29        &mut self,
30        address: u64,
31        size: usize,
32        callback: impl FnOnce(&[u8]) -> T,
33    ) -> Result<T, Self::Error>;
34}