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

Minor cleanups #24

Merged
merged 2 commits into from
Mar 23, 2023
Merged
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
34 changes: 16 additions & 18 deletions src/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ impl MemoryRegion {
pub const fn is_empty(&self) -> bool {
self.0.start.0 == self.0.end.0
}

fn split(&self, level: usize) -> ChunkedIterator {
ChunkedIterator {
range: self,
granularity: granularity_at_level(level),
start: self.0.start.0,
}
}

/// Returns whether this region can be mapped at 'level' using block mappings only.
fn is_block(&self, level: usize) -> bool {
let gran = granularity_at_level(level);
(self.0.start.0 | self.0.end.0) & (gran - 1) == 0
}
}

impl From<Range<VirtualAddress>> for MemoryRegion {
Expand Down Expand Up @@ -363,22 +377,6 @@ impl Iterator for ChunkedIterator<'_> {
}
}

impl MemoryRegion {
fn split(&self, level: usize) -> ChunkedIterator {
ChunkedIterator {
range: self,
granularity: granularity_at_level(level),
start: self.0.start.0,
}
}

/// Returns whether this region can be mapped at 'level' using block mappings only.
fn is_block(&self, level: usize) -> bool {
let gran = granularity_at_level(level);
(self.0.start.0 | self.0.end.0) & (gran - 1) == 0
}
}

bitflags! {
/// Attribute bits for a mapping in a page table.
pub struct Attributes: usize {
Expand Down Expand Up @@ -654,7 +652,7 @@ pub struct Descriptor(usize);
impl Descriptor {
const PHYSICAL_ADDRESS_BITMASK: usize = !(PAGE_SIZE - 1) & !(0xffff << 48);

fn output_address(&self) -> Option<PhysicalAddress> {
fn output_address(self) -> Option<PhysicalAddress> {
if self.is_valid() {
Some(PhysicalAddress(self.0 & Self::PHYSICAL_ADDRESS_BITMASK))
} else {
Expand Down Expand Up @@ -692,7 +690,7 @@ impl Descriptor {
}

fn subtable<T: Translation>(
&self,
self,
translation: &T,
level: usize,
) -> Option<PageTableWithLevel<T>> {
Expand Down