|
|
@ -47,14 +47,28 @@ impl<T> Array<T> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn get(&self, index: u32) -> Option<&T> {
|
|
|
|
pub fn get(&self, index: u32) -> Option<&T> {
|
|
|
|
unsafe {
|
|
|
|
// FIXME: alignment
|
|
|
|
let value = bpf_map_lookup_elem(
|
|
|
|
unsafe { self.lookup(index).map(|p| p.as_ref()) }
|
|
|
|
self.def.get() as *mut _,
|
|
|
|
}
|
|
|
|
&index as *const _ as *const c_void,
|
|
|
|
|
|
|
|
);
|
|
|
|
#[inline(always)]
|
|
|
|
// FIXME: alignment
|
|
|
|
pub fn get_ptr(&self, index: u32) -> Option<*const T> {
|
|
|
|
NonNull::new(value as *mut T).map(|p| p.as_ref())
|
|
|
|
unsafe { self.lookup(index).map(|p| p.as_ptr() as *const T) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
|
|
|
pub fn get_ptr_mut(&self, index: u32) -> Option<*mut T> {
|
|
|
|
|
|
|
|
unsafe { self.lookup(index).map(|p| p.as_ptr()) }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
|
|
|
unsafe fn lookup(&self, index: u32) -> Option<NonNull<T>> {
|
|
|
|
|
|
|
|
let ptr = bpf_map_lookup_elem(
|
|
|
|
|
|
|
|
self.def.get() as *mut _,
|
|
|
|
|
|
|
|
&index as *const _ as *const c_void,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
NonNull::new(ptr as *mut T)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|