Skip to content

refactor: 清理匿名 Result 错误类型#256

Merged
ZIYAN137 merged 6 commits into
mainfrom
refactor/cleanup-unit-result-errors
May 27, 2026
Merged

refactor: 清理匿名 Result 错误类型#256
ZIYAN137 merged 6 commits into
mainfrom
refactor/cleanup-unit-result-errors

Conversation

@ZIYAN137

Copy link
Copy Markdown
Contributor

变更内容

本 PR 处理 #246,主要清理内核中的 Result<_, ()> / Result<(), ()> 匿名错误类型,避免底层错误在跨模块传播时被湮灭。

  • PageTableInner::new() / new_as_kernel_table() 改为 fallible 初始化,移除页表创建路径中的分配失败 panic
  • 补齐 VFS 错误到 errno 的映射,统一文件系统错误返回路径
  • 为网络 socket/stack/syscall 路径引入 NetworkError,替代匿名 ()
  • 为 ring buffer、字符串拷贝、文件锁范围计算等工具路径补充具体错误类型
  • 合入最新 main,解决架构抽象重构后的冲突

验证情况

  • cargo fmt --all -- --check
  • cargo check --target riscv64gc-unknown-none-elf
  • cargo clippy --target riscv64gc-unknown-none-elf
  • make run TEST=1

make run TEST=1 结果:Total: 510, Passed: 510, Failed: 0

额外确认:

  • rg "Result<[^\n]*, \(\)>|Result<\(\), \(\)>" os/src -n 无结果
  • PageTableInner::new().unwrap() / new_as_kernel_table().unwrap() 无结果

Closes #246

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors error handling across the kernel, replacing generic Result<(), ()> types with structured error enums such as PagingError, NetworkError, FsError, FlockRangeError, RingBufferError, and StringCopyError. System calls, virtual memory operations, and network stack functions now propagate these detailed errors and convert them to appropriate system error codes (errno). Additionally, the default error for unsupported lseek operations has been updated from NotSupported to NotSeekable. A security improvement is recommended in get_args_safe to limit the number of arguments copied from user space to MAX_ARGV, preventing potential denial-of-service (OOM) attacks from excessively long argument lists.

Comment thread os/src/kernel/syscall/util.rs
@ZIYAN137 ZIYAN137 merged commit 0f5427e into main May 27, 2026
1 check passed
@ZIYAN137 ZIYAN137 deleted the refactor/cleanup-unit-result-errors branch May 27, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

消除 Result<(), ()> 错误湮灭 + Error 类型间 From 转换

1 participant