Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getters for the page table frame mapping #385

Merged
merged 2 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/structures/paging/mapper/mapped_page_table.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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