source: mainline/uspace/lib/posix/signal.h@ 324d46b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 324d46b was d3ce33fa, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

signal.h: Add some functions and implementations

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libposix
30 * @{
31 */
32/** @file
33 */
34
35#ifndef POSIX_SIGNAL_H_
36#define POSIX_SIGNAL_H_
37
38#include "libc/errno.h"
39#include "sys/types.h"
40
41extern void __posix_default_signal_handler(int signo);
42extern void __posix_hold_signal_handler(int signo);
43extern void __posix_ignore_signal_handler(int signo);
44
45#undef SIG_DFL
46#define SIG_DFL ((void (*)(int)) __posix_default_signal_handler)
47#undef SIG_ERR
48#define SIG_ERR ((void (*)(int)) NULL)
49#undef SIG_HOLD
50#define SIG_HOLD ((void (*)(int)) __posix_hold_signal_handler)
51#undef SIG_IGN
52#define SIG_IGN ((void (*)(int)) __posix_ignore_signal_handler)
53
54typedef int posix_sig_atomic_t;
55typedef uint32_t posix_sigset_t;
56typedef struct posix_mcontext {
57 // FIXME: should not be empty to avoid compiler warnings (-pedantic)
58 int dummy;
59} posix_mcontext_t;
60
61union posix_sigval {
62 int sival_int;
63 void *sival_ptr;
64};
65
66struct posix_sigevent {
67 int sigev_notify; /* Notification type. */
68 int sigev_signo; /* Signal number. */
69 union posix_sigval sigev_value; /* Signal value. */
70 void (*sigev_notify_function)(union posix_sigval); /* Notification function. */
71 posix_thread_attr_t *sigev_notify_attributes; /* Notification attributes. */
72};
73
74typedef struct {
75 int si_signo;
76 int si_code;
77
78 int si_errno;
79
80 posix_pid_t si_pid;
81 posix_uid_t si_uid;
82 void *si_addr;
83 int si_status;
84
85 long si_band;
86
87 union posix_sigval si_value;
88} posix_siginfo_t;
89
90struct posix_sigaction {
91 void (*sa_handler)(int);
92 posix_sigset_t sa_mask;
93 int sa_flags;
94 void (*sa_sigaction)(int, posix_siginfo_t *, void *);
95};
96
97typedef struct {
98 void *ss_sp;
99 size_t ss_size;
100 int ss_flags;
101} posix_stack_t;
102
103typedef struct posix_ucontext {
104 struct posix_ucontext *uc_link;
105 posix_sigset_t uc_sigmask;
106 posix_stack_t uc_stack;
107 posix_mcontext_t uc_mcontext;
108} posix_ucontext_t;
109
110
111/* Values of posix_sigevent::sigev_notify */
112#undef SIGEV_NONE
113#undef SIGEV_SIGNAL
114#undef SIGEV_THREAD
115#define SIGEV_NONE 0
116#define SIGEV_SIGNAL 0
117#define SIGEV_THREAD 0
118
119#undef SIGRT_MIN
120#undef SIGRT_MAX
121#define SIGRT_MIN 0
122#define SIGRT_MAX 0
123
124#undef SIG_BLOCK
125#undef SIG_UNBLOCK
126#undef SIG_SETMASK
127#define SIG_BLOCK 0
128#define SIG_UNBLOCK 1
129#define SIG_SETMASK 2
130
131#undef SA_NOCLDSTOP
132#undef SA_ONSTACK
133#undef SA_RESETHAND
134#undef SA_RESTART
135#undef SA_SIGINFO
136#undef SA_NOCLDWAIT
137#undef SA_NODEFER
138#define SA_NOCLDSTOP (1 << 0)
139#define SA_ONSTACK (1 << 1)
140#define SA_RESETHAND (1 << 2)
141#define SA_RESTART (1 << 3)
142#define SA_SIGINFO (1 << 4)
143#define SA_NOCLDWAIT (1 << 5)
144#define SA_NODEFER (1 << 6)
145
146#undef SS_ONSTACK
147#undef SS_DISABLE
148#define SS_ONSTACK 0
149#define SS_DISABLE 0
150
151#undef MINSIGSTKSZ
152#undef SIGSTKSZ
153#define MINSIGSTKSZ 0
154#define SIGSTKSZ 0
155
156/* full POSIX set */
157enum {
158 /* Termination Signals */
159 SIGABRT,
160 SIGQUIT,
161 SIGINT,
162 SIGTERM,
163
164 /* Child Signal */
165 SIGCHLD,
166
167 /* User signals */
168 SIGUSR1,
169 SIGUSR2,
170
171 /* Timer */
172 SIGALRM,
173 SIGVTALRM,
174 SIGPROF, /* obsolete */
175
176 _TOP_CATCHABLE_SIGNAL = SIGPROF,
177
178 /* Process Scheduler Interaction - not supported */
179 SIGSTOP,
180 SIGCONT,
181
182 /* Process Termination - can't be caught */
183 SIGKILL,
184
185 _TOP_SENDABLE_SIGNAL = SIGKILL,
186
187 /* Hardware Exceptions - can't be caught or sent */
188 SIGFPE,
189 SIGBUS,
190 SIGILL,
191 SIGSEGV,
192
193 /* Other Exceptions - not supported */
194 SIGSYS,
195 SIGXCPU,
196 SIGXFSZ,
197
198 /* Debugging - not supported */
199 SIGTRAP,
200
201 /* Communication Signals - not supported */
202 SIGHUP,
203 SIGPIPE,
204 SIGPOLL, /* obsolete */
205 SIGURG,
206
207 /* Terminal Signals - not supported */
208 SIGTSTP,
209 SIGTTIN,
210 SIGTTOU,
211
212 _TOP_SIGNAL = SIGTTOU
213};
214
215/* Values for sigaction field si_code. */
216
217enum {
218 SI_USER,
219 SI_QUEUE,
220 SI_TIMER,
221 SI_ASYNCIO,
222 SI_MESGQ,
223 ILL_ILLOPC,
224 ILL_ILLOPN,
225 ILL_ILLADR,
226 ILL_ILLTRP,
227 ILL_PRVOPC,
228 ILL_PRVREG,
229 ILL_COPROC,
230 ILL_BADSTK,
231 FPE_INTDIV,
232 FPE_INTOVF,
233 FPE_FLTDIV,
234 FPE_FLTOVF,
235 FPE_FLTUND,
236 FPE_FLTRES,
237 FPE_FLTINV,
238 FPE_FLTSUB,
239 SEGV_MAPERR,
240 SEGV_ACCERR,
241 BUS_ADRALN,
242 BUS_ADRERR,
243 BUS_OBJERR,
244 TRAP_BRKPT,
245 TRAP_TRACE,
246 CLD_EXITED,
247 CLD_KILLED,
248 CLD_DUMPED,
249 CLD_TRAPPED,
250 CLD_STOPPED,
251 CLD_CONTINUED,
252 POLL_IN,
253 POLL_OUT,
254 POLL_MSG,
255 POLL_ERR,
256 POLL_PRI,
257 POLL_HUP
258};
259
260extern int posix_sigaction(int sig, const struct posix_sigaction *restrict act,
261 struct posix_sigaction *restrict oact);
262
263extern void (*posix_signal(int sig, void (*func)(int)))(int);
264extern int posix_raise(int sig);
265extern int posix_kill(posix_pid_t pid, int sig);
266extern int posix_killpg(posix_pid_t pid, int sig);
267
268extern void posix_psiginfo(const posix_siginfo_t *pinfo, const char *message);
269extern void posix_psignal(int signum, const char *message);
270
271extern int posix_sigemptyset(posix_sigset_t *set);
272extern int posix_sigfillset(posix_sigset_t *set);
273extern int posix_sigaddset(posix_sigset_t *set, int signo);
274extern int posix_sigdelset(posix_sigset_t *set, int signo);
275extern int posix_sigismember(const posix_sigset_t *set, int signo);
276
277extern int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,
278 posix_sigset_t *restrict oset);
279extern int posix_sigprocmask(int how, const posix_sigset_t *restrict set,
280 posix_sigset_t *restrict oset);
281
282#ifndef LIBPOSIX_INTERNAL
283 #define sig_atomic_t posix_sig_atomic_t
284 #define sigset_t posix_sigset_t
285 #define sigval posix_sigval
286 #define sigevent posix_sigevent
287 #define sigaction posix_sigaction
288 #define mcontext_t posix_mcontext_t
289 #define ucontext_t posix_ucontext_t
290 #define stack_t posix_stack_t
291 #define siginfo_t posix_siginfo_t
292
293 #define signal posix_signal
294 #define raise posix_raise
295 #define kill posix_kill
296 #define killpg posix_killpg
297
298 #define psiginfo posix_psiginfo
299 #define psignal posix_psignal
300
301 #define sigemptyset posix_sigemptyset
302 #define sigfillset posix_sigfillset
303 #define sigaddset posix_sigaddset
304 #define sigdelset posix_sigdelset
305 #define sigismember posix_sigismember
306
307 #define pthread_sigmask posix_thread_sigmask
308 #define sigprocmask posix_sigprocmask
309#endif
310
311#endif /* POSIX_SIGNAL_H_ */
312
313/** @}
314 */
Note: See TracBrowser for help on using the repository browser.