diff options
| author | Russ Cox <rsc@golang.org> | 2014-12-22 22:42:05 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-01-06 00:26:45 +0000 |
| commit | a73c1cef070a33527c869d36a763ea265f689fe3 (patch) | |
| tree | 287c7aa774df19d838d621bb57a05bc338f841ea /src/runtime/slice.go | |
| parent | dcec123a4923437242c52d2693ace80d2f3c704e (diff) | |
| download | go-a73c1cef070a33527c869d36a763ea265f689fe3.tar.xz | |
runtime: add missing write barriers in append's copy of slice data
Found with GODEBUG=wbshadow=1 mode.
Eventually that will run automatically, but right now
it still detects other missing write barriers.
Change-Id: Ic8624401d7c8225a935f719f96f2675c6f5c0d7c
Reviewed-on: https://go-review.googlesource.com/2064
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/slice.go')
| -rw-r--r-- | src/runtime/slice.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go index e427a8b7cc..8264cd6956 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -81,12 +81,16 @@ func growslice(t *slicetype, old sliceStruct, n int64) sliceStruct { var p unsafe.Pointer if et.kind&kindNoPointers != 0 { p = rawmem(capmem) + memmove(p, old.array, lenmem) memclr(add(p, lenmem), capmem-lenmem) } else { - // Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan unitialized memory + // Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan unitialized memory. + // TODO(rsc): Use memmove when !needwb(). p = newarray(et, uintptr(newcap)) + for i := 0; i < old.len; i++ { + writebarrierfat(et, add(p, uintptr(i)*et.size), add(old.array, uintptr(i)*et.size)) + } } - memmove(p, old.array, lenmem) return sliceStruct{p, old.len, newcap} } |
