]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.11] runtime: never call into race detector with retaken P
authorNikhil Benesch <nikhil.benesch@gmail.com>
Fri, 9 Nov 2018 05:55:13 +0000 (00:55 -0500)
committerIan Lance Taylor <iant@golang.org>
Mon, 12 Nov 2018 19:10:48 +0000 (19:10 +0000)
commit402eb45b217d315840f63ed60895c256bdca04ce
treea06925a515bdaad26a6af0677a764f547a2967ce
parente8a95aeb75536496432bcace1fb2bbfa449bf0fa
[release-branch.go1.11] runtime: never call into race detector with retaken P

cgocall could previously invoke the race detector on an M whose P had
been retaken. The race detector would attempt to use the P-local state
from this stale P, racing with the thread that was actually wired to
that P. The result was memory corruption of ThreadSanitizer's internal
data structures that presented as hard-to-understand assertion failures
and segfaults.

Reorder cgocall so that it always acquires a P before invoking the race
detector, and add a test that stresses the interaction between cgo and
the race detector to protect against future bugs of this kind.

Fixes #28690.

Change-Id: Ide93f96a23490314d6647547140e0a412a97f0d4
Reviewed-on: https://go-review.googlesource.com/c/148717
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
(cherry picked from commit e496e612b7f45a09209f8f4e1c7c1d0db378dc18)
Reviewed-on: https://go-review.googlesource.com/c/148902
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/cgo_test.go
misc/cgo/test/test27660.go [new file with mode: 0644]
src/runtime/cgocall.go