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("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
* This assembler routine takes the args from registers, puts them on the stack,
30
* and calls sighandler().
32
extern void runtime·sigtramp(void);
33
extern void runtime·sigreturn(void); // calls runtime·sigreturn
36
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
47
runtime·sigprof((uint8*)r->eip, (uint8*)r->esp, nil, gp);
51
t = &runtime·sigtab[sig];
52
if(info->si_code != SI_USER && (t->flags & SigPanic)) {
55
// Make it look like a call to the signal func.
56
// Have to pass arguments out of band since
57
// augmenting the stack frame would break
58
// the unwinding code.
60
gp->sigcode0 = info->si_code;
61
gp->sigcode1 = ((uintptr*)info)[3];
64
// Only push runtime·sigpanic if r->eip != 0.
65
// If r->eip == 0, probably panicked because of a
66
// call to a nil func. Not pushing that onto sp will
67
// make the trace look like a call to runtime·sigpanic instead.
68
// (Otherwise the trace will end at runtime·sigpanic and we
69
// won't get to see who faulted.)
71
sp = (uintptr*)r->esp;
75
r->eip = (uintptr)runtime·sigpanic;
79
if(info->si_code == SI_USER || (t->flags & SigNotify))
80
if(runtime·sigsend(sig))
82
if(t->flags & SigKill)
84
if(!(t->flags & SigThrow))
90
if(sig < 0 || sig >= NSIG)
91
runtime·printf("Signal %d\n", sig);
93
runtime·printf("%s\n", runtime·sigtab[sig].name);
95
runtime·printf("PC=%X\n", r->eip);
98
if(runtime·gotraceback()){
99
runtime·traceback((void*)r->eip, (void*)r->esp, 0, gp);
100
runtime·tracebackothers(gp);
108
runtime·signalstack(byte *p, int32 n)
115
runtime·sigaltstack(&st, nil);
119
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
123
runtime·memclr((byte*)&sa, sizeof sa);
124
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
126
sa.sa_flags |= SA_RESTART;
128
sa.sa_restorer = (void*)runtime·sigreturn;
129
if(fn == runtime·sighandler)
130
fn = (void*)runtime·sigtramp;
131
sa.k_sa_handler = fn;
132
runtime·rt_sigaction(i, &sa, nil, 8);
136
#define AT_SYSINFO 32
137
extern uint32 runtime·_vdso;
141
runtime·linux_setup_vdso(int32 argc, void *argv_list)
143
byte **argv = &argv_list;
147
// skip envp to get to ELF auxiliary vector.
148
for(envp = &argv[argc+1]; *envp != nil; envp++)
152
for(auxv=(uint32*)envp; auxv[0] != AT_NULL; auxv += 2) {
153
if(auxv[0] == AT_SYSINFO) {
154
runtime·_vdso = auxv[1];