Merge pull request #3349 from bytecodealliance/pch/limiter

add a hook to ResourceLimiter to detect memory grow failure
This commit is contained in:
Pat Hickey
2021-09-15 18:04:31 -07:00
committed by GitHub
6 changed files with 257 additions and 46 deletions

View File

@@ -524,9 +524,10 @@ pub unsafe trait LinearMemory: Send + Sync + 'static {
/// Grows this memory to have the `new_size`, in bytes, specified.
///
/// Returns `None` if memory can't be grown by the specified amount
/// of bytes. Returns `Some` if memory was grown successfully.
fn grow_to(&mut self, new_size: usize) -> Option<()>;
/// Returns `Err` if memory can't be grown by the specified amount
/// of bytes. The error may be downcastable to `std::io::Error`.
/// Returns `Ok` if memory was grown successfully.
fn grow_to(&mut self, new_size: usize) -> Result<()>;
/// Return the allocated memory as a mutable pointer to u8.
fn as_ptr(&self) -> *mut u8;

View File

@@ -36,7 +36,7 @@ impl RuntimeLinearMemory for LinearMemoryProxy {
self.mem.maximum_byte_size()
}
fn grow_to(&mut self, new_size: usize) -> Option<()> {
fn grow_to(&mut self, new_size: usize) -> Result<()> {
self.mem.grow_to(new_size)
}