github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/os_windows_386.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 #include "runtime.h" 6 #include "defs_GOOS_GOARCH.h" 7 #include "os_GOOS.h" 8 9 void 10 runtime·dumpregs(Context *r) 11 { 12 runtime·printf("eax %x\n", r->Eax); 13 runtime·printf("ebx %x\n", r->Ebx); 14 runtime·printf("ecx %x\n", r->Ecx); 15 runtime·printf("edx %x\n", r->Edx); 16 runtime·printf("edi %x\n", r->Edi); 17 runtime·printf("esi %x\n", r->Esi); 18 runtime·printf("ebp %x\n", r->Ebp); 19 runtime·printf("esp %x\n", r->Esp); 20 runtime·printf("eip %x\n", r->Eip); 21 runtime·printf("eflags %x\n", r->EFlags); 22 runtime·printf("cs %x\n", r->SegCs); 23 runtime·printf("fs %x\n", r->SegFs); 24 runtime·printf("gs %x\n", r->SegGs); 25 } 26 27 bool 28 runtime·isgoexception(ExceptionRecord *info, Context *r) 29 { 30 extern byte runtime·text[], runtime·etext[]; 31 32 // Only handle exception if executing instructions in Go binary 33 // (not Windows library code). 34 if(r->Eip < (uint32)runtime·text || (uint32)runtime·etext < r->Eip) 35 return false; 36 37 if(!runtime·issigpanic(info->ExceptionCode)) 38 return false; 39 40 return true; 41 } 42 43 // Called by sigtramp from Windows VEH handler. 44 // Return value signals whether the exception has been handled (EXCEPTION_CONTINUE_EXECUTION) 45 // or should be made available to other handlers in the chain (EXCEPTION_CONTINUE_SEARCH). 46 uint32 47 runtime·exceptionhandler(ExceptionRecord *info, Context *r, G *gp) 48 { 49 uintptr *sp; 50 51 if(!runtime·isgoexception(info, r)) 52 return EXCEPTION_CONTINUE_SEARCH; 53 54 // Make it look like a call to the signal func. 55 // Have to pass arguments out of band since 56 // augmenting the stack frame would break 57 // the unwinding code. 58 gp->sig = info->ExceptionCode; 59 gp->sigcode0 = info->ExceptionInformation[0]; 60 gp->sigcode1 = info->ExceptionInformation[1]; 61 gp->sigpc = r->Eip; 62 63 // Only push runtime·sigpanic if r->eip != 0. 64 // If r->eip == 0, probably panicked because of a 65 // call to a nil func. Not pushing that onto sp will 66 // make the trace look like a call to runtime·sigpanic instead. 67 // (Otherwise the trace will end at runtime·sigpanic and we 68 // won't get to see who faulted.) 69 if(r->Eip != 0) { 70 sp = (uintptr*)r->Esp; 71 *--sp = r->Eip; 72 r->Esp = (uintptr)sp; 73 } 74 r->Eip = (uintptr)runtime·sigpanic; 75 return EXCEPTION_CONTINUE_EXECUTION; 76 } 77 78 // lastcontinuehandler is reached, because runtime cannot handle 79 // current exception. lastcontinuehandler will print crash info and exit. 80 uint32 81 runtime·lastcontinuehandler(ExceptionRecord *info, Context *r, G *gp) 82 { 83 bool crash; 84 85 if(runtime·panicking) // traceback already printed 86 runtime·exit(2); 87 runtime·panicking = 1; 88 89 runtime·printf("Exception %x %p %p %p\n", info->ExceptionCode, 90 (uintptr)info->ExceptionInformation[0], (uintptr)info->ExceptionInformation[1], (uintptr)r->Eip); 91 92 runtime·printf("PC=%x\n", r->Eip); 93 if(g->m->lockedg != nil && g->m->ncgo > 0 && gp == g->m->g0) { 94 runtime·printf("signal arrived during cgo execution\n"); 95 gp = g->m->lockedg; 96 } 97 runtime·printf("\n"); 98 99 if(runtime·gotraceback(&crash)){ 100 runtime·traceback(r->Eip, r->Esp, 0, gp); 101 runtime·tracebackothers(gp); 102 runtime·dumpregs(r); 103 } 104 105 if(crash) 106 runtime·crash(); 107 108 runtime·exit(2); 109 return 0; // not reached 110 } 111 112 void 113 runtime·sigenable(uint32 sig) 114 { 115 USED(sig); 116 } 117 118 void 119 runtime·sigdisable(uint32 sig) 120 { 121 USED(sig); 122 } 123 124 void 125 runtime·dosigprof(Context *r, G *gp, M *mp) 126 { 127 runtime·sigprof((uint8*)r->Eip, (uint8*)r->Esp, nil, gp, mp); 128 }