fn buf_region_addr<'a>(
        &self,
        mem: &'a GuestMemoryMmap,
        offset: usize,
        count: usize,
    ) -> Result<(&'a GuestRegionMmap, MemoryRegionAddress)> {
        // Check that the desired slice is inside the buf.
        self.buf_size
            .checked_sub(offset)
            .and_then(|remaining_size| remaining_size.checked_sub(count))
            .ok_or(VsockError::GuestMemoryBounds)?;

        let buf_addr = self.buf_addr.ok_or(VsockError::PktBufMissing)?;
        buf_addr
            .checked_add(offset as u64)
            .and_then(|offset_addr| mem.to_region_addr(offset_addr))
            .and_then(|(region, region_addr)| {
                region.checked_offset(region_addr, count.checked_sub(1)?)?;
                Some((region, region_addr))
            })
            .ok_or(VsockError::GuestMemoryBounds)
    }
/// Gets the GuestRegion and the MemoryRegionAddress where the buf starts.
///
/// As they are currently implemented, `GuestMemory::write_to()` and `GuestMemory::read_from()`
/// have 2 significant disadvantages:
/// 1. Performance: They process chunks of length 4K and they copy data to an auxiliary buffer.
/// 2. Error handling: They don't handle `EWOULDBLOCK` correctly. So for example if it manages to
///    write 1K bytes out of 10K and then receives `EWOULDBLOCK`, it returns a
///    `GuestMemory::IoError`. On the Rx path we read from a stream, but we don't know its
///    length. We just try to write as much as possible. This is guaranteed to lead to an
///    `EWOULDBLOCK` error eventually.
/// This makes them unusable. But the entire buffer should be placed inside a single
/// `GuestRegion`. Also `GuestRegion::write_to()` and `GuestRegion::read_from()` don't have
/// the problems mentioned above. So we will read/write directly to/from the `GuestRegion`.
///
/// TODO: use `GuestMemory::write_to()` and `GuestMemory::read_from()` when they are stable
/// enough:
/// 1. https://github.com/rust-vmm/vm-memory/pull/125 should be merged.
/// 2. The `EWOULDBLOCK` scenario should be fixed.
Gets the GuestRegion and the MemoryRegionAddress where the buf starts.


Gets the GuestRegion and the MemoryRegionAddress where the buf starts .
fn buf_region_addr<'a>(
        &self,
        mem: &'a GuestMemoryMmap,
        offset: usize,
        count: usize,
    ) -> Result<(&'a GuestRegionMmap, MemoryRegionAddress)> {
        // Check that the desired slice is inside the buf.
        self.buf_size
            .checked_sub(offset)
            .and_then(|remaining_size| remaining_size.checked_sub(count))
            .ok_or(VsockError::GuestMemoryBounds)?;
        let buf_addr = self.buf_addr.ok_or(VsockError::PktBufMissing)?;
        buf_addr
            .checked_add(offset as u64)
            .and_then(|offset_addr| mem.to_region_addr(offset_addr))
            .and_then(|(region, region_addr)| {
                region.checked_offset(region_addr, count.checked_sub(1)?)?;
                Some((region, region_addr))
            })
            .ok_or(VsockError::GuestMemoryBounds)
    }
fn buf_region_addr < ' a > ( & self , mem : & ' a GuestMemoryMmap , offset : usize , count : usize , ) -> Result < ( & ' a GuestRegionMmap , MemoryRegionAddress ) > { // Check that the desired slice is inside the buf. self . buf_size . checked_sub ( offset ) . and_then ( | remaining_size | remaining_size . checked_sub ( count ) ) . ok_or ( VsockError :: GuestMemoryBounds ) ? ; let buf_addr = self . buf_addr . ok_or ( VsockError :: PktBufMissing ) ? ; buf_addr . checked_add ( offset as u64 ) . and_then ( | offset_addr | mem . to_region_addr ( offset_addr ) ) . and_then ( | ( region , region_addr ) | { region . checked_offset ( region_addr , count . checked_sub ( 1 ) ? ) ? ; Some ( ( region , region_addr ) ) } ) . ok_or ( VsockError :: GuestMemoryBounds ) }
Gets the GuestRegion and the MemoryRegionAddress where the buf starts.
Gets the GuestRegion and the MemoryRegionAddress where the buf starts .
&self
mem
&'a GuestMemoryMmap
offset
usize
count
usize
&self
mem
&'a GuestMemoryMmap
offset
usize
count
usize