From 7c87012f041948af55d323fc5447230c930e79aa Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 15 Sep 2022 11:33:58 -0700 Subject: 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 Run-TryBot: Ian Lance Taylor Reviewed-by: Michael Pratt Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/runtime/testdata/testprogcgo/segv.go | 18 ++++----- src/runtime/testdata/testprogcgo/segv_linux.go | 51 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 src/runtime/testdata/testprogcgo/segv_linux.go (limited to 'src/runtime/testdata') 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 // 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 +// 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() +} -- cgit v1.3-5-g9baa