Skip to content

Commit ecf388f

Browse files
aclementsrsc
authored andcommitted
runtime: take stack barrier lock during copystack
Commit bbd1a1c prevented SIGPROF from scanning stacks that were being copied, but it didn't prevent a stack copy (specifically a stack shrink) from happening while SIGPROF is scanning the stack. As a result, a stack copy may adjust stack barriers while SIGPROF is in the middle of scanning a stack, causing SIGPROF to panic when it detects an inconsistent stack barrier. Fix this by taking the stack barrier lock while adjusting the stack. In addition to preventing SIGPROF from scanning this stack, this will block until any in-progress SIGPROF is done scanning the stack. For 1.5.2. Fixes #13362. Updates #12932. Change-Id: I422219c363054410dfa56381f7b917e04690e5dd Reviewed-on: https://go-review.googlesource.com/17191 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent ab4c929 commit ecf388f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/stack.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,10 @@ func copystack(gp *g, newsize uintptr) {
719719
print("copystack gp=", gp, " [", hex(old.lo), " ", hex(old.hi-used), " ", hex(old.hi), "]/", gp.stackAlloc, " -> [", hex(new.lo), " ", hex(new.hi-used), " ", hex(new.hi), "]/", newsize, "\n")
720720
}
721721

722+
// Disallow sigprof scans of this stack and block if there's
723+
// one in progress.
724+
gcLockStackBarriers(gp)
725+
722726
// adjust pointers in the to-be-copied frames
723727
var adjinfo adjustinfo
724728
adjinfo.old = old
@@ -751,6 +755,8 @@ func copystack(gp *g, newsize uintptr) {
751755
gp.stkbar = newstkbar
752756
gp.stktopsp += adjinfo.delta
753757

758+
gcUnlockStackBarriers(gp)
759+
754760
// free old stack
755761
if stackPoisonCopy != 0 {
756762
fillstack(old, 0xfc)

0 commit comments

Comments
 (0)