1 .\" Copyright (C) 2008, 2014, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Created Sat Aug 21 1995 Thomas K. Dyas <tdyas@eden.rutgers.edu>
26 .\" Modified Tue Oct 22 22:09:03 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .\" 2008-06-26, mtk, added some more detail on the work done by sigreturn()
28 .\" 2014-12-05, mtk, rewrote all of the rest of the original page
30 .TH SIGRETURN 2 2021-03-22 "Linux" "Linux Programmer's Manual"
32 sigreturn, rt_sigreturn \- return from signal handler and cleanup stack frame
35 .BI "int sigreturn(...);"
38 If the Linux kernel determines that an unblocked
39 signal is pending for a process, then,
40 at the next transition back to user mode in that process
41 (e.g., upon return from a system call or
42 when the process is rescheduled onto the CPU),
43 it creates a new frame on the user-space stack where it
44 saves various pieces of process context
45 (processor status word, registers, signal mask, and signal stack settings).
46 .\" See arch/x86/kernel/signal.c::__setup_frame() [in 3.17 source code]
48 The kernel also arranges that, during the transition back to user mode,
49 the signal handler is called, and that, upon return from the handler,
50 control passes to a piece of user-space code commonly called
51 the "signal trampoline".
52 The signal trampoline code in turn calls
57 call undoes everything that was
58 done\(emchanging the process's signal mask, switching signal stacks (see
59 .BR sigaltstack "(2))\(emin"
60 order to invoke the signal handler.
61 Using the information that was earlier saved on the user-space stack
63 restores the process's signal mask, switches stacks,
64 and restores the process's context
65 (processor flags and registers,
66 including the stack pointer and instruction pointer),
67 so that the process resumes execution
68 at the point where it was interrupted by the signal.
73 Many UNIX-type systems have a
75 system call or near equivalent.
76 However, this call is not specified in POSIX,
77 and details of its behavior vary across systems.
80 exists only to allow the implementation of signal handlers.
86 .\" See sysdeps/unix/sysv/linux/sigreturn.c and
87 .\" signal/sigreturn.c in the glibc source
88 wrapper in the GNU C library simply returns \-1, with
92 Details of the arguments (if any) passed to
94 vary depending on the architecture.
95 (On some architectures, such as x86-64,
97 takes no arguments, since all of the information that it requires
98 is available in the stack frame that was previously created by the
99 kernel on the user-space stack.)
101 Once upon a time, UNIX systems placed the signal trampoline code
103 Nowadays, pages of the user stack are protected so as to
104 disallow code execution.
105 Thus, on contemporary Linux systems, depending on the architecture,
106 the signal trampoline code lives either in the
110 .\" See, for example, sysdeps/unix/sysv/linux/i386/sigaction.c and
111 .\" sysdeps/unix/sysv/linux/x86_64/sigaction.c in the glibc (2.20) source.
114 wrapper function informs the kernel of the location of the trampoline code
115 by placing its address in the
126 The saved process context information is placed in a
129 .IR <sys/ucontext.h> ).
130 That structure is visible within the signal handler
131 as the third argument of a handler established via
137 On some other UNIX systems,
138 the operation of the signal trampoline differs a little.
139 In particular, on some systems, upon transitioning back to user mode,
140 the kernel passes control to the trampoline (rather than the signal handler),
141 and the trampoline code calls the signal handler (and then calls
143 once the handler returns).
145 .SS C library/kernel differences
146 The original Linux system call was named
148 However, with the addition of real-time signals in Linux 2.2,
151 was added to support an enlarged
155 hides these details from us, transparently employing
157 when the kernel provides it.
161 .BR restart_syscall (2),