safa_api/syscalls/
mod.rs

1//! This module exposes SafaOS's syscalls and their rust counterparts
2
3#[cfg(not(feature = "rustc-dep-of-std"))]
4extern crate alloc;
5
6pub(crate) mod call;
7
8pub use safa_abi::syscalls::SyscallTable as SyscallNum;
9
10macro_rules! err_from_u16 {
11    ($result:expr) => {
12        $result.into_result()
13    };
14    ($result:expr, $ok:expr) => {
15        err_from_u16!($result).map(|()| $ok)
16    };
17}
18
19pub(crate) use err_from_u16;
20
21pub use call::syscall;
22
23macro_rules! define_syscall {
24    ($num:path => { $(#[$attrss:meta])* $name:ident ($($arg:ident : $ty:ty),*) unreachable }) => {
25        $(#[$attrss])*
26        #[cfg_attr(
27            not(any(feature = "std", feature = "rustc-dep-of-std")),
28            unsafe(no_mangle)
29        )]
30        #[cfg_attr(any(feature = "std", feature = "rustc-dep-of-std"), inline(always))]
31        pub extern "C" fn $name($($arg: $ty),*) -> ! {
32            #[allow(unused_imports)]
33            use $crate::syscalls::types::IntoSyscallArg;
34            _ = $crate::syscalls::syscall!($num, $( $arg.into_syscall_arg() ),*);
35            unreachable!()
36        }
37    };
38    ($num:path => { $(#[$attrss:meta])* $name:ident ($($arg:ident : $ty:ty),*) }) => {
39        $(#[$attrss])*
40        #[cfg_attr(
41            not(any(feature = "std", feature = "rustc-dep-of-std")),
42            unsafe(no_mangle)
43        )]
44        #[cfg_attr(any(feature = "std", feature = "rustc-dep-of-std"), inline(always))]
45        pub extern "C" fn $name($($arg: $ty),*) -> $crate::syscalls::types::SyscallResult {
46            #[allow(unused_imports)]
47            use $crate::syscalls::types::IntoSyscallArg;
48            let result = $crate::syscalls::syscall!($num, $( $arg ),*);
49            result
50        }
51    };
52    {$($num:path => { $(#[$attrss:meta])* $name:ident ($($arg:ident: $ty:ty),*) $($modifier:tt)* }),* $(,)?} => {
53        $(define_syscall!($num => { $(#[$attrss])* $name($($arg: $ty),*) $($modifier)* });)*
54    };
55}
56
57pub(crate) use define_syscall;
58
59/// FS Operations related syscalls (that takes a path) such as create, remove, open, rename and etc
60pub mod fs;
61/// (SysTFut) Futex related syscalls and operations
62pub mod futex;
63/// I/O Operations related syscalls (that takes a resource) such as read, write, truncate, etc
64pub mod io;
65/// Syscalls and operations that don't fall into a specific category
66pub mod misc;
67/// (SysP) Process related syscalls and operations
68pub mod process;
69/// Syscalls and operations related to the current process
70pub mod process_misc;
71/// (SysR) Resources related syscalls and operations such as destroying resources, duplicating them, etc
72pub mod resources;
73/// (SysT) Thread related syscalls and operations
74pub mod thread;
75/// Contains documentation-only types for syscall arguments
76pub mod types;