Skip to content

Commit

Permalink
Make update_flags unsafe too
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Apr 11, 2020
1 parent 84aa200 commit 78ddc43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/structures/paging/mapper/mapped_page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'a, P: PhysToVirt> Mapper<Size1GiB> for MappedPageTable<'a, P> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size1GiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -237,7 +237,7 @@ impl<'a, P: PhysToVirt> Mapper<Size2MiB> for MappedPageTable<'a, P> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size2MiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<'a, P: PhysToVirt> Mapper<Size4KiB> for MappedPageTable<'a, P> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size4KiB>,
flags: PageTableFlags,
Expand Down
10 changes: 9 additions & 1 deletion src/structures/paging/mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ pub trait Mapper<S: PageSize> {
fn unmap(&mut self, page: Page<S>) -> Result<(PhysFrame<S>, MapperFlush<S>), UnmapError>;

/// Updates the flags of an existing mapping.
fn update_flags(
///
/// ## Safety
///
/// This method is unsafe because changing the flags of a mapping
/// might result in undefined behavior. For example, setting the
/// `GLOBAL` and `MUTABLE` flags for a page might result in the corruption
/// of values stored in that page from processes running in other address
/// spaces.
unsafe fn update_flags(
&mut self,
page: Page<S>,
flags: PageTableFlags,
Expand Down
6 changes: 3 additions & 3 deletions src/structures/paging/mapper/offset_page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> Mapper<Size1GiB> for OffsetPageTable<'a> {
}

#[inline]
fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size1GiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
}

#[inline]
fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size2MiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
}

#[inline]
fn update_flags(
unsafe fn update_flags(
&mut self,
page: Page<Size4KiB>,
flags: PageTableFlags,
Expand Down
12 changes: 9 additions & 3 deletions src/structures/paging/mapper/recursive_page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ impl<'a> Mapper<Size1GiB> for RecursivePageTable<'a> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
// allow unused_unsafe until https://github.com/rust-lang/rust/pull/69245 lands
#[allow(unused_unsafe)]
unsafe fn update_flags(
&mut self,
page: Page<Size1GiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -359,7 +361,9 @@ impl<'a> Mapper<Size2MiB> for RecursivePageTable<'a> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
// allow unused_unsafe until https://github.com/rust-lang/rust/pull/69245 lands
#[allow(unused_unsafe)]
unsafe fn update_flags(
&mut self,
page: Page<Size2MiB>,
flags: PageTableFlags,
Expand Down Expand Up @@ -465,7 +469,9 @@ impl<'a> Mapper<Size4KiB> for RecursivePageTable<'a> {
Ok((frame, MapperFlush::new(page)))
}

fn update_flags(
// allow unused_unsafe until https://github.com/rust-lang/rust/pull/69245 lands
#[allow(unused_unsafe)]
unsafe fn update_flags(
&mut self,
page: Page<Size4KiB>,
flags: PageTableFlags,
Expand Down

0 comments on commit 78ddc43

Please sign in to comment.