Skip to content

Commit

Permalink
codegen: remove outdated workaround
Browse files Browse the repository at this point in the history
bindgen can handle these macros now.
  • Loading branch information
tamird committed Feb 4, 2025
1 parent 9aa08b4 commit b6b8dd4
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 28 deletions.
5 changes: 0 additions & 5 deletions aya-obj/include/linux_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@
#include <linux/pkt_sched.h>
#include <linux/rtnetlink.h>
#include <sys/socket.h>

/* workaround the fact that bindgen can't parse the IOC macros */
int AYA_PERF_EVENT_IOC_ENABLE = PERF_EVENT_IOC_ENABLE;
int AYA_PERF_EVENT_IOC_DISABLE = PERF_EVENT_IOC_DISABLE;
int AYA_PERF_EVENT_IOC_SET_BPF = PERF_EVENT_IOC_SET_BPF;
6 changes: 0 additions & 6 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
ffi::c_int,
fs, io,
os::fd::{AsFd as _, AsRawFd as _},
path::{Path, PathBuf},
Expand All @@ -12,7 +11,6 @@ use aya_obj::{
btf::{Btf, BtfError, BtfFeatures, BtfRelocationError},
generated::{
bpf_map_type::{self, *},
AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF,
BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS,
},
relocation::EbpfRelocationError,
Expand Down Expand Up @@ -42,10 +40,6 @@ use crate::{

pub(crate) const BPF_OBJ_NAME_LEN: usize = 16;

pub(crate) const PERF_EVENT_IOC_ENABLE: c_int = AYA_PERF_EVENT_IOC_ENABLE;
pub(crate) const PERF_EVENT_IOC_DISABLE: c_int = AYA_PERF_EVENT_IOC_DISABLE;
pub(crate) const PERF_EVENT_IOC_SET_BPF: c_int = AYA_PERF_EVENT_IOC_SET_BPF;

/// Marker trait for types that can safely be converted to and from byte slices.
pub unsafe trait Pod: Copy + 'static {}

Expand Down
6 changes: 2 additions & 4 deletions aya/src/maps/perf/perf_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use std::{
use aya_obj::generated::{
perf_event_header, perf_event_mmap_page,
perf_event_type::{PERF_RECORD_LOST, PERF_RECORD_SAMPLE},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};
use bytes::BytesMut;
use libc::{munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use thiserror::Error;

use crate::{
sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};
use crate::sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult};

/// Perf buffer error.
#[derive(Error, Debug)]
Expand Down
7 changes: 5 additions & 2 deletions aya/src/programs/perf_attach.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Perf attach links.
use std::os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, RawFd};

use aya_obj::generated::bpf_attach_type::BPF_PERF_EVENT;
use aya_obj::generated::{
bpf_attach_type::BPF_PERF_EVENT, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
PERF_EVENT_IOC_SET_BPF,
};

use crate::{
programs::{
Expand All @@ -13,7 +16,7 @@ use crate::{
bpf_link_create, is_bpf_cookie_supported, perf_event_ioctl, BpfLinkCreateArgs, LinkTarget,
SysResult, SyscallError,
},
FEATURES, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF,
FEATURES,
};

#[derive(Debug, Hash, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion aya/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) enum Syscall<'a> {
},
PerfEventIoctl {
fd: BorrowedFd<'a>,
request: c_int,
request: u32,
arg: c_int,
},
}
Expand Down
6 changes: 1 addition & 5 deletions aya/src/sys/perf_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ pub(crate) fn perf_event_open_trace_point(
perf_event_sys(attr, pid, cpu, PERF_FLAG_FD_CLOEXEC)
}

pub(crate) fn perf_event_ioctl(
fd: BorrowedFd<'_>,
request: c_int,
arg: c_int,
) -> SysResult<c_long> {
pub(crate) fn perf_event_ioctl(fd: BorrowedFd<'_>, request: u32, arg: c_int) -> SysResult<c_long> {
let call = Syscall::PerfEventIoctl { fd, request, arg };
#[cfg(not(test))]
return syscall(call);
Expand Down
2 changes: 0 additions & 2 deletions xtask/src/codegen/aya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> {
"PERF_FLAG_.*",
"PERF_EVENT_.*",
"PERF_MAX_.*",
// see linux_wrapper.h, these are to workaround the IOC macros
"AYA_PERF_EVENT_.*",
// NETLINK
"NLMSG_ALIGNTO",
"IFLA_XDP_FD",
Expand Down
4 changes: 1 addition & 3 deletions xtask/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ mod aya;
mod aya_ebpf_bindings;
mod helpers;

use std::{
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};

use anyhow::{Context as _, Result};
use clap::Parser;
Expand Down

0 comments on commit b6b8dd4

Please sign in to comment.