1use crate::{elf::ElfError, memory_region::AccessType, verifier::VerifierError};
21
22pub trait UserDefinedError: 'static + std::error::Error {}
24
25#[derive(Debug, thiserror::Error, PartialEq, Eq)]
27pub enum EbpfError<E: UserDefinedError> {
28 #[error("{0}")]
30 UserError(#[from] E),
31 #[error("ELF error: {0}")]
33 ElfError(#[from] ElfError),
34 #[error("syscall #{0} was already registered before")]
36 SycallAlreadyRegistered(usize),
37 #[error("syscall #{0} was not registered before bind")]
39 SyscallNotRegistered(usize),
40 #[error("syscall #{0} already has a bound context object")]
42 SyscallAlreadyBound(usize),
43 #[error("exceeded max BPF to BPF call depth of {1} at instruction #{0}")]
45 CallDepthExceeded(usize, usize),
46 #[error("attempted to exit root call frame")]
48 ExitRootCallFrame,
49 #[error("divide by zero at instruction {0}")]
51 DivideByZero(usize),
52 #[error("attempted to execute past the end of the text segment at instruction #{0}")]
54 ExecutionOverrun(usize),
55 #[error(
57 "callx at instruction {0} attempted to call outside of the text segment to addr 0x{1:x}"
58 )]
59 CallOutsideTextSegment(usize, u64),
60 #[error("exceeded maximum number of instructions allowed ({1}) at instruction #{0}")]
62 ExceededMaxInstructions(usize, u64),
63 #[error("program has not been JIT-compiled")]
65 JitNotCompiled,
66 #[error("invalid virtual address {0:x?}")]
68 InvalidVirtualAddress(u64),
69 #[error("Invalid memory region at index {0}")]
71 InvalidMemoryRegion(usize),
72 #[error("Access violation in {4} section at address {2:#x} of size {3:?} by instruction #{0}")]
74 AccessViolation(usize, AccessType, u64, u64, &'static str),
75 #[error(
77 "Access violation in stack frame {4} at address {2:#x} of size {3:?} by instruction #{0}"
78 )]
79 StackAccessViolation(usize, AccessType, u64, u64, i64),
80 #[error("invalid instruction at {0}")]
82 InvalidInstruction(usize),
83 #[error("unsupported instruction at instruction {0}")]
85 UnsupportedInstruction(usize),
86 #[error("Compilation exhaused text segment at instruction {0}")]
88 ExhausedTextSegment(usize),
89 #[error("Libc calling {0} {1:?} returned error code {2}")]
91 LibcInvocationFailed(&'static str, Vec<String>, i32),
92 #[error("Verifier error: {0}")]
94 VerifierError(#[from] VerifierError),
95}