safa_abi/
syscalls.rs

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