pub struct GuestMemoryVirtQueue { /* private fields */ }Expand description
A VirtIO split virtqueue backed by guest physical memory.
The queue addresses (desc, avail, used) are guest physical addresses
set by the guest driver during device initialization. The ram_base
pointer is the host virtual address corresponding to GPA 0.
Implementations§
Source§impl GuestMemoryVirtQueue
impl GuestMemoryVirtQueue
Sourcepub unsafe fn new(
queue_idx: u16,
size: u16,
desc_gpa: u64,
avail_gpa: u64,
used_gpa: u64,
ram_base: *mut u8,
ram_size: usize,
) -> GuestMemoryVirtQueue
pub unsafe fn new( queue_idx: u16, size: u16, desc_gpa: u64, avail_gpa: u64, used_gpa: u64, ram_base: *mut u8, ram_size: usize, ) -> GuestMemoryVirtQueue
Creates a new guest memory virtqueue.
§Safety
ram_base must point to a valid allocation of at least ram_size bytes
that remains valid for the lifetime of this queue.
Sourcepub fn set_event_idx(&mut self, enabled: bool)
pub fn set_event_idx(&mut self, enabled: bool)
Enables event index feature (VIRTIO_F_EVENT_IDX).
Sourcepub fn pop_avail(&mut self) -> Option<DescriptorChain>
pub fn pop_avail(&mut self) -> Option<DescriptorChain>
Pops the next available descriptor chain.
Sourcepub fn push_used_batch(&mut self, completions: &[(u16, u32)])
pub fn push_used_batch(&mut self, completions: &[(u16, u32)])
Pushes multiple used buffers with a single index update.
Sourcepub fn read_buffer(&self, gpa: u64, len: u32) -> Option<Vec<u8>>
pub fn read_buffer(&self, gpa: u64, len: u32) -> Option<Vec<u8>>
Reads bytes from a guest buffer into a host Vec.
Sourcepub fn write_buffer(&self, gpa: u64, data: &[u8]) -> bool
pub fn write_buffer(&self, gpa: u64, data: &[u8]) -> bool
Writes bytes from a host buffer into guest memory.
Sourcepub unsafe fn guest_slice(&self, gpa: u64, len: usize) -> Option<&[u8]>
pub unsafe fn guest_slice(&self, gpa: u64, len: usize) -> Option<&[u8]>
Returns a raw host pointer for zero-copy access to a guest buffer.
§Safety
The caller must ensure no concurrent modifications to the same guest memory region and that the returned pointer is not used after the queue (and its backing RAM) is dropped.
Trait Implementations§
impl Send for GuestMemoryVirtQueue
impl Sync for GuestMemoryVirtQueue
Auto Trait Implementations§
impl Freeze for GuestMemoryVirtQueue
impl RefUnwindSafe for GuestMemoryVirtQueue
impl Unpin for GuestMemoryVirtQueue
impl UnsafeUnpin for GuestMemoryVirtQueue
impl UnwindSafe for GuestMemoryVirtQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more