File : s-intman.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
   4 --                                                                          --
   5 --            S Y S T E M . I N T E R R U P T _ M A N A G E M E N T         --
   6 --                                                                          --
   7 --                                  S p e c                                 --
   8 --                                                                          --
   9 --          Copyright (C) 1992-2014, 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 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  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 package encapsulates and centralizes information about all uses of
  33 --  interrupts (or signals), including the target-dependent mapping of
  34 --  interrupts (or signals) to exceptions.
  35 
  36 --  Unlike the original design, System.Interrupt_Management can only be used
  37 --  for tasking systems.
  38 
  39 --  PLEASE DO NOT put any subprogram declarations with arguments of type
  40 --  Interrupt_ID into the visible part of this package. The type Interrupt_ID
  41 --  is used to derive the type in Ada.Interrupts, and adding more operations
  42 --  to that type would be illegal according to the Ada Reference Manual. This
  43 --  is the reason why the signals sets are implemented using visible arrays
  44 --  rather than functions.
  45 
  46 with System.OS_Interface;
  47 
  48 with Interfaces.C;
  49 
  50 package System.Interrupt_Management is
  51    pragma Preelaborate;
  52 
  53    type Interrupt_Mask is limited private;
  54 
  55    type Interrupt_ID is new Interfaces.C.int
  56      range 0 .. System.OS_Interface.Max_Interrupt;
  57 
  58    type Interrupt_Set is array (Interrupt_ID) of Boolean;
  59 
  60    --  The following objects serve as constants, but are initialized in the
  61    --  body to aid portability. This permits us to use more portable names for
  62    --  interrupts, where distinct names may map to the same interrupt ID
  63    --  value.
  64 
  65    --  For example, suppose SIGRARE is a signal that is not defined on all
  66    --  systems, but is always reserved when it is defined. If we have the
  67    --  convention that ID zero is not used for any "real" signals, and SIGRARE
  68    --  = 0 when SIGRARE is not one of the locally supported signals, we can
  69    --  write:
  70    --     Reserved (SIGRARE) := True;
  71    --  and the initialization code will be portable.
  72 
  73    Abort_Task_Interrupt : Interrupt_ID;
  74    --  The interrupt that is used to implement task abort if an interrupt is
  75    --  used for that purpose. This is one of the reserved interrupts.
  76 
  77    Keep_Unmasked : Interrupt_Set := (others => False);
  78    --  Keep_Unmasked (I) is true iff the interrupt I is one that must be kept
  79    --  unmasked at all times, except (perhaps) for short critical sections.
  80    --  This includes interrupts that are mapped to exceptions (see
  81    --  System.Interrupt_Exceptions.Is_Exception), but may also include
  82    --  interrupts (e.g. timer) that need to be kept unmasked for other
  83    --  reasons. Where interrupts are implemented as OS signals, and signal
  84    --  masking is per-task, the interrupt should be unmasked in ALL TASKS.
  85 
  86    Reserve : Interrupt_Set := (others => False);
  87    --  Reserve (I) is true iff the interrupt I is one that cannot be permitted
  88    --  to be attached to a user handler. The possible reasons are many. For
  89    --  example, it may be mapped to an exception used to implement task abort,
  90    --  or used to implement time delays.
  91 
  92    procedure Initialize;
  93    --  Initialize the various variables defined in this package. This procedure
  94    --  must be called before accessing any object from this package, and can be
  95    --  called multiple times.
  96 
  97 private
  98    type Interrupt_Mask is new System.OS_Interface.sigset_t;
  99    --  In some implementations Interrupt_Mask is represented as a linked list
 100 
 101    procedure Adjust_Context_For_Raise
 102      (Signo    : System.OS_Interface.Signal;
 103       Ucontext : System.Address);
 104    pragma Import
 105      (C, Adjust_Context_For_Raise, "__gnat_adjust_context_for_raise");
 106    --  Target specific hook performing adjustments to the signal's machine
 107    --  context, to be called before an exception may be raised from a signal
 108    --  handler. This service is provided by init.c, together with the
 109    --  non-tasking signal handler.
 110 
 111 end System.Interrupt_Management;