* Cranelift: Make `heap_addr` return calculated `base + index + offset`
Rather than return just the `base + index`.
(Note: I've chosen to use the nomenclature "index" for the dynamic operand and
"offset" for the static immediate.)
This move the addition of the `offset` into `heap_addr`, instead of leaving it
for the subsequent memory operation, so that we can Spectre-guard the full
address, and not allow speculative execution to read the first 4GiB of memory.
Before this commit, we were effectively doing
load(spectre_guard(base + index) + offset)
Now we are effectively doing
load(spectre_guard(base + index + offset))
Finally, this also corrects `heap_addr`'s documented semantics to say that it
returns an address that will trap on access if `index + offset + access_size` is
out of bounds for the given heap, rather than saying that the `heap_addr` itself
will trap. This matches the implemented behavior for static memories, and after
https://github.com/bytecodealliance/wasmtime/pull/5190 lands (which is blocked
on this commit) will also match the implemented behavior for dynamic memories.
* Update heap_addr docs
* Factor out `offset + size` to a helper
88 lines
2.3 KiB
Plaintext
88 lines
2.3 KiB
Plaintext
; Test basic code generation for i32 memory WebAssembly instructions.
|
|
test compile
|
|
|
|
; We only test on 64-bit since the heap_addr instructions and vmctx parameters
|
|
; explicitly mention the pointer width.
|
|
target aarch64
|
|
target x86_64 haswell
|
|
|
|
function %i32_load(i32, i64 vmctx) -> i32 {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i64):
|
|
v2 = heap_addr.i64 heap0, v0, 0, 1
|
|
v3 = load.i32 v2
|
|
return v3
|
|
}
|
|
|
|
function %i32_store(i32, i32, i64 vmctx) {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i32, v2: i64):
|
|
v3 = heap_addr.i64 heap0, v1, 0, 1
|
|
store v0, v3
|
|
return
|
|
}
|
|
|
|
function %i32_load8_s(i32, i64 vmctx) -> i32 {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i64):
|
|
v2 = heap_addr.i64 heap0, v0, 0, 1
|
|
v3 = sload8.i32 v2
|
|
return v3
|
|
}
|
|
|
|
function %i32_load8_u(i32, i64 vmctx) -> i32 {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i64):
|
|
v2 = heap_addr.i64 heap0, v0, 0, 1
|
|
v3 = uload8.i32 v2
|
|
return v3
|
|
}
|
|
|
|
function %i32_store8(i32, i32, i64 vmctx) {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i32, v2: i64):
|
|
v3 = heap_addr.i64 heap0, v1, 0, 1
|
|
istore8 v0, v3
|
|
return
|
|
}
|
|
|
|
function %i32_load16_s(i32, i64 vmctx) -> i32 {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i64):
|
|
v2 = heap_addr.i64 heap0, v0, 0, 1
|
|
v3 = sload16.i32 v2
|
|
return v3
|
|
}
|
|
|
|
function %i32_load16_u(i32, i64 vmctx) -> i32 {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i64):
|
|
v2 = heap_addr.i64 heap0, v0, 0, 1
|
|
v3 = uload16.i32 v2
|
|
return v3
|
|
}
|
|
|
|
function %i32_store16(i32, i32, i64 vmctx) {
|
|
gv0 = vmctx
|
|
heap0 = static gv0, min 0x0001_0000, bound 0x0001_0000_0000, offset_guard 0x8000_0000
|
|
|
|
block0(v0: i32, v1: i32, v2: i64):
|
|
v3 = heap_addr.i64 heap0, v1, 0, 1
|
|
istore16 v0, v3
|
|
return
|
|
}
|