Skip to content

Commit fc0f36b

Browse files
committed
[release-branch.go1.5] runtime: use 4 byte writes in amd64p32 memmove/memclr
Currently, amd64p32's memmove and memclr use 8 byte writes as much as possible and 1 byte writes for the tail of the object. However, if an object ends with a 4 byte pointer at an 8 byte aligned offset, this may copy/zero the pointer field one byte at a time, allowing the garbage collector to observe a partially copied pointer. Fix this by using 4 byte writes instead of 8 byte writes. Updates #12552. Change-Id: I13324fd05756fb25ae57e812e836f0a975b5595c Reviewed-on: https://go-review.googlesource.com/15370 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-on: https://go-review.googlesource.com/16908 Reviewed-by: Russ Cox <[email protected]>
1 parent 9f59bc8 commit fc0f36b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/runtime/asm_amd64p32.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,12 @@ TEXT runtime·memclr(SB),NOSPLIT,$0-8
627627
MOVL ptr+0(FP), DI
628628
MOVL n+4(FP), CX
629629
MOVQ CX, BX
630-
ANDQ $7, BX
631-
SHRQ $3, CX
630+
ANDQ $3, BX
631+
SHRQ $2, CX
632632
MOVQ $0, AX
633633
CLD
634634
REP
635-
STOSQ
635+
STOSL
636636
MOVQ BX, CX
637637
REP
638638
STOSB

src/runtime/memmove_nacl_amd64p32.s

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "textflag.h"
66

7+
// This could use MOVSQ, but we use MOVSL so that if an object ends in
8+
// a 4 byte pointer, we copy it as a unit instead of byte by byte.
9+
710
TEXT runtime·memmove(SB), NOSPLIT, $0-12
811
MOVL to+0(FP), DI
912
MOVL from+4(FP), SI
@@ -14,9 +17,9 @@ TEXT runtime·memmove(SB), NOSPLIT, $0-12
1417

1518
forward:
1619
MOVL BX, CX
17-
SHRL $3, CX
18-
ANDL $7, BX
19-
REP; MOVSQ
20+
SHRL $2, CX
21+
ANDL $3, BX
22+
REP; MOVSL
2023
MOVL BX, CX
2124
REP; MOVSB
2225
RET
@@ -32,13 +35,13 @@ back:
3235
STD
3336

3437
MOVL BX, CX
35-
SHRL $3, CX
36-
ANDL $7, BX
37-
SUBL $8, DI
38-
SUBL $8, SI
39-
REP; MOVSQ
40-
ADDL $7, DI
41-
ADDL $7, SI
38+
SHRL $2, CX
39+
ANDL $3, BX
40+
SUBL $4, DI
41+
SUBL $4, SI
42+
REP; MOVSL
43+
ADDL $3, DI
44+
ADDL $3, SI
4245
MOVL BX, CX
4346
REP; MOVSB
4447
CLD

0 commit comments

Comments
 (0)