File : s-btstch.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . B B . T H R E A D S . S T A C K _ C H E C K I N G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2004 The European Space Agency --
10 -- Copyright (C) 2004-2013, AdaCore --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- --
19 -- --
20 -- --
21 -- --
22 -- --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
27 -- --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 -- --
31 -- The port of GNARL to bare board targets was initially developed by the --
32 -- Real-Time Systems Group at the Technical University of Madrid. --
33 -- --
34 ------------------------------------------------------------------------------
35
36 pragma Restrictions (No_Elaboration_Code);
37 -- We want to guarantee the absence of elaboration code because the binder
38 -- does not handle references to this package.
39
40 with System.Parameters;
41 with System.BB.Interrupts;
42
43 package body System.BB.Threads.Stack_Checking is
44
45 procedure Stack_Check (Stack_Address : System.Address) is
46 Self : constant Thread_Id := Thread_Self;
47
48 begin
49 -- No stack checking can be performed if the run time has not yet been
50 -- initialized.
51
52 -- When Self = Null_Thread_Id it means that there is no task ready to
53 -- execute, so only external hardware interrupts can be handled.
54 -- Interrupts can also appear when there are tasks ready to execute.
55
56 -- Check whether the stack pointer is outside the stack area, so that
57 -- possible wrap-around address 0 is considered.
58
59 if Initialized
60 and then
61 (Self = Null_Thread_Id
62 or else Stack_Address < Self.Bottom_Of_Stack
63 or else Stack_Address > Self.Top_Of_Stack)
64 and then not Interrupts.Within_Interrupt_Stack (Stack_Address)
65 then
66 raise Storage_Error;
67 end if;
68 end Stack_Check;
69
70 end System.BB.Threads.Stack_Checking;