Use own Pod trait

pull/1/head
Alessandro Decina 4 years ago
parent 561b0015bb
commit b0b83cbd8c

@ -10,8 +10,6 @@ use crate::{
syscalls::bpf_map_update_elem_ptr, syscalls::bpf_map_update_elem_ptr,
}; };
pub use object::Pod;
unsafe impl object::Pod for bpf_insn {} unsafe impl object::Pod for bpf_insn {}
pub(crate) const BPF_OBJ_NAME_LEN: usize = 16; pub(crate) const BPF_OBJ_NAME_LEN: usize = 16;
@ -21,6 +19,18 @@ pub(crate) const PERF_EVENT_IOC_ENABLE: libc::c_ulong = 9216;
pub(crate) const PERF_EVENT_IOC_DISABLE: libc::c_ulong = 9217; pub(crate) const PERF_EVENT_IOC_DISABLE: libc::c_ulong = 9217;
pub(crate) const PERF_EVENT_IOC_SET_BPF: libc::c_ulong = 1074013192; pub(crate) const PERF_EVENT_IOC_SET_BPF: libc::c_ulong = 1074013192;
pub unsafe trait Pod: Copy + 'static {}
macro_rules! unsafe_impl_pod {
($($struct_name:ident),+ $(,)?) => {
$(
unsafe impl Pod for $struct_name { }
)+
}
}
unsafe_impl_pod!(i8, u8, i16, u16, i32, u32, i64, u64);
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub(crate) struct bpf_map_def { pub(crate) struct bpf_map_def {

@ -13,7 +13,7 @@ use crate::{
generated::{bpf_attach_type, bpf_attr, bpf_cmd, bpf_insn}, generated::{bpf_attach_type, bpf_attr, bpf_cmd, bpf_insn},
programs::VerifierLog, programs::VerifierLog,
syscalls::SysResult, syscalls::SysResult,
RawFd, BPF_OBJ_NAME_LEN, Pod, RawFd, BPF_OBJ_NAME_LEN,
}; };
use super::{syscall, Syscall}; use super::{syscall, Syscall};
@ -62,7 +62,7 @@ pub(crate) fn bpf_load_program(
sys_bpf(bpf_cmd::BPF_PROG_LOAD, &attr) sys_bpf(bpf_cmd::BPF_PROG_LOAD, &attr)
} }
fn lookup<K, V: crate::Pod>( fn lookup<K, V: Pod>(
fd: RawFd, fd: RawFd,
key: &K, key: &K,
flags: u64, flags: u64,
@ -84,7 +84,7 @@ fn lookup<K, V: crate::Pod>(
} }
} }
pub(crate) fn bpf_map_lookup_elem<K, V: crate::Pod>( pub(crate) fn bpf_map_lookup_elem<K, V: Pod>(
fd: RawFd, fd: RawFd,
key: &K, key: &K,
flags: u64, flags: u64,
@ -92,7 +92,7 @@ pub(crate) fn bpf_map_lookup_elem<K, V: crate::Pod>(
lookup(fd, key, flags, bpf_cmd::BPF_MAP_LOOKUP_ELEM) lookup(fd, key, flags, bpf_cmd::BPF_MAP_LOOKUP_ELEM)
} }
pub(crate) fn bpf_map_lookup_and_delete_elem<K, V: crate::Pod>( pub(crate) fn bpf_map_lookup_and_delete_elem<K, V: Pod>(
fd: RawFd, fd: RawFd,
key: &K, key: &K,
) -> Result<Option<V>, (c_long, io::Error)> { ) -> Result<Option<V>, (c_long, io::Error)> {

Loading…
Cancel
Save