Skip to content

Commit 78a920b

Browse files
committed
gen: don't fail on non-autocreate maps
if autocreate(false) is set for a map, the fd will be invalid, causing further failure of the skeleton loading. this is the case when trying to load some program with #define BPF_NO_GLOBAL_DATA (when bpf_printk() is used), as the '.rodata.str1.1' map skips auto-creating. Signed-off-by: Eliad Peller <eliad.peller@wiz.io>
1 parent 5cf3960 commit 78a920b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libbpf-rs/src/map.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ impl Map {
264264

265265
// Get the map fd
266266
let fd = unsafe { libbpf_sys::bpf_map__fd(ptr.as_ptr()) };
267-
let fd = util::parse_ret_i32(fd)?;
267+
let fd = match util::parse_ret_i32(fd) {
268+
Ok(fd) => fd,
269+
// fail only if the map is autocreate
270+
Err(e) if unsafe { libbpf_sys::bpf_map__autocreate(ptr.as_ptr()) } => return Err(e),
271+
Err(_) => fd,
272+
};
268273

269274
let ty = MapType::try_from(unsafe { libbpf_sys::bpf_map__type(ptr.as_ptr()) })
270275
.unwrap_or(MapType::Unknown);

0 commit comments

Comments
 (0)