safa_abi/
syscalls.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2#[repr(u16)]
3pub enum SyscallTable {
4    SysExit = 0,
5    SysYield = 1,
6
7    SysOpen = 2,
8    SysDirIterOpen = 8,
9    SysClose = 5,
10    SysDirIterClose = 9,
11    SysDirIterNext = 10,
12    SysWrite = 3,
13    SysRead = 4,
14    SysCreate = 6,
15    SysCreateDir = 7,
16    SysSync = 16,
17    SysTruncate = 17,
18    SysCtl = 12,
19    SysFSize = 22,
20    SysGetDirEntry = 23,
21
22    SysCHDir = 14,
23    SysGetCWD = 15,
24    SysSbrk = 18,
25
26    SysPSpawn = 19,
27    SysWait = 11,
28
29    SysShutdown = 20,
30    SysReboot = 21,
31}
32
33impl SyscallTable {
34    // update when a new Syscall Num is added
35    const MAX: u16 = Self::SysReboot as u16;
36}
37
38impl TryFrom<u16> for SyscallTable {
39    type Error = ();
40    fn try_from(value: u16) -> Result<Self, Self::Error> {
41        if value <= Self::MAX {
42            Ok(unsafe { core::mem::transmute(value) })
43        } else {
44            Err(())
45        }
46    }
47}