Skip to content

Commit

Permalink
完善了 sys_munmap 系统调用
Browse files Browse the repository at this point in the history
要提交的变更:
      修改:     src/mm/memory_set.rs
      修改:     src/mm/mod.rs
      修改:     src/mm/page_table.rs
      修改:     src/syscall/process.rs
      修改:     src/task/mod.rs
      修改:     src/task/processor.rs
  • Loading branch information
Eternal60f3 committed May 14, 2024
1 parent f14d713 commit 5ce895d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
17 changes: 17 additions & 0 deletions os/src/mm/memory_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ impl MemorySet {
-1
}
}

/// 取消当前进程指定区间的映射
/// 样例比较简单所以直接以开头页面进行删除了
pub fn unmap_vpnrange(&mut self, start: VirtPageNum, end: VirtPageNum) -> isize {
if let Some(_) = self.areas
.iter()
.position(|area| {
let (l, r) = (area.vpn_range.get_start(), area.vpn_range.get_end());
l == start && r == end
})
{
self.remove_area_with_start_vpn(start);
0
} else {
-1
}
}
}
/// map area structure, controls a contiguous piece of virtual memory
pub struct MapArea {
Expand Down
4 changes: 2 additions & 2 deletions os/src/mm/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ impl PageTable {
return None;
}
pub fn is_map(&self, vpn: VirtPageNum) -> bool {
if let Some(_) = self.find_pte(vpn) {
true
if let Some(pte) = self.find_pte(vpn) {
pte.is_valid()
} else {
false
}
Expand Down
11 changes: 6 additions & 5 deletions os/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ impl TaskManager {
curr_task.memory_set.insert_framed_area(start_va, end_va, permission);
}

/// unmap [start_va, end_va]
pub fn curr_munmap_with_start_vpn(&self, start_vpn: VirtPageNum) -> isize {
/// unmap [start_va, end _va]
pub fn curr_munmap(&self, start_vpn: VirtPageNum, end_vpn: VirtPageNum) -> isize {
let mut inner = self.inner.exclusive_access();
let curr_id = inner.current_task;
let curr_task = &mut inner.tasks[curr_id];
curr_task.memory_set.remove_area_with_start_vpn(start_vpn)
curr_task.memory_set.unmap_vpnrange(start_vpn, end_vpn)
}
}

Expand Down Expand Up @@ -346,9 +346,10 @@ pub fn curr_mmap(start: usize, len: usize, mut port: usize) -> isize {
pub fn curr_munmap(start: usize, len: usize) -> isize {
let start_va = VirtAddr::from(start);
let end_va = VirtAddr::from(start + len);
if !start_va.aligned() || curr_vpnrange_exist_unmap(start_va.floor(), end_va.ceil()) {
if !start_va.aligned() ||
curr_vpnrange_exist_unmap(start_va.floor(), end_va.ceil()) {
-1
} else {
TASK_MANAGER.curr_munmap_with_start_vpn(start_va.floor())
TASK_MANAGER.curr_munmap(start_va.floor(), end_va.ceil())
}
}

0 comments on commit 5ce895d

Please sign in to comment.