diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index d1c73898c..564b35084 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -321,8 +321,40 @@ pub trait Mapper { /// error otherwise. fn translate_page(&self, page: Page) -> Result, TranslateError>; + /// Maps the given page to an unused frame obtained from the frame_allocator. + /// + /// This function allocates at least one physical frame from the given + /// frame allocator. It might also need additional physical frames to create + /// new page tables, which are also allocated from the `frame_allocator` + /// argument. At most four frames are required from the allocator in total. + /// + /// ## Safety + /// + /// This is a convencience function that invokes [`map_to`] internally, so + /// all safety requirements of it also apply for this function. + #[inline] + unsafe fn map( + &mut self, + page: Page, + flags: PageTableFlags, + frame_allocator: &mut A, + ) -> Result, MapToError> + where + Self: Sized, + A: FrameAllocator + FrameAllocator, + { + let frame = frame_allocator + .allocate_frame() + .ok_or(MapToError::FrameAllocationFailed)?; + self.map_to(page, frame, flags, frame_allocator) + } + /// Maps the given frame to the virtual page with the same address. /// + /// This function might need additional physical frames to create new page + /// tables. These frames are allocated from the `frame_allocator` argument. + /// At most three frames are required. + /// /// ## Safety /// /// This is a convencience function that invokes [`map_to`] internally, so