devela/sys/os/linux/consts/
signal.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// devela::sys::os::linux::consts::signal
//

#![allow(non_camel_case_types)]

use core::ffi::c_int;

/// Linux flag constants for [`LinuxSigaction`][crate::sys::os::linux::LinuxSigaction].
#[allow(non_camel_case_types)]
pub struct LINUX_SIGACTION;

/// Linux standard signals constants.
///
/// Each signal has a current disposition, which determines how the process
/// behaves when it is delivered the signal.
///
/// - `Term`:   Default action is to terminate the process.
/// - `Ign`:    Default action is to ignore the signal.
/// - `Core`:   Default action is to terminate the process and dump core (see core(5)).
/// - `Stop`:   Default action is to stop the process.
/// - `Cont`:   Default action is to continue the process if it is currently stopped.
///
/// The signals [`SIGKILL`] and [`SIGSTOP`] cannot be caught, blocked, or ignored.
///
/// # Info
/// - <https://man7.org/linux/man-pages/man7/signal.7.html>
///
/// [`SIGKILL`]: Self::SIGKILL
/// [`SIGSTOP`]: Self::SIGSTOP
#[allow(non_camel_case_types)]
pub struct LINUX_SIGNAL;

// 36 signals
impl LINUX_SIGNAL {
    /// Hangup detected on controlling terminal or death of controlling process.
    ///
    /// Default action: `Term`.
    pub const SIGHUP: c_int = 1;

    /// Interrupt from keyboard.
    ///
    /// Default action: `Term`.
    pub const SIGINT: c_int = 2;

    /// Quit from keyboard.
    ///
    /// Default action: `Core`.
    pub const SIGQUIT: c_int = 3;

    /// Illegal Instruction
    ///
    /// Default action: `Core`.
    pub const SIGILL: c_int = 4;

    /// Trace/breakpoint trap.
    ///
    /// Default action: `Core`.
    pub const SIGTRAP: c_int = 5;

    /// Abort signal from [`abort(3)`].
    ///
    /// Default action: `Core`.
    ///
    /// [`abort(3)`]: https://man7.org/linux/man-pages/man3/abort.3.html
    pub const SIGABRT: c_int = 6;

    /// IOT trap. A synonym for [`SIGABRT`][Self::SIGABRT].
    ///
    /// Default action:  
    pub const SIGIOT: c_int = Self::SIGABRT;

    /// Bus error (bad memory access)
    ///
    /// Default action: `Core`.
    pub const SIGBUS: c_int = 7;

    /// Floating-point exception.
    ///
    /// Default action: `Core`.
    pub const SIGFPE: c_int = 8;

    /// Kill signal.
    ///
    /// Default action: `Term`.
    pub const SIGKILL: c_int = 9;

    /// User-defined signal 1.
    ///
    /// Default action: `Term`.
    pub const SIGUSR1: c_int = 10;

    /// Invalid memory reference.
    ///
    /// Default action: `Core`.
    pub const SIGSEGV: c_int = 11;

    /// User-defined signal 2.
    ///
    /// Default action: `Term`.
    pub const SIGUSR2: c_int = 12;

    /// Broken pipe: write to pipe with no readers; see [`pipe(7)`].
    ///
    /// Default action: `Term`.
    ///
    /// [`pipe(7)`]: https://man7.org/linux/man-pages/man7/pipe.7.html
    pub const SIGPIPE: c_int = 13;

    /// Timer signal from [`alarm(2)`].
    ///
    /// Default action: `Term`.
    ///
    /// [`alarm(2)`]: https://man7.org/linux/man-pages/man2/alarm.2.html
    pub const SIGALRM: c_int = 14;

    /// Termination signal.
    ///
    /// Default action: `Term`.
    pub const SIGTERM: c_int = 15;

    /// Stack fault on coprocessor (unused).
    ///
    /// Default action: `Term`.
    pub const SIGSTKFLT: c_int = 16;

