|
|
@ -159,36 +159,23 @@ fn get_btf_info(prog_fd: i32, func_name: &str) -> Result<(RawFd, u32), ProgramEr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the bpf fd of the BTF object
|
|
|
|
// the bpf fd of the BTF object
|
|
|
|
let btf_fd = sys::bpf_btf_get_fd_by_id(info.btf_id).map_err(|io_error| SyscallError {
|
|
|
|
let btf_fd = sys::bpf_btf_get_fd_by_id(info.btf_id)?;
|
|
|
|
call: "bpf_btf_get_fd_by_id",
|
|
|
|
|
|
|
|
io_error,
|
|
|
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we need to read the btf bytes into a buffer but we don't know the size ahead of time.
|
|
|
|
// we need to read the btf bytes into a buffer but we don't know the size ahead of time.
|
|
|
|
// assume 4kb. if this is too small we can resize based on the size obtained in the response.
|
|
|
|
// assume 4kb. if this is too small we can resize based on the size obtained in the response.
|
|
|
|
let mut buf = vec![0u8; 4096];
|
|
|
|
let mut buf = vec![0u8; 4096];
|
|
|
|
let btf_info = match sys::btf_obj_get_info_by_fd(btf_fd, &buf) {
|
|
|
|
loop {
|
|
|
|
Ok(info) => {
|
|
|
|
let info = sys::btf_obj_get_info_by_fd(btf_fd, &mut buf)?;
|
|
|
|
if info.btf_size > buf.len() as u32 {
|
|
|
|
let btf_size = info.btf_size as usize;
|
|
|
|
buf.resize(info.btf_size as usize, 0u8);
|
|
|
|
if btf_size > buf.len() {
|
|
|
|
let btf_info =
|
|
|
|
buf.resize(btf_size, 0u8);
|
|
|
|
sys::btf_obj_get_info_by_fd(btf_fd, &buf).map_err(|io_error| SyscallError {
|
|
|
|
continue;
|
|
|
|
call: "bpf_prog_get_info_by_fd",
|
|
|
|
|
|
|
|
io_error,
|
|
|
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
Ok(btf_info)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Ok(info)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(io_error) => Err(SyscallError {
|
|
|
|
buf.truncate(btf_size);
|
|
|
|
call: "bpf_prog_get_info_by_fd",
|
|
|
|
break;
|
|
|
|
io_error,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
}?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let btf = Btf::parse(&buf[0..btf_info.btf_size as usize], Endianness::default())
|
|
|
|
let btf = Btf::parse(&buf, Endianness::default()).map_err(ProgramError::Btf)?;
|
|
|
|
.map_err(ProgramError::Btf)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let btf_id = btf
|
|
|
|
let btf_id = btf
|
|
|
|
.id_by_type_name_kind(func_name, BtfKind::Func)
|
|
|
|
.id_by_type_name_kind(func_name, BtfKind::Func)
|
|
|
|