]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: clear signal stack on main thread
authorIan Lance Taylor <iant@golang.org>
Fri, 17 Mar 2017 20:48:56 +0000 (13:48 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 Mar 2017 22:59:26 +0000 (22:59 +0000)
This is a workaround for a FreeBSD kernel bug. It can be removed when
we are confident that all people are using the fixed kernel. See #15658.

Updates #15658.

Change-Id: I0ecdccb77ddd0c270bdeac4d3a5c8abaf0449075
Reviewed-on: https://go-review.googlesource.com/38325
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/os_freebsd.go

index f736019faa7e8b7d797a9976b4de372c89c153fe..7c989de10931a73e38315d6e0d8c7740ee6671f1 100644 (file)
@@ -240,6 +240,20 @@ func minit() {
                _g_.m.procid = uint64(*(*uint32)(unsafe.Pointer(&_g_.m.procid)))
        }
 
+       // On FreeBSD before about April 2017 there was a bug such
+       // that calling execve from a thread other than the main
+       // thread did not reset the signal stack. That would confuse
+       // minitSignals, which calls minitSignalStack, which checks
+       // whether there is currently a signal stack and uses it if
+       // present. To avoid this confusion, explicitly disable the
+       // signal stack on the main thread when not running in a
+       // library. This can be removed when we are confident that all
+       // FreeBSD users are running a patched kernel. See issue #15658.
+       if gp := getg(); !isarchive && !islibrary && gp.m == &m0 && gp == gp.m.g0 {
+               st := stackt{ss_flags: _SS_DISABLE}
+               sigaltstack(&st, nil)
+       }
+
        minitSignals()
 }