    /// Child stopped or terminated.
    ///
    /// Default action: `Ign`.
    pub const SIGCHLD: c_int = 17;

    /// A synonym for [`SIGCHLD`][Self::SIGCHLD].
    pub const SIGCLD: c_int = Self::SIGCHLD;

    /// Continue if stopped.
    ///
    /// Default action: `Cont`.
    pub const SIGCONT: c_int = 18;

    /// Stop process.
    ///
    /// Default action: `Stop`.
    pub const SIGSTOP: c_int = 19;

    /// Stop typed at terminal.
    ///
    /// Default action: `Stop`.
    pub const SIGTSTP: c_int = 20;

    /// Terminal input for background process.
    ///
    /// Default action: `Stop`.
    pub const SIGTTIN: c_int = 21;

    /// Terminal output for background process.
    ///
    /// Default action: `Stop`.
    pub const SIGTTOU: c_int = 22;

    /// Urgent condition on socket (4.2BSD).
    ///
    /// Default action: `Ign`.
    pub const SIGURG: c_int = 23;

    /// CPU time limit exceeded (4.2BSD); see [`setrlimit(2)`].
    ///
    /// Default action: `Core`.
    ///
    /// [`setrlimit(2)`]: https://man7.org/linux/man-pages/man2/setrlimit.2.html
    pub const SIGXCPU: c_int = 24;

    /// File size limit exceeded (4.2BSD); see [`setrlimit(2)`].
    ///
    /// Default action: `Core`.
    ///
    /// [`setrlimit(2)`]: https://man7.org/linux/man-pages/man2/setrlimit.2.html
    pub const SIGXFSZ: c_int = 25;

    /// Virtual alarm clock (4.2BSD).
    ///
    /// Default action: `Term`.
    pub const SIGVTALRM: c_int = 26;

    /// Profiling timer expired.
    ///
    /// Default action: `Term`.
    pub const SIGPROF: c_int = 27;

    /// Window resize signal (4.3BSD, Sun).
    ///
    /// Default action: `Ign`.
    pub const SIGWINCH: c_int = 28;

    /// I/O now possible (4.2BSD).
    ///
    /// Default action: `Term`.
    pub const SIGIO: c_int = 29;

    /// Pollable event (Sys V); synonym for [`SIGIO`][Self::SIGIO].
    pub const SIGPOLL: c_int = Self::SIGIO;

    /// Power failure (System V).
    ///
    /// Default action: `Term`.
    pub const SIGPWR: c_int = 30;

    /// A synonym for [`SIGPWR`][Self::SIGPWR].
    pub const SIGINFO: c_int = Self::SIGPWR;

    /// Bad system call (SVr4); see also [`seccomp(2)`].
    ///
    /// Default action: `Core`.
    ///
    /// [`seccomp(2)`]: https://man7.org/linux/man-pages/man2/seccomp.2.html
    pub const SIGSYS: c_int = 31;

    /// Synonymous with [`SIGSYS`][Self::SIGSYS].
    pub const SIGUNUSED: c_int = Self::SIGSYS;

    // /// Emulator trap.
    // ///
    // /// Default action: `Term`.
    // pub const SIGEMT: c_int = ?;

    // /// File lock lost (unused).
    // ///
    // /// Default action: `Term`.
    // pub const SIGLOST: c_int = ?
}

// 8 flags
impl LINUX_SIGACTION {
    /// If signum is [`SIGCHLD`], do not receive notification when child processes
    /// stop (i.e., when they receive one of [`SIGSTOP`], [`SIGTSTP`], [`SIGTTIN`],
    /// or [`SIGTTOU`]) or resume (i.e., they receive [`SIGCONT`])
    /// (see [`wait(2)`]).
    ///
    /// This flag is meaningful only when establishing a handler for `SIGCHLD`.
    ///
    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
    /// [`SIGSTOP`]: LINUX_SIGNAL::SIGSTOP
    /// [`SIGTSTP`]: LINUX_SIGNAL::SIGTSTP
    /// [`SIGTTIN`]: LINUX_SIGNAL::SIGTTIN
    /// [`SIGTTOU`]: LINUX_SIGNAL::SIGTTOU
    /// [`SIGCONT`]: LINUX_SIGNAL::SIGCONT
    /// [`wait(2)`]: https://man7.org/linux/man-pages/man2/wait.2.html
    pub const SA_NOCLDSTOP: usize = 0x0000_0001;

