1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
29 #ifdef __USING_SJLJ_EXCEPTIONS__
31 #ifdef DONT_USE_BUILTIN_SETJMP
35 typedef void *jmp_buf[JMP_BUF_SIZE
];
36 extern void longjmp(jmp_buf, int) __attribute__((noreturn
));
39 #define setjmp __builtin_setjmp
40 #define longjmp __builtin_longjmp
43 /* This structure is allocated on the stack of the target function.
44 This must match the definition created in except.c:init_eh. */
45 struct SjLj_Function_Context
47 /* This is the chain through all registered contexts. It is
48 filled in by _Unwind_SjLj_Register. */
49 struct SjLj_Function_Context
*prev
;
51 /* This is assigned in by the target function before every call
52 to the index of the call site in the lsda. It is assigned by
53 the personality routine to the landing pad index. */
56 /* This is how data is returned from the personality routine to
57 the target function's handler. */
60 /* These are filled in once by the target function before any
61 exceptions are expected to be handled. */
62 _Unwind_Personality_Fn personality
;
65 #ifdef DONT_USE_BUILTIN_SETJMP
66 /* We don't know what sort of alignment requirements the system
67 jmp_buf has. We over estimated in except.c, and now we have
68 to match that here just in case the system *didn't* have more
69 restrictive requirements. */
70 jmp_buf jbuf
__attribute__((aligned
));
76 struct _Unwind_Context
78 struct SjLj_Function_Context
*fc
;
83 _Unwind_Personality_Fn personality
;
87 /* Manage the chain of registered function contexts. */
89 /* Single threaded fallback chain. */
90 static struct SjLj_Function_Context
*fc_static
;
93 static __gthread_key_t fc_key
;
94 static int use_fc_key
= -1;
99 use_fc_key
= __gthread_key_create (&fc_key
, 0) == 0;
103 fc_key_init_once (void)
105 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
106 if (__gthread_once (&once
, fc_key_init
) != 0 || use_fc_key
< 0)
112 _Unwind_SjLj_Register (struct SjLj_Function_Context
*fc
)
120 fc
->prev
= __gthread_getspecific (fc_key
);
121 __gthread_setspecific (fc_key
, fc
);
126 fc
->prev
= fc_static
;
131 static inline struct SjLj_Function_Context
*
132 _Unwind_SjLj_GetContext (void)
139 return __gthread_getspecific (fc_key
);
145 _Unwind_SjLj_SetContext (struct SjLj_Function_Context
*fc
)
152 __gthread_setspecific (fc_key
, fc
);
159 _Unwind_SjLj_Unregister (struct SjLj_Function_Context
*fc
)
161 _Unwind_SjLj_SetContext (fc
->prev
);
165 /* Get/set the return data value at INDEX in CONTEXT. */
168 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
170 return context
->fc
->data
[index
];
174 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
176 context
->fc
->data
[index
] = val
;
179 /* Get the call-site index as saved in CONTEXT. */
182 _Unwind_GetIP (struct _Unwind_Context
*context
)
184 return context
->fc
->call_site
+ 1;
187 /* Set the return landing pad index in CONTEXT. */
190 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
192 context
->fc
->call_site
= val
- 1;
196 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
198 return context
->fc
->lsda
;
202 _Unwind_GetRegionStart (struct _Unwind_Context
*context
__attribute__((unused
)) )
208 _Unwind_FindEnclosingFunction (void *pc
)
215 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
__attribute__((unused
)) )
221 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
__attribute__((unused
)) )
227 static inline _Unwind_Reason_Code
228 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
230 if (context
->fc
== NULL
)
232 fs
->personality
= NULL
;
233 return _URC_END_OF_STACK
;
237 fs
->personality
= context
->fc
->personality
;
238 return _URC_NO_REASON
;
243 uw_update_context (struct _Unwind_Context
*context
,
244 _Unwind_FrameState
*fs
__attribute__((unused
)) )
246 context
->fc
= context
->fc
->prev
;
250 uw_init_context (struct _Unwind_Context
*context
)
252 context
->fc
= _Unwind_SjLj_GetContext ();
255 /* ??? There appear to be bugs in integrate.c wrt __builtin_longjmp and
256 virtual-stack-vars. An inline version of this segfaults on SPARC. */
257 #define uw_install_context(CURRENT, TARGET) \
260 _Unwind_SjLj_SetContext ((TARGET)->fc); \
261 longjmp ((TARGET)->fc->jbuf, 1); \
266 static inline _Unwind_Ptr
267 uw_identify_context (struct _Unwind_Context
*context
)
269 return (_Unwind_Ptr
) context
->fc
;
273 /* Play games with unwind symbols so that we can have call frame
274 and sjlj symbols in the same shared library. Not that you can
275 use them simultaneously... */
276 #define _Unwind_RaiseException _Unwind_SjLj_RaiseException
277 #define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
278 #define _Unwind_Resume _Unwind_SjLj_Resume
280 #include "unwind.inc"
282 #endif /* USING_SJLJ_EXCEPTIONS */