github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/testdata/testprogcgo/segv_linux.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 // #include <unistd.h> 8 // static void nop() {} 9 import "C" 10 11 import "syscall" 12 13 func init() { 14 register("TgkillSegv", TgkillSegv) 15 register("TgkillSegvInCgo", TgkillSegvInCgo) 16 } 17 18 func TgkillSegv() { 19 c := make(chan bool) 20 go func() { 21 close(c) 22 for i := 0; ; i++ { 23 // Sum defined in segv.go. 24 Sum += i 25 } 26 }() 27 28 <-c 29 30 syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV) 31 32 // Wait for the OS to deliver the signal. 33 C.pause() 34 } 35 36 func TgkillSegvInCgo() { 37 c := make(chan bool) 38 go func() { 39 close(c) 40 for { 41 C.nop() 42 } 43 }() 44 45 <-c 46 47 syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV) 48 49 // Wait for the OS to deliver the signal. 50 C.pause() 51 }