The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
signal.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Data Structures

struct  ksigaction_t
 what a process does with one signal (ABI: the sigaction syscall copies it to and from user space in this layout). More...
struct  signal_state_t
 the signal state of a process (inside process_t). More...
struct  signal_handlers
 what a process does with each signal. More...

Macros

#define SIGHUP   1
 signal numbers.
#define SIGINT   2
#define SIGQUIT   3
#define SIGILL   4
#define SIGTRAP   5
#define SIGABRT   6
#define SIGBUS   7
#define SIGFPE   8
#define SIGKILL   9
#define SIGUSR1   10
#define SIGSEGV   11
#define SIGUSR2   12
#define SIGPIPE   13
#define SIGALRM   14
#define SIGTERM   15
#define SIGCHLD   17
#define SIGCONT   18
#define SIGSTOP   19
#define SIGTSTP   20
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGURG   23
#define SIGVTALRM   26
#define SIGPROF   27
#define SIGWINCH   28
#define NSIG   32
#define SIG_BIT(sig)
#define SIG_UNBLOCKABLE   (SIG_BIT(SIGKILL) | SIG_BIT(SIGSTOP))
#define SIG_DFL   0
#define SIG_IGN   1
#define SA_NOCLDSTOP   0x00000001
#define SA_RESTORER   0x04000000
#define SA_RESTART   0x10000000
#define SA_NODEFER   0x40000000
#define SA_RESETHAND   0x80000000
#define SIG_BLOCK   0
#define SIG_UNBLOCK   1
#define SIG_SETMASK   2

Typedefs

typedef struct signal_handlers signal_handlers_t
 what a process does with each signal.

Functions

signal_handlers_t * signal_handlers_create (void)
 make a set of handlers, all SIG_DFL, with one user.
signal_handlers_t * signal_handlers_get (signal_handlers_t *handlers)
 add a user to a set of handlers (a new thread that shares it).
void signal_handlers_put (signal_handlers_t *handlers)
 remove a user from a set of handlers; the last user frees it.
void signal_send (struct process *proc, int sig)
 send a signal to one thread.
void signal_send_process (struct process *proc, int sig)
 send a signal to a process (a thread group): one of its threads takes it (signal_send), one that does not block it if there is one.
int signal_send_group (uint32_t pgid, int sig)
 send a signal to every process of a process group.
void signal_force (struct process *proc, int sig)
 send a signal caused by the process's own instruction (a fault).
bool signal_pending (const struct process *proc)
 true if a signal waits that the process does not block.
void signal_deliver (struct registers *regs)
 act on pending signals before returning to user mode: run the default action, or set up the user handler's frame.
void signal_fork (struct process *child, const struct process *parent)
 the signal state of a forked child: the parent's mask, no pending signals.
void signal_exec (struct process *proc)
 the signal state after execve: handlers go back to SIG_DFL (ignored signals stay ignored); the mask and pending signals stay.
uint32_t signal_state_lock (void)
 take the lock of the signal state of all processes, with interrupts masked.
void signal_state_unlock (uint32_t flags)
 release the lock that signal_state_lock() took.
void signal_init (void)
 set up signal handling.
void signal_alarm_tick (uint64_t now)
 send SIGALRM to processes whose alarm is due.

Macro Definition Documentation

◆ SIGHUP

#define SIGHUP   1

signal numbers.

they are ABI: the same numbers are in the libc's <signal.h>, and a process killed by a signal reports its number in its wait status (wait_status.h).

◆ SIGINT

#define SIGINT   2

◆ SIGQUIT

#define SIGQUIT   3

◆ SIGILL

#define SIGILL   4

◆ SIGTRAP

#define SIGTRAP   5

◆ SIGABRT

#define SIGABRT   6

◆ SIGBUS

#define SIGBUS   7

◆ SIGFPE

#define SIGFPE   8

◆ SIGKILL

#define SIGKILL   9

◆ SIGUSR1

#define SIGUSR1   10

◆ SIGSEGV

#define SIGSEGV   11

◆ SIGUSR2

#define SIGUSR2   12

◆ SIGPIPE

#define SIGPIPE   13

◆ SIGALRM

#define SIGALRM   14

◆ SIGTERM

#define SIGTERM   15

◆ SIGCHLD

#define SIGCHLD   17

◆ SIGCONT

#define SIGCONT   18

◆ SIGSTOP

#define SIGSTOP   19

◆ SIGTSTP

#define SIGTSTP   20

◆ SIGTTIN

#define SIGTTIN   21

◆ SIGTTOU

#define SIGTTOU   22

◆ SIGURG

#define SIGURG   23

◆ SIGVTALRM

#define SIGVTALRM   26

◆ SIGPROF

