]> gcc.gnu.org Git - gcc.git/blame - gcc/unwind-sjlj.c
configure.in: Enable libgcj for darwin.
[gcc.git] / gcc / unwind-sjlj.c
CommitLineData
52a11cbf 1/* DWARF2 exception handling and frame unwind runtime interface routines.
a01da83b
KH
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
52a11cbf 4
1322177d 5 This file is part of GCC.
52a11cbf 6
1322177d
LB
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
52a11cbf
RH
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
1322177d
LB
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.
52a11cbf
RH
16
17 You should have received a copy of the GNU General Public License
1322177d
LB
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
52a11cbf
RH
21
22#include "tconfig.h"
23#include "tsystem.h"
4977bab6
ZW
24#include "coretypes.h"
25#include "tm.h"
52a11cbf
RH
26#include "unwind.h"
27#include "gthr.h"
28
0d24f4d1 29#ifdef __USING_SJLJ_EXCEPTIONS__
52a11cbf
RH
30
31#ifdef DONT_USE_BUILTIN_SETJMP
9defc9b7 32#ifndef inhibit_libc
52a11cbf
RH
33#include <setjmp.h>
34#else
9defc9b7
RH
35typedef void *jmp_buf[JMP_BUF_SIZE];
36extern void longjmp(jmp_buf, int) __attribute__((noreturn));
37#endif
38#else
52a11cbf
RH
39#define setjmp __builtin_setjmp
40#define longjmp __builtin_longjmp
41#endif
42
43/* This structure is allocated on the stack of the target function.
44 This must match the definition created in except.c:init_eh. */
45struct SjLj_Function_Context
46{
47 /* This is the chain through all registered contexts. It is
48 filled in by _Unwind_SjLj_Register. */
49 struct SjLj_Function_Context *prev;
50
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. */
54 int call_site;
55
56 /* This is how data is returned from the personality routine to
57 the target function's handler. */
58 _Unwind_Word data[4];
59
60 /* These are filled in once by the target function before any
61 exceptions are expected to be handled. */
62 _Unwind_Personality_Fn personality;
63 void *lsda;
64
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
41077ce4 68 to match that here just in case the system *didn't* have more
52a11cbf
RH
69 restrictive requirements. */
70 jmp_buf jbuf __attribute__((aligned));
71#else
72 void *jbuf[];
73#endif
74};
75
76struct _Unwind_Context
77{
78 struct SjLj_Function_Context *fc;
79};
80
41077ce4 81typedef struct
52a11cbf
RH
82{
83 _Unwind_Personality_Fn personality;
84} _Unwind_FrameState;
85
86\f
87/* Manage the chain of registered function contexts. */
88
89/* Single threaded fallback chain. */
90static struct SjLj_Function_Context *fc_static;
91
92#if __GTHREADS
93static __gthread_key_t fc_key;
94static int use_fc_key = -1;
95
52a11cbf
RH
96static void
97fc_key_init (void)
98{
4977bab6 99 use_fc_key = __gthread_key_create (&fc_key, 0) == 0;
52a11cbf
RH
100}
101
102static void
103fc_key_init_once (void)
104{
105 static __gthread_once_t once = __GTHREAD_ONCE_INIT;
106 if (__gthread_once (&once, fc_key_init) != 0 || use_fc_key < 0)
107 use_fc_key = 0;
108}
109#endif
110
111void
112_Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
113{
114#if __GTHREADS
115 if (use_fc_key < 0)
116 fc_key_init_once ();
117
118 if (use_fc_key)
119 {
120 fc->prev = __gthread_getspecific (fc_key);
121 __gthread_setspecific (fc_key, fc);
122 }
123 else
124#endif
125 {
126 fc->prev = fc_static;
127 fc_static = fc;
128 }
129}
130
131static inline struct SjLj_Function_Context *
132_Unwind_SjLj_GetContext (void)
133{
134#if __GTHREADS
135 if (use_fc_key < 0)
136 fc_key_init_once ();
137
138 if (use_fc_key)
139 return __gthread_getspecific (fc_key);
140#endif
141 return fc_static;
142}
143
144static inline void
145_Unwind_SjLj_SetContext (struct SjLj_Function_Context *fc)
146{
147#if __GTHREADS
148 if (use_fc_key < 0)
149 fc_key_init_once ();
150
151 if (use_fc_key)
152 __gthread_setspecific (fc_key, fc);
153 else
154#endif
155 fc_static = fc;
156}
157
158void
159_Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
160{
161 _Unwind_SjLj_SetContext (fc->prev);
162}
163
164\f
165/* Get/set the return data value at INDEX in CONTEXT. */
166
167_Unwind_Word
168_Unwind_GetGR (struct _Unwind_Context *context, int index)
169{
170 return context->fc->data[index];
171}
172
378683cf
RH
173/* Get the value of the CFA as saved in CONTEXT. */
174
175_Unwind_Word
176_Unwind_GetCFA (struct _Unwind_Context *context)
177{
178 /* ??? Ideally __builtin_setjmp places the CFA in the jmpbuf. */
179 return NULL;
180}
181
52a11cbf
RH
182void
183_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
184{
185 context->fc->data[index] = val;
186}
187
188/* Get the call-site index as saved in CONTEXT. */
189
190_Unwind_Ptr
191_Unwind_GetIP (struct _Unwind_Context *context)
192{
193 return context->fc->call_site + 1;
194}
195
196/* Set the return landing pad index in CONTEXT. */
197
198void
199_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
200{
201 context->fc->call_site = val - 1;
202}
203
204void *
205_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
206{
207 return context->fc->lsda;
208}
209
210_Unwind_Ptr
2adaabc6 211_Unwind_GetRegionStart (struct _Unwind_Context *context __attribute__((unused)) )
52a11cbf
RH
212{
213 return 0;
214}
215
5dafd282 216void *
5154b05d 217_Unwind_FindEnclosingFunction (void *pc)
5dafd282
AH
218{
219 return NULL;
220}
221
48941cb8
RH
222#ifndef __ia64__
223_Unwind_Ptr
2adaabc6 224_Unwind_GetDataRelBase (struct _Unwind_Context *context __attribute__((unused)) )
48941cb8
RH
225{
226 return 0;
227}
228
229_Unwind_Ptr
2adaabc6 230_Unwind_GetTextRelBase (struct _Unwind_Context *context __attribute__((unused)) )
48941cb8
RH
231{
232 return 0;
233}
234#endif
52a11cbf
RH
235\f
236static inline _Unwind_Reason_Code
237uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
238{
239 if (context->fc == NULL)
240 {
241 fs->personality = NULL;
242 return _URC_END_OF_STACK;
243 }
244 else
245 {
246 fs->personality = context->fc->personality;
247 return _URC_NO_REASON;
248 }
249}
250
251static inline void
252uw_update_context (struct _Unwind_Context *context,
253 _Unwind_FrameState *fs __attribute__((unused)) )
254{
255 context->fc = context->fc->prev;
256}
257
41077ce4 258static inline void
52a11cbf
RH
259uw_init_context (struct _Unwind_Context *context)
260{
261 context->fc = _Unwind_SjLj_GetContext ();
262}
263
264/* ??? There appear to be bugs in integrate.c wrt __builtin_longjmp and
981f6289 265 virtual-stack-vars. An inline version of this segfaults on SPARC. */
a01da83b
KH
266#define uw_install_context(CURRENT, TARGET) \
267 do \
268 { \
269 _Unwind_SjLj_SetContext ((TARGET)->fc); \
270 longjmp ((TARGET)->fc->jbuf, 1); \
271 } \
272 while (0)
52a11cbf
RH
273
274
275static inline _Unwind_Ptr
276uw_identify_context (struct _Unwind_Context *context)
277{
278 return (_Unwind_Ptr) context->fc;
279}
280
281
282/* Play games with unwind symbols so that we can have call frame
283 and sjlj symbols in the same shared library. Not that you can
284 use them simultaneously... */
285#define _Unwind_RaiseException _Unwind_SjLj_RaiseException
286#define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
287#define _Unwind_Resume _Unwind_SjLj_Resume
a944ceb9 288#define _Unwind_Resume_or_Rethrow _Unwind_SjLj_Resume_or_Rethrow
52a11cbf
RH
289
290#include "unwind.inc"
291
292#endif /* USING_SJLJ_EXCEPTIONS */
This page took 0.948713 seconds and 5 git commands to generate.