diff options
| author | Ian Lance Taylor <iant@golang.org> | 2022-09-20 12:24:07 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-21 01:56:24 +0000 |
| commit | d11c58eedbee29b4912dd50508b36ad15ebb739e (patch) | |
| tree | 9306af01cc8b15d02076420e86dc8db063712526 /src/runtime/testdata | |
| parent | fec83c8a7d1a3bb5f63366acd55f83ed8782bff0 (diff) | |
| download | go-d11c58eedbee29b4912dd50508b36ad15ebb739e.tar.xz | |
runtime: treat SI_TKILL like SI_USER on Linux
On Linux a signal sent using tgkill will have si_code == SI_TKILL,
not SI_USER. Treat the two cases the same. Add a Linux-specific test.
Change the test to use the C pause function rather than sleeping
for a second, as that achieves the same effect.
This is a roll forward of CL 431255 which was rolled back in CL 431715.
This new version skips flaky tests on more systems, and marks a new method
nosplit.
Change-Id: Ibf2d3e6fc43d63d0a71afa8fcca6a11fda03f291
Reviewed-on: https://go-review.googlesource.com/c/go/+/432136
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/testdata')
| -rw-r--r-- | src/runtime/testdata/testprogcgo/segv.go | 18 | ||||
| -rw-r--r-- | src/runtime/testdata/testprogcgo/segv_linux.go | 51 |
2 files changed, 59 insertions, 10 deletions
diff --git a/src/runtime/testdata/testprogcgo/segv.go b/src/runtime/testdata/testprogcgo/segv.go index 0632475228..bf5aa313b3 100644 --- a/src/runtime/testdata/testprogcgo/segv.go +++ b/src/runtime/testdata/testprogcgo/segv.go @@ -2,18 +2,16 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !plan9 && !windows -// +build !plan9,!windows +//go:build unix +// +build unix package main +// #include <unistd.h> // static void nop() {} import "C" -import ( - "syscall" - "time" -) +import "syscall" func init() { register("Segv", Segv) @@ -35,8 +33,8 @@ func Segv() { syscall.Kill(syscall.Getpid(), syscall.SIGSEGV) - // Give the OS time to deliver the signal. - time.Sleep(time.Second) + // Wait for the OS to deliver the signal. + C.pause() } func SegvInCgo() { @@ -52,6 +50,6 @@ func SegvInCgo() { syscall.Kill(syscall.Getpid(), syscall.SIGSEGV) - // Give the OS time to deliver the signal. - time.Sleep(time.Second) + // Wait for the OS to deliver the signal. + C.pause() } diff --git a/src/runtime/testdata/testprogcgo/segv_linux.go b/src/runtime/testdata/testprogcgo/segv_linux.go new file mode 100644 index 0000000000..fe93778781 --- /dev/null +++ b/src/runtime/testdata/testprogcgo/segv_linux.go @@ -0,0 +1,51 @@ +// 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() +} |
