Skip to content

Commit 814c97b

Browse files
committed
runtime/internal/atomic: fix wasm's StorepNoWB implementation
Package unsafe's safety rules require that pointers converted to uintptr must be converted back to pointer-type before being stored into memory. In particular, storing a pointer into a non-pointer-typed expression does not guarantee the pointer stays valid, even if the expression refers to a pointer-typed variable. wasm's StorepNoWB implementation violates these rules by storing a pointer through a uintptr-typed expression. This happens to work today because esc.go is lenient in its implementation of package unsafe's rules, but my escape analysis rewrite follows them more rigorously, which causes val to be treated as a non-leaking parameter. This CL fixes the issue by using a *T-typed expression, where T is marked //go:notinheap so that the compiler still omits the write barrier as appropriate. Updates #23109. Change-Id: I49bc5474dbaa95729e5c93201493afe692591bc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/170323 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 2038955 commit 814c97b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/internal/atomic/atomic_wasm.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ func Store64(ptr *uint64, val uint64) {
123123
*ptr = val
124124
}
125125

126+
//go:notinheap
127+
type noWB struct{}
128+
126129
//go:noinline
127130
//go:nosplit
128131
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) {
129-
*(*uintptr)(ptr) = uintptr(val)
132+
*(**noWB)(ptr) = (*noWB)(val)
130133
}
131134

132135
//go:nosplit

0 commit comments

Comments
 (0)