]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/libsupc++/eh_personality.cc
Inital import
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / libsupc++ / eh_personality.cc
1 // -*- C++ -*- The GNU C++ exception personality routine.
2 // Copyright (C) 2001, 2002, 2003, 2006, 2008 Free Software Foundation, Inc.
3 //
4 // This file is part of GCC.
5 //
6 // GCC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10 //
11 // GCC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
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
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 #include <bits/c++config.h>
31 #include <cstdlib>
32 #include <exception_defines.h>
33 #include <cxxabi.h>
34 #include "unwind-cxx.h"
35
36 using namespace __cxxabiv1;
37
38 #ifdef __ARM_EABI_UNWINDER__
39 #define NO_SIZE_OF_ENCODED_VALUE
40 #endif
41
42 #include "unwind-pe.h"
43
44 \f
45 struct lsda_header_info
46 {
47   _Unwind_Ptr Start;
48   _Unwind_Ptr LPStart;
49   _Unwind_Ptr ttype_base;
50   const unsigned char *TType;
51   const unsigned char *action_table;
52   unsigned char ttype_encoding;
53   unsigned char call_site_encoding;
54 };
55
56 static const unsigned char *
57 parse_lsda_header (_Unwind_Context *context, const unsigned char *p,
58                    lsda_header_info *info)
59 {
60   _uleb128_t tmp;
61   unsigned char lpstart_encoding;
62
63   info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
64
65   // Find @LPStart, the base to which landing pad offsets are relative.
66   lpstart_encoding = *p++;
67   if (lpstart_encoding != DW_EH_PE_omit)
68     p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
69   else
70     info->LPStart = info->Start;
71
72   // Find @TType, the base of the handler and exception spec type data.
73   info->ttype_encoding = *p++;
74   if (info->ttype_encoding != DW_EH_PE_omit)
75     {
76       p = read_uleb128 (p, &tmp);
77       info->TType = p + tmp;
78     }
79   else
80     info->TType = 0;
81
82   // The encoding and length of the call-site table; the action table
83   // immediately follows.
84   info->call_site_encoding = *p++;
85   p = read_uleb128 (p, &tmp);
86   info->action_table = p + tmp;
87
88   return p;
89 }
90
91 #ifdef __ARM_EABI_UNWINDER__
92
93 // Return an element from a type table.
94
95 static const std::type_info*
96 get_ttype_entry(lsda_header_info* info, _uleb128_t i)
97 {
98   _Unwind_Ptr ptr;
99
100   ptr = (_Unwind_Ptr) (info->TType - (i * 4));
101   ptr = _Unwind_decode_target2(ptr);
102   
103   return reinterpret_cast<const std::type_info *>(ptr);
104 }
105
106 // The ABI provides a routine for matching exception object types.
107 typedef _Unwind_Control_Block _throw_typet;
108 #define get_adjusted_ptr(catch_type, throw_type, thrown_ptr_p) \
109   (__cxa_type_match (throw_type, catch_type, false, thrown_ptr_p) \
110    != ctm_failed)
111
112 // Return true if THROW_TYPE matches one if the filter types.
113
114 static bool
115 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
116                      void* thrown_ptr, _sleb128_t filter_value)
117 {
118   const _uleb128_t* e = ((const _uleb128_t*) info->TType)
119                           - filter_value - 1;
120
121   while (1)
122     {
123       const std::type_info* catch_type;
124       _uleb128_t tmp;
125
126       tmp = *e;
127       
128       // Zero signals the end of the list.  If we've not found
129       // a match by now, then we've failed the specification.
130       if (tmp == 0)
131         return false;
132
133       tmp = _Unwind_decode_target2((_Unwind_Word) e);
134
135       // Match a ttype entry.
136       catch_type = reinterpret_cast<const std::type_info*>(tmp);
137
138       // ??? There is currently no way to ask the RTTI code about the
139       // relationship between two types without reference to a specific
140       // object.  There should be; then we wouldn't need to mess with
141       // thrown_ptr here.
142       if (get_adjusted_ptr(catch_type, throw_type, &thrown_ptr))
143         return true;
144
145       // Advance to the next entry.
146       e++;
147     }
148 }
149
150
151 // Save stage1 handler information in the exception object
152
153 static inline void
154 save_caught_exception(struct _Unwind_Exception* ue_header,
155                       struct _Unwind_Context* context,
156                       void* thrown_ptr,
157                       int handler_switch_value,
158                       const unsigned char* language_specific_data,
159                       _Unwind_Ptr landing_pad,
160                       const unsigned char* action_record
161                         __attribute__((__unused__)))
162 {
163     ue_header->barrier_cache.sp = _Unwind_GetGR(context, 13);
164     ue_header->barrier_cache.bitpattern[0] = (_uw) thrown_ptr;
165     ue_header->barrier_cache.bitpattern[1]
166       = (_uw) handler_switch_value;
167     ue_header->barrier_cache.bitpattern[2]
168       = (_uw) language_specific_data;
169     ue_header->barrier_cache.bitpattern[3] = (_uw) landing_pad;
170 }
171
172
173 // Restore the catch handler data saved during phase1.
174
175 static inline void
176 restore_caught_exception(struct _Unwind_Exception* ue_header,
177                          int& handler_switch_value,
178                          const unsigned char*& language_specific_data,
179                          _Unwind_Ptr& landing_pad)
180 {
181   handler_switch_value = (int) ue_header->barrier_cache.bitpattern[1];
182   language_specific_data =
183     (const unsigned char*) ue_header->barrier_cache.bitpattern[2];
184   landing_pad = (_Unwind_Ptr) ue_header->barrier_cache.bitpattern[3];
185 }
186
187 #define CONTINUE_UNWINDING \
188   do                                                            \
189     {                                                           \
190       if (__gnu_unwind_frame(ue_header, context) != _URC_OK)    \
191         return _URC_FAILURE;                                    \
192       return _URC_CONTINUE_UNWIND;                              \
193     }                                                           \
194   while (0)
195
196 // Return true if the filter spec is empty, ie throw().
197
198 static bool
199 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
200 {
201   const _Unwind_Word* e = ((const _Unwind_Word*) info->TType)
202                           - filter_value - 1;
203
204   return *e == 0;
205 }
206
207 #else
208 typedef const std::type_info _throw_typet;
209
210
211 // Return an element from a type table.
212
213 static const std::type_info *
214 get_ttype_entry (lsda_header_info *info, _uleb128_t i)
215 {
216   _Unwind_Ptr ptr;
217
218   i *= size_of_encoded_value (info->ttype_encoding);
219   read_encoded_value_with_base (info->ttype_encoding, info->ttype_base,
220                                 info->TType - i, &ptr);
221
222   return reinterpret_cast<const std::type_info *>(ptr);
223 }
224
225 // Given the thrown type THROW_TYPE, pointer to a variable containing a
226 // pointer to the exception object THROWN_PTR_P and a type CATCH_TYPE to
227 // compare against, return whether or not there is a match and if so,
228 // update *THROWN_PTR_P.
229
230 static bool
231 get_adjusted_ptr (const std::type_info *catch_type,
232                   const std::type_info *throw_type,
233                   void **thrown_ptr_p)
234 {
235   void *thrown_ptr = *thrown_ptr_p;
236
237   // Pointer types need to adjust the actual pointer, not
238   // the pointer to pointer that is the exception object.
239   // This also has the effect of passing pointer types
240   // "by value" through the __cxa_begin_catch return value.
241   if (throw_type->__is_pointer_p ())
242     thrown_ptr = *(void **) thrown_ptr;
243
244   if (catch_type->__do_catch (throw_type, &thrown_ptr, 1))
245     {
246       *thrown_ptr_p = thrown_ptr;
247       return true;
248     }
249
250   return false;
251 }
252
253 // Return true if THROW_TYPE matches one if the filter types.
254
255 static bool
256 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
257                       void* thrown_ptr, _sleb128_t filter_value)
258 {
259   const unsigned char *e = info->TType - filter_value - 1;
260
261   while (1)
262     {
263       const std::type_info *catch_type;
264       _uleb128_t tmp;
265
266       e = read_uleb128 (e, &tmp);
267
268       // Zero signals the end of the list.  If we've not found
269       // a match by now, then we've failed the specification.
270       if (tmp == 0)
271         return false;
272
273       // Match a ttype entry.
274       catch_type = get_ttype_entry (info, tmp);
275
276       // ??? There is currently no way to ask the RTTI code about the
277       // relationship between two types without reference to a specific
278       // object.  There should be; then we wouldn't need to mess with
279       // thrown_ptr here.
280       if (get_adjusted_ptr (catch_type, throw_type, &thrown_ptr))
281         return true;
282     }
283 }
284
285
286 // Save stage1 handler information in the exception object
287
288 static inline void
289 save_caught_exception(struct _Unwind_Exception* ue_header,
290                       struct _Unwind_Context* context
291                         __attribute__((__unused__)),
292                       void* thrown_ptr,
293                       int handler_switch_value,
294                       const unsigned char* language_specific_data,
295                       _Unwind_Ptr landing_pad __attribute__((__unused__)),
296                       const unsigned char* action_record)
297 {
298   __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
299
300   xh->handlerSwitchValue = handler_switch_value;
301   xh->actionRecord = action_record;
302   xh->languageSpecificData = language_specific_data;
303   xh->adjustedPtr = thrown_ptr;
304
305   // ??? Completely unknown what this field is supposed to be for.
306   // ??? Need to cache TType encoding base for call_unexpected.
307   xh->catchTemp = landing_pad;
308 }
309
310
311 // Restore the catch handler information saved during phase1.
312
313 static inline void
314 restore_caught_exception(struct _Unwind_Exception* ue_header,
315                          int& handler_switch_value,
316                          const unsigned char*& language_specific_data,
317                          _Unwind_Ptr& landing_pad)
318 {
319   __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
320   handler_switch_value = xh->handlerSwitchValue;
321   language_specific_data = xh->languageSpecificData;
322   landing_pad = (_Unwind_Ptr) xh->catchTemp;
323 }
324
325 #define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
326
327 // Return true if the filter spec is empty, ie throw().
328
329 static bool
330 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
331 {
332   const unsigned char *e = info->TType - filter_value - 1;
333   _uleb128_t tmp;
334
335   e = read_uleb128 (e, &tmp);
336   return tmp == 0;
337 }
338
339 #endif // !__ARM_EABI_UNWINDER__
340
341 namespace __cxxabiv1
342 {
343
344 // Using a different personality function name causes link failures
345 // when trying to mix code using different exception handling models.
346 #ifdef _GLIBCXX_SJLJ_EXCEPTIONS
347 #define PERSONALITY_FUNCTION    __gxx_personality_sj0
348 #define __builtin_eh_return_data_regno(x) x
349 #else
350 #define PERSONALITY_FUNCTION    __gxx_personality_v0
351 #endif
352
353 extern "C" _Unwind_Reason_Code
354 #ifdef __ARM_EABI_UNWINDER__
355 PERSONALITY_FUNCTION (_Unwind_State state,
356                       struct _Unwind_Exception* ue_header,
357                       struct _Unwind_Context* context)
358 #else
359 PERSONALITY_FUNCTION (int version,
360                       _Unwind_Action actions,
361                       _Unwind_Exception_Class exception_class,
362                       struct _Unwind_Exception *ue_header,
363                       struct _Unwind_Context *context)
364 #endif
365 {
366   enum found_handler_type
367   {
368     found_nothing,
369     found_terminate,
370     found_cleanup,
371     found_handler
372   } found_type;
373
374   lsda_header_info info;
375   const unsigned char *language_specific_data;
376   const unsigned char *action_record;
377   const unsigned char *p;
378   _Unwind_Ptr landing_pad, ip;
379   int handler_switch_value;
380   void* thrown_ptr = ue_header + 1;
381   bool foreign_exception;
382   int ip_before_insn = 0;
383
384 #ifdef __ARM_EABI_UNWINDER__
385   _Unwind_Action actions;
386
387   switch (state & _US_ACTION_MASK)
388     {
389     case _US_VIRTUAL_UNWIND_FRAME:
390       actions = _UA_SEARCH_PHASE;
391       break;
392
393     case _US_UNWIND_FRAME_STARTING:
394       actions = _UA_CLEANUP_PHASE;
395       if (!(state & _US_FORCE_UNWIND)
396           && ue_header->barrier_cache.sp == _Unwind_GetGR(context, 13))
397         actions |= _UA_HANDLER_FRAME;
398       break;
399
400     case _US_UNWIND_FRAME_RESUME:
401       CONTINUE_UNWINDING;
402       break;
403
404     default:
405       std::abort();
406     }
407   actions |= state & _US_FORCE_UNWIND;
408
409   // We don't know which runtime we're working with, so can't check this.
410   // However the ABI routines hide this from us, and we don't actually need
411   // to know.
412   foreign_exception = false;
413
414   // The dwarf unwinder assumes the context structure holds things like the
415   // function and LSDA pointers.  The ARM implementation caches these in
416   // the exception header (UCB).  To avoid rewriting everything we make the
417   // virtual IP register point at the UCB.
418   ip = (_Unwind_Ptr) ue_header;
419   _Unwind_SetGR(context, 12, ip);
420 #else
421   __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
422
423   // Interface version check.
424   if (version != 1)
425     return _URC_FATAL_PHASE1_ERROR;
426   foreign_exception = !__is_gxx_exception_class(exception_class);
427 #endif
428
429   // Shortcut for phase 2 found handler for domestic exception.
430   if (actions == (_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME)
431       && !foreign_exception)
432     {
433       restore_caught_exception(ue_header, handler_switch_value,
434                                language_specific_data, landing_pad);
435       found_type = (landing_pad == 0 ? found_terminate : found_handler);
436       goto install_context;
437     }
438
439   language_specific_data = (const unsigned char *)
440     _Unwind_GetLanguageSpecificData (context);
441
442   // If no LSDA, then there are no handlers or cleanups.
443   if (! language_specific_data)
444     CONTINUE_UNWINDING;
445
446   // Parse the LSDA header.
447   p = parse_lsda_header (context, language_specific_data, &info);
448   info.ttype_base = base_of_encoded_value (info.ttype_encoding, context);
449 #ifdef _GLIBCXX_HAVE_GETIPINFO
450   ip = _Unwind_GetIPInfo (context, &ip_before_insn);
451 #else
452   ip = _Unwind_GetIP (context);
453 #endif
454   if (! ip_before_insn)
455     --ip;
456   landing_pad = 0;
457   action_record = 0;
458   handler_switch_value = 0;
459
460 #ifdef _GLIBCXX_SJLJ_EXCEPTIONS
461   // The given "IP" is an index into the call-site table, with two
462   // exceptions -- -1 means no-action, and 0 means terminate.  But
463   // since we're using uleb128 values, we've not got random access
464   // to the array.
465   if ((int) ip < 0)
466     return _URC_CONTINUE_UNWIND;
467   else if (ip == 0)
468     {
469       // Fall through to set found_terminate.
470     }
471   else
472     {
473       _uleb128_t cs_lp, cs_action;
474       do
475         {
476           p = read_uleb128 (p, &cs_lp);
477           p = read_uleb128 (p, &cs_action);
478         }
479       while (--ip);
480
481       // Can never have null landing pad for sjlj -- that would have
482       // been indicated by a -1 call site index.
483       landing_pad = cs_lp + 1;
484       if (cs_action)
485         action_record = info.action_table + cs_action - 1;
486       goto found_something;
487     }
488 #else
489   // Search the call-site table for the action associated with this IP.
490   while (p < info.action_table)
491     {
492       _Unwind_Ptr cs_start, cs_len, cs_lp;
493       _uleb128_t cs_action;
494
495       // Note that all call-site encodings are "absolute" displacements.
496       p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
497       p = read_encoded_value (0, info.call_site_encoding, p, &cs_len);
498       p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp);
499       p = read_uleb128 (p, &cs_action);
500
501       // The table is sorted, so if we've passed the ip, stop.
502       if (ip < info.Start + cs_start)
503         p = info.action_table;
504       else if (ip < info.Start + cs_start + cs_len)
505         {
506           if (cs_lp)
507             landing_pad = info.LPStart + cs_lp;
508           if (cs_action)
509             action_record = info.action_table + cs_action - 1;
510           goto found_something;
511         }
512     }
513 #endif // _GLIBCXX_SJLJ_EXCEPTIONS
514
515   // If ip is not present in the table, call terminate.  This is for
516   // a destructor inside a cleanup, or a library routine the compiler
517   // was not expecting to throw.
518   found_type = found_terminate;
519   goto do_something;
520
521  found_something:
522   if (landing_pad == 0)
523     {
524       // If ip is present, and has a null landing pad, there are
525       // no cleanups or handlers to be run.
526       found_type = found_nothing;
527     }
528   else if (action_record == 0)
529     {
530       // If ip is present, has a non-null landing pad, and a null
531       // action table offset, then there are only cleanups present.
532       // Cleanups use a zero switch value, as set above.
533       found_type = found_cleanup;
534     }
535   else
536     {
537       // Otherwise we have a catch handler or exception specification.
538
539       _sleb128_t ar_filter, ar_disp;
540       const std::type_info* catch_type;
541       _throw_typet* throw_type;
542       bool saw_cleanup = false;
543       bool saw_handler = false;
544
545 #ifdef __ARM_EABI_UNWINDER__
546       throw_type = ue_header;
547       if ((actions & _UA_FORCE_UNWIND)
548           || foreign_exception)
549         thrown_ptr = 0;
550 #else
551       // During forced unwinding, match a magic exception type.
552       if (actions & _UA_FORCE_UNWIND)
553         {
554           throw_type = &typeid(abi::__forced_unwind);
555           thrown_ptr = 0;
556         }
557       // With a foreign exception class, there's no exception type.
558       // ??? What to do about GNU Java and GNU Ada exceptions?
559       else if (foreign_exception)
560         {
561           throw_type = &typeid(abi::__foreign_exception);
562           thrown_ptr = 0;
563         }
564       else
565         throw_type = xh->exceptionType;
566 #endif
567
568       while (1)
569         {
570           p = action_record;
571           p = read_sleb128 (p, &ar_filter);
572           read_sleb128 (p, &ar_disp);
573
574           if (ar_filter == 0)
575             {
576               // Zero filter values are cleanups.
577               saw_cleanup = true;
578             }
579           else if (ar_filter > 0)
580             {
581               // Positive filter values are handlers.
582               catch_type = get_ttype_entry (&info, ar_filter);
583
584               // Null catch type is a catch-all handler; we can catch foreign
585               // exceptions with this.  Otherwise we must match types.
586               if (! catch_type
587                   || (throw_type
588                       && get_adjusted_ptr (catch_type, throw_type,
589                                            &thrown_ptr)))
590                 {
591                   saw_handler = true;
592                   break;
593                 }
594             }
595           else
596             {
597               // Negative filter values are exception specifications.
598               // ??? How do foreign exceptions fit in?  As far as I can
599               // see we can't match because there's no __cxa_exception
600               // object to stuff bits in for __cxa_call_unexpected to use.
601               // Allow them iff the exception spec is non-empty.  I.e.
602               // a throw() specification results in __unexpected.
603               if ((throw_type
604                    && !(actions & _UA_FORCE_UNWIND)
605                    && !foreign_exception)
606                   ? ! check_exception_spec (&info, throw_type, thrown_ptr,
607                                             ar_filter)
608                   : empty_exception_spec (&info, ar_filter))
609                 {
610                   saw_handler = true;
611                   break;
612                 }
613             }
614
615           if (ar_disp == 0)
616             break;
617           action_record = p + ar_disp;
618         }
619
620       if (saw_handler)
621         {
622           handler_switch_value = ar_filter;
623           found_type = found_handler;
624         }
625       else
626         found_type = (saw_cleanup ? found_cleanup : found_nothing);
627     }
628
629  do_something:
630    if (found_type == found_nothing)
631      CONTINUE_UNWINDING;
632
633   if (actions & _UA_SEARCH_PHASE)
634     {
635       if (found_type == found_cleanup)
636         CONTINUE_UNWINDING;
637
638       // For domestic exceptions, we cache data from phase 1 for phase 2.
639       if (!foreign_exception)
640         {
641           save_caught_exception(ue_header, context, thrown_ptr,
642                                 handler_switch_value, language_specific_data,
643                                 landing_pad, action_record);
644         }
645       return _URC_HANDLER_FOUND;
646     }
647
648  install_context:
649   
650   // We can't use any of the cxa routines with foreign exceptions,
651   // because they all expect ue_header to be a struct __cxa_exception.
652   // So in that case, call terminate or unexpected directly.
653   if ((actions & _UA_FORCE_UNWIND)
654       || foreign_exception)
655     {
656       if (found_type == found_terminate)
657         std::terminate ();
658       else if (handler_switch_value < 0)
659         {
660           try 
661             { std::unexpected (); } 
662           catch(...) 
663             { std::terminate (); }
664         }
665     }
666   else
667     {
668       if (found_type == found_terminate)
669         __cxa_call_terminate(ue_header);
670
671       // Cache the TType base value for __cxa_call_unexpected, as we won't
672       // have an _Unwind_Context then.
673       if (handler_switch_value < 0)
674         {
675           parse_lsda_header (context, language_specific_data, &info);
676
677 #ifdef __ARM_EABI_UNWINDER__
678           const _Unwind_Word* e;
679           _Unwind_Word n;
680           
681           e = ((const _Unwind_Word*) info.TType) - handler_switch_value - 1;
682           // Count the number of rtti objects.
683           n = 0;
684           while (e[n] != 0)
685             n++;
686
687           // Count.
688           ue_header->barrier_cache.bitpattern[1] = n;
689           // Base (obsolete)
690           ue_header->barrier_cache.bitpattern[2] = 0;
691           // Stride.
692           ue_header->barrier_cache.bitpattern[3] = 4;
693           // List head.
694           ue_header->barrier_cache.bitpattern[4] = (_Unwind_Word) e;
695 #else
696           xh->catchTemp = base_of_encoded_value (info.ttype_encoding, context);
697 #endif
698         }
699     }
700
701   /* For targets with pointers smaller than the word size, we must extend the
702      pointer, and this extension is target dependent.  */
703   _Unwind_SetGR (context, __builtin_eh_return_data_regno (0),
704                  __builtin_extend_pointer (ue_header));
705   _Unwind_SetGR (context, __builtin_eh_return_data_regno (1),
706                  handler_switch_value);
707   _Unwind_SetIP (context, landing_pad);
708 #ifdef __ARM_EABI_UNWINDER__
709   if (found_type == found_cleanup)
710     __cxa_begin_cleanup(ue_header);
711 #endif
712   return _URC_INSTALL_CONTEXT;
713 }
714
715 /* The ARM EABI implementation of __cxa_call_unexpected is in a
716    different file so that the personality routine (PR) can be used
717    standalone.  The generic routine shared datastructures with the PR
718    so it is most convenient to implement it here.  */
719 #ifndef __ARM_EABI_UNWINDER__
720 extern "C" void
721 __cxa_call_unexpected (void *exc_obj_in)
722 {
723   _Unwind_Exception *exc_obj
724     = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
725
726   __cxa_begin_catch (exc_obj);
727
728   // This function is a handler for our exception argument.  If we exit
729   // by throwing a different exception, we'll need the original cleaned up.
730   struct end_catch_protect
731   {
732     end_catch_protect() { }
733     ~end_catch_protect() { __cxa_end_catch(); }
734   } end_catch_protect_obj;
735
736   lsda_header_info info;
737   __cxa_exception *xh = __get_exception_header_from_ue (exc_obj);
738   const unsigned char *xh_lsda;
739   _Unwind_Sword xh_switch_value;
740   std::terminate_handler xh_terminate_handler;
741
742   // If the unexpectedHandler rethrows the exception (e.g. to categorize it),
743   // it will clobber data about the current handler.  So copy the data out now.
744   xh_lsda = xh->languageSpecificData;
745   xh_switch_value = xh->handlerSwitchValue;
746   xh_terminate_handler = xh->terminateHandler;
747   info.ttype_base = (_Unwind_Ptr) xh->catchTemp;
748
749   try 
750     { __unexpected (xh->unexpectedHandler); } 
751   catch(...) 
752     {
753       // Get the exception thrown from unexpected.
754
755       __cxa_eh_globals *globals = __cxa_get_globals_fast ();
756       __cxa_exception *new_xh = globals->caughtExceptions;
757       void *new_ptr = new_xh + 1;
758
759       // We don't quite have enough stuff cached; re-parse the LSDA.
760       parse_lsda_header (0, xh_lsda, &info);
761
762       // If this new exception meets the exception spec, allow it.
763       if (check_exception_spec (&info, new_xh->exceptionType,
764                                 new_ptr, xh_switch_value))
765         __throw_exception_again;
766
767       // If the exception spec allows std::bad_exception, throw that.
768       // We don't have a thrown object to compare against, but since
769       // bad_exception doesn't have virtual bases, that's OK; just pass 0.
770 #ifdef __EXCEPTIONS  
771       const std::type_info &bad_exc = typeid (std::bad_exception);
772       if (check_exception_spec (&info, &bad_exc, 0, xh_switch_value))
773         throw std::bad_exception();
774 #endif   
775
776       // Otherwise, die.
777       __terminate (xh_terminate_handler);
778     }
779 }
780 #endif
781
782 } // namespace __cxxabiv1