Skip to content

Commit efd8589

Browse files
committed
make map_range safe
1 parent f34bae0 commit efd8589

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
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: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,10 @@ pub trait Mapper<S: PageSize> {
378378

379379
/// Maps frames from the allocator to the given range of virtual pages.
380380
///
381-
/// ## Safety
382-
///
383-
/// This is a convencience function that invokes [`Mapper::map_to_with_table_flags`] internally, so
384-
/// all safety requirements of it also apply for this function.
385-
///
386381
/// ## Errors
387382
///
388383
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
389-
unsafe fn map_range_with_table_flags<A>(
384+
fn map_range_with_table_flags<A>(
390385
&mut self,
391386
mut pages: PageRange<S>,
392387
flags: PageTableFlags,
@@ -403,13 +398,16 @@ pub trait Mapper<S: PageSize> {
403398
.allocate_frame()
404399
.ok_or((MapToError::FrameAllocationFailed, page))?;
405400

406-
self.map_to_with_table_flags(
407-
page,
408-
frame,
409-
flags,
410-
parent_table_flags,
411-
frame_allocator,
412-
)
401+
unsafe {
402+
// SAFETY: frame was just freshly allocated and therefore can't cause aliasing issues
403+
self.map_to_with_table_flags(
404+
page,
405+
frame,
406+
flags,
407+
parent_table_flags,
408+
frame_allocator,
409+
)
410+
}
413411
.map(|_| ())
414412
.map_err(|e| (e, page))
415413
})
@@ -427,16 +425,11 @@ pub trait Mapper<S: PageSize> {
427425

428426
/// Maps frames from the allocator to the given range of virtual pages.
429427
///
430-
/// ## Safety
431-
///
432-
/// This is a convencience function that invokes [`Mapper::map_range_with_table_flags`] internally, so
433-
/// all safety requirements of it also apply for this function.
434-
///
435428
/// ## Errors
436429
///
437430
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
438431
#[inline]
439-
unsafe fn map_range<A>(
432+
fn map_range<A>(
440433
&mut self,
441434
pages: PageRange<S>,
442435
flags: PageTableFlags,

src/structures/paging/mapper/offset_page_table.rs

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

9999
#[inline]
100-
unsafe fn map_range_with_table_flags<A>(
100+
fn map_range_with_table_flags<A>(
101101
&mut self,
102102
pages: PageRange<Size1GiB>,
103103
flags: PageTableFlags,
@@ -213,7 +213,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
213213
}
214214

215215
#[inline]
216-
unsafe fn map_range_with_table_flags<A>(
216+
fn map_range_with_table_flags<A>(
217217
&mut self,
218218
pages: PageRange<Size2MiB>,
219219
flags: PageTableFlags,
@@ -329,7 +329,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
329329
}
330330

331331
#[inline]
332-
unsafe fn map_range_with_table_flags<A>(
332+
fn map_range_with_table_flags<A>(
333333
&mut self,
334334
pages: PageRange<Size4KiB>,
335335
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)