twizzler_abi/syscall/
mod.rs

1//! Wrapper functions around for raw_syscall, providing a typed and safer way to interact with the
2//! kernel.
3
4mod console;
5mod create;
6mod handle;
7mod info;
8mod kaction;
9mod map;
10mod object_control;
11mod object_stat;
12mod random;
13mod security;
14mod spawn;
15mod thread_control;
16mod thread_sync;
17mod time;
18
19use crate::arch::syscall::raw_syscall;
20#[derive(Copy, Clone, Debug)]
21#[repr(C)]
22/// All possible Synchronous syscalls into the Twizzler kernel.
23pub enum Syscall {
24    Null,
25    /// Read data from the kernel console, either buffer or input.
26    KernelConsoleRead,
27    /// Write data to the kernel console.
28    KernelConsoleWrite,
29    /// Sync a thread with other threads using some number of memory words.
30    ThreadSync,
31    /// General thread control functions.
32    ThreadCtrl,
33    /// Create new object.
34    ObjectCreate,
35    /// Map an object into address space.
36    ObjectMap,
37    /// Returns system info.
38    SysInfo,
39    /// Spawn a new thread.
40    Spawn,
41    /// Read clock information.
42    ReadClockInfo,
43    /// List clock sources.
44    ReadClockList,
45    /// Apply a kernel action to an object (used for device drivers).
46    Kaction,
47    /// New Handle.
48    NewHandle,
49    /// Unmap an object.
50    ObjectUnmap,
51    /// Manage in-kernel object properties.
52    ObjectCtrl,
53    /// Get kernel information about an object.
54    ObjectStat,
55    /// Read mapping information.
56    ObjectReadMap,
57    /// Remove an object as a handle.
58    UnbindHandle,
59    /// Attach to a security context.
60    SctxAttach,
61    /// Gets random bytes
62    GetRandom,
63    NumSyscalls,
64}
65
66impl Syscall {
67    /// Return the number associated with this syscall.
68    pub fn num(&self) -> u64 {
69        *self as u64
70    }
71}
72
73impl From<usize> for Syscall {
74    fn from(x: usize) -> Self {
75        if x >= Syscall::NumSyscalls as usize {
76            return Syscall::Null;
77        }
78        unsafe { core::intrinsics::transmute(x as u32) }
79    }
80}
81
82pub use console::*;
83pub use create::*;
84pub use handle::*;
85pub use info::*;
86pub use kaction::*;
87pub use map::*;
88pub use object_control::*;
89pub use object_stat::*;
90pub use random::*;
91pub use security::*;
92pub use spawn::*;
93pub use thread_control::*;
94pub use thread_sync::*;
95pub use time::*;
96use twizzler_rt_abi::error::{RawTwzError, TwzError};
97
98#[inline]
99fn convert_codes_to_result<T, E, D, F, G>(code: u64, val: u64, d: D, f: F, g: G) -> Result<T, E>
100where
101    F: Fn(u64, u64) -> T,
102    G: Fn(u64, u64) -> E,
103    D: Fn(u64, u64) -> bool,
104{
105    if d(code, val) {
106        Err(g(code, val))
107    } else {
108        Ok(f(code, val))
109    }
110}
111
112#[inline]
113fn twzerr(_: u64, v: u64) -> TwzError {
114    RawTwzError::new(v).error()
115}
116
117/// Shutdown the computer.
118#[deprecated]
119pub fn sys_debug_shutdown(code: u32) {
120    unsafe {
121        raw_syscall(Syscall::Null, &[0x12345678, code as u64]);
122    }
123}