]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: darwin signal masking
authorRuss Cox <rsc@golang.org>
Thu, 23 Feb 2012 19:44:06 +0000 (14:44 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 23 Feb 2012 19:44:06 +0000 (14:44 -0500)
Fixes #3101 (darwin).

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5693044

src/pkg/runtime/os_darwin.h
src/pkg/runtime/sys_darwin_386.s
src/pkg/runtime/sys_darwin_amd64.s
src/pkg/runtime/thread_darwin.c

index 0003b66c91aab2c5b455a054cf996acf13f8b674..071a547177dfaf10af642066fb42fbf1f155567c 100644 (file)
@@ -20,6 +20,9 @@ uint32        runtime·mach_thread_self(void);
 uint32 runtime·mach_thread_self(void);
 int32  runtime·sysctl(uint32*, uint32, byte*, uintptr*, byte*, uintptr);
 
+typedef uint32 Sigset;
+void   runtime·sigprocmask(int32, Sigset*, Sigset*);
+
 struct Sigaction;
 void   runtime·sigaction(uintptr, struct Sigaction*, struct Sigaction*);
 void   runtime·setsig(int32, void(*)(int32, Siginfo*, void*, G*), bool);
@@ -35,3 +38,4 @@ void  runtime·raisesigpipe(void);
 
 #define        NSIG 32
 #define        SI_USER 0  /* empirically true, but not what headers say */
+#define        SIG_SETMASK 3
index 24eac766aac8d01082aacead41d4df72b9e4deb0..e235a8473ddd41988eeec618e7ea6acdc8e16191 100644 (file)
@@ -106,6 +106,13 @@ TEXT runtime·nanotime(SB), 7, $32
        MOVL    DX, 4(DI)
        RET
 
+TEXT runtime·sigprocmask(SB),7,$0
+       MOVL    $48, AX
+       INT     $0x80
+       JAE     2(PC)
+       CALL    runtime·notok(SB)
+       RET
+
 TEXT runtime·sigaction(SB),7,$0
        MOVL    $46, AX
        INT     $0x80
index 9d2ecbe2a544ec18776c39a14a0c4d0ec7cccc71..13882c8524ee932abbbd54bc71641e242d41b116 100644 (file)
@@ -92,6 +92,16 @@ TEXT runtime·nanotime(SB), 7, $32
        ADDQ    DX, AX
        RET
 
+TEXT runtime·sigprocmask(SB),7,$0
+       MOVL    8(SP), DI
+       MOVQ    16(SP), SI
+       MOVQ    24(SP), DX
+       MOVL    $(0x2000000+48), AX     // syscall entry
+       SYSCALL
+       JCC     2(PC)
+       CALL    runtime·notok(SB)
+       RET
+
 TEXT runtime·sigaction(SB),7,$0
        MOVL    8(SP), DI               // arg 1 sig
        MOVQ    16(SP), SI              // arg 2 act
index 832c74beafe8d30e4b8e1a8121bb4d4b14159643..42fb7702e8f0b771283d42385a8ac86754f9e97f 100644 (file)
@@ -9,6 +9,9 @@
 
 extern SigTab runtime·sigtab[];
 
+static Sigset sigset_all = ~(Sigset)0;
+static Sigset sigset_none;
+
 static void
 unimplemented(int8 *name)
 {
@@ -70,13 +73,19 @@ void
 runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
 {
        int32 errno;
+       Sigset oset;
 
        m->tls[0] = m->id;      // so 386 asm can find it
        if(0){
                runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
                        stk, m, g, fn, m->id, m->tls[0], &m);
        }
-       if((errno = runtime·bsdthread_create(stk, m, g, fn)) < 0) {
+
+       runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
+       errno = runtime·bsdthread_create(stk, m, g, fn);
+       runtime·sigprocmask(SIG_SETMASK, &oset, nil);
+       
+       if(errno < 0) {
                runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), -errno);
                runtime·throw("runtime.newosproc");
        }
@@ -89,6 +98,7 @@ runtime·minit(void)
        // Initialize signal handling.
        m->gsignal = runtime·malg(32*1024);    // OS X wants >=8K, Linux >=2K
        runtime·signalstack(m->gsignal->stackguard - StackGuard, 32*1024);
+       runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
 }
 
 // Mach IPC, to get at semaphores