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