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:
parent
285df82b80
commit
48ebf98f11
@ -280,12 +280,14 @@ impl<T: InactivePageTable> MemorySet<T> {
|
|||||||
*/
|
*/
|
||||||
pub fn pop_with_split(&mut self, start_addr: VirtAddr, end_addr: VirtAddr) {
|
pub fn pop_with_split(&mut self, start_addr: VirtAddr, end_addr: VirtAddr) {
|
||||||
assert!(start_addr <= end_addr, "invalid memory area");
|
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].is_overlap_with(start_addr, end_addr) {
|
||||||
if self.areas[i].start_addr >= start_addr && self.areas[i].end_addr <= end_addr {
|
if self.areas[i].start_addr >= start_addr && self.areas[i].end_addr <= end_addr {
|
||||||
// subset
|
// subset
|
||||||
let area = self.areas.remove(i);
|
let area = self.areas.remove(i);
|
||||||
self.page_table.edit(|pt| area.unmap(pt));
|
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 {
|
} else if self.areas[i].start_addr >= start_addr && self.areas[i].start_addr < end_addr {
|
||||||
// prefix
|
// prefix
|
||||||
let area = self.areas.remove(i);
|
let area = self.areas.remove(i);
|
||||||
@ -307,11 +309,12 @@ impl<T: InactivePageTable> MemorySet<T> {
|
|||||||
self.page_table.edit(|pt| dead_area.unmap(pt));
|
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 };
|
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);
|
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 };
|
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, new_area_right);
|
self.areas.insert(i + 1, new_area_right);
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,8 +370,11 @@ pub fn sys_close(fd: usize) -> SysResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_access(path: *const u8, mode: usize) -> SysResult {
|
pub fn sys_access(path: *const u8, mode: usize) -> SysResult {
|
||||||
info!("access: path: {:?}, mode: {}", path, mode);
|
// TODO: check permissions based on uid/gid
|
||||||
// TODO: check permissions based on uid/git
|
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)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub fn sys_mmap(
|
|||||||
addr + len,
|
addr + len,
|
||||||
prot.to_attr(),
|
prot.to_attr(),
|
||||||
Delay::new(GlobalFrameAlloc),
|
Delay::new(GlobalFrameAlloc),
|
||||||
"mmap",
|
"mmap_anon",
|
||||||
);
|
);
|
||||||
return Ok(addr);
|
return Ok(addr);
|
||||||
} else {
|
} else {
|
||||||
@ -60,7 +60,7 @@ pub fn sys_mmap(
|
|||||||
addr + len,
|
addr + len,
|
||||||
prot.to_attr(),
|
prot.to_attr(),
|
||||||
ByFrame::new(GlobalFrameAlloc),
|
ByFrame::new(GlobalFrameAlloc),
|
||||||
"mmap",
|
"mmap_file",
|
||||||
);
|
);
|
||||||
let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) };
|
let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) };
|
||||||
let file = proc.get_file(fd)?;
|
let file = proc.get_file(fd)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user