safa_abi/
syscalls.rs

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