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

« back to all changes in this revision

Viewing changes to src/pkg/runtime/signal_arm.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
// +build darwin freebsd linux netbsd openbsd
 
6
 
 
7
#include "runtime.h"
 
8
#include "defs_GOOS_GOARCH.h"
 
9
#include "os_GOOS.h"
 
10
#include "signal_GOOS_GOARCH.h"
 
11
#include "signals_GOOS.h"
 
12
 
 
13
void
 
14
runtime·dumpregs(Siginfo *info, void *ctxt)
 
15
{
 
16
        USED(info);
 
17
        USED(ctxt);
 
18
 
 
19
        runtime·printf("trap    %x\n", SIG_TRAP(info, ctxt));
 
20
        runtime·printf("error   %x\n", SIG_ERROR(info, ctxt));
 
21
        runtime·printf("oldmask %x\n", SIG_OLDMASK(info, ctxt));
 
22
        runtime·printf("r0      %x\n", SIG_R0(info, ctxt));
 
23
        runtime·printf("r1      %x\n", SIG_R1(info, ctxt));
 
24
        runtime·printf("r2      %x\n", SIG_R2(info, ctxt));
 
25
        runtime·printf("r3      %x\n", SIG_R3(info, ctxt));
 
26
        runtime·printf("r4      %x\n", SIG_R4(info, ctxt));
 
27
        runtime·printf("r5      %x\n", SIG_R5(info, ctxt));
 
28
        runtime·printf("r6      %x\n", SIG_R6(info, ctxt));
 
29
        runtime·printf("r7      %x\n", SIG_R7(info, ctxt));
 
30
        runtime·printf("r8      %x\n", SIG_R8(info, ctxt));
 
31
        runtime·printf("r9      %x\n", SIG_R9(info, ctxt));
 
32
        runtime·printf("r10     %x\n", SIG_R10(info, ctxt));
 
33
        runtime·printf("fp      %x\n", SIG_FP(info, ctxt));
 
34
        runtime·printf("ip      %x\n", SIG_IP(info, ctxt));
 
35
        runtime·printf("sp      %x\n", SIG_SP(info, ctxt));
 
36
        runtime·printf("lr      %x\n", SIG_LR(info, ctxt));
 
37
        runtime·printf("pc      %x\n", SIG_PC(info, ctxt));
 
38
        runtime·printf("cpsr    %x\n", SIG_CPSR(info, ctxt));
 
39
        runtime·printf("fault   %x\n", SIG_FAULT(info, ctxt));
 
40
}
 
41
 
 
42
void
 
43
runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
 
44
{
 
45
        SigTab *t;
 
46
        bool crash;
 
47
 
 
48
        if(sig == SIGPROF) {
 
49
                if(gp != m->g0 && gp != m->gsignal)
 
50
                        runtime·sigprof((uint8*)SIG_PC(info, ctxt), (uint8*)SIG_SP(info, ctxt), (uint8*)SIG_LR(info, ctxt), gp);
 
51
                return;
 
52
        }
 
53
 
 
54
        t = &runtime·sigtab[sig];
 
55
        if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) {
 
56
                if(gp == nil || gp == m->g0)
 
57
                        goto Throw;
 
58
 
 
59
                // Make it look like a call to the signal func.
 
60
                // Have to pass arguments out of band since
 
61
                // augmenting the stack frame would break
 
62
                // the unwinding code.
 
63
                gp->sig = sig;
 
64
                gp->sigcode0 = SIG_CODE0(info, ctxt);
 
65
                gp->sigcode1 = SIG_FAULT(info, ctxt);
 
66
                gp->sigpc = SIG_PC(info, ctxt);
 
67
 
 
68
                // We arrange lr, and pc to pretend the panicking
 
69
                // function calls sigpanic directly.
 
70
                // Always save LR to stack so that panics in leaf
 
71
                // functions are correctly handled. This smashes
 
72
                // the stack frame but we're not going back there
 
73
                // anyway.
 
74
                SIG_SP(info, ctxt) -= 4;
 
75
                *(uint32*)SIG_SP(info, ctxt) = SIG_LR(info, ctxt);
 
76
                // Don't bother saving PC if it's zero, which is
 
77
                // probably a call to a nil func: the old link register
 
78
                // is more useful in the stack trace.
 
79
                if(gp->sigpc != 0)
 
80
                        SIG_LR(info, ctxt) = gp->sigpc;
 
81
                // In case we are panicking from external C code
 
82
                SIG_R10(info, ctxt) = (uintptr)gp;
 
83
                SIG_R9(info, ctxt) = (uintptr)m;
 
84
                SIG_PC(info, ctxt) = (uintptr)runtime·sigpanic;
 
85
                return;
 
86
        }
 
87
 
 
88
        if(SIG_CODE0(info, ctxt) == SI_USER || (t->flags & SigNotify))
 
89
                if(runtime·sigsend(sig))
 
90
                        return;
 
91
        if(t->flags & SigKill)
 
92
                runtime·exit(2);
 
93
        if(!(t->flags & SigThrow))
 
94
                return;
 
95
 
 
96
Throw:
 
97
        if(runtime·panicking)   // traceback already printed
 
98
                runtime·exit(2);
 
99
        runtime·panicking = 1;
 
100
 
 
101
        if(sig < 0 || sig >= NSIG)
 
102
                runtime·printf("Signal %d\n", sig);
 
103
        else
 
104
                runtime·printf("%s\n", runtime·sigtab[sig].name);
 
105
 
 
106
        runtime·printf("PC=%x\n", SIG_PC(info, ctxt));
 
107
        if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) {
 
108
                runtime·printf("signal arrived during cgo execution\n");
 
109
                gp = m->lockedg;
 
110
        }
 
111
        runtime·printf("\n");
 
112
 
 
113
        if(runtime·gotraceback(&crash)){
 
114
                runtime·traceback((void*)SIG_PC(info, ctxt), (void*)SIG_SP(info, ctxt), (void*)SIG_LR(info, ctxt), gp);
 
115
                runtime·tracebackothers(gp);
 
116
                runtime·printf("\n");
 
117
                runtime·dumpregs(info, ctxt);
 
118
        }
 
119
        
 
120
        if(crash)
 
121
                runtime·crash();
 
122
 
 
123
        runtime·exit(2);
 
124
}