fmt & fixed
This commit is contained in:
parent
f45e14bfeb
commit
76ac3b9886
6 changed files with 21 additions and 21 deletions
|
@ -241,12 +241,12 @@ 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()) {
|
||||
.find(|area| area.vpn_range.get_start() == start.floor())
|
||||
{
|
||||
area.shrink_to(&mut self.page_table, new_end.ceil());
|
||||
true
|
||||
} else {
|
||||
|
@ -254,12 +254,12 @@ impl MemorySet {
|
|||
}
|
||||
}
|
||||
#[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()) {
|
||||
.find(|area| area.vpn_range.get_start() == start.floor())
|
||||
{
|
||||
area.append_to(&mut self.page_table, new_end.ceil());
|
||||
true
|
||||
} else {
|
||||
|
|
|
@ -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() -> ! {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -42,6 +42,5 @@ fn main() -> i32 {
|
|||
for pos in 0..PAGE_SIZE {
|
||||
new_page[pos] = 2;
|
||||
}
|
||||
println!("Test sbrk OK!");
|
||||
0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue