Skip to content

Commit 96a2892

Browse files
committed
make map_range safe
1 parent d3a8468 commit 96a2892

File tree

4 files changed

+20
-36
lines changed

4 files changed

+20
-36
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: 5 additions & 15 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,
@@ -458,9 +449,8 @@ pub trait Mapper<S: PageSize> {
458449
& (PageTableFlags::PRESENT
459450
| PageTableFlags::WRITABLE
460451
| PageTableFlags::USER_ACCESSIBLE);
461-
unsafe {
462-
self.map_range_with_table_flags(pages, flags, parent_table_flags, frame_allocator)
463-
}
452+
453+
self.map_range_with_table_flags(pages, flags, parent_table_flags, frame_allocator)
464454
}
465455

466456
/// Removes a mapping from the page table and returns the frame that used to be mapped.

src/structures/paging/mapper/offset_page_table.rs

Lines changed: 9 additions & 15 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,
@@ -112,10 +112,8 @@ impl<'a> Mapper<Size1GiB> for OffsetPageTable<'a> {
112112
where
113113
A: FrameAllocator<Size4KiB> + FrameAllocator<Size1GiB> + ?Sized,
114114
{
115-
unsafe {
116-
self.inner
117-
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
118-
}
115+
self.inner
116+
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
119117
}
120118

121119
#[inline]
@@ -224,7 +222,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
224222
}
225223

226224
#[inline]
227-
unsafe fn map_range_with_table_flags<A>(
225+
fn map_range_with_table_flags<A>(
228226
&mut self,
229227
pages: PageRange<Size2MiB>,
230228
flags: PageTableFlags,
@@ -234,10 +232,8 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
234232
where
235233
A: FrameAllocator<Size4KiB> + FrameAllocator<Size2MiB> + ?Sized,
236234
{
237-
unsafe {
238-
self.inner
239-
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
240-
}
235+
self.inner
236+
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
241237
}
242238

243239
#[inline]
@@ -346,7 +342,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
346342
}
347343

348344
#[inline]
349-
unsafe fn map_range_with_table_flags<A>(
345+
fn map_range_with_table_flags<A>(
350346
&mut self,
351347
pages: PageRange<Size4KiB>,
352348
flags: PageTableFlags,
@@ -356,10 +352,8 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
356352
where
357353
A: FrameAllocator<Size4KiB> + ?Sized,
358354
{
359-
unsafe {
360-
self.inner
361-
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
362-
}
355+
self.inner
356+
.map_range_with_table_flags(pages, flags, parent_table_flags, allocator)
363357
}
364358

365359
#[inline]

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)