2016-03-14 21:48:00 -06:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum EvalError {
|
|
|
|
DanglingPointerDeref,
|
|
|
|
InvalidBool,
|
|
|
|
PointerOutOfBounds,
|
|
|
|
InvalidPointerAccess,
|
2016-03-17 07:24:10 -06:00
|
|
|
ReadBytesAsPointer,
|
2016-03-14 21:48:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub type EvalResult<T> = Result<T, EvalError>;
|
|
|
|
|
|
|
|
impl Error for EvalError {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
EvalError::DanglingPointerDeref => "dangling pointer was dereferenced",
|
|
|
|
EvalError::InvalidBool => "invalid boolean value read",
|
|
|
|
EvalError::PointerOutOfBounds => "pointer offset outside bounds of allocation",
|
|
|
|
EvalError::InvalidPointerAccess =>
|
|
|
|
"a raw memory access tried to access part of a pointer value as bytes",
|
2016-03-17 07:24:10 -06:00
|
|
|
EvalError::ReadBytesAsPointer =>
|
|
|
|
"attempted to read some raw bytes as a pointer address",
|
2016-03-14 21:48:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cause(&self) -> Option<&Error> { None }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for EvalError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.description())
|
|
|
|
}
|
|
|
|
}
|