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