diff --git a/ebpf/aya-ebpf/src/error.rs b/ebpf/aya-ebpf/src/error.rs new file mode 100644 index 00000000..78c9606b --- /dev/null +++ b/ebpf/aya-ebpf/src/error.rs @@ -0,0 +1,3 @@ +use crate::cty::c_long; + +pub const EINVAL: c_long = 22; diff --git a/ebpf/aya-ebpf/src/lib.rs b/ebpf/aya-ebpf/src/lib.rs index ced59066..44d886a4 100644 --- a/ebpf/aya-ebpf/src/lib.rs +++ b/ebpf/aya-ebpf/src/lib.rs @@ -23,6 +23,7 @@ pub use aya_ebpf_bindings::bindings; mod args; pub use args::{PtRegs, RawTracepointArgs}; +pub mod error; #[expect(clippy::missing_safety_doc, unsafe_op_in_unsafe_fn)] pub mod helpers; pub mod maps; diff --git a/ebpf/aya-ebpf/src/maps/array.rs b/ebpf/aya-ebpf/src/maps/array.rs index ca26e48b..534aede5 100644 --- a/ebpf/aya-ebpf/src/maps/array.rs +++ b/ebpf/aya-ebpf/src/maps/array.rs @@ -4,6 +4,7 @@ use aya_ebpf_cty::c_long; use crate::{ bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_ARRAY}, + error::EINVAL, insert, lookup, maps::PinningType, }; @@ -48,9 +49,19 @@ impl Array { } #[inline(always)] - pub fn get(&self, index: u32) -> Option<&T> { - // FIXME: alignment - unsafe { self.lookup(index).map(|p| p.as_ref()) } + pub fn get(&self, index: u32) -> Result, c_long> { + unsafe { + match self.lookup(index) { + Some(p) => { + if p.is_aligned() { + Ok(Some(p.as_ref())) + } else { + Err(-EINVAL) + } + } + None => Ok(None), + } + } } #[inline(always)]