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. |