Repository: libbpf/libbpf-rs (language: rust)

Issue:
How can I access `*const bpf_object`, `*const bpf_map` from corresponding Rust structs?
Like the title. I'm going to get the raw pointer and do some operations manually with `libbpf-sys`, but I didn't find any way to access underlying raw pointer in `Object` or `Map`


Discussion / hints:
I don't believe we expose that currently. But we probably should, similar to what we did over here https://github.com/libbpf/libbpf-rs/pull/348.

@Officeyutong do you want to work on exposing that?

Fix patch:
diff --git a/libbpf-rs/src/map.rs b/libbpf-rs/src/map.rs
index 4a1afc8b..ec765cff 100644
--- a/libbpf-rs/src/map.rs
+++ b/libbpf-rs/src/map.rs
@@ -602,6 +602,11 @@ impl Map {
             Link::new(ptr)
         })
     }
+
+    /// Retrieve the underlying [`libbpf_sys::bpf_map`].
+    pub fn as_libbpf_bpf_map_ptr(&self) -> Option<NonNull<libbpf_sys::bpf_map>> {
+        self.ptr
+    }
 }
 
 bitflags! {
diff --git a/libbpf-rs/src/object.rs b/libbpf-rs/src/object.rs
index 7e12f4cd..6724fc30 100644
--- a/libbpf-rs/src/object.rs
+++ b/libbpf-rs/src/object.rs
@@ -406,6 +406,11 @@ impl Object {
     pub fn progs_iter_mut(&mut self) -> impl Iterator<Item = &mut Program> {
         self.progs.values_mut()
     }
+
+    /// Retrieve the underlying [`libbpf_sys::bpf_object`].
+    pub fn as_libbpf_bpf_object_ptr(&self) -> NonNull<libbpf_sys::bpf_object> {
+        self.ptr
+    }
 }
 
 impl Drop for Object {


Test patch: