diff --git a/aya/src/maps/bloom_filter.rs b/aya/src/maps/bloom_filter.rs index 6135da5b..f646c2bb 100644 --- a/aya/src/maps/bloom_filter.rs +++ b/aya/src/maps/bloom_filter.rs @@ -90,7 +90,7 @@ mod tests { }; use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; - use std::io; + use std::{ffi::c_long, io}; fn new_obj_map() -> obj::Map { obj::Map::Legacy(LegacyMap { @@ -108,7 +108,7 @@ mod tests { }) } - fn sys_error(value: i32) -> SysResult { + fn sys_error(value: i32) -> SysResult { Err((-1, io::Error::from_raw_os_error(value))) } diff --git a/aya/src/maps/hash_map/hash_map.rs b/aya/src/maps/hash_map/hash_map.rs index 34f0b851..2fcb1334 100644 --- a/aya/src/maps/hash_map/hash_map.rs +++ b/aya/src/maps/hash_map/hash_map.rs @@ -105,7 +105,7 @@ impl, K: Pod, V: Pod> IterableMap for HashMap #[cfg(test)] mod tests { - use std::io; + use std::{ffi::c_long, io}; use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; @@ -139,7 +139,7 @@ mod tests { }) } - fn sys_error(value: i32) -> SysResult { + fn sys_error(value: i32) -> SysResult { Err((-1, io::Error::from_raw_os_error(value))) } @@ -451,7 +451,7 @@ mod tests { assert_matches!(keys, Ok(ks) if ks.is_empty()) } - fn get_next_key(attr: &bpf_attr) -> SysResult { + fn get_next_key(attr: &bpf_attr) -> SysResult { match bpf_key(attr) { None => set_next_key(attr, 10), Some(10) => set_next_key(attr, 20), @@ -463,7 +463,7 @@ mod tests { Ok(1) } - fn lookup_elem(attr: &bpf_attr) -> SysResult { + fn lookup_elem(attr: &bpf_attr) -> SysResult { match bpf_key(attr) { Some(10) => set_ret(attr, 100), Some(20) => set_ret(attr, 200), diff --git a/aya/src/maps/lpm_trie.rs b/aya/src/maps/lpm_trie.rs index b2e21e88..4adb3f47 100644 --- a/aya/src/maps/lpm_trie.rs +++ b/aya/src/maps/lpm_trie.rs @@ -209,7 +209,7 @@ mod tests { }; use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; - use std::{io, mem, net::Ipv4Addr}; + use std::{ffi::c_long, io, mem, net::Ipv4Addr}; fn new_obj_map() -> obj::Map { obj::Map::Legacy(LegacyMap { @@ -227,7 +227,7 @@ mod tests { }) } - fn sys_error(value: i32) -> SysResult { + fn sys_error(value: i32) -> SysResult { Err((-1, io::Error::from_raw_os_error(value))) } diff --git a/aya/src/sys/bpf.rs b/aya/src/sys/bpf.rs index e9f2eba8..5a26c57f 100644 --- a/aya/src/sys/bpf.rs +++ b/aya/src/sys/bpf.rs @@ -37,7 +37,7 @@ pub(crate) fn bpf_create_map( def: &obj::Map, btf_fd: Option, kernel_version: KernelVersion, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_1 }; @@ -93,7 +93,7 @@ pub(crate) fn bpf_create_map( sys_bpf(bpf_cmd::BPF_MAP_CREATE, &attr) } -pub(crate) fn bpf_pin_object(fd: RawFd, path: &CStr) -> SysResult { +pub(crate) fn bpf_pin_object(fd: RawFd, path: &CStr) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_4 }; u.bpf_fd = fd as u32; @@ -101,7 +101,7 @@ pub(crate) fn bpf_pin_object(fd: RawFd, path: &CStr) -> SysResult { sys_bpf(bpf_cmd::BPF_OBJ_PIN, &attr) } -pub(crate) fn bpf_get_object(path: &CStr) -> SysResult { +pub(crate) fn bpf_get_object(path: &CStr) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_4 }; u.pathname = path.as_ptr() as u64; @@ -130,7 +130,7 @@ pub(crate) fn bpf_load_program( aya_attr: &BpfLoadProgramAttrs, log_buf: &mut [u8], verifier_log_level: VerifierLogLevel, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_3 }; @@ -272,7 +272,7 @@ pub(crate) fn bpf_map_update_elem( key: Option<&K>, value: &V, flags: u64, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; @@ -286,7 +286,7 @@ pub(crate) fn bpf_map_update_elem( sys_bpf(bpf_cmd::BPF_MAP_UPDATE_ELEM, &attr) } -pub(crate) fn bpf_map_push_elem(fd: RawFd, value: &V, flags: u64) -> SysResult { +pub(crate) fn bpf_map_push_elem(fd: RawFd, value: &V, flags: u64) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; @@ -302,7 +302,7 @@ pub(crate) fn bpf_map_update_elem_ptr( key: *const K, value: *mut V, flags: u64, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; @@ -319,12 +319,12 @@ pub(crate) fn bpf_map_update_elem_per_cpu( key: &K, values: &PerCpuValues, flags: u64, -) -> SysResult { +) -> SysResult { let mut mem = values.build_kernel_mem().map_err(|e| (-1, e))?; bpf_map_update_elem_ptr(fd, key, mem.as_mut_ptr(), flags) } -pub(crate) fn bpf_map_delete_elem(fd: RawFd, key: &K) -> SysResult { +pub(crate) fn bpf_map_delete_elem(fd: RawFd, key: &K) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; @@ -356,7 +356,7 @@ pub(crate) fn bpf_map_get_next_key( } // since kernel 5.2 -pub(crate) fn bpf_map_freeze(fd: RawFd) -> SysResult { +pub(crate) fn bpf_map_freeze(fd: RawFd) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; u.map_fd = fd as u32; @@ -370,7 +370,7 @@ pub(crate) fn bpf_link_create( attach_type: bpf_attach_type, btf_id: Option, flags: u32, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.link_create.__bindgen_anon_1.prog_fd = prog_fd as u32; @@ -390,7 +390,7 @@ pub(crate) fn bpf_link_update( new_prog_fd: RawFd, old_prog_fd: Option, flags: u32, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.link_update.link_fd = link_fd as u32; @@ -409,7 +409,7 @@ pub(crate) fn bpf_prog_attach( prog_fd: RawFd, target_fd: RawFd, attach_type: bpf_attach_type, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.__bindgen_anon_5.attach_bpf_fd = prog_fd as u32; @@ -423,7 +423,7 @@ pub(crate) fn bpf_prog_detach( prog_fd: RawFd, map_fd: RawFd, attach_type: bpf_attach_type, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.__bindgen_anon_5.attach_bpf_fd = prog_fd as u32; @@ -440,7 +440,7 @@ pub(crate) fn bpf_prog_query( attach_flags: Option<&mut u32>, prog_ids: &mut [u32], prog_cnt: &mut u32, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.query.target_fd = target_fd as u32; @@ -545,7 +545,7 @@ pub(crate) fn btf_obj_get_info_by_fd( } } -pub(crate) fn bpf_raw_tracepoint_open(name: Option<&CStr>, prog_fd: RawFd) -> SysResult { +pub(crate) fn bpf_raw_tracepoint_open(name: Option<&CStr>, prog_fd: RawFd) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.raw_tracepoint.name = match name { @@ -561,7 +561,7 @@ pub(crate) fn bpf_load_btf( raw_btf: &[u8], log_buf: &mut [u8], verifier_log_level: VerifierLogLevel, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_7 }; u.btf = raw_btf.as_ptr() as *const _ as u64; @@ -987,7 +987,7 @@ pub(crate) fn is_btf_type_tag_supported() -> bool { } } -pub fn sys_bpf(cmd: bpf_cmd, attr: &bpf_attr) -> SysResult { +pub fn sys_bpf(cmd: bpf_cmd, attr: &bpf_attr) -> SysResult { syscall(Syscall::Bpf { cmd, attr }) } @@ -1002,10 +1002,10 @@ pub(crate) fn bpf_prog_get_next_id(id: u32) -> Result, (c_long, io:: } } -pub(crate) fn retry_with_verifier_logs( +pub(crate) fn retry_with_verifier_logs( max_retries: usize, - f: impl Fn(&mut [u8]) -> SysResult, -) -> (SysResult, String) { + f: impl Fn(&mut [u8]) -> SysResult, +) -> (SysResult, String) { const MIN_LOG_BUF_SIZE: usize = 1024 * 10; const MAX_LOG_BUF_SIZE: usize = (std::u32::MAX >> 8) as usize; diff --git a/aya/src/sys/fake.rs b/aya/src/sys/fake.rs index 2c2c337c..6cac51b6 100644 --- a/aya/src/sys/fake.rs +++ b/aya/src/sys/fake.rs @@ -1,10 +1,10 @@ -use std::{cell::RefCell, io, ptr}; +use std::{cell::RefCell, ffi::c_long, io, ptr}; use libc::c_void; use super::{SysResult, Syscall}; -type SyscallFn = unsafe fn(Syscall) -> SysResult; +type SyscallFn = unsafe fn(Syscall) -> SysResult; #[cfg(test)] thread_local! { @@ -13,11 +13,11 @@ thread_local! { } #[cfg(test)] -unsafe fn test_syscall(_call: Syscall) -> SysResult { +unsafe fn test_syscall(_call: Syscall) -> SysResult { Err((-1, io::Error::from_raw_os_error(libc::EINVAL))) } #[cfg(test)] -pub(crate) fn override_syscall(call: unsafe fn(Syscall) -> SysResult) { +pub(crate) fn override_syscall(call: unsafe fn(Syscall) -> SysResult) { TEST_SYSCALL.with(|test_impl| *test_impl.borrow_mut() = call); } diff --git a/aya/src/sys/mod.rs b/aya/src/sys/mod.rs index 646d6cfe..448e7fee 100644 --- a/aya/src/sys/mod.rs +++ b/aya/src/sys/mod.rs @@ -17,7 +17,7 @@ pub(crate) use perf_event::*; use crate::generated::{bpf_attr, bpf_cmd, perf_event_attr}; -pub(crate) type SysResult = Result; +pub(crate) type SysResult = Result; pub(crate) enum Syscall<'a> { Bpf { @@ -38,7 +38,7 @@ pub(crate) enum Syscall<'a> { }, } -fn syscall(call: Syscall) -> SysResult { +fn syscall(call: Syscall) -> SysResult { #[cfg(test)] return TEST_SYSCALL.with(|test_impl| unsafe { test_impl.borrow()(call) }); diff --git a/aya/src/sys/perf_event.rs b/aya/src/sys/perf_event.rs index 68eddd35..586bd50a 100644 --- a/aya/src/sys/perf_event.rs +++ b/aya/src/sys/perf_event.rs @@ -1,4 +1,7 @@ -use std::{ffi::CString, mem}; +use std::{ + ffi::{c_long, CString}, + mem, +}; use libc::{c_int, pid_t}; @@ -22,7 +25,7 @@ pub(crate) fn perf_event_open( sample_frequency: Option, wakeup: bool, flags: u32, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.config = config; @@ -48,7 +51,7 @@ pub(crate) fn perf_event_open( }) } -pub(crate) fn perf_event_open_bpf(cpu: c_int) -> SysResult { +pub(crate) fn perf_event_open_bpf(cpu: c_int) -> SysResult { perf_event_open( PERF_TYPE_SOFTWARE as u32, PERF_COUNT_SW_BPF_OUTPUT as u64, @@ -67,7 +70,7 @@ pub(crate) fn perf_event_open_probe( name: &str, offset: u64, pid: Option, -) -> SysResult { +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; if let Some(ret_bit) = ret_bit { @@ -93,7 +96,7 @@ pub(crate) fn perf_event_open_probe( }) } -pub(crate) fn perf_event_open_trace_point(id: u32, pid: Option) -> SysResult { +pub(crate) fn perf_event_open_trace_point(id: u32, pid: Option) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.size = mem::size_of::() as u32; @@ -112,7 +115,7 @@ pub(crate) fn perf_event_open_trace_point(id: u32, pid: Option) -> SysRes }) } -pub(crate) fn perf_event_ioctl(fd: c_int, request: c_int, arg: c_int) -> SysResult { +pub(crate) fn perf_event_ioctl(fd: c_int, request: c_int, arg: c_int) -> SysResult { let call = Syscall::PerfEventIoctl { fd, request, arg }; #[cfg(not(test))] return syscall(call);