Skip to content

Commit 6b26788

Browse files
committed
[release-branch.go1.5] 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 <[email protected]> Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/17194
1 parent 9f9b95b commit 6b26788

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/stack1.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ func copystack(gp *g, newsize uintptr) {
609609
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")
610610
}
611611

612+
// Disallow sigprof scans of this stack and block if there's
613+
// one in progress.
614+
gcLockStackBarriers(gp)
615+
612616
// adjust pointers in the to-be-copied frames
613617
var adjinfo adjustinfo
614618
adjinfo.old = old
@@ -640,6 +644,8 @@ func copystack(gp *g, newsize uintptr) {
640644
gp.stackAlloc = newsize
641645
gp.stkbar = newstkbar
642646

647+
gcUnlockStackBarriers(gp)
648+
643649
// free old stack
644650
if stackPoisonCopy != 0 {
645651
fillstack(old, 0xfc)

0 commit comments

Comments
 (0)