...

Source file src/pkg/runtime/signal_386.go

     1	// Copyright 2013 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	// +build darwin dragonfly freebsd linux nacl netbsd openbsd
     6	
     7	package runtime
     8	
     9	import (
    10		"runtime/internal/sys"
    11		"unsafe"
    12	)
    13	
    14	func dumpregs(c *sigctxt) {
    15		print("eax    ", hex(c.eax()), "\n")
    16		print("ebx    ", hex(c.ebx()), "\n")
    17		print("ecx    ", hex(c.ecx()), "\n")
    18		print("edx    ", hex(c.edx()), "\n")
    19		print("edi    ", hex(c.edi()), "\n")
    20		print("esi    ", hex(c.esi()), "\n")
    21		print("ebp    ", hex(c.ebp()), "\n")
    22		print("esp    ", hex(c.esp()), "\n")
    23		print("eip    ", hex(c.eip()), "\n")
    24		print("eflags ", hex(c.eflags()), "\n")
    25		print("cs     ", hex(c.cs()), "\n")
    26		print("fs     ", hex(c.fs()), "\n")
    27		print("gs     ", hex(c.gs()), "\n")
    28	}
    29	
    30	//go:nosplit
    31	//go:nowritebarrierrec
    32	func (c *sigctxt) sigpc() uintptr { return uintptr(c.eip()) }
    33	
    34	func (c *sigctxt) sigsp() uintptr { return uintptr(c.esp()) }
    35	func (c *sigctxt) siglr() uintptr { return 0 }
    36	func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
    37	
    38	// preparePanic sets up the stack to look like a call to sigpanic.
    39	func (c *sigctxt) preparePanic(sig uint32, gp *g) {
    40		if GOOS == "darwin" {
    41			// Work around Leopard bug that doesn't set FPE_INTDIV.
    42			// Look at instruction to see if it is a divide.
    43			// Not necessary in Snow Leopard (si_code will be != 0).
    44			if sig == _SIGFPE && gp.sigcode0 == 0 {
    45				pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
    46				i := 0
    47				if pc[i] == 0x66 { // 16-bit instruction prefix
    48					i++
    49				}
    50				if pc[i] == 0xF6 || pc[i] == 0xF7 {
    51					gp.sigcode0 = _FPE_INTDIV
    52				}
    53			}
    54		}
    55	
    56		pc := uintptr(c.eip())
    57		sp := uintptr(c.esp())
    58	
    59		if shouldPushSigpanic(gp, pc, *(*uintptr)(unsafe.Pointer(sp))) {
    60			// Make it look like the faulting PC called sigpanic.
    61			if sys.RegSize > sys.PtrSize {
    62				sp -= sys.PtrSize
    63				*(*uintptr)(unsafe.Pointer(sp)) = 0
    64			}
    65			sp -= sys.PtrSize
    66			*(*uintptr)(unsafe.Pointer(sp)) = pc
    67			c.set_esp(uint32(sp))
    68		}
    69		c.set_eip(uint32(funcPC(sigpanic)))
    70	}
    71	

View as plain text