sel4_shared_ring_buffer_block_io/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use sel4_shared_ring_buffer::PeerMisbehaviorError as SharedRingBuffersPeerMisbehaviorError;
use sel4_shared_ring_buffer_bookkeeping::slot_tracker::SlotTrackerError;

#[derive(Debug, Clone)]
pub enum ErrorOrUserError {
    Error(Error),
    UserError(UserError),
}

#[derive(Debug, Clone)]
pub enum UserError {
    InvalidRequestIndex,
    RequestStateMismatch,
    TooManyOutstandingRequests,
}

#[derive(Debug, Clone)]
pub enum Error {
    IOError(IOError),
    BounceBufferAllocationError,
    PeerMisbehaviorError(PeerMisbehaviorError),
}

#[derive(Debug, Clone)]
pub struct IOError;

#[derive(Debug, Clone)]
pub enum PeerMisbehaviorError {
    InvalidDescriptor,
    DescriptorMismatch,
    OutOfBoundsCookie,
    StateMismatch,
    SharedRingBuffersPeerMisbehaviorError(SharedRingBuffersPeerMisbehaviorError),
}

impl ErrorOrUserError {
    pub fn unwrap_error(self) -> Error {
        match self {
            Self::Error(err) => err,
            Self::UserError(err) => panic!(
                "called `ErrorOrUserError::unwrap_error()` on an `UserError` value: {:?}",
                err
            ),
        }
    }
}

impl From<Error> for ErrorOrUserError {
    fn from(err: Error) -> Self {
        Self::Error(err)
    }
}

impl From<UserError> for ErrorOrUserError {
    fn from(err: UserError) -> Self {
        Self::UserError(err)
    }
}

impl From<IOError> for Error {
    fn from(err: IOError) -> Self {
        Self::IOError(err)
    }
}

impl From<IOError> for ErrorOrUserError {
    fn from(err: IOError) -> Self {
        Error::from(err).into()
    }
}

impl From<PeerMisbehaviorError> for Error {
    fn from(err: PeerMisbehaviorError) -> Self {
        Self::PeerMisbehaviorError(err)
    }
}

impl From<PeerMisbehaviorError> for ErrorOrUserError {
    fn from(err: PeerMisbehaviorError) -> Self {
        Error::from(err).into()
    }
}

impl From<SharedRingBuffersPeerMisbehaviorError> for PeerMisbehaviorError {
    fn from(err: SharedRingBuffersPeerMisbehaviorError) -> Self {
        Self::SharedRingBuffersPeerMisbehaviorError(err)
    }
}

impl From<SharedRingBuffersPeerMisbehaviorError> for Error {
    fn from(err: SharedRingBuffersPeerMisbehaviorError) -> Self {
        PeerMisbehaviorError::from(err).into()
    }
}

impl From<SharedRingBuffersPeerMisbehaviorError> for ErrorOrUserError {
    fn from(err: SharedRingBuffersPeerMisbehaviorError) -> Self {
        Error::from(err).into()
    }
}

impl From<SlotTrackerError> for UserError {
    fn from(err: SlotTrackerError) -> Self {
        match err {
            SlotTrackerError::OutOfBounds => UserError::InvalidRequestIndex,
            SlotTrackerError::StateMismatch => UserError::RequestStateMismatch,
        }
    }
}

impl From<SlotTrackerError> for ErrorOrUserError {
    fn from(err: SlotTrackerError) -> Self {
        UserError::from(err).into()
    }
}