提交 b2627812 编写于 作者: chyyuu1972's avatar chyyuu1972

fix bug in impl Drop for FrameTracker, for the correctly mapping/unmapping display buffer in app

上级 fbb59236
......@@ -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),
......
......@@ -108,6 +108,7 @@ impl DrawingBoard {
pub fn main() -> i32 {
// let fb_ptr = framebuffer() as *mut u8;
let mut board = DrawingBoard::new();
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
for i in 0..20 {
board.latest_pos.x += i;
board.latest_pos.y += i;
......
......@@ -382,6 +382,7 @@ const CR: u8 = 0x0du8;
pub fn main() -> i32 {
let mut disp = Display::new(Size::new(1280, 800), Point::new(0, 0));
let mut game = SnakeGame::<20, Rgb888>::new(1280, 800, 20, 20, Rgb888::RED, Rgb888::YELLOW, 50);
let _ = disp.clear(Rgb888::BLACK).unwrap();
loop {
if key_pressed() {
let c = getchar();
......
......@@ -111,6 +111,7 @@ const CR: u8 = 0x0du8;
pub fn main() -> i32 {
// let fb_ptr = framebuffer() as *mut u8;
let mut board = DrawingBoard::new();
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
for i in 0..20 {
let c=getchar();
if c == LF || c == CR {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册