Expand description
Memory tracking and enforcement for the WASM sandbox.
MemoryTracker implements Wasmtime’s ResourceLimiter trait so
the host can deny linear-memory growth that would exceed the
configured cap, and observe the per-store peak. Wire it into a
Store<T> by holding the tracker inside the store’s data type and
installing the limiter:
ⓘ
struct StoreData {
wasi: WasiCtx,
tracker: MemoryTracker,
}
let mut store = Store::new(&engine, StoreData {
wasi: wasi_ctx,
tracker: MemoryTracker::with_byte_limit(10 * 1024 * 1024),
});
store.limiter(|d| &mut d.tracker as &mut dyn wasmtime::ResourceLimiter);Modern Wasmtime (≥27) removed the standalone Store::set_limits
API in favor of the closure-based Store::limiter, which is why
the limiter must live inside the store’s data type.
Structs§
- Memory
Stats - Snapshot of a tracker’s state. Cheap to clone for emitting on the invocation metrics bus or returning from a status endpoint.
- Memory
Tracker - Memory tracker for a single Wasmtime
Store.