github.com/lzhfromustc/gofuzz@v0.0.0-20211116160056-151b3108bbd1/runtime/signal_arm.go (about)

     1  // Copyright 2009 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 "unsafe"
    10  
    11  func dumpregs(c *sigctxt) {
    12  	print("trap    ", hex(c.trap()), "\n")
    13  	print("error   ", hex(c.error()), "\n")
    14  	print("oldmask ", hex(c.oldmask()), "\n")
    15  	print("r0      ", hex(c.r0()), "\n")
    16  	print("r1      ", hex(c.r1()), "\n")
    17  	print("r2      ", hex(c.r2()), "\n")
    18  	print("r3      ", hex(c.r3()), "\n")
    19  	print("r4      ", hex(c.r4()), "\n")
    20  	print("r5      ", hex(c.r5()), "\n")
    21  	print("r6      ", hex(c.r6()), "\n")
    22  	print("r7      ", hex(c.r7()), "\n")
    23  	print("r8      ", hex(c.r8()), "\n")
    24  	print("r9      ", hex(c.r9()), "\n")
    25  	print("r10     ", hex(c.r10()), "\n")
    26  	print("fp      ", hex(c.fp()), "\n")
    27  	print("ip      ", hex(c.ip()), "\n")
    28  	print("sp      ", hex(c.sp()), "\n")
    29  	print("lr      ", hex(c.lr()), "\n")
    30  	print("pc      ", hex(c.pc()), "\n")
    31  	print("cpsr    ", hex(c.cpsr()), "\n")
    32  	print("fault   ", hex(c.fault()), "\n")
    33  }
    34  
    35  //go:nosplit
    36  //go:nowritebarrierrec
    37  func (c *sigctxt) sigpc() uintptr { return uintptr(c.pc()) }
    38  
    39  func (c *sigctxt) sigsp() uintptr { return uintptr(c.sp()) }
    40  func (c *sigctxt) siglr() uintptr { return uintptr(c.lr()) }
    41  
    42  // preparePanic sets up the stack to look like a call to sigpanic.
    43  func (c *sigctxt) preparePanic(sig uint32, gp *g) {
    44  	// We arrange lr, and pc to pretend the panicking
    45  	// function calls sigpanic directly.
    46  	// Always save LR to stack so that panics in leaf
    47  	// functions are correctly handled. This smashes
    48  	// the stack frame but we're not going back there
    49  	// anyway.
    50  	sp := c.sp() - 4
    51  	c.set_sp(sp)
    52  	*(*uint32)(unsafe.Pointer(uintptr(sp))) = c.lr()
    53  
    54  	pc := gp.sigpc
    55  
    56  	if shouldPushSigpanic(gp, pc, uintptr(c.lr())) {
    57  		// Make it look the like faulting PC called sigpanic.
    58  		c.set_lr(uint32(pc))
    59  	}
    60  
    61  	// In case we are panicking from external C code
    62  	c.set_r10(uint32(uintptr(unsafe.Pointer(gp))))
    63  	c.set_pc(uint32(funcPC(sigpanic)))
    64  }
    65  
    66  func (c *sigctxt) pushCall(targetPC, resumePC uintptr) {
    67  	// Push the LR to stack, as we'll clobber it in order to
    68  	// push the call. The function being pushed is responsible
    69  	// for restoring the LR and setting the SP back.
    70  	// This extra slot is known to gentraceback.
    71  	sp := c.sp() - 4
    72  	c.set_sp(sp)
    73  	*(*uint32)(unsafe.Pointer(uintptr(sp))) = c.lr()
    74  	// Set up PC and LR to pretend the function being signaled
    75  	// calls targetPC at resumePC.
    76  	c.set_lr(uint32(resumePC))
    77  	c.set_pc(uint32(targetPC))
    78  }