Blame man2/restart_syscall.2

Packit 7cfc04
.\" Copyright (c) 2013 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" http://thread.gmane.org/gmane.linux.kernel/76552/focus=76803
Packit 7cfc04
.\" From: Linus Torvalds <torvalds <at> transmeta.com>
Packit 7cfc04
.\" Subject: Re: [PATCH] compatibility syscall layer (lets try again)
Packit 7cfc04
.\" Newsgroups: gmane.linux.kernel
Packit 7cfc04
.\" Date: 2002-12-05 02:51:12 GMT
Packit 7cfc04
.\"
Packit 7cfc04
.\" See also Section 11.3.3 of Understanding the Linux Kernel, 3rd edition
Packit 7cfc04
.\"
Packit 7cfc04
.TH RESTART_SYSCALL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
restart_syscall \- restart a system call after interruption by a stop signal
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B int restart_syscall(void);
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There is no glibc wrapper for this system call; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
system call is used to restart certain system calls
Packit 7cfc04
after a process that was stopped by a signal (e.g.,
Packit 7cfc04
.BR SIGSTOP
Packit 7cfc04
or
Packit 7cfc04
.BR SIGTSTP )
Packit 7cfc04
is later resumed after receiving a
Packit 7cfc04
.BR SIGCONT
Packit 7cfc04
signal.
Packit 7cfc04
This system call is designed only for internal use by the kernel.
Packit 7cfc04
.PP
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
is used for restarting only those system calls that,
Packit 7cfc04
when restarted, should adjust their time-related parameters\(emnamely
Packit 7cfc04
.BR poll (2)
Packit 7cfc04
(since Linux 2.6.24),
Packit 7cfc04
.BR nanosleep (2)
Packit 7cfc04
(since Linux 2.6),
Packit 7cfc04
.BR clock_nanosleep (2)
Packit 7cfc04
(since Linux 2.6),
Packit 7cfc04
and
Packit 7cfc04
.BR futex (2),
Packit 7cfc04
when employed with the
Packit 7cfc04
.BR FUTEX_WAIT
Packit 7cfc04
(since Linux 2.6.22)
Packit 7cfc04
and
Packit 7cfc04
.BR FUTEX_WAIT_BITSET
Packit 7cfc04
(since Linux 2.6.31)
Packit 7cfc04
operations.
Packit 7cfc04
.\" These system calls correspond to the special internal errno value
Packit 7cfc04
.\" ERESTART_RESTARTBLOCK. Each of the system calls has a "restart"
Packit 7cfc04
.\" helper function that is invoked by restart_syscall().
Packit 7cfc04
.\" Notable (as at Linux 3.17) is that poll() has such a "restart"
Packit 7cfc04
.\" function, but ppoll(), select(), and pselect() do not.
Packit 7cfc04
.\" This means that the latter system calls do not take account of the
Packit 7cfc04
.\" time spent in the stopped state when restarting.
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
restarts the interrupted system call with a
Packit 7cfc04
time argument that is suitably adjusted to account for the
Packit 7cfc04
time that has already elapsed (including the time where the process
Packit 7cfc04
was stopped by a signal).
Packit 7cfc04
Without the
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
mechanism, restarting these system calls would not correctly deduct the
Packit 7cfc04
already elapsed time when the process continued execution.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The return value of
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
is the return value of whatever system call is being restarted.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.I errno
Packit 7cfc04
is set as per the errors for whatever system call is being restarted by
Packit 7cfc04
.BR restart_syscall ().
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
The
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
system call is present since Linux 2.6.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This system call is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
There is no glibc wrapper for this system call,
Packit 7cfc04
because it is intended for use only by the kernel and
Packit 7cfc04
should never be called by applications.
Packit 7cfc04
.PP
Packit 7cfc04
The kernel uses
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
to ensure that when a system call is restarted
Packit 7cfc04
after a process has been stopped by a signal and then resumed by
Packit 7cfc04
.BR SIGCONT ,
Packit 7cfc04
then the time that the process spent in the stopped state is counted
Packit 7cfc04
against the timeout interval specified in the original system call.
Packit 7cfc04
In the case of system calls that take a timeout argument and
Packit 7cfc04
automatically restart after a stop signal plus
Packit 7cfc04
.BR SIGCONT ,
Packit 7cfc04
but which do not have the
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
mechanism built in, then, after the process resumes execution,
Packit 7cfc04
the time that the process spent in the stop state is
Packit 7cfc04
.I not
Packit 7cfc04
counted against the timeout value.
Packit 7cfc04
Notable examples of system calls that suffer this problem are
Packit 7cfc04
.BR ppoll (2),
Packit 7cfc04
.BR select (2),
Packit 7cfc04
and
Packit 7cfc04
.BR pselect (2).
Packit 7cfc04
.PP
Packit 7cfc04
From user space, the operation of
Packit 7cfc04
.BR restart_syscall ()
Packit 7cfc04
is largely invisible:
Packit 7cfc04
to the process that made the system call that is restarted,
Packit 7cfc04
it appears as though that system call executed and
Packit 7cfc04
returned in the usual fashion.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR sigaction (2),
Packit 7cfc04
.BR sigreturn (2),
Packit 7cfc04
.BR signal (7)
Packit 7cfc04
.\" FIXME . ppoll(2), select(2), and pselect(2)
Packit 7cfc04
.\"     should probably get the restart_syscall() treatment:
Packit 7cfc04
.\"     If a select() call is suspended by stop-sig+SIGCONT, the time
Packit 7cfc04
.\"     spent suspended is *not* deducted when the select() is restarted.
Packit 7cfc04
.\" FIXME . check whether recvmmsg() handles stop-sig+SIGCONT properly.
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.