Skip to content

Commit

Permalink
Merge pull request #24 from google/cleanup
Browse files Browse the repository at this point in the history
Minor cleanups
  • Loading branch information
qwandor committed Mar 23, 2023
2 parents 8b573a0 + 25e6044 commit 1ade791
Showing 1 changed file with 16 additions and 18 deletions.
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

0 comments on commit 1ade791

Please sign in to comment.