source: mainline/uspace/lib/posix/signal.h@ aa5acd47

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since aa5acd47 was 4cf8ca6, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Various minor commenting (no change in functionality).

  • Property mode set to 100644
File size: 7.2 KB
RevLine 
[098eeba3]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
[4f4b4e7]29/** @addtogroup libposix
30 * @{
31 */
[4cf8ca6]32/** @file Signal handling.
[4f4b4e7]33 */
34
[098eeba3]35#ifndef POSIX_SIGNAL_H_
36#define POSIX_SIGNAL_H_
37
[4cf8ca6]38// TODO: documentation
39
[4f4b4e7]40#include "libc/errno.h"
[fa9815d9]41#include "sys/types.h"
[098eeba3]42
[d3ce33fa]43extern void __posix_default_signal_handler(int signo);
44extern void __posix_hold_signal_handler(int signo);
45extern void __posix_ignore_signal_handler(int signo);
[098eeba3]46
[4f4b4e7]47#undef SIG_DFL
[d3ce33fa]48#define SIG_DFL ((void (*)(int)) __posix_default_signal_handler)
[4f4b4e7]49#undef SIG_ERR
[d3ce33fa]50#define SIG_ERR ((void (*)(int)) NULL)
[fa9815d9]51#undef SIG_HOLD
[d3ce33fa]52#define SIG_HOLD ((void (*)(int)) __posix_hold_signal_handler)
[4f4b4e7]53#undef SIG_IGN
[d3ce33fa]54#define SIG_IGN ((void (*)(int)) __posix_ignore_signal_handler)
[098eeba3]55
[4f4b4e7]56typedef int posix_sig_atomic_t;
[d3ce33fa]57typedef uint32_t posix_sigset_t;
[fa9815d9]58typedef struct posix_mcontext {
[1a552fd]59 // FIXME: should not be empty to avoid compiler warnings (-pedantic)
60 int dummy;
[fa9815d9]61} posix_mcontext_t;
62
63union posix_sigval {
64 int sival_int;
65 void *sival_ptr;
66};
67
68struct posix_sigevent {
69 int sigev_notify; /* Notification type. */
70 int sigev_signo; /* Signal number. */
71 union posix_sigval sigev_value; /* Signal value. */
[1a552fd]72 void (*sigev_notify_function)(union posix_sigval); /* Notification function. */
[fa9815d9]73 posix_thread_attr_t *sigev_notify_attributes; /* Notification attributes. */
74};
75
76typedef struct {
77 int si_signo;
78 int si_code;
79
80 int si_errno;
81
[7530a00]82 posix_pid_t si_pid;
83 posix_uid_t si_uid;
[fa9815d9]84 void *si_addr;
85 int si_status;
86
87 long si_band;
88
89 union posix_sigval si_value;
90} posix_siginfo_t;
91
92struct posix_sigaction {
93 void (*sa_handler)(int);
94 posix_sigset_t sa_mask;
95 int sa_flags;
96 void (*sa_sigaction)(int, posix_siginfo_t *, void *);
97};
98
99typedef struct {
100 void *ss_sp;
101 size_t ss_size;
102 int ss_flags;
103} posix_stack_t;
104
105typedef struct posix_ucontext {
106 struct posix_ucontext *uc_link;
107 posix_sigset_t uc_sigmask;
108 posix_stack_t uc_stack;
109 posix_mcontext_t uc_mcontext;
110} posix_ucontext_t;
111
112/* Values of posix_sigevent::sigev_notify */
113#undef SIGEV_NONE
114#undef SIGEV_SIGNAL
115#undef SIGEV_THREAD
[d3ce33fa]116#define SIGEV_NONE 0
117#define SIGEV_SIGNAL 0
[fa9815d9]118#define SIGEV_THREAD 0
119
120#undef SIGRT_MIN
121#undef SIGRT_MAX
[d3ce33fa]122#define SIGRT_MIN 0
[fa9815d9]123#define SIGRT_MAX 0
124
125#undef SIG_BLOCK
126#undef SIG_UNBLOCK
127#undef SIG_SETMASK
[d3ce33fa]128#define SIG_BLOCK 0
129#define SIG_UNBLOCK 1
130#define SIG_SETMASK 2
[fa9815d9]131
132#undef SA_NOCLDSTOP
133#undef SA_ONSTACK
134#undef SA_RESETHAND
135#undef SA_RESTART
136#undef SA_SIGINFO
137#undef SA_NOCLDWAIT
138#undef SA_NODEFER
[d3ce33fa]139#define SA_NOCLDSTOP (1 << 0)
140#define SA_ONSTACK (1 << 1)
141#define SA_RESETHAND (1 << 2)
142#define SA_RESTART (1 << 3)
143#define SA_SIGINFO (1 << 4)
144#define SA_NOCLDWAIT (1 << 5)
145#define SA_NODEFER (1 << 6)
[fa9815d9]146
147#undef SS_ONSTACK
148#undef SS_DISABLE
[d3ce33fa]149#define SS_ONSTACK 0
[fa9815d9]150#define SS_DISABLE 0
151
152#undef MINSIGSTKSZ
153#undef SIGSTKSZ
[d3ce33fa]154#define MINSIGSTKSZ 0
[fa9815d9]155#define SIGSTKSZ 0
[098eeba3]156
[4cf8ca6]157/* Full POSIX set */
[098eeba3]158enum {
[d3ce33fa]159 /* Termination Signals */
[098eeba3]160 SIGABRT,
[d3ce33fa]161 SIGQUIT,
162 SIGINT,
163 SIGTERM,
164
165 /* Child Signal */
[098eeba3]166 SIGCHLD,
[d3ce33fa]167
168 /* User signals */
169 SIGUSR1,
170 SIGUSR2,
171
172 /* Timer */
173 SIGALRM,
174 SIGVTALRM,
175 SIGPROF, /* obsolete */
176
177 _TOP_CATCHABLE_SIGNAL = SIGPROF,
178
179 /* Process Scheduler Interaction - not supported */
180 SIGSTOP,
[098eeba3]181 SIGCONT,
[d3ce33fa]182
183 /* Process Termination - can't be caught */
184 SIGKILL,
185
186 _TOP_SENDABLE_SIGNAL = SIGKILL,
187
188 /* Hardware Exceptions - can't be caught or sent */
[098eeba3]189 SIGFPE,
[d3ce33fa]190 SIGBUS,
[098eeba3]191 SIGILL,
192 SIGSEGV,
[d3ce33fa]193
194 /* Other Exceptions - not supported */
[098eeba3]195 SIGSYS,
[d3ce33fa]196 SIGXCPU,
197 SIGXFSZ,
198
199 /* Debugging - not supported */
[098eeba3]200 SIGTRAP,
[d3ce33fa]201
202 /* Communication Signals - not supported */
203 SIGHUP,
204 SIGPIPE,
205 SIGPOLL, /* obsolete */
[098eeba3]206 SIGURG,
[d3ce33fa]207
208 /* Terminal Signals - not supported */
209 SIGTSTP,
210 SIGTTIN,
211 SIGTTOU,
212
213 _TOP_SIGNAL = SIGTTOU
[098eeba3]214};
215
[d3ce33fa]216/* Values for sigaction field si_code. */
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
[7530a00]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);
[d3ce33fa]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);
[7530a00]270
[1a552fd]271extern int posix_sigemptyset(posix_sigset_t *set);
[d3ce33fa]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);
[1a552fd]279extern int posix_sigprocmask(int how, const posix_sigset_t *restrict set,
280 posix_sigset_t *restrict oset);
281
[491e1ee]282#ifndef LIBPOSIX_INTERNAL
[4f4b4e7]283 #define sig_atomic_t posix_sig_atomic_t
[fa9815d9]284 #define sigset_t posix_sigset_t
285 #define sigval posix_sigval
[3f466c33]286 #ifndef sigevent
287 #define sigevent posix_sigevent
288 #endif
[fa9815d9]289 #define mcontext_t posix_mcontext_t
290 #define ucontext_t posix_ucontext_t
291 #define stack_t posix_stack_t
292 #define siginfo_t posix_siginfo_t
[7530a00]293
[4cf8ca6]294 #define sigaction posix_sigaction
295
[7530a00]296 #define signal posix_signal
297 #define raise posix_raise
298 #define kill posix_kill
[d3ce33fa]299 #define killpg posix_killpg
300
301 #define psiginfo posix_psiginfo
302 #define psignal posix_psignal
303
[1a552fd]304 #define sigemptyset posix_sigemptyset
[d3ce33fa]305 #define sigfillset posix_sigfillset
306 #define sigaddset posix_sigaddset
307 #define sigdelset posix_sigdelset
308 #define sigismember posix_sigismember
309
310 #define pthread_sigmask posix_thread_sigmask
[1a552fd]311 #define sigprocmask posix_sigprocmask
[4f4b4e7]312#endif
313
[098eeba3]314#endif /* POSIX_SIGNAL_H_ */
315
[4f4b4e7]316/** @}
317 */
Note: See TracBrowser for help on using the repository browser.