Skip to content

Commit 68058ed

Browse files
committed
runtime: document pointer write atomicity for memclrNoHeapPointers
memclrNoHeapPointers is the underlying implementation of typedmemclr and memclrHasPointers, so it still needs to write pointer-aligned words atomically. Document this requirement. Updates #41428. Change-Id: Ice00dee5de7a96a50e51ff019fcef069e8a8406a Reviewed-on: https://go-review.googlesource.com/c/go/+/287692 Trust: Cherry Zhang <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent c8bd801 commit 68058ed

13 files changed

+32
-0
lines changed

src/runtime/memclr_386.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
// NOTE: Windows externalthreadhandler expects memclr to preserve DX.
1111

12+
// See memclrNoHeapPointers Go doc for important implementation constraints.
13+
1214
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
1315
TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-8
1416
MOVL ptr+0(FP), DI

src/runtime/memclr_amd64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
// NOTE: Windows externalthreadhandler expects memclr to preserve DX.
1111

12+
// See memclrNoHeapPointers Go doc for important implementation constraints.
13+
1214
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
1315
TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-16
1416
MOVQ ptr+0(FP), DI

src/runtime/memclr_arm.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define N R12
3131
#define TMP R12 /* N and TMP don't overlap */
3232

33+
// See memclrNoHeapPointers Go doc for important implementation constraints.
34+
3335
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
3436
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-8
3537
MOVW ptr+0(FP), TO

src/runtime/memclr_arm64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
911
MOVD ptr+0(FP), R0

src/runtime/memclr_mips64x.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "go_asm.h"
88
#include "textflag.h"
99

10+
// See memclrNoHeapPointers Go doc for important implementation constraints.
11+
1012
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
1113
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
1214
MOVV ptr+0(FP), R1

src/runtime/memclr_mipsx.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define MOVWLO MOVWL
1515
#endif
1616

17+
// See memclrNoHeapPointers Go doc for important implementation constraints.
18+
1719
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
1820
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-8
1921
MOVW n+4(FP), R2

src/runtime/memclr_plan9_386.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-8
911
MOVL ptr+0(FP), DI

src/runtime/memclr_plan9_amd64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
911
MOVQ ptr+0(FP), DI

src/runtime/memclr_ppc64x.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "textflag.h"
88

9+
// See memclrNoHeapPointers Go doc for important implementation constraints.
10+
911
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
1012
TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT|NOFRAME, $0-16
1113
MOVD ptr+0(FP), R3

src/runtime/memclr_riscv64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// void runtime·memclrNoHeapPointers(void*, uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
911
MOV ptr+0(FP), T1

src/runtime/memclr_s390x.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT|NOFRAME,$0-16
911
MOVD ptr+0(FP), R4

src/runtime/memclr_wasm.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "textflag.h"
66

7+
// See memclrNoHeapPointers Go doc for important implementation constraints.
8+
79
// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
810
TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-16
911
MOVD ptr+0(FP), R0

src/runtime/stubs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ func badsystemstack() {
7373
// *ptr is uninitialized memory (e.g., memory that's being reused
7474
// for a new allocation) and hence contains only "junk".
7575
//
76+
// memclrNoHeapPointers ensures that if ptr is pointer-aligned, and n
77+
// is a multiple of the pointer size, then any pointer-aligned,
78+
// pointer-sized portion is cleared atomically. Despite the function
79+
// name, this is necessary because this function is the underlying
80+
// implementation of typedmemclr and memclrHasPointers. See the doc of
81+
// memmove for more details.
82+
//
7683
// The (CPU-specific) implementations of this function are in memclr_*.s.
84+
//
7785
//go:noescape
7886
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
7987

0 commit comments

Comments
 (0)