]> Cypherpunks repositories - gostls13.git/commitdiff
fix garbage collection race: save stack trace
authorRuss Cox <rsc@golang.org>
Tue, 16 Jun 2009 04:30:53 +0000 (21:30 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 16 Jun 2009 04:30:53 +0000 (21:30 -0700)
when changing process state to Gsyscall, not after.

R=r
DELTA=8  (4 added, 3 deleted, 1 changed)
OCL=30320
CL=30325

src/pkg/runtime/proc.c

index 1d065e6d2ad318cd2aa3a0809df4df86a3ce0bd8..ada3efd4f6b2b269672bd3bfb5031fb81230e3d6 100644 (file)
@@ -447,7 +447,7 @@ scheduler(void)
        if(debug > 1) {
                lock(&debuglock);
                printf("m%d run g%d at %p\n", m->id, gp->goid, gp->sched.PC);
-               traceback(gp->sched.PC, gp->sched.SP+8, gp);
+               traceback(gp->sched.PC, gp->sched.SP+sizeof(uintptr), gp);
                unlock(&debuglock);
        }
        m->curg = gp;
@@ -488,6 +488,10 @@ sys·entersyscall(uint64 callerpc, int64 trap)
        }
        lock(&sched);
        g->status = Gsyscall;
+       // Leave SP around for gc and traceback.
+       // Do before notewakeup so that gc
+       // never sees Gsyscall with wrong stack.
+       gosave(&g->sched);
        sched.mcpu--;
        sched.msyscall++;
        if(sched.gwait != 0)
@@ -497,8 +501,6 @@ sys·entersyscall(uint64 callerpc, int64 trap)
                notewakeup(&sched.stopped);
        }
        unlock(&sched);
-       // leave SP around for gc and traceback
-       gosave(&g->sched);
 }
 
 // The goroutine g exited its system call.
@@ -823,7 +825,6 @@ sys·deferreturn(uintptr arg0)
 {
        Defer *d;
        byte *sp, *fn;
-       uintptr *caller;
 
        d = g->defer;
        if(d == nil)