Skip to main content

kernel/mm/
mm_error.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! MM Error Type
3//!
4//! Authors: MarioS271
5
6use crate::mm::vmm::VmmError;
7
8/// A wrapper around `Result<T, MmError>`
9pub type MmResult<T> = Result<T, MmError>;
10
11/// An enum which describes possible memory management errors that can occur
12#[derive(Debug)]
13pub enum MmError {
14    /// No free memory left to allocate
15    OutOfMemory,
16    /// The given address is not frame aligned
17    MisalignedAddress,
18    /// The requested region overlaps with an existing one
19    Overlap,
20    /// No region at the given address found
21    NotFound
22}
23impl From<VmmError> for MmError {
24    /// Convert a given [`VmmError`] to a [`MmError`]
25    fn from(value: VmmError) -> Self {
26        match value {
27            VmmError::OutOfMemory => Self::OutOfMemory,
28            VmmError::VmaOverlap => Self::Overlap,
29            VmmError::VmaNotFound => Self::NotFound,
30            VmmError::InvalidUnmap | VmmError::InvalidRemap => Self::NotFound
31        }
32    }
33}