]>
Commit | Line | Data |
---|---|---|
40a4417a | 1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
8bed087e | 3 | -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- |
40a4417a | 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 | -- -- | |
dc483d7c | 9 | -- Copyright (C) 1999-2015, Free Software Foundation, Inc. -- |
40a4417a | 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- -- | |
6bc9506f | 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- -- | |
40a4417a | 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
6bc9506f | 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/>. -- | |
40a4417a | 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 | ||
dc483d7c | 32 | -- This is the verson for VxWorks 5, VxWorks 6 Cert and VxWorks MILS |
b6250473 | 33 | |
40a4417a | 34 | -- This file should be kept synchronized with the general implementation |
b6250473 | 35 | -- provided by s-stchop.adb. |
40a4417a | 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 | ||
40a4417a | 41 | with System.Storage_Elements; use System.Storage_Elements; |
42 | with System.Parameters; use System.Parameters; | |
40a4417a | 43 | with Interfaces.C; |
40a4417a | 44 | |
45 | package body System.Stack_Checking.Operations is | |
46 | ||
3d572c5a | 47 | -- In order to have stack checking working appropriately on VxWorks we need |
a03d8852 | 48 | -- to extract the stack size information from the VxWorks kernel itself. |
49 | ||
dc483d7c | 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: | |
3d572c5a | 53 | |
40a4417a | 54 | -- * defining INCLUDE_SHOW_ROUTINES in config.h when using |
55 | -- configuration header files, or | |
3d572c5a | 56 | |
40a4417a | 57 | -- * selecting INCLUDE_TASK_SHOW when using the Tornado project |
58 | -- facility. | |
59 | ||
a03d8852 | 60 | -- VxWorks MILS includes the necessary routine in taskLib, so nothing |
61 | -- special needs to be done there. | |
62 | ||
bbbfe30c | 63 | Stack_Limit : Address := |
64 | Boolean'Pos (Stack_Grows_Down) * Address'First | |
65 | + Boolean'Pos (not Stack_Grows_Down) * Address'Last; | |
66 | pragma Export (C, Stack_Limit, "__gnat_stack_limit"); | |
dc483d7c | 67 | |
783fd6de | 68 | -- Stack_Limit contains the limit of the stack. This variable is later made |
69 | -- a task variable (by calling taskVarAdd) and then correctly set to the | |
70 | -- stack limit of the task. Before being so initialized its value must be | |
71 | -- valid so that any subprogram with stack checking enabled will run. We | |
72 | -- use extreme values according to the direction of the stack. | |
73 | ||
74 | type Set_Stack_Limit_Proc_Acc is access procedure; | |
75 | pragma Convention (C, Set_Stack_Limit_Proc_Acc); | |
76 | ||
77 | Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc; | |
78 | pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook"); | |
79 | -- Procedure to be called when a task is created to set stack | |
80 | -- limit. | |
81 | ||
82 | procedure Set_Stack_Limit_For_Current_Task; | |
83 | pragma Convention (C, Set_Stack_Limit_For_Current_Task); | |
84 | -- Register Initial_SP as the initial stack pointer value for the current | |
85 | -- task when it starts and Size as the associated stack area size. This | |
86 | -- should be called once, after the soft-links have been initialized? | |
40a4417a | 87 | |
f23c9933 | 88 | ----------------------------- |
783fd6de | 89 | -- Initialize_Stack_Limit -- |
f23c9933 | 90 | ----------------------------- |
91 | ||
783fd6de | 92 | procedure Initialize_Stack_Limit is |
93 | begin | |
063ed58b | 94 | -- For the environment task |
95 | ||
783fd6de | 96 | Set_Stack_Limit_For_Current_Task; |
f23c9933 | 97 | |
063ed58b | 98 | -- Will be called by every created task |
99 | ||
783fd6de | 100 | Set_Stack_Limit_Hook := Set_Stack_Limit_For_Current_Task'Access; |
101 | end Initialize_Stack_Limit; | |
f23c9933 | 102 | |
783fd6de | 103 | -------------------------------------- |
104 | -- Set_Stack_Limit_For_Current_Task -- | |
105 | -------------------------------------- | |
106 | ||
107 | procedure Set_Stack_Limit_For_Current_Task is | |
108 | use Interfaces.C; | |
f23c9933 | 109 | |
982a5d65 | 110 | type OS_Stack_Info is record |
111 | Size : Interfaces.C.int; | |
112 | Base : System.Address; | |
113 | Limit : System.Address; | |
40a4417a | 114 | end record; |
982a5d65 | 115 | pragma Convention (C, OS_Stack_Info); |
116 | -- Type representing the information that we want to extract from the | |
117 | -- underlying kernel. | |
40a4417a | 118 | |
982a5d65 | 119 | procedure Get_Stack_Info (Stack : not null access OS_Stack_Info); |
120 | pragma Import (C, Get_Stack_Info, "__gnat_get_stack_info"); | |
121 | -- Procedure that fills the stack information associated to the | |
122 | -- currently executing task. | |
40a4417a | 123 | |
783fd6de | 124 | Stack_Info : aliased OS_Stack_Info; |
40a4417a | 125 | |
063ed58b | 126 | Limit : System.Address; |
127 | ||
40a4417a | 128 | begin |
063ed58b | 129 | -- Get stack bounds from VxWorks |
130 | ||
783fd6de | 131 | Get_Stack_Info (Stack_Info'Access); |
40a4417a | 132 | |
783fd6de | 133 | if Stack_Grows_Down then |
fbc5a5a6 | 134 | Limit := |
135 | Stack_Info.Base - Storage_Offset (Stack_Info.Size) + | |
136 | Storage_Offset'(16#12_000#); | |
783fd6de | 137 | else |
fbc5a5a6 | 138 | Limit := |
139 | Stack_Info.Base + Storage_Offset (Stack_Info.Size) - | |
140 | Storage_Offset'(16#12_000#); | |
40a4417a | 141 | end if; |
142 | ||
dc483d7c | 143 | Stack_Limit := Limit; |
783fd6de | 144 | end Set_Stack_Limit_For_Current_Task; |
40a4417a | 145 | |
146 | end System.Stack_Checking.Operations; |