* tree-vect-loop-manip.c (vect_do_peeling): Do not use
[official-gcc.git] / libgo / misc / cgo / testcarchive / main_unix.c
blobb23ac1c2428bac3abcf1d242c44b3c42e19abcd8
1 // Copyright 2015 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.
5 #include <signal.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 struct sigaction sa;
12 struct sigaction osa;
14 static void (*oldHandler)(int, siginfo_t*, void*);
16 static void handler(int signo, siginfo_t* info, void* ctxt) {
17 if (oldHandler) {
18 oldHandler(signo, info, ctxt);
22 int install_handler() {
23 // Install our own signal handler.
24 memset(&sa, 0, sizeof sa);
25 sa.sa_sigaction = handler;
26 sigemptyset(&sa.sa_mask);
27 sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
28 memset(&osa, 0, sizeof osa);
29 sigemptyset(&osa.sa_mask);
30 if (sigaction(SIGSEGV, &sa, &osa) < 0) {
31 perror("sigaction");
32 return 2;
34 if (osa.sa_handler == SIG_DFL) {
35 fprintf(stderr, "Go runtime did not install signal handler\n");
36 return 2;
38 // gccgo does not set SA_ONSTACK for SIGSEGV.
39 if (getenv("GCCGO") == "" && (osa.sa_flags&SA_ONSTACK) == 0) {
40 fprintf(stderr, "Go runtime did not install signal handler\n");
41 return 2;
43 oldHandler = osa.sa_sigaction;
45 return 0;
48 int check_handler() {
49 if (sigaction(SIGSEGV, NULL, &sa) < 0) {
50 perror("sigaction check");
51 return 2;
53 if (sa.sa_sigaction != handler) {
54 fprintf(stderr, "ERROR: wrong signal handler: %p != %p\n", sa.sa_sigaction, handler);
55 return 2;
57 return 0;