From: Russ Cox Date: Tue, 16 Jun 2009 04:31:56 +0000 (-0700) Subject: fix another gc bug, one that i have only imagined, X-Git-Tag: weekly.2009-11-06~1399 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8c357ce269c3c264ce29ff9c3e52b45d8591b707;p=gostls13.git fix another gc bug, one that i have only imagined, not observed: do not use malloc to allocate stacks during garbage collection, because it would make the malloc data structures change underfoot. R=r DELTA=6 (3 added, 0 deleted, 3 changed) OCL=30323 CL=30326 --- diff --git a/src/pkg/runtime/malloc.c b/src/pkg/runtime/malloc.c index 81cdfb3001..84c802f94a 100644 --- a/src/pkg/runtime/malloc.c +++ b/src/pkg/runtime/malloc.c @@ -274,7 +274,7 @@ stackalloc(uint32 n) uint32 *ref; //return oldmal(n); - if(m->mallocing) { + if(m->mallocing || m->gcing) { lock(&stacks); if(stacks.size == 0) FixAlloc_Init(&stacks, n, SysAlloc, nil, nil); @@ -298,7 +298,7 @@ stackfree(void *v) { //return; - if(m->mallocing) { + if(m->mallocing || m->gcing) { lock(&stacks); FixAlloc_Free(&stacks, v); unlock(&stacks); diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index d58d6ce44d..75f2003783 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -215,6 +215,7 @@ gc(int32 force) if(gcpercent < 0) return; + m->gcing = 1; semacquire(&gcsema); gosave(&g->sched); // update g's stack pointer for scanstack stoptheworld(); @@ -228,4 +229,5 @@ gc(int32 force) starttheworld(); gosave(&g->sched); // update g's stack pointer for debugging semrelease(&gcsema); + m->gcing = 0; } diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index 749364f954..dc80a088dc 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -177,6 +177,7 @@ struct M int32 siz2; int32 id; int32 mallocing; + int32 gcing; int32 locks; Note havenextg; G* nextg;