~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/pkg/runtime/signal_linux_amd64.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
4
 
 
5
 
#include "runtime.h"
6
 
#include "defs_GOOS_GOARCH.h"
7
 
#include "signals_GOOS.h"
8
 
#include "os_GOOS.h"
9
 
 
10
 
void
11
 
runtime·dumpregs(Sigcontext *r)
12
 
{
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);
34
 
}
35
 
 
36
 
/*
37
 
 * This assembler routine takes the args from registers, puts them on the stack,
38
 
 * and calls sighandler().
39
 
 */
40
 
extern void runtime·sigtramp(void);
41
 
extern void runtime·sigreturn(void);    // calls runtime·sigreturn
42
 
 
43
 
void
44
 
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
45
 
{
46
 
        Ucontext *uc;
47
 
        Mcontext *mc;
48
 
        Sigcontext *r;
49
 
        uintptr *sp;
50
 
        SigTab *t;
51
 
 
52
 
        uc = context;
53
 
        mc = &uc->uc_mcontext;
54
 
        r = (Sigcontext*)mc;    // same layout, more conveient names
55
 
 
56
 
        if(sig == SIGPROF) {
57
 
                runtime·sigprof((uint8*)r->rip, (uint8*)r->rsp, nil, gp);
58
 
                return;
59
 
        }
60
 
 
61
 
        t = &runtime·sigtab[sig];
62
 
        if(info->si_code != SI_USER && (t->flags & SigPanic)) {
63
 
                if(gp == nil)
64
 
                        goto Throw;
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.
69
 
                gp->sig = sig;
70
 
                gp->sigcode0 = info->si_code;
71
 
                gp->sigcode1 = ((uintptr*)info)[2];
72
 
                gp->sigpc = r->rip;
73
 
 
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.)
80
 
                if(r->rip != 0) {
81
 
                        sp = (uintptr*)r->rsp;
82
 
                        *--sp = r->rip;
83
 
                        r->rsp = (uintptr)sp;
84
 
                }
85
 
                r->rip = (uintptr)runtime·sigpanic;
86
 
                return;
87
 
        }
88
 
 
89
 
        if(info->si_code == SI_USER || (t->flags & SigNotify))
90
 
                if(runtime·sigsend(sig))
91
 
                        return;
92
 
        if(t->flags & SigKill)
93
 
                runtime·exit(2);
94
 
        if(!(t->flags & SigThrow))
95
 
                return;
96
 
 
97
 
Throw:
98
 
        runtime·startpanic();
99
 
 
100
 
        if(sig < 0 || sig >= NSIG)
101
 
                runtime·printf("Signal %d\n", sig);
102
 
        else
103
 
                runtime·printf("%s\n", runtime·sigtab[sig].name);
104
 
 
105
 
        runtime·printf("PC=%X\n", r->rip);
106
 
        runtime·printf("\n");
107
 
 
108
 
        if(runtime·gotraceback()){
109
 
                runtime·traceback((void*)r->rip, (void*)r->rsp, 0, gp);
110
 
                runtime·tracebackothers(gp);
111
 
                runtime·dumpregs(r);
112
 
        }
113
 
 
114
 
        runtime·exit(2);
115
 
}
116
 
 
117
 
void
118
 
runtime·signalstack(byte *p, int32 n)
119
 
{
120
 
        Sigaltstack st;
121
 
 
122
 
        st.ss_sp = p;
123
 
        st.ss_size = n;
124
 
        st.ss_flags = 0;
125
 
        runtime·sigaltstack(&st, nil);
126
 
}
127
 
 
128
 
void
129
 
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
130
 
{
131
 
        Sigaction sa;
132
 
 
133
 
        runtime·memclr((byte*)&sa, sizeof sa);
134
 
        sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
135
 
        if(restart)
136
 
                sa.sa_flags |= SA_RESTART;
137
 
        sa.sa_mask = ~0ULL;
138
 
        sa.sa_restorer = (void*)runtime·sigreturn;
139
 
        if(fn == runtime·sighandler)
140
 
                fn = (void*)runtime·sigtramp;
141
 
        sa.sa_handler = fn;
142
 
        runtime·rt_sigaction(i, &sa, nil, 8);
143
 
}