Subversion Repositories shark

Rev

Rev 3 | 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
 ------------
80 pj 23
 CVS :        $Id: signal.h,v 1.2 2003-03-13 13:41:04 pj Exp $
2 pj 24
 
25
 File:        $File$
80 pj 26
 Revision:    $Revision: 1.2 $
27
 Last update: $Date: 2003-03-13 13:41:04 $
2 pj 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>
80 pj 98
#include "ll/sys/cdefs.h"
2 pj 99
 
80 pj 100
__BEGIN_DECLS
101
 
2 pj 102
__DJ_pid_t
103
#undef __DJ_pid_t
104
#define __DJ_pid_t
105
 
106
 
107
/*---------------------------------------------------------------------*/
108
/* Signal codes                                                        */
109
/*---------------------------------------------------------------------*/
110
 
111
/*+ Posix Signal codes: +*/
112
#define SIGABRT       0UL  /*+ Abnormal termination   +*/
113
#define SIGALRM       1UL  /*+ Alarm timeout          +*/
114
#define SIGFPE        2UL  /*+ Math error             +*/
115
#define SIGILL        3UL  /*+ Illegal opcode         +*/
116
#define SIGKILL       4UL  /*+ Kill!!!                +*/
117
#define SIGSEGV       5UL  /*+ Segmantation Violation +*/
118
#define SIGTERM       6UL  /*+ Termination signal     +*/
119
#define SIGUSR1       7UL
120
#define SIGUSR2       8UL
121
 
122
#define SIGHEXC       9UL  /*+ S.Ha.R.K. exception    +*/
123
#define SIGARPFULL   10UL  /*+ ARP table Full, see drivers/net/arp.c +*/
124
 
125
 
126
#define SIGRTMIN     11UL
127
#define SIGRTMAX     31UL
128
 
129
/*+ Maximum signal number in the system +*/
130
#define SIG_MAX      32UL
131
 
132
/*+ codes used in pthread_sigmask (alias task_sigmask) +*/
133
#define SIG_BLOCK      1
134
#define SIG_UNBLOCK    2
135
#define SIG_SETMASK    3
136
 
137
/*+ codes used in sigaction structure +*/
138
#define SIG_DFL (void (*)(int))0
139
#define SIG_IGN (void (*)(int))1
140
#define SIG_ERR (void (*)(int))-1
141
 
142
 
143
/*+ codes used in sigevent structure +*/
144
#define SIGEV_NONE    0
145
#define SIGEV_SIGNAL  1
146
#define SIGEV_THREAD  2
147
 
148
 
149
/*+ signal used by timers if the sigevent parameter is NULL +*/
150
#define DEFAULT_TIMER_SIGNAL 31
151
 
152
/*---------------------------------------------------------------------*/
153
/* Signal handlers and data structures                                 */
154
/*---------------------------------------------------------------------*/
155
 
156
 
157
/*+ sigval is the value passed to the exception handler +*/
158
union sigval {
159
  int    sival_int;
160
  void * sival_ptr;
161
};
162
 
163
/*+ siginfo_t contains some information about the signal... +*/
164
typedef struct siginfo {
165
  int          si_signo;
166
  int          si_code;
167
  union sigval si_value;
168
  PID          si_task;         /* the sending task... */
169
} siginfo_t;
170
 
171
/*+ this structure is used in the realtime timers +*/
172
struct sigevent {
173
  int                sigev_notify;
174
  int                sigev_signo;
175
  union sigval       sigev_value;
176
  void               (*sigev_notify_function)(union sigval);
177
  pthread_attr_t     *sigev_notify_attributes;
178
};
179
 
180
/*+ si_code values: +*/
181
#define SI_USER     0  /*+ signal sent by kill, alarm +*/
182
#define SI_QUEUE    1  /*+ signal sent by sigqueue +*/
183
#define SI_TIMER    2  /*+ signal generated by the expiration of a timer +*/
184
#define SI_ASYNCIO  3  /*+ signal gen. by the completion of an async I/O +*/
185
#define SI_MESGQ    4  /*+ a message is arrived on an empty queue +*/
186
 
187
 
188
/*+ signal Handler: there is only this definition. It corresponds to
189
    a Realtime Signal handler. The Posix signals are called with a dirty
190
    call... in effect these signals have only the signo parameter, but when
191
    the system call them he puts all the three parameters, and then
192
    the handler use only the first. It works well because the
193
    activation frame of the two tasks are similar!!! +*/
194
typedef void (*SIG_HANDLER)(int signo, siginfo_t *info, void *c);
195
 
196
 
197
/*+ a 32 bit signal mask.
198
    If modified, modify also descr.h :-( +*/
199
typedef int sigset_t;
200
 
201
/*+ sigaction structure: used with sigaction()  to set a signal handler.
202
    Normally, we have to set sa_flags = SA_SIGINFO and sa_sigaction =
203
    the signal handler.
204
    sa_mask, sa_handler are used only with Posix signals!!!
205
+*/
206
struct sigaction {
207
  void (*sa_handler)(int);
208
  sigset_t sa_mask;
209
  int sa_flags;
210
  SIG_HANDLER sa_sigaction;
211
};
212
 
213
/*+ bit values for the sa_flags structure +*/
214
#define SA_SIGINFO         1
215
//#define SA_USEFAST         2
216
 
217
 
218
/*---------------------------------------------------------------------*/
219
/* Internal stuffs                                                     */
220
/*---------------------------------------------------------------------*/
221
 
222
/* placed here because this data structures and definitions are used
223
   in signals *and* timer handlers
224
   (maybe in the near future they become another include file...
225
*/
226
 
