Skip to main content

procmod_hook/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during hook installation or removal.
4#[derive(Debug, Error)]
5pub enum Error {
6    /// Failed to allocate executable memory within 2GB of the target function.
7    #[error("failed to allocate trampoline within 2GB of target")]
8    TrampolineAlloc,
9
10    /// Failed to change memory protection on the target function's page.
11    #[error("failed to change memory protection")]
12    ProtectFailed,
13
14    /// The target function is too small to hook.
15    #[error("target too small to hook: need {need} bytes, found {have}")]
16    InsufficientSpace { need: usize, have: usize },
17
18    /// Instruction decoding or relocation failed.
19    #[error("instruction relocation failed")]
20    RelocationFailed,
21
22    /// Attempted to unhook a hook that is not currently installed.
23    #[error("hook not installed")]
24    NotInstalled,
25}
26
27/// Convenience alias for `std::result::Result<T, Error>`.
28pub type Result<T> = std::result::Result<T, Error>;