Subversion Repositories shark

Rev

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
 ------------
926 pj 23
 CVS :        $Id: signal.h,v 1.3 2005-01-08 14:54:19 pj Exp $
2 pj 24
 
25
 File:        $File$
926 pj 26
 Revision:    $Revision: 1.3 $
27
 Last update: $Date: 2005-01-08 14:54:19 $
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
 
216
 
217
/*---------------------------------------------------------------------*/
218
/* Internal stuffs                                                     */
219
/*---------------------------------------------------------------------*/
220
 
221
/* placed here because this data structures and definitions are used
222
   in signals *and* timer handlers
223
   (maybe in the near future they become another include file...
224
*/
225
 
226
/*+ a signal queue +*/
227
typedef int SIGQ;
228
 
229
/*+ the sigqueue structure is allocated to a timer +*/
230
#define USED_FOR_TIMER 1
231
 
232
/*+ the signal is posted via a sigqueue call and still pending... +*/
233
#define SIGNAL_POSTED    2
234
 
235
/*+ These are the items that go on the sigqueue. +*/
236
typedef struct {
237
  SIGQ next;
238
  siginfo_t info;
239
  int flags;
240
} sig_queue_entry;
241
 
242
/*+ We avoid malloc in interrupt handlers by preallocating the queue
243
    entries for sig_queued above.
244
    it is used also in kernel/time.c +*/
245
extern SIGQ                sigqueue_free;
246
 
247
/*+ this is the signal queue... +*/
248
extern sig_queue_entry     sig_queue[SIGQUEUE_MAX];
249
 
250
/* this version of sigqueue accept also the si_code parameter, useful
251
   for timers and message queues */
252
int
253
sigqueue_internal(pid_t pid, int signo, const union sigval value, int si_code);
254
 
255
 
256
 
257
/*---------------------------------------------------------------------*/
258
/* Signal functions & primitives                                       */
259
/*---------------------------------------------------------------------*/
260
 
261
/*
262
  Posix signals primitives:
263
  (they require sys/types.h and signal.h )
264
 
265
  IMP int kill(pid_t pid, int sig);
266
     . pid is a non-sense
267
 
268
  IMP int sigemptyset(sigset_t *set);
269
  IMP int sigfillset(sigset_t *set);
270
  IMP int sigaddset(sigset_t *set, int signo);
271
  IMP int sigdelset(sigset_t *set, int signo);
272
  IMP int sigismember(const sigset_t *set, int signo);
273
 
274
  IMP int sigaction(int sig, const struct sigaction *act,
275
                    struct sigaction *oact);
276
 
277
  IMP int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
278
      -> also renamed as task_sigmask;
279
  IMP int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
280
 
281
  IMP int sigpending(sigset_t *set);
282
 
283
  IMP int sigsuspend(const sigset_t *sigmask);
284
 
285
  IMP int sigwait(const sigset_t *set, int *sig);
286
  IMP int sigwaitinfo(const sigset_t *set, siginfo_t *info);
287
  IMP int sigtimedwait(const sigset_t *set, siginfo_t *info,
288
                       const struct timespec *timeout);
289
 
290
  IMP int sigqueue(pid_t pid, int signo, const union sigval value);
291
 
292
  IMP int pthread_kill(pthread_t thread, int sig);
293
      -> also renamed as task_signal
294
 
295
  IMP unsigned int alarm(unsigned int seconds);
296
 
297
  IMP int pause(void);
298
 
299
  IMP unsigned int sleep(unsigned int seconds);
300
 
301
  IMP int raise(int sig)
302
 
303
  IMP void (*signal(int signum, void (*handler)(int)))(int);
304
 
305
+*/
306
 
307
 
308
 
309
/*+ this function is called by __kernel_init__ and initialize the signal
310
    subsystem. +*/
311
void signals_init(void);
312
 
313
/*+ this function handles the pending signals...
314
    it is called only in kern_context_load... see func.h +*/
315
void kern_deliver_pending_signals();
316
 
317
 
318
/*+ Posix sigset_t management functions +*/
319
int sigemptyset(sigset_t *set);
320
int sigfillset(sigset_t *set);
321
int sigaddset(sigset_t *set, int signo);
322
int sigdelset(sigset_t *set, int signo);
323
int sigismember(const sigset_t *set, int signo);
324
 
325
 
326
int kill(pid_t pid, int sig);
327
 
328
/*+ This function allow the calling task to examine or specify (or both)
329
    the action to be associated with a specific signal +*/
330
int sigaction(int sig, const struct sigaction *act,
331
              struct sigaction *oact);
332
 
333
int task_sigmask(int how, const sigset_t *set, sigset_t *oset);
334
 
335
int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
336
 
337
int sigsuspend(const sigset_t *sigmask);
338
 
339
/* the sigwait & co. functions simply returns ENOSYS */
340
int sigwait(const sigset_t *set, int *sig);
341
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
342
int sigtimedwait(const sigset_t *set, siginfo_t *info,
343
                       const struct timespec *timeout);
344
 
345
/*+ This function causes the signal specified by signo to be sent with the
346
    value specified by value to the task specified by p. it is slightly
347
    different to the Posix implementation +*/
348
int sigqueue(pid_t p, int signo, const union sigval value);
349
 
350
int task_signal(PID p, int signo);
351
 
352
/*+ raise is like task_signal on the current task... +*/
353
int raise(int sig);
354
 
355
/*+ set a signal handler; it uses internally sigaction +*/
356
void (*signal(int signum, void (*handler)(int)))(int);
357
 
358
/*+ store into *set the pending signals either for the process or the
359
    current task +*/
360
int sigpending(sigset_t *set);
361
 
362
/*+ stops the task until it will execute a signal handler +*/
363
int sigsuspend(const sigset_t *sigmask);
364
 
365
/*+ S.Ha.R.K. exception raise...
366
    This function uses sigqueue to put a signal to the task pointed
367
    by p.
368
+*/
369
void kern_raise(int n, PID p);
370
 
371
 
372
 
373
/*
374
 * sigqueue.
375
 */
376
extern __inline__ int
377
sigqueue(pid_t pid, int signo, const union sigval value)
378
{
379
  return sigqueue_internal(pid, signo, value, SI_QUEUE);
380
}
381
 
80 pj 382
__END_DECLS
2 pj 383
#endif