aya: move mmap from perf_buffer.rs to sys/mod.rs

mmap() is needed for the ring buffer implementation, so move it to a common module
reviewable/pr629/r58
William Findlay 4 years ago committed by Andrew Werner
parent 3bb25bdd10
commit 613927a391

@ -7,7 +7,7 @@ use std::{
};
use bytes::BytesMut;
use libc::{c_int, munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use libc::{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, SysResult},
sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};
@ -282,25 +282,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: 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)]
use crate::sys::TEST_MMAP_RET;
#[cfg(test)]
TEST_MMAP_RET.with(|ret| *ret.borrow())
}
#[derive(Debug)]
#[repr(C)]
struct Sample {

@ -5,11 +5,12 @@ mod perf_event;
#[cfg(test)]
mod fake;
use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open};
use std::{
io, mem,
os::fd::{AsRawFd as _, BorrowedFd},
};
use libc::{c_int, c_long, c_void, pid_t, SYS_bpf, SYS_perf_event_open};
use thiserror::Error;
pub(crate) use bpf::*;
@ -114,3 +115,19 @@ fn syscall(call: Syscall<'_>) -> SysResult<c_long> {
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())
}

Loading…
Cancel
Save