Skip to content

Commit c65ec51

Browse files
committed
Make update_flags unsafe too
1 parent 817a88f commit c65ec51

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/structures/paging/mapper/mapped_page_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a, P: PhysToVirt> Mapper<Size1GiB> for MappedPageTable<'a, P> {
161161
Ok((frame, MapperFlush::new(page)))
162162
}
163163

164-
fn update_flags(
164+
unsafe fn update_flags(
165165
&mut self,
166166
page: Page<Size1GiB>,
167167
flags: PageTableFlags,
@@ -237,7 +237,7 @@ impl<'a, P: PhysToVirt> Mapper<Size2MiB> for MappedPageTable<'a, P> {
237237
Ok((frame, MapperFlush::new(page)))
238238
}
239239

240-
fn update_flags(
240+
unsafe fn update_flags(
241241
&mut self,
242242
page: Page<Size2MiB>,
243243
flags: PageTableFlags,
@@ -315,7 +315,7 @@ impl<'a, P: PhysToVirt> Mapper<Size4KiB> for MappedPageTable<'a, P> {
315315
Ok((frame, MapperFlush::new(page)))
316316
}
317317

318-
fn update_flags(
318+
unsafe fn update_flags(
319319
&mut self,
320320
page: Page<Size4KiB>,
321321
flags: PageTableFlags,

src/structures/paging/mapper/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ pub trait Mapper<S: PageSize> {
128128
fn unmap(&mut self, page: Page<S>) -> Result<(PhysFrame<S>, MapperFlush<S>), UnmapError>;
129129

130130
/// Updates the flags of an existing mapping.
131-
fn update_flags(
131+
///
132+
/// ## Safety
133+
///
134+
/// This method is unsafe because changing the flags of a mapping
135+
/// might result in undefined behavior. For example, setting the
136+
/// `GLOBAL` and `MUTABLE` flags for a page might result in the corruption
137+
/// of values stored in that page from processes running in other address
138+
/// spaces.
139+
unsafe fn update_flags(
132140
&mut self,
133141
page: Page<S>,
134142
flags: PageTableFlags,

src/structures/paging/mapper/offset_page_table.rs

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

7777
#[inline]
78-
fn update_flags(
78+
unsafe fn update_flags(
7979
&mut self,
8080
page: Page<Size1GiB>,
8181
flags: PageTableFlags,
@@ -113,7 +113,7 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
113113
}
114114

115115
#[inline]
116-
fn update_flags(
116+
unsafe fn update_flags(
117117
&mut self,
118118
page: Page<Size2MiB>,
119119
flags: PageTableFlags,
@@ -151,7 +151,7 @@ impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
151151
}
152152

153153
#[inline]
154-
fn update_flags(
154+
unsafe fn update_flags(
155155
&mut self,
156156
page: Page<Size4KiB>,
157157
flags: PageTableFlags,

src/structures/paging/mapper/recursive_page_table.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ impl<'a> Mapper<Size1GiB> for RecursivePageTable<'a> {
267267
Ok((frame, MapperFlush::new(page)))
268268
}
269269

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

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

468-
fn update_flags(
472+
// allow unused_unsafe until https://github.com/rust-lang/rust/pull/69245 lands
473+
#[allow(unused_unsafe)]
474+
unsafe fn update_flags(
469475
&mut self,
470476
page: Page<Size4KiB>,
471477
flags: PageTableFlags,

0 commit comments

Comments
 (0)