]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sigreturn.2
sock_diag.7: Tweaks to Dmitry Levin's page
[thirdparty/man-pages.git] / man2 / sigreturn.2
CommitLineData
eda078d4 1.\" Copyright (C) 2008, 2014, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
7.\"
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.
c13182ef 12.\"
fea681da
MK
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
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
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>
0678a1d4 27.\" 2008-06-26, mtk, added some more detail on the work done by sigreturn()
eda078d4 28.\" 2014-12-05, mtk, rewrote all of the rest of the original page
fea681da 29.\"
29b41e74 30.TH SIGRETURN 2 2015-12-28 "Linux" "Linux Programmer's Manual"
fea681da 31.SH NAME
d893db64 32sigreturn, rt_sigreturn \- return from signal handler and cleanup stack frame
fea681da 33.SH SYNOPSIS
eda078d4 34.BI "int sigreturn(...);"
fea681da 35.SH DESCRIPTION
eda078d4
MK
36If the Linux kernel determines that an unblocked
37signal is pending for a process, then,
38at the next transition back to user mode in that process
39(e.g., upon return from a system call or
40when the process is rescheduled onto the CPU),
41it saves various pieces of process context
42(processor status word, registers, signal mask, and signal stack settings)
43into the user-space stack.
44.\" See arch/x86/kernel/signal.c::__setup_frame() [in 3.17 source code]
45
46The kernel also arranges that, during the transition back to user mode,
47the signal handler is called, and that, upon return from the handler,
48control passes to a piece of user-space code commonly called
49the "signal trampoline".
50The signal trampoline code in turn calls
51.BR sigreturn ().
0678a1d4 52
00ac6ce4 53This
e511ffb6 54.BR sigreturn ()
0678a1d4 55call undoes everything that was
eda078d4 56done\(emchanging the process's signal mask, switching signal stacks (see
0678a1d4 57.BR sigaltstack "(2))\(emin "
eda078d4
MK
58order to invoke the signal handler.
59It restores the process's signal mask, switches stacks,
60and restores the process's context
61(processor flags and registers,
62including the stack pointer and instruction pointer),
63so that the process resumes execution
0678a1d4 64at the point where it was interrupted by the signal.
47297adb 65.SH RETURN VALUE
e511ffb6 66.BR sigreturn ()
fea681da 67never returns.
47297adb 68.SH CONFORMING TO
eda078d4 69Many UNIX-type systems have a
2dd578fd 70.BR sigreturn ()
eda078d4
MK
71system call or near equivalent.
72However, this call is not specified in POSIX,
73and details of its behavior vary across systems.
6c36ac81 74.SH NOTES
e511ffb6 75.BR sigreturn ()
eda078d4 76exists only to allow the implementation of signal handlers.
c13182ef 77It should
fea681da 78.B never
c13182ef 79be called directly.
eda078d4
MK
80Details of the arguments (if any) passed to
81.BR sigreturn ()
82vary depending on the architecture.
83
84Once upon a time, UNIX systems placed the signal trampoline code
85onto the user stack.
86Nowadays, pages of the user stack are protected so as to
87disallow code execution.
88Thus, on contemporary Linux systems, depending on the architecture,
89the signal trampoline code lives either in the
90.BR vdso (7)
91or in the C library.
92In the latter case,
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.
95the C library supplies the location of the trampoline code using the
96.I sa_restorer
97field of the
98.I sigaction
99structure that is passed to
100.BR sigaction (2),
101and sets the
102.BR SA_RESTORER
103flag in the
104.IR sa_flags
105field.
106
107The saved process context information is placed in a
108.I ucontext_t
109structure (see
110.IR <sys/ucontext.h> ).
111That structure is visible within the signal handler
112as the third argument of a handler established with the
113.BR SA_SIGINFO
114flag.
115
116On some other UNIX systems,
117the operation of the signal trampoline differs a little.
118In particular, on some systems, upon transitioning back to user mode,
119the kernel passes control to the trampoline (rather than the signal handler),
120and the trampoline code calls the signal handler (and then calls
121.BR sigreturn ()
122once the handler returns).
d893db64 123.\"
0722a578 124.SS C library/kernel differences
d893db64
MK
125The original Linux system call was named
126.BR sigreturn ().
127However, with the addition of real-time signals in Linux 2.2,
128a new system call,
129.BR rt_sigreturn ()
130was added to support an enlarged
131.IR sigset_t
132type.
133The GNU C library
134hides these details from us, transparently employing
135.BR rt_sigreturn ()
136when the kernel provides it.
137.\"
47297adb 138.SH SEE ALSO
fea681da 139.BR kill (2),
d806bc05 140.BR restart_syscall (2),
e91751c9 141.BR sigaltstack (2),
fea681da 142.BR signal (2),
eda078d4 143.BR getcontext (3),
cc158601
MK
144.BR signal (7),
145.BR vdso (7)