aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgcmark.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2015-11-18 14:10:40 -0500
committerAustin Clements <austin@google.com>2015-11-19 16:35:38 +0000
commit9c9d74aba7eb4de2a253b04817ff26b32a6fea40 (patch)
treef67a45f98c691d1a9c67b99a97e44d4a9d5133e2 /src/runtime/mgcmark.go
parent3a2fc06833a346a7c3b071a984b5265b7ea1da57 (diff)
downloadgo-9c9d74aba7eb4de2a253b04817ff26b32a6fea40.tar.xz
runtime: prevent sigprof during all stack barrier ops
A sigprof during stack barrier insertion or removal can crash if it detects an inconsistency between the stkbar array and the stack itself. Currently we protect against this when scanning another G's stack using stackLock, but we don't protect against it when unwinding stack barriers for a recover or a memmove to the stack. This commit cleans up and improves the stack locking code. It abstracts out the lock and unlock operations. It uses the lock consistently everywhere we perform stack operations, and pushes the lock/unlock down closer to where the stack barrier operations happen to make it more obvious what it's protecting. Finally, it modifies sigprof so that instead of spinning until it acquires the lock, it simply doesn't perform a traceback if it can't acquire it. This is necessary to prevent self-deadlock. Updates #11863, which introduced stackLock to fix some of these issues, but didn't go far enough. Updates #12528. Change-Id: I9d1fa88ae3744d31ba91500c96c6988ce1a3a349 Reviewed-on: https://go-review.googlesource.com/17036 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/mgcmark.go')
-rw-r--r--src/runtime/mgcmark.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go
index 07eb1901a0..6deb09adbf 100644
--- a/src/runtime/mgcmark.go
+++ b/src/runtime/mgcmark.go
@@ -620,6 +620,8 @@ func scanstack(gp *g) {
throw("g already has stack barriers")
}
+ gcLockStackBarriers(gp)
+
case _GCmarktermination:
if int(gp.stkbarPos) == len(gp.stkbar) {
// gp hit all of the stack barriers (or there
@@ -675,6 +677,9 @@ func scanstack(gp *g) {
if gcphase == _GCmarktermination {
gcw.dispose()
}
+ if gcphase == _GCmark {
+ gcUnlockStackBarriers(gp)
+ }
gp.gcscanvalid = true
}