-
-
Notifications
You must be signed in to change notification settings - Fork 161
feat(syscall/mincore):实现了mincore系统调用 #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(syscall/mincore):实现了mincore系统调用 #1258
Conversation
d45967d
to
d18c8cc
Compare
d18c8cc
to
252b107
Compare
kernel/src/mm/syscall/sys_mincore.rs
Outdated
let mut writer = UserBufferWriter::new(vec as *mut u8, page_count, true)?; | ||
let mut tmp: Vec<u8> = vec![0; page_count]; | ||
let page_count = PageFrameCount::new(page_count); | ||
current_address_space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没必要多动态申请内存,导致多拷贝一次。有userbuffer writer就能安全访问了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试程序放到c_unitest
目录下,并且要有判断成功/失败的条件,具体让ai写个测试用例的demo就知道了。这个测试程序没法看出成功或失败。
pub fn do_mincore( | ||
&self, | ||
mapper: &PageMapper, | ||
vec: &mut [u8], | ||
start_addr: VirtAddr, | ||
end_addr: VirtAddr, | ||
offset: usize, | ||
) -> Result<(), SystemError> { | ||
let total_pages = (end_addr - start_addr) >> MMArch::PAGE_SHIFT; | ||
if vec.len() < total_pages + offset { | ||
return Err(SystemError::EINVAL); | ||
} | ||
if !(self.is_anonymous()) { | ||
//todo: 当进程是否拥有文件写权限或是文件所有者,才允许对映射了文件的vma调用mincore,否则将对应地址范围的位图置为0 | ||
} | ||
//todo: 处理大页 | ||
self.mincore_walk_page_range(mapper, start_addr, end_addr, 3, vec, offset); | ||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kernel/src/mm/mincore.rs
Outdated
for i in 0..nr { | ||
vec[vec_offset + i] = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有两个问题:
- 批量赋值为的不应该这样写,而是应该用数组切片的fill方法。
- 没有校验
offset+i
是否会溢出下标导致panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缓冲区的容量在一开始就开好了,检查固定页数
let page_cache = guard.vm_file().unwrap().inode().page_cache(); | ||
match page_cache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里直接unwrap可能会panic. 比如inode刚好删掉了,然后page cache因为是延迟清除的所以导致vm_file为空。
kernel/src/mm/mincore.rs
Outdated
if page_cache.lock_irqsave().get_page(pgoff + i).is_some() { | ||
vec[vec_offset + i] = 1; | ||
} else { | ||
vec[vec_offset + i] = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里每个操作都很轻量,没必要多次加锁。因为加锁本身的开销大于一次get_page.
kernel/src/mm/mincore.rs
Outdated
for i in 0..nr { | ||
vec[vec_offset + i] = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如上,创建新的切片然后使用fill()
081c661
to
edd5968
Compare
edd5968
to
9c09ad2
Compare
- 添加大页支持,在遇到大页时按4K粒度填充 - 修复地址对齐检查,将assert改为返回EINVAL错误 - 严格验证用户缓冲区映射与写权限 - 修复VMA查找和排序逻辑,确保地址连续性判断正确 - 添加覆盖完整性校验 - 重写mincore测试用例,增加边界条件和文件映射测试 Signed-off-by: longjin <[email protected]>
b1cf6bf 这个commit里面修复了几个bug,并且完善了测试用例。以下是GPT-5对问题的解析。 PageFault 中
|
No description provided.