Skip to content

Commit 9e23888

Browse files
committed
make map_range safe
1 parent 1e3c87c commit 9e23888

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
@@ -380,15 +380,10 @@ pub trait Mapper<S: PageSize> {
380380

381381
/// Maps frames from the allocator to the given range of virtual pages.
382382
///
383-
/// ## Safety
384-
///
385-
/// This is a convencience function that invokes [`Mapper::map_to_with_table_flags`] internally, so
386-
/// all safety requirements of it also apply for this function.
387-
///
388383
/// ## Errors
389384
///
390385
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
391-
unsafe fn map_range_with_table_flags<A>(
386+
fn map_range_with_table_flags<A>(
392387
&mut self,
393388
mut pages: PageRange<S>,
394389
flags: PageTableFlags,
@@ -405,13 +400,16 @@ pub trait Mapper<S: PageSize> {
405400
.allocate_frame()
406401
.ok_or((MapToError::FrameAllocationFailed, page))?;
407402

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

430428
/// Maps frames from the allocator to the given range of virtual pages.
431429
///
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-
///
437430
/// ## Errors
438431
///
439432
/// If an error occurs half-way through a [`MapperFlushRange<S>`] is returned that contains the frames that were successfully mapped.
440433
#[inline]
441-
unsafe fn map_range<A>(
434+
fn map_range<A>(
442435
&mut self,
443436
pages: PageRange<S>,
444437
flags: PageTableFlags,

src/structures/paging/mapper/offset_page_table.rs

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

100100
#[inline]
101-
unsafe fn map_range_with_table_flags<A>(
101+
fn map_range_with_table_flags<A>(
102102
&mut self,
103103
pages: PageRange<Size1GiB>,
104104
flags: PageTableFlags,
@@ -214,7 +214,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
214214
}
215215

216216
#[inline]
217-
unsafe fn map_range_with_table_flags<A>(
217+
fn map_range_with_table_flags<A>(
218218
&mut self,
219219
pages: PageRange<Size2MiB>,
220220
flags: PageTableFlags,
@@ -330,7 +330,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
330330
}
331331

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