github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/signal_386.c (about) 1 // Copyright 2013 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 nacl 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("eax %x\n", SIG_EAX(info, ctxt)); 20 runtime·printf("ebx %x\n", SIG_EBX(info, ctxt)); 21 runtime·printf("ecx %x\n", SIG_ECX(info, ctxt)); 22 runtime·printf("edx %x\n", SIG_EDX(info, ctxt)); 23 runtime·printf("edi %x\n", SIG_EDI(info, ctxt)); 24 runtime·printf("esi %x\n", SIG_ESI(info, ctxt)); 25 runtime·printf("ebp %x\n", SIG_EBP(info, ctxt)); 26 runtime·printf("esp %x\n", SIG_ESP(info, ctxt)); 27 runtime·printf("eip %x\n", SIG_EIP(info, ctxt)); 28 runtime·printf("eflags %x\n", SIG_EFLAGS(info, ctxt)); 29 runtime·printf("cs %x\n", SIG_CS(info, ctxt)); 30 runtime·printf("fs %x\n", SIG_FS(info, ctxt)); 31 runtime·printf("gs %x\n", SIG_GS(info, ctxt)); 32 } 33 34 void 35 runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp) 36 { 37 uintptr *sp; 38 SigTab *t; 39 bool crash; 40 41 if(sig == SIGPROF) { 42 runtime·sigprof((byte*)SIG_EIP(info, ctxt), (byte*)SIG_ESP(info, ctxt), nil, gp, g->m); 43 return; 44 } 45 46 t = &runtime·sigtab[sig]; 47 if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) { 48 // Make it look like a call to the signal func. 49 // Have to pass arguments out of band since 50 // augmenting the stack frame would break 51 // the unwinding code. 52 gp->sig = sig; 53 gp->sigcode0 = SIG_CODE0(info, ctxt); 54 gp->sigcode1 = SIG_CODE1(info, ctxt); 55 gp->sigpc = SIG_EIP(info, ctxt); 56 57 #ifdef GOOS_darwin 58 // Work around Leopard bug that doesn't set FPE_INTDIV. 59 // Look at instruction to see if it is a divide. 60 // Not necessary in Snow Leopard (si_code will be != 0). 61 if(sig == SIGFPE && gp->sigcode0 == 0) { 62 byte *pc; 63 pc = (byte*)gp->sigpc; 64 if(pc[0] == 0x66) // 16-bit instruction prefix 65 pc++; 66 if(pc[0] == 0xF6 || pc[0] == 0xF7) 67 gp->sigcode0 = FPE_INTDIV; 68 } 69 #endif 70 71 // Only push runtime·sigpanic if eip != 0. 72 // If eip == 0, probably panicked because of a 73 // call to a nil func. Not pushing that onto sp will 74 // make the trace look like a call to runtime·sigpanic instead. 75 // (Otherwise the trace will end at runtime·sigpanic and we 76 // won't get to see who faulted.) 77 if(SIG_EIP(info, ctxt) != 0) { 78 sp = (uintptr*)SIG_ESP(info, ctxt); 79 *--sp = SIG_EIP(info, ctxt); 80 SIG_ESP(info, ctxt) = (uintptr)sp; 81 } 82 SIG_EIP(info, ctxt) = (uintptr)runtime·sigpanic; 83 return; 84 } 85 86 if(SIG_CODE0(info, ctxt) == SI_USER || (t->flags & SigNotify)) 87 if(runtime·sigsend(sig)) 88 return; 89 if(t->flags & SigKill) 90 runtime·exit(2); 91 if(!(t->flags & SigThrow)) 92 return; 93 94 g->m->throwing = 1; 95 g->m->caughtsig = gp; 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 runtime·printf("PC=%x\n", SIG_EIP(info, ctxt)); 104 if(g->m->lockedg != nil && g->m->ncgo > 0 && gp == g->m->g0) { 105 runtime·printf("signal arrived during cgo execution\n"); 106 gp = g->m->lockedg; 107 } 108 runtime·printf("\n"); 109 110 if(runtime·gotraceback(&crash)){ 111 runtime·goroutineheader(gp); 112 runtime·traceback(SIG_EIP(info, ctxt), SIG_ESP(info, ctxt), 0, gp); 113 runtime·tracebackothers(gp); 114 runtime·printf("\n"); 115 runtime·dumpregs(info, ctxt); 116 } 117 118 if(crash) 119 runtime·crash(); 120 121 runtime·exit(2); 122 }