Source file src/runtime/testdata/testprogcgo/segv_linux.go

     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("TgkillSegvInCgo", TgkillSegvInCgo)
    15  }
    16  
    17  func TgkillSegvInCgo() {
    18  	c := make(chan bool)
    19  	go func() {
    20  		close(c)
    21  		for {
    22  			C.nop()
    23  		}
    24  	}()
    25  
    26  	<-c
    27  
    28  	syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV)
    29  
    30  	// Wait for the OS to deliver the signal.
    31  	C.pause()
    32  }
    33  

View as plain text