Skip to main content

tg_rcore_tutorial_syscall/
lib.rs

1#![no_std]
2#![deny(warnings)]
3//!
4//! 教程阅读建议:
5//!
6//! - 用户态读 `user.rs`:看 syscall 封装如何把参数放入 a0-a5/a7;
7//! - 内核态读 `kernel/mod.rs`:看 syscall 号如何分发到各子系统 trait。
8
9#[cfg(all(feature = "kernel", feature = "user"))]
10compile_error!("You can only use one of `supervisor` or `user` features at a time");
11
12mod fs;
13mod io;
14mod time;
15
16include!(concat!(env!("OUT_DIR"), "/syscalls.rs"));
17// 由构建脚本生成的 syscall 编号常量(与课程章节保持同步)。
18
19pub use fs::*;
20pub use io::*;
21pub use tg_signal_defs::{SignalAction, SignalNo, MAX_SIG};
22pub use time::*;
23
24#[cfg(feature = "user")]
25mod user;
26
27#[cfg(feature = "user")]
28pub use user::*;
29
30#[cfg(feature = "kernel")]
31mod kernel;
32
33#[cfg(feature = "kernel")]
34pub use kernel::*;
35
36/// 系统调用号。
37///
38/// 实现为包装类型,在不损失扩展性的情况下实现类型安全性。
39#[derive(PartialEq, Eq, Clone, Copy, Debug)]
40#[repr(transparent)]
41pub struct SyscallId(pub usize);
42
43impl From<usize> for SyscallId {
44    #[inline]
45    fn from(val: usize) -> Self {
46        Self(val)
47    }
48}