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.
14 static void (*oldHandler)(int, siginfo_t*, void*);
16 static void handler(int signo, siginfo_t* info, void* ctxt) {
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) {
34 if (osa.sa_handler == SIG_DFL) {
35 fprintf(stderr, "Go runtime did not install signal handler\n");
38 // gccgo does not set SA_ONSTACK for SIGSEGV.
39 if (getenv("GCCGO") == NULL && (osa.sa_flags&SA_ONSTACK) == 0) {
40 fprintf(stderr, "Go runtime did not install signal handler\n");
43 oldHandler = osa.sa_sigaction;
49 if (sigaction(SIGSEGV, NULL, &sa) < 0) {
50 perror("sigaction check");
53 if (sa.sa_sigaction != handler) {
54 fprintf(stderr, "ERROR: wrong signal handler: %p != %p\n", sa.sa_sigaction, handler);