Skip to main content

dope_sys/kernel/
mod.rs

1use std::{marker, mem, num};
2
3pub use returned::Returned;
4pub use source::Source;
5
6pub mod errno;
7pub mod raw;
8
9mod returned;
10mod source;
11
12/// Exact value observed in the thread-local errno slot after a rejected syscall.
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14#[repr(transparent)]
15pub struct Errno<O>(crate::Errno, marker::PhantomData<fn() -> O>);
16
17impl<O> Errno<O> {
18    pub const fn code(&self) -> num::NonZero<i32> {
19        self.0.code()
20    }
21
22    pub const fn is_code(self, code: crate::Errno) -> bool {
23        self.0.code().get() == code.code().get()
24    }
25}
26
27impl<O> From<crate::Errno> for Errno<O> {
28    fn from(code: crate::Errno) -> Self {
29        Self(code, marker::PhantomData)
30    }
31}
32
33impl<O> From<Errno<O>> for crate::Errno {
34    fn from(error: Errno<O>) -> Self {
35        error.0
36    }
37}
38
39/// The exact scalar rejected by one native result domain.
40#[derive(Clone, Copy, Debug, Eq, PartialEq)]
41pub struct Invalid {
42    pub actual: libc::ssize_t,
43    pub minimum: libc::ssize_t,
44    pub maximum: libc::ssize_t,
45}
46
47const _: () = {
48    assert!(mem::size_of::<Errno<()>>() == mem::size_of::<i32>());
49    assert!(mem::size_of::<Result<(), Errno<()>>>() == mem::size_of::<i32>());
50};
51
52/// A nonnegative result admitted at the syscall boundary.
53#[derive(Clone, Copy, Debug, Eq, PartialEq)]
54#[repr(transparent)]
55pub struct Value(libc::c_int);
56
57impl Value {
58    pub const fn get(self) -> libc::c_int {
59        self.0
60    }
61}
62
63/// Canonical kernel-operation and descriptor-table failures for every backend.
64/// Diagnostics retain the backend's exact failure without a second error domain.
65#[derive(Clone, Copy, Debug, Eq, PartialEq)]
66pub enum Diagnostic<S> {
67    Setup(crate::Errno),
68    Enter(crate::Errno),
69    FileUpdate(crate::Errno),
70    Probe(crate::Errno),
71    FileTable(crate::Errno),
72    RingRegister(crate::Errno),
73    BufferRegister(crate::Errno),
74    BufferUnregister(crate::Errno),
75    Cancel(crate::Errno),
76    FileRange(crate::Errno),
77    Map(crate::Errno),
78    Unmap(crate::Errno),
79    Fault(crate::Errno),
80    FileIndex(S),
81    FileOccupied(S),
82}
83
84impl<S> From<crate::Errno> for Diagnostic<S> {
85    fn from(cause: crate::Errno) -> Self {
86        Self::Fault(cause)
87    }
88}
89
90/// Native failures that prevent releasing worker or driver storage, or an armed watchdog.
91#[derive(Debug)]
92pub enum Fatal {
93    Join(crate::Errno),
94    TimerDelete(crate::Errno),
95    /// Native retirement failed while borrowed driver storage remains live.
96    Retirement,
97}
98
99impl Fatal {
100    /// Stops before workers, kernel borrows, or live watchdogs can outlive their owners.
101    #[cold]
102    pub fn terminate(self) -> ! {
103        unreachable!("native")
104    }
105}