-
Notifications
You must be signed in to change notification settings - Fork 1.6k
cranelift: Add stack support to the interpreter with virtual addresses #3187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cranelift: Add stack support to the interpreter with virtual addresses #3187
Conversation
Subscribe to Label Actioncc @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:
To subscribe or unsubscribe from this label, edit the |
a6f7dbd to
908d245
Compare
abrown
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
cfallin
left a comment
There was a problem hiding this 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!
acd3634 to
9a086eb
Compare
|
@afonso360 if you rebase this on |
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.
9a086eb to
84ed9b2
Compare
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.
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
entryfield and anoffsetfield. In general theentryfield corresponds to the instance of the resource (e.g. table5 is entry 5) and theoffsetfield 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