diff --git a/aya/src/maps/bloom_filter.rs b/aya/src/maps/bloom_filter.rs index d038e35f3..5a1326049 100644 --- a/aya/src/maps/bloom_filter.rs +++ b/aya/src/maps/bloom_filter.rs @@ -79,10 +79,10 @@ impl, V: Pod> BloomFilter { #[cfg(test)] mod tests { - use std::{ffi::c_long, io}; + use std::io; use assert_matches::assert_matches; - use libc::{EFAULT, ENOENT}; + use libc::{c_long, EFAULT, ENOENT}; use super::*; use crate::{ diff --git a/aya/src/maps/hash_map/hash_map.rs b/aya/src/maps/hash_map/hash_map.rs index bfc968456..ac697a638 100644 --- a/aya/src/maps/hash_map/hash_map.rs +++ b/aya/src/maps/hash_map/hash_map.rs @@ -103,10 +103,10 @@ impl, K: Pod, V: Pod> IterableMap for HashMap #[cfg(test)] mod tests { - use std::{ffi::c_long, io}; + use std::io; use assert_matches::assert_matches; - use libc::{EFAULT, ENOENT}; + use libc::{c_long, EFAULT, ENOENT}; use super::{ super::test_utils::{self, new_map}, diff --git a/aya/src/maps/lpm_trie.rs b/aya/src/maps/lpm_trie.rs index 181a2f57a..6c23742d0 100644 --- a/aya/src/maps/lpm_trie.rs +++ b/aya/src/maps/lpm_trie.rs @@ -196,10 +196,10 @@ impl, K: Pod, V: Pod> IterableMap, V> for LpmTrie, - offset: libc::off_t, -) -> *mut c_void { - #[cfg(not(test))] - return libc::mmap(addr, len, prot, flags, fd.as_raw_fd(), offset); - - #[cfg(test)] - use crate::sys::TEST_MMAP_RET; - - #[cfg(test)] - TEST_MMAP_RET.with(|ret| *ret.borrow()) -} - #[derive(Debug)] #[repr(C)] struct Sample { diff --git a/aya/src/sys/fake.rs b/aya/src/sys/fake.rs index df2deece5..fba0c144a 100644 --- a/aya/src/sys/fake.rs +++ b/aya/src/sys/fake.rs @@ -1,6 +1,6 @@ -use std::{cell::RefCell, ffi::c_long, io, ptr}; +use std::{cell::RefCell, io, ptr}; -use libc::c_void; +use libc::{c_long, c_void}; use super::{SysResult, Syscall}; diff --git a/aya/src/sys/mod.rs b/aya/src/sys/mod.rs index 641c25ce1..c19367c79 100644 --- a/aya/src/sys/mod.rs +++ b/aya/src/sys/mod.rs @@ -13,7 +13,7 @@ use std::{ pub(crate) use bpf::*; #[cfg(test)] pub(crate) use fake::*; -use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open}; +use libc::{c_int, c_long, c_void, pid_t, SYS_bpf, SYS_perf_event_open}; #[doc(hidden)] pub use netlink::netlink_set_link_up; pub(crate) use netlink::*; @@ -114,3 +114,19 @@ fn syscall(call: Syscall<'_>) -> SysResult { ret => Err((ret, io::Error::last_os_error())), } } + +#[cfg_attr(test, allow(unused_variables))] +pub(crate) unsafe fn mmap( + addr: *mut c_void, + len: usize, + prot: c_int, + flags: c_int, + fd: BorrowedFd<'_>, + offset: libc::off_t, +) -> *mut c_void { + #[cfg(not(test))] + return libc::mmap(addr, len, prot, flags, fd.as_raw_fd(), offset); + + #[cfg(test)] + TEST_MMAP_RET.with(|ret| *ret.borrow()) +} diff --git a/aya/src/sys/perf_event.rs b/aya/src/sys/perf_event.rs index ebfcc4a5d..803fca5c7 100644 --- a/aya/src/sys/perf_event.rs +++ b/aya/src/sys/perf_event.rs @@ -1,10 +1,10 @@ use std::{ - ffi::{c_long, CString, OsStr}, + ffi::{CString, OsStr}, io, mem, os::fd::{BorrowedFd, FromRawFd as _, OwnedFd}, }; -use libc::{c_int, pid_t}; +use libc::{c_int, c_long, pid_t}; use super::{syscall, SysResult, Syscall}; use crate::generated::{