Source file src/runtime/testdata/testprogcgo/segv.go
1 // Copyright 2020 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 //go:build unix 6 7 package main 8 9 // #include <unistd.h> 10 // static void nop() {} 11 import "C" 12 13 import "syscall" 14 15 func init() { 16 register("SegvInCgo", SegvInCgo) 17 } 18 19 func SegvInCgo() { 20 c := make(chan bool) 21 go func() { 22 close(c) 23 for { 24 C.nop() 25 } 26 }() 27 28 <-c 29 30 syscall.Kill(syscall.Getpid(), syscall.SIGSEGV) 31 32 // Wait for the OS to deliver the signal. 33 C.pause() 34 } 35