|
|
|
@ -45,25 +45,29 @@ impl<T> Deref for RingBufEntry<T> {
|
|
|
|
|
type Target = MaybeUninit<T>;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
self.0
|
|
|
|
|
let Self(inner) = self;
|
|
|
|
|
inner
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> DerefMut for RingBufEntry<T> {
|
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
|
self.0
|
|
|
|
|
let Self(inner) = self;
|
|
|
|
|
inner
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> RingBufEntry<T> {
|
|
|
|
|
/// Discard this ring buffer entry. The entry will be skipped by the userspace reader.
|
|
|
|
|
pub fn discard(self, flags: u64) {
|
|
|
|
|
unsafe { bpf_ringbuf_discard(self.0.as_mut_ptr() as *mut _, flags) };
|
|
|
|
|
let Self(inner) = self;
|
|
|
|
|
unsafe { bpf_ringbuf_discard(inner.as_mut_ptr().cast(), flags) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Commit this ring buffer entry. The entry will be made visible to the userspace reader.
|
|
|
|
|
pub fn submit(self, flags: u64) {
|
|
|
|
|
unsafe { bpf_ringbuf_submit(self.0.as_mut_ptr() as *mut _, flags) };
|
|
|
|
|
let Self(inner) = self;
|
|
|
|
|
unsafe { bpf_ringbuf_submit(inner.as_mut_ptr().cast(), flags) };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -125,8 +129,9 @@ impl RingBuf {
|
|
|
|
|
|
|
|
|
|
fn reserve_impl<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>> {
|
|
|
|
|
let ptr = unsafe {
|
|
|
|
|
bpf_ringbuf_reserve(self.def.get() as *mut _, mem::size_of::<T>() as _, flags)
|
|
|
|
|
} as *mut MaybeUninit<T>;
|
|
|
|
|
bpf_ringbuf_reserve(self.def.get().cast(), mem::size_of::<T>() as u64, flags)
|
|
|
|
|
}
|
|
|
|
|
.cast::<MaybeUninit<T>>();
|
|
|
|
|
unsafe { ptr.as_mut() }.map(|ptr| RingBufEntry(ptr))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -149,9 +154,9 @@ impl RingBuf {
|
|
|
|
|
assert_eq!(8 % mem::align_of_val(data), 0);
|
|
|
|
|
let ret = unsafe {
|
|
|
|
|
bpf_ringbuf_output(
|
|
|
|
|
self.def.get() as *mut _,
|
|
|
|
|
data as *const _ as *mut _,
|
|
|
|
|
mem::size_of_val(data) as _,
|
|
|
|
|
self.def.get().cast(),
|
|
|
|
|
core::ptr::from_ref(data).cast_mut().cast(),
|
|
|
|
|
mem::size_of_val(data) as u64,
|
|
|
|
|
flags,
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
@ -162,6 +167,6 @@ impl RingBuf {
|
|
|
|
|
///
|
|
|
|
|
/// Consult `bpf_ringbuf_query` documentation for a list of allowed flags.
|
|
|
|
|
pub fn query(&self, flags: u64) -> u64 {
|
|
|
|
|
unsafe { bpf_ringbuf_query(self.def.get() as *mut _, flags) }
|
|
|
|
|
unsafe { bpf_ringbuf_query(self.def.get().cast(), flags) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|