~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/runtime/signal_darwin_386.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(Regs32 *r)
12
 
{
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);
26
 
}
27
 
 
28
 
void
29
 
runtime·sighandler(int32 sig, Siginfo *info, void *context, G *gp)
30
 
{
31
 
        Ucontext *uc;
32
 
        Mcontext32 *mc;
33
 
        Regs32 *r;
34
 
        uintptr *sp;
35
 
        byte *pc;
36
 
        SigTab *t;
37
 
 
38
 
        uc = context;
39
 
        mc = uc->uc_mcontext;
40
 
        r = &mc->ss;
41
 
 
42
 
        if(sig == SIGPROF) {
43
 
                if(gp != m->g0 && gp != m->gsignal)
44
 
                        runtime·sigprof((uint8*)r->eip, (uint8*)r->esp, nil, gp);
45
 
                return;
46
 
        }
47
 
 
48
 
        t = &runtime·sigtab[sig];
49
 
        if(info->si_code != SI_USER && (t->flags & SigPanic)) {
50
 
                if(gp == nil)
51
 
                        goto Throw;
52
 
                // Work around Leopard bug that doesn't set FPE_INTDIV.
53
 
                // Look at instruction to see if it is a divide.
54
 
                // Not necessary in Snow Leopard (si_code will be != 0).
55
 
                if(sig == SIGFPE && info->si_code == 0) {
56
 
                        pc = (byte*)r->eip;
57
 
                        if(pc[0] == 0x66)       // 16-bit instruction prefix
58
 
                                pc++;
59
 
                        if(pc[0] == 0xF6 || pc[0] == 0xF7)
60
 
                                info->si_code = FPE_INTDIV;
61
 
                }
62
 
 
63
 
                // Make it look like a call to the signal func.
64
 
                // Have to pass arguments out of band since
65
 
                // augmenting the stack frame would break
66
 
                // the unwinding code.
67
 
                gp->sig = sig;
68
 
                gp->sigcode0 = info->si_code;
69
 
                gp->sigcode1 = (uintptr)info->si_addr;
70
 
                gp->sigpc = r->eip;
71
 
 
72
 
                // Only push runtime·sigpanic if r->eip != 0.
73
 
                // If r->eip == 0, probably panicked because of a
74
 
                // call to a nil func.  Not pushing that onto sp will
75
 
                // make the trace look like a call to runtime·sigpanic instead.
76
 
                // (Otherwise the trace will end at runtime·sigpanic and we
77
 
                // won't get to see who faulted.)
78
 
                if(r->eip != 0) {
79
 
                        sp = (uintptr*)r->esp;
80
 
                        *--sp = r->eip;
81
 
                        r->esp = (uintptr)sp;
82
 
                }
83
 
                r->eip = (uintptr)runtime·sigpanic;
84
 
                return;
85
 
        }
86
 
 
87
 
        if(info->si_code == SI_USER || (t->flags & SigNotify))
88
 
                if(runtime·sigsend(sig))
89
 
                        return;
90
 
        if(t->flags & SigKill)
91
 
                runtime·exit(2);
92
 
        if(!(t->flags & SigThrow))
93
 
                return;
94
 
 
95
 
Throw:
96
 
        runtime·startpanic();
97
 
 
98
 
        if(sig < 0 || sig >= NSIG){
99
 
                runtime·printf("Signal %d\n", sig);
100
 
        }else{
101
 
                runtime·printf("%s\n", runtime·sigtab[sig].name);
102
 
        }
103
 
 
104
 
        runtime·printf("pc: %x\n", r->eip);
105
 
        runtime·printf("\n");
106
 
 
107
 
        if(runtime·gotraceback()){
108
 
                runtime·traceback((void*)r->eip, (void*)r->esp, 0, gp);
109
 
                runtime·tracebackothers(gp);
110
 
                runtime·dumpregs(r);
111
 
        }
112
 
 
113
 
        runtime·exit(2);
114
 
}
115
 
 
116
 
void
117
 
runtime·signalstack(byte *p, int32 n)
118
 
{
119
 
        StackT st;
120
 
 
121
 
        st.ss_sp = p;
122
 
        st.ss_size = n;
123
 
        st.ss_flags = 0;
124
 
        runtime·sigaltstack(&st, nil);
125
 
}
126
 
 
127
 
void
128
 
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
129
 
{
130
 
        Sigaction sa;
131
 
 
132
 
        runtime·memclr((byte*)&sa, sizeof sa);
133
 
        sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
134
 
        if(restart)
135
 
                sa.sa_flags |= SA_RESTART;
136
 
        sa.sa_mask = ~0U;
137
 
        sa.sa_tramp = (void*)runtime·sigtramp;  // runtime·sigtramp's job is to call into real handler
138
 
        *(uintptr*)sa.__sigaction_u = (uintptr)fn;
139
 
        runtime·sigaction(i, &sa, nil);
140
 
}