OSDN Git Service

gcc/ChangeLog:
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-stchop-vxworks.adb
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-2009, 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 VxWorks version of this package.
33 --  This file should be kept synchronized with the general implementation
34 --  provided by s-stchop.adb. This version is for VxWorks 5 and VxWorks MILS.
35
36 pragma Restrictions (No_Elaboration_Code);
37 --  We want to guarantee the absence of elaboration code because the
38 --  binder does not handle references to this package.
39
40 with System.Storage_Elements; use System.Storage_Elements;
41 with System.Parameters; use System.Parameters;
42 with Interfaces.C;
43
44 package body System.Stack_Checking.Operations is
45
46    --  In order to have stack checking working appropriately on VxWorks we need
47    --  to extract the stack size information from the VxWorks kernel itself.
48
49    --  For VxWorks 5 the library for showing task-related information needs to
50    --  be linked into the VxWorks system, when using stack checking. The
51    --  taskShow library can be linked into the VxWorks system by either:
52
53    --    * defining INCLUDE_SHOW_ROUTINES in config.h when using
54    --      configuration header files, or
55
56    --    * selecting INCLUDE_TASK_SHOW when using the Tornado project
57    --      facility.
58
59    --  VxWorks MILS includes the necessary routine in taskLib, so nothing
60    --  special needs to be done there.
61
62    Stack_Limit : Address :=
63                    Boolean'Pos (Stack_Grows_Down) * Address'First
64                    + Boolean'Pos (not Stack_Grows_Down) * Address'Last;
65    pragma Export (C, Stack_Limit, "__gnat_stack_limit");
66    --  Stack_Limit contains the limit of the stack. This variable is later made
67    --  a task variable (by calling taskVarAdd) and then correctly set to the
68    --  stack limit of the task. Before being so initialized its value must be
69    --  valid so that any subprogram with stack checking enabled will run. We
70    --  use extreme values according to the direction of the stack.
71
72    type Set_Stack_Limit_Proc_Acc is access procedure;
73    pragma Convention (C, Set_Stack_Limit_Proc_Acc);
74
75    Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
76    pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
77    --  Procedure to be called when a task is created to set stack
78    --  limit.
79
80    procedure Set_Stack_Limit_For_Current_Task;
81    pragma Convention (C, Set_Stack_Limit_For_Current_Task);
82    --  Register Initial_SP as the initial stack pointer value for the current
83    --  task when it starts and Size as the associated stack area size. This
84    --  should be called once, after the soft-links have been initialized?
85
86    -----------------------------
87    --  Initialize_Stack_Limit --
88    -----------------------------
89
90    procedure Initialize_Stack_Limit is
91    begin
92       --  For the environment task
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       use Interfaces.C;
107
108       function Task_Var_Add (Tid : Interfaces.C.int; Var : Address)
109                             return Interfaces.C.int;
110       pragma Import (C, Task_Var_Add, "taskVarAdd");
111       --  Import from VxWorks
112
113       type OS_Stack_Info is record
114          Size  : Interfaces.C.int;
115          Base  : System.Address;
116          Limit : System.Address;
117       end record;
118       pragma Convention (C, OS_Stack_Info);
119       --  Type representing the information that we want to extract from the
120       --  underlying kernel.
121
122       procedure Get_Stack_Info (Stack : not null access OS_Stack_Info);
123       pragma Import (C, Get_Stack_Info, "__gnat_get_stack_info");
124       --  Procedure that fills the stack information associated to the
125       --  currently executing task.
126
127       Stack_Info : aliased OS_Stack_Info;
128
129       Limit : System.Address;
130
131    begin
132       --  Get stack bounds from VxWorks
133
134       Get_Stack_Info (Stack_Info'Access);
135
136       --  In s-stchop.adb, we check for overflow in the following operations,
137       --  but we have no such check in this vxworks version. Why not ???
138
139       if Stack_Grows_Down then
140          Limit := Stack_Info.Base - Storage_Offset (Stack_Info.Size);
141       else
142          Limit := Stack_Info.Base + Storage_Offset (Stack_Info.Size);
143       end if;
144
145       --  Note: taskVarAdd implicitly calls taskVarInit if required
146
147       if Task_Var_Add (0, Stack_Limit'Address) = 0 then
148          Stack_Limit := Limit;
149       end if;
150    end Set_Stack_Limit_For_Current_Task;
151
152 end System.Stack_Checking.Operations;