Skip to content

Commit 1d45d06

Browse files
authored
Merge pull request #385 from Freax13/phys-offset-getter
add getters for the page table frame mapping
2 parents 3a8f380 + 1335841 commit 1d45d06

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/structures/paging/mapper/mapped_page_table.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ pub struct MappedPageTable<'a, P: PageTableFrameMapping> {
2020
}
2121

2222
impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> {
23-
/// Creates a new `MappedPageTable` that uses the passed closure for converting virtual
23+
/// Creates a new `MappedPageTable` that uses the passed `PageTableFrameMapping` for converting virtual
2424
/// to physical addresses.
2525
///
2626
/// ## Safety
2727
///
2828
/// This function is unsafe because the caller must guarantee that the passed `page_table_frame_mapping`
29-
/// closure is correct. Also, the passed `level_4_table` must point to the level 4 page table
29+
/// `PageTableFrameMapping` is correct. Also, the passed `level_4_table` must point to the level 4 page table
3030
/// of a valid page table hierarchy. Otherwise this function might break memory safety, e.g.
3131
/// by writing to an illegal memory location.
3232
#[inline]
@@ -42,6 +42,11 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> {
4242
&mut self.level_4_table
4343
}
4444

45+
/// Returns the `PageTableFrameMapping` used for converting virtual to physical addresses.
46+
pub fn page_table_frame_mapping(&self) -> &P {
47+
&self.page_table_walker.page_table_frame_mapping
48+
}
49+
4550
/// Helper function for implementing Mapper. Safe to limit the scope of unsafe, see
4651
/// https://github.com/rust-lang/rfcs/pull/2585.
4752
fn map_to_1gib<A>(

src/structures/paging/mapper/offset_page_table.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ impl<'a> OffsetPageTable<'a> {
4242
pub fn level_4_table(&mut self) -> &mut PageTable {
4343
self.inner.level_4_table()
4444
}
45+
46+
/// Returns the offset used for converting virtual to physical addresses.
47+
pub fn phys_offset(&self) -> VirtAddr {
48+
self.inner.page_table_frame_mapping().offset
49+
}
4550
}
4651

4752
#[derive(Debug)]

0 commit comments

Comments
 (0)