|
AquilaOS documentation
How it works, and its code
|
Signals: sending them, and taking them on the way back to user mode. More...
#include <core/system.h>#include <core/arch.h>#include <ds/queue.h>#include <sys/proc.h>#include <sys/signal.h>#include <sys/kthread.h>#include <sys/sched.h>#include <aquila/errno.h>Go to the source code of this file.
Macros | |
| #define | STOP_SIGNALS ((1UL << SIGSTOP) | (1UL << SIGTSTP) | (1UL << SIGTTIN) | (1UL << SIGTTOU)) |
Functions | |
| int | signal_stops (struct proc *proc, int sig) |
| Says whether delivering a signal to a process would stop it: the signal isn't caught, and its default action is to stop. | |
| static void | signal_notify_parent (struct proc *proc) |
| Tells a process's parent that it stopped or continued: its wait() wakes up, and it gets SIGCHLD unless it asked not to (SA_NOCLDSTOP). | |
| void | signal_stop (int sig) |
| Stops the current process, until SIGCONT or SIGKILL. | |
| static int | is_stop_signal (int sig) |
| Returns whether sig is one of the stop signals. | |
| static int | signal_ignored (struct proc *proc, int sig) |
| Returns whether delivering sig would do nothing: the process ignores it, or its default action is to ignore it. | |
| static int | signal_to (struct proc *proc, int signal) |
| Sends a signal to a process: makes it pending, and if the process doesn't block it, wakes up its sleeping threads so that one takes it on its way back to user mode. | |
| void | signal_action_set (struct proc *proc, int sig) |
| Discards a pending signal that sigaction() just made ignored. | |
| int | signal_interrupts (struct thread *thread) |
| Says whether a thread has a signal to take, which ends a sleep that a signal may end. | |
| 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 blocks or ignores it, it is unblocked and its action reset to the default. | |
| void | signal_exit (int sig) |
| Ends the current process because of a signal. | |
| int | signal_take (void) |
| Takes the current process's pending signals, on the way back to user mode: ignored ones are dropped, and default actions are carried out (ending or stopping the process), until one with a handler is found. | |
| int | signal_proc_send (struct proc *proc, int signal) |
| Sends a signal to a process. | |
| int | signal_pgrp_send (struct pgroup *pg, int signal) |
| Sends a signal to every process of a process group. | |
| int | signal_send (pid_t pid, int signal) |
| Sends a signal as kill() does. | |
Variables | |
| int | sig_default_action [SIG_MAX+1] |
Signals: sending them, and taking them on the way back to user mode.
Sending a signal makes it pending (a bit of proc->sig_pending). If the process doesn't block it, its threads that sleep where a signal may end the sleep (waitq_sleep()) wake up: they return -ERESTARTSYS, and their system calls unwind. A signal is only delivered on the way back to user mode: the architecture's return path calls signal_take(), which carries out stops and default actions, and runs the handler it returns. So the kernel never leaves anything halfway for a signal. See docs/kernel/signals.md.
Definition in file signal.c.
| #define STOP_SIGNALS ((1UL << SIGSTOP) | (1UL << SIGTSTP) | (1UL << SIGTTIN) | (1UL << SIGTTOU)) |
Definition at line 110 of file signal.c.
Referenced by is_stop_signal(), and signal_to().
|
static |
Returns whether sig is one of the stop signals.
Definition at line 113 of file signal.c.
References is_stop_signal(), and STOP_SIGNALS.
Referenced by is_stop_signal(), and signal_to().
| void signal_action_set | ( | struct proc * | proc, |
| int | sig ) |
Discards a pending signal that sigaction() just made ignored.
| proc | the process |
| sig | the signal whose action changed |
Definition at line 201 of file signal.c.
References proc::sig_pending, signal_action_set(), and signal_ignored().
Referenced by signal_action_set(), and sys_sigaction().
| void signal_exit | ( | int | sig | ) |
Ends the current process because of a signal.
It doesn't return.
| sig | the signal, which its parent's wait() reports |
Definition at line 245 of file signal.c.
References arch_sleep(), curproc, PROC_EXIT, proc_kill(), and signal_exit().
Referenced by deliver(), deliver(), signal_exit(), and signal_take().
| 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 blocks or ignores it, it is unblocked and its action reset to the default.
| proc | the process |
| signal | the signal |
Definition at line 230 of file signal.c.
References SIG_DFL, SIG_IGN, proc::sigaction, proc::sigmask, signal_force(), and signal_to().
Referenced by abort(), arch_sigreturn(), isr_dispatch(), signal_force(), and sync_dispatch().
|
static |
Returns whether delivering sig would do nothing: the process ignores it, or its default action is to ignore it.
SIGCONT counts, since its action is done when it is sent.
Definition at line 121 of file signal.c.
References sig_default_action, SIG_DFL, SIG_IGN, SIGACT_CONTINUE, SIGACT_IGNORE, proc::sigaction, and signal_ignored().
Referenced by signal_action_set(), signal_ignored(), and signal_to().
| int signal_interrupts | ( | struct thread * | thread | ) |
Says whether a thread has a signal to take, which ends a sleep that a signal may end.
| thread | the thread |
Definition at line 215 of file signal.c.
References kproc, thread::owner, proc::sig_pending, proc::sigmask, and signal_interrupts().
Referenced by signal_interrupts(), and waitq_sleep().
|
static |
Tells a process's parent that it stopped or continued: its wait() wakes up, and it gets SIGCHLD unless it asked not to (SA_NOCLDSTOP).
Definition at line 77 of file signal.c.
References proc::parent, proc::sigaction, signal_notify_parent(), signal_proc_send(), proc::wait_queue, and waitq_wakeup().
Referenced by signal_notify_parent(), signal_stop(), and signal_to().
| int signal_pgrp_send | ( | struct pgroup * | pg, |
| int | signal ) |
Sends a signal to every process of a process group.
| pg | the process group |
| signal | the signal |
Definition at line 322 of file signal.c.
References pgroup::procs, queue_for, signal_pgrp_send(), and signal_to().
Referenced by pgrp_orphaned_hangup(), signal_pgrp_send(), tty_background(), tty_hangup(), and tty_signal().
| int signal_proc_send | ( | struct proc * | proc, |
| int | signal ) |
Sends a signal to a process.
| proc | the process |
| signal | the signal (0 only checks that the process exists) |
Definition at line 310 of file signal.c.
References signal_proc_send(), and signal_to().
Referenced by kernel_ctrlaltdel(), mm_page_fault(), proc_zombie_notify(), sched_timer_tick(), signal_notify_parent(), signal_proc_send(), sys_send(), sys_write(), vt_signal(), and x86_fpu_trap().
| int signal_send | ( | pid_t | pid, |
| int | signal ) |
Sends a signal as kill() does.
| pid | whom to: a process if pid > 0, the caller's process group if 0, every process but init and the caller if -1, or process group -pid if < -1 |
| signal | the signal |
Definition at line 340 of file signal.c.
References curproc, kproc, pgroup::pgid, proc::pgrp, proc::pid, proc_pid_find(), procs, queue_for, proc::running, SIG_MAX, signal_send(), and signal_to().
Referenced by signal_send(), and sys_kill().
| void signal_stop | ( | int | sig | ) |
Stops the current process, until SIGCONT or SIGKILL.
Its thread calls this on its way back to user mode (signal_take()), and sleeps here; other signals don't end the sleep, only continuing (or killing) the process does.
| sig | the signal that stops it |
Definition at line 98 of file signal.c.
References curproc, signal_notify_parent(), signal_stop(), proc::stop_queue, proc::stopped, WAIT_CONTINUED, proc::wait_event, WAIT_STOPPED, and waitq_sleep_unint().
Referenced by signal_stop(), and signal_take().
| int signal_stops | ( | struct proc * | proc, |
| int | sig ) |
Says whether delivering a signal to a process would stop it: the signal isn't caught, and its default action is to stop.
| proc | the process |
| sig | the signal |
Definition at line 69 of file signal.c.
References sig_default_action, SIG_DFL, SIGACT_STOP, proc::sigaction, and signal_stops().
Referenced by signal_stops().
| int signal_take | ( | void | ) |
Takes the current process's pending signals, on the way back to user mode: ignored ones are dropped, and default actions are carried out (ending or stopping the process), until one with a handler is found.
Definition at line 262 of file signal.c.
References curproc, NULL, proc::pgrp, pgrp_orphaned(), ready, proc::running, sig_default_action, SIG_DFL, SIG_IGN, proc::sig_pending, SIGACT_ABORT, SIGACT_STOP, SIGACT_TERMINATE, proc::sigaction, proc::sigmask, signal_exit(), signal_stop(), and signal_take().
Referenced by aarch64_return_to_user(), signal_take(), and x86_return_to_user().
|
static |
Sends a signal to a process: makes it pending, and if the process doesn't block it, wakes up its sleeping threads so that one takes it on its way back to user mode.
Returns 0, -EINVAL for a bad signal, or -EPERM for process 0.
Definition at line 138 of file signal.c.
References is_stop_signal(), ISLEEP, kproc, queue_for, proc::running, sched_thread_kick(), SIG_MAX, proc::sig_pending, proc::sigmask, signal_ignored(), signal_notify_parent(), signal_to(), thread::state, proc::stop_queue, STOP_SIGNALS, proc::stopped, thread_wakeup(), proc::threads, WAIT_CONTINUED, proc::wait_event, WAIT_STOPPED, thread::waitq, and waitq_wakeup().
Referenced by signal_force(), signal_pgrp_send(), signal_proc_send(), signal_send(), and signal_to().
| int sig_default_action[SIG_MAX+1] |
Definition at line 27 of file signal.c.
Referenced by signal_ignored(), signal_stops(), and signal_take().