OSDN Git Service

PR preprocessor/20348
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-except.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       A D A . E X C E P T I O N S                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2005 Free Software Foundation, Inc.          --
10 --                                                                          --
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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 pragma Polling (Off);
35 --  We must turn polling off for this unit, because otherwise we get
36 --  elaboration circularities with System.Exception_Tables.
37
38 pragma Warnings (Off);
39 --  Since several constructs give warnings in 3.14a1, including unreferenced
40 --  variables and pragma Unreferenced itself.
41
42 with System;                  use System;
43 with System.Standard_Library; use System.Standard_Library;
44 with System.Soft_Links;       use System.Soft_Links;
45 with System.Machine_State_Operations; use System.Machine_State_Operations;
46
47 package body Ada.Exceptions is
48
49    procedure builtin_longjmp (buffer : Address; Flag : Integer);
50    pragma No_Return (builtin_longjmp);
51    pragma Import (C, builtin_longjmp, "_gnat_builtin_longjmp");
52
53    pragma Suppress (All_Checks);
54    --  We definitely do not want exceptions occurring within this unit, or
55    --  we are in big trouble. If an exceptional situation does occur, better
56    --  that it not be raised, since raising it can cause confusing chaos.
57
58    Zero_Cost_Exceptions : Integer;
59    pragma Import (C, Zero_Cost_Exceptions, "__gl_zero_cost_exceptions");
60    --  Boolean indicating if we are handling exceptions using a zero cost
61    --  mechanism.
62    --
63    --  Note that although we currently do not support it, the GCC3 back-end
64    --  tables are also potentially useable for setjmp/longjmp processing.
65
66    -----------------------
67    -- Local Subprograms --
68    -----------------------
69
70    --  Note: the exported subprograms in this package body are called directly
71    --  from C clients using the given external name, even though they are not
72    --  technically visible in the Ada sense.
73
74    procedure AAA;
75    procedure ZZZ;
76    --  Mark start and end of procedures in this package
77    --
78    --  The AAA and ZZZ procedures are used to provide exclusion bounds in
79    --  calls to Call_Chain at exception raise points from this unit. The
80    --  purpose is to arrange for the exception tracebacks not to include
81    --  frames from routines involved in the raise process, as these are
82    --  meaningless from the user's standpoint.
83    --
84    --  For these bounds to be meaningful, we need to ensure that the object
85    --  code for the routines involved in processing a raise is located after
86    --  the object code for AAA and before the object code for ZZZ. This will
87    --  indeed be the case as long as the following rules are respected:
88    --
89    --  1) The bodies of the subprograms involved in processing a raise
90    --     are located after the body of AAA and before the body of ZZZ.
91    --
92    --  2) No pragma Inline applies to any of these subprograms, as this
93    --     could delay the corresponding assembly output until the end of
94    --     the unit.
95
96    Code_Address_For_AAA, Code_Address_For_ZZZ : System.Address;
97    --  Used to represent addresses really inside the code range for AAA and
98    --  ZZZ, initialized to the address of a label inside the corresponding
99    --  procedure. This is initialization takes place inside the procedures
100    --  themselves, which are called as part of the elaboration code.
101    --
102    --  We are doing this instead of merely using Proc'Address because on some
103    --  platforms the latter does not yield the address we want, but the
104    --  address of a stub or of a descriptor instead. This is the case at least
105    --  on Alpha-VMS and PA-HPUX.
106
107    procedure Call_Chain (Excep : EOA);
108    --  Store up to Max_Tracebacks in Excep, corresponding to the current
109    --  call chain.
110
111    procedure Process_Raise_Exception
112      (E                   : Exception_Id;
113       From_Signal_Handler : Boolean);
114    pragma No_Return (Process_Raise_Exception);
115    --  This is the lowest level raise routine. It raises the exception
116    --  referenced by Current_Excep.all in the TSD, without deferring abort
117    --  (the caller must ensure that abort is deferred on entry).
118    --
119    --  This is the common implementation for Raise_Current_Excep and
120    --  Raise_From_Signal_Handler. The origin of the call is indicated by the
121    --  From_Signal_Handler argument.
122
123    procedure To_Stderr (S : String);
124    pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
125    --  Little routine to output string to stderr that is also used
126    --  in the tasking run time.
127
128    procedure To_Stderr (C : Character);
129    pragma Inline (To_Stderr);
130    pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
131    --  Little routine to output a character to stderr, used by some of
132    --  the separate units below.
133
134    package Exception_Data is
135
136       ---------------------------------
137       -- Exception messages routines --
138       ---------------------------------
139
140       procedure Set_Exception_C_Msg
141         (Id   : Exception_Id;
142          Msg1 : Big_String_Ptr;
143          Line : Integer        := 0;
144          Msg2 : Big_String_Ptr := null);
145       --  This routine is called to setup the exception referenced by the
146       --  Current_Excep field in the TSD to contain the indicated Id value
147       --  and message. Msg1 is a null terminated string which is generated
148       --  as the exception message. If line is non-zero, then a colon and
149       --  the decimal representation of this integer is appended to the
150       --  message. When Msg2 is non-null, a space and this additional null
151       --  terminated string is added to the message.
152
153       procedure Set_Exception_Msg
154         (Id      : Exception_Id;
155          Message : String);
156       --  This routine is called to setup the exception referenced by the
157       --  Current_Excep field in the TSD to contain the indicated Id value
158       --  and message. Message is a string which is generated as the
159       --  exception message.
160
161       --------------------------------------
162       -- Exception information subprogram --
163       --------------------------------------
164
165       function Exception_Information (X : Exception_Occurrence) return String;
166       --  The format of the exception information is as follows:
167       --
168       --    Exception_Name: <exception name> (as in Exception_Name)
169       --    Message: <message> (only if Exception_Message is empty)
170       --    PID=nnnn (only if != 0)
171       --    Call stack traceback locations:  (only if at least one location)
172       --    <0xyyyyyyyy 0xyyyyyyyy ...>      (is recorded)
173       --
174       --  The lines are separated by a ASCII.LF character.
175       --  The nnnn is the partition Id given as decimal digits.
176       --  The 0x... line represents traceback program counter locations, in
177       --  execution order with the first one being the exception location. It
178       --  is present only
179       --
180       --  The Exception_Name and Message lines are omitted in the abort
181       --  signal case, since this is not really an exception.
182
183       --  !! If the format of the generated string is changed, please note
184       --  !! that an equivalent modification to the routine String_To_EO must
185       --  !! be made to preserve proper functioning of the stream attributes.
186
187       ---------------------------------------
188       -- Exception backtracing subprograms --
189       ---------------------------------------
190
191       --  What is automatically output when exception tracing is on is the
192       --  usual exception information with the call chain backtrace possibly
193       --  tailored by a backtrace decorator. Modifying Exception_Information
194       --  itself is not a good idea because the decorated output is completely
195       --  out of control and would break all our code related to the streaming
196       --  of exceptions.  We then provide an alternative function to compute
197       --  the possibly tailored output, which is equivalent if no decorator is
198       --  currently set:
199
200       function Tailored_Exception_Information
201         (X : Exception_Occurrence) return String;
202       --  Exception information to be output in the case of automatic tracing
203       --  requested through GNAT.Exception_Traces.
204       --
205       --  This is the same as Exception_Information if no backtrace decorator
206       --  is currently in place. Otherwise, this is Exception_Information with
207       --  the call chain raw addresses replaced by the result of a call to the
208       --  current decorator provided with the call chain addresses.
209
210       pragma Export
211         (Ada, Tailored_Exception_Information,
212            "__gnat_tailored_exception_information");
213       --  This is currently used by System.Tasking.Stages.
214
215    end Exception_Data;
216
217    package Exception_Traces is
218
219       use Exception_Data;
220       --  Imports Tailored_Exception_Information
221
222       ----------------------------------------------
223       -- Run-Time Exception Notification Routines --
224       ----------------------------------------------
225
226       --  These subprograms provide a common run-time interface to trigger the
227       --  actions required when an exception is about to be propagated (e.g.
228       --  user specified actions or output of exception information). They are
229       --  exported to be usable by the Ada exception handling personality
230       --  routine when the GCC 3 mechanism is used.
231
232       procedure Notify_Handled_Exception;
233       pragma Export
234         (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
235       --  This routine is called for a handled occurrence is about to be
236       --  propagated.
237
238       procedure Notify_Unhandled_Exception;
239       pragma Export
240         (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
241       --  This routine is called when an unhandled occurrence is about to be
242       --  propagated.
243
244       procedure Unhandled_Exception_Terminate;
245       pragma No_Return (Unhandled_Exception_Terminate);
246       --  This procedure is called to terminate execution following an
247       --  unhandled exception. The exception information, including
248       --  traceback if available is output, and execution is then
249       --  terminated. Note that at the point where this routine is
250       --  called, the stack has typically been destroyed.
251
252    end Exception_Traces;
253
254    package Exception_Propagation is
255
256       use Exception_Traces;
257       --  Imports Notify_Unhandled_Exception and
258       --  Unhandled_Exception_Terminate
259
260       ------------------------------------
261       -- Exception propagation routines --
262       ------------------------------------
263
264       procedure Setup_Exception
265         (Excep    : EOA;
266          Current  : EOA;
267          Reraised : Boolean := False);
268       --  Perform the necessary operations to prepare the propagation of Excep
269       --  in a task where Current is the current occurrence. Excep is assumed
270       --  to be a valid (non null) pointer.
271       --
272       --  This should be called before any (re-)setting of the current
273       --  occurrence. Any such (re-)setting shall take care *not* to clobber
274       --  the Private_Data component.
275       --
276       --  Having Current provided as an argument (instead of retrieving it via
277       --  Get_Current_Excep internally) is required to allow one task to setup
278       --  an exception for another task, which is used by Transfer_Occurrence.
279
280       procedure Propagate_Exception (From_Signal_Handler : Boolean);
281       pragma No_Return (Propagate_Exception);
282       --  This procedure propagates the exception represented by the occurrence
283       --  referenced by Current_Excep in the TSD for the current task.
284
285    end Exception_Propagation;
286
287    package Stream_Attributes is
288
289       --------------------------------
290       -- Stream attributes routines --
291       --------------------------------
292
293       function EId_To_String (X : Exception_Id) return String;
294       function String_To_EId (S : String) return Exception_Id;
295       --  Functions for implementing Exception_Id stream attributes
296
297       function EO_To_String (X : Exception_Occurrence) return String;
298       function String_To_EO (S : String) return Exception_Occurrence;
299       --  Functions for implementing Exception_Occurrence stream
300       --  attributes
301
302    end Stream_Attributes;
303
304    procedure Raise_Current_Excep (E : Exception_Id);
305    pragma No_Return (Raise_Current_Excep);
306    pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
307    --  This is a simple wrapper to Process_Raise_Exception setting the
308    --  From_Signal_Handler argument to False.
309    --
310    --  This external name for Raise_Current_Excep is historical, and probably
311    --  should be changed but for now we keep it, because gdb and gigi know
312    --  about it.
313
314    procedure Raise_Exception_No_Defer
315       (E : Exception_Id; Message : String := "");
316    pragma Export
317     (Ada, Raise_Exception_No_Defer,
318      "ada__exceptions__raise_exception_no_defer");
319    pragma No_Return (Raise_Exception_No_Defer);
320    --  Similar to Raise_Exception, but with no abort deferral
321
322    procedure Raise_With_Msg (E : Exception_Id);
323    pragma No_Return (Raise_With_Msg);
324    pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
325    --  Raises an exception with given exception id value. A message
326    --  is associated with the raise, and has already been stored in the
327    --  exception occurrence referenced by the Current_Excep in the TSD.
328    --  Abort is deferred before the raise call.
329
330    procedure Raise_With_Location_And_Msg
331      (E : Exception_Id;
332       F : Big_String_Ptr;
333       L : Integer;
334       M : Big_String_Ptr := null);
335    pragma No_Return (Raise_With_Location_And_Msg);
336    --  Raise an exception with given exception id value. A filename and line
337    --  number is associated with the raise and is stored in the exception
338    --  occurrence and in addition a string message M is appended to
339    --  this (if M is not null).
340
341    procedure Raise_Constraint_Error
342      (File : Big_String_Ptr;
343       Line : Integer);
344    pragma No_Return (Raise_Constraint_Error);
345    pragma Export
346      (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
347    --  Raise constraint error with file:line information
348
349    procedure Raise_Constraint_Error_Msg
350      (File : Big_String_Ptr;
351       Line : Integer;
352       Msg  : Big_String_Ptr);
353    pragma No_Return (Raise_Constraint_Error_Msg);
354    pragma Export
355      (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
356    --  Raise constraint error with file:line + msg information
357
358    procedure Raise_Program_Error
359      (File : Big_String_Ptr;
360       Line : Integer);
361    pragma No_Return (Raise_Program_Error);
362    pragma Export
363      (C, Raise_Program_Error, "__gnat_raise_program_error");
364    --  Raise program error with file:line information
365
366    procedure Raise_Program_Error_Msg
367      (File : Big_String_Ptr;
368       Line : Integer;
369       Msg  : Big_String_Ptr);
370    pragma No_Return (Raise_Program_Error_Msg);
371    pragma Export
372      (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
373    --  Raise program error with file:line + msg information
374
375    procedure Raise_Storage_Error
376      (File : Big_String_Ptr;
377       Line : Integer);
378    pragma No_Return (Raise_Storage_Error);
379    pragma Export
380      (C, Raise_Storage_Error, "__gnat_raise_storage_error");
381    --  Raise storage error with file:line information
382
383    procedure Raise_Storage_Error_Msg
384      (File : Big_String_Ptr;
385       Line : Integer;
386       Msg  : Big_String_Ptr);
387    pragma No_Return (Raise_Storage_Error_Msg);
388    pragma Export
389      (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
390    --  Raise storage error with file:line + reason msg information
391
392    --  The exception raising process and the automatic tracing mechanism rely
393    --  on some careful use of flags attached to the exception occurrence. The
394    --  graph below illustrates the relations between the Raise_ subprograms
395    --  and identifies the points where basic flags such as Exception_Raised
396    --  are initialized.
397    --
398    --  (i) signs indicate the flags initialization points. R stands for Raise,
399    --  W for With, and E for Exception.
400    --
401    --                   R_No_Msg    R_E   R_Pe  R_Ce  R_Se
402    --                       |        |     |     |     |
403    --                       +--+  +--+     +---+ | +---+
404    --                          |  |            | | |
405    --     R_E_No_Defer(i)    R_W_Msg(i)       R_W_Loc
406    --           |               |              |   |
407    --           +------------+  |  +-----------+   +--+
408    --                        |  |  |                  |
409    --                        |  |  |             Set_E_C_Msg(i)
410    --                        |  |  |
411    --                   Raise_Current_Excep
412
413    procedure Reraise;
414    pragma No_Return (Reraise);
415    pragma Export (C, Reraise, "__gnat_reraise");
416    --  Reraises the exception referenced by the Current_Excep field of
417    --  the TSD (all fields of this exception occurrence are set). Abort
418    --  is deferred before the reraise operation.
419
420    --  Save_Occurrence variations: As the management of the private data
421    --  attached to occurrences is delicate, wether or not pointers to such
422    --  data has to be copied in various situations is better made explicit.
423    --  The following procedures provide an internal interface to help making
424    --  this explicit.
425
426    procedure Save_Occurrence_And_Private
427      (Target : out Exception_Occurrence;
428       Source : Exception_Occurrence);
429    --  Copy all the components of Source to Target as well as the
430    --  Private_Data pointer.
431
432    procedure Save_Occurrence_No_Private
433      (Target : out Exception_Occurrence;
434       Source : Exception_Occurrence);
435    --  Copy all the components of Source to Target, except the
436    --  Private_Data pointer.
437
438    procedure Transfer_Occurrence
439      (Target : Exception_Occurrence_Access;
440       Source : Exception_Occurrence);
441    pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
442    --  Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
443    --  to setup Target from Source as an exception to be propagated in the
444    --  caller task. Target is expected to be a pointer to the fixed TSD
445    --  occurrence for this task.
446
447    -----------------------------
448    -- Run-Time Check Routines --
449    -----------------------------
450
451    --  These routines are called from the runtime to raise a specific
452    --  exception with a reason message attached. The parameters are
453    --  the file name and line number in each case. The names are keyed
454    --  to the codes defined in Types.ads and a-types.h (for example,
455    --  the name Rcheck_05 refers to the Reason whose Pos code is 5).
456
457    procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer);
458    procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer);
459    procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer);
460    procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer);
461    procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer);
462    procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer);
463    procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer);
464    procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer);
465    procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer);
466    procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer);
467    procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer);
468    procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer);
469    procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer);
470    procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer);
471    procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer);
472    procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer);
473    procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer);
474    procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer);
475    procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer);
476    procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer);
477    procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer);
478    procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer);
479    procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer);
480    procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer);
481    procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer);
482    procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer);
483    procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer);
484    procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer);
485    procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer);
486    procedure Rcheck_29 (File : Big_String_Ptr; Line : Integer);
487    procedure Rcheck_30 (File : Big_String_Ptr; Line : Integer);
488
489    pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
490    pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
491    pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
492    pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
493    pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
494    pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
495    pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
496    pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
497    pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
498    pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
499    pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
500    pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
501    pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
502    pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
503    pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
504    pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
505    pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
506    pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
507    pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
508    pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
509    pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
510    pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
511    pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
512    pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
513    pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
514    pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
515    pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
516    pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
517    pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
518    pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
519    pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
520
521    --  None of these procedures ever returns (they raise an exception!). By
522    --  using pragma No_Return, we ensure that any junk code after the call,
523    --  such as normal return epilog stuff, can be eliminated).
524
525    pragma No_Return (Rcheck_00);
526    pragma No_Return (Rcheck_01);
527    pragma No_Return (Rcheck_02);
528    pragma No_Return (Rcheck_03);
529    pragma No_Return (Rcheck_04);
530    pragma No_Return (Rcheck_05);
531    pragma No_Return (Rcheck_06);
532    pragma No_Return (Rcheck_07);
533    pragma No_Return (Rcheck_08);
534    pragma No_Return (Rcheck_09);
535    pragma No_Return (Rcheck_10);
536    pragma No_Return (Rcheck_11);
537    pragma No_Return (Rcheck_12);
538    pragma No_Return (Rcheck_13);
539    pragma No_Return (Rcheck_14);
540    pragma No_Return (Rcheck_15);
541    pragma No_Return (Rcheck_16);
542    pragma No_Return (Rcheck_17);
543    pragma No_Return (Rcheck_18);
544    pragma No_Return (Rcheck_19);
545    pragma No_Return (Rcheck_20);
546    pragma No_Return (Rcheck_21);
547    pragma No_Return (Rcheck_22);
548    pragma No_Return (Rcheck_23);
549    pragma No_Return (Rcheck_24);
550    pragma No_Return (Rcheck_25);
551    pragma No_Return (Rcheck_26);
552    pragma No_Return (Rcheck_27);
553    pragma No_Return (Rcheck_28);
554    pragma No_Return (Rcheck_29);
555    pragma No_Return (Rcheck_30);
556
557    ---------------------------------------------
558    -- Reason Strings for Run-Time Check Calls --
559    ---------------------------------------------
560
561    --  These strings are null-terminated and are used by Rcheck_nn. The
562    --  strings correspond to the definitions for Types.RT_Exception_Code.
563
564    use ASCII;
565
566    Rmsg_00 : constant String := "access check failed"              & NUL;
567    Rmsg_01 : constant String := "access parameter is null"         & NUL;
568    Rmsg_02 : constant String := "discriminant check failed"        & NUL;
569    Rmsg_03 : constant String := "divide by zero"                   & NUL;
570    Rmsg_04 : constant String := "explicit raise"                   & NUL;
571    Rmsg_05 : constant String := "index check failed"               & NUL;
572    Rmsg_06 : constant String := "invalid data"                     & NUL;
573    Rmsg_07 : constant String := "length check failed"              & NUL;
574    Rmsg_08 : constant String := "null-exclusion check failed"      & NUL;
575    Rmsg_09 : constant String := "overflow check failed"            & NUL;
576    Rmsg_10 : constant String := "partition check failed"           & NUL;
577    Rmsg_11 : constant String := "range check failed"               & NUL;
578    Rmsg_12 : constant String := "tag check failed"                 & NUL;
579    Rmsg_13 : constant String := "access before elaboration"        & NUL;
580    Rmsg_14 : constant String := "accessibility check failed"       & NUL;
581    Rmsg_15 : constant String := "all guards closed"                & NUL;
582    Rmsg_16 : constant String := "duplicated entry address"         & NUL;
583    Rmsg_17 : constant String := "explicit raise"                   & NUL;
584    Rmsg_18 : constant String := "finalize/adjust raised exception" & NUL;
585    Rmsg_19 : constant String := "misaligned address value"         & NUL;
586    Rmsg_20 : constant String := "missing return"                   & NUL;
587    Rmsg_21 : constant String := "overlaid controlled object"       & NUL;
588    Rmsg_22 : constant String := "potentially blocking operation"   & NUL;
589    Rmsg_23 : constant String := "stubbed subprogram called"        & NUL;
590    Rmsg_24 : constant String := "unchecked union restriction"      & NUL;
591    Rmsg_25 : constant String := "illegal use of"
592              & " remote access-to-class-wide type, see RM E.4(18)" & NUL;
593    Rmsg_26 : constant String := "empty storage pool"               & NUL;
594    Rmsg_27 : constant String := "explicit raise"                   & NUL;
595    Rmsg_28 : constant String := "infinite recursion"               & NUL;
596    Rmsg_29 : constant String := "object too large"                 & NUL;
597    Rmsg_30 : constant String := "restriction violation"            & NUL;
598
599    -----------------------
600    -- Polling Interface --
601    -----------------------
602
603    type Unsigned is mod 2 ** 32;
604
605    Counter : Unsigned := 0;
606    pragma Warnings (Off, Counter);
607    --  This counter is provided for convenience. It can be used in Poll to
608    --  perform periodic but not systematic operations.
609
610    procedure Poll is separate;
611    --  The actual polling routine is separate, so that it can easily
612    --  be replaced with a target dependent version.
613
614    ---------
615    -- AAA --
616    ---------
617
618    --  This dummy procedure gives us the start of the PC range for addresses
619    --  within the exception unit itself. We hope that gigi/gcc keep all the
620    --  procedures in their original order!
621
622    procedure AAA is
623    begin
624       <<Start_Of_AAA>>
625       Code_Address_For_AAA := Start_Of_AAA'Address;
626    end AAA;
627
628    ----------------
629    -- Call_Chain --
630    ----------------
631
632    procedure Call_Chain (Excep : EOA) is separate;
633    --  The actual Call_Chain routine is separate, so that it can easily
634    --  be dummied out when no exception traceback information is needed.
635
636    ------------------------------
637    -- Current_Target_Exception --
638    ------------------------------
639
640    function Current_Target_Exception return Exception_Occurrence is
641    begin
642       return Null_Occurrence;
643    end Current_Target_Exception;
644
645    -------------------
646    -- EId_To_String --
647    -------------------
648
649    function EId_To_String (X : Exception_Id) return String
650      renames Stream_Attributes.EId_To_String;
651
652    ------------------
653    -- EO_To_String --
654    ------------------
655
656    --  We use the null string to represent the null occurrence, otherwise
657    --  we output the Exception_Information string for the occurrence.
658
659    function EO_To_String (X : Exception_Occurrence) return String
660      renames Stream_Attributes.EO_To_String;
661
662    ------------------------
663    -- Exception_Identity --
664    ------------------------
665
666    function Exception_Identity
667      (X : Exception_Occurrence) return Exception_Id
668    is
669    begin
670       --  Note that the following test used to be here for the original
671       --  Ada 95 semantics, but these were modified by AI-241 to require
672       --  returning Null_Id instead of raising Constraint_Error.
673
674       --  if X.Id = Null_Id then
675       --     raise Constraint_Error;
676       --  end if;
677
678       return X.Id;
679    end Exception_Identity;
680
681    ---------------------------
682    -- Exception_Information --
683    ---------------------------
684
685    function Exception_Information (X : Exception_Occurrence) return String is
686    begin
687       if X.Id = Null_Id then
688          raise Constraint_Error;
689       end if;
690
691       return Exception_Data.Exception_Information (X);
692    end Exception_Information;
693
694    -----------------------
695    -- Exception_Message --
696    -----------------------
697
698    function Exception_Message (X : Exception_Occurrence) return String is
699    begin
700       if X.Id = Null_Id then
701          raise Constraint_Error;
702       end if;
703
704       return X.Msg (1 .. X.Msg_Length);
705    end Exception_Message;
706
707    --------------------
708    -- Exception_Name --
709    --------------------
710
711    function Exception_Name (Id : Exception_Id) return String is
712    begin
713       if Id = null then
714          raise Constraint_Error;
715       end if;
716
717       return Id.Full_Name.all (1 .. Id.Name_Length - 1);
718    end Exception_Name;
719
720    function Exception_Name (X : Exception_Occurrence) return String is
721    begin
722       return Exception_Name (X.Id);
723    end Exception_Name;
724
725    ---------------------------
726    -- Exception_Name_Simple --
727    ---------------------------
728
729    function Exception_Name_Simple (X : Exception_Occurrence) return String is
730       Name : constant String := Exception_Name (X);
731       P    : Natural;
732
733    begin
734       P := Name'Length;
735       while P > 1 loop
736          exit when Name (P - 1) = '.';
737          P := P - 1;
738       end loop;
739
740       --  Return result making sure lower bound is 1
741
742       declare
743          subtype Rname is String (1 .. Name'Length - P + 1);
744       begin
745          return Rname (Name (P .. Name'Length));
746       end;
747    end Exception_Name_Simple;
748
749    --------------------
750    -- Exception_Data --
751    --------------------
752
753    package body Exception_Data is separate;
754    --  This package can be easily dummied out if we do not want the
755    --  basic support for exception messages (such as in Ada 83).
756
757    ---------------------------
758    -- Exception_Propagation --
759    ---------------------------
760
761    package body Exception_Propagation is separate;
762    --  Depending on the actual exception mechanism used (front-end or
763    --  back-end based), the implementation will differ, which is why this
764    --  package is separated.
765
766    ----------------------
767    -- Exception_Traces --
768    ----------------------
769
770    package body Exception_Traces is separate;
771    --  Depending on the underlying support for IO the implementation
772    --  will differ. Moreover we would like to dummy out this package
773    --  in case we do not want any exception tracing support. This is
774    --  why this package is separated.
775
776    -----------------------
777    -- Stream Attributes --
778    -----------------------
779
780    package body Stream_Attributes is separate;
781    --  This package can be easily dummied out if we do not want the
782    --  support for streaming Exception_Ids and Exception_Occurrences.
783
784    -----------------------------
785    -- Process_Raise_Exception --
786    -----------------------------
787
788    procedure Process_Raise_Exception
789      (E                   : Exception_Id;
790       From_Signal_Handler : Boolean)
791    is
792       pragma Inspection_Point (E);
793       --  This is so the debugger can reliably inspect the parameter
794
795       Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
796       Excep       : EOA := Get_Current_Excep.all;
797
798    begin
799       --  WARNING : There should be no exception handler for this body
800       --  because this would cause gigi to prepend a setup for a new
801       --  jmpbuf to the sequence of statements. We would then always get
802       --  this new buf in Jumpbuf_Ptr instead of the one for the exception
803       --  we are handling, which would completely break the whole design
804       --  of this procedure.
805
806       --  Processing varies between zero cost and setjmp/lonjmp processing.
807
808       if Zero_Cost_Exceptions /= 0 then
809
810          --  Use the front-end tables to propagate if we have them, otherwise
811          --  resort to the GCC back-end alternative. Backtrace computation is
812          --  performed, if required, by the underlying routine. Notifications
813          --  for the debugger are also not performed here, because we do not
814          --  yet know if the exception is handled.
815
816          Exception_Propagation.Propagate_Exception (From_Signal_Handler);
817
818       else
819          --  Compute the backtrace for this occurrence if the corresponding
820          --  binder option has been set. Call_Chain takes care of the reraise
821          --  case.
822
823          Call_Chain (Excep);
824          --  We used to only do this if From_Signal_Handler was not set,
825          --  based on the assumption that backtracing from a signal handler
826          --  would not work due to stack layout oddities. However, since
827          --
828          --   1. The flag is never set in tasking programs (Notify_Exception
829          --      performs regular raise statements), and
830          --
831          --   2. No problem has shown up in tasking programs around here so
832          --      far, this turned out to be too strong an assumption.
833          --
834          --  As, in addition, the test was
835          --
836          --   1. preventing the production of backtraces in non-tasking
837          --      programs, and
838          --
839          --   2. introducing a behavior inconsistency between
840          --      the tasking and non-tasking cases,
841          --
842          --  we have simply removed it.
843
844          --  If the jump buffer pointer is non-null, transfer control using
845          --  it. Otherwise announce an unhandled exception (note that this
846          --  means that we have no finalizations to do other than at the outer
847          --  level). Perform the necessary notification tasks in both cases.
848
849          if Jumpbuf_Ptr /= Null_Address then
850
851             if not Excep.Exception_Raised then
852                Excep.Exception_Raised := True;
853                Exception_Traces.Notify_Handled_Exception;
854             end if;
855
856             builtin_longjmp (Jumpbuf_Ptr, 1);
857
858          else
859             --  The pragma Inspection point here ensures that the debugger
860             --  can inspect the parameter.
861
862             pragma Inspection_Point (E);
863
864             Exception_Traces.Notify_Unhandled_Exception;
865             Exception_Traces.Unhandled_Exception_Terminate;
866          end if;
867       end if;
868    end Process_Raise_Exception;
869
870    ----------------------------
871    -- Raise_Constraint_Error --
872    ----------------------------
873
874    procedure Raise_Constraint_Error
875      (File : Big_String_Ptr;
876       Line : Integer)
877    is
878    begin
879       Raise_With_Location_And_Msg
880         (Constraint_Error_Def'Access, File, Line);
881    end Raise_Constraint_Error;
882
883    --------------------------------
884    -- Raise_Constraint_Error_Msg --
885    --------------------------------
886
887    procedure Raise_Constraint_Error_Msg
888      (File : Big_String_Ptr;
889       Line : Integer;
890       Msg  : Big_String_Ptr)
891    is
892    begin
893       Raise_With_Location_And_Msg
894         (Constraint_Error_Def'Access, File, Line, Msg);
895    end Raise_Constraint_Error_Msg;
896
897    -------------------------
898    -- Raise_Current_Excep --
899    -------------------------
900
901    procedure Raise_Current_Excep (E : Exception_Id) is
902       pragma Inspection_Point (E);
903       --  This is so the debugger can reliably inspect the parameter
904    begin
905       Process_Raise_Exception (E => E, From_Signal_Handler => False);
906    end Raise_Current_Excep;
907
908    ---------------------
909    -- Raise_Exception --
910    ---------------------
911
912    procedure Raise_Exception
913      (E       : Exception_Id;
914       Message : String := "")
915    is
916    begin
917       if E /= null then
918          Exception_Data.Set_Exception_Msg (E, Message);
919          Abort_Defer.all;
920          Raise_Current_Excep (E);
921       end if;
922    end Raise_Exception;
923
924    ----------------------------
925    -- Raise_Exception_Always --
926    ----------------------------
927
928    procedure Raise_Exception_Always
929      (E       : Exception_Id;
930       Message : String := "")
931    is
932    begin
933       Exception_Data.Set_Exception_Msg (E, Message);
934       Abort_Defer.all;
935       Raise_Current_Excep (E);
936    end Raise_Exception_Always;
937
938    -------------------------------
939    -- Raise_From_Signal_Handler --
940    -------------------------------
941
942    procedure Raise_From_Signal_Handler
943      (E : Exception_Id;
944       M : Big_String_Ptr)
945    is
946    begin
947       Exception_Data.Set_Exception_C_Msg (E, M);
948       Abort_Defer.all;
949       Process_Raise_Exception (E => E, From_Signal_Handler => True);
950    end Raise_From_Signal_Handler;
951
952    -------------------------
953    -- Raise_Program_Error --
954    -------------------------
955
956    procedure Raise_Program_Error
957      (File : Big_String_Ptr;
958       Line : Integer)
959    is
960    begin
961       Raise_With_Location_And_Msg
962         (Program_Error_Def'Access, File, Line);
963    end Raise_Program_Error;
964
965    -----------------------------
966    -- Raise_Program_Error_Msg --
967    -----------------------------
968
969    procedure Raise_Program_Error_Msg
970      (File : Big_String_Ptr;
971       Line : Integer;
972       Msg  : Big_String_Ptr)
973    is
974    begin
975       Raise_With_Location_And_Msg
976         (Program_Error_Def'Access, File, Line, Msg);
977    end Raise_Program_Error_Msg;
978
979    -------------------------
980    -- Raise_Storage_Error --
981    -------------------------
982
983    procedure Raise_Storage_Error
984      (File : Big_String_Ptr;
985       Line : Integer)
986    is
987    begin
988       Raise_With_Location_And_Msg
989         (Storage_Error_Def'Access, File, Line);
990    end Raise_Storage_Error;
991
992    -----------------------------
993    -- Raise_Storage_Error_Msg --
994    -----------------------------
995
996    procedure Raise_Storage_Error_Msg
997      (File : Big_String_Ptr;
998       Line : Integer;
999       Msg  : Big_String_Ptr)
1000    is
1001    begin
1002       Raise_With_Location_And_Msg
1003         (Storage_Error_Def'Access, File, Line, Msg);
1004    end Raise_Storage_Error_Msg;
1005
1006    ---------------------------------
1007    -- Raise_With_Location_And_Msg --
1008    ---------------------------------
1009
1010    procedure Raise_With_Location_And_Msg
1011      (E : Exception_Id;
1012       F : Big_String_Ptr;
1013       L : Integer;
1014       M : Big_String_Ptr := null)
1015    is
1016    begin
1017       Exception_Data.Set_Exception_C_Msg (E, F, L, M);
1018       Abort_Defer.all;
1019       Raise_Current_Excep (E);
1020    end Raise_With_Location_And_Msg;
1021
1022    --------------------
1023    -- Raise_With_Msg --
1024    --------------------
1025
1026    procedure Raise_With_Msg (E : Exception_Id) is
1027       Excep : constant EOA := Get_Current_Excep.all;
1028
1029    begin
1030       Exception_Propagation.Setup_Exception (Excep, Excep);
1031
1032       Excep.Exception_Raised := False;
1033       Excep.Id               := E;
1034       Excep.Num_Tracebacks   := 0;
1035       Excep.Cleanup_Flag     := False;
1036       Excep.Pid              := Local_Partition_ID;
1037       Abort_Defer.all;
1038       Raise_Current_Excep (E);
1039    end Raise_With_Msg;
1040
1041    --------------------------------------
1042    -- Calls to Run-Time Check Routines --
1043    --------------------------------------
1044
1045    procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer) is
1046    begin
1047       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_00'Address));
1048    end Rcheck_00;
1049
1050    procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer) is
1051    begin
1052       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_01'Address));
1053    end Rcheck_01;
1054
1055    procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer) is
1056    begin
1057       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_02'Address));
1058    end Rcheck_02;
1059
1060    procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer) is
1061    begin
1062       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_03'Address));
1063    end Rcheck_03;
1064
1065    procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer) is
1066    begin
1067       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_04'Address));
1068    end Rcheck_04;
1069
1070    procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer) is
1071    begin
1072       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_05'Address));
1073    end Rcheck_05;
1074
1075    procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer) is
1076    begin
1077       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_06'Address));
1078    end Rcheck_06;
1079
1080    procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer) is
1081    begin
1082       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_07'Address));
1083    end Rcheck_07;
1084
1085    procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer) is
1086    begin
1087       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_08'Address));
1088    end Rcheck_08;
1089
1090    procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer) is
1091    begin
1092       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_09'Address));
1093    end Rcheck_09;
1094
1095    procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer) is
1096    begin
1097       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_10'Address));
1098    end Rcheck_10;
1099
1100    procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer) is
1101    begin
1102       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_11'Address));
1103    end Rcheck_11;
1104
1105    procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer) is
1106    begin
1107       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_12'Address));
1108    end Rcheck_12;
1109
1110    procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer) is
1111    begin
1112       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_13'Address));
1113    end Rcheck_13;
1114
1115    procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer) is
1116    begin
1117       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_14'Address));
1118    end Rcheck_14;
1119
1120    procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer) is
1121    begin
1122       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_15'Address));
1123    end Rcheck_15;
1124
1125    procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer) is
1126    begin
1127       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_16'Address));
1128    end Rcheck_16;
1129
1130    procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer) is
1131    begin
1132       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_17'Address));
1133    end Rcheck_17;
1134
1135    procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer) is
1136    begin
1137       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_18'Address));
1138    end Rcheck_18;
1139
1140    procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer) is
1141    begin
1142       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_19'Address));
1143    end Rcheck_19;
1144
1145    procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer) is
1146    begin
1147       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_20'Address));
1148    end Rcheck_20;
1149
1150    procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer) is
1151    begin
1152       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_21'Address));
1153    end Rcheck_21;
1154
1155    procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer) is
1156    begin
1157       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_22'Address));
1158    end Rcheck_22;
1159
1160    procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer) is
1161    begin
1162       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_23'Address));
1163    end Rcheck_23;
1164
1165    procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer) is
1166    begin
1167       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_24'Address));
1168    end Rcheck_24;
1169
1170    procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer) is
1171    begin
1172       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_25'Address));
1173    end Rcheck_25;
1174
1175    procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer) is
1176    begin
1177       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_26'Address));
1178    end Rcheck_26;
1179
1180    procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer) is
1181    begin
1182       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_27'Address));
1183    end Rcheck_27;
1184
1185    procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer) is
1186    begin
1187       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_28'Address));
1188    end Rcheck_28;
1189
1190    procedure Rcheck_29 (File : Big_String_Ptr; Line : Integer) is
1191    begin
1192       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_29'Address));
1193    end Rcheck_29;
1194
1195    procedure Rcheck_30 (File : Big_String_Ptr; Line : Integer) is
1196    begin
1197       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_30'Address));
1198    end Rcheck_30;
1199
1200    -------------
1201    -- Reraise --
1202    -------------
1203
1204    procedure Reraise is
1205       Excep : constant EOA := Get_Current_Excep.all;
1206
1207    begin
1208       Abort_Defer.all;
1209       Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1210       Raise_Current_Excep (Excep.Id);
1211    end Reraise;
1212
1213    ------------------------
1214    -- Reraise_Occurrence --
1215    ------------------------
1216
1217    procedure Reraise_Occurrence (X : Exception_Occurrence) is
1218    begin
1219       if X.Id /= null then
1220          Abort_Defer.all;
1221          Exception_Propagation.Setup_Exception
1222            (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1223          Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1224          Raise_Current_Excep (X.Id);
1225       end if;
1226    end Reraise_Occurrence;
1227
1228    -------------------------------
1229    -- Reraise_Occurrence_Always --
1230    -------------------------------
1231
1232    procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1233    begin
1234       Abort_Defer.all;
1235       Exception_Propagation.Setup_Exception
1236         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1237       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1238       Raise_Current_Excep (X.Id);
1239    end Reraise_Occurrence_Always;
1240
1241    ---------------------------------
1242    -- Reraise_Occurrence_No_Defer --
1243    ---------------------------------
1244
1245    procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1246    begin
1247       Exception_Propagation.Setup_Exception
1248         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1249       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1250       Raise_Current_Excep (X.Id);
1251    end Reraise_Occurrence_No_Defer;
1252
1253    ---------------------
1254    -- Save_Occurrence --
1255    ---------------------
1256
1257    procedure Save_Occurrence
1258      (Target : out Exception_Occurrence;
1259       Source : Exception_Occurrence)
1260    is
1261    begin
1262       Save_Occurrence_No_Private (Target, Source);
1263    end Save_Occurrence;
1264
1265    function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1266       Target : EOA := new Exception_Occurrence;
1267    begin
1268       Save_Occurrence (Target.all, Source);
1269       return Target;
1270    end Save_Occurrence;
1271
1272    --------------------------------
1273    -- Save_Occurrence_And_Private --
1274    --------------------------------
1275
1276    procedure Save_Occurrence_And_Private
1277      (Target : out Exception_Occurrence;
1278       Source : Exception_Occurrence)
1279    is
1280    begin
1281       Save_Occurrence_No_Private (Target, Source);
1282       Target.Private_Data := Source.Private_Data;
1283    end Save_Occurrence_And_Private;
1284
1285    --------------------------------
1286    -- Save_Occurrence_No_Private --
1287    --------------------------------
1288
1289    procedure Save_Occurrence_No_Private
1290      (Target : out Exception_Occurrence;
1291       Source : Exception_Occurrence)
1292    is
1293    begin
1294       Target.Id             := Source.Id;
1295       Target.Msg_Length     := Source.Msg_Length;
1296       Target.Num_Tracebacks := Source.Num_Tracebacks;
1297       Target.Pid            := Source.Pid;
1298       Target.Cleanup_Flag   := Source.Cleanup_Flag;
1299
1300       Target.Msg (1 .. Target.Msg_Length) :=
1301         Source.Msg (1 .. Target.Msg_Length);
1302
1303       Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1304         Source.Tracebacks (1 .. Target.Num_Tracebacks);
1305    end Save_Occurrence_No_Private;
1306
1307    -------------------------
1308    -- Transfer_Occurrence --
1309    -------------------------
1310
1311    procedure Transfer_Occurrence
1312      (Target : Exception_Occurrence_Access;
1313       Source : Exception_Occurrence)
1314    is
1315    begin
1316       --  Setup Target as an exception to be propagated in the calling task
1317       --  (rendezvous-wise), taking care not to clobber the associated private
1318       --  data.  Target is expected to be a pointer to the calling task's
1319       --  fixed TSD occurrence, which is very different from Get_Current_Excep
1320       --  here because this subprogram is called from the called task.
1321
1322       Exception_Propagation.Setup_Exception (Target, Target);
1323       Save_Occurrence_No_Private (Target.all, Source);
1324    end Transfer_Occurrence;
1325
1326    -------------------
1327    -- String_To_EId --
1328    -------------------
1329
1330    function String_To_EId (S : String) return Exception_Id
1331      renames Stream_Attributes.String_To_EId;
1332
1333    ------------------
1334    -- String_To_EO --
1335    ------------------
1336
1337    function String_To_EO (S : String) return Exception_Occurrence
1338      renames Stream_Attributes.String_To_EO;
1339
1340    ------------------------------
1341    -- Raise_Exception_No_Defer --
1342    ------------------------------
1343
1344    procedure Raise_Exception_No_Defer
1345      (E       : Exception_Id;
1346       Message : String := "")
1347    is
1348    begin
1349       Exception_Data.Set_Exception_Msg (E, Message);
1350
1351       --  DO NOT CALL Abort_Defer.all; !!!!
1352       --  why not??? would be nice to have more comments here
1353
1354       Raise_Current_Excep (E);
1355    end Raise_Exception_No_Defer;
1356
1357    ---------------
1358    -- To_Stderr --
1359    ---------------
1360
1361    procedure To_Stderr (C : Character) is
1362
1363       type int is new Integer;
1364
1365       procedure put_char_stderr (C : int);
1366       pragma Import (C, put_char_stderr, "put_char_stderr");
1367
1368    begin
1369       put_char_stderr (Character'Pos (C));
1370    end To_Stderr;
1371
1372    procedure To_Stderr (S : String) is
1373    begin
1374       for J in S'Range loop
1375          if S (J) /= ASCII.CR then
1376             To_Stderr (S (J));
1377          end if;
1378       end loop;
1379    end To_Stderr;
1380
1381    ---------
1382    -- ZZZ --
1383    ---------
1384
1385    --  This dummy procedure gives us the end of the PC range for addresses
1386    --  within the exception unit itself. We hope that gigi/gcc keeps all the
1387    --  procedures in their original order!
1388
1389    procedure ZZZ is
1390    begin
1391       <<Start_Of_ZZZ>>
1392       Code_Address_For_ZZZ := Start_Of_ZZZ'Address;
1393    end ZZZ;
1394
1395 begin
1396    pragma Warnings (Off);
1397    --  Allow calls to non-static subprograms in Ada 2005 mode where this
1398    --  package will be implicitly categorized as Preelaborate. See AI-362 for
1399    --  details. It is safe in the context of the run-time to violate the rules!
1400
1401    --  Allocate the Non-Tasking Machine_State
1402
1403    Set_Machine_State_Addr_NT (System.Address (Allocate_Machine_State));
1404
1405    --  Call the AAA/ZZZ routines to setup the code addresses for the
1406    --  bounds of this unit.
1407
1408    AAA;
1409    ZZZ;
1410
1411    pragma Warnings (On);
1412 end Ada.Exceptions;