Skip to content

Commit

Permalink
runtime: see whether gp==nil before checking preemption state
Browse files Browse the repository at this point in the history
Recent we changed from using gFromTLS to using gFromSP, which apparently
sometimes returns nil. This causes crashes when dereferenced. Fix that
by not checking for preemption in the case that gFromSP returns nil.

Fixes golang#44679.

Change-Id: I0199ebe7cd113379c5fa35c27932d913df79092a
Reviewed-on: https://go-review.googlesource.com/c/go/+/297390
Trust: Jason A. Donenfeld <[email protected]>
Run-TryBot: Jason A. Donenfeld <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
zx2c4 committed Apr 8, 2021
1 parent 46ffbec commit 98dd205
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ func preemptM(mp *m) {

// Does it want a preemption and is it safe to preempt?
gp := gFromSP(mp, c.sp())
if wantAsyncPreempt(gp) {
if gp != nil && wantAsyncPreempt(gp) {
if ok, newpc := isAsyncSafePoint(gp, c.ip(), c.sp(), c.lr()); ok {
// Inject call to asyncPreempt
targetPC := funcPC(asyncPreempt)
Expand Down

0 comments on commit 98dd205

Please sign in to comment.