1use alloc::boxed::Box;
7use thiserror::Error;
8
9#[derive(Debug, Error, Clone, Copy, Eq, PartialEq)]
11#[repr(u8)]
12pub enum PageError {
13 #[error("mmap failed")]
14 Create = 0,
15
16 #[error("mlock failed")]
17 Lock = 1,
18
19 #[error("mprotect(PROT_NONE) failed")]
20 Protect = 2,
21
22 #[error("mprotect(PROT_WRITE) failed")]
23 Unprotect = 3,
24
25 #[error("madvise(MADV_DONTDUMP) failed")]
26 Madvise = 4,
27}
28
29#[derive(Debug, Error)]
31pub enum BufferError {
32 #[error("PageError: {0}")]
34 Page(#[from] PageError),
35
36 #[error("page is no longer available")]
38 PageNoLongerAvailable,
39
40 #[error("callback error: {0:?}")]
42 CallbackError(Box<dyn core::fmt::Debug + Send + Sync + 'static>),
43
44 #[error("mutex poisoned")]
46 MutexPoisoned,
47}
48
49impl BufferError {
50 pub fn callback_error<E: core::fmt::Debug + Send + Sync + 'static>(e: E) -> Self {
52 Self::CallbackError(Box::new(e))
53 }
54}