Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / g-excact.adb
blobd4abcc1085d7c7543ec88a0cef4ede4114d1c127
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T . E X C E P T I O N _ A C T I O N S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2002-2023, 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 3, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Ada.Unchecked_Conversion;
33 with System;
34 with System.Soft_Links; use System.Soft_Links;
35 with System.Standard_Library; use System.Standard_Library;
36 with System.Exception_Table; use System.Exception_Table;
38 package body GNAT.Exception_Actions is
40 Global_Action : Exception_Action;
41 pragma Import
42 (Ada, Global_Action, "__gnat_exception_actions_global_action");
43 pragma Atomic (Global_Action);
44 -- Imported from Ada.Exceptions. Any change in the external name needs to
45 -- be coordinated with a-exextr.adb.
47 Global_Unhandled_Action : Exception_Action;
48 pragma Import
49 (Ada, Global_Unhandled_Action,
50 "__gnat_exception_actions_global_unhandled_action");
51 pragma Atomic (Global_Unhandled_Action);
52 -- Imported from Ada.Exceptions. Any change in the external name needs to
53 -- be coordinated with a-exextr.adb.
55 Raise_Hook_Initialized : Boolean;
56 pragma Import
57 (Ada, Raise_Hook_Initialized, "__gnat_exception_actions_initialized");
59 function To_Raise_Action is new Ada.Unchecked_Conversion
60 (Exception_Action, Raise_Action);
62 -- ??? Would be nice to have this in System.Standard_Library
63 function To_Data is new Ada.Unchecked_Conversion
64 (Exception_Id, Exception_Data_Ptr);
65 function To_Id is new Ada.Unchecked_Conversion
66 (Exception_Data_Ptr, Exception_Id);
68 ----------------------------
69 -- Register_Global_Action --
70 ----------------------------
72 procedure Register_Global_Action (Action : Exception_Action) is
73 begin
74 Global_Action := Action;
75 end Register_Global_Action;
77 --------------------------------------
78 -- Register_Global_Unhandled_Action --
79 --------------------------------------
81 procedure Register_Global_Unhandled_Action (Action : Exception_Action) is
82 begin
83 Global_Unhandled_Action := Action;
84 end Register_Global_Unhandled_Action;
86 ------------------------
87 -- Register_Id_Action --
88 ------------------------
90 procedure Register_Id_Action
91 (Id : Exception_Id;
92 Action : Exception_Action)
94 begin
95 if Id = Null_Id then
96 raise Program_Error;
97 end if;
99 Lock_Task.all;
100 To_Data (Id).Raise_Hook := To_Raise_Action (Action);
101 Raise_Hook_Initialized := True;
102 Unlock_Task.all;
103 end Register_Id_Action;
105 ---------------
106 -- Core_Dump --
107 ---------------
109 procedure Core_Dump (Occurrence : Exception_Occurrence) is separate;
111 --------------------------
112 -- Is_Foreign_Exception --
113 --------------------------
115 function Is_Foreign_Exception (E : Exception_Occurrence) return Boolean is
116 Foreign_Exception : aliased Exception_Data;
117 pragma Import
118 (Ada, Foreign_Exception, "system__exceptions__foreign_exception");
119 begin
120 return (To_Data (Exception_Identity (E))
121 = Foreign_Exception'Unchecked_Access);
122 end Is_Foreign_Exception;
124 ----------------
125 -- Name_To_Id --
126 ----------------
128 function Name_To_Id (Name : String) return Exception_Id is
129 begin
130 return To_Id (Internal_Exception (Name, Create_If_Not_Exist => False));
131 end Name_To_Id;
133 ---------------------------------
134 -- Registered_Exceptions_Count --
135 ---------------------------------
137 function Registered_Exceptions_Count return Natural renames
138 System.Exception_Table.Registered_Exceptions_Count;
140 -------------------------------
141 -- Get_Registered_Exceptions --
142 -------------------------------
143 -- This subprogram isn't an iterator to avoid concurrency problems,
144 -- since the exceptions are registered dynamically. Since we have to lock
145 -- the runtime while computing this array, this means that any callback in
146 -- an active iterator would be unable to access the runtime.
148 procedure Get_Registered_Exceptions
149 (List : out Exception_Id_Array;
150 Last : out Integer)
152 Ids : Exception_Data_Array (List'Range);
153 begin
154 Get_Registered_Exceptions (Ids, Last);
156 for L in List'First .. Last loop
157 List (L) := To_Id (Ids (L));
158 end loop;
159 end Get_Registered_Exceptions;
161 end GNAT.Exception_Actions;