MentOS  0.8.0
The Mentoring Operating System
signal.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "sys/types.h"
9 #include "stddef.h"
10 
12 typedef enum {
13  SIGHUP = 1,
14  SIGINT = 2,
15  SIGQUIT = 3,
16  SIGILL = 4,
17  SIGTRAP = 5,
18  SIGABRT = 6,
19  SIGEMT = 7,
20  SIGFPE = 8,
21  SIGKILL = 9,
22  SIGBUS = 10,
23  SIGSEGV = 11,
24  SIGSYS = 12,
25  SIGPIPE = 13,
26  SIGALRM = 14,
27  SIGTERM = 15,
28  SIGUSR1 = 16,
29  SIGUSR2 = 17,
30  SIGCHLD = 18,
31  SIGPWR = 19,
32  SIGWINCH = 20,
33  SIGURG = 21,
34  SIGPOLL = 22,
35  SIGSTOP = 23,
36  SIGTSTP = 24,
37  SIGCONT = 25,
38  SIGTTIN = 26,
39  SIGTTOU = 27,
40  SIGVTALRM = 28,
41  SIGPROF = 29,
42  SIGXCPU = 30,
43  SIGXFSZ = 31,
44  NSIG
46 
48 typedef enum {
50 
51  // Signal : -
52  // Enabled fields : si_pid, si_uid
54 
55  // Signal : -
56  // Enabled fields : -
58 
59  // Signal : -
60  // Enabled fields : si_pid, si_uid, si_value
65 
66  // Signal : SIGILL
67  // Enabled fields : si_addr (address of failing instruction)
76 
77  // Signal : SIGFPE
78  // Enabled fields : si_addr (address of failing instruction)
87 
88  // Signal : SIGSEGV
89  // Enabled fields : si_addr (address of faulting memory reference)
92 
93  // Signal : SIGBUS
94  // Enabled fields : si_addr (address of faulting memory reference)
98 
99  // Signal : SIGTRAP
100  // Enabled fields : -
103 
104  // Signal : SIGCHLD
105  // Enabled fields : si_pid (child process ID)
106  // si_uid (real user ID of process that sent the signal)
107  // si_status (exit value or signal)
114 
115  // Signal : SIGIO/SIGPOLL
116  // Enabled fields : si_band
124 
126 typedef enum {
137 
140 
141 #define SA_NOCLDSTOP 0x00000001U
142 #define SA_NOCLDWAIT 0x00000002U
143 #define SA_SIGINFO 0x00000004U
144 #define SA_ONSTACK 0x08000000U
145 #define SA_RESTART 0x10000000U
146 #define SA_NODEFER 0x40000000U
147 #define SA_RESETHAND 0x80000000U
148 
150 
152 typedef void (*sighandler_t)(int);
153 
154 #define SIG_DFL ((sighandler_t)0)
155 #define SIG_IGN ((sighandler_t)1)
156 #define SIG_ERR ((sighandler_t)-1)
157 
165 typedef struct sigset {
167  unsigned long sig[2];
169 
171 typedef struct sigaction {
180  unsigned int sa_flags;
182 
184 typedef union sigval {
185  int sival_int;
186  void *sival_ptr;
188 
190 typedef struct siginfo {
192  int si_signo;
194  int si_code;
198  int si_errno;
204  void *si_addr;
208  int si_band;
210 
215 int kill(pid_t pid, int sig);
216 
221 sighandler_t signal(int signum, sighandler_t handler);
222 
228 int sigaction(int signum, const sigaction_t *act, sigaction_t *oldact);
229 
239 int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
240 
244 const char *strsignal(int sig);
245 
249 int sigemptyset(sigset_t *set);
250 
254 int sigfillset(sigset_t *set);
255 
260 int sigaddset(sigset_t *set, int signum);
261 
266 int sigdelset(sigset_t *set, int signum);
267 
273 int sigismember(sigset_t *set, int signum);
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
Examine and change blocked signals.
int sigaction(int signum, const sigaction_t *act, sigaction_t *oldact)
Examine and change a signal action.
Definition: signal.c:62
int kill(pid_t pid, int sig)
Send signal to a process.
sighandler_t signal(int signum, sighandler_t handler)
Sets the disposition of the signal signum to handler.
Definition: signal.c:55
signed int pid_t
The type of process id.
Definition: types.h:9
signal_type_t
Signal codes.
Definition: signal.h:14
@ SIGTTOU
Terminal output for background process.
Definition: signal.h:41
@ SIGURG
Urgent condition on socket.
Definition: signal.h:35
@ SIGQUIT
Issued if the user sends a quit signal (Ctrl + D).
Definition: signal.h:17
@ SIGXCPU
CPU time limit exceeded.
Definition: signal.h:44
@ SIGPROF
Profiling timer expired.
Definition: signal.h:43
@ SIGILL
Illegal Instruction.
Definition: signal.h:18
@ SIGXFSZ
File size limit exceeded.
Definition: signal.h:45
@ SIGCONT
Continue if stopped.
Definition: signal.h:39
@ SIGWINCH
Window resize signal.
Definition: signal.h:34
@ SIGABRT
Abort signal from abort().
Definition: signal.h:20
@ SIGSYS
Bad system call (SVr4).
Definition: signal.h:26
@ SIGTERM
Software termination signal (sent by kill by default).
Definition: signal.h:29
@ SIGSEGV
Invalid memory reference.
Definition: signal.h:25
@ SIGUSR1
User-defined signal 1.
Definition: signal.h:30
@ SIGCHLD
Child stopped or terminated.
Definition: signal.h:32
@ SIGPWR
Power failure.
Definition: signal.h:33
@ SIGEMT
Emulator trap.
Definition: signal.h:21
@ SIGHUP
Hang up detected on controlling terminal or death of controlling process.
Definition: signal.h:15
@ SIGTTIN
Terminal input for background process.
Definition: signal.h:40
@ SIGINT
Issued if the user sends an interrupt signal (Ctrl + C).
Definition: signal.h:16
@ SIGTSTP
Stop typed at terminal.
Definition: signal.h:38
@ SIGKILL
If a process gets this signal it must quit immediately and will not perform any clean-up operations.
Definition: signal.h:23
@ SIGFPE
Floating-point arithmetic exception.
Definition: signal.h:22
@ SIGPOLL
Pollable event.
Definition: signal.h:36
@ SIGUSR2
User-defined signal 2.
Definition: signal.h:31
@ SIGPIPE
Broken pipe: write to pipe with no readers.
Definition: signal.h:27
@ SIGTRAP
Trace/breakpoint trap.
Definition: signal.h:19
@ SIGALRM
Alarm clock signal (used for timers).
Definition: signal.h:28
@ SIGSTOP
Stop process.
Definition: signal.h:37
@ SIGBUS
Bus error (bad memory access).
Definition: signal.h:24
@ SIGVTALRM
Virtual alarm clock.
Definition: signal.h:42
signal_sender_code_t
Codes that indentify the sender of a signal.
Definition: signal.h:50
@ POLL_OUT
Output buffers available.
Definition: signal.h:120
@ ILL_ILLOPC
Illegal opcode.
Definition: signal.h:70
@ CLD_STOPPED
Child has stopped.
Definition: signal.h:114
@ SEGV_MAPERR
Address not mapped.
Definition: signal.h:92
@ FPE_FLTINV
Invalid floating point operation.
Definition: signal.h:87
@ CLD_KILLED
Child has terminated abnormally and did not create a core file.
Definition: signal.h:111
@ CLD_EXITED
Child has exited.
Definition: signal.h:110
@ SEGV_ACCERR
Invalid permissions.
Definition: signal.h:93
@ ILL_ILLTRP
Illegal trap.
Definition: signal.h:73
@ POLL_IN
Data input available.
Definition: signal.h:119
@ BUS_OBJERR
Object-specific hardware error.
Definition: signal.h:99
@ FPE_INTOVF
Integer overflow.
Definition: signal.h:82
@ BUS_ADRALN
Invalid address alignment.
Definition: signal.h:97
@ CLD_DUMPED
Child has terminated abnormally and created a core file.
Definition: signal.h:112
@ FPE_INTDIV
Integer divide-by-zero.
Definition: signal.h:81
@ ILL_PRVOPC
Privileged opcode.
Definition: signal.h:74
@ FPE_FLTSUB
Subscript out of range.
Definition: signal.h:88
@ ILL_ILLADR
Illegal addressing mode.
Definition: signal.h:72
@ POLL_PRI
High priority input available.
Definition: signal.h:123
@ SI_ASYNCIO
Signal was generated by completion of an asynchronous I/O request.
Definition: signal.h:65
@ SI_MESGQ
Signal was generated by arrival of a message on an empty message queue.
Definition: signal.h:66
@ TRAP_TRACE
Process trace trap.
Definition: signal.h:104
@ TRAP_BRKPT
Process breakpoint.
Definition: signal.h:103
@ SI_NOINFO
Unable to determine complete signal information.
Definition: signal.h:51
@ BUS_ADRERR
Non-existent physical address.
Definition: signal.h:98
@ CLD_TRAPPED
Traced child has trapped.
Definition: signal.h:113
@ FPE_FLTRES
Floating point inexact result.
Definition: signal.h:86
@ SI_QUEUE
Signal was sent by sigqueue().
Definition: signal.h:63
@ SI_TIMER
Signal was generated by expiration of a timer set by timer_settimer().
Definition: signal.h:64
@ FPE_FLTDIV
Floating point divide-by-zero.
Definition: signal.h:83
@ SI_USER
Signal sent by kill(), pthread_kill(), raise(), abort() or alarm().
Definition: signal.h:55
@ FPE_FLTOVF
Floating point overflow.
Definition: signal.h:84
@ ILL_COPROC
Coprocessor error.
Definition: signal.h:76
@ SI_KERNEL
Generic kernel function.
Definition: signal.h:59
@ CLD_CONTINUED
Stopped child has continued.
Definition: signal.h:115
@ ILL_PRVREG
Privileged register.
Definition: signal.h:75
@ FPE_FLTUND
Floating point underflow.
Definition: signal.h:85
@ POLL_ERR
I/O error.
Definition: signal.h:122
@ ILL_ILLOPN
Illegal operand.
Definition: signal.h:71
@ POLL_MSG
Input message available.
Definition: signal.h:121
@ POLL_HUP
Device disconnected.
Definition: signal.h:124
@ ILL_BADSTK
Internal stack error.
Definition: signal.h:77
struct sigaction_t sigaction_t
Holds the information on how to handle a specific signal.
union sigval sigval_t
Data passed with signal info.
int sigismember(sigset_t *set, int signum)
Checks if the given signal is part of the set.
Definition: signal.c:912
int sigemptyset(sigset_t *set)
Prepare an empty set.
Definition: signal.c:876
void(* sighandler_t)(int)
Type of a signal handler.
Definition: signal.h:154
int sigfillset(sigset_t *set)
Prepare a full set.
Definition: signal.c:885
struct sigset_t sigset_t
Structure used to mask and unmask signals.
int sigdelset(sigset_t *set, int signum)
Removes the given signal to the correct set.
Definition: signal.c:903
sigmask_how_t
Defines what to do with the provided signal mask.
Definition: signal.h:128
@ SIG_BLOCK
The set of blocked signals is the union of the current set and the set argument.
Definition: signal.h:131
@ SIG_UNBLOCK
The signals in set are removed from the current set of blocked signals. It is permissible to attempt ...
Definition: signal.h:135
@ SIG_SETMASK
The set of blocked signals is set to the argument set.
Definition: signal.h:137
int sigaddset(sigset_t *set, int signum)
Adds the given signal to the correct set.
Definition: signal.c:894
struct siginfo_t siginfo_t
Stores information about an occurrence of a specific signal.
const char * strsignal(int sig)
Returns the string describing the given signal.
Definition: signal.c:868
Define basic data types.
int uid_t
The type of user-id.
Definition: stddef.h:40
Holds the information on how to handle a specific signal.
Definition: signal.h:173
Holds the information on how to handle a specific signal.
Definition: signal.h:171
sighandler_t sa_handler
Definition: signal.h:176
unsigned int sa_flags
This set of flags specifies how the signal must be handled;.
Definition: signal.h:180
sigset_t sa_mask
This sigset_t variable specifies the signals to be masked when running the signal handler.
Definition: signal.h:178
Stores information about an occurrence of a specific signal.
Definition: signal.h:190
pid_t si_pid
Process ID of sending process.
Definition: signal.h:200
int si_signo
The signal number.
Definition: signal.h:192
int si_status
Exit value or signal for process termination.
Definition: signal.h:206
void * si_addr
Address at which fault occurred.
Definition: signal.h:204
int si_code
A code identifying who raised the signal (see signal_sender_code_t).
Definition: signal.h:194
int si_errno
The error code of the instruction that caused the signal to be raised, or 0 if there was no error.
Definition: signal.h:198
uid_t si_uid
Real user ID of sending process.
Definition: signal.h:202
int si_band
Band event for SIGPOLL/SIGIO.
Definition: signal.h:208
sigval_t si_value
Signal value.
Definition: signal.h:196
Structure used to mask and unmask signals.
Definition: signal.h:167
Structure used to mask and unmask signals.
Definition: signal.h:165
unsigned long sig[2]
Signals divided into two cathegories.
Definition: signal.h:167
Data passed with signal info.
Definition: signal.h:196
int sival_int
Integer value.
Definition: signal.h:197
void * sival_ptr
Pointer value.
Definition: signal.h:198