Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1069)

Unified Diff: src/pkg/runtime/panic.c

Issue 100300043: cmd/gc, runtime: place defer structs on stack if possible (Closed)
Patch Set: diff -r 209bb94bd691 https://code.google.com/p/go/ Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/cmd/gc/subr.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/runtime/panic.c
===================================================================
--- a/src/pkg/runtime/panic.c
+++ b/src/pkg/runtime/panic.c
@@ -102,6 +102,38 @@
return 0;
}
+// Create a new deferred function fn with siz bytes of arguments.
+// The compiler turns a defer statement into a call to this.
+// Cannot split the stack because it assumes that the arguments
+// are available sequentially after &fn; they would not be
+// copied if a stack split occurred. It's OK for this to call
+// functions that split the stack.
+#pragma textflag NOSPLIT
+uintptr
+runtime·deferproc1(Defer *d, uintptr siz, FuncVal *fn, ...)
+{
+ d->siz = siz;
+ d->special = 2;
+ d->link = g->defer;
+ g->defer = d;
+
+ d->fn = fn;
+ d->pc = runtime·getcallerpc(&siz);
+ if(thechar == '5')
+ d->argp = (byte*)(&fn+2); // skip caller's saved link register
+ else
+ d->argp = (byte*)(&fn+1);
+ runtime·memmove(d->args, d->argp, d->siz);
+
+ // deferproc returns 0 normally.
+ // a deferred func that stops a panic
+ // makes the deferproc return 1.
+ // the code the compiler generates always
+ // checks the return value and jumps to the
+ // end of the function if deferproc returns != 0.
+ return 0;
+}
+
// Run a deferred function if there is one.
// The compiler inserts a call to this at the end of any
// function which calls defer.
« no previous file with comments | « src/cmd/gc/subr.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b