1 /* go-defer.c -- manage the defer stack.
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. */
14 /* This function is called each time we need to defer a call. */
17 __go_defer (_Bool
*frame
, void (*pfn
) (void *), void *arg
)
20 struct __go_defer_stack
*n
;
23 n
= (struct __go_defer_stack
*) __go_alloc (sizeof (struct __go_defer_stack
));
26 n
->__panic
= g
->panic
;
30 n
->__makefunc_can_recover
= 0;
35 /* This function is called when we want to undefer the stack. */
38 __go_undefer (_Bool
*frame
)
43 while (g
->defer
!= NULL
&& g
->defer
->__frame
== frame
)
45 struct __go_defer_stack
*d
;
58 /* This may be called by a cgo callback routine to defer the
59 call to syscall.CgocallBackDone, in which case we will not
60 have a memory context. Don't try to free anything in that
61 case--the GC will release it later. */
63 if (m
!= NULL
&& m
->mcache
!= NULL
&& d
->__free
)
66 /* Since we are executing a defer function here, we know we are
67 returning from the calling function. If the calling
68 function, or one of its callees, paniced, then the defer
69 functions would be executed by __go_panic. */
74 /* This function is called to record the address to which the deferred
75 function returns. This may in turn be checked by __go_can_recover.
76 The frontend relies on this function returning false. */
79 __go_set_defer_retaddr (void *retaddr
)
85 g
->defer
->__retaddr
= retaddr
;