Back to index

glibc  2.9
Classes | Defines | Functions | Variables
sigpreempt.h File Reference
#include <errno.h>
#include <signal.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hurd_signal_preemptor

Defines

#define HURD_PREEMPT_SIGNAL_P(preemptor, signo, sigcode)

Functions

void hurd_preempt_signals (struct hurd_signal_preemptor *preemptor)
void hurd_unpreempt_signals (struct hurd_signal_preemptor *preemptor)
error_t hurd_catch_signal (sigset_t sigset, unsigned long int first, unsigned long int last, error_t(*operate)(struct hurd_signal_preemptor *), sighandler_t handler)
error_t hurd_safe_memset (void *dest, int byte, size_t nbytes)
error_t hurd_safe_copyin (void *dest, const void *src, size_t nbytes)
error_t hurd_safe_copyout (void *dest, const void *src, size_t nbytes)
error_t hurd_safe_memmove (void *dest, const void *src, size_t nbytes)

Variables

struct hurd_signal_preemptor_hurdsig_preemptors
sigset_t _hurdsig_preempted_set

Define Documentation

#define HURD_PREEMPT_SIGNAL_P (   preemptor,
  signo,
  sigcode 
)
Value:
(((preemptor)->signals & sigmask (signo)) && \
   (sigcode) >= (preemptor)->first && (sigcode) <= (preemptor)->last)

Definition at line 50 of file sigpreempt.h.


Function Documentation

error_t hurd_catch_signal ( sigset_t  sigset,
unsigned long int  first,
unsigned long int  last,
error_t(*)(struct hurd_signal_preemptor *)  operate,
sighandler_t  handler 
)

Definition at line 26 of file catch-signal.c.

{
  jmp_buf buf;
  void throw (int signo, long int sigcode, struct sigcontext *scp)
    { longjmp (buf, scp->sc_error ?: EGRATUITOUS); }

  struct hurd_signal_preemptor preemptor =
    {
      sigset, first, last,
      NULL, handler == SIG_ERR ? (sighandler_t) &throw : handler,
    };

  struct hurd_sigstate *const ss = _hurd_self_sigstate ();
  error_t error;

  if (handler == SIG_ERR)
    /* Not our handler; don't bother saving state.  */
    error = 0;
  else
    /* This returns again with nonzero value when we preempt a signal.  */
    error = setjmp (buf);

  if (error == 0)
    {
      /* Install a signal preemptor for the thread.  */
      __spin_lock (&ss->lock);
      preemptor.next = ss->preemptors;
      ss->preemptors = &preemptor;
      __spin_unlock (&ss->lock);

      /* Try the operation that might crash.  */
      (*operate) (&preemptor);
    }

  /* Either FUNCTION completed happily and ERROR is still zero, or it hit
     an expected signal and `throw' made setjmp return the signal error
     code in ERROR.  Now we can remove the preemptor and return.  */

  __spin_lock (&ss->lock);
  assert (ss->preemptors == &preemptor);
  ss->preemptors = preemptor.next;
  __spin_unlock (&ss->lock);

  return error;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hurd_preempt_signals ( struct hurd_signal_preemptor preemptor)

Definition at line 24 of file preempt-sig.c.

{
  __mutex_lock (&_hurd_siglock);
  preemptor->next = _hurdsig_preemptors;
  _hurdsig_preemptors = preemptor;
  _hurdsig_preempted_set |= preemptor->signals;
  __mutex_unlock (&_hurd_siglock);
}

Here is the call graph for this function:

error_t hurd_safe_copyin ( void *  dest,
const void *  src,
size_t  nbytes 
)

Definition at line 104 of file catch-signal.c.

{
  error_t operate (struct hurd_signal_preemptor *preemptor)
    {
      memcpy (dest, src, nbytes);
      return 0;
    }
  return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
                         (vm_address_t) src, (vm_address_t) src + nbytes,
                         &operate, SIG_ERR);
}

Here is the call graph for this function:

