-
-
Notifications
You must be signed in to change notification settings - Fork 168
fix(vfs): 修复 pread64 系统调用的兼容性和错误处理 #1398
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
Changes from 5 commits
66b967e
696122e
c8c4dd9
c716be8
3f3ef9f
a756668
94d0a91
0dc99c0
667c09c
cbad321
030dfbe
8761ffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ use system_error::SystemError; | |
|
|
||
| use crate::arch::interrupt::TrapFrame; | ||
| use crate::arch::syscall::nr::SYS_PREAD64; | ||
| use crate::filesystem::vfs::FileType; | ||
| use crate::process::ProcessManager; | ||
| use crate::syscall::table::FormattedSyscallParam; | ||
| use crate::syscall::table::Syscall; | ||
|
|
@@ -35,7 +36,15 @@ impl Syscall for SysPread64Handle { | |
| let len = Self::len(args); | ||
| let offset = Self::offset(args); | ||
|
|
||
| let mut user_buffer_writer = UserBufferWriter::new(buf_vaddr, len, frame.is_from_user())?; | ||
| // 检查offset + len是否溢出 同时检查offset是否为负数 | ||
|
|
||
| let end_pos = offset.checked_add(len).ok_or(SystemError::EINVAL)?; | ||
| if offset > i64::MAX as usize || end_pos > i64::MAX as usize { | ||
kaleidoscope416 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return Err(SystemError::EINVAL); | ||
| } | ||
|
|
||
| let mut user_buffer_writer = | ||
| UserBufferWriter::new_checked(buf_vaddr, len, frame.is_from_user())?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 要求用户缓冲区已经映射应该是不对的。可能是pagefault延迟映射。应该是使用protected的那个,校验vma
fslongjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let user_buf = user_buffer_writer.buffer(0)?; | ||
|
|
||
| let binding = ProcessManager::current_pcb().fd_table(); | ||
|
|
@@ -48,6 +57,15 @@ impl Syscall for SysPread64Handle { | |
| // Drop guard to avoid scheduling issues | ||
| drop(fd_table_guard); | ||
|
|
||
| // 检查是否是管道/Socket (ESPIPE) | ||
| let md = file.metadata()?; | ||
| if md.file_type == FileType::Pipe | ||
| || md.file_type == FileType::Socket | ||
| || md.file_type == FileType::CharDevice | ||
| { | ||
| return Err(SystemError::ESPIPE); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: CharDevice incorrectly included in ESPIPE file type checkThe comment states this check is for pipes and sockets, but the code also includes |
||
|
|
||
| return file.pread(offset, len, user_buf); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||
| # SYS_MEMFD_CREATE未实现 | ||||
| Pread64Test.Overflow | ||||
|
||||
| Pread64Test.Overflow |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ sync_test | |
| #chown_test | ||
| chdir_test | ||
| fchdir_test | ||
| pread64_test | ||
|
|
||
| # 进程相关测试 | ||
| fork_test | ||
|
|
||
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.
Missing space after
||operator. The condition should bemode == FileMode::O_WRONLY || mode.contains(FileMode::O_PATH)for consistency with Rust formatting conventions.