* include/signal.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_SIGNAL_H
#define __INCLUDE_SIGNAL_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <time.h>
* Pre-processor Definitions
****************************************************************************/
#define MIN_SIGNO 1
#define MAX_SIGNO 63
#define SIGSTDMIN 1
#define SIGSTDMAX 31
#define SIGRTMIN (SIGSTDMAX + 1)
#define SIGRTMAX MAX_SIGNO
#define _NSIG (MAX_SIGNO + 1)
#define NSIG _NSIG
* _SIGSET_NELEM is the allocated isze of the array
*/
#define _SIGSET_NELEM ((_NSIG + 31) >> 5)
* are referred to as "real time" signals. The default action of all NuttX
* signals is to simply ignore the signal. Certain signals can be
* configured to support there default actions as indicated by NOTEs to the
* following table.
*
* This is not POSIX compliant behavior! Per OpenGroup.org: The following
* signals and default signal actions must be supported on all
* implementations:
*
* ---------- ------- ----------------------------------------------------
* Signal Default Description
* Name Action
* ---------- ------- ----------------------------------------------------
* SIGABRT A Process abort signal
* SIGALRM T (1) Alarm clock
* SIGBUS A Access to an undefined portion of a memory object
* SIGCHLD I Child process terminated, stopped
* (or continued XSI extension)
* SIGCONT C (2) Continue executing, if stopped
* SIGFPE A Erroneous arithmetic operation
* SIGHUP T Hangup
* SIGILL A Illegal instruction
* SIGINT T (3) Terminal interrupt signal
* SIGKILL T (3) Kill (cannot be caught or ignored)
* SIGPIPE T (7) Write on a pipe with no one to read it
* SIGQUIT A Terminal quit signal
* SIGSEGV A Invalid memory reference
* SIGSTOP S (2) Stop executing (cannot be caught or ignored)
* SIGTERM T Termination signal
* SIGTSTP S (2) Terminal stop signal
* SIGTTIN S Background process attempting read
* SIGTTOU S Background process attempting write
* SIGUSR1 T (4) User-defined signal 1
* SIGUSR2 T (5) User-defined signal 2
* SIGPOLL T (6) Poll-able event (XSI extension)
* SIGPROF T Profiling timer expired (XSI extension)
* SIGSYS A Bad system call (XSI extension)
* SIGTRAP A Trace/breakpoint trap (XSI extension)
* SIGURG I High bandwidth data is available at a socket
* SIGVTALRM T Virtual timer expired (XSI extension)
* SIGXCPU A CPU time limit exceeded (XSI extension)
* SIGXFSZ A File size limit exceeded (XSI extension)
* ---------- ------- ----------------------------------------------------
*
* Where default action codes are:
*
* T Abnormal termination of the process. The process is terminated with
* all the consequences of _exit() except that the status made available
* to wait() and waitpid() indicates abnormal termination by the
* specified signal.
* A Abnormal termination of the process. Additionally with the XSI
* extension, implementation-defined abnormal termination actions, such
* as creation of a core file, may occur.
* I Ignore the signal.
* S Stop the process.
* C Continue the process, if it is stopped; otherwise, ignore the signal.
*
* NOTES:
* (1) The default action can be enabled with CONFIG_SIG_SIGALRM_ACTION
* (2) The default action can be enabled with CONFIG_SIG_SIGSTOP_ACTION
* (3) The default action can be enabled with CONFIG_SIG_SIGKILL_ACTION
* (4) The default action can be enabled with CONFIG_SIG_SIGUSR1_ACTION
* (5) The default action can be enabled with CONFIG_SIG_SIGUSR2_ACTION
* (6) The default action can be enabled with CONFIG_SIG_SIGPOLL_ACTION
* (7) The default action can be enabled with CONFIG_SIG_SIGPIPE_ACTION
*/
* default values that can be overridden from the configuration file. The
* rest are all standard or user real-time signals.
*
* The signal number zero is wasted for the most part. It is a valid
* signal number, but has special meaning at many interfaces (e.g., Kill()).
*
* These are the semi-standard signal definitions:
*/
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGPOLL 29
#define SIGIO SIGPOLL
#define SIGSYS 31
#define SIGIOT SIGABRT
* Only one of the following can be specified:
*/
#define SIG_BLOCK 1
#define SIG_UNBLOCK 2
#define SIG_SETMASK 3
#define SA_NOCLDSTOP (1 << 0)
* children stop (ignored) */
#define SA_SIGINFO (1 << 1)
* with 3 args instead of 1
* (always assumed) */
#define SA_NOCLDWAIT (1 << 2)
* processes will be discarded */
#define SA_ONSTACK (1 << 3)
* will be used */
#define SA_RESTART (1 << 4)
* (which were the default long ago) */
#define SA_NODEFER (1 << 5)
* being masked in the handler */
#define SA_RESETHAND (1 << 6)
* is delivered */
#define SA_KERNELHAND (1 << 7)
#define SA_NOMASK SA_NODEFER
#define SI_USER 0
#define SI_QUEUE 1
#define SI_TIMER 2
#define SI_ASYNCIO 3
#define SI_MESGQ 4
#define CLD_EXITED 5
#define CLD_KILLED 6
#define CLD_DUMPED 7
#define CLD_TRAPPED 8
#define CLD_STOPPED 9
#define CLD_CONTINUED 10
#define ILL_ILLOPC 1
#define ILL_ILLOPN 2
#define ILL_ILLADR 3
#define ILL_ILLTRP 4
#define ILL_PRVOPC 5
#define ILL_PRVREG 6
#define ILL_COPROC 7
#define ILL_BADSTK 8
#define FPE_INTDIV 1
#define FPE_INTOVF 2
#define FPE_FLTDIV 3
#define FPE_FLTOVF 4
#define FPE_FLTUND 5
#define FPE_FLTRES 6
#define FPE_FLTINV 7
#define FPE_FLTSUB 8
#define SEGV_MAPERR 1
#define SEGV_ACCERR 2
#define BUS_ADRALN 1
#define BUS_ADRERR 2
#define BUS_OBJERR 3
#define TRAP_BRKPT 1
#define TRAP_TRACE 2
#define POLL_IN 1
#define POLL_OUT 2
#define POLL_MSG 3
#define POLL_ERR 4
#define POLL_PRI 5
#define POLL_HUP 6
#define SIGEV_NONE 0
#define SIGEV_SIGNAL 1
#ifdef CONFIG_SIG_EVTHREAD
# define SIGEV_THREAD 2
#endif
#define SIGEV_THREAD_ID 4
#define MINSIGSTKSZ CONFIG_PTHREAD_STACK_MIN
#define SIGSTKSZ CONFIG_PTHREAD_STACK_DEFAULT
#define SS_ONSTACK 1
#define SS_DISABLE 2
* treated like NULL for now. This is okay for SIG_DFL and SIG_IGN because
* in NuttX, the default action for all signals is to ignore them.
*/
#define SIG_ERR ((_sa_handler_t)-1)
#define SIG_IGN ((_sa_handler_t)0)
#ifdef CONFIG_SIG_DEFAULT
# define SIG_DFL ((_sa_handler_t)1)
# define SIG_HOLD ((_sa_handler_t)2)
#else
# define SIG_DFL ((_sa_handler_t)0)
# define SIG_HOLD ((_sa_handler_t)1)
#endif
#define GOOD_SIGNO(s) (((unsigned)(s)) <= ((unsigned)(MAX_SIGNO)))
#define UNCAUGHT_SIGNO(s) ((s) == SIGKILL || (s) == SIGSTOP)
#define tkill(tid, signo) tgkill((pid_t)-1, tid, signo)
* Public Types
****************************************************************************/
* REVISIT: Signal 0 is, however, not generally usable since that value has
* special meaning in some circumstances (e.g., kill()).
*/
struct sigset_s
{
uint32_t _elem[_SIGSET_NELEM];
};
typedef struct sigset_s sigset_t;
* as an atomic entity, even in the presence of asynchronous interrupts.
*/
typedef volatile int sig_atomic_t;
union sigval
{
int sival_int;
FAR void *sival_ptr;
};
* The following is used to attach a signal to a message queue
* to notify a task when a message is available on a queue.
*/
typedef CODE void (*sigev_notify_function_t)(union sigval);
typedef struct sigevent
{
int sigev_notify;
int sigev_signo;
union sigval sigev_value;
union
{
#ifdef CONFIG_SIG_EVTHREAD
struct
{
sigev_notify_function_t _function;
FAR struct pthread_attr_s *_attribute;
} _sigev_thread;
#endif
pid_t _tid;
} _sigev_un;
} sigevent_t;
#ifdef CONFIG_SIG_EVTHREAD
# define sigev_notify_function _sigev_un._sigev_thread._function
# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
#endif
#define sigev_notify_thread_id _sigev_un._tid
struct siginfo
{
int si_signo;
int si_code;
uint8_t si_errno;
union sigval si_value;
#ifdef CONFIG_SCHED_HAVE_PARENT
pid_t si_pid;
int si_status;
#endif
#if 0
FAR void *si_addr;
#endif
FAR void *si_user;
};
typedef struct siginfo siginfo_t;
* These should be used only internally within the NuttX signal logic.
*/
typedef CODE void (*_sa_handler_t)(int);
typedef CODE void (*_sa_sigaction_t)(int, FAR siginfo_t *,
FAR void *);
typedef _sa_handler_t sighandler_t;
struct sigaction
{
union
{
_sa_handler_t _sa_handler;
_sa_sigaction_t _sa_sigaction;
} sa_u;
sigset_t sa_mask;
int sa_flags;
union
{
CODE void (*sa_restorer)(void);
FAR void *sa_user;
};
};
#define sa_handler sa_u._sa_handler
#define sa_sigaction sa_u._sa_sigaction
typedef struct
{
FAR void *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
typedef CODE void (*sig_t)(int);
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
int kill(pid_t, int);
int killpg(pid_t, int);
int tgkill(pid_t, pid_t, int);
void psignal(int, FAR const char *);
void psiginfo(FAR const siginfo_t *, FAR const char *);
int raise(int);
int sigaction(int, FAR const struct sigaction *,
FAR struct sigaction *);
int sigaddset(FAR sigset_t *, int);
int sigandset(FAR sigset_t *, FAR const sigset_t *,
FAR const sigset_t *);
int sigdelset(FAR sigset_t *, int);
int sigemptyset(FAR sigset_t *);
int sigfillset(FAR sigset_t *);
int sighold(int);
int sigisemptyset(FAR sigset_t *);
int sigismember(FAR const sigset_t *, int);
int sigignore(int);
_sa_handler_t signal(int, _sa_handler_t);
int sigorset(FAR sigset_t *, FAR const sigset_t *,
FAR const sigset_t *);
int sigpause(int);
int sigpending(FAR sigset_t *);
int sigprocmask(int, FAR const sigset_t *, FAR sigset_t *);
int sigqueue(int, int, const union sigval);
int sigrelse(int);
_sa_handler_t sigset(int, _sa_handler_t);
int sigwait(FAR const sigset_t *, FAR int *);
int sigtimedwait(FAR const sigset_t *, FAR struct siginfo *,
FAR const struct timespec *);
int sigsuspend(FAR const sigset_t *);
int sigwaitinfo(FAR const sigset_t *, FAR struct siginfo *);
int sigaltstack(FAR const stack_t *, FAR stack_t *);
int siginterrupt(int, int);
int pthread_kill(pthread_t, int);
int pthread_sigmask(int, FAR const sigset_t *, FAR sigset_t *);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif