2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
2014-11-21 11:39:01 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2015-11-11 10:39:30 -07:00
|
|
|
import (
|
|
|
|
"runtime/internal/sys"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2014-11-21 11:39:01 -07:00
|
|
|
|
2015-03-24 09:51:24 -06:00
|
|
|
// May run during STW, so write barriers are not allowed.
|
2015-11-17 15:20:38 -07:00
|
|
|
//
|
|
|
|
//go:nowritebarrierrec
|
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
|
2015-10-30 09:03:02 -06:00
|
|
|
var level int32
|
2014-11-21 11:39:01 -07:00
|
|
|
|
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()
|
2015-07-28 12:48:10 -06:00
|
|
|
|
2016-02-29 16:01:00 -07:00
|
|
|
pc := c.pc()
|
|
|
|
sp := c.sp()
|
2015-07-28 12:48:10 -06:00
|
|
|
|
|
|
|
// If we don't recognize the PC as code
|
|
|
|
// but we do recognize the top pointer on the stack as code,
|
|
|
|
// then assume this was a call to non-code and treat like
|
|
|
|
// pc == 0, to make unwinding show the context.
|
|
|
|
if pc != 0 && findfunc(pc) == nil && findfunc(*(*uintptr)(unsafe.Pointer(sp))) != nil {
|
|
|
|
pc = 0
|
|
|
|
}
|
|
|
|
|
2016-01-27 11:43:36 -07:00
|
|
|
// IF LR exists, sigpanictramp must save it to the stack
|
|
|
|
// before entry to sigpanic so that panics in leaf
|
|
|
|
// functions are correctly handled. This will smash
|
|
|
|
// the stack frame but we're not going back there
|
|
|
|
// anyway.
|
|
|
|
if usesLR {
|
|
|
|
c.savelr(c.lr())
|
|
|
|
}
|
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
// If PC == 0, probably panicked because of a call to a nil func.
|
2016-01-27 11:43:36 -07:00
|
|
|
// Not faking that as the return address will make the trace look like a call
|
2014-11-21 11:39:01 -07:00
|
|
|
// to sigpanic instead. (Otherwise the trace will end at
|
|
|
|
// sigpanic and we won't get to see who faulted).
|
2015-07-28 12:48:10 -06:00
|
|
|
if pc != 0 {
|
2016-01-27 11:43:36 -07:00
|
|
|
if usesLR {
|
|
|
|
c.setlr(pc)
|
|
|
|
} else {
|
|
|
|
if sys.RegSize > sys.PtrSize {
|
|
|
|
sp -= sys.PtrSize
|
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = 0
|
|
|
|
}
|
2015-11-11 10:39:30 -07:00
|
|
|
sp -= sys.PtrSize
|
2016-01-27 11:43:36 -07:00
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = pc
|
|
|
|
c.setsp(sp)
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
}
|
2016-01-27 11:43:36 -07:00
|
|
|
if usesLR {
|
|
|
|
c.setpc(funcPC(sigpanictramp))
|
|
|
|
} else {
|
|
|
|
c.setpc(funcPC(sigpanic))
|
|
|
|
}
|
2014-11-21 11:39:01 -07:00
|
|
|
return _NCONT
|
|
|
|
}
|
|
|
|
if flags&_SigNotify != 0 {
|
2016-11-11 12:49:11 -07:00
|
|
|
if ignoredNote(note) {
|
|
|
|
return _NCONT
|
|
|
|
}
|
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-04-16 22:21:30 -06:00
|
|
|
_g_.m.caughtsig.set(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")
|
2015-10-30 09:03:02 -06:00
|
|
|
level, _, docrash = gotraceback()
|
|
|
|
if level > 0 {
|
2014-11-21 11:39:01 -07:00
|
|
|
goroutineheader(gp)
|
2016-01-27 11:43:36 -07:00
|
|
|
tracebacktrap(c.pc(), c.sp(), c.lr(), 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) {
|
|
|
|
}
|
|
|
|
|
2016-12-06 21:54:41 -07:00
|
|
|
func setProcessCPUProfiler(hz int32) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func setThreadCPUProfiler(hz int32) {
|
2014-11-21 11:39:01 -07:00
|
|
|
// TODO: Enable profiling interrupts.
|
|
|
|
getg().m.profilehz = hz
|
|
|
|
}
|