github.com/rafaeltorres324/go/src@v0.0.0-20210519164414-9fdf653a9838/runtime/signal_386.go (about)

     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 dragonfly freebsd linux 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  	pc := uintptr(c.eip())
    41  	sp := uintptr(c.esp())
    42  
    43  	if shouldPushSigpanic(gp, pc, *(*uintptr)(unsafe.Pointer(sp))) {
    44  		c.pushCall(funcPC(sigpanic), pc)
    45  	} else {
    46  		// Not safe to push the call. Just clobber the frame.
    47  		c.set_eip(uint32(funcPC(sigpanic)))
    48  	}
    49  }
    50  
    51  func (c *sigctxt) pushCall(targetPC, resumePC uintptr) {
    52  	// Make it look like we called target at resumePC.
    53  	sp := uintptr(c.esp())
    54  	sp -= sys.PtrSize
    55  	*(*uintptr)(unsafe.Pointer(sp)) = resumePC
    56  	c.set_esp(uint32(sp))
    57  	c.set_eip(uint32(targetPC))
    58  }