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(Regs64 *r)
13
runtime·printf("rax %X\n", r->rax);
14
runtime·printf("rbx %X\n", r->rbx);
15
runtime·printf("rcx %X\n", r->rcx);
16
runtime·printf("rdx %X\n", r->rdx);
17
runtime·printf("rdi %X\n", r->rdi);
18
runtime·printf("rsi %X\n", r->rsi);
19
runtime·printf("rbp %X\n", r->rbp);
20
runtime·printf("rsp %X\n", r->rsp);
21
runtime·printf("r8 %X\n", r->r8 );
22
runtime·printf("r9 %X\n", r->r9 );
23
runtime·printf("r10 %X\n", r->r10);
24
runtime·printf("r11 %X\n", r->r11);
25
runtime·printf("r12 %X\n", r->r12);
26
runtime·printf("r13 %X\n", r->r13);
27
runtime·printf("r14 %X\n", r->r14);
28
runtime·printf("r15 %X\n", r->r15);
29
runtime·printf("rip %X\n", r->rip);
30
runtime·printf("rflags %X\n", r->rflags);
31
runtime·printf("cs %X\n", r->cs);
32
runtime·printf("fs %X\n", r->fs);
33
runtime·printf("gs %X\n", r->gs);
37
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
51
if(gp != m->g0 && gp != m->gsignal)
52
runtime·sigprof((uint8*)r->rip, (uint8*)r->rsp, nil, gp);
56
t = &runtime·sigtab[sig];
57
if(info->si_code != SI_USER && (t->flags & SigPanic)) {
60
// Work around Leopard bug that doesn't set FPE_INTDIV.
61
// Look at instruction to see if it is a divide.
62
// Not necessary in Snow Leopard (si_code will be != 0).
63
if(sig == SIGFPE && info->si_code == 0) {
65
if((pc[0]&0xF0) == 0x40) // 64-bit REX prefix
67
else if(pc[0] == 0x66) // 16-bit instruction prefix
69
if(pc[0] == 0xF6 || pc[0] == 0xF7)
70
info->si_code = FPE_INTDIV;
73
// Make it look like a call to the signal func.
74
// Have to pass arguments out of band since
75
// augmenting the stack frame would break
76
// the unwinding code.
78
gp->sigcode0 = info->si_code;
79
gp->sigcode1 = (uintptr)info->si_addr;
82
// Only push runtime·sigpanic if r->rip != 0.
83
// If r->rip == 0, probably panicked because of a
84
// call to a nil func. Not pushing that onto sp will
85
// make the trace look like a call to runtime·sigpanic instead.
86
// (Otherwise the trace will end at runtime·sigpanic and we
87
// won't get to see who faulted.)
89
sp = (uintptr*)r->rsp;
93
r->rip = (uintptr)runtime·sigpanic;
97
if(info->si_code == SI_USER || (t->flags & SigNotify))
98
if(runtime·sigsend(sig))
100
if(t->flags & SigKill)
102
if(!(t->flags & SigThrow))
106
runtime·startpanic();
108
if(sig < 0 || sig >= NSIG){
109
runtime·printf("Signal %d\n", sig);
111
runtime·printf("%s\n", runtime·sigtab[sig].name);
114
runtime·printf("pc: %X\n", r->rip);
115
runtime·printf("\n");
117
if(runtime·gotraceback()){
118
runtime·traceback((void*)r->rip, (void*)r->rsp, 0, gp);
119
runtime·tracebackothers(gp);
127
runtime·signalstack(byte *p, int32 n)
134
runtime·sigaltstack(&st, nil);
138
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
142
runtime·memclr((byte*)&sa, sizeof sa);
143
sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
145
sa.sa_flags |= SA_RESTART;
147
sa.sa_tramp = runtime·sigtramp; // runtime·sigtramp's job is to call into real handler
148
*(uintptr*)sa.__sigaction_u = (uintptr)fn;
149
runtime·sigaction(i, &sa, nil);