@@ -190,6 +190,29 @@ impl TaskManager {
190190 memory_set. insert_framed_area ( start_va, end_va, map_perm) ;
191191 true
192192 }
193+
194+ /// Unmap memory area for the current task
195+ fn munmap_for_current_task (
196+ & self ,
197+ start_va : crate :: mm:: VirtAddr ,
198+ end_va : crate :: mm:: VirtAddr ,
199+ ) -> bool {
200+ let mut inner = self . inner . exclusive_access ( ) ;
201+ let current = inner. current_task ;
202+ let memory_set = & mut inner. tasks [ current] . memory_set ;
203+
204+ // 检查地址范围是否完全被映射
205+ let start_vpn = start_va. floor ( ) ;
206+ let end_vpn = end_va. ceil ( ) ;
207+ for vpn in crate :: mm:: VPNRange :: new ( start_vpn, end_vpn) {
208+ if memory_set. translate ( vpn) . is_none ( ) {
209+ return false ; // 有未映射的页
210+ }
211+ }
212+
213+ // 移除对应的 MapArea
214+ memory_set. remove_area_with_range ( start_va, end_va)
215+ }
193216}
194217
195218/// Run the first task in task list.
@@ -258,3 +281,13 @@ pub fn mmap_for_current_task(
258281) -> bool {
259282 TASK_MANAGER . mmap_for_current_task ( start_va, end_va, map_perm)
260283}
284+
285+ /// Unmap memory area for the current task
286+ pub fn munmap_for_current_task (
287+ start_va : crate :: mm:: VirtAddr ,
288+ end_va : crate :: mm:: VirtAddr ,
289+ ) -> bool {
290+ TASK_MANAGER . munmap_for_current_task ( start_va, end_va)
291+ }
292+
293+
0 commit comments