Skip to content

Commit 2ac88f7

Browse files
committed
Add Public Access to All Memory Regions
Add a function to the MemoryMapTag struct to access all memory regions
1 parent 30d64f4 commit 2ac88f7

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/memory_map.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ pub struct MemoryMapTag {
2323
impl MemoryMapTag {
2424
/// Return an iterator over all AVAILABLE marked memory areas.
2525
pub fn memory_areas(&self) -> MemoryAreaIter {
26+
MemoryAreaIter {
27+
iter: self.all_memory_areas();
28+
}
29+
}
30+
/// Return an iterator over all marked memory areas.
31+
pub fn all_memory_areas(&self) -> AllMemoryAreaIter {
2632
let self_ptr = self as *const MemoryMapTag;
2733
let start_area = (&self.first_area) as *const MemoryArea;
28-
MemoryAreaIter {
34+
AllMemoryAreaIter {
2935
current_area: start_area as u64,
3036
last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64),
3137
entry_size: self.entry_size,
@@ -91,26 +97,42 @@ pub enum MemoryAreaType {
9197
Defective,
9298
}
9399

94-
/// An iterator over Available memory areas.
100+
/// An iterator over all memory areas
95101
#[derive(Clone, Debug)]
96-
pub struct MemoryAreaIter<'a> {
102+
pub struct AllMemoryAreaIter<'a> {
97103
current_area: u64,
98104
last_area: u64,
99105
entry_size: u32,
100106
phantom: PhantomData<&'a MemoryArea>,
101107
}
102108

103-
impl<'a> Iterator for MemoryAreaIter<'a> {
109+
impl<'a> Iterator for AllMemoryAreaIter<'a> {
104110
type Item = &'a MemoryArea;
105111
fn next(&mut self) -> Option<&'a MemoryArea> {
106112
if self.current_area > self.last_area {
107113
None
108114
} else {
109115
let area = unsafe{&*(self.current_area as *const MemoryArea)};
110116
self.current_area = self.current_area + (self.entry_size as u64);
111-
if area.typ == 1 {
112-
Some(area)
113-
} else {self.next()}
117+
Some(area)
118+
}
119+
}
120+
}
121+
122+
/// An iterator over Available memory areas.
123+
#[derive(Clone, Debug)]
124+
pub struct MemoryAreaIter<'a> {
125+
iter: AllMemoryAreaIter<'a>,
126+
}
127+
128+
impl<'a> Iterator for MemoryAreaIter<'a> {
129+
type Item = &'a MemoryArea;
130+
fn next(&mut self) -> Option<&'a MemoryArea> {
131+
let ret = self.iter.next()?;
132+
if ret.typ == 1 {
133+
Some(ret)
134+
} else {
135+
self.next()
114136
}
115137
}
116138
}

0 commit comments

Comments
 (0)