Subversion Repositories shark

Rev

Rev 2 | Rev 80 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
23
 CVS :        $Id: signal.h,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1.1.1 $
27
 Last update: $Date: 2002-03-29 14:12:51 $
28
 ------------
29
 
30
 This file contains the Signal Handling stuffs...
31
 
32
 All the signals have a unique identifier through the system.
33
 
34
 The signals numbers are from 0 to 255. All the signals are queued as
35
 they are in Posix Realtime extension.
36
 
37
 All the modules, libraries, and task models can define a signal with
38
 a unique signal handler.
39
 
40
 It's better if the schedule levels don't define any signal, because
41
 in this case the application will depend to the level.
42
 The signal numbers have instead to be defined in the task modules...
43
 
44
 Index of this include file:
45
 
46
 - Signal codes
47
 - Signal handlers and data structures
48
 - Signal functions & primitives
49
 
50
**/
51
 
52
/*
53
 * Copyright (C) 2000 Paolo Gai
54
 *
55
 * This program is free software; you can redistribute it and/or modify
56
 * it under the terms of the GNU General Public License as published by
57
 * the Free Software Foundation; either version 2 of the License, or
58
 * (at your option) any later version.
59
 *
60
 * This program is distributed in the hope that it will be useful,
61
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
62
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
63
 * GNU General Public License for more details.
64
 *
65
 * You should have received a copy of the GNU General Public License
66
 * along with this program; if not, write to the Free Software
67
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
68
 *
69
 */
70
 
71
/*
72
 * some functions are inspired on the implementation of OsKit..
73
 *
74
 * Copyright (c) 1997, 1998, 1999 University of Utah and the Flux Group.
75
 * All rights reserved.
76
 *
77
 * [...] The OSKit is free software, also known
78
 * as "open source;" you can redistribute it and/or modify it under the terms
79
 * of the GNU General Public License (GPL), version 2, as published by the Free
80
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
81
 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
82
 *
83
 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
84
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
85
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
86
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
87
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
88
 */
89
 
90
 
91
#ifndef __SIGNAL_H__
92
#define __SIGNAL_H__
93
 
94
#include <kernel/const.h>
95
#include <kernel/types.h>
96
#include <sys/types.h>
97
//#include <time.h>
98
 
99
__DJ_pid_t
100
#undef __DJ_pid_t
101
#define __DJ_pid_t
102
 
103
 
104
/*---------------------------------------------------------------------*/
105
/* Signal codes                                                        */
106
/*---------------------------------------------------------------------*/
107
 
108
/*+ Posix Signal codes: +*/
109
#define SIGABRT       0UL  /*+ Abnormal termination   +*/
110
#define SIGALRM       1UL  /*+ Alarm timeout          +*/
111
#define SIGFPE        2UL  /*+ Math error             +*/
112
#define SIGILL        3UL  /*+ Illegal opcode         +*/
113
#define SIGKILL       4UL  /*+ Kill!!!                +*/
114
#define SIGSEGV       5UL  /*+ Segmantation Violation +*/
115
#define SIGTERM       6UL  /*+ Termination signal     +*/
116
#define SIGUSR1       7UL
117
#define SIGUSR2       8UL
118
 
119
#define SIGHEXC       9UL  /*+ S.Ha.R.K. exception    +*/
120
#define SIGARPFULL   10UL  /*+ ARP table Full, see drivers/net/arp.c +*/
121
 
122
 
123
#define SIGRTMIN     11UL
124
#define SIGRTMAX     31UL
125
 
126
/*+ Maximum signal number in the system +*/
127
#define SIG_MAX      32UL
128
 
129
/*+ codes used in pthread_sigmask (alias task_sigmask) +*/
130
#define SIG_BLOCK      1
131
#define SIG_UNBLOCK    2
132
#define SIG_SETMASK    3
133
 
134
/*+ codes used in sigaction structure +*/
135
#define SIG_DFL (void (*)(int))0
136
#define SIG_IGN (void (*)(int))1
137
#define SIG_ERR (void (*)(int))-1
138
 
139
 
140
/*+ codes used in sigevent structure +*/
141
#define SIGEV_NONE    0
142
#define SIGEV_SIGNAL  1
143
#define SIGEV_THREAD  2
144
 
145
 
146
/*+ signal used by timers if the sigevent parameter is NULL +*/
147
#define DEFAULT_TIMER_SIGNAL 31
148
 
