pub trait Architecture {
type Registers: Registers;
type PageTableLevel: Debug + Clone + Copy;
type Interrupt: Debug + Clone + Copy;
type SpecialRegister: Debug + Clone + Copy;
type EventMonitor;
type EventReason: EventReason;
const PAGE_SIZE: u64;
const PAGE_SHIFT: u64;
const PAGE_MASK: u64;
const BREAKPOINT: &'static [u8];
// Required methods
fn gfn_from_pa(pa: Pa) -> Gfn;
fn pa_from_gfn(gfn: Gfn) -> Pa;
fn pa_offset(pa: Pa) -> u64;
fn va_align_down(va: Va) -> Va;
fn va_align_down_for(va: Va, level: Self::PageTableLevel) -> Va;
fn va_align_up(va: Va) -> Va;
fn va_align_up_for(va: Va, level: Self::PageTableLevel) -> Va;
fn va_offset(va: Va) -> u64;
fn va_offset_for(va: Va, level: Self::PageTableLevel) -> u64;
fn va_index(va: Va) -> u64;
fn va_index_for(va: Va, level: Self::PageTableLevel) -> u64;
fn translate_address<Driver>(
vmi: &VmiCore<Driver>,
va: Va,
root: Pa,
) -> Result<Pa, VmiError>
where Driver: VmiDriver<Architecture = Self>;
}
Expand description
Defines an interface for CPU architecture-specific operations and constants.
The Architecture
trait provides generic abstraction for interacting with
different CPU architectures in the context of virtual machine introspection.
This trait encapsulates the key characteristics and operations that vary across different CPU architectures, allowing for the implementation of architecture-agnostic tools and libraries.
Required Associated Constants§
Sourceconst PAGE_SIZE: u64
const PAGE_SIZE: u64
The size of a memory page in bytes for the given architecture.
§Architecture-specific
- AMD64:
0x1000
(4096 bytes)
Sourceconst PAGE_SHIFT: u64
const PAGE_SHIFT: u64
The number of bits to shift when converting between page numbers and physical addresses.
§Architecture-specific
- AMD64:
12
(2^12 = 4096)
Sourceconst PAGE_MASK: u64
const PAGE_MASK: u64
A bitmask used to isolate the page number from a full address.
§Architecture-specific
- AMD64:
0xFFFFFFFFFFFFF000
Sourceconst BREAKPOINT: &'static [u8]
const BREAKPOINT: &'static [u8]
The machine code for a breakpoint instruction in the given architecture.
§Architecture-specific
- AMD64:
&[0xcc]
(INT3
instruction)
Required Associated Types§
Sourcetype Registers: Registers
type Registers: Registers
The complete set of CPU registers for the architecture.
This type should include general-purpose registers, and all control and special registers.
Sourcetype PageTableLevel: Debug + Clone + Copy
type PageTableLevel: Debug + Clone + Copy
An enumeration representing the levels of page tables in the architecture’s paging structure.
§Architecture-specific
- AMD64: PML5, PML4, PDPT, PD, PT
Sourcetype Interrupt: Debug + Clone + Copy
type Interrupt: Debug + Clone + Copy
Various types of interrupts that can occur in the architecture.
Sourcetype SpecialRegister: Debug + Clone + Copy
type SpecialRegister: Debug + Clone + Copy
Represents special-purpose registers in the architecture.
§Architecture-specific
- AMD64: May represent control registers like
CR0
,CR2
,CR3
,CR4
Sourcetype EventMonitor
type EventMonitor
Options for monitoring.
Sourcetype EventReason: EventReason
type EventReason: EventReason
Architecture-specific event details.
Required Methods§
Sourcefn gfn_from_pa(pa: Pa) -> Gfn
fn gfn_from_pa(pa: Pa) -> Gfn
Converts a guest physical address (GPA) to a guest frame number (GFN).
§Architecture-specific
- AMD64:
gfn = pa >> 12
Sourcefn pa_from_gfn(gfn: Gfn) -> Pa
fn pa_from_gfn(gfn: Gfn) -> Pa
Converts a guest frame number (GFN) to a guest physical address (GPA).
§Architecture-specific
- AMD64:
pa = gfn << 12
Sourcefn pa_offset(pa: Pa) -> u64
fn pa_offset(pa: Pa) -> u64
Extracts the offset within a page from a physical address.
§Architecture-specific
- AMD64:
offset = pa & 0xfff
Sourcefn va_align_down(va: Va) -> Va
fn va_align_down(va: Va) -> Va
Aligns a virtual address down to the nearest page boundary.
§Architecture-specific
- AMD64:
va & ~0xfff
Sourcefn va_align_down_for(va: Va, level: Self::PageTableLevel) -> Va
fn va_align_down_for(va: Va, level: Self::PageTableLevel) -> Va
Aligns a virtual address down to the nearest page boundary for a given page table level.
Sourcefn va_align_up(va: Va) -> Va
fn va_align_up(va: Va) -> Va
Aligns a virtual address up to the nearest page boundary.
§Architecture-specific
- AMD64:
(va + 0xfff) & ~0xfff
Sourcefn va_align_up_for(va: Va, level: Self::PageTableLevel) -> Va
fn va_align_up_for(va: Va, level: Self::PageTableLevel) -> Va
Aligns a virtual address up to the nearest page boundary for a given page table level.
Sourcefn va_offset(va: Va) -> u64
fn va_offset(va: Va) -> u64
Extracts the offset within a page from a virtual address.
§Architecture-specific
- AMD64:
offset = va & 0xfff
Sourcefn va_offset_for(va: Va, level: Self::PageTableLevel) -> u64
fn va_offset_for(va: Va, level: Self::PageTableLevel) -> u64
Calculates the offset within a page for a given virtual address and page table level.
Sourcefn va_index(va: Va) -> u64
fn va_index(va: Va) -> u64
Calculates the index into the lowest level page table for a given virtual address.
§Architecture-specific
- AMD64:
index = va & 0x1ff
Sourcefn va_index_for(va: Va, level: Self::PageTableLevel) -> u64
fn va_index_for(va: Va, level: Self::PageTableLevel) -> u64
Calculates the index into the specified level of the page table hierarchy for a given virtual address.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.