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)
}
#[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
}

View file

@ -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() -> ! {

View file

@ -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
}
}
}

View file

@ -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<usize> {
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<usize> {
/// Change the current 'Running' task's program break
pub fn change_program_brk(size: i32) -> Option<usize> {
TASK_MANAGER.change_current_program_brk(size)
}
}

View file

@ -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;

View file

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