wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

API for custom native stack registration

Open mkokryashkin opened this issue 1 year ago • 4 comments

Feature

Currently my application runs WASM modules withing custom C fibers. These fibers have their own stacks, different from their thread stack. WAMR, on the other hand, heavilly relies on pthread API for native stack boundary checking. It would be nice to have a handle like

wasm_runtime_register_native_stack_boundary(uint8_t *stack_boundary)

So it is possible to register your own native stack boundary and use WAMR within a fiber.

Implementation

We just need to set exec_env->native_stack_boundary to a custom value.

mkokryashkin avatar Sep 26 '24 08:09 mkokryashkin

Hi, it is interested to support fibers. Currently the exec_env->native_stack_boundary is updated in each time wasm_call_function/aot_call_function, which calls wasm_exec_env_set_thread_info to get native stack boundary from os and update it. Per my understanding, you want to use the registered native stack boundary in wasm_call_function/aot_call_function? Seems it is better to store the registered native stack boundary in a new field of exec_env and use it if it is not NULL in wasm_exec_env_set_thread_info?

wenyongh avatar Oct 15 '24 07:10 wenyongh

Seems it is better to store the registered native stack boundary in a new field of exec_env and use it if it is not NULL in wasm_exec_env_set_thread_info?

Yes, that is a great option and it adds a lot of flexibility.

mkokryashkin avatar Oct 15 '24 10:10 mkokryashkin

I uploaded PR #3862, could you check whether it resolves your issue? You can call wasm_runtime_set_native_stack_boundary to set the native stack boundary to exec_env.

wenyongh avatar Oct 16 '24 04:10 wenyongh

It works nicely, thank you very much!

mkokryashkin avatar Oct 16 '24 09:10 mkokryashkin

Close this issue since https://github.com/bytecodealliance/wasm-micro-runtime/pull/3862 was merged.

wenyongh avatar Oct 23 '24 08:10 wenyongh