    /// If signum is [`SIGCHLD`], do not transform children into
    /// zombies when they terminate.
    ///
    /// See also [`waitpid(2)`].
    ///
    /// This flag is meaningful only when establishing a handler for `SIGCHLD`,
    /// or when setting that signal's disposition to [`SIG_DFL`].
    ///
    /// (since Linux 2.6)
    ///
    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
    /// [`SIG_DFL`]: crate::sys::os::linux::LinuxSigaction::SIG_DFL
    /// [`waitpid(2)`]: https://man7.org/linux/man-pages/man2/wait.2.html
    pub const SA_NOCLDWAIT: usize = 0x0000_0002;

    /// If the [`SA_NOCLDWAIT`] flag is set when establishing a handler for
    /// [`SIGCHLD`], POSIX.1 leaves it unspecified whether a `SIGCHLD` signal is
    /// generated when a child process terminates.
    ///
    /// On Linux, a `SIGCHLD` signal is generated in this case; on some other
    /// implementations, it is not.
    ///
    /// Do not add the signal to the thread's signal mask while the handler is
    /// executing, unless the signal is specified in act.sa_mask.  Consequently,
    /// a further instance of the signal may be delivered to the thread while it
    /// is executing the handler.  This flag is meaningful only when establishing
    /// a signal handler.
    ///
    /// `SA_NOMASK` is an obsolete, nonstandard synonym for this flag.
    ///
    /// [`SIGCHLD`]: LINUX_SIGNAL::SIGCHLD
    /// [`SA_NOCLDWAIT`]: Self::SA_NOCLDWAIT
    pub const SA_NODEFER: usize = 0x4000_0000;

    /// Call the signal handler on an alternate signal stack provided by
    /// [`sigaltstack(2)`].
    ///
    /// If an alternate stack is not available, the default stack will be used.
    /// This flag is meaningful only when establishing a signal handler.
    ///
    /// [`sigaltstack(2)`]: https://man7.org/linux/man-pages/man2/sigaltstack.2.html
    pub const SA_ONSTACK: usize = 0x0800_0000;

    /// Restore the signal action to the default upon entry to the signal handler.
    ///
    /// This flag is meaningful only when establishing a signal handler.
    ///
    /// `SA_ONESHOT` is an obsolete, nonstandard synonym for this flag.
    pub const SA_RESETHAND: usize = 0x8000_0000;

    /// Provide behavior compatible with BSD signal semantics by making certain
    /// system calls restartable across signals. This flag is meaningful only
    /// when establishing a signal handler.  See [`signal(7)`] for a discussion of
    /// system call restarting.
    ///
    /// [`signal(7)`]: https://man7.org/linux/man-pages/man7/signal.7.html
    pub const SA_RESTART: usize = 0x1000_0000;

    /// Not intended for application use.
    ///
    /// This flag is used by C libraries to indicate that the `sa_restorer` field
    /// contains the address of a "signal trampoline".  See [`sigreturn(2)`] for more
    /// details.
    ///
    /// [`sigreturn(2)`]: https://man7.org/linux/man-pages/man2/sigreturn.2.html
    pub const SA_RESTORER: usize = 0x0400_0000;

    /// The signal handler takes three arguments, not one.
    ///
    /// In this case, `sa_sigaction` should be set instead of `sa_handler`.
    ///
    /// This flag is meaningful only when establishing a signal handler.
    ///
    /// (since Linux 2.2)
    pub const SA_SIGINFO: usize = 0x0000_0004;
}