From 3d4264ff4547ca690b924ff6bc053a9bf957da53 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Mon, 27 Jun 2022 20:43:47 +0200 Subject: [PATCH 1/2] fix comment --- src/structures/paging/mapper/mapped_page_table.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index 6a3aa9f4b..1b42170f9 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -20,13 +20,13 @@ pub struct MappedPageTable<'a, P: PageTableFrameMapping> { } impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> { - /// Creates a new `MappedPageTable` that uses the passed closure for converting virtual + /// Creates a new `MappedPageTable` that uses the passed `PageTableFrameMapping` for converting virtual /// to physical addresses. /// /// ## Safety /// /// This function is unsafe because the caller must guarantee that the passed `page_table_frame_mapping` - /// closure is correct. Also, the passed `level_4_table` must point to the level 4 page table + /// `PageTableFrameMapping` is correct. Also, the passed `level_4_table` must point to the level 4 page table /// of a valid page table hierarchy. Otherwise this function might break memory safety, e.g. /// by writing to an illegal memory location. #[inline] From 13358412a68efb5a401fcc6fa27a8edc30407410 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Mon, 27 Jun 2022 20:44:18 +0200 Subject: [PATCH 2/2] add getter for the offset in `OffsetPageTable` --- src/structures/paging/mapper/mapped_page_table.rs | 5 +++++ src/structures/paging/mapper/offset_page_table.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index 1b42170f9..5537fd02b 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -42,6 +42,11 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> { &mut self.level_4_table } + /// Returns the `PageTableFrameMapping` used for converting virtual to physical addresses. + pub fn page_table_frame_mapping(&self) -> &P { + &self.page_table_walker.page_table_frame_mapping + } + /// Helper function for implementing Mapper. Safe to limit the scope of unsafe, see /// https://github.com/rust-lang/rfcs/pull/2585. fn map_to_1gib( diff --git a/src/structures/paging/mapper/offset_page_table.rs b/src/structures/paging/mapper/offset_page_table.rs index 580924fe9..7a44132c8 100644 --- a/src/structures/paging/mapper/offset_page_table.rs +++ b/src/structures/paging/mapper/offset_page_table.rs @@ -42,6 +42,11 @@ impl<'a> OffsetPageTable<'a> { pub fn level_4_table(&mut self) -> &mut PageTable { self.inner.level_4_table() } + + /// Returns the offset used for converting virtual to physical addresses. + pub fn phys_offset(&self) -> VirtAddr { + self.inner.page_table_frame_mapping().offset + } } #[derive(Debug)]