Skip to content

Access to non-available memory areas #71

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

Merged
merged 3 commits into from
Nov 2, 2020
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
13 changes: 8 additions & 5 deletions src/memory_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ pub struct MemoryMapTag {

impl MemoryMapTag {
/// Return an iterator over all AVAILABLE marked memory areas.
pub fn memory_areas(&self) -> MemoryAreaIter {
pub fn memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
self.all_memory_areas().filter(|entry| entry.typ == 1)
}

/// Return an iterator over all marked memory areas.
pub fn all_memory_areas(&self) -> MemoryAreaIter {
let self_ptr = self as *const MemoryMapTag;
let start_area = (&self.first_area) as *const MemoryArea;
MemoryAreaIter {
Expand Down Expand Up @@ -91,7 +96,7 @@ pub enum MemoryAreaType {
Defective,
}

/// An iterator over Available memory areas.
/// An iterator over all memory areas
#[derive(Clone, Debug)]
pub struct MemoryAreaIter<'a> {
current_area: u64,
Expand All @@ -108,9 +113,7 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
} else {
let area = unsafe{&*(self.current_area as *const MemoryArea)};
self.current_area = self.current_area + (self.entry_size as u64);
if area.typ == 1 {
Some(area)
} else {self.next()}
Some(area)
}
}
}
Expand Down