source: trunk/src/gcc/gcc/unwind-sjlj.c@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.4 KB
Line 
1/* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
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
20 02111-1307, USA. */
21
22#include "tconfig.h"
23#include "tsystem.h"
24#include "unwind.h"
25#include "gthr.h"
26
27#ifdef __USING_SJLJ_EXCEPTIONS__
28
29#ifdef DONT_USE_BUILTIN_SETJMP
30#ifndef inhibit_libc
31#include <setjmp.h>
32#else
33typedef void *jmp_buf[JMP_BUF_SIZE];
34extern void longjmp(jmp_buf, int) __attribute__((noreturn));
35#endif
36#else
37#define setjmp __builtin_setjmp
38#define longjmp __builtin_longjmp
39#endif
40
41/* This structure is allocated on the stack of the target function.
42 This must match the definition created in except.c:init_eh. */
43struct SjLj_Function_Context
44{
45 /* This is the chain through all registered contexts. It is
46 filled in by _Unwind_SjLj_Register. */
47 struct SjLj_Function_Context *prev;
48
49 /* This is assigned in by the target function before every call
50 to the index of the call site in the lsda. It is assigned by
51 the personality routine to the landing pad index. */
52 int call_site;
53
54 /* This is how data is returned from the personality routine to
55 the target function's handler. */
56 _Unwind_Word data[4];
57
58 /* These are filled in once by the target function before any
59 exceptions are expected to be handled. */
60 _Unwind_Personality_Fn personality;
61 void *lsda;
62
63#ifdef DONT_USE_BUILTIN_SETJMP
64 /* We don't know what sort of alignment requirements the system
65 jmp_buf has. We over estimated in except.c, and now we have
66 to match that here just in case the system *didn't* have more
67 restrictive requirements. */
68 jmp_buf jbuf __attribute__((aligned));
69#else
70 void *jbuf[];
71#endif
72};
73
74struct _Unwind_Context
75{
76 struct SjLj_Function_Context *fc;
77};
78
79typedef struct
80{
81 _Unwind_Personality_Fn personality;
82} _Unwind_FrameState;
83
84
85
86/* Manage the chain of registered function contexts. */
87
88/* Single threaded fallback chain. */
89static struct SjLj_Function_Context *fc_static;
90
91#if __GTHREADS
92static __gthread_key_t fc_key;
93static int use_fc_key = -1;
94
95static void
96fc_key_dtor (void *ptr)
97{
98 __gthread_key_dtor (fc_key, ptr);
99}
100
101static void
102fc_key_init (void)
103{
104 use_fc_key = __gthread_key_create (&fc_key, fc_key_dtor) == 0;
105}
106
107static void
108fc_key_init_once (void)
109{
110 static __gthread_once_t once = __GTHREAD_ONCE_INIT;
111 if (__gthread_once (&once, fc_key_init) != 0 || use_fc_key < 0)
112 use_fc_key = 0;
113}
114#endif
115
116void
117_Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
118{
119#if __GTHREADS
120 if (use_fc_key < 0)
121 fc_key_init_once ();
122
123 if (use_fc_key)
124 {
125 fc->prev = __gthread_getspecific (fc_key);
126 __gthread_setspecific (fc_key, fc);
127 }
128 else
129#endif
130 {
131 fc->prev = fc_static;
132 fc_static = fc;
133 }
134}
135
136static inline struct SjLj_Function_Context *
137_Unwind_SjLj_GetContext (void)
138{
139#if __GTHREADS
140 if (use_fc_key < 0)
141 fc_key_init_once ();
142
143 if (use_fc_key)
144 return __gthread_getspecific (fc_key);
145#endif
146 return fc_static;
147}
148
149static inline void
150_Unwind_SjLj_SetContext (struct SjLj_Function_Context *fc)
151{
152#if __GTHREADS
153 if (use_fc_key < 0)
154 fc_key_init_once ();
155
156 if (use_fc_key)
157 __gthread_setspecific (fc_key, fc);
158 else
159#endif
160 fc_static = fc;
161}
162
163void
164_Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
165{
166 _Unwind_SjLj_SetContext (fc->prev);
167}
168
169
170
171/* Get/set the return data value at INDEX in CONTEXT. */
172
173_Unwind_Word
174_Unwind_GetGR (struct _Unwind_Context *context, int index)
175{
176 return context->fc->data[index];
177}
178
179void
180_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
181{
182 context->fc->data[index] = val;
183}
184
185/* Get the call-site index as saved in CONTEXT. */
186
187_Unwind_Ptr
188_Unwind_GetIP (struct _Unwind_Context *context)
189{
190 return context->fc->call_site + 1;
191}
192
193/* Set the return landing pad index in CONTEXT. */
194
195void
196_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
197{
198 context->fc->call_site = val - 1;
199}
200
201void *
202_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
203{
204 return context->fc->lsda;
205}
206
207_Unwind_Ptr
208_Unwind_GetRegionStart (struct _Unwind_Context *context __attribute__((unused)) )
209{
210 return 0;
211}
212
213#ifndef __ia64__
214_Unwind_Ptr
215_Unwind_GetDataRelBase (struct _Unwind_Context *context __attribute__((unused)) )
216{
217 return 0;
218}
219
220_Unwind_Ptr
221_Unwind_GetTextRelBase (struct _Unwind_Context *context __attribute__((unused)) )
222{
223 return 0;
224}
225#endif
226
227
228static inline _Unwind_Reason_Code
229uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
230{
231 if (context->fc == NULL)
232 {
233 fs->personality = NULL;
234 return _URC_END_OF_STACK;
235 }
236 else
237 {
238 fs->personality = context->fc->personality;
239 return _URC_NO_REASON;
240 }
241}
242
243static inline void
244uw_update_context (struct _Unwind_Context *context,
245 _Unwind_FrameState *fs __attribute__((unused)) )
246{
247 context->fc = context->fc->prev;
248}
249
250static inline void
251uw_init_context (struct _Unwind_Context *context)
252{
253 context->fc = _Unwind_SjLj_GetContext ();
254}
255
256/* ??? There appear to be bugs in integrate.c wrt __builtin_longjmp and
257 virtual-stack-vars. An inline version of this segfaults on Sparc. */
258#define uw_install_context(CURRENT, TARGET) \
259 do \
260 { \
261 _Unwind_SjLj_SetContext ((TARGET)->fc); \
262 longjmp ((TARGET)->fc->jbuf, 1); \
263 } \
264 while (0)
265
266
267static inline _Unwind_Ptr
268uw_identify_context (struct _Unwind_Context *context)
269{
270 return (_Unwind_Ptr) context->fc;
271}
272
273
274/* Play games with unwind symbols so that we can have call frame
275 and sjlj symbols in the same shared library. Not that you can
276 use them simultaneously... */
277#define _Unwind_RaiseException _Unwind_SjLj_RaiseException
278#define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
279#define _Unwind_Resume _Unwind_SjLj_Resume
280
281#include "unwind.inc"
282
283#endif /* USING_SJLJ_EXCEPTIONS */
Note: See TracBrowser for help on using the repository browser.