// Helper method that writes a descriptor chain to a `GuestMemoryMmap` object and returns
// the associated `DescriptorChain` object. `descs` represents a slice of `Descriptor` objects
// which are used to populate the chain. This method ensures the next flags and values are
// set properly for the desired chain, but keeps the other characteristics of the input
// descriptors (`addr`, `len`, other flags).
// The queue/descriptor chain related information is written in memory starting with
// address 0. The `addr` fields of the input descriptors should start at a sufficiently
// greater location (i.e. 1MiB, or `0x10_0000`).
Helper method that writes a descriptor chain to a `GuestMemoryMmap` object and returns
the associated `DescriptorChain` object. `descs` represents a slice of `Descriptor` objects
which are used to populate the chain. This method ensures the next flags and values are
set properly for the desired chain, but keeps the other characteristics of the input
descriptors (`addr`, `len`, other flags).
The queue/descriptor chain related information is written in memory starting with
address 0. The `addr` fields of the input descriptors should start at a sufficiently
greater location .
Helper method that writes a descriptor chain to a ` GuestMemoryMmap ` object and returns the associated ` DescriptorChain ` object . ` descs ` represents a slice of ` Descriptor ` objects which are used to populate the chain . This method ensures the next flags and values are set properly for the desired chain but keeps the other characteristics of the input descriptors ( ` addr ` ` len ` other flags ) . The queue / descriptor chain related information is written in memory starting with address 0 . The ` addr ` fields of the input descriptors should start at a sufficiently greater location .
fn build_desc_chain<'a>(
        mem: &'a GuestMemoryMmap,
        descs: &[Descriptor],
    ) -> DescriptorChain<&'a GuestMemoryMmap> {
        // Support a max of 16 descriptors for now.
        let vq = MockSplitQueue::new(mem, 16);
        for (idx, desc) in descs.iter().enumerate() {
            let i = idx as u16;
            let addr = desc.addr().0;
            let len = desc.len();
            let (flags, next) = if idx == descs.len() - 1 {
                // Clear the NEXT flag if it was set. The value of the next field of the
                // Descriptor doesn't matter at this point.
                (desc.flags() & !VIRTQ_DESC_F_NEXT, 0)
            } else {
                // Ensure that the next flag is set and that we are referring the following
                // descriptor. This ignores any value is actually present in `desc.next`.
                (desc.flags() | VIRTQ_DESC_F_NEXT, i + 1)
            };
            let desc = Descriptor::new(addr, len, flags, next);
            vq.desc_table().store(i, desc);
        }
        // Put the descriptor index 0 in the first available ring position.
        mem.write_obj(0u16, vq.avail_addr().unchecked_add(4))
            .unwrap();
        // Set `avail_idx` to 1.
        mem.write_obj(1u16, vq.avail_addr().unchecked_add(2))
            .unwrap();
        vq.create_queue(mem)
            .iter()
            .unwrap()
            .next()
            .expect("failed to build desc chain")
    }
fn build_desc_chain < ' a > ( mem : & ' a GuestMemoryMmap , descs : & [ Descriptor ] , ) -> DescriptorChain < & ' a GuestMemoryMmap > { // Support a max of 16 descriptors for now. let vq = MockSplitQueue :: new ( mem , 16 ) ; for ( idx , desc ) in descs . iter ( ) . enumerate ( ) { let i = idx as u16 ; let addr = desc . addr ( ) . 0 ; let len = desc . len ( ) ; let ( flags , next ) = if idx == descs . len ( ) - 1 { // Clear the NEXT flag if it was set. The value of the next field of the // Descriptor doesn't matter at this point. ( desc . flags ( ) & ! VIRTQ_DESC_F_NEXT , 0 ) } else { // Ensure that the next flag is set and that we are referring the following // descriptor. This ignores any value is actually present in `desc.next`. ( desc . flags ( ) | VIRTQ_DESC_F_NEXT , i + 1 ) } ; let desc = Descriptor :: new ( addr , len , flags , next ) ; vq . desc_table ( ) . store ( i , desc ) ; } // Put the descriptor index 0 in the first available ring position. mem . write_obj ( 0u16 , vq . avail_addr ( ) . unchecked_add ( 4 ) ) . unwrap ( ) ; // Set `avail_idx` to 1. mem . write_obj ( 1u16 , vq . avail_addr ( ) . unchecked_add ( 2 ) ) . unwrap ( ) ; vq . create_queue ( mem ) . iter ( ) . unwrap ( ) . next ( ) . expect ( " " ) }
Helper method that writes a descriptor chain to a `GuestMemoryMmap` object and returns
the associated `DescriptorChain` object.
Helper method that writes a descriptor chain to a ` GuestMemoryMmap ` object and returns the associated ` DescriptorChain ` object .
mem
&'a GuestMemoryMmap
descs
&[Descriptor]