Skip to content

Commit

Permalink
Merge pull request #385 from Freax13/phys-offset-getter
Browse files Browse the repository at this point in the history
add getters for the page table frame mapping
  • Loading branch information
phil-opp committed Jul 10, 2022
2 parents 3a8f380 + 1335841 commit 1d45d06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/structures/paging/mapper/mapped_page_table.rs
Expand Up @@ -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]
Expand All @@ -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<A>(
Expand Down
5 changes: 5 additions & 0 deletions src/structures/paging/mapper/offset_page_table.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 1d45d06

Please sign in to comment.