Commit e9c99495 authored by Cherry Zhang's avatar Cherry Zhang

runtime: fix past-the-end write of wasmStack

On Wasm, at program start, we set the SP to
wasmStack+sizeof(wasmStack), and start to write on it. This write
is actually past the end of wasmStack. This may scribble to some
other variable next to it in the data segment. Or if wasmStack
happens to be the last object in the data segment, we'll scribble
to unreserved memory and cause the next sysReserve return
non-zero memory. Either way, this is bad. Fix this by subtracting
16 before writing.

Found while debugging the new page allocator (CL 190622 and the
stack) with Michael. We found that on Wasm, the first sysReserve
may return memory with the first a few words being non-zero.

Change-Id: I2d76dd3fee85bddb2ff6a902b5876dea3f2969a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/202086Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 46aa8354
......@@ -19,7 +19,7 @@ TEXT _rt0_wasm_js(SB),NOSPLIT,$0
// R0: argc (i32)
// R1: argv (i32)
TEXT wasm_export_run(SB),NOSPLIT,$0
MOVD $runtime·wasmStack+m0Stack__size(SB), SP
MOVD $runtime·wasmStack+(m0Stack__size-16)(SB), SP
Get SP
Get R0 // argc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment