Skip to content

Commit 44d9e96

Browse files
committed
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: David Crawshaw <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a3e013b commit 44d9e96

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/runtime/proc.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,13 @@ func mexit(osStack bool) {
12681268
unminit()
12691269

12701270
// Free the gsignal stack.
1271-
if m.gsignal != nil {
1271+
//
1272+
// If the signal stack was created outside Go, then gsignal
1273+
// will be non-nil, but unminitSignals set stack.lo to 0
1274+
// (e.g., Android's libc creates all threads with a signal
1275+
// stack, so it's possible for Go to exit them but not control
1276+
// the signal stack).
1277+
if m.gsignal != nil && m.gsignal.stack.lo != 0 {
12721278
stackfree(m.gsignal.stack)
12731279
}
12741280

src/runtime/signal_unix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ func unminitSignals() {
744744
if getg().m.newSigstack {
745745
st := stackt{ss_flags: _SS_DISABLE}
746746
sigaltstack(&st, nil)
747+
} else {
748+
// We got the signal stack from someone else. Clear it
749+
// so we don't get confused.
750+
getg().m.gsignal.stack = stack{}
747751
}
748752
}
749753

0 commit comments

Comments
 (0)