-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,15 @@ pub struct MemoryMapTag { | |
impl MemoryMapTag { | ||
/// Return an iterator over all AVAILABLE marked memory areas. | ||
pub fn memory_areas(&self) -> MemoryAreaIter { | ||
MemoryAreaIter { | ||
iter: self.all_memory_areas(), | ||
} | ||
} | ||
/// Return an iterator over all marked memory areas. | ||
pub fn all_memory_areas(&self) -> AllMemoryAreaIter { | ||
let self_ptr = self as *const MemoryMapTag; | ||
let start_area = (&self.first_area) as *const MemoryArea; | ||
MemoryAreaIter { | ||
AllMemoryAreaIter { | ||
current_area: start_area as u64, | ||
last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64), | ||
entry_size: self.entry_size, | ||
|
@@ -91,26 +97,42 @@ pub enum MemoryAreaType { | |
Defective, | ||
} | ||
|
||
/// An iterator over Available memory areas. | ||
/// An iterator over all memory areas | ||
#[derive(Clone, Debug)] | ||
pub struct MemoryAreaIter<'a> { | ||
pub struct AllMemoryAreaIter<'a> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks to me like EFIMemoryMapTag already iterates over all memory areas. |
||
current_area: u64, | ||
last_area: u64, | ||
entry_size: u32, | ||
phantom: PhantomData<&'a MemoryArea>, | ||
} | ||
|
||
impl<'a> Iterator for MemoryAreaIter<'a> { | ||
impl<'a> Iterator for AllMemoryAreaIter<'a> { | ||
type Item = &'a MemoryArea; | ||
fn next(&mut self) -> Option<&'a MemoryArea> { | ||
if self.current_area > self.last_area { | ||
None | ||
} 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) | ||
} | ||
} | ||
} | ||
|
||
/// An iterator over Available memory areas. | ||
#[derive(Clone, Debug)] | ||
pub struct MemoryAreaIter<'a> { | ||
iter: AllMemoryAreaIter<'a>, | ||
} | ||
|
||
impl<'a> Iterator for MemoryAreaIter<'a> { | ||
type Item = &'a MemoryArea; | ||
fn next(&mut self) -> Option<&'a MemoryArea> { | ||
let ret = self.iter.next()?; | ||
if ret.typ == 1 { | ||
Some(ret) | ||
} else { | ||
self.next() | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if, rather than having two iteratory types, this could return
impl Iterator<Item = &MemoryArea>
(maybe you'll need a lifetime idk) and then the body could beself.all_memory_areas().filter(|entry| entry.typ == 1)
? I think that'd be cleaner, if it works.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be cleaner and it does work. Initially I was worried that filter wouldn't work without the standard library (I'm using this crate for work on an OS kernel where I don't have the standard library and I'm new to working without the standard library, so I haven't yet figured out what is part of the standard library vs what is part of core), so I chose to avoid using filter initially. On further investigation, it seems to work fine, so I will update my pull request to make use of fileter.