Stream: git-wasmtime

Topic: wasmtime / issue #5403 How to use StoreLimits with WasiCtx?


view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2022 at 13:54):

TheWaWaR opened issue #5403:

wasmtime version: 3.0.1

Currently, we can use wasmtime_wasi::WasiCtx as follow:

let mut linker: Linker<WasiCtx> = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;
let wasi = WasiCtxBuilder::new().build();
let mut store = Store::new(engine, wasi);

The problem here is the WasiCtx can only be used as concrete store state and can't compose with other fields.

From the example we can use like this:

store.limiter(move |state| &mut state.limits);

But now wasit have no limits field, so how can we StoreLimits to limit the resource usage?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2022 at 14:22):

bjorn3 commented on issue #5403:

I believe you can do

struct State {
    limits: MyResourceLimiter,
    wasi: WasiCtx,
}

let mut linker: Linker<WasiCtx> = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |state| &mut state.wasi)?;
let wasi = WasiCtxBuilder::new().build();
let limits = todo!();
let mut store = Store::new(engine, State { limits, wasi });
store.limiter(move |state| &mut state.limits);

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2022 at 14:29):

TheWaWaR commented on issue #5403:

Oh, there it is.

Thanks very much!

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2022 at 14:29):

TheWaWaR closed issue #5403:

wasmtime version: 3.0.1

Currently, we can use wasmtime_wasi::WasiCtx as follow:

let mut linker: Linker<WasiCtx> = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;
let wasi = WasiCtxBuilder::new().build();
let mut store = Store::new(engine, wasi);

The problem here is the WasiCtx can only be used as concrete store state and can't compose with other fields.

From the example we can use like this:

store.limiter(move |state| &mut state.limits);

But now wasit have no limits field, so how can we StoreLimits to limit the resource usage?


Last updated: Nov 22 2024 at 17:03 UTC