rename
This commit is contained in:
@@ -91,17 +91,12 @@ pub unsafe trait Store {
|
|||||||
) -> (&mut VMExternRefActivationsTable, &dyn ModuleInfoLookup);
|
) -> (&mut VMExternRefActivationsTable, &dyn ModuleInfoLookup);
|
||||||
|
|
||||||
/// Callback invoked to allow the store's resource limiter to reject a memory grow operation.
|
/// Callback invoked to allow the store's resource limiter to reject a memory grow operation.
|
||||||
fn limiter_memory_growing(
|
fn memory_growing(&mut self, current: usize, desired: usize, maximum: Option<usize>) -> bool;
|
||||||
&mut self,
|
|
||||||
current: usize,
|
|
||||||
desired: usize,
|
|
||||||
maximum: Option<usize>,
|
|
||||||
) -> bool;
|
|
||||||
/// Callback invoked to notify the store's resource limiter that a memory grow operation has
|
/// Callback invoked to notify the store's resource limiter that a memory grow operation has
|
||||||
/// failed.
|
/// failed.
|
||||||
fn limiter_memory_grow_failed(&mut self, error: &anyhow::Error);
|
fn memory_grow_failed(&mut self, error: &anyhow::Error);
|
||||||
/// Callback invoked to allow the store's resource limiter to reject a table grow operation.
|
/// Callback invoked to allow the store's resource limiter to reject a table grow operation.
|
||||||
fn limiter_table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool;
|
fn table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool;
|
||||||
|
|
||||||
/// Callback invoked whenever fuel runs out by a wasm instance. If an error
|
/// Callback invoked whenever fuel runs out by a wasm instance. If an error
|
||||||
/// is returned that's raised as a trap. Otherwise wasm execution will
|
/// is returned that's raised as a trap. Otherwise wasm execution will
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ impl Memory {
|
|||||||
// calculation overflowed. This means that the `minimum` we're informing
|
// calculation overflowed. This means that the `minimum` we're informing
|
||||||
// the limiter is lossy and may not be 100% accurate, but for now the
|
// the limiter is lossy and may not be 100% accurate, but for now the
|
||||||
// expected uses of limiter means that's ok.
|
// expected uses of limiter means that's ok.
|
||||||
if !store.limiter_memory_growing(0, minimum.unwrap_or(absolute_max), maximum) {
|
if !store.memory_growing(0, minimum.unwrap_or(absolute_max), maximum) {
|
||||||
bail!(
|
bail!(
|
||||||
"memory minimum size of {} pages exceeds memory limits",
|
"memory minimum size of {} pages exceeds memory limits",
|
||||||
plan.memory.minimum
|
plan.memory.minimum
|
||||||
@@ -402,14 +402,14 @@ impl Memory {
|
|||||||
|
|
||||||
let maximum = self.maximum_byte_size();
|
let maximum = self.maximum_byte_size();
|
||||||
// Store limiter gets first chance to reject memory_growing.
|
// Store limiter gets first chance to reject memory_growing.
|
||||||
if !store.limiter_memory_growing(old_byte_size, new_byte_size, maximum) {
|
if !store.memory_growing(old_byte_size, new_byte_size, maximum) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never exceed maximum, even if limiter permitted it.
|
// Never exceed maximum, even if limiter permitted it.
|
||||||
if let Some(max) = maximum {
|
if let Some(max) = maximum {
|
||||||
if new_byte_size > max {
|
if new_byte_size > max {
|
||||||
store.limiter_memory_grow_failed(&format_err!("Memory maximum size exceeded"));
|
store.memory_grow_failed(&format_err!("Memory maximum size exceeded"));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -431,7 +431,7 @@ impl Memory {
|
|||||||
} => {
|
} => {
|
||||||
// Never exceed static memory size
|
// Never exceed static memory size
|
||||||
if new_byte_size > base.len() {
|
if new_byte_size > base.len() {
|
||||||
store.limiter_memory_grow_failed(&format_err!("static memory size exceeded"));
|
store.memory_grow_failed(&format_err!("static memory size exceeded"));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,13 +440,13 @@ impl Memory {
|
|||||||
base.as_mut_ptr().add(old_byte_size),
|
base.as_mut_ptr().add(old_byte_size),
|
||||||
new_byte_size - old_byte_size,
|
new_byte_size - old_byte_size,
|
||||||
);
|
);
|
||||||
r.map_err(|e| store.limiter_memory_grow_failed(&e)).ok()?;
|
r.map_err(|e| store.memory_grow_failed(&e)).ok()?;
|
||||||
|
|
||||||
*size = new_byte_size;
|
*size = new_byte_size;
|
||||||
}
|
}
|
||||||
Memory::Dynamic(mem) => {
|
Memory::Dynamic(mem) => {
|
||||||
let r = mem.grow_to(new_byte_size);
|
let r = mem.grow_to(new_byte_size);
|
||||||
r.map_err(|e| store.limiter_memory_grow_failed(&e)).ok()?;
|
r.map_err(|e| store.memory_grow_failed(&e)).ok()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(old_byte_size)
|
Some(old_byte_size)
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ impl Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn limit_new(plan: &TablePlan, store: &mut dyn Store) -> Result<()> {
|
fn limit_new(plan: &TablePlan, store: &mut dyn Store) -> Result<()> {
|
||||||
if !store.limiter_table_growing(0, plan.table.minimum, plan.table.maximum) {
|
if !store.table_growing(0, plan.table.minimum, plan.table.maximum) {
|
||||||
bail!(
|
bail!(
|
||||||
"table minimum size of {} elements exceeds table limits",
|
"table minimum size of {} elements exceeds table limits",
|
||||||
plan.table.minimum
|
plan.table.minimum
|
||||||
@@ -292,7 +292,7 @@ impl Table {
|
|||||||
let old_size = self.size();
|
let old_size = self.size();
|
||||||
let new_size = old_size.checked_add(delta)?;
|
let new_size = old_size.checked_add(delta)?;
|
||||||
|
|
||||||
if !store.limiter_table_growing(old_size, new_size, self.maximum()) {
|
if !store.table_growing(old_size, new_size, self.maximum()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1526,12 +1526,7 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
|||||||
(&mut inner.externref_activations_table, &inner.modules)
|
(&mut inner.externref_activations_table, &inner.modules)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn limiter_memory_growing(
|
fn memory_growing(&mut self, current: usize, desired: usize, maximum: Option<usize>) -> bool {
|
||||||
&mut self,
|
|
||||||
current: usize,
|
|
||||||
desired: usize,
|
|
||||||
maximum: Option<usize>,
|
|
||||||
) -> bool {
|
|
||||||
// Need to borrow async_cx before the mut borrow of the limiter.
|
// Need to borrow async_cx before the mut borrow of the limiter.
|
||||||
// self.async_cx() panicks when used with a non-async store, so
|
// self.async_cx() panicks when used with a non-async store, so
|
||||||
// wrap this in an option.
|
// wrap this in an option.
|
||||||
@@ -1560,7 +1555,7 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn limiter_memory_grow_failed(&mut self, error: &anyhow::Error) {
|
fn memory_grow_failed(&mut self, error: &anyhow::Error) {
|
||||||
match self.limiter {
|
match self.limiter {
|
||||||
Some(ResourceLimiterInner::Sync(ref mut limiter)) => {
|
Some(ResourceLimiterInner::Sync(ref mut limiter)) => {
|
||||||
limiter(&mut self.data).memory_grow_failed(error)
|
limiter(&mut self.data).memory_grow_failed(error)
|
||||||
@@ -1573,7 +1568,7 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn limiter_table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool {
|
fn table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool {
|
||||||
// Need to borrow async_cx before the mut borrow of the limiter.
|
// Need to borrow async_cx before the mut borrow of the limiter.
|
||||||
// self.async_cx() panicks when used with a non-async store, so
|
// self.async_cx() panicks when used with a non-async store, so
|
||||||
// wrap this in an option.
|
// wrap this in an option.
|
||||||
|
|||||||
Reference in New Issue
Block a user