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"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#define C SigCatch
|
|
|
|
#define I SigIgnore
|
|
|
|
#define R SigRestart
|
|
|
|
#define Q SigQueue
|
|
|
|
#define P SigPanic
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
{ SIGHUP, Q + R },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
|
|
|
{ SIGINT, Q + R },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
{ SIGQUIT, C },
|
|
|
|
#endif
|
2011-11-28 06:45:49 +01:00
|
|
|
#ifdef SIGILL
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGILL, C },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGTRAP, C },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGABRT, C },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
2010-12-03 05:34:57 +01:00
|
|
|
#ifdef SIGBUS
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGBUS, C + P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGFPE, C + P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGUSR1, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGSEGV, C + P },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGUSR2, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGPIPE, I },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
|
|
|
{ SIGALRM, Q + I + R },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
|
|
|
{ SIGTERM, Q + R },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTKFLT
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGSTKFLT, C },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGCHLD, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGTSTP, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGTTIN, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGTTOU, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGURG, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGXCPU, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGXFSZ, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGVTALRM
|
|
|
|
{ SIGVTALRM, Q + I + R },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGPROF, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGWINCH, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGIO, Q + I + R },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGPWR, Q + I + R },
|
2011-11-28 06:45:49 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2011-12-21 23:24:47 +01:00
|
|
|
{ SIGSYS, C },
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
2011-12-21 23:24:47 +01:00
|
|
|
#ifdef SIGEMT
|
|
|
|
{ SIGEMT, C },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
|
|
|
{ SIGINFO, Q + I + R },
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTHR
|
|
|
|
{ SIGTHR, Q + I + R },
|
|
|
|
#endif
|
|
|
|
{ -1, 0 }
|
2010-12-03 05:34:57 +01:00
|
|
|
};
|
2011-12-21 23:24:47 +01:00
|
|
|
#undef C
|
|
|
|
#undef I
|
|
|
|
#undef R
|
|
|
|
#undef Q
|
|
|
|
#undef P
|
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
|
|
|
|
|
|
|
static void
|
2011-12-21 23:24:47 +01:00
|
|
|
sig_handler (int sig)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-12-13 22:59:26 +01:00
|
|
|
#ifdef SIGPROF
|
2011-03-27 21:14:55 +02:00
|
|
|
if (sig == SIGPROF)
|
|
|
|
{
|
|
|
|
/* FIXME. */
|
2011-11-28 06:45:49 +01:00
|
|
|
runtime_sigprof (0, 0, nil, nil);
|
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
|
|
|
|
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
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
struct sigaction sa;
|
2011-11-28 06:45:49 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
if (runtime_sigtab[i].sig != sig)
|
|
|
|
continue;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
if ((runtime_sigtab[i].flags & SigQueue) != 0)
|
|
|
|
{
|
|
|
|
if (__go_sigsend (sig)
|
|
|
|
|| (runtime_sigtab[sig].flags & SigIgnore) != 0)
|
|
|
|
return;
|
|
|
|
runtime_exit (2); // SIGINT, SIGTERM, etc
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
if (runtime_panicking)
|
|
|
|
runtime_exit (2);
|
|
|
|
runtime_panicking = 1;
|
|
|
|
|
|
|
|
/* We should do a stack backtrace here. Until we can do that,
|
|
|
|
we reraise the signal in order to get a slightly better
|
|
|
|
report from the shell. */
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
|
|
|
|
i = sigemptyset (&sa.sa_mask);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
|
|
|
if (sigaction (sig, &sa, NULL) != 0)
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
raise (sig);
|
|
|
|
|
|
|
|
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);
|
|
|
|
i = sigprocmask (SIG_UNBLOCK, &clear, NULL);
|
|
|
|
__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
|
|
|
|
sig_panic_info_handler (int sig, siginfo_t *info,
|
|
|
|
void *context __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
if (runtime_g () == NULL)
|
|
|
|
{
|
|
|
|
sig_handler (sig);
|
|
|
|
return;
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (runtime_g () == NULL)
|
|
|
|
{
|
|
|
|
sig_handler (sig);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
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) */
|
|
|
|
|
|
|
|
/* Ignore a signal. This is called on the alternate signal stack so
|
|
|
|
it may not split the stack. */
|
|
|
|
|
|
|
|
static void sig_ignore (int) __attribute__ ((no_split_stack));
|
2011-11-28 06:45:49 +01:00
|
|
|
|
|
|
|
static void
|
2011-12-01 18:08:12 +01:00
|
|
|
sig_ignore (int sig __attribute__ ((unused)))
|
2011-11-28 06:45:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
/* 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
|
|
|
|
sig_tramp (int) __attribute__ ((no_split_stack));
|
|
|
|
|
|
|
|
static void
|
|
|
|
sig_tramp (int sig)
|
|
|
|
{
|
|
|
|
G *gp;
|
|
|
|
M *mp;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
__splitstack_getcontext (&gp->stack_context[0]);
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
|
|
|
sig_handler (sig);
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
__splitstack_setcontext (&gp->stack_context[0]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
/* Initialize signal handling for Go. This is called when the program
|
|
|
|
starts. */
|
|
|
|
|
|
|
|
void
|
2011-11-28 06:45:49 +01:00
|
|
|
runtime_initsig (int32 queue)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
siginit ();
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
|
|
|
|
|
|
|
i = sigfillset (&sa.sa_mask);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
2011-12-21 23:24:47 +01:00
|
|
|
for (i = 0; runtime_sigtab[i].sig != -1; ++i)
|
2011-03-27 21:14:55 +02:00
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
if (runtime_sigtab[i].flags == 0)
|
|
|
|
continue;
|
|
|
|
if ((runtime_sigtab[i].flags & SigQueue) != queue)
|
2011-11-28 06:45:49 +01:00
|
|
|
continue;
|
2011-12-21 23:24:47 +01:00
|
|
|
|
|
|
|
if ((runtime_sigtab[i].flags & (SigCatch | SigQueue)) != 0)
|
|
|
|
{
|
|
|
|
if ((runtime_sigtab[i].flags & SigPanic) == 0)
|
|
|
|
{
|
|
|
|
sa.sa_flags = SA_ONSTACK;
|
|
|
|
sa.sa_handler = sig_tramp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef SA_SIGINFO
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
sa.sa_sigaction = sig_panic_info_handler;
|
|
|
|
#else
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
sa.sa_handler = sig_panic_handler;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2011-11-28 06:45:49 +01:00
|
|
|
else
|
2011-12-21 23:24:47 +01:00
|
|
|
{
|
|
|
|
sa.sa_flags = SA_ONSTACK;
|
|
|
|
sa.sa_handler = sig_ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((runtime_sigtab[i].flags & SigRestart) != 0)
|
|
|
|
sa.sa_flags |= SA_RESTART;
|
|
|
|
|
|
|
|
if (sigaction (runtime_sigtab[i].sig, &sa, NULL) != 0)
|
2011-03-27 21:14:55 +02:00
|
|
|
__go_assert (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime_resetcpuprofiler(int32 hz)
|
|
|
|
{
|
2011-12-13 22:59:26 +01:00
|
|
|
#ifdef SIGPROF
|
2011-03-27 21:14:55 +02:00
|
|
|
struct itimerval it;
|
|
|
|
struct sigaction sa;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset (&it, 0, sizeof it);
|
|
|
|
|
|
|
|
memset (&sa, 0, sizeof sa);
|
|
|
|
i = sigfillset (&sa.sa_mask);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
|
|
|
if (hz == 0)
|
|
|
|
{
|
|
|
|
i = setitimer (ITIMER_PROF, &it, NULL);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
i = sigaction (SIGPROF, &sa, NULL);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-21 23:24:47 +01:00
|
|
|
sa.sa_handler = sig_handler;
|
2011-03-27 21:14:55 +02:00
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
i = sigaction (SIGPROF, &sa, NULL);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
|
|
|
|
it.it_interval.tv_sec = 0;
|
|
|
|
it.it_interval.tv_usec = 1000000 / hz;
|
|
|
|
it.it_value = it.it_interval;
|
|
|
|
i = setitimer (ITIMER_PROF, &it, NULL);
|
|
|
|
__go_assert (i == 0);
|
|
|
|
}
|
2011-12-13 22:59:26 +01:00
|
|
|
#endif
|
2011-03-27 21:14:55 +02:00
|
|
|
|
2011-11-28 06:45:49 +01:00
|
|
|
runtime_m()->profilehz = hz;
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2011-05-20 02:18:15 +02:00
|
|
|
|
|
|
|
/* Used by the os package to raise SIGPIPE. */
|
|
|
|
|
|
|
|
void os_sigpipe (void) __asm__ ("libgo_os.os.sigpipe");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|