149
/*---------------------------------------------------------------------*/
150
/* Signal handlers and data structures                                 */
151
/*---------------------------------------------------------------------*/
152
 
153
 
154
/*+ sigval is the value passed to the exception handler +*/
155
union sigval {
156
  int    sival_int;
157
  void * sival_ptr;
158
};
159
 
160
/*+ siginfo_t contains some information about the signal... +*/
161
typedef struct siginfo {
162
  int          si_signo;
163
  int          si_code;
164
  union sigval si_value;
165
  PID          si_task;         /* the sending task... */
166
} siginfo_t;
167
 
168
/*+ this structure is used in the realtime timers +*/
169
struct sigevent {
170
  int                sigev_notify;
171
  int                sigev_signo;
172
  union sigval       sigev_value;
173
  void               (*sigev_notify_function)(union sigval);
174
  pthread_attr_t     *sigev_notify_attributes;
175
};
176
 
177
/*+ si_code values: +*/
178
#define SI_USER     0  /*+ signal sent by kill, alarm +*/
179
#define SI_QUEUE    1  /*+ signal sent by sigqueue +*/
180
#define SI_TIMER    2  /*+ signal generated by the expiration of a timer +*/
181
#define SI_ASYNCIO  3  /*+ signal gen. by the completion of an async I/O +*/
182
#define SI_MESGQ    4  /*+ a message is arrived on an empty queue +*/
183
 
184
 
185
/*+ signal Handler: there is only this definition. It corresponds to
186
    a Realtime Signal handler. The Posix signals are called with a dirty
187
    call... in effect these signals have only the signo parameter, but when
188
    the system call them he puts all the three parameters, and then
189
    the handler use only the first. It works well because the
190
    activation frame of the two tasks are similar!!! +*/
191
typedef void (*SIG_HANDLER)(int signo, siginfo_t *info, void *c);
192
 
193
 
194
/*+ a 32 bit signal mask.
195
    If modified, modify also descr.h :-( +*/
196
typedef int sigset_t;
197
 
198
/*+ sigaction structure: used with sigaction()  to set a signal handler.
199
    Normally, we have to set sa_flags = SA_SIGINFO and sa_sigaction =
200
    the signal handler.
201
    sa_mask, sa_handler are used only with Posix signals!!!
202
+*/
203
struct sigaction {
204
  void (*sa_handler)(int);
205
  sigset_t sa_mask;
206
  int sa_flags;
207
  SIG_HANDLER sa_sigaction;
208
};
209
 
210
/*+ bit values for the sa_flags structure +*/
211
#define SA_SIGINFO         1
212
//#define SA_USEFAST         2
213
 
214
 
215
/*---------------------------------------------------------------------*/
216
/* Internal stuffs                                                     */
217
/*---------------------------------------------------------------------*/
218
 
219
/* placed here because this data structures and definitions are used
220
   in signals *and* timer handlers
221
   (maybe in the near future they become another include file...
222
*/
223
 
224
/*+ a signal queue +*/
225
typedef int SIGQ;
226
 
227
/*+ the sigqueue structure is allocated to a timer +*/
228
#define USED_FOR_TIMER 1
229
 
230
/*+ the signal is posted via a sigqueue call and still pending... +*/
231
#define SIGNAL_POSTED    2
232
 
233
/*+ These are the items that go on the sigqueue. +*/
234
typedef struct {
235
  SIGQ next;
236
  siginfo_t info;
237
  int flags;
238
} sig_queue_entry;
239
 
240
/*+ We avoid malloc in interrupt handlers by preallocating the queue
241
    entries for sig_queued above.
242
    it is used also in kernel/time.c +*/
243
extern SIGQ                sigqueue_free;
244
 
245
/*+ this is the signal queue... +*/
246
extern sig_queue_entry     sig_queue[SIGQUEUE_MAX];
247
 
248
/* this version of sigqueue accept also the si_code parameter, useful
249
   for timers and message queues */
250
int
251
sigqueue_internal(pid_t pid, int signo, const union sigval value, int si_code);
252
 
253
 
254
 
255
/*---------------------------------------------------------------------*/
256
/* Signal functions & primitives                                       */
257
/*---------------------------------------------------------------------*/
258
 
