aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2022-09-19 05:48:35 +0000
committerGopher Robot <gobot@golang.org>2022-09-19 13:56:07 +0000
commitfc1cddcfe916eff82b7c6a0e82765e9b9fe29980 (patch)
treeafc75e6ed97a32ac813329638709acea5e1d7141 /src/runtime
parent00bee6d9a4c3ed6168350fc6551043ff7a1895f2 (diff)
downloadgo-fc1cddcfe916eff82b7c6a0e82765e9b9fe29980.tar.xz
Revert "runtime: treat SI_TKILL like SI_USER on Linux"
This reverts CL 431255. Reason for revert: breaks darwin-arm and linux-noopt builders. Change-Id: I29332b935cc1e35fa039af3d70465e496361fcc9 Reviewed-on: https://go-review.googlesource.com/c/go/+/431715 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/crash_cgo_test.go17
-rw-r--r--src/runtime/os_linux.go12
-rw-r--r--src/runtime/os_linux_be64.go1
-rw-r--r--src/runtime/os_linux_generic.go1
-rw-r--r--src/runtime/os_linux_mips64x.go1
-rw-r--r--src/runtime/os_linux_mipsx.go1
-rw-r--r--src/runtime/os_unix_nonlinux.go13
-rw-r--r--src/runtime/signal_unix.go14
-rw-r--r--src/runtime/testdata/testprogcgo/segv.go18
-rw-r--r--src/runtime/testdata/testprogcgo/segv_linux.go51
10 files changed, 22 insertions, 107 deletions
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index f0a27507b9..5e58712297 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -603,14 +603,8 @@ func TestSegv(t *testing.T) {
t.Skipf("no signals on %s", runtime.GOOS)
}
- for _, test := range []string{"Segv", "SegvInCgo", "TgkillSegv", "TgkillSegvInCgo"} {
+ for _, test := range []string{"Segv", "SegvInCgo"} {
test := test
-
- // The tgkill variants only run on Linux.
- if runtime.GOOS != "linux" && strings.HasPrefix(test, "Tgkill") {
- continue
- }
-
t.Run(test, func(t *testing.T) {
t.Parallel()
got := runTestProg(t, "testprogcgo", test)
@@ -623,15 +617,6 @@ func TestSegv(t *testing.T) {
t.Errorf("did not see %q in output", want)
}
- doNotWant := "fatal error:"
- if strings.Contains(got, doNotWant) {
- if runtime.GOOS == "darwin" && strings.Contains(got, "0xb01dfacedebac1e") {
- // See the comment in signal_darwin_amd64.go.
- t.Skip("skipping due to Darwin handling of malformed addresses")
- }
- t.Errorf("saw %q in output", doNotWant)
- }
-
// No runtime errors like "runtime: unknown pc".
switch runtime.GOOS {
case "darwin", "illumos", "solaris":
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index e84f065e24..3ae665c83d 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -886,15 +886,3 @@ func runPerThreadSyscall() {
gp.m.needPerThreadSyscall.Store(0)
}
-
-const (
- _SI_USER = 0
- _SI_TKILL = -6
-)
-
-// sigFromUser reports whether the signal was sent because of a call
-// to kill or tgkill.
-func (c *sigctxt) sigFromUser() bool {
- code := int32(c.sigcode())
- return code == _SI_USER || code == _SI_TKILL
-}
diff --git a/src/runtime/os_linux_be64.go b/src/runtime/os_linux_be64.go
index d8d4ac2497..537515fcf2 100644
--- a/src/runtime/os_linux_be64.go
+++ b/src/runtime/os_linux_be64.go
@@ -11,6 +11,7 @@ package runtime
const (
_SS_DISABLE = 2
_NSIG = 65
+ _SI_USER = 0
_SIG_BLOCK = 0
_SIG_UNBLOCK = 1
_SIG_SETMASK = 2
diff --git a/src/runtime/os_linux_generic.go b/src/runtime/os_linux_generic.go
index 15fafc14ea..bed9e66e15 100644
--- a/src/runtime/os_linux_generic.go
+++ b/src/runtime/os_linux_generic.go
@@ -9,6 +9,7 @@ package runtime
const (
_SS_DISABLE = 2
_NSIG = 65
+ _SI_USER = 0
_SIG_BLOCK = 0
_SIG_UNBLOCK = 1
_SIG_SETMASK = 2
diff --git a/src/runtime/os_linux_mips64x.go b/src/runtime/os_linux_mips64x.go
index 11d35bc020..188db01034 100644
--- a/src/runtime/os_linux_mips64x.go
+++ b/src/runtime/os_linux_mips64x.go
@@ -27,6 +27,7 @@ func cputicks() int64 {
const (
_SS_DISABLE = 2
_NSIG = 129
+ _SI_USER = 0
_SIG_BLOCK = 1
_SIG_UNBLOCK = 2
_SIG_SETMASK = 3
diff --git a/src/runtime/os_linux_mipsx.go b/src/runtime/os_linux_mipsx.go
index cdf83ff71d..73016f81d9 100644
--- a/src/runtime/os_linux_mipsx.go
+++ b/src/runtime/os_linux_mipsx.go
@@ -21,6 +21,7 @@ func cputicks() int64 {
const (
_SS_DISABLE = 2
_NSIG = 128 + 1
+ _SI_USER = 0
_SIG_BLOCK = 1
_SIG_UNBLOCK = 2
_SIG_SETMASK = 3
diff --git a/src/runtime/os_unix_nonlinux.go b/src/runtime/os_unix_nonlinux.go
deleted file mode 100644
index 5c8a137f18..0000000000
--- a/src/runtime/os_unix_nonlinux.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build unix && !linux
-
-package runtime
-
-// sigFromUser reports whether the signal was sent because of a call
-// to kill.
-func (c *sigctxt) sigFromUser() bool {
- return c.sigcode() == _SI_USER
-}
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index 4c55e83747..545094c640 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -662,7 +662,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
if sig < uint32(len(sigtable)) {
flags = sigtable[sig].flags
}
- if !c.sigFromUser() && flags&_SigPanic != 0 && gp.throwsplit {
+ if c.sigcode() != _SI_USER && flags&_SigPanic != 0 && gp.throwsplit {
// We can't safely sigpanic because it may grow the
// stack. Abort in the signal handler instead.
flags = _SigThrow
@@ -672,7 +672,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
// causes a memory fault. Don't turn that into a panic.
flags = _SigThrow
}
- if !c.sigFromUser() && flags&_SigPanic != 0 {
+ if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {
// The signal is going to cause a panic.
// Arrange the stack so that it looks like the point
// where the signal occurred made a call to the
@@ -690,13 +690,13 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
return
}
- if c.sigFromUser() || flags&_SigNotify != 0 {
+ if c.sigcode() == _SI_USER || flags&_SigNotify != 0 {
if sigsend(sig) {
return
}
}
- if c.sigFromUser() && signal_ignored(sig) {
+ if c.sigcode() == _SI_USER && signal_ignored(sig) {
return
}
@@ -706,7 +706,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
// _SigThrow means that we should exit now.
// If we get here with _SigPanic, it means that the signal
- // was sent to us by a program (c.sigFromUser() is true);
+ // was sent to us by a program (c.sigcode() == _SI_USER);
// in that case, if we didn't handle it in sigsend, we exit now.
if flags&(_SigThrow|_SigPanic) == 0 {
return
@@ -929,7 +929,7 @@ func raisebadsignal(sig uint32, c *sigctxt) {
//
// On FreeBSD, the libthr sigaction code prevents
// this from working so we fall through to raise.
- if GOOS != "freebsd" && (isarchive || islibrary) && handler == _SIG_DFL && !c.sigFromUser() {
+ if GOOS != "freebsd" && (isarchive || islibrary) && handler == _SIG_DFL && c.sigcode() != _SI_USER {
return
}
@@ -1110,7 +1110,7 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
// Unfortunately, user generated SIGPIPEs will also be forwarded, because si_code
// is set to _SI_USER even for a SIGPIPE raised from a write to a closed socket
// or pipe.
- if (c.sigFromUser() || flags&_SigPanic == 0) && sig != _SIGPIPE {
+ if (c.sigcode() == _SI_USER || flags&_SigPanic == 0) && sig != _SIGPIPE {
return false
}
// Determine if the signal occurred inside Go code. We test that:
diff --git a/src/runtime/testdata/testprogcgo/segv.go b/src/runtime/testdata/testprogcgo/segv.go
index bf5aa313b3..0632475228 100644
--- a/src/runtime/testdata/testprogcgo/segv.go
+++ b/src/runtime/testdata/testprogcgo/segv.go
@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build unix
-// +build unix
+//go:build !plan9 && !windows
+// +build !plan9,!windows
package main
-// #include <unistd.h>
// static void nop() {}
import "C"
-import "syscall"
+import (
+ "syscall"
+ "time"
+)
func init() {
register("Segv", Segv)
@@ -33,8 +35,8 @@ func Segv() {
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
- // Wait for the OS to deliver the signal.
- C.pause()
+ // Give the OS time to deliver the signal.
+ time.Sleep(time.Second)
}
func SegvInCgo() {
@@ -50,6 +52,6 @@ func SegvInCgo() {
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
- // Wait for the OS to deliver the signal.
- C.pause()
+ // Give the OS time to deliver the signal.
+ time.Sleep(time.Second)
}
diff --git a/src/runtime/testdata/testprogcgo/segv_linux.go b/src/runtime/testdata/testprogcgo/segv_linux.go
deleted file mode 100644
index fe93778781..0000000000
--- a/src/runtime/testdata/testprogcgo/segv_linux.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-// #include <unistd.h>
-// static void nop() {}
-import "C"
-
-import "syscall"
-
-func init() {
- register("TgkillSegv", TgkillSegv)
- register("TgkillSegvInCgo", TgkillSegvInCgo)
-}
-
-func TgkillSegv() {
- c := make(chan bool)
- go func() {
- close(c)
- for i := 0; ; i++ {
- // Sum defined in segv.go.
- Sum += i
- }
- }()
-
- <-c
-
- syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV)
-
- // Wait for the OS to deliver the signal.
- C.pause()
-}
-
-func TgkillSegvInCgo() {
- c := make(chan bool)
- go func() {
- close(c)
- for {
- C.nop()
- }
- }()
-
- <-c
-
- syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV)
-
- // Wait for the OS to deliver the signal.
- C.pause()
-}