1 /* go-recover.c -- support for the go recover function.
3 Copyright 2010 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. */
12 /* This is called by a thunk to see if the real function should be
13 permitted to recover a panic value. Recovering a value is
14 permitted if the thunk was called directly by defer. RETADDR is
15 the return address of the function which is calling
16 __go_can_recover--this is, the thunk. */
19 __go_can_recover (const void* retaddr
)
22 struct __go_defer_stack
*d
;
32 /* The panic which this function would recover is the one on the top
33 of the panic stack. We do not want to recover it if that panic
34 was on the top of the panic stack when this function was
36 if (d
->__panic
== g
->panic
)
39 /* D->__RETADDR is the address of a label immediately following the
40 call to the thunk. We can recover a panic if that is the same as
41 the return address of the thunk. We permit a bit of slack in
42 case there is any code between the function return and the label,
43 such as an instruction to adjust the stack pointer. */
45 ret
= (const char *) retaddr
;
46 dret
= (const char *) d
->__retaddr
;
47 return ret
<= dret
&& ret
+ 16 >= dret
;
50 /* This is only called when it is valid for the caller to recover the
51 value on top of the panic stack, if there is one. */
53 struct __go_empty_interface
57 struct __go_panic_stack
*p
;
61 if (g
->panic
== NULL
|| g
->panic
->__was_recovered
)
63 struct __go_empty_interface ret
;
65 ret
.__type_descriptor
= NULL
;
70 p
->__was_recovered
= 1;