diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 93e2f43..a6a0fdb 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -241,27 +241,27 @@ impl MemorySet { self.page_table.translate(vpn) } #[allow(unused)] - pub fn shrink_to(&mut self, start: VirtAddr, end: VirtAddr, new_end: VirtAddr) -> bool { + pub fn shrink_to(&mut self, start: VirtAddr, new_end: VirtAddr) -> bool { if let Some(area) = self .areas .iter_mut() - .find(|area| area.vpn_range.get_start() == start.floor() - && area.vpn_range.get_end() == end.ceil()) { - area.shrink_to(&mut self.page_table, new_end.ceil()); - true + .find(|area| area.vpn_range.get_start() == start.floor()) + { + area.shrink_to(&mut self.page_table, new_end.ceil()); + true } else { false } } #[allow(unused)] - pub fn append_to(&mut self, start: VirtAddr, end: VirtAddr, new_end: VirtAddr) -> bool { + pub fn append_to(&mut self, start: VirtAddr, new_end: VirtAddr) -> bool { if let Some(area) = self .areas .iter_mut() - .find(|area| area.vpn_range.get_start() == start.floor() - && area.vpn_range.get_end() == end.ceil()) { - area.append_to(&mut self.page_table, new_end.ceil()); - true + .find(|area| area.vpn_range.get_start() == start.floor()) + { + area.append_to(&mut self.page_table, new_end.ceil()); + true } else { false } diff --git a/os/src/sbi.rs b/os/src/sbi.rs index cdee65b..269581f 100644 --- a/os/src/sbi.rs +++ b/os/src/sbi.rs @@ -44,7 +44,6 @@ pub fn console_putchar(c: usize) { // pub fn console_getchar() -> usize { // sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0) // } - use crate::board::QEMUExit; /// use sbi call to shutdown the kernel pub fn shutdown() -> ! { diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index a39914a..d302373 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -1,6 +1,6 @@ //! Process management syscalls -use crate::task::{exit_current_and_run_next, suspend_current_and_run_next, change_program_brk}; +use crate::task::{change_program_brk, exit_current_and_run_next, suspend_current_and_run_next}; use crate::timer::get_time_ms; /// task exits and submit an exit code @@ -28,4 +28,4 @@ pub fn sys_sbrk(size: i32) -> isize { } else { -1 } -} \ No newline at end of file +} diff --git a/os/src/task/mod.rs b/os/src/task/mod.rs index bba26a1..dd27422 100644 --- a/os/src/task/mod.rs +++ b/os/src/task/mod.rs @@ -126,7 +126,7 @@ impl TaskManager { inner.tasks[inner.current_task].get_trap_cx() } - /// Change the current 'Running' task's program break + /// Change the current 'Running' task's program break pub fn change_current_program_brk(&self, size: i32) -> Option { let mut inner = self.inner.exclusive_access(); let cur = inner.current_task; @@ -200,7 +200,7 @@ pub fn current_trap_cx() -> &'static mut TrapContext { TASK_MANAGER.get_current_trap_cx() } - /// Change the current 'Running' task's program break - pub fn change_program_brk(size: i32) -> Option { +/// Change the current 'Running' task's program break +pub fn change_program_brk(size: i32) -> Option { TASK_MANAGER.change_current_program_brk(size) - } +} diff --git a/os/src/task/task.rs b/os/src/task/task.rs index 64e9f67..6c87ddd 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -62,12 +62,14 @@ impl TaskControlBlock { let old_break = self.program_brk; let new_brk = self.program_brk as isize + size as isize; if new_brk < self.heap_bottom as isize { - return None + return None; } let result = if size < 0 { - self.memory_set.shrink_to(VirtAddr(self.heap_bottom), VirtAddr(self.program_brk), VirtAddr(new_brk as usize)) + self.memory_set + .shrink_to(VirtAddr(self.heap_bottom), VirtAddr(new_brk as usize)) } else { - self.memory_set.append_to(VirtAddr(self.heap_bottom), VirtAddr(self.program_brk), VirtAddr(new_brk as usize)) + self.memory_set + .append_to(VirtAddr(self.heap_bottom), VirtAddr(new_brk as usize)) }; if result { self.program_brk = new_brk as usize; diff --git a/user/src/bin/sbrk_test.rs b/user/src/bin/sbrk_test.rs index 3dfe4f4..af21bd1 100644 --- a/user/src/bin/sbrk_test.rs +++ b/user/src/bin/sbrk_test.rs @@ -42,6 +42,5 @@ fn main() -> i32 { for pos in 0..PAGE_SIZE { new_page[pos] = 2; } - println!("Test sbrk OK!"); 0 }