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 Typeimpl 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 thedata
of Store, but as thedata
is almost often to be aWasiCtx
, 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.
alexcrichton commented on issue #6712:
When using WASI the
T
inStore<T>
doesn't have to beWasiCtx
, it only needs to containWasiCtx
. 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?
alexcrichton edited a comment on issue #6712:
When using WASI the
T
inStore<T>
doesn't have to beWasiCtx
, it only needs to containWasiCtx
. 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?
abel-von commented on issue #6712:
Thank you for reply , I think it works for me.
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 Typeimpl 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 thedata
of Store, but as thedata
is almost often to be aWasiCtx
, 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: Dec 23 2024 at 13:07 UTC