From 82cd3e695a9843b97e4a87472d65e04a326a4348 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 9 Jun 2022 23:13:16 +1000 Subject: [PATCH] ebpf: PerCpuArray: remove get_mut() and add get_ptr() and get_ptr_mut() get_mut() wasn't sound as it allowed creating multiple mutable references. --- bpf/aya-bpf/src/maps/per_cpu_array.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bpf/aya-bpf/src/maps/per_cpu_array.rs b/bpf/aya-bpf/src/maps/per_cpu_array.rs index 7c567b49..5785de6e 100644 --- a/bpf/aya-bpf/src/maps/per_cpu_array.rs +++ b/bpf/aya-bpf/src/maps/per_cpu_array.rs @@ -56,11 +56,13 @@ impl PerCpuArray { } #[inline(always)] - pub fn get_mut(&self, index: u32) -> Option<&mut T> { - unsafe { - // FIXME: alignment - self.lookup(index).map(|mut p| p.as_mut()) - } + pub fn get_ptr(&self, index: u32) -> Option<*const T> { + 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)]