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 2022-09-09 "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 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\(emchanging the process's signal mask, switching signal stacks (see
42 .BR sigaltstack "(2))\(emin"
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.
63 exists only to allow the implementation of signal handlers.
69 .\" See sysdeps/unix/sysv/linux/sigreturn.c and
70 .\" signal/sigreturn.c in the glibc source
71 wrapper in the GNU C library simply returns \-1, with
75 Details of the arguments (if any) passed to
77 vary depending on the architecture.
78 (On some architectures, such as x86-64,
80 takes no arguments, since all of the information that it requires
81 is available in the stack frame that was previously created by the
82 kernel on the user-space stack.)
84 Once upon a time, UNIX systems placed the signal trampoline code
86 Nowadays, pages of the user stack are protected so as to
87 disallow code execution.
88 Thus, on contemporary Linux systems, depending on the architecture,
89 the signal trampoline code lives either in the
93 .\" See, for example, sysdeps/unix/sysv/linux/i386/sigaction.c and
94 .\" sysdeps/unix/sysv/linux/x86_64/sigaction.c in the glibc (2.20) source.
97 wrapper function informs the kernel of the location of the trampoline code
98 by placing its address in the
109 The saved process context information is placed in a
112 .IR <sys/ucontext.h> ).
113 That structure is visible within the signal handler
114 as the third argument of a handler established via
120 On some other UNIX systems,
121 the operation of the signal trampoline differs a little.
122 In particular, on some systems, upon transitioning back to user mode,
123 the kernel passes control to the trampoline (rather than the signal handler),
124 and the trampoline code calls the signal handler (and then calls
126 once the handler returns).
128 .SS C library/kernel differences
129 The original Linux system call was named
131 However, with the addition of real-time signals in Linux 2.2,
134 was added to support an enlarged
138 hides these details from us, transparently employing
140 when the kernel provides it.
144 .BR restart_syscall (2),