source: rtems/cpukit/posix/src/psignal.c @ 7d9ec2d

4.104.114.84.9
Last change on this file since 7d9ec2d was 7d9ec2d, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 6, 2002 at 8:10:04 PM

2002-02-05 Ralf Corsepius <corsepiu@…>

  • configure.ac: AC_CONFIG_SRCDIR([src/pthreads.c])
  • src/psignal.c: #include <string.h>.
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  $Id$
3 */
4
5#if HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <assert.h>
10#include <errno.h>
11#include <pthread.h>
12#include <signal.h>
13#include <string.h>     /* memcpy */
14
15#include <rtems/system.h>
16#include <rtems/score/isr.h>
17#include <rtems/score/thread.h>
18#include <rtems/score/tqdata.h>
19#include <rtems/score/wkspace.h>
20#include <rtems/seterr.h>
21#include <rtems/posix/threadsup.h>
22#include <rtems/posix/psignal.h>
23#include <rtems/posix/pthread.h>
24#include <rtems/posix/time.h>
25#include <stdio.h>
26
27
28/*
29 *  Currently 32 signals numbered 1-32 are defined
30 */
31
32#define SIGNAL_EMPTY_MASK  0x00000000
33#define SIGNAL_ALL_MASK    0xffffffff
34
35#define signo_to_mask( _sig ) (1 << ((_sig) - 1))
36
37#define is_valid_signo( _sig ) \
38  ((_sig) >= 1 && (_sig) <= 32 )
39
40/*** PROCESS WIDE STUFF ****/
41
42sigset_t  _POSIX_signals_Pending;
43
44void _POSIX_signals_Abnormal_termination_handler( int signo )
45{
46  exit( 1 );
47}
48
49#define SIG_ARRAY_MAX  (SIGRTMAX + 1)
50struct sigaction _POSIX_signals_Default_vectors[ SIG_ARRAY_MAX ] = {
51  /* NO SIGNAL 0 */  SIGACTION_IGNORE,
52  /* SIGHUP    1 */  SIGACTION_TERMINATE,
53  /* SIGINT    2 */  SIGACTION_TERMINATE,
54  /* SIGQUIT   3 */  SIGACTION_TERMINATE,
55  /* SIGILL    4 */  SIGACTION_TERMINATE,
56  /* SIGTRAP   5 */  SIGACTION_TERMINATE,
57  /* SIGIOT    6 */  SIGACTION_TERMINATE,
58  /* SIGABRT   6     SIGACTION_TERMINATE, -- alias for SIGIOT */
59  /* SIGEMT    7 */  SIGACTION_TERMINATE,
60  /* SIGFPE    8 */  SIGACTION_TERMINATE,
61  /* SIGKILL   9 */  SIGACTION_TERMINATE,
62  /* SIGBUS   10 */  SIGACTION_TERMINATE,
63  /* SIGSEGV  11 */  SIGACTION_TERMINATE,
64  /* SIGSYS   12 */  SIGACTION_TERMINATE,
65  /* SIGPIPE  13 */  SIGACTION_TERMINATE,
66  /* SIGALRM  14 */  SIGACTION_TERMINATE,
67  /* SIGTERM  15 */  SIGACTION_TERMINATE,
68  /* SIGUSR1  16 */  SIGACTION_TERMINATE,
69  /* SIGUSR2  17 */  SIGACTION_TERMINATE,
70  /* SIGRTMIN 18 */  SIGACTION_TERMINATE,
71  /* SIGRT    19 */  SIGACTION_TERMINATE,
72  /* SIGRT    20 */  SIGACTION_TERMINATE,
73  /* SIGRT    21 */  SIGACTION_TERMINATE,
74  /* SIGRT    22 */  SIGACTION_TERMINATE,
75  /* SIGRT    23 */  SIGACTION_TERMINATE,
76  /* SIGRT    24 */  SIGACTION_TERMINATE,
77  /* SIGRT    25 */  SIGACTION_TERMINATE,
78  /* SIGRT    26 */  SIGACTION_TERMINATE,
79  /* SIGRT    27 */  SIGACTION_TERMINATE,
80  /* SIGRT    28 */  SIGACTION_TERMINATE,
81  /* SIGRT    29 */  SIGACTION_TERMINATE,
82  /* SIGRT    30 */  SIGACTION_TERMINATE,
83  /* SIGRT    31 */  SIGACTION_TERMINATE,
84  /* SIGRTMAX 32 */  SIGACTION_TERMINATE
85};
86
87struct sigaction _POSIX_signals_Vectors[ SIG_ARRAY_MAX ];
88
89Watchdog_Control _POSIX_signals_Alarm_timer;
90
91Thread_queue_Control _POSIX_signals_Wait_queue;
92
93Chain_Control _POSIX_signals_Inactive_siginfo;
94Chain_Control _POSIX_signals_Siginfo[ SIG_ARRAY_MAX ];
95
96/*PAGE
97 *
98 *  XXX - move these
99 */
100
101#define _States_Is_interruptible_signal( _states ) \
102  ( ((_states) & \
103    (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL)) == \
104      (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
105
106/*
107 *  _POSIX_signals_Post_switch_extension
108 */
109
110void _POSIX_signals_Post_switch_extension(
111  Thread_Control  *the_thread
112)
113{
114  POSIX_API_Control  *api;
115  int                 signo;
116  ISR_Level           level;
117
118  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
119
120  /*
121   *  If we invoke any user code, there is the possibility that
122   *  a new signal has been posted that we should process so we
123   *  restart the loop if a signal handler was invoked.
124   *
125   *  The first thing done is to check there are any signals to be
126   *  processed at all.  No point in doing this loop otherwise.
127   */
128
129restart:
130  _ISR_Disable( level );
131    if ( !(~api->signals_blocked & 
132          (api->signals_pending | _POSIX_signals_Pending)) ) {
133     _ISR_Enable( level );
134     return;
135   }
136  _ISR_Enable( level );
137
138  for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
139
140    if ( _POSIX_signals_Check_signal( api, signo, FALSE ) )
141      goto restart;
142
143    if ( _POSIX_signals_Check_signal( api, signo, TRUE ) )
144      goto restart;
145
146  }
147
148/* XXX - add __SIGFIRSTNOTRT or something like that to newlib signal .h */
149
150  for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
151
152    if ( _POSIX_signals_Check_signal( api, signo, FALSE ) )
153      goto restart;
154 
155    if ( _POSIX_signals_Check_signal( api, signo, TRUE ) )
156      goto restart;
157
158  }
159
160}
161
162/*PAGE
163 *
164 *  _POSIX_signals_Alarm_TSR
165 */
166 
167void _POSIX_signals_Alarm_TSR(
168  Objects_Id      id,
169  void           *argument
170)
171{
172  int status;
173
174  status = kill( getpid(), SIGALRM );
175  /* XXX can't print from an ISR, should this be fatal? */
176  assert( !status );
177}
178
179/*PAGE
180 *
181 *  _POSIX_signals_Manager_Initialization
182 */
183
184void _POSIX_signals_Manager_Initialization(
185  int  maximum_queued_signals
186)
187{
188  unsigned32 signo;
189
190  /*
191   *  Insure we have the same number of vectors and default vector entries
192   */
193
194  assert(
195   sizeof(_POSIX_signals_Vectors) == sizeof(_POSIX_signals_Default_vectors)
196  );
197
198  memcpy( 
199    _POSIX_signals_Vectors,
200    _POSIX_signals_Default_vectors,
201    sizeof( _POSIX_signals_Vectors )
202  );
203 
204  /*
205   *  Initialize the set of pending signals for the entire process
206   */
207
208  sigemptyset( &_POSIX_signals_Pending );
209
210  /*
211   *  Initialize the timer used to implement alarm().
212   */
213
214  _Watchdog_Initialize(
215    &_POSIX_signals_Alarm_timer,
216    _POSIX_signals_Alarm_TSR,
217    0,
218    NULL
219  );
220 
221  /*
222   *  Initialize the queue we use to block for signals
223   */
224 
225  _Thread_queue_Initialize(
226    &_POSIX_signals_Wait_queue,
227    OBJECTS_NO_CLASS,
228    THREAD_QUEUE_DISCIPLINE_PRIORITY,
229    STATES_WAITING_FOR_SIGNAL | STATES_INTERRUPTIBLE_BY_SIGNAL,
230    NULL,
231    EAGAIN
232  );
233
234  /* XXX status codes */
235
236  /*
237   *  Allocate the siginfo pools.
238   */
239
240  for ( signo=1 ; signo<= SIGRTMAX ; signo++ )
241    _Chain_Initialize_empty( &_POSIX_signals_Siginfo[ signo ] );
242
243  _Chain_Initialize(
244    &_POSIX_signals_Inactive_siginfo,
245    _Workspace_Allocate_or_fatal_error(
246      maximum_queued_signals * sizeof( POSIX_signals_Siginfo_node )
247    ),
248    maximum_queued_signals,
249    sizeof( POSIX_signals_Siginfo_node )
250  );
251}
Note: See TracBrowser for help on using the repository browser.