summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-01-11 16:25:37 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-13 03:23:13 -0800
commit4adfdc03227a076b485d8b37fc8f227c08897696 (patch)
tree56291e9f77020b423e511bd6f36da00c4bb6f4b3 /devices
parentf3d39e2f1b8c21337f1a971a73e57013a31ff054 (diff)
downloadcrosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar.gz
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar.bz2
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar.lz
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar.xz
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.tar.zst
crosvm-4adfdc03227a076b485d8b37fc8f227c08897696.zip
memory: Add methods to return error on short writes and reads
Add GuestMemory::write_all_at_addr, GuestMemory::read_exact_at_addr
which return error if the entire write or read cannot be completed.

Also rename write_slice_at_addr to write_at_addr, read_slice_at_addr to
read_at_addr to make the entire set of four methods consistent in naming
with the methods of std::io::Write and std::io::Read.

Context:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1387624/16/devices/src/virtio/tpm.rs#75

TEST=cargo test

Change-Id: Ia0775b75281ccf8030c84b41f9018a511204b8c9
Reviewed-on: https://chromium-review.googlesource.com/1407156
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/src/usb/xhci/event_ring.rs2
-rw-r--r--devices/src/virtio/net.rs4
-rw-r--r--devices/src/virtio/p9.rs4
3 files changed, 5 insertions, 5 deletions
diff --git a/devices/src/usb/xhci/event_ring.rs b/devices/src/usb/xhci/event_ring.rs
index f7f2645..b508e5a 100644
--- a/devices/src/usb/xhci/event_ring.rs
+++ b/devices/src/usb/xhci/event_ring.rs
@@ -80,7 +80,7 @@ impl EventRing {
                 .checked_add(CYCLE_STATE_OFFSET as u64)
                 .expect("unexpected address in event ring");
             self.mem
-                .write_slice_at_addr(cycle_bit_dword, address)
+                .write_at_addr(cycle_bit_dword, address)
                 .expect("Fail to write Guest Memory");
         }
 
diff --git a/devices/src/virtio/net.rs b/devices/src/virtio/net.rs
index dd8afd9..84249ab 100644
--- a/devices/src/virtio/net.rs
+++ b/devices/src/virtio/net.rs
@@ -103,7 +103,7 @@ where
                     }
                     let limit = cmp::min(write_count + desc.len as usize, self.rx_count);
                     let source_slice = &self.rx_buf[write_count..limit];
-                    let write_result = self.mem.write_slice_at_addr(source_slice, desc.addr);
+                    let write_result = self.mem.write_at_addr(source_slice, desc.addr);
 
                     match write_result {
                         Ok(sz) => {
@@ -182,7 +182,7 @@ where
                 let limit = cmp::min(read_count + desc.len as usize, frame.len());
                 let read_result = self
                     .mem
-                    .read_slice_at_addr(&mut frame[read_count..limit as usize], desc.addr);
+                    .read_at_addr(&mut frame[read_count..limit as usize], desc.addr);
                 match read_result {
                     Ok(sz) => {
                         read_count += sz;
diff --git a/devices/src/virtio/p9.rs b/devices/src/virtio/p9.rs
index e9bdbb7..50ceedb 100644
--- a/devices/src/virtio/p9.rs
+++ b/devices/src/virtio/p9.rs
@@ -135,7 +135,7 @@ where
             let len = min(buf.len(), (current.len - self.offset) as usize);
             let count = self
                 .mem
-                .read_slice_at_addr(&mut buf[..len], addr)
+                .read_at_addr(&mut buf[..len], addr)
                 .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
 
             // |count| has to fit into a u32 because it must be less than or equal to
@@ -191,7 +191,7 @@ where
             let len = min(buf.len(), (current.len - self.offset) as usize);
             let count = self
                 .mem
-                .write_slice_at_addr(&buf[..len], addr)
+                .write_at_addr(&buf[..len], addr)
                 .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
 
             // |count| has to fit into a u32 because it must be less than or equal to