1
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
6
#include "defs_GOOS_GOARCH.h"
8
#include "signals_GOOS.h"
11
runtime·dumpregs(Regs32 *r)
13
runtime·printf("eax %x\n", r->eax);
14
runtime·printf("ebx %x\n", r->ebx);
15
runtime·printf("ecx %x\n", r->ecx);
16
runtime·printf("edx %x\n", r->edx);
17
runtime·printf("edi %x\n", r->edi);
18
runtime·printf("esi %x\n", r->esi);
19
runtime·printf("ebp %x\n", r->ebp);
20
runtime·printf("esp %x\n", r->esp);
21
runtime·printf("eip %x\n", r->eip);
22
runtime·printf("eflags %x\n", r->eflags);
23
runtime·printf("cs %x\n", r->cs);
24
runtime·printf("fs %x\n", r->fs);
25
runtime·printf("gs %x\n", r->gs);
29
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
43
if(gp != m->g0 && gp != m->gsignal)
44
runtime·sigprof((uint8*)r->eip, (uint8*)r->esp, nil, gp);
48
t = &runtime·sigtab[sig];
49
if(info->si_code != SI_USER && (t->flags & SigPanic)) {
52
// Work around Leopard bug that doesn't set FPE_INTDIV.
53
// Look at instruction to see if it is a divide.
54
// Not necessary in Snow Leopard (si_code will be != 0).
55
if(sig == SIGFPE && info->si_code == 0) {
57
if(pc[0] == 0x66) // 16-bit instruction prefix
59
if(pc[0] == 0xF6 || pc[0] == 0xF7)
60
info->si_code = FPE_INTDIV;
63
// Make it look like a call to the signal func.
64
// Have to pass arguments out of band since
65
// augmenting the stack frame would break
66
// the unwinding code.
68
gp->sigcode0 = info->si_code;
69
gp->sigcode1 = (uintptr)info->si_addr;
72
// Only push runtime·sigpanic if r->eip != 0.
73
// If r->eip == 0, probably panicked because of a
74
// call to a nil func. Not pushing that onto sp will
75
// make the trace look like a call to runtime·sigpanic instead.
76
// (Otherwise the trace will end at runtime·sigpanic and we
77
// won't get to see who faulted.)
79
sp = (uintptr*)r->esp;
83
r->eip = (uintptr)runtime·sigpanic;
87
if(info->si_code == SI_USER || (t->flags & SigNotify))
88
if(runtime·sigsend(sig))
90
if(t->flags & SigKill)
92
if(!(t->flags & SigThrow))
98
if(sig < 0 || sig >= NSIG){
99
runtime·printf("Signal %d\n", sig);
101
runtime·printf("%s\n", runtime·sigtab[sig].name);
104
runtime·printf("pc: %x\n", r->eip);
105
runtime·printf("\n");
107
if(runtime·gotraceback()){
108
runtime·traceback((void*)r->eip, (void*)r->esp, 0, gp);
109
runtime·tracebackothers(gp);
117
runtime·signalstack(byte *p, int32 n)
124
runtime·sigaltstack(&st, nil);
128
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
132
runtime·memclr((byte*)&sa, sizeof sa);
133
sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
135
sa.sa_flags |= SA_RESTART;
137
sa.sa_tramp = (void*)runtime·sigtramp; // runtime·sigtramp's job is to call into real handler
138
*(uintptr*)sa.__sigaction_u = (uintptr)fn;
139
runtime·sigaction(i, &sa, nil);