| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . S T A C K _ C H E C K I N G . O P E R A T I O N S -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1999-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 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. -- |
| 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 |
-- GNARL was developed by the GNARL team at Florida State University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies, Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- This is the verson for VxWorks 5, VxWorks 6 Cert and VxWorks MILS |
| 33 |
|
| 34 |
-- This file should be kept synchronized with the general implementation |
| 35 |
-- provided by s-stchop.adb. |
| 36 |
|
| 37 |
pragma Restrictions (No_Elaboration_Code); |
| 38 |
-- We want to guarantee the absence of elaboration code because the |
| 39 |
-- binder does not handle references to this package. |
| 40 |
|
| 41 |
with System.Storage_Elements; use System.Storage_Elements; |
| 42 |
with System.Parameters; use System.Parameters; |
| 43 |
with Interfaces.C; |
| 44 |
|
| 45 |
package body System.Stack_Checking.Operations is |
| 46 |
|
| 47 |
-- In order to have stack checking working appropriately on VxWorks we need |
| 48 |
-- to extract the stack size information from the VxWorks kernel itself. |
| 49 |
|
| 50 |
-- For VxWorks 5 & 6 the library for showing task-related information |
| 51 |
-- needs to be linked into the VxWorks system, when using stack checking. |
| 52 |
-- The taskShow library can be linked into the VxWorks system by either: |
| 53 |
|
| 54 |
-- * defining INCLUDE_SHOW_ROUTINES in config.h when using |
| 55 |
-- configuration header files, or |
| 56 |
|
| 57 |
-- * selecting INCLUDE_TASK_SHOW when using the Tornado project |
| 58 |
-- facility. |
| 59 |
|
| 60 |
-- VxWorks MILS includes the necessary routine in taskLib, so nothing |
| 61 |
-- special needs to be done there. |
| 62 |
|
| 63 |
Stack_Limit : Address; |
| 64 |
|
| 65 |
pragma Import (C, Stack_Limit, "__gnat_stack_limit"); |
| 66 |
|
| 67 |
-- Stack_Limit contains the limit of the stack. This variable is later made |
| 68 |
-- a task variable (by calling taskVarAdd) and then correctly set to the |
| 69 |
-- stack limit of the task. Before being so initialized its value must be |
| 70 |
-- valid so that any subprogram with stack checking enabled will run. We |
| 71 |
-- use extreme values according to the direction of the stack. |
| 72 |
|
| 73 |
type Set_Stack_Limit_Proc_Acc is access procedure; |
| 74 |
pragma Convention (C, Set_Stack_Limit_Proc_Acc); |
| 75 |
|
| 76 |
Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc; |
| 77 |
pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook"); |
| 78 |
-- Procedure to be called when a task is created to set stack |
| 79 |
-- limit. |
| 80 |
|
| 81 |
procedure Set_Stack_Limit_For_Current_Task; |
| 82 |
pragma Convention (C, Set_Stack_Limit_For_Current_Task); |
| 83 |
-- Register Initial_SP as the initial stack pointer value for the current |
| 84 |
-- task when it starts and Size as the associated stack area size. This |
| 85 |
-- should be called once, after the soft-links have been initialized? |
| 86 |
|
| 87 |
----------------------------- |
| 88 |
-- Initialize_Stack_Limit -- |
| 89 |
----------------------------- |
| 90 |
|
| 91 |
procedure Initialize_Stack_Limit is |
| 92 |
begin |
| 93 |
|
| 94 |
Set_Stack_Limit_For_Current_Task; |
| 95 |
|
| 96 |
-- Will be called by every created task |
| 97 |
|
| 98 |
Set_Stack_Limit_Hook := Set_Stack_Limit_For_Current_Task'Access; |
| 99 |
end Initialize_Stack_Limit; |
| 100 |
|
| 101 |
-------------------------------------- |
| 102 |
-- Set_Stack_Limit_For_Current_Task -- |
| 103 |
-------------------------------------- |
| 104 |
|
| 105 |
procedure Set_Stack_Limit_For_Current_Task is |
| 106 |
type OS_Stack_Info is record |
| 107 |
Size : Interfaces.C.int; |
| 108 |
Base : System.Address; |
| 109 |
Limit : System.Address; |
| 110 |
end record; |
| 111 |
pragma Convention (C, OS_Stack_Info); |
| 112 |
-- Type representing the information that we want to extract from the |
| 113 |
-- underlying kernel. |
| 114 |
|
| 115 |
procedure Get_Stack_Info (Stack : not null access OS_Stack_Info); |
| 116 |
pragma Import (C, Get_Stack_Info, "__gnat_get_stack_info"); |
| 117 |
-- Procedure that fills the stack information associated to the |
| 118 |
-- currently executing task. |
| 119 |
|
| 120 |
Stack_Info : aliased OS_Stack_Info; |
| 121 |
|
| 122 |
Limit : System.Address; |
| 123 |
|
| 124 |
begin |
| 125 |
|
| 126 |
-- Get stack bounds from VxWorks |
| 127 |
|
| 128 |
Get_Stack_Info (Stack_Info'Access); |
| 129 |
|
| 130 |
if Stack_Grows_Down then |
| 131 |
Limit := |
| 132 |
Stack_Info.Base - Storage_Offset (Stack_Info.Size) + |
| 133 |
Storage_Offset'(12_000); |
| 134 |
else |
| 135 |
Limit := |
| 136 |
Stack_Info.Base + Storage_Offset (Stack_Info.Size) - |
| 137 |
Storage_Offset'(12_000); |
| 138 |
end if; |
| 139 |
|
| 140 |
Stack_Limit := Limit; |
| 141 |
|
| 142 |
end Set_Stack_Limit_For_Current_Task; |
| 143 |
end System.Stack_Checking.Operations; |