From: Austin Clements Date: Wed, 11 Oct 2017 21:04:26 +0000 (-0400) Subject: runtime: don't try to free OS-created signal stacks X-Git-Tag: go1.10beta1~757 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=44d9e96da9b7625be81f2c7eacf73fcc609874ce;p=gostls13.git runtime: don't try to free OS-created signal stacks Android's libc creates a signal stack for every thread it creates. In Go, minitSignalStack picks up this existing signal stack and puts it in m.gsignal.stack. However, if we later try to exit a thread (because a locked goroutine is exiting), we'll attempt to stackfree this libc-allocated signal stack and panic. Fix this by clearing gsignal.stack when we unminitSignals in such a situation. This should fix the Android build, which is currently broken. Change-Id: Ieea8d72ef063d22741c54c9daddd8bb84926a488 Reviewed-on: https://go-review.googlesource.com/70130 Reviewed-by: David Crawshaw Reviewed-by: Ian Lance Taylor Run-TryBot: David Crawshaw TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 165b04eb43..d096df547e 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1268,7 +1268,13 @@ func mexit(osStack bool) { unminit() // Free the gsignal stack. - if m.gsignal != nil { + // + // If the signal stack was created outside Go, then gsignal + // will be non-nil, but unminitSignals set stack.lo to 0 + // (e.g., Android's libc creates all threads with a signal + // stack, so it's possible for Go to exit them but not control + // the signal stack). + if m.gsignal != nil && m.gsignal.stack.lo != 0 { stackfree(m.gsignal.stack) } diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 5ea4b9f631..a616d46bac 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -744,6 +744,10 @@ func unminitSignals() { if getg().m.newSigstack { st := stackt{ss_flags: _SS_DISABLE} sigaltstack(&st, nil) + } else { + // We got the signal stack from someone else. Clear it + // so we don't get confused. + getg().m.gsignal.stack = stack{} } }