Skip to main content

ax_memory_set/
lib.rs

1#![cfg_attr(not(test), no_std)]
2#![doc = include_str!("../README.md")]
3
4extern crate alloc;
5
6mod area;
7mod backend;
8mod set;
9
10#[cfg(test)]
11mod tests;
12
13pub use self::{area::MemoryArea, backend::MappingBackend, set::MemorySet};
14
15/// Error type for memory mapping operations.
16#[derive(Debug, Eq, PartialEq)]
17pub enum MappingError {
18    /// Invalid parameter (e.g., `addr`, `size`, `flags`, etc.)
19    InvalidParam,
20    /// The given range overlaps with an existing mapping.
21    AlreadyExists,
22    /// The backend page table is in a bad state.
23    BadState,
24}
25
26#[cfg(feature = "ax-errno")]
27impl From<MappingError> for ax_errno::AxError {
28    fn from(err: MappingError) -> Self {
29        match err {
30            MappingError::InvalidParam => ax_errno::AxError::InvalidInput,
31            MappingError::AlreadyExists => ax_errno::AxError::AlreadyExists,
32            MappingError::BadState => ax_errno::AxError::BadState,
33        }
34    }
35}
36
37/// A [`Result`] type with [`MappingError`] as the error type.
38pub type MappingResult<T = ()> = Result<T, MappingError>;