pub struct ResourceLimits {
pub max_memory_size: Option<usize>,
pub max_table_elements: Option<usize>,
}Expand description
Configure limits on the resources a single waPC WebAssembly instance is
allowed to consume, leveraging wasmtime’s
ResourceLimiter
facility (via wasmtime::StoreLimits).
This can be used to prevent a malicious, or misbehaving, WebAssembly module from exhausting the host’s memory, for example by growing its linear memory in an unbounded loop.
When a limit is exceeded, the corresponding memory.grow/table.grow
wasm instruction fails and returns -1 to the guest, following the
WebAssembly specification. Most language toolchains (Rust, TinyGo,
AssemblyScript, …) treat a failed growth as a fatal allocation failure
and abort the guest, which is reported back to the host as a trap. The
memory/table cap itself is always enforced by the host regardless of how
the guest reacts to the failed growth.
Fields§
§max_memory_size: Option<usize>Maximum size, in bytes, that each of the module’s linear memories is allowed to grow to. This limit is applied to each linear memory individually.
None (the default) means no limit is enforced.
max_table_elements: Option<usize>Maximum number of elements each of the module’s tables is allowed to grow to. This limit is applied to each table individually.
WebAssembly tables are used to hold indirect function references (e.g.
Rust trait objects, Go interfaces, C function pointers) and each
element costs roughly the size of a pointer of host memory. Most
modules never grow their tables at runtime, so this is a secondary,
defense-in-depth limit compared to ResourceLimits::max_memory_size.
A generous value such as 100_000 (~0.8 MB on a 64-bit host) is
unlikely to affect legitimate modules.
None (the default) means no limit is enforced.
Trait Implementations§
Source§impl Clone for ResourceLimits
impl Clone for ResourceLimits
Source§fn clone(&self) -> ResourceLimits
fn clone(&self) -> ResourceLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ResourceLimits
Source§impl Debug for ResourceLimits
impl Debug for ResourceLimits
Source§impl Default for ResourceLimits
impl Default for ResourceLimits
Source§fn default() -> ResourceLimits
fn default() -> ResourceLimits
Auto Trait Implementations§
impl Freeze for ResourceLimits
impl RefUnwindSafe for ResourceLimits
impl Send for ResourceLimits
impl Sync for ResourceLimits
impl Unpin for ResourceLimits
impl UnsafeUnpin for ResourceLimits
impl UnwindSafe for ResourceLimits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more