1 /* go-signal.c -- signal handling for Go.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
10 #include "go-assert.h"
12 #include "go-signal.h"
22 /* What to do for a signal. */
28 /* Nonzero if the signal should be ignored. */
32 /* What to do for signals. */
34 static struct sigtab signals[] =
94 /* The Go signal handler. */
102 /* FIXME: Should check siginfo for more information when
109 msg = "invalid memory address or nil pointer dereference";
115 msg = "integer divide by zero or floating point error";
121 msg = "invalid memory address or nil pointer dereference";
133 if (__sync_bool_compare_and_swap (&m->mallocing, 1, 1))
135 fprintf (stderr, "caught signal while mallocing: %s\n", msg);
139 /* The signal handler blocked signals; unblock them. */
140 i = sigfillset (&clear);
141 __go_assert (i == 0);
142 i = sigprocmask (SIG_UNBLOCK, &clear, NULL);
143 __go_assert (i == 0);
145 __go_panic_msg (msg);
148 if (__go_sigsend (sig))
150 for (i = 0; signals[i].sig != -1; ++i)
152 if (signals[i].sig == sig)
156 if (signals[i].ignore)
159 memset (&sa, 0, sizeof sa);
161 sa.sa_handler = SIG_DFL;
163 i = sigemptyset (&sa.sa_mask);
164 __go_assert (i == 0);
166 if (sigaction (sig, &sa, NULL) != 0)
176 /* Initialize signal handling for Go. This is called when the program
187 memset (&sa, 0, sizeof sa);
189 sa.sa_handler = sighandler;
191 i = sigfillset (&sa.sa_mask);
192 __go_assert (i == 0);
194 for (i = 0; signals[i].sig != -1; ++i)
195 if (sigaction (signals[i].sig, &sa, NULL) != 0)