From 0aa7b932cea1053ffd43694812cffc09ca1e43a7 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 2 Dec 2021 22:02:16 +0100 Subject: [PATCH] add an immutable getter for the level 4 page table --- src/structures/paging/mapper/mapped_page_table.rs | 9 +++++++-- src/structures/paging/mapper/offset_page_table.rs | 9 +++++++-- src/structures/paging/mapper/recursive_page_table.rs | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index 7ae9e2c83..83878d5b8 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -37,9 +37,14 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> { } } + /// Returns an immutable reference to the wrapped level 4 `PageTable` instance. + pub fn level_4_table(&self) -> &PageTable { + self.level_4_table + } + /// Returns a mutable reference to the wrapped level 4 `PageTable` instance. - pub fn level_4_table(&mut self) -> &mut PageTable { - &mut self.level_4_table + pub fn level_4_table_mut(&mut self) -> &mut PageTable { + self.level_4_table } /// Helper function for implementing Mapper. Safe to limit the scope of unsafe, see diff --git a/src/structures/paging/mapper/offset_page_table.rs b/src/structures/paging/mapper/offset_page_table.rs index 6cfaf42f6..a0b1d5eab 100644 --- a/src/structures/paging/mapper/offset_page_table.rs +++ b/src/structures/paging/mapper/offset_page_table.rs @@ -37,10 +37,15 @@ impl<'a> OffsetPageTable<'a> { } } - /// Returns a mutable reference to the wrapped level 4 `PageTable` instance. - pub fn level_4_table(&mut self) -> &mut PageTable { + /// Returns an immutable reference to the wrapped level 4 `PageTable` instance. + pub fn level_4_table(&self) -> &PageTable { self.inner.level_4_table() } + + /// Returns a mutable reference to the wrapped level 4 `PageTable` instance. + pub fn level_4_table_mut(&mut self) -> &mut PageTable { + self.inner.level_4_table_mut() + } } #[derive(Debug)] diff --git a/src/structures/paging/mapper/recursive_page_table.rs b/src/structures/paging/mapper/recursive_page_table.rs index b66aec176..bb6df2cfe 100644 --- a/src/structures/paging/mapper/recursive_page_table.rs +++ b/src/structures/paging/mapper/recursive_page_table.rs @@ -83,9 +83,14 @@ impl<'a> RecursivePageTable<'a> { } } + /// Returns an immutable reference to the wrapped level 4 `PageTable` instance. + pub fn level_4_table(&self) -> &PageTable { + self.p4 + } + /// Returns a mutable reference to the wrapped level 4 `PageTable` instance. - pub fn level_4_table(&mut self) -> &mut PageTable { - &mut self.p4 + pub fn level_4_table_mut(&mut self) -> &mut PageTable { + self.p4 } /// Internal helper function to create the page table of the next level if needed.