From: Ian Lance Taylor Date: Fri, 17 Mar 2017 20:48:56 +0000 (-0700) Subject: runtime: clear signal stack on main thread X-Git-Tag: go1.9beta1~1082 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5dc14af6824ed31eab5a8a16e8e08082c5ddcb14;p=gostls13.git runtime: clear signal stack on main thread 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 --- diff --git a/src/runtime/os_freebsd.go b/src/runtime/os_freebsd.go index f736019faa..7c989de109 100644 --- a/src/runtime/os_freebsd.go +++ b/src/runtime/os_freebsd.go @@ -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() }