bkolobara opened issue #3040:
Is it possible to add a memory limit to a
Store
, similar to thefuel
limit?I'm building a platform for running untrusted Wasm code and I need to limit the memory usage of a particular Store (heap & tables). It could work similar to the
fuel
property, if a memory limit is reached the call to a Wasm function would trap.Currently I'm working around it by forcing users to import a memory and table, but that's not ideal because you can't use multi-memory/table modules and there is no way to enforce
table + heap < max_memory
, onlytable < max_table && heap < max_heap
peterhuene commented on issue #3040:
Hi @bkolobara.
While it doesn't inherently trap, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.
If the resource limiter prevents the requested operation, the
memory.grow
andtable.grow
instructions will behave as if limits have been reached, at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.Would that suffice for your use-case or would additional functionality be needed?
peterhuene edited a comment on issue #3040:
Hi @bkolobara.
While it doesn't inherently trap, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.
If the resource limiter prevents the requested operation, the
memory.grow
andtable.grow
instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.Would that suffice for your use-case or would additional functionality be needed?
peterhuene edited a comment on issue #3040:
Hi @bkolobara.
While it doesn't inherently trap on reached limits, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.
If the resource limiter prevents the requested operation, the
memory.grow
andtable.grow
instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.Would that suffice for your use-case or would additional functionality be needed?
peterhuene edited a comment on issue #3040:
Hi @bkolobara.
While it doesn't inherently trap on reached limits, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.
If the resource limiter prevents the requested operation, the
memory.grow
andtable.grow
instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in out-of-memory conditions.Would that suffice for your use-case or would additional functionality be needed?
bkolobara commented on issue #3040:
This is exactly what I need. I keep looking at the docs every day, but somehow missed this limiter :)
Thanks @peterhuene!
bkolobara closed issue #3040:
Is it possible to add a memory limit to a
Store
, similar to thefuel
limit?I'm building a platform for running untrusted Wasm code and I need to limit the memory usage of a particular Store (heap & tables). It could work similar to the
fuel
property, if a memory limit is reached the call to a Wasm function would trap.Currently I'm working around it by forcing users to import a memory and table, but that's not ideal because you can't use multi-memory/table modules and there is no way to enforce
table + heap < max_memory
, onlytable < max_table && heap < max_heap
Last updated: Dec 23 2024 at 13:07 UTC