1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #if USING_SJLJ_EXCEPTIONS
28 #ifdef DONT_USE_BUILTIN_SETJMP
32 typedef void *jmp_buf[JMP_BUF_SIZE
];
33 extern void longjmp(jmp_buf, int) __attribute__((noreturn
));
36 #define setjmp __builtin_setjmp
37 #define longjmp __builtin_longjmp
40 /* This structure is allocated on the stack of the target function.
41 This must match the definition created in except.c:init_eh. */
42 struct SjLj_Function_Context
44 /* This is the chain through all registered contexts. It is
45 filled in by _Unwind_SjLj_Register. */
46 struct SjLj_Function_Context
*prev
;
48 /* This is assigned in by the target function before every call
49 to the index of the call site in the lsda. It is assigned by
50 the personality routine to the landing pad index. */
53 /* This is how data is returned from the personality routine to
54 the target function's handler. */
57 /* These are filled in once by the target function before any
58 exceptions are expected to be handled. */
59 _Unwind_Personality_Fn personality
;
62 #ifdef DONT_USE_BUILTIN_SETJMP
63 /* We don't know what sort of alignment requirements the system
64 jmp_buf has. We over estimated in except.c, and now we have
65 to match that here just in case the system *didn't* have more
66 restrictive requirements. */
67 jmp_buf jbuf
__attribute__((aligned
));
73 struct _Unwind_Context
75 struct SjLj_Function_Context
*fc
;
80 _Unwind_Personality_Fn personality
;
84 /* Manage the chain of registered function contexts. */
86 /* Single threaded fallback chain. */
87 static struct SjLj_Function_Context
*fc_static
;
90 static __gthread_key_t fc_key
;
91 static int use_fc_key
= -1;
94 fc_key_dtor (void *ptr
)
96 __gthread_key_dtor (fc_key
, ptr
);
102 use_fc_key
= __gthread_key_create (&fc_key
, fc_key_dtor
) == 0;
106 fc_key_init_once (void)
108 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
109 if (__gthread_once (&once
, fc_key_init
) != 0 || use_fc_key
< 0)
115 _Unwind_SjLj_Register (struct SjLj_Function_Context
*fc
)
123 fc
->prev
= __gthread_getspecific (fc_key
);
124 __gthread_setspecific (fc_key
, fc
);
129 fc
->prev
= fc_static
;
134 static inline struct SjLj_Function_Context
*
135 _Unwind_SjLj_GetContext (void)
142 return __gthread_getspecific (fc_key
);
148 _Unwind_SjLj_SetContext (struct SjLj_Function_Context
*fc
)
155 __gthread_setspecific (fc_key
, fc
);
162 _Unwind_SjLj_Unregister (struct SjLj_Function_Context
*fc
)
164 _Unwind_SjLj_SetContext (fc
->prev
);
168 /* Get/set the return data value at INDEX in CONTEXT. */
171 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
173 return context
->fc
->data
[index
];
177 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
179 context
->fc
->data
[index
] = val
;
182 /* Get the call-site index as saved in CONTEXT. */
185 _Unwind_GetIP (struct _Unwind_Context
*context
)
187 return context
->fc
->call_site
+ 1;
190 /* Set the return landing pad index in CONTEXT. */
193 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
195 context
->fc
->call_site
= val
- 1;
199 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
201 return context
->fc
->lsda
;
205 _Unwind_GetRegionStart (struct _Unwind_Context
*context
__attribute__((unused
)) )
212 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
__attribute__((unused
)) )
218 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
__attribute__((unused
)) )
224 static inline _Unwind_Reason_Code
225 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
227 if (context
->fc
== NULL
)
229 fs
->personality
= NULL
;
230 return _URC_END_OF_STACK
;
234 fs
->personality
= context
->fc
->personality
;
235 return _URC_NO_REASON
;
240 uw_update_context (struct _Unwind_Context
*context
,
241 _Unwind_FrameState
*fs
__attribute__((unused
)) )
243 context
->fc
= context
->fc
->prev
;
247 uw_init_context (struct _Unwind_Context
*context
)
249 context
->fc
= _Unwind_SjLj_GetContext ();
252 /* ??? There appear to be bugs in integrate.c wrt __builtin_longjmp and
253 virtual-stack-vars. An inline version of this segfaults on Sparc. */
254 #define uw_install_context(CURRENT, TARGET) \
256 _Unwind_SjLj_SetContext ((TARGET)->fc); \
257 longjmp ((TARGET)->fc->jbuf, 1); \
261 static inline _Unwind_Ptr
262 uw_identify_context (struct _Unwind_Context
*context
)
264 return (_Unwind_Ptr
) context
->fc
;
268 /* Play games with unwind symbols so that we can have call frame
269 and sjlj symbols in the same shared library. Not that you can
270 use them simultaneously... */
271 #define _Unwind_RaiseException _Unwind_SjLj_RaiseException
272 #define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
273 #define _Unwind_Resume _Unwind_SjLj_Resume
275 #include "unwind.inc"
277 #endif /* USING_SJLJ_EXCEPTIONS */