isla_lib/error.rs
1// BSD 2-Clause License
2//
3// Copyright (c) 2019, 2020 Alasdair Armstrong
4//
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are
9// met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13//
14// 2. Redistributions in binary form must reproduce the above copyright
15// notice, this list of conditions and the following disclaimer in the
16// documentation and/or other materials provided with the distribution.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30use std::error::Error;
31use std::fmt;
32
33#[derive(Debug)]
34pub enum ExecError {
35 Type(String),
36 Unimplemented,
37 AssertionFailed(String),
38 Overflow,
39 /// SMTLIB only supports fixed-length bitvectors. This error is
40 /// raised if a bitvector width would become symbolic.
41 SymbolicLength(&'static str),
42 /// Returned when there is no symbolic representation for a
43 /// specific type. Certain types like strings are always assumed
44 /// to be concrete.
45 NoSymbolicType,
46 /// Used for cases that should be unreachable (i.e. are definite
47 /// errors).
48 Unreachable(String),
49 /// Used when we try to access memory that does not have any
50 /// defined semantics.
51 Unmapped,
52 BadRead(&'static str),
53 BadWrite(&'static str),
54 NoElfEntry,
55 OutOfBounds(&'static str),
56 MatchFailure,
57 Timeout,
58 Dead,
59 Exit,
60 NoModel,
61 Z3Error(String),
62 Z3Unknown,
63 /// Execution stopped because this function is in the stop_functions set
64 Stopped(String),
65}
66
67impl fmt::Display for ExecError {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 write!(f, "{:?}", self)
70 }
71}
72
73impl Error for ExecError {
74 fn source(&self) -> Option<&(dyn Error + 'static)> {
75 None
76 }
77}