Commit dd740343 authored by Dave Cheney's avatar Dave Cheney Committed by Russ Cox

runtime: stack allocate Panic structure during runtime.panic

Update #7347

When runtime.panic is called the *Panic is malloced from the heap. This can lead to a gc cycle while panicing which can make a bad situation worse.

It appears to be possible to stack allocate the Panic and avoid malloc'ing during a panic.

Ref: https://groups.google.com/d/topic/golang-dev/OfxqpklGkh0/discussion

LGTM=minux.ma, dvyukov, rsc
R=r, minux.ma, gobot, rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/66830043
parent 86c976ff
......@@ -211,14 +211,14 @@ void
runtime·panic(Eface e)
{
Defer *d;
Panic *p;
Panic p;
void *pc, *argp;
p = runtime·mal(sizeof *p);
p->arg = e;
p->link = g->panic;
p->stackbase = g->stackbase;
g->panic = p;
runtime·memclr((byte*)&p, sizeof p);
p.arg = e;
p.link = g->panic;
p.stackbase = g->stackbase;
g->panic = &p;
for(;;) {
d = g->defer;
......@@ -231,11 +231,10 @@ runtime·panic(Eface e)
pc = d->pc;
runtime·newstackcall(d->fn, (byte*)d->args, d->siz);
freedefer(d);
if(p->recovered) {
g->panic = p->link;
if(p.recovered) {
g->panic = p.link;
if(g->panic == nil) // must be done with signal
g->sig = 0;
runtime·free(p);
// Pass information about recovering frame to recovery.
g->sigcode0 = (uintptr)argp;
g->sigcode1 = (uintptr)pc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment