Skip to content

Conversation

@afonso360
Copy link
Contributor

@afonso360 afonso360 commented Aug 15, 2021

Hey,

This PR is #3164 with an additional Virtual Addressing scheme that was discussed as a better alternative to returning the real addresses.

The virtual addresses are split into 4 regions (stack, heap, tables and global values), and the address itself is composed of an entry field and an offset field. In general the entry field corresponds to the instance of the resource (e.g. table5 is entry 5) and the offset field is a byte offset inside that entry.

There is one exception to this which is the stack, where due to only having one stack, the whole address is an offset field.

The number of bits in entry vs offset fields is variable with respect to the region and the address size (32bits vs 64bits). This is done because with 32 bit addresses we would have to compromise on heap size, or have a small number of global values / tables. With 64 bit addresses we do not have to compromise on this, but we need to support 32 bit addresses.

cc: @abrown @cfallin

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself labels Aug 15, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "cranelift", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@afonso360 afonso360 force-pushed the interperter-stack-vaddr branch 2 times, most recently from a6f7dbd to 908d245 Compare August 15, 2021 19:22
Copy link
Member

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on various details here -- I just zoomed in on the most important bits but will defer to @abrown for the final LGTM. Thanks for putting this together so quickly after we discussed it; I'm looking forward to more flexible interpreter-based fuzzing using this!

@abrown
Copy link
Member

abrown commented Aug 23, 2021

@afonso360 if you rebase this on main I think CI will pass and I'll merge.

We also change the approach for heap loads and stores.

Previously we would use the offset as the address to the heap. However,
this approach does not allow using the load/store instructions to
read/write from both the heap and the stack.

This commit changes the addressing mechanism of the interpreter. We now
return the real addresses from the addressing instructions
(stack_addr/heap_addr), and instead check if the address passed into
the load/store instructions points to an area in the heap or the stack.
Adds a  Virtual Addressing scheme that was discussed as a better
alternative to returning the real addresses.

The virtual addresses are split into 4 regions (stack, heap, tables and
global values), and the address itself is composed of an `entry` field
and an `offset` field. In general the `entry` field corresponds to the
instance of the resource (e.g. table5 is entry 5) and the `offset` field
is a byte offset inside that entry.

There is one exception to this which is the stack, where due to only
having one stack, the whole address is an offset field.

The number of bits in entry vs offset fields is variable with respect to
the `region` and the address size (32bits vs 64bits). This is done
because with 32 bit addresses we would have to compromise on heap size,
or have a small number of global values / tables. With 64 bit addresses
we do not have to compromise on this, but we need to support 32 bit
addresses.
@afonso360 afonso360 force-pushed the interperter-stack-vaddr branch from 9a086eb to 84ed9b2 Compare August 24, 2021 08:04
@abrown abrown merged commit 2776074 into bytecodealliance:main Aug 24, 2021
@afonso360 afonso360 deleted the interperter-stack-vaddr branch September 2, 2021 13:26
uweigand added a commit to uweigand/wasmtime that referenced this pull request Sep 11, 2021
PR bytecodealliance#3187 introduced a
change to the write_to_slice and read_from_slice routines in
data_value.rs that switched byte order on big-endian systems:
the code used to use native byte order, and now hard-codes
little-endian byte order.

Fix by using native byte order again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants