home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-stache.ads < prev    next >
Text File  |  2000-07-19  |  6KB  |  108 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                GNU ADA 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                --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.5 $                             --
  10. --                                                                          --
  11. --             Copyright (C) 1999 Free Software Foundation, Inc.            --
  12. --                                                                          --
  13. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNARL was developed by the GNARL team at Florida State University. It is --
  32. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  33. -- State University (http://www.gnat.com).                                  --
  34. --                                                                          --
  35. ------------------------------------------------------------------------------
  36.  
  37. --  This package provides a system-independent implementation of stack
  38. --  checking using comparison with stack base and limit.
  39.  
  40. with System.Storage_Elements;
  41.  
  42. pragma Polling (Off);
  43. --  Turn off polling, we do not want polling to take place during stack
  44. --  checking operations. It causes infinite loops and other problems.
  45.  
  46. package System.Stack_Checking is
  47.  
  48.    type Stack_Info is limited record
  49.       Limit : System.Address := System.Null_Address;
  50.       Base  : System.Address := System.Null_Address;
  51.       Size  : System.Storage_Elements.Storage_Offset := 0;
  52.    end record;
  53.    --  This record may be part of a larger data structure like the
  54.    --  task control block in the tasking case.
  55.    --  This specific layout has the advantage of being able with the
  56.    --  Intel x86 BOUNDS instruction.
  57.  
  58.    type Stack_Access is access all Stack_Info;
  59.    --  Unique local storage associated with a specific task. This storage is
  60.    --  used for the stack base and limit, and is returned by Checked_Self.
  61.    --  Only self may write this information, it may be read by any task.
  62.    --  At no time the address range Limit .. Base (or Base .. Limit for
  63.    --  upgrowing stack) may contain any address that is part of another stack.
  64.    --  The Stack_Access may be part of a larger data structure.
  65.  
  66.    Multi_Processor        : constant Boolean := False; --  Not supported yet
  67.  
  68.    ----------------------
  69.    -- Client Interface --
  70.    ----------------------
  71.  
  72.    procedure Set_Stack_Size
  73.      (Stack_Size : System.Storage_Elements.Storage_Offset);
  74.    --  Specify the stack size for the current task.
  75.  
  76.    procedure Update_Stack_Cache (Stack : Stack_Access);
  77.    --  Set the stack cache for the current task. Note that this is only
  78.    --  for optimization purposes, nothing can be assumed about the
  79.    --  contents of the cache at any time, see Set_Stack_Info.
  80.  
  81.    procedure Invalidate_Stack_Cache (Any_Stack : Stack_Access);
  82.    --  Invalidate cache entries for the task T that owns Any_Stack.
  83.    --  This causes the Set_Stack_Info function to be called during
  84.    --  the next stack check done by T. This can be used to interrupt
  85.    --  task T asynchronously.
  86.    --  Stack_Check should be called in loops for this to work reliably.
  87.  
  88.    function Stack_Check
  89.      (Stack_Address : System.Address)
  90.       return Stack_Access;
  91.    --  This version of Stack_Check should not be inlined.
  92.  
  93. private
  94.  
  95.    Null_Stack_Info  : aliased Stack_Info;
  96.    --  The default initialization is correct here.
  97.  
  98.    Null_Stack       : constant Stack_Access := Null_Stack_Info'Access;
  99.    --  Stack_Access value that will return a Stack_Base and Stack_Limit
  100.    --  that fail any stack check.
  101.  
  102.    Cache            : aliased Stack_Access := Null_Stack;
  103.  
  104.    pragma Export (C, Cache, "_gnat_stack_cache");
  105.    pragma Export (C, Stack_Check, "_gnat_stack_check");
  106.  
  107. end System.Stack_Checking;
  108.