1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2003, Free Software Foundation, Inc. *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 2, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING. If not, write *
19 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, USA. *
22 * As a special exception, if you link this file with other files to *
23 * produce an executable, this file does not by itself cause the resulting *
24 * executable to be covered by the GNU General Public License. This except- *
25 * ion does not however invalidate any other reasons why the executable *
26 * file might be covered by the GNU Public License. *
28 * GNAT was originally developed by the GNAT team at New York University. *
29 * Extensive contributions were provided by Ada Core Technologies Inc. *
31 ****************************************************************************/
33 /* Routines to support runtime exception handling */
37 /* In the top-of-tree GCC, tconfig does not include tm.h, but in GCC 3.2
38 it does. To avoid branching raise.c just for that purpose, we kludge by
39 looking for a symbol always defined by tm.h and if it's not defined,
41 #ifndef FIRST_PSEUDO_REGISTER
42 #include "coretypes.h"
58 /* We have not yet figured out how to import this directly */
61 _gnat_builtin_longjmp (void *ptr
, int flag ATTRIBUTE_UNUSED
)
63 __builtin_longjmp (ptr
, 1);
66 /* When an exception is raised for which no handler exists, the procedure
67 Ada.Exceptions.Unhandled_Exception is called, which performs the call to
68 adafinal to complete finalization, and then prints out the error messages
69 for the unhandled exception. The final step is to call this routine, which
70 performs any system dependent cleanup required. */
73 __gnat_unhandled_terminate (void)
75 /* Special termination handling for VMS */
81 /* Remove the exception vector so it won't intercept any errors
82 in the call to exit, and go into and endless loop */
84 SYS$
SETEXV (1, 0, 3, &prvhnd
);
88 /* Termination handling for all other systems. */
90 #elif !defined (__RT__)
95 /* Below is the code related to the integration of the GCC mechanism for
96 exception handling. */
100 /* The names of a couple of "standard" routines for unwinding/propagation
101 actually vary depending on the underlying GCC scheme for exception handling
102 (SJLJ or DWARF). We need a consistently named interface to import from
103 a-except, so stubs are defined here. */
105 typedef struct _Unwind_Context _Unwind_Context
;
106 typedef struct _Unwind_Exception _Unwind_Exception
;
109 __gnat_Unwind_RaiseException (_Unwind_Exception
*);
112 __gnat_Unwind_ForcedUnwind (_Unwind_Exception
*, void *, void *);
115 #ifdef IN_RTS /* For eh personality routine */
118 #include "unwind-dw2-fde.h"
119 #include "unwind-pe.h"
122 /* --------------------------------------------------------------
123 -- The DB stuff below is there for debugging purposes only. --
124 -------------------------------------------------------------- */
126 #define DB_PHASES 0x1
128 #define DB_ACTIONS 0x4
129 #define DB_REGIONS 0x8
131 #define DB_ERR 0x1000
133 /* The "action" stuff below is also there for debugging purposes only. */
137 _Unwind_Action phase
;
141 static phase_descriptor phase_descriptors
[]
142 = {{ _UA_SEARCH_PHASE
, "SEARCH_PHASE" },
143 { _UA_CLEANUP_PHASE
, "CLEANUP_PHASE" },
144 { _UA_HANDLER_FRAME
, "HANDLER_FRAME" },
145 { _UA_FORCE_UNWIND
, "FORCE_UNWIND" },
149 db_accepted_codes (void)
151 static int accepted_codes
= -1;
153 if (accepted_codes
== -1)
155 char * db_env
= getenv ("EH_DEBUG");
157 accepted_codes
= db_env
? (atoi (db_env
) | DB_ERR
) : 0;
158 /* Arranged for ERR stuff to always be visible when the variable
159 is defined. One may just set the variable to 0 to see the ERR
163 return accepted_codes
;
166 #define DB_INDENT_INCREASE 0x01
167 #define DB_INDENT_DECREASE 0x02
168 #define DB_INDENT_OUTPUT 0x04
169 #define DB_INDENT_NEWLINE 0x08
170 #define DB_INDENT_RESET 0x10
172 #define DB_INDENT_UNIT 8
175 db_indent (int requests
)
177 static int current_indentation_level
= 0;
179 if (requests
& DB_INDENT_RESET
)
181 current_indentation_level
= 0;
184 if (requests
& DB_INDENT_INCREASE
)
186 current_indentation_level
++;
189 if (requests
& DB_INDENT_DECREASE
)
191 current_indentation_level
--;
194 if (requests
& DB_INDENT_NEWLINE
)
196 fprintf (stderr
, "\n");
199 if (requests
& DB_INDENT_OUTPUT
)
201 fprintf (stderr
, "%*s",
202 current_indentation_level
* DB_INDENT_UNIT
, " ");
208 db (int db_code
, char * msg_format
, ...)
210 if (db_accepted_codes () & db_code
)
214 db_indent (DB_INDENT_OUTPUT
);
216 va_start (msg_args
, msg_format
);
217 vfprintf (stderr
, msg_format
, msg_args
);
223 db_phases (int phases
)
225 phase_descriptor
*a
= phase_descriptors
;
227 if (! (db_accepted_codes() & DB_PHASES
))
230 db (DB_PHASES
, "\n");
232 for (; a
->description
!= 0; a
++)
233 if (phases
& a
->phase
)
234 db (DB_PHASES
, "%s ", a
->description
);
236 db (DB_PHASES
, " :\n");
240 /* ---------------------------------------------------------------
241 -- Now come a set of useful structures and helper routines. --
242 --------------------------------------------------------------- */
244 /* There are three major runtime tables involved, generated by the
245 GCC back-end. Contents slightly vary depending on the underlying
246 implementation scheme (dwarf zero cost / sjlj).
248 =======================================
249 * Tables for the dwarf zero cost case *
250 =======================================
253 -------------------------------------------------------------------
254 * region-start | region-length | landing-pad | first-action-index *
255 -------------------------------------------------------------------
257 Identify possible actions to be taken and where to resume control
258 for that when an exception propagates through a pc inside the region
259 delimited by start and length.
261 A null landing-pad indicates that nothing is to be done.
263 Otherwise, first-action-index provides an entry into the action[]
264 table which heads a list of possible actions to be taken (see below).
266 If it is determined that indeed an action should be taken, that
267 is, if one action filter matches the exception beeing propagated,
268 then control should be transfered to landing-pad.
270 A null first-action-index indicates that there are only cleanups
274 -------------------------------
275 * action-filter | next-action *
276 -------------------------------
278 This table contains lists (called action chains) of possible actions
279 associated with call-site entries described in the call-site [] table.
280 There is at most one action list per call-site entry.
282 A null action-filter indicates a cleanup.
284 Non null action-filters provide an index into the ttypes [] table
285 (see below), from which information may be retrieved to check if it
286 matches the exception beeing propagated.
288 action-filter > 0 means there is a regular handler to be run,
290 action-filter < 0 means there is a some "exception_specification"
291 data to retrieve, which is only relevant for C++
292 and should never show up for Ada.
294 next-action indexes the next entry in the list. 0 indicates there is
302 A null value indicates a catch-all handler in C++, and an "others"
305 Non null values are used to match the exception beeing propagated:
306 In C++ this is a pointer to some rtti data, while in Ada this is an
309 The special id value 1 indicates an "all_others" handler.
311 For C++, this table is actually also used to store "exception
312 specification" data. The differentiation between the two kinds
313 of entries is made by the sign of the associated action filter,
314 which translates into positive or negative offsets from the
315 so called base of the table:
317 Exception Specification data is stored at positive offsets from
318 the ttypes table base, which Exception Type data is stored at
321 ---------------------------------------------------------------------------
323 Here is a quick summary of the tables organization:
325 +-- Unwind_Context (pc, ...)
331 | +=============================================================+
332 | | region-start + length | landing-pad | first-action-index |
333 | +=============================================================+
334 +-> | pc range 0 => no-action 0 => cleanups only |
335 | !0 => jump @ N --+ |
336 +====================================================== | ====+
341 +==========================================================+ |
342 | action-filter | next-action | |
343 +==========================================================+ |
345 | >0 => ttype index for handler ------+ 0 => end of chain | <-+
346 | <0 => ttype index for spec data | |
347 +==================================== | ===================+
351 | Offset negated from
352 +=====================+ | the actual base.
354 +============+=====================+ |
355 | | 0 => "others" | |
356 | ... | 1 => "all others" | <---+
357 | | X => exception id |
358 | handlers +---------------------+
362 +============+=====================+ <<------ Table base
364 | specs | ... | (should not see negative filter
365 | ... | ... | values for Ada).
366 +============+=====================+
369 ============================
370 * Tables for the sjlj case *
371 ============================
373 So called "function contexts" are pushed on a context stack by calls to
374 _Unwind_SjLj_Register on function entry, and popped off at exit points by
375 calls to _Unwind_SjLj_Unregister. The current call_site for a function is
376 updated in the function context as the function's code runs along.
378 The generic unwinding engine in _Unwind_RaiseException walks the function
379 context stack and not the actual call chain.
381 The ACTION and TTYPES tables remain unchanged, which allows to search them
382 during the propagation phase to determine wether or not the propagated
383 exception is handled somewhere. When it is, we only "jump" up once directly
384 to the context where the handler will be found. Besides, this allows "break
385 exception unhandled" to work also
387 The CALL-SITE table is setup differently, though: the pc attached to the
388 unwind context is a direct index into the table, so the entries in this
389 table do not hold region bounds any more.
391 A special index (-1) is used to indicate that no action is possibly
392 connected with the context at hand, so null landing pads cannot appear
395 Additionally, landing pad values in the table do not represent code address
396 to jump at, but so called "dispatch" indices used by a common landing pad
397 for the function to switch to the appropriate post-landing-pad.
399 +-- Unwind_Context (pc, ...)
401 | pc = call-site index
402 | 0 => terminate (should not see this for Ada)
407 | +=====================================+
408 | | landing-pad | first-action-index |
409 | +=====================================+
410 +-> | 0 => cleanups only |
412 +=====================================+
415 ===================================
416 * Basic organization of this unit *
417 ===================================
419 The major point of this unit is to provide an exception propagation
420 personality routine for Ada. This is __gnat_eh_personality.
422 It is provided with a pointer to the propagated exception, an unwind
423 context describing a location the propagation is going through, and a
424 couple of other arguments including a description of the current
427 It shall return to the generic propagation engine what is to be performed
428 next, after possible context adjustments, depending on what it finds in the
429 traversed context (a handler for the exception, a cleanup, nothing, ...),
430 and on the propagation phase.
432 A number of structures and subroutines are used for this purpose, as
435 o region_descriptor: General data associated with the context (base pc,
436 call-site table, action table, ttypes table, ...)
438 o action_descriptor: Data describing the action to be taken for the
439 propagated exception in the provided context (kind of action: nothing,
440 handler, cleanup; pointer to the action table entry, ...).
446 Propagate_Exception (a-exexpr.adb)
449 _Unwind_RaiseException (libgcc)
453 +--> __gnat_eh_personality (context, exception)
455 +--> get_region_descriptor_for (context)
457 +--> get_action_descriptor_for (context, exception, region)
459 | +--> get_call_site_action_for (context, region)
460 | (one version for each underlying scheme)
462 +--> setup_to_install (context)
464 This unit is inspired from the C++ version found in eh_personality.cc,
465 part of libstdc++-v3.
470 /* This is the structure of exception objects as built by the GNAT runtime
471 library (a-exexpr.adb). The layouts should exactly match, and the "common"
472 header is mandated by the exception handling ABI. */
476 _Unwind_Exception common
;
477 /* ABI header, maximally aligned. */
480 /* Id of the exception beeing propagated, filled by Propagate_Exception.
482 This is compared against the ttype entries associated with actions in the
483 examined context to see if one of these actions matches. */
485 bool handled_by_others
;
486 /* Indicates wether a "when others" may catch this exception, also filled by
489 This is used to decide if a GNAT_OTHERS ttype entry matches. */
491 int n_cleanups_to_trigger
;
492 /* Number of cleanups on the propagation way for the occurrence. This is
493 initialized to 0 by Propagate_Exception and computed by the personality
494 routine during the first phase of the propagation (incremented for each
495 context in which only cleanup actions match).
497 This is used by Propagate_Exception when the occurrence is not handled,
498 to control a forced unwinding phase aimed at triggering all the cleanups
499 before calling Unhandled_Exception_Terminate.
501 This is also used by __gnat_eh_personality to identify the point at which
502 the notification routine shall be called for a handled occurrence. */
505 /* The two constants below are specific ttype identifiers for special
506 exception ids. Their value is currently hardcoded at the gigi level
507 (see N_Exception_Handler). */
509 #define GNAT_OTHERS ((_Unwind_Ptr) 0x0)
510 #define GNAT_ALL_OTHERS ((_Unwind_Ptr) 0x1)
512 /* Describe the useful region data associated with an unwind context. */
516 /* The base pc of the region. */
519 /* Pointer to the Language Specific Data for the region. */
522 /* Call-Site data associated with this region. */
523 unsigned char call_site_encoding
;
524 const unsigned char *call_site_table
;
526 /* The base to which are relative landing pad offsets inside the call-site
530 /* Action-Table associated with this region. */
531 const unsigned char *action_table
;
533 /* Ttype data associated with this region. */
534 unsigned char ttype_encoding
;
535 const unsigned char *ttype_table
;
536 _Unwind_Ptr ttype_base
;
541 db_region_for (region_descriptor
*region
, _Unwind_Context
*uw_context
)
543 _Unwind_Ptr ip
= _Unwind_GetIP (uw_context
) - 1;
545 if (! (db_accepted_codes () & DB_REGIONS
))
548 db (DB_REGIONS
, "For ip @ 0x%08x => ", ip
);
551 db (DB_REGIONS
, "lsda @ 0x%x", region
->lsda
);
553 db (DB_REGIONS
, "no lsda");
555 db (DB_REGIONS
, "\n");
558 /* Retrieve the ttype entry associated with FILTER in the REGION's
561 static const _Unwind_Ptr
562 get_ttype_entry_for (region_descriptor
*region
, long filter
)
564 _Unwind_Ptr ttype_entry
;
566 filter
*= size_of_encoded_value (region
->ttype_encoding
);
567 read_encoded_value_with_base
568 (region
->ttype_encoding
, region
->ttype_base
,
569 region
->ttype_table
- filter
, &ttype_entry
);
574 /* Fill out the REGION descriptor for the provided UW_CONTEXT. */
577 get_region_description_for (_Unwind_Context
*uw_context
,
578 region_descriptor
*region
)
580 const unsigned char * p
;
582 unsigned char lpbase_encoding
;
584 /* Get the base address of the lsda information. If the provided context
585 is null or if there is no associated language specific data, there's
586 nothing we can/should do. */
588 = (_Unwind_Ptr
) (uw_context
589 ? _Unwind_GetLanguageSpecificData (uw_context
) : 0);
594 /* Parse the lsda and fill the region descriptor. */
595 p
= (char *)region
->lsda
;
597 region
->base
= _Unwind_GetRegionStart (uw_context
);
599 /* Find @LPStart, the base to which landing pad offsets are relative. */
600 lpbase_encoding
= *p
++;
601 if (lpbase_encoding
!= DW_EH_PE_omit
)
602 p
= read_encoded_value
603 (uw_context
, lpbase_encoding
, p
, ®ion
->lp_base
);
605 region
->lp_base
= region
->base
;
607 /* Find @TType, the base of the handler and exception spec type data. */
608 region
->ttype_encoding
= *p
++;
609 if (region
->ttype_encoding
!= DW_EH_PE_omit
)
611 p
= read_uleb128 (p
, &tmp
);
612 region
->ttype_table
= p
+ tmp
;
615 region
->ttype_table
= 0;
618 = base_of_encoded_value (region
->ttype_encoding
, uw_context
);
620 /* Get the encoding and length of the call-site table; the action table
621 immediately follows. */
622 region
->call_site_encoding
= *p
++;
623 region
->call_site_table
= read_uleb128 (p
, &tmp
);
625 region
->action_table
= region
->call_site_table
+ tmp
;
629 /* Describe an action to be taken when propagating an exception up to
634 /* Found some call site base data, but need to analyze further
635 before beeing able to decide. */
638 /* There is nothing relevant in the context at hand. */
641 /* There are only cleanups to run in this context. */
644 /* There is a handler for the exception in this context. */
651 /* The kind of action to be taken. */
654 /* A pointer to the action record entry. */
655 const unsigned char *table_entry
;
657 /* Where we should jump to actually take an action (trigger a cleanup or an
658 exception handler). */
659 _Unwind_Ptr landing_pad
;
661 /* If we have a handler matching our exception, these are the filter to
662 trigger it and the corresponding id. */
663 _Unwind_Sword ttype_filter
;
664 _Unwind_Ptr ttype_entry
;
670 db_action_for (action_descriptor
*action
, _Unwind_Context
*uw_context
)
672 _Unwind_Ptr ip
= _Unwind_GetIP (uw_context
) - 1;
674 db (DB_ACTIONS
, "For ip @ 0x%08x => ", ip
);
676 switch (action
->kind
)
679 db (DB_ACTIONS
, "lpad @ 0x%x, record @ 0x%x\n",
680 ip
, action
->landing_pad
, action
->table_entry
);
684 db (DB_ACTIONS
, "Nothing\n");
688 db (DB_ACTIONS
, "Cleanup\n");
692 db (DB_ACTIONS
, "Handler, filter = %d\n", action
->ttype_filter
);
696 db (DB_ACTIONS
, "Err? Unexpected action kind !\n");
704 /* Search the call_site_table of REGION for an entry appropriate for the
705 UW_CONTEXT's ip. If one is found, store the associated landing_pad and
706 action_table entry, and set the ACTION kind to unknown for further
707 analysis. Otherwise, set the ACTION kind to nothing.
709 There are two variants of this routine, depending on the underlying
710 mechanism (dwarf/sjlj), which account for differences in the tables
714 #ifdef __USING_SJLJ_EXCEPTIONS__
716 #define __builtin_eh_return_data_regno(x) x
719 get_call_site_action_for (_Unwind_Context
*uw_context
,
720 region_descriptor
*region
,
721 action_descriptor
*action
)
723 _Unwind_Ptr call_site
724 = _Unwind_GetIP (uw_context
) - 1;
725 /* Subtract 1 because GetIP returns the actual call_site value + 1. */
727 /* call_site is a direct index into the call-site table, with two special
728 values : -1 for no-action and 0 for "terminate". The latter should never
729 show up for Ada. To test for the former, beware that _Unwind_Ptr might be
732 if ((int)call_site
< 0)
734 action
->kind
= nothing
;
737 else if (call_site
== 0)
739 db (DB_ERR
, "========> Err, null call_site for Ada/sjlj\n");
740 action
->kind
= nothing
;
745 _Unwind_Word cs_lp
, cs_action
;
747 /* Let the caller know there may be an action to take, but let it
748 determine the kind. */
749 action
->kind
= unknown
;
751 /* We have a direct index into the call-site table, but this table is
752 made of leb128 values, the encoding length of which is variable. We
753 can't merely compute an offset from the index, then, but have to read
754 all the entries before the one of interest. */
756 const unsigned char * p
= region
->call_site_table
;
759 p
= read_uleb128 (p
, &cs_lp
);
760 p
= read_uleb128 (p
, &cs_action
);
761 } while (--call_site
);
764 action
->landing_pad
= cs_lp
+ 1;
767 action
->table_entry
= region
->action_table
+ cs_action
- 1;
769 action
->table_entry
= 0;
776 /* ! __USING_SJLJ_EXCEPTIONS__ */
779 get_call_site_action_for (_Unwind_Context
*uw_context
,
780 region_descriptor
*region
,
781 action_descriptor
*action
)
784 = _Unwind_GetIP (uw_context
) - 1;
785 /* Substract 1 because GetIP yields a call return address while we are
786 interested in information for the call point. This does not always yield
787 the exact call instruction address but always brings the ip back within
788 the corresponding region.
790 ??? When unwinding up from a signal handler triggered by a trap on some
791 instruction, we usually have the faulting instruction address here and
792 subtracting 1 might get us into the wrong region. */
794 const unsigned char * p
795 = region
->call_site_table
;
797 /* Unless we are able to determine otherwise ... */
798 action
->kind
= nothing
;
802 while (p
< region
->action_table
)
804 _Unwind_Ptr cs_start
, cs_len
, cs_lp
;
805 _Unwind_Word cs_action
;
807 /* Note that all call-site encodings are "absolute" displacements. */
808 p
= read_encoded_value (0, region
->call_site_encoding
, p
, &cs_start
);
809 p
= read_encoded_value (0, region
->call_site_encoding
, p
, &cs_len
);
810 p
= read_encoded_value (0, region
->call_site_encoding
, p
, &cs_lp
);
811 p
= read_uleb128 (p
, &cs_action
);
814 "c_site @ 0x%08x (+0x%03x), len = %3d, lpad @ 0x%08x (+0x%03x)\n",
815 region
->base
+cs_start
, cs_start
, cs_len
,
816 region
->lp_base
+cs_lp
, cs_lp
);
818 /* The table is sorted, so if we've passed the ip, stop. */
819 if (ip
< region
->base
+ cs_start
)
822 /* If we have a match, fill the ACTION fields accordingly. */
823 else if (ip
< region
->base
+ cs_start
+ cs_len
)
825 /* Let the caller know there may be an action to take, but let it
826 determine the kind. */
827 action
->kind
= unknown
;
830 action
->landing_pad
= region
->lp_base
+ cs_lp
;
832 action
->landing_pad
= 0;
835 action
->table_entry
= region
->action_table
+ cs_action
- 1;
837 action
->table_entry
= 0;
839 db (DB_CSITE
, "+++\n");
844 db (DB_CSITE
, "---\n");
849 /* Fill out the ACTION to be taken from propagating UW_EXCEPTION up to
850 UW_CONTEXT in REGION. */
853 get_action_description_for (_Unwind_Context
*uw_context
,
854 _Unwind_Exception
*uw_exception
,
855 region_descriptor
*region
,
856 action_descriptor
*action
)
858 _GNAT_Exception
* gnat_exception
= (_GNAT_Exception
*) uw_exception
;
860 /* Search the call site table first, which may get us a landing pad as well
861 as the head of an action record list. */
862 get_call_site_action_for (uw_context
, region
, action
);
863 db_action_for (action
, uw_context
);
865 /* If there is not even a call_site entry, we are done. */
866 if (action
->kind
== nothing
)
869 /* Otherwise, check what we have at the place of the call site */
871 /* No landing pad => no cleanups or handlers. */
872 if (action
->landing_pad
== 0)
874 action
->kind
= nothing
;
878 /* Landing pad + null table entry => only cleanups. */
879 else if (action
->table_entry
== 0)
881 action
->kind
= cleanup
;
885 /* Landing pad + Table entry => handlers + possible cleanups. */
888 const unsigned char * p
= action
->table_entry
;
890 _Unwind_Sword ar_filter
, ar_disp
;
892 action
->kind
= nothing
;
896 p
= read_sleb128 (p
, &ar_filter
);
897 read_sleb128 (p
, &ar_disp
);
898 /* Don't assign p here, as it will be incremented by ar_disp
901 /* Null filters are for cleanups. */
903 action
->kind
= cleanup
;
905 /* Positive filters are for regular handlers. */
906 else if (ar_filter
> 0)
908 /* See if the filter we have is for an exception which matches
909 the one we are propagating. */
910 _Unwind_Ptr eid
= get_ttype_entry_for (region
, ar_filter
);
912 if (eid
== gnat_exception
->id
913 || eid
== GNAT_ALL_OTHERS
914 || (eid
== GNAT_OTHERS
&& gnat_exception
->handled_by_others
))
916 action
->ttype_filter
= ar_filter
;
917 action
->ttype_entry
= eid
;
918 action
->kind
= handler
;
923 /* Negative filter values are for C++ exception specifications.
924 Should not be there for Ada :/ */
926 db (DB_ERR
, "========> Err, filter < 0 for Ada/dwarf\n");
936 /* Setup in UW_CONTEXT the eh return target IP and data registers, which will
937 be restored with the others and retrieved by the landing pad once the jump
941 setup_to_install (_Unwind_Context
*uw_context
,
942 _Unwind_Exception
*uw_exception
,
943 _Unwind_Ptr uw_landing_pad
,
946 #ifndef EH_RETURN_DATA_REGNO
947 /* We should not be called if the appropriate underlying support is not
951 /* 1/ exception object pointer, which might be provided back to
952 _Unwind_Resume (and thus to this personality routine) if we are jumping
954 _Unwind_SetGR (uw_context
, __builtin_eh_return_data_regno (0),
955 (_Unwind_Word
)uw_exception
);
957 /* 2/ handler switch value register, which will also be used by the target
958 landing pad to decide what action it shall take. */
959 _Unwind_SetGR (uw_context
, __builtin_eh_return_data_regno (1),
960 (_Unwind_Word
)uw_filter
);
962 /* Setup the address we should jump at to reach the code where there is the
963 "something" we found. */
964 _Unwind_SetIP (uw_context
, uw_landing_pad
);
968 /* The following is defined from a-except.adb. Its purpose is to enable
969 automatic backtraces upon exception raise, as provided through the
970 GNAT.Traceback facilities. */
971 extern void __gnat_notify_handled_exception (void);
972 extern void __gnat_notify_unhandled_exception (void);
974 /* Below is the eh personality routine per se. We currently assume that only
975 GNU-Ada exceptions are met. */
978 __gnat_eh_personality (int uw_version
,
979 _Unwind_Action uw_phases
,
980 _Unwind_Exception_Class uw_exception_class
,
981 _Unwind_Exception
*uw_exception
,
982 _Unwind_Context
*uw_context
)
984 _GNAT_Exception
* gnat_exception
= (_GNAT_Exception
*) uw_exception
;
986 region_descriptor region
;
987 action_descriptor action
;
990 return _URC_FATAL_PHASE1_ERROR
;
992 db_indent (DB_INDENT_RESET
);
993 db_phases (uw_phases
);
994 db_indent (DB_INDENT_INCREASE
);
996 /* Get the region description for the context we were provided with. This
997 will tell us if there is some lsda, call_site, action and/or ttype data
998 for the associated ip. */
999 get_region_description_for (uw_context
, ®ion
);
1000 db_region_for (®ion
, uw_context
);
1002 /* No LSDA => no handlers or cleanups => we shall unwind further up. */
1004 return _URC_CONTINUE_UNWIND
;
1006 /* Search the call-site and action-record tables for the action associated
1008 get_action_description_for (uw_context
, uw_exception
, ®ion
, &action
);
1009 db_action_for (&action
, uw_context
);
1011 /* Whatever the phase, if there is nothing relevant in this frame,
1012 unwinding should just go on. */
1013 if (action
.kind
== nothing
)
1014 return _URC_CONTINUE_UNWIND
;
1016 /* If we found something in search phase, we should return a code indicating
1017 what to do next depending on what we found. If we only have cleanups
1018 around, we shall try to unwind further up to find a handler, otherwise,
1019 tell we have a handler, which will trigger the second phase. */
1020 if (uw_phases
& _UA_SEARCH_PHASE
)
1022 if (action
.kind
== cleanup
)
1024 gnat_exception
->n_cleanups_to_trigger
++;
1025 return _URC_CONTINUE_UNWIND
;
1029 /* Trigger the appropriate notification routines before the second
1030 phase starts, which ensures the stack is still intact. */
1031 __gnat_notify_handled_exception ();
1033 return _URC_HANDLER_FOUND
;
1037 /* We found something in cleanup/handler phase, which might be the handler
1038 or a cleanup for a handled occurrence, or a cleanup for an unhandled
1039 occurrence (we are in a FORCED_UNWIND phase in this case). Install the
1040 context to get there. */
1042 /* If we are going to install a cleanup context, decrement the cleanup
1043 count. This is required in a FORCED_UNWINDing phase (for an unhandled
1044 exception), as this is used from the forced unwinding handler in
1045 Ada.Exceptions.Exception_Propagation to decide wether unwinding should
1046 proceed further or Unhandled_Exception_Terminate should be called. */
1047 if (action
.kind
== cleanup
)
1048 gnat_exception
->n_cleanups_to_trigger
--;
1051 (uw_context
, uw_exception
, action
.landing_pad
, action
.ttype_filter
);
1053 return _URC_INSTALL_CONTEXT
;
1056 /* Define the consistently named stubs imported by Propagate_Exception. */
1058 #ifdef __USING_SJLJ_EXCEPTIONS__
1060 #undef _Unwind_RaiseException
1063 __gnat_Unwind_RaiseException (_Unwind_Exception
*e
)
1065 return _Unwind_SjLj_RaiseException (e
);
1069 #undef _Unwind_ForcedUnwind
1072 __gnat_Unwind_ForcedUnwind (_Unwind_Exception
*e
,
1076 return _Unwind_SjLj_ForcedUnwind (e
, handler
, argument
);
1080 #else /* __USING_SJLJ_EXCEPTIONS__ */
1083 __gnat_Unwind_RaiseException (_Unwind_Exception
*e
)
1085 return _Unwind_RaiseException (e
);
1089 __gnat_Unwind_ForcedUnwind (_Unwind_Exception
*e
,
1093 return _Unwind_ForcedUnwind (e
, handler
, argument
);
1096 #endif /* __USING_SJLJ_EXCEPTIONS__ */
1101 /* The calls to the GCC runtime interface for exception raising are currently
1102 issued from a-exexpr.adb, which is used by both the runtime library and the
1105 As the compiler binary is not linked against the GCC runtime library, we
1106 need also need stubs for this interface in the compiler case. We should not
1107 be using the GCC eh mechanism for the compiler, however, so expect these
1108 functions never to be called. */
1111 __gnat_Unwind_RaiseException (_Unwind_Exception
*e ATTRIBUTE_UNUSED
)
1118 __gnat_Unwind_ForcedUnwind (_Unwind_Exception
*e ATTRIBUTE_UNUSED
,
1119 void * handler ATTRIBUTE_UNUSED
,
1120 void * argument ATTRIBUTE_UNUSED
)