I am trying to run some code from two different native threads at the same time. WAVM supports this case fine, but it seems clang will use the same stack for both threads and thus crash the code horribly.
Is there a way to set a custom stack for one of the threads? I was pointed at --export __stack_pointer to get access to the stack pointer global and overwriting it, but it seems the symbol is not actually exported if you do this.
Any other trick I might use to set a new stack?
The https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/Obtaining.20stack_pointer.3F might be helpful
Well, it's saying this doesn't work, that's all I got from it?
correct, you can export your own utility functions to mingle with mutable global though
I read elsewhere that you can't actually access globals in clang though, do I need to implement them directly in wat instead or something?
setting a new stack in LLVM compiled code at this moment is more like a hack
Well, I'm working on a longer-term project where I am hoping the tooling will catch up with me eventually, but I need the hack to be able to do the work for now.
so if the runtime will do wasm stack switching it can also do shadow stack as well
How do you plan to switch wasm call stack?
Just allocating a bit of memory and pointing the stack pointer for my extra thread there, and keeping the main stack for the main thread.
(I need to do audio processing, which happens in a background thread on the native side, the rest happens in a main thread.)
But the main question is, how do I actually do that in practice. If I had the global, I could use the API on the native side to set it, I guess. But it does not get exported. I could just assume it is global 0, but not sure if the WAVM API would let me do that... Doing it on the WASM side would be slightly easier since then I can actually allocate the memory too, but I don't know how to access the global then?
Finally managed to create a function in a WAT file that I got to link that sets __stack_pointer, and it works. Thanks!
Last updated: Nov 22 2024 at 16:03 UTC