2014-11-19 18:24:03 -07:00
|
|
|
// Copyright 2011 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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func isgoexception(info *exceptionrecord, r *context) bool {
|
|
|
|
// Only handle exception if executing instructions in Go binary
|
|
|
|
// (not Windows library code).
|
2015-02-11 18:14:02 -07:00
|
|
|
if r.ip() < themoduledata.text || themoduledata.etext < r.ip() {
|
2014-11-19 18:24:03 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if issigpanic(info.exceptioncode) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by sigtramp from Windows VEH handler.
|
|
|
|
// Return value signals whether the exception has been handled (EXCEPTION_CONTINUE_EXECUTION)
|
|
|
|
// or should be made available to other handlers in the chain (EXCEPTION_CONTINUE_SEARCH).
|
|
|
|
|
|
|
|
func exceptionhandler(info *exceptionrecord, r *context, gp *g) int32 {
|
|
|
|
if !isgoexception(info, r) {
|
|
|
|
return _EXCEPTION_CONTINUE_SEARCH
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make it look like a call to the signal func.
|
|
|
|
// Have to pass arguments out of band since
|
|
|
|
// augmenting the stack frame would break
|
|
|
|
// the unwinding code.
|
|
|
|
gp.sig = info.exceptioncode
|
|
|
|
gp.sigcode0 = uintptr(info.exceptioninformation[0])
|
|
|
|
gp.sigcode1 = uintptr(info.exceptioninformation[1])
|
2015-02-11 18:14:02 -07:00
|
|
|
gp.sigpc = r.ip()
|
2014-11-19 18:24:03 -07:00
|
|
|
|
2015-02-11 18:14:02 -07:00
|
|
|
// Only push runtime·sigpanic if r.ip() != 0.
|
|
|
|
// If r.ip() == 0, probably panicked because of a
|
2014-11-19 18:24:03 -07:00
|
|
|
// call to a nil func. Not pushing that onto sp will
|
|
|
|
// make the trace look like a call to runtime·sigpanic instead.
|
|
|
|
// (Otherwise the trace will end at runtime·sigpanic and we
|
|
|
|
// won't get to see who faulted.)
|
2015-02-11 18:14:02 -07:00
|
|
|
if r.ip() != 0 {
|
|
|
|
sp := unsafe.Pointer(r.sp())
|
2014-11-19 18:24:03 -07:00
|
|
|
sp = add(sp, ^uintptr(unsafe.Sizeof(uintptr(0))-1)) // sp--
|
2015-02-11 18:14:02 -07:00
|
|
|
*((*uintptr)(sp)) = r.ip()
|
|
|
|
r.setsp(uintptr(sp))
|
2014-11-19 18:24:03 -07:00
|
|
|
}
|
2015-02-11 18:14:02 -07:00
|
|
|
r.setip(funcPC(sigpanic))
|
2014-11-19 18:24:03 -07:00
|
|
|
return _EXCEPTION_CONTINUE_EXECUTION
|
|
|
|
}
|
|
|
|
|
|
|
|
// It seems Windows searches ContinueHandler's list even
|
|
|
|
// if ExceptionHandler returns EXCEPTION_CONTINUE_EXECUTION.
|
|
|
|
// firstcontinuehandler will stop that search,
|
|
|
|
// if exceptionhandler did the same earlier.
|
|
|
|
func firstcontinuehandler(info *exceptionrecord, r *context, gp *g) int32 {
|
|
|
|
if !isgoexception(info, r) {
|
|
|
|
return _EXCEPTION_CONTINUE_SEARCH
|
|
|
|
}
|
|
|
|
return _EXCEPTION_CONTINUE_EXECUTION
|
|
|
|
}
|
|
|
|
|
2014-12-30 19:46:58 -07:00
|
|
|
var testingWER bool
|
|
|
|
|
2014-11-19 18:24:03 -07:00
|
|
|
// lastcontinuehandler is reached, because runtime cannot handle
|
|
|
|
// current exception. lastcontinuehandler will print crash info and exit.
|
|
|
|
func lastcontinuehandler(info *exceptionrecord, r *context, gp *g) uint32 {
|
2014-12-30 19:46:58 -07:00
|
|
|
if testingWER {
|
|
|
|
return _EXCEPTION_CONTINUE_SEARCH
|
|
|
|
}
|
|
|
|
|
2014-11-19 18:24:03 -07:00
|
|
|
_g_ := getg()
|
|
|
|
|
|
|
|
if panicking != 0 { // traceback already printed
|
|
|
|
exit(2)
|
|
|
|
}
|
|
|
|
panicking = 1
|
|
|
|
|
2015-02-11 18:14:02 -07:00
|
|
|
print("Exception ", hex(info.exceptioncode), " ", hex(info.exceptioninformation[0]), " ", hex(info.exceptioninformation[1]), " ", hex(r.ip()), "\n")
|
2014-11-19 18:24:03 -07:00
|
|
|
|
2015-02-11 18:14:02 -07:00
|
|
|
print("PC=", hex(r.ip()), "\n")
|
2014-11-19 18:24:03 -07:00
|
|
|
if _g_.m.lockedg != nil && _g_.m.ncgo > 0 && gp == _g_.m.g0 {
|
|
|
|
print("signal arrived during cgo execution\n")
|
|
|
|
gp = _g_.m.lockedg
|
|
|
|
}
|
|
|
|
print("\n")
|
|
|
|
|
|
|
|
var docrash bool
|
|
|
|
if gotraceback(&docrash) > 0 {
|
2015-02-11 18:14:02 -07:00
|
|
|
tracebacktrap(r.ip(), r.sp(), 0, gp)
|
2014-11-19 18:24:03 -07:00
|
|
|
tracebackothers(gp)
|
|
|
|
dumpregs(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
if docrash {
|
|
|
|
crash()
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(2)
|
|
|
|
return 0 // not reached
|
|
|
|
}
|
|
|
|
|
|
|
|
func sigenable(sig uint32) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func sigdisable(sig uint32) {
|
|
|
|
}
|
2015-01-29 20:37:41 -07:00
|
|
|
|
|
|
|
func sigignore(sig uint32) {
|
|
|
|
}
|