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
;
48 /* On SPARC the address we get, from __builtin_return_address, is
49 the address of the call instruction. Adjust forward, also
50 skipping the delayed instruction following the call. */
54 dret
= (const char *) d
->__retaddr
;
55 return ret
<= dret
&& ret
+ 16 >= dret
;
58 /* This is only called when it is valid for the caller to recover the
59 value on top of the panic stack, if there is one. */
61 struct __go_empty_interface
65 struct __go_panic_stack
*p
;
69 if (g
->panic
== NULL
|| g
->panic
->__was_recovered
)
71 struct __go_empty_interface ret
;
73 ret
.__type_descriptor
= NULL
;
78 p
->__was_recovered
= 1;