aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgocall.go
diff options
context:
space:
mode:
authorElias Naur <elias.naur@gmail.com>2017-01-29 15:34:50 +0100
committerElias Naur <elias.naur@gmail.com>2017-02-03 20:07:36 +0000
commit78074f6850c34a955d69f578e363d1d3f3e00e25 (patch)
treedd3094b3311599ae02fcaeba5ec8585e70d3b9c1 /src/runtime/cgocall.go
parentb612ab3acbf3a11ea6dbaac8f244b4bdfed308cd (diff)
downloadgo-78074f6850c34a955d69f578e363d1d3f3e00e25.tar.gz
go-78074f6850c34a955d69f578e363d1d3f3e00e25.zip
runtime: handle SIGPIPE in c-archive and c-shared programs
Before this CL, Go programs in c-archive or c-shared buildmodes would not handle SIGPIPE. That leads to surprising behaviour where writes on a closed pipe or socket would raise SIGPIPE and terminate the program. This CL changes the Go runtime to handle SIGPIPE regardless of buildmode. In addition, SIGPIPE from non-Go code is forwarded. This is a refinement of CL 32796 that fixes the case where a non-default handler for SIGPIPE is installed by the host C program. Fixes #17393 Change-Id: Ia41186e52c1ac209d0a594bae9904166ae7df7de Reviewed-on: https://go-review.googlesource.com/35960 Run-TryBot: Elias Naur <elias.naur@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/cgocall.go')
-rw-r--r--src/runtime/cgocall.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go
index 879e786231..755269ebd2 100644
--- a/src/runtime/cgocall.go
+++ b/src/runtime/cgocall.go
@@ -110,6 +110,7 @@ func cgocall(fn, arg unsafe.Pointer) int32 {
mp := getg().m
mp.ncgocall++
mp.ncgo++
+ mp.incgo = true
// Reset traceback.
mp.cgoCallers[0] = 0
@@ -151,6 +152,7 @@ func cgocall(fn, arg unsafe.Pointer) int32 {
//go:nosplit
func endcgo(mp *m) {
+ mp.incgo = false
mp.ncgo--
if raceenabled {
@@ -180,9 +182,11 @@ func cgocallbackg(ctxt uintptr) {
savedsp := unsafe.Pointer(gp.syscallsp)
savedpc := gp.syscallpc
exitsyscall(0) // coming out of cgo call
+ gp.m.incgo = false
cgocallbackg1(ctxt)
+ gp.m.incgo = true
// going back to cgo call
reentersyscall(savedpc, uintptr(savedsp))