1 use crate::IoctlFlags; 2 use thiserror::Error; 3 use nix::errno::Errno; 4 5 pub type Result<T> = std::result::Result<T, Error>; 6 7 /// Errors for this crate. 8 /// 9 /// Several of these errors contain an underlying `Errno` value; see 10 /// [`userfaultfd(2)`](http://man7.org/linux/man-pages/man2/userfaultfd.2.html) and 11 /// [`ioctl_userfaultfd(2)`](http://man7.org/linux/man-pages/man2/ioctl_userfaultfd.2.html) for more 12 /// details on how to interpret these errors. 13 #[derive(Debug, Error)] 14 pub enum Error { 15 /// Copy ioctl failure with `errno` value. 16 #[error("Copy failed")] 17 CopyFailed(Errno), 18 19 /// Failure to read a full `uffd_msg` struct from the underlying file descriptor. 20 #[error("Incomplete uffd_msg; read only {read}/{expected} bytes")] 21 IncompleteMsg { read: usize, expected: usize }, 22 23 /// Generic system error. 24 #[error("System error")] 25 SystemError(#[source] nix::Error), 26 27 /// End-of-file was read from the underlying file descriptor. 28 #[error("EOF when reading file descriptor")] 29 ReadEof, 30 31 /// An unrecognized event code was found in a `uffd_msg` struct. 32 #[error("Unrecognized event in uffd_msg: {0}")] 33 UnrecognizedEvent(u8), 34 35 /// An unrecognized ioctl bit was set in the result of API initialization or registration. 36 #[error("Unrecognized ioctl flags: {0}")] 37 UnrecognizedIoctls(u64), 38 39 /// Requested ioctls were not available when initializing the API. 40 #[error("Requested ioctls unsupported; supported: {0:?}")] 41 UnsupportedIoctls(IoctlFlags), 42 43 /// Zeropage ioctl failure with `errno` value. 44 #[error("Zeropage failed: {0}")] 45 ZeropageFailed(Errno), 46 } 47 48 impl From<nix::Error> for Error { from(e: nix::Error) -> Error49 fn from(e: nix::Error) -> Error { 50 Error::SystemError(e) 51 } 52 } 53