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"
7
#include "signals_GOOS.h"
11
runtime·dumpregs(Sigcontext *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->eflags);
31
runtime·printf("cs %X\n", (uint64)r->cs);
32
runtime·printf("fs %X\n", (uint64)r->fs);
33
runtime·printf("gs %X\n", (uint64)r->gs);
37
* This assembler routine takes the args from registers, puts them on the stack,
38
* and calls sighandler().
40
extern void runtime·sigtramp(void);
41
extern void runtime·sigreturn(void); // calls runtime·sigreturn
44
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
53
mc = &uc->uc_mcontext;
54
r = (Sigcontext*)mc; // same layout, more conveient names
57
runtime·sigprof((uint8*)r->rip, (uint8*)r->rsp, nil, gp);
61
t = &runtime·sigtab[sig];
62
if(info->si_code != SI_USER && (t->flags & SigPanic)) {
65
// Make it look like a call to the signal func.
66
// Have to pass arguments out of band since
67
// augmenting the stack frame would break
68
// the unwinding code.
70
gp->sigcode0 = info->si_code;
71
gp->sigcode1 = ((uintptr*)info)[2];
74
// Only push runtime·sigpanic if r->rip != 0.
75
// If r->rip == 0, probably panicked because of a
76
// call to a nil func. Not pushing that onto sp will
77
// make the trace look like a call to runtime·sigpanic instead.
78
// (Otherwise the trace will end at runtime·sigpanic and we
79
// won't get to see who faulted.)
81
sp = (uintptr*)r->rsp;
85
r->rip = (uintptr)runtime·sigpanic;
89
if(info->si_code == SI_USER || (t->flags & SigNotify))
90
if(runtime·sigsend(sig))
92
if(t->flags & SigKill)
94
if(!(t->flags & SigThrow))
100
if(sig < 0 || sig >= NSIG)
101
runtime·printf("Signal %d\n", sig);
103
runtime·printf("%s\n", runtime·sigtab[sig].name);
105
runtime·printf("PC=%X\n", r->rip);
106
runtime·printf("\n");
108
if(runtime·gotraceback()){
109
runtime·traceback((void*)r->rip, (void*)r->rsp, 0, gp);
110
runtime·tracebackothers(gp);
118
runtime·signalstack(byte *p, int32 n)
125
runtime·sigaltstack(&st, nil);
129
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
133
runtime·memclr((byte*)&sa, sizeof sa);
134
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
136
sa.sa_flags |= SA_RESTART;
138
sa.sa_restorer = (void*)runtime·sigreturn;
139
if(fn == runtime·sighandler)
140
fn = (void*)runtime·sigtramp;
142
runtime·rt_sigaction(i, &sa, nil, 8);