github.com/karrick/go@v0.0.0-20170817181416-d5b0ec858b37/src/runtime/testdata/testprogcgo/catchpanic.go (about) 1 // Copyright 2017 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 // +build !plan9,!windows 6 7 package main 8 9 /* 10 #include <signal.h> 11 #include <stdlib.h> 12 #include <string.h> 13 14 static void abrthandler(int signum) { 15 if (signum == SIGABRT) { 16 exit(0); // success 17 } 18 } 19 20 static void __attribute__ ((constructor)) sigsetup(void) { 21 struct sigaction act; 22 23 if (getenv("CGOCATCHPANIC_INSTALL_HANDLER") == NULL) 24 return; 25 memset(&act, 0, sizeof act); 26 act.sa_handler = abrthandler; 27 sigaction(SIGABRT, &act, NULL); 28 } 29 */ 30 import "C" 31 32 func init() { 33 register("CgoCatchPanic", CgoCatchPanic) 34 } 35 36 // Test that the SIGABRT raised by panic can be caught by an early signal handler. 37 func CgoCatchPanic() { 38 panic("catch me") 39 }