Skip to content

Commit a4e2be8

Browse files
committed
add map_range
1 parent c47ddff commit a4e2be8

File tree

1 file changed

+30
-0
lines changed
  • src/structures/paging/mapper

1 file changed

+30
-0
lines changed

src/structures/paging/mapper/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,36 @@ pub trait Mapper<S: PageSize> {
433433
})
434434
}
435435

436+
/// Maps frames from the allocator to the given range of virtual pages.
437+
///
438+
/// ## Safety
439+
///
440+
/// This is a convencience function that invokes [`Mapper::map_range_with_table_flags`] internally, so
441+
/// all safety requirements of it also apply for this function.
442+
///
443+
/// ## Errors
444+
///
445+
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
446+
#[inline]
447+
unsafe fn map_range<A>(
448+
&mut self,
449+
pages: PageRange<S>,
450+
flags: PageTableFlags,
451+
frame_allocator: &mut A,
452+
) -> Result<MapperFlushRange<S>, (MapToError<S>, MapperFlushRange<S>)>
453+
where
454+
Self: Sized,
455+
A: FrameAllocator<Size4KiB> + FrameAllocator<S> + ?Sized,
456+
{
457+
let parent_table_flags = flags
458+
& (PageTableFlags::PRESENT
459+
| PageTableFlags::WRITABLE
460+
| PageTableFlags::USER_ACCESSIBLE);
461+
unsafe {
462+
self.map_range_with_table_flags(pages, flags, parent_table_flags, frame_allocator)
463+
}
464+
}
465+
436466
/// Removes a mapping from the page table and returns the frame that used to be mapped.
437467
///
438468
/// Note that no page tables or pages are deallocated.

0 commit comments

Comments
 (0)