Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

添加一个新的syscall

在内核中添加一个新的syscall很容易。

有3个步骤。

  1. Add new syscall number for the new syscall in header/src/lib.rs.
pub enum NR {
    Read,
}
  1. 在kernel/src/syscall_handlers/mod.rs中实现新的syscall。

这通常通过define_syscall_handler!完成,如果系统调用是简单的。例如

define_syscall_handler!(
read(fd: i32, buf: *mut i8, len: usize) -> c_long {
    // 实现你的 vfs 读取。});
  1. 在kernel/src/syscall_handlers/mod.rs中注册新的syscall。

在 syscall_table! 中添加一个新条目。例如,

(Read, read),

必须注意,第一个操作数必须是 NR 枚举的非限定名称。