pub mod access;
pub mod heap;
pub mod mmio;
pub mod page_table;

mod platform;

use thiserror::Error;

pub use access::{FastMem, MemoryAccess};
pub use heap::{set_writer_ctx, GuestMemory, HeapType};
pub use mmio::MmioRegion;
pub use page_table::PageEntry;

#[derive(Debug, Error)]
pub enum MemoryError {
    #[error("Failed to allocate guest address space: {0}")]
    AllocationFailed(String),

    #[error("Invalid guest address: {0:#010x}")]
    InvalidAddress(u32),

    #[error("MMIO access at {0:#010x}")]
    MmioAccess(u32),

    #[error("Protection violation at {0:#010x}")]
    ProtectionViolation(u32),

    #[error("Out of memory in heap {0:?}")]
    OutOfMemory(HeapType),
}
