Skip to main content

DescriptorTable

Struct DescriptorTable 

Source
pub struct DescriptorTable {
    pub base_addr: GuestPhysAddr,
    pub size: u16,
}
Expand description

Descriptor table management structure.

This structure provides a high-level interface for managing the VirtIO descriptor table in guest memory. It wraps the guest memory accessor and provides methods to read/write individual descriptors and follow descriptor chains.

Relationship with VirtQueueDesc:

  • VirtQueueDesc defines the memory layout of a single descriptor
  • DescriptorTable uses VirtQueueDesc to access descriptors in guest memory
  • DescriptorTable manages the entire descriptor table and provides operations for descriptor chains, validation, and buffer management

Memory Layout:

base_addr -> +-------------------+
             | VirtQueueDesc[0]  |  (addr + len + flags + next)
             +-------------------+
             | VirtQueueDesc[1]  |  (addr + len + flags + next)
             +-------------------+
             | ...               |
             +-------------------+
             | VirtQueueDesc[n-1]|  (addr + len + flags + next)
             +-------------------+

Descriptor chains are formed by setting the NEXT flag and the next field to link descriptors together, allowing scatter-gather I/O operations.

Fields§

§base_addr: GuestPhysAddr

Base address of the descriptor table

§size: u16

Number of descriptors

Implementations§

Source§

impl DescriptorTable

Source

pub const fn new(base_addr: GuestPhysAddr, size: u16) -> Self

Create a new descriptor table

Source

pub fn desc_addr(&self, index: u16) -> Option<GuestPhysAddr>

Get the address of a specific descriptor

Source

pub fn total_size(&self) -> usize

Calculate the total size of the descriptor table

Source

pub fn is_valid(&self) -> bool

Check if the descriptor table is valid

Source

pub fn read_desc( &self, index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<VirtQueueDesc>

Read a descriptor from the table

Source

pub fn write_desc( &self, index: u16, desc: &VirtQueueDesc, memory: &mut dyn GuestMemory, ) -> VirtioResult<()>

Write a descriptor to the table

Source

pub fn follow_chain( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<Vec<VirtQueueDesc>>

Follow a descriptor chain starting from the given index

Source

pub fn descriptor_chain( &self, head: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<DescriptorChain>

Build a fully validated, device-agnostic DescriptorChain from a head index.

Validation performed (all guest-provided input is untrusted):

  • head and every next index must be < size.
  • VIRTQ_DESC_F_INDIRECT is rejected (indirect descriptors are not negotiated in the first version).
  • base_addr + len must not overflow.
  • The chain may reference at most size descriptors; a longer walk indicates a cycle or a corrupted next field.
Source

pub fn chain_length( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<u32>

Get the total length of a descriptor chain

Source

pub fn validate_chain( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<bool>

Check if a descriptor chain is valid

Source

pub fn get_data_buffers( &self, head_index: u16, device_type: VirtioDeviceID, memory: &mut dyn GuestMemory, ) -> VirtioResult<Vec<(GuestPhysAddr, usize, bool)>>

Get data buffer descriptors (excluding first and last)

Source

pub fn get_status_addr( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<GuestPhysAddr>

Get the status descriptor address (last descriptor)

Trait Implementations§

Source§

impl Clone for DescriptorTable

Source§

fn clone(&self) -> DescriptorTable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DescriptorTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.