Stream: git-wasmtime

Topic: wasmtime / issue #6712 ResourceLimiter live within the li...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 08:03):

abel-von opened issue #6712:

As if we want to use WASI, we will make the "data" as WasiCtx, and if we want to limit the resources, we have to call limiter with a function of Type impl FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync + 'static. To satisfy this lifecycle requirement, we have to initialize an object of type that implements ResourceLimiter, and add it into the data of Store, but as the data is almost often to be a WasiCtx, we have no way to store this ResourceLimiter into it. That makes it no way to define a ResourceLimiter for those run wasm with wasi supported.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 12:31):

alexcrichton commented on issue #6712:

When using WASI the T in Store<T> doesn't have to be WasiCtx, it only needs to contain WasiCtx. This means you can do something like:

struct MyData {
    wasi: WasiCtx,
    max_memory: usize,
}

impl ResourceLImiter for MyData {
    // ...
}

and then when you call wasmtime_wasi::add_to_linker the closure would be |data| &mut data.wasi (or something along these lines).

Does that work for your use case?

view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 12:31):

alexcrichton edited a comment on issue #6712:

When using WASI the T in Store<T> doesn't have to be WasiCtx, it only needs to contain WasiCtx. This means you can do something like:

struct MyData {
    wasi: WasiCtx,
    max_memory: usize,
}

impl ResourceLimiter for MyData {
    // ...
}

and then when you call wasmtime_wasi::add_to_linker the closure would be |data| &mut data.wasi (or something along these lines).

Does that work for your use case?

view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2023 at 08:44):

abel-von commented on issue #6712:

Thank you for reply , I think it works for me.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2023 at 08:44):

abel-von closed issue #6712:

As if we want to use WASI, we will make the "data" as WasiCtx, and if we want to limit the resources, we have to call limiter with a function of Type impl FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync + 'static. To satisfy this lifecycle requirement, we have to initialize an object of type that implements ResourceLimiter, and add it into the data of Store, but as the data is almost often to be a WasiCtx, we have no way to store this ResourceLimiter into it. That makes it no way to define a ResourceLimiter for those run wasm with wasi supported.


Last updated: Nov 22 2024 at 16:03 UTC