github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/runtime/signal_arm.c (about) 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 dragonfly 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 runtime·sigprof((uint8*)SIG_PC(info, ctxt), (uint8*)SIG_SP(info, ctxt), (uint8*)SIG_LR(info, ctxt), gp); 50 return; 51 } 52 53 t = &runtime·sigtab[sig]; 54 if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) { 55 if(gp == nil || gp == m->g0) 56 goto Throw; 57 58 // Make it look like a call to the signal func. 59 // Have to pass arguments out of band since 60 // augmenting the stack frame would break 61 // the unwinding code. 62 gp->sig = sig; 63 gp->sigcode0 = SIG_CODE0(info, ctxt); 64 gp->sigcode1 = SIG_FAULT(info, ctxt); 65 gp->sigpc = SIG_PC(info, ctxt); 66 67 // We arrange lr, and pc to pretend the panicking 68 // function calls sigpanic directly. 69 // Always save LR to stack so that panics in leaf 70 // functions are correctly handled. This smashes 71 // the stack frame but we're not going back there 72 // anyway. 73 SIG_SP(info, ctxt) -= 4; 74 *(uint32*)SIG_SP(info, ctxt) = SIG_LR(info, ctxt); 75 // Don't bother saving PC if it's zero, which is 76 // probably a call to a nil func: the old link register 77 // is more useful in the stack trace. 78 if(gp->sigpc != 0) 79 SIG_LR(info, ctxt) = gp->sigpc; 80 // In case we are panicking from external C code 81 SIG_R10(info, ctxt) = (uintptr)gp; 82 SIG_R9(info, ctxt) = (uintptr)m; 83 SIG_PC(info, ctxt) = (uintptr)runtime·sigpanic; 84 return; 85 } 86 87 if(SIG_CODE0(info, ctxt) == 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 m->throwing = 1; 97 m->caughtsig = gp; 98 if(runtime·panicking) // traceback already printed 99 runtime·exit(2); 100 runtime·panicking = 1; 101 102 if(sig < 0 || sig >= NSIG) 103 runtime·printf("Signal %d\n", sig); 104 else 105 runtime·printf("%s\n", runtime·sigtab[sig].name); 106 107 runtime·printf("PC=%x\n", SIG_PC(info, ctxt)); 108 if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) { 109 runtime·printf("signal arrived during cgo execution\n"); 110 gp = m->lockedg; 111 } 112 runtime·printf("\n"); 113 114 if(runtime·gotraceback(&crash)){ 115 runtime·traceback(SIG_PC(info, ctxt), SIG_SP(info, ctxt), SIG_LR(info, ctxt), gp); 116 runtime·tracebackothers(gp); 117 runtime·printf("\n"); 118 runtime·dumpregs(info, ctxt); 119 } 120 121 if(crash) 122 runtime·crash(); 123 124 runtime·exit(2); 125 }