#define SIGPROF   27

◆ SIGWINCH

#define SIGWINCH   28

◆ NSIG

#define NSIG   32

◆ SIG_BIT

#define SIG_BIT ( sig)
Value:
(1u << (sig))

◆ SIG_UNBLOCKABLE

#define SIG_UNBLOCKABLE   (SIG_BIT(SIGKILL) | SIG_BIT(SIGSTOP))

◆ SIG_DFL

#define SIG_DFL   0

◆ SIG_IGN

#define SIG_IGN   1

◆ SA_NOCLDSTOP

#define SA_NOCLDSTOP   0x00000001

◆ SA_RESTORER

#define SA_RESTORER   0x04000000

◆ SA_RESTART

#define SA_RESTART   0x10000000

◆ SA_NODEFER

#define SA_NODEFER   0x40000000

◆ SA_RESETHAND

#define SA_RESETHAND   0x80000000

◆ SIG_BLOCK

#define SIG_BLOCK   0

◆ SIG_UNBLOCK

#define SIG_UNBLOCK   1

◆ SIG_SETMASK

#define SIG_SETMASK   2

Typedef Documentation

◆ signal_handlers_t

what a process does with each signal.

the threads of a process use one together; it is freed when the last of them lets it go.

Function Documentation

◆ signal_handlers_create()

signal_handlers_t * signal_handlers_create ( void )

make a set of handlers, all SIG_DFL, with one user.

Returns
the set, or NULL if there is no memory.

◆ signal_handlers_get()

signal_handlers_t * signal_handlers_get ( signal_handlers_t * handlers)

add a user to a set of handlers (a new thread that shares it).

Returns
handlers.

◆ signal_handlers_put()

void signal_handlers_put ( signal_handlers_t * handlers)

remove a user from a set of handlers; the last user frees it.

Parameters
handlersthe set, or NULL (nothing is done).

◆ signal_send()

void signal_send ( struct process * proc,
int sig )

send a signal to one thread.

a signal the process ignores is dropped; a deliverable one wakes the process from an interruptible sleep. SIGCONT continues a stopped process, SIGKILL wakes one. safe in any context.

Parameters
procthe process.
sigthe signal (1 to NSIG - 1).

◆ signal_send_process()

void signal_send_process ( struct process * proc,
int sig )

send a signal to a process (a thread group): one of its threads takes it (signal_send), one that does not block it if there is one.

SIGCONT goes to every thread.

Parameters
procany thread of the process, or NULL (nothing is done).
sigthe signal.

◆ signal_send_group()

int signal_send_group ( uint32_t pgid,
int sig )

send a signal to every process of a process group.

Parameters
pgidthe group.
sigthe signal.
Returns
the number of processes it went to.

◆ signal_force()

void signal_force ( struct process * proc,
int sig )

send a signal caused by the process's own instruction (a fault).

it is delivered even if blocked or ignored: blocked or ignored, it kills.

Parameters
procthe process.
sigthe signal.

◆ signal_pending()

bool signal_pending ( const struct process * proc)

true if a signal waits that the process does not block.

a sleeping syscall that sees this gives up its wait (EINTR or a restart).

Parameters
procthe process (NULL: false).

◆ signal_deliver()

void signal_deliver ( struct registers * regs)

act on pending signals before returning to user mode: run the default action, or set up the user handler's frame.

also turns an interrupted syscall's -ERESTARTSYS into EINTR or a restart. called at the end of every interrupt and syscall that came from user mode.

Parameters
regsthe user registers about to be restored.

◆ signal_fork()

void signal_fork ( struct process * child,
const struct process * parent )

the signal state of a forked child: the parent's mask, no pending signals.

the child's handlers (its own set) are copied from the parent's.

◆ signal_exec()

void signal_exec ( struct process * proc)

the signal state after execve: handlers go back to SIG_DFL (ignored signals stay ignored); the mask and pending signals stay.

◆ signal_state_lock()

uint32_t signal_state_lock ( void )

take the lock of the signal state of all processes, with interrupts masked.

it also guards the exit and exec state of each thread group (group_exiting, group_status, exec_thread) and the waitpid reports, as the signal_struct lock does in Linux. it nests outside the process table lock and sched_lock.

Returns
the interrupt state for signal_state_unlock().

◆ signal_state_unlock()

void signal_state_unlock ( uint32_t flags)

release the lock that signal_state_lock() took.

Parameters
flagsthe value from signal_state_lock().

◆ signal_init()

void signal_init ( void )

set up signal handling.

call once at boot.

◆ signal_alarm_tick()

void signal_alarm_tick ( uint64_t now)

send SIGALRM to processes whose alarm is due.

called from the timer interrupt.

Parameters
nowthe current tick.