• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::IoctlFlags;
2 use nix::errno::Errno;
3 use thiserror::Error;
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     /// Copy ioctl failure with copied length.
20     #[error("Copy partially succeeded")]
21     PartiallyCopied(usize),
22 
23     /// Failure to read a full `uffd_msg` struct from the underlying file descriptor.
24     #[error("Incomplete uffd_msg; read only {read}/{expected} bytes")]
25     IncompleteMsg { read: usize, expected: usize },
26 
27     /// Generic system error.
28     #[error("System error")]
29     SystemError(#[source] nix::Error),
30 
31     /// End-of-file was read from the underlying file descriptor.
32     #[error("EOF when reading file descriptor")]
33     ReadEof,
34 
35     /// An unrecognized event code was found in a `uffd_msg` struct.
36     #[error("Unrecognized event in uffd_msg: {0}")]
37     UnrecognizedEvent(u8),
38 
39     /// An unrecognized ioctl bit was set in the result of API initialization or registration.
40     #[error("Unrecognized ioctl flags: {0}")]
41     UnrecognizedIoctls(u64),
42 
43     /// Requested ioctls were not available when initializing the API.
44     #[error("Requested ioctls unsupported; supported: {0:?}")]
45     UnsupportedIoctls(IoctlFlags),
46 
47     /// Zeropage ioctl failure with `errno` value.
48     #[error("Zeropage failed: {0}")]
49     ZeropageFailed(Errno),
50 }
51 
52 impl From<nix::Error> for Error {
from(e: nix::Error) -> Error53     fn from(e: nix::Error) -> Error {
54         Error::SystemError(e)
55     }
56 }
57