Skip to content

Commit 1048a7d

Browse files
committed
make map_range safe
1 parent a4e2be8 commit 1048a7d

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

src/structures/paging/mapper/mapped_page_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size1GiB> for MappedPageTable<'a, P> {
598598
}
599599

600600
#[inline]
601-
unsafe fn map_range_with_table_flags<A>(
601+
fn map_range_with_table_flags<A>(
602602
&mut self,
603603
pages: PageRange<Size1GiB>,
604604
flags: PageTableFlags,
@@ -800,7 +800,7 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size2MiB> for MappedPageTable<'a, P> {
800800
}
801801

802802
#[inline]
803-
unsafe fn map_range_with_table_flags<A>(
803+
fn map_range_with_table_flags<A>(
804804
&mut self,
805805
pages: PageRange<Size2MiB>,
806806
flags: PageTableFlags,
@@ -1022,7 +1022,7 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size4KiB> for MappedPageTable<'a, P> {
10221022
}
10231023

10241024
#[inline]
1025-
unsafe fn map_range_with_table_flags<A>(
1025+
fn map_range_with_table_flags<A>(
10261026
&mut self,
10271027
pages: PageRange<Size4KiB>,
10281028
flags: PageTableFlags,

src/structures/paging/mapper/mod.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,10 @@ pub trait Mapper<S: PageSize> {
384384

385385
/// Maps frames from the allocator to the given range of virtual pages.
386386
///
387-
/// ## Safety
388-
///
389-
/// This is a convencience function that invokes [`Mapper::map_to_with_table_flags`] internally, so
390-
/// all safety requirements of it also apply for this function.
391-
///
392387
/// ## Errors
393388
///
394389
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
395-
unsafe fn map_range_with_table_flags<A>(
390+
fn map_range_with_table_flags<A>(
396391
&mut self,
397392
mut pages: PageRange<S>,
398393
flags: PageTableFlags,
@@ -410,6 +405,7 @@ pub trait Mapper<S: PageSize> {
410405
.ok_or((MapToError::FrameAllocationFailed, page))?;
411406

412407
unsafe {
408+
// SAFETY: frame was just freshly allocated and therefore can't cause aliasing issues
413409
self.map_to_with_table_flags(
414410
page,
415411
frame,
@@ -435,16 +431,11 @@ pub trait Mapper<S: PageSize> {
435431

436432
/// Maps frames from the allocator to the given range of virtual pages.
437433
///
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-
///
443434
/// ## Errors
444435
///
445436
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
446437
#[inline]
447-
unsafe fn map_range<A>(
438+
fn map_range<A>(
448439
&mut self,
449440
pages: PageRange<S>,
450441
flags: PageTableFlags,

src/structures/paging/mapper/offset_page_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> Mapper<Size1GiB> for OffsetPageTable<'a> {
102102
}
103103

104104
#[inline]
105-
unsafe fn map_range_with_table_flags<A>(
105+
fn map_range_with_table_flags<A>(
106106
&mut self,
107107
pages: PageRange<Size1GiB>,
108108
flags: PageTableFlags,
@@ -224,7 +224,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
224224
}
225225

226226
#[inline]
227-
unsafe fn map_range_with_table_flags<A>(
227+
fn map_range_with_table_flags<A>(
228228
&mut self,
229229
pages: PageRange<Size2MiB>,
230230
flags: PageTableFlags,
@@ -346,7 +346,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
346346
}
347347

348348
#[inline]
349-
unsafe fn map_range_with_table_flags<A>(
349+
fn map_range_with_table_flags<A>(
350350
&mut self,
351351
pages: PageRange<Size4KiB>,
352352
flags: PageTableFlags,

src/structures/paging/mapper/recursive_page_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ impl<'a> Mapper<Size1GiB> for RecursivePageTable<'a> {
767767
}
768768

769769
#[inline]
770-
unsafe fn map_range_with_table_flags<A>(
770+
fn map_range_with_table_flags<A>(
771771
&mut self,
772772
pages: PageRange<Size1GiB>,
773773
flags: PageTableFlags,
@@ -983,7 +983,7 @@ impl<'a> Mapper<Size2MiB> for RecursivePageTable<'a> {
983983
}
984984

985985
#[inline]
986-
unsafe fn map_range_with_table_flags<A>(
986+
fn map_range_with_table_flags<A>(
987987
&mut self,
988988
pages: PageRange<Size2MiB>,
989989
flags: PageTableFlags,
@@ -1234,7 +1234,7 @@ impl<'a> Mapper<Size4KiB> for RecursivePageTable<'a> {
12341234
}
12351235

12361236
#[inline]
1237-
unsafe fn map_range_with_table_flags<A>(
1237+
fn map_range_with_table_flags<A>(
12381238
&mut self,
12391239
pages: PageRange<Size4KiB>,
12401240
flags: PageTableFlags,

0 commit comments

Comments
 (0)