2014-11-21 11:39:01 -07:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
2015-03-24 09:51:24 -06:00
|
|
|
// May run during STW, so write barriers are not allowed.
|
|
|
|
//go:nowritebarrier
|
2014-11-21 11:39:01 -07:00
|
|
|
func sighandler(_ureg *ureg, note *byte, gp *g) int {
|
|
|
|
_g_ := getg()
|
|
|
|
var t sigTabT
|
|
|
|
var docrash bool
|
|
|
|
var sig int
|
|
|
|
var flags int
|
|
|
|
|
2014-12-18 06:05:44 -07:00
|
|
|
c := &sigctxt{_ureg}
|
2015-02-12 20:09:12 -07:00
|
|
|
notestr := gostringnocopy(note)
|
2014-12-18 06:05:44 -07:00
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
// The kernel will never pass us a nil note or ureg so we probably
|
|
|
|
// made a mistake somewhere in sigtramp.
|
|
|
|
if _ureg == nil || note == nil {
|
|
|
|
print("sighandler: ureg ", _ureg, " note ", note, "\n")
|
|
|
|
goto Throw
|
|
|
|
}
|
|
|
|
// Check that the note is no more than ERRMAX bytes (including
|
|
|
|
// the trailing NUL). We should never receive a longer note.
|
2015-02-12 20:09:12 -07:00
|
|
|
if len(notestr) > _ERRMAX-1 {
|
2014-11-21 11:39:01 -07:00
|
|
|
print("sighandler: note is longer than ERRMAX\n")
|
|
|
|
goto Throw
|
|
|
|
}
|
|
|
|
// See if the note matches one of the patterns in sigtab.
|
|
|
|
// Notes that do not match any pattern can be handled at a higher
|
|
|
|
// level by the program but will otherwise be ignored.
|
|
|
|
flags = _SigNotify
|
|
|
|
for sig, t = range sigtable {
|
2015-02-12 20:09:12 -07:00
|
|
|
if hasprefix(notestr, t.name) {
|
2014-11-21 11:39:01 -07:00
|
|
|
flags = t.flags
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if flags&_SigGoExit != 0 {
|
|
|
|
exits((*byte)(add(unsafe.Pointer(note), 9))) // Strip "go: exit " prefix.
|
|
|
|
}
|
|
|
|
if flags&_SigPanic != 0 {
|
|
|
|
// Copy the error string from sigtramp's stack into m->notesig so
|
|
|
|
// we can reliably access it from the panic routines.
|
2015-02-12 20:09:12 -07:00
|
|
|
memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1))
|
2014-11-21 11:39:01 -07:00
|
|
|
gp.sig = uint32(sig)
|
2014-12-18 06:05:44 -07:00
|
|
|
gp.sigpc = c.pc()
|
2014-11-21 11:39:01 -07:00
|
|
|
// Only push sigpanic if PC != 0.
|
|
|
|
//
|
|
|
|
// If PC == 0, probably panicked because of a call to a nil func.
|
|
|
|
// Not pushing that onto SP will make the trace look like a call
|
|
|
|
// to sigpanic instead. (Otherwise the trace will end at
|
|
|
|
// sigpanic and we won't get to see who faulted).
|
2014-12-18 06:05:44 -07:00
|
|
|
if c.pc() != 0 {
|
|
|
|
sp := c.sp()
|
2014-11-21 11:39:01 -07:00
|
|
|
if regSize > ptrSize {
|
|
|
|
sp -= ptrSize
|
2014-12-18 06:05:44 -07:00
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = 0
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
sp -= ptrSize
|
2014-12-18 06:05:44 -07:00
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = c.pc()
|
|
|
|
c.setsp(sp)
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
2014-12-18 06:05:44 -07:00
|
|
|
c.setpc(funcPC(sigpanic))
|
2014-11-21 11:39:01 -07:00
|
|
|
return _NCONT
|
|
|
|
}
|
|
|
|
if flags&_SigNotify != 0 {
|
2015-01-22 15:38:29 -07:00
|
|
|
if sendNote(note) {
|
|
|
|
return _NCONT
|
|
|
|
}
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
if flags&_SigKill != 0 {
|
|
|
|
goto Exit
|
|
|
|
}
|
|
|
|
if flags&_SigThrow == 0 {
|
|
|
|
return _NCONT
|
|
|
|
}
|
|
|
|
Throw:
|
|
|
|
_g_.m.throwing = 1
|
2015-03-24 09:51:24 -06:00
|
|
|
setGNoWriteBarrier(&_g_.m.caughtsig, gp)
|
2014-11-21 11:39:01 -07:00
|
|
|
startpanic()
|
2015-02-12 20:09:12 -07:00
|
|
|
print(notestr, "\n")
|
2014-12-18 06:05:44 -07:00
|
|
|
print("PC=", hex(c.pc()), "\n")
|
2014-11-21 11:39:01 -07:00
|
|
|
print("\n")
|
|
|
|
if gotraceback(&docrash) > 0 {
|
|
|
|
goroutineheader(gp)
|
2014-12-18 06:05:44 -07:00
|
|
|
tracebacktrap(c.pc(), c.sp(), 0, gp)
|
2014-11-21 11:39:01 -07:00
|
|
|
tracebackothers(gp)
|
|
|
|
print("\n")
|
|
|
|
dumpregs(_ureg)
|
|
|
|
}
|
|
|
|
if docrash {
|
|
|
|
crash()
|
|
|
|
}
|
|
|
|
Exit:
|
|
|
|
goexitsall(note)
|
|
|
|
exits(note)
|
|
|
|
return _NDFLT // not reached
|
|
|
|
}
|
|
|
|
|
|
|
|
func sigenable(sig uint32) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func sigdisable(sig uint32) {
|
|
|
|
}
|
|
|
|
|
2015-01-29 20:37:41 -07:00
|
|
|
func sigignore(sig uint32) {
|
|
|
|
}
|
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
func resetcpuprofiler(hz int32) {
|
|
|
|
// TODO: Enable profiling interrupts.
|
|
|
|
getg().m.profilehz = hz
|
|
|
|
}
|