1 .\" Copyright (C) 2008, 2014, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" Created Sat Aug 21 1995 Thomas K. Dyas <tdyas@eden.rutgers.edu>
6 .\" Modified Tue Oct 22 22:09:03 1996 by Eric S. Raymond <esr@thyrsus.com>
7 .\" 2008-06-26, mtk, added some more detail on the work done by sigreturn()
8 .\" 2014-12-05, mtk, rewrote all of the rest of the original page
10 .TH sigreturn 2 (date) "Linux man-pages (unreleased)"
12 sigreturn, rt_sigreturn \- return from signal handler and cleanup stack frame
15 .RI ( libc ", " \-lc )
18 .B int sigreturn(...);
21 If the Linux kernel determines that an unblocked
22 signal is pending for a process, then,
23 at the next transition back to user mode in that process
24 (e.g., upon return from a system call or
25 when the process is rescheduled onto the CPU),
26 it creates a new frame on the user-space stack where it
27 saves various pieces of process context
28 (processor status word, registers, signal mask, and signal stack settings).
29 .\" See arch/x86/kernel/signal.c::__setup_frame() [in Linux 3.17 source code]
31 The kernel also arranges that, during the transition back to user mode,
32 the signal handler is called, and that, upon return from the handler,
33 control passes to a piece of user-space code commonly called
34 the "signal trampoline".
35 The signal trampoline code in turn calls
40 call undoes everything that was
41 done\[em]changing the process's signal mask, switching signal stacks (see
42 .BR sigaltstack "(2))\[em]in"
43 order to invoke the signal handler.
44 Using the information that was earlier saved on the user-space stack
46 restores the process's signal mask, switches stacks,
47 and restores the process's context
48 (processor flags and registers,
49 including the stack pointer and instruction pointer),
50 so that the process resumes execution
51 at the point where it was interrupted by the signal.
56 Many UNIX-type systems have a
58 system call or near equivalent.
59 However, this call is not specified in POSIX,
60 and details of its behavior vary across systems.
65 exists only to allow the implementation of signal handlers.
71 .\" See sysdeps/unix/sysv/linux/sigreturn.c and
72 .\" signal/sigreturn.c in the glibc source
73 wrapper in the GNU C library simply returns \-1, with
77 Details of the arguments (if any) passed to
79 vary depending on the architecture.
80 (On some architectures, such as x86-64,
82 takes no arguments, since all of the information that it requires
83 is available in the stack frame that was previously created by the
84 kernel on the user-space stack.)
86 Once upon a time, UNIX systems placed the signal trampoline code
88 Nowadays, pages of the user stack are protected so as to
89 disallow code execution.
90 Thus, on contemporary Linux systems, depending on the architecture,
91 the signal trampoline code lives either in the
95 .\" See, for example, sysdeps/unix/sysv/linux/i386/sigaction.c and
96 .\" sysdeps/unix/sysv/linux/x86_64/sigaction.c in the glibc (2.20) source.
99 wrapper function informs the kernel of the location of the trampoline code
100 by placing its address in the
111 The saved process context information is placed in a
114 .IR <sys/ucontext.h> ).
115 That structure is visible within the signal handler
116 as the third argument of a handler established via
122 On some other UNIX systems,
123 the operation of the signal trampoline differs a little.
124 In particular, on some systems, upon transitioning back to user mode,
125 the kernel passes control to the trampoline (rather than the signal handler),
126 and the trampoline code calls the signal handler (and then calls
128 once the handler returns).
130 .SS C library/kernel differences
131 The original Linux system call was named
133 However, with the addition of real-time signals in Linux 2.2,
136 was added to support an enlarged
140 hides these details from us, transparently employing
142 when the kernel provides it.
146 .BR restart_syscall (2),