LIBGNAT_TARGET_PAIRS += \
s-intman.adb<libgnarl/s-intman__cheribsd.adb \
s-osinte.ads<libgnarl/s-osinte__cheribsd.ads \
+ s-tsgsba.adb<libgnarl/s-tsgsba__cheri.adb \
s-secsta.adb<libgnat/s-secsta__cheri.adb
EXTRA_GNATRTL_NONTASKING_OBJS += i-cheri.o i-cheri-exceptions.o
-- Different code is used at master completion, in Terminate_Dependents,
-- due to a need for tighter synchronization with the master.
+ function Get_Stack_Base (Self_ID : Task_Id) return System.Address;
+ -- Get the stack base of Self.
+ --
+ -- If the stack base cannot be determined, then Null_Address is returned.
+
----------------------
-- Abort_Dependents --
----------------------
-- Address of the base of the stack
begin
- Stack_Base := Self_ID.Common.Compiler_Data.Pri_Stack_Info.Base;
+ Stack_Base := Get_Stack_Base (Self_ID);
if Stack_Base = Null_Address then
(Self_ID.Common.Analyzer,
Self_ID.Common.Task_Image (1 .. Self_ID.Common.Task_Image_Len),
Natural (Self_ID.Common.Compiler_Data.Pri_Stack_Info.Size),
- SSE.To_Integer (Stack_Base),
+ Stack_Base,
Pattern_Size);
STPO.Unlock_RTS;
Fill_Stack (Self_ID.Common.Analyzer);
System.Task_Primitives.Operations.Finalize_TCB (T);
end Vulnerable_Free_Task;
+ --------------------
+ -- Get_Stack_Base --
+ --------------------
+
+ -- Get_Stack_Base is architecture-specific
+
+ function Get_Stack_Base (Self_ID : Task_Id) return System.Address
+ is separate;
+
-- Package elaboration code
begin
--- /dev/null
+------------------------------------------------------------------------------
+-- --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
+-- --
+-- S Y S T E M . T A S K I N G . S T A G E S . G E T _ S T A C K _ B A S E --
+-- --
+-- B o d y --
+-- --
+-- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
+-- --
+-- GNARL is free software; you can redistribute it and/or modify it under --
+-- terms of the GNU General Public License as published by the Free Soft- --
+-- ware Foundation; either version 3, or (at your option) any later ver- --
+-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception, --
+-- version 3.1, as published by the Free Software Foundation. --
+-- --
+-- You should have received a copy of the GNU General Public License and --
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
+-- <http://www.gnu.org/licenses/>. --
+-- --
+-- GNARL was developed by the GNARL team at Florida State University. --
+-- Extensive contributions were provided by Ada Core Technologies, Inc. --
+-- --
+------------------------------------------------------------------------------
+
+-- This is the default version for most platforms which tries to get the
+-- stack base from the compiler info. It returns Null_Address if the stack
+-- base is not available.
+
+separate (System.Tasking.Stages)
+function Get_Stack_Base (Self_ID : Task_Id) return System.Address is
+begin
+ return Self_ID.Common.Compiler_Data.Pri_Stack_Info.Base;
+end Get_Stack_Base;
--- /dev/null
+------------------------------------------------------------------------------
+-- --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
+-- --
+-- S Y S T E M . T A S K I N G . S T A G E S . G E T _ S T A C K _ B A S E --
+-- --
+-- B o d y --
+-- --
+-- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
+-- --
+-- GNARL is free software; you can redistribute it and/or modify it under --
+-- terms of the GNU General Public License as published by the Free Soft- --
+-- ware Foundation; either version 3, or (at your option) any later ver- --
+-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception, --
+-- version 3.1, as published by the Free Software Foundation. --
+-- --
+-- You should have received a copy of the GNU General Public License and --
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
+-- <http://www.gnu.org/licenses/>. --
+-- --
+-- GNARL was developed by the GNARL team at Florida State University. --
+-- Extensive contributions were provided by Ada Core Technologies, Inc. --
+-- --
+------------------------------------------------------------------------------
+with Interfaces.CHERI;
+
+-- This is the version for CHERI targets where we can derive the stack base
+-- from the upper bound of the capability stack pointer (CSP).
+
+separate (System.Tasking.Stages)
+function Get_Stack_Base (Self_ID : Task_Id) return System.Address is
+ pragma Unreferenced (Self_ID);
+
+ use type SSE.Integer_Address;
+
+ CSP : constant System.Address := Interfaces.CHERI.Get_CSP;
+begin
+ return Interfaces.CHERI.Capability_With_Address
+ (Cap => CSP,
+ Addr => Interfaces.CHERI.Get_Base (CSP) +
+ SSE.Integer_Address
+ (Interfaces.CHERI.Get_Length (CSP)));
+end Get_Stack_Base;
-- allocated byte on the stack.
begin
if Parameters.Stack_Grows_Down then
- if Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size) >
+ if To_Stack_Address (Analyzer.Stack_Base) -
+ Stack_Address (Analyzer.Pattern_Size) >
To_Stack_Address (Current_Stack_Level'Address) - Guard
then
-- No room for a pattern
end if;
Analyzer.Pattern_Limit :=
- Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size);
+ Analyzer.Stack_Base - Storage_Offset (Analyzer.Pattern_Size);
- if Analyzer.Stack_Base >
+ if To_Stack_Address (Analyzer.Stack_Base) >
To_Stack_Address (Current_Stack_Level'Address) - Guard
then
-- Reduce pattern size to prevent local frame overwrite
Analyzer.Pattern_Size :=
Integer (To_Stack_Address (Current_Stack_Level'Address) - Guard
- - Analyzer.Pattern_Limit);
+ - To_Stack_Address (Analyzer.Pattern_Limit));
end if;
- Analyzer.Pattern_Overlay_Address :=
- To_Address (Analyzer.Pattern_Limit);
+ Analyzer.Pattern_Overlay_Address := Analyzer.Pattern_Limit;
else
- if Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size) <
+ if To_Stack_Address (Analyzer.Stack_Base) +
+ Stack_Address (Analyzer.Pattern_Size) <
To_Stack_Address (Current_Stack_Level'Address) + Guard
then
-- No room for a pattern
end if;
Analyzer.Pattern_Limit :=
- Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size);
+ Analyzer.Stack_Base + Storage_Offset (Analyzer.Pattern_Size);
- if Analyzer.Stack_Base <
+ if To_Stack_Address (Analyzer.Stack_Base) <
To_Stack_Address (Current_Stack_Level'Address) + Guard
then
-- Reduce pattern size to prevent local frame overwrite
Analyzer.Pattern_Size :=
Integer
- (Analyzer.Pattern_Limit -
+ (To_Stack_Address (Analyzer.Pattern_Limit) -
(To_Stack_Address (Current_Stack_Level'Address) + Guard));
end if;
Analyzer.Pattern_Overlay_Address :=
- To_Address (Analyzer.Pattern_Limit -
- Stack_Address (Analyzer.Pattern_Size));
+ Analyzer.Pattern_Limit - Storage_Offset (Analyzer.Pattern_Size);
end if;
-- Declare and fill the pattern buffer
(Analyzer : in out Stack_Analyzer;
Task_Name : String;
Stack_Size : Natural;
- Stack_Base : Stack_Address;
+ Stack_Base : System.Address;
Pattern_Size : Natural;
Pattern : Interfaces.Unsigned_32 := 16#DEAD_BEEF#)
is
if Parameters.Stack_Grows_Down then
Analyzer.Topmost_Touched_Mark :=
- Analyzer.Pattern_Limit + Stack_Address (Analyzer.Pattern_Size);
+ Analyzer.Pattern_Limit + Storage_Offset (Analyzer.Pattern_Size);
else
Analyzer.Topmost_Touched_Mark :=
- Analyzer.Pattern_Limit - Stack_Address (Analyzer.Pattern_Size);
+ Analyzer.Pattern_Limit - Storage_Offset (Analyzer.Pattern_Size);
end if;
if Analyzer.Pattern_Size = 0 then
if System.Parameters.Stack_Grows_Down then
for J in Stack'Range loop
if Stack (J) /= Analyzer.Pattern then
- Analyzer.Topmost_Touched_Mark :=
- To_Stack_Address (Stack (J)'Address);
+ Analyzer.Topmost_Touched_Mark := Stack (J)'Address;
exit;
end if;
end loop;
else
for J in reverse Stack'Range loop
if Stack (J) /= Analyzer.Pattern then
- Analyzer.Topmost_Touched_Mark :=
- To_Stack_Address (Stack (J)'Address);
+ Analyzer.Topmost_Touched_Mark := Stack (J)'Address;
exit;
end if;
end loop;
Result.Value := Analyzer.Stack_Size;
else
- Result.Value := Stack_Size (Analyzer.Topmost_Touched_Mark,
- Analyzer.Stack_Base);
+ Result.Value :=
+ Stack_Size (To_Stack_Address (Analyzer.Topmost_Touched_Mark),
+ To_Stack_Address (Analyzer.Stack_Base));
end if;
if Analyzer.Result_Id in Result_Array'Range then
(Analyzer : in out Stack_Analyzer;
Task_Name : String;
Stack_Size : Natural;
- Stack_Base : Stack_Address;
+ Stack_Base : System.Address;
Pattern_Size : Natural;
Pattern : Interfaces.Unsigned_32 := 16#DEAD_BEEF#);
-- Should be called before any use of a Stack_Analyzer, to initialize it.
Task_Name : String (1 .. Task_Name_Length);
-- Name of the task
- Stack_Base : Stack_Address;
+ Stack_Base : System.Address;
-- Address of the base of the stack, as given by the caller of
-- Initialize_Analyzer.
Pattern : Pattern_Type;
-- Pattern used to recognize untouched memory
- Pattern_Limit : Stack_Address;
+ Pattern_Limit : System.Address;
-- Bound of the pattern area farthest to the base
- Topmost_Touched_Mark : Stack_Address;
+ Topmost_Touched_Mark : System.Address;
-- Topmost address of the pattern area whose value it is pointing
-- at has been modified during execution. If the systematic error are
-- compensated, it is the topmost value of the stack pointer during