From 98dd205fa4f125c8ba8099c3d84d95189666068e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 28 Feb 2021 12:24:02 +0100 Subject: [PATCH] runtime: see whether gp==nil before checking preemption state 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 Run-TryBot: Jason A. Donenfeld TryBot-Result: Go Bot Reviewed-by: Russ Cox --- src/runtime/os_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 707c9054b5..705b42c61c 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -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) -- 2.48.1