aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os_linux.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-03-11 21:51:09 -0700
committerIan Lance Taylor <iant@golang.org>2020-03-13 21:56:51 +0000
commitb851e51160bc8ed412e229152b430b75e7ce56f9 (patch)
treed0e8f8608bf164454726fa1fc3c1aeeab18e3737 /src/runtime/os_linux.go
parentdcc5c249260526aa1b1534aa9f7f33228fcd25d7 (diff)
downloadgo-b851e51160bc8ed412e229152b430b75e7ce56f9.tar.gz
go-b851e51160bc8ed412e229152b430b75e7ce56f9.zip
runtime: don't crash on mlock failure
Instead, note that mlock has failed, start trying the mitigation of touching the signal stack before sending a preemption signal, and, if the program crashes, mention the possible problem and a wiki page describing the issue (https://golang.org/wiki/LinuxKernelSignalVectorBug). Tested on a kernel in the buggy version range, but with the patch, by using `ulimit -l 0`. Fixes #37436 Change-Id: I072aadb2101496dffd655e442fa5c367dad46ce8 Reviewed-on: https://go-review.googlesource.com/c/go/+/223121 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/os_linux.go')
-rw-r--r--src/runtime/os_linux.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index e0e3f4e341..d8c1827852 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -5,6 +5,7 @@
package runtime
import (
+ "runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
)
@@ -479,7 +480,21 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
func getpid() int
func tgkill(tgid, tid, sig int)
+// touchStackBeforeSignal stores an errno value. If non-zero, it means
+// that we should touch the signal stack before sending a signal.
+// This is used on systems that have a bug when the signal stack must
+// be faulted in. See #35777 and #37436.
+//
+// This is accessed atomically as it is set and read in different threads.
+//
+// TODO(austin): Remove this after Go 1.15 when we remove the
+// mlockGsignal workaround.
+var touchStackBeforeSignal uint32
+
// signalM sends a signal to mp.
func signalM(mp *m, sig int) {
+ if atomic.Load(&touchStackBeforeSignal) != 0 {
+ atomic.Cas((*uint32)(unsafe.Pointer(mp.gsignal.stack.hi-4)), 0, 0)
+ }
tgkill(getpid(), int(mp.procid), sig)
}