github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/src/runtime/signal2_unix.go (about) 1 // Copyright 2012 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 darwin linux 6 7 package runtime 8 9 import "unsafe" 10 11 //go:noescape 12 func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer) 13 14 // Determines if the signal should be handled by Go and if not, forwards the 15 // signal to the handler that was installed before Go's. Returns whether the 16 // signal was forwarded. 17 //go:nosplit 18 func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool { 19 g := getg() 20 c := &sigctxt{info, ctx} 21 if sig >= uint32(len(sigtable)) { 22 return false 23 } 24 fwdFn := fwdSig[sig] 25 flags := sigtable[sig].flags 26 27 // If there is no handler to forward to, no need to forward. 28 if fwdFn == _SIG_DFL { 29 return false 30 } 31 // Only forward synchronous signals. 32 if c.sigcode() == _SI_USER || flags&_SigPanic == 0 { 33 return false 34 } 35 // Determine if the signal occurred inside Go code. We test that: 36 // (1) we were in a goroutine (i.e., m.curg != nil), and 37 // (2) we weren't in CGO (i.e., m.curg.syscallsp == 0). 38 if g != nil && g.m != nil && g.m.curg != nil && g.m.curg.syscallsp == 0 { 39 return false 40 } 41 // Signal not handled by Go, forward it. 42 if fwdFn != _SIG_IGN { 43 sigfwd(fwdFn, sig, info, ctx) 44 } 45 return true 46 }