Stream: wasmtime

Topic: stack walking/scanning


view this post on Zulip bndbsh (Aug 24 2020 at 18:29):

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

view this post on Zulip fitzgen (he/him) (Aug 24 2020 at 18:54):

what are you trying to accomplish?

every call is a safepoint, fwiw

view this post on Zulip bndbsh (Aug 24 2020 at 20:11):

trying to see if the calling wasm code has any references on the stack/in locals to add to gc roots

view this post on Zulip fitzgen (he/him) (Aug 24 2020 at 21:32):

@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?

view this post on Zulip bndbsh (Aug 24 2020 at 21:38):

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

view this post on Zulip fitzgen (he/him) (Aug 25 2020 at 15:58):

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.

view this post on Zulip bndbsh (Aug 26 2020 at 17:31):

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: Dec 23 2024 at 13:07 UTC