Skip to content

Commit 1e3c87c

Browse files
committed
add map_range
1 parent 03d111d commit 1e3c87c

File tree

1 file changed

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

1 file changed

+28
-0
lines changed

src/structures/paging/mapper/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,34 @@ pub trait Mapper<S: PageSize> {
427427
})
428428
}
429429

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

0 commit comments

Comments
 (0)