Skip to content

Commit 9f6df6c

Browse files
committed
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]>
1 parent 44078a3 commit 9f6df6c

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
@@ -620,12 +620,12 @@ TEXT runtime·memclr(SB),NOSPLIT,$0-8
620620
MOVL ptr+0(FP), DI
621621
MOVL n+4(FP), CX
622622
MOVQ CX, BX
623-
ANDQ $7, BX
624-
SHRQ $3, CX
623+
ANDQ $3, BX
624+
SHRQ $2, CX
625625
MOVQ $0, AX
626626
CLD
627627
REP
628-
STOSQ
628+
STOSL
629629
MOVQ BX, CX
630630
REP
631631
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)