]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: do not handle signals before configuring handler
authorRuss Cox <rsc@golang.org>
Fri, 16 Mar 2012 02:17:54 +0000 (22:17 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 16 Mar 2012 02:17:54 +0000 (22:17 -0400)
There was a small window during program initialization
where a signal could come in before the handling mechanisms
were set up to handle it.  Delay the signal-handler installation
until we're ready for the signals.

Fixes #3314.

R=golang-dev, dsymonds, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/5833049

src/pkg/runtime/proc.c
src/pkg/runtime/runtime.c

index 844128c87c1cb5ca0f1d823e988da1e1a81d0518..962f748ce860f921bfa8b6d9d9a2a02c75e35897 100644 (file)
@@ -734,6 +734,12 @@ runtime·mstart(void)
        m->g0->sched.pc = (void*)-1;  // make sure it is never used
        runtime·asminit();
        runtime·minit();
+
+       // Install signal handlers; after minit so that minit can
+       // prepare the thread to be able to handle the signals.
+       if(m == &runtime·m0)
+               runtime·initsig();
+
        schedule(nil);
 }
 
@@ -1161,7 +1167,7 @@ runtime·malg(int32 stacksize)
 {
        G *newg;
        byte *stk;
-       
+
        if(StackTop < sizeof(Stktop)) {
                runtime·printf("runtime: SizeofStktop=%d, should be >=%d\n", (int32)StackTop, (int32)sizeof(Stktop));
                runtime·throw("runtime: bad stack.h");
index afe8c5abeb5b8afc99334852e98284242b804b69..ebb5544fbae380316f286b0d9f62b7eab6834e7d 100644 (file)
@@ -119,7 +119,7 @@ void
 runtime·panicstring(int8 *s)
 {
        Eface err;
-       
+
        if(m->gcing) {
                runtime·printf("panic: %s\n", s);
                runtime·throw("panic during gc");
@@ -189,7 +189,7 @@ runtime·goargs(void)
 {
        String *s;
        int32 i;
-       
+
        // for windows implementation see "os" package
        if(Windows)
                return;
@@ -207,7 +207,7 @@ runtime·goenvs_unix(void)
 {
        String *s;
        int32 i, n;
-       
+
        for(n=0; argv[argc+1+n] != 0; n++)
                ;
 
@@ -342,8 +342,6 @@ runtime·check(void)
                runtime·throw("float32nan2");
        if(!(i != i1))
                runtime·throw("float32nan3");
-
-       runtime·initsig();
 }
 
 void