AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
signal.h
Go to the documentation of this file.
1#ifndef _SYS_SIGNAL_H
2#define _SYS_SIGNAL_H
3
4#include <core/system.h>
5
6struct aquila_sigaction;
7
8#include <sys/proc.h>
9
10/* Signals (sys/signal.c). See docs/kernel/signals.md. */
11
12/* the signals' numbers */
13#include <aquila/signal.h>
14
15/* The highest signal number. */
16#define SIG_MAX (NSIG - 1)
17
18/* A signal's default action. */
19#define SIGACT_ABORT 1
20#define SIGACT_TERMINATE 2
21#define SIGACT_IGNORE 3
22#define SIGACT_STOP 4
23#define SIGACT_CONTINUE 5
24
25/* A handler's special values, as the C library's. */
26#define SIG_DFL ((uintptr_t) 0) /* the default action */
27#define SIG_IGN ((uintptr_t) 1) /* ignore the signal */
28#define SIG_ERR ((uintptr_t) -1) /* an error */
29
30/* Each signal's default action (SIGACT_*). */
31extern int sig_default_action[SIG_MAX+1];
32
33/*
34 * Sending a signal makes it pending (a bit for each signal) and wakes up
35 * the process's sleeping threads. Signals are delivered only on the way
36 * back to user mode (signal_take(), from the architecture's return path),
37 * never from the middle of the kernel: a sleep that a signal interrupts
38 * returns ERESTARTSYS, and the system call unwinds.
39 */
40int signal_send(int pid, int sig);
41int signal_proc_send(struct proc *proc, int signal);
42int signal_pgrp_send(struct pgroup *pg, int signal);
43
44/* Notes that sigaction() changed a signal's action (a pending signal that
45 * is now ignored is discarded). */
46void signal_action_set(struct proc *proc, int sig);
47
48/* Sends a fault's signal (SIGSEGV, SIGILL...): it is delivered even if
49 * it's blocked or ignored, by its default action then, because the
50 * instruction would only fault again. */
51void signal_force(struct proc *proc, int signal);
52
53/* Says whether a signal is pending that the thread's process doesn't
54 * block, which ends its interruptible sleeps. */
56
57/* On the way back to user mode: stops the process, or does the default
58 * actions, of the pending signals (terminating doesn't return), and
59 * returns the signal whose handler is to run, or 0. */
60int signal_take(void);
61
62/* Ends the current process, by `sig`, from where it can't go on. */
63void signal_exit(int sig) __attribute__((noreturn));
64
65/* Stopping and continuing (job control): what waitpid() reports, whether
66 * a signal stops a process, and stopping the current one. */
67#define WAIT_STOPPED 1
68#define WAIT_CONTINUED 2
69
70int signal_stops(struct proc *proc, int sig);
71void signal_stop(int sig);
72
73/*
74 * What a system call that a signal interrupted returns (a sleep returned
75 * it). With ERESTARTSYS, the call is restarted on the way out if no
76 * handler runs, or if the handler has SA_RESTART. With ERESTARTNOHAND,
77 * it's restarted only if no handler runs: for the waits that POSIX says
78 * fail with EINTR whatever SA_RESTART says. User space never sees these
79 * values: it gets EINTR.
80 */
81#define ERESTARTSYS 512
82#define ERESTARTNOHAND 514
83
84/* The signals that can't be blocked. */
85#define SIG_UNMASKABLE ((1UL << SIGKILL) | (1UL << SIGSTOP))
86
87#endif /* ! _SYS_SIGNAL_H */
#define SIG_MAX
Definition signal.h:16
int signal_interrupts(struct thread *thread)
Says whether a thread has a signal to take, which ends a sleep that a signal may end.
Definition signal.c:215
int signal_proc_send(struct proc *proc, int signal)
Sends a signal to a process.
Definition signal.c:310
void signal_exit(int sig)
Ends the current process because of a signal.
Definition signal.c:245
int signal_stops(struct proc *proc, int sig)
Says whether delivering a signal to a process would stop it: the signal isn't caught,...
Definition signal.c:69
void signal_stop(int sig)
Stops the current process, until SIGCONT or SIGKILL.
Definition signal.c:98
int signal_send(int pid, int sig)
Sends a signal as kill() does.
Definition signal.c:340
void signal_force(struct proc *proc, int signal)
Sends a signal that can't be blocked or ignored, such as the SIGSEGV of a fault: if the process block...
Definition signal.c:230
int signal_take(void)
Takes the current process's pending signals, on the way back to user mode: ignored ones are dropped,...
Definition signal.c:262
int sig_default_action[SIG_MAX+1]
Definition signal.c:27
int signal_pgrp_send(struct pgroup *pg, int signal)
Sends a signal to every process of a process group.
Definition signal.c:322
void signal_action_set(struct proc *proc, int sig)
Discards a pending signal that sigaction() just made ignored.
Definition signal.c:201
A process group: the processes of a job.
Definition proc.h:56
A process.
Definition proc.h:75
A thread.
Definition thread.h:23