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
[] =
97 /* The Go signal handler. */
105 /* FIXME: Should check siginfo for more information when
112 msg
= "invalid memory address or nil pointer dereference";
118 msg
= "integer divide by zero or floating point error";
124 msg
= "invalid memory address or nil pointer dereference";
136 if (__sync_bool_compare_and_swap (&m
->mallocing
, 1, 1))
138 fprintf (stderr
, "caught signal while mallocing: %s\n", msg
);
142 /* The signal handler blocked signals; unblock them. */
143 i
= sigfillset (&clear
);
144 __go_assert (i
== 0);
145 i
= sigprocmask (SIG_UNBLOCK
, &clear
, NULL
);
146 __go_assert (i
== 0);
148 __go_panic_msg (msg
);
151 if (__go_sigsend (sig
))
153 for (i
= 0; signals
[i
].sig
!= -1; ++i
)
155 if (signals
[i
].sig
== sig
)
159 if (signals
[i
].ignore
)
162 memset (&sa
, 0, sizeof sa
);
164 sa
.sa_handler
= SIG_DFL
;
166 i
= sigemptyset (&sa
.sa_mask
);
167 __go_assert (i
== 0);
169 if (sigaction (sig
, &sa
, NULL
) != 0)
179 /* Initialize signal handling for Go. This is called when the program
190 memset (&sa
, 0, sizeof sa
);
192 sa
.sa_handler
= sighandler
;
194 i
= sigfillset (&sa
.sa_mask
);
195 __go_assert (i
== 0);
197 for (i
= 0; signals
[i
].sig
!= -1; ++i
)
198 if (sigaction (signals
[i
].sig
, &sa
, NULL
) != 0)