github.com/sean-/go@v0.0.0-20151219100004-97f854cd7bb6/src/runtime/os3_plan9.go (about) 1 // Copyright 2010 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 package runtime 6 7 import ( 8 "runtime/internal/sys" 9 "unsafe" 10 ) 11 12 // May run during STW, so write barriers are not allowed. 13 // 14 //go:nowritebarrierrec 15 func sighandler(_ureg *ureg, note *byte, gp *g) int { 16 _g_ := getg() 17 var t sigTabT 18 var docrash bool 19 var sig int 20 var flags int 21 var level int32 22 23 c := &sigctxt{_ureg} 24 notestr := gostringnocopy(note) 25 26 // The kernel will never pass us a nil note or ureg so we probably 27 // made a mistake somewhere in sigtramp. 28 if _ureg == nil || note == nil { 29 print("sighandler: ureg ", _ureg, " note ", note, "\n") 30 goto Throw 31 } 32 // Check that the note is no more than ERRMAX bytes (including 33 // the trailing NUL). We should never receive a longer note. 34 if len(notestr) > _ERRMAX-1 { 35 print("sighandler: note is longer than ERRMAX\n") 36 goto Throw 37 } 38 // See if the note matches one of the patterns in sigtab. 39 // Notes that do not match any pattern can be handled at a higher 40 // level by the program but will otherwise be ignored. 41 flags = _SigNotify 42 for sig, t = range sigtable { 43 if hasprefix(notestr, t.name) { 44 flags = t.flags 45 break 46 } 47 } 48 if flags&_SigGoExit != 0 { 49 exits((*byte)(add(unsafe.Pointer(note), 9))) // Strip "go: exit " prefix. 50 } 51 if flags&_SigPanic != 0 { 52 // Copy the error string from sigtramp's stack into m->notesig so 53 // we can reliably access it from the panic routines. 54 memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1)) 55 gp.sig = uint32(sig) 56 gp.sigpc = c.pc() 57 58 pc := uintptr(c.pc()) 59 sp := uintptr(c.sp()) 60 61 // If we don't recognize the PC as code 62 // but we do recognize the top pointer on the stack as code, 63 // then assume this was a call to non-code and treat like 64 // pc == 0, to make unwinding show the context. 65 if pc != 0 && findfunc(pc) == nil && findfunc(*(*uintptr)(unsafe.Pointer(sp))) != nil { 66 pc = 0 67 } 68 69 // Only push sigpanic if PC != 0. 70 // 71 // If PC == 0, probably panicked because of a call to a nil func. 72 // Not pushing that onto SP will make the trace look like a call 73 // to sigpanic instead. (Otherwise the trace will end at 74 // sigpanic and we won't get to see who faulted). 75 if pc != 0 { 76 if sys.RegSize > sys.PtrSize { 77 sp -= sys.PtrSize 78 *(*uintptr)(unsafe.Pointer(sp)) = 0 79 } 80 sp -= sys.PtrSize 81 *(*uintptr)(unsafe.Pointer(sp)) = pc 82 c.setsp(sp) 83 } 84 c.setpc(funcPC(sigpanic)) 85 return _NCONT 86 } 87 if flags&_SigNotify != 0 { 88 if sendNote(note) { 89 return _NCONT 90 } 91 } 92 if flags&_SigKill != 0 { 93 goto Exit 94 } 95 if flags&_SigThrow == 0 { 96 return _NCONT 97 } 98 Throw: 99 _g_.m.throwing = 1 100 _g_.m.caughtsig.set(gp) 101 startpanic() 102 print(notestr, "\n") 103 print("PC=", hex(c.pc()), "\n") 104 print("\n") 105 level, _, docrash = gotraceback() 106 if level > 0 { 107 goroutineheader(gp) 108 tracebacktrap(c.pc(), c.sp(), 0, gp) 109 tracebackothers(gp) 110 print("\n") 111 dumpregs(_ureg) 112 } 113 if docrash { 114 crash() 115 } 116 Exit: 117 goexitsall(note) 118 exits(note) 119 return _NDFLT // not reached 120 } 121 122 func sigenable(sig uint32) { 123 } 124 125 func sigdisable(sig uint32) { 126 } 127 128 func sigignore(sig uint32) { 129 } 130 131 func resetcpuprofiler(hz int32) { 132 // TODO: Enable profiling interrupts. 133 getg().m.profilehz = hz 134 }