source: rtems/cpukit/posix/src/psignal.c @ 3c465878

4.104.114.84.95
Last change on this file since 3c465878 was 3c465878, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:33:47

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/rtems/posix/key.h, src/cond.c, src/condinit.c, src/intr.c, src/key.c, src/keycreate.c, src/keydelete.c, src/killinfo.c, src/mqueue.c, src/mqueuecreatesupp.c, src/mutex.c, src/mutexinit.c, src/psignal.c, src/pthread.c, src/semaphore.c, src/semaphorecreatesupp.c: Modified as part of above.
  • 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#include <stdlib.h>     /* exit */
15
16#include <rtems/system.h>
17#include <rtems/score/isr.h>
18#include <rtems/score/thread.h>
19#include <rtems/score/tqdata.h>
20#include <rtems/score/wkspace.h>
21#include <rtems/seterr.h>
22#include <rtems/posix/threadsup.h>
23#include <rtems/posix/psignal.h>
24#include <rtems/posix/pthread.h>
25#include <rtems/posix/time.h>
26#include <stdio.h>
27
28
29/*
30 *  Currently 32 signals numbered 1-32 are defined
31 */
32
33#define SIGNAL_EMPTY_MASK  0x00000000
34#define SIGNAL_ALL_MASK    0xffffffff
35
36#define signo_to_mask( _sig ) (1 << ((_sig) - 1))
37
38#define is_valid_signo( _sig ) \
39  ((_sig) >= 1 && (_sig) <= 32 )
40
41/*** PROCESS WIDE STUFF ****/
42
43sigset_t  _POSIX_signals_Pending;
44
45void _POSIX_signals_Abnormal_termination_handler( int signo )
46{
47  exit( 1 );
48}
49
50#define SIG_ARRAY_MAX  (SIGRTMAX + 1)
51struct sigaction _POSIX_signals_Default_vectors[ SIG_ARRAY_MAX ] = {
52  /* NO SIGNAL 0 */  SIGACTION_IGNORE,
53  /* SIGHUP    1 */  SIGACTION_TERMINATE,
54  /* SIGINT    2 */  SIGACTION_TERMINATE,
55  /* SIGQUIT   3 */  SIGACTION_TERMINATE,
56  /* SIGILL    4 */  SIGACTION_TERMINATE,
57  /* SIGTRAP   5 */  SIGACTION_TERMINATE,
58  /* SIGIOT    6 */  SIGACTION_TERMINATE,
59  /* SIGABRT   6     SIGACTION_TERMINATE, -- alias for SIGIOT */
60  /* SIGEMT    7 */  SIGACTION_TERMINATE,
61  /* SIGFPE    8 */  SIGACTION_TERMINATE,
62  /* SIGKILL   9 */  SIGACTION_TERMINATE,
63  /* SIGBUS   10 */  SIGACTION_TERMINATE,
64  /* SIGSEGV  11 */  SIGACTION_TERMINATE,
65  /* SIGSYS   12 */  SIGACTION_TERMINATE,
66  /* SIGPIPE  13 */  SIGACTION_TERMINATE,
67  /* SIGALRM  14 */  SIGACTION_TERMINATE,
68  /* SIGTERM  15 */  SIGACTION_TERMINATE,
69  /* SIGUSR1  16 */  SIGACTION_TERMINATE,
70  /* SIGUSR2  17 */  SIGACTION_TERMINATE,
71  /* SIGRTMIN 18 */  SIGACTION_TERMINATE,
72  /* SIGRT    19 */  SIGACTION_TERMINATE,
73  /* SIGRT    20 */  SIGACTION_TERMINATE,
74  /* SIGRT    21 */  SIGACTION_TERMINATE,
75  /* SIGRT    22 */  SIGACTION_TERMINATE,
76  /* SIGRT    23 */  SIGACTION_TERMINATE,
77  /* SIGRT    24 */  SIGACTION_TERMINATE,
78  /* SIGRT    25 */  SIGACTION_TERMINATE,
79  /* SIGRT    26 */  SIGACTION_TERMINATE,
80  /* SIGRT    27 */  SIGACTION_TERMINATE,
81  /* SIGRT    28 */  SIGACTION_TERMINATE,
82  /* SIGRT    29 */  SIGACTION_TERMINATE,
83  /* SIGRT    30 */  SIGACTION_TERMINATE,
84  /* SIGRT    31 */  SIGACTION_TERMINATE,
85  /* SIGRTMAX 32 */  SIGACTION_TERMINATE
86};
87
88struct sigaction _POSIX_signals_Vectors[ SIG_ARRAY_MAX ];
89
90Watchdog_Control _POSIX_signals_Alarm_timer;
91
92Thread_queue_Control _POSIX_signals_Wait_queue;
93
94Chain_Control _POSIX_signals_Inactive_siginfo;
95Chain_Control _POSIX_signals_Siginfo[ SIG_ARRAY_MAX ];
96
97/*PAGE
98 *
99 *  XXX - move these
100 */
101
102#define _States_Is_interruptible_signal( _states ) \
103  ( ((_states) & \
104    (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL)) == \
105      (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
106
107/*
108 *  _POSIX_signals_Post_switch_extension
109 */
110
111void _POSIX_signals_Post_switch_extension(
112  Thread_Control  *the_thread
113)
114{
115  POSIX_API_Control  *api;
116  int                 signo;
117  ISR_Level           level;
118
119  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
120
121  /*
122   *  If we invoke any user code, there is the possibility that
123   *  a new signal has been posted that we should process so we
124   *  restart the loop if a signal handler was invoked.
125   *
126   *  The first thing done is to check there are any signals to be
127   *  processed at all.  No point in doing this loop otherwise.
128   */
129
130restart:
131  _ISR_Disable( level );
132    if ( !(~api->signals_blocked &
133          (api->signals_pending | _POSIX_signals_Pending)) ) {
134     _ISR_Enable( level );
135     return;
136   }
137  _ISR_Enable( level );
138
139  for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
140
141    if ( _POSIX_signals_Check_signal( api, signo, FALSE ) )
142      goto restart;
143
144    if ( _POSIX_signals_Check_signal( api, signo, TRUE ) )
145      goto restart;
146
147  }
148
149/* XXX - add __SIGFIRSTNOTRT or something like that to newlib signal .h */
150
151  for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
152
153    if ( _POSIX_signals_Check_signal( api, signo, FALSE ) )
154      goto restart;
155 
156    if ( _POSIX_signals_Check_signal( api, signo, TRUE ) )
157      goto restart;
158
159  }
160
161}
162
163/*PAGE
164 *
165 *  _POSIX_signals_Alarm_TSR
166 */
167 
168void _POSIX_signals_Alarm_TSR(
169  Objects_Id      id,
170  void           *argument
171)
172{
173  int status;
174
175  status = kill( getpid(), SIGALRM );
176  /* XXX can't print from an ISR, should this be fatal? */
177  assert( !status );
178}
179
180/*PAGE
181 *
182 *  _POSIX_signals_Manager_Initialization
183 */
184
185void _POSIX_signals_Manager_Initialization(
186  int  maximum_queued_signals
187)
188{
189  unsigned32 signo;
190
191  /*
192   *  Insure we have the same number of vectors and default vector entries
193   */
194
195  assert(
196   sizeof(_POSIX_signals_Vectors) == sizeof(_POSIX_signals_Default_vectors)
197  );
198
199  memcpy(
200    _POSIX_signals_Vectors,
201    _POSIX_signals_Default_vectors,
202    sizeof( _POSIX_signals_Vectors )
203  );
204 
205  /*
206   *  Initialize the set of pending signals for the entire process
207   */
208
209  sigemptyset( &_POSIX_signals_Pending );
210
211  /*
212   *  Initialize the timer used to implement alarm().
213   */
214
215  _Watchdog_Initialize(
216    &_POSIX_signals_Alarm_timer,
217    _POSIX_signals_Alarm_TSR,
218    0,
219    NULL
220  );
221 
222  /*
223   *  Initialize the queue we use to block for signals
224   */
225 
226  _Thread_queue_Initialize(
227    &_POSIX_signals_Wait_queue,
228    THREAD_QUEUE_DISCIPLINE_PRIORITY,
229    STATES_WAITING_FOR_SIGNAL | STATES_INTERRUPTIBLE_BY_SIGNAL,
230    EAGAIN
231  );
232
233  /* XXX status codes */
234
235  /*
236   *  Allocate the siginfo pools.
237   */
238
239  for ( signo=1 ; signo<= SIGRTMAX ; signo++ )
240    _Chain_Initialize_empty( &_POSIX_signals_Siginfo[ signo ] );
241
242  _Chain_Initialize(
243    &_POSIX_signals_Inactive_siginfo,
244    _Workspace_Allocate_or_fatal_error(
245      maximum_queued_signals * sizeof( POSIX_signals_Siginfo_node )
246    ),
247    maximum_queued_signals,
248    sizeof( POSIX_signals_Siginfo_node )
249  );
250}
Note: See TracBrowser for help on using the repository browser.