Commit 57912032 authored by Keith Randall's avatar Keith Randall

runtime: mapassign_* should use typedmemmove to update keys

We need to make sure that when the key contains a pointer, we use
a write barrier to update the key.

Also mapdelete_* should use typedmemclr.

Fixes #21297

Change-Id: I63dc90bec1cb909c2c6e08676c9ec853d736cdf8
Reviewed-on: https://go-review.googlesource.com/53414
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 38052559
...@@ -495,7 +495,7 @@ again: ...@@ -495,7 +495,7 @@ again:
} }
// store new key/value at insert position // store new key/value at insert position
*((*uint32)(insertk)) = key typedmemmove(t.key, insertk, unsafe.Pointer(&key))
*inserti = top *inserti = top
h.count++ h.count++
...@@ -583,7 +583,7 @@ again: ...@@ -583,7 +583,7 @@ again:
} }
// store new key/value at insert position // store new key/value at insert position
*((*uint64)(insertk)) = key typedmemmove(t.key, insertk, unsafe.Pointer(&key))
*inserti = top *inserti = top
h.count++ h.count++
...@@ -723,7 +723,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) { ...@@ -723,7 +723,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) {
if key != *k { if key != *k {
continue continue
} }
*k = 0 typedmemclr(t.key, unsafe.Pointer(k))
v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*4 + i*uintptr(t.valuesize)) v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*4 + i*uintptr(t.valuesize))
typedmemclr(t.elem, v) typedmemclr(t.elem, v)
b.tophash[i] = empty b.tophash[i] = empty
...@@ -778,7 +778,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) { ...@@ -778,7 +778,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) {
if key != *k { if key != *k {
continue continue
} }
*k = 0 typedmemclr(t.key, unsafe.Pointer(k))
v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*8 + i*uintptr(t.valuesize)) v := unsafe.Pointer(uintptr(unsafe.Pointer(b)) + dataOffset + bucketCnt*8 + i*uintptr(t.valuesize))
typedmemclr(t.elem, v) typedmemclr(t.elem, v)
b.tophash[i] = empty b.tophash[i] = empty
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment