use crate::bindings;
use libc::pid_t;
use std::os::raw::{c_int, c_ulong};
pub unsafe fn perf_event_open(
attrs: *mut bindings::perf_event_attr,
pid: pid_t,
cpu: c_int,
group_fd: c_int,
flags: c_ulong,
) -> c_int {
libc::syscall(
bindings::__NR_perf_event_open as libc::c_long,
attrs as *const bindings::perf_event_attr,
pid,
cpu,
group_fd,
flags,
) as c_int
}
#[allow(dead_code, non_snake_case)]
pub mod ioctls {
use crate::bindings::{self, perf_event_attr, perf_event_query_bpf};
use std::os::raw::{c_char, c_int, c_uint};
macro_rules! define_ioctls {
( $( $args:tt )* ) => {
$(
define_ioctl!($args);
)*
}
}
macro_rules! define_ioctl {
({ $name:ident, $ioctl:ident, $arg_type:ty }) => {
#[allow(clippy::missing_safety_doc)]
pub unsafe fn $name(fd: c_int, arg: $arg_type) -> c_int {
untyped_ioctl(fd, bindings::$ioctl, arg)
}
};
}
define_ioctls! {
{ ENABLE, ENABLE, c_uint }
{ DISABLE, DISABLE, c_uint }
{ REFRESH, REFRESH, c_int }
{ RESET, RESET, c_uint }
{ PERIOD, PERIOD, u64 }
{ SET_OUTPUT, SET_OUTPUT, c_int }
{ SET_FILTER, SET_FILTER, *mut c_char }
{ ID, ID, *mut u64 }
{ SET_BPF, SET_BPF, u32 }
{ PAUSE_OUTPUT, PAUSE_OUTPUT, u32 }
{ QUERY_BPF, QUERY_BPF, *mut perf_event_query_bpf }
{ MODIFY_ATTRIBUTES, MODIFY_ATTRIBUTES, *mut perf_event_attr }
}
unsafe fn untyped_ioctl<A>(fd: c_int, ioctl: bindings::perf_event_ioctls, arg: A) -> c_int {
libc::ioctl(fd, ioctl as _, arg)
}
}