AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
signal.h File Reference
#include <core/system.h>
#include <sys/proc.h>
#include <aquila/signal.h>

Go to the source code of this file.

Macros

#define SIG_MAX   (NSIG - 1)
#define SIGACT_ABORT   1
#define SIGACT_TERMINATE   2
#define SIGACT_IGNORE   3
#define SIGACT_STOP   4
#define SIGACT_CONTINUE   5
#define SIG_DFL   ((uintptr_t) 0)
#define SIG_IGN   ((uintptr_t) 1)
#define SIG_ERR   ((uintptr_t) -1)
#define WAIT_STOPPED   1
#define WAIT_CONTINUED   2
#define ERESTARTSYS   512
#define ERESTARTNOHAND   514
#define SIG_UNMASKABLE   ((1UL << SIGKILL) | (1UL << SIGSTOP))

Functions

int signal_send (int pid, int sig)
 Sends a signal as kill() does.
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.
void signal_action_set (struct proc *proc, int sig)
 Discards a pending signal that sigaction() just made ignored.
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.
int signal_interrupts (struct thread *thread)
 Says whether a thread has a signal to take, which ends a sleep that a signal may end.
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.
void signal_exit (int sig)
 Ends the current process because of a signal.
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.
void signal_stop (int sig)
 Stops the current process, until SIGCONT or SIGKILL.

Variables

int sig_default_action [SIG_MAX+1]

Macro Definition Documentation

◆ ERESTARTNOHAND

#define ERESTARTNOHAND   514

◆ ERESTARTSYS

#define ERESTARTSYS   512

◆ SIG_DFL

#define SIG_DFL   ((uintptr_t) 0)

◆ SIG_ERR

#define SIG_ERR   ((uintptr_t) -1)

Definition at line 28 of file signal.h.

◆ SIG_IGN

#define SIG_IGN   ((uintptr_t) 1)

◆ SIG_MAX

#define SIG_MAX   (NSIG - 1)

Definition at line 16 of file signal.h.

Referenced by kproc_init(), proc_execve(), proc_new(), signal_send(), signal_to(), and sys_sigaction().

◆ SIG_UNMASKABLE

#define SIG_UNMASKABLE   ((1UL << SIGKILL) | (1UL << SIGSTOP))

Definition at line 85 of file signal.h.

Referenced by arch_sigreturn(), deliver(), deliver(), sys_select(), sys_sigmask(), and sys_sigsuspend().

◆ SIGACT_ABORT

#define SIGACT_ABORT   1

Definition at line 19 of file signal.h.

Referenced by signal_take().

◆ SIGACT_CONTINUE

#define SIGACT_CONTINUE   5

Definition at line 23 of file signal.h.

Referenced by signal_ignored().

◆ SIGACT_IGNORE

#define SIGACT_IGNORE   3

Definition at line 21 of file signal.h.

Referenced by signal_ignored().

◆ SIGACT_STOP

#define SIGACT_STOP   4

Definition at line 22 of file signal.h.

Referenced by signal_stops(), and signal_take().

◆ SIGACT_TERMINATE

#define SIGACT_TERMINATE   2

Definition at line 20 of file signal.h.

Referenced by signal_take().

◆ WAIT_CONTINUED

#define WAIT_CONTINUED   2

Definition at line 68 of file signal.h.

Referenced by signal_stop(), signal_to(), and sys_waitpid().

◆ WAIT_STOPPED

#define WAIT_STOPPED   1

Definition at line 67 of file signal.h.

Referenced by signal_stop(), signal_to(), and sys_waitpid().

Function Documentation

◆ signal_action_set()

void signal_action_set ( struct proc * proc,
int sig )

Discards a pending signal that sigaction() just made ignored.

Parameters
procthe process
sigthe 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().

◆ signal_exit()

void signal_exit ( int sig)

Ends the current process because of a signal.

It doesn't return.

Parameters
sigthe 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().

◆ signal_force()

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.

Parameters
procthe process
signalthe 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().

◆ signal_interrupts()

int signal_interrupts ( struct thread * thread)

Says whether a thread has a signal to take, which ends a sleep that a signal may end.

Parameters
threadthe thread
Returns
1 if its process has a pending signal that it doesn't block, 0 if not

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().

◆ signal_pgrp_send()

int signal_pgrp_send ( struct pgroup * pg,
int signal )

Sends a signal to every process of a process group.

Parameters
pgthe process group
signalthe signal
Returns
0

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().

◆ signal_proc_send()

int signal_proc_send ( struct proc * proc,
int signal )

Sends a signal to a process.

Parameters
procthe process
signalthe signal (0 only checks that the process exists)
Returns
0, -EINVAL for a bad signal, or -EPERM for process 0

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().

◆ signal_send()

int signal_send ( pid_t pid,
int signal )

Sends a signal as kill() does.

Parameters
pidwhom 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
signalthe signal
Returns
0, -EINVAL for a bad signal, or -ESRCH if no such process or group exists

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().

◆ signal_stop()

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.

Parameters
sigthe 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().

◆ signal_stops()

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.

Parameters
procthe process
sigthe signal
Returns
1 if it would, 0 if not

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().

◆ signal_take()

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.

Returns
a signal whose handler the architecture runs now, or 0 if there is none

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().

Variable Documentation

◆ sig_default_action

int sig_default_action[SIG_MAX+1]
extern

Definition at line 27 of file signal.c.

Referenced by signal_ignored(), signal_stops(), and signal_take().