From 8217b4a203daaa7f24590f9369c77b758dad1cd6 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 5 Sep 2014 10:04:16 -0400 Subject: runtime: convert panic/recover to Go created panic1.go just so diffs were available. After this CL is in, I'd like to move panic.go -> defer.go and panic1.go -> panic.go. LGTM=rsc R=rsc, khr CC=golang-codereviews https://golang.org/cl/133530045 --- src/pkg/runtime/stack.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/pkg/runtime/stack.c') diff --git a/src/pkg/runtime/stack.c b/src/pkg/runtime/stack.c index 3993a372e0..f0861e4085 100644 --- a/src/pkg/runtime/stack.c +++ b/src/pkg/runtime/stack.c @@ -714,8 +714,8 @@ adjustdefers(G *gp, AdjustInfo *adjinfo) if(adjinfo->oldstk <= (byte*)d && (byte*)d < adjinfo->oldbase) { // The Defer record is on the stack. Its fields will // get adjusted appropriately. - // This only happens for runtime.main now, but a compiler - // optimization could do more of this. + // This only happens for runtime.main and runtime.gopanic now, + // but a compiler optimization could do more of this. *dp = (Defer*)((byte*)d + adjinfo->delta); continue; } @@ -752,6 +752,25 @@ adjustdefers(G *gp, AdjustInfo *adjinfo) } } +static void +adjustpanics(G *gp, AdjustInfo *adjinfo) +{ + Panic *p; + + // only the topmost panic is on the current stack + p = gp->panic; + if(p == nil) + return; + if(p->link != nil) { + // only the topmost panic can be on the current stack + // (because panic runs defers on a new stack) + if(adjinfo->oldstk <= (byte*)p->link && (byte*)p->link < adjinfo->oldbase) + runtime·throw("two panics on one stack"); + } + if(adjinfo->oldstk <= (byte*)p && (byte*)p < adjinfo->oldbase) + gp->panic = (Panic*)((byte*)p + adjinfo->delta); +} + static void adjustsudogs(G *gp, AdjustInfo *adjinfo) { @@ -811,6 +830,7 @@ copystack(G *gp, uintptr nframes, uintptr newsize) // adjust other miscellaneous things that have pointers into stacks. adjustctxt(gp, &adjinfo); adjustdefers(gp, &adjinfo); + adjustpanics(gp, &adjinfo); adjustsudogs(gp, &adjinfo); // copy the stack (including Stktop) to the new location -- cgit v1.3-5-g9baa