From 604a79b636f54470dcabbd55ae9cf74c141ecf0f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 6 Mar 2020 14:41:53 +0100 Subject: [PATCH] Make update_flags unsafe too --- src/structures/paging/mapper/mapped_page_table.rs | 6 +++--- src/structures/paging/mapper/mod.rs | 10 +++++++++- src/structures/paging/mapper/offset_page_table.rs | 6 +++--- src/structures/paging/mapper/recursive_page_table.rs | 12 +++++++++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index 4e706fa83..9a0486ec7 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -161,7 +161,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { Ok((frame, MapperFlush::new(page))) } - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, @@ -237,7 +237,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { Ok((frame, MapperFlush::new(page))) } - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, @@ -315,7 +315,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { Ok((frame, MapperFlush::new(page))) } - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index 01c15cb36..85b6ac856 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -128,7 +128,15 @@ pub trait Mapper { fn unmap(&mut self, page: Page) -> Result<(PhysFrame, MapperFlush), 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, flags: PageTableFlags, diff --git a/src/structures/paging/mapper/offset_page_table.rs b/src/structures/paging/mapper/offset_page_table.rs index a646c93c1..23e4da4d2 100644 --- a/src/structures/paging/mapper/offset_page_table.rs +++ b/src/structures/paging/mapper/offset_page_table.rs @@ -75,7 +75,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { } #[inline] - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, @@ -113,7 +113,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { } #[inline] - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, @@ -151,7 +151,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { } #[inline] - fn update_flags( + unsafe fn update_flags( &mut self, page: Page, flags: PageTableFlags, diff --git a/src/structures/paging/mapper/recursive_page_table.rs b/src/structures/paging/mapper/recursive_page_table.rs index 7c1c7f37f..53901031c 100644 --- a/src/structures/paging/mapper/recursive_page_table.rs +++ b/src/structures/paging/mapper/recursive_page_table.rs @@ -267,7 +267,9 @@ impl<'a> Mapper 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, flags: PageTableFlags, @@ -359,7 +361,9 @@ impl<'a> Mapper 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, flags: PageTableFlags, @@ -465,7 +469,9 @@ impl<'a> Mapper 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, flags: PageTableFlags,