227
/*+ a signal queue +*/
228
typedef int SIGQ;
229
 
230
/*+ the sigqueue structure is allocated to a timer +*/
231
#define USED_FOR_TIMER 1
232
 
233
/*+ the signal is posted via a sigqueue call and still pending... +*/
234
#define SIGNAL_POSTED    2
235
 
236
/*+ These are the items that go on the sigqueue. +*/
237
typedef struct {
238
  SIGQ next;
239
  siginfo_t info;
240
  int flags;
241
} sig_queue_entry;
242
 
243
/*+ We avoid malloc in interrupt handlers by preallocating the queue
244
    entries for sig_queued above.
245
    it is used also in kernel/time.c +*/
246
extern SIGQ                sigqueue_free;
247
 
248
/*+ this is the signal queue... +*/
249
extern sig_queue_entry     sig_queue[SIGQUEUE_MAX];
250
 
251
/* this version of sigqueue accept also the si_code parameter, useful
252
   for timers and message queues */
253
int
254
sigqueue_internal(pid_t pid, int signo, const union sigval value, int si_code);
255
 
256
 
257
 
258
/*---------------------------------------------------------------------*/
259
/* Signal functions & primitives                                       */
260
/*---------------------------------------------------------------------*/
261
 
262
/*
263
  Posix signals primitives:
264
  (they require sys/types.h and signal.h )
265
 
266
  IMP int kill(pid_t pid, int sig);
267
     . pid is a non-sense
268
 
269
  IMP int sigemptyset(sigset_t *set);
270
  IMP int sigfillset(sigset_t *set);
271
  IMP int sigaddset(sigset_t *set, int signo);
272
  IMP int sigdelset(sigset_t *set, int signo);
273
  IMP int sigismember(const sigset_t *set, int signo);
274
 
275
  IMP int sigaction(int sig, const struct sigaction *act,
276
                    struct sigaction *oact);
277
 
278
  IMP int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
279
      -> also renamed as task_sigmask;
280
  IMP int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
281
 
282
  IMP int sigpending(sigset_t *set);
283
 
284
  IMP int sigsuspend(const sigset_t *sigmask);
285
 
286
  IMP int sigwait(const sigset_t *set, int *sig);
287
  IMP int sigwaitinfo(const sigset_t *set, siginfo_t *info);
288
  IMP int sigtimedwait(const sigset_t *set, siginfo_t *info,
289
                       const struct timespec *timeout);
290
 
291
  IMP int sigqueue(pid_t pid, int signo, const union sigval value);
292
 
293
  IMP int pthread_kill(pthread_t thread, int sig);
294
      -> also renamed as task_signal
295
 
296
  IMP unsigned int alarm(unsigned int seconds);
297
 
298
  IMP int pause(void);
299
 
300
  IMP unsigned int sleep(unsigned int seconds);
301
 
302
  IMP int raise(int sig)
303
 
304
  IMP void (*signal(int signum, void (*handler)(int)))(int);
305
 
306
+*/
307
 
308
 
309
 
310
/*+ this function is called by __kernel_init__ and initialize the signal
311
    subsystem. +*/
312
void signals_init(void);
313
 
314
/*+ this function handles the pending signals...
315
    it is called only in kern_context_load... see func.h +*/
316
void kern_deliver_pending_signals();
317
 
318
 
319
/*+ Posix sigset_t management functions +*/
320
int sigemptyset(sigset_t *set);
321
int sigfillset(sigset_t *set);
322
int sigaddset(sigset_t *set, int signo);
323
int sigdelset(sigset_t *set, int signo);
324
int sigismember(const sigset_t *set, int signo);
325
 
326
 
327
int kill(pid_t pid, int sig);
328
 
329
/*+ This function allow the calling task to examine or specify (or both)
330
    the action to be associated with a specific signal +*/
331
int sigaction(int sig, const struct sigaction *act,
332
              struct sigaction *oact);
333
 
334
int task_sigmask(int how, const sigset_t *set, sigset_t *oset);
335
 
336
int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
337
 
338
int sigsuspend(const sigset_t *sigmask);
339
 
340
/* the sigwait & co. functions simply returns ENOSYS */
341
int sigwait(const sigset_t *set, int *sig);
342
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
343
int sigtimedwait(const sigset_t *set, siginfo_t *info,
344
                       const struct timespec *timeout);
345
 
346
/*+ This function causes the signal specified by signo to be sent with the
347
    value specified by value to the task specified by p. it is slightly
348
    different to the Posix implementation +*/
349
int sigqueue(pid_t p, int signo, const union sigval value);
350
 
351
int task_signal(PID p, int signo);
352
 
353
/*+ raise is like task_signal on the current task... +*/
354
int raise(int sig);
355
 
356
/*+ set a signal handler; it uses internally sigaction +*/
357
void (*signal(int signum, void (*handler)(int)))(int);
358
 
359
/*+ store into *set the pending signals either for the process or the
360
    current task +*/
361
int sigpending(sigset_t *set);
362
 
363
/*+ stops the task until it will execute a signal handler +*/
364
int sigsuspend(const sigset_t *sigmask);
365
 
366
/*+ S.Ha.R.K. exception raise...
367
    This function uses sigqueue to put a signal to the task pointed
368
    by p.
369
+*/
370
void kern_raise(int n, PID p);
371
 
372
 
373
 
374
/*
375
 * sigqueue.
376
 */
377
extern __inline__ int
378
sigqueue(pid_t pid, int signo, const union sigval value)
379
{
380
  return sigqueue_internal(pid, signo, value, SI_QUEUE);
381
}
382
 
80 pj 383
__END_DECLS
2 pj 384
#endif