From 48ebf98f114c441983b4a3c507290de9c794f610 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sun, 24 Mar 2019 16:25:32 +0800 Subject: [PATCH] Fix pop_with_split, check file existence in sys_access --- crate/memory/src/memory_set/mod.rs | 11 +++++++---- kernel/src/syscall/fs.rs | 7 +++++-- kernel/src/syscall/mem.rs | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crate/memory/src/memory_set/mod.rs b/crate/memory/src/memory_set/mod.rs index a36a93ed..adbe962c 100644 --- a/crate/memory/src/memory_set/mod.rs +++ b/crate/memory/src/memory_set/mod.rs @@ -280,12 +280,14 @@ impl MemorySet { */ pub fn pop_with_split(&mut self, start_addr: VirtAddr, end_addr: VirtAddr) { assert!(start_addr <= end_addr, "invalid memory area"); - for i in 0..self.areas.len() { + let mut i = 0; + while i < self.areas.len() { if self.areas[i].is_overlap_with(start_addr, end_addr) { if self.areas[i].start_addr >= start_addr && self.areas[i].end_addr <= end_addr { // subset let area = self.areas.remove(i); self.page_table.edit(|pt| area.unmap(pt)); + i -= 1; } else if self.areas[i].start_addr >= start_addr && self.areas[i].start_addr < end_addr { // prefix let area = self.areas.remove(i); @@ -307,11 +309,12 @@ impl MemorySet { self.page_table.edit(|pt| dead_area.unmap(pt)); let new_area_left = MemoryArea { start_addr: area.start_addr, end_addr: start_addr, attr: area.attr, handler: area.handler.box_clone(), name: area.name }; self.areas.insert(i, new_area_left); - let new_area_right = MemoryArea { start_addr: end_addr, end_addr: area.start_addr, attr: area.attr, handler: area.handler, name: area.name }; - self.areas.insert(i, new_area_right); + let new_area_right = MemoryArea { start_addr: end_addr, end_addr: area.end_addr, attr: area.attr, handler: area.handler, name: area.name }; + self.areas.insert(i + 1, new_area_right); + i += 1; } - return; } + i += 1; } } diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 99d042de..03f25698 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -370,8 +370,11 @@ pub fn sys_close(fd: usize) -> SysResult { } pub fn sys_access(path: *const u8, mode: usize) -> SysResult { - info!("access: path: {:?}, mode: {}", path, mode); - // TODO: check permissions based on uid/git + // TODO: check permissions based on uid/gid + let proc = process(); + let path = unsafe { proc.vm.check_and_clone_cstr(path)? }; + info!("access: path: {:?}, mode: {:#o}", path, mode); + let inode = proc.lookup_inode(&path)?; Ok(0) } diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 8a78b053..25669951 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -47,7 +47,7 @@ pub fn sys_mmap( addr + len, prot.to_attr(), Delay::new(GlobalFrameAlloc), - "mmap", + "mmap_anon", ); return Ok(addr); } else { @@ -60,7 +60,7 @@ pub fn sys_mmap( addr + len, prot.to_attr(), ByFrame::new(GlobalFrameAlloc), - "mmap", + "mmap_file", ); let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) }; let file = proc.get_file(fd)?;