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