Skip to content

Commit

Permalink
runtime: prevent race between setNextBarrierPC and sigprof
Browse files Browse the repository at this point in the history
Currently, setNextBarrierPC manipulates the stack barriers without
acquiring the stack barrier lock. This is mostly okay because
setNextBarrierPC also runs synchronously on the G and prevents safe
points, but this doesn't prevent a sigprof from occurring during a
setNextBarrierPC and performing a traceback.

Given that setNextBarrierPC simply sets one entry in the stack barrier
array, this is almost certainly safe in reality. However, given that
this depends on a subtle argument, which may not hold in the future,
and that setNextBarrierPC almost never happens, making it nowhere near
performance-critical, we can simply acquire the stack barrier lock and
be sure that the synchronization will work.

Updates #12528. For 1.5.3.

Change-Id: Ife696e10d969f190157eb1cbe762a2de2ebce079
Reviewed-on: https://go-review.googlesource.com/18022
Run-TryBot: Austin Clements <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
aclements committed Dec 18, 2015
1 parent 90a6893 commit a4a57bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/runtime/mstkbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ func nextBarrierPC() uintptr {
//go:nosplit
func setNextBarrierPC(pc uintptr) {
gp := getg()
gcLockStackBarriers(gp)
gp.stkbar[gp.stkbarPos].savedLRVal = pc
gcUnlockStackBarriers(gp)
}

// gcLockStackBarriers synchronizes with tracebacks of gp's stack
Expand Down

0 comments on commit a4a57bb

Please sign in to comment.