summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/signal_netbsd_386.c
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-03-04 21:27:36 +0100
committerMichael Stapelberg <michael@stapelberg.de>2013-03-04 21:27:36 +0100
commit04b08da9af0c450d645ab7389d1467308cfc2db8 (patch)
treedb247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/runtime/signal_netbsd_386.c
parent917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff)
downloadgolang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/runtime/signal_netbsd_386.c')
-rw-r--r--src/pkg/runtime/signal_netbsd_386.c122
1 files changed, 77 insertions, 45 deletions
diff --git a/src/pkg/runtime/signal_netbsd_386.c b/src/pkg/runtime/signal_netbsd_386.c
index 39d829484..08744c425 100644
--- a/src/pkg/runtime/signal_netbsd_386.c
+++ b/src/pkg/runtime/signal_netbsd_386.c
@@ -7,76 +7,79 @@
#include "signals_GOOS.h"
#include "os_GOOS.h"
+extern void runtime·lwp_tramp(void);
extern void runtime·sigtramp(void);
typedef struct sigaction {
union {
- void (*__sa_handler)(int32);
- void (*__sa_sigaction)(int32, Siginfo*, void *);
- } __sigaction_u; /* signal handler */
- uint32 sa_mask; /* signal mask to apply */
+ void (*_sa_handler)(int32);
+ void (*_sa_sigaction)(int32, Siginfo*, void *);
+ } _sa_u; /* signal handler */
+ uint32 sa_mask[4]; /* signal mask to apply */
int32 sa_flags; /* see signal options below */
} Sigaction;
void
-runtime·dumpregs(Sigcontext *r)
+runtime·dumpregs(McontextT *mc)
{
- runtime·printf("eax %x\n", r->sc_eax);
- runtime·printf("ebx %x\n", r->sc_ebx);
- runtime·printf("ecx %x\n", r->sc_ecx);
- runtime·printf("edx %x\n", r->sc_edx);
- runtime·printf("edi %x\n", r->sc_edi);
- runtime·printf("esi %x\n", r->sc_esi);
- runtime·printf("ebp %x\n", r->sc_ebp);
- runtime·printf("esp %x\n", r->sc_esp);
- runtime·printf("eip %x\n", r->sc_eip);
- runtime·printf("eflags %x\n", r->sc_eflags);
- runtime·printf("cs %x\n", r->sc_cs);
- runtime·printf("fs %x\n", r->sc_fs);
- runtime·printf("gs %x\n", r->sc_gs);
+ runtime·printf("eax %x\n", mc->__gregs[REG_EAX]);
+ runtime·printf("ebx %x\n", mc->__gregs[REG_EBX]);
+ runtime·printf("ecx %x\n", mc->__gregs[REG_ECX]);
+ runtime·printf("edx %x\n", mc->__gregs[REG_EDX]);
+ runtime·printf("edi %x\n", mc->__gregs[REG_EDI]);
+ runtime·printf("esi %x\n", mc->__gregs[REG_ESI]);
+ runtime·printf("ebp %x\n", mc->__gregs[REG_EBP]);
+ runtime·printf("esp %x\n", mc->__gregs[REG_UESP]);
+ runtime·printf("eip %x\n", mc->__gregs[REG_EIP]);
+ runtime·printf("eflags %x\n", mc->__gregs[REG_EFL]);
+ runtime·printf("cs %x\n", mc->__gregs[REG_CS]);
+ runtime·printf("fs %x\n", mc->__gregs[REG_FS]);
+ runtime·printf("gs %x\n", mc->__gregs[REG_GS]);
}
void
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
{
- Sigcontext *r = context;
+ UcontextT *uc = context;
+ McontextT *mc = &uc->uc_mcontext;
uintptr *sp;
SigTab *t;
if(sig == SIGPROF) {
- runtime·sigprof((uint8*)r->sc_eip, (uint8*)r->sc_esp, nil, gp);
+ runtime·sigprof((uint8*)mc->__gregs[REG_EIP],
+ (uint8*)mc->__gregs[REG_UESP], nil, gp);
return;
}
t = &runtime·sigtab[sig];
- if(info->si_code != SI_USER && (t->flags & SigPanic)) {
- if(gp == nil)
+ if(info->_code != SI_USER && (t->flags & SigPanic)) {
+ if(gp == nil || gp == m->g0)
goto Throw;
// Make it look like a call to the signal func.
- // Have to pass arguments out of band since
+ // We need to pass arguments out of band since
// augmenting the stack frame would break
// the unwinding code.
gp->sig = sig;
- gp->sigcode0 = info->si_code;
- gp->sigcode1 = *(uintptr*)((byte*)info + 12); /* si_addr */
- gp->sigpc = r->sc_eip;
-
- // Only push runtime·sigpanic if r->sc_eip != 0.
- // If r->sc_eip == 0, probably panicked because of a
- // call to a nil func. Not pushing that onto sp will
- // make the trace look like a call to runtime·sigpanic instead.
- // (Otherwise the trace will end at runtime·sigpanic and we
- // won't get to see who faulted.)
- if(r->sc_eip != 0) {
- sp = (uintptr*)r->sc_esp;
- *--sp = r->sc_eip;
- r->sc_esp = (uintptr)sp;
+ gp->sigcode0 = info->_code;
+ gp->sigcode1 = *(uintptr*)&info->_reason[0]; /* _addr */
+ gp->sigpc = mc->__gregs[REG_EIP];
+
+ // Only push runtime·sigpanic if __gregs[REG_EIP] != 0.
+ // If __gregs[REG_EIP] == 0, probably panicked because of a
+ // call to a nil func. Not pushing that onto sp will make the
+ // trace look like a call to runtime·sigpanic instead.
+ // (Otherwise the trace will end at runtime·sigpanic
+ // and we won't get to see who faulted.)
+ if(mc->__gregs[REG_EIP] != 0) {
+ sp = (uintptr*)mc->__gregs[REG_UESP];
+ *--sp = mc->__gregs[REG_EIP];
+ mc->__gregs[REG_UESP] = (uintptr)sp;
}
- r->sc_eip = (uintptr)runtime·sigpanic;
+ mc->__gregs[REG_EIP] = (uintptr)runtime·sigpanic;
return;
}
- if(info->si_code == SI_USER || (t->flags & SigNotify))
+ if(info->_code == SI_USER || (t->flags & SigNotify))
if(runtime·sigsend(sig))
return;
if(t->flags & SigKill)
@@ -92,13 +95,18 @@ Throw:
else
runtime·printf("%s\n", runtime·sigtab[sig].name);
- runtime·printf("PC=%X\n", r->sc_eip);
+ runtime·printf("PC=%X\n", mc->__gregs[REG_EIP]);
+ if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) {
+ runtime·printf("signal arrived during cgo execution\n");
+ gp = m->lockedg;
+ }
runtime·printf("\n");
if(runtime·gotraceback()){
- runtime·traceback((void*)r->sc_eip, (void*)r->sc_esp, 0, gp);
+ runtime·traceback((void*)mc->__gregs[REG_EIP],
+ (void*)mc->__gregs[REG_UESP], 0, gp);
runtime·tracebackothers(gp);
- runtime·dumpregs(r);
+ runtime·dumpregs(mc);
}
runtime·exit(2);
@@ -109,9 +117,11 @@ runtime·signalstack(byte *p, int32 n)
{
Sigaltstack st;
- st.ss_sp = (int8*)p;
+ st.ss_sp = p;
st.ss_size = n;
st.ss_flags = 0;
+ if(p == nil)
+ st.ss_flags = SS_DISABLE;
runtime·sigaltstack(&st, nil);
}
@@ -120,13 +130,35 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
{
Sigaction sa;
+ // If SIGHUP handler is SIG_IGN, assume running
+ // under nohup and do not set explicit handler.
+ if(i == SIGHUP) {
+ runtime·memclr((byte*)&sa, sizeof sa);
+ runtime·sigaction(i, nil, &sa);
+ if(sa._sa_u._sa_sigaction == SIG_IGN)
+ return;
+ }
+
runtime·memclr((byte*)&sa, sizeof sa);
sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
if(restart)
sa.sa_flags |= SA_RESTART;
- sa.sa_mask = ~0ULL;
+ sa.sa_mask[0] = ~0U;
+ sa.sa_mask[1] = ~0U;
+ sa.sa_mask[2] = ~0U;
+ sa.sa_mask[3] = ~0U;
if (fn == runtime·sighandler)
fn = (void*)runtime·sigtramp;
- sa.__sigaction_u.__sa_sigaction = (void*)fn;
+ sa._sa_u._sa_sigaction = (void*)fn;
runtime·sigaction(i, &sa, nil);
}
+
+void
+runtime·lwp_mcontext_init(McontextT *mc, void *stack, M *mp, G *gp, void (*fn)(void))
+{
+ mc->__gregs[REG_EIP] = (uint32)runtime·lwp_tramp;
+ mc->__gregs[REG_UESP] = (uint32)stack;
+ mc->__gregs[REG_EBX] = (uint32)mp;
+ mc->__gregs[REG_EDX] = (uint32)gp;
+ mc->__gregs[REG_ESI] = (uint32)fn;
+}