1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . S T A C K _ C H E C K I N G --
9 -- Copyright (C) 1999-2024, Free Software Foundation, Inc. --
11 -- GNARL 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. --
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. --
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/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This package provides a system-independent implementation of stack
33 -- checking using comparison with stack base and limit.
35 -- This package defines basic types and objects. Operations related to
36 -- stack checking can be found in package System.Stack_Checking.Operations.
38 with System
.Storage_Elements
;
40 package System
.Stack_Checking
is
42 pragma Elaborate_Body
;
43 -- This unit has a junk null body. The reason is that historically we
44 -- used to have a real body, and it causes bootstrapping path problems
45 -- to eliminate it, since the old body may still be present in the
46 -- compilation environment for a build.
48 type Stack_Info
is record
49 Limit
: System
.Address
:= System
.Null_Address
;
50 Base
: System
.Address
:= System
.Null_Address
;
51 Size
: System
.Storage_Elements
.Storage_Offset
:= 0;
53 -- This record may be part of a larger data structure like the
54 -- task control block in the tasking case.
55 -- This specific layout has the advantage of being compatible with the
56 -- Intel x86 BOUNDS instruction.
58 type Stack_Access
is access all Stack_Info
;
59 -- Unique local storage associated with a specific task. This storage is
60 -- used for the stack base and limit, and is returned by Checked_Self.
61 -- Only self may write this information, it may be read by any task.
62 -- At no time the address range Limit .. Base (or Base .. Limit for
63 -- upgrowing stack) may contain any address that is part of another stack.
64 -- The Stack_Access may be part of a larger data structure.
66 Multi_Processor
: constant Boolean := False; -- Not supported yet
70 Null_Stack_Info
: aliased Stack_Info
:=
71 (Limit
=> System
.Null_Address
,
72 Base
=> System
.Null_Address
,
74 -- Use explicit assignment to avoid elaboration code (call to init proc)
76 Null_Stack
: constant Stack_Access
:= Null_Stack_Info
'Access;
77 -- Stack_Access value that will return a Stack_Base and Stack_Limit
78 -- that fail any stack check.
80 end System
.Stack_Checking
;