...

Source file src/runtime/signal_linux_s390x.go

Documentation: runtime

     1  // Copyright 2016 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  package runtime
     6  
     7  import (
     8  	"internal/abi"
     9  	"internal/goarch"
    10  	"runtime/internal/sys"
    11  	"unsafe"
    12  )
    13  
    14  type sigctxt struct {
    15  	info *siginfo
    16  	ctxt unsafe.Pointer
    17  }
    18  
    19  //go:nosplit
    20  //go:nowritebarrierrec
    21  func (c *sigctxt) regs() *sigcontext {
    22  	return (*sigcontext)(unsafe.Pointer(&(*ucontext)(c.ctxt).uc_mcontext))
    23  }
    24  
    25  func (c *sigctxt) r0() uint64   { return c.regs().gregs[0] }
    26  func (c *sigctxt) r1() uint64   { return c.regs().gregs[1] }
    27  func (c *sigctxt) r2() uint64   { return c.regs().gregs[2] }
    28  func (c *sigctxt) r3() uint64   { return c.regs().gregs[3] }
    29  func (c *sigctxt) r4() uint64   { return c.regs().gregs[4] }
    30  func (c *sigctxt) r5() uint64   { return c.regs().gregs[5] }
    31  func (c *sigctxt) r6() uint64   { return c.regs().gregs[6] }
    32  func (c *sigctxt) r7() uint64   { return c.regs().gregs[7] }
    33  func (c *sigctxt) r8() uint64   { return c.regs().gregs[8] }
    34  func (c *sigctxt) r9() uint64   { return c.regs().gregs[9] }
    35  func (c *sigctxt) r10() uint64  { return c.regs().gregs[10] }
    36  func (c *sigctxt) r11() uint64  { return c.regs().gregs[11] }
    37  func (c *sigctxt) r12() uint64  { return c.regs().gregs[12] }
    38  func (c *sigctxt) r13() uint64  { return c.regs().gregs[13] }
    39  func (c *sigctxt) r14() uint64  { return c.regs().gregs[14] }
    40  func (c *sigctxt) r15() uint64  { return c.regs().gregs[15] }
    41  func (c *sigctxt) link() uint64 { return c.regs().gregs[14] }
    42  func (c *sigctxt) sp() uint64   { return c.regs().gregs[15] }
    43  
    44  //go:nosplit
    45  //go:nowritebarrierrec
    46  func (c *sigctxt) pc() uint64 { return c.regs().psw_addr }
    47  
    48  func (c *sigctxt) sigcode() uint32 { return uint32(c.info.si_code) }
    49  func (c *sigctxt) sigaddr() uint64 { return c.info.si_addr }
    50  
    51  func (c *sigctxt) set_r0(x uint64)      { c.regs().gregs[0] = x }
    52  func (c *sigctxt) set_r13(x uint64)     { c.regs().gregs[13] = x }
    53  func (c *sigctxt) set_link(x uint64)    { c.regs().gregs[14] = x }
    54  func (c *sigctxt) set_sp(x uint64)      { c.regs().gregs[15] = x }
    55  func (c *sigctxt) set_pc(x uint64)      { c.regs().psw_addr = x }
    56  func (c *sigctxt) set_sigcode(x uint32) { c.info.si_code = int32(x) }
    57  func (c *sigctxt) set_sigaddr(x uint64) {
    58  	*(*uintptr)(add(unsafe.Pointer(c.info), 2*goarch.PtrSize)) = uintptr(x)
    59  }
    60  
    61  func dumpregs(c *sigctxt) {
    62  	print("r0   ", hex(c.r0()), "\t")
    63  	print("r1   ", hex(c.r1()), "\n")
    64  	print("r2   ", hex(c.r2()), "\t")
    65  	print("r3   ", hex(c.r3()), "\n")
    66  	print("r4   ", hex(c.r4()), "\t")
    67  	print("r5   ", hex(c.r5()), "\n")
    68  	print("r6   ", hex(c.r6()), "\t")
    69  	print("r7   ", hex(c.r7()), "\n")
    70  	print("r8   ", hex(c.r8()), "\t")
    71  	print("r9   ", hex(c.r9()), "\n")
    72  	print("r10  ", hex(c.r10()), "\t")
    73  	print("r11  ", hex(c.r11()), "\n")
    74  	print("r12  ", hex(c.r12()), "\t")
    75  	print("r13  ", hex(c.r13()), "\n")
    76  	print("r14  ", hex(c.r14()), "\t")
    77  	print("r15  ", hex(c.r15()), "\n")
    78  	print("pc   ", hex(c.pc()), "\t")
    79  	print("link ", hex(c.link()), "\n")
    80  }
    81  
    82  //go:nosplit
    83  //go:nowritebarrierrec
    84  func (c *sigctxt) sigpc() uintptr { return uintptr(c.pc()) }
    85  
    86  func (c *sigctxt) sigsp() uintptr { return uintptr(c.sp()) }
    87  func (c *sigctxt) siglr() uintptr { return uintptr(c.link()) }
    88  func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
    89  
    90  // preparePanic sets up the stack to look like a call to sigpanic.
    91  func (c *sigctxt) preparePanic(sig uint32, gp *g) {
    92  	// We arrange link, and pc to pretend the panicking
    93  	// function calls sigpanic directly.
    94  	// Always save LINK to stack so that panics in leaf
    95  	// functions are correctly handled. This smashes
    96  	// the stack frame but we're not going back there
    97  	// anyway.
    98  	sp := c.sp() - sys.MinFrameSize
    99  	c.set_sp(sp)
   100  	*(*uint64)(unsafe.Pointer(uintptr(sp))) = c.link()
   101  
   102  	pc := uintptr(gp.sigpc)
   103  
   104  	if shouldPushSigpanic(gp, pc, uintptr(c.link())) {
   105  		// Make it look the like faulting PC called sigpanic.
   106  		c.set_link(uint64(pc))
   107  	}
   108  
   109  	// In case we are panicking from external C code
   110  	c.set_r0(0)
   111  	c.set_r13(uint64(uintptr(unsafe.Pointer(gp))))
   112  	c.set_pc(uint64(abi.FuncPCABIInternal(sigpanic)))
   113  }
   114  
   115  func (c *sigctxt) pushCall(targetPC, resumePC uintptr) {
   116  	// Push the LR to stack, as we'll clobber it in order to
   117  	// push the call. The function being pushed is responsible
   118  	// for restoring the LR and setting the SP back.
   119  	// This extra slot is known to gentraceback.
   120  	sp := c.sp() - 8
   121  	c.set_sp(sp)
   122  	*(*uint64)(unsafe.Pointer(uintptr(sp))) = c.link()
   123  	// Set up PC and LR to pretend the function being signaled
   124  	// calls targetPC at resumePC.
   125  	c.set_link(uint64(resumePC))
   126  	c.set_pc(uint64(targetPC))
   127  }
   128  

View as plain text