diff --git a/crates/wasmtime/src/limits.rs b/crates/wasmtime/src/limits.rs index 169630a058d4..fc65aa2e90f6 100644 --- a/crates/wasmtime/src/limits.rs +++ b/crates/wasmtime/src/limits.rs @@ -4,8 +4,9 @@ pub(crate) const DEFAULT_MEMORY_LIMIT: usize = 10000; /// Used by hosts to limit resource consumption of instances at runtime. /// -/// A [`Store`](crate::Store) can be created with a resource limiter so that hosts can take into account -/// non-WebAssembly resource usage to determine if a linear memory or table should grow. +/// [`Store::new_with_limits`](crate::Store::new_with_limits) can be used +/// with a resource limiter to take into account non-WebAssembly resource +/// usage to determine if a linear memory or table should be grown. pub trait ResourceLimiter { /// Notifies the resource limiter that an instance's linear memory has been requested to grow. /// diff --git a/crates/wasmtime/src/store.rs b/crates/wasmtime/src/store.rs index c0182a90ea94..fb60ded7d009 100644 --- a/crates/wasmtime/src/store.rs +++ b/crates/wasmtime/src/store.rs @@ -122,20 +122,37 @@ impl Hash for HostInfoKey { } impl Store { - /// Creates a new store to be associated with the given [`Engine`]. + /// Creates a new [`Store`] to be associated with the given [`Engine`]. + /// + /// The created [`Store`] will place no additional limits on the size of linear + /// memories or tables at runtime. Linear memories and tables will be allowed to + /// grow to any upper limit specified in their definitions. + /// + /// The store will limit the number of instances, linear memories, and tables created to 10,000. + /// + /// Use [`Store::new_with_limits`] with a [`StoreLimitsBuilder`](crate::StoreLimitsBuilder) to + /// specify different limits for the store. pub fn new(engine: &Engine) -> Self { Self::new_(engine, None) } - /// Creates a new store to be associated with the given [`Engine`] and using the supplied + /// Creates a new [`Store`] to be associated with the given [`Engine`] and using the supplied /// resource limiter. /// + /// A [`ResourceLimiter`] can be implemented by hosts to control the size of WebAssembly + /// linear memories and tables when a request is made to grow them. + /// + /// [`StoreLimitsBuilder`](crate::StoreLimitsBuilder) can be used to create a + /// [`StoreLimits`](crate::StoreLimits) that implements [`ResourceLimiter`] using + /// static limit values. + /// /// # Example /// /// ```rust /// # use wasmtime::{Engine, Store, StoreLimitsBuilder}; + /// // Place a limit on linear memories so they cannot grow beyond 1 MiB /// let engine = Engine::default(); - /// let store = Store::new_with_limits(&engine, StoreLimitsBuilder::new().instances(10).build()); + /// let store = Store::new_with_limits(&engine, StoreLimitsBuilder::new().memory_pages(16).build()); /// ``` pub fn new_with_limits(engine: &Engine, limiter: impl ResourceLimiter + 'static) -> Self { Self::new_(engine, Some(Rc::new(ResourceLimiterProxy(limiter)))) diff --git a/tests/all/limits.rs b/tests/all/limits.rs index 3d603b647c19..f4c74be61228 100644 --- a/tests/all/limits.rs +++ b/tests/all/limits.rs @@ -215,9 +215,13 @@ fn test_initial_table_limits_exceeded() -> Result<()> { #[test] fn test_pooling_allocator_initial_limits_exceeded() -> Result<()> { let mut config = Config::new(); + config.wasm_multi_memory(true); config.allocation_strategy(InstanceAllocationStrategy::Pooling { strategy: PoolingAllocationStrategy::NextAvailable, - module_limits: ModuleLimits::default(), + module_limits: ModuleLimits { + memories: 2, + ..Default::default() + }, instance_limits: InstanceLimits { count: 1, ..Default::default() @@ -225,7 +229,10 @@ fn test_pooling_allocator_initial_limits_exceeded() -> Result<()> { }); let engine = Engine::new(&config)?; - let module = Module::new(&engine, r#"(module (memory (export "m") 5))"#)?; + let module = Module::new( + &engine, + r#"(module (memory (export "m1") 2) (memory (export "m2") 5))"#, + )?; let store = Store::new_with_limits(&engine, StoreLimitsBuilder::new().memory_pages(3).build());