aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/internal
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2019-04-02 14:14:51 -0700
committerMatthew Dempsky <mdempsky@google.com>2019-04-02 21:42:07 +0000
commit814c97b3133d0e5a8aa884e2ef752aaf7e7bd500 (patch)
treea0abf0cf8a3a360d1e95f4fdb858c42c7f05f7e1 /src/runtime/internal
parent20389553c7d287a4fffb9718e328a514640a915c (diff)
downloadgo-814c97b3133d0e5a8aa884e2ef752aaf7e7bd500.tar.gz
go-814c97b3133d0e5a8aa884e2ef752aaf7e7bd500.zip
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 <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/internal')
-rw-r--r--src/runtime/internal/atomic/atomic_wasm.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/runtime/internal/atomic/atomic_wasm.go b/src/runtime/internal/atomic/atomic_wasm.go
index 71288e9003..9c2193fa1b 100644
--- a/src/runtime/internal/atomic/atomic_wasm.go
+++ b/src/runtime/internal/atomic/atomic_wasm.go
@@ -123,10 +123,13 @@ func Store64(ptr *uint64, val uint64) {
*ptr = val
}
+//go:notinheap
+type noWB struct{}
+
//go:noinline
//go:nosplit
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) {
- *(*uintptr)(ptr) = uintptr(val)
+ *(**noWB)(ptr) = (*noWB)(val)
}
//go:nosplit