]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: disable preemption during runtime.settype
authorRuss Cox <rsc@golang.org>
Fri, 19 Jul 2013 02:58:49 +0000 (22:58 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 19 Jul 2013 02:58:49 +0000 (22:58 -0400)
It assumes that the m will not change, and the m may
change if the goroutine is preempted.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/11560043

src/pkg/runtime/malloc.goc

index 78535c61f0fc8cde241c87c2a13a8f3dece15476..24ead24c41898eecef918b1fff7372ed9a2bf461 100644 (file)
@@ -672,6 +672,7 @@ runtime·settype(void *v, uintptr t)
                runtime·throw("settype: zero type");
 
        mp = m;
+       m->locks++;
        buf = mp->settype_buf;
        i = mp->settype_bufsize;
        buf[i+0] = (uintptr)v;
@@ -687,6 +688,10 @@ runtime·settype(void *v, uintptr t)
                s = runtime·MHeap_Lookup(&runtime·mheap, v);
                *(uintptr*)((uintptr)v+s->elemsize-sizeof(uintptr)) = t;
        }
+
+       m->locks--;
+       if(m->locks == 0 && g->preempt)  // restore the preemption request in case we've cleared it in newstack
+               g->stackguard0 = StackPreempt;
 }
 
 void