diff options
| author | Ian Lance Taylor <iant@golang.org> | 2022-09-15 11:33:58 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-17 01:41:08 +0000 |
| commit | 7c87012f041948af55d323fc5447230c930e79aa (patch) | |
| tree | ca7338bb06edf5e9f029c2e134238d187be1befd /src/runtime/testdata | |
| parent | a9ca741d311772efb828c4b4f45e737783a89ca3 (diff) | |
| download | go-7c87012f041948af55d323fc5447230c930e79aa.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.
Change-Id: I2a36646aecabcab9ec42ed9a048b07c2ff0a3987
Reviewed-on: https://go-review.googlesource.com/c/go/+/431255
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
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() +} |
