Skip to content

Commit 271895a

Browse files
mimullin-bbrydanielocfb
authored andcommitted
libbpf-rs, libbpf-cargo: Update to libbpf-sys v 1.1.0
Update both libbpf-rs and libbpf-cargo to version 1.1.0 Signed-off-by: Michael Mullin <mimullin@blackberry.com>
1 parent 07e470c commit 271895a

File tree

13 files changed

+28
-47
lines changed

13 files changed

+28
-47
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libbpf-cargo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ novendor = ["libbpf-sys/novendor"]
3232
[dependencies]
3333
anyhow = "1.0"
3434
cargo_metadata = "0.14"
35-
libbpf-sys = { version = "1.0.3" }
35+
libbpf-sys = { version = "1.1.0" }
3636
memmap2 = "0.5"
3737
num_enum = "0.5"
3838
regex = { version = "1.6.0", default-features = false, features = ["std", "unicode-perl"] }

libbpf-cargo/src/btf/btf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ffi::{c_void, CStr, CString};
55
use std::fmt::Write;
66
use std::marker::PhantomData;
77
use std::mem::size_of;
8-
use std::os::raw::{c_char, c_ulong};
8+
use std::os::raw::c_char;
99
use std::ptr;
1010
use std::slice;
1111

@@ -375,14 +375,14 @@ impl Btf {
375375
pub fn new(name: &str, object_file: &[u8]) -> Result<Option<Self>> {
376376
let cname = CString::new(name)?;
377377
let obj_opts = libbpf_sys::bpf_object_open_opts {
378-
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
378+
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>(),
379379
object_name: cname.as_ptr(),
380380
..Default::default()
381381
};
382382
let bpf_obj = unsafe {
383383
libbpf_sys::bpf_object__open_mem(
384384
object_file.as_ptr() as *const c_void,
385-
object_file.len() as c_ulong,
385+
object_file.len(),
386386
&obj_opts,
387387
)
388388
};

libbpf-cargo/src/gen.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::fs::File;
77
use std::io::stdout;
88
use std::io::ErrorKind;
99
use std::io::Write;
10-
use std::os::raw::c_ulong;
1110
use std::path::{Path, PathBuf};
1211
use std::process::{Command, Stdio};
1312
use std::ptr;
@@ -604,16 +603,12 @@ fn gen_skel_link_getter(skel: &mut String, object: &mut BpfObj, obj_name: &str)
604603
fn open_bpf_object(name: &str, data: &[u8]) -> Result<BpfObj> {
605604
let cname = CString::new(name)?;
606605
let obj_opts = libbpf_sys::bpf_object_open_opts {
607-
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
606+
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>(),
608607
object_name: cname.as_ptr(),
609608
..Default::default()
610609
};
611610
let object = unsafe {
612-
libbpf_sys::bpf_object__open_mem(
613-
data.as_ptr() as *const c_void,
614-
data.len() as c_ulong,
615-
&obj_opts,
616-
)
611+
libbpf_sys::bpf_object__open_mem(data.as_ptr() as *const c_void, data.len(), &obj_opts)
617612
};
618613
if object.is_null() {
619614
bail!("Failed to bpf_object__open_mem()");

libbpf-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static = ["libbpf-sys/static"]
2323
[dependencies]
2424
bitflags = "1.3"
2525
lazy_static = "1.4"
26-
libbpf-sys = { version = "1.0.3" }
26+
libbpf-sys = { version = "1.1.0" }
2727
nix = { version = "0.24", default-features = false, features = ["net", "user"] }
2828
num_enum = "0.5"
2929
strum_macros = "0.23"

libbpf-rs/src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl OpenMap {
5757
libbpf_sys::bpf_map__set_initial_value(
5858
self.ptr,
5959
data.as_ptr() as *const std::ffi::c_void,
60-
data.len() as libbpf_sys::size_t,
60+
data.len(),
6161
)
6262
};
6363

libbpf-rs/src/object.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ObjectBuilder {
3939
/// Get an instance of libbpf_sys::bpf_object_open_opts.
4040
pub fn opts(&mut self, name: *const c_char) -> libbpf_sys::bpf_object_open_opts {
4141
libbpf_sys::bpf_object_open_opts {
42-
sz: mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
42+
sz: mem::size_of::<libbpf_sys::bpf_object_open_opts>(),
4343
object_name: name,
4444
relaxed_maps: self.relaxed_maps,
4545
pin_root_path: ptr::null(),
@@ -97,11 +97,7 @@ impl ObjectBuilder {
9797
let opts = self.opts(name_ptr);
9898

9999
let obj = unsafe {
100-
libbpf_sys::bpf_object__open_mem(
101-
mem.as_ptr() as *const c_void,
102-
mem.len() as libbpf_sys::size_t,
103-
&opts,
104-
)
100+
libbpf_sys::bpf_object__open_mem(mem.as_ptr() as *const c_void, mem.len(), &opts)
105101
};
106102
let err = unsafe { libbpf_sys::libbpf_get_error(obj as *const _) };
107103
if err != 0 {

libbpf-rs/src/perf_buffer.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'b> PerfBufferBuilder<'a, 'b> {
113113
let ptr = unsafe {
114114
libbpf_sys::perf_buffer__new(
115115
self.map.fd(),
116-
self.pages as libbpf_sys::size_t,
116+
self.pages,
117117
c_sample_cb,
118118
c_lost_cb,
119119
callback_struct_ptr as *mut _,
@@ -175,19 +175,16 @@ impl<'b> PerfBuffer<'b> {
175175
}
176176

177177
pub fn consume_buffer(&self, buf_idx: usize) -> Result<()> {
178-
let ret = unsafe {
179-
libbpf_sys::perf_buffer__consume_buffer(self.ptr, buf_idx as libbpf_sys::size_t)
180-
};
178+
let ret = unsafe { libbpf_sys::perf_buffer__consume_buffer(self.ptr, buf_idx) };
181179
util::parse_ret(ret)
182180
}
183181

184182
pub fn buffer_cnt(&self) -> usize {
185-
unsafe { libbpf_sys::perf_buffer__buffer_cnt(self.ptr) as usize }
183+
unsafe { libbpf_sys::perf_buffer__buffer_cnt(self.ptr) }
186184
}
187185

188186
pub fn buffer_fd(&self, buf_idx: usize) -> Result<i32> {
189-
let ret =
190-
unsafe { libbpf_sys::perf_buffer__buffer_fd(self.ptr, buf_idx as libbpf_sys::size_t) };
187+
let ret = unsafe { libbpf_sys::perf_buffer__buffer_fd(self.ptr, buf_idx) };
191188
util::parse_ret_i32(ret)
192189
}
193190
}

libbpf-rs/src/program.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl OpenProgram {
105105
/// So [`OpenProgram::insn_cnt`] and [`Program::insn_cnt`] may return different values.
106106
///
107107
pub fn insn_cnt(&self) -> usize {
108-
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) as usize }
108+
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) }
109109
}
110110

111111
/// Gives read-only access to BPF program's underlying BPF instructions.
@@ -374,13 +374,7 @@ impl Program {
374374
let path = util::path_to_cstring(binary_path.as_ref())?;
375375
let path_ptr = path.as_ptr();
376376
let ptr = unsafe {
377-
libbpf_sys::bpf_program__attach_uprobe(
378-
self.ptr,
379-
retprobe,
380-
pid,
381-
path_ptr,
382-
func_offset as libbpf_sys::size_t,
383-
)
377+
libbpf_sys::bpf_program__attach_uprobe(self.ptr, retprobe, pid, path_ptr, func_offset)
384378
};
385379
let err = unsafe { libbpf_sys::libbpf_get_error(ptr as *const _) };
386380
if err != 0 {
@@ -526,7 +520,7 @@ impl Program {
526520
///
527521
/// Please see note in [`OpenProgram::insn_cnt`].
528522
pub fn insn_cnt(&self) -> usize {
529-
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) as usize }
523+
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) }
530524
}
531525

532526
/// Gives read-only access to BPF program's underlying BPF instructions.

libbpf-rs/src/ringbuf.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::ffi::c_void;
22
use std::boxed::Box;
3-
use std::os::raw::c_ulong;
43
use std::ptr;
54
use std::slice;
65
use std::time::Duration;
@@ -110,11 +109,11 @@ impl<'a> RingBufferBuilder<'a> {
110109
Ok(RingBuffer { ptr, _cbs: cbs })
111110
}
112111

113-
unsafe extern "C" fn call_sample_cb(ctx: *mut c_void, data: *mut c_void, size: c_ulong) -> i32 {
112+
unsafe extern "C" fn call_sample_cb(ctx: *mut c_void, data: *mut c_void, size: usize) -> i32 {
114113
let callback_struct = ctx as *mut RingBufferCallback;
115114
let callback = (*callback_struct).cb.as_mut();
116115

117-
callback(slice::from_raw_parts(data as *const u8, size as usize))
116+
callback(slice::from_raw_parts(data as *const u8, size))
118117
}
119118
}
120119

0 commit comments

Comments
 (0)