259
/*
260
  Posix signals primitives:
261
  (they require sys/types.h and signal.h )
262
 
263
  IMP int kill(pid_t pid, int sig);
264
     . pid is a non-sense
265
 
266
  IMP int sigemptyset(sigset_t *set);
267
  IMP int sigfillset(sigset_t *set);
268
  IMP int sigaddset(sigset_t *set, int signo);
269
  IMP int sigdelset(sigset_t *set, int signo);
270
  IMP int sigismember(const sigset_t *set, int signo);
271
 
272
  IMP int sigaction(int sig, const struct sigaction *act,
273
                    struct sigaction *oact);
274
 
275
  IMP int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
276
      -> also renamed as task_sigmask;
277
  IMP int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
278
 
279
  IMP int sigpending(sigset_t *set);
280
 
281
  IMP int sigsuspend(const sigset_t *sigmask);
282
 
283
  IMP int sigwait(const sigset_t *set, int *sig);
284
  IMP int sigwaitinfo(const sigset_t *set, siginfo_t *info);
285
  IMP int sigtimedwait(const sigset_t *set, siginfo_t *info,
286
                       const struct timespec *timeout);
287
 
288
  IMP int sigqueue(pid_t pid, int signo, const union sigval value);
289
 
290
  IMP int pthread_kill(pthread_t thread, int sig);
291
      -> also renamed as task_signal
292
 
293
  IMP unsigned int alarm(unsigned int seconds);
294
 
295
  IMP int pause(void);
296
 
297
  IMP unsigned int sleep(unsigned int seconds);
298
 
299
  IMP int raise(int sig)
300
 
301
  IMP void (*signal(int signum, void (*handler)(int)))(int);
302
 
303
+*/
304
 
305
 
306
 
307
/*+ this function is called by __kernel_init__ and initialize the signal
308
    subsystem. +*/
309
void signals_init(void);
310
 
311
/*+ this function handles the pending signals...
312
    it is called only in kern_context_load... see func.h +*/
313
void kern_deliver_pending_signals();
314
 
315
 
316
/*+ Posix sigset_t management functions +*/
317
int sigemptyset(sigset_t *set);
318
int sigfillset(sigset_t *set);
319
int sigaddset(sigset_t *set, int signo);
320
int sigdelset(sigset_t *set, int signo);
321
int sigismember(const sigset_t *set, int signo);
322
 
323
 
324
int kill(pid_t pid, int sig);
325
 
326
/*+ This function allow the calling task to examine or specify (or both)
327
    the action to be associated with a specific signal +*/
328
int sigaction(int sig, const struct sigaction *act,
329
              struct sigaction *oact);
330
 
331
int task_sigmask(int how, const sigset_t *set, sigset_t *oset);
332
 
333
int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
334
 
335
int sigsuspend(const sigset_t *sigmask);
336
 
337
/* the sigwait & co. functions simply returns ENOSYS */
338
int sigwait(const sigset_t *set, int *sig);
339
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
340
int sigtimedwait(const sigset_t *set, siginfo_t *info,
341
                       const struct timespec *timeout);
342
 
343
/*+ This function causes the signal specified by signo to be sent with the
344
    value specified by value to the task specified by p. it is slightly
345
    different to the Posix implementation +*/
346
int sigqueue(pid_t p, int signo, const union sigval value);
347
 
348
int task_signal(PID p, int signo);
349
 
350
/*+ raise is like task_signal on the current task... +*/
351
int raise(int sig);
352
 
353
/*+ set a signal handler; it uses internally sigaction +*/
354
void (*signal(int signum, void (*handler)(int)))(int);
355
 
356
/*+ store into *set the pending signals either for the process or the
357
    current task +*/
358
int sigpending(sigset_t *set);
359
 
360
/*+ stops the task until it will execute a signal handler +*/
361
int sigsuspend(const sigset_t *sigmask);
362
 
363
/*+ S.Ha.R.K. exception raise...
364
    This function uses sigqueue to put a signal to the task pointed
365
    by p.
366
+*/
367
void kern_raise(int n, PID p);
368
 
369
 
370
 
371
/*
372
 * sigqueue.
373
 */
374
extern __inline__ int
375
sigqueue(pid_t pid, int signo, const union sigval value)
376
{
377
  return sigqueue_internal(pid, signo, value, SI_QUEUE);
378
}
379
 
380
 
381
#endif