From: Russ Cox Date: Tue, 16 Jun 2009 04:30:53 +0000 (-0700) Subject: fix garbage collection race: save stack trace X-Git-Tag: weekly.2009-11-06~1400 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=36835c7a47dac796f64159e5e1b1d5abc26c4b8b;p=gostls13.git fix garbage collection race: save stack trace when changing process state to Gsyscall, not after. R=r DELTA=8 (4 added, 3 deleted, 1 changed) OCL=30320 CL=30325 --- diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 1d065e6d2a..ada3efd4f6 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -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)