diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-04-19 20:09:13 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-19 20:09:13 +0000 |
commit | 2779f5f9c0659ff7dbeb0ba2e4d711179b04d593 (patch) | |
tree | 5f478a4378b71af8c83d8e007d789a200bd12e21 /pkg | |
parent | 4f5baf0d38f48e7696a6591579d1a6f6490982ea (diff) | |
parent | b0333d33a206b3a3cf3bcc90e44793708ed5cb7a (diff) |
Merge release-20210412.0-30-gb0333d33a (automated)
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/safemem/block_unsafe.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/pkg/safemem/block_unsafe.go b/pkg/safemem/block_unsafe.go index 93879bb4f..4af534385 100644 --- a/pkg/safemem/block_unsafe.go +++ b/pkg/safemem/block_unsafe.go @@ -20,6 +20,7 @@ import ( "gvisor.dev/gvisor/pkg/gohacks" "gvisor.dev/gvisor/pkg/safecopy" + "gvisor.dev/gvisor/pkg/sync" ) // A Block is a range of contiguous bytes, similar to []byte but with the @@ -223,8 +224,22 @@ func Copy(dst, src Block) (int, error) { func Zero(dst Block) (int, error) { if !dst.needSafecopy { bs := dst.ToSlice() - for i := range bs { - bs[i] = 0 + if !sync.RaceEnabled { + // If the race detector isn't enabled, the golang + // compiler replaces the next loop with memclr + // (https://github.com/golang/go/issues/5373). + for i := range bs { + bs[i] = 0 + } + } else { + bsLen := len(bs) + if bsLen == 0 { + return 0, nil + } + bs[0] = 0 + for i := 1; i < bsLen; i *= 2 { + copy(bs[i:], bs[:i]) + } } return len(bs), nil } |