Commit c0f22945 authored by Keith Randall's avatar Keith Randall

runtime: fix race detector when map keys/values are passed by pointer.

Now that the map implementation is reading the keys and values from
arbitrary memory (instead of from stack slots), it needs to tell the
race detector when it does so.

Fixes #6875.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/36360043
parent 742f755a
...@@ -991,9 +991,10 @@ reflect·makemap(MapType *t, Hmap *ret) ...@@ -991,9 +991,10 @@ reflect·makemap(MapType *t, Hmap *ret)
void void
runtime·mapaccess1(MapType *t, Hmap *h, byte *ak, byte *av) runtime·mapaccess1(MapType *t, Hmap *h, byte *ak, byte *av)
{ {
if(raceenabled && h != nil) if(raceenabled && h != nil) {
runtime·racereadpc(h, runtime·getcallerpc(&t), runtime·mapaccess1); runtime·racereadpc(h, runtime·getcallerpc(&t), runtime·mapaccess1);
runtime·racereadpc(ak, runtime·getcallerpc(&t), runtime·mapaccess1);
}
if(h == nil || h->count == 0) { if(h == nil || h->count == 0) {
av = t->elem->zero; av = t->elem->zero;
} else { } else {
...@@ -1021,8 +1022,10 @@ runtime·mapaccess1(MapType *t, Hmap *h, byte *ak, byte *av) ...@@ -1021,8 +1022,10 @@ runtime·mapaccess1(MapType *t, Hmap *h, byte *ak, byte *av)
void void
runtime·mapaccess2(MapType *t, Hmap *h, byte *ak, byte *av, bool pres) runtime·mapaccess2(MapType *t, Hmap *h, byte *ak, byte *av, bool pres)
{ {
if(raceenabled && h != nil) if(raceenabled && h != nil) {
runtime·racereadpc(h, runtime·getcallerpc(&t), runtime·mapaccess2); runtime·racereadpc(h, runtime·getcallerpc(&t), runtime·mapaccess2);
runtime·racereadpc(ak, runtime·getcallerpc(&t), runtime·mapaccess2);
}
if(h == nil || h->count == 0) { if(h == nil || h->count == 0) {
av = t->elem->zero; av = t->elem->zero;
...@@ -1097,8 +1100,11 @@ runtime·mapassign1(MapType *t, Hmap *h, byte *ak, byte *av) ...@@ -1097,8 +1100,11 @@ runtime·mapassign1(MapType *t, Hmap *h, byte *ak, byte *av)
if(h == nil) if(h == nil)
runtime·panicstring("assignment to entry in nil map"); runtime·panicstring("assignment to entry in nil map");
if(raceenabled) if(raceenabled) {
runtime·racewritepc(h, runtime·getcallerpc(&t), runtime·mapassign1); runtime·racewritepc(h, runtime·getcallerpc(&t), runtime·mapassign1);
runtime·racereadpc(ak, runtime·getcallerpc(&t), runtime·mapassign1);
runtime·racereadpc(av, runtime·getcallerpc(&t), runtime·mapassign1);
}
hash_insert(t, h, ak, av); hash_insert(t, h, ak, av);
...@@ -1121,8 +1127,10 @@ runtime·mapdelete(MapType *t, Hmap *h, byte *ak) ...@@ -1121,8 +1127,10 @@ runtime·mapdelete(MapType *t, Hmap *h, byte *ak)
if(h == nil) if(h == nil)
return; return;
if(raceenabled) if(raceenabled) {
runtime·racewritepc(h, runtime·getcallerpc(&t), runtime·mapdelete); runtime·racewritepc(h, runtime·getcallerpc(&t), runtime·mapdelete);
runtime·racereadpc(ak, runtime·getcallerpc(&t), runtime·mapdelete);
}
hash_remove(t, h, ak); hash_remove(t, h, ak);
......
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