Tizen RT Libs&Environment  v1.0 D5
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 /* sigprocmask() "how" definitions. Only one of the following can be specified: */
166 
167 #define SIG_BLOCK 1 /* Block the given signals */
168 #define SIG_UNBLOCK 2 /* Unblock the given signals */
169 #define SIG_SETMASK 3 /* Set the signal mask to the current set */
170 
171 /* struct sigaction flag values */
172 
173 #define SA_NOCLDSTOP (1 << 0) /* Do not generate SIGCHILD when
174  * children stop (ignored) */
175 #define SA_SIGINFO (1 << 1) /* Invoke the signal-catching function
176  * with 3 args instead of 1
177  * (always assumed) */
178 #define SA_NOCLDWAIT (1 << 2) /* If signo=SIGCHLD, exit status of child
179  * processes will be discarded */
180 
181 /* These are the possible values of the signfo si_code field */
182 
183 #define SI_USER 0 /* Signal sent from kill, raise, or abort */
184 #define SI_QUEUE 1 /* Signal sent from sigqueue */
185 #define SI_TIMER 2 /* Signal is result of timer expiration */
186 #define SI_ASYNCIO 3 /* Signal is the result of asynch IO completion */
187 #define SI_MESGQ 4 /* Signal generated by arrival of a message on an */
188 /* empty message queue */
189 #define CLD_EXITED 5 /* Child has exited (SIGCHLD only) */
190 #define CLD_KILLED 6 /* Child was killed (SIGCHLD only) */
191 #define CLD_DUMPED 7 /* Child terminated abnormally (SIGCHLD only) */
192 #define CLD_TRAPPED 8 /* Traced child has trapped (SIGCHLD only) */
193 #define CLD_STOPPED 9 /* Child has stopped (SIGCHLD only) */
194 #define CLD_CONTINUED 10 /* Stopped child had continued (SIGCHLD only) */
195 
196 /* Values for the sigev_notify field of struct sigevent */
197 
198 #define SIGEV_NONE 0 /* No notification desired */
199 #define SIGEV_SIGNAL 1 /* Notify via signal */
200 
201 /* Special values of sigaction (all treated like NULL) */
202 
203 #define SIG_ERR ((CODE void*)-1)
204 #define SIG_DFL ((CODE void*)0)
205 #define SIG_IGN ((CODE void*)0)
206 
207 /********************************************************************************
208  * Global Type Declarations
209  ********************************************************************************/
210 
211 /* This defines a set of 32 signals (numbered 0 through 31). */
212 
213 typedef uint32_t sigset_t; /* Bit set of 32 signals */
214 
219 union sigval {
220  int sival_int; /* Integer value */
221  FAR void *sival_ptr; /* Pointer value */
222 };
223 
230 struct sigevent {
231  uint8_t sigev_notify; /* Notification method: SIGEV_SIGNAL or SIGEV_NONE */
232  uint8_t sigev_signo; /* Notification signal */
233  union sigval sigev_value; /* Data passed with notification */
234 };
235 
240 struct siginfo {
241  uint8_t si_signo; /* Identifies signal */
242  uint8_t si_code; /* Source: SI_USER, SI_QUEUE, SI_TIMER, SI_ASYNCIO, or SI_MESGQ */
243  union sigval si_value; /* Data passed with signal */
244 #ifdef CONFIG_SCHED_HAVE_PARENT
245  pid_t si_pid; /* Sending task ID */
246  int si_status; /* Exit value or signal (SIGCHLD only). */
247 #endif
248 };
249 
250 typedef struct siginfo siginfo_t;
251 
252 /* Non-standard convenience definition of signal handling function types.
253  * These should be used only internally within the TinyAra signal logic.
254  */
255 
256 typedef CODE void (*_sa_handler_t)(int);
257 typedef CODE void (*_sa_sigaction_t)(int, FAR siginfo_t *, FAR void *);
258 
263 struct sigaction {
264  union {
267  } sa_u;
269  int sa_flags;
270 };
271 
272 /* Definitions that adjust the non-standard naming */
273 
274 #define sa_handler sa_u._sa_handler
275 #define sa_sigaction sa_u._sa_sigaction
276 
279 /********************************************************************************
280  * Global Variables
281  ********************************************************************************/
282 
283 /********************************************************************************
284  * Global Function Prototypes
285  ********************************************************************************/
286 
287 #ifdef __cplusplus
288 #define EXTERN extern "C"
289 extern "C" {
290 #else
291 #define EXTERN extern
292 #endif
293 
299 int kill(pid_t, int);
300 
309 int sigemptyset(FAR sigset_t *set);
314 int sigfillset(FAR sigset_t *set);
319 int sigaddset(FAR sigset_t *set, int signo);
324 int sigdelset(FAR sigset_t *set, int signo);
329 int sigismember(FAR const sigset_t *set, int signo);
334 int sighold(int signo);
339 int sigrelse(int signo);
349 int sigaction(int sig, FAR const struct sigaction *act, FAR struct sigaction *oact);
356 int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
363 int sigpending(FAR sigset_t *set);
370 int sigsuspend(FAR const sigset_t *sigmask);
377 int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value);
384 int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, FAR const struct timespec *timeout);
391 #ifdef CONFIG_CAN_PASS_STRUCTS
392 int sigqueue(int pid, int signo, union sigval value);
393 #else
394 int sigqueue(int pid, int signo, FAR void *sival_ptr);
395 #endif
396 
397 #undef EXTERN
398 #ifdef __cplusplus
399 }
400 #endif
401 
402 #endif /* __INCLUDE_SIGNAL_H */
CODE void(* _sa_sigaction_t)(int, FAR siginfo_t *, FAR void *)
Definition: signal.h:257
Union for defining the types of the siginfo si_value field.
Definition: signal.h:219
int sigaction(int sig, FAR const struct sigaction *act, FAR struct sigaction *oact)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigrelse(int signo)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigpending(FAR sigset_t *set)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigfillset(FAR sigset_t *set)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
pid_t si_pid
Definition: signal.h:245
int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR void * sival_ptr
Definition: signal.h:221
int si_status
Definition: signal.h:246
Structure for using to pass parameters to/from signal handlers.
Definition: signal.h:240
int sighold(int signo)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigemptyset(FAR sigset_t *set)
POSIX APIs (refer to : http://pubs.pengroup.org/onlinepubs/9699919799/)
int sigsuspend(FAR const sigset_t *sigmask)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, FAR const struct timespec *timeout)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Structure for elements that define a queue signal. The following is used to attach a signal to a mess...
Definition: signal.h:230
int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint8_t si_signo
Definition: signal.h:241
_sa_handler_t _sa_handler
Definition: signal.h:265
uint8_t sigev_signo
Definition: signal.h:232
sigset_t sa_mask
Definition: signal.h:268
int sigqueue(int pid, int signo, FAR void *sival_ptr)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int kill(pid_t, int)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigaddset(FAR sigset_t *set, int signo)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int sigdelset(FAR sigset_t *set, int signo)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint8_t si_code
Definition: signal.h:242
Structure for defining the action to take for given signal.
Definition: signal.h:263
structure represents an elapsed time
Definition: time.h:152
CODE void(* _sa_handler_t)(int)
Definition: signal.h:256
uint32_t sigset_t
Definition: signal.h:213
int sival_int
Definition: signal.h:220
int sa_flags
Definition: signal.h:269
int sigismember(FAR const sigset_t *set, int signo)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
_sa_sigaction_t _sa_sigaction
Definition: signal.h:266
uint8_t sigev_notify
Definition: signal.h:231