is there any reasonable way to check the wasm stack (eg for gc purposes) from the host? it looks like internally wasmtime uses cranelift's StackMap, I think to handle externref gc. but this information is not exposed in the api
one approach I'm thinking of would be to scan the whole native stack, though that seems like overkill. and not sure if there's any guarantee around there being a gc safepoint
what are you trying to accomplish?
every call is a safepoint, fwiw
trying to see if the calling wasm code has any references on the stack/in locals to add to gc roots
@bndbsh roots for an external-to-Wasmtime GC? i.e. integrating Wasmtime into a JVM and finding JVM objects that have been passed into Wasm and are on the stack?
in this case the memory to be gc'd is wasm linear memory, and the references are i32 offsets into it. but since wasm is not allowed inspect its own stack, i thought it might help to have an external function do the scan via wasmtime APIs
Cranelift will only generate stack maps for values whose type is a reference type, not i32s, so I don't think this approach will work out very well.
Instead, I'd suggest maintaining your own shadow stack of gc pointers in the linear memory that you can walk and scan whenever you want.
yeah, that seems to be the most reasonable approach and the one taken by other projects I've looked at. thanks for the pointers
Last updated: Nov 22 2024 at 16:03 UTC