OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [psignal.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.