annotate gcc/ada/libgnat/s-excmac__gcc.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . E X C E P T I O N S . M A C H I N E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2013-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Declaration of the machine exception and some associated facilities. The
kono
parents:
diff changeset
33 -- machine exception is the object that is propagated by low level routines
kono
parents:
diff changeset
34 -- and that contains the Ada exception occurrence.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- This is the version using the GCC EH mechanism
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
39 with Ada.Exceptions;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package System.Exceptions.Machine is
kono
parents:
diff changeset
42 pragma Preelaborate;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 ------------------------------------------------
kono
parents:
diff changeset
45 -- Entities to interface with the GCC runtime --
kono
parents:
diff changeset
46 ------------------------------------------------
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- These come from "C++ ABI for Itanium: Exception handling", which is
kono
parents:
diff changeset
49 -- the reference for GCC.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 -- Return codes from the GCC runtime functions used to propagate
kono
parents:
diff changeset
52 -- an exception.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type Unwind_Reason_Code is
kono
parents:
diff changeset
55 (URC_NO_REASON,
kono
parents:
diff changeset
56 URC_FOREIGN_EXCEPTION_CAUGHT,
kono
parents:
diff changeset
57 URC_PHASE2_ERROR,
kono
parents:
diff changeset
58 URC_PHASE1_ERROR,
kono
parents:
diff changeset
59 URC_NORMAL_STOP,
kono
parents:
diff changeset
60 URC_END_OF_STACK,
kono
parents:
diff changeset
61 URC_HANDLER_FOUND,
kono
parents:
diff changeset
62 URC_INSTALL_CONTEXT,
kono
parents:
diff changeset
63 URC_CONTINUE_UNWIND);
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 pragma Unreferenced
kono
parents:
diff changeset
66 (URC_NO_REASON,
kono
parents:
diff changeset
67 URC_FOREIGN_EXCEPTION_CAUGHT,
kono
parents:
diff changeset
68 URC_PHASE2_ERROR,
kono
parents:
diff changeset
69 URC_PHASE1_ERROR,
kono
parents:
diff changeset
70 URC_NORMAL_STOP,
kono
parents:
diff changeset
71 URC_END_OF_STACK,
kono
parents:
diff changeset
72 URC_HANDLER_FOUND,
kono
parents:
diff changeset
73 URC_INSTALL_CONTEXT,
kono
parents:
diff changeset
74 URC_CONTINUE_UNWIND);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 pragma Convention (C, Unwind_Reason_Code);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- Mandatory common header for any exception object handled by the
kono
parents:
diff changeset
79 -- GCC unwinding runtime.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 type Exception_Class is mod 2 ** 64;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 GNAT_Exception_Class : constant Exception_Class := 16#474e552d41646100#;
kono
parents:
diff changeset
84 -- "GNU-Ada\0"
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 type Unwind_Word is mod 2 ** System.Word_Size;
kono
parents:
diff changeset
87 for Unwind_Word'Size use System.Word_Size;
kono
parents:
diff changeset
88 -- Map the corresponding C type used in Unwind_Exception below
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 type Unwind_Exception is record
kono
parents:
diff changeset
91 Class : Exception_Class;
kono
parents:
diff changeset
92 Cleanup : System.Address;
kono
parents:
diff changeset
93 Private1 : Unwind_Word;
kono
parents:
diff changeset
94 Private2 : Unwind_Word;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 -- Usual exception structure has only two private fields, but the SEH
kono
parents:
diff changeset
97 -- one has six. To avoid making this file more complex, we use six
kono
parents:
diff changeset
98 -- fields on all platforms, wasting a few bytes on some.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 Private3 : Unwind_Word;
kono
parents:
diff changeset
101 Private4 : Unwind_Word;
kono
parents:
diff changeset
102 Private5 : Unwind_Word;
kono
parents:
diff changeset
103 Private6 : Unwind_Word;
kono
parents:
diff changeset
104 end record;
kono
parents:
diff changeset
105 pragma Convention (C, Unwind_Exception);
kono
parents:
diff changeset
106 -- Map the GCC struct used for exception handling
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
kono
parents:
diff changeset
109 -- The C++ ABI mandates the common exception header to be at least
kono
parents:
diff changeset
110 -- doubleword aligned, and the libGCC implementation actually makes it
kono
parents:
diff changeset
111 -- maximally aligned (see unwind.h). See additional comments on the
kono
parents:
diff changeset
112 -- alignment below.
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 -- There is a subtle issue with the common header alignment, since the C
kono
parents:
diff changeset
115 -- version is aligned on BIGGEST_ALIGNMENT, the Ada version is aligned on
kono
parents:
diff changeset
116 -- Standard'Maximum_Alignment, and those two values don't quite represent
kono
parents:
diff changeset
117 -- the same concepts and so may be decoupled someday. One typical reason
kono
parents:
diff changeset
118 -- is that BIGGEST_ALIGNMENT may be larger than what the underlying system
kono
parents:
diff changeset
119 -- allocator guarantees, and there are extra costs involved in allocating
kono
parents:
diff changeset
120 -- objects aligned to such factors.
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 -- To deal with the potential alignment differences between the C and Ada
kono
parents:
diff changeset
123 -- representations, the Ada part of the whole structure is only accessed
kono
parents:
diff changeset
124 -- by the personality routine through accessors. Ada specific fields are
kono
parents:
diff changeset
125 -- thus always accessed through consistent layout, and we expect the
kono
parents:
diff changeset
126 -- actual alignment to always be large enough to avoid traps from the C
kono
parents:
diff changeset
127 -- accesses to the common header. Besides, accessors alleviate the need
kono
parents:
diff changeset
128 -- for a C struct whole counterpart, both painful and error-prone to
kono
parents:
diff changeset
129 -- maintain anyway.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 type GCC_Exception_Access is access all Unwind_Exception;
kono
parents:
diff changeset
132 -- Pointer to a GCC exception
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 procedure Unwind_DeleteException (Excp : not null GCC_Exception_Access);
kono
parents:
diff changeset
135 pragma Import (C, Unwind_DeleteException, "_Unwind_DeleteException");
kono
parents:
diff changeset
136 -- Procedure to free any GCC exception
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 --------------------------------------------------------------
kono
parents:
diff changeset
139 -- GNAT Specific Entities To Deal With The GCC EH Circuitry --
kono
parents:
diff changeset
140 --------------------------------------------------------------
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 -- A GNAT exception object to be dealt with by the personality routine
kono
parents:
diff changeset
143 -- called by the GCC unwinding runtime.
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 type GNAT_GCC_Exception is record
kono
parents:
diff changeset
146 Header : Unwind_Exception;
kono
parents:
diff changeset
147 -- ABI Exception header first
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 Occurrence : aliased Ada.Exceptions.Exception_Occurrence;
kono
parents:
diff changeset
150 -- The Ada occurrence
kono
parents:
diff changeset
151 end record;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 pragma Convention (C, GNAT_GCC_Exception);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 type GNAT_GCC_Exception_Access is access all GNAT_GCC_Exception;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function To_GCC_Exception is new
kono
parents:
diff changeset
158 Ada.Unchecked_Conversion (System.Address, GCC_Exception_Access);
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 function To_GNAT_GCC_Exception is new
kono
parents:
diff changeset
161 Ada.Unchecked_Conversion
kono
parents:
diff changeset
162 (GCC_Exception_Access, GNAT_GCC_Exception_Access);
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 function New_Occurrence return GNAT_GCC_Exception_Access;
kono
parents:
diff changeset
165 -- Allocate and initialize a machine occurrence
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 end System.Exceptions.Machine;