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