]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: turn "too many EPIPE" into real SIGPIPE
authorRuss Cox <rsc@golang.org>
Mon, 25 Apr 2011 20:58:00 +0000 (16:58 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 25 Apr 2011 20:58:00 +0000 (16:58 -0400)
Tested on Linux and OS X, amd64 and 386.

R=r, iant
CC=golang-dev
https://golang.org/cl/4452046

20 files changed:
src/pkg/os/file_posix.go
src/pkg/runtime/darwin/386/signal.c
src/pkg/runtime/darwin/386/sys.s
src/pkg/runtime/darwin/amd64/signal.c
src/pkg/runtime/darwin/amd64/sys.s
src/pkg/runtime/darwin/os.h
src/pkg/runtime/freebsd/386/signal.c
src/pkg/runtime/freebsd/386/sys.s
src/pkg/runtime/freebsd/amd64/signal.c
src/pkg/runtime/freebsd/amd64/sys.s
src/pkg/runtime/freebsd/os.h
src/pkg/runtime/linux/386/signal.c
src/pkg/runtime/linux/386/sys.s
src/pkg/runtime/linux/amd64/signal.c
src/pkg/runtime/linux/amd64/sys.s
src/pkg/runtime/linux/arm/signal.c
src/pkg/runtime/linux/arm/sys.s
src/pkg/runtime/linux/os.h
src/pkg/runtime/plan9/thread.c
src/pkg/runtime/windows/thread.c

index 7d96818b7f6ab52a25a47c142a1f091c699ee3d4..f1191d61feb7a427064e51bae059c5d78bacc255 100644 (file)
@@ -10,11 +10,13 @@ import (
        "syscall"
 )
 
+func sigpipe() // implemented in package runtime
+
 func epipecheck(file *File, e int) {
        if e == syscall.EPIPE {
                file.nepipe++
                if file.nepipe >= 10 {
-                       panic("os.File Write: caller keeps writing after too many EPIPE errors")
+                       sigpipe()
                }
        } else {
                file.nepipe = 0
index 35bbb178b1cdc3e17a39fdc793ee23ab37991828..29170b6691bbdecfab657a989ebd915ae2706ef4 100644 (file)
@@ -185,3 +185,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index 08eca9d5a87ca57376312bc9959c499a15582e49..87fbdbb79ec249e603c7f60f2ed31aa53a5d0103 100644 (file)
@@ -33,6 +33,16 @@ TEXT runtime·write(SB),7,$0
        INT     $0x80
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$8
+       get_tls(CX)
+       MOVL    m(CX), DX
+       MOVL    m_procid(DX), DX
+       MOVL    DX, 0(SP)       // thread_port
+       MOVL    $13, 4(SP)      // signal: SIGPIPE
+       MOVL    $328, AX        // __pthread_kill
+       INT     $0x80
+       RET
+
 TEXT runtime·mmap(SB),7,$0
        MOVL    $197, AX
        INT     $0x80
index 3a99d2308fc595a17f675024d33ef2289cbcd543..036a3aca73cf4db583d4bae40d45419180f2c8bb 100644 (file)
@@ -195,3 +195,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index 39398e065d56c975b959ca2ee4df57b46a65369f..8d1b20f11899e8ed0cc254b757ec8bd94efd86dd 100644 (file)
@@ -38,6 +38,15 @@ TEXT runtime·write(SB),7,$0
        SYSCALL
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$24
+       get_tls(CX)
+       MOVQ    m(CX), DX
+       MOVL    $13, DI // arg 1 SIGPIPE
+       MOVQ    m_procid(DX), SI        // arg 2 thread_port
+       MOVL    $(0x2000000+328), AX    // syscall entry __pthread_kill
+       SYSCALL
+       RET
+
 TEXT runtime·setitimer(SB), 7, $0
        MOVL    8(SP), DI
        MOVQ    16(SP), SI
index 339768e5163d56282062e6080dc848002028c6d9..db3c2e8a7c6fc9a802fce8899bca6a7f880a93bd 100644 (file)
@@ -27,3 +27,5 @@ void  runtime·sigaltstack(struct StackT*, struct StackT*);
 void   runtime·sigtramp(void);
 void   runtime·sigpanic(void);
 void   runtime·setitimer(int32, Itimerval*, Itimerval*);
+
+void   runtime·raisesigpipe(void);
index 1ae2554eb47a9175d7c81447f8060072beb7e6db..3600f0762a1051f9b807c08c331d9d2fa132b2fa 100644 (file)
@@ -182,3 +182,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index c4715b668bb702bffb287751e6db163e3dd17ae1..765e2fcc40e3f32c8b256eb0ed11f2dd86b39f33 100644 (file)
@@ -60,6 +60,20 @@ TEXT runtime·write(SB),7,$-4
        INT     $0x80
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$12
+       // thr_self(&8(SP))
+       LEAL    8(SP), AX
+       MOVL    AX, 0(SP)
+       MOVL    $432, AX
+       INT     $0x80
+       // thr_kill(self, SIGPIPE)
+       MOVL    8(SP), AX
+       MOVL    AX, 0(SP)
+       MOVL    $13, 4(SP)
+       MOVL    $433, AX
+       INT     $0x80
+       RET
+
 TEXT runtime·notok(SB),7,$0
        MOVL    $0xf1, 0xf1
        RET
index 9d8e5e692958278575cb1c04d1d29c4e1c75eb96..85cb1d855274d9dac66c5e5bd10c1788dd64ac03 100644 (file)
@@ -190,3 +190,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index 9a6fdf1ac6c916d3b4904e21674a5fde7c86d501..c5cc082e4d127ab516e5b8b379b771d0a803e32c 100644 (file)
@@ -65,6 +65,18 @@ TEXT runtime·write(SB),7,$-8
        SYSCALL
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$16
+       // thr_self(&8(SP))
+       LEAQ    8(SP), DI       // arg 1 &8(SP)
+       MOVL    $432, AX
+       SYSCALL
+       // thr_kill(self, SIGPIPE)
+       MOVQ    8(SP), DI       // arg 1 id
+       MOVQ    $13, SI // arg 2 SIGPIPE
+       MOVL    $433, AX
+       SYSCALL
+       RET
+
 TEXT runtime·setitimer(SB), 7, $-8
        MOVL    8(SP), DI
        MOVQ    16(SP), SI
index 13754688b4b3ad0f0635d3b7ed1adaaaa513981f..007856c6bcd773109dc3eba264eb962a703c760b 100644 (file)
@@ -8,3 +8,5 @@ struct sigaction;
 void runtime·sigaction(int32, struct sigaction*, struct sigaction*);
 void   runtiem·setitimerval(int32, Itimerval*, Itimerval*);
 void   runtime·setitimer(int32, Itimerval*, Itimerval*);
+
+void   runtime·raisesigpipe(void);
index 9b72ecbaeef05ad27feb1fcb94d0b7e65a3a71e0..8916e10bd1822fb2e18873cf10b93aea654d3afb 100644 (file)
@@ -175,3 +175,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index c39ce253f064c338bb8e40f11f4436099a7208ab..868a0d901a89d9e3d9e69d69bcd44ba642162e7d 100644 (file)
@@ -30,6 +30,14 @@ TEXT runtime·write(SB),7,$0
        INT     $0x80
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$12
+       MOVL    $224, AX        // syscall - gettid
+       INT     $0x80
+       MOVL    AX, 0(SP)       // arg 1 tid
+       MOVL    $13, 4(SP)      // arg 2 SIGPIPE
+       MOVL    $238, AX        // syscall - tkill
+       INT     $0x80
+       RET
 
 TEXT runtime·setitimer(SB),7,$0-24
        MOVL    $104, AX                        // syscall - setitimer
index 1db9c95e50b2dbd785a899bf1a006bf799d2fb0a..ee90271ed2e2b01704458d7f1635dcc33fe66681 100644 (file)
@@ -185,3 +185,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index 11df1f894b27165f162733c63c446b44d3dc07a5..eadd30005880b7509cb4e96ebd743070d6f30e90 100644 (file)
@@ -36,6 +36,15 @@ TEXT runtime·write(SB),7,$0-24
        SYSCALL
        RET
 
+TEXT runtime·raisesigpipe(SB),7,$12
+       MOVL    $186, AX        // syscall - gettid
+       SYSCALL
+       MOVL    AX, DI  // arg 1 tid
+       MOVL    $13, SI // arg 2 SIGPIPE
+       MOVL    $200, AX        // syscall - tkill
+       SYSCALL
+       RET
+
 TEXT runtime·setitimer(SB),7,$0-24
        MOVL    8(SP), DI
        MOVQ    16(SP), SI
index 05c6b0261299df35b843312a33958f66a9a798d6..88a84d1120a4a66e6dfb4d647cb02fd551b007f5 100644 (file)
@@ -180,3 +180,10 @@ runtime·resetcpuprofiler(int32 hz)
        }
        m->profilehz = hz;
 }
+
+void
+os·sigpipe(void)
+{
+       sigaction(SIGPIPE, SIG_DFL, false);
+       runtime·raisesigpipe();
+}
index b9767a0284d00617afdd69e18e869e2c2fb59816..3fe7d4a82839d5f45313c3cb9cf56286dcd98976 100644 (file)
@@ -27,6 +27,8 @@
 #define SYS_exit_group (SYS_BASE + 248)
 #define SYS_munmap (SYS_BASE + 91)
 #define SYS_setitimer (SYS_BASE + 104)
+#define SYS_gettid (SYS_BASE + 224)
+#define SYS_tkill (SYS_BASE + 238)
 
 #define ARM_BASE (SYS_BASE + 0x0f0000)
 #define SYS_ARM_cacheflush (ARM_BASE + 2)
@@ -55,6 +57,15 @@ TEXT runtime·exit1(SB),7,$-4
        MOVW    $1003, R1
        MOVW    R0, (R1)        // fail hard
 
+TEXT   runtime·raisesigpipe(SB),7,$-4
+       MOVW    $SYS_gettid, R7
+       SWI     $0
+       // arg 1 tid already in R0 from gettid
+       MOVW    $13, R1 // arg 2 SIGPIPE
+       MOVW    $SYS_tkill, R7
+       SWI     $0
+       RET
+
 TEXT runtime·mmap(SB),7,$0
        MOVW    0(FP), R0
        MOVW    4(FP), R1
index 6ae08897772f085e5e4106199dd79437b638d115..0bb8d03392eabfca333acc27ec88c49249a1f3ef 100644 (file)
@@ -15,3 +15,5 @@ void  runtime·rt_sigaction(uintptr, struct Sigaction*, void*, uintptr);
 void   runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
 void   runtime·sigpanic(void);
 void runtime·setitimer(int32, Itimerval*, Itimerval*);
+
+void   runtime·raisesigpipe(void);
index fa96552a91543390c2d9a78d121f20404ecf461a..7c6ca45a3d66724f0ae666de108ec47dc3453bea 100644 (file)
@@ -138,3 +138,8 @@ runtime·notewakeup(Note *n)
        runtime·usemrelease(&n->sema);
 }
 
+void
+os·sigpipe(void)
+{
+       runtime·throw("too many writes on closed pipe");
+}
index aedd24200af561e4f2239a452404e2da41caf313..2ce92dcfbfd969ac2bb3d995d6f4fb749afd14db 100644 (file)
@@ -378,3 +378,9 @@ runtime·compilecallback(Eface fn, bool cleanstack)
 
        return ret;
 }
+
+void
+os·sigpipe(void)
+{
+       runtime·throw("too many writes on closed pipe");
+}