Skip to content

Commit a7a0dde

Browse files
mimullin-bbrydanielocfb
authored andcommitted
Revert "libbpf-rs, libbpf-cargo: Update to libbpf-sys v 1.1.0"
This reverts commit 271895a. libbpf-sys has updated to 1.1.1 and the changes to compile against 1.1.0 now cause breaks. Signed-off-by: Michael Mullin <mimullin@blackberry.com>
1 parent 271895a commit a7a0dde

File tree

13 files changed

+47
-28
lines changed

13 files changed

+47
-28
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.1.0" }
35+
libbpf-sys = { version = "1.0.3" }
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;
8+
use std::os::raw::{c_char, c_ulong};
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>(),
378+
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
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(),
385+
object_file.len() as c_ulong,
386386
&obj_opts,
387387
)
388388
};

libbpf-cargo/src/gen.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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;
1011
use std::path::{Path, PathBuf};
1112
use std::process::{Command, Stdio};
1213
use std::ptr;
@@ -603,12 +604,16 @@ fn gen_skel_link_getter(skel: &mut String, object: &mut BpfObj, obj_name: &str)
603604
fn open_bpf_object(name: &str, data: &[u8]) -> Result<BpfObj> {
604605
let cname = CString::new(name)?;
605606
let obj_opts = libbpf_sys::bpf_object_open_opts {
606-
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>(),
607+
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
607608
object_name: cname.as_ptr(),
608609
..Default::default()
609610
};
610611
let object = unsafe {
611-
libbpf_sys::bpf_object__open_mem(data.as_ptr() as *const c_void, data.len(), &obj_opts)
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+
)
612617
};
613618
if object.is_null() {
614619
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.1.0" }
26+
libbpf-sys = { version = "1.0.3" }
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(),
60+
data.len() as libbpf_sys::size_t,
6161
)
6262
};
6363

libbpf-rs/src/object.rs

Lines changed: 6 additions & 2 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>(),
42+
sz: mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
4343
object_name: name,
4444
relaxed_maps: self.relaxed_maps,
4545
pin_root_path: ptr::null(),
@@ -97,7 +97,11 @@ impl ObjectBuilder {
9797
let opts = self.opts(name_ptr);
9898

9999
let obj = unsafe {
100-
libbpf_sys::bpf_object__open_mem(mem.as_ptr() as *const c_void, mem.len(), &opts)
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+
)
101105
};
102106
let err = unsafe { libbpf_sys::libbpf_get_error(obj as *const _) };
103107
if err != 0 {

libbpf-rs/src/perf_buffer.rs

Lines changed: 7 additions & 4 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,
116+
self.pages as libbpf_sys::size_t,
117117
c_sample_cb,
118118
c_lost_cb,
119119
callback_struct_ptr as *mut _,
@@ -175,16 +175,19 @@ impl<'b> PerfBuffer<'b> {
175175
}
176176

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

182184
pub fn buffer_cnt(&self) -> usize {
183-
unsafe { libbpf_sys::perf_buffer__buffer_cnt(self.ptr) }
185+
unsafe { libbpf_sys::perf_buffer__buffer_cnt(self.ptr) as usize }
184186
}
185187

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

libbpf-rs/src/program.rs

Lines changed: 9 additions & 3 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) }
108+
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) as usize }
109109
}
110110

111111
/// Gives read-only access to BPF program's underlying BPF instructions.
@@ -374,7 +374,13 @@ 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(self.ptr, retprobe, pid, path_ptr, func_offset)
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+
)
378384
};
379385
let err = unsafe { libbpf_sys::libbpf_get_error(ptr as *const _) };
380386
if err != 0 {
@@ -520,7 +526,7 @@ impl Program {
520526
///
521527
/// Please see note in [`OpenProgram::insn_cnt`].
522528
pub fn insn_cnt(&self) -> usize {
523-
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) }
529+
unsafe { libbpf_sys::bpf_program__insn_cnt(self.ptr) as usize }
524530
}
525531

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

libbpf-rs/src/ringbuf.rs

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

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

116-
callback(slice::from_raw_parts(data as *const u8, size))
117+
callback(slice::from_raw_parts(data as *const u8, size as usize))
117118
}
118119
}
119120

0 commit comments

Comments
 (0)