pub struct EbpfBufferPtr<'a> { /* private fields */ }Expand description
Wraps a pointer to buffer used in eBPF runtime, such as an eBPF maps
entry. The referenced data may be access from multiple threads in parallel,
which makes it unsafe to access it using standard Rust types.
EbpfBufferPtr allows to access these buffers safely. It may be used to
reference either a whole VMO allocated for and eBPF map or individual
elements of that VMO (see slice()). The address and the size of the
buffer are always 8-byte aligned.
Implementations§
Source§impl<'a> EbpfBufferPtr<'a>
impl<'a> EbpfBufferPtr<'a>
pub const ALIGNMENT: usize
Sourcepub unsafe fn new(ptr: *mut u8, size: usize) -> Self
pub unsafe fn new(ptr: *mut u8, size: usize) -> Self
Creates a new EbpfBufferPtr from the specified pointer.
§Safety
Caller must ensure that the buffer referenced by ptr is valid for
lifetime 'a.
Sourcepub fn get_ptr<T>(&self, offset: usize) -> Option<EbpfPtr<'a, T>>
pub fn get_ptr<T>(&self, offset: usize) -> Option<EbpfPtr<'a, T>>
Returns a pointer to a value of type T at the specified offset.
Sourcepub fn slice(&self, range: impl RangeBounds<usize>) -> Option<Self>
pub fn slice(&self, range: impl RangeBounds<usize>) -> Option<Self>
Returns pointer to the specified range in the buffer.
Sourcepub fn load_to_slice(&self, dst: &mut [MaybeUninit<u8>])
pub fn load_to_slice(&self, dst: &mut [MaybeUninit<u8>])
Loads contents of the buffer into the specified slice, dst must be
of the same size as self.
Sourcepub fn load<const N: usize>(&self) -> SmallVec<[u8; N]>
pub fn load<const N: usize>(&self) -> SmallVec<[u8; N]>
Loads all buffer contents into a SmallVec.
Sourcepub fn store(&self, data: &[u8])
pub fn store(&self, data: &[u8])
Stores data in the buffer. data must not be larger than the buffer.
Sourcepub fn copy(&self, src: &EbpfBufferPtr<'_>)
pub fn copy(&self, src: &EbpfBufferPtr<'_>)
Copies the data from another EbpfBufferPtr. src may be smaller than
self. In this case it’s copied to the beginning of self.
Trait Implementations§
Source§impl<'a> Clone for EbpfBufferPtr<'a>
impl<'a> Clone for EbpfBufferPtr<'a>
Source§fn clone(&self) -> EbpfBufferPtr<'a>
fn clone(&self) -> EbpfBufferPtr<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more