4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 #include "thr_uberdata.h"
32 * This is common code for sparc, sparcv9, and i386.
33 * The amd64 unwind code is vastly different from this.
34 * Look under the amd64-specific directory structure for details.
38 * _ex_unwind() is provided by libC, but if libC is not loaded we
39 * need to call a local version of _ex_unwind() which does exactly
40 * the same thing except for calling C++ destructors.
42 * Note that neither of these literally "returns twice" as, for eg, setjmp
43 * does, but they induce unusual control flow which the compiler should treat
44 * in the same manner (make all registers dead, etc.).
46 extern void _ex_clnup_handler(void *, void (*)(void *)) __RETURNS_TWICE
;
47 extern void _ex_unwind_local(void) __RETURNS_TWICE
;
48 #pragma unknown_control_flow(_ex_clnup_handler)
49 #pragma unknown_control_flow(_ex_unwind_local)
52 * _t_cancel(fp):calls cleanup handlers if there are any in
53 * frame (fp), and calls _ex_unwind() to call
54 * destructors if libC has been linked.
56 * Control comes here from _thrp_unwind. Logically:
58 * _thrp_unwind: first arg = current fp;
61 * We could have called _t_cancel(_getfp) from thr_exit()
62 * but _ex_unwind() also calls _t_cancel() and it does after
63 * poping out the two frames. If _ex_unwind() passes the current
64 * fp, then it will be invalid. For a caller of _thrp_unwind()
65 * it looks as if it is calling _t_cancel(fp).
67 * _t_cancel will eventually call _thrp_exit().
68 * It never returns from _t_cancel().
74 ulwp_t
*self
= curthread
;
76 void (*fptr
)(void (*func
)(void *), void *arg
);
78 /* Do this once per thread exit, not once per unwind frame */
79 if (self
->ul_ex_unwind
== NULL
&&
80 (self
->ul_ex_unwind
= dlsym(RTLD_PROBE
, "_ex_unwind")) == NULL
)
81 self
->ul_ex_unwind
= (void *)-1;
83 if (self
->ul_ex_unwind
== (void *)-1)
86 fptr
= (void (*)())self
->ul_ex_unwind
;
90 thr_panic("_t_cancel(): _thrp_exit() returned");
93 if ((head
= self
->ul_clnup_hdr
) != NULL
&& fp
== head
->fp
) {
94 self
->ul_clnup_hdr
= head
->next
;
95 /* execute the cleanup handler */
96 _ex_clnup_handler(head
->arg
, head
->func
);
97 thr_panic("_t_cancel(): _ex_clnup_handler() returned");
100 if (fptr
!= NULL
&& self
->ul_unwind
) {
101 /* libC is loaded and thread is canceled, call libC version */
102 (*fptr
)(_thrp_unwind
, NULL
);
103 thr_panic("_t_cancel(): _ex_unwind() returned");
104 } else if (head
!= NULL
) {
105 /* libC not present, call local version */
107 thr_panic("_t_cancel(): _ex_unwind_local() returned");
109 /* libC not present and no cleanup handlers, exit here */
111 thr_panic("_t_cancel(): _thrp_exit() returned");
113 /* never returns here */