inkpad_executor/trap.rs
1//! wasm traps
2use crate::Error;
3use inkpad_std::{Box, String, Vec};
4
5/// A trap code describing the reason for a trap.
6///
7/// All trap instructions have an explicit trap code.
8#[non_exhaustive]
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub enum TrapCode {
11 /// The current stack space was exhausted.
12 StackOverflow,
13
14 /// An out-of-bounds memory access.
15 MemoryOutOfBounds,
16
17 /// A wasm atomic operation was presented with a not-naturally-aligned linear-memory address.
18 HeapMisaligned,
19
20 /// An out-of-bounds access to a table.
21 TableOutOfBounds,
22
23 /// Indirect call to a null table entry.
24 IndirectCallToNull,
25
26 /// Signature mismatch on indirect call.
27 BadSignature,
28
29 /// An integer arithmetic operation caused an overflow.
30 IntegerOverflow,
31
32 /// An integer division by zero.
33 IntegerDivisionByZero,
34
35 /// Failed float-to-int conversion.
36 BadConversionToInteger,
37
38 /// Code that was supposed to have been unreachable was reached.
39 UnreachableCodeReached,
40
41 /// Execution has potentially run too long and may be interrupted.
42 Interrupt,
43
44 /// HostError
45 HostError(Box<Error>),
46
47 // Unknown Error
48 Unknown,
49
50 // Termination
51 Termination,
52
53 // Restoration
54 Restoration,
55}
56
57/// Wasm Trap
58#[derive(Clone, Debug, PartialEq, Eq)]
59pub struct Trap {
60 /// Trap code
61 pub code: TrapCode,
62 /// Wasm backtrace (in wasmtime, this includes native backtrace)
63 pub trace: Vec<String>,
64}
65
66impl From<TrapCode> for Trap {
67 fn from(code: TrapCode) -> Trap {
68 Trap {
69 code,
70 trace: Vec::new(),
71 }
72 }
73}