qemu_plugin/error/
mod.rs

1//! Errors that can occur in the qemu-plugin crate
2
3#[derive(thiserror::Error, Debug)]
4/// An error from the qemu-plugin crate
5pub enum Error {
6    #[error("Missing key for argument {argument}")]
7    /// Error when an argument is missing a key
8    MissingArgKey {
9        /// The argument string a key is missing for
10        argument: String,
11    },
12    #[error("Missing value for argument {argument}")]
13    /// Error when an argument is missing a value
14    MissingArgValue {
15        /// The argument string a value is missing for
16        argument: String,
17    },
18    #[error("Invalid boolean value {name} ({val})")]
19    /// Error when a boolean argument is invalid
20    InvalidBool {
21        /// The name of the key-value argument pair which does not correctly parse as boolean
22        name: String,
23        /// The value of the key-value argument pair which does not correctly parse as boolean
24        val: String,
25    },
26    #[error(
27        "Setting the QEMU plugin uninstall callback was attempted concurrently and this attempt failed."
28    )]
29    /// Error when the QEMU plugin uninstall callback is set concurrently
30    ConcurrentPluginUninstallCallbackSet,
31    #[error(
32        "Setting the QEMU plugin reset callback was attempted concurrently and this attempt failed."
33    )]
34    /// Error when the QEMU plugin reset callback is set concurrently
35    ConcurrentPluginResetCallbackSet,
36    #[error("Invalid state for plugin reset callback")]
37    /// Error when the plugin reset callback is in an invalid state
38    PluginResetCallbackState,
39    #[error("Invalid instruction index {index} for translation block of size {size}")]
40    /// Error when an instruction index is invalid
41    InvalidInstructionIndex {
42        /// The index into the translation block that is invalid
43        index: usize,
44        /// The size of the translation block
45        size: usize,
46    },
47    #[error("No disassembly string available for instruction")]
48    /// Error when no disassembly string is available for an instruction (i.e. NULL string
49    NoDisassemblyString,
50    #[error("Invalid size {size} for read of register {name}")]
51    /// Error when the size of a register read is invalid
52    InvalidRegisterReadSize {
53        /// The register name
54        name: String,
55        /// The size of the attempted read
56        size: usize,
57    },
58    #[error("Error while reading register {name}")]
59    /// Error when reading a register fails
60    RegisterReadError {
61        /// The register name
62        name: String,
63    },
64    #[error("Error while writing register {name}")]
65    /// Error when writing a register fails
66    RegisterWriteError {
67        /// The register name
68        name: String,
69    },
70    #[cfg(not(any(
71        feature = "plugin-api-v0",
72        feature = "plugin-api-v1",
73        feature = "plugin-api-v2",
74        feature = "plugin-api-v3"
75    )))]
76    #[error("Error while reading {len} bytes from virtual address {addr:#x}")]
77    /// Error when reading memory from a virtual address fails
78    VaddrReadError {
79        /// The address read from
80        addr: u64,
81        /// The number of bytes read
82        len: u32,
83    },
84    #[cfg(not(any(
85        feature = "plugin-api-v0",
86        feature = "plugin-api-v1",
87        feature = "plugin-api-v2",
88        feature = "plugin-api-v3",
89        feature = "plugin-api-v4"
90    )))]
91    #[error("Error while writing {len} bytes to virtual address {addr:#x}")]
92    /// Error when writing memory from a virtual address fails
93    VaddrWriteError {
94        /// The address written to
95        addr: u64,
96        /// The number of bytes written
97        len: u32,
98    },
99    #[cfg(not(any(
100        feature = "plugin-api-v0",
101        feature = "plugin-api-v1",
102        feature = "plugin-api-v2",
103        feature = "plugin-api-v3",
104        feature = "plugin-api-v4"
105    )))]
106    #[error("Error while reading {len} bytes from hardware address {addr:#x}: {result}")]
107    /// Error when reading memory from a hardware address fails
108    HwaddrReadError {
109        /// The address read from
110        addr: u64,
111        /// The number of bytes read
112        len: u32,
113        /// The operation result
114        result: crate::HwaddrOperationResult,
115    },
116    #[cfg(not(any(
117        feature = "plugin-api-v0",
118        feature = "plugin-api-v1",
119        feature = "plugin-api-v2",
120        feature = "plugin-api-v3",
121        feature = "plugin-api-v4"
122    )))]
123    #[error("Error while writing {len} bytes to hardware address {addr:#x}: {result}")]
124    /// Error when writing memory from a hardware address fails
125    HwaddrWriteError {
126        /// The address written to
127        addr: u64,
128        /// The number of bytes written
129        len: u32,
130        /// The operation result
131        result: crate::HwaddrOperationResult,
132    },
133    #[cfg(not(any(
134        feature = "plugin-api-v0",
135        feature = "plugin-api-v1",
136        feature = "plugin-api-v2",
137        feature = "plugin-api-v3",
138        feature = "plugin-api-v4"
139    )))]
140    #[error("Error while translating virtual address {vaddr:#x} to hardware address")]
141    /// Error when translating a virtual address to a hardware address fails
142    VaddrTranslateError {
143        /// The virtual address that failed to translate
144        vaddr: u64,
145    },
146    #[error(transparent)]
147    /// A transparently wrapped `std::str::Utf8Error`
148    Utf8Error(#[from] std::str::Utf8Error),
149    #[error(transparent)]
150    /// A transparently wrapped `std::ffi::NulError`
151    NulError(#[from] std::ffi::NulError),
152    #[error(transparent)]
153    /// A transparently wrapped `anyhow::Error`
154    Other(#[from] anyhow::Error),
155}
156
157/// Result type for the qemu-plugin crate
158pub type Result<T> = std::result::Result<T, Error>;