1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . R I D E N T --
9 -- Copyright (C) 1992-2008, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package defines the set of restriction identifiers. It is a generic
35 -- package that is instantiated by the compiler/binder in package Rident, and
36 -- is instantiated in package System.Restrictions for use at run-time.
38 -- The reason that we make this a generic package is so that in the case of
39 -- the instantiation in Rident for use at compile time and bind time, we can
40 -- generate normal image tables for the enumeration types, which are needed
41 -- for diagnostic and informational messages. At run-time we really do not
42 -- want to waste the space for these image tables, and they are not needed,
43 -- so we can do the instantiation under control of Discard_Names to remove
47 package System
.Rident
is
50 -- The following enumeration type defines the set of restriction
51 -- identifiers that are implemented in GNAT.
53 -- To add a new restriction identifier, add an entry with the name
54 -- to be used in the pragma, and add appropriate calls to the
55 -- Restrict.Check_Restriction routine.
57 type Restriction_Id
is
59 -- The following cases are checked for consistency in the binder. The
60 -- binder will check that every unit either has the restriction set, or
61 -- does not violate the restriction.
63 (Simple_Barriers
, -- GNAT (Ravenscar)
64 No_Abort_Statements
, -- (RM D.7(5), H.4(3))
65 No_Access_Subprograms
, -- (RM H.4(17))
66 No_Allocators
, -- (RM H.4(7))
67 No_Asynchronous_Control
, -- (RM D.7(10))
69 No_Delay
, -- (RM H.4(21))
70 No_Direct_Boolean_Operators
, -- GNAT
71 No_Dispatch
, -- (RM H.4(19))
72 No_Dispatching_Calls
, -- GNAT
73 No_Dynamic_Attachment
, -- GNAT
74 No_Dynamic_Priorities
, -- (RM D.9(9))
75 No_Enumeration_Maps
, -- GNAT
76 No_Entry_Calls_In_Elaboration_Code
, -- GNAT
77 No_Entry_Queue
, -- GNAT (Ravenscar)
78 No_Exception_Handlers
, -- GNAT
79 No_Exception_Propagation
, -- GNAT
80 No_Exception_Registration
, -- GNAT
81 No_Exceptions
, -- (RM H.4(12))
82 No_Finalization
, -- GNAT
83 No_Fixed_Point
, -- (RM H.4(15))
84 No_Floating_Point
, -- (RM H.4(14))
85 No_IO
, -- (RM H.4(20))
86 No_Implicit_Conditionals
, -- GNAT
87 No_Implicit_Dynamic_Code
, -- GNAT
88 No_Implicit_Heap_Allocations
, -- (RM D.8(8), H.4(3))
89 No_Implicit_Loops
, -- GNAT
90 No_Initialize_Scalars
, -- GNAT
91 No_Local_Allocators
, -- (RM H.4(8))
92 No_Local_Timing_Events
, -- (RM D.7(10.2/2))
93 No_Local_Protected_Objects
, -- GNAT
94 No_Nested_Finalization
, -- (RM D.7(4))
95 No_Protected_Type_Allocators
, -- GNAT
96 No_Protected_Types
, -- (RM H.4(5))
97 No_Recursion
, -- (RM H.4(22))
98 No_Reentrancy
, -- (RM H.4(23))
99 No_Relative_Delay
, -- GNAT (Ravenscar)
100 No_Requeue_Statements
, -- GNAT
101 No_Secondary_Stack
, -- GNAT
102 No_Select_Statements
, -- GNAT (Ravenscar)
103 No_Specific_Termination_Handlers
, -- (RM D.7(10.7/2))
104 No_Standard_Storage_Pools
, -- GNAT
106 No_Task_Allocators
, -- (RM D.7(7))
107 No_Task_Attributes_Package
, -- GNAT
108 No_Task_Hierarchy
, -- (RM D.7(3), H.4(3))
109 No_Task_Termination
, -- GNAT (Ravenscar)
111 No_Terminate_Alternatives
, -- (RM D.7(6))
112 No_Unchecked_Access
, -- (RM H.4(18))
113 No_Unchecked_Conversion
, -- (RM H.4(16))
114 No_Unchecked_Deallocation
, -- (RM H.4(9))
115 Static_Priorities
, -- GNAT
116 Static_Storage_Size
, -- GNAT
118 -- The following require consistency checking with special rules. See
119 -- individual routines in unit Bcheck for details of what is required.
121 No_Default_Initialization
, -- GNAT
123 -- The following cases do not require consistency checking
125 Immediate_Reclamation
, -- (RM H.4(10))
126 No_Implementation_Attributes
, -- Ada 2005 AI-257
127 No_Implementation_Pragmas
, -- Ada 2005 AI-257
128 No_Implementation_Restrictions
, -- GNAT
129 No_Elaboration_Code
, -- GNAT
130 No_Obsolescent_Features
, -- Ada 2005 AI-368
131 No_Wide_Characters
, -- GNAT
133 -- The following cases require a parameter value
135 -- The following entries are fully checked at compile/bind time, which
136 -- means that the compiler can in general tell the minimum value which
137 -- could be used with a restrictions pragma. The binder can deduce the
138 -- appropriate minimum value for the partition by taking the maximum
139 -- value required by any unit.
141 Max_Protected_Entries
, -- (RM D.7(14))
142 Max_Select_Alternatives
, -- (RM D.7(12))
143 Max_Task_Entries
, -- (RM D.7(13), H.4(3))
145 -- The following entries are also fully checked at compile/bind time,
146 -- and the compiler can also at least in some cases tell the minimum
147 -- value which could be used with a restriction pragma. The difference
148 -- is that the contributions are additive, so the binder deduces this
149 -- value by adding the unit contributions.
151 Max_Tasks
, -- (RM D.7(19), H.4(3))
153 -- The following entries are checked at compile time only for zero/
154 -- nonzero entries. This means that the compiler can tell at compile
155 -- time if a restriction value of zero is (would be) violated, but that
156 -- the compiler cannot distinguish between different non-zero values.
158 Max_Asynchronous_Select_Nesting
, -- (RM D.7(18), H.4(3))
159 Max_Entry_Queue_Length
, -- GNAT
161 -- The remaining entries are not checked at compile/bind time
163 Max_Storage_At_Blocking
, -- (RM D.7(17))
165 Not_A_Restriction_Id
);
167 -- Synonyms permitted for historical purposes of compatibility.
168 -- Must be coordinated with Restrict.Process_Restriction_Synonym.
170 Boolean_Entry_Barriers
: Restriction_Id
renames Simple_Barriers
;
171 Max_Entry_Queue_Depth
: Restriction_Id
renames Max_Entry_Queue_Length
;
172 No_Dynamic_Interrupts
: Restriction_Id
renames No_Dynamic_Attachment
;
173 No_Requeue
: Restriction_Id
renames No_Requeue_Statements
;
174 No_Task_Attributes
: Restriction_Id
renames No_Task_Attributes_Package
;
176 subtype All_Restrictions
is Restriction_Id
range
177 Simple_Barriers
.. Max_Storage_At_Blocking
;
178 -- All restrictions (excluding only Not_A_Restriction_Id)
180 subtype All_Boolean_Restrictions
is Restriction_Id
range
181 Simple_Barriers
.. No_Wide_Characters
;
182 -- All restrictions which do not take a parameter
184 subtype Partition_Boolean_Restrictions
is All_Boolean_Restrictions
range
185 Simple_Barriers
.. Static_Storage_Size
;
186 -- Boolean restrictions that are checked for partition consistency.
187 -- Note that all parameter restrictions are checked for partition
188 -- consistency by default, so this distinction is only needed in the
189 -- case of Boolean restrictions.
191 subtype Cunit_Boolean_Restrictions
is All_Boolean_Restrictions
range
192 Immediate_Reclamation
.. No_Wide_Characters
;
193 -- Boolean restrictions that are not checked for partition consistency
194 -- and that thus apply only to the current unit. Note that for these
195 -- restrictions, the compiler does not apply restrictions found in
196 -- with'ed units, parent specs etc. to the main unit.
198 subtype All_Parameter_Restrictions
is
200 Max_Protected_Entries
.. Max_Storage_At_Blocking
;
201 -- All restrictions that are take a parameter
203 subtype Checked_Parameter_Restrictions
is
204 All_Parameter_Restrictions
range
205 Max_Protected_Entries
.. Max_Entry_Queue_Length
;
206 -- These are the parameter restrictions that can be at least partially
207 -- checked at compile/binder time. Minimally, the compiler can detect
208 -- violations of a restriction pragma with a value of zero reliably.
210 subtype Checked_Max_Parameter_Restrictions
is
211 Checked_Parameter_Restrictions
range
212 Max_Protected_Entries
.. Max_Task_Entries
;
213 -- Restrictions with parameters that can be checked in some cases by
214 -- maximizing among statically detected instances where the compiler
215 -- can determine the count.
217 subtype Checked_Add_Parameter_Restrictions
is
218 Checked_Parameter_Restrictions
range
219 Max_Tasks
.. Max_Tasks
;
220 -- Restrictions with parameters that can be checked in some cases by
221 -- summing the statically detected instances where the compiler can
222 -- determine the count.
224 subtype Checked_Val_Parameter_Restrictions
is
225 Checked_Parameter_Restrictions
range
226 Max_Protected_Entries
.. Max_Tasks
;
227 -- Restrictions with parameter where the count is known at least in
228 -- some cases by the compiler/binder.
230 subtype Checked_Zero_Parameter_Restrictions
is
231 Checked_Parameter_Restrictions
range
232 Max_Asynchronous_Select_Nesting
.. Max_Entry_Queue_Length
;
233 -- Restrictions with parameters where the compiler can detect the use of
234 -- the feature, and hence violations of a restriction specifying a value
235 -- of zero, but cannot detect specific values other than zero/nonzero.
237 subtype Unchecked_Parameter_Restrictions
is
238 All_Parameter_Restrictions
range
239 Max_Storage_At_Blocking
.. Max_Storage_At_Blocking
;
240 -- Restrictions with parameters where the compiler cannot ever detect
241 -- corresponding compile time usage, so the binder and compiler never
242 -- detect violations of any restriction.
244 -------------------------------------
245 -- Restriction Status Declarations --
246 -------------------------------------
248 -- The following declarations are used to record the current status or
249 -- restrictions (for the current unit, or related units, at compile time,
250 -- and for all units in a partition at bind time or run time).
252 type Restriction_Flags
is array (All_Restrictions
) of Boolean;
253 type Restriction_Values
is array (All_Parameter_Restrictions
) of Natural;
254 type Parameter_Flags
is array (All_Parameter_Restrictions
) of Boolean;
256 type Restrictions_Info
is record
257 Set
: Restriction_Flags
;
258 -- An entry is True in the Set array if a restrictions pragma has been
259 -- encountered for the given restriction. If the value is True for a
260 -- parameter restriction, then the corresponding entry in the Value
261 -- array gives the minimum value encountered for any such restriction.
263 Value
: Restriction_Values
;
264 -- If the entry for a parameter restriction in Set is True (i.e. a
265 -- restrictions pragma for the restriction has been encountered), then
266 -- the corresponding entry in the Value array is the minimum value
267 -- specified by any such restrictions pragma. Note that a restrictions
268 -- pragma specifying a value greater than Int'Last is simply ignored.
270 Violated
: Restriction_Flags
;
271 -- An entry is True in the violations array if the compiler has detected
272 -- a violation of the restriction. For a parameter restriction, the
273 -- Count and Unknown arrays have additional information.
275 Count
: Restriction_Values
;
276 -- If an entry for a parameter restriction is True in Violated, the
277 -- corresponding entry in the Count array may record additional
278 -- information. If the actual minimum count is known (by taking
279 -- maximums, or sums, depending on the restriction), it will be
280 -- recorded in this array. If not, then the value will remain zero.
281 -- The value is also zero for a non-violated restriction.
283 Unknown
: Parameter_Flags
;
284 -- If an entry for a parameter restriction is True in Violated, the
285 -- corresponding entry in the Unknown array may record additional
286 -- information. If the actual count is not known by the compiler (but
287 -- is known to be non-zero), then the entry in Unknown will be True.
288 -- This indicates that the value in Count is not known to be exact,
289 -- and the actual violation count may be higher.
291 -- Note: If Violated (K) is True, then either Count (K) > 0 or
292 -- Unknown (K) = True. It is possible for both these to be set.
293 -- For example, if Count (K) = 3 and Unknown (K) is True, it means
294 -- that the actual violation count is at least 3 but might be higher.
297 No_Restrictions
: constant Restrictions_Info
:=
298 (Set
=> (others => False),
299 Value
=> (others => 0),
300 Violated
=> (others => False),
301 Count
=> (others => 0),
302 Unknown
=> (others => False));
303 -- Used to initialize Restrictions_Info variables
305 ----------------------------------
306 -- Profile Definitions and Data --
307 ----------------------------------
309 type Profile_Name
is (Ravenscar
, Restricted
);
310 -- Names of recognized profiles
312 type Profile_Data
is record
313 Set
: Restriction_Flags
;
314 -- Set to True if given restriction must be set for the profile,
315 -- and False if it need not be set (False does not mean that it
316 -- must not be set, just that it need not be set). If the flag
317 -- is True for a parameter restriction, then the Value array
318 -- gives the maximum value permitted by the profile.
320 Value
: Restriction_Values
;
321 -- An entry in this array is meaningful only if the corresponding
322 -- flag in Set is True. In that case, the value in this array is
323 -- the maximum value of the parameter permitted by the profile.
326 Profile_Info
: array (Profile_Name
) of Profile_Data
:=
328 -- Restricted Profile
332 -- Restrictions for Restricted profile
335 (No_Abort_Statements
=> True,
336 No_Asynchronous_Control
=> True,
337 No_Dynamic_Attachment
=> True,
338 No_Dynamic_Priorities
=> True,
339 No_Entry_Queue
=> True,
340 No_Local_Protected_Objects
=> True,
341 No_Protected_Type_Allocators
=> True,
342 No_Requeue_Statements
=> True,
343 No_Task_Allocators
=> True,
344 No_Task_Attributes_Package
=> True,
345 No_Task_Hierarchy
=> True,
346 No_Terminate_Alternatives
=> True,
347 Max_Asynchronous_Select_Nesting
=> True,
348 Max_Protected_Entries
=> True,
349 Max_Select_Alternatives
=> True,
350 Max_Task_Entries
=> True,
353 -- Value settings for Restricted profile
356 (Max_Asynchronous_Select_Nesting
=> 0,
357 Max_Protected_Entries
=> 1,
358 Max_Select_Alternatives
=> 0,
359 Max_Task_Entries
=> 0,
364 -- Note: the table entries here only represent the
365 -- required restriction profile for Ravenscar. The
366 -- full Ravenscar profile also requires:
368 -- pragma Dispatching_Policy (FIFO_Within_Priorities);
369 -- pragma Locking_Policy (Ceiling_Locking);
370 -- pragma Detect_Blocking
374 -- Restrictions for Ravenscar = Restricted profile ..
377 (No_Abort_Statements
=> True,
378 No_Asynchronous_Control
=> True,
379 No_Dynamic_Attachment
=> True,
380 No_Dynamic_Priorities
=> True,
381 No_Entry_Queue
=> True,
382 No_Local_Protected_Objects
=> True,
383 No_Protected_Type_Allocators
=> True,
384 No_Requeue_Statements
=> True,
385 No_Task_Allocators
=> True,
386 No_Task_Attributes_Package
=> True,
387 No_Task_Hierarchy
=> True,
388 No_Terminate_Alternatives
=> True,
389 Max_Asynchronous_Select_Nesting
=> True,
390 Max_Protected_Entries
=> True,
391 Max_Select_Alternatives
=> True,
392 Max_Task_Entries
=> True,
394 -- plus these additional restrictions:
397 No_Implicit_Heap_Allocations
=> True,
398 No_Relative_Delay
=> True,
399 No_Select_Statements
=> True,
400 No_Task_Termination
=> True,
401 Simple_Barriers
=> True,
404 -- Value settings for Ravenscar (same as Restricted)
407 (Max_Asynchronous_Select_Nesting
=> 0,
408 Max_Protected_Entries
=> 1,
409 Max_Select_Alternatives
=> 0,
410 Max_Task_Entries
=> 0,