aya: generate code with xtask

pull/1/head
Alessandro Decina 4 years ago
parent fb0c8f0bc9
commit 59ed237343

@ -1,137 +0,0 @@
#!/usr/bin/env sh
set -e
LIBBPF_DIR=$1
OUTPUT_DIR=$2
if test -z "$LIBBPF_DIR"; then
echo "error: no libbpf dir provided"
exit 1
fi
if test -z "$OUTPUT_DIR"; then
echo "error: no output dir provided"
exit 1
fi
BPF_TYPES="\
bpf_cmd \
bpf_insn \
bpf_attr \
bpf_map_type \
bpf_prog_type \
bpf_attach_type
"
BPF_VARS="\
BPF_PSEUDO_.*
BPF_ALU \
BPF_ALU64 \
BPF_LDX \
BPF_ST \
BPF_STX \
BPF_LD \
BPF_K \
BPF_DW \
BPF_W \
BPF_H \
BPF_B \
SO_ATTACH_BPF \
SO_DETACH_BPF
"
BTF_TYPES="\
btf_header \
btf_ext_header \
btf_ext_info \
btf_ext_info_sec \
bpf_core_relo \
bpf_core_relo_kind \
btf_type \
btf_enum \
btf_array \
btf_member \
btf_param \
btf_var \
btf_var_secinfo
"
BTF_VARS="\
BTF_KIND_.*
BTF_INT_.*
"
PERF_TYPES="\
perf_event_attr \
perf_sw_ids \
perf_event_sample_format \
perf_event_mmap_page \
perf_event_header \
perf_type_id \
perf_event_type
"
PERF_VARS="\
PERF_FLAG_.* \
PERF_EVENT_.*
"
NETLINK_TYPES="\
ifinfomsg
"
NETLINK_VARS="\
NLMSG_ALIGNTO \
IFLA_XDP_FD \
XDP_FLAGS_.*
"
LINUX_TYPES="$BPF_TYPES $BTF_TYPES $PERF_TYPES $NETLINK_TYPES"
LINUX_VARS="$BPF_VARS $BTF_VARS $PERF_VARS $NETLINK_VARS"
bindgen $LIBBPF_DIR/src/libbpf_internal.h \
--no-layout-tests \
--default-enum-style moduleconsts \
$(for ty in $BTF_TYPES; do
echo --whitelist-type "$ty"
done) \
$(for var in $BTF_VARS; do
echo --whitelist-var "$var"
done) \
> $OUTPUT_DIR/btf_internal_bindings.rs
KVER=5.10.0-051000
bindgen aya/include/linux_wrapper.h \
--no-layout-tests \
--default-enum-style moduleconsts \
$(for ty in $LINUX_TYPES; do
echo --whitelist-type "$ty"
done) \
$(for var in $LINUX_VARS; do
echo --whitelist-var "$var"
done) \
-- \
-target x86_64 \
-I $LIBBPF_DIR/include/uapi \
-I $LIBBPF_DIR/include/ \
-I /usr/include/x86_64-linux-gnu \
> $OUTPUT_DIR/linux_bindings_x86_64.rs
# requires libc6-dev-arm64-cross
bindgen aya/include/linux_wrapper.h \
--no-layout-tests \
--default-enum-style moduleconsts \
$(for ty in $LINUX_TYPES; do
echo --whitelist-type "$ty"
done) \
$(for var in $LINUX_VARS; do
echo --whitelist-var "$var"
done) \
-- \
-target arm64 \
-I $LIBBPF_DIR/include/uapi \
-I $LIBBPF_DIR/include/ \
-I /usr/aarch64-linux-gnu/include \
> $OUTPUT_DIR/linux_bindings_aarch64.rs

