1 |
27 |
unneback |
#ifndef CYGONCE_SIGNAL_H
|
2 |
|
|
#define CYGONCE_SIGNAL_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// signal.h
|
6 |
|
|
//
|
7 |
|
|
// POSIX signal header
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//=============================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): nickg, jlarmour
|
46 |
|
|
// Contributors:
|
47 |
|
|
// Date: 2000-03-17
|
48 |
|
|
// Purpose: POSIX signal header
|
49 |
|
|
// Description: This header contains all the definitions needed to support
|
50 |
|
|
// the POSIX signal API under eCos.
|
51 |
|
|
//
|
52 |
|
|
// Usage: This file can either be included directly, or indirectly via
|
53 |
|
|
// the C library signal.h header.
|
54 |
|
|
//
|
55 |
|
|
//
|
56 |
|
|
//####DESCRIPTIONEND####
|
57 |
|
|
//
|
58 |
|
|
//=============================================================================
|
59 |
|
|
|
60 |
|
|
#include <pkgconf/hal.h>
|
61 |
|
|
#include <pkgconf/kernel.h>
|
62 |
|
|
#include <pkgconf/posix.h>
|
63 |
|
|
|
64 |
|
|
#ifdef CYGPKG_POSIX_SIGNALS
|
65 |
|
|
|
66 |
|
|
#include <stddef.h> // NULL, size_t
|
67 |
|
|
|
68 |
|
|
#include <limits.h>
|
69 |
|
|
#include <sys/types.h>
|
70 |
|
|
|
71 |
|
|
//-----------------------------------------------------------------------------
|
72 |
|
|
// POSIX feature test macros
|
73 |
|
|
|
74 |
|
|
// We do not support job control
|
75 |
|
|
#undef _POSIX_JOB_CONTROL
|
76 |
|
|
|
77 |
|
|
//-----------------------------------------------------------------------------
|
78 |
|
|
// Manifest constants
|
79 |
|
|
|
80 |
|
|
#ifdef _POSIX_REALTIME_SIGNALS
|
81 |
|
|
// For now we define the topmost 8 signals as realtime
|
82 |
|
|
#define SIGRTMIN 24
|
83 |
|
|
#define SIGRTMAX 31
|
84 |
|
|
#endif
|
85 |
|
|
|
86 |
|
|
//-----------------------------------------------------------------------------
|
87 |
|
|
// forward references
|
88 |
|
|
|
89 |
|
|
struct timespec;
|
90 |
|
|
|
91 |
|
|
//-----------------------------------------------------------------------------
|
92 |
|
|
// Sigval structure
|
93 |
|
|
|
94 |
|
|
union sigval
|
95 |
|
|
{
|
96 |
|
|
int sival_int; // used when application-defined value is an int
|
97 |
|
|
void *sival_ptr; // used when application-defined value is a pointer
|
98 |
|
|
};
|
99 |
|
|
|
100 |
|
|
//-----------------------------------------------------------------------------
|
101 |
|
|
// Siginfo structure passed to an SA_SIGINFO style handler
|
102 |
|
|
|
103 |
|
|
typedef struct
|
104 |
|
|
{
|
105 |
|
|
int si_signo; // signal number
|
106 |
|
|
int si_code; // cause of signal
|
107 |
|
|
union sigval si_value; // signal value
|
108 |
|
|
} siginfo_t;
|
109 |
|
|
|
110 |
|
|
// Values for si_code
|
111 |
|
|
# define SI_USER 1
|
112 |
|
|
# define SI_QUEUE 2
|
113 |
|
|
# define SI_TIMER 3
|
114 |
|
|
# define SI_ASYNCIO 4
|
115 |
|
|
# define SI_MESGQ 5
|
116 |
|
|
# define SI_EXCEPT 6 // signal is result of an exception delivery
|
117 |
|
|
|
118 |
|
|
//-----------------------------------------------------------------------------
|
119 |
|
|
// Basic types
|
120 |
|
|
|
121 |
|
|
// Integral type that can be accessed atomically - from ISO C 7.7
|
122 |
|
|
typedef cyg_atomic sig_atomic_t;
|
123 |
|
|
|
124 |
|
|
// Type of signal handler functions
|
125 |
|
|
typedef void (*sa_sighandler_t)(int);
|
126 |
|
|
|
127 |
|
|
// Type of signal handler used if SA_SIGINFO is set in sa_flags
|
128 |
|
|
typedef void (*sa_siginfoaction_t)(int signo, siginfo_t *info,
|
129 |
|
|
void *context);
|
130 |
|
|
|
131 |
|
|
//-----------------------------------------------------------------------------
|
132 |
|
|
//Signal handlers for use with signal() and sigaction(). We avoid 0
|
133 |
|
|
//because in an embedded system this may be start of ROM and thus
|
134 |
|
|
//a possible function pointer for reset.
|
135 |
|
|
|
136 |
|
|
#define SIG_DFL ((sa_sighandler_t) 1) // Default action
|
137 |
|
|
#define SIG_IGN ((sa_sighandler_t) 2) // Ignore action
|
138 |
|
|
#define SIG_ERR ((sa_sighandler_t)-1) // Error return
|
139 |
|
|
|
140 |
|
|
//-----------------------------------------------------------------------------
|
141 |
|
|
// Signal values
|
142 |
|
|
|
143 |
|
|
#define SIGNULL 0 // Reserved signal - do not use (POSIX 3.3.1.1)
|
144 |
|
|
#define SIGHUP 1 // Hangup on controlling terminal (POSIX)
|
145 |
|
|
#define SIGINT 2 // Interactive attention (ISO C)
|
146 |
|
|
#define SIGQUIT 3 // Interactive termination (POSIX)
|
147 |
|
|
#define SIGILL 4 // Illegal instruction (not reset when caught) (ISO C)
|
148 |
|
|
#define SIGTRAP 5 // Trace trap (not reset when caught)
|
149 |
|
|
#define SIGIOT 6 // IOT instruction
|
150 |
|
|
#define SIGABRT 6 // Abnormal termination - used by abort() (ISO C)
|
151 |
|
|
#define SIGEMT 7 // EMT instruction
|
152 |
|
|
#define SIGFPE 8 // Floating Point Exception e.g. div by 0 (ISO C)
|
153 |
|
|
#define SIGKILL 9 // Kill (cannot be caught or ignored) (POSIX)
|
154 |
|
|
#define SIGBUS 10 // Bus error (POSIX)
|
155 |
|
|
#define SIGSEGV 11 // Invalid memory reference (ISO C)
|
156 |
|
|
#define SIGSYS 12 // Bad argument to system call (used by anything?)
|
157 |
|
|
#define SIGPIPE 13 // Write on a pipe with no one to read it (POSIX)
|
158 |
|
|
#define SIGALRM 14 // Alarm timeout (POSIX)
|
159 |
|
|
#define SIGTERM 15 // Software termination request (ISO C)
|
160 |
|
|
#define SIGUSR1 16 // Application-defined signal 1 (POSIX)
|
161 |
|
|
#define SIGUSR2 17 // Application-defined signal 2 (POSIX)
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
//-----------------------------------------------------------------------------
|
165 |
|
|
// Signal sets.
|
166 |
|
|
// At present we define a single 32 bit integer mask. We may need, at
|
167 |
|
|
// some future point, to extend this to 64 bits, or a structure
|
168 |
|
|
// containing an array of masks.
|
169 |
|
|
|
170 |
|
|
typedef cyg_uint32 sigset_t;
|
171 |
|
|
|
172 |
|
|
//-----------------------------------------------------------------------------
|
173 |
|
|
// struct sigaction describes the action to be taken when we get a signal
|
174 |
|
|
|
175 |
|
|
struct sigaction
|
176 |
|
|
{
|
177 |
|
|
sigset_t sa_mask; // Additional signals to be blocked
|
178 |
|
|
int sa_flags; // Special flags
|
179 |
|
|
union
|
180 |
|
|
{
|
181 |
|
|
sa_sighandler_t sa_handler; // signal handler
|
182 |
|
|
sa_siginfoaction_t sa_sigaction; // Function to call instead of
|
183 |
|
|
// sa_handler if SA_SIGINFO is
|
184 |
|
|
// set in sa_flags
|
185 |
|
|
} sa_sigactionhandler;
|
186 |
|
|
#define sa_handler sa_sigactionhandler.sa_handler
|
187 |
|
|
#define sa_sigaction sa_sigactionhandler.sa_sigaction
|
188 |
|
|
};
|
189 |
|
|
|
190 |
|
|
// sa_flag bits
|
191 |
|
|
#define SA_NOCLDSTOP 1 // Don't generate SIGCHLD when children stop
|
192 |
|
|
#define SA_SIGINFO 2 // Use the sa_siginfoaction_t style signal
|
193 |
|
|
// handler, instead of the single argument handler
|
194 |
|
|
|
195 |
|
|
//-----------------------------------------------------------------------------
|
196 |
|
|
// Sigevent structure.
|
197 |
|
|
|
198 |
|
|
struct sigevent
|
199 |
|
|
{
|
200 |
|
|
int sigev_notify;
|
201 |
|
|
int sigev_signo;
|
202 |
|
|
union sigval sigev_value;
|
203 |
|
|
void (*sigev_notify_function) (union sigval);
|
204 |
|
|
pthread_attr_t *sigev_notify_attributes;
|
205 |
|
|
};
|
206 |
|
|
|
207 |
|
|
# define SIGEV_NONE 1
|
208 |
|
|
# define SIGEV_SIGNAL 2
|
209 |
|
|
# define SIGEV_THREAD 3
|
210 |
|
|
|
211 |
|
|
//-----------------------------------------------------------------------------
|
212 |
|
|
// Functions to generate signals
|
213 |
|
|
|
214 |
|
|
// Deliver sig to a process.
|
215 |
|
|
// eCos only supports the value 0 for pid.
|
216 |
|
|
externC int kill (pid_t pid, int sig);
|
217 |
|
|
|
218 |
|
|
externC int pthread_kill (pthread_t thread, int sig);
|
219 |
|
|
|
220 |
|
|
//-----------------------------------------------------------------------------
|
221 |
|
|
// Functions to catch signals
|
222 |
|
|
|
223 |
|
|
// Install signal handler for sig.
|
224 |
|
|
externC int sigaction (int sig, const struct sigaction *act,
|
225 |
|
|
struct sigaction *oact);
|
226 |
|
|
|
227 |
|
|
// Queue signal to process with value.
|
228 |
|
|
externC int sigqueue (pid_t pid, int sig, const union sigval value);
|
229 |
|
|
|
230 |
|
|
//-----------------------------------------------------------------------------
|
231 |
|
|
// Functions to deal with current blocked and pending masks
|
232 |
|
|
|
233 |
|
|
// Set process blocked signal mask
|
234 |
|
|
externC int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
|
235 |
|
|
|
236 |
|
|
// Set calling thread's blocked signal mask
|
237 |
|
|
externC int pthread_sigmask (int how, const sigset_t *set, sigset_t *oset);
|
238 |
|
|
|
239 |
|
|
// Get set of pending signals for this process
|
240 |
|
|
externC int sigpending (sigset_t *set);
|
241 |
|
|
|
242 |
|
|
// Values for the how arguments:
|
243 |
|
|
#define SIG_BLOCK 1
|
244 |
|
|
#define SIG_UNBLOCK 2
|
245 |
|
|
#define SIG_SETMASK 3
|
246 |
|
|
|
247 |
|
|
//-----------------------------------------------------------------------------
|
248 |
|
|
// Wait for or accept signals
|
249 |
|
|
|
250 |
|
|
// Block signals in set and wait for a signal
|
251 |
|
|
externC int sigsuspend (const sigset_t *set);
|
252 |
|
|
|
253 |
|
|
// Wait for a signal in set to arrive
|
254 |
|
|
externC int sigwait (const sigset_t *set, int *sig);
|
255 |
|
|
|
256 |
|
|
// Do the same as sigwait() except return a siginfo_t object too.
|
257 |
|
|
externC int sigwaitinfo (const sigset_t *set, siginfo_t *info);
|
258 |
|
|
|
259 |
|
|
// Do the same as sigwaitinfo() but return anyway after timeout.
|
260 |
|
|
externC int sigtimedwait (const sigset_t *set, siginfo_t *info,
|
261 |
|
|
const struct timespec *timeout);
|
262 |
|
|
|
263 |
|
|
//-----------------------------------------------------------------------------
|
264 |
|
|
// Signal sets
|
265 |
|
|
|
266 |
|
|
// Clear all signals from set.
|
267 |
|
|
externC int sigemptyset (sigset_t *set);
|
268 |
|
|
|
269 |
|
|
// Set all signals in set.
|
270 |
|
|
externC int sigfillset (sigset_t *set);
|
271 |
|
|
|
272 |
|
|
// Add signo to set.
|
273 |
|
|
externC int sigaddset (sigset_t *set, int signo);
|
274 |
|
|
|
275 |
|
|
// Remove signo from set.
|
276 |
|
|
externC int sigdelset (sigset_t *set, int signo);
|
277 |
|
|
|
278 |
|
|
// Test whether signo is in set
|
279 |
|
|
externC int sigismember (const sigset_t *set, int signo);
|
280 |
|
|
|
281 |
|
|
//-----------------------------------------------------------------------------
|
282 |
|
|
// alarm, pause and sleep
|
283 |
|
|
|
284 |
|
|
// Generate SIGALRM after some number of seconds
|
285 |
|
|
externC unsigned int alarm( unsigned int seconds );
|
286 |
|
|
|
287 |
|
|
// Wait for a signal to be delivered.
|
288 |
|
|
externC int pause( void );
|
289 |
|
|
|
290 |
|
|
// Wait for a signal, or the given number of seconds
|
291 |
|
|
externC unsigned int sleep( unsigned int seconds );
|
292 |
|
|
|
293 |
|
|
//-----------------------------------------------------------------------------
|
294 |
|
|
// signal() - ISO C 7.7.1 //
|
295 |
|
|
//
|
296 |
|
|
// Installs a new signal handler for the specified signal, and returns
|
297 |
|
|
// the old handler
|
298 |
|
|
//
|
299 |
|
|
|
300 |
|
|
externC sa_sighandler_t signal(int __sig, sa_sighandler_t __handler);
|
301 |
|
|
|
302 |
|
|
// raise() - ISO C 7.7.2 //
|
303 |
|
|
//
|
304 |
|
|
// Raises the signal, which will cause the current signal handler for
|
305 |
|
|
// that signal to be called
|
306 |
|
|
|
307 |
|
|
externC int raise(int __sig);
|
308 |
|
|
|
309 |
|
|
#endif // ifdef CYGPKG_POSIX_SIGNALS
|
310 |
|
|
|
311 |
|
|
//-----------------------------------------------------------------------------
|
312 |
|
|
#endif // ifndef CYGONCE_SIGNAL_H
|
313 |
|
|
// End of signal.h
|