home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / h / signal < prev    next >
Encoding:
Text File  |  2006-09-17  |  7.2 KB  |  264 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/signal.h,v $
  4.  * $Date: 2005/04/19 08:50:36 $
  5.  * $Revision: 1.13 $
  6.  * $State: Exp $
  7.  * $Author: nick $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* ANSI, POSIX and BSD signal handling.  */
  12.  
  13. #ifndef __SIGNAL_H
  14. #define __SIGNAL_H
  15.  
  16. #ifndef __UNIXLIB_FEATURES_H
  17. #include <features.h>
  18. #endif
  19.  
  20. #ifndef __UNIXLIB_TYPES_H
  21. #include <unixlib/types.h>
  22. #endif
  23. #ifndef __STDDEF_H
  24. #include <stddef.h>
  25. #endif
  26.  
  27. #define __need_pthread_t
  28. #include <pthread.h>
  29.  
  30. __BEGIN_DECLS
  31.  
  32. #include <bits/signum.h>
  33.  
  34. /* Type of a signal handler.  */
  35. typedef void (*__sighandler_t)(int);
  36. #ifdef __USE_GNU
  37. typedef __sighandler_t sighandler_t;
  38. #endif
  39.  
  40. extern int sys_nsig;        /* = NSIG */
  41. extern const char * const sys_siglist[NSIG];    /* signal messages */
  42.  
  43.  
  44. extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
  45.  
  46. /* Send signal 'sig' to process number 'pid'.  If pid is zero,
  47.    send sig to all processes in the current process's process group.
  48.    If pid is < -1, send sig to all processes in process group -pid.  */
  49. extern int kill (__pid_t __pid, int __sig) __THROW;
  50.  
  51. /* Send signal 'sig' to all processes in process group 'pgrp'.
  52.    If pgrp is zero, send sig to all processes in the current
  53.    process's process group.  */
  54. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  55.  
  56. /* Raise signal sig.  */
  57. extern int raise (int __sig) __THROW;
  58.  
  59. /* Print a message describing the meaning of the given signal number.  */
  60. extern void psignal (int __sig, const char *__s) __THROW;
  61.  
  62.  
  63. /* BSD signal functions.  */
  64.  
  65. /* Block signals in mask, returning the old mask.  */
  66. extern int sigblock (int __mask) __THROW;
  67.  
  68. /* Set the mask of blocked signals to mask, return the old mask.  */
  69. extern int sigsetmask (int __mask) __THROW;
  70.  
  71. /* Set the mask of blocked signals to mask, wait for a signal
  72.    to arrive, and then restore the mask.
  73.  
  74.    This function is a cancellation point.  */
  75. extern int sigpause (int __mask);
  76.  
  77. #define sig_atomic_t __sig_atomic_t
  78.  
  79. /* POSIX signal functions.  */
  80.  
  81. /* Don't rely on sigset_t remaining an unsigned long. It's usage
  82.    could soon change into the structure form below. Use the
  83.    signal functions below to manipulate its value.  */
  84.  
  85. #define sigset_t __sigset_t
  86.  
  87. #if 0
  88. typedef struct __usigset
  89. {
  90.   unsigned int sig[NSIG] : 1;
  91. } __sigset_t;
  92. #endif
  93.  
  94. /* Structure describing the action to be taken when a signal arrives.  */
  95. struct sigaction
  96.   {
  97.     /* Signal handler.  */
  98.     __sighandler_t sa_handler;
  99.     /* Additional set of signals to be blocked.  */
  100.     __sigset_t sa_mask;
  101.     /* Special flags.  */
  102.     int sa_flags;
  103.   };
  104.  
  105. /* Bits in sa_flags.  */
  106.  
  107. /* Take signal on signal stack.  */
  108. #define    SA_ONSTACK    0x1
  109. /* Don't restart syscall on signal return.  */
  110. #define    SA_RESTART    0x2
  111. /* Disable alternate signal stack.  */
  112. #define    SA_DISABLE    0x4
  113. /* Don't send SIGCHLD when children stop.  */
  114. #define    SA_NOCLDSTOP    0x8
  115.  
  116.  
  117. /* Values for the HOW argument to `sigprocmask'.  */
  118.  
  119. /* Block signals.  */
  120. #define    SIG_BLOCK    1
  121. /* Unblock signals.  */
  122. #define    SIG_UNBLOCK    2
  123. /* Set the set of blocked signals.  */
  124. #define    SIG_SETMASK    3
  125.  
  126. /* Currently in an optimised state but this could soon change.  */
  127.  
  128. /* Clear all signals from set.  */
  129. extern int sigemptyset (__sigset_t *__set) __THROW __nonnull ((1));
  130. #define sigemptyset(set) ((*(set) = (__sigset_t) 0), 0)
  131.  
  132. /* Set all signals in set.  */
  133. extern int sigfillset (__sigset_t *__set) __THROW __nonnull ((1));
  134. #define sigfillset(set) ((*(set) = ~(__sigset_t) 0), 0)
  135.  
  136. extern __sigset_t sigmask (int __sig) __THROW;
  137. #define sigmask(sig) (((__sigset_t) 1) << ((sig) - 1))
  138.  
  139.  
  140. /* Add signo to set.  */
  141. extern int sigaddset (__sigset_t *__set, int __signo) __THROW __nonnull ((1));
  142.  
  143. /* Remove signo from set.  */
  144. extern int sigdelset (__sigset_t *__set, int __signo) __THROW __nonnull ((1));
  145.  
  146. /* Remove 1 if signo is in set, 0 if not.  */
  147. extern int sigismember (const __sigset_t *__set, int __signo)
  148.      __THROW __nonnull ((1));
  149.  
  150. #ifdef __UNIXLIB_INTERNALS
  151. /* Inline versions for UnixLib library only. These are subject to change.  */
  152.  
  153. /* Add signo to set.  */
  154. #define sigaddset(set,signo) ((*(set) |= sigmask (signo)), 0)
  155.  
  156. /* Remove signo from set.  */
  157. #define sigdelset(set,signo) ((*(set) &= ~sigmask (signo)), 0)
  158.  
  159. /* Remove 1 if signo is in set, 0 if not.  */
  160. #define sigismember(set,signo) ((*(set) & sigmask (signo)) ? 1 : 0)
  161.  
  162. #endif  /* __UNIXLIB_INTERNALS */
  163.  
  164. /* Get and/or change the set of blocked signals.  */
  165. extern int sigprocmask (int __how, const __sigset_t *__restrict __set,
  166.             __sigset_t *__oldset) __THROW;
  167.  
  168. /* Change the set of blocked signals,
  169.    wait until a signal arrives, and restore the set of blocked signals.
  170.    This function is a cancellation point.  */
  171. extern int sigsuspend (const __sigset_t *__set);
  172.  
  173. /* Get and/or set the action for signal sig.  */
  174. extern int sigaction (int __sig, const struct sigaction *__restrict __act,
  175.               struct sigaction *__oldact) __THROW;
  176.  
  177. /* Put in set all signals that are blocked and waiting to be delivered.  */
  178. extern int sigpending (__sigset_t *__set) __THROW;
  179.  
  180. /* BSD signal handling functionality.  */
  181. #if 0
  182. struct sigvec
  183. {
  184.   /* Signal handler.  */
  185.   sighandler_t sv_handler;
  186.   /* Mask of signals to be blocked.  */
  187.   int sv_mask;
  188.   /* Flags.  */
  189.   int sv_flags;
  190. /* 4.2 BSD compatibility.  */
  191. #define sv_onstack sv_flags
  192. };
  193.  
  194. /* Bits in sv_flags.  */
  195.  
  196. /* Take the signal on the signal stack. */
  197. #define SV_ONSTACK 1
  198. /* Do not restart system calls.  */
  199. #define SV_INTERRUPT 2
  200. /* Reset handler to SIG_DFL on receipt.  */
  201. #define SV_RESETHAND 4
  202.  
  203. extern int sigvec (int __sig, const struct sigvec *__vec,
  204.            struct sigvec *__ovec) __THROW;
  205. #endif
  206.  
  207. /* If interrupt is nonzero, make signal sig interrupt system calls
  208.    (causing them to fail with EINTR); if interrupt is zero, make
  209.    system calls be restarted after signal sig.  */
  210. extern int siginterrupt (int __sig, int __interrupt) __THROW;
  211.  
  212. /* Signal stack structure (BSD style).  */
  213. struct sigstack
  214.   {
  215.     /* Signal stack pointer.  */
  216.     void *ss_sp;
  217.     /* Non zero if executing on this stack.  */
  218.     int ss_onstack;
  219.   };
  220.  
  221. /* Run signal handlers on the stack specified by 'ss' (if not NULL).
  222.    The old status is returned in oss (if not NULL).  */
  223. extern int sigstack (const struct sigstack *__ss,
  224.              struct sigstack *__oss) __THROW;
  225.  
  226. /* Signal stack structure (POSIX alternative interface).  */
  227. struct sigaltstack
  228.   {
  229.     /* Pointer to stack base.  */
  230.     void *ss_sp;
  231.     /* Size of stack.  */
  232.     size_t ss_size;
  233.     /* sigaltstack flags.  */
  234.     int ss_flags;
  235.   };
  236.  
  237. extern int sigaltstack (const struct sigaltstack *__ss,
  238.             struct sigaltstack *__oss) __THROW;
  239.  
  240. /* Signal stack constants.  */
  241.  
  242. /* The recommended signal stack size for a signal handler.  */
  243. #define SIGSTKSZ 4096
  244.  
  245. /* The absolute safe minimum signal stack size
  246.    for running signal handlers in.  */
  247.  
  248. #define MINSIGSTKSZ 2048
  249.  
  250. /* Send a signal to a specific thread */
  251. extern int pthread_kill (pthread_t thread, int sig) __THROW;
  252.  
  253. /* Set the signal mask for a thread */
  254. extern int pthread_sigmask (int how, const sigset_t *set,
  255.                 sigset_t *oset) __THROW;
  256.  
  257. /* Suspend thread until delivery of a signal.
  258.    This function is a cancellation point.  */
  259. extern int sigwait (const sigset_t *__restrict set, int *sig);
  260.  
  261. __END_DECLS
  262.  
  263. #endif
  264.