@ -1,47 +1,10 @@
/* automatically generated by rust-bindgen 0.55.1 */ /* automatically generated by rust-bindgen 0.57.0 */
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
pub fn as_ptr(&self) -> *const T {
self as *const _ as *const T
}
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T {
self as *mut _ as *mut T
}
#[inline]
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
::std::slice::from_raw_parts(self.as_ptr(), len)
}
#[inline]
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
pub type __u8 = ::std::os::raw::c_uchar; pub type __u8 = ::std::os::raw::c_uchar;
pub type __u16 = ::std::os::raw::c_ushort; pub type __u16 = ::std::os::raw::c_ushort;
pub type __u32 = ::std::os::raw::c_uint; pub type __u32 = ::std::os::raw::c_uint;
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct btf_ext_info {
pub info: *mut ::std::os::raw::c_void,
pub rec_size: __u32,
pub len: __u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct btf_ext_header { pub struct btf_ext_header {
pub magic: __u16, pub magic: __u16,
pub version: __u8, pub version: __u8,
@ -54,13 +17,6 @@ pub struct btf_ext_header {
pub core_relo_off: __u32, pub core_relo_off: __u32,
pub core_relo_len: __u32, pub core_relo_len: __u32,
} }
#[repr(C)]
#[derive(Debug)]
pub struct btf_ext_info_sec {
pub sec_name_off: __u32,
pub num_info: __u32,
pub data: __IncompleteArrayField<__u8>,
}
pub mod bpf_core_relo_kind { pub mod bpf_core_relo_kind {
pub type Type = ::std::os::raw::c_uint; pub type Type = ::std::os::raw::c_uint;
pub const BPF_FIELD_BYTE_OFFSET: Type = 0; pub const BPF_FIELD_BYTE_OFFSET: Type = 0;

@ -1,18 +1,17 @@
/* automatically generated by rust-bindgen 0.55.1 */ /* automatically generated by rust-bindgen 0.57.0 */
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage, Align> { pub struct __BindgenBitfieldUnit<Storage> {
storage: Storage, storage: Storage,
align: [Align; 0],
} }
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { impl<Storage> __BindgenBitfieldUnit<Storage> {
#[inline] #[inline]
pub const fn new(storage: Storage) -> Self { pub const fn new(storage: Storage) -> Self {
Self { storage, align: [] } Self { storage }
} }
} }
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> impl<Storage> __BindgenBitfieldUnit<Storage>
where where
Storage: AsRef<[u8]> + AsMut<[u8]>, Storage: AsRef<[u8]> + AsMut<[u8]>,
{ {
@ -141,7 +140,8 @@ pub type __u64 = ::std::os::raw::c_ulonglong;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct bpf_insn { pub struct bpf_insn {
pub code: __u8, pub code: __u8,
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, pub _bitfield_align_1: [u8; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>,
pub off: __s16, pub off: __s16,
pub imm: __s32, pub imm: __s32,
} }
@ -169,9 +169,8 @@ impl bpf_insn {
} }
} }
#[inline] #[inline]
pub fn new_bitfield_1(dst_reg: __u8, src_reg: __u8) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { pub fn new_bitfield_1(dst_reg: __u8, src_reg: __u8) -> __BindgenBitfieldUnit<[u8; 1usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 4u8, { __bindgen_bitfield_unit.set(0usize, 4u8, {
let dst_reg: u8 = unsafe { ::std::mem::transmute(dst_reg) }; let dst_reg: u8 = unsafe { ::std::mem::transmute(dst_reg) };
dst_reg as u64 dst_reg as u64
@ -712,7 +711,8 @@ pub struct perf_event_attr {
pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1, pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1,
pub sample_type: __u64, pub sample_type: __u64,
pub read_format: __u64, pub read_format: __u64,
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u32>, pub _bitfield_align_1: [u32; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
pub __bindgen_anon_2: perf_event_attr__bindgen_ty_2, pub __bindgen_anon_2: perf_event_attr__bindgen_ty_2,
pub bp_type: __u32, pub bp_type: __u32,
pub __bindgen_anon_3: perf_event_attr__bindgen_ty_3, pub __bindgen_anon_3: perf_event_attr__bindgen_ty_3,
@ -1159,9 +1159,8 @@ impl perf_event_attr {
aux_output: __u64, aux_output: __u64,
cgroup: __u64, cgroup: __u64,
__reserved_1: __u64, __reserved_1: __u64,
) -> __BindgenBitfieldUnit<[u8; 8usize], u32> { ) -> __BindgenBitfieldUnit<[u8; 8usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize], u32> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 1u8, { __bindgen_bitfield_unit.set(0usize, 1u8, {
let disabled: u64 = unsafe { ::std::mem::transmute(disabled) }; let disabled: u64 = unsafe { ::std::mem::transmute(disabled) };
disabled as u64 disabled as u64
@ -1337,7 +1336,8 @@ pub union perf_event_mmap_page__bindgen_ty_1 {
#[repr(align(8))] #[repr(align(8))]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 { pub struct perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, pub _bitfield_align_1: [u64; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
} }
impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 { impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
#[inline] #[inline]
@ -1414,9 +1414,8 @@ impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
cap_user_time: __u64, cap_user_time: __u64,
cap_user_time_zero: __u64, cap_user_time_zero: __u64,
cap_____res: __u64, cap_____res: __u64,
) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { ) -> __BindgenBitfieldUnit<[u8; 8usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize], u64> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 1u8, { __bindgen_bitfield_unit.set(0usize, 1u8, {
let cap_bit0: u64 = unsafe { ::std::mem::transmute(cap_bit0) }; let cap_bit0: u64 = unsafe { ::std::mem::transmute(cap_bit0) };
cap_bit0 as u64 cap_bit0 as u64

@ -1,18 +1,17 @@
/* automatically generated by rust-bindgen 0.55.1 */ /* automatically generated by rust-bindgen 0.57.0 */
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage, Align> { pub struct __BindgenBitfieldUnit<Storage> {
storage: Storage, storage: Storage,
align: [Align; 0],
} }
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { impl<Storage> __BindgenBitfieldUnit<Storage> {
#[inline] #[inline]
pub const fn new(storage: Storage) -> Self { pub const fn new(storage: Storage) -> Self {
Self { storage, align: [] } Self { storage }
} }
} }
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> impl<Storage> __BindgenBitfieldUnit<Storage>
where where
Storage: AsRef<[u8]> + AsMut<[u8]>, Storage: AsRef<[u8]> + AsMut<[u8]>,
{ {
@ -141,7 +140,8 @@ pub type __u64 = ::std::os::raw::c_ulonglong;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct bpf_insn { pub struct bpf_insn {
pub code: __u8, pub code: __u8,
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, pub _bitfield_align_1: [u8; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>,
pub off: __s16, pub off: __s16,
pub imm: __s32, pub imm: __s32,
} }
@ -169,9 +169,8 @@ impl bpf_insn {
} }
} }
#[inline] #[inline]
pub fn new_bitfield_1(dst_reg: __u8, src_reg: __u8) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { pub fn new_bitfield_1(dst_reg: __u8, src_reg: __u8) -> __BindgenBitfieldUnit<[u8; 1usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 4u8, { __bindgen_bitfield_unit.set(0usize, 4u8, {
let dst_reg: u8 = unsafe { ::std::mem::transmute(dst_reg) }; let dst_reg: u8 = unsafe { ::std::mem::transmute(dst_reg) };
dst_reg as u64 dst_reg as u64
@ -712,7 +711,8 @@ pub struct perf_event_attr {
pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1, pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1,
pub sample_type: __u64, pub sample_type: __u64,
pub read_format: __u64, pub read_format: __u64,
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u32>, pub _bitfield_align_1: [u32; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
pub __bindgen_anon_2: perf_event_attr__bindgen_ty_2, pub __bindgen_anon_2: perf_event_attr__bindgen_ty_2,
pub bp_type: __u32, pub bp_type: __u32,
pub __bindgen_anon_3: perf_event_attr__bindgen_ty_3, pub __bindgen_anon_3: perf_event_attr__bindgen_ty_3,
@ -1159,9 +1159,8 @@ impl perf_event_attr {
aux_output: __u64, aux_output: __u64,
cgroup: __u64, cgroup: __u64,
__reserved_1: __u64, __reserved_1: __u64,
) -> __BindgenBitfieldUnit<[u8; 8usize], u32> { ) -> __BindgenBitfieldUnit<[u8; 8usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize], u32> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 1u8, { __bindgen_bitfield_unit.set(0usize, 1u8, {
let disabled: u64 = unsafe { ::std::mem::transmute(disabled) }; let disabled: u64 = unsafe { ::std::mem::transmute(disabled) };
disabled as u64 disabled as u64
@ -1337,7 +1336,8 @@ pub union perf_event_mmap_page__bindgen_ty_1 {
#[repr(align(8))] #[repr(align(8))]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 { pub struct perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, pub _bitfield_align_1: [u64; 0],
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
} }
impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 { impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
#[inline] #[inline]
@ -1414,9 +1414,8 @@ impl perf_event_mmap_page__bindgen_ty_1__bindgen_ty_1 {
cap_user_time: __u64, cap_user_time: __u64,
cap_user_time_zero: __u64, cap_user_time_zero: __u64,
cap_____res: __u64, cap_____res: __u64,
) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { ) -> __BindgenBitfieldUnit<[u8; 8usize]> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize], u64> = let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
Default::default();
__bindgen_bitfield_unit.set(0usize, 1u8, { __bindgen_bitfield_unit.set(0usize, 1u8, {
let cap_bit0: u64 = unsafe { ::std::mem::transmute(cap_bit0) }; let cap_bit0: u64 = unsafe { ::std::mem::transmute(cap_bit0) };
cap_bit0 as u64 cap_bit0 as u64

@ -389,6 +389,7 @@ mod tests {
fn fake_ins() -> bpf_insn { fn fake_ins() -> bpf_insn {
bpf_insn { bpf_insn {
code: 0, code: 0,
_bitfield_align_1: [],
_bitfield_1: bpf_insn::new_bitfield_1(0, 0), _bitfield_1: bpf_insn::new_bitfield_1(0, 0),
off: 0, off: 0,
imm: 0, imm: 0,

Loading…
Cancel
Save