safa_abi/
syscalls.rs

1/// defines Syscall numbers
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u16)]
4pub enum SyscallTable {
5    SysPExit = 0,
6    SysTYield = 1,
7    /// Opens a file or directory with all permissions
8    SysOpenAll = 2,
9    /// Opens a file or directory with given mode (permissions and flags)
10    SysOpen = 25,
11    /// Deletes a path
12    SysRemovePath = 28,
13    SysDirIterOpen = 8,
14    /// Destroys (closes) an open resource whether it is a file, directory, directory iterator, or any other resource
15    SysDestroyResource = 5,
16    /// Legacy system call to close a directory iterator, use [`SysDestroy`] instead
17    SysDirIterClose = 9,
18    SysDirIterNext = 10,
19    SysWrite = 3,
20    SysRead = 4,
21    SysCreate = 6,
22    SysCreateDir = 7,
23    SysSync = 16,
24    SysTruncate = 17,
25    SysCtl = 12,
26
27    SysDup = 26,
28    // TODO: remove in favor of FAttrs
29    SysFSize = 22,
30    SysFAttrs = 24,
31    SysGetDirEntry = 23,
32
33    SysCHDir = 14,
34    SysGetCWD = 15,
35    SysSbrk = 18,
36
37    /// Spawns a process (task)
38    SysPSpawn = 19,
39    /// Spawns a thread (context) inside the current process (task) with the given entry point
40    SysTSpawn = 29,
41    SysTExit = 30,
42    SysTSleep = 31,
43    /// Waits for a child process with a given PID to exit, cleans it up and returns the exit code
44    SysPWait = 11,
45    /// Waits for a child thread with a given TID to exit
46    SysTWait = 32,
47    /// like [`SysPWait`] without the waiting part, cleans up the given process and returns the exit code
48    ///
49    /// returns [`crate::errors::ErrorStatus::InvalidPid`] if the process doesn't exist
50    ///
51    /// returns [`crate::errors::ErrorStatus::Generic`] if the process exists but hasn't exited yet
52    SysPTryCleanUp = 33,
53
54    SysShutdown = 20,
55    SysReboot = 21,
56    /// returns the Uptime of the system in milliseconds
57    SysUptime = 27,
58}
59
60// sadly we cannot use any proc macros here because this crate is used by the libstd port and more, they don't happen to like proc macros...
61/// When a new syscall is added, add to this number, and use the old value as the syscall number
62const NEXT_SYSCALL_NUM: u16 = 34;
63
64impl TryFrom<u16> for SyscallTable {
65    type Error = ();
66    fn try_from(value: u16) -> Result<Self, Self::Error> {
67        if value < NEXT_SYSCALL_NUM {
68            Ok(unsafe { core::mem::transmute(value) })
69        } else {
70            Err(())
71        }
72    }
73}