source: rtems/cpukit/posix/src/psignalchecksignal.c @ 173d1f8

5
Last change on this file since 173d1f8 was 173d1f8, checked in by Sebastian Huber <sebastian.huber@…>, on 12/14/15 at 12:10:24

posix: Store unblocked signals

Store the unblock signals to exploit the zero-initialization of the
thread control block.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief POSIX Signals Check Signal
5 *  @ingroup POSIX_SIGNALS
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#if defined(RTEMS_DEBUG)
22  #include <assert.h>
23#endif
24#include <errno.h>
25#include <pthread.h>
26#include <signal.h>
27#include <string.h>
28
29#include <rtems/system.h>
30#include <rtems/score/isr.h>
31#include <rtems/score/thread.h>
32#include <rtems/score/wkspace.h>
33#include <rtems/seterr.h>
34#include <rtems/posix/threadsup.h>
35#include <rtems/posix/psignalimpl.h>
36#include <rtems/posix/pthreadimpl.h>
37#include <stdio.h>
38
39bool    _POSIX_signals_Check_signal(
40  POSIX_API_Control  *api,
41  int                 signo,
42  bool                is_global
43)
44{
45  siginfo_t                   siginfo_struct;
46  sigset_t                    saved_signals_unblocked;
47  Thread_Wait_information     stored_thread_wait_information;
48  Thread_Control             *executing;
49
50  if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct,
51                                       is_global, true, true ) )
52    return false;
53
54  /*
55   *  Since we made a union of these, only one test is necessary but this is
56   *  safer.
57   */
58  #if defined(RTEMS_DEBUG)
59    assert( _POSIX_signals_Vectors[ signo ].sa_handler ||
60            _POSIX_signals_Vectors[ signo ].sa_sigaction );
61  #endif
62
63  /*
64   *  Just to prevent sending a signal which is currently being ignored.
65   */
66  if ( _POSIX_signals_Vectors[ signo ].sa_handler == SIG_IGN )
67    return false;
68
69  /*
70   *  Block the signals requested in sa_mask
71   */
72  saved_signals_unblocked = api->signals_unblocked;
73  api->signals_unblocked &= ~_POSIX_signals_Vectors[ signo ].sa_mask;
74
75  executing = _Thread_Get_executing();
76
77  /*
78   *  We have to save the blocking information of the current wait queue
79   *  because the signal handler may subsequently go on and put the thread
80   *  on a wait queue, for its own purposes.
81   */
82  memcpy( &stored_thread_wait_information, &executing->Wait,
83          sizeof( stored_thread_wait_information ));
84
85  /*
86   *  Here, the signal handler function executes
87   */
88  switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) {
89    case SA_SIGINFO:
90      (*_POSIX_signals_Vectors[ signo ].sa_sigaction)(
91        signo,
92        &siginfo_struct,
93        NULL        /* context is undefined per 1003.1b-1993, p. 66 */
94      );
95      break;
96    default:
97      (*_POSIX_signals_Vectors[ signo ].sa_handler)( signo );
98      break;
99  }
100
101  /*
102   *  Restore the blocking information
103   */
104  memcpy( &executing->Wait, &stored_thread_wait_information,
105          sizeof( executing->Wait ));
106
107  /*
108   *  Restore the previous set of unblocked signals
109   */
110  api->signals_unblocked = saved_signals_unblocked;
111
112  return true;
113}
Note: See TracBrowser for help on using the repository browser.