2010-12-03 05:34:57 +01:00
|
|
|
/* go-signal.c -- signal handling for Go.
|
|
|
|
|
|
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
2011-11-28 06:45:49 +01:00
|
|
|
#include <unistd.h>
|
2011-03-27 21:14:55 +02:00
|
|
|
#include <sys/time.h>
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
#include "runtime.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
#include "go-assert.h"
|
|
|
|
#include "go-panic.h"
|
2013-07-16 08:54:42 +02:00
|
|
|
#include "signal_unix.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-03-27 21:14:55 +02:00
|
|
|
#ifndef SA_RESTART
|
|
|
|
#define SA_RESTART 0
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef USING_SPLIT_STACK
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
extern void __splitstack_getcontext(void *context[10]);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
extern void __splitstack_setcontext(void *context[10]);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
#define N SigNotify
|
|
|
|
#define K SigKill
|
|
|
|
#define T SigThrow
|
2011-12-21 23:24:47 +01:00
|
|
|
#define P SigPanic
|
2012-03-02 17:38:43 +01:00
|
|
|
#define D SigDefault
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
/* Signal actions. This collects the sigtab tables for several
|
|
|
|
different targets from the master library. SIGKILL, SIGCONT, and
|
|
|
|
SIGSTOP are not listed, as we don't want to set signal handlers for
|
|
|
|
them. */
|
|
|
|
|
|
|
|
SigTab runtime_sigtab[] = {
|
|
|
|
#ifdef SIGHUP
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGHUP, N + K },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGINT, N + K },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGQUIT, N + T },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
2011-11-28 06:45:49 +01:00
|
|
|
#ifdef SIGILL
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGILL, T },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTRAP, T },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGABRT, N + T },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
#ifdef SIGBUS
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGBUS, P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGFPE, P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGUSR1, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGSEGV, P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGUSR2, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGPIPE, N },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGALRM, N },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTERM, N + K },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTKFLT
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGSTKFLT, T },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGCHLD, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTSTP, N + D },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTTIN, N + D },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTTOU, N + D },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGURG, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGXCPU, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGXFSZ, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGVTALRM
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGVTALRM, N },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGPROF, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGWINCH, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGIO, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGPWR, N },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGSYS, N },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGEMT
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGEMT, T },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGINFO, N },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTHR
|
2012-03-02 17:38:43 +01:00
|
|
|
{ SIGTHR, N },
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
{ -1, 0 }
|
2010-12-03 05:34:57 +01:00
|
|
|
};
|
2012-03-02 17:38:43 +01:00
|
|
|
#undef N
|
|
|
|
#undef K
|
|
|
|
#undef T
|
2011-12-21 23:24:47 +01:00
|
|
|
#undef P
|
2012-03-02 17:38:43 +01:00
|
|
|
#undef D
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
/* Handle a signal, for cases where we don't panic. We can split the
|
|
|
|
stack here. */
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
void
|
|
|
|
runtime_sighandler (int sig, Siginfo *info,
|
|
|
|
void *context __attribute__ ((unused)), G *gp)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2013-07-16 08:54:42 +02:00
|
|
|
M *m;
|
2010-12-03 05:34:57 +01:00
|
|
|
int i;
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
m = runtime_m ();
|
2012-10-23 06:31:11 +02:00
|
|
|
|
2011-12-13 22:59:26 +01:00
|
|
|
#ifdef SIGPROF
|
2011-03-27 21:14:55 +02:00
|
|
|
if (sig == SIGPROF)
|
|
|
|
{
|
2013-07-23 06:42:09 +02:00
|
|
|
if (m != NULL && gp != m->g0 && gp != m->gsignal)
|
2013-07-16 08:54:42 +02:00
|
|
|
runtime_sigprof ();
|
2011-03-27 21:14:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-12-13 22:59:26 +01:00
|
|
|
#endif
|
2011-03-27 21:14:55 +02:00
|
|
|
|
2013-07-23 06:42:09 +02:00
|
|
|
if (m == NULL)
|
|
|
|
{
|
|
|
|
runtime_badsignal (sig);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
for (i = 0; runtime_sigtab[i].sig != -1; ++i)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2012-03-02 17:38:43 +01:00
|
|
|
SigTab *t;
|
2013-07-16 08:54:42 +02:00
|
|
|
bool notify, crash;
|
2011-11-28 06:45:49 +01:00
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
t = &runtime_sigtab[i];
|
|
|
|
|
|
|
|
if (t->sig != sig)
|
2011-12-21 23:24:47 +01:00
|
|
|
continue;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
notify = false;
|
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
notify = info != NULL && info->si_code == SI_USER;
|
|
|
|
#endif
|
|
|
|
if (notify || (t->flags & SigNotify) != 0)
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
2012-03-02 17:38:43 +01:00
|
|
|
if (__go_sigsend (sig))
|
2011-12-21 23:24:47 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-02 17:38:43 +01:00
|
|
|
if ((t->flags & SigKill) != 0)
|
2011-12-21 23:24:47 +01:00
|
|
|
runtime_exit (2);
|
2012-03-02 17:38:43 +01:00
|
|
|
if ((t->flags & SigThrow) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
runtime_startpanic ();
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
{
|
|
|
|
const char *name = NULL;
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
#ifdef HAVE_STRSIGNAL
|
|
|
|
name = strsignal (sig);
|
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
if (name == NULL)
|
|
|
|
runtime_printf ("Signal %d\n", sig);
|
|
|
|
else
|
|
|
|
runtime_printf ("%s\n", name);
|
|
|
|
}
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
if (m->lockedg != NULL && m->ncgo > 0 && gp == m->g0)
|
|
|
|
{
|
|
|
|
runtime_printf("signal arrived during cgo execution\n");
|
|
|
|
gp = m->lockedg;
|
|
|
|
}
|
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
runtime_printf ("\n");
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
if (runtime_gotraceback (&crash))
|
2012-05-17 07:30:25 +02:00
|
|
|
{
|
|
|
|
G *g;
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
g = runtime_g ();
|
2013-12-03 15:51:07 +01:00
|
|
|
runtime_traceback ();
|
2012-05-17 07:30:25 +02:00
|
|
|
runtime_tracebackothers (g);
|
|
|
|
|
|
|
|
/* The gc library calls runtime_dumpregs here, and provides
|
|
|
|
a function that prints the registers saved in context in
|
|
|
|
a readable form. */
|
|
|
|
}
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
if (crash)
|
|
|
|
runtime_crash ();
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
runtime_exit (2);
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The start of handling a signal which panics. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
sig_panic_leadin (int sig)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sigset_t clear;
|
|
|
|
|
|
|
|
if (runtime_m ()->mallocing)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
runtime_printf ("caught signal while mallocing: %d\n", sig);
|
|
|
|
runtime_throw ("caught signal while mallocing");
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
/* The signal handler blocked signals; unblock them. */
|
|
|
|
i = sigfillset (&clear);
|
|
|
|
__go_assert (i == 0);
|
2013-12-04 02:35:53 +01:00
|
|
|
i = pthread_sigmask (SIG_UNBLOCK, &clear, NULL);
|
2011-12-21 23:24:47 +01:00
|
|
|
__go_assert (i == 0);
|
|
|
|
}
|
2010-12-14 06:19:51 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SA_SIGINFO
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
/* Signal dispatch for signals which panic, on systems which support
|
|
|
|
SA_SIGINFO. This is called on the thread stack, and as such it is
|
|
|
|
permitted to split the stack. */
|
|
|
|
|
|
|
|
static void
|
2013-07-16 08:54:42 +02:00
|
|
|
sig_panic_info_handler (int sig, Siginfo *info, void *context)
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
2012-05-17 07:30:25 +02:00
|
|
|
G *g;
|
|
|
|
|
|
|
|
g = runtime_g ();
|
|
|
|
if (g == NULL || info->si_code == SI_USER)
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
2013-07-16 08:54:42 +02:00
|
|
|
runtime_sighandler (sig, info, context, g);
|
2011-12-21 23:24:47 +01:00
|
|
|
return;
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
g->sig = sig;
|
|
|
|
g->sigcode0 = info->si_code;
|
|
|
|
g->sigcode1 = (uintptr_t) info->si_addr;
|
|
|
|
|
|
|
|
/* It would be nice to set g->sigpc here as the gc library does, but
|
|
|
|
I don't know how to get it portably. */
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
sig_panic_leadin (sig);
|
|
|
|
|
|
|
|
switch (sig)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS:
|
|
|
|
if (info->si_code == BUS_ADRERR && (uintptr_t) info->si_addr < 0x1000)
|
|
|
|
runtime_panicstring ("invalid memory address or "
|
|
|
|
"nil pointer dereference");
|
|
|
|
runtime_printf ("unexpected fault address %p\n", info->si_addr);
|
|
|
|
runtime_throw ("fault");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV:
|
|
|
|
if ((info->si_code == 0
|
|
|
|
|| info->si_code == SEGV_MAPERR
|
|
|
|
|| info->si_code == SEGV_ACCERR)
|
|
|
|
&& (uintptr_t) info->si_addr < 0x1000)
|
|
|
|
runtime_panicstring ("invalid memory address or "
|
|
|
|
"nil pointer dereference");
|
|
|
|
runtime_printf ("unexpected fault address %p\n", info->si_addr);
|
|
|
|
runtime_throw ("fault");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGFPE
|
|
|
|
case SIGFPE:
|
|
|
|
switch (info->si_code)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
case FPE_INTDIV:
|
|
|
|
runtime_panicstring ("integer divide by zero");
|
|
|
|
case FPE_INTOVF:
|
|
|
|
runtime_panicstring ("integer overflow");
|
|
|
|
}
|
|
|
|
runtime_panicstring ("floating point error");
|
|
|
|
#endif
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
/* All signals with SigPanic should be in cases above, and this
|
|
|
|
handler should only be invoked for those signals. */
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
2011-11-28 06:45:49 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#else /* !defined (SA_SIGINFO) */
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
static void
|
|
|
|
sig_panic_handler (int sig)
|
|
|
|
{
|
2012-05-17 07:30:25 +02:00
|
|
|
G *g;
|
|
|
|
|
|
|
|
g = runtime_g ();
|
|
|
|
if (g == NULL)
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
2013-07-16 08:54:42 +02:00
|
|
|
runtime_sighandler (sig, NULL, NULL, g);
|
2011-12-21 23:24:47 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-05-17 07:30:25 +02:00
|
|
|
g->sig = sig;
|
|
|
|
g->sigcode0 = 0;
|
|
|
|
g->sigcode1 = 0;
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
sig_panic_leadin (sig);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS:
|
|
|
|
runtime_panicstring ("invalid memory address or "
|
|
|
|
"nil pointer dereference");
|
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV:
|
|
|
|
runtime_panicstring ("invalid memory address or "
|
|
|
|
"nil pointer dereference");
|
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGFPE
|
|
|
|
case SIGFPE:
|
|
|
|
runtime_panicstring ("integer divide by zero or floating point error");
|
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
/* All signals with SigPanic should be in cases above, and this
|
|
|
|
handler should only be invoked for those signals. */
|
|
|
|
__builtin_unreachable ();
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif /* !defined (SA_SIGINFO) */
|
|
|
|
|
|
|
|
/* A signal handler used for signals which are not going to panic.
|
|
|
|
This is called on the alternate signal stack so it may not split
|
|
|
|
the stack. */
|
|
|
|
|
|
|
|
static void
|
2013-07-16 08:54:42 +02:00
|
|
|
sig_tramp_info (int, Siginfo *, void *) __attribute__ ((no_split_stack));
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
static void
|
2013-07-16 08:54:42 +02:00
|
|
|
sig_tramp_info (int sig, Siginfo *info, void *context)
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
|
|
|
G *gp;
|
|
|
|
M *mp;
|
2013-10-16 15:37:35 +02:00
|
|
|
#ifdef USING_SPLIT_STACK
|
2013-10-14 23:02:52 +02:00
|
|
|
void *stack_context[10];
|
2013-10-16 15:37:35 +02:00
|
|
|
#endif
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
/* We are now running on the stack registered via sigaltstack.
|
|
|
|
(Actually there is a small span of time between runtime_siginit
|
|
|
|
and sigaltstack when the program starts.) */
|
|
|
|
gp = runtime_g ();
|
|
|
|
mp = runtime_m ();
|
|
|
|
|
|
|
|
if (gp != NULL)
|
2011-12-22 20:07:12 +01:00
|
|
|
{
|
|
|
|
#ifdef USING_SPLIT_STACK
|
2013-10-14 23:02:52 +02:00
|
|
|
__splitstack_getcontext (&stack_context[0]);
|
2011-12-22 20:07:12 +01:00
|
|
|
#endif
|
|
|
|
}
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
if (gp != NULL && mp->gsignal != NULL)
|
|
|
|
{
|
|
|
|
/* We are running on the signal stack. Set the split stack
|
|
|
|
context so that the stack guards are checked correctly. */
|
|
|
|
#ifdef USING_SPLIT_STACK
|
|
|
|
__splitstack_setcontext (&mp->gsignal->stack_context[0]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
runtime_sighandler (sig, info, context, gp);
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
/* We are going to return back to the signal trampoline and then to
|
|
|
|
whatever we were doing before we got the signal. Restore the
|
|
|
|
split stack context so that stack guards are checked
|
|
|
|
correctly. */
|
|
|
|
|
|
|
|
if (gp != NULL)
|
|
|
|
{
|
|
|
|
#ifdef USING_SPLIT_STACK
|
2013-10-14 23:02:52 +02:00
|
|
|
__splitstack_setcontext (&stack_context[0]);
|
2011-12-21 23:24:47 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
#ifndef SA_SIGINFO
|
|
|
|
|
|
|
|
static void sig_tramp (int sig) __attribute__ ((no_split_stack));
|
|
|
|
|
|
|
|
static void
|
|
|
|
sig_tramp (int sig)
|
|
|
|
{
|
|
|
|
sig_tramp_info (sig, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
void
|
2013-07-16 08:54:42 +02:00
|
|
|
runtime_setsig (int32 i, GoSighandler *fn, bool restart)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
struct sigaction sa;
|
2012-03-02 17:38:43 +01:00
|
|
|
int r;
|
|
|
|
SigTab *t;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
r = sigfillset (&sa.sa_mask);
|
|
|
|
__go_assert (r == 0);
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
t = &runtime_sigtab[i];
|
2011-12-21 23:24:47 +01:00
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
if ((t->flags & SigPanic) == 0)
|
2011-03-27 21:14:55 +02:00
|
|
|
{
|
2013-07-16 08:54:42 +02:00
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
|
|
|
|
if (fn == runtime_sighandler)
|
|
|
|
fn = (void *) sig_tramp_info;
|
|
|
|
sa.sa_sigaction = (void *) fn;
|
|
|
|
#else
|
2012-03-02 17:38:43 +01:00
|
|
|
sa.sa_flags = SA_ONSTACK;
|
2013-07-16 08:54:42 +02:00
|
|
|
if (fn == runtime_sighandler)
|
|
|
|
fn = (void *) sig_tramp;
|
|
|
|
sa.sa_handler = (void *) fn;
|
|
|
|
#endif
|
2011-03-27 21:14:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-02 17:38:43 +01:00
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
2013-07-16 08:54:42 +02:00
|
|
|
if (fn == runtime_sighandler)
|
|
|
|
fn = (void *) sig_panic_info_handler;
|
|
|
|
sa.sa_sigaction = (void *) fn;
|
2012-03-02 17:38:43 +01:00
|
|
|
#else
|
|
|
|
sa.sa_flags = 0;
|
2013-07-16 08:54:42 +02:00
|
|
|
if (fn == runtime_sighandler)
|
|
|
|
fn = (void *) sig_panic_handler;
|
|
|
|
sa.sa_handler = (void *) fn;
|
2011-12-13 22:59:26 +01:00
|
|
|
#endif
|
2012-03-02 17:38:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (restart)
|
|
|
|
sa.sa_flags |= SA_RESTART;
|
2011-03-27 21:14:55 +02:00
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
if (sigaction (t->sig, &sa, NULL) != 0)
|
|
|
|
__go_assert (0);
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2011-05-20 02:18:15 +02:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
GoSighandler*
|
|
|
|
runtime_getsig (int32 i)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
int r;
|
|
|
|
SigTab *t;
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
|
|
|
|
|
|
|
r = sigemptyset (&sa.sa_mask);
|
|
|
|
__go_assert (r == 0);
|
|
|
|
|
|
|
|
t = &runtime_sigtab[i];
|
|
|
|
|
|
|
|
if (sigaction (t->sig, NULL, &sa) != 0)
|
|
|
|
runtime_throw ("sigaction read failure");
|
|
|
|
|
|
|
|
if ((void *) sa.sa_handler == sig_tramp_info)
|
|
|
|
return runtime_sighandler;
|
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
if ((void *) sa.sa_handler == sig_panic_info_handler)
|
|
|
|
return runtime_sighandler;
|
|
|
|
#else
|
|
|
|
if ((void *) sa.sa_handler == sig_tramp
|
|
|
|
|| (void *) sa.sa_handler == sig_panic_handler)
|
|
|
|
return runtime_sighandler;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (void *) sa.sa_handler;
|
|
|
|
}
|
|
|
|
|
2011-05-20 02:18:15 +02:00
|
|
|
/* Used by the os package to raise SIGPIPE. */
|
|
|
|
|
2013-01-24 20:44:23 +01:00
|
|
|
void os_sigpipe (void) __asm__ (GOSYM_PREFIX "os.sigpipe");
|
2011-05-20 02:18:15 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
os_sigpipe (void)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
|
|
|
|
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
|
|
|
|
i = sigemptyset (&sa.sa_mask);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
|
|
|
if (sigaction (SIGPIPE, &sa, NULL) != 0)
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
raise (SIGPIPE);
|
|
|
|
}
|
2012-03-02 17:38:43 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
runtime_setprof(bool on)
|
|
|
|
{
|
|
|
|
USED(on);
|
|
|
|
}
|