diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index 8db3ee4d..e22aa765 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -7,7 +7,7 @@ use std::{ }; use bytes::BytesMut; -use libc::{c_int, close, munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE}; +use libc::{close, munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE}; use thiserror::Error; use crate::{ @@ -15,7 +15,7 @@ use crate::{ perf_event_header, perf_event_mmap_page, perf_event_type::{PERF_RECORD_LOST, PERF_RECORD_SAMPLE}, }, - sys::{perf_event_ioctl, perf_event_open_bpf}, + sys::{mmap, perf_event_ioctl, perf_event_open_bpf}, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, }; @@ -277,25 +277,6 @@ impl Drop for PerfBuffer { } } -#[cfg_attr(test, allow(unused_variables))] -unsafe fn mmap( - addr: *mut c_void, - len: usize, - prot: c_int, - flags: c_int, - fd: i32, - offset: libc::off_t, -) -> *mut c_void { - #[cfg(not(test))] - return libc::mmap(addr, len, prot, flags, 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/mod.rs b/aya/src/sys/mod.rs index 129889c5..b825f253 100644 --- a/aya/src/sys/mod.rs +++ b/aya/src/sys/mod.rs @@ -11,7 +11,7 @@ use std::{ffi::CString, mem}; #[cfg(not(test))] use libc::utsname; -use libc::{c_int, c_long, pid_t}; +use libc::{c_int, c_long, c_void, pid_t}; pub(crate) use bpf::*; #[cfg(test)] @@ -108,3 +108,19 @@ pub(crate) fn kernel_version() -> Result<(u32, u32, u32), ()> { Ok((major, minor, patch)) } } + +#[cfg_attr(test, allow(unused_variables))] +pub(crate) unsafe fn mmap( + addr: *mut c_void, + len: usize, + prot: c_int, + flags: c_int, + fd: i32, + offset: libc::off_t, +) -> *mut c_void { + #[cfg(not(test))] + return libc::mmap(addr, len, prot, flags, fd, offset); + + #[cfg(test)] + TEST_MMAP_RET.with(|ret| *ret.borrow()) +}