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
44 SysPWait = 11,
45 /// Waits for a child thread with a given TID to exit
46 SysTWait = 32,
47
48 SysShutdown = 20,
49 SysReboot = 21,
50 /// returns the Uptime of the system in milliseconds
51 SysUptime = 27,
52}
53
54// 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...
55/// When a new syscall is added, add to this number, and use the old value as the syscall number
56const NEXT_SYSCALL_NUM: u16 = 33;
57
58impl TryFrom<u16> for SyscallTable {
59 type Error = ();
60 fn try_from(value: u16) -> Result<Self, Self::Error> {
61 if value < NEXT_SYSCALL_NUM {
62 Ok(unsafe { core::mem::transmute(value) })
63 } else {
64 Err(())
65 }
66 }
67}