TizenRT Libs&Environment  v2.0 M2
signal.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /********************************************************************************
19  * include/signal.h
20  *
21  * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ********************************************************************************/
60 
63 #ifndef __INCLUDE_SIGNAL_H
64 #define __INCLUDE_SIGNAL_H
65 
66 /********************************************************************************
67  * Included Files
68  ********************************************************************************/
69 
70 #include <tinyara/config.h>
71 #include <tinyara/compiler.h>
72 
73 #include <stdint.h>
74 #include <time.h>
75 
76 /********************************************************************************
77  * Pre-processor Definitions
78  ********************************************************************************/
79 
80 /* Signal set management definitions and macros. */
81 
82 #define NULL_SIGNAL_SET ((sigset_t)0x00000000)
83 #define ALL_SIGNAL_SET ((sigset_t)0xffffffff)
84 #define MIN_SIGNO 0
85 #define MAX_SIGNO 31
86 #define GOOD_SIGNO(s) ((((unsigned)(s)) <= MAX_SIGNO))
87 #define SIGNO2SET(s) ((sigset_t)1 << (s))
88 
89 /* All signals are "real time" signals */
90 
91 #define SIGRTMIN MIN_SIGNO /* First real time signal */
92 #define SIGRTMAX MAX_SIGNO /* Last real time signal */
93 
94 /* A few of the real time signals are used within the OS. They have
95  * default values that can be overridden from the configuration file. The
96  * rest are all user signals.
97  *
98  * The signal number zero is wasted for the most part. It is a valid
99  * signal number, but has special meaning at many interfaces (e.g., Kill()).
100  *
101  * These are the semi-standard signal definitions:
102  */
103 
104 #ifndef CONFIG_SIG_SIGUSR1
105 #define SIGUSR1 1 /* User signal 1 */
106 #else
107 #define SIGUSR1 CONFIG_SIG_SIGUSR1
108 #endif
109 
110 #ifndef CONFIG_SIG_SIGUSR2
111 #define SIGUSR2 2 /* User signal 2 */
112 #else
113 #define SIGUSR2 CONFIG_SIG_SIGUSR2
114 #endif
115 
116 #ifndef CONFIG_SIG_SIGALARM
117 #define SIGALRM 3 /* Default signal used with POSIX timers (used only */
118 /* no other signal is provided) */
119 #else
120 #define SIGALRM CONFIG_SIG_SIGALARM
121 #endif
122 
123 #ifdef CONFIG_SCHED_HAVE_PARENT
124 #ifndef CONFIG_SIG_SIGCHLD
125 #define SIGCHLD 4 /* Used by child threads to signal parent thread */
126 #else
127 #define SIGCHLD CONFIG_SIG_SIGCHLD
128 #endif
129 #endif
130 
131 #ifdef CONFIG_FS_AIO
132 #ifndef CONFIG_SIG_POLL
133 #define SIGPOLL 5 /* Sent when an asynchronous I/O event occurs */
134 #else
135 #define SIGPOLL CONFIG_SIG_POLL
136 #endif
137 #endif
138 
139 #ifndef CONFIG_SIG_SIGKILL
140 #define SIGKILL 9 /* Sent to cause process to terminate */
141 #else
142 #define SIGKILL CONFIG_SIG_SIGKILL
143 #endif
144 
145 /* The following are non-standard signal definitions */
146 
147 #ifndef CONFIG_DISABLE_PTHREAD
148 #ifndef CONFIG_SIG_SIGCONDTIMEDOUT
149 #define SIGCONDTIMEDOUT 16 /* Used in the implementation of pthread_cond_timedwait */
150 #else
151 #define SIGCONDTIMEDOUT CONFIG_SIG_SIGCONDTIMEDOUT
152 #endif
153 #endif
154 
155 /* SIGWORK is used to wake up various internal, TinyAra worker thread */
156 
157 #if defined(CONFIG_SCHED_WORKQUEUE) || defined(CONFIG_PAGING)
158 #ifndef CONFIG_SIG_SIGWORK
159 #define SIGWORK 17 /* Used to wake up the work queue */
160 #else
161 #define SIGWORK CONFIG_SIG_SIGWORK
162 #endif
163 #endif
164 
165 /* SIGTM is used in Task Manager */
166 #ifndef CONFIG_SIG_SIGTM_UNICAST
167 #define SIGTM_UNICAST 18 /* Taskmgt signal */
168 #else
169 #define SIGTM_UNICAST CONFIG_SIG_SIGTM_UNICAST
170 #endif
171 
172 /* SIGTM_PAUSE is used in Task Manager */
173 #ifndef CONFIG_SIG_SIGTM_PAUSE
174 #define SIGTM_PAUSE 19 /* Taskmgt signal */
175 #else
176 #define SIGTM_PAUSE CONFIG_SIG_SIGTM_PAUSE
177 #endif
178 
179 /* SIGTM_RESUME is used in Task Manager */
180 #ifndef CONFIG_SIG_SIGTM_RESUME
181 #define SIGTM_RESUME 20 /* Taskmgt signal */
182 #else
183 #define SIGTM_RESUME CONFIG_SIG_SIGTM_RESUME
184 #endif
185 
186 /* SIGTM_BROADCAST is used in Task Manager */
187 #ifndef CONFIG_SIG_SIGTM_BROADCAST
188 #define SIGTM_BROADCAST 21 /* Taskmgt signal */
189 #else
190 #define SIGTM_BROADCAST CONFIG_SIG_SIGTM_BROADCAST
191 #endif
192 
193 /* SIG_SIGEL_WAKEUP is used in Event Loop */
194 #ifndef CONFIG_SIG_SIGEL_WAKEUP
195 #define SIGEL_WAKEUP 22 /* Eventloop signal */
196 #else
197 #define SIGEL_WAKEUP CONFIG_SIG_SIGEL_WAKEUP
198 #endif
199 
200 /* SIG_SIGTM_TERMINATION is used in Task Manager */
201 #ifndef CONFIG_SIG_SIGTM_TERMINATION
202 #define SIGTM_TERMINATION 23 /* Taskmgt signal */
203 #else
204 #define SIGTM_TERMINATION CONFIG_SIG_SIGTM_TERMINATION
205 #endif
206 
207 /* SIG_SIGEL_EVENT is used for event handling in Event Loop */
208 #ifndef CONFIG_SIG_SIGEL_EVENT
209 #define SIGEL_EVENT 24 /* Eventloop signal */
210 #else
211 #define SIGEL_EVENT CONFIG_SIG_SIGEL_EVENT
212 #endif
213 
214 /* sigprocmask() "how" definitions. Only one of the following can be specified: */
215 
216 #define SIG_BLOCK 1 /* Block the given signals */
217 #define SIG_UNBLOCK 2 /* Unblock the given signals */
218 #define SIG_SETMASK 3 /* Set the signal mask to the current set */
219 
220 /* struct sigaction flag values */
221 
222 #define SA_NOCLDSTOP (1 << 0) /* Do not generate SIGCHILD when
223  * children stop (ignored) */
224 #define SA_SIGINFO (1 << 1) /* Invoke the signal-catching function
225  * with 3 args instead of 1
226  * (always assumed) */
227 #define SA_NOCLDWAIT (1 << 2) /* If signo=SIGCHLD, exit status of child
228  * processes will be discarded */
229 
230 /* These are the possible values of the signfo si_code field */
231 
232 #define SI_USER 0 /* Signal sent from kill, raise, or abort */
233 #define SI_QUEUE 1 /* Signal sent from sigqueue */
234 #define SI_TIMER 2 /* Signal is result of timer expiration */
235 #define SI_ASYNCIO 3 /* Signal is the result of asynch IO completion */
236 #define SI_MESGQ 4 /* Signal generated by arrival of a message on an */
237 /* empty message queue */
238 #define CLD_EXITED 5 /* Child has exited (SIGCHLD only) */
239 #define CLD_KILLED 6 /* Child was killed (SIGCHLD only) */
240 #define CLD_DUMPED 7 /* Child terminated abnormally (SIGCHLD only) */
241 #define CLD_TRAPPED 8 /* Traced child has trapped (SIGCHLD only) */
242 #define CLD_STOPPED 9 /* Child has stopped (SIGCHLD only) */
243 #define CLD_CONTINUED 10 /* Stopped child had continued (SIGCHLD only) */
244 
245 /* Values for the sigev_notify field of struct sigevent */
246 
247 #define SIGEV_NONE 0 /* No notification desired */
248 #define SIGEV_SIGNAL 1 /* Notify via signal */
249 
250 /* Special values of sigaction (all treated like NULL) */
251 
252 #define SIG_ERR ((_sa_handler_t)-1)
253 #define SIG_DFL ((_sa_handler_t)0)
254 #define SIG_IGN ((_sa_handler_t)0)
255 #define SIG_HOLD ((_sa_handler_t)1) /* Used only with sigset() */
256 
257 #define COPY_SIGACTION(t, f) \
258  { \
259  (t)->sa_sigaction = (f)->sa_sigaction; \
260  (t)->sa_mask = (f)->sa_mask; \
261  (t)->sa_flags = (f)->sa_flags; \
262  }
263 
264 /********************************************************************************
265  * Global Type Declarations
266  ********************************************************************************/
267 
268 /* This defines a set of 32 signals (numbered 0 through 31). */
269 
270 typedef uint32_t sigset_t; /* Bit set of 32 signals */
271 
276 union sigval {
277  int sival_int; /* Integer value */
278  FAR void *sival_ptr; /* Pointer value */
279 };
280 
287 struct sigevent {
288  uint8_t sigev_notify; /* Notification method: SIGEV_SIGNAL or SIGEV_NONE */
289  uint8_t sigev_signo; /* Notification signal */
290  union sigval sigev_value; /* Data passed with notification */
291 };
292 
297 struct siginfo {
298  uint8_t si_signo; /* Identifies signal */
299  uint8_t si_code; /* Source: SI_USER, SI_QUEUE, SI_TIMER, SI_ASYNCIO, or SI_MESGQ */
300  union sigval si_value; /* Data passed with signal */
301 #ifdef CONFIG_SCHED_HAVE_PARENT
302  pid_t si_pid; /* Sending task ID */
303  int si_status; /* Exit value or signal (SIGCHLD only). */
304 #endif
305 };
306 
307 typedef struct siginfo siginfo_t;
308 
309 /* Non-standard convenience definition of signal handling function types.
310  * These should be used only internally within the TinyAra signal logic.
311  */
312 
313 typedef CODE void (*_sa_handler_t)(int);
314 typedef CODE void (*_sa_sigaction_t)(int, FAR siginfo_t *, FAR void *);
315 
320 struct sigaction {
321  union {
324  } sa_u;
326  int sa_flags;
327 };
328 
329 /* Definitions that adjust the non-standard naming */
330 
331 #define sa_handler sa_u._sa_handler
332 #define sa_sigaction sa_u._sa_sigaction
333 
337 /********************************************************************************
338  * Global Variables
339  ********************************************************************************/
340 
341 /********************************************************************************
342  * Global Function Prototypes
343  ********************************************************************************/
344 
345 #ifdef __cplusplus
346 #define EXTERN extern "C"
347 extern "C" {
348 #else
349 #define EXTERN extern
350 #endif
351 
359 int kill(pid_t pid, int sig);
360 
371 int sigemptyset(FAR sigset_t *set);
378 int sigfillset(FAR sigset_t *set);
385 int sigaddset(FAR sigset_t *set, int signo);
392 int sigdelset(FAR sigset_t *set, int signo);
399 int sigismember(FAR const sigset_t *set, int signo);
406 int sighold(int sig);
413 int sigignore(int sig);
420 int sigpause(int sig);
427 int raise(int sig);
434 int sigrelse(int sig);
441 CODE void (*sigset(int sig, CODE void (*func)(int sig)))(int sig);
448 CODE void (*signal(int sig, CODE void (*func)(int sig)))(int sig);
461 int sigaction(int sig, FAR const struct sigaction *act, FAR struct sigaction *oact);
470 int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
479 int sigpending(FAR sigset_t *set);
488 int sigsuspend(FAR const sigset_t *sigmask);
497 int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value);
506 int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, FAR const struct timespec *timeout);
515 #ifdef CONFIG_CAN_PASS_STRUCTS
516 int sigqueue(int pid, int signo, union sigval value);
517 #else
518 int sigqueue(int pid, int signo, FAR void *sival_ptr);
519 #endif
520 
521 #undef EXTERN
522 #ifdef __cplusplus
523 }
524 #endif
525 
526 #endif /* __INCLUDE_SIGNAL_H */
CODE void(* _sa_sigaction_t)(int, FAR siginfo_t *, FAR void *)
Definition: signal.h:314
Union for defining the types of the siginfo si_value field.
Definition: signal.h:276
int sigignore(int sig)
signal management
int sigaction(int sig, FAR const struct sigaction *act, FAR struct sigaction *oact)
examine and change a signal action
int sigpause(int sig)
signal management
int sigrelse(int sig)
signal management
CODE void(*)(int sig) sigset(int sig, CODE void(*func)(int sig))
signal management
Definition: signal.h:441
int sigpending(FAR sigset_t *set)
examine pending signals
int sigfillset(FAR sigset_t *set)
initialize and fill a signal set
pid_t si_pid
Definition: signal.h:302
int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
examine and change blocked signals
FAR void * sival_ptr
Definition: signal.h:278
int si_status
Definition: signal.h:303
Structure for using to pass parameters to/from signal handlers.
Definition: signal.h:297
int sigemptyset(FAR sigset_t *set)
initialize and empty a signal set
int sigsuspend(FAR const sigset_t *sigmask)
wait for a signal
int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, FAR const struct timespec *timeout)
wait for queued signals
Structure for elements that define a queue signal. The following is used to attach a signal to a mess...
Definition: signal.h:287
int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value)
wait for queued signals
uint8_t si_signo
Definition: signal.h:298
int sighold(int sig)
signal management
_sa_handler_t _sa_handler
Definition: signal.h:322
uint8_t sigev_signo
Definition: signal.h:289
sigset_t sa_mask
Definition: signal.h:325
CODE void(*)(int sig) signal(int sig, CODE void(*func)(int sig))
signal management
Definition: signal.h:448
int sigaddset(FAR sigset_t *set, int signo)
add a signal to a signal set
int kill(pid_t pid, int sig)
send a signal to a process or a group of processes
int sigdelset(FAR sigset_t *set, int signo)
delete a signal from a signal set
uint8_t si_code
Definition: signal.h:299
Structure for defining the action to take for given signal.
Definition: signal.h:320
structure represents an elapsed time
Definition: time.h:160
CODE void(* _sa_handler_t)(int)
Definition: signal.h:313
uint32_t sigset_t
Definition: signal.h:270
int sival_int
Definition: signal.h:277
int sa_flags
Definition: signal.h:326
int sigqueue(int pid, int signo, union sigval value)
queue a signal to a process
int sigismember(FAR const sigset_t *set, int signo)
test for a signal in a signal set
_sa_sigaction_t _sa_sigaction
Definition: signal.h:323
uint8_t sigev_notify
Definition: signal.h:288