Skip to main content

dope_sys/ring/map/
mod.rs

1use std::{convert::Infallible, num::NonZero};
2mod failure;
3
4pub use failure::Failure;
5
6use crate::{
7    io::{self, Retry},
8    kernel, memory,
9    ring::{layout::Region, register},
10};
11
12/// Mapping rejection retaining its exact region, extent, and operation error.
13#[derive(Debug, Clone, Copy, Eq, PartialEq)]
14pub enum Map<E> {
15    Syscall {
16        region: Region,
17        len: NonZero<usize>,
18        code: E,
19    },
20    Null {
21        region: Region,
22        len: NonZero<usize>,
23    },
24}
25
26/// Current mapping failure without erasing its native region or buffer extent.
27#[derive(Debug, Eq, PartialEq)]
28pub enum Storage<E> {
29    Ring(Failure<E>),
30    Buffer(memory::Error),
31    Unregister(kernel::Errno<register::Unregister>),
32}
33
34/// A retained mapping cleanup state reports its current exact failure.
35pub trait Unmap: Retry<Failure: Into<Storage<Self::Error>>> {
36    type Error;
37    fn failure(&self) -> Storage<Self::Error>;
38}
39
40impl Unmap for Infallible {
41    type Error = Infallible;
42
43    fn failure(&self) -> Storage<Self::Error> {
44        match *self {}
45    }
46}
47
48impl<E> From<Infallible> for Storage<E> {
49    fn from(value: Infallible) -> Self {
50        match value {}
51    }
52}
53
54impl<E, R: Into<Storage<E>>, S: Into<memory::Error>> From<io::Cleanup<R, S>> for Storage<E> {
55    fn from(value: io::Cleanup<R, S>) -> Self {
56        match value {
57            io::Cleanup::Owner(failure) => failure.into(),
58            io::Cleanup::Storage(failure) => Self::Buffer(failure.into()),
59        }
60    }
61}
62
63impl<E> From<Failure<E>> for Storage<E> {
64    fn from(cause: Failure<E>) -> Self {
65        Self::Ring(cause)
66    }
67}
68
69impl<E> From<kernel::Errno<register::Unregister>> for Storage<E> {
70    fn from(cause: kernel::Errno<register::Unregister>) -> Self {
71        Self::Unregister(cause)
72    }
73}