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