fix bug in impl Drop for FrameTracker, for the correctly mapping/unmapping display buffer in app
This commit is contained in:
parent
2cbd237260
commit
73fcb72cbb
6 changed files with 16 additions and 5 deletions
|
@ -7,6 +7,7 @@ use lazy_static::*;
|
|||
|
||||
pub struct FrameTracker {
|
||||
pub ppn: PhysPageNum,
|
||||
pub nodrop: bool,
|
||||
}
|
||||
|
||||
impl FrameTracker {
|
||||
|
@ -16,10 +17,10 @@ impl FrameTracker {
|
|||
for i in bytes_array {
|
||||
*i = 0;
|
||||
}
|
||||
Self { ppn }
|
||||
Self { ppn, nodrop: false }
|
||||
}
|
||||
pub fn new_nowrite(ppn: PhysPageNum) -> Self {
|
||||
Self { ppn }
|
||||
pub fn new_noalloc(ppn: PhysPageNum) -> Self {
|
||||
Self { ppn, nodrop: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,9 @@ impl Debug for FrameTracker {
|
|||
|
||||
impl Drop for FrameTracker {
|
||||
fn drop(&mut self) {
|
||||
if self.nodrop {
|
||||
return;
|
||||
}
|
||||
frame_dealloc(self.ppn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,6 +290,9 @@ impl MapArea {
|
|||
ppn = frame.ppn;
|
||||
self.data_frames.insert(vpn, frame);
|
||||
}
|
||||
MapType::Noalloc => {
|
||||
panic!("Noalloc should not be mapped");
|
||||
}
|
||||
}
|
||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
||||
page_table.map(vpn, ppn, pte_flags);
|
||||
|
@ -307,7 +310,7 @@ impl MapArea {
|
|||
}
|
||||
pub fn map_noalloc(&mut self, page_table: &mut PageTable,ppn_range:PPNRange) {
|
||||
for (vpn,ppn) in core::iter::zip(self.vpn_range,ppn_range) {
|
||||
self.data_frames.insert(vpn, FrameTracker::new_nowrite(ppn));
|
||||
self.data_frames.insert(vpn, FrameTracker::new_noalloc(ppn));
|
||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
||||
page_table.map(vpn, ppn, pte_flags);
|
||||
}
|
||||
|
@ -346,6 +349,7 @@ impl MapArea {
|
|||
pub enum MapType {
|
||||
Identical,
|
||||
Framed,
|
||||
Noalloc,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn sys_framebuffer() -> isize {
|
|||
MapArea::new(
|
||||
(FB_VADDR as usize).into(),
|
||||
(FB_VADDR + len as usize).into(),
|
||||
MapType::Framed,
|
||||
MapType::Noalloc,
|
||||
MapPermission::R | MapPermission::W | MapPermission::U,
|
||||
),
|
||||
PPNRange::new(fb_ppn, fb_end_ppn),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue