Skip to content

Commit edd5968

Browse files
committed
完成can_do_mincore逻辑
1 parent 310c293 commit edd5968

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kernel/src/mm/mincore.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ impl LockedVMA {
1818
if vec.len() < total_pages + offset {
1919
return Err(SystemError::EINVAL);
2020
}
21-
if !(self.is_anonymous()) {
22-
//todo: 当进程是否拥有文件写权限或是文件所有者,才允许对映射了文件的vma调用mincore,否则将对应地址范围的位图置为0
21+
22+
if !self.can_do_mincore() {
23+
let pages = (end_addr - start_addr) >> MMArch::PAGE_SHIFT;
24+
vec[offset..offset + pages].fill(0);
25+
return Ok(());
2326
}
2427
//todo: 处理大页
2528
self.mincore_walk_page_range(mapper, start_addr, end_addr, 3, vec, offset);
@@ -102,4 +105,14 @@ impl LockedVMA {
102105
}
103106
nr
104107
}
108+
109+
pub fn can_do_mincore(&self) -> bool {
110+
//todo: 没有实现vm_ops,这里只能找到匿名映射和文件映射。对于设备映射和其他特殊映射(对应linux中vm_ops有值,但不是文件映射的vma),返回false
111+
if self.is_accessible() {
112+
return true;
113+
} else {
114+
//todo: 若文件不是当前用户所有,需要当前用户对文件有写权限,否则返回false
115+
return true;
116+
}
117+
}
105118
}

0 commit comments

Comments
 (0)