home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / i-cporte.ads < prev    next >
Text File  |  1996-09-28  |  11KB  |  298 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                I N T E R F A C E S . C . P O S I X _ R T E               --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.20 $                            --
  10. --                                                                          --
  11. --     Copyright (c) 1991,1992,1993,1994,1995 FSU, All Rights Reserved      --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. --  This package interfaces with the POSIX real-time extensions. It may
  27. --  also implement some of them using UNIX operations. It is not a complete
  28. --  interface, it only includes what is needed to implement the Ada runtime.
  29.  
  30. with System;
  31.  
  32. --  temporarily, should really only be for 1 ???
  33. with Interfaces.C.POSIX_Error;
  34. --  Used for: Return_Code
  35.  
  36. with Interfaces.C.System_Constants;
  37. --  Used for: various constants
  38.  
  39. package Interfaces.C.POSIX_RTE is
  40.  
  41.    pragma Elaborate_Body (Interfaces.C.POSIX_RTE);
  42.  
  43.    use Interfaces.C;
  44.    use Interfaces.C.POSIX_Error;
  45.  
  46.    package ICCS renames Interfaces.C.System_Constants;
  47.    package ICPE renames Interfaces.C.Posix_Error;
  48.  
  49.    Alignment : constant := Natural'Min (Standard'Maximum_Alignment, 8);
  50.  
  51.    NSIG : constant := ICCS.NSIG;
  52.    --  Maximum number of signal entries
  53.  
  54.    type Signal is new int;
  55.  
  56.    type Signal_Set is private;
  57.  
  58.    procedure sigaddset
  59.      (set    : access Signal_Set;
  60.       sig    : in Signal;
  61.       Result : out ICPE.Return_Code);
  62.  
  63.    procedure sigdelset
  64.      (set    : access Signal_Set;
  65.       sig    : in Signal;
  66.       Result : out ICPE.Return_Code);
  67.  
  68.    procedure sigfillset
  69.      (set : access Signal_Set;
  70.       Result : out ICPE.Return_Code);
  71.  
  72.    procedure sigemptyset
  73.      (set : access Signal_Set;
  74.       Result : out ICPE.Return_Code);
  75.  
  76.    function sigismember
  77.      (set  : access Signal_Set;
  78.       sig  : Signal)
  79.       return Return_Code;
  80.    pragma Import (C, sigismember, "sigismember");
  81.  
  82.    type sigval is record
  83.       u0 : int;
  84.    end record;
  85.    --  This is not used at the moment, need to update to reflect
  86.    --  any changes in the Pthreads signal.h in the future
  87.  
  88.    type struct_siginfo is record
  89.       si_signo : Signal;
  90.       si_code : int;
  91.    end record;
  92.  
  93.    --  Lay out the POSIX-defined components of the struct_sigaction record to
  94.    --  match their C definition, using information in the i-csycon.ads file.
  95.    --  ??? This depends on constants describing the record computed
  96.    --      by a program that must be run on the target architecture,
  97.    --      and cannot handle records containing bit fields.
  98.    --      This should be done by redefining the entire C structure as
  99.    --      an Ada record and then naming it in a Convention C pragma.  This
  100.    --      will have to be derived from the source code of the
  101.    --      C header file, either automatically or manually.
  102.  
  103.    for struct_siginfo use record
  104.       si_signo at ICCS.si_signo_offset / System.Storage_Unit
  105.         range 0 .. Signal'Size - 1;
  106.       si_code at ICCS.si_code_offset / System.Storage_Unit
  107.         range 0 .. int'Size - 1;
  108.    end record;
  109.    for struct_siginfo'Size use ICCS.siginfo_size * unsigned_char'Size;
  110.    for struct_siginfo'Alignment use Alignment;
  111.  
  112.    type siginfo_ptr is access struct_siginfo;
  113.  
  114.    type sigset_t_ptr is access Signal_Set;
  115.  
  116.    SIG_ERR : constant := ICCS.SIG_ERR;
  117.    SIG_DFL : constant := ICCS.SIG_DFL;
  118.    SIG_IGN : constant := ICCS.SIG_IGN;
  119.    --  constants for sa_handler
  120.  
  121.    type struct_sigaction is record
  122.  
  123.       sa_handler : System.Address;
  124.       --  address of signal handler
  125.  
  126.       sa_mask : aliased Signal_Set;
  127.       --  Additional signals to be blocked during
  128.       --  execution of signal-catching function
  129.  
  130.       sa_flags : int;
  131.       --  Special flags to affect behavior of signal
  132.  
  133.    end record;
  134.  
  135.  
  136.    type sigaction_ptr is access struct_sigaction;
  137.  
  138.    --  Signal catching function (signal handler) has the following profile :
  139.  
  140.    --  procedure Signal_Handler
  141.    --    (signo   : Signal;
  142.    --     info    : siginfo_ptr;
  143.    --     context : sigcontext_ptr);
  144.  
  145.    SA_NOCLDSTOP : constant := ICCS.SA_NOCLDSTOP;
  146.    --  Don't send a SIGCHLD on child stop
  147.  
  148.    SA_SIGINFO : constant := ICCS.SA_SIGINFO;
  149.    --  sa_flags flags for struct_sigaction
  150.  
  151.    SIG_BLOCK   : constant := ICCS.SIG_BLOCK;
  152.    SIG_UNBLOCK : constant := ICCS.SIG_UNBLOCK;
  153.    SIG_SETMASK : constant := ICCS.SIG_SETMASK;
  154.    --  sigprocmask flags (how)
  155.  
  156.    type jmp_buf is array (1 .. ICCS.jmp_buf_size) of unsigned_char;
  157.    for jmp_buf'Alignment use Alignment;
  158.  
  159.    type sigjmp_buf is array (1 .. ICCS.sigjmp_buf_size) of unsigned_char;
  160.    for sigjmp_buf'Alignment use Alignment;
  161.  
  162.    type jmp_buf_ptr is access jmp_buf;
  163.  
  164.    type sigjmp_buf_ptr is access sigjmp_buf;
  165.    --  Environment for long jumps
  166.  
  167.    procedure sigaction
  168.      (sig    : Signal;
  169.       act    : access struct_sigaction;
  170.       oact   : access struct_sigaction;
  171.       Result : out Return_Code);
  172.    pragma Inline (sigaction);
  173.    --  install new sigaction structure and obtain old one
  174.  
  175.    procedure sigaction
  176.      (sig    : Signal;
  177.       oact   : access struct_sigaction;
  178.       Result : out Return_Code);
  179.    pragma Inline (sigaction);
  180.    --  Same thing as above, but without the act parameter. By passing null
  181.    --  pointer we can find out the action associated with it.
  182.    --  WE WANT TO MAKE THIS VERSION TO INCLUDE THE PREVIOUS sigaction.
  183.    --  TO BE FIXED LATER ???
  184.  
  185.    procedure sigprocmask
  186.      (how    : int;
  187.       set    : access Signal_Set;
  188.       oset   : access Signal_Set;
  189.       Result : out Return_Code);
  190.    pragma Inline (sigprocmask);
  191.    --  Install new signal mask and obtain old one
  192.  
  193.    procedure sigsuspend
  194.      (mask   : access Signal_Set;
  195.       Result : out Return_Code);
  196.    pragma Inline (sigsuspend);
  197.    --  Suspend waiting for signals in mask and resume after
  198.    --  executing handler or take default action
  199.  
  200.    procedure sigpending
  201.      (set    : access Signal_Set;
  202.       Result : out Return_Code);
  203.    pragma Inline (sigpending);
  204.    --  get pending signals on thread and process
  205.  
  206.    procedure longjmp (env : jmp_buf; val : int);
  207.    pragma Inline (longjmp);
  208.    --  execute a jump across procedures according to setjmp
  209.  
  210.    procedure siglongjmp (env : sigjmp_buf; val : int);
  211.    pragma Inline (siglongjmp);
  212.    --  execute a jump across procedures according to sigsetjmp
  213.  
  214.    procedure setjmp (env : jmp_buf; Result : out Return_Code);
  215.    pragma Inline (setjmp);
  216.    --  set up a jump across procedures and return here with longjmp
  217.  
  218.    procedure sigsetjmp
  219.      (env      : sigjmp_buf;
  220.       savemask : int;
  221.       Result   : out Return_Code);
  222.    pragma Inline (sigsetjmp);
  223.    --  Set up a jump across procedures and return here with siglongjmp
  224.  
  225.    SIGKILL                    : constant Signal := ICCS.SIGKILL;
  226.    SIGSTOP                    : constant Signal := ICCS.SIGSTOP;
  227.    --  Signals which cannot be masked
  228.  
  229.    --  Some synchronous signals (cannot be used for interrupt entries)
  230.  
  231.    SIGALRM                    : constant Signal := ICCS.SIGALRM;
  232.  
  233.    SIGILL                     : constant Signal := ICCS.SIGILL;
  234.    SIGFPE                     : constant Signal := ICCS.SIGFPE;
  235.    SIGSEGV                    : constant Signal := ICCS.SIGSEGV;
  236.  
  237.    SIGABRT                    : constant Signal := ICCS.SIGABRT;
  238.  
  239.    --  Signals which can be used for Interrupt Entries.
  240.  
  241.    SIGHUP                     : constant Signal := ICCS.SIGHUP;
  242.    SIGINT                     : constant Signal := ICCS.SIGINT;
  243.    SIGQUIT                    : constant Signal := ICCS.SIGQUIT;
  244.    SIGPIPE                    : constant Signal := ICCS.SIGPIPE;
  245.    SIGTERM                    : constant Signal := ICCS.SIGTERM;
  246.    SIGUSR1                    : constant Signal := ICCS.SIGUSR1;
  247.    SIGUSR2                    : constant Signal := ICCS.SIGUSR2;
  248.    SIGCHLD                    : constant Signal := ICCS.SIGCHLD;
  249.    SIGCONT                    : constant Signal := ICCS.SIGCONT;
  250.    SIGTSTP                    : constant Signal := ICCS.SIGTSTP;
  251.    SIGTTIN                    : constant Signal := ICCS.SIGTTIN;
  252.    SIGTTOU                    : constant Signal := ICCS.SIGTTOU;
  253.  
  254.    --  OS specific signals
  255.  
  256.    type Signal_Array is array (positive range <>) of Signal;
  257.  
  258.    OS_Specific_Sync_Signals :
  259.       Signal_Array (ICCS.OS_Specific_Sync_Sigs'Range);
  260.  
  261.    OS_Specific_Async_Signals :
  262.       Signal_Array (ICCS.OS_Specific_Async_Sigs'Range);
  263.  
  264. private
  265.  
  266.    type Signal_Set is array
  267.       (1 .. ICCS.sigset_t_size) of unsigned_char;
  268.    for Signal_Set'Alignment use Alignment;
  269.  
  270.    --  Lay out the POSIX-defined components of the struct_sigaction record to
  271.    --  match their C definition, using information in the i-csycon.ads file.
  272.    --  ??? This depends on constants describing the record computed
  273.    --      by a program that must be run on the target architecture,
  274.    --      and cannot handle records containing bit fields.
  275.    --      This should be done by redefining the entire C structure as
  276.    --      an Ada record and then naming it in a Convention C pragma.  This
  277.    --      will have to be derived from the source code of the
  278.    --      C header file, either automatically or manually.
  279.  
  280.    for struct_sigaction use record
  281.       sa_handler at ICCS.sa_handler_offset / System.Storage_Unit
  282.         range 0 .. Standard'Address_Size - 1;
  283.       sa_mask at ICCS.sa_mask_offset / System.Storage_Unit
  284.         range 0 .. ICCS.sigset_t_size * unsigned_char'Size - 1;
  285.  
  286.       --  range 0 .. Signal_Set'Size - 1;
  287.       --  The compiler things that Signal_Set'Size is not static,
  288.       --  and will therefore not accept this, though I don't see why???
  289.  
  290.       sa_flags at ICCS.sa_flags_offset / System.Storage_Unit
  291.         range 0 .. int'Size - 1;
  292.    end record;
  293.  
  294.    for struct_sigaction'Size use ICCS.sigaction_size * unsigned_char'Size;
  295.    for struct_sigaction'Alignment use Alignment;
  296.  
  297. end Interfaces.C.POSIX_RTE;
  298.