1 /* go-panic.c -- support for the go panic function.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
15 #include "interface.h"
17 /* Print the panic stack. This is used when there is no recover. */
20 __printpanics (Panic
*p
)
24 __printpanics (p
->next
);
25 runtime_printf ("\t");
27 runtime_printf ("panic: ");
28 runtime_printany (p
->arg
);
30 runtime_printf (" [recovered]");
31 runtime_printf ("\n");
34 /* This implements __go_panic which is used for the panic
38 __go_panic (struct __go_empty_interface arg
)
45 n
= (Panic
*) __go_alloc (sizeof (Panic
));
50 /* Run all the defer functions. */
61 pfn
= (void (*) (void *)) d
->pfn
;
70 /* Some defer function called recover. That means that
71 we should stop running this panic. */
76 /* Now unwind the stack by throwing an exception. The
77 compiler has arranged to create exception handlers in
78 each function which uses a defer statement. These
79 exception handlers will check whether the entry on
80 the top of the defer stack is from the current
81 function. If it is, we have unwound the stack far
85 /* __go_unwind_stack should not return. */
89 /* Because we executed that defer function by a panic, and
90 it did not call recover, we know that we are not
91 returning from the calling function--we are panicing
98 /* This may be called by a cgo callback routine to defer the
99 call to syscall.CgocallBackDone, in which case we will not
100 have a memory context. Don't try to free anything in that
101 case--the GC will release it later. */
102 if (runtime_m () != NULL
)
103 runtime_freedefer (d
);
106 /* The panic was not recovered. */
108 runtime_startpanic ();
109 __printpanics (g
->_panic
);