Go to file
Adhemerval Zanella 34b5783ea2 sparc: Fix restartable syscalls (BZ 32173)
The commit 'sparc: Use Linux kABI for syscall return'
(86c5d2cf0c) did not take into account
a subtle sparc syscall kABI constraint.  For syscalls that might block
indefinitely, on an interrupt (like SIGCONT) the kernel will set the
instruction pointer to just before the syscall:

arch/sparc/kernel/signal_64.c
476 static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
477 {
[...]
525                 if (restart_syscall) {
526                         switch (regs->u_regs[UREG_I0]) {
527                         case ERESTARTNOHAND:
528                         case ERESTARTSYS:
529                         case ERESTARTNOINTR:
530                                 /* replay the system call when we are done */
531                                 regs->u_regs[UREG_I0] = orig_i0;
532                                 regs->tpc -= 4;
533                                 regs->tnpc -= 4;
534                                 pt_regs_clear_syscall(regs);
535                                 fallthrough;
536                         case ERESTART_RESTARTBLOCK:
537                                 regs->u_regs[UREG_G1] = __NR_restart_syscall;
538                                 regs->tpc -= 4;
539                                 regs->tnpc -= 4;
540                                 pt_regs_clear_syscall(regs);
541                         }

However, on a SIGCONT it seems that 'g1' register is being clobbered after the
syscall returns.  Before 86c5d2cf0c, the 'g1' was always placed jus
before the 'ta' instruction which then reloads the syscall number and restarts
the syscall.

On master, where 'g1' might be placed before 'ta':

  $ cat test.c
  #include <unistd.h>

  int main ()
  {
    pause ();
  }
  $ gcc test.c -o test
  $ strace -f ./t
  [...]
  ppoll(NULL, 0, NULL, NULL, 0

On another terminal

  $ kill -STOP 2262828

  $ strace -f ./t
  [...]
  --- SIGSTOP {si_signo=SIGSTOP, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  --- stopped by SIGSTOP ---

And then

  $ kill -CONT 2262828

Results in:

  --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  restart_syscall(<... resuming interrupted ppoll ...>) = -1 EINTR (Interrupted system call)

Where the expected behaviour would be:

  $ strace -f ./t
  [...]
  ppoll(NULL, 0, NULL, NULL, 0)           = ? ERESTARTNOHAND (To be restarted if no handler)
  --- SIGSTOP {si_signo=SIGSTOP, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  --- stopped by SIGSTOP ---
  --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  ppoll(NULL, 0, NULL, NULL, 0

Just moving the 'g1' setting near the syscall asm is not suffice,
the compiler might optimize it away (as I saw on cancellation.c by
trying this fix).  Instead, I have change the inline asm to put the
'g1' setup in ithe asm block.  This would require to change the asm
constraint for INTERNAL_SYSCALL_NCS, since the syscall number is not
constant.

Checked on sparc64-linux-gnu.

Reported-by: René Rebe <rene@exactcode.de>
Tested-by: Sam James <sam@gentoo.org>
Reviewed-by: Sam James <sam@gentoo.org>
(cherry picked from commit 2c1903cbba)
2024-10-16 15:03:00 -03:00
argp
assert
benchtests
bits
catgets
ChangeLog.old
conform
csu Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-10-01 09:45:59 +08:00
ctype
debug debug: Fix read error handling in pcprofiledump 2024-09-10 12:41:28 +02:00
dirent
dlfcn
elf elf: Fix tst-dlopen-tlsreinit1.out test dependency 2024-09-09 21:31:34 +02:00
gmon
gnulib
hesiod
htl
hurd
iconv
iconvdata
include elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717) 2024-09-09 21:31:28 +02:00
inet
intl
io Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
libio Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-10-01 09:45:59 +08:00
locale
localedata support: Add FAIL test failure helper 2024-08-28 15:58:01 -04:00
login
mach
malloc malloc: add multi-threaded tests for aligned_alloc/calloc/malloc 2024-07-29 15:23:09 +02:00
manual ungetc: Fix uninitialized read when putting into unused streams [BZ #27821] 2024-08-28 15:58:01 -04:00
math Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-10-01 09:45:59 +08:00
mathvec
misc Add mremap tests 2024-08-01 14:21:57 +02:00
nis
nptl elf: Clarify and invert second argument of _dl_allocate_tls_init 2024-09-09 21:15:23 +02:00
nptl_db
nscd
nss
po
posix posix: Use <support/check.h> facilities in tst-truncate and tst-truncate64 2024-08-30 15:28:16 -04:00
resolv resolv: Fix tst-resolv-short-response for older GCC (bug 32042) 2024-08-01 21:09:33 +02:00
resource Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
rt Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
scripts Adjust check-local-headers test for libaudit 4.0 2024-08-13 09:57:26 +02:00
setjmp
signal Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
socket Fix name space violation in fortify wrappers (bug 32052) 2024-08-06 08:21:58 +02:00
soft-fp
stdio-common Add tests of fread 2024-09-26 16:18:59 +02:00
stdlib Add tests of more strtod special cases 2024-09-27 17:25:43 +02:00
string string: strerror, strsignal cannot use buffer after dlmopen (bug 32026) 2024-08-19 16:11:19 +02:00
sunrpc
support support: Make support_process_state_wait return the found state 2024-10-16 15:03:00 -03:00
sysdeps sparc: Fix restartable syscalls (BZ 32173) 2024-10-16 15:03:00 -03:00
sysvipc Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
termios
time Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-05-28 07:30:07 +02:00
timezone
wcsmbs Fix name space violation in fortify wrappers (bug 32052) 2024-08-06 08:21:58 +02:00
wctype
.clang-format
.gitattributes
.gitignore
abi-tags
aclocal.m4
ADVISORIES
config.h.in
config.make.in
configure
configure.ac
CONTRIBUTED-BY
COPYING
COPYING.LIB
extra-lib.mk
gen-locales.mk
INSTALL
libc-abis
libof-iterator.mk
LICENSES
MAINTAINERS
Makeconfig Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-10-01 09:45:59 +08:00
Makefile
Makefile.help
Makefile.in
Makerules
NEWS libio: Attempt wide backup free only for non-legacy code 2024-09-11 08:48:53 +02:00
o-iterator.mk
README
Rules Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-10-01 09:45:59 +08:00
SECURITY.md
SHARED-FILES
shlib-versions
test-skeleton.c
version.h

This directory contains the sources of the GNU C Library.
See the file "version.h" for what release version you have.

The GNU C Library is the standard system C library for all GNU systems,
and is an important part of what makes up a GNU system.  It provides the
system API for all programs written in C and C-compatible languages such
as C++ and Objective C; the runtime facilities of other programming
languages use the C library to access the underlying operating system.

In GNU/Linux systems, the C library works with the Linux kernel to
implement the operating system behavior seen by user applications.
In GNU/Hurd systems, it works with a microkernel and Hurd servers.

The GNU C Library implements much of the POSIX.1 functionality in the
GNU/Hurd system, using configurations i[4567]86-*-gnu and x86_64-gnu.

When working with Linux kernels, this version of the GNU C Library
requires Linux kernel version 3.2 or later.

Also note that the shared version of the libgcc_s library must be
installed for the pthread library to work correctly.

The GNU C Library supports these configurations for using Linux kernels:

	aarch64*-*-linux-gnu
	alpha*-*-linux-gnu
	arc*-*-linux-gnu
	arm-*-linux-gnueabi
	csky-*-linux-gnuabiv2
	hppa-*-linux-gnu
	i[4567]86-*-linux-gnu
	x86_64-*-linux-gnu	Can build either x86_64 or x32
	loongarch64-*-linux-gnu Hardware floating point, LE only.
	m68k-*-linux-gnu
	microblaze*-*-linux-gnu
	mips-*-linux-gnu
	mips64-*-linux-gnu
	or1k-*-linux-gnu
	powerpc-*-linux-gnu	Hardware or software floating point, BE only.
	powerpc64*-*-linux-gnu	Big-endian and little-endian.
	s390-*-linux-gnu
	s390x-*-linux-gnu
	riscv32-*-linux-gnu
	riscv64-*-linux-gnu
	sh[34]-*-linux-gnu
	sparc*-*-linux-gnu
	sparc64*-*-linux-gnu

If you are interested in doing a port, please contact the glibc
maintainers; see https://www.gnu.org/software/libc/ for more
information.

See the file INSTALL to find out how to configure, build, and install
the GNU C Library.  You might also consider reading the WWW pages for
the C library at https://www.gnu.org/software/libc/.

The GNU C Library is (almost) completely documented by the Texinfo manual
found in the `manual/' subdirectory.  The manual is still being updated
and contains some known errors and omissions; we regret that we do not
have the resources to work on the manual as much as we would like.  For
corrections to the manual, please file a bug in the `manual' component,
following the bug-reporting instructions below.  Please be sure to check
the manual in the current development sources to see if your problem has
already been corrected.

Please see https://www.gnu.org/software/libc/bugs.html for bug reporting
information.  We are now using the Bugzilla system to track all bug reports.
This web page gives detailed information on how to report bugs properly.

The GNU C Library is free software.  See the file COPYING.LIB for copying
conditions, and LICENSES for notices about a few contributions that require
these additional notices to be distributed.  License copyright years may be
listed using range notation, e.g., 1996-2015, indicating that every year in
the range, inclusive, is a copyrightable year that would otherwise be listed
individually.