error_t hurd_safe_copyout ( void *  dest,
const void *  src,
size_t  nbytes 
)

Definition at line 91 of file catch-signal.c.

{
  error_t operate (struct hurd_signal_preemptor *preemptor)
    {
      memcpy (dest, src, nbytes);
      return 0;
    }
  return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
                         (vm_address_t) dest, (vm_address_t) dest + nbytes,
                         &operate, SIG_ERR);
}

Here is the call graph for this function:

error_t hurd_safe_memmove ( void *  dest,
const void *  src,
size_t  nbytes 
)

Definition at line 117 of file catch-signal.c.

{
  jmp_buf buf;
  void throw (int signo, long int sigcode, struct sigcontext *scp)
    { longjmp (buf, scp->sc_error ?: EGRATUITOUS); }

  struct hurd_signal_preemptor src_preemptor =
    {
      sigmask (SIGBUS) | sigmask (SIGSEGV),
      (vm_address_t) src, (vm_address_t) src + nbytes,
      NULL, (sighandler_t) &throw,
    };
  struct hurd_signal_preemptor dest_preemptor =
    {
      sigmask (SIGBUS) | sigmask (SIGSEGV),
      (vm_address_t) dest, (vm_address_t) dest + nbytes,
      NULL, (sighandler_t) &throw,
      &src_preemptor
    };

  struct hurd_sigstate *const ss = _hurd_self_sigstate ();
  error_t error;

  /* This returns again with nonzero value when we preempt a signal.  */
  error = setjmp (buf);

  if (error == 0)
    {
      /* Install a signal preemptor for the thread.  */
      __spin_lock (&ss->lock);
      src_preemptor.next = ss->preemptors;
      ss->preemptors = &dest_preemptor;
      __spin_unlock (&ss->lock);

      /* Do the copy; it might fault.  */
      memmove (dest, src, nbytes);
    }

  /* Either memmove completed happily and ERROR is still zero, or it hit
     an expected signal and `throw' made setjmp return the signal error
     code in ERROR.  Now we can remove the preemptor and return.  */

  __spin_lock (&ss->lock);
  assert (ss->preemptors == &dest_preemptor);
  ss->preemptors = src_preemptor.next;
  __spin_unlock (&ss->lock);

  return error;
}

Here is the call graph for this function:

error_t hurd_safe_memset ( void *  dest,
int  byte,
size_t  nbytes 
)

Definition at line 77 of file catch-signal.c.

{
  error_t operate (struct hurd_signal_preemptor *preemptor)
    {
      memset (dest, byte, nbytes);
      return 0;
    }
  return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
                         (vm_address_t) dest, (vm_address_t) dest + nbytes,
                         &operate, SIG_ERR);
}

Here is the call graph for this function:

void hurd_unpreempt_signals ( struct hurd_signal_preemptor preemptor)

Definition at line 34 of file preempt-sig.c.

{
  struct hurd_signal_preemptor **p;
  sigset_t preempted = 0;

  __mutex_lock (&_hurd_siglock);

  p = &_hurdsig_preemptors;
  while (*p)
    if (*p == preemptor)
      {
       /* Found it; take it off the chain.  */
       *p = (*p)->next;
       if ((preemptor->signals & preempted) != preemptor->signals)
         {
           /* This might have been the only preemptor for some
              of those signals, so we must collect the full mask
              from the others.  */
           struct hurd_signal_preemptor *pp;
           for (pp = *p; pp; pp = pp->next)
             preempted |= pp->signals;
           _hurdsig_preempted_set = preempted;
         }
       __mutex_unlock (&_hurd_siglock);
       return;
      }
    else
      {
       preempted |= (*p)->signals;
       p = &(*p)->next;
      }

  __mutex_unlock (&_hurd_siglock); /* Avoid deadlock during death rattle.  */
  assert (! "removing absent preemptor");
}

Here is the call graph for this function:


Variable Documentation

Definition at line 447 of file hurdsig.c.

Definition at line 446 of file hurdsig.c.