mirror of
https://github.com/golang/go
synced 2024-11-19 14:14:40 -07:00
0efc8b2188
Currently almost every function that deals with a *_func has to first look up the *moduledata for the module containing the function's entry point. This means we almost always do at least two identical module lookups whenever we deal with a *_func (one to get the *_func and another to get something from its module data) and sometimes several more. Fix this by making findfunc return a new funcInfo type that embeds *_func, but also includes the *moduledata, and making all of the functions that currently take a *_func instead take a funcInfo and use the already-found *moduledata. This transformation is trivial for the most part, since the *_func type is usually inferred. The annoying part is that we can no longer use nil to indicate failure, so this introduces a funcInfo.valid() method and replaces nil checks with calls to valid. Change-Id: I9b8075ef1c31185c1943596d96dec45c7ab5100f Reviewed-on: https://go-review.googlesource.com/37331 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
156 lines
3.7 KiB
Go
156 lines
3.7 KiB
Go
// 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 (
|
|
"runtime/internal/sys"
|
|
"unsafe"
|
|
)
|
|
|
|
// May run during STW, so write barriers are not allowed.
|
|
//
|
|
//go:nowritebarrierrec
|
|
func sighandler(_ureg *ureg, note *byte, gp *g) int {
|
|
_g_ := getg()
|
|
var t sigTabT
|
|
var docrash bool
|
|
var sig int
|
|
var flags int
|
|
var level int32
|
|
|
|
c := &sigctxt{_ureg}
|
|
notestr := gostringnocopy(note)
|
|
|
|
// 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.
|
|
if len(notestr) > _ERRMAX-1 {
|
|
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 {
|
|
if hasprefix(notestr, t.name) {
|
|
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.
|
|
memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1))
|
|
gp.sig = uint32(sig)
|
|
gp.sigpc = c.pc()
|
|
|
|
pc := c.pc()
|
|
sp := c.sp()
|
|
|
|
// 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).valid() && findfunc(*(*uintptr)(unsafe.Pointer(sp))).valid() {
|
|
pc = 0
|
|
}
|
|
|
|
// 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())
|
|
}
|
|
|
|
// If PC == 0, probably panicked because of a call to a nil func.
|
|
// Not faking that as the return address 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).
|
|
if pc != 0 {
|
|
if usesLR {
|
|
c.setlr(pc)
|
|
} else {
|
|
if sys.RegSize > sys.PtrSize {
|
|
sp -= sys.PtrSize
|
|
*(*uintptr)(unsafe.Pointer(sp)) = 0
|
|
}
|
|
sp -= sys.PtrSize
|
|
*(*uintptr)(unsafe.Pointer(sp)) = pc
|
|
c.setsp(sp)
|
|
}
|
|
}
|
|
if usesLR {
|
|
c.setpc(funcPC(sigpanictramp))
|
|
} else {
|
|
c.setpc(funcPC(sigpanic))
|
|
}
|
|
return _NCONT
|
|
}
|
|
if flags&_SigNotify != 0 {
|
|
if ignoredNote(note) {
|
|
return _NCONT
|
|
}
|
|
if sendNote(note) {
|
|
return _NCONT
|
|
}
|
|
}
|
|
if flags&_SigKill != 0 {
|
|
goto Exit
|
|
}
|
|
if flags&_SigThrow == 0 {
|
|
return _NCONT
|
|
}
|
|
Throw:
|
|
_g_.m.throwing = 1
|
|
_g_.m.caughtsig.set(gp)
|
|
startpanic()
|
|
print(notestr, "\n")
|
|
print("PC=", hex(c.pc()), "\n")
|
|
print("\n")
|
|
level, _, docrash = gotraceback()
|
|
if level > 0 {
|
|
goroutineheader(gp)
|
|
tracebacktrap(c.pc(), c.sp(), c.lr(), gp)
|
|
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) {
|
|
}
|
|
|
|
func sigignore(sig uint32) {
|
|
}
|
|
|
|
func setProcessCPUProfiler(hz int32) {
|
|
}
|
|
|
|
func setThreadCPUProfiler(hz int32) {
|
|
// TODO: Enable profiling interrupts.
|
|
getg().m.profilehz = hz
|
|
}
|