Section: Linux Programmer's Manual (2)
sigreturn, rt_sigreturn - return from signal handler and cleanup stack frame
If the Linux kernel determines that an unblocked
signal is pending for a process, then,
at the next transition back to user mode in that process
(e.g., upon return from a system call or
when the process is rescheduled onto the CPU),
it creates a new frame on the user-space stack where it
saves various pieces of process context
(processor status word, registers, signal mask, and signal stack settings).
The kernel also arranges that, during the transition back to user mode,
the signal handler is called, and that, upon return from the handler,
control passes to a piece of user-space code commonly called
the "signal trampoline".
The signal trampoline code in turn calls
call undoes everything that was
done---changing the process's signal mask, switching signal stacks (see
order to invoke the signal handler.
Using the information that was earlier saved on the user-space stack
restores the process's signal mask, switches stacks,
and restores the process's context
(processor flags and registers,
including the stack pointer and instruction pointer),
so that the process resumes execution
at the point where it was interrupted by the signal.
Many UNIX-type systems have a
system call or near equivalent.
However, this call is not specified in POSIX,
and details of its behavior vary across systems.
exists only to allow the implementation of signal handlers.
be called directly.
(Indeed, a simple
wrapper in the GNU C library simply returns -1, with
Details of the arguments (if any) passed to
vary depending on the architecture.
(On some architectures, such as x86-64,
takes no arguments, since all of the information that it requires
is available in the stack frame that was previously created by the
kernel on the user-space stack.)
Once upon a time, UNIX systems placed the signal trampoline code
onto the user stack.
Nowadays, pages of the user stack are protected so as to
disallow code execution.
Thus, on contemporary Linux systems, depending on the architecture,
the signal trampoline code lives either in the
or in the C library.
In the latter case,
the C library's
wrapper function informs the kernel of the location of the trampoline code
by placing its address in the
field of the
and sets the
flag in the
The saved process context information is placed in a
That structure is visible within the signal handler
as the third argument of a handler established via
On some other UNIX systems,
the operation of the signal trampoline differs a little.
In particular, on some systems, upon transitioning back to user mode,
the kernel passes control to the trampoline (rather than the signal handler),
and the trampoline code calls the signal handler (and then calls
once the handler returns).
C library/kernel differences
The original Linux system call was named
However, with the addition of real-time signals in Linux 2.2,
a new system call,
was added to support an enlarged
The GNU C library
hides these details from us, transparently employing
when the kernel provides it.
This page is part of release 5.02 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at