1use std::sync::Arc;
2
3use elf::{relocation::Rel, ParseError};
4use thiserror::Error as ThisError;
5
6#[derive(ThisError, Debug, Clone)]
7#[error("ebpf runtime error: {0}")]
8pub struct Error(pub(crate) RuntimeError);
10
11#[derive(ThisError, Debug, Clone)]
12pub(crate) enum RuntimeError {
13 #[error("invalid argument: {0}")]
14 InvalidArgument(&'static str),
15
16 #[error("invalid argument: {0}")]
17 InvalidArgumentOwned(String),
18
19 #[error("platform error: {0}")]
20 PlatformError(&'static str),
21
22 #[error("helper returned error: {0}")]
23 HelperError(&'static str),
24
25 #[error("helper returned error during async invocation: {0}")]
26 AsyncHelperError(&'static str),
27
28 #[error("linker returned error: {0}")]
29 Linker(LinkerError),
30
31 #[error("memory fault at virtual address {0:#x}")]
32 MemoryFault(usize),
33}
34
35#[derive(ThisError, Debug, Clone)]
36pub(crate) enum LinkerError {
37 #[error("invalid elf image: {0}")]
38 InvalidElf(&'static str),
39
40 #[error("bad relocation: {0} ({1:?})")]
41 Reloc(String, Rel),
42
43 #[error("elf parse failed: {0}")]
44 Parse(Arc<ParseError>),
45}
46
47impl From<ParseError> for LinkerError {
48 fn from(e: ParseError) -> Self {
49 Self::Parse(Arc::new(e))
50 }
51}