From 5cdd1baf291f7d98128257a6a73cf8df2c144908 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 11 Oct 2023 10:57:23 -0400 Subject: [PATCH] aya: import types from std::ffi rather than libc --- aya/src/maps/mod.rs | 4 ++-- aya/src/maps/perf/perf_buffer.rs | 4 ++-- aya/src/sys/bpf.rs | 4 ++-- aya/src/sys/fake.rs | 8 +++++--- aya/src/sys/mod.rs | 3 ++- aya/src/sys/perf_event.rs | 4 ++-- xtask/public-api/aya.txt | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 771486c2..c643ccd6 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -49,7 +49,7 @@ //! implement the [Pod] trait. use std::{ borrow::BorrowMut, - ffi::CString, + ffi::{c_long, CString}, fmt, io, marker::PhantomData, mem, @@ -122,7 +122,7 @@ pub enum MapError { /// Map name name: String, /// Error code - code: libc::c_long, + code: c_long, #[source] /// Original io::Error io_error: io::Error, diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index 17742320..c3248ab9 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -1,5 +1,5 @@ use std::{ - ffi::c_void, + ffi::{c_int, c_void}, io, mem, os::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}, ptr, slice, @@ -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::{ diff --git a/aya/src/sys/bpf.rs b/aya/src/sys/bpf.rs index fdcddd07..dd42120a 100644 --- a/aya/src/sys/bpf.rs +++ b/aya/src/sys/bpf.rs @@ -1,6 +1,6 @@ use std::{ cmp, - ffi::{CStr, CString}, + ffi::{c_char, c_long, CStr, CString}, io, iter, mem::{self, MaybeUninit}, os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd, RawFd}, @@ -8,7 +8,7 @@ use std::{ }; use assert_matches::assert_matches; -use libc::{c_char, c_long, ENOENT, ENOSPC}; +use libc::{ENOENT, ENOSPC}; use obj::{ btf::{BtfEnum64, Enum64}, maps::{bpf_map_def, LegacyMap}, diff --git a/aya/src/sys/fake.rs b/aya/src/sys/fake.rs index df2deece..cfd06e4d 100644 --- a/aya/src/sys/fake.rs +++ b/aya/src/sys/fake.rs @@ -1,6 +1,8 @@ -use std::{cell::RefCell, ffi::c_long, io, ptr}; - -use libc::c_void; +use std::{ + cell::RefCell, + ffi::{c_long, c_void}, + io, ptr, +}; use super::{SysResult, Syscall}; diff --git a/aya/src/sys/mod.rs b/aya/src/sys/mod.rs index 641c25ce..b7aac263 100644 --- a/aya/src/sys/mod.rs +++ b/aya/src/sys/mod.rs @@ -6,6 +6,7 @@ mod perf_event; mod fake; use std::{ + ffi::{c_int, c_long}, io, mem, os::fd::{AsRawFd as _, BorrowedFd}, }; @@ -13,7 +14,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::{pid_t, SYS_bpf, SYS_perf_event_open}; #[doc(hidden)] pub use netlink::netlink_set_link_up; pub(crate) use netlink::*; diff --git a/aya/src/sys/perf_event.rs b/aya/src/sys/perf_event.rs index ebfcc4a5..b06f4fba 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::{c_int, c_long, CString, OsStr}, io, mem, os::fd::{BorrowedFd, FromRawFd as _, OwnedFd}, }; -use libc::{c_int, pid_t}; +use libc::pid_t; use super::{syscall, SysResult, Syscall}; use crate::generated::{ diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 81fa16ec..fb3f5b58 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -1219,7 +1219,7 @@ impl core::convert::From for aya::maps::Map pub fn aya::maps::Map::from(t: T) -> T pub enum aya::maps::MapError pub aya::maps::MapError::CreateError -pub aya::maps::MapError::CreateError::code: libc::unix::linux_like::linux::gnu::b64::x86_64::not_x32::c_long +pub aya::maps::MapError::CreateError::code: core::ffi::c_long pub aya::maps::MapError::CreateError::io_error: std::io::error::Error pub aya::maps::MapError::CreateError::name: alloc::string::String pub aya::maps::MapError::ElementNotFound