]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: see whether gp==nil before checking preemption state
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 28 Feb 2021 11:24:02 +0000 (12:24 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 8 Apr 2021 19:51:32 +0000 (19:51 +0000)
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 #44679.

Change-Id: I0199ebe7cd113379c5fa35c27932d913df79092a
Reviewed-on: https://go-review.googlesource.com/c/go/+/297390
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/os_windows.go

index 707c9054b56ac2ac1050ae264c423e0fd0ec2390..705b42c61c6d23b02192e0a2c2413a142b164ade 100644 (file)
@@ -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)