Stream: winch

Topic: Shared memory


view this post on Zulip marin (Jan 10 2025 at 15:03):

I realized that I needed to get shared memory working before I could get the spec tests to pass. Do you have any pointers @Saúl Cabrera ?

While debugging, I found this function: https://github.com/bytecodealliance/wasmtime/blob/main/crates/environ/src/module.rs#L456-L473
But it find it fishy: If there is only a single shared memory in the module, this function returns 0, which seems incorrect, since we get an offset to an unexisting owned memory

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Alex Crichton (Jan 10 2025 at 15:23):

IIRC "owned" here is defined-and-not-shared, so if a shared memory gets an owned index I think that's a bug?

view this post on Zulip marin (Jan 10 2025 at 15:24):

sounds like a bug to me too

view this post on Zulip Saúl Cabrera (Jan 10 2025 at 15:29):

I believe you'd need to handle the shared memory here: https://github.com/bytecodealliance/wasmtime/blob/main/winch/codegen/src/codegen/env.rs#L250

view this post on Zulip marin (Jan 10 2025 at 15:29):

how are owned memories laid out in the vm context? are all owned memoried contiguous? what's at index 0? because even it there's a single owned memory, this function would return 1, but I would assume that the first owned memory would be at offset 0 :thinking:

view this post on Zulip Alex Crichton (Jan 10 2025 at 15:30):

it looks like this in the vmcontext

view this post on Zulip marin (Jan 10 2025 at 15:30):

@Saúl Cabrera yes, that how I got to the linked function
where do shared memories live?

view this post on Zulip marin (Jan 10 2025 at 15:31):

here: https://github.com/bytecodealliance/wasmtime/blob/de1ad347e34f00d3c10959ff14460e90b44f7907/crates/environ/src/vmoffsets.rs#L28? @Alex Crichton

view this post on Zulip Alex Crichton (Jan 10 2025 at 15:32):

yes all memories should live in that memories field, and for owned-and-not-shared memories those are self-pointers to the owned_memories field

view this post on Zulip Alex Crichton (Jan 10 2025 at 15:32):

for shared memories the memories field should point to within the shared memory itself

view this post on Zulip Saúl Cabrera (Jan 10 2025 at 15:54):

@marin The Memory entry in HeapData has a shared field, to help you determine if it's shared or not. Here's how that case is handled in Cranelift: https://github.com/bytecodealliance/wasmtime/blob/de1ad347e34f00d3c10959ff14460e90b44f7907/crates/cranelift/src/func_environ.rs#L2323

view this post on Zulip marin (Jan 10 2025 at 15:55):

Thanks @Saúl Cabrera, that's what I was looking for :thumbs_up:

view this post on Zulip marin (Jan 10 2025 at 16:57):

alright, got it to work, all the tests are passing now. Thanks :salute:


Last updated: Jan 24 2025 at 00:11 UTC