github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/runtime/signal_darwin_amd64.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 package runtime 6 7 import "unsafe" 8 9 type sigctxt struct { 10 info *siginfo 11 ctxt unsafe.Pointer 12 } 13 14 func (c *sigctxt) regs() *regs64 { return &(*ucontext)(c.ctxt).uc_mcontext.ss } 15 func (c *sigctxt) rax() uint64 { return c.regs().rax } 16 func (c *sigctxt) rbx() uint64 { return c.regs().rbx } 17 func (c *sigctxt) rcx() uint64 { return c.regs().rcx } 18 func (c *sigctxt) rdx() uint64 { return c.regs().rdx } 19 func (c *sigctxt) rdi() uint64 { return c.regs().rdi } 20 func (c *sigctxt) rsi() uint64 { return c.regs().rsi } 21 func (c *sigctxt) rbp() uint64 { return c.regs().rbp } 22 func (c *sigctxt) rsp() uint64 { return c.regs().rsp } 23 func (c *sigctxt) r8() uint64 { return c.regs().r8 } 24 func (c *sigctxt) r9() uint64 { return c.regs().r9 } 25 func (c *sigctxt) r10() uint64 { return c.regs().r10 } 26 func (c *sigctxt) r11() uint64 { return c.regs().r11 } 27 func (c *sigctxt) r12() uint64 { return c.regs().r12 } 28 func (c *sigctxt) r13() uint64 { return c.regs().r13 } 29 func (c *sigctxt) r14() uint64 { return c.regs().r14 } 30 func (c *sigctxt) r15() uint64 { return c.regs().r15 } 31 func (c *sigctxt) rip() uint64 { return c.regs().rip } 32 func (c *sigctxt) rflags() uint64 { return c.regs().rflags } 33 func (c *sigctxt) cs() uint64 { return c.regs().cs } 34 func (c *sigctxt) fs() uint64 { return c.regs().fs } 35 func (c *sigctxt) gs() uint64 { return c.regs().gs } 36 func (c *sigctxt) sigcode() uint64 { return uint64(c.info.si_code) } 37 func (c *sigctxt) sigaddr() uint64 { return c.info.si_addr } 38 39 func (c *sigctxt) set_rip(x uint64) { c.regs().rip = x } 40 func (c *sigctxt) set_rsp(x uint64) { c.regs().rsp = x } 41 func (c *sigctxt) set_sigcode(x uint64) { c.info.si_code = int32(x) } 42 func (c *sigctxt) set_sigaddr(x uint64) { c.info.si_addr = x } 43 44 func (c *sigctxt) fixsigcode(sig uint32) { 45 switch sig { 46 case _SIGTRAP: 47 // OS X sets c.sigcode() == TRAP_BRKPT unconditionally for all SIGTRAPs, 48 // leaving no way to distinguish a breakpoint-induced SIGTRAP 49 // from an asynchronous signal SIGTRAP. 50 // They all look breakpoint-induced by default. 51 // Try looking at the code to see if it's a breakpoint. 52 // The assumption is that we're very unlikely to get an 53 // asynchronous SIGTRAP at just the moment that the 54 // PC started to point at unmapped memory. 55 pc := uintptr(c.rip()) 56 // OS X will leave the pc just after the INT 3 instruction. 57 // INT 3 is usually 1 byte, but there is a 2-byte form. 58 code := (*[2]byte)(unsafe.Pointer(pc - 2)) 59 if code[1] != 0xCC && (code[0] != 0xCD || code[1] != 3) { 60 // SIGTRAP on something other than INT 3. 61 c.set_sigcode(_SI_USER) 62 } 63 } 64 }