2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2013 The Go Authors. All rights reserved.
|
2014-11-11 15:05:55 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build amd64 amd64p32
|
|
|
|
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2015-01-14 09:18:24 -07:00
|
|
|
import (
|
2015-11-11 10:39:30 -07:00
|
|
|
"runtime/internal/sys"
|
2015-01-14 09:18:24 -07:00
|
|
|
"unsafe"
|
|
|
|
)
|
2014-11-11 15:05:55 -07:00
|
|
|
|
|
|
|
func dumpregs(c *sigctxt) {
|
|
|
|
print("rax ", hex(c.rax()), "\n")
|
|
|
|
print("rbx ", hex(c.rbx()), "\n")
|
|
|
|
print("rcx ", hex(c.rcx()), "\n")
|
|
|
|
print("rdx ", hex(c.rdx()), "\n")
|
|
|
|
print("rdi ", hex(c.rdi()), "\n")
|
|
|
|
print("rsi ", hex(c.rsi()), "\n")
|
|
|
|
print("rbp ", hex(c.rbp()), "\n")
|
|
|
|
print("rsp ", hex(c.rsp()), "\n")
|
|
|
|
print("r8 ", hex(c.r8()), "\n")
|
|
|
|
print("r9 ", hex(c.r9()), "\n")
|
|
|
|
print("r10 ", hex(c.r10()), "\n")
|
|
|
|
print("r11 ", hex(c.r11()), "\n")
|
|
|
|
print("r12 ", hex(c.r12()), "\n")
|
|
|
|
print("r13 ", hex(c.r13()), "\n")
|
|
|
|
print("r14 ", hex(c.r14()), "\n")
|
|
|
|
print("r15 ", hex(c.r15()), "\n")
|
|
|
|
print("rip ", hex(c.rip()), "\n")
|
|
|
|
print("rflags ", hex(c.rflags()), "\n")
|
|
|
|
print("cs ", hex(c.cs()), "\n")
|
|
|
|
print("fs ", hex(c.fs()), "\n")
|
|
|
|
print("gs ", hex(c.gs()), "\n")
|
|
|
|
}
|
|
|
|
|
2016-10-04 08:11:55 -06:00
|
|
|
//go:nosplit
|
|
|
|
//go:nowritebarrierrec
|
2016-09-23 23:05:51 -06:00
|
|
|
func (c *sigctxt) sigpc() uintptr { return uintptr(c.rip()) }
|
2016-10-04 08:11:55 -06:00
|
|
|
|
2016-09-23 23:05:51 -06:00
|
|
|
func (c *sigctxt) sigsp() uintptr { return uintptr(c.rsp()) }
|
|
|
|
func (c *sigctxt) siglr() uintptr { return 0 }
|
|
|
|
func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
|
2014-11-11 15:05:55 -07:00
|
|
|
|
2016-09-23 23:05:51 -06:00
|
|
|
// preparePanic sets up the stack to look like a call to sigpanic.
|
|
|
|
func (c *sigctxt) preparePanic(sig uint32, gp *g) {
|
2014-11-11 15:05:55 -07:00
|
|
|
if GOOS == "darwin" {
|
2016-09-23 23:05:51 -06:00
|
|
|
// Work around Leopard bug that doesn't set FPE_INTDIV.
|
|
|
|
// Look at instruction to see if it is a divide.
|
|
|
|
// Not necessary in Snow Leopard (si_code will be != 0).
|
|
|
|
if sig == _SIGFPE && gp.sigcode0 == 0 {
|
|
|
|
pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
|
|
|
|
i := 0
|
|
|
|
if pc[i]&0xF0 == 0x40 { // 64-bit REX prefix
|
|
|
|
i++
|
|
|
|
} else if pc[i] == 0x66 { // 16-bit instruction prefix
|
|
|
|
i++
|
2014-11-11 15:05:55 -07:00
|
|
|
}
|
2016-09-23 23:05:51 -06:00
|
|
|
if pc[i] == 0xF6 || pc[i] == 0xF7 {
|
|
|
|
gp.sigcode0 = _FPE_INTDIV
|
2014-11-11 15:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-23 23:05:51 -06:00
|
|
|
pc := uintptr(c.rip())
|
|
|
|
sp := uintptr(c.rsp())
|
2014-11-11 15:05:55 -07:00
|
|
|
|
2018-01-31 15:34:22 -07:00
|
|
|
if shouldPushSigpanic(gp, pc, *(*uintptr)(unsafe.Pointer(sp))) {
|
|
|
|
// Make it look the like faulting PC called sigpanic.
|
2016-09-23 23:05:51 -06:00
|
|
|
if sys.RegSize > sys.PtrSize {
|
|
|
|
sp -= sys.PtrSize
|
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = 0
|
2015-01-14 09:18:24 -07:00
|
|
|
}
|
2016-09-23 23:05:51 -06:00
|
|
|
sp -= sys.PtrSize
|
|
|
|
*(*uintptr)(unsafe.Pointer(sp)) = pc
|
|
|
|
c.set_rsp(uint64(sp))
|
2014-11-11 15:05:55 -07:00
|
|
|
}
|
2016-09-23 23:05:51 -06:00
|
|
|
c.set_rip(uint64(funcPC(sigpanic)))
|
2014-11-11 15:05:55 -07:00
|
|
|
}
|