~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

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 "os_GOOS.h"
8
 
#include "signals_GOOS.h"
9
 
 
10
 
void
11
 
runtime·dumpregs(Regs64 *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->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);
34
 
}
35
 
 
36
 
void
37
 
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
38
 
{
39
 
        Ucontext *uc;
40
 
        Mcontext64 *mc;
41
 
        Regs64 *r;
42
 
        uintptr *sp;
43
 
        byte *pc;
44
 
        SigTab *t;
45
 
 
46
 
        uc = context;
47
 
        mc = uc->uc_mcontext;
48
 
        r = &mc->ss;
49
 
 
50
 
        if(sig == SIGPROF) {
51
 
                if(gp != m->g0 && gp != m->gsignal)
52
 
                        runtime·sigprof((uint8*)r->rip, (uint8*)r->rsp, nil, gp);
53
 
                return;
54
 
        }
55
 
 
56
 
        t = &runtime·sigtab[sig];
57
 
        if(info->si_code != SI_USER && (t->flags & SigPanic)) {
58
 
                if(gp == nil)
59
 
                        goto Throw;
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) {
64
 
                        pc = (byte*)r->rip;
65
 
                        if((pc[0]&0xF0) == 0x40)        // 64-bit REX prefix
66
 
                                pc++;
67
 
                        else if(pc[0] == 0x66)  // 16-bit instruction prefix
68
 
                                pc++;
69
 
                        if(pc[0] == 0xF6 || pc[0] == 0xF7)
70
 
                                info->si_code = FPE_INTDIV;
71
 
                }
72
 
 
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.
77
 
                gp->sig = sig;
78
 
                gp->sigcode0 = info->si_code;
79
 
                gp->sigcode1 = (uintptr)info->si_addr;
80
 
                gp->sigpc = r->rip;
81
 
 
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.)
88
 
                if(r->rip != 0) {
89
 
                        sp = (uintptr*)r->rsp;
90
 
                        *--sp = r->rip;
91
 
                        r->rsp = (uintptr)sp;
92
 
                }
93
 
                r->rip = (uintptr)runtime·sigpanic;
94
 
                return;
95
 
        }
96
 
 
97
 
        if(info->si_code == SI_USER || (t->flags & SigNotify))
98
 
                if(runtime·sigsend(sig))
99
 
                        return;
100
 
        if(t->flags & SigKill)
101
 
                runtime·exit(2);
102
 
        if(!(t->flags & SigThrow))
103
 
                return;
104
 
 
105
 
Throw:
106
 
        runtime·startpanic();
107
 
 
108
 
        if(sig < 0 || sig >= NSIG){
109
 
                runtime·printf("Signal %d\n", sig);
110
 
        }else{
111
 
                runtime·printf("%s\n", runtime·sigtab[sig].name);
112
 
        }
113
 
 
114
 
        runtime·printf("pc: %X\n", r->rip);
115
 
        runtime·printf("\n");
116
 
 
117
 
        if(runtime·gotraceback()){
118
 
                runtime·traceback((void*)r->rip, (void*)r->rsp, 0, gp);
119
 
                runtime·tracebackothers(gp);
120
 
                runtime·dumpregs(r);
121
 
        }
122
 
 
123
 
        runtime·exit(2);
124
 
}
125
 
 
126
 
void
127
 
runtime·signalstack(byte *p, int32 n)
128
 
{
129
 
        StackT st;
130
 
 
131
 
        st.ss_sp = p;
132
 
        st.ss_size = n;
133
 
        st.ss_flags = 0;
134
 
        runtime·sigaltstack(&st, nil);
135
 
}
136
 
 
137
 
void
138
 
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
139
 
{
140
 
        Sigaction sa;
141
 
 
142
 
        runtime·memclr((byte*)&sa, sizeof sa);
143
 
        sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
144
 
        if(restart)
145
 
                sa.sa_flags |= SA_RESTART;
146
 
        sa.sa_mask = ~0ULL;
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);
150
 
}