fmt & fixed

This commit is contained in:
闭浩扬 2023-02-04 22:43:58 +08:00
parent f45e14bfeb
commit 76ac3b9886
6 changed files with 21 additions and 21 deletions

View file

@ -241,27 +241,27 @@ impl MemorySet {
self.page_table.translate(vpn) self.page_table.translate(vpn)
} }
#[allow(unused)] #[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 if let Some(area) = self
.areas .areas
.iter_mut() .iter_mut()
.find(|area| area.vpn_range.get_start() == start.floor() .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()); area.shrink_to(&mut self.page_table, new_end.ceil());
true true
} else { } else {
false false
} }
} }
#[allow(unused)] #[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 if let Some(area) = self
.areas .areas
.iter_mut() .iter_mut()
.find(|area| area.vpn_range.get_start() == start.floor() .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()); area.append_to(&mut self.page_table, new_end.ceil());
true true
} else { } else {
false false
} }

View file

@ -44,7 +44,6 @@ pub fn console_putchar(c: usize) {
// pub fn console_getchar() -> usize { // pub fn console_getchar() -> usize {
// sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0) // sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
// } // }
use crate::board::QEMUExit; use crate::board::QEMUExit;
/// use sbi call to shutdown the kernel /// use sbi call to shutdown the kernel
pub fn shutdown() -> ! { pub fn shutdown() -> ! {

View file

@ -1,6 +1,6 @@
//! Process management syscalls //! 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; use crate::timer::get_time_ms;
/// task exits and submit an exit code /// task exits and submit an exit code
@ -28,4 +28,4 @@ pub fn sys_sbrk(size: i32) -> isize {
} else { } else {
-1 -1
} }
} }

View file

@ -126,7 +126,7 @@ impl TaskManager {
inner.tasks[inner.current_task].get_trap_cx() 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<usize> { pub fn change_current_program_brk(&self, size: i32) -> Option<usize> {
let mut inner = self.inner.exclusive_access(); let mut inner = self.inner.exclusive_access();
let cur = inner.current_task; let cur = inner.current_task;
@ -200,7 +200,7 @@ pub fn current_trap_cx() -> &'static mut TrapContext {
TASK_MANAGER.get_current_trap_cx() TASK_MANAGER.get_current_trap_cx()
} }
/// Change the current 'Running' task's program break /// Change the current 'Running' task's program break
pub fn change_program_brk(size: i32) -> Option<usize> { pub fn change_program_brk(size: i32) -> Option<usize> {
TASK_MANAGER.change_current_program_brk(size) TASK_MANAGER.change_current_program_brk(size)
} }

View file

@ -62,12 +62,14 @@ impl TaskControlBlock {
let old_break = self.program_brk; let old_break = self.program_brk;
let new_brk = self.program_brk as isize + size as isize; let new_brk = self.program_brk as isize + size as isize;
if new_brk < self.heap_bottom as isize { if new_brk < self.heap_bottom as isize {
return None return None;
} }
let result = if size < 0 { 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 { } 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 { if result {
self.program_brk = new_brk as usize; self.program_brk = new_brk as usize;

View file

@ -42,6 +42,5 @@ fn main() -> i32 {
for pos in 0..PAGE_SIZE { for pos in 0..PAGE_SIZE {
new_page[pos] = 2; new_page[pos] = 2;
} }
println!("Test sbrk OK!");
0 0
} }