1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-26 01:43:29 +04:00

Fix pop_with_split, check file existence in sys_access

This commit is contained in:
Jiajie Chen 2019-03-24 16:25:32 +08:00
parent 285df82b80
commit 48ebf98f11
3 changed files with 14 additions and 8 deletions

View File

@ -280,12 +280,14 @@ impl<T: InactivePageTable> MemorySet<T> {
*/
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<T: InactivePageTable> MemorySet<T> {
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;
}
}

View File

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

View File

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