wasmtime: clarify Memory::{read,write} behavior with out-of-bounds ranges

This documents that we will never do partial reads/writes, and expands our
existing tests to assert this.
This commit is contained in:
Nick Fitzgerald
2021-01-26 10:11:29 -08:00
parent 0cdc80fbf8
commit 4f3bc1d5d4
2 changed files with 12 additions and 4 deletions

View File

@@ -304,8 +304,8 @@ impl Memory {
///
/// The entire buffer will be filled.
///
/// If offset + buffer length exceed the current memory capacity,
/// a [`MemoryAccessError`] is returned.
/// If offset + buffer length exceed the current memory capacity, then the
/// buffer is left untouched and a [`MemoryAccessError`] is returned.
pub fn read(&self, offset: usize, buffer: &mut [u8]) -> Result<(), MemoryAccessError> {
unsafe {
let slice = self
@@ -320,8 +320,9 @@ impl Memory {
/// Safely writes contents of a buffer to this memory at the given offset.
///
/// If the offset + buffer length exceed current memory capacity, a
/// [`MemoryAccessError`] is returned.
/// If the offset + buffer length exceed current memory capacity, then none
/// of the buffer is written to memory and a [`MemoryAccessError`] is
/// returned.
pub fn write(&self, offset: usize, buffer: &[u8]) -> Result<(), MemoryAccessError> {
unsafe {
self.data_unchecked_mut()