From 00304c34025a9a66ddc8c44530b1d0b75d5911b4 Mon Sep 17 00:00:00 2001 From: Luis Gerhorst Date: Mon, 21 Oct 2024 16:14:03 +0200 Subject: [PATCH] HashMap: Impl. safe get_corrupt_u32() --- ebpf/aya-ebpf/src/maps/hash_map.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ebpf/aya-ebpf/src/maps/hash_map.rs b/ebpf/aya-ebpf/src/maps/hash_map.rs index 765188dc..b1581229 100644 --- a/ebpf/aya-ebpf/src/maps/hash_map.rs +++ b/ebpf/aya-ebpf/src/maps/hash_map.rs @@ -85,6 +85,16 @@ impl HashMap { } } +impl HashMap { + /// Retrieve the value associate with `key` from the map. This can not lead + /// to memory/type-safety bugs because a corrupt scalar can only lead to + /// logic bugs. + #[inline] + pub fn get_corrupt_u32(&self, key: &K) -> Option<&u32> { + unsafe { get(self.def.get(), key) } + } +} + #[repr(transparent)] pub struct LruHashMap { def: UnsafeCell,