Back to index

glibc  2.9
sigpreempt.h
Go to the documentation of this file.
00001 /* Preemption of Hurd signals before POSIX.1 semantics take over.
00002    Copyright (C) 1996 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _HURD_SIGPREEMPT_H
00021 
00022 #define       _HURD_SIGPREEMPT_H   1
00023 #include <errno.h>
00024 #include <signal.h>         /* For sigset_t, sighandler_t, SIG_ERR.  */
00025 struct hurd_sigstate;              /* <hurd/signal.h> */
00026 struct hurd_signal_detail;  /* <hurd/signal.h> */
00027 
00028 struct hurd_signal_preemptor
00029   {
00030     /* These members select which signals this structure will apply to.
00031        The rest of the structure is only consulted if these match.  */
00032     sigset_t signals;              /* Signals preempted.  */
00033     unsigned long int first, last; /* Range of sigcode values preempted.  */
00034 
00035     /* This function will be called (with SS->lock held) to decide what to
00036        do with the signal described.  It may modify the codes of the signal
00037        passed.  If the return value is SIG_ERR, the next matching preemptor
00038        is tried, or the normal handling is done for the signal (which may
00039        have been changed by the preemptor function).  Otherwise, the signal
00040        is processed as if the return value were its handler setting.  */
00041     sighandler_t (*preemptor) (struct hurd_signal_preemptor *preemptor,
00042                             struct hurd_sigstate *ss,
00043                             int *signo, struct hurd_signal_detail *detail);
00044     /* If PREEMPTOR is null, act as if it returned HANDLER.  */
00045     sighandler_t handler;
00046 
00047     struct hurd_signal_preemptor *next;   /* List structure.  */
00048   };
00049 
00050 #define HURD_PREEMPT_SIGNAL_P(preemptor, signo, sigcode) \
00051   (((preemptor)->signals & sigmask (signo)) && \
00052    (sigcode) >= (preemptor)->first && (sigcode) <= (preemptor)->last)
00053 
00054 
00055 /* Signal preemptors applying to all threads; locked by _hurd_siglock.  */
00056 extern struct hurd_signal_preemptor *_hurdsig_preemptors;
00057 extern sigset_t _hurdsig_preempted_set;
00058 
00059 
00060 /* The caller must initialize all members of *PREEMPTOR except `next'.
00061    The preemptor is registered on the global list.  */
00062 void hurd_preempt_signals (struct hurd_signal_preemptor *preemptor);
00063 
00064 /* Remove a preemptor registered with hurd_preempt_signals.  */
00065 void hurd_unpreempt_signals (struct hurd_signal_preemptor *preemptor);
00066 
00067 
00068 /* Call *OPERATE and return its value.  If a signal in SIGSET with a sigcode
00069    in the range [FIRST,LAST] arrives during the call, catch it.  If HANDLER
00070    is a function, it handles the signal in the normal way (i.e. it should
00071    longjmp unless it can restart the insn on return).  If it is SIG_ERR,
00072    hurd_catch_signal returns the sc_error value from the signal (or
00073    EGRATUITOUS if that is zero).
00074 
00075    The preemptor structure is passed to *OPERATE, which may modify its
00076    sigcode range or functions at any time during which it is guaranteed no
00077    signal in SIGSET will arrive.  */
00078 
00079 error_t hurd_catch_signal (sigset_t sigset,
00080                         unsigned long int first, unsigned long int last,
00081                         error_t (*operate) (struct hurd_signal_preemptor *),
00082                         sighandler_t handler);
00083 
00084 
00085 /* Convenience functions using `hurd_catch_signal'.  */
00086 
00087 
00088 /* Like `memset', but catch faults in DEST.  */
00089 error_t hurd_safe_memset (void *dest, int byte, size_t nbytes);
00090 
00091 /* Like `memcpy', but catch faults in SRC.  */
00092 error_t hurd_safe_copyin (void *dest, const void *src, size_t nbytes);
00093 
00094 /* Like `memcpy', but catch faults in DEST.  */
00095 error_t hurd_safe_copyout (void *dest, const void *src, size_t nbytes);
00096 
00097 /* Like `memmove', but catch faults in SRC or DEST.
00098    If only one region is expected to fault, it is more efficient
00099    to use `hurd_safe_copyin' or `hurd_safe_copyout' as appropriate.  */
00100 error_t hurd_safe_memmove (void *dest, const void *src, size_t nbytes);
00101 
00102 
00103 #endif /* hurd/sigpreempt.h */