From aa85dbb4f1ff00a60019ced140e9d7bf984d44c5 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 6 Mar 2020 14:38:22 +0100 Subject: [PATCH 1/2] Add a Mapper::map convenience function --- src/structures/paging/mapper/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index d1c73898c..53f126a90 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -321,6 +321,34 @@ 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. /// /// ## Safety From 9c7ff09fd77030d72360d286af0353155abd0e85 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 6 Mar 2020 14:38:40 +0100 Subject: [PATCH 2/2] Improve docs for Mapper::identity_map --- src/structures/paging/mapper/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index 53f126a90..564b35084 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -351,6 +351,10 @@ pub trait Mapper { /// 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