Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Mapper::map convenience method #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/structures/paging/mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,40 @@ pub trait Mapper<S: PageSize> {
/// error otherwise.
fn translate_page(&self, page: Page<S>) -> Result<PhysFrame<S>, 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<A>(
&mut self,
page: Page<S>,
flags: PageTableFlags,
frame_allocator: &mut A,
) -> Result<MapperFlush<S>, MapToError<S>>
where
Self: Sized,
A: FrameAllocator<Size4KiB> + FrameAllocator<S>,
{
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
Expand Down