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: GuestPhysAddrBase address of the descriptor table
size: u16Number of descriptors
Implementations§
Source§impl DescriptorTable
impl DescriptorTable
Sourcepub const fn new(base_addr: GuestPhysAddr, size: u16) -> Self
pub const fn new(base_addr: GuestPhysAddr, size: u16) -> Self
Create a new descriptor table
Sourcepub fn desc_addr(&self, index: u16) -> Option<GuestPhysAddr>
pub fn desc_addr(&self, index: u16) -> Option<GuestPhysAddr>
Get the address of a specific descriptor
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Calculate the total size of the descriptor table
Sourcepub fn read_desc(
&self,
index: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<VirtQueueDesc>
pub fn read_desc( &self, index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<VirtQueueDesc>
Read a descriptor from the table
Sourcepub fn write_desc(
&self,
index: u16,
desc: &VirtQueueDesc,
memory: &mut dyn GuestMemory,
) -> VirtioResult<()>
pub fn write_desc( &self, index: u16, desc: &VirtQueueDesc, memory: &mut dyn GuestMemory, ) -> VirtioResult<()>
Write a descriptor to the table
Sourcepub fn follow_chain(
&self,
head_index: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<Vec<VirtQueueDesc>>
pub fn follow_chain( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<Vec<VirtQueueDesc>>
Follow a descriptor chain starting from the given index
Sourcepub fn descriptor_chain(
&self,
head: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<DescriptorChain>
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):
headand everynextindex must be< size.VIRTQ_DESC_F_INDIRECTis rejected (indirect descriptors are not negotiated in the first version).base_addr + lenmust not overflow.- The chain may reference at most
sizedescriptors; a longer walk indicates a cycle or a corruptednextfield.
Sourcepub fn chain_length(
&self,
head_index: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<u32>
pub fn chain_length( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<u32>
Get the total length of a descriptor chain
Sourcepub fn validate_chain(
&self,
head_index: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<bool>
pub fn validate_chain( &self, head_index: u16, memory: &mut dyn GuestMemory, ) -> VirtioResult<bool>
Check if a descriptor chain is valid
Sourcepub fn get_data_buffers(
&self,
head_index: u16,
device_type: VirtioDeviceID,
memory: &mut dyn GuestMemory,
) -> VirtioResult<Vec<(GuestPhysAddr, usize, bool)>>
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)
Sourcepub fn get_status_addr(
&self,
head_index: u16,
memory: &mut dyn GuestMemory,
) -> VirtioResult<GuestPhysAddr>
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
impl Clone for DescriptorTable
Source§fn clone(&self) -> DescriptorTable
fn clone(&self) -> DescriptorTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more