Skip to content

Commit 0b80775

Browse files
randall77dmitshur
authored andcommitted
[release-branch.go1.15] runtime: implement StorepNoWB for wasm in assembly
The second argument of StorepNoWB must be forced to escape. The current Go code does not explicitly enforce that property. By implementing in assembly, and not using go:noescape, we force the issue. Test is in CL 249761. Issue #40975. This CL is needed for CL 249917, which changes how go:notinheap works and breaks the previous StorepNoWB wasm code. I checked for other possible errors like this. This is the only go:notinheap that isn't in the runtime itself. Included test from CL 249761. Update #41432 Change-Id: I43400a806662655727c4a3baa8902b63bdc9fa57 Reviewed-on: https://go-review.googlesource.com/c/go/+/249962 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> (cherry picked from commit c060260) Reviewed-on: https://go-review.googlesource.com/c/go/+/260878 Trust: Keith Randall <[email protected]> Trust: Cuong Manh Le <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 2c2e11f commit 0b80775

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include "textflag.h"
6+
7+
TEXT runtime∕internal∕atomic·StorepNoWB(SB), NOSPLIT, $0-16
8+
MOVD ptr+0(FP), R0
9+
MOVD val+8(FP), 0(R0)
10+
RET

src/runtime/internal/atomic/atomic_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,13 @@ func TestBitwiseContended(t *testing.T) {
220220
}
221221
}
222222
}
223+
224+
func TestStorepNoWB(t *testing.T) {
225+
var p [2]*int
226+
for i := range p {
227+
atomic.StorepNoWB(unsafe.Pointer(&p[i]), unsafe.Pointer(new(int)))
228+
}
229+
if p[0] == p[1] {
230+
t.Error("Bad escape analysis of StorepNoWB")
231+
}
232+
}

src/runtime/internal/atomic/atomic_wasm.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,11 @@ func Store64(ptr *uint64, val uint64) {
153153
*ptr = val
154154
}
155155

156-
//go:notinheap
157-
type noWB struct{}
158-
159-
//go:noinline
160-
//go:nosplit
161-
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) {
162-
*(**noWB)(ptr) = (*noWB)(val)
163-
}
156+
// StorepNoWB performs *ptr = val atomically and without a write
157+
// barrier.
158+
//
159+
// NO go:noescape annotation; see atomic_pointer.go.
160+
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer)
164161

165162
//go:nosplit
166163
//go:noinline

0 commit comments

